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

N = 1
observations = []
def solve(quote, actual, rate):
    def metered():
        return rate['base'] + (actual['m'] * rate['per_km'] * 2 + 1000) // 2000 + (actual['s'] * rate['per_min'] * 2 + 60) // 120
    if actual['dest'] != quote['dest']:
        reason = 'destination'
    elif actual['stops_added'] > 0:
        reason = 'stops'
    elif actual['m'] * 4 >= quote['est_m'] * 5:
        reason = 'distance'
    elif actual['s'] * 2 > quote['est_s'] * 3:
        reason = 'time'
    else:
        reason = 'quote'
    charged = quote['price'] if reason == 'quote' else metered()
    return {'charged': charged, 'reason': reason}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: distance deviation edge',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 1801, 'price': 1250},
    {'dest': 'D1', 'm': 5000, 's': 2701, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1250, 'reason': 'quote'}),
  ('partial repair probe: distance deviation edge',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 1200, 'price': 1250},
    {'dest': 'D1', 'm': 10001, 's': 1800, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 1250, 'reason': 'quote'}),
  ('second regression',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 601, 'price': 1250},
    {'dest': 'D1', 'm': 1252, 's': 501, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1250, 'reason': 'quote'}),
  ('normal control 1',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 900, 'price': 1250},
    {'dest': 'D2', 'm': 10002, 's': 1350, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1750, 'reason': 'destination'}),
  ('normal control 2',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 601, 'price': 1250},
    {'dest': 'D2', 'm': 10000, 's': 901, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 1826, 'reason': 'destination'}),
  ('normal control 3',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 601, 'price': 1250},
    {'dest': 'D1', 'm': 15000, 's': 1202, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 2476, 'reason': 'distance'}),
  ('normal control 4',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 900, 'price': 3999},
    {'dest': 'D2', 'm': 802, 's': 1351, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 1088, 'reason': 'destination'})],
 [('regression: distance deviation edge',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 601, 'price': 2100},
    {'dest': 'D1', 'm': 5000, 's': 601, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 2100, 'reason': 'quote'}),
  ('partial repair probe: distance deviation edge',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 900, 'price': 3999},
    {'dest': 'D1', 'm': 1252, 's': 1800, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 938, 'reason': 'time'}),
  ('second regression',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 900, 'price': 3999},
    {'dest': 'D1', 'm': 1252, 's': 1800, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 957, 'reason': 'time'}),
  ('normal control 1',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 900, 'price': 3999},
    {'dest': 'D2', 'm': 5000, 's': 800, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 1092, 'reason': 'destination'}),
  ('normal control 2',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 1801, 'price': 2100},
    {'dest': 'D1', 'm': 3800, 's': 1701, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 2100, 'reason': 'quote'}),
  ('normal control 3',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 1801, 'price': 2100},
    {'dest': 'D1', 'm': 1002, 's': 1801, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 2100, 'reason': 'quote'}),
  ('normal control 4',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 900, 'price': 3999},
    {'dest': 'D1', 'm': 12501, 's': 1800, 'stops_added': 1}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 2813, 'reason': 'stops'})],
 [('regression: distance deviation edge',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 1200, 'price': 1250},
    {'dest': 'D1', 'm': 12500, 's': 1200, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 1250, 'reason': 'quote'}),
  ('partial repair probe: distance deviation edge',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 601, 'price': 2100},
    {'dest': 'D1', 'm': 10001, 's': 902, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 1976, 'reason': 'time'}),
  ('second regression',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 1801, 'price': 2100},
    {'dest': 'D1', 'm': 5000, 's': 1801, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 2100, 'reason': 'quote'}),
  ('normal control 1',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 900, 'price': 1250},
    {'dest': 'D1', 'm': 12001, 's': 900, 'stops_added': 1}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1820, 'reason': 'stops'}),
  ('normal control 2',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 1200, 'price': 3999},
    {'dest': 'D1', 'm': 3800, 's': 1200, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 3999, 'reason': 'quote'}),
  ('normal control 3',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 1200, 'price': 1250},
    {'dest': 'D1', 'm': 3800, 's': 1801, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 1726, 'reason': 'time'}),
  ('normal control 4',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 900, 'price': 1250},
    {'dest': 'D1', 'm': 802, 's': 800, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 1250, 'reason': 'quote'})],
 [('regression: distance deviation edge',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 1801, 'price': 1250},
    {'dest': 'D1', 'm': 12500, 's': 2701, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 1250, 'reason': 'quote'}),
  ('partial repair probe: distance deviation edge',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 1801, 'price': 2100},
    {'dest': 'D1', 'm': 12500, 's': 3602, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 2776, 'reason': 'time'}),
  ('second regression',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 601, 'price': 3999},
    {'dest': 'D1', 'm': 12500, 's': 1202, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 2164, 'reason': 'time'}),
  ('normal control 1',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 1200, 'price': 3999},
    {'dest': 'D2', 'm': 1503, 's': 2400, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 1188, 'reason': 'destination'}),
  ('normal control 2',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 1801, 'price': 2100},
    {'dest': 'D1', 'm': 9800, 's': 2702, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 2854, 'reason': 'time'}),
  ('normal control 3',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 601, 'price': 3999},
    {'dest': 'D1', 'm': 6000, 's': 501, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 1242, 'reason': 'distance'}),
  ('normal control 4',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 1801, 'price': 3999},
    {'dest': 'D1', 'm': 1253, 's': 2701, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 1914, 'reason': 'distance'})],
 [('regression: distance deviation edge',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 900, 'price': 2100},
    {'dest': 'D1', 'm': 12500, 's': 1800, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 2625, 'reason': 'time'}),
  ('partial repair probe: distance deviation edge',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 601, 'price': 2100},
    {'dest': 'D1', 'm': 12500, 's': 1202, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1976, 'reason': 'time'}),
  ('second regression',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 1200, 'price': 2100},
    {'dest': 'D1', 'm': 5000, 's': 2400, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 2225, 'reason': 'time'}),
  ('normal control 1',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 1801, 'price': 2100},
    {'dest': 'D1', 'm': 12501, 's': 1701, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 2330, 'reason': 'distance'}),
  ('normal control 2',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 900, 'price': 1250},
    {'dest': 'D1', 'm': 10002, 's': 1350, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 1900, 'reason': 'distance'}),
  ('normal control 3',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 1801, 'price': 2100},
    {'dest': 'D2', 'm': 10002, 's': 2702, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 3026, 'reason': 'destination'}),
  ('normal control 4',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 1801, 'price': 2100},
    {'dest': 'D1', 'm': 10002, 's': 1701, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 2017, 'reason': 'distance'})]]
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(quote, actual, rate):
    def metered():
        return rate['base'] + (actual['m'] * rate['per_km'] * 2 + 1000) // 2000 + (actual['s'] * rate['per_min'] * 2 + 60) // 120
    if actual['dest'] != quote['dest']:
        reason = 'destination'
    elif actual['stops_added'] > 0:
        reason = 'stops'
    elif actual['m'] >= quote['est_m'] * 5 // 4:
        reason = 'distance'
    elif actual['s'] * 2 > quote['est_s'] * 3:
        reason = 'time'
    else:
        reason = 'quote'
    charged = quote['price'] if reason == 'quote' else metered()
    return {'charged': charged, 'reason': reason}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: distance deviation edge',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 1801, 'price': 1250},
    {'dest': 'D1', 'm': 5000, 's': 2701, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1250, 'reason': 'quote'}),
  ('partial repair probe: distance deviation edge',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 1200, 'price': 1250},
    {'dest': 'D1', 'm': 10001, 's': 1800, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 1250, 'reason': 'quote'}),
  ('second regression',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 601, 'price': 1250},
    {'dest': 'D1', 'm': 1252, 's': 501, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1250, 'reason': 'quote'}),
  ('normal control 1',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 900, 'price': 1250},
    {'dest': 'D2', 'm': 10002, 's': 1350, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1750, 'reason': 'destination'}),
  ('normal control 2',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 601, 'price': 1250},
    {'dest': 'D2', 'm': 10000, 's': 901, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 1826, 'reason': 'destination'}),
  ('normal control 3',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 601, 'price': 1250},
    {'dest': 'D1', 'm': 15000, 's': 1202, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 2476, 'reason': 'distance'}),
  ('normal control 4',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 900, 'price': 3999},
    {'dest': 'D2', 'm': 802, 's': 1351, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 1088, 'reason': 'destination'})],
 [('regression: distance deviation edge',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 601, 'price': 2100},
    {'dest': 'D1', 'm': 5000, 's': 601, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 2100, 'reason': 'quote'}),
  ('partial repair probe: distance deviation edge',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 900, 'price': 3999},
    {'dest': 'D1', 'm': 1252, 's': 1800, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 938, 'reason': 'time'}),
  ('second regression',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 900, 'price': 3999},
    {'dest': 'D1', 'm': 1252, 's': 1800, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 957, 'reason': 'time'}),
  ('normal control 1',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 900, 'price': 3999},
    {'dest': 'D2', 'm': 5000, 's': 800, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 1092, 'reason': 'destination'}),
  ('normal control 2',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 1801, 'price': 2100},
    {'dest': 'D1', 'm': 3800, 's': 1701, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 2100, 'reason': 'quote'}),
  ('normal control 3',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 1801, 'price': 2100},
    {'dest': 'D1', 'm': 1002, 's': 1801, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 2100, 'reason': 'quote'}),
  ('normal control 4',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 900, 'price': 3999},
    {'dest': 'D1', 'm': 12501, 's': 1800, 'stops_added': 1}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 2813, 'reason': 'stops'})],
 [('regression: distance deviation edge',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 1200, 'price': 1250},
    {'dest': 'D1', 'm': 12500, 's': 1200, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 1250, 'reason': 'quote'}),
  ('partial repair probe: distance deviation edge',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 601, 'price': 2100},
    {'dest': 'D1', 'm': 10001, 's': 902, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 1976, 'reason': 'time'}),
  ('second regression',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 1801, 'price': 2100},
    {'dest': 'D1', 'm': 5000, 's': 1801, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 2100, 'reason': 'quote'}),
  ('normal control 1',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 900, 'price': 1250},
    {'dest': 'D1', 'm': 12001, 's': 900, 'stops_added': 1}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1820, 'reason': 'stops'}),
  ('normal control 2',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 1200, 'price': 3999},
    {'dest': 'D1', 'm': 3800, 's': 1200, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 3999, 'reason': 'quote'}),
  ('normal control 3',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 1200, 'price': 1250},
    {'dest': 'D1', 'm': 3800, 's': 1801, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 1726, 'reason': 'time'}),
  ('normal control 4',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 900, 'price': 1250},
    {'dest': 'D1', 'm': 802, 's': 800, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 1250, 'reason': 'quote'})],
 [('regression: distance deviation edge',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 1801, 'price': 1250},
    {'dest': 'D1', 'm': 12500, 's': 2701, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 1250, 'reason': 'quote'}),
  ('partial repair probe: distance deviation edge',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 1801, 'price': 2100},
    {'dest': 'D1', 'm': 12500, 's': 3602, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 2776, 'reason': 'time'}),
  ('second regression',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 601, 'price': 3999},
    {'dest': 'D1', 'm': 12500, 's': 1202, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 2164, 'reason': 'time'}),
  ('normal control 1',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 1200, 'price': 3999},
    {'dest': 'D2', 'm': 1503, 's': 2400, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 1188, 'reason': 'destination'}),
  ('normal control 2',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 1801, 'price': 2100},
    {'dest': 'D1', 'm': 9800, 's': 2702, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 2854, 'reason': 'time'}),
  ('normal control 3',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 601, 'price': 3999},
    {'dest': 'D1', 'm': 6000, 's': 501, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 1242, 'reason': 'distance'}),
  ('normal control 4',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 1801, 'price': 3999},
    {'dest': 'D1', 'm': 1253, 's': 2701, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 1914, 'reason': 'distance'})],
 [('regression: distance deviation edge',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 900, 'price': 2100},
    {'dest': 'D1', 'm': 12500, 's': 1800, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 2625, 'reason': 'time'}),
  ('partial repair probe: distance deviation edge',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 601, 'price': 2100},
    {'dest': 'D1', 'm': 12500, 's': 1202, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1976, 'reason': 'time'}),
  ('second regression',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 1200, 'price': 2100},
    {'dest': 'D1', 'm': 5000, 's': 2400, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 2225, 'reason': 'time'}),
  ('normal control 1',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 1801, 'price': 2100},
    {'dest': 'D1', 'm': 12501, 's': 1701, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 2330, 'reason': 'distance'}),
  ('normal control 2',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 900, 'price': 1250},
    {'dest': 'D1', 'm': 10002, 's': 1350, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 1900, 'reason': 'distance'}),
  ('normal control 3',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 1801, 'price': 2100},
    {'dest': 'D2', 'm': 10002, 's': 2702, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 3026, 'reason': 'destination'}),
  ('normal control 4',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 1801, 'price': 2100},
    {'dest': 'D1', 'm': 10002, 's': 1701, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 2017, 'reason': 'distance'})]]
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 trip precisely at the 25% tolerance is repriced on the meter.

An upfront quote is honored unless (checked in this order) the destination changed, stops were added, actual distance exceeds the estimate by more than 25% (m*4 > est*5), or actual time exceeds it by more than 50% (s*2 > est*3). Otherwise-recomputed fares use actual meters and seconds: base + half-up(m*per_km/1000) + half-up(s*per_min/60). Return the charge and the reason code.

split: open-access


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

N = 1
observations = []
def solve(quote, actual, rate):
    def metered():
        return rate['base'] + (actual['m'] * rate['per_km'] * 2 + 1000) // 2000 + (actual['s'] * rate['per_min'] * 2 + 60) // 120
    if actual['dest'] != quote['dest']:
        reason = 'destination'
    elif actual['stops_added'] > 0:
        reason = 'stops'
    elif actual['m'] * 4 > quote['est_m'] * 5:
        reason = 'distance'
    elif actual['s'] * 3 > quote['est_s'] * 2:
        reason = 'time'
    else:
        reason = 'quote'
    charged = quote['price'] if reason == 'quote' else metered()
    return {'charged': charged, 'reason': reason}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: time deviation ratio',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 900, 'price': 1250},
    {'dest': 'D1', 'm': 5000, 's': 800, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1250, 'reason': 'quote'}),
  ('partial repair probe: time deviation ratio',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 1801, 'price': 3999},
    {'dest': 'D1', 'm': 802, 's': 3602, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 1501, 'reason': 'time'}),
  ('second regression',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 1801, 'price': 2100},
    {'dest': 'D1', 'm': 8001, 's': 2701, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 2100, 'reason': 'quote'}),
  ('normal control 1',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 900, 'price': 1250},
    {'dest': 'D1', 'm': 1252, 's': 1351, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 1145, 'reason': 'time'}),
  ('normal control 2',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 1801, 'price': 2100},
    {'dest': 'D1', 'm': 5001, 's': 1801, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 1801, 'reason': 'distance'}),
  ('normal control 3',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 601, 'price': 2100},
    {'dest': 'D2', 'm': 8001, 's': 601, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 1551, 'reason': 'destination'}),
  ('normal control 4',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 601, 'price': 1250},
    {'dest': 'D2', 'm': 5000, 's': 501, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 992, 'reason': 'destination'})],
 [('regression: time deviation ratio',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 900, 'price': 3999},
    {'dest': 'D1', 'm': 7801, 's': 1350, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 3999, 'reason': 'quote'}),
  ('partial repair probe: time deviation ratio',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 1200, 'price': 1250},
    {'dest': 'D1', 'm': 1002, 's': 2400, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 1710, 'reason': 'time'}),
  ('second regression',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 601, 'price': 2100},
    {'dest': 'D1', 'm': 4000, 's': 1202, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1041, 'reason': 'time'}),
  ('normal control 1',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 1200, 'price': 2100},
    {'dest': 'D1', 'm': 12501, 's': 1800, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 2813, 'reason': 'distance'}),
  ('normal control 2',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 1200, 'price': 3999},
    {'dest': 'D2', 'm': 10000, 's': 2400, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 2850, 'reason': 'destination'}),
  ('normal control 3',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 900, 'price': 1250},
    {'dest': 'D1', 'm': 1253, 's': 1351, 'stops_added': 1}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 807, 'reason': 'stops'}),
  ('normal control 4',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 900, 'price': 3999},
    {'dest': 'D2', 'm': 10000, 's': 1350, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 2088, 'reason': 'destination'})],
 [('regression: time deviation ratio',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 1801, 'price': 3999},
    {'dest': 'D1', 'm': 7801, 's': 1801, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 3999, 'reason': 'quote'}),
  ('partial repair probe: time deviation ratio',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 601, 'price': 1250},
    {'dest': 'D1', 'm': 7801, 's': 902, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 1584, 'reason': 'time'}),
  ('second regression',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 900, 'price': 1250},
    {'dest': 'D1', 'm': 1252, 's': 800, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1250, 'reason': 'quote'}),
  ('normal control 1',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 1801, 'price': 3999},
    {'dest': 'D2', 'm': 4000, 's': 3602, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1841, 'reason': 'destination'}),
  ('normal control 2',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 601, 'price': 3999},
    {'dest': 'D2', 'm': 5000, 's': 901, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 1125, 'reason': 'destination'}),
  ('normal control 3',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 601, 'price': 3999},
    {'dest': 'D2', 'm': 3800, 's': 601, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 1026, 'reason': 'destination'}),
  ('normal control 4',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 601, 'price': 1250},
    {'dest': 'D1', 'm': 12001, 's': 601, 'stops_added': 1}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1720, 'reason': 'stops'})],
 [('regression: time deviation ratio',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 601, 'price': 3999},
    {'dest': 'D1', 'm': 12500, 's': 901, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 3999, 'reason': 'quote'}),
  ('partial repair probe: time deviation ratio',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 601, 'price': 3999},
    {'dest': 'D1', 'm': 10000, 's': 1202, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 1851, 'reason': 'time'}),
  ('second regression',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 1200, 'price': 1250},
    {'dest': 'D1', 'm': 4000, 's': 1801, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1240, 'reason': 'time'}),
  ('normal control 1',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 1200, 'price': 1250},
    {'dest': 'D1', 'm': 1503, 's': 2400, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1165, 'reason': 'distance'}),
  ('normal control 2',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 900, 'price': 2100},
    {'dest': 'D2', 'm': 10000, 's': 900, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 1975, 'reason': 'destination'}),
  ('normal control 3',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 1801, 'price': 1250},
    {'dest': 'D1', 'm': 10002, 's': 2701, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 2876, 'reason': 'distance'}),
  ('normal control 4',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 601, 'price': 1250},
    {'dest': 'D2', 'm': 1503, 's': 1202, 'stops_added': 1}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 1089, 'reason': 'destination'})],
 [('regression: time deviation ratio',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 900, 'price': 2100},
    {'dest': 'D1', 'm': 4000, 's': 1350, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 2100, 'reason': 'quote'}),
  ('partial repair probe: time deviation ratio',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 1200, 'price': 2100},
    {'dest': 'D1', 'm': 9800, 's': 2400, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 2678, 'reason': 'time'}),
  ('second regression',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 601, 'price': 1250},
    {'dest': 'D1', 'm': 1002, 's': 501, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 1250, 'reason': 'quote'}),
  ('normal control 1',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 601, 'price': 2100},
    {'dest': 'D1', 'm': 1252, 's': 1202, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 739, 'reason': 'time'}),
  ('normal control 2',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 1801, 'price': 3999},
    {'dest': 'D1', 'm': 12001, 's': 3602, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 2721, 'reason': 'distance'}),
  ('normal control 3',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 1200, 'price': 2100},
    {'dest': 'D1', 'm': 1252, 's': 1801, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 1389, 'reason': 'time'}),
  ('normal control 4',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 1200, 'price': 2100},
    {'dest': 'D1', 'm': 1253, 's': 1801, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 938, 'reason': 'distance'})]]
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(quote, actual, rate):
    def metered():
        return rate['base'] + (actual['m'] * rate['per_km'] * 2 + 1000) // 2000 + (actual['s'] * rate['per_min'] * 2 + 60) // 120
    if actual['dest'] != quote['dest']:
        reason = 'destination'
    elif actual['stops_added'] > 0:
        reason = 'stops'
    elif actual['m'] * 4 > quote['est_m'] * 5:
        reason = 'distance'
    elif actual['s'] * 2 > quote['est_s'] * 3 and actual['m'] > quote['est_m']:
        reason = 'time'
    else:
        reason = 'quote'
    charged = quote['price'] if reason == 'quote' else metered()
    return {'charged': charged, 'reason': reason}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: time deviation ratio',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 900, 'price': 1250},
    {'dest': 'D1', 'm': 5000, 's': 800, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1250, 'reason': 'quote'}),
  ('partial repair probe: time deviation ratio',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 1801, 'price': 3999},
    {'dest': 'D1', 'm': 802, 's': 3602, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 1501, 'reason': 'time'}),
  ('second regression',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 1801, 'price': 2100},
    {'dest': 'D1', 'm': 8001, 's': 2701, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 2100, 'reason': 'quote'}),
  ('normal control 1',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 900, 'price': 1250},
    {'dest': 'D1', 'm': 1252, 's': 1351, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 1145, 'reason': 'time'}),
  ('normal control 2',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 1801, 'price': 2100},
    {'dest': 'D1', 'm': 5001, 's': 1801, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 1801, 'reason': 'distance'}),
  ('normal control 3',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 601, 'price': 2100},
    {'dest': 'D2', 'm': 8001, 's': 601, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 1551, 'reason': 'destination'}),
  ('normal control 4',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 601, 'price': 1250},
    {'dest': 'D2', 'm': 5000, 's': 501, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 992, 'reason': 'destination'})],
 [('regression: time deviation ratio',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 900, 'price': 3999},
    {'dest': 'D1', 'm': 7801, 's': 1350, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 3999, 'reason': 'quote'}),
  ('partial repair probe: time deviation ratio',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 1200, 'price': 1250},
    {'dest': 'D1', 'm': 1002, 's': 2400, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 1710, 'reason': 'time'}),
  ('second regression',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 601, 'price': 2100},
    {'dest': 'D1', 'm': 4000, 's': 1202, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1041, 'reason': 'time'}),
  ('normal control 1',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 1200, 'price': 2100},
    {'dest': 'D1', 'm': 12501, 's': 1800, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 2813, 'reason': 'distance'}),
  ('normal control 2',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 1200, 'price': 3999},
    {'dest': 'D2', 'm': 10000, 's': 2400, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 2850, 'reason': 'destination'}),
  ('normal control 3',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 900, 'price': 1250},
    {'dest': 'D1', 'm': 1253, 's': 1351, 'stops_added': 1}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 807, 'reason': 'stops'}),
  ('normal control 4',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 900, 'price': 3999},
    {'dest': 'D2', 'm': 10000, 's': 1350, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 2088, 'reason': 'destination'})],
 [('regression: time deviation ratio',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 1801, 'price': 3999},
    {'dest': 'D1', 'm': 7801, 's': 1801, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 3999, 'reason': 'quote'}),
  ('partial repair probe: time deviation ratio',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 601, 'price': 1250},
    {'dest': 'D1', 'm': 7801, 's': 902, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 1584, 'reason': 'time'}),
  ('second regression',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 900, 'price': 1250},
    {'dest': 'D1', 'm': 1252, 's': 800, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1250, 'reason': 'quote'}),
  ('normal control 1',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 1801, 'price': 3999},
    {'dest': 'D2', 'm': 4000, 's': 3602, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1841, 'reason': 'destination'}),
  ('normal control 2',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 601, 'price': 3999},
    {'dest': 'D2', 'm': 5000, 's': 901, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 1125, 'reason': 'destination'}),
  ('normal control 3',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 601, 'price': 3999},
    {'dest': 'D2', 'm': 3800, 's': 601, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 1026, 'reason': 'destination'}),
  ('normal control 4',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 601, 'price': 1250},
    {'dest': 'D1', 'm': 12001, 's': 601, 'stops_added': 1}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1720, 'reason': 'stops'})],
 [('regression: time deviation ratio',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 601, 'price': 3999},
    {'dest': 'D1', 'm': 12500, 's': 901, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 3999, 'reason': 'quote'}),
  ('partial repair probe: time deviation ratio',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 601, 'price': 3999},
    {'dest': 'D1', 'm': 10000, 's': 1202, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 1851, 'reason': 'time'}),
  ('second regression',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 1200, 'price': 1250},
    {'dest': 'D1', 'm': 4000, 's': 1801, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1240, 'reason': 'time'}),
  ('normal control 1',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 1200, 'price': 1250},
    {'dest': 'D1', 'm': 1503, 's': 2400, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1165, 'reason': 'distance'}),
  ('normal control 2',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 900, 'price': 2100},
    {'dest': 'D2', 'm': 10000, 's': 900, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 1975, 'reason': 'destination'}),
  ('normal control 3',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 1801, 'price': 1250},
    {'dest': 'D1', 'm': 10002, 's': 2701, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 2876, 'reason': 'distance'}),
  ('normal control 4',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 601, 'price': 1250},
    {'dest': 'D2', 'm': 1503, 's': 1202, 'stops_added': 1}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 1089, 'reason': 'destination'})],
 [('regression: time deviation ratio',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 900, 'price': 2100},
    {'dest': 'D1', 'm': 4000, 's': 1350, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 2100, 'reason': 'quote'}),
  ('partial repair probe: time deviation ratio',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 1200, 'price': 2100},
    {'dest': 'D1', 'm': 9800, 's': 2400, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 2678, 'reason': 'time'}),
  ('second regression',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 601, 'price': 1250},
    {'dest': 'D1', 'm': 1002, 's': 501, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 1250, 'reason': 'quote'}),
  ('normal control 1',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 601, 'price': 2100},
    {'dest': 'D1', 'm': 1252, 's': 1202, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 739, 'reason': 'time'}),
  ('normal control 2',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 1801, 'price': 3999},
    {'dest': 'D1', 'm': 12001, 's': 3602, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 2721, 'reason': 'distance'}),
  ('normal control 3',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 1200, 'price': 2100},
    {'dest': 'D1', 'm': 1252, 's': 1801, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 1389, 'reason': 'time'}),
  ('normal control 4',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 1200, 'price': 2100},
    {'dest': 'D1', 'm': 1253, 's': 1801, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 938, 'reason': 'distance'})]]
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:
Any trip taking more than two thirds of the estimated time is metered.

An upfront quote is honored unless (checked in this order) the destination changed, stops were added, actual distance exceeds the estimate by more than 25% (m*4 > est*5), or actual time exceeds it by more than 50% (s*2 > est*3). Otherwise-recomputed fares use actual meters and seconds: base + half-up(m*per_km/1000) + half-up(s*per_min/60). Return the charge and the reason code.

split: open-access


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

N = 1
observations = []
def solve(quote, actual, rate):
    def metered():
        return rate['base'] + (actual['m'] * rate['per_km'] * 2 + 1000) // 2000 + (actual['s'] * rate['per_min'] * 2 + 60) // 120
    if actual['stops_added'] > 0:
        reason = 'stops'
    elif actual['dest'] != quote['dest']:
        reason = 'destination'
    elif actual['m'] * 4 > quote['est_m'] * 5:
        reason = 'distance'
    elif actual['s'] * 2 > quote['est_s'] * 3:
        reason = 'time'
    else:
        reason = 'quote'
    charged = quote['price'] if reason == 'quote' else metered()
    return {'charged': charged, 'reason': reason}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: reason precedence',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 1801, 'price': 3999},
    {'dest': 'D2', 'm': 6000, 's': 2702, 'stops_added': 1}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 2526, 'reason': 'destination'}),
  ('partial repair probe: reason precedence',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 1801, 'price': 3999},
    {'dest': 'D1', 'm': 10001, 's': 1701, 'stops_added': 1}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1867, 'reason': 'stops'}),
  ('second regression',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 1200, 'price': 3999},
    {'dest': 'D1', 'm': 8001, 's': 1100, 'stops_added': 1}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 1722, 'reason': 'stops'}),
  ('normal control 1',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 1801, 'price': 2100},
    {'dest': 'D1', 'm': 1253, 's': 2701, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 1914, 'reason': 'distance'}),
  ('normal control 2',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 1801, 'price': 1250},
    {'dest': 'D1', 'm': 4000, 's': 2701, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1250, 'reason': 'quote'}),
  ('normal control 3',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 1200, 'price': 2100},
    {'dest': 'D1', 'm': 8001, 's': 1200, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 2100, 'reason': 'quote'}),
  ('normal control 4',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 1801, 'price': 3999},
    {'dest': 'D1', 'm': 1253, 's': 3602, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 1558, 'reason': 'distance'})],
 [('regression: reason precedence',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 1801, 'price': 1250},
    {'dest': 'D2', 'm': 4000, 's': 2701, 'stops_added': 1}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 2276, 'reason': 'destination'}),
  ('partial repair probe: reason precedence',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 900, 'price': 2100},
    {'dest': 'D1', 'm': 1503, 's': 1800, 'stops_added': 1}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 965, 'reason': 'stops'}),
  ('second regression',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 601, 'price': 1250},
    {'dest': 'D1', 'm': 7801, 's': 1202, 'stops_added': 1}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 1759, 'reason': 'stops'}),
  ('normal control 1',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 900, 'price': 3999},
    {'dest': 'D1', 'm': 802, 's': 1350, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 3999, 'reason': 'quote'}),
  ('normal control 2',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 601, 'price': 1250},
    {'dest': 'D1', 'm': 1253, 's': 902, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 639, 'reason': 'distance'}),
  ('normal control 3',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 601, 'price': 2100},
    {'dest': 'D1', 'm': 8001, 's': 601, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 2100, 'reason': 'quote'}),
  ('normal control 4',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 1200, 'price': 2100},
    {'dest': 'D1', 'm': 8001, 's': 1100, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 2100, 'reason': 'quote'})],
 [('regression: reason precedence',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 1801, 'price': 1250},
    {'dest': 'D2', 'm': 1253, 's': 1701, 'stops_added': 1}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 905, 'reason': 'destination'}),
  ('partial repair probe: reason precedence',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 900, 'price': 1250},
    {'dest': 'D1', 'm': 10001, 's': 1351, 'stops_added': 1}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 2088, 'reason': 'stops'}),
  ('second regression',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 601, 'price': 2100},
    {'dest': 'D1', 'm': 8001, 's': 901, 'stops_added': 1}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 1726, 'reason': 'stops'}),
  ('normal control 1',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 900, 'price': 1250},
    {'dest': 'D1', 'm': 7801, 's': 1351, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 1846, 'reason': 'time'}),
  ('normal control 2',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 601, 'price': 1250},
    {'dest': 'D1', 'm': 9800, 's': 902, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1579, 'reason': 'time'}),
  ('normal control 3',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 601, 'price': 1250},
    {'dest': 'D1', 'm': 10001, 's': 902, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 1826, 'reason': 'time'}),
  ('normal control 4',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 1801, 'price': 1250},
    {'dest': 'D1', 'm': 10002, 's': 2701, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 2350, 'reason': 'distance'})],
 [('regression: reason precedence',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 1801, 'price': 2100},
    {'dest': 'D2', 'm': 12001, 's': 2702, 'stops_added': 1}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 2421, 'reason': 'destination'}),
  ('partial repair probe: reason precedence',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 900, 'price': 2100},
    {'dest': 'D1', 'm': 7801, 's': 800, 'stops_added': 1}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 1642, 'reason': 'stops'}),
  ('second regression',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 1200, 'price': 1250},
    {'dest': 'D1', 'm': 5000, 's': 2400, 'stops_added': 1}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 1625, 'reason': 'stops'}),
  ('normal control 1',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 1801, 'price': 1250},
    {'dest': 'D1', 'm': 5000, 's': 3602, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 2851, 'reason': 'time'}),
  ('normal control 2',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 601, 'price': 3999},
    {'dest': 'D1', 'm': 8001, 's': 902, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1381, 'reason': 'time'}),
  ('normal control 3',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 601, 'price': 3999},
    {'dest': 'D1', 'm': 6000, 's': 601, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1060, 'reason': 'distance'}),
  ('normal control 4',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 601, 'price': 1250},
    {'dest': 'D1', 'm': 12501, 's': 1202, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1976, 'reason': 'distance'})],
 [('regression: reason precedence',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 900, 'price': 2100},
    {'dest': 'D2', 'm': 10002, 's': 1351, 'stops_added': 1}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 1900, 'reason': 'destination'}),
  ('partial repair probe: reason precedence',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 601, 'price': 1250},
    {'dest': 'D1', 'm': 1002, 's': 901, 'stops_added': 1}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 610, 'reason': 'stops'}),
  ('second regression',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 601, 'price': 2100},
    {'dest': 'D2', 'm': 1253, 's': 1202, 'stops_added': 1}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 1058, 'reason': 'destination'}),
  ('normal control 1',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 1200, 'price': 1250},
    {'dest': 'D2', 'm': 9800, 's': 2400, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 2225, 'reason': 'destination'}),
  ('normal control 2',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 601, 'price': 1250},
    {'dest': 'D2', 'm': 5001, 's': 902, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1051, 'reason': 'destination'}),
  ('normal control 3',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 601, 'price': 3999},
    {'dest': 'D2', 'm': 4000, 's': 601, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 991, 'reason': 'destination'}),
  ('normal control 4',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 601, 'price': 2100},
    {'dest': 'D1', 'm': 802, 's': 1202, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 689, 'reason': 'time'})]]
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(quote, actual, rate):
    def metered():
        return rate['base'] + (actual['m'] * rate['per_km'] * 2 + 1000) // 2000 + (actual['s'] * rate['per_min'] * 2 + 60) // 120
    if actual['dest'] != quote['dest'] or actual['stops_added'] > 0:
        reason = 'destination'
    elif actual['m'] * 4 > quote['est_m'] * 5:
        reason = 'distance'
    elif actual['s'] * 2 > quote['est_s'] * 3:
        reason = 'time'
    else:
        reason = 'quote'
    charged = quote['price'] if reason == 'quote' else metered()
    return {'charged': charged, 'reason': reason}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: reason precedence',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 1801, 'price': 3999},
    {'dest': 'D2', 'm': 6000, 's': 2702, 'stops_added': 1}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 2526, 'reason': 'destination'}),
  ('partial repair probe: reason precedence',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 1801, 'price': 3999},
    {'dest': 'D1', 'm': 10001, 's': 1701, 'stops_added': 1}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1867, 'reason': 'stops'}),
  ('second regression',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 1200, 'price': 3999},
    {'dest': 'D1', 'm': 8001, 's': 1100, 'stops_added': 1}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 1722, 'reason': 'stops'}),
  ('normal control 1',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 1801, 'price': 2100},
    {'dest': 'D1', 'm': 1253, 's': 2701, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 1914, 'reason': 'distance'}),
  ('normal control 2',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 1801, 'price': 1250},
    {'dest': 'D1', 'm': 4000, 's': 2701, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1250, 'reason': 'quote'}),
  ('normal control 3',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 1200, 'price': 2100},
    {'dest': 'D1', 'm': 8001, 's': 1200, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 2100, 'reason': 'quote'}),
  ('normal control 4',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 1801, 'price': 3999},
    {'dest': 'D1', 'm': 1253, 's': 3602, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 1558, 'reason': 'distance'})],
 [('regression: reason precedence',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 1801, 'price': 1250},
    {'dest': 'D2', 'm': 4000, 's': 2701, 'stops_added': 1}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 2276, 'reason': 'destination'}),
  ('partial repair probe: reason precedence',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 900, 'price': 2100},
    {'dest': 'D1', 'm': 1503, 's': 1800, 'stops_added': 1}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 965, 'reason': 'stops'}),
  ('second regression',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 601, 'price': 1250},
    {'dest': 'D1', 'm': 7801, 's': 1202, 'stops_added': 1}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 1759, 'reason': 'stops'}),
  ('normal control 1',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 900, 'price': 3999},
    {'dest': 'D1', 'm': 802, 's': 1350, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 3999, 'reason': 'quote'}),
  ('normal control 2',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 601, 'price': 1250},
    {'dest': 'D1', 'm': 1253, 's': 902, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 639, 'reason': 'distance'}),
  ('normal control 3',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 601, 'price': 2100},
    {'dest': 'D1', 'm': 8001, 's': 601, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 2100, 'reason': 'quote'}),
  ('normal control 4',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 1200, 'price': 2100},
    {'dest': 'D1', 'm': 8001, 's': 1100, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 2100, 'reason': 'quote'})],
 [('regression: reason precedence',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 1801, 'price': 1250},
    {'dest': 'D2', 'm': 1253, 's': 1701, 'stops_added': 1}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 905, 'reason': 'destination'}),
  ('partial repair probe: reason precedence',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 900, 'price': 1250},
    {'dest': 'D1', 'm': 10001, 's': 1351, 'stops_added': 1}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 2088, 'reason': 'stops'}),
  ('second regression',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 601, 'price': 2100},
    {'dest': 'D1', 'm': 8001, 's': 901, 'stops_added': 1}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 1726, 'reason': 'stops'}),
  ('normal control 1',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 900, 'price': 1250},
    {'dest': 'D1', 'm': 7801, 's': 1351, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 1846, 'reason': 'time'}),
  ('normal control 2',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 601, 'price': 1250},
    {'dest': 'D1', 'm': 9800, 's': 902, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1579, 'reason': 'time'}),
  ('normal control 3',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 601, 'price': 1250},
    {'dest': 'D1', 'm': 10001, 's': 902, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 1826, 'reason': 'time'}),
  ('normal control 4',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 1801, 'price': 1250},
    {'dest': 'D1', 'm': 10002, 's': 2701, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 2350, 'reason': 'distance'})],
 [('regression: reason precedence',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 1801, 'price': 2100},
    {'dest': 'D2', 'm': 12001, 's': 2702, 'stops_added': 1}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 2421, 'reason': 'destination'}),
  ('partial repair probe: reason precedence',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 900, 'price': 2100},
    {'dest': 'D1', 'm': 7801, 's': 800, 'stops_added': 1}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 1642, 'reason': 'stops'}),
  ('second regression',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 1200, 'price': 1250},
    {'dest': 'D1', 'm': 5000, 's': 2400, 'stops_added': 1}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 1625, 'reason': 'stops'}),
  ('normal control 1',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 1801, 'price': 1250},
    {'dest': 'D1', 'm': 5000, 's': 3602, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 2851, 'reason': 'time'}),
  ('normal control 2',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 601, 'price': 3999},
    {'dest': 'D1', 'm': 8001, 's': 902, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1381, 'reason': 'time'}),
  ('normal control 3',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 601, 'price': 3999},
    {'dest': 'D1', 'm': 6000, 's': 601, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1060, 'reason': 'distance'}),
  ('normal control 4',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 601, 'price': 1250},
    {'dest': 'D1', 'm': 12501, 's': 1202, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1976, 'reason': 'distance'})],
 [('regression: reason precedence',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 900, 'price': 2100},
    {'dest': 'D2', 'm': 10002, 's': 1351, 'stops_added': 1}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 1900, 'reason': 'destination'}),
  ('partial repair probe: reason precedence',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 601, 'price': 1250},
    {'dest': 'D1', 'm': 1002, 's': 901, 'stops_added': 1}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 610, 'reason': 'stops'}),
  ('second regression',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 601, 'price': 2100},
    {'dest': 'D2', 'm': 1253, 's': 1202, 'stops_added': 1}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 1058, 'reason': 'destination'}),
  ('normal control 1',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 1200, 'price': 1250},
    {'dest': 'D2', 'm': 9800, 's': 2400, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 2225, 'reason': 'destination'}),
  ('normal control 2',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 601, 'price': 1250},
    {'dest': 'D2', 'm': 5001, 's': 902, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1051, 'reason': 'destination'}),
  ('normal control 3',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 601, 'price': 3999},
    {'dest': 'D2', 'm': 4000, 's': 601, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 991, 'reason': 'destination'}),
  ('normal control 4',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 601, 'price': 2100},
    {'dest': 'D1', 'm': 802, 's': 1202, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 689, 'reason': 'time'})]]
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:
Receipts cite added stops when the rider also changed the destination.

An upfront quote is honored unless (checked in this order) the destination changed, stops were added, actual distance exceeds the estimate by more than 25% (m*4 > est*5), or actual time exceeds it by more than 50% (s*2 > est*3). Otherwise-recomputed fares use actual meters and seconds: base + half-up(m*per_km/1000) + half-up(s*per_min/60). Return the charge and the reason code.

split: open-access


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

N = 1
observations = []
def solve(quote, actual, rate):
    def metered():
        return rate['base'] + (quote['est_m'] * rate['per_km'] * 2 + 1000) // 2000 + (actual['s'] * rate['per_min'] * 2 + 60) // 120
    if actual['dest'] != quote['dest']:
        reason = 'destination'
    elif actual['stops_added'] > 0:
        reason = 'stops'
    elif actual['m'] * 4 > quote['est_m'] * 5:
        reason = 'distance'
    elif actual['s'] * 2 > quote['est_s'] * 3:
        reason = 'time'
    else:
        reason = 'quote'
    charged = quote['price'] if reason == 'quote' else metered()
    return {'charged': charged, 'reason': reason}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: recompute inputs',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 900, 'price': 3999},
    {'dest': 'D1', 'm': 6000, 's': 900, 'stops_added': 1}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 1385, 'reason': 'stops'}),
  ('partial repair probe: recompute inputs',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 601, 'price': 3999},
    {'dest': 'D1', 'm': 6000, 's': 1202, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1261, 'reason': 'distance'}),
  ('second regression',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 900, 'price': 1250},
    {'dest': 'D2', 'm': 5000, 's': 900, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 1125, 'reason': 'destination'}),
  ('normal control 1',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 601, 'price': 2100},
    {'dest': 'D1', 'm': 10001, 's': 501, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 2100, 'reason': 'quote'}),
  ('normal control 2',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 1801, 'price': 3999},
    {'dest': 'D1', 'm': 10000, 's': 1801, 'stops_added': 1}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 2501, 'reason': 'stops'}),
  ('normal control 3',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 900, 'price': 2100},
    {'dest': 'D1', 'm': 12500, 's': 1350, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 2100, 'reason': 'quote'}),
  ('normal control 4',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 1200, 'price': 3999},
    {'dest': 'D1', 'm': 9800, 's': 1100, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 3999, 'reason': 'quote'})],
 [('regression: recompute inputs',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 900, 'price': 1250},
    {'dest': 'D1', 'm': 6000, 's': 1350, 'stops_added': 1}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 1738, 'reason': 'stops'}),
  ('partial repair probe: recompute inputs',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 1200, 'price': 3999},
    {'dest': 'D1', 'm': 10002, 's': 1100, 'stops_added': 1}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 2092, 'reason': 'stops'}),
  ('second regression',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 1801, 'price': 2100},
    {'dest': 'D1', 'm': 1252, 's': 1701, 'stops_added': 1}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 905, 'reason': 'stops'}),
  ('normal control 1',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 1200, 'price': 2100},
    {'dest': 'D1', 'm': 10000, 's': 1800, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 2100, 'reason': 'quote'}),
  ('normal control 2',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 1801, 'price': 3999},
    {'dest': 'D1', 'm': 1252, 's': 2701, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 3999, 'reason': 'quote'}),
  ('normal control 3',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 1200, 'price': 1250},
    {'dest': 'D1', 'm': 4000, 's': 1200, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 1250, 'reason': 'quote'}),
  ('normal control 4',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 1200, 'price': 1250},
    {'dest': 'D1', 'm': 3800, 's': 1100, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 1250, 'reason': 'quote'})],
 [('regression: recompute inputs',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 601, 'price': 2100},
    {'dest': 'D1', 'm': 10002, 's': 1202, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 2151, 'reason': 'distance'}),
  ('partial repair probe: recompute inputs',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 601, 'price': 1250},
    {'dest': 'D1', 'm': 10000, 's': 1202, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 1851, 'reason': 'time'}),
  ('second regression',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 900, 'price': 3999},
    {'dest': 'D1', 'm': 1002, 's': 1351, 'stops_added': 1}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 760, 'reason': 'stops'}),
  ('normal control 1',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 601, 'price': 3999},
    {'dest': 'D1', 'm': 4000, 's': 901, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 3999, 'reason': 'quote'}),
  ('normal control 2',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 1200, 'price': 2100},
    {'dest': 'D1', 'm': 3800, 's': 1200, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 2100, 'reason': 'quote'}),
  ('normal control 3',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 601, 'price': 3999},
    {'dest': 'D1', 'm': 5000, 's': 901, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 3999, 'reason': 'quote'}),
  ('normal control 4',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 601, 'price': 3999},
    {'dest': 'D1', 'm': 7801, 's': 901, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 3999, 'reason': 'quote'})],
 [('regression: recompute inputs',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 1200, 'price': 3999},
    {'dest': 'D2', 'm': 802, 's': 1100, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 667, 'reason': 'destination'}),
  ('partial repair probe: recompute inputs',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 1801, 'price': 3999},
    {'dest': 'D2', 'm': 5001, 's': 1701, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 1392, 'reason': 'destination'}),
  ('second regression',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 1801, 'price': 3999},
    {'dest': 'D2', 'm': 10001, 's': 1801, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1900, 'reason': 'destination'}),
  ('normal control 1',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 601, 'price': 1250},
    {'dest': 'D1', 'm': 9800, 's': 901, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 1250, 'reason': 'quote'}),
  ('normal control 2',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 1200, 'price': 1250},
    {'dest': 'D1', 'm': 802, 's': 1800, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 1250, 'reason': 'quote'}),
  ('normal control 3',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 601, 'price': 3999},
    {'dest': 'D1', 'm': 9800, 's': 601, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 3999, 'reason': 'quote'}),
  ('normal control 4',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 601, 'price': 1250},
    {'dest': 'D1', 'm': 4000, 's': 501, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 1250, 'reason': 'quote'})],
 [('regression: recompute inputs',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 1200, 'price': 3999},
    {'dest': 'D1', 'm': 10002, 's': 2400, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 2850, 'reason': 'distance'}),
  ('partial repair probe: recompute inputs',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 601, 'price': 2100},
    {'dest': 'D1', 'm': 12501, 's': 902, 'stops_added': 1}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 2064, 'reason': 'stops'}),
  ('second regression',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 900, 'price': 3999},
    {'dest': 'D1', 'm': 9800, 's': 900, 'stops_added': 1}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1578, 'reason': 'stops'}),
  ('normal control 1',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 601, 'price': 1250},
    {'dest': 'D1', 'm': 8001, 's': 501, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 1250, 'reason': 'quote'}),
  ('normal control 2',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 601, 'price': 3999},
    {'dest': 'D1', 'm': 802, 's': 501, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 3999, 'reason': 'quote'}),
  ('normal control 3',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 601, 'price': 3999},
    {'dest': 'D1', 'm': 3800, 's': 601, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 3999, 'reason': 'quote'}),
  ('normal control 4',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 900, 'price': 3999},
    {'dest': 'D1', 'm': 802, 's': 1350, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 3999, 'reason': 'quote'})]]
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(quote, actual, rate):
    def metered():
        return rate['base'] + (actual['m'] * rate['per_km'] * 2 + 1000) // 2000 + (quote['est_s'] * rate['per_min'] * 2 + 60) // 120
    if actual['dest'] != quote['dest']:
        reason = 'destination'
    elif actual['stops_added'] > 0:
        reason = 'stops'
    elif actual['m'] * 4 > quote['est_m'] * 5:
        reason = 'distance'
    elif actual['s'] * 2 > quote['est_s'] * 3:
        reason = 'time'
    else:
        reason = 'quote'
    charged = quote['price'] if reason == 'quote' else metered()
    return {'charged': charged, 'reason': reason}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: recompute inputs',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 900, 'price': 3999},
    {'dest': 'D1', 'm': 6000, 's': 900, 'stops_added': 1}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 1385, 'reason': 'stops'}),
  ('partial repair probe: recompute inputs',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 601, 'price': 3999},
    {'dest': 'D1', 'm': 6000, 's': 1202, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1261, 'reason': 'distance'}),
  ('second regression',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 900, 'price': 1250},
    {'dest': 'D2', 'm': 5000, 's': 900, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 1125, 'reason': 'destination'}),
  ('normal control 1',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 601, 'price': 2100},
    {'dest': 'D1', 'm': 10001, 's': 501, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 2100, 'reason': 'quote'}),
  ('normal control 2',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 1801, 'price': 3999},
    {'dest': 'D1', 'm': 10000, 's': 1801, 'stops_added': 1}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 2501, 'reason': 'stops'}),
  ('normal control 3',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 900, 'price': 2100},
    {'dest': 'D1', 'm': 12500, 's': 1350, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 2100, 'reason': 'quote'}),
  ('normal control 4',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 1200, 'price': 3999},
    {'dest': 'D1', 'm': 9800, 's': 1100, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 3999, 'reason': 'quote'})],
 [('regression: recompute inputs',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 900, 'price': 1250},
    {'dest': 'D1', 'm': 6000, 's': 1350, 'stops_added': 1}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 1738, 'reason': 'stops'}),
  ('partial repair probe: recompute inputs',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 1200, 'price': 3999},
    {'dest': 'D1', 'm': 10002, 's': 1100, 'stops_added': 1}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 2092, 'reason': 'stops'}),
  ('second regression',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 1801, 'price': 2100},
    {'dest': 'D1', 'm': 1252, 's': 1701, 'stops_added': 1}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 905, 'reason': 'stops'}),
  ('normal control 1',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 1200, 'price': 2100},
    {'dest': 'D1', 'm': 10000, 's': 1800, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 2100, 'reason': 'quote'}),
  ('normal control 2',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 1801, 'price': 3999},
    {'dest': 'D1', 'm': 1252, 's': 2701, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 3999, 'reason': 'quote'}),
  ('normal control 3',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 1200, 'price': 1250},
    {'dest': 'D1', 'm': 4000, 's': 1200, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 1250, 'reason': 'quote'}),
  ('normal control 4',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 1200, 'price': 1250},
    {'dest': 'D1', 'm': 3800, 's': 1100, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 1250, 'reason': 'quote'})],
 [('regression: recompute inputs',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 601, 'price': 2100},
    {'dest': 'D1', 'm': 10002, 's': 1202, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 2151, 'reason': 'distance'}),
  ('partial repair probe: recompute inputs',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 601, 'price': 1250},
    {'dest': 'D1', 'm': 10000, 's': 1202, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 1851, 'reason': 'time'}),
  ('second regression',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 900, 'price': 3999},
    {'dest': 'D1', 'm': 1002, 's': 1351, 'stops_added': 1}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 760, 'reason': 'stops'}),
  ('normal control 1',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 601, 'price': 3999},
    {'dest': 'D1', 'm': 4000, 's': 901, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 3999, 'reason': 'quote'}),
  ('normal control 2',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 1200, 'price': 2100},
    {'dest': 'D1', 'm': 3800, 's': 1200, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 2100, 'reason': 'quote'}),
  ('normal control 3',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 601, 'price': 3999},
    {'dest': 'D1', 'm': 5000, 's': 901, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 3999, 'reason': 'quote'}),
  ('normal control 4',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 601, 'price': 3999},
    {'dest': 'D1', 'm': 7801, 's': 901, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 3999, 'reason': 'quote'})],
 [('regression: recompute inputs',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 1200, 'price': 3999},
    {'dest': 'D2', 'm': 802, 's': 1100, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 667, 'reason': 'destination'}),
  ('partial repair probe: recompute inputs',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 1801, 'price': 3999},
    {'dest': 'D2', 'm': 5001, 's': 1701, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 1392, 'reason': 'destination'}),
  ('second regression',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 1801, 'price': 3999},
    {'dest': 'D2', 'm': 10001, 's': 1801, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1900, 'reason': 'destination'}),
  ('normal control 1',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 601, 'price': 1250},
    {'dest': 'D1', 'm': 9800, 's': 901, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 1250, 'reason': 'quote'}),
  ('normal control 2',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 1200, 'price': 1250},
    {'dest': 'D1', 'm': 802, 's': 1800, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 1250, 'reason': 'quote'}),
  ('normal control 3',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 601, 'price': 3999},
    {'dest': 'D1', 'm': 9800, 's': 601, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 3999, 'reason': 'quote'}),
  ('normal control 4',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 601, 'price': 1250},
    {'dest': 'D1', 'm': 4000, 's': 501, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 1250, 'reason': 'quote'})],
 [('regression: recompute inputs',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 1200, 'price': 3999},
    {'dest': 'D1', 'm': 10002, 's': 2400, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 2850, 'reason': 'distance'}),
  ('partial repair probe: recompute inputs',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 601, 'price': 2100},
    {'dest': 'D1', 'm': 12501, 's': 902, 'stops_added': 1}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 2064, 'reason': 'stops'}),
  ('second regression',
   [{'dest': 'D1', 'est_m': 10000, 'est_s': 900, 'price': 3999},
    {'dest': 'D1', 'm': 9800, 's': 900, 'stops_added': 1}, {'base': 200, 'per_km': 110, 'per_min': 20}],
   {'charged': 1578, 'reason': 'stops'}),
  ('normal control 1',
   [{'dest': 'D1', 'est_m': 8001, 'est_s': 601, 'price': 1250},
    {'dest': 'D1', 'm': 8001, 's': 501, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 20}],
   {'charged': 1250, 'reason': 'quote'}),
  ('normal control 2',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 601, 'price': 3999},
    {'dest': 'D1', 'm': 802, 's': 501, 'stops_added': 0}, {'base': 200, 'per_km': 125, 'per_min': 35}],
   {'charged': 3999, 'reason': 'quote'}),
  ('normal control 3',
   [{'dest': 'D1', 'est_m': 4000, 'est_s': 601, 'price': 3999},
    {'dest': 'D1', 'm': 3800, 's': 601, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 3999, 'reason': 'quote'}),
  ('normal control 4',
   [{'dest': 'D1', 'est_m': 1002, 'est_s': 900, 'price': 3999},
    {'dest': 'D1', 'm': 802, 's': 1350, 'stops_added': 0}, {'base': 200, 'per_km': 110, 'per_min': 35}],
   {'charged': 3999, 'reason': 'quote'})]]
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 rider who lengthened the trip pays for the estimated distance.

An upfront quote is honored unless (checked in this order) the destination changed, stops were added, actual distance exceeds the estimate by more than 25% (m*4 > est*5), or actual time exceeds it by more than 50% (s*2 > est*3). Otherwise-recomputed fares use actual meters and seconds: base + half-up(m*per_km/1000) + half-up(s*per_min/60). Return the charge and the reason code.

split: open-access


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

N = 1
observations = []
def solve(ev, policy):
    start = ev['arrive'] if ev['scheduled'] is None else max(ev['arrive'], ev['scheduled'])
    wait = ev['board'] - start
    if wait <= policy['grace']:
        return 0
    minutes = (wait - policy['grace']) // 60
    return min(minutes, policy['cap_min']) * policy['per_min']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: started minute billing',
   [{'arrive': 10000, 'board': 10301, 'scheduled': 10120}, {'cap_min': 10, 'grace': 120, 'per_min': 40}],
   80),
  ('partial repair probe: started minute billing',
   [{'arrive': 10000, 'board': 10421, 'scheduled': 10300}, {'cap_min': 5, 'grace': 120, 'per_min': 25}], 25),
  ('second regression',
   [{'arrive': 10000, 'board': 10401, 'scheduled': None}, {'cap_min': 10, 'grace': 120, 'per_min': 40}],
   200),
  ('normal control 1',
   [{'arrive': 10000, 'board': 10120, 'scheduled': None}, {'cap_min': 5, 'grace': 120, 'per_min': 25}], 0),
  ('normal control 2',
   [{'arrive': 10000, 'board': 10900, 'scheduled': 9940}, {'cap_min': 10, 'grace': 120, 'per_min': 25}],
   250),
  ('normal control 3',
   [{'arrive': 10000, 'board': 11020, 'scheduled': 10120}, {'cap_min': 10, 'grace': 120, 'per_min': 25}],
   250),
  ('normal control 4',
   [{'arrive': 10000, 'board': 10060, 'scheduled': None}, {'cap_min': 10, 'grace': 120, 'per_min': 40}], 0)],
 [('regression: started minute billing',
   [{'arrive': 10000, 'board': 10241, 'scheduled': 10120}, {'cap_min': 5, 'grace': 120, 'per_min': 25}], 25),
  ('partial repair probe: started minute billing',
   [{'arrive': 10000, 'board': 10421, 'scheduled': 10300}, {'cap_min': 5, 'grace': 120, 'per_min': 40}], 40),
  ('second regression',
   [{'arrive': 10000, 'board': 10121, 'scheduled': None}, {'cap_min': 5, 'grace': 120, 'per_min': 35}], 35),
  ('normal control 1',
   [{'arrive': 10000, 'board': 10420, 'scheduled': 10300}, {'cap_min': 10, 'grace': 120, 'per_min': 40}], 0),
  ('normal control 2',
   [{'arrive': 10000, 'board': 11178, 'scheduled': None}, {'cap_min': 10, 'grace': 120, 'per_min': 25}],
   250),
  ('normal control 3',
   [{'arrive': 10000, 'board': 10060, 'scheduled': None}, {'cap_min': 5, 'grace': 120, 'per_min': 25}], 0),
  ('normal control 4',
   [{'arrive': 10000, 'board': 10600, 'scheduled': 9940}, {'cap_min': 10, 'grace': 120, 'per_min': 40}],
   320)],
 [('regression: started minute billing',
   [{'arrive': 10000, 'board': 10301, 'scheduled': 10120}, {'cap_min': 10, 'grace': 120, 'per_min': 40}],
   80),
  ('partial repair probe: started minute billing',
   [{'arrive': 10000, 'board': 10301, 'scheduled': 10120}, {'cap_min': 5, 'grace': 120, 'per_min': 35}], 70),
  ('second regression',
   [{'arrive': 10000, 'board': 10121, 'scheduled': 9940}, {'cap_min': 10, 'grace': 120, 'per_min': 25}], 25),
  ('normal control 1',
   [{'arrive': 10000, 'board': 11020, 'scheduled': 10120}, {'cap_min': 10, 'grace': 120, 'per_min': 25}],
   250),
  ('normal control 2',
   [{'arrive': 10000, 'board': 10300, 'scheduled': 10300}, {'cap_min': 5, 'grace': 120, 'per_min': 35}], 0),
  ('normal control 3',
   [{'arrive': 10000, 'board': 10900, 'scheduled': None}, {'cap_min': 10, 'grace': 120, 'per_min': 40}],
   400),
  ('normal control 4',
   [{'arrive': 10000, 'board': 10900, 'scheduled': 9940}, {'cap_min': 5, 'grace': 120, 'per_min': 35}],
   175)],
 [('regression: started minute billing',
   [{'arrive': 10000, 'board': 10421, 'scheduled': 10300}, {'cap_min': 5, 'grace': 120, 'per_min': 40}], 40),
  ('partial repair probe: started minute billing',
   [{'arrive': 10000, 'board': 10181, 'scheduled': 9940}, {'cap_min': 10, 'grace': 120, 'per_min': 40}], 80),
  ('second regression',
   [{'arrive': 10000, 'board': 10642, 'scheduled': None}, {'cap_min': 10, 'grace': 120, 'per_min': 40}],
   360),
  ('normal control 1',
   [{'arrive': 10000, 'board': 10300, 'scheduled': 10300}, {'cap_min': 10, 'grace': 120, 'per_min': 25}], 0),
  ('normal control 2',
   [{'arrive': 10000, 'board': 10872, 'scheduled': None}, {'cap_min': 5, 'grace': 120, 'per_min': 35}], 175),
  ('normal control 3',
   [{'arrive': 10000, 'board': 10060, 'scheduled': None}, {'cap_min': 5, 'grace': 120, 'per_min': 35}], 0),
  ('normal control 4',
   [{'arrive': 10000, 'board': 10120, 'scheduled': None}, {'cap_min': 10, 'grace': 120, 'per_min': 35}], 0)],
 [('regression: started minute billing',
   [{'arrive': 10000, 'board': 10301, 'scheduled': 10120}, {'cap_min': 5, 'grace': 120, 'per_min': 35}], 70),
  ('partial repair probe: started minute billing',
   [{'arrive': 10000, 'board': 10181, 'scheduled': None}, {'cap_min': 5, 'grace': 120, 'per_min': 35}], 70),
  ('second regression',
   [{'arrive': 10000, 'board': 10121, 'scheduled': 9940}, {'cap_min': 10, 'grace': 120, 'per_min': 35}], 35),
  ('normal control 1',
   [{'arrive': 10000, 'board': 10900, 'scheduled': 9940}, {'cap_min': 5, 'grace': 120, 'per_min': 35}], 175),
  ('normal control 2',
   [{'arrive': 10000, 'board': 11162, 'scheduled': 10120}, {'cap_min': 10, 'grace': 120, 'per_min': 25}],
   250),
  ('normal control 3',
   [{'arrive': 10000, 'board': 10180, 'scheduled': None}, {'cap_min': 5, 'grace': 120, 'per_min': 25}], 25),
  ('normal control 4',
   [{'arrive': 10000, 'board': 11200, 'scheduled': 10300}, {'cap_min': 5, 'grace': 120, 'per_min': 35}],
   175)]]
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):
    start = ev['arrive'] if ev['scheduled'] is None else max(ev['arrive'], ev['scheduled'])
    wait = ev['board'] - start
    if wait <= policy['grace']:
        return 0
    minutes = round((wait - policy['grace']) / 60)
    return min(minutes, policy['cap_min']) * policy['per_min']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: started minute billing',
   [{'arrive': 10000, 'board': 10301, 'scheduled': 10120}, {'cap_min': 10, 'grace': 120, 'per_min': 40}],
   80),
  ('partial repair probe: started minute billing',
   [{'arrive': 10000, 'board': 10421, 'scheduled': 10300}, {'cap_min': 5, 'grace': 120, 'per_min': 25}], 25),
  ('second regression',
   [{'arrive': 10000, 'board': 10401, 'scheduled': None}, {'cap_min': 10, 'grace': 120, 'per_min': 40}],
   200),
  ('normal control 1',
   [{'arrive': 10000, 'board': 10120, 'scheduled': None}, {'cap_min': 5, 'grace': 120, 'per_min': 25}], 0),
  ('normal control 2',
   [{'arrive': 10000, 'board': 10900, 'scheduled': 9940}, {'cap_min': 10, 'grace': 120, 'per_min': 25}],
   250),
  ('normal control 3',
   [{'arrive': 10000, 'board': 11020, 'scheduled': 10120}, {'cap_min': 10, 'grace': 120, 'per_min': 25}],
   250),
  ('normal control 4',
   [{'arrive': 10000, 'board': 10060, 'scheduled': None}, {'cap_min': 10, 'grace': 120, 'per_min': 40}], 0)],
 [('regression: started minute billing',
   [{'arrive': 10000, 'board': 10241, 'scheduled': 10120}, {'cap_min': 5, 'grace': 120, 'per_min': 25}], 25),
  ('partial repair probe: started minute billing',
   [{'arrive': 10000, 'board': 10421, 'scheduled': 10300}, {'cap_min': 5, 'grace': 120, 'per_min': 40}], 40),
  ('second regression',
   [{'arrive': 10000, 'board': 10121, 'scheduled': None}, {'cap_min': 5, 'grace': 120, 'per_min': 35}], 35),
  ('normal control 1',
   [{'arrive': 10000, 'board': 10420, 'scheduled': 10300}, {'cap_min': 10, 'grace': 120, 'per_min': 40}], 0),
  ('normal control 2',
   [{'arrive': 10000, 'board': 11178, 'scheduled': None}, {'cap_min': 10, 'grace': 120, 'per_min': 25}],
   250),
  ('normal control 3',
   [{'arrive': 10000, 'board': 10060, 'scheduled': None}, {'cap_min': 5, 'grace': 120, 'per_min': 25}], 0),
  ('normal control 4',
   [{'arrive': 10000, 'board': 10600, 'scheduled': 9940}, {'cap_min': 10, 'grace': 120, 'per_min': 40}],
   320)],
 [('regression: started minute billing',
   [{'arrive': 10000, 'board': 10301, 'scheduled': 10120}, {'cap_min': 10, 'grace': 120, 'per_min': 40}],
   80),
  ('partial repair probe: started minute billing',
   [{'arrive': 10000, 'board': 10301, 'scheduled': 10120}, {'cap_min': 5, 'grace': 120, 'per_min': 35}], 70),
  ('second regression',
   [{'arrive': 10000, 'board': 10121, 'scheduled': 9940}, {'cap_min': 10, 'grace': 120, 'per_min': 25}], 25),
  ('normal control 1',
   [{'arrive': 10000, 'board': 11020, 'scheduled': 10120}, {'cap_min': 10, 'grace': 120, 'per_min': 25}],
   250),
  ('normal control 2',
   [{'arrive': 10000, 'board': 10300, 'scheduled': 10300}, {'cap_min': 5, 'grace': 120, 'per_min': 35}], 0),
  ('normal control 3',
   [{'arrive': 10000, 'board': 10900, 'scheduled': None}, {'cap_min': 10, 'grace': 120, 'per_min': 40}],
   400),
  ('normal control 4',
   [{'arrive': 10000, 'board': 10900, 'scheduled': 9940}, {'cap_min': 5, 'grace': 120, 'per_min': 35}],
   175)],
 [('regression: started minute billing',
   [{'arrive': 10000, 'board': 10421, 'scheduled': 10300}, {'cap_min': 5, 'grace': 120, 'per_min': 40}], 40),
  ('partial repair probe: started minute billing',
   [{'arrive': 10000, 'board': 10181, 'scheduled': 9940}, {'cap_min': 10, 'grace': 120, 'per_min': 40}], 80),
  ('second regression',
   [{'arrive': 10000, 'board': 10642, 'scheduled': None}, {'cap_min': 10, 'grace': 120, 'per_min': 40}],
   360),
  ('normal control 1',
   [{'arrive': 10000, 'board': 10300, 'scheduled': 10300}, {'cap_min': 10, 'grace': 120, 'per_min': 25}], 0),
  ('normal control 2',
   [{'arrive': 10000, 'board': 10872, 'scheduled': None}, {'cap_min': 5, 'grace': 120, 'per_min': 35}], 175),
  ('normal control 3',
   [{'arrive': 10000, 'board': 10060, 'scheduled': None}, {'cap_min': 5, 'grace': 120, 'per_min': 35}], 0),
  ('normal control 4',
   [{'arrive': 10000, 'board': 10120, 'scheduled': None}, {'cap_min': 10, 'grace': 120, 'per_min': 35}], 0)],
 [('regression: started minute billing',
   [{'arrive': 10000, 'board': 10301, 'scheduled': 10120}, {'cap_min': 5, 'grace': 120, 'per_min': 35}], 70),
  ('partial repair probe: started minute billing',
   [{'arrive': 10000, 'board': 10181, 'scheduled': None}, {'cap_min': 5, 'grace': 120, 'per_min': 35}], 70),
  ('second regression',
   [{'arrive': 10000, 'board': 10121, 'scheduled': 9940}, {'cap_min': 10, 'grace': 120, 'per_min': 35}], 35),
  ('normal control 1',
   [{'arrive': 10000, 'board': 10900, 'scheduled': 9940}, {'cap_min': 5, 'grace': 120, 'per_min': 35}], 175),
  ('normal control 2',
   [{'arrive': 10000, 'board': 11162, 'scheduled': 10120}, {'cap_min': 10, 'grace': 120, 'per_min': 25}],
   250),
  ('normal control 3',
   [{'arrive': 10000, 'board': 10180, 'scheduled': None}, {'cap_min': 5, 'grace': 120, 'per_min': 25}], 25),
  ('normal control 4',
   [{'arrive': 10000, 'board': 11200, 'scheduled': 10300}, {'cap_min': 5, 'grace': 120, 'per_min': 35}],
   175)]]
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 rider who kept the driver 61 seconds past grace pays for one minute instead of two.

Wait time starts at driver arrival, or at the scheduled pickup time if the ride was scheduled and the driver arrived early. The first grace seconds are free; beyond that each started minute is billed at per_min cents, up to cap_min billed minutes. Return the wait fee in cents.

split: open-access