broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(trip, plan):
    surged = (trip['core'] * trip['surge'] * 2 + 10) // 20
    share = surged * (100 - plan['commission']) // 100
    pay = max(share + trip['tip'], plan['min_pay']) + trip['tolls']
    n = plan['trips_before'] + 1
    bonus = 0
    for need, amount in plan['quests']:
        if n == need:
            bonus += amount
    return {'pay': pay, 'bonus': bonus}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: minimum pay scope',
   [{'booking_fee': 0, 'core': 450, 'surge': 10, 'tip': 500, 'tolls': 0},
    {'commission': 20, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 19}],
   {'bonus': 2500, 'pay': 1000}),
  ('partial repair probe: minimum pay scope',
   [{'booking_fee': 250, 'core': 450, 'surge': 15, 'tip': 0, 'tolls': 300},
    {'commission': 20, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 1000}),
  ('second regression',
   [{'booking_fee': 0, 'core': 450, 'surge': 10, 'tip': 200, 'tolls': 300},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 24}],
   {'bonus': 1000, 'pay': 900}),
  ('normal control 1',
   [{'booking_fee': 250, 'core': 2500, 'surge': 10, 'tip': 200, 'tolls': 0},
    {'commission': 25, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 9}],
   {'bonus': 1500, 'pay': 2075}),
  ('normal control 2',
   [{'booking_fee': 0, 'core': 900, 'surge': 12, 'tip': 500, 'tolls': 0},
    {'commission': 20, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 24}],
   {'bonus': 1000, 'pay': 1364}),
  ('normal control 3',
   [{'booking_fee': 0, 'core': 1733, 'surge': 10, 'tip': 500, 'tolls': 300},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 24}],
   {'bonus': 1000, 'pay': 2186}),
  ('normal control 4',
   [{'booking_fee': 250, 'core': 900, 'surge': 10, 'tip': 0, 'tolls': 300},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 1020})],
 [('regression: minimum pay scope',
   [{'booking_fee': 0, 'core': 450, 'surge': 10, 'tip': 200, 'tolls': 300},
    {'commission': 25, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 19}],
   {'bonus': 2500, 'pay': 1200}),
  ('partial repair probe: minimum pay scope',
   [{'booking_fee': 250, 'core': 450, 'surge': 12, 'tip': 0, 'tolls': 300},
    {'commission': 25, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 19}],
   {'bonus': 2500, 'pay': 800}),
  ('second regression',
   [{'booking_fee': 0, 'core': 450, 'surge': 10, 'tip': 0, 'tolls': 300},
    {'commission': 25, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 9}],
   {'bonus': 1500, 'pay': 800}),
  ('normal control 1',
   [{'booking_fee': 0, 'core': 2500, 'surge': 10, 'tip': 200, 'tolls': 300},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 24}],
   {'bonus': 1000, 'pay': 2500}),
  ('normal control 2',
   [{'booking_fee': 0, 'core': 900, 'surge': 12, 'tip': 500, 'tolls': 0},
    {'commission': 25, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 9}],
   {'bonus': 1500, 'pay': 1310}),
  ('normal control 3',
   [{'booking_fee': 250, 'core': 1733, 'surge': 20, 'tip': 500, 'tolls': 0},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 9}],
   {'bonus': 1500, 'pay': 3272}),
  ('normal control 4',
   [{'booking_fee': 250, 'core': 450, 'surge': 15, 'tip': 0, 'tolls': 0},
    {'commission': 25, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 19}],
   {'bonus': 2500, 'pay': 506})],
 [('regression: minimum pay scope',
   [{'booking_fee': 250, 'core': 450, 'surge': 15, 'tip': 500, 'tolls': 0},
    {'commission': 25, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 9}],
   {'bonus': 1500, 'pay': 1200}),
  ('partial repair probe: minimum pay scope',
   [{'booking_fee': 250, 'core': 450, 'surge': 10, 'tip': 0, 'tolls': 300},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 10}],
   {'bonus': 0, 'pay': 700}),
  ('second regression',
   [{'booking_fee': 0, 'core': 450, 'surge': 10, 'tip': 500, 'tolls': 0},
    {'commission': 20, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 10}],
   {'bonus': 0, 'pay': 1200}),
  ('normal control 1',
   [{'booking_fee': 0, 'core': 1733, 'surge': 20, 'tip': 500, 'tolls': 300},
    {'commission': 25, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 9}],
   {'bonus': 1500, 'pay': 3399}),
  ('normal control 2',
   [{'booking_fee': 250, 'core': 450, 'surge': 20, 'tip': 500, 'tolls': 300},
    {'commission': 25, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 19}],
   {'bonus': 2500, 'pay': 1475}),
  ('normal control 3',
   [{'booking_fee': 250, 'core': 2500, 'surge': 10, 'tip': 200, 'tolls': 0},
    {'commission': 25, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 24}],
   {'bonus': 1000, 'pay': 2075}),
  ('normal control 4',
   [{'booking_fee': 0, 'core': 2500, 'surge': 12, 'tip': 500, 'tolls': 300},
    {'commission': 20, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 19}],
   {'bonus': 2500, 'pay': 3200})],
 [('regression: minimum pay scope',
   [{'booking_fee': 0, 'core': 450, 'surge': 12, 'tip': 200, 'tolls': 300},
    {'commission': 20, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 24}],
   {'bonus': 1000, 'pay': 1200}),
  ('partial repair probe: minimum pay scope',
   [{'booking_fee': 250, 'core': 900, 'surge': 10, 'tip': 500, 'tolls': 300},
    {'commission': 25, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 1500}),
  ('second regression',
   [{'booking_fee': 250, 'core': 450, 'surge': 12, 'tip': 500, 'tolls': 0},
    {'commission': 25, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 1200}),
  ('normal control 1',
   [{'booking_fee': 250, 'core': 1733, 'surge': 15, 'tip': 200, 'tolls': 0},
    {'commission': 20, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 24}],
   {'bonus': 1000, 'pay': 2280}),
  ('normal control 2',
   [{'booking_fee': 0, 'core': 2500, 'surge': 10, 'tip': 0, 'tolls': 0},
    {'commission': 20, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 9}],
   {'bonus': 1500, 'pay': 2000}),
  ('normal control 3',
   [{'booking_fee': 0, 'core': 450, 'surge': 15, 'tip': 0, 'tolls': 0},
    {'commission': 25, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 24}],
   {'bonus': 1000, 'pay': 506}),
  ('normal control 4',
   [{'booking_fee': 0, 'core': 1733, 'surge': 10, 'tip': 200, 'tolls': 300},
    {'commission': 25, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 1799})],
 [('regression: minimum pay scope',
   [{'booking_fee': 250, 'core': 450, 'surge': 10, 'tip': 500, 'tolls': 0},
    {'commission': 20, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 9}],
   {'bonus': 1500, 'pay': 1000}),
  ('partial repair probe: minimum pay scope',
   [{'booking_fee': 250, 'core': 450, 'surge': 12, 'tip': 500, 'tolls': 300},
    {'commission': 20, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 10}],
   {'bonus': 0, 'pay': 1500}),
  ('second regression',
   [{'booking_fee': 250, 'core': 450, 'surge': 12, 'tip': 200, 'tolls': 0},
    {'commission': 20, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 10}],
   {'bonus': 0, 'pay': 700}),
  ('normal control 1',
   [{'booking_fee': 250, 'core': 900, 'surge': 20, 'tip': 0, 'tolls': 0},
    {'commission': 20, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 20}],
   {'bonus': 0, 'pay': 1440}),
  ('normal control 2',
   [{'booking_fee': 250, 'core': 2500, 'surge': 10, 'tip': 200, 'tolls': 300},
    {'commission': 20, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 19}],
   {'bonus': 2500, 'pay': 2500}),
  ('normal control 3',
   [{'booking_fee': 0, 'core': 2500, 'surge': 15, 'tip': 200, 'tolls': 300},
    {'commission': 20, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 10}],
   {'bonus': 0, 'pay': 3500}),
  ('normal control 4',
   [{'booking_fee': 250, 'core': 1733, 'surge': 12, 'tip': 200, 'tolls': 300},
    {'commission': 20, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 9}],
   {'bonus': 1500, 'pay': 2164})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(trip, plan):
    surged = (trip['core'] * trip['surge'] * 2 + 10) // 20
    share = surged * (100 - plan['commission']) // 100
    pay = max(share + trip['tolls'], plan['min_pay']) + trip['tip']
    n = plan['trips_before'] + 1
    bonus = 0
    for need, amount in plan['quests']:
        if n == need:
            bonus += amount
    return {'pay': pay, 'bonus': bonus}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: minimum pay scope',
   [{'booking_fee': 0, 'core': 450, 'surge': 10, 'tip': 500, 'tolls': 0},
    {'commission': 20, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 19}],
   {'bonus': 2500, 'pay': 1000}),
  ('partial repair probe: minimum pay scope',
   [{'booking_fee': 250, 'core': 450, 'surge': 15, 'tip': 0, 'tolls': 300},
    {'commission': 20, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 1000}),
  ('second regression',
   [{'booking_fee': 0, 'core': 450, 'surge': 10, 'tip': 200, 'tolls': 300},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 24}],
   {'bonus': 1000, 'pay': 900}),
  ('normal control 1',
   [{'booking_fee': 250, 'core': 2500, 'surge': 10, 'tip': 200, 'tolls': 0},
    {'commission': 25, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 9}],
   {'bonus': 1500, 'pay': 2075}),
  ('normal control 2',
   [{'booking_fee': 0, 'core': 900, 'surge': 12, 'tip': 500, 'tolls': 0},
    {'commission': 20, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 24}],
   {'bonus': 1000, 'pay': 1364}),
  ('normal control 3',
   [{'booking_fee': 0, 'core': 1733, 'surge': 10, 'tip': 500, 'tolls': 300},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 24}],
   {'bonus': 1000, 'pay': 2186}),
  ('normal control 4',
   [{'booking_fee': 250, 'core': 900, 'surge': 10, 'tip': 0, 'tolls': 300},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 1020})],
 [('regression: minimum pay scope',
   [{'booking_fee': 0, 'core': 450, 'surge': 10, 'tip': 200, 'tolls': 300},
    {'commission': 25, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 19}],
   {'bonus': 2500, 'pay': 1200}),
  ('partial repair probe: minimum pay scope',
   [{'booking_fee': 250, 'core': 450, 'surge': 12, 'tip': 0, 'tolls': 300},
    {'commission': 25, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 19}],
   {'bonus': 2500, 'pay': 800}),
  ('second regression',
   [{'booking_fee': 0, 'core': 450, 'surge': 10, 'tip': 0, 'tolls': 300},
    {'commission': 25, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 9}],
   {'bonus': 1500, 'pay': 800}),
  ('normal control 1',
   [{'booking_fee': 0, 'core': 2500, 'surge': 10, 'tip': 200, 'tolls': 300},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 24}],
   {'bonus': 1000, 'pay': 2500}),
  ('normal control 2',
   [{'booking_fee': 0, 'core': 900, 'surge': 12, 'tip': 500, 'tolls': 0},
    {'commission': 25, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 9}],
   {'bonus': 1500, 'pay': 1310}),
  ('normal control 3',
   [{'booking_fee': 250, 'core': 1733, 'surge': 20, 'tip': 500, 'tolls': 0},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 9}],
   {'bonus': 1500, 'pay': 3272}),
  ('normal control 4',
   [{'booking_fee': 250, 'core': 450, 'surge': 15, 'tip': 0, 'tolls': 0},
    {'commission': 25, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 19}],
   {'bonus': 2500, 'pay': 506})],
 [('regression: minimum pay scope',
   [{'booking_fee': 250, 'core': 450, 'surge': 15, 'tip': 500, 'tolls': 0},
    {'commission': 25, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 9}],
   {'bonus': 1500, 'pay': 1200}),
  ('partial repair probe: minimum pay scope',
   [{'booking_fee': 250, 'core': 450, 'surge': 10, 'tip': 0, 'tolls': 300},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 10}],
   {'bonus': 0, 'pay': 700}),
  ('second regression',
   [{'booking_fee': 0, 'core': 450, 'surge': 10, 'tip': 500, 'tolls': 0},
    {'commission': 20, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 10}],
   {'bonus': 0, 'pay': 1200}),
  ('normal control 1',
   [{'booking_fee': 0, 'core': 1733, 'surge': 20, 'tip': 500, 'tolls': 300},
    {'commission': 25, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 9}],
   {'bonus': 1500, 'pay': 3399}),
  ('normal control 2',
   [{'booking_fee': 250, 'core': 450, 'surge': 20, 'tip': 500, 'tolls': 300},
    {'commission': 25, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 19}],
   {'bonus': 2500, 'pay': 1475}),
  ('normal control 3',
   [{'booking_fee': 250, 'core': 2500, 'surge': 10, 'tip': 200, 'tolls': 0},
    {'commission': 25, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 24}],
   {'bonus': 1000, 'pay': 2075}),
  ('normal control 4',
   [{'booking_fee': 0, 'core': 2500, 'surge': 12, 'tip': 500, 'tolls': 300},
    {'commission': 20, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 19}],
   {'bonus': 2500, 'pay': 3200})],
 [('regression: minimum pay scope',
   [{'booking_fee': 0, 'core': 450, 'surge': 12, 'tip': 200, 'tolls': 300},
    {'commission': 20, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 24}],
   {'bonus': 1000, 'pay': 1200}),
  ('partial repair probe: minimum pay scope',
   [{'booking_fee': 250, 'core': 900, 'surge': 10, 'tip': 500, 'tolls': 300},
    {'commission': 25, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 1500}),
  ('second regression',
   [{'booking_fee': 250, 'core': 450, 'surge': 12, 'tip': 500, 'tolls': 0},
    {'commission': 25, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 1200}),
  ('normal control 1',
   [{'booking_fee': 250, 'core': 1733, 'surge': 15, 'tip': 200, 'tolls': 0},
    {'commission': 20, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 24}],
   {'bonus': 1000, 'pay': 2280}),
  ('normal control 2',
   [{'booking_fee': 0, 'core': 2500, 'surge': 10, 'tip': 0, 'tolls': 0},
    {'commission': 20, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 9}],
   {'bonus': 1500, 'pay': 2000}),
  ('normal control 3',
   [{'booking_fee': 0, 'core': 450, 'surge': 15, 'tip': 0, 'tolls': 0},
    {'commission': 25, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 24}],
   {'bonus': 1000, 'pay': 506}),
  ('normal control 4',
   [{'booking_fee': 0, 'core': 1733, 'surge': 10, 'tip': 200, 'tolls': 300},
    {'commission': 25, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 1799})],
 [('regression: minimum pay scope',
   [{'booking_fee': 250, 'core': 450, 'surge': 10, 'tip': 500, 'tolls': 0},
    {'commission': 20, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 9}],
   {'bonus': 1500, 'pay': 1000}),
  ('partial repair probe: minimum pay scope',
   [{'booking_fee': 250, 'core': 450, 'surge': 12, 'tip': 500, 'tolls': 300},
    {'commission': 20, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 10}],
   {'bonus': 0, 'pay': 1500}),
  ('second regression',
   [{'booking_fee': 250, 'core': 450, 'surge': 12, 'tip': 200, 'tolls': 0},
    {'commission': 20, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 10}],
   {'bonus': 0, 'pay': 700}),
  ('normal control 1',
   [{'booking_fee': 250, 'core': 900, 'surge': 20, 'tip': 0, 'tolls': 0},
    {'commission': 20, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 20}],
   {'bonus': 0, 'pay': 1440}),
  ('normal control 2',
   [{'booking_fee': 250, 'core': 2500, 'surge': 10, 'tip': 200, 'tolls': 300},
    {'commission': 20, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 19}],
   {'bonus': 2500, 'pay': 2500}),
  ('normal control 3',
   [{'booking_fee': 0, 'core': 2500, 'surge': 15, 'tip': 200, 'tolls': 300},
    {'commission': 20, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 10}],
   {'bonus': 0, 'pay': 3500}),
  ('normal control 4',
   [{'booking_fee': 250, 'core': 1733, 'surge': 12, 'tip': 200, 'tolls': 300},
    {'commission': 20, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 9}],
   {'bonus': 1500, 'pay': 2164})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A generous tip silently replaces the platform-funded minimum pay top-up.

Driver pay per trip in cents: the surged core fare (core x surge tenths, half up) minus the commission percentage (floored), raised to min_pay if lower; tolls and tips pass through untouched and are outside commission and the minimum; the booking fee is platform revenue. A quest bonus is paid when this trip is exactly the Nth trip for a quest threshold N (trips_before + 1 == N). Return pay and bonus.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(trip, plan):
    surged = (trip['core'] * trip['surge'] * 2 + 10) // 20
    share = surged * (100 - plan['commission']) // 100
    share = max(share, plan['min_pay'])
    pay = share + trip['tolls'] + trip['tip']
    n = plan['trips_before'] + 1
    bonus = 0
    for need, amount in plan['quests']:
        if n >= need:
            bonus += amount
    return {'pay': pay, 'bonus': bonus}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: quest crossing',
   [{'booking_fee': 0, 'core': 900, 'surge': 15, 'tip': 0, 'tolls': 300},
    {'commission': 25, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 19}],
   {'bonus': 2500, 'pay': 1312}),
  ('partial repair probe: quest crossing',
   [{'booking_fee': 250, 'core': 900, 'surge': 10, 'tip': 200, 'tolls': 0},
    {'commission': 20, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 9}],
   {'bonus': 1500, 'pay': 920}),
  ('second regression',
   [{'booking_fee': 250, 'core': 2500, 'surge': 20, 'tip': 0, 'tolls': 0},
    {'commission': 25, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 20}],
   {'bonus': 0, 'pay': 3750}),
  ('normal control 1',
   [{'booking_fee': 250, 'core': 450, 'surge': 12, 'tip': 200, 'tolls': 300},
    {'commission': 25, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 1000}),
  ('normal control 2',
   [{'booking_fee': 0, 'core': 450, 'surge': 15, 'tip': 200, 'tolls': 0},
    {'commission': 25, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 706}),
  ('normal control 3',
   [{'booking_fee': 0, 'core': 1733, 'surge': 15, 'tip': 500, 'tolls': 0},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 2580}),
  ('normal control 4',
   [{'booking_fee': 0, 'core': 900, 'surge': 10, 'tip': 500, 'tolls': 300},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 1520})],
 [('regression: quest crossing',
   [{'booking_fee': 0, 'core': 900, 'surge': 10, 'tip': 0, 'tolls': 300},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 20}],
   {'bonus': 0, 'pay': 1020}),
  ('partial repair probe: quest crossing',
   [{'booking_fee': 250, 'core': 450, 'surge': 15, 'tip': 200, 'tolls': 0},
    {'commission': 25, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 24}],
   {'bonus': 1000, 'pay': 706}),
  ('second regression',
   [{'booking_fee': 250, 'core': 2500, 'surge': 12, 'tip': 0, 'tolls': 300},
    {'commission': 25, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 19}],
   {'bonus': 2500, 'pay': 2550}),
  ('normal control 1',
   [{'booking_fee': 0, 'core': 2500, 'surge': 20, 'tip': 500, 'tolls': 0},
    {'commission': 25, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 4250}),
  ('normal control 2',
   [{'booking_fee': 0, 'core': 450, 'surge': 10, 'tip': 500, 'tolls': 300},
    {'commission': 20, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 1300}),
  ('normal control 3',
   [{'booking_fee': 250, 'core': 2500, 'surge': 12, 'tip': 200, 'tolls': 300},
    {'commission': 20, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 2900}),
  ('normal control 4',
   [{'booking_fee': 250, 'core': 1733, 'surge': 15, 'tip': 0, 'tolls': 0},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 2080})],
 [('regression: quest crossing',
   [{'booking_fee': 0, 'core': 450, 'surge': 15, 'tip': 0, 'tolls': 0},
    {'commission': 20, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 24}],
   {'bonus': 1000, 'pay': 540}),
  ('partial repair probe: quest crossing',
   [{'booking_fee': 250, 'core': 1733, 'surge': 12, 'tip': 0, 'tolls': 300},
    {'commission': 20, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 9}],
   {'bonus': 1500, 'pay': 1964}),
  ('second regression',
   [{'booking_fee': 250, 'core': 450, 'surge': 15, 'tip': 500, 'tolls': 300},
    {'commission': 25, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 19}],
   {'bonus': 2500, 'pay': 1500}),
  ('normal control 1',
   [{'booking_fee': 0, 'core': 1733, 'surge': 12, 'tip': 500, 'tolls': 0},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 2164}),
  ('normal control 2',
   [{'booking_fee': 0, 'core': 450, 'surge': 20, 'tip': 0, 'tolls': 300},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 1020}),
  ('normal control 3',
   [{'booking_fee': 0, 'core': 1733, 'surge': 12, 'tip': 200, 'tolls': 300},
    {'commission': 20, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 2164}),
  ('normal control 4',
   [{'booking_fee': 250, 'core': 900, 'surge': 12, 'tip': 200, 'tolls': 0},
    {'commission': 25, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 1010})],
 [('regression: quest crossing',
   [{'booking_fee': 250, 'core': 1733, 'surge': 12, 'tip': 0, 'tolls': 0},
    {'commission': 25, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 10}],
   {'bonus': 0, 'pay': 1560}),
  ('partial repair probe: quest crossing',
   [{'booking_fee': 250, 'core': 1733, 'surge': 10, 'tip': 0, 'tolls': 300},
    {'commission': 20, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 24}],
   {'bonus': 1000, 'pay': 1686}),
  ('second regression',
   [{'booking_fee': 0, 'core': 1733, 'surge': 15, 'tip': 0, 'tolls': 0},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 9}],
   {'bonus': 1500, 'pay': 2080}),
  ('normal control 1',
   [{'booking_fee': 250, 'core': 1733, 'surge': 15, 'tip': 0, 'tolls': 300},
    {'commission': 25, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 2250}),
  ('normal control 2',
   [{'booking_fee': 250, 'core': 900, 'surge': 12, 'tip': 200, 'tolls': 300},
    {'commission': 25, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 1310}),
  ('normal control 3',
   [{'booking_fee': 250, 'core': 2500, 'surge': 12, 'tip': 500, 'tolls': 0},
    {'commission': 20, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 2900}),
  ('normal control 4',
   [{'booking_fee': 0, 'core': 2500, 'surge': 15, 'tip': 0, 'tolls': 300},
    {'commission': 25, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 3112})],
 [('regression: quest crossing',
   [{'booking_fee': 0, 'core': 450, 'surge': 10, 'tip': 200, 'tolls': 0},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 19}],
   {'bonus': 2500, 'pay': 600}),
  ('partial repair probe: quest crossing',
   [{'booking_fee': 250, 'core': 450, 'surge': 12, 'tip': 500, 'tolls': 0},
    {'commission': 20, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 24}],
   {'bonus': 1000, 'pay': 1000}),
  ('second regression',
   [{'booking_fee': 0, 'core': 450, 'surge': 20, 'tip': 0, 'tolls': 300},
    {'commission': 25, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 20}],
   {'bonus': 0, 'pay': 975}),
  ('normal control 1',
   [{'booking_fee': 250, 'core': 2500, 'surge': 12, 'tip': 500, 'tolls': 300},
    {'commission': 25, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 3050}),
  ('normal control 2',
   [{'booking_fee': 250, 'core': 1733, 'surge': 15, 'tip': 200, 'tolls': 300},
    {'commission': 20, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 2580}),
  ('normal control 3',
   [{'booking_fee': 0, 'core': 450, 'surge': 15, 'tip': 500, 'tolls': 300},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 1340}),
  ('normal control 4',
   [{'booking_fee': 0, 'core': 900, 'surge': 20, 'tip': 500, 'tolls': 300},
    {'commission': 20, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 2240})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(trip, plan):
    surged = (trip['core'] * trip['surge'] * 2 + 10) // 20
    share = surged * (100 - plan['commission']) // 100
    share = max(share, plan['min_pay'])
    pay = share + trip['tolls'] + trip['tip']
    n = plan['trips_before'] + 1
    bonus = 0
    for need, amount in plan['quests']:
        if plan['trips_before'] == need:
            bonus += amount
    return {'pay': pay, 'bonus': bonus}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: quest crossing',
   [{'booking_fee': 0, 'core': 900, 'surge': 15, 'tip': 0, 'tolls': 300},
    {'commission': 25, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 19}],
   {'bonus': 2500, 'pay': 1312}),
  ('partial repair probe: quest crossing',
   [{'booking_fee': 250, 'core': 900, 'surge': 10, 'tip': 200, 'tolls': 0},
    {'commission': 20, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 9}],
   {'bonus': 1500, 'pay': 920}),
  ('second regression',
   [{'booking_fee': 250, 'core': 2500, 'surge': 20, 'tip': 0, 'tolls': 0},
    {'commission': 25, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 20}],
   {'bonus': 0, 'pay': 3750}),
  ('normal control 1',
   [{'booking_fee': 250, 'core': 450, 'surge': 12, 'tip': 200, 'tolls': 300},
    {'commission': 25, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 1000}),
  ('normal control 2',
   [{'booking_fee': 0, 'core': 450, 'surge': 15, 'tip': 200, 'tolls': 0},
    {'commission': 25, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 706}),
  ('normal control 3',
   [{'booking_fee': 0, 'core': 1733, 'surge': 15, 'tip': 500, 'tolls': 0},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 2580}),
  ('normal control 4',
   [{'booking_fee': 0, 'core': 900, 'surge': 10, 'tip': 500, 'tolls': 300},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 1520})],
 [('regression: quest crossing',
   [{'booking_fee': 0, 'core': 900, 'surge': 10, 'tip': 0, 'tolls': 300},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 20}],
   {'bonus': 0, 'pay': 1020}),
  ('partial repair probe: quest crossing',
   [{'booking_fee': 250, 'core': 450, 'surge': 15, 'tip': 200, 'tolls': 0},
    {'commission': 25, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 24}],
   {'bonus': 1000, 'pay': 706}),
  ('second regression',
   [{'booking_fee': 250, 'core': 2500, 'surge': 12, 'tip': 0, 'tolls': 300},
    {'commission': 25, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 19}],
   {'bonus': 2500, 'pay': 2550}),
  ('normal control 1',
   [{'booking_fee': 0, 'core': 2500, 'surge': 20, 'tip': 500, 'tolls': 0},
    {'commission': 25, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 4250}),
  ('normal control 2',
   [{'booking_fee': 0, 'core': 450, 'surge': 10, 'tip': 500, 'tolls': 300},
    {'commission': 20, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 1300}),
  ('normal control 3',
   [{'booking_fee': 250, 'core': 2500, 'surge': 12, 'tip': 200, 'tolls': 300},
    {'commission': 20, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 2900}),
  ('normal control 4',
   [{'booking_fee': 250, 'core': 1733, 'surge': 15, 'tip': 0, 'tolls': 0},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 2080})],
 [('regression: quest crossing',
   [{'booking_fee': 0, 'core': 450, 'surge': 15, 'tip': 0, 'tolls': 0},
    {'commission': 20, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 24}],
   {'bonus': 1000, 'pay': 540}),
  ('partial repair probe: quest crossing',
   [{'booking_fee': 250, 'core': 1733, 'surge': 12, 'tip': 0, 'tolls': 300},
    {'commission': 20, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 9}],
   {'bonus': 1500, 'pay': 1964}),
  ('second regression',
   [{'booking_fee': 250, 'core': 450, 'surge': 15, 'tip': 500, 'tolls': 300},
    {'commission': 25, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 19}],
   {'bonus': 2500, 'pay': 1500}),
  ('normal control 1',
   [{'booking_fee': 0, 'core': 1733, 'surge': 12, 'tip': 500, 'tolls': 0},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 2164}),
  ('normal control 2',
   [{'booking_fee': 0, 'core': 450, 'surge': 20, 'tip': 0, 'tolls': 300},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 1020}),
  ('normal control 3',
   [{'booking_fee': 0, 'core': 1733, 'surge': 12, 'tip': 200, 'tolls': 300},
    {'commission': 20, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 2164}),
  ('normal control 4',
   [{'booking_fee': 250, 'core': 900, 'surge': 12, 'tip': 200, 'tolls': 0},
    {'commission': 25, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 1010})],
 [('regression: quest crossing',
   [{'booking_fee': 250, 'core': 1733, 'surge': 12, 'tip': 0, 'tolls': 0},
    {'commission': 25, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 10}],
   {'bonus': 0, 'pay': 1560}),
  ('partial repair probe: quest crossing',
   [{'booking_fee': 250, 'core': 1733, 'surge': 10, 'tip': 0, 'tolls': 300},
    {'commission': 20, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 24}],
   {'bonus': 1000, 'pay': 1686}),
  ('second regression',
   [{'booking_fee': 0, 'core': 1733, 'surge': 15, 'tip': 0, 'tolls': 0},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 9}],
   {'bonus': 1500, 'pay': 2080}),
  ('normal control 1',
   [{'booking_fee': 250, 'core': 1733, 'surge': 15, 'tip': 0, 'tolls': 300},
    {'commission': 25, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 2250}),
  ('normal control 2',
   [{'booking_fee': 250, 'core': 900, 'surge': 12, 'tip': 200, 'tolls': 300},
    {'commission': 25, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 1310}),
  ('normal control 3',
   [{'booking_fee': 250, 'core': 2500, 'surge': 12, 'tip': 500, 'tolls': 0},
    {'commission': 20, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 2900}),
  ('normal control 4',
   [{'booking_fee': 0, 'core': 2500, 'surge': 15, 'tip': 0, 'tolls': 300},
    {'commission': 25, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 3112})],
 [('regression: quest crossing',
   [{'booking_fee': 0, 'core': 450, 'surge': 10, 'tip': 200, 'tolls': 0},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 19}],
   {'bonus': 2500, 'pay': 600}),
  ('partial repair probe: quest crossing',
   [{'booking_fee': 250, 'core': 450, 'surge': 12, 'tip': 500, 'tolls': 0},
    {'commission': 20, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 24}],
   {'bonus': 1000, 'pay': 1000}),
  ('second regression',
   [{'booking_fee': 0, 'core': 450, 'surge': 20, 'tip': 0, 'tolls': 300},
    {'commission': 25, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 20}],
   {'bonus': 0, 'pay': 975}),
  ('normal control 1',
   [{'booking_fee': 250, 'core': 2500, 'surge': 12, 'tip': 500, 'tolls': 300},
    {'commission': 25, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 3050}),
  ('normal control 2',
   [{'booking_fee': 250, 'core': 1733, 'surge': 15, 'tip': 200, 'tolls': 300},
    {'commission': 20, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 2580}),
  ('normal control 3',
   [{'booking_fee': 0, 'core': 450, 'surge': 15, 'tip': 500, 'tolls': 300},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 1340}),
  ('normal control 4',
   [{'booking_fee': 0, 'core': 900, 'surge': 20, 'tip': 500, 'tolls': 300},
    {'commission': 20, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 2240})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
After the tenth trip each further trip repeats the 10-trip bonus.

Driver pay per trip in cents: the surged core fare (core x surge tenths, half up) minus the commission percentage (floored), raised to min_pay if lower; tolls and tips pass through untouched and are outside commission and the minimum; the booking fee is platform revenue. A quest bonus is paid when this trip is exactly the Nth trip for a quest threshold N (trips_before + 1 == N). Return pay and bonus.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(trip, plan):
    surged = (trip['core'] * trip['surge'] * 2 + 10) // 20
    share = (surged + trip['booking_fee']) * (100 - plan['commission']) // 100
    share = max(share, plan['min_pay'])
    pay = share + trip['tolls'] + trip['tip']
    n = plan['trips_before'] + 1
    bonus = 0
    for need, amount in plan['quests']:
        if n == need:
            bonus += amount
    return {'pay': pay, 'bonus': bonus}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: booking fee to driver',
   [{'booking_fee': 250, 'core': 450, 'surge': 20, 'tip': 500, 'tolls': 300},
    {'commission': 20, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 1520}),
  ('partial repair probe: booking fee to driver',
   [{'booking_fee': 250, 'core': 1733, 'surge': 15, 'tip': 500, 'tolls': 0},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 19}],
   {'bonus': 2500, 'pay': 2580}),
  ('second regression',
   [{'booking_fee': 250, 'core': 2500, 'surge': 15, 'tip': 0, 'tolls': 0},
    {'commission': 25, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 10}],
   {'bonus': 0, 'pay': 2812}),
  ('normal control 1',
   [{'booking_fee': 0, 'core': 450, 'surge': 15, 'tip': 500, 'tolls': 300},
    {'commission': 25, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 24}],
   {'bonus': 1000, 'pay': 1306}),
  ('normal control 2',
   [{'booking_fee': 0, 'core': 1733, 'surge': 12, 'tip': 500, 'tolls': 0},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 20}],
   {'bonus': 0, 'pay': 2164}),
  ('normal control 3',
   [{'booking_fee': 0, 'core': 900, 'surge': 12, 'tip': 500, 'tolls': 300},
    {'commission': 25, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 10}],
   {'bonus': 0, 'pay': 1610}),
  ('normal control 4',
   [{'booking_fee': 0, 'core': 900, 'surge': 15, 'tip': 0, 'tolls': 0},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 10}],
   {'bonus': 0, 'pay': 1080})],
 [('regression: booking fee to driver',
   [{'booking_fee': 250, 'core': 2500, 'surge': 20, 'tip': 500, 'tolls': 300},
    {'commission': 20, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 9}],
   {'bonus': 1500, 'pay': 4800}),
  ('partial repair probe: booking fee to driver',
   [{'booking_fee': 250, 'core': 450, 'surge': 12, 'tip': 500, 'tolls': 0},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 19}],
   {'bonus': 2500, 'pay': 932}),
  ('second regression',
   [{'booking_fee': 250, 'core': 1733, 'surge': 15, 'tip': 500, 'tolls': 0},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 19}],
   {'bonus': 2500, 'pay': 2580}),
  ('normal control 1',
   [{'booking_fee': 0, 'core': 450, 'surge': 20, 'tip': 0, 'tolls': 0},
    {'commission': 20, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 720}),
  ('normal control 2',
   [{'booking_fee': 0, 'core': 1733, 'surge': 12, 'tip': 200, 'tolls': 300},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 20}],
   {'bonus': 0, 'pay': 2164}),
  ('normal control 3',
   [{'booking_fee': 0, 'core': 2500, 'surge': 15, 'tip': 500, 'tolls': 0},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 24}],
   {'bonus': 1000, 'pay': 3500}),
  ('normal control 4',
   [{'booking_fee': 0, 'core': 2500, 'surge': 20, 'tip': 0, 'tolls': 0},
    {'commission': 25, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 9}],
   {'bonus': 1500, 'pay': 3750})],
 [('regression: booking fee to driver',
   [{'booking_fee': 250, 'core': 900, 'surge': 20, 'tip': 500, 'tolls': 0},
    {'commission': 25, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 24}],
   {'bonus': 1000, 'pay': 1850}),
  ('partial repair probe: booking fee to driver',
   [{'booking_fee': 250, 'core': 450, 'surge': 12, 'tip': 0, 'tolls': 0},
    {'commission': 25, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 405}),
  ('second regression',
   [{'booking_fee': 250, 'core': 450, 'surge': 20, 'tip': 0, 'tolls': 300},
    {'commission': 20, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 9}],
   {'bonus': 1500, 'pay': 1020}),
  ('normal control 1',
   [{'booking_fee': 0, 'core': 2500, 'surge': 20, 'tip': 200, 'tolls': 0},
    {'commission': 25, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 10}],
   {'bonus': 0, 'pay': 3950}),
  ('normal control 2',
   [{'booking_fee': 0, 'core': 1733, 'surge': 20, 'tip': 0, 'tolls': 0},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 24}],
   {'bonus': 1000, 'pay': 2772}),
  ('normal control 3',
   [{'booking_fee': 0, 'core': 2500, 'surge': 20, 'tip': 500, 'tolls': 0},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 9}],
   {'bonus': 1500, 'pay': 4500}),
  ('normal control 4',
   [{'booking_fee': 0, 'core': 1733, 'surge': 10, 'tip': 0, 'tolls': 0},
    {'commission': 20, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 20}],
   {'bonus': 0, 'pay': 1386})],
 [('regression: booking fee to driver',
   [{'booking_fee': 250, 'core': 1733, 'surge': 12, 'tip': 0, 'tolls': 0},
    {'commission': 25, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 9}],
   {'bonus': 1500, 'pay': 1560}),
  ('partial repair probe: booking fee to driver',
   [{'booking_fee': 250, 'core': 2500, 'surge': 10, 'tip': 0, 'tolls': 300},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 20}],
   {'bonus': 0, 'pay': 2300}),
  ('second regression',
   [{'booking_fee': 250, 'core': 1733, 'surge': 15, 'tip': 200, 'tolls': 0},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 10}],
   {'bonus': 0, 'pay': 2280}),
  ('normal control 1',
   [{'booking_fee': 0, 'core': 900, 'surge': 12, 'tip': 0, 'tolls': 0},
    {'commission': 20, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 19}],
   {'bonus': 2500, 'pay': 864}),
  ('normal control 2',
   [{'booking_fee': 0, 'core': 1733, 'surge': 12, 'tip': 200, 'tolls': 0},
    {'commission': 20, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 1864}),
  ('normal control 3',
   [{'booking_fee': 0, 'core': 450, 'surge': 20, 'tip': 0, 'tolls': 0},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 720}),
  ('normal control 4',
   [{'booking_fee': 0, 'core': 450, 'surge': 15, 'tip': 0, 'tolls': 0},
    {'commission': 25, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 19}],
   {'bonus': 2500, 'pay': 506})],
 [('regression: booking fee to driver',
   [{'booking_fee': 250, 'core': 450, 'surge': 15, 'tip': 0, 'tolls': 0},
    {'commission': 25, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 20}],
   {'bonus': 0, 'pay': 506}),
  ('partial repair probe: booking fee to driver',
   [{'booking_fee': 250, 'core': 900, 'surge': 10, 'tip': 0, 'tolls': 300},
    {'commission': 20, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 19}],
   {'bonus': 2500, 'pay': 1020}),
  ('second regression',
   [{'booking_fee': 250, 'core': 900, 'surge': 20, 'tip': 0, 'tolls': 300},
    {'commission': 25, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 1650}),
  ('normal control 1',
   [{'booking_fee': 0, 'core': 1733, 'surge': 15, 'tip': 500, 'tolls': 300},
    {'commission': 25, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 20}],
   {'bonus': 0, 'pay': 2750}),
  ('normal control 2',
   [{'booking_fee': 0, 'core': 2500, 'surge': 10, 'tip': 200, 'tolls': 0},
    {'commission': 20, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 9}],
   {'bonus': 1500, 'pay': 2200}),
  ('normal control 3',
   [{'booking_fee': 0, 'core': 2500, 'surge': 12, 'tip': 500, 'tolls': 0},
    {'commission': 20, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 9}],
   {'bonus': 1500, 'pay': 2900}),
  ('normal control 4',
   [{'booking_fee': 0, 'core': 450, 'surge': 15, 'tip': 200, 'tolls': 300},
    {'commission': 20, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 10}],
   {'bonus': 0, 'pay': 1040})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(trip, plan):
    surged = (trip['core'] * trip['surge'] * 2 + 10) // 20
    share = surged * (100 - plan['commission']) // 100 + trip['booking_fee'] // 4
    share = max(share, plan['min_pay'])
    pay = share + trip['tolls'] + trip['tip']
    n = plan['trips_before'] + 1
    bonus = 0
    for need, amount in plan['quests']:
        if n == need:
            bonus += amount
    return {'pay': pay, 'bonus': bonus}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: booking fee to driver',
   [{'booking_fee': 250, 'core': 450, 'surge': 20, 'tip': 500, 'tolls': 300},
    {'commission': 20, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 1520}),
  ('partial repair probe: booking fee to driver',
   [{'booking_fee': 250, 'core': 1733, 'surge': 15, 'tip': 500, 'tolls': 0},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 19}],
   {'bonus': 2500, 'pay': 2580}),
  ('second regression',
   [{'booking_fee': 250, 'core': 2500, 'surge': 15, 'tip': 0, 'tolls': 0},
    {'commission': 25, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 10}],
   {'bonus': 0, 'pay': 2812}),
  ('normal control 1',
   [{'booking_fee': 0, 'core': 450, 'surge': 15, 'tip': 500, 'tolls': 300},
    {'commission': 25, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 24}],
   {'bonus': 1000, 'pay': 1306}),
  ('normal control 2',
   [{'booking_fee': 0, 'core': 1733, 'surge': 12, 'tip': 500, 'tolls': 0},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 20}],
   {'bonus': 0, 'pay': 2164}),
  ('normal control 3',
   [{'booking_fee': 0, 'core': 900, 'surge': 12, 'tip': 500, 'tolls': 300},
    {'commission': 25, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 10}],
   {'bonus': 0, 'pay': 1610}),
  ('normal control 4',
   [{'booking_fee': 0, 'core': 900, 'surge': 15, 'tip': 0, 'tolls': 0},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 10}],
   {'bonus': 0, 'pay': 1080})],
 [('regression: booking fee to driver',
   [{'booking_fee': 250, 'core': 2500, 'surge': 20, 'tip': 500, 'tolls': 300},
    {'commission': 20, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 9}],
   {'bonus': 1500, 'pay': 4800}),
  ('partial repair probe: booking fee to driver',
   [{'booking_fee': 250, 'core': 450, 'surge': 12, 'tip': 500, 'tolls': 0},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 19}],
   {'bonus': 2500, 'pay': 932}),
  ('second regression',
   [{'booking_fee': 250, 'core': 1733, 'surge': 15, 'tip': 500, 'tolls': 0},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 19}],
   {'bonus': 2500, 'pay': 2580}),
  ('normal control 1',
   [{'booking_fee': 0, 'core': 450, 'surge': 20, 'tip': 0, 'tolls': 0},
    {'commission': 20, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 720}),
  ('normal control 2',
   [{'booking_fee': 0, 'core': 1733, 'surge': 12, 'tip': 200, 'tolls': 300},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 20}],
   {'bonus': 0, 'pay': 2164}),
  ('normal control 3',
   [{'booking_fee': 0, 'core': 2500, 'surge': 15, 'tip': 500, 'tolls': 0},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 24}],
   {'bonus': 1000, 'pay': 3500}),
  ('normal control 4',
   [{'booking_fee': 0, 'core': 2500, 'surge': 20, 'tip': 0, 'tolls': 0},
    {'commission': 25, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 9}],
   {'bonus': 1500, 'pay': 3750})],
 [('regression: booking fee to driver',
   [{'booking_fee': 250, 'core': 900, 'surge': 20, 'tip': 500, 'tolls': 0},
    {'commission': 25, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 24}],
   {'bonus': 1000, 'pay': 1850}),
  ('partial repair probe: booking fee to driver',
   [{'booking_fee': 250, 'core': 450, 'surge': 12, 'tip': 0, 'tolls': 0},
    {'commission': 25, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 405}),
  ('second regression',
   [{'booking_fee': 250, 'core': 450, 'surge': 20, 'tip': 0, 'tolls': 300},
    {'commission': 20, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 9}],
   {'bonus': 1500, 'pay': 1020}),
  ('normal control 1',
   [{'booking_fee': 0, 'core': 2500, 'surge': 20, 'tip': 200, 'tolls': 0},
    {'commission': 25, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 10}],
   {'bonus': 0, 'pay': 3950}),
  ('normal control 2',
   [{'booking_fee': 0, 'core': 1733, 'surge': 20, 'tip': 0, 'tolls': 0},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 24}],
   {'bonus': 1000, 'pay': 2772}),
  ('normal control 3',
   [{'booking_fee': 0, 'core': 2500, 'surge': 20, 'tip': 500, 'tolls': 0},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 9}],
   {'bonus': 1500, 'pay': 4500}),
  ('normal control 4',
   [{'booking_fee': 0, 'core': 1733, 'surge': 10, 'tip': 0, 'tolls': 0},
    {'commission': 20, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 20}],
   {'bonus': 0, 'pay': 1386})],
 [('regression: booking fee to driver',
   [{'booking_fee': 250, 'core': 1733, 'surge': 12, 'tip': 0, 'tolls': 0},
    {'commission': 25, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 9}],
   {'bonus': 1500, 'pay': 1560}),
  ('partial repair probe: booking fee to driver',
   [{'booking_fee': 250, 'core': 2500, 'surge': 10, 'tip': 0, 'tolls': 300},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 20}],
   {'bonus': 0, 'pay': 2300}),
  ('second regression',
   [{'booking_fee': 250, 'core': 1733, 'surge': 15, 'tip': 200, 'tolls': 0},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 10}],
   {'bonus': 0, 'pay': 2280}),
  ('normal control 1',
   [{'booking_fee': 0, 'core': 900, 'surge': 12, 'tip': 0, 'tolls': 0},
    {'commission': 20, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 19}],
   {'bonus': 2500, 'pay': 864}),
  ('normal control 2',
   [{'booking_fee': 0, 'core': 1733, 'surge': 12, 'tip': 200, 'tolls': 0},
    {'commission': 20, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 1864}),
  ('normal control 3',
   [{'booking_fee': 0, 'core': 450, 'surge': 20, 'tip': 0, 'tolls': 0},
    {'commission': 20, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 720}),
  ('normal control 4',
   [{'booking_fee': 0, 'core': 450, 'surge': 15, 'tip': 0, 'tolls': 0},
    {'commission': 25, 'min_pay': 400, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 19}],
   {'bonus': 2500, 'pay': 506})],
 [('regression: booking fee to driver',
   [{'booking_fee': 250, 'core': 450, 'surge': 15, 'tip': 0, 'tolls': 0},
    {'commission': 25, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 20}],
   {'bonus': 0, 'pay': 506}),
  ('partial repair probe: booking fee to driver',
   [{'booking_fee': 250, 'core': 900, 'surge': 10, 'tip': 0, 'tolls': 300},
    {'commission': 20, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 19}],
   {'bonus': 2500, 'pay': 1020}),
  ('second regression',
   [{'booking_fee': 250, 'core': 900, 'surge': 20, 'tip': 0, 'tolls': 300},
    {'commission': 25, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 3}],
   {'bonus': 0, 'pay': 1650}),
  ('normal control 1',
   [{'booking_fee': 0, 'core': 1733, 'surge': 15, 'tip': 500, 'tolls': 300},
    {'commission': 25, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 20}],
   {'bonus': 0, 'pay': 2750}),
  ('normal control 2',
   [{'booking_fee': 0, 'core': 2500, 'surge': 10, 'tip': 200, 'tolls': 0},
    {'commission': 20, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 9}],
   {'bonus': 1500, 'pay': 2200}),
  ('normal control 3',
   [{'booking_fee': 0, 'core': 2500, 'surge': 12, 'tip': 500, 'tolls': 0},
    {'commission': 20, 'min_pay': 700, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 9}],
   {'bonus': 1500, 'pay': 2900}),
  ('normal control 4',
   [{'booking_fee': 0, 'core': 450, 'surge': 15, 'tip': 200, 'tolls': 300},
    {'commission': 20, 'min_pay': 500, 'quests': [[10, 1500], [20, 2500], [25, 1000]], 'trips_before': 10}],
   {'bonus': 0, 'pay': 1040})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Driver pay rises by most of the booking fee on every trip.

Driver pay per trip in cents: the surged core fare (core x surge tenths, half up) minus the commission percentage (floored), raised to min_pay if lower; tolls and tips pass through untouched and are outside commission and the minimum; the booking fee is platform revenue. A quest bonus is paid when this trip is exactly the Nth trip for a quest threshold N (trips_before + 1 == N). Return pay and bonus.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(promo, ride, now_day):
    reason = None
    if now_day >= promo['expires_day']:
        reason = 'expired'
    elif promo['uses_left'] <= 0:
        reason = 'exhausted'
    elif promo['first_ride_only'] and ride['rider_rides'] > 0:
        reason = 'not_first'
    elif ride['fare'] < promo['min_fare']:
        reason = 'min_fare'
    disc = 0
    if reason is None:
        if promo['kind'] == 'pct':
            disc = ride['fare'] * promo['value'] // 100
            if promo['cap'] is not None:
                disc = min(disc, promo['cap'])
        else:
            disc = min(promo['value'], ride['fare'])
    credit = min(ride['credits'], ride['fare'] - disc)
    return {'discount': disc, 'credit_used': credit, 'due': ride['fare'] - disc - credit, 'reason': reason}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: expiry day inclusive',
   [{'cap': None,
     'expires_day': 100,
     'first_ride_only': True,
     'kind': 'flat',
     'min_fare': 1050,
     'uses_left': 1,
     'value': 1000},
    {'credits': 5000, 'fare': 1050, 'rider_rides': 0}, 100],
   {'credit_used': 50, 'discount': 1000, 'due': 0, 'reason': None}),
  ('partial repair probe: expiry day inclusive',
   [{'cap': 800,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'flat',
     'min_fare': 1000,
     'uses_left': 0,
     'value': 2500},
    {'credits': 0, 'fare': 1050, 'rider_rides': 1}, 100],
   {'credit_used': 0, 'discount': 0, 'due': 1050, 'reason': 'exhausted'}),
  ('second regression',
   [{'cap': 800,
     'expires_day': 100,
     'first_ride_only': True,
     'kind': 'flat',
     'min_fare': 1000,
     'uses_left': 3,
     'value': 500},
    {'credits': 5000, 'fare': 3315, 'rider_rides': 1}, 100],
   {'credit_used': 3315, 'discount': 0, 'due': 0, 'reason': 'not_first'}),
  ('normal control 1',
   [{'cap': 800,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'pct',
     'min_fare': 1050,
     'uses_left': 0,
     'value': 25},
    {'credits': 0, 'fare': 3279, 'rider_rides': 0}, 101],
   {'credit_used': 0, 'discount': 0, 'due': 3279, 'reason': 'expired'}),
  ('normal control 2',
   [{'cap': None,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'flat',
     'min_fare': 1050,
     'uses_left': 3,
     'value': 1000},
    {'credits': 5000, 'fare': 700, 'rider_rides': 5}, 101],
   {'credit_used': 700, 'discount': 0, 'due': 0, 'reason': 'expired'}),
  ('normal control 3',
   [{'cap': 300,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'flat',
     'min_fare': 1000,
     'uses_left': 0,
     'value': 1000},
    {'credits': 5000, 'fare': 700, 'rider_rides': 1}, 101],
   {'credit_used': 700, 'discount': 0, 'due': 0, 'reason': 'expired'}),
  ('normal control 4',
   [{'cap': 300,
     'expires_day': 100,
     'first_ride_only': True,
     'kind': 'flat',
     'min_fare': 1050,
     'uses_left': 1,
     'value': 500},
    {'credits': 5000, 'fare': 2400, 'rider_rides': 1}, 101],
   {'credit_used': 2400, 'discount': 0, 'due': 0, 'reason': 'expired'})],
 [('regression: expiry day inclusive',
   [{'cap': 0,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'flat',
     'min_fare': 0,
     'uses_left': 0,
     'value': 2500},
    {'credits': 250, 'fare': 1000, 'rider_rides': 5}, 100],
   {'credit_used': 250, 'discount': 0, 'due': 750, 'reason': 'exhausted'}),
  ('partial repair probe: expiry day inclusive',
   [{'cap': 0,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'flat',
     'min_fare': 1050,
     'uses_left': 0,
     'value': 2500},
    {'credits': 250, 'fare': 1099, 'rider_rides': 0}, 100],
   {'credit_used': 250, 'discount': 0, 'due': 849, 'reason': 'exhausted'}),
  ('second regression',
   [{'cap': 0,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'pct',
     'min_fare': 1050,
     'uses_left': 0,
     'value': 25},
    {'credits': 0, 'fare': 1000, 'rider_rides': 0}, 100],
   {'credit_used': 0, 'discount': 0, 'due': 1000, 'reason': 'exhausted'}),
  ('normal control 1',
   [{'cap': 300,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'flat',
     'min_fare': 0,
     'uses_left': 3,
     'value': 2500},
    {'credits': 0, 'fare': 1000, 'rider_rides': 5}, 101],
   {'credit_used': 0, 'discount': 0, 'due': 1000, 'reason': 'expired'}),
  ('normal control 2',
   [{'cap': 0,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'flat',
     'min_fare': 1000,
     'uses_left': 1,
     'value': 1000},
    {'credits': 0, 'fare': 1000, 'rider_rides': 5}, 101],
   {'credit_used': 0, 'discount': 0, 'due': 1000, 'reason': 'expired'}),
  ('normal control 3',
   [{'cap': 300,
     'expires_day': 100,
     'first_ride_only': True,
     'kind': 'flat',
     'min_fare': 0,
     'uses_left': 0,
     'value': 1000},
    {'credits': 0, 'fare': 1099, 'rider_rides': 1}, 101],
   {'credit_used': 0, 'discount': 0, 'due': 1099, 'reason': 'expired'}),
  ('normal control 4',
   [{'cap': 800,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'flat',
     'min_fare': 0,
     'uses_left': 1,
     'value': 1000},
    {'credits': 5000, 'fare': 3865, 'rider_rides': 5}, 101],
   {'credit_used': 3865, 'discount': 0, 'due': 0, 'reason': 'expired'})],
 [('regression: expiry day inclusive',
   [{'cap': 0,
     'expires_day': 100,
     'first_ride_only': True,
     'kind': 'flat',
     'min_fare': 0,
     'uses_left': 1,
     'value': 2500},
    {'credits': 5000, 'fare': 3055, 'rider_rides': 0}, 100],
   {'credit_used': 555, 'discount': 2500, 'due': 0, 'reason': None}),
  ('partial repair probe: expiry day inclusive',
   [{'cap': 300,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'flat',
     'min_fare': 0,
     'uses_left': 1,
     'value': 2500},
    {'credits': 0, 'fare': 1099, 'rider_rides': 1}, 99],
   {'credit_used': 0, 'discount': 1099, 'due': 0, 'reason': None}),
  ('second regression',
   [{'cap': 800,
     'expires_day': 100,
     'first_ride_only': True,
     'kind': 'pct',
     'min_fare': 1000,
     'uses_left': 0,
     'value': 10},
    {'credits': 0, 'fare': 700, 'rider_rides': 0}, 100],
   {'credit_used': 0, 'discount': 0, 'due': 700, 'reason': 'exhausted'}),
  ('normal control 1',
   [{'cap': 300,
     'expires_day': 100,
     'first_ride_only': True,
     'kind': 'pct',
     'min_fare': 1000,
     'uses_left': 1,
     'value': 10},
    {'credits': 250, 'fare': 2400, 'rider_rides': 5}, 101],
   {'credit_used': 250, 'discount': 0, 'due': 2150, 'reason': 'expired'}),
  ('normal control 2',
   [{'cap': None,
     'expires_day': 100,
     'first_ride_only': True,
     'kind': 'flat',
     'min_fare': 0,
     'uses_left': 1,
     'value': 500},
    {'credits': 0, 'fare': 1000, 'rider_rides': 0}, 101],
   {'credit_used': 0, 'discount': 0, 'due': 1000, 'reason': 'expired'}),
  ('normal control 3',
   [{'cap': None,
     'expires_day': 100,
     'first_ride_only': True,
     'kind': 'pct',
     'min_fare': 0,
     'uses_left': 1,
     'value': 10},
    {'credits': 5000, 'fare': 1050, 'rider_rides': 1}, 101],
   {'credit_used': 1050, 'discount': 0, 'due': 0, 'reason': 'expired'}),
  ('normal control 4',
   [{'cap': 800,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'flat',
     'min_fare': 0,
     'uses_left': 0,
     'value': 2500},
    {'credits': 5000, 'fare': 1000, 'rider_rides': 1}, 101],
   {'credit_used': 1000, 'discount': 0, 'due': 0, 'reason': 'expired'})],
 [('regression: expiry day inclusive',
   [{'cap': 0,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'flat',
     'min_fare': 1050,
     'uses_left': 1,
     'value': 2500},
    {'credits': 0, 'fare': 2400, 'rider_rides': 5}, 100],
   {'credit_used': 0, 'discount': 2400, 'due': 0, 'reason': None}),
  ('partial repair probe: expiry day inclusive',
   [{'cap': 800,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'pct',
     'min_fare': 1050,
     'uses_left': 0,
     'value': 25},
    {'credits': 0, 'fare': 700, 'rider_rides': 0}, 99],
   {'credit_used': 0, 'discount': 0, 'due': 700, 'reason': 'exhausted'}),
  ('second regression',
   [{'cap': None,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'flat',
     'min_fare': 1000,
     'uses_left': 1,
     'value': 500},
    {'credits': 0, 'fare': 2400, 'rider_rides': 0}, 100],
   {'credit_used': 0, 'discount': 500, 'due': 1900, 'reason': None}),
  ('normal control 1',
   [{'cap': None,
     'expires_day': 100,
     'first_ride_only': True,
     'kind': 'pct',
     'min_fare': 0,
     'uses_left': 1,
     'value': 50},
    {'credits': 5000, 'fare': 1099, 'rider_rides': 0}, 101],
   {'credit_used': 1099, 'discount': 0, 'due': 0, 'reason': 'expired'}),
  ('normal control 2',
   [{'cap': None,
     'expires_day': 100,
     'first_ride_only': True,
     'kind': 'flat',
     'min_fare': 1050,
     'uses_left': 1,
     'value': 500},
    {'credits': 5000, 'fare': 1318, 'rider_rides': 0}, 101],
   {'credit_used': 1318, 'discount': 0, 'due': 0, 'reason': 'expired'}),
  ('normal control 3',
   [{'cap': 300,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'pct',
     'min_fare': 0,
     'uses_left': 0,
     'value': 10},
    {'credits': 0, 'fare': 2400, 'rider_rides': 0}, 101],
   {'credit_used': 0, 'discount': 0, 'due': 2400, 'reason': 'expired'}),
  ('normal control 4',
   [{'cap': 800,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'pct',
     'min_fare': 0,
     'uses_left': 3,
     'value': 10},
    {'credits': 0, 'fare': 2400, 'rider_rides': 5}, 101],
   {'credit_used': 0, 'discount': 0, 'due': 2400, 'reason': 'expired'})],
 [('regression: expiry day inclusive',
   [{'cap': 800,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'pct',
     'min_fare': 1050,
     'uses_left': 1,
     'value': 50},
    {'credits': 5000, 'fare': 1050, 'rider_rides': 1}, 100],
   {'credit_used': 525, 'discount': 525, 'due': 0, 'reason': None}),
  ('partial repair probe: expiry day inclusive',
   [{'cap': None,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'pct',
     'min_fare': 0,
     'uses_left': 1,
     'value': 50},
    {'credits': 5000, 'fare': 2400, 'rider_rides': 1}, 99],
   {'credit_used': 1200, 'discount': 1200, 'due': 0, 'reason': None}),
  ('second regression',
   [{'cap': None,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'pct',
     'min_fare': 1050,
     'uses_left': 3,
     'value': 10},
    {'credits': 0, 'fare': 2400, 'rider_rides': 0}, 100],
   {'credit_used': 0, 'discount': 240, 'due': 2160, 'reason': None}),
  ('normal control 1',
   [{'cap': None,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'flat',
     'min_fare': 1050,
     'uses_left': 1,
     'value': 500},
    {'credits': 5000, 'fare': 1000, 'rider_rides': 1}, 101],
   {'credit_used': 1000, 'discount': 0, 'due': 0, 'reason': 'expired'}),
  ('normal control 2',
   [{'cap': 0,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'flat',
     'min_fare': 0,
     'uses_left': 0,
     'value': 2500},
    {'credits': 0, 'fare': 2400, 'rider_rides': 0}, 101],
   {'credit_used': 0, 'discount': 0, 'due': 2400, 'reason': 'expired'}),
  ('normal control 3',
   [{'cap': 300,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'pct',
     'min_fare': 1050,
     'uses_left': 1,
     'value': 10},
    {'credits': 0, 'fare': 1000, 'rider_rides': 1}, 101],
   {'credit_used': 0, 'discount': 0, 'due': 1000, 'reason': 'expired'}),
  ('normal control 4',
   [{'cap': 800,
     'expires_day': 100,
     'first_ride_only': True,
     'kind': 'flat',
     'min_fare': 1000,
     'uses_left': 3,
     'value': 1000},
    {'credits': 5000, 'fare': 1050, 'rider_rides': 5}, 101],
   {'credit_used': 1050, 'discount': 0, 'due': 0, 'reason': 'expired'})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(promo, ride, now_day):
    reason = None
    if now_day * 86400 > promo['expires_day']:
        reason = 'expired'
    elif promo['uses_left'] <= 0:
        reason = 'exhausted'
    elif promo['first_ride_only'] and ride['rider_rides'] > 0:
        reason = 'not_first'
    elif ride['fare'] < promo['min_fare']:
        reason = 'min_fare'
    disc = 0
    if reason is None:
        if promo['kind'] == 'pct':
            disc = ride['fare'] * promo['value'] // 100
            if promo['cap'] is not None:
                disc = min(disc, promo['cap'])
        else:
            disc = min(promo['value'], ride['fare'])
    credit = min(ride['credits'], ride['fare'] - disc)
    return {'discount': disc, 'credit_used': credit, 'due': ride['fare'] - disc - credit, 'reason': reason}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: expiry day inclusive',
   [{'cap': None,
     'expires_day': 100,
     'first_ride_only': True,
     'kind': 'flat',
     'min_fare': 1050,
     'uses_left': 1,
     'value': 1000},
    {'credits': 5000, 'fare': 1050, 'rider_rides': 0}, 100],
   {'credit_used': 50, 'discount': 1000, 'due': 0, 'reason': None}),
  ('partial repair probe: expiry day inclusive',
   [{'cap': 800,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'flat',
     'min_fare': 1000,
     'uses_left': 0,
     'value': 2500},
    {'credits': 0, 'fare': 1050, 'rider_rides': 1}, 100],
   {'credit_used': 0, 'discount': 0, 'due': 1050, 'reason': 'exhausted'}),
  ('second regression',
   [{'cap': 800,
     'expires_day': 100,
     'first_ride_only': True,
     'kind': 'flat',
     'min_fare': 1000,
     'uses_left': 3,
     'value': 500},
    {'credits': 5000, 'fare': 3315, 'rider_rides': 1}, 100],
   {'credit_used': 3315, 'discount': 0, 'due': 0, 'reason': 'not_first'}),
  ('normal control 1',
   [{'cap': 800,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'pct',
     'min_fare': 1050,
     'uses_left': 0,
     'value': 25},
    {'credits': 0, 'fare': 3279, 'rider_rides': 0}, 101],
   {'credit_used': 0, 'discount': 0, 'due': 3279, 'reason': 'expired'}),
  ('normal control 2',
   [{'cap': None,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'flat',
     'min_fare': 1050,
     'uses_left': 3,
     'value': 1000},
    {'credits': 5000, 'fare': 700, 'rider_rides': 5}, 101],
   {'credit_used': 700, 'discount': 0, 'due': 0, 'reason': 'expired'}),
  ('normal control 3',
   [{'cap': 300,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'flat',
     'min_fare': 1000,
     'uses_left': 0,
     'value': 1000},
    {'credits': 5000, 'fare': 700, 'rider_rides': 1}, 101],
   {'credit_used': 700, 'discount': 0, 'due': 0, 'reason': 'expired'}),
  ('normal control 4',
   [{'cap': 300,
     'expires_day': 100,
     'first_ride_only': True,
     'kind': 'flat',
     'min_fare': 1050,
     'uses_left': 1,
     'value': 500},
    {'credits': 5000, 'fare': 2400, 'rider_rides': 1}, 101],
   {'credit_used': 2400, 'discount': 0, 'due': 0, 'reason': 'expired'})],
 [('regression: expiry day inclusive',
   [{'cap': 0,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'flat',
     'min_fare': 0,
     'uses_left': 0,
     'value': 2500},
    {'credits': 250, 'fare': 1000, 'rider_rides': 5}, 100],
   {'credit_used': 250, 'discount': 0, 'due': 750, 'reason': 'exhausted'}),
  ('partial repair probe: expiry day inclusive',
   [{'cap': 0,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'flat',
     'min_fare': 1050,
     'uses_left': 0,
     'value': 2500},
    {'credits': 250, 'fare': 1099, 'rider_rides': 0}, 100],
   {'credit_used': 250, 'discount': 0, 'due': 849, 'reason': 'exhausted'}),
  ('second regression',
   [{'cap': 0,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'pct',
     'min_fare': 1050,
     'uses_left': 0,
     'value': 25},
    {'credits': 0, 'fare': 1000, 'rider_rides': 0}, 100],
   {'credit_used': 0, 'discount': 0, 'due': 1000, 'reason': 'exhausted'}),
  ('normal control 1',
   [{'cap': 300,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'flat',
     'min_fare': 0,
     'uses_left': 3,
     'value': 2500},
    {'credits': 0, 'fare': 1000, 'rider_rides': 5}, 101],
   {'credit_used': 0, 'discount': 0, 'due': 1000, 'reason': 'expired'}),
  ('normal control 2',
   [{'cap': 0,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'flat',
     'min_fare': 1000,
     'uses_left': 1,
     'value': 1000},
    {'credits': 0, 'fare': 1000, 'rider_rides': 5}, 101],
   {'credit_used': 0, 'discount': 0, 'due': 1000, 'reason': 'expired'}),
  ('normal control 3',
   [{'cap': 300,
     'expires_day': 100,
     'first_ride_only': True,
     'kind': 'flat',
     'min_fare': 0,
     'uses_left': 0,
     'value': 1000},
    {'credits': 0, 'fare': 1099, 'rider_rides': 1}, 101],
   {'credit_used': 0, 'discount': 0, 'due': 1099, 'reason': 'expired'}),
  ('normal control 4',
   [{'cap': 800,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'flat',
     'min_fare': 0,
     'uses_left': 1,
     'value': 1000},
    {'credits': 5000, 'fare': 3865, 'rider_rides': 5}, 101],
   {'credit_used': 3865, 'discount': 0, 'due': 0, 'reason': 'expired'})],
 [('regression: expiry day inclusive',
   [{'cap': 0,
     'expires_day': 100,
     'first_ride_only': True,
     'kind': 'flat',
     'min_fare': 0,
     'uses_left': 1,
     'value': 2500},
    {'credits': 5000, 'fare': 3055, 'rider_rides': 0}, 100],
   {'credit_used': 555, 'discount': 2500, 'due': 0, 'reason': None}),
  ('partial repair probe: expiry day inclusive',
   [{'cap': 300,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'flat',
     'min_fare': 0,
     'uses_left': 1,
     'value': 2500},
    {'credits': 0, 'fare': 1099, 'rider_rides': 1}, 99],
   {'credit_used': 0, 'discount': 1099, 'due': 0, 'reason': None}),
  ('second regression',
   [{'cap': 800,
     'expires_day': 100,
     'first_ride_only': True,
     'kind': 'pct',
     'min_fare': 1000,
     'uses_left': 0,
     'value': 10},
    {'credits': 0, 'fare': 700, 'rider_rides': 0}, 100],
   {'credit_used': 0, 'discount': 0, 'due': 700, 'reason': 'exhausted'}),
  ('normal control 1',
   [{'cap': 300,
     'expires_day': 100,
     'first_ride_only': True,
     'kind': 'pct',
     'min_fare': 1000,
     'uses_left': 1,
     'value': 10},
    {'credits': 250, 'fare': 2400, 'rider_rides': 5}, 101],
   {'credit_used': 250, 'discount': 0, 'due': 2150, 'reason': 'expired'}),
  ('normal control 2',
   [{'cap': None,
     'expires_day': 100,
     'first_ride_only': True,
     'kind': 'flat',
     'min_fare': 0,
     'uses_left': 1,
     'value': 500},
    {'credits': 0, 'fare': 1000, 'rider_rides': 0}, 101],
   {'credit_used': 0, 'discount': 0, 'due': 1000, 'reason': 'expired'}),
  ('normal control 3',
   [{'cap': None,
     'expires_day': 100,
     'first_ride_only': True,
     'kind': 'pct',
     'min_fare': 0,
     'uses_left': 1,
     'value': 10},
    {'credits': 5000, 'fare': 1050, 'rider_rides': 1}, 101],
   {'credit_used': 1050, 'discount': 0, 'due': 0, 'reason': 'expired'}),
  ('normal control 4',
   [{'cap': 800,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'flat',
     'min_fare': 0,
     'uses_left': 0,
     'value': 2500},
    {'credits': 5000, 'fare': 1000, 'rider_rides': 1}, 101],
   {'credit_used': 1000, 'discount': 0, 'due': 0, 'reason': 'expired'})],
 [('regression: expiry day inclusive',
   [{'cap': 0,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'flat',
     'min_fare': 1050,
     'uses_left': 1,
     'value': 2500},
    {'credits': 0, 'fare': 2400, 'rider_rides': 5}, 100],
   {'credit_used': 0, 'discount': 2400, 'due': 0, 'reason': None}),
  ('partial repair probe: expiry day inclusive',
   [{'cap': 800,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'pct',
     'min_fare': 1050,
     'uses_left': 0,
     'value': 25},
    {'credits': 0, 'fare': 700, 'rider_rides': 0}, 99],
   {'credit_used': 0, 'discount': 0, 'due': 700, 'reason': 'exhausted'}),
  ('second regression',
   [{'cap': None,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'flat',
     'min_fare': 1000,
     'uses_left': 1,
     'value': 500},
    {'credits': 0, 'fare': 2400, 'rider_rides': 0}, 100],
   {'credit_used': 0, 'discount': 500, 'due': 1900, 'reason': None}),
  ('normal control 1',
   [{'cap': None,
     'expires_day': 100,
     'first_ride_only': True,
     'kind': 'pct',
     'min_fare': 0,
     'uses_left': 1,
     'value': 50},
    {'credits': 5000, 'fare': 1099, 'rider_rides': 0}, 101],
   {'credit_used': 1099, 'discount': 0, 'due': 0, 'reason': 'expired'}),
  ('normal control 2',
   [{'cap': None,
     'expires_day': 100,
     'first_ride_only': True,
     'kind': 'flat',
     'min_fare': 1050,
     'uses_left': 1,
     'value': 500},
    {'credits': 5000, 'fare': 1318, 'rider_rides': 0}, 101],
   {'credit_used': 1318, 'discount': 0, 'due': 0, 'reason': 'expired'}),
  ('normal control 3',
   [{'cap': 300,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'pct',
     'min_fare': 0,
     'uses_left': 0,
     'value': 10},
    {'credits': 0, 'fare': 2400, 'rider_rides': 0}, 101],
   {'credit_used': 0, 'discount': 0, 'due': 2400, 'reason': 'expired'}),
  ('normal control 4',
   [{'cap': 800,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'pct',
     'min_fare': 0,
     'uses_left': 3,
     'value': 10},
    {'credits': 0, 'fare': 2400, 'rider_rides': 5}, 101],
   {'credit_used': 0, 'discount': 0, 'due': 2400, 'reason': 'expired'})],
 [('regression: expiry day inclusive',
   [{'cap': 800,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'pct',
     'min_fare': 1050,
     'uses_left': 1,
     'value': 50},
    {'credits': 5000, 'fare': 1050, 'rider_rides': 1}, 100],
   {'credit_used': 525, 'discount': 525, 'due': 0, 'reason': None}),
  ('partial repair probe: expiry day inclusive',
   [{'cap': None,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'pct',
     'min_fare': 0,
     'uses_left': 1,
     'value': 50},
    {'credits': 5000, 'fare': 2400, 'rider_rides': 1}, 99],
   {'credit_used': 1200, 'discount': 1200, 'due': 0, 'reason': None}),
  ('second regression',
   [{'cap': None,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'pct',
     'min_fare': 1050,
     'uses_left': 3,
     'value': 10},
    {'credits': 0, 'fare': 2400, 'rider_rides': 0}, 100],
   {'credit_used': 0, 'discount': 240, 'due': 2160, 'reason': None}),
  ('normal control 1',
   [{'cap': None,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'flat',
     'min_fare': 1050,
     'uses_left': 1,
     'value': 500},
    {'credits': 5000, 'fare': 1000, 'rider_rides': 1}, 101],
   {'credit_used': 1000, 'discount': 0, 'due': 0, 'reason': 'expired'}),
  ('normal control 2',
   [{'cap': 0,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'flat',
     'min_fare': 0,
     'uses_left': 0,
     'value': 2500},
    {'credits': 0, 'fare': 2400, 'rider_rides': 0}, 101],
   {'credit_used': 0, 'discount': 0, 'due': 2400, 'reason': 'expired'}),
  ('normal control 3',
   [{'cap': 300,
     'expires_day': 100,
     'first_ride_only': False,
     'kind': 'pct',
     'min_fare': 1050,
     'uses_left': 1,
     'value': 10},
    {'credits': 0, 'fare': 1000, 'rider_rides': 1}, 101],
   {'credit_used': 0, 'discount': 0, 'due': 1000, 'reason': 'expired'}),
  ('normal control 4',
   [{'cap': 800,
     'expires_day': 100,
     'first_ride_only': True,
     'kind': 'flat',
     'min_fare': 1000,
     'uses_left': 3,
     'value': 1000},
    {'credits': 5000, 'fare': 1050, 'rider_rides': 5}, 101],
   {'credit_used': 1050, 'discount': 0, 'due': 0, 'reason': 'expired'})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Riders using a code on the last valid day are told it expired.

Validate a promo in order: expired if now_day is after expires_day (the expiry day itself is valid), exhausted if no uses remain, not_first if first-ride-only and the rider has prior rides, min_fare if the fare (cents) is below min_fare. A valid pct promo takes value% of the fare (floored), capped at cap cents when cap is not None (a cap of 0 means a zero discount); a flat promo takes value but never more than the fare. Ride credits then cover up to the remaining fare. Return discount, credit used, amount due and reason.

split: open-access