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 | |
|---|---|---|---|---|---|
| Mar 12, 2026 16:33 | RUSTrust-1.94.0 | Success | 84,115 | ||
| Mar 12, 2026 16:30 | RUSTrust-1.94.0 | Success | 82,269+4.96 RP | ||
| Mar 12, 2026 16:24 | RUSTrust-1.94.0 | Success | 85,769+23.64 RP | ||
| Mar 12, 2026 16:16 | RUSTrust-1.94.0 | Success | 107,585+15.48 RP | ||
| Mar 12, 2026 16:12 | RUSTrust-1.94.0 | Success | 137,511 | ||
| Mar 12, 2026 16:11 | RUSTrust-1.94.0 | Success | 142,901 | ||
| Mar 12, 2026 16:09 | RUSTrust-1.94.0 | Success | 132,745 | ||
| Mar 12, 2026 16:01 | RUSTrust-1.94.0 | Success | 129,077+18.70 RP | ||
| Mar 12, 2026 05:26 | CPPclang++18.1.3 | Success | 6,531+121.12 RP | ||
| Mar 12, 2026 04:55 | RUSTrust-1.94.0 | Success | 8,192 | ||
| Mar 12, 2026 04:39 | CPPclang++18.1.3 | Success | 7,092+71.71 RP | ||
| Mar 12, 2026 04:25 | RUSTrust-1.94.0 | Success | 7,472+113.59 RP | ||
| Mar 12, 2026 04:00 | RUSTrust-1.94.0 | Success | 8,484 | ||
| Mar 12, 2026 03:51 | RUSTrust-1.94.0 | Error | |||
| Mar 12, 2026 03:40 | CPPclang++18.1.3 | Success | 8,165+205.79 RP | ||
| Mar 12, 2026 02:53 | CPPclang++18.1.3 | Success | 10,897 | ||
| Mar 12, 2026 02:44 | RUSTrust-1.94.0 | Success | 11,864 | ||
| Mar 12, 2026 02:39 | RUSTrust-1.94.0 | Success | 10,449 | ||
| Mar 11, 2026 13:18 | RUSTrust-1.94.0 | Success | 170,146+0.12 RP | ||
| Mar 11, 2026 09:33 | RUSTrust-1.90.0 | Success | 170,504+6.24 RP | ||
| Mar 10, 2026 15:02 | CPPg++13.3.0 | Success | 112,449 | ||
| Mar 10, 2026 04:58 | CPPclang++18.1.3 | Success | 10,973 | ||
| Mar 3, 2026 13:26 | RUSTrust-1.93.1 | Success | 208,689+47.92 RP | ||
| Feb 21, 2026 18:05 | CPPclang++18.1.3 | Success | 10,836 | ||
| Feb 21, 2026 18:00 | CPPclang++18.1.3 | Success | 9,814+28.56 RP | ||
| Feb 21, 2026 17:42 | CPPclang++18.1.3 | Success | 10,097+0.29 RP | ||
| Feb 21, 2026 17:34 | CPPclang++18.1.3 | Success | 10,100+54.30 RP | ||
| Feb 21, 2026 17:01 | CPPclang++18.1.3 | Success | 11,121 | ||
| Feb 21, 2026 16:58 | CPPclang++18.1.3 | Success | 10,944 | ||
| Feb 21, 2026 16:44 | CPPclang++18.1.3 | Success | 12,107 | ||
| Feb 21, 2026 16:40 | CPPclang++18.1.3 | Success | 11,572 | ||
| Feb 21, 2026 16:39 | CPPclang++18.1.3 | Success | 11,676 | ||
| Feb 21, 2026 16:31 | CPPclang++18.1.3 | Success | 22,398 | ||
| Feb 21, 2026 16:26 | CPPclang++18.1.3 | Success | 12,102 | ||
| Feb 21, 2026 16:21 | CPPclang++18.1.3 | Success | 11,579 | ||
| Feb 21, 2026 16:18 | CPPclang++18.1.3 | Success | 12,044 | ||
| Feb 21, 2026 16:13 | CPPg++13.3.0 | Success | 14,259 | ||
| Feb 21, 2026 16:11 | CPPclang++18.1.3 | Success | 12,843 | ||
| Feb 21, 2026 16:06 | CPPclang++18.1.3 | Success | 49,217 | ||
| Feb 21, 2026 15:58 | CPPclang++18.1.3 | Success | 12,298 | ||
| Feb 21, 2026 15:47 | CPPclang++18.1.3 | Success | 10,871 | ||
| Feb 21, 2026 15:38 | CPPclang++18.1.3 | Success | 11,778 | ||
| Feb 21, 2026 15:38 | CPPclang++18.1.3 | Success | 10,960 | ||
| Feb 21, 2026 15:34 | CPPg++13.3.0 | Success | 13,752 | ||
| Feb 21, 2026 15:30 | CPPclang++18.1.3 | Success | 12,099 | ||
| Feb 21, 2026 15:19 | CPPclang++18.1.3 | Success | 11,476 | ||
| Feb 21, 2026 15:16 | CPPg++13.3.0 | Success | 15,046 | ||
| Feb 21, 2026 15:12 | CPPclang++18.1.3 | Error | |||
| Feb 21, 2026 15:01 | CPPclang++18.1.3 | Success | 10,808 | ||
| Feb 21, 2026 15:00 | CPPclang++18.1.3 | Success | 11,296 | ||
| Feb 21, 2026 14:55 | CPPg++13.3.0 | Success | 12,698 | ||
| Feb 21, 2026 14:44 | CPPg++13.3.0 | Success | 13,946 | ||
| Feb 21, 2026 07:18 | CPPclang++18.1.3 | Success | 12,111 | ||
| Feb 21, 2026 07:06 | CPPclang++18.1.3 | Success | 11,193 | ||
| Feb 21, 2026 06:41 | CPPclang++18.1.3 | Success | 11,982 | ||
| Feb 21, 2026 05:55 | CPPclang++18.1.3 | Success | 11,648 | ||
| Feb 21, 2026 05:37 | CPPclang++18.1.3 | Success | 11,945 | ||
| Feb 21, 2026 05:31 | CPPclang++18.1.3 | Success | 12,021 | ||
| Feb 21, 2026 05:22 | CPPclang++18.1.3 | Success | 11,324 | ||
| Feb 21, 2026 05:15 | CPPclang++18.1.3 | Success | 11,523 | ||
| Feb 21, 2026 05:10 | CPPclang++18.1.3 | Success | 10,815 | ||
| Feb 21, 2026 04:54 | CPPclang++18.1.3 | Success | 11,551 | ||
| Feb 21, 2026 04:28 | CPPclang++18.1.3 | Success | 10,959 | ||
| Feb 21, 2026 04:22 | CPPclang++18.1.3 | Success | 10,933 | ||
| Feb 21, 2026 04:07 | CPPclang++18.1.3 | Success | 12,333 | ||
| Feb 21, 2026 03:55 | CPPclang++18.1.3 | Success | 11,255 | ||
| Feb 21, 2026 03:48 | CPPclang++18.1.3 | Success | 11,364 | ||
| Feb 21, 2026 03:43 | CPPclang++18.1.3 | Success | 11,500 | ||
| Feb 21, 2026 03:34 | CPPg++13.3.0 | Success | 11,728 | ||
| Feb 21, 2026 03:23 | CPPclang++18.1.3 | Success | 10,686+63.36 RP | ||
| Feb 21, 2026 03:14 | CPPclang++18.1.3 | Success | 11,484 | ||
| Feb 21, 2026 03:09 | CPPclang++18.1.3 | Success | 11,462+19.64 RP | ||
| Feb 21, 2026 03:04 | CPPclang++18.1.3 | Success | 11,726+18.50 RP | ||
| Feb 21, 2026 02:52 | CPPclang++18.1.3 | Success | 35,685 | ||
| Feb 21, 2026 02:47 | CPPclang++18.1.3 | Success | 37,584 | ||
| Feb 21, 2026 02:43 | CPPclang++18.1.3 | Success | 34,570 | ||
| Feb 21, 2026 02:38 | CPPclang++18.1.3 | Success | 34,478 | ||
| Feb 21, 2026 02:35 | CPPclang++18.1.3 | Success | 32,906 | ||
| Feb 21, 2026 02:31 | CPPclang++18.1.3 | Success | 40,349 | ||
| Feb 21, 2026 02:24 | CPPclang++18.1.3 | Success | 36,770 | ||
| Feb 21, 2026 02:22 | CPPclang++18.1.3 | Success | 36,710 | ||
| Feb 21, 2026 02:15 | CPPclang++18.1.3 | Success | 37,747 | ||
| Feb 21, 2026 02:05 | CPPclang++18.1.3 | Success | 11,986+20.57 RP | ||
| Feb 21, 2026 02:02 | CPPclang++18.1.3 | Success | 12,289+6.05 RP | ||
| Feb 19, 2026 05:29 | CPPg++13.3.0 | Success | 3,488 | ||
| Feb 19, 2026 05:23 | CPPg++13.3.0 | Success | 3,478 | ||
| Feb 19, 2026 05:17 | RUSTrust-1.93.1 | Success | 3,638 | ||
| Feb 19, 2026 05:06 | CPPg++13.3.0 | Success | 3,505 | ||
| Feb 19, 2026 04:34 | RUSTrust-1.93.1 | Success | 3,562 | ||
| Feb 19, 2026 04:33 | CPPg++13.3.0 | Success | 3,803 | ||
| Feb 19, 2026 04:30 | RUSTrust-1.93.1 | Success | 3,436 | ||
| Feb 19, 2026 04:29 | CPPg++13.3.0 | Success | 3,838 | ||
| Feb 19, 2026 03:06 | RUSTrust-1.93.1 | Success | 4,003 | ||
| Feb 19, 2026 03:05 | CPPg++13.3.0 | Success | 3,814 | ||
| Feb 19, 2026 03:02 | RUSTrust-1.93.1 | Success | 3,606 | ||
| Feb 19, 2026 03:01 | CPPg++13.3.0 | Success | 3,421 | ||
| Feb 19, 2026 01:19 | CPPg++13.3.0 | Success | 3,696 | ||
| Feb 19, 2026 01:18 | RUSTrust-1.93.1 | Success | 4,028 | ||
| Feb 19, 2026 01:17 | RUSTrust-1.93.1 | Success | 4,244 | ||
| Feb 19, 2026 01:02 | RUSTrust-1.93.1 | Success | 4,396 |