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
| Date | Author | Language | Status | Score | |
|---|---|---|---|---|---|
| Feb 19, 2026 01:01 | CPPg++13.3.0 | Success | 3,687 | ||
| Feb 19, 2026 01:00 | RUSTrust-1.93.1 | Success | 3,839 | ||
| Feb 19, 2026 00:34 | RUSTrust-1.93.1 | Success | 4,315 | ||
| Feb 19, 2026 00:30 | RUSTrust-1.93.1 | Success | 4,168 | ||
| Feb 19, 2026 00:17 | RUSTrust-1.93.1 | Success | 4,017 | ||
| Feb 19, 2026 00:16 | CPPg++13.3.0 | Success | 3,545 | ||
| Feb 18, 2026 23:44 | RUSTrust-1.92.0 | Success | 4,340 | ||
| Feb 18, 2026 07:17 | CPPclang++18.1.3 | Success | 12,381+229.29 RP | ||
| Feb 18, 2026 06:57 | CPPclang++18.1.3 | Success | 18,424 | ||
| Feb 18, 2026 06:49 | CPPclang++18.1.3 | Success | 19,114 | ||
| Feb 18, 2026 06:38 | CPPclang++18.1.3 | Success | 21,405 | ||
| Feb 18, 2026 06:17 | CPPg++13.3.0 | Success | 18,383 | ||
| Feb 18, 2026 06:07 | CPPclang++18.1.3 | Success | 19,324 | ||
| Feb 18, 2026 05:56 | CPPclang++18.1.3 | Success | 20,339 | ||
| Feb 18, 2026 05:48 | CPPclang++18.1.3 | Success | 20,441 | ||
| Feb 18, 2026 05:27 | CPPclang++18.1.3 | Success | 17,655 | ||
| Feb 18, 2026 05:21 | CPPclang++18.1.3 | Success | 18,675 | ||
| Feb 18, 2026 05:15 | CPPclang++18.1.3 | Success | 18,829 | ||
| Feb 18, 2026 05:07 | CPPclang++18.1.3 | Success | 22,938 | ||
| Feb 18, 2026 04:58 | CPPclang++18.1.3 | Success | 18,412 | ||
| Feb 18, 2026 04:53 | CPPclang++18.1.3 | Success | 22,044 | ||
| Feb 18, 2026 04:45 | CPPclang++18.1.3 | Success | 19,981 | ||
| Feb 18, 2026 04:39 | CPPclang++18.1.3 | Success | 17,289+38.71 RP | ||
| Feb 18, 2026 04:26 | CPPclang++18.1.3 | Success | 19,885 | ||
| Feb 18, 2026 04:17 | CPPclang++18.1.3 | Success | 18,529+0.12 RP | ||
| Feb 18, 2026 04:11 | CPPclang++18.1.3 | Success | 20,498 | ||
| Feb 18, 2026 04:03 | CPPclang++18.1.3 | Success | 18,533+1.10 RP | ||
| Feb 18, 2026 03:56 | CPPclang++18.1.3 | Success | 21,040 | ||
| Feb 18, 2026 03:47 | CPPclang++18.1.3 | Success | 19,775 | ||
| Feb 18, 2026 03:35 | CPPclang++18.1.3 | Success | 20,198 | ||
| Feb 18, 2026 03:22 | CPPclang++18.1.3 | Success | 18,571+0.06 RP | ||
| Feb 18, 2026 03:15 | CPPg++13.3.0 | Success | 20,511 | ||
| Feb 18, 2026 02:52 | CPPclang++18.1.3 | Success | 18,861 | ||
| Feb 18, 2026 02:42 | CPPclang++18.1.3 | Success | 18,573+99.59 RP | ||
| Feb 18, 2026 02:32 | CPPclang++18.1.3 | Success | 22,788+33.71 RP | ||
| Feb 18, 2026 02:22 | CPPclang++18.1.3 | Success | 24,684+74.14 RP | ||
| Feb 18, 2026 02:16 | CPPclang++18.1.3 | Success | 30,213+27.36 RP | ||
| Feb 18, 2026 02:10 | CPPclang++18.1.3 | Success | 37,389 | ||
| Feb 18, 2026 01:54 | CPPclang++18.1.3 | Success | 40,049 | ||
| Feb 18, 2026 01:48 | CPPclang++18.1.3 | Success | 38,277 | ||
| Feb 18, 2026 01:40 | CPPclang++18.1.3 | Success | 32,936+38.33 RP | ||
| Feb 18, 2026 01:27 | CPPclang++18.1.3 | Success | 37,695+76.22 RP | ||
| Feb 18, 2026 01:12 | CPPclang++18.1.3 | Success | 52,891+11.67 RP | ||
| Feb 18, 2026 01:08 | CPPclang++18.1.3 | Success | 56,369+2.68 RP | ||
| Feb 18, 2026 01:04 | CPPg++13.3.0 | Success | 57,232+28.47 RP | ||
| Feb 18, 2026 01:00 | CPPg++13.3.0 | Success | 68,371+10.29 RP | ||
| Feb 17, 2026 22:34 | CPPclang++18.1.3 | Success | 73,546+10.00 RP | ||
| Feb 17, 2026 22:26 | CPPclang++18.1.3 | Success | 79,382+80.93 RP | ||
| Feb 17, 2026 22:19 | CPPg++13.3.0 | Success | 222,024+2.12 RP | ||
| Feb 17, 2026 22:10 | CPPg++13.3.0 | Success | 233,008+42.92 RP | ||
| Feb 17, 2026 22:05 | CPPg++13.3.0 | Error | |||
| Feb 17, 2026 21:55 | CPPg++13.3.0 | Error | |||
| Feb 7, 2026 22:53 | CPPg++13.3.0 | Error | |||
| Feb 7, 2026 22:53 | CPPg++13.3.0 | Success | 71,639 | ||
| Feb 7, 2026 22:53 | CPPg++13.3.0 | Success | 104,352 | ||
| Feb 7, 2026 22:53 | CPPg++13.3.0 | Success | 65,701 | ||
| Feb 7, 2026 22:53 | CPPg++13.3.0 | Success | 81,375 | ||
| Feb 7, 2026 21:32 | CPPg++13.3.0 | Success | 67,617 | ||
| Feb 7, 2026 21:32 | CPPg++13.3.0 | Success | 63,251 | ||
| Feb 7, 2026 21:31 | CPPg++13.3.0 | Error | |||
| Feb 7, 2026 21:31 | CPPg++13.3.0 | Success | 65,489 | ||
| Feb 7, 2026 21:28 | CPPg++13.3.0 | Success | 63,236 | ||
| Feb 7, 2026 20:35 | CPPg++13.3.0 | Error | |||
| Feb 7, 2026 19:27 | CPPg++13.3.0 | Success | 39,187+198.49 RP | ||
| Feb 7, 2026 17:48 | CPPg++13.3.0 | Success | 176,389+23.75 RP | ||
| Feb 7, 2026 17:34 | CPPg++13.3.0 | Success | 303,538+32.94 RP | ||
| Jan 25, 2026 23:15 | CPPg++13.3.0 | Error | |||
| Jan 25, 2026 23:02 | CPPg++13.3.0 | Error | |||
| Jan 25, 2026 22:54 | CPPg++13.3.0 | Error | |||
| Jan 25, 2026 22:47 | CPPg++13.3.0 | Error | |||
| Jan 25, 2026 22:42 | CPPg++13.3.0 | Error | |||
| Jan 18, 2026 04:39 | CPPg++13.3.0 | Error | |||
| Jan 7, 2026 05:30 | GOgo1.25.5 | Success | 3,774+1'465.72 RP | ||
| Jan 1, 2026 01:14 | RUSTrust-1.92.0 | Success | 4,279 | ||
| Dec 31, 2025 16:25 | CPPg++13.3.0 | Error | |||
| Dec 31, 2025 15:26 | CPPg++13.3.0 | Success | 49,994 | ||
| Dec 31, 2025 15:22 | CPPg++13.3.0 | Success | 47,419+2.82 RP | ||
| Dec 31, 2025 15:22 | CPPg++13.3.0 | Error | |||
| Dec 31, 2025 15:03 | RUSTrust-1.92.0 | Error | |||
| Dec 31, 2025 14:55 | RUSTrust-1.92.0 | Success | 4,048 | ||
| Dec 31, 2025 14:47 | RUSTrust-1.92.0 | Success | 31,539 | ||
| Dec 31, 2025 14:17 | CPPg++13.3.0 | Success | 75,535 | ||
| Dec 31, 2025 14:13 | CPPg++13.3.0 | Success | 67,438 | ||
| Dec 31, 2025 14:11 | CPPg++13.3.0 | Error | |||
| Dec 31, 2025 13:42 | CPPg++13.3.0 | Success | 94,166 | ||
| Dec 31, 2025 13:35 | CPPg++13.3.0 | Success | 96,360 | ||
| Dec 31, 2025 13:32 | CPPg++13.3.0 | Success | 54,152 | ||
| Dec 31, 2025 13:29 | CPPg++13.3.0 | Success | 297,663 | ||
| Dec 31, 2025 13:09 | CPPg++13.3.0 | Success | 62,194 | ||
| Dec 31, 2025 12:15 | CPPg++13.3.0 | Success | 60,740 | ||
| Dec 31, 2025 12:12 | CPPg++13.3.0 | Success | 48,062+1.88 RP | ||
| Dec 31, 2025 10:38 | CPPg++13.3.0 | Success | 107,632 | ||
| Dec 31, 2025 03:02 | RUSTrust-1.92.0 | Success | 4,377 | ||
| Dec 31, 2025 01:07 | CPPg++13.3.0 | Success | 3,759 | ||
| Dec 31, 2025 00:50 | CPPg++13.3.0 | Success | 4,042 | ||
| Dec 31, 2025 00:37 | CPPg++13.3.0 | Success | 3,575 | ||
| Dec 30, 2025 23:42 | CPPg++13.3.0 | Success | 3,934 | ||
| Dec 30, 2025 22:49 | CPPg++13.3.0 | Success | 3,685 | ||
| Dec 30, 2025 22:38 | RUSTrust-1.92.0 | Success | 4,418 | ||
| Dec 30, 2025 20:42 | CPPg++13.3.0 | Success | 3,477 |