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:50 | Tomislav Tunkovic | 21.76 | Custom | Solution Broken |
| # | Date | Score | Wall Time | CPU User | CPU System | Memory | Error | |
|---|---|---|---|---|---|---|---|---|
| 1 | Sep 9, 2026 09:51 | 0 | 180,031,673 | 157,678,000 | 12,096,000 | 11,153,408 | line 11: expected liquidate 6 5019 14233167 got liquidate 6 38001 14266149 | |
| 2 | Sep 9, 2026 09:51 | 0 | 177,199,441 | 155,249,000 | 11,770,000 | 10,891,264 | line 36: expected liquidate 25 8778 1381072 got liquidate 25 -22154 1350140 | |
| 3 | Sep 9, 2026 09:51 | 0 | 169,630,993 | 146,875,000 | 12,480,000 | 13,209,600 | line 16: expected liquidate 3 28985 3615722 got liquidate 5 -74769 16751575 | |
| 4 | Dec 27, 2025 18:58 | 4,332 | 89,172,064 | 54,311,000 | 2,011,000 | 2,387,968 | ||
| 5 | Dec 27, 2025 18:57 | 4,484 | 90,569,542 | 55,272,000 | 3,014,000 | 2,412,544 | ||
| 6 | Dec 27, 2025 18:57 | 4,694 | 87,724,870 | 58,026,000 | 3,001,000 | 2,420,736 | ||
| 7 | Dec 27, 2025 18:57 | 4,720 | 87,581,561 | 59,346,000 | 2,011,000 | 2,404,352 | ||
| 8 | Dec 27, 2025 18:58 | 4,780 | 89,152,435 | 57,134,000 | 5,011,000 | 2,486,272 | ||
| 9 | Dec 27, 2025 18:57 | 4,797 | 89,774,089 | 58,341,000 | 4,023,000 | 2,465,792 | ||
| 10 | Dec 27, 2025 18:58 | 4,914 | 90,136,989 | 60,891,000 | 2,994,000 | 2,363,392 | ||
| 11 | Dec 27, 2025 18:57 | 4,936 | 89,592,002 | 60,161,000 | 4,010,000 | 2,490,368 | ||
| 12 | Dec 27, 2025 18:58 | 5,036 | 86,125,426 | 62,444,000 | 3,021,000 | 2,457,600 | ||
| 13 | Dec 27, 2025 18:57 | 5,053 | 92,725,911 | 61,644,000 | 4,042,000 | 2,273,280 | ||
| 14 | Dec 27, 2025 18:57 | 5,106 | 93,909,843 | 60,342,000 | 6,034,000 | 2,322,432 | ||
| 15 | Dec 27, 2025 18:58 | 5,118 | 88,020,156 | 62,502,000 | 4,032,000 | 2,322,432 | ||
| 16 | Dec 27, 2025 18:58 | 5,142 | 94,937,290 | 61,854,000 | 4,988,000 | 2,379,776 | ||
| 17 | Dec 27, 2025 18:58 | 5,234 | 94,361,153 | 65,042,000 | 3,001,000 | 2,449,408 | ||
| 18 | Dec 27, 2025 18:58 | 5,297 | 93,252,840 | 66,863,000 | 1,995,000 | 2,408,448 | ||
| 19 | Dec 27, 2025 18:57 | 5,392 | 101,391,796 | 67,094,000 | 3,004,000 | 2,326,528 | ||
| 20 | Dec 27, 2025 18:57 | 5,416 | 94,335,089 | 66,388,000 | 4,023,000 | 2,519,040 | ||
| 21 | Dec 27, 2025 18:57 | 5,447 | 97,063,121 | 67,815,000 | 2,991,000 | 2,482,176 | ||
| 22 | Dec 27, 2025 18:58 | 5,451 | 98,586,501 | 67,864,000 | 2,994,000 | 2,494,464 | ||
| 23 | Dec 27, 2025 18:58 | 5,570 | 96,245,071 | 70,400,000 | 2,011,000 | 2,498,560 | ||
| 24 | Dec 27, 2025 18:58 | 5,604 | 98,691,641 | 68,865,000 | 3,992,000 | 2,400,256 | ||
| 25 | Dec 27, 2025 18:57 | 5,800 | 104,218,632 | 72,384,000 | 3,016,000 | 2,347,008 | ||
| 26 | Dec 27, 2025 18:57 | 6,066 | 110,001,176 | 75,862,000 | 2,994,000 | 2,404,352 | ||
| 27 | Dec 27, 2025 18:58 | 6,848 | 119,705,017 | 86,020,000 | 3,000,000 | 2,359,296 |