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 | |
|---|---|---|---|---|---|
| Apr 27, 2026 21:52 | CPPg++14.2.0 | Error | |||
| Apr 27, 2026 12:49 | CPPg++13.3.0 | Success | 63,340 | ||
| Apr 27, 2026 08:12 | GOgo1.26.2 | Success | 6,426 | ||
| Apr 27, 2026 07:02 | RUSTrust-1.95.0 | Success | 5,297 | ||
| Apr 27, 2026 06:34 | CPPg++13.3.0 | Success | 5,396 | ||
| Apr 27, 2026 01:03 | CPPg++13.3.0 | Success | 60,070 | ||
| Apr 26, 2026 22:23 | CPPg++13.3.0 | Success | 60,837 | ||
| Apr 26, 2026 20:56 | CPPclang++20.1.2 | Success | 263,148 | ||
| Apr 26, 2026 20:53 | CPPclang++20.1.2 | Success | 258,933+3.78 RP | ||
| Apr 26, 2026 20:40 | CPPclang++20.1.2 | Success | 297,048 | ||
| Apr 26, 2026 20:38 | CPPclang++20.1.2 | Success | 290,860 | ||
| Apr 26, 2026 20:36 | CPPg++14.2.0 | Success | 370,805 | ||
| Apr 26, 2026 20:34 | CPPg++14.2.0 | Success | 356,563 | ||
| Apr 26, 2026 17:51 | CPPg++10.5.0 | Success | 372,257 | ||
| Apr 26, 2026 17:26 | CPPg++10.5.0 | Success | 287,008+34.84 RP | ||
| Apr 26, 2026 14:34 | GOgo1.26.2 | Success | 5,957 | ||
| Apr 26, 2026 12:13 | CPPg++10.5.0 | Success | 5,940 | ||
| Apr 26, 2026 12:03 | CPPg++10.5.0 | Success | 5,703 | ||
| Apr 26, 2026 07:40 | RUSTrust-1.95.0 | Success | 5,405 | ||
| Apr 25, 2026 10:05 | GOgo1.26.2 | Success | 6,222 | ||
| Apr 24, 2026 08:17 | CPPclang++18.1.3 | Success | 15,169 | ||
| Apr 24, 2026 07:48 | CPPclang++18.1.3 | Success | 13,918 | ||
| Apr 24, 2026 07:46 | CPPclang++18.1.3 | Success | 14,464 | ||
| Apr 24, 2026 07:45 | CPPclang++18.1.3 | Success | 15,809 | ||
| Apr 24, 2026 07:44 | CPPclang++18.1.3 | Success | 14,812 | ||
| Apr 24, 2026 07:43 | CPPclang++18.1.3 | Success | 13,500+55.72 RP | ||
| Apr 24, 2026 04:26 | RUSTrust-1.95.0 | Success | 5,047 | ||
| Apr 23, 2026 20:25 | RUSTrust-1.95.0 | Success | 30,266+0.95 RP | ||
| Apr 23, 2026 19:07 | RUSTrust-1.95.0 | Success | 181,832 | ||
| Apr 23, 2026 10:05 | CPPclang++18.1.3 | Success | 16,987 | ||
| Apr 23, 2026 10:03 | CPPclang++18.1.3 | Success | 15,657 | ||
| Apr 23, 2026 10:01 | CPPclang++18.1.3 | Success | 16,057 | ||
| Apr 23, 2026 09:15 | CPPclang++18.1.3 | Success | 14,894 | ||
| Apr 23, 2026 09:02 | CPPclang++20.1.2 | Success | 15,625 | ||
| Apr 23, 2026 09:01 | CPPclang++18.1.3 | Success | 22,464 | ||
| Apr 23, 2026 08:58 | CPPclang++18.1.3 | Success | 24,457 | ||
| Apr 23, 2026 08:55 | CPPclang++18.1.3 | Success | 23,392 | ||
| Apr 23, 2026 08:28 | CPPclang++18.1.3 | Success | 78,017 | ||
| Apr 23, 2026 08:26 | CPPclang++18.1.3 | Error | |||
| Apr 23, 2026 08:06 | CPPclang++18.1.3 | Success | 15,320 | ||
| Apr 23, 2026 08:00 | CPPg++10.5.0 | Success | 16,812 | ||
| Apr 23, 2026 07:58 | CPPclang++18.1.3 | Success | 14,946 | ||
| Apr 23, 2026 06:19 | GOgo1.26.2 | Success | 6,289 | ||
| Apr 22, 2026 23:36 | CPPg++13.3.0 | Success | 59,874 | ||
| Apr 22, 2026 22:03 | CPPg++10.5.0 | Success | 5,582 | ||
| Apr 22, 2026 22:01 | RUSTrust-1.95.0 | Success | 5,299 | ||
| Apr 22, 2026 20:47 | CPPg++10.5.0 | Success | 18,366 | ||
| Apr 22, 2026 20:25 | CPPclang++18.1.3 | Success | 17,282 | ||
| Apr 22, 2026 20:04 | CPPg++13.3.0 | Success | 58,998+6.67 RP | ||
| Apr 22, 2026 16:48 | CPPg++10.5.0 | Success | 5,550 | ||
| Apr 22, 2026 14:53 | CPPclang++18.1.3 | Success | 429,766 | ||
| Apr 22, 2026 13:41 | CPPg++14.2.0 | Success | 116,810 | ||
| Apr 22, 2026 12:02 | CPPclang++18.1.3 | Success | 22,366 | ||
| Apr 22, 2026 08:27 | CSHARP9.0.15 | Success | 7,342 | ||
| Apr 22, 2026 08:02 | CPPg++10.5.0 | Success | 5,500 | ||
| Apr 21, 2026 20:23 | CPPg++10.5.0 | Success | 6,172 | ||
| Apr 21, 2026 18:50 | CPPg++10.5.0 | Success | 5,980 | ||
| Apr 21, 2026 18:31 | CPPg++10.5.0 | Success | 6,244 | ||
| Apr 21, 2026 17:39 | CPPg++13.3.0 | Success | 67,813 | ||
| Apr 21, 2026 10:04 | CPPclang++18.1.3 | Success | 25,900 | ||
| Apr 21, 2026 09:54 | CPPg++13.3.0 | Error | |||
| Apr 21, 2026 09:40 | CPPclang++18.1.3 | Error | |||
| Apr 21, 2026 09:07 | CPPg++13.3.0 | Success | 66,492 | ||
| Apr 21, 2026 04:04 | CPPg++10.5.0 | Success | 6,252 | ||
| Apr 21, 2026 03:23 | CPPg++13.3.0 | Success | 68,190 | ||
| Apr 21, 2026 01:30 | RUSTrust-1.95.0 | Success | 268,197+37.29 RP | ||
| Apr 20, 2026 21:15 | CPPg++13.3.0 | Success | 63,184 | ||
| Apr 20, 2026 20:22 | CPPg++13.3.0 | Error | |||
| Apr 20, 2026 19:09 | CPPg++14.2.0 | Success | 115,528+23.72 RP | ||
| Apr 20, 2026 19:02 | CPPclang++18.1.3 | Success | 159,132+31.82 RP | ||
| Apr 20, 2026 18:45 | CPPclang++18.1.3 | Success | 322,385+31.02 RP | ||
| Apr 20, 2026 18:45 | CPPclang++18.1.3 | Success | 367,901 | ||
| Apr 20, 2026 18:45 | CPPg++14.2.0 | Success | 417,450 | ||
| Apr 20, 2026 16:52 | CPPclang++18.1.3 | Error | |||
| Apr 20, 2026 16:52 | CPPg++13.3.0 | Error | |||
| Apr 20, 2026 16:51 | CPPclang++18.1.3 | Error | |||
| Apr 20, 2026 16:17 | CPPg++13.3.0 | Error | |||
| Apr 20, 2026 15:41 | RUSTrust-1.94.0 | Success | 4,888+82.35 RP | ||
| Apr 20, 2026 15:38 | GOgo1.26.1 | Success | 7,023 | ||
| Apr 20, 2026 15:36 | CPPg++13.3.0 | Success | 6,375 | ||
| Apr 20, 2026 14:14 | CPPg++13.3.0 | Error | |||
| Apr 20, 2026 12:53 | CPPclang++18.1.3 | Success | 18,546 | ||
| Apr 20, 2026 12:42 | CPPclang++18.1.3 | Success | 16,658 | ||
| Apr 19, 2026 09:41 | CPPg++13.3.0 | Success | 61,414+15.22 RP | ||
| Apr 19, 2026 05:47 | CPPg++13.3.0 | Success | 71,122 | ||
| Apr 19, 2026 05:39 | RUSTrust-1.95.0 | Success | 30,353+312.11 RP | ||
| Apr 18, 2026 20:50 | CPPg++13.3.0 | Success | 70,283 | ||
| Apr 18, 2026 16:50 | CPPg++13.3.0 | Success | 67,747+41.85 RP | ||
| Apr 18, 2026 16:04 | RUSTrust-1.95.0 | Success | 576,417+17.35 RP | ||
| Apr 18, 2026 14:37 | CPPg++13.3.0 | Success | 94,555+50.44 RP | ||
| Apr 18, 2026 01:28 | CPPg++13.3.0 | Success | 180,762+34.82 RP | ||
| Apr 18, 2026 00:02 | GOgo1.26.1 | Success | 7,028 | ||
| Apr 17, 2026 20:53 | CPPg++13.3.0 | Success | 487,675+20.51 RP | ||
| Apr 17, 2026 20:12 | GOgo1.26.1 | Success | 7,529 | ||
| Apr 17, 2026 20:09 | GOgo1.26.1 | Success | 6,910 | ||
| Apr 17, 2026 20:06 | GOgo1.26.1 | Error | |||
| Apr 17, 2026 19:38 | CPPg++13.3.0 | Error | |||
| Apr 17, 2026 19:11 | GOgo1.26.1 | Success | 7,651 | ||
| Apr 17, 2026 18:20 | RUSTrust-1.94.0 | Success | 5,274 | ||
| Apr 17, 2026 18:08 | GOgo1.26.1 | Success | 6,431 |