Cross-Margin Liquidation Engine 
Simulate a cross-margin derivatives engine: process trades, track account equity, and liquidate undercollateralized accounts as fast as possible.
Accounts are funded with a USD deposit and trade instruments whose prices change over time. When a price update causes an account’s equity to fall below 1% of its total position notional, the account must be liquidated.
Definitions
- Account equity =
balance + Σ(size_i * price_i) - Σ(total_paid_i) - Total position notional =
Σ(|size_i| * price_i) - Total paid for instrument
i= signed sum oftrade_size * price_at_trade_timeacross all trades - Margin rule: liquidate if
equity < total_notional / 100after any price update
Input
One command per line on STDIN:
a <balance>– create account with USD balance (IDs start at0, incrementing)p <instrument_idx> <price>– set/update instrument price (0-indexed)t <account_idx> <instrument_idx> <size>– tradesize(signed) at current price- Final line:
<account_idx>– query this account and terminate
Output
On each price update, liquidate all accounts violating the margin rule. For each liquidation, print:
liquidate <account_id> <equity> <position_notional>
Liquidation order: largest total position notional first, then account ID descending as tie-breaker. Liquidated accounts have their balance and positions cleared.
For the final query, print <equity> <notional> for the requested account.
Constraints
- Accounts: <= 100,000
- Instruments: <= 1,000
- Price range: 100 to 1,000,000
- Trade size range: 1 to 10,000
Example
a 100
p 0 100
t 0 0 10
p 0 90
0
Output:
liquidate 0 0 900
0 0
Source code access is restricted. Log in to request access.
| Date | Challenger | Cost | Type | Status |
|---|---|---|---|---|
| Sep 11, 2026 17:40 | Andrew Epstein | 24.42 | Custom | Solution Broken |
| # | Date | Score | Wall Time | CPU User | CPU System | Memory | Error | |
|---|---|---|---|---|---|---|---|---|
| 1 | Sep 11, 2026 17:50 | 0 | 467,488,143 | 443,738,000 | 12,750,000 | 6,311,936 | line 3: expected liquidate 5 20047 9900000 got liquidate 4 0 10000000000 | |
| 2 | Sep 11, 2026 17:50 | 0 | 466,537,395 | 442,892,000 | 12,532,000 | 6,311,936 | line 3: expected liquidate 5 20047 9900000 got liquidate 4 0 10000000000 | |
| 3 | Sep 11, 2026 17:50 | 0 | 464,220,651 | 441,261,000 | 12,644,000 | 6,311,936 | line 3: expected liquidate 5 20047 9900000 got liquidate 4 0 10000000000 | |
| 4 | Oct 13, 2025 00:01 | 15,033 | 220,530,294 | 189,417,000 | 6,013,000 | 2,486,272 | ||
| 5 | Oct 13, 2025 00:10 | 15,360 | 226,159,117 | 194,691,000 | 4,992,000 | 2,490,368 | ||
| 6 | Oct 13, 2025 00:10 | 15,405 | 228,511,937 | 197,257,000 | 3,003,000 | 2,310,144 | ||
| 7 | Oct 13, 2025 00:10 | 15,425 | 228,664,037 | 194,511,000 | 6,015,000 | 2,510,848 | ||
| 8 | Oct 13, 2025 00:01 | 15,571 | 228,398,615 | 197,418,000 | 5,010,000 | 2,506,752 | ||
| 9 | Oct 13, 2025 00:01 | 15,619 | 236,465,716 | 199,049,000 | 4,000,000 | 2,502,656 | ||
| 10 | Oct 13, 2025 00:10 | 15,727 | 231,146,082 | 200,437,000 | 4,008,000 | 2,449,408 | ||
| 11 | Oct 13, 2025 00:01 | 16,020 | 236,614,761 | 206,260,000 | 2,002,000 | 2,392,064 | ||
| 12 | Oct 13, 2025 00:11 | 16,142 | 241,185,406 | 205,852,000 | 3,997,000 | 2,387,968 | ||
| 13 | Oct 13, 2025 00:01 | 16,142 | 237,180,820 | 203,849,000 | 5,995,000 | 2,523,136 | ||
| 14 | Oct 13, 2025 00:10 | 16,312 | 239,104,446 | 207,058,000 | 5,001,000 | 2,473,984 | ||
| 15 | Oct 13, 2025 00:10 | 16,429 | 240,765,274 | 208,563,000 | 5,013,000 | 2,408,448 | ||
| 16 | Oct 13, 2025 00:10 | 16,441 | 245,271,976 | 206,741,000 | 6,991,000 | 2,416,640 | ||
| 17 | Oct 13, 2025 00:01 | 16,526 | 243,115,640 | 209,842,000 | 4,996,000 | 2,387,968 | ||
| 18 | Oct 13, 2025 00:01 | 16,828 | 246,645,340 | 214,765,000 | 3,995,000 | 2,404,352 | ||
| 19 | Oct 13, 2025 00:11 | 17,014 | 247,675,953 | 217,178,000 | 4,003,000 | 2,412,544 | ||
| 20 | Oct 13, 2025 00:01 | 17,015 | 243,700,822 | 217,196,000 | 4,003,000 | 2,289,664 | ||
| 21 | Oct 13, 2025 00:10 | 17,387 | 254,989,313 | 222,036,000 | 4,000,000 | 2,457,600 | ||
| 22 | Oct 13, 2025 00:01 | 17,565 | 257,039,948 | 226,345,000 | 2,003,000 | 2,416,640 | ||
| 23 | Oct 13, 2025 00:10 | 17,801 | 257,191,332 | 227,406,000 | 4,007,000 | 2,428,928 | ||
| 24 | Oct 13, 2025 00:11 | 18,203 | 264,616,935 | 231,651,000 | 4,992,000 | 2,367,488 |