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 | |
|---|---|---|---|---|---|
| Sep 18, 2026 16:36 | CPPg++14.2.0 | Success | 262,396 | ||
| Sep 18, 2026 16:31 | CPPg++14.2.0 | Success | 250,547 | ||
| Sep 18, 2026 16:24 | CPPg++14.2.0 | Success | 10,474 | ||
| Sep 17, 2026 19:43 | ZIG0.15.1 | Success | 2,194+1'230.10 RP | ||
| Sep 17, 2026 19:35 | CPPg++14.2.0 | Success | 2,166 | ||
| Sep 17, 2026 19:25 | CPPg++14.2.0 | Success | 2,184 | ||
| Sep 17, 2026 19:25 | ZIG0.15.1 | Success | 3,046 | ||
| Sep 17, 2026 19:25 | CSHARP9.0.15 | Success | 2,253 | ||
| Sep 17, 2026 19:24 | RUSTrust-1.95.0 | Success | 2,114+231.94 RP | ||
| Sep 17, 2026 19:16 | CSHARP9.0.15 | Success | 2,162+1'134.95 RP | ||
| Sep 17, 2026 19:15 | RUSTrust-1.95.0 | Success | 2,223+133.52 RP | ||
| Sep 17, 2026 19:11 | CSHARP9.0.15 | Success | 3,721 | ||
| Sep 17, 2026 19:09 | RUSTrust-1.95.0 | Success | 3,042 | ||
| Sep 17, 2026 19:09 | ZIG0.15.1 | Success | 3,005+1'485.15 RP | ||
| Sep 17, 2026 19:09 | GOgo1.26.2 | Success | 2,269+187.82 RP | ||
| Sep 17, 2026 18:52 | ZIG0.15.1 | Error | |||
| Sep 17, 2026 18:51 | CSHARP9.0.15 | Success | 3,778 | ||
| Sep 17, 2026 18:50 | GOgo1.26.2 | Success | 4,262 | ||
| Sep 17, 2026 18:46 | RUSTrust-1.95.0 | Success | 3,075 | ||
| Sep 17, 2026 18:35 | CPPg++14.2.0 | Success | 2,119 | ||
| Sep 15, 2026 22:10 | CPPclang++18.1.3 | Error | |||
| Sep 15, 2026 21:52 | CPPclang++18.1.3 | Error | |||
| Sep 15, 2026 21:24 | CPPclang++18.1.3 | Error | |||
| Sep 15, 2026 21:01 | CPPclang++18.1.3 | Error | |||
| Sep 15, 2026 20:16 | CPPclang++18.1.3 | Error | |||
| Sep 15, 2026 19:33 | CPPclang++18.1.3 | Error | |||
| Sep 15, 2026 19:21 | CPPclang++18.1.3 | Error | |||
| Sep 15, 2026 19:16 | CPPclang++18.1.3 | Error | |||
| Sep 15, 2026 18:38 | CPPclang++18.1.3 | Error | |||
| Sep 15, 2026 18:19 | CPPclang++18.1.3 | Error | |||
| Sep 15, 2026 18:01 | CPPclang++18.1.3 | Error | |||
| Sep 15, 2026 17:55 | CPPclang++18.1.3 | Error | |||
| Sep 15, 2026 17:33 | CPPclang++18.1.3 | Error | |||
| Sep 15, 2026 17:31 | CPPclang++18.1.3 | Error | +109.27 RP | ||
| Sep 15, 2026 17:21 | CPPclang++18.1.3 | Error | |||
| Sep 15, 2026 17:03 | CPPclang++18.1.3 | Error | |||
| Sep 15, 2026 16:20 | CPPclang++18.1.3 | Error | |||
| Sep 15, 2026 16:05 | CPPclang++18.1.3 | Error | |||
| Sep 15, 2026 15:55 | CPPclang++18.1.3 | Error | |||
| Sep 15, 2026 15:24 | CPPclang++18.1.3 | Error | |||
| Sep 15, 2026 02:04 | CPPclang++18.1.3 | Error | +254.46 RP | ||
| Sep 14, 2026 11:23 | CPPg++14.2.0 | Error | |||
| Sep 14, 2026 10:58 | CPPg++14.2.0 | Error | |||
| Sep 14, 2026 09:34 | CPPg++14.2.0 | Error | |||
| Sep 13, 2026 16:32 | CPPg++14.2.0 | Error | |||
| Sep 13, 2026 16:22 | CPPg++14.2.0 | Error | |||
| Sep 13, 2026 16:14 | CPPg++14.2.0 | Error | |||
| Sep 13, 2026 15:37 | CPPg++14.2.0 | Error | |||
| Sep 11, 2026 16:59 | CPPg++14.2.0 | Error | |||
| Sep 11, 2026 16:27 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 18:06 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 18:00 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 17:05 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 16:06 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 15:59 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 15:50 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 15:13 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 15:03 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 14:44 | RUSTrust-1.98.1 | Success | 275,176+5.00 RP | ||
| Sep 10, 2026 14:39 | RUSTrust-1.98.1 | Error | |||
| Sep 10, 2026 14:36 | CPPclang++20.1.2 | Error | |||
| Sep 10, 2026 13:56 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 13:36 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 13:32 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 10:54 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 10:49 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 10:45 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 10:35 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 09:09 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 09:02 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 08:53 | CPPg++14.2.0 | Error | |||
| Sep 10, 2026 08:43 | CPPg++14.2.0 | Error | +5.00 RP | ||
| Sep 9, 2026 17:14 | CSHARP10.0.7 | Error | |||
| Sep 9, 2026 15:59 | CPPg++14.2.0 | Error | +300.41 RP | ||
| Sep 9, 2026 14:17 | CPPg++14.2.0 | Error | |||
| Sep 9, 2026 14:12 | CPPg++14.2.0 | Error | |||
| Sep 9, 2026 14:07 | CPPg++14.2.0 | Error | |||
| Sep 9, 2026 13:43 | CPPg++14.2.0 | Error | +101.74 RP | ||
| Sep 9, 2026 13:33 | CPPg++14.2.0 | Error | |||
| Sep 8, 2026 23:57 | CPPg++14.2.0 | Error | |||
| Sep 8, 2026 23:20 | CPPg++14.2.0 | Error | |||
| Sep 8, 2026 23:16 | CPPg++14.2.0 | Error | |||
| Sep 8, 2026 22:45 | CPPg++14.2.0 | Error | |||
| Sep 8, 2026 21:57 | CPPg++14.2.0 | Error | |||
| Sep 8, 2026 21:24 | CPPg++14.2.0 | Error | |||
| Sep 8, 2026 21:11 | CPPg++14.2.0 | Error | +14.39 RP | ||
| Sep 8, 2026 20:28 | CPPg++14.2.0 | Error | |||
| Sep 8, 2026 20:12 | CPPg++14.2.0 | Error | |||
| Sep 8, 2026 19:50 | CPPg++14.2.0 | Error | +294.50 RP | ||
| Sep 8, 2026 19:03 | CPPg++14.2.0 | Error | +135.21 RP | ||
| Sep 8, 2026 17:12 | CPPg++14.2.0 | Error | |||
| Sep 8, 2026 15:44 | RUSTrust-1.95.0 | Error | |||
| Sep 8, 2026 15:41 | RUSTrust-1.95.0 | Error | |||
| Sep 8, 2026 15:38 | RUSTrust-1.95.0 | Error | |||
| Sep 8, 2026 15:03 | ZIG0.16.0 | Error | |||
| Sep 8, 2026 14:55 | ZIG0.16.0 | Error | +53.21 RP | ||
| Sep 8, 2026 14:45 | ZIG0.16.0 | Error | |||
| Sep 8, 2026 14:42 | ZIG0.16.0 | Error | |||
| Sep 8, 2026 14:38 | ZIG0.16.0 | Error | +143.84 RP | ||
| Sep 8, 2026 13:31 | GOgo1.26.2 | Error |