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 9, 2026 09:49 | Tomislav Tunkovic | 36.08 | Custom | Solution Broken |
| # | Date | Score | Wall Time | CPU User | CPU System | Memory | Error | |
|---|---|---|---|---|---|---|---|---|
| 1 | Sep 9, 2026 09:49 | 0 | 166,818,535 | 144,863,000 | 11,994,000 | 13,365,248 | line 35: expected liquidate 3 36504 14204268 got liquidate 3 87750 14255514 | |
| 2 | Sep 9, 2026 09:49 | 0 | 156,594,487 | 134,991,000 | 11,538,000 | 13,099,008 | line 8: expected liquidate 0 11632 5227130 got liquidate 0 -146854 5068644 | |
| 3 | Sep 9, 2026 09:49 | 0 | 158,097,709 | 135,922,000 | 10,861,000 | 13,053,952 | line 7: expected liquidate 6 1560 1864980 got liquidate 6 -52260 1918800 | |
| 4 | Dec 29, 2025 06:07 | 3,027 | 70,893,015 | 36,322,000 | 3,026,000 | 2,420,736 | ||
| 5 | Dec 29, 2025 06:09 | 3,203 | 72,624,138 | 39,612,000 | 2,031,000 | 2,437,120 | ||
| 6 | Dec 29, 2025 06:08 | 3,223 | 74,160,619 | 38,901,000 | 2,992,000 | 2,420,736 | ||
| 7 | Dec 29, 2025 06:08 | 3,336 | 69,308,296 | 38,323,000 | 5,042,000 | 2,392,064 | ||
| 8 | Dec 29, 2025 06:11 | 3,341 | 65,366,648 | 39,399,000 | 4,040,000 | 2,334,720 | ||
| 9 | Dec 29, 2025 06:10 | 3,392 | 74,878,941 | 42,098,000 | 2,004,000 | 2,396,160 | ||
| 10 | Dec 29, 2025 06:07 | 3,461 | 70,668,909 | 41,988,000 | 2,999,000 | 2,473,984 | ||
| 11 | Dec 29, 2025 06:11 | 3,488 | 69,237,112 | 42,323,000 | 3,023,000 | 2,408,448 | ||
| 12 | Dec 29, 2025 06:09 | 3,529 | 76,743,801 | 43,887,000 | 1,994,000 | 2,306,048 | ||
| 13 | Dec 29, 2025 06:12 | 3,579 | 67,762,883 | 44,510,000 | 2,023,000 | 2,461,696 | ||
| 14 | Dec 29, 2025 06:14 | 3,586 | 78,688,428 | 45,611,000 | 1,013,000 | 2,510,848 | ||
| 15 | Dec 29, 2025 06:11 | 3,743 | 81,623,968 | 47,646,000 | 1,013,000 | 2,310,144 | ||
| 16 | Dec 29, 2025 06:14 | 3,783 | 74,554,010 | 47,177,000 | 2,007,000 | 2,457,600 | ||
| 17 | Dec 29, 2025 06:14 | 3,851 | 75,885,601 | 45,058,000 | 5,006,000 | 2,490,368 | ||
| 18 | Dec 29, 2025 06:09 | 3,864 | 83,062,039 | 48,229,000 | 2,009,000 | 2,326,528 | ||
| 19 | Dec 29, 2025 06:07 | 3,871 | 72,979,254 | 47,299,000 | 3,019,000 | 2,400,256 | ||
| 20 | Dec 29, 2025 06:12 | 3,949 | 81,905,323 | 46,301,000 | 5,032,000 | 2,355,200 | ||
| 21 | Dec 29, 2025 06:10 | 4,035 | 79,756,421 | 49,430,000 | 3,026,000 | 2,457,600 | ||
| 22 | Dec 29, 2025 06:12 | 4,186 | 83,370,037 | 52,403,000 | 2,015,000 | 2,318,336 | ||
| 23 | Dec 29, 2025 06:08 | 4,276 | 84,946,498 | 51,548,000 | 4,043,000 | 2,469,888 | ||
| 24 | Dec 29, 2025 06:10 | 4,304 | 85,238,082 | 53,957,000 | 1,998,000 | 2,363,392 |