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

N = 1
observations = []
def solve(ev, policy):
    if ev['cancel_by'] == 'driver':
        return [0, 'driver']
    if ev['arrived_t'] is not None and ev['cancel_t'] >= ev['arrived_t']:
        if ev['cancel_t'] - ev['arrived_t'] > policy['noshow_wait']:
            return [policy['noshow_fee'], 'no_show']
        return [policy['fee'], 'after_arrival']
    if ev['cancel_t'] - ev['accept_t'] <= policy['free_window']:
        return [0, 'free_window']
    if ev['eta_latest'] - ev['eta_at_accept'] > policy['late_margin']:
        return [0, 'driver_late']
    if ev['cancel_t'] > ev['accept_t'] + ev['eta_at_accept'] + policy['late_margin']:
        return [0, 'driver_late']
    return [policy['fee'], 'late_cancel']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: no-show threshold',
   [{'accept_t': 1000,
     'arrived_t': 2100,
     'cancel_by': 'rider',
     'cancel_t': 2400,
     'eta_at_accept': 900,
     'eta_latest': 900},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('partial repair probe: no-show threshold',
   [{'accept_t': 1000,
     'arrived_t': 1900,
     'cancel_by': 'rider',
     'cancel_t': 2201,
     'eta_at_accept': 900,
     'eta_latest': 500},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('second regression',
   [{'accept_t': 1000,
     'arrived_t': 1300,
     'cancel_by': 'rider',
     'cancel_t': 1600,
     'eta_at_accept': 300,
     'eta_latest': 601},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('normal control 1',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1121,
     'eta_at_accept': 240,
     'eta_latest': 240},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('normal control 2',
   [{'accept_t': 1000,
     'arrived_t': 1240,
     'cancel_by': 'rider',
     'cancel_t': 1900,
     'eta_at_accept': 240,
     'eta_latest': 240},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('normal control 3',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'driver',
     'cancel_t': 1121,
     'eta_at_accept': 480,
     'eta_latest': 780},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver']),
  ('normal control 4',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 2081,
     'eta_at_accept': 900,
     'eta_latest': 900},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel'])],
 [('regression: no-show threshold',
   [{'accept_t': 1000,
     'arrived_t': 1300,
     'cancel_by': 'rider',
     'cancel_t': 1600,
     'eta_at_accept': 300,
     'eta_latest': 600},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('partial repair probe: no-show threshold',
   [{'accept_t': 1000,
     'arrived_t': 1680,
     'cancel_by': 'rider',
     'cancel_t': 1981,
     'eta_at_accept': 480,
     'eta_latest': 781},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('second regression',
   [{'accept_t': 1000,
     'arrived_t': 2100,
     'cancel_by': 'rider',
     'cancel_t': 2401,
     'eta_at_accept': 900,
     'eta_latest': 500},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('normal control 1',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'driver',
     'cancel_t': 1121,
     'eta_at_accept': 240,
     'eta_latest': -160},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver']),
  ('normal control 2',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1120,
     'eta_at_accept': 900,
     'eta_latest': 1201},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'free_window']),
  ('normal control 3',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'driver',
     'cancel_t': 1120,
     'eta_at_accept': 480,
     'eta_latest': 780},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver']),
  ('normal control 4',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 2200,
     'eta_at_accept': 900,
     'eta_latest': 780},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel'])],
 [('regression: no-show threshold',
   [{'accept_t': 1000,
     'arrived_t': 1440,
     'cancel_by': 'rider',
     'cancel_t': 1740,
     'eta_at_accept': 240,
     'eta_latest': 540},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('partial repair probe: no-show threshold',
   [{'accept_t': 1000,
     'arrived_t': 1440,
     'cancel_by': 'rider',
     'cancel_t': 1740,
     'eta_at_accept': 240,
     'eta_latest': 240},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('second regression',
   [{'accept_t': 1000,
     'arrived_t': 1300,
     'cancel_by': 'rider',
     'cancel_t': 1601,
     'eta_at_accept': 300,
     'eta_latest': 300},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('normal control 1',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1900,
     'eta_at_accept': 300,
     'eta_latest': 900},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver_late']),
  ('normal control 2',
   [{'accept_t': 1000,
     'arrived_t': 1240,
     'cancel_by': 'rider',
     'cancel_t': 1962,
     'eta_at_accept': 240,
     'eta_latest': 240},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('normal control 3',
   [{'accept_t': 1000,
     'arrived_t': 1440,
     'cancel_by': 'driver',
     'cancel_t': 1540,
     'eta_at_accept': 240,
     'eta_latest': 840},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver']),
  ('normal control 4',
   [{'accept_t': 1000,
     'arrived_t': 1900,
     'cancel_by': 'rider',
     'cancel_t': 1300,
     'eta_at_accept': 900,
     'eta_latest': 1200},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel'])],
 [('regression: no-show threshold',
   [{'accept_t': 1000,
     'arrived_t': 1440,
     'cancel_by': 'rider',
     'cancel_t': 1740,
     'eta_at_accept': 240,
     'eta_latest': 541},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('partial repair probe: no-show threshold',
   [{'accept_t': 1000,
     'arrived_t': 1440,
     'cancel_by': 'rider',
     'cancel_t': 1741,
     'eta_at_accept': 240,
     'eta_latest': 240},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('second regression',
   [{'accept_t': 1000,
     'arrived_t': 1900,
     'cancel_by': 'rider',
     'cancel_t': 2200,
     'eta_at_accept': 900,
     'eta_latest': 1201},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('normal control 1',
   [{'accept_t': 1000,
     'arrived_t': 1240,
     'cancel_by': 'rider',
     'cancel_t': 1480,
     'eta_at_accept': 240,
     'eta_latest': 840},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'after_arrival']),
  ('normal control 2',
   [{'accept_t': 1000,
     'arrived_t': 1480,
     'cancel_by': 'rider',
     'cancel_t': 1480,
     'eta_at_accept': 480,
     'eta_latest': 1080},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'after_arrival']),
  ('normal control 3',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 2200,
     'eta_at_accept': 300,
     'eta_latest': 300},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver_late']),
  ('normal control 4',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1354,
     'eta_at_accept': 300,
     'eta_latest': 300},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel'])],
 [('regression: no-show threshold',
   [{'accept_t': 1000,
     'arrived_t': 1480,
     'cancel_by': 'rider',
     'cancel_t': 1780,
     'eta_at_accept': 480,
     'eta_latest': 360},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('partial repair probe: no-show threshold',
   [{'accept_t': 1000,
     'arrived_t': 1900,
     'cancel_by': 'rider',
     'cancel_t': 2200,
     'eta_at_accept': 900,
     'eta_latest': 500},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('second regression',
   [{'accept_t': 1000,
     'arrived_t': 1900,
     'cancel_by': 'rider',
     'cancel_t': 2200,
     'eta_at_accept': 900,
     'eta_latest': 1201},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('normal control 1',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 2200,
     'eta_at_accept': 240,
     'eta_latest': 120},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver_late']),
  ('normal control 2',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1121,
     'eta_at_accept': 480,
     'eta_latest': 480},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('normal control 3',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 2200,
     'eta_at_accept': 900,
     'eta_latest': 900},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('normal control 4',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1300,
     'eta_at_accept': 240,
     'eta_latest': 240},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel'])]]
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(ev, policy):
    if ev['cancel_by'] == 'driver':
        return [0, 'driver']
    if ev['arrived_t'] is not None and ev['cancel_t'] >= ev['arrived_t']:
        if ev['cancel_t'] - ev['arrived_t'] >= policy['noshow_wait'] + 60:
            return [policy['noshow_fee'], 'no_show']
        return [policy['fee'], 'after_arrival']
    if ev['cancel_t'] - ev['accept_t'] <= policy['free_window']:
        return [0, 'free_window']
    if ev['eta_latest'] - ev['eta_at_accept'] > policy['late_margin']:
        return [0, 'driver_late']
    if ev['cancel_t'] > ev['accept_t'] + ev['eta_at_accept'] + policy['late_margin']:
        return [0, 'driver_late']
    return [policy['fee'], 'late_cancel']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: no-show threshold',
   [{'accept_t': 1000,
     'arrived_t': 2100,
     'cancel_by': 'rider',
     'cancel_t': 2400,
     'eta_at_accept': 900,
     'eta_latest': 900},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('partial repair probe: no-show threshold',
   [{'accept_t': 1000,
     'arrived_t': 1900,
     'cancel_by': 'rider',
     'cancel_t': 2201,
     'eta_at_accept': 900,
     'eta_latest': 500},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('second regression',
   [{'accept_t': 1000,
     'arrived_t': 1300,
     'cancel_by': 'rider',
     'cancel_t': 1600,
     'eta_at_accept': 300,
     'eta_latest': 601},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('normal control 1',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1121,
     'eta_at_accept': 240,
     'eta_latest': 240},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('normal control 2',
   [{'accept_t': 1000,
     'arrived_t': 1240,
     'cancel_by': 'rider',
     'cancel_t': 1900,
     'eta_at_accept': 240,
     'eta_latest': 240},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('normal control 3',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'driver',
     'cancel_t': 1121,
     'eta_at_accept': 480,
     'eta_latest': 780},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver']),
  ('normal control 4',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 2081,
     'eta_at_accept': 900,
     'eta_latest': 900},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel'])],
 [('regression: no-show threshold',
   [{'accept_t': 1000,
     'arrived_t': 1300,
     'cancel_by': 'rider',
     'cancel_t': 1600,
     'eta_at_accept': 300,
     'eta_latest': 600},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('partial repair probe: no-show threshold',
   [{'accept_t': 1000,
     'arrived_t': 1680,
     'cancel_by': 'rider',
     'cancel_t': 1981,
     'eta_at_accept': 480,
     'eta_latest': 781},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('second regression',
   [{'accept_t': 1000,
     'arrived_t': 2100,
     'cancel_by': 'rider',
     'cancel_t': 2401,
     'eta_at_accept': 900,
     'eta_latest': 500},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('normal control 1',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'driver',
     'cancel_t': 1121,
     'eta_at_accept': 240,
     'eta_latest': -160},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver']),
  ('normal control 2',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1120,
     'eta_at_accept': 900,
     'eta_latest': 1201},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'free_window']),
  ('normal control 3',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'driver',
     'cancel_t': 1120,
     'eta_at_accept': 480,
     'eta_latest': 780},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver']),
  ('normal control 4',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 2200,
     'eta_at_accept': 900,
     'eta_latest': 780},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel'])],
 [('regression: no-show threshold',
   [{'accept_t': 1000,
     'arrived_t': 1440,
     'cancel_by': 'rider',
     'cancel_t': 1740,
     'eta_at_accept': 240,
     'eta_latest': 540},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('partial repair probe: no-show threshold',
   [{'accept_t': 1000,
     'arrived_t': 1440,
     'cancel_by': 'rider',
     'cancel_t': 1740,
     'eta_at_accept': 240,
     'eta_latest': 240},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('second regression',
   [{'accept_t': 1000,
     'arrived_t': 1300,
     'cancel_by': 'rider',
     'cancel_t': 1601,
     'eta_at_accept': 300,
     'eta_latest': 300},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('normal control 1',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1900,
     'eta_at_accept': 300,
     'eta_latest': 900},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver_late']),
  ('normal control 2',
   [{'accept_t': 1000,
     'arrived_t': 1240,
     'cancel_by': 'rider',
     'cancel_t': 1962,
     'eta_at_accept': 240,
     'eta_latest': 240},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('normal control 3',
   [{'accept_t': 1000,
     'arrived_t': 1440,
     'cancel_by': 'driver',
     'cancel_t': 1540,
     'eta_at_accept': 240,
     'eta_latest': 840},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver']),
  ('normal control 4',
   [{'accept_t': 1000,
     'arrived_t': 1900,
     'cancel_by': 'rider',
     'cancel_t': 1300,
     'eta_at_accept': 900,
     'eta_latest': 1200},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel'])],
 [('regression: no-show threshold',
   [{'accept_t': 1000,
     'arrived_t': 1440,
     'cancel_by': 'rider',
     'cancel_t': 1740,
     'eta_at_accept': 240,
     'eta_latest': 541},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('partial repair probe: no-show threshold',
   [{'accept_t': 1000,
     'arrived_t': 1440,
     'cancel_by': 'rider',
     'cancel_t': 1741,
     'eta_at_accept': 240,
     'eta_latest': 240},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('second regression',
   [{'accept_t': 1000,
     'arrived_t': 1900,
     'cancel_by': 'rider',
     'cancel_t': 2200,
     'eta_at_accept': 900,
     'eta_latest': 1201},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('normal control 1',
   [{'accept_t': 1000,
     'arrived_t': 1240,
     'cancel_by': 'rider',
     'cancel_t': 1480,
     'eta_at_accept': 240,
     'eta_latest': 840},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'after_arrival']),
  ('normal control 2',
   [{'accept_t': 1000,
     'arrived_t': 1480,
     'cancel_by': 'rider',
     'cancel_t': 1480,
     'eta_at_accept': 480,
     'eta_latest': 1080},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'after_arrival']),
  ('normal control 3',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 2200,
     'eta_at_accept': 300,
     'eta_latest': 300},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver_late']),
  ('normal control 4',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1354,
     'eta_at_accept': 300,
     'eta_latest': 300},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel'])],
 [('regression: no-show threshold',
   [{'accept_t': 1000,
     'arrived_t': 1480,
     'cancel_by': 'rider',
     'cancel_t': 1780,
     'eta_at_accept': 480,
     'eta_latest': 360},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('partial repair probe: no-show threshold',
   [{'accept_t': 1000,
     'arrived_t': 1900,
     'cancel_by': 'rider',
     'cancel_t': 2200,
     'eta_at_accept': 900,
     'eta_latest': 500},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('second regression',
   [{'accept_t': 1000,
     'arrived_t': 1900,
     'cancel_by': 'rider',
     'cancel_t': 2200,
     'eta_at_accept': 900,
     'eta_latest': 1201},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('normal control 1',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 2200,
     'eta_at_accept': 240,
     'eta_latest': 120},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver_late']),
  ('normal control 2',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1121,
     'eta_at_accept': 480,
     'eta_latest': 480},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('normal control 3',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 2200,
     'eta_at_accept': 900,
     'eta_latest': 900},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('normal control 4',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1300,
     'eta_at_accept': 240,
     'eta_latest': 240},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel'])]]
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 driver who waited exactly five minutes receives only the regular fee.

Decide a cancellation charge [cents, reason]. Driver cancellations are free. A rider cancelling at or after driver arrival pays the no-show fee if at least noshow_wait seconds passed since arrival, else the regular fee. Before arrival, cancelling within free_window seconds of acceptance is free; it is also free if the ETA grew by more than late_margin since acceptance, or if the driver is more than late_margin past the ETA promised at acceptance; otherwise the regular fee applies.

split: open-access


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

N = 1
observations = []
def solve(ev, policy):
    if ev['cancel_by'] == 'driver':
        return [0, 'driver']
    if ev['arrived_t'] is not None and ev['cancel_t'] >= ev['arrived_t']:
        if ev['cancel_t'] - ev['arrived_t'] >= policy['noshow_wait']:
            return [policy['noshow_fee'], 'no_show']
        return [policy['fee'], 'after_arrival']
    if ev['cancel_t'] - ev['accept_t'] <= policy['free_window']:
        return [0, 'free_window']
    if ev['eta_at_accept'] - ev['eta_latest'] > policy['late_margin']:
        return [0, 'driver_late']
    if ev['cancel_t'] > ev['accept_t'] + ev['eta_at_accept'] + policy['late_margin']:
        return [0, 'driver_late']
    return [policy['fee'], 'late_cancel']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: eta growth direction',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1300,
     'eta_at_accept': 240,
     'eta_latest': -160},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('partial repair probe: eta growth direction',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1600,
     'eta_at_accept': 300,
     'eta_latest': -100},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('second regression',
   [{'accept_t': 1000,
     'arrived_t': 2100,
     'cancel_by': 'rider',
     'cancel_t': 1300,
     'eta_at_accept': 900,
     'eta_latest': 1201},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver_late']),
  ('normal control 1',
   [{'accept_t': 1000,
     'arrived_t': 1680,
     'cancel_by': 'driver',
     'cancel_t': 1300,
     'eta_at_accept': 480,
     'eta_latest': 480},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver']),
  ('normal control 2',
   [{'accept_t': 1000,
     'arrived_t': 1480,
     'cancel_by': 'rider',
     'cancel_t': 1781,
     'eta_at_accept': 480,
     'eta_latest': 360},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('normal control 3',
   [{'accept_t': 1000,
     'arrived_t': 1900,
     'cancel_by': 'driver',
     'cancel_t': 2199,
     'eta_at_accept': 900,
     'eta_latest': 900},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver']),
  ('normal control 4',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'driver',
     'cancel_t': 1060,
     'eta_at_accept': 480,
     'eta_latest': 360},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver'])],
 [('regression: eta growth direction',
   [{'accept_t': 1000,
     'arrived_t': 1440,
     'cancel_by': 'rider',
     'cancel_t': 1121,
     'eta_at_accept': 240,
     'eta_latest': -160},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('partial repair probe: eta growth direction',
   [{'accept_t': 1000,
     'arrived_t': 1480,
     'cancel_by': 'rider',
     'cancel_t': 1121,
     'eta_at_accept': 480,
     'eta_latest': 80},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('second regression',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1121,
     'eta_at_accept': 480,
     'eta_latest': 781},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver_late']),
  ('normal control 1',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 2200,
     'eta_at_accept': 300,
     'eta_latest': 300},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver_late']),
  ('normal control 2',
   [{'accept_t': 1000,
     'arrived_t': 1900,
     'cancel_by': 'driver',
     'cancel_t': 1121,
     'eta_at_accept': 900,
     'eta_latest': 900},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver']),
  ('normal control 3',
   [{'accept_t': 1000,
     'arrived_t': 1900,
     'cancel_by': 'rider',
     'cancel_t': 2199,
     'eta_at_accept': 900,
     'eta_latest': 1200},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'after_arrival']),
  ('normal control 4',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1601,
     'eta_at_accept': 480,
     'eta_latest': 480},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel'])],
 [('regression: eta growth direction',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1300,
     'eta_at_accept': 900,
     'eta_latest': 1500},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver_late']),
  ('partial repair probe: eta growth direction',
   [{'accept_t': 1000,
     'arrived_t': 1440,
     'cancel_by': 'rider',
     'cancel_t': 1274,
     'eta_at_accept': 240,
     'eta_latest': -160},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('second regression',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1900,
     'eta_at_accept': 900,
     'eta_latest': 1201},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver_late']),
  ('normal control 1',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 2344,
     'eta_at_accept': 900,
     'eta_latest': 780},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver_late']),
  ('normal control 2',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1120,
     'eta_at_accept': 480,
     'eta_latest': 80},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'free_window']),
  ('normal control 3',
   [{'accept_t': 1000,
     'arrived_t': 1480,
     'cancel_by': 'rider',
     'cancel_t': 2446,
     'eta_at_accept': 480,
     'eta_latest': 480},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('normal control 4',
   [{'accept_t': 1000,
     'arrived_t': 1680,
     'cancel_by': 'rider',
     'cancel_t': 1121,
     'eta_at_accept': 480,
     'eta_latest': 780},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel'])],
 [('regression: eta growth direction',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 2200,
     'eta_at_accept': 900,
     'eta_latest': 1500},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver_late']),
  ('partial repair probe: eta growth direction',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1300,
     'eta_at_accept': 300,
     'eta_latest': -100},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('second regression',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1121,
     'eta_at_accept': 300,
     'eta_latest': 601},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver_late']),
  ('normal control 1',
   [{'accept_t': 1000,
     'arrived_t': 1500,
     'cancel_by': 'driver',
     'cancel_t': 1121,
     'eta_at_accept': 300,
     'eta_latest': -100},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver']),
  ('normal control 2',
   [{'accept_t': 1000,
     'arrived_t': 1900,
     'cancel_by': 'driver',
     'cancel_t': 2199,
     'eta_at_accept': 900,
     'eta_latest': 1500},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver']),
  ('normal control 3',
   [{'accept_t': 1000,
     'arrived_t': 1500,
     'cancel_by': 'driver',
     'cancel_t': 2000,
     'eta_at_accept': 300,
     'eta_latest': 300},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver']),
  ('normal control 4',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 2311,
     'eta_at_accept': 300,
     'eta_latest': 601},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver_late'])],
 [('regression: eta growth direction',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1600,
     'eta_at_accept': 900,
     'eta_latest': 1500},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver_late']),
  ('partial repair probe: eta growth direction',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1600,
     'eta_at_accept': 300,
     'eta_latest': -100},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('second regression',
   [{'accept_t': 1000,
     'arrived_t': 1900,
     'cancel_by': 'rider',
     'cancel_t': 1604,
     'eta_at_accept': 900,
     'eta_latest': 1201},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver_late']),
  ('normal control 1',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1120,
     'eta_at_accept': 300,
     'eta_latest': -100},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'free_window']),
  ('normal control 2',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1120,
     'eta_at_accept': 240,
     'eta_latest': 840},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'free_window']),
  ('normal control 3',
   [{'accept_t': 1000,
     'arrived_t': 1440,
     'cancel_by': 'driver',
     'cancel_t': 1440,
     'eta_at_accept': 240,
     'eta_latest': 120},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver']),
  ('normal control 4',
   [{'accept_t': 1000,
     'arrived_t': 1300,
     'cancel_by': 'driver',
     'cancel_t': 1601,
     'eta_at_accept': 300,
     'eta_latest': 900},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver'])]]
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(ev, policy):
    if ev['cancel_by'] == 'driver':
        return [0, 'driver']
    if ev['arrived_t'] is not None and ev['cancel_t'] >= ev['arrived_t']:
        if ev['cancel_t'] - ev['arrived_t'] >= policy['noshow_wait']:
            return [policy['noshow_fee'], 'no_show']
        return [policy['fee'], 'after_arrival']
    if ev['cancel_t'] - ev['accept_t'] <= policy['free_window']:
        return [0, 'free_window']
    if abs(ev['eta_latest'] - ev['eta_at_accept']) > policy['late_margin']:
        return [0, 'driver_late']
    if ev['cancel_t'] > ev['accept_t'] + ev['eta_at_accept'] + policy['late_margin']:
        return [0, 'driver_late']
    return [policy['fee'], 'late_cancel']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: eta growth direction',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1300,
     'eta_at_accept': 240,
     'eta_latest': -160},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('partial repair probe: eta growth direction',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1600,
     'eta_at_accept': 300,
     'eta_latest': -100},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('second regression',
   [{'accept_t': 1000,
     'arrived_t': 2100,
     'cancel_by': 'rider',
     'cancel_t': 1300,
     'eta_at_accept': 900,
     'eta_latest': 1201},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver_late']),
  ('normal control 1',
   [{'accept_t': 1000,
     'arrived_t': 1680,
     'cancel_by': 'driver',
     'cancel_t': 1300,
     'eta_at_accept': 480,
     'eta_latest': 480},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver']),
  ('normal control 2',
   [{'accept_t': 1000,
     'arrived_t': 1480,
     'cancel_by': 'rider',
     'cancel_t': 1781,
     'eta_at_accept': 480,
     'eta_latest': 360},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('normal control 3',
   [{'accept_t': 1000,
     'arrived_t': 1900,
     'cancel_by': 'driver',
     'cancel_t': 2199,
     'eta_at_accept': 900,
     'eta_latest': 900},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver']),
  ('normal control 4',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'driver',
     'cancel_t': 1060,
     'eta_at_accept': 480,
     'eta_latest': 360},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver'])],
 [('regression: eta growth direction',
   [{'accept_t': 1000,
     'arrived_t': 1440,
     'cancel_by': 'rider',
     'cancel_t': 1121,
     'eta_at_accept': 240,
     'eta_latest': -160},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('partial repair probe: eta growth direction',
   [{'accept_t': 1000,
     'arrived_t': 1480,
     'cancel_by': 'rider',
     'cancel_t': 1121,
     'eta_at_accept': 480,
     'eta_latest': 80},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('second regression',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1121,
     'eta_at_accept': 480,
     'eta_latest': 781},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver_late']),
  ('normal control 1',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 2200,
     'eta_at_accept': 300,
     'eta_latest': 300},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver_late']),
  ('normal control 2',
   [{'accept_t': 1000,
     'arrived_t': 1900,
     'cancel_by': 'driver',
     'cancel_t': 1121,
     'eta_at_accept': 900,
     'eta_latest': 900},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver']),
  ('normal control 3',
   [{'accept_t': 1000,
     'arrived_t': 1900,
     'cancel_by': 'rider',
     'cancel_t': 2199,
     'eta_at_accept': 900,
     'eta_latest': 1200},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'after_arrival']),
  ('normal control 4',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1601,
     'eta_at_accept': 480,
     'eta_latest': 480},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel'])],
 [('regression: eta growth direction',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1300,
     'eta_at_accept': 900,
     'eta_latest': 1500},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver_late']),
  ('partial repair probe: eta growth direction',
   [{'accept_t': 1000,
     'arrived_t': 1440,
     'cancel_by': 'rider',
     'cancel_t': 1274,
     'eta_at_accept': 240,
     'eta_latest': -160},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('second regression',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1900,
     'eta_at_accept': 900,
     'eta_latest': 1201},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver_late']),
  ('normal control 1',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 2344,
     'eta_at_accept': 900,
     'eta_latest': 780},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver_late']),
  ('normal control 2',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1120,
     'eta_at_accept': 480,
     'eta_latest': 80},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'free_window']),
  ('normal control 3',
   [{'accept_t': 1000,
     'arrived_t': 1480,
     'cancel_by': 'rider',
     'cancel_t': 2446,
     'eta_at_accept': 480,
     'eta_latest': 480},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('normal control 4',
   [{'accept_t': 1000,
     'arrived_t': 1680,
     'cancel_by': 'rider',
     'cancel_t': 1121,
     'eta_at_accept': 480,
     'eta_latest': 780},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel'])],
 [('regression: eta growth direction',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 2200,
     'eta_at_accept': 900,
     'eta_latest': 1500},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver_late']),
  ('partial repair probe: eta growth direction',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1300,
     'eta_at_accept': 300,
     'eta_latest': -100},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('second regression',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1121,
     'eta_at_accept': 300,
     'eta_latest': 601},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver_late']),
  ('normal control 1',
   [{'accept_t': 1000,
     'arrived_t': 1500,
     'cancel_by': 'driver',
     'cancel_t': 1121,
     'eta_at_accept': 300,
     'eta_latest': -100},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver']),
  ('normal control 2',
   [{'accept_t': 1000,
     'arrived_t': 1900,
     'cancel_by': 'driver',
     'cancel_t': 2199,
     'eta_at_accept': 900,
     'eta_latest': 1500},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver']),
  ('normal control 3',
   [{'accept_t': 1000,
     'arrived_t': 1500,
     'cancel_by': 'driver',
     'cancel_t': 2000,
     'eta_at_accept': 300,
     'eta_latest': 300},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver']),
  ('normal control 4',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 2311,
     'eta_at_accept': 300,
     'eta_latest': 601},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver_late'])],
 [('regression: eta growth direction',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1600,
     'eta_at_accept': 900,
     'eta_latest': 1500},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver_late']),
  ('partial repair probe: eta growth direction',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1600,
     'eta_at_accept': 300,
     'eta_latest': -100},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('second regression',
   [{'accept_t': 1000,
     'arrived_t': 1900,
     'cancel_by': 'rider',
     'cancel_t': 1604,
     'eta_at_accept': 900,
     'eta_latest': 1201},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver_late']),
  ('normal control 1',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1120,
     'eta_at_accept': 300,
     'eta_latest': -100},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'free_window']),
  ('normal control 2',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1120,
     'eta_at_accept': 240,
     'eta_latest': 840},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'free_window']),
  ('normal control 3',
   [{'accept_t': 1000,
     'arrived_t': 1440,
     'cancel_by': 'driver',
     'cancel_t': 1440,
     'eta_at_accept': 240,
     'eta_latest': 120},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver']),
  ('normal control 4',
   [{'accept_t': 1000,
     'arrived_t': 1300,
     'cancel_by': 'driver',
     'cancel_t': 1601,
     'eta_at_accept': 300,
     'eta_latest': 900},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver'])]]
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 are charged although the ETA ballooned by ten minutes.

Decide a cancellation charge [cents, reason]. Driver cancellations are free. A rider cancelling at or after driver arrival pays the no-show fee if at least noshow_wait seconds passed since arrival, else the regular fee. Before arrival, cancelling within free_window seconds of acceptance is free; it is also free if the ETA grew by more than late_margin since acceptance, or if the driver is more than late_margin past the ETA promised at acceptance; otherwise the regular fee applies.

split: open-access


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

N = 1
observations = []
def solve(ev, policy):
    if ev['cancel_by'] == 'driver':
        return [0, 'driver']
    if ev['arrived_t'] is not None and ev['cancel_t'] >= ev['arrived_t']:
        if ev['cancel_t'] - ev['arrived_t'] >= policy['noshow_wait']:
            return [policy['noshow_fee'], 'no_show']
        return [policy['fee'], 'after_arrival']
    if ev['cancel_t'] - ev['accept_t'] <= policy['free_window']:
        return [0, 'free_window']
    if ev['eta_latest'] - ev['eta_at_accept'] > policy['late_margin']:
        return [0, 'driver_late']
    if ev['cancel_t'] > ev['accept_t'] + ev['eta_at_accept']:
        return [0, 'driver_late']
    return [policy['fee'], 'late_cancel']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: past-eta lateness',
   [{'accept_t': 1000,
     'arrived_t': 1680,
     'cancel_by': 'rider',
     'cancel_t': 1600,
     'eta_at_accept': 480,
     'eta_latest': 480},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('partial repair probe: past-eta lateness',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1900,
     'eta_at_accept': 900,
     'eta_latest': 500},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('second regression',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1429,
     'eta_at_accept': 240,
     'eta_latest': 540},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('normal control 1',
   [{'accept_t': 1000,
     'arrived_t': 1500,
     'cancel_by': 'driver',
     'cancel_t': 1600,
     'eta_at_accept': 300,
     'eta_latest': 300},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver']),
  ('normal control 2',
   [{'accept_t': 1000,
     'arrived_t': 1240,
     'cancel_by': 'driver',
     'cancel_t': 2200,
     'eta_at_accept': 240,
     'eta_latest': 240},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver']),
  ('normal control 3',
   [{'accept_t': 1000,
     'arrived_t': 2100,
     'cancel_by': 'rider',
     'cancel_t': 2401,
     'eta_at_accept': 900,
     'eta_latest': 500},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('normal control 4',
   [{'accept_t': 1000,
     'arrived_t': 1680,
     'cancel_by': 'rider',
     'cancel_t': 1709,
     'eta_at_accept': 480,
     'eta_latest': 80},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'after_arrival'])],
 [('regression: past-eta lateness',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1300,
     'eta_at_accept': 240,
     'eta_latest': 240},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('partial repair probe: past-eta lateness',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1600,
     'eta_at_accept': 240,
     'eta_latest': 540},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver_late']),
  ('second regression',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1600,
     'eta_at_accept': 480,
     'eta_latest': 80},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('normal control 1',
   [{'accept_t': 1000,
     'arrived_t': 1300,
     'cancel_by': 'driver',
     'cancel_t': 1600,
     'eta_at_accept': 300,
     'eta_latest': 900},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver']),
  ('normal control 2',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 2200,
     'eta_at_accept': 240,
     'eta_latest': 540},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver_late']),
  ('normal control 3',
   [{'accept_t': 1000,
     'arrived_t': 1440,
     'cancel_by': 'rider',
     'cancel_t': 1540,
     'eta_at_accept': 240,
     'eta_latest': 540},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'after_arrival']),
  ('normal control 4',
   [{'accept_t': 1000,
     'arrived_t': 1480,
     'cancel_by': 'rider',
     'cancel_t': 1120,
     'eta_at_accept': 480,
     'eta_latest': 781},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'free_window'])],
 [('regression: past-eta lateness',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1300,
     'eta_at_accept': 240,
     'eta_latest': 540},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('partial repair probe: past-eta lateness',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1900,
     'eta_at_accept': 300,
     'eta_latest': 600},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver_late']),
  ('second regression',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 2200,
     'eta_at_accept': 900,
     'eta_latest': 780},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('normal control 1',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'driver',
     'cancel_t': 1600,
     'eta_at_accept': 900,
     'eta_latest': 1200},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver']),
  ('normal control 2',
   [{'accept_t': 1000,
     'arrived_t': 1240,
     'cancel_by': 'rider',
     'cancel_t': 1541,
     'eta_at_accept': 240,
     'eta_latest': 120},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('normal control 3',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1121,
     'eta_at_accept': 900,
     'eta_latest': 500},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('normal control 4',
   [{'accept_t': 1000,
     'arrived_t': 2100,
     'cancel_by': 'rider',
     'cancel_t': 2100,
     'eta_at_accept': 900,
     'eta_latest': 1500},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'after_arrival'])],
 [('regression: past-eta lateness',
   [{'accept_t': 1000,
     'arrived_t': 1680,
     'cancel_by': 'rider',
     'cancel_t': 1600,
     'eta_at_accept': 480,
     'eta_latest': 480},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('partial repair probe: past-eta lateness',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1724,
     'eta_at_accept': 480,
     'eta_latest': 80},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('second regression',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1580,
     'eta_at_accept': 300,
     'eta_latest': 600},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('normal control 1',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1120,
     'eta_at_accept': 300,
     'eta_latest': -100},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'free_window']),
  ('normal control 2',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1060,
     'eta_at_accept': 240,
     'eta_latest': 240},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'free_window']),
  ('normal control 3',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'driver',
     'cancel_t': 2200,
     'eta_at_accept': 900,
     'eta_latest': 1201},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver']),
  ('normal control 4',
   [{'accept_t': 1000,
     'arrived_t': 1480,
     'cancel_by': 'driver',
     'cancel_t': 1580,
     'eta_at_accept': 480,
     'eta_latest': 480},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver'])],
 [('regression: past-eta lateness',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 2200,
     'eta_at_accept': 900,
     'eta_latest': 500},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('partial repair probe: past-eta lateness',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 2200,
     'eta_at_accept': 900,
     'eta_latest': 780},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('second regression',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1600,
     'eta_at_accept': 480,
     'eta_latest': 480},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('normal control 1',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1300,
     'eta_at_accept': 300,
     'eta_latest': 600},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('normal control 2',
   [{'accept_t': 1000,
     'arrived_t': 1480,
     'cancel_by': 'rider',
     'cancel_t': 2200,
     'eta_at_accept': 480,
     'eta_latest': 781},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('normal control 3',
   [{'accept_t': 1000,
     'arrived_t': 1480,
     'cancel_by': 'rider',
     'cancel_t': 1600,
     'eta_at_accept': 480,
     'eta_latest': 480},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'after_arrival']),
  ('normal control 4',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'driver',
     'cancel_t': 1121,
     'eta_at_accept': 900,
     'eta_latest': 1500},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver'])]]
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(ev, policy):
    if ev['cancel_by'] == 'driver':
        return [0, 'driver']
    if ev['arrived_t'] is not None and ev['cancel_t'] >= ev['arrived_t']:
        if ev['cancel_t'] - ev['arrived_t'] >= policy['noshow_wait']:
            return [policy['noshow_fee'], 'no_show']
        return [policy['fee'], 'after_arrival']
    if ev['cancel_t'] - ev['accept_t'] <= policy['free_window']:
        return [0, 'free_window']
    if ev['eta_latest'] - ev['eta_at_accept'] > policy['late_margin']:
        return [0, 'driver_late']
    if ev['cancel_t'] > ev['accept_t'] + ev['eta_latest'] + policy['late_margin']:
        return [0, 'driver_late']
    return [policy['fee'], 'late_cancel']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: past-eta lateness',
   [{'accept_t': 1000,
     'arrived_t': 1680,
     'cancel_by': 'rider',
     'cancel_t': 1600,
     'eta_at_accept': 480,
     'eta_latest': 480},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('partial repair probe: past-eta lateness',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1900,
     'eta_at_accept': 900,
     'eta_latest': 500},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('second regression',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1429,
     'eta_at_accept': 240,
     'eta_latest': 540},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('normal control 1',
   [{'accept_t': 1000,
     'arrived_t': 1500,
     'cancel_by': 'driver',
     'cancel_t': 1600,
     'eta_at_accept': 300,
     'eta_latest': 300},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver']),
  ('normal control 2',
   [{'accept_t': 1000,
     'arrived_t': 1240,
     'cancel_by': 'driver',
     'cancel_t': 2200,
     'eta_at_accept': 240,
     'eta_latest': 240},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver']),
  ('normal control 3',
   [{'accept_t': 1000,
     'arrived_t': 2100,
     'cancel_by': 'rider',
     'cancel_t': 2401,
     'eta_at_accept': 900,
     'eta_latest': 500},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('normal control 4',
   [{'accept_t': 1000,
     'arrived_t': 1680,
     'cancel_by': 'rider',
     'cancel_t': 1709,
     'eta_at_accept': 480,
     'eta_latest': 80},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'after_arrival'])],
 [('regression: past-eta lateness',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1300,
     'eta_at_accept': 240,
     'eta_latest': 240},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('partial repair probe: past-eta lateness',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1600,
     'eta_at_accept': 240,
     'eta_latest': 540},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver_late']),
  ('second regression',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1600,
     'eta_at_accept': 480,
     'eta_latest': 80},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('normal control 1',
   [{'accept_t': 1000,
     'arrived_t': 1300,
     'cancel_by': 'driver',
     'cancel_t': 1600,
     'eta_at_accept': 300,
     'eta_latest': 900},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver']),
  ('normal control 2',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 2200,
     'eta_at_accept': 240,
     'eta_latest': 540},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver_late']),
  ('normal control 3',
   [{'accept_t': 1000,
     'arrived_t': 1440,
     'cancel_by': 'rider',
     'cancel_t': 1540,
     'eta_at_accept': 240,
     'eta_latest': 540},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'after_arrival']),
  ('normal control 4',
   [{'accept_t': 1000,
     'arrived_t': 1480,
     'cancel_by': 'rider',
     'cancel_t': 1120,
     'eta_at_accept': 480,
     'eta_latest': 781},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'free_window'])],
 [('regression: past-eta lateness',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1300,
     'eta_at_accept': 240,
     'eta_latest': 540},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('partial repair probe: past-eta lateness',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1900,
     'eta_at_accept': 300,
     'eta_latest': 600},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver_late']),
  ('second regression',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 2200,
     'eta_at_accept': 900,
     'eta_latest': 780},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('normal control 1',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'driver',
     'cancel_t': 1600,
     'eta_at_accept': 900,
     'eta_latest': 1200},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver']),
  ('normal control 2',
   [{'accept_t': 1000,
     'arrived_t': 1240,
     'cancel_by': 'rider',
     'cancel_t': 1541,
     'eta_at_accept': 240,
     'eta_latest': 120},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('normal control 3',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1121,
     'eta_at_accept': 900,
     'eta_latest': 500},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('normal control 4',
   [{'accept_t': 1000,
     'arrived_t': 2100,
     'cancel_by': 'rider',
     'cancel_t': 2100,
     'eta_at_accept': 900,
     'eta_latest': 1500},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'after_arrival'])],
 [('regression: past-eta lateness',
   [{'accept_t': 1000,
     'arrived_t': 1680,
     'cancel_by': 'rider',
     'cancel_t': 1600,
     'eta_at_accept': 480,
     'eta_latest': 480},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('partial repair probe: past-eta lateness',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1724,
     'eta_at_accept': 480,
     'eta_latest': 80},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('second regression',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1580,
     'eta_at_accept': 300,
     'eta_latest': 600},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('normal control 1',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1120,
     'eta_at_accept': 300,
     'eta_latest': -100},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'free_window']),
  ('normal control 2',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1060,
     'eta_at_accept': 240,
     'eta_latest': 240},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'free_window']),
  ('normal control 3',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'driver',
     'cancel_t': 2200,
     'eta_at_accept': 900,
     'eta_latest': 1201},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver']),
  ('normal control 4',
   [{'accept_t': 1000,
     'arrived_t': 1480,
     'cancel_by': 'driver',
     'cancel_t': 1580,
     'eta_at_accept': 480,
     'eta_latest': 480},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver'])],
 [('regression: past-eta lateness',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 2200,
     'eta_at_accept': 900,
     'eta_latest': 500},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('partial repair probe: past-eta lateness',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 2200,
     'eta_at_accept': 900,
     'eta_latest': 780},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('second regression',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1600,
     'eta_at_accept': 480,
     'eta_latest': 480},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('normal control 1',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'rider',
     'cancel_t': 1300,
     'eta_at_accept': 300,
     'eta_latest': 600},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'late_cancel']),
  ('normal control 2',
   [{'accept_t': 1000,
     'arrived_t': 1480,
     'cancel_by': 'rider',
     'cancel_t': 2200,
     'eta_at_accept': 480,
     'eta_latest': 781},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [700, 'no_show']),
  ('normal control 3',
   [{'accept_t': 1000,
     'arrived_t': 1480,
     'cancel_by': 'rider',
     'cancel_t': 1600,
     'eta_at_accept': 480,
     'eta_latest': 480},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [500, 'after_arrival']),
  ('normal control 4',
   [{'accept_t': 1000,
     'arrived_t': None,
     'cancel_by': 'driver',
     'cancel_t': 1121,
     'eta_at_accept': 900,
     'eta_latest': 1500},
    {'fee': 500, 'free_window': 120, 'late_margin': 300, 'noshow_fee': 700, 'noshow_wait': 300}],
   [0, 'driver'])]]
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 cancelling a few seconds after the ETA get a free cancel.

Decide a cancellation charge [cents, reason]. Driver cancellations are free. A rider cancelling at or after driver arrival pays the no-show fee if at least noshow_wait seconds passed since arrival, else the regular fee. Before arrival, cancelling within free_window seconds of acceptance is free; it is also free if the ETA grew by more than late_margin since acceptance, or if the driver is more than late_margin past the ETA promised at acceptance; otherwise the regular fee applies.

split: open-access


prompt:
A pickup on the border between two zones picks up the neighbor's surge.

Surge zones are rectangles, half-open [x0, x1) x [y0, y1). The multiplier comes from the pickup point only. Among zones containing it choose highest priority, then highest multiplier, then lowest id. No containing zone gives [None, 10] (1.0x in tenths). Return [zone id, multiplier].

split: open-access


prompt:
Riders heading into a surging stadium zone pay its surge from a calm neighborhood.

Surge zones are rectangles, half-open [x0, x1) x [y0, y1). The multiplier comes from the pickup point only. Among zones containing it choose highest priority, then highest multiplier, then lowest id. No containing zone gives [None, 10] (1.0x in tenths). Return [zone id, multiplier].

split: open-access


prompt:
An event overlay with priority 2 loses to a base zone with a higher multiplier.

Surge zones are rectangles, half-open [x0, x1) x [y0, y1). The multiplier comes from the pickup point only. Among zones containing it choose highest priority, then highest multiplier, then lowest id. No containing zone gives [None, 10] (1.0x in tenths). Return [zone id, multiplier].

split: open-access


prompt:
Receipts cite a different zone id than the zone map for identical overlaps.

Surge zones are rectangles, half-open [x0, x1) x [y0, y1). The multiplier comes from the pickup point only. Among zones containing it choose highest priority, then highest multiplier, then lowest id. No containing zone gives [None, 10] (1.0x in tenths). Return [zone id, multiplier].

split: open-access


prompt:
Trips starting outside the zone map are priced at zero.

Surge zones are rectangles, half-open [x0, x1) x [y0, y1). The multiplier comes from the pickup point only. Among zones containing it choose highest priority, then highest multiplier, then lowest id. No containing zone gives [None, 10] (1.0x in tenths). Return [zone id, multiplier].

split: open-access


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

N = 1
observations = []
def solve(ts_utc, offset_min, cards, holidays):
    local = ts_utc - offset_min * 60
    day = local // 86400
    minute = local % 86400 // 60
    wd = (day + 3) % 7
    is_hol = day in holidays
    for c in cards:
        if c['days'] == 'holiday':
            if is_hol and c['start'] <= minute < c['end']:
                return c['card']
            continue
        if c['start'] < c['end']:
            if wd in c['days'] and c['start'] <= minute < c['end']:
                return c['card']
        else:
            if wd in c['days'] and minute >= c['start']:
                return c['card']
            if (wd - 1) % 7 in c['days'] and minute < c['end']:
                return c['card']
    return 'standard'
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: utc offset sign',
   [1728863940, -480,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20002]],
   'standard'),
  ('partial repair probe: utc offset sign',
   [1728082800, 600,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20008]],
   'standard'),
  ('second regression',
   [1728601200, -480,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20000]],
   'standard'),
  ('normal control 1',
   [1728000000, 330,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20012]],
   'standard'),
  ('normal control 2',
   [1728972000, -480,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20003]],
   'standard'),
  ('normal control 3',
   [1728864060, 600,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20012]],
   'standard'),
  ('normal control 4',
   [1728856800, -300,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20004]],
   'standard')],
 [('regression: utc offset sign',
   [1728856800, 600,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20004]],
   'rush'),
  ('partial repair probe: utc offset sign',
   [1728342000, 600,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20008]],
   'rush'),
  ('second regression',
   [1728518400, -480,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20002]],
   'standard'),
  ('normal control 1',
   [1728345660, -300,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20000]],
   'standard'),
  ('normal control 2',
   [1728863940, 60,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20005]],
   'standard'),
  ('normal control 3',
   [1728000000, 330,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20012]],
   'standard'),
  ('normal control 4',
   [1728946800, -300,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20004]],
   'standard')],
 [('regression: utc offset sign',
   [1728468000, 60,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20012]],
   'standard'),
  ('partial repair probe: utc offset sign',
   [1729005186, 600,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20011]],
   'standard'),
  ('second regression',
   [1728457200, 60,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20006]],
   'rush'),
  ('normal control 1',
   [1728108000, 0,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20008]],
   'standard'),
  ('normal control 2',
   [1729033200, 330,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20005]],
   'standard'),
  ('normal control 3',
   [1729058400, -480,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20006]],
   'standard'),
  ('normal control 4',
   [1728712800, 60,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20010]],
   'standard')],
 [('regression: utc offset sign',
   [1728198000, 330,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20013]],
   'standard'),
  ('partial repair probe: utc offset sign',
   [1728783376, 330,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20005]],
   'standard'),
  ('second regression',
   [1728640800, -300,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20004]],
   'standard'),
  ('normal control 1',
   [1729159200, 330,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20010]],
   'standard'),
  ('normal control 2',
   [1728511200, 0,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20003]],
   'standard'),
  ('normal control 3',
   [1729206000, 60,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20005]],
   'standard'),
  ('normal control 4',
   [1728543600, 0,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20007]],
   'rush')],
 [('regression: utc offset sign',
   [1728165600, 330,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20005]],
   'late_night'),
  ('partial repair probe: utc offset sign',
   [1728169200, 330,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20002]],
   'holiday'),
  ('second regression',
   [1728370800, 600,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20006]],
   'standard'),
  ('normal control 1',
   [1728331831, 60,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20002]],
   'standard'),
  ('normal control 2',
   [1728710003, 60,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20006]],
   'standard'),
  ('normal control 3',
   [1728867600, -300,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20011]],
   'standard'),
  ('normal control 4',
   [1728194400, 600,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20011]],
   'standard')]]
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(ts_utc, offset_min, cards, holidays):
    local = ts_utc + offset_min
    day = local // 86400
    minute = local % 86400 // 60
    wd = (day + 3) % 7
    is_hol = day in holidays
    for c in cards:
        if c['days'] == 'holiday':
            if is_hol and c['start'] <= minute < c['end']:
                return c['card']
            continue
        if c['start'] < c['end']:
            if wd in c['days'] and c['start'] <= minute < c['end']:
                return c['card']
        else:
            if wd in c['days'] and minute >= c['start']:
                return c['card']
            if (wd - 1) % 7 in c['days'] and minute < c['end']:
                return c['card']
    return 'standard'
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: utc offset sign',
   [1728863940, -480,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20002]],
   'standard'),
  ('partial repair probe: utc offset sign',
   [1728082800, 600,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20008]],
   'standard'),
  ('second regression',
   [1728601200, -480,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20000]],
   'standard'),
  ('normal control 1',
   [1728000000, 330,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20012]],
   'standard'),
  ('normal control 2',
   [1728972000, -480,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20003]],
   'standard'),
  ('normal control 3',
   [1728864060, 600,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20012]],
   'standard'),
  ('normal control 4',
   [1728856800, -300,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20004]],
   'standard')],
 [('regression: utc offset sign',
   [1728856800, 600,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20004]],
   'rush'),
  ('partial repair probe: utc offset sign',
   [1728342000, 600,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20008]],
   'rush'),
  ('second regression',
   [1728518400, -480,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20002]],
   'standard'),
  ('normal control 1',
   [1728345660, -300,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20000]],
   'standard'),
  ('normal control 2',
   [1728863940, 60,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20005]],
   'standard'),
  ('normal control 3',
   [1728000000, 330,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20012]],
   'standard'),
  ('normal control 4',
   [1728946800, -300,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20004]],
   'standard')],
 [('regression: utc offset sign',
   [1728468000, 60,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20012]],
   'standard'),
  ('partial repair probe: utc offset sign',
   [1729005186, 600,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20011]],
   'standard'),
  ('second regression',
   [1728457200, 60,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20006]],
   'rush'),
  ('normal control 1',
   [1728108000, 0,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20008]],
   'standard'),
  ('normal control 2',
   [1729033200, 330,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20005]],
   'standard'),
  ('normal control 3',
   [1729058400, -480,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20006]],
   'standard'),
  ('normal control 4',
   [1728712800, 60,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20010]],
   'standard')],
 [('regression: utc offset sign',
   [1728198000, 330,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20013]],
   'standard'),
  ('partial repair probe: utc offset sign',
   [1728783376, 330,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20005]],
   'standard'),
  ('second regression',
   [1728640800, -300,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20004]],
   'standard'),
  ('normal control 1',
   [1729159200, 330,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20010]],
   'standard'),
  ('normal control 2',
   [1728511200, 0,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20003]],
   'standard'),
  ('normal control 3',
   [1729206000, 60,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20005]],
   'standard'),
  ('normal control 4',
   [1728543600, 0,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20007]],
   'rush')],
 [('regression: utc offset sign',
   [1728165600, 330,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20005]],
   'late_night'),
  ('partial repair probe: utc offset sign',
   [1728169200, 330,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20002]],
   'holiday'),
  ('second regression',
   [1728370800, 600,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20006]],
   'standard'),
  ('normal control 1',
   [1728331831, 60,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20002]],
   'standard'),
  ('normal control 2',
   [1728710003, 60,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20006]],
   'standard'),
  ('normal control 3',
   [1728867600, -300,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20011]],
   'standard'),
  ('normal control 4',
   [1728194400, 600,
    [{'card': 'holiday', 'days': 'holiday', 'end': 1440, 'start': 0},
     {'card': 'late_night', 'days': [4, 5], 'end': 240, 'start': 1320},
     {'card': 'rush', 'days': [0, 1, 2, 3, 4], 'end': 600, 'start': 420}],
    [20011]],
   'standard')]]
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 city behind UTC gets its evening rush card in the early afternoon.

Pick the rate card for a pickup at ts_utc seconds (Unix epoch; day 0 was a Thursday) in a city at offset_min minutes from UTC. Local day index and minute-of-day come from the local time; weekday is Monday=0. Cards are checked in order, windows are half-open [start, end) minutes; a window with start > end wraps midnight and its after-midnight part belongs to the previous weekday. Holiday cards match local day indexes in holidays. Default "standard".

split: open-access