Cross-Margin Liquidation Engine yenw0d

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 of trade_size * price_at_trade_time across all trades
  • Margin rule: liquidate if equity < total_notional / 100 after any price update

Input

One command per line on STDIN:

  • a <balance> – create account with USD balance (IDs start at 0, incrementing)
  • p <instrument_idx> <price> – set/update instrument price (0-indexed)
  • t <account_idx> <instrument_idx> <size> – trade size (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
Back to listMar 20, 2026 20:10Yuriy LyfenkoYuriy LyfenkoError
Source Code

Source code access is restricted. Log in to request access.

Challenge History
DateChallengerCostTypeStatus
Sep 11, 2026 17:48Andrew Epstein13.73CustomSolution Broken
Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Sep 11, 2026 17:58012,095,7711,083,0002,389,0002,121,728line 0: expected liquidate 1 8 998 got 0 0stderr
2Sep 11, 2026 17:58012,092,1881,080,0002,478,0002,121,728line 0: expected liquidate 1 8 998 got 0 0stderr
3Sep 11, 2026 17:58012,230,9071,195,0002,506,0002,121,728line 0: expected liquidate 1 8 998 got 0 0stderr
4Mar 20, 2026 20:112,16152,607,35625,086,0003,010,0002,338,816
5Mar 20, 2026 20:112,17049,906,24923,177,0005,038,0002,359,296
6Mar 21, 2026 19:352,19152,533,90922,383,0006,104,0002,416,640
7Mar 21, 2026 19:352,28252,233,90426,599,0003,069,0002,506,752
8Mar 21, 2026 19:352,30052,794,94225,918,0003,987,0002,523,136
9Mar 20, 2026 20:112,31852,770,14425,114,0005,022,0002,539,520
10Mar 20, 2026 20:112,32755,797,90726,221,0004,034,0002,387,968
11Mar 21, 2026 19:352,33157,483,36226,266,0004,041,0002,527,232
12Mar 21, 2026 19:352,33854,245,46326,347,0004,053,0002,387,968
13Mar 21, 2026 19:322,34464,760,50426,406,0004,062,0002,289,664
14Mar 21, 2026 19:352,35261,255,08428,544,0002,038,0002,379,776
15Mar 21, 2026 19:322,37657,452,88025,911,0004,982,0002,510,848
16Mar 20, 2026 20:112,39259,417,18728,092,0003,009,0002,510,848
17Mar 21, 2026 19:352,39455,251,00328,107,0003,011,0002,437,120
18Mar 20, 2026 20:112,39761,982,91526,134,0005,025,0002,490,368
19Mar 21, 2026 19:352,40058,552,15729,182,0002,012,0002,461,696
20Mar 20, 2026 20:112,40253,463,16727,202,0004,029,0002,338,816
21Mar 20, 2026 20:112,41958,518,82828,399,0003,042,0002,539,520
22Mar 20, 2026 20:102,43458,845,36126,699,0004,944,0002,404,352
23Mar 20, 2026 20:112,45963,438,34727,966,0003,995,0002,371,584
24Mar 20, 2026 20:102,48262,140,99428,228,0004,032,0002,392,064
25Mar 21, 2026 19:352,50856,691,30928,531,0004,075,0002,408,448
26Mar 21, 2026 19:322,51357,192,88528,590,0004,084,0002,379,776
27Mar 20, 2026 20:112,53759,237,54628,984,0003,997,0002,428,928
28Mar 20, 2026 20:112,62464,704,15828,094,0006,020,0002,453,504
29Mar 20, 2026 20:112,65356,368,19328,405,0006,086,0002,347,008
30Mar 20, 2026 20:102,71265,479,33730,220,0005,036,0002,277,376