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

N = 1
observations = []
def solve(x):
    inc = x['increment']
    c = x['paid_cents'] - x['paid_cents'] % inc
    now = x['now']
    if now >= x['enf_end']:
        return [None, 0]
    base = max(now, x['enf_start'])
    start = base if x['expiry'] is None else max(base, x['expiry'])
    mins = c * 60 // x['rate_per_hour']
    end = min(start + mins, base + x['max_minutes'], x['enf_end'])
    used = max(0, end - start)
    cost = min(c, used * x['rate_per_hour'] // 60)
    return [max(end, start), cost]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'now': 1080, 'expiry': None, 'paid_cents': 342, 'rate_per_hour': 200, 'max_minutes': 60, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [None, 0]), ({'now': 853, 'expiry': None, 'paid_cents': 395, 'rate_per_hour': 250, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [947, 392]), ({'now': 600, 'expiry': 650, 'paid_cents': 400, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [720, 234]), ({'now': 491, 'expiry': None, 'paid_cents': 211, 'rate_per_hour': 250, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [541, 209]), ({'now': 880, 'expiry': None, 'paid_cents': 102, 'rate_per_hour': 250, 'max_minutes': 60, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [904, 100]), ({'now': 420, 'expiry': None, 'paid_cents': 200, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [540, 200]), ({'now': 1048, 'expiry': 1120, 'paid_cents': 599, 'rate_per_hour': 100, 'max_minutes': 240, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [1120, 0]), ({'now': 1040, 'expiry': None, 'paid_cents': 333, 'rate_per_hour': 150, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [1080, 100])], [({'now': 783, 'expiry': None, 'paid_cents': 518, 'rate_per_hour': 250, 'max_minutes': 240, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [906, 513]), ({'now': 420, 'expiry': None, 'paid_cents': 200, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [540, 200]), ({'now': 1040, 'expiry': None, 'paid_cents': 333, 'rate_per_hour': 150, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [1080, 100]), ({'now': 608, 'expiry': 560, 'paid_cents': 57, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [623, 50]), ({'now': 1006, 'expiry': 975, 'paid_cents': 428, 'rate_per_hour': 250, 'max_minutes': 240, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [1080, 309]), ({'now': 424, 'expiry': 372, 'paid_cents': 544, 'rate_per_hour': 250, 'max_minutes': 240, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [609, 538]), ({'now': 1080, 'expiry': 1100, 'paid_cents': 100, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [None, 0]), ({'now': 148, 'expiry': 178, 'paid_cents': 179, 'rate_per_hour': 100, 'max_minutes': 60, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [540, 100])], [({'now': 826, 'expiry': 909, 'paid_cents': 304, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [946, 124]), ({'now': 420, 'expiry': None, 'paid_cents': 200, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [540, 200]), ({'now': 1080, 'expiry': None, 'paid_cents': 252, 'rate_per_hour': 100, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [None, 0]), ({'now': 1080, 'expiry': 1100, 'paid_cents': 100, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [None, 0]), ({'now': 943, 'expiry': None, 'paid_cents': 503, 'rate_per_hour': 150, 'max_minutes': 240, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [1080, 343]), ({'now': 1080, 'expiry': None, 'paid_cents': 506, 'rate_per_hour': 100, 'max_minutes': 240, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [None, 0]), ({'now': 779, 'expiry': None, 'paid_cents': 506, 'rate_per_hour': 150, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [899, 300]), ({'now': 600, 'expiry': 650, 'paid_cents': 400, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [720, 234])], [({'now': 600, 'expiry': 650, 'paid_cents': 400, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [720, 234]), ({'now': 104, 'expiry': 123, 'paid_cents': 90, 'rate_per_hour': 250, 'max_minutes': 240, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [501, 88]), ({'now': 1080, 'expiry': 1100, 'paid_cents': 100, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [None, 0]), ({'now': 606, 'expiry': 668, 'paid_cents': 424, 'rate_per_hour': 100, 'max_minutes': 60, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [668, 0]), ({'now': 480, 'expiry': None, 'paid_cents': 287, 'rate_per_hour': 100, 'max_minutes': 240, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [645, 275]), ({'now': 480, 'expiry': None, 'paid_cents': 3, 'rate_per_hour': 150, 'max_minutes': 60, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [480, 0]), ({'now': 1040, 'expiry': None, 'paid_cents': 333, 'rate_per_hour': 150, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [1080, 100]), ({'now': 460, 'expiry': None, 'paid_cents': 15, 'rate_per_hour': 200, 'max_minutes': 60, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [484, 14])], [({'now': 480, 'expiry': 490, 'paid_cents': 142, 'rate_per_hour': 100, 'max_minutes': 60, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [540, 84]), ({'now': 480, 'expiry': None, 'paid_cents': 474, 'rate_per_hour': 150, 'max_minutes': 240, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [660, 450]), ({'now': 480, 'expiry': 538, 'paid_cents': 595, 'rate_per_hour': 250, 'max_minutes': 240, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [680, 592]), ({'now': 1080, 'expiry': 1081, 'paid_cents': 121, 'rate_per_hour': 250, 'max_minutes': 60, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [None, 0]), ({'now': 1080, 'expiry': 1100, 'paid_cents': 100, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [None, 0]), ({'now': 600, 'expiry': 650, 'paid_cents': 400, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [720, 234]), ({'now': 480, 'expiry': 543, 'paid_cents': 144, 'rate_per_hour': 250, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [573, 125]), ({'now': 1040, 'expiry': None, 'paid_cents': 333, 'rate_per_hour': 150, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [1080, 100])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('fee oracle' + ' %d' % i, 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(x):
    inc = x['increment']
    c = x['paid_cents'] - x['paid_cents'] % inc
    now = x['now']
    if now >= x['enf_end']:
        return [None, 0]
    base = max(now, x['enf_start'])
    start = base if x['expiry'] is None else max(base, x['expiry'])
    mins = c * 60 // x['rate_per_hour']
    end = min(start + mins, base + x['max_minutes'], x['enf_end'])
    used = max(0, end - start)
    cost = min(c, c if used else 0)
    return [max(end, start), cost]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'now': 1080, 'expiry': None, 'paid_cents': 342, 'rate_per_hour': 200, 'max_minutes': 60, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [None, 0]), ({'now': 853, 'expiry': None, 'paid_cents': 395, 'rate_per_hour': 250, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [947, 392]), ({'now': 600, 'expiry': 650, 'paid_cents': 400, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [720, 234]), ({'now': 491, 'expiry': None, 'paid_cents': 211, 'rate_per_hour': 250, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [541, 209]), ({'now': 880, 'expiry': None, 'paid_cents': 102, 'rate_per_hour': 250, 'max_minutes': 60, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [904, 100]), ({'now': 420, 'expiry': None, 'paid_cents': 200, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [540, 200]), ({'now': 1048, 'expiry': 1120, 'paid_cents': 599, 'rate_per_hour': 100, 'max_minutes': 240, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [1120, 0]), ({'now': 1040, 'expiry': None, 'paid_cents': 333, 'rate_per_hour': 150, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [1080, 100])], [({'now': 783, 'expiry': None, 'paid_cents': 518, 'rate_per_hour': 250, 'max_minutes': 240, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [906, 513]), ({'now': 420, 'expiry': None, 'paid_cents': 200, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [540, 200]), ({'now': 1040, 'expiry': None, 'paid_cents': 333, 'rate_per_hour': 150, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [1080, 100]), ({'now': 608, 'expiry': 560, 'paid_cents': 57, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [623, 50]), ({'now': 1006, 'expiry': 975, 'paid_cents': 428, 'rate_per_hour': 250, 'max_minutes': 240, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [1080, 309]), ({'now': 424, 'expiry': 372, 'paid_cents': 544, 'rate_per_hour': 250, 'max_minutes': 240, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [609, 538]), ({'now': 1080, 'expiry': 1100, 'paid_cents': 100, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [None, 0]), ({'now': 148, 'expiry': 178, 'paid_cents': 179, 'rate_per_hour': 100, 'max_minutes': 60, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [540, 100])], [({'now': 826, 'expiry': 909, 'paid_cents': 304, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [946, 124]), ({'now': 420, 'expiry': None, 'paid_cents': 200, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [540, 200]), ({'now': 1080, 'expiry': None, 'paid_cents': 252, 'rate_per_hour': 100, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [None, 0]), ({'now': 1080, 'expiry': 1100, 'paid_cents': 100, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [None, 0]), ({'now': 943, 'expiry': None, 'paid_cents': 503, 'rate_per_hour': 150, 'max_minutes': 240, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [1080, 343]), ({'now': 1080, 'expiry': None, 'paid_cents': 506, 'rate_per_hour': 100, 'max_minutes': 240, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [None, 0]), ({'now': 779, 'expiry': None, 'paid_cents': 506, 'rate_per_hour': 150, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [899, 300]), ({'now': 600, 'expiry': 650, 'paid_cents': 400, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [720, 234])], [({'now': 600, 'expiry': 650, 'paid_cents': 400, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [720, 234]), ({'now': 104, 'expiry': 123, 'paid_cents': 90, 'rate_per_hour': 250, 'max_minutes': 240, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [501, 88]), ({'now': 1080, 'expiry': 1100, 'paid_cents': 100, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [None, 0]), ({'now': 606, 'expiry': 668, 'paid_cents': 424, 'rate_per_hour': 100, 'max_minutes': 60, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [668, 0]), ({'now': 480, 'expiry': None, 'paid_cents': 287, 'rate_per_hour': 100, 'max_minutes': 240, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [645, 275]), ({'now': 480, 'expiry': None, 'paid_cents': 3, 'rate_per_hour': 150, 'max_minutes': 60, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [480, 0]), ({'now': 1040, 'expiry': None, 'paid_cents': 333, 'rate_per_hour': 150, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [1080, 100]), ({'now': 460, 'expiry': None, 'paid_cents': 15, 'rate_per_hour': 200, 'max_minutes': 60, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [484, 14])], [({'now': 480, 'expiry': 490, 'paid_cents': 142, 'rate_per_hour': 100, 'max_minutes': 60, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [540, 84]), ({'now': 480, 'expiry': None, 'paid_cents': 474, 'rate_per_hour': 150, 'max_minutes': 240, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [660, 450]), ({'now': 480, 'expiry': 538, 'paid_cents': 595, 'rate_per_hour': 250, 'max_minutes': 240, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [680, 592]), ({'now': 1080, 'expiry': 1081, 'paid_cents': 121, 'rate_per_hour': 250, 'max_minutes': 60, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [None, 0]), ({'now': 1080, 'expiry': 1100, 'paid_cents': 100, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [None, 0]), ({'now': 600, 'expiry': 650, 'paid_cents': 400, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [720, 234]), ({'now': 480, 'expiry': 543, 'paid_cents': 144, 'rate_per_hour': 250, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [573, 125]), ({'now': 1040, 'expiry': None, 'paid_cents': 333, 'rate_per_hour': 150, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [1080, 100])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('fee oracle' + ' %d' % i, 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:
Street meter time purchase returns a wrong result when the accepted amount truncates partial minutes of charge.

Input {now, expiry (or null), paid_cents, rate_per_hour, max_minutes, enf_start, enf_end, increment}. Only whole increments are credited. At or after enforcement end nothing is sold: [null, 0]. Paid time starts at the later of now, enforcement start and any unexpired expiry; it ends at the earliest of start + purchased minutes (floor), max(now, enf_start) + max_minutes, and enf_end. Accepted cents = min(credited, ceil(used minutes * rate/60)). Return [new expiry, accepted cents].

split: open-access


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

N = 1
observations = []
def solve(x):
    inc = x['increment']
    c = x['paid_cents'] - x['paid_cents'] % inc
    now = x['now']
    if now > x['enf_end']:
        return [None, 0]
    base = max(now, x['enf_start'])
    start = base if x['expiry'] is None else max(base, x['expiry'])
    mins = c * 60 // x['rate_per_hour']
    end = min(start + mins, base + x['max_minutes'], x['enf_end'])
    used = max(0, end - start)
    cost = min(c, -(-used * x['rate_per_hour'] // 60))
    return [max(end, start), cost]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'now': 1080, 'expiry': 1078, 'paid_cents': 85, 'rate_per_hour': 100, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [None, 0]), ({'now': 1080, 'expiry': None, 'paid_cents': 480, 'rate_per_hour': 100, 'max_minutes': 240, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [None, 0]), ({'now': 600, 'expiry': 650, 'paid_cents': 400, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [720, 234]), ({'now': 1040, 'expiry': None, 'paid_cents': 333, 'rate_per_hour': 150, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [1080, 100]), ({'now': 1350, 'expiry': 1335, 'paid_cents': 5, 'rate_per_hour': 250, 'max_minutes': 60, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [None, 0]), ({'now': 1080, 'expiry': 1071, 'paid_cents': 491, 'rate_per_hour': 250, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [None, 0]), ({'now': 420, 'expiry': None, 'paid_cents': 200, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [540, 200]), ({'now': 1243, 'expiry': 1214, 'paid_cents': 292, 'rate_per_hour': 200, 'max_minutes': 60, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [None, 0])], [({'now': 1080, 'expiry': 1152, 'paid_cents': 523, 'rate_per_hour': 150, 'max_minutes': 60, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [None, 0]), ({'now': 420, 'expiry': None, 'paid_cents': 200, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [540, 200]), ({'now': 233, 'expiry': 231, 'paid_cents': 298, 'rate_per_hour': 100, 'max_minutes': 60, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [540, 100]), ({'now': 600, 'expiry': 650, 'paid_cents': 400, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [720, 234]), ({'now': 1080, 'expiry': 1025, 'paid_cents': 393, 'rate_per_hour': 100, 'max_minutes': 240, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [None, 0]), ({'now': 655, 'expiry': None, 'paid_cents': 200, 'rate_per_hour': 150, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [735, 200]), ({'now': 1069, 'expiry': 1154, 'paid_cents': 524, 'rate_per_hour': 150, 'max_minutes': 60, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [1154, 0]), ({'now': 1080, 'expiry': 1100, 'paid_cents': 100, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [None, 0])], [({'now': 1080, 'expiry': 1100, 'paid_cents': 100, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [None, 0]), ({'now': 1040, 'expiry': None, 'paid_cents': 333, 'rate_per_hour': 150, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [1080, 100]), ({'now': 600, 'expiry': 650, 'paid_cents': 400, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [720, 234]), ({'now': 1080, 'expiry': None, 'paid_cents': 109, 'rate_per_hour': 100, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [None, 0]), ({'now': 1221, 'expiry': 1229, 'paid_cents': 328, 'rate_per_hour': 150, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [None, 0]), ({'now': 1208, 'expiry': None, 'paid_cents': 533, 'rate_per_hour': 100, 'max_minutes': 60, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [None, 0]), ({'now': 1080, 'expiry': 1154, 'paid_cents': 297, 'rate_per_hour': 100, 'max_minutes': 240, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [None, 0]), ({'now': 480, 'expiry': None, 'paid_cents': 226, 'rate_per_hour': 100, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [600, 200])], [({'now': 1080, 'expiry': 1168, 'paid_cents': 356, 'rate_per_hour': 200, 'max_minutes': 60, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [None, 0]), ({'now': 1080, 'expiry': None, 'paid_cents': 584, 'rate_per_hour': 100, 'max_minutes': 60, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [None, 0]), ({'now': 1080, 'expiry': None, 'paid_cents': 350, 'rate_per_hour': 200, 'max_minutes': 60, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [None, 0]), ({'now': 600, 'expiry': 650, 'paid_cents': 400, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [720, 234]), ({'now': 480, 'expiry': None, 'paid_cents': 469, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [600, 400]), ({'now': 1040, 'expiry': None, 'paid_cents': 333, 'rate_per_hour': 150, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [1080, 100]), ({'now': 1087, 'expiry': 1093, 'paid_cents': 264, 'rate_per_hour': 100, 'max_minutes': 240, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [None, 0]), ({'now': 420, 'expiry': None, 'paid_cents': 200, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [540, 200])], [({'now': 1040, 'expiry': None, 'paid_cents': 333, 'rate_per_hour': 150, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [1080, 100]), ({'now': 63, 'expiry': 65, 'paid_cents': 478, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [600, 400]), ({'now': 1080, 'expiry': 1106, 'paid_cents': 493, 'rate_per_hour': 150, 'max_minutes': 240, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [None, 0]), ({'now': 480, 'expiry': 511, 'paid_cents': 308, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [600, 297]), ({'now': 1080, 'expiry': 1112, 'paid_cents': 319, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [None, 0]), ({'now': 1080, 'expiry': 1100, 'paid_cents': 100, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [None, 0]), ({'now': 600, 'expiry': 650, 'paid_cents': 400, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [720, 234]), ({'now': 655, 'expiry': None, 'paid_cents': 248, 'rate_per_hour': 200, 'max_minutes': 60, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [715, 200])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('fee oracle' + ' %d' % i, 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(x):
    inc = x['increment']
    c = x['paid_cents'] - x['paid_cents'] % inc
    now = x['now']
    if now >= x['enf_end'] and x['expiry'] is None:
        return [None, 0]
    base = max(now, x['enf_start'])
    start = base if x['expiry'] is None else max(base, x['expiry'])
    mins = c * 60 // x['rate_per_hour']
    end = min(start + mins, base + x['max_minutes'], x['enf_end'])
    used = max(0, end - start)
    cost = min(c, -(-used * x['rate_per_hour'] // 60))
    return [max(end, start), cost]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'now': 1080, 'expiry': 1078, 'paid_cents': 85, 'rate_per_hour': 100, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [None, 0]), ({'now': 1080, 'expiry': None, 'paid_cents': 480, 'rate_per_hour': 100, 'max_minutes': 240, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [None, 0]), ({'now': 600, 'expiry': 650, 'paid_cents': 400, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [720, 234]), ({'now': 1040, 'expiry': None, 'paid_cents': 333, 'rate_per_hour': 150, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [1080, 100]), ({'now': 1350, 'expiry': 1335, 'paid_cents': 5, 'rate_per_hour': 250, 'max_minutes': 60, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [None, 0]), ({'now': 1080, 'expiry': 1071, 'paid_cents': 491, 'rate_per_hour': 250, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [None, 0]), ({'now': 420, 'expiry': None, 'paid_cents': 200, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [540, 200]), ({'now': 1243, 'expiry': 1214, 'paid_cents': 292, 'rate_per_hour': 200, 'max_minutes': 60, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [None, 0])], [({'now': 1080, 'expiry': 1152, 'paid_cents': 523, 'rate_per_hour': 150, 'max_minutes': 60, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [None, 0]), ({'now': 420, 'expiry': None, 'paid_cents': 200, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [540, 200]), ({'now': 233, 'expiry': 231, 'paid_cents': 298, 'rate_per_hour': 100, 'max_minutes': 60, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [540, 100]), ({'now': 600, 'expiry': 650, 'paid_cents': 400, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [720, 234]), ({'now': 1080, 'expiry': 1025, 'paid_cents': 393, 'rate_per_hour': 100, 'max_minutes': 240, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [None, 0]), ({'now': 655, 'expiry': None, 'paid_cents': 200, 'rate_per_hour': 150, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [735, 200]), ({'now': 1069, 'expiry': 1154, 'paid_cents': 524, 'rate_per_hour': 150, 'max_minutes': 60, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [1154, 0]), ({'now': 1080, 'expiry': 1100, 'paid_cents': 100, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [None, 0])], [({'now': 1080, 'expiry': 1100, 'paid_cents': 100, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [None, 0]), ({'now': 1040, 'expiry': None, 'paid_cents': 333, 'rate_per_hour': 150, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [1080, 100]), ({'now': 600, 'expiry': 650, 'paid_cents': 400, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [720, 234]), ({'now': 1080, 'expiry': None, 'paid_cents': 109, 'rate_per_hour': 100, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [None, 0]), ({'now': 1221, 'expiry': 1229, 'paid_cents': 328, 'rate_per_hour': 150, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [None, 0]), ({'now': 1208, 'expiry': None, 'paid_cents': 533, 'rate_per_hour': 100, 'max_minutes': 60, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [None, 0]), ({'now': 1080, 'expiry': 1154, 'paid_cents': 297, 'rate_per_hour': 100, 'max_minutes': 240, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [None, 0]), ({'now': 480, 'expiry': None, 'paid_cents': 226, 'rate_per_hour': 100, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [600, 200])], [({'now': 1080, 'expiry': 1168, 'paid_cents': 356, 'rate_per_hour': 200, 'max_minutes': 60, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [None, 0]), ({'now': 1080, 'expiry': None, 'paid_cents': 584, 'rate_per_hour': 100, 'max_minutes': 60, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [None, 0]), ({'now': 1080, 'expiry': None, 'paid_cents': 350, 'rate_per_hour': 200, 'max_minutes': 60, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [None, 0]), ({'now': 600, 'expiry': 650, 'paid_cents': 400, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [720, 234]), ({'now': 480, 'expiry': None, 'paid_cents': 469, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [600, 400]), ({'now': 1040, 'expiry': None, 'paid_cents': 333, 'rate_per_hour': 150, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [1080, 100]), ({'now': 1087, 'expiry': 1093, 'paid_cents': 264, 'rate_per_hour': 100, 'max_minutes': 240, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [None, 0]), ({'now': 420, 'expiry': None, 'paid_cents': 200, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [540, 200])], [({'now': 1040, 'expiry': None, 'paid_cents': 333, 'rate_per_hour': 150, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [1080, 100]), ({'now': 63, 'expiry': 65, 'paid_cents': 478, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [600, 400]), ({'now': 1080, 'expiry': 1106, 'paid_cents': 493, 'rate_per_hour': 150, 'max_minutes': 240, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [None, 0]), ({'now': 480, 'expiry': 511, 'paid_cents': 308, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [600, 297]), ({'now': 1080, 'expiry': 1112, 'paid_cents': 319, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [None, 0]), ({'now': 1080, 'expiry': 1100, 'paid_cents': 100, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 25}, [None, 0]), ({'now': 600, 'expiry': 650, 'paid_cents': 400, 'rate_per_hour': 200, 'max_minutes': 120, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [720, 234]), ({'now': 655, 'expiry': None, 'paid_cents': 248, 'rate_per_hour': 200, 'max_minutes': 60, 'enf_start': 480, 'enf_end': 1080, 'increment': 5}, [715, 200])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('fee oracle' + ' %d' % i, 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:
Street meter time purchase returns a wrong result when a purchase at exactly enforcement end is processed.

Input {now, expiry (or null), paid_cents, rate_per_hour, max_minutes, enf_start, enf_end, increment}. Only whole increments are credited. At or after enforcement end nothing is sold: [null, 0]. Paid time starts at the later of now, enforcement start and any unexpired expiry; it ends at the earliest of start + purchased minutes (floor), max(now, enf_start) + max_minutes, and enf_end. Accepted cents = min(credited, ceil(used minutes * rate/60)). Return [new expiry, accepted cents].

split: open-access


prompt:
Closed-system distance toll returns a wrong result when the exit kilometre marker is charged instead of the distance.

Input {plazas: [[name, km]], entry (null = lost ticket), exit, class_pct, vclass, rate_milli (milli-cents per km), min_toll, uturn_fee}. Entry equal to exit pays uturn_fee. A lost ticket is charged from the plaza farthest from the exit. raw = km distance * rate * class percent / 100 (milli-cents, floored); the toll is raw rounded half-up to the nearest 5 cents, at least min_toll.

split: open-access


prompt:
Closed-system distance toll returns a wrong result when a lost ticket is charged the whole road length.

Input {plazas: [[name, km]], entry (null = lost ticket), exit, class_pct, vclass, rate_milli (milli-cents per km), min_toll, uturn_fee}. Entry equal to exit pays uturn_fee. A lost ticket is charged from the plaza farthest from the exit. raw = km distance * rate * class percent / 100 (milli-cents, floored); the toll is raw rounded half-up to the nearest 5 cents, at least min_toll.

split: open-access


prompt:
Closed-system distance toll returns a wrong result when the class percentage is truncated to a whole factor.

Input {plazas: [[name, km]], entry (null = lost ticket), exit, class_pct, vclass, rate_milli (milli-cents per km), min_toll, uturn_fee}. Entry equal to exit pays uturn_fee. A lost ticket is charged from the plaza farthest from the exit. raw = km distance * rate * class percent / 100 (milli-cents, floored); the toll is raw rounded half-up to the nearest 5 cents, at least min_toll.

split: open-access


prompt:
Closed-system distance toll returns a wrong result when tolls are truncated to 5 cents.

Input {plazas: [[name, km]], entry (null = lost ticket), exit, class_pct, vclass, rate_milli (milli-cents per km), min_toll, uturn_fee}. Entry equal to exit pays uturn_fee. A lost ticket is charged from the plaza farthest from the exit. raw = km distance * rate * class percent / 100 (milli-cents, floored); the toll is raw rounded half-up to the nearest 5 cents, at least min_toll.

split: open-access


prompt:
Closed-system distance toll returns a wrong result when short trips bypass the minimum toll.

Input {plazas: [[name, km]], entry (null = lost ticket), exit, class_pct, vclass, rate_milli (milli-cents per km), min_toll, uturn_fee}. Entry equal to exit pays uturn_fee. A lost ticket is charged from the plaza farthest from the exit. raw = km distance * rate * class percent / 100 (milli-cents, floored); the toll is raw rounded half-up to the nearest 5 cents, at least min_toll.

split: open-access


prompt:
Axle and height vehicle classification returns a wrong result when a motorcycle towing a trailer stays in class M.

Input {axles, trailer_axles, height_cm, dual_tires, motorcycle, tolls: [[class, cents]], oversize_fee}. A two-axle motorcycle without trailer is class M. Otherwise total axles = vehicle + trailer: up to two axles is class 1 when under 200 cm and without dual tires, else class 2; three or more is the axle count, capped at 5. Vehicles 410 cm or taller pay oversize_fee per total axle. Return [class, cents].

split: open-access


prompt:
Axle and height vehicle classification returns a wrong result when trailer axles are not counted.

Input {axles, trailer_axles, height_cm, dual_tires, motorcycle, tolls: [[class, cents]], oversize_fee}. A two-axle motorcycle without trailer is class M. Otherwise total axles = vehicle + trailer: up to two axles is class 1 when under 200 cm and without dual tires, else class 2; three or more is the axle count, capped at 5. Vehicles 410 cm or taller pay oversize_fee per total axle. Return [class, cents].

split: open-access


prompt:
Axle and height vehicle classification returns a wrong result when dual tires are ignored for two-axle vehicles.

Input {axles, trailer_axles, height_cm, dual_tires, motorcycle, tolls: [[class, cents]], oversize_fee}. A two-axle motorcycle without trailer is class M. Otherwise total axles = vehicle + trailer: up to two axles is class 1 when under 200 cm and without dual tires, else class 2; three or more is the axle count, capped at 5. Vehicles 410 cm or taller pay oversize_fee per total axle. Return [class, cents].

split: open-access


prompt:
Axle and height vehicle classification returns a wrong result when the oversize surcharge ignores trailer axles.

Input {axles, trailer_axles, height_cm, dual_tires, motorcycle, tolls: [[class, cents]], oversize_fee}. A two-axle motorcycle without trailer is class M. Otherwise total axles = vehicle + trailer: up to two axles is class 1 when under 200 cm and without dual tires, else class 2; three or more is the axle count, capped at 5. Vehicles 410 cm or taller pay oversize_fee per total axle. Return [class, cents].

split: open-access


prompt:
Axle and height vehicle classification returns a wrong result when oversize applies only to trucks.

Input {axles, trailer_axles, height_cm, dual_tires, motorcycle, tolls: [[class, cents]], oversize_fee}. A two-axle motorcycle without trailer is class M. Otherwise total axles = vehicle + trailer: up to two axles is class 1 when under 200 cm and without dual tires, else class 2; three or more is the axle count, capped at 5. Vehicles 410 cm or taller pay oversize_fee per total axle. Return [class, cents].

split: open-access


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

N = 1
observations = []
def solve(x):
    if x['zero_emission']:
        return 0
    byday = {}
    for d, m in sorted(x['crossings']):
        byday.setdefault(d, []).append(m)
    total = 0
    for d, ms in byday.items():
        if x['weekend_free'] and d % 7 >= 5:
            continue
        last = None
        day_sum = 0
        for m in ms:
            if last is not None and m - last <= x['grace']:
                last = m
                continue
            last = m
            peak = any(s <= m < e for s, e in x['peak'])
            day_sum += x['peak_fee'] if peak else x['offpeak_fee']
        total += min(day_sum, x['daily_cap'])
    return total
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[7, 808], [2, 357], [7, 818], [9, 848], [7, 803], [3, 1057], [6, 1244]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1900), ({'crossings': [[1, 1077], [1, 1057]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 2000, 'weekend_free': False, 'zero_emission': False, 'grace': 10}, 1800), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400), ({'crossings': [[0, 325], [1, 437], [1, 432], [1, 877], [9, 768], [9, 1258], [1, 422]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 250, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 2000), ({'crossings': [[8, 829], [6, 980], [3, 425], [1, 667], [8, 839], [8, 834]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1500), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900), ({'crossings': [[9, 362], [0, 588], [0, 578], [0, 598], [4, 513]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 3000)], [({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400), ({'crossings': [[5, 1011], [5, 656], [5, 671], [5, 681]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 1500, 'weekend_free': False, 'zero_emission': False, 'grace': 15}, 1500), ({'crossings': [[9, 765], [8, 888], [7, 889], [4, 754], [3, 1120], [4, 900], [3, 1140], [7, 689], [3, 1135], [0, 1056]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 3550), ({'crossings': [[3, 471], [9, 408], [7, 308], [2, 900], [3, 466], [7, 368], [3, 456]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 250, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 2000), ({'crossings': [[0, 641], [4, 994], [6, 843], [3, 505], [4, 974], [8, 946], [7, 892]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 200, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 3300), ({'crossings': [[2, 1225], [2, 389]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 400)], [({'crossings': [[8, 351], [0, 745], [8, 946], [8, 341], [2, 414], [7, 1117], [4, 603]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 2000), ({'crossings': [[7, 385], [6, 656], [6, 661], [6, 646]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 3000, 'weekend_free': False, 'zero_emission': False, 'grace': 15}, 600), ({'crossings': [[7, 718], [6, 1027], [6, 695], [7, 701], [4, 1199], [7, 713]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 200, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 600), ({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[3, 1273], [9, 868], [7, 364], [4, 1093], [8, 916], [3, 1283], [3, 1278]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 3000, 'weekend_free': False, 'zero_emission': False, 'grace': 10}, 2100), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400), ({'crossings': [[6, 670], [2, 1136], [2, 1146], [5, 987], [2, 1156], [5, 556], [7, 927]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 1500)], [({'crossings': [[2, 1113], [2, 1280], [9, 567], [6, 556], [8, 1067], [9, 577], [4, 1241], [3, 1274]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 1500, 'weekend_free': False, 'zero_emission': False, 'grace': 10}, 4900), ({'crossings': [[8, 927], [9, 1274], [7, 1026], [9, 1299], [9, 1289]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 3000, 'weekend_free': False, 'zero_emission': False, 'grace': 15}, 1650), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400), ({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900), ({'crossings': [[3, 502], [3, 492], [5, 835], [9, 790], [4, 1009], [3, 461], [3, 512]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 3900), ({'crossings': [[5, 688], [5, 683], [4, 424], [7, 1235], [9, 1296], [2, 870], [5, 1119], [1, 895]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 2000, 'weekend_free': False, 'zero_emission': False, 'grace': 15}, 3500), ({'crossings': [[9, 425], [2, 1292], [5, 1026], [0, 1286], [7, 717], [3, 401], [0, 1276], [9, 839]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2000)], [({'crossings': [[5, 673], [5, 683], [5, 700], [4, 508]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 2000, 'weekend_free': False, 'zero_emission': False, 'grace': 10}, 1500), ({'crossings': [[9, 1004], [6, 1000], [6, 1020], [6, 1015]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 3000, 'weekend_free': False, 'zero_emission': False, 'grace': 15}, 3000), ({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[9, 830], [0, 735], [0, 706]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 250, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 750), ({'crossings': [[4, 989], [7, 961], [4, 1004]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 1800), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400), ({'crossings': [[9, 1022], [4, 445], [8, 953], [5, 461], [9, 699], [8, 573], [8, 588], [7, 514], [8, 583], [1, 1080]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 6300), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900)]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('fee oracle' + ' %d' % i, 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(x):
    if x['zero_emission']:
        return 0
    byday = {}
    for d, m in sorted(x['crossings']):
        byday.setdefault(d, []).append(m)
    total = 0
    for d, ms in byday.items():
        if x['weekend_free'] and d % 7 >= 5:
            continue
        last = None
        day_sum = 0
        for m in ms:
            if last is not None and m - last < x['grace']:
                continue
            last = m
            peak = any(s <= m < e for s, e in x['peak'])
            day_sum += x['peak_fee'] if peak else x['offpeak_fee']
        total += min(day_sum, x['daily_cap'])
    return total
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[7, 808], [2, 357], [7, 818], [9, 848], [7, 803], [3, 1057], [6, 1244]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1900), ({'crossings': [[1, 1077], [1, 1057]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 2000, 'weekend_free': False, 'zero_emission': False, 'grace': 10}, 1800), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400), ({'crossings': [[0, 325], [1, 437], [1, 432], [1, 877], [9, 768], [9, 1258], [1, 422]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 250, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 2000), ({'crossings': [[8, 829], [6, 980], [3, 425], [1, 667], [8, 839], [8, 834]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1500), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900), ({'crossings': [[9, 362], [0, 588], [0, 578], [0, 598], [4, 513]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 3000)], [({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400), ({'crossings': [[5, 1011], [5, 656], [5, 671], [5, 681]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 1500, 'weekend_free': False, 'zero_emission': False, 'grace': 15}, 1500), ({'crossings': [[9, 765], [8, 888], [7, 889], [4, 754], [3, 1120], [4, 900], [3, 1140], [7, 689], [3, 1135], [0, 1056]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 3550), ({'crossings': [[3, 471], [9, 408], [7, 308], [2, 900], [3, 466], [7, 368], [3, 456]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 250, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 2000), ({'crossings': [[0, 641], [4, 994], [6, 843], [3, 505], [4, 974], [8, 946], [7, 892]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 200, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 3300), ({'crossings': [[2, 1225], [2, 389]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 400)], [({'crossings': [[8, 351], [0, 745], [8, 946], [8, 341], [2, 414], [7, 1117], [4, 603]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 2000), ({'crossings': [[7, 385], [6, 656], [6, 661], [6, 646]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 3000, 'weekend_free': False, 'zero_emission': False, 'grace': 15}, 600), ({'crossings': [[7, 718], [6, 1027], [6, 695], [7, 701], [4, 1199], [7, 713]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 200, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 600), ({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[3, 1273], [9, 868], [7, 364], [4, 1093], [8, 916], [3, 1283], [3, 1278]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 3000, 'weekend_free': False, 'zero_emission': False, 'grace': 10}, 2100), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400), ({'crossings': [[6, 670], [2, 1136], [2, 1146], [5, 987], [2, 1156], [5, 556], [7, 927]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 1500)], [({'crossings': [[2, 1113], [2, 1280], [9, 567], [6, 556], [8, 1067], [9, 577], [4, 1241], [3, 1274]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 1500, 'weekend_free': False, 'zero_emission': False, 'grace': 10}, 4900), ({'crossings': [[8, 927], [9, 1274], [7, 1026], [9, 1299], [9, 1289]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 3000, 'weekend_free': False, 'zero_emission': False, 'grace': 15}, 1650), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400), ({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900), ({'crossings': [[3, 502], [3, 492], [5, 835], [9, 790], [4, 1009], [3, 461], [3, 512]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 3900), ({'crossings': [[5, 688], [5, 683], [4, 424], [7, 1235], [9, 1296], [2, 870], [5, 1119], [1, 895]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 2000, 'weekend_free': False, 'zero_emission': False, 'grace': 15}, 3500), ({'crossings': [[9, 425], [2, 1292], [5, 1026], [0, 1286], [7, 717], [3, 401], [0, 1276], [9, 839]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2000)], [({'crossings': [[5, 673], [5, 683], [5, 700], [4, 508]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 2000, 'weekend_free': False, 'zero_emission': False, 'grace': 10}, 1500), ({'crossings': [[9, 1004], [6, 1000], [6, 1020], [6, 1015]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 3000, 'weekend_free': False, 'zero_emission': False, 'grace': 15}, 3000), ({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[9, 830], [0, 735], [0, 706]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 250, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 750), ({'crossings': [[4, 989], [7, 961], [4, 1004]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 1800), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400), ({'crossings': [[9, 1022], [4, 445], [8, 953], [5, 461], [9, 699], [8, 573], [8, 588], [7, 514], [8, 583], [1, 1080]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 6300), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900)]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('fee oracle' + ' %d' % i, 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:
Cordon congestion charge returns a wrong result when the grace window slides with every free crossing.

Input {crossings: [[day, minute]] unordered, peak: [[start, end)] windows, peak_fee, offpeak_fee, daily_cap, weekend_free, zero_emission, grace}. Zero-emission vehicles pay 0. Days with day % 7 in {5, 6} are free when weekend_free. Within a day, a crossing no more than grace minutes after the last charged crossing is free (the grace anchor is the charged crossing). Each charged crossing pays the peak fee inside a window else off-peak; each day's sum is capped at daily_cap.

split: open-access


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

N = 1
observations = []
def solve(x):
    if x['zero_emission']:
        return 0
    byday = {}
    for d, m in sorted(x['crossings']):
        byday.setdefault(d, []).append(m)
    total = 0
    for d, ms in byday.items():
        if x['weekend_free'] and d % 7 >= 5:
            continue
        last = None
        day_sum = 0
        for m in ms:
            if last is not None and m - last <= x['grace']:
                continue
            last = m
            peak = any(s <= m <= e for s, e in x['peak'])
            day_sum += x['peak_fee'] if peak else x['offpeak_fee']
        total += min(day_sum, x['daily_cap'])
    return total
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'crossings': [[6, 406], [9, 1150], [9, 365], [9, 1140], [7, 883]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 200, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 600), ({'crossings': [[7, 419], [0, 577], [2, 538], [3, 418], [2, 1056], [1, 1275], [1, 303], [9, 333]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 1500, 'weekend_free': False, 'zero_emission': False, 'grace': 10}, 3650), ({'crossings': [[6, 1265], [2, 510], [3, 1249], [5, 658], [5, 673]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 1150), ({'crossings': [[3, 805], [5, 356], [9, 391], [3, 810], [0, 368]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 750), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400), ({'crossings': [[7, 573], [3, 540], [5, 1030], [7, 739], [3, 960], [8, 906]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 3600), ({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900)], [({'crossings': [[1, 1172], [1, 565], [0, 799], [6, 1296], [1, 550], [1, 600], [1, 570]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 2900), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400), ({'crossings': [[4, 815], [3, 796], [6, 713], [4, 566], [3, 366], [1, 666], [5, 664], [4, 1087]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 200, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2600), ({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[3, 1140], [1, 924], [5, 1081], [0, 886], [1, 467], [1, 1255], [7, 1290], [1, 472], [1, 353]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 200, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2100), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900), ({'crossings': [[9, 1080], [8, 999], [9, 572], [8, 814], [7, 656]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 200, 'daily_cap': 2000, 'weekend_free': False, 'zero_emission': False, 'grace': 15}, 3100), ({'crossings': [[0, 1157], [1, 338], [3, 478], [1, 1304], [1, 1292], [4, 1195], [5, 620], [1, 793]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 2000, 'weekend_free': False, 'zero_emission': False, 'grace': 10}, 2400)], [({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[9, 740], [3, 1230], [3, 1225]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 600), ({'crossings': [[9, 1224], [9, 685], [2, 831], [3, 1244], [9, 611], [9, 1204]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1800), ({'crossings': [[0, 598], [3, 426], [6, 1284], [6, 1274], [6, 330], [4, 420], [3, 444], [4, 1214]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 3800), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400), ({'crossings': [[4, 451], [5, 385], [6, 676], [4, 466], [9, 918], [2, 1010]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 200, 'daily_cap': 3000, 'weekend_free': False, 'zero_emission': False, 'grace': 10}, 3300), ({'crossings': [[0, 1120], [9, 1245], [0, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 2000, 'weekend_free': False, 'zero_emission': False, 'grace': 10}, 1500), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900)], [({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900), ({'crossings': [[9, 1140], [6, 401], [1, 561], [1, 581], [1, 586]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 3000, 'weekend_free': False, 'zero_emission': False, 'grace': 15}, 2400), ({'crossings': [[3, 633], [7, 1147], [4, 1075], [2, 1207], [0, 952], [0, 932], [7, 754], [4, 306], [1, 1277]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 1500, 'weekend_free': False, 'zero_emission': False, 'grace': 10}, 2600), ({'crossings': [[9, 898], [1, 377], [9, 1185], [7, 543], [9, 1195], [9, 1173], [2, 1261], [8, 806], [9, 1133]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 3000, 'weekend_free': False, 'zero_emission': False, 'grace': 15}, 3300), ({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[0, 457], [0, 442], [0, 871]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 250, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 1250), ({'crossings': [[6, 1192], [0, 573], [0, 625], [7, 449], [1, 600]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 200, 'daily_cap': 2000, 'weekend_free': False, 'zero_emission': False, 'grace': 15}, 2400), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400)], [({'crossings': [[8, 1081], [8, 805]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 1200), ({'crossings': [[2, 1101], [2, 600], [8, 434], [8, 439], [5, 601], [2, 1015]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 200, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2900), ({'crossings': [[7, 571], [1, 883], [1, 1152], [4, 405], [0, 1151], [9, 471], [9, 456], [3, 837], [9, 359]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 1500, 'weekend_free': False, 'zero_emission': False, 'grace': 15}, 3600), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900), ({'crossings': [[7, 314], [8, 752], [4, 372], [8, 737]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 750), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400), ({'crossings': [[7, 600], [8, 992], [3, 436], [3, 983], [0, 965], [2, 862], [3, 441]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 4200), ({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700)]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('fee oracle' + ' %d' % i, 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(x):
    if x['zero_emission']:
        return 0
    byday = {}
    for d, m in sorted(x['crossings']):
        byday.setdefault(d, []).append(m)
    total = 0
    for d, ms in byday.items():
        if x['weekend_free'] and d % 7 >= 5:
            continue
        last = None
        day_sum = 0
        for m in ms:
            if last is not None and m - last <= x['grace']:
                continue
            last = m
            peak = any(s < m <= e for s, e in x['peak'])
            day_sum += x['peak_fee'] if peak else x['offpeak_fee']
        total += min(day_sum, x['daily_cap'])
    return total
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'crossings': [[6, 406], [9, 1150], [9, 365], [9, 1140], [7, 883]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 200, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 600), ({'crossings': [[7, 419], [0, 577], [2, 538], [3, 418], [2, 1056], [1, 1275], [1, 303], [9, 333]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 1500, 'weekend_free': False, 'zero_emission': False, 'grace': 10}, 3650), ({'crossings': [[6, 1265], [2, 510], [3, 1249], [5, 658], [5, 673]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 1150), ({'crossings': [[3, 805], [5, 356], [9, 391], [3, 810], [0, 368]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 750), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400), ({'crossings': [[7, 573], [3, 540], [5, 1030], [7, 739], [3, 960], [8, 906]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 3600), ({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900)], [({'crossings': [[1, 1172], [1, 565], [0, 799], [6, 1296], [1, 550], [1, 600], [1, 570]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 2900), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400), ({'crossings': [[4, 815], [3, 796], [6, 713], [4, 566], [3, 366], [1, 666], [5, 664], [4, 1087]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 200, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2600), ({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[3, 1140], [1, 924], [5, 1081], [0, 886], [1, 467], [1, 1255], [7, 1290], [1, 472], [1, 353]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 200, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2100), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900), ({'crossings': [[9, 1080], [8, 999], [9, 572], [8, 814], [7, 656]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 200, 'daily_cap': 2000, 'weekend_free': False, 'zero_emission': False, 'grace': 15}, 3100), ({'crossings': [[0, 1157], [1, 338], [3, 478], [1, 1304], [1, 1292], [4, 1195], [5, 620], [1, 793]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 2000, 'weekend_free': False, 'zero_emission': False, 'grace': 10}, 2400)], [({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[9, 740], [3, 1230], [3, 1225]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 600), ({'crossings': [[9, 1224], [9, 685], [2, 831], [3, 1244], [9, 611], [9, 1204]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1800), ({'crossings': [[0, 598], [3, 426], [6, 1284], [6, 1274], [6, 330], [4, 420], [3, 444], [4, 1214]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 3800), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400), ({'crossings': [[4, 451], [5, 385], [6, 676], [4, 466], [9, 918], [2, 1010]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 200, 'daily_cap': 3000, 'weekend_free': False, 'zero_emission': False, 'grace': 10}, 3300), ({'crossings': [[0, 1120], [9, 1245], [0, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 2000, 'weekend_free': False, 'zero_emission': False, 'grace': 10}, 1500), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900)], [({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900), ({'crossings': [[9, 1140], [6, 401], [1, 561], [1, 581], [1, 586]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 3000, 'weekend_free': False, 'zero_emission': False, 'grace': 15}, 2400), ({'crossings': [[3, 633], [7, 1147], [4, 1075], [2, 1207], [0, 952], [0, 932], [7, 754], [4, 306], [1, 1277]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 1500, 'weekend_free': False, 'zero_emission': False, 'grace': 10}, 2600), ({'crossings': [[9, 898], [1, 377], [9, 1185], [7, 543], [9, 1195], [9, 1173], [2, 1261], [8, 806], [9, 1133]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 3000, 'weekend_free': False, 'zero_emission': False, 'grace': 15}, 3300), ({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[0, 457], [0, 442], [0, 871]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 250, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 1250), ({'crossings': [[6, 1192], [0, 573], [0, 625], [7, 449], [1, 600]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 200, 'daily_cap': 2000, 'weekend_free': False, 'zero_emission': False, 'grace': 15}, 2400), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400)], [({'crossings': [[8, 1081], [8, 805]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 1200), ({'crossings': [[2, 1101], [2, 600], [8, 434], [8, 439], [5, 601], [2, 1015]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 200, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2900), ({'crossings': [[7, 571], [1, 883], [1, 1152], [4, 405], [0, 1151], [9, 471], [9, 456], [3, 837], [9, 359]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 1500, 'weekend_free': False, 'zero_emission': False, 'grace': 15}, 3600), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900), ({'crossings': [[7, 314], [8, 752], [4, 372], [8, 737]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 750), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400), ({'crossings': [[7, 600], [8, 992], [3, 436], [3, 983], [0, 965], [2, 862], [3, 441]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 4200), ({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700)]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('fee oracle' + ' %d' % i, 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:
Cordon congestion charge returns a wrong result when the peak window includes its end minute.

Input {crossings: [[day, minute]] unordered, peak: [[start, end)] windows, peak_fee, offpeak_fee, daily_cap, weekend_free, zero_emission, grace}. Zero-emission vehicles pay 0. Days with day % 7 in {5, 6} are free when weekend_free. Within a day, a crossing no more than grace minutes after the last charged crossing is free (the grace anchor is the charged crossing). Each charged crossing pays the peak fee inside a window else off-peak; each day's sum is capped at daily_cap.

split: open-access


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

N = 1
observations = []
def solve(x):
    if x['zero_emission']:
        return 0
    byday = {}
    for d, m in sorted(x['crossings']):
        byday.setdefault(d, []).append(m)
    total = 0
    for d, ms in byday.items():
        if x['weekend_free'] and d % 7 > 5:
            continue
        last = None
        day_sum = 0
        for m in ms:
            if last is not None and m - last <= x['grace']:
                continue
            last = m
            peak = any(s <= m < e for s, e in x['peak'])
            day_sum += x['peak_fee'] if peak else x['offpeak_fee']
        total += min(day_sum, x['daily_cap'])
    return total
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'crossings': [[7, 1011], [2, 457], [5, 795], [8, 472], [5, 720], [4, 569], [0, 734], [8, 1142]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 4400), ({'crossings': [[7, 315], [4, 625], [7, 300], [6, 1179], [0, 470], [3, 1200], [7, 408], [9, 859]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[1, 1264], [8, 433], [8, 428], [7, 372], [6, 974], [3, 363], [0, 1276], [9, 442]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 250, 'daily_cap': 3000, 'weekend_free': False, 'zero_emission': False, 'grace': 10}, 4000), ({'crossings': [[2, 620], [4, 1014], [8, 1202], [5, 705]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 1500), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900), ({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[3, 715], [8, 886], [5, 1195], [7, 1063], [5, 1183], [5, 1173], [6, 1131], [3, 1187]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 3000, 'weekend_free': False, 'zero_emission': True, 'grace': 15}, 0), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400)], [({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400), ({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[7, 1100], [7, 1151], [7, 1110], [4, 492], [8, 1149], [9, 300], [7, 1105]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 250, 'daily_cap': 2000, 'weekend_free': False, 'zero_emission': False, 'grace': 15}, 2750), ({'crossings': [[2, 590], [0, 765], [6, 889], [0, 775], [8, 1250], [5, 861], [2, 345], [4, 936], [8, 801]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2150), ({'crossings': [[2, 1117], [4, 851], [3, 589], [8, 775], [6, 600], [0, 1194], [2, 1107], [6, 384]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900), ({'crossings': [[9, 748], [0, 1184], [1, 874], [7, 1258], [6, 703], [7, 1268], [6, 939], [6, 799]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 800), ({'crossings': [[5, 786]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 0)], [({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400), ({'crossings': [[3, 754], [3, 759], [0, 309], [2, 1116], [9, 1181], [5, 1282], [3, 734], [7, 419], [8, 971], [7, 931]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 3200), ({'crossings': [[0, 576], [0, 566]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 250, 'daily_cap': 2000, 'weekend_free': False, 'zero_emission': False, 'grace': 10}, 1000), ({'crossings': [[0, 1137], [0, 1132], [0, 1127], [5, 1045], [3, 734]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1300), ({'crossings': [[2, 449], [2, 645]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': True, 'grace': 10}, 0), ({'crossings': [[5, 1131], [9, 680], [4, 409], [6, 1038], [9, 350], [6, 1048], [1, 697], [2, 718], [0, 372]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 1500), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900)], [({'crossings': [[0, 938], [5, 366], [3, 483], [5, 1185], [9, 605], [5, 356], [7, 1233], [0, 756]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 200, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1700), ({'crossings': [[9, 806], [9, 791]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 500), ({'crossings': [[6, 665], [6, 653]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 200, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 0), ({'crossings': [[6, 1222], [4, 460], [2, 1209], [5, 936], [3, 638], [2, 940], [2, 524], [2, 648]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 200, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 2600), ({'crossings': [[7, 446], [9, 991]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 2000), ({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400)], [({'crossings': [[1, 547], [1, 869], [7, 1218], [2, 625], [9, 660], [2, 929], [1, 881], [6, 885]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 200, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2100), ({'crossings': [[4, 934], [2, 398], [7, 1029], [4, 924], [0, 1175], [4, 939], [2, 362]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 200, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': True, 'grace': 10}, 0), ({'crossings': [[9, 1270], [5, 335], [0, 685], [0, 1088], [9, 1258]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 1500), ({'crossings': [[7, 916], [7, 402], [1, 613], [6, 519], [1, 623], [1, 628], [0, 750], [5, 734]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 3000, 'weekend_free': False, 'zero_emission': False, 'grace': 15}, 2150), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400), ({'crossings': [[0, 320], [5, 385], [2, 1238], [0, 315]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 600), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900), ({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700)]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('fee oracle' + ' %d' % i, 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(x):
    if x['zero_emission']:
        return 0
    byday = {}
    for d, m in sorted(x['crossings']):
        byday.setdefault(d, []).append(m)
    total = 0
    for d, ms in byday.items():
        if x['weekend_free'] and d % 7 in (0, 6):
            continue
        last = None
        day_sum = 0
        for m in ms:
            if last is not None and m - last <= x['grace']:
                continue
            last = m
            peak = any(s <= m < e for s, e in x['peak'])
            day_sum += x['peak_fee'] if peak else x['offpeak_fee']
        total += min(day_sum, x['daily_cap'])
    return total
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'crossings': [[7, 1011], [2, 457], [5, 795], [8, 472], [5, 720], [4, 569], [0, 734], [8, 1142]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 4400), ({'crossings': [[7, 315], [4, 625], [7, 300], [6, 1179], [0, 470], [3, 1200], [7, 408], [9, 859]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[1, 1264], [8, 433], [8, 428], [7, 372], [6, 974], [3, 363], [0, 1276], [9, 442]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 250, 'daily_cap': 3000, 'weekend_free': False, 'zero_emission': False, 'grace': 10}, 4000), ({'crossings': [[2, 620], [4, 1014], [8, 1202], [5, 705]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 1500), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900), ({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[3, 715], [8, 886], [5, 1195], [7, 1063], [5, 1183], [5, 1173], [6, 1131], [3, 1187]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 3000, 'weekend_free': False, 'zero_emission': True, 'grace': 15}, 0), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400)], [({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400), ({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[7, 1100], [7, 1151], [7, 1110], [4, 492], [8, 1149], [9, 300], [7, 1105]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 250, 'daily_cap': 2000, 'weekend_free': False, 'zero_emission': False, 'grace': 15}, 2750), ({'crossings': [[2, 590], [0, 765], [6, 889], [0, 775], [8, 1250], [5, 861], [2, 345], [4, 936], [8, 801]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2150), ({'crossings': [[2, 1117], [4, 851], [3, 589], [8, 775], [6, 600], [0, 1194], [2, 1107], [6, 384]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900), ({'crossings': [[9, 748], [0, 1184], [1, 874], [7, 1258], [6, 703], [7, 1268], [6, 939], [6, 799]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 800), ({'crossings': [[5, 786]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 0)], [({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400), ({'crossings': [[3, 754], [3, 759], [0, 309], [2, 1116], [9, 1181], [5, 1282], [3, 734], [7, 419], [8, 971], [7, 931]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 200, 'daily_cap': 2000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 3200), ({'crossings': [[0, 576], [0, 566]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 250, 'daily_cap': 2000, 'weekend_free': False, 'zero_emission': False, 'grace': 10}, 1000), ({'crossings': [[0, 1137], [0, 1132], [0, 1127], [5, 1045], [3, 734]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1300), ({'crossings': [[2, 449], [2, 645]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': True, 'grace': 10}, 0), ({'crossings': [[5, 1131], [9, 680], [4, 409], [6, 1038], [9, 350], [6, 1048], [1, 697], [2, 718], [0, 372]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 1500), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900)], [({'crossings': [[0, 938], [5, 366], [3, 483], [5, 1185], [9, 605], [5, 356], [7, 1233], [0, 756]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 200, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1700), ({'crossings': [[9, 806], [9, 791]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 500), ({'crossings': [[6, 665], [6, 653]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 200, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 0), ({'crossings': [[6, 1222], [4, 460], [2, 1209], [5, 936], [3, 638], [2, 940], [2, 524], [2, 648]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 200, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 2600), ({'crossings': [[7, 446], [9, 991]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 1000, 'offpeak_fee': 300, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 2000), ({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400)], [({'crossings': [[1, 547], [1, 869], [7, 1218], [2, 625], [9, 660], [2, 929], [1, 881], [6, 885]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 200, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2100), ({'crossings': [[4, 934], [2, 398], [7, 1029], [4, 924], [0, 1175], [4, 939], [2, 362]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 200, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': True, 'grace': 10}, 0), ({'crossings': [[9, 1270], [5, 335], [0, 685], [0, 1088], [9, 1258]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 3000, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 1500), ({'crossings': [[7, 916], [7, 402], [1, 613], [6, 519], [1, 623], [1, 628], [0, 750], [5, 734]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 3000, 'weekend_free': False, 'zero_emission': False, 'grace': 15}, 2150), ({'crossings': [[2, 600], [2, 420], [2, 1140]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 1400), ({'crossings': [[0, 320], [5, 385], [2, 1238], [0, 315]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 300, 'daily_cap': 1500, 'weekend_free': True, 'zero_emission': False, 'grace': 15}, 600), ({'crossings': [[6, 500], [0, 500], [5, 500]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 900), ({'crossings': [[1, 500], [1, 508], [1, 516], [1, 530]], 'peak': [[420, 600], [960, 1140]], 'peak_fee': 900, 'offpeak_fee': 250, 'daily_cap': 5000, 'weekend_free': True, 'zero_emission': False, 'grace': 10}, 2700)]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('fee oracle' + ' %d' % i, 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:
Cordon congestion charge returns a wrong result when saturday is charged.

Input {crossings: [[day, minute]] unordered, peak: [[start, end)] windows, peak_fee, offpeak_fee, daily_cap, weekend_free, zero_emission, grace}. Zero-emission vehicles pay 0. Days with day % 7 in {5, 6} are free when weekend_free. Within a day, a crossing no more than grace minutes after the last charged crossing is free (the grace anchor is the charged crossing). Each charged crossing pays the peak fee inside a window else off-peak; each day's sum is capped at daily_cap.

split: open-access