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:45 | Andrew Epstein | 14.37 | Custom | Solution Broken |
| # | Date | Score | Wall Time | CPU User | CPU System | Memory | Error | |
|---|---|---|---|---|---|---|---|---|
| 1 | Sep 11, 2026 17:56 | 0 | 880,452,662 | 857,352,000 | 12,776,000 | 6,311,936 | line 3: expected liquidate 5 20047 9900000 got liquidate 4 0 10000000000 | |
| 2 | Sep 11, 2026 17:56 | 0 | 876,785,233 | 853,817,000 | 12,556,000 | 6,311,936 | line 3: expected liquidate 5 20047 9900000 got liquidate 4 0 10000000000 | |
| 3 | Sep 11, 2026 17:56 | 0 | 877,700,060 | 854,368,000 | 13,002,000 | 6,311,936 | line 3: expected liquidate 5 20047 9900000 got liquidate 4 0 10000000000 | |
| 4 | Oct 12, 2025 22:58 | 23,256 | 326,817,231 | 298,321,000 | 4,004,000 | 2,490,368 | ||
| 5 | Oct 12, 2025 23:08 | 23,931 | 335,770,529 | 306,107,000 | 5,001,000 | 2,281,472 | ||
| 6 | Oct 12, 2025 22:58 | 25,920 | 362,131,548 | 333,956,000 | 2,999,000 | 2,371,584 | ||
| 7 | Oct 12, 2025 22:58 | 26,540 | 372,824,434 | 341,020,000 | 4,000,000 | 2,433,024 | ||
| 8 | Oct 12, 2025 23:08 | 26,628 | 373,180,426 | 344,166,000 | 2,000,000 | 2,310,144 | ||
| 9 | Oct 12, 2025 23:02 | 26,708 | 371,820,706 | 340,196,000 | 7,004,000 | 2,478,080 | ||
| 10 | Oct 12, 2025 23:08 | 26,945 | 374,826,115 | 347,277,000 | 3,002,000 | 2,301,952 | ||
| 11 | Oct 12, 2025 22:58 | 27,003 | 374,760,995 | 348,036,000 | 3,000,000 | 2,404,352 | ||
| 12 | Oct 12, 2025 23:08 | 27,095 | 384,910,593 | 348,230,000 | 4,002,000 | 2,469,888 | ||
| 13 | Oct 12, 2025 23:02 | 27,105 | 378,061,799 | 346,374,000 | 5,989,000 | 2,486,272 | ||
| 14 | Oct 12, 2025 22:58 | 27,114 | 379,978,850 | 346,471,000 | 6,008,000 | 2,277,376 | ||
| 15 | Oct 12, 2025 23:02 | 27,201 | 378,692,743 | 347,626,000 | 5,993,000 | 2,383,872 | ||
| 16 | Oct 12, 2025 23:08 | 27,272 | 382,874,426 | 351,541,000 | 2,996,000 | 2,433,024 | ||
| 17 | Oct 12, 2025 23:08 | 27,599 | 388,936,744 | 353,788,000 | 4,997,000 | 2,367,488 | ||
| 18 | Oct 12, 2025 22:58 | 28,247 | 392,942,445 | 363,215,000 | 4,002,000 | 2,498,560 | ||
| 19 | Oct 12, 2025 23:08 | 28,734 | 404,857,891 | 369,553,000 | 3,995,000 | 2,326,528 | ||
| 20 | Oct 12, 2025 22:58 | 28,877 | 404,744,901 | 372,395,000 | 3,003,000 | 2,445,312 | ||
| 21 | Oct 12, 2025 23:08 | 29,078 | 402,308,716 | 375,008,000 | 3,000,000 | 2,482,176 | ||
| 22 | Oct 12, 2025 23:08 | 29,194 | 406,860,169 | 373,536,000 | 5,992,000 | 2,330,624 | ||
| 23 | Oct 12, 2025 22:58 | 30,783 | 424,940,998 | 397,179,000 | 3,001,000 | 2,490,368 | ||
| 24 | Oct 12, 2025 22:58 | 31,407 | 443,563,745 | 406,291,000 | 2,001,000 | 2,326,528 |