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 | |
|---|---|---|---|---|---|
| May 5, 2026 09:25 | CPPclang++18.1.3 | Error | |||
| May 5, 2026 09:16 | CPPclang++18.1.3 | Error | |||
| May 5, 2026 09:12 | CPPclang++18.1.3 | Error | |||
| May 5, 2026 09:09 | RUSTrust-1.95.0 | Error | |||
| May 5, 2026 09:07 | CPPclang++18.1.3 | Error | |||
| May 5, 2026 09:00 | RUSTrust-1.95.0 | Success | 1,909+43.54 RP | ||
| May 5, 2026 08:50 | ZIG0.16.0 | Error | |||
| May 5, 2026 08:41 | RUSTrust-1.95.0 | Error | |||
| May 5, 2026 08:35 | GOgo1.26.2 | Error | |||
| May 5, 2026 08:27 | CSHARP10.0.7 | Error | |||
| May 5, 2026 08:21 | ZIG0.16.0 | Error | |||
| May 5, 2026 08:17 | RUSTrust-1.95.0 | Error | |||
| May 5, 2026 08:14 | CPPclang++18.1.3 | Success | 5,195 | ||
| May 5, 2026 08:14 | ZIG0.16.0 | Error | |||
| May 5, 2026 05:32 | RUSTrust-1.94.0 | Success | 5,081 | ||
| May 5, 2026 04:28 | GOgo1.26.2 | Success | 6,166 | ||
| May 5, 2026 02:20 | GOgo1.26.2 | Success | 5,969 | ||
| May 5, 2026 02:09 | GOgo1.26.2 | Success | 6,386 | ||
| May 5, 2026 01:59 | ZIG0.14.0 | Success | 5,427 | ||
| May 5, 2026 01:51 | ZIG0.14.0 | Success | 5,485 | ||
| May 5, 2026 01:45 | CPPclang++18.1.3 | Success | 5,151 | ||
| May 4, 2026 22:00 | CPPclang++18.1.3 | Success | 5,236 | ||
| May 4, 2026 13:01 | CPPg++14.2.0 | Success | 124,281 | ||
| May 4, 2026 12:16 | CPPg++14.2.0 | Error | |||
| May 4, 2026 11:57 | CPPclang++18.1.3 | Error | +978.03 RP | ||
| May 4, 2026 11:51 | CPPg++14.2.0 | Success | 389,178 | ||
| May 4, 2026 11:45 | CPPclang++18.1.3 | Error | |||
| May 4, 2026 11:21 | CPPclang++18.1.3 | Error | |||
| May 4, 2026 11:14 | CPPclang++18.1.3 | Error | |||
| May 1, 2026 09:35 | CPPg++14.2.0 | Success | 16,943 | ||
| May 1, 2026 09:34 | CPPclang++20.1.2 | Success | 13,849 | ||
| May 1, 2026 09:32 | CPPg++10.5.0 | Success | 17,429 | ||
| May 1, 2026 05:16 | GOgo1.26.2 | Success | 5,956 | ||
| May 1, 2026 04:45 | CPPg++10.5.0 | Success | 5,564 | ||
| May 1, 2026 00:13 | CPPg++10.5.0 | Success | 5,786 | ||
| Apr 30, 2026 15:12 | RUSTrust-1.95.0 | Success | 1,925+940.92 RP | ||
| Apr 30, 2026 15:05 | RUSTrust-1.95.0 | Error | |||
| Apr 30, 2026 14:48 | RUSTrust-1.95.0 | Error | |||
| Apr 30, 2026 14:06 | RUSTrust-1.95.0 | Error | |||
| Apr 30, 2026 13:59 | RUSTrust-1.95.0 | Error | |||
| Apr 30, 2026 13:52 | RUSTrust-1.95.0 | Error | |||
| Apr 30, 2026 13:38 | RUSTrust-1.95.0 | Error | |||
| Apr 30, 2026 13:11 | GOgo1.26.2 | Success | 1,970+3'973.99 RP | ||
| Apr 30, 2026 12:14 | CPPg++13.3.0 | Success | 35,220+16.08 RP | ||
| Apr 30, 2026 11:57 | CSHARP10.0.7 | Success | 3,120+1'786.49 RP | ||
| Apr 30, 2026 11:40 | ZIG0.16.0 | Success | 2,834+1'998.01 RP | ||
| Apr 30, 2026 11:27 | CPPg++14.2.0 | Success | 3,054+3'032.96 RP | ||
| Apr 30, 2026 10:45 | CPPg++14.2.0 | Success | 112,054 | ||
| Apr 30, 2026 10:30 | CPPg++14.2.0 | Success | 116,948 | ||
| Apr 30, 2026 10:23 | CPPg++14.2.0 | Success | 112,090 | ||
| Apr 30, 2026 10:00 | CPPg++14.2.0 | Success | 112,880 | ||
| Apr 30, 2026 09:39 | CPPg++14.2.0 | Success | 126,704 | ||
| Apr 29, 2026 23:20 | GOgo1.26.2 | Success | 6,148 | ||
| Apr 29, 2026 23:15 | CPPg++13.3.0 | Success | 37,335+98.35 RP | ||
| Apr 29, 2026 12:21 | CPPg++13.3.0 | Success | 5,284 | ||
| Apr 29, 2026 11:35 | CPPclang++18.1.3 | Success | 15,301 | ||
| Apr 29, 2026 07:20 | RUSTrust-1.95.0 | Success | 5,104 | ||
| Apr 29, 2026 07:01 | GOgo1.26.2 | Success | 5,989 | ||
| Apr 28, 2026 23:26 | CPPg++13.3.0 | Success | 61,101 | ||
| Apr 28, 2026 23:26 | CPPg++10.5.0 | Success | 5,661 | ||
| Apr 28, 2026 13:43 | CPPclang++18.1.3 | Success | 100,775 | ||
| Apr 28, 2026 12:46 | CPPclang++20.1.2 | Success | 63,778 | ||
| Apr 28, 2026 12:42 | CPPclang++18.1.3 | Success | 15,371 | ||
| Apr 28, 2026 12:41 | CPPclang++20.1.2 | Success | 14,379 | ||
| Apr 28, 2026 12:34 | CPPg++13.3.0 | Success | 19,329 | ||
| Apr 28, 2026 10:46 | CPPg++14.2.0 | Success | 129,856 | ||
| Apr 28, 2026 10:39 | CPPg++14.2.0 | Success | 128,201 | ||
| Apr 28, 2026 10:10 | CPPg++14.2.0 | Success | 118,942 | ||
| Apr 28, 2026 09:58 | CPPg++14.2.0 | Success | 120,357 | ||
| Apr 28, 2026 09:50 | CPPg++14.2.0 | Success | 41,420+141.72 RP | ||
| Apr 28, 2026 09:19 | CPPg++14.2.0 | Success | 108,087 | ||
| Apr 28, 2026 09:06 | CPPg++14.2.0 | Success | 100,293+33.50 RP | ||
| Apr 28, 2026 08:58 | CPPg++14.2.0 | Success | 389,437 | ||
| Apr 28, 2026 08:41 | CPPg++14.2.0 | Success | 385,529 | ||
| Apr 28, 2026 08:34 | CPPg++14.2.0 | Success | 390,444 | ||
| Apr 28, 2026 08:25 | CPPg++14.2.0 | Success | 400,897 | ||
| Apr 28, 2026 08:17 | CPPg++14.2.0 | Success | 394,675 | ||
| Apr 28, 2026 08:05 | CPPg++14.2.0 | Success | 403,952 | ||
| Apr 28, 2026 07:44 | CPPg++14.2.0 | Success | 371,748 | ||
| Apr 28, 2026 07:24 | CPPg++14.2.0 | Success | 388,866 | ||
| Apr 28, 2026 01:21 | CPPg++14.2.0 | Success | 151,033+41.16 RP | ||
| Apr 28, 2026 01:09 | CPPg++14.2.0 | Success | 399,194+25.05 RP | ||
| Apr 28, 2026 01:02 | CPPg++14.2.0 | Error | |||
| Apr 28, 2026 00:50 | CPPg++14.2.0 | Error | |||
| Apr 28, 2026 00:43 | CPPg++14.2.0 | Error | |||
| Apr 27, 2026 23:10 | CPPg++14.2.0 | Success | 409,504 | ||
| Apr 27, 2026 23:07 | CPPclang++18.1.3 | Success | 175,013 | ||
| Apr 27, 2026 23:03 | CPPclang++20.1.2 | Success | 172,602 | ||
| Apr 27, 2026 23:00 | CPPclang++20.1.2 | Success | 185,803 | ||
| Apr 27, 2026 22:57 | CPPclang++20.1.2 | Success | 189,944 | ||
| Apr 27, 2026 22:53 | CPPclang++20.1.2 | Success | 315,863 | ||
| Apr 27, 2026 22:51 | CPPclang++20.1.2 | Success | 279,549 | ||
| Apr 27, 2026 22:47 | CPPclang++20.1.2 | Success | 319,769 | ||
| Apr 27, 2026 22:43 | CPPclang++20.1.2 | Success | 293,088 | ||
| Apr 27, 2026 22:38 | CPPclang++20.1.2 | Success | 195,940 | ||
| Apr 27, 2026 22:10 | CPPclang++20.1.2 | Success | 243,296 | ||
| Apr 27, 2026 22:08 | CPPg++14.2.0 | Success | 267,288 | ||
| Apr 27, 2026 22:04 | CPPclang++20.1.2 | Success | 172,930 | ||
| Apr 27, 2026 22:00 | CPPclang++20.1.2 | Success | 168,151+20.85 RP | ||
| Apr 27, 2026 21:56 | CPPclang++20.1.2 | Error |