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 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 | |||
| 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 |