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 8, 2026 13:19 | GOgo1.26.2 | Error | |||
| Sep 8, 2026 13:06 | GOgo1.26.2 | Error | |||
| Sep 8, 2026 12:50 | GOgo1.26.2 | Error | |||
| Sep 8, 2026 12:09 | CPPg++14.2.0 | Error | |||
| Sep 7, 2026 14:02 | CSHARP10.0.7 | Error | |||
| Sep 7, 2026 13:57 | CSHARP10.0.7 | Error | |||
| Sep 7, 2026 13:50 | CSHARP10.0.7 | Error | |||
| Sep 7, 2026 13:44 | CSHARP10.0.7 | Error | |||
| Sep 7, 2026 13:39 | CSHARP10.0.7 | Error | |||
| Sep 7, 2026 13:32 | CSHARP10.0.7 | Error | |||
| Sep 7, 2026 13:21 | CSHARP10.0.7 | Error | |||
| Sep 7, 2026 13:15 | CSHARP10.0.7 | Error | |||
| Sep 7, 2026 12:32 | CSHARP10.0.7 | Error | |||
| Sep 7, 2026 10:28 | CSHARP10.0.7 | Error | |||
| Sep 6, 2026 17:31 | CPPg++14.2.0 | Error | +12.90 RP | ||
| Sep 4, 2026 20:39 | CPPclang++20.1.2 | Error | +93.66 RP | ||
| Sep 4, 2026 19:00 | RUSTrust-1.98.1 | Success | 2,291 | ||
| Sep 4, 2026 18:31 | CPPclang++20.1.2 | Error | |||
| Sep 4, 2026 18:02 | CPPclang++20.1.2 | Error | |||
| Sep 4, 2026 17:54 | CPPclang++20.1.2 | Error | |||
| Sep 4, 2026 17:04 | CPPclang++20.1.2 | Error | |||
| Sep 4, 2026 15:42 | CPPg++14.2.0 | Error | +52.73 RP | ||
| Sep 4, 2026 10:32 | CSHARP10.0.7 | Error | |||
| Sep 4, 2026 10:21 | CSHARP10.0.7 | Error | |||
| Sep 4, 2026 10:18 | GOgo1.26.2 | Error | |||
| Sep 4, 2026 10:06 | CPPg++14.2.0 | Error | |||
| Sep 4, 2026 09:55 | CSHARP10.0.7 | Error | |||
| Sep 4, 2026 09:45 | CSHARP10.0.7 | Error | |||
| Sep 4, 2026 09:41 | GOgo1.26.2 | Error | |||
| Sep 4, 2026 09:05 | ZIG0.16.0 | Error | |||
| Sep 4, 2026 09:02 | RUSTrust-1.95.0 | Error | +104.02 RP | ||
| Sep 4, 2026 08:59 | ZIG0.16.0 | Error | |||
| Sep 4, 2026 08:18 | CPPg++14.2.0 | Error | |||
| Sep 4, 2026 07:59 | CPPg++14.2.0 | Error | +25.71 RP | ||
| Sep 4, 2026 06:42 | CPPg++10.5.0 | Success | 292,197 | ||
| Sep 4, 2026 00:07 | CPPg++14.2.0 | Error | |||
| Sep 3, 2026 22:48 | CPPg++14.2.0 | Error | |||
| Sep 3, 2026 22:42 | CPPg++14.2.0 | Error | |||
| Sep 3, 2026 21:51 | CPPg++14.2.0 | Error | |||
| Sep 3, 2026 21:37 | CPPg++14.2.0 | Error | |||
| Sep 3, 2026 21:06 | CPPg++14.2.0 | Error | |||
| Sep 3, 2026 20:59 | CPPg++14.2.0 | Error | |||
| Sep 3, 2026 12:50 | CPPg++14.2.0 | Error | |||
| Sep 3, 2026 12:37 | CPPg++14.2.0 | Error | |||
| Sep 2, 2026 17:31 | CPPg++14.2.0 | Error | |||
| Sep 2, 2026 17:00 | CPPg++14.2.0 | Error | +323.93 RP | ||
| Sep 2, 2026 16:35 | CPPg++14.2.0 | Error | |||
| Sep 2, 2026 15:42 | CPPg++14.2.0 | Error | +452.58 RP | ||
| Sep 2, 2026 13:08 | CPPg++14.2.0 | Error | |||
| Sep 2, 2026 12:37 | CPPg++14.2.0 | Error | |||
| Sep 2, 2026 12:07 | CPPg++14.2.0 | Error | |||
| Sep 2, 2026 11:07 | CPPg++14.2.0 | Error | +88.27 RP | ||
| Sep 2, 2026 10:47 | CPPg++14.2.0 | Error | |||
| Sep 2, 2026 10:23 | CPPg++14.2.0 | Error | |||
| Sep 2, 2026 10:14 | CPPg++14.2.0 | Error | |||
| Sep 2, 2026 08:02 | CPPg++14.2.0 | Error | |||
| Sep 2, 2026 07:22 | CPPg++14.2.0 | Error | +182.76 RP | ||
| Sep 2, 2026 06:48 | CPPg++14.2.0 | Error | +186.67 RP | ||
| Sep 2, 2026 06:09 | CPPg++14.2.0 | Error | |||
| Sep 2, 2026 05:34 | CPPg++14.2.0 | Error | |||
| Sep 2, 2026 04:41 | CPPg++14.2.0 | Error | |||
| Sep 2, 2026 04:23 | CPPg++14.2.0 | Error | |||
| Sep 2, 2026 03:59 | CPPg++14.2.0 | Error | |||
| Sep 2, 2026 03:40 | CPPg++14.2.0 | Error | |||
| Sep 2, 2026 03:30 | CPPg++14.2.0 | Error | |||
| Sep 2, 2026 03:21 | CPPg++14.2.0 | Error | |||
| Sep 2, 2026 02:57 | CPPg++14.2.0 | Error | +199.62 RP | ||
| Sep 2, 2026 02:30 | CPPg++14.2.0 | Error | |||
| Sep 2, 2026 02:20 | CPPg++14.2.0 | Error | |||
| Sep 2, 2026 02:08 | CPPg++14.2.0 | Error | |||
| Sep 2, 2026 01:49 | CPPg++14.2.0 | Error | |||
| Sep 2, 2026 01:27 | CPPg++14.2.0 | Error | |||
| Sep 2, 2026 01:15 | CPPg++14.2.0 | Error | |||
| Sep 2, 2026 01:05 | CPPg++14.2.0 | Error | |||
| Sep 2, 2026 00:46 | CPPg++14.2.0 | Error | |||
| Sep 2, 2026 00:37 | CPPg++14.2.0 | Error | |||
| Sep 2, 2026 00:16 | CPPg++14.2.0 | Error | |||
| Sep 1, 2026 20:50 | CPPg++14.2.0 | Error | |||
| Sep 1, 2026 20:24 | CPPg++14.2.0 | Error | |||
| Sep 1, 2026 19:56 | CPPg++14.2.0 | Error | |||
| Sep 1, 2026 19:40 | CPPg++14.2.0 | Error | |||
| Sep 1, 2026 19:15 | CPPg++14.2.0 | Error | |||
| Sep 1, 2026 18:32 | CPPg++14.2.0 | Error | |||
| Sep 1, 2026 18:05 | CPPg++14.2.0 | Error | |||
| Sep 1, 2026 17:38 | CPPg++14.2.0 | Error | |||
| Sep 1, 2026 17:27 | CPPg++14.2.0 | Error | |||
| Sep 1, 2026 17:21 | CPPg++14.2.0 | Error | |||
| Sep 1, 2026 16:57 | CPPg++14.2.0 | Error | |||
| Sep 1, 2026 16:19 | CPPg++14.2.0 | Error | |||
| Sep 1, 2026 15:42 | CPPg++14.2.0 | Error | |||
| Sep 1, 2026 15:39 | CPPg++14.2.0 | Error | |||
| Sep 1, 2026 15:27 | CPPg++14.2.0 | Error | |||
| Sep 1, 2026 15:22 | CPPg++14.2.0 | Error | |||
| Sep 1, 2026 14:44 | CPPg++14.2.0 | Error | |||
| Sep 1, 2026 14:27 | CPPg++14.2.0 | Error | |||
| Sep 1, 2026 14:12 | CPPg++14.2.0 | Error | |||
| Sep 1, 2026 14:07 | CPPg++14.2.0 | Error | |||
| Sep 1, 2026 13:58 | CPPg++14.2.0 | Error | |||
| Sep 1, 2026 13:34 | CPPg++14.2.0 | Error | |||
| Sep 1, 2026 13:23 | CPPg++14.2.0 | Error |