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

N = 1
observations = []
def solve(x):
    ev = x['today']
    age = ev - x['issued_day']
    pen = 0
    if age > x['stage1_days']:
        pen += x['first_fee']
        if x['waiver_first'] and x['paid_day'] is not None and age <= x['stage2_days']:
            pen -= x['first_fee']
    if age > x['stage2_days']:
        pen += x['second_fee']
    return x['toll'] + min(pen, x['cap'])
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'toll': 400, 'issued_day': 86, 'paid_day': 105, 'today': 117, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': False}, 400), ({'toll': 250, 'issued_day': 42, 'paid_day': None, 'today': 73, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1250), ({'toll': 250, 'issued_day': 41, 'paid_day': 71, 'today': 102, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 250), ({'toll': 400, 'issued_day': 97, 'paid_day': None, 'today': 128, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': False}, 1400), ({'toll': 875, 'issued_day': 0, 'paid_day': None, 'today': 100, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3875), ({'toll': 400, 'issued_day': 97, 'paid_day': None, 'today': 127, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': False}, 400), ({'toll': 400, 'issued_day': 0, 'paid_day': None, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1400), ({'toll': 400, 'issued_day': 0, 'paid_day': 0, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400)], [({'toll': 875, 'issued_day': 0, 'paid_day': None, 'today': 100, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3875), ({'toll': 400, 'issued_day': 0, 'paid_day': None, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1400), ({'toll': 875, 'issued_day': 16, 'paid_day': 20, 'today': 77, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 875), ({'toll': 400, 'issued_day': 0, 'paid_day': 0, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 875, 'issued_day': 76, 'paid_day': None, 'today': 106, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 875), ({'toll': 250, 'issued_day': 45, 'paid_day': None, 'today': 105, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 750), ({'toll': 400, 'issued_day': 10, 'paid_day': 70, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 400), ({'toll': 875, 'issued_day': 30, 'paid_day': 60, 'today': 91, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': False}, 875)], [({'toll': 875, 'issued_day': 50, 'paid_day': None, 'today': 94, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': False}, 1375), ({'toll': 400, 'issued_day': 0, 'paid_day': None, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1400), ({'toll': 400, 'issued_day': 0, 'paid_day': 0, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 250, 'issued_day': 86, 'paid_day': 117, 'today': 147, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 250), ({'toll': 400, 'issued_day': 44, 'paid_day': 74, 'today': 75, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 400), ({'toll': 875, 'issued_day': 0, 'paid_day': None, 'today': 100, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3875), ({'toll': 875, 'issued_day': 98, 'paid_day': 129, 'today': 129, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 875), ({'toll': 400, 'issued_day': 10, 'paid_day': 70, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 400)], [({'toll': 250, 'issued_day': 28, 'paid_day': None, 'today': 59, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 750), ({'toll': 400, 'issued_day': 7, 'paid_day': None, 'today': 37, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': False}, 400), ({'toll': 400, 'issued_day': 0, 'paid_day': None, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1400), ({'toll': 400, 'issued_day': 0, 'paid_day': 0, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 875, 'issued_day': 2, 'paid_day': 33, 'today': 63, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': True}, 875), ({'toll': 400, 'issued_day': 10, 'paid_day': 40, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 875, 'issued_day': 65, 'paid_day': 96, 'today': 96, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 1875), ({'toll': 400, 'issued_day': 10, 'paid_day': 70, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 400)], [({'toll': 250, 'issued_day': 18, 'paid_day': 48, 'today': 77, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 250), ({'toll': 875, 'issued_day': 0, 'paid_day': None, 'today': 100, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3875), ({'toll': 400, 'issued_day': 10, 'paid_day': 70, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 400), ({'toll': 875, 'issued_day': 86, 'paid_day': 116, 'today': 147, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': False}, 875), ({'toll': 400, 'issued_day': 0, 'paid_day': 0, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 250, 'issued_day': 8, 'paid_day': None, 'today': 91, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 3250), ({'toll': 875, 'issued_day': 78, 'paid_day': None, 'today': 109, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1375), ({'toll': 400, 'issued_day': 0, 'paid_day': None, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1400)]]
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):
    ev = x['paid_day'] if x['paid_day'] else x['today']
    age = ev - x['issued_day']
    pen = 0
    if age > x['stage1_days']:
        pen += x['first_fee']
        if x['waiver_first'] and x['paid_day'] is not None and age <= x['stage2_days']:
            pen -= x['first_fee']
    if age > x['stage2_days']:
        pen += x['second_fee']
    return x['toll'] + min(pen, x['cap'])
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'toll': 400, 'issued_day': 86, 'paid_day': 105, 'today': 117, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': False}, 400), ({'toll': 250, 'issued_day': 42, 'paid_day': None, 'today': 73, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1250), ({'toll': 250, 'issued_day': 41, 'paid_day': 71, 'today': 102, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 250), ({'toll': 400, 'issued_day': 97, 'paid_day': None, 'today': 128, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': False}, 1400), ({'toll': 875, 'issued_day': 0, 'paid_day': None, 'today': 100, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3875), ({'toll': 400, 'issued_day': 97, 'paid_day': None, 'today': 127, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': False}, 400), ({'toll': 400, 'issued_day': 0, 'paid_day': None, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1400), ({'toll': 400, 'issued_day': 0, 'paid_day': 0, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400)], [({'toll': 875, 'issued_day': 0, 'paid_day': None, 'today': 100, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3875), ({'toll': 400, 'issued_day': 0, 'paid_day': None, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1400), ({'toll': 875, 'issued_day': 16, 'paid_day': 20, 'today': 77, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 875), ({'toll': 400, 'issued_day': 0, 'paid_day': 0, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 875, 'issued_day': 76, 'paid_day': None, 'today': 106, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 875), ({'toll': 250, 'issued_day': 45, 'paid_day': None, 'today': 105, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 750), ({'toll': 400, 'issued_day': 10, 'paid_day': 70, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 400), ({'toll': 875, 'issued_day': 30, 'paid_day': 60, 'today': 91, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': False}, 875)], [({'toll': 875, 'issued_day': 50, 'paid_day': None, 'today': 94, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': False}, 1375), ({'toll': 400, 'issued_day': 0, 'paid_day': None, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1400), ({'toll': 400, 'issued_day': 0, 'paid_day': 0, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 250, 'issued_day': 86, 'paid_day': 117, 'today': 147, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 250), ({'toll': 400, 'issued_day': 44, 'paid_day': 74, 'today': 75, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 400), ({'toll': 875, 'issued_day': 0, 'paid_day': None, 'today': 100, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3875), ({'toll': 875, 'issued_day': 98, 'paid_day': 129, 'today': 129, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 875), ({'toll': 400, 'issued_day': 10, 'paid_day': 70, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 400)], [({'toll': 250, 'issued_day': 28, 'paid_day': None, 'today': 59, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 750), ({'toll': 400, 'issued_day': 7, 'paid_day': None, 'today': 37, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': False}, 400), ({'toll': 400, 'issued_day': 0, 'paid_day': None, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1400), ({'toll': 400, 'issued_day': 0, 'paid_day': 0, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 875, 'issued_day': 2, 'paid_day': 33, 'today': 63, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': True}, 875), ({'toll': 400, 'issued_day': 10, 'paid_day': 40, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 875, 'issued_day': 65, 'paid_day': 96, 'today': 96, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 1875), ({'toll': 400, 'issued_day': 10, 'paid_day': 70, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 400)], [({'toll': 250, 'issued_day': 18, 'paid_day': 48, 'today': 77, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 250), ({'toll': 875, 'issued_day': 0, 'paid_day': None, 'today': 100, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3875), ({'toll': 400, 'issued_day': 10, 'paid_day': 70, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 400), ({'toll': 875, 'issued_day': 86, 'paid_day': 116, 'today': 147, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': False}, 875), ({'toll': 400, 'issued_day': 0, 'paid_day': 0, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 250, 'issued_day': 8, 'paid_day': None, 'today': 91, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 3250), ({'toll': 875, 'issued_day': 78, 'paid_day': None, 'today': 109, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1375), ({'toll': 400, 'issued_day': 0, 'paid_day': None, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1400)]]
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:
Unpaid toll violation escalation returns a wrong result when penalties keep accruing after payment.

Input {toll, issued_day, paid_day (or null), today, first_fee, second_fee, stage1_days, stage2_days, cap, waiver_first}. Age is measured to the payment day if paid, else today. Age above stage1 adds first_fee; first-time offenders (waiver_first) who actually paid within stage2 have it waived. Age above stage2 adds second_fee. Penalties (not the toll) are capped at cap. Return amount due.

split: open-access


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

N = 1
observations = []
def solve(x):
    ev = x['paid_day'] if x['paid_day'] is not None else x['today']
    age = ev - x['issued_day']
    pen = 0
    if age >= x['stage1_days']:
        pen += x['first_fee']
        if x['waiver_first'] and x['paid_day'] is not None and age <= x['stage2_days']:
            pen -= x['first_fee']
    if age > x['stage2_days']:
        pen += x['second_fee']
    return x['toll'] + min(pen, x['cap'])
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'toll': 400, 'issued_day': 0, 'paid_day': None, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1400), ({'toll': 250, 'issued_day': 61, 'paid_day': 92, 'today': 92, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 750), ({'toll': 400, 'issued_day': 2, 'paid_day': 32, 'today': 36, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': False}, 400), ({'toll': 875, 'issued_day': 73, 'paid_day': None, 'today': 104, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 1375), ({'toll': 250, 'issued_day': 79, 'paid_day': 109, 'today': 109, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': False}, 250), ({'toll': 250, 'issued_day': 12, 'paid_day': None, 'today': 42, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': False}, 250), ({'toll': 875, 'issued_day': 0, 'paid_day': None, 'today': 100, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3875), ({'toll': 400, 'issued_day': 0, 'paid_day': 0, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400)], [({'toll': 400, 'issued_day': 50, 'paid_day': None, 'today': 80, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 400), ({'toll': 875, 'issued_day': 47, 'paid_day': 78, 'today': 78, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': False}, 1375), ({'toll': 875, 'issued_day': 0, 'paid_day': None, 'today': 100, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3875), ({'toll': 400, 'issued_day': 10, 'paid_day': 40, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 875, 'issued_day': 55, 'paid_day': 85, 'today': 116, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 875), ({'toll': 875, 'issued_day': 51, 'paid_day': None, 'today': 82, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 1875), ({'toll': 400, 'issued_day': 10, 'paid_day': 70, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 400), ({'toll': 400, 'issued_day': 14, 'paid_day': None, 'today': 74, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 900)], [({'toll': 400, 'issued_day': 83, 'paid_day': 113, 'today': 187, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 400), ({'toll': 400, 'issued_day': 93, 'paid_day': None, 'today': 123, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 400), ({'toll': 400, 'issued_day': 10, 'paid_day': 40, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 400, 'issued_day': 35, 'paid_day': None, 'today': 96, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 5400), ({'toll': 400, 'issued_day': 0, 'paid_day': None, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1400), ({'toll': 250, 'issued_day': 27, 'paid_day': None, 'today': 58, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1250), ({'toll': 400, 'issued_day': 10, 'paid_day': 70, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 400), ({'toll': 250, 'issued_day': 66, 'paid_day': None, 'today': 97, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 1250)], [({'toll': 250, 'issued_day': 59, 'paid_day': 89, 'today': 89, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 250), ({'toll': 250, 'issued_day': 85, 'paid_day': 116, 'today': 143, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 750), ({'toll': 400, 'issued_day': 0, 'paid_day': None, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1400), ({'toll': 250, 'issued_day': 81, 'paid_day': 112, 'today': 175, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': False}, 1250), ({'toll': 250, 'issued_day': 39, 'paid_day': 69, 'today': 69, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 250), ({'toll': 875, 'issued_day': 0, 'paid_day': None, 'today': 100, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3875), ({'toll': 250, 'issued_day': 28, 'paid_day': 58, 'today': 88, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 250), ({'toll': 400, 'issued_day': 0, 'paid_day': 0, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400)], [({'toll': 400, 'issued_day': 76, 'paid_day': 106, 'today': 106, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 400), ({'toll': 400, 'issued_day': 0, 'paid_day': 0, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 875, 'issued_day': 55, 'paid_day': None, 'today': 86, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 1875), ({'toll': 875, 'issued_day': 0, 'paid_day': None, 'today': 100, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3875), ({'toll': 400, 'issued_day': 0, 'paid_day': None, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1400), ({'toll': 250, 'issued_day': 25, 'paid_day': 55, 'today': 55, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': False}, 250), ({'toll': 400, 'issued_day': 74, 'paid_day': None, 'today': 104, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 400), ({'toll': 875, 'issued_day': 64, 'paid_day': 95, 'today': 125, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 1375)]]
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):
    ev = x['paid_day'] if x['paid_day'] is not None else x['today']
    age = ev - x['issued_day']
    pen = 0
    if age > x['stage1_days'] + 1:
        pen += x['first_fee']
        if x['waiver_first'] and x['paid_day'] is not None and age <= x['stage2_days']:
            pen -= x['first_fee']
    if age > x['stage2_days']:
        pen += x['second_fee']
    return x['toll'] + min(pen, x['cap'])
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'toll': 400, 'issued_day': 0, 'paid_day': None, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1400), ({'toll': 250, 'issued_day': 61, 'paid_day': 92, 'today': 92, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 750), ({'toll': 400, 'issued_day': 2, 'paid_day': 32, 'today': 36, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': False}, 400), ({'toll': 875, 'issued_day': 73, 'paid_day': None, 'today': 104, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 1375), ({'toll': 250, 'issued_day': 79, 'paid_day': 109, 'today': 109, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': False}, 250), ({'toll': 250, 'issued_day': 12, 'paid_day': None, 'today': 42, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': False}, 250), ({'toll': 875, 'issued_day': 0, 'paid_day': None, 'today': 100, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3875), ({'toll': 400, 'issued_day': 0, 'paid_day': 0, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400)], [({'toll': 400, 'issued_day': 50, 'paid_day': None, 'today': 80, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 400), ({'toll': 875, 'issued_day': 47, 'paid_day': 78, 'today': 78, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': False}, 1375), ({'toll': 875, 'issued_day': 0, 'paid_day': None, 'today': 100, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3875), ({'toll': 400, 'issued_day': 10, 'paid_day': 40, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 875, 'issued_day': 55, 'paid_day': 85, 'today': 116, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 875), ({'toll': 875, 'issued_day': 51, 'paid_day': None, 'today': 82, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 1875), ({'toll': 400, 'issued_day': 10, 'paid_day': 70, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 400), ({'toll': 400, 'issued_day': 14, 'paid_day': None, 'today': 74, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 900)], [({'toll': 400, 'issued_day': 83, 'paid_day': 113, 'today': 187, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 400), ({'toll': 400, 'issued_day': 93, 'paid_day': None, 'today': 123, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 400), ({'toll': 400, 'issued_day': 10, 'paid_day': 40, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 400, 'issued_day': 35, 'paid_day': None, 'today': 96, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 5400), ({'toll': 400, 'issued_day': 0, 'paid_day': None, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1400), ({'toll': 250, 'issued_day': 27, 'paid_day': None, 'today': 58, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1250), ({'toll': 400, 'issued_day': 10, 'paid_day': 70, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 400), ({'toll': 250, 'issued_day': 66, 'paid_day': None, 'today': 97, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 1250)], [({'toll': 250, 'issued_day': 59, 'paid_day': 89, 'today': 89, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 250), ({'toll': 250, 'issued_day': 85, 'paid_day': 116, 'today': 143, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 750), ({'toll': 400, 'issued_day': 0, 'paid_day': None, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1400), ({'toll': 250, 'issued_day': 81, 'paid_day': 112, 'today': 175, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': False}, 1250), ({'toll': 250, 'issued_day': 39, 'paid_day': 69, 'today': 69, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 250), ({'toll': 875, 'issued_day': 0, 'paid_day': None, 'today': 100, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3875), ({'toll': 250, 'issued_day': 28, 'paid_day': 58, 'today': 88, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 250), ({'toll': 400, 'issued_day': 0, 'paid_day': 0, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400)], [({'toll': 400, 'issued_day': 76, 'paid_day': 106, 'today': 106, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 400), ({'toll': 400, 'issued_day': 0, 'paid_day': 0, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 875, 'issued_day': 55, 'paid_day': None, 'today': 86, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 1875), ({'toll': 875, 'issued_day': 0, 'paid_day': None, 'today': 100, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3875), ({'toll': 400, 'issued_day': 0, 'paid_day': None, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1400), ({'toll': 250, 'issued_day': 25, 'paid_day': 55, 'today': 55, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': False}, 250), ({'toll': 400, 'issued_day': 74, 'paid_day': None, 'today': 104, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 400), ({'toll': 875, 'issued_day': 64, 'paid_day': 95, 'today': 125, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 1375)]]
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:
Unpaid toll violation escalation returns a wrong result when the first fee applies on day 30.

Input {toll, issued_day, paid_day (or null), today, first_fee, second_fee, stage1_days, stage2_days, cap, waiver_first}. Age is measured to the payment day if paid, else today. Age above stage1 adds first_fee; first-time offenders (waiver_first) who actually paid within stage2 have it waived. Age above stage2 adds second_fee. Penalties (not the toll) are capped at cap. Return amount due.

split: open-access


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

N = 1
observations = []
def solve(x):
    ev = x['paid_day'] if x['paid_day'] is not None else x['today']
    age = ev - x['issued_day']
    pen = 0
    if age > x['stage1_days']:
        pen += x['first_fee']
        if x['waiver_first'] and x['paid_day'] is not None :
            pen -= x['first_fee']
    if age > x['stage2_days']:
        pen += x['second_fee']
    return x['toll'] + min(pen, x['cap'])
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'toll': 875, 'issued_day': 85, 'paid_day': None, 'today': 115, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 875), ({'toll': 250, 'issued_day': 18, 'paid_day': 91, 'today': 132, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 3750), ({'toll': 400, 'issued_day': 0, 'paid_day': 0, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 875, 'issued_day': 41, 'paid_day': 72, 'today': 102, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 1375), ({'toll': 875, 'issued_day': 65, 'paid_day': 96, 'today': 96, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 1375), ({'toll': 400, 'issued_day': 52, 'paid_day': 112, 'today': 113, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 400), ({'toll': 400, 'issued_day': 10, 'paid_day': 70, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 400), ({'toll': 875, 'issued_day': 0, 'paid_day': None, 'today': 100, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3875)], [({'toll': 400, 'issued_day': 41, 'paid_day': 102, 'today': 126, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 3400), ({'toll': 250, 'issued_day': 29, 'paid_day': 89, 'today': 89, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': True}, 250), ({'toll': 875, 'issued_day': 45, 'paid_day': 106, 'today': 106, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 3875), ({'toll': 400, 'issued_day': 0, 'paid_day': 0, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 875, 'issued_day': 2, 'paid_day': 63, 'today': 120, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 4375), ({'toll': 875, 'issued_day': 0, 'paid_day': None, 'today': 100, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3875), ({'toll': 400, 'issued_day': 0, 'paid_day': None, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1400), ({'toll': 250, 'issued_day': 16, 'paid_day': 76, 'today': 76, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 250)], [({'toll': 400, 'issued_day': 0, 'paid_day': None, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1400), ({'toll': 875, 'issued_day': 33, 'paid_day': 94, 'today': 94, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 4375), ({'toll': 400, 'issued_day': 59, 'paid_day': 120, 'today': 120, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': True}, 3400), ({'toll': 250, 'issued_day': 56, 'paid_day': 116, 'today': 116, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 250), ({'toll': 250, 'issued_day': 31, 'paid_day': 92, 'today': 92, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': True}, 3250), ({'toll': 400, 'issued_day': 40, 'paid_day': 100, 'today': 100, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 400), ({'toll': 400, 'issued_day': 0, 'paid_day': 0, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 875, 'issued_day': 0, 'paid_day': None, 'today': 100, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3875)], [({'toll': 400, 'issued_day': 10, 'paid_day': 40, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 400, 'issued_day': 34, 'paid_day': 95, 'today': 95, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 3400), ({'toll': 400, 'issued_day': 10, 'paid_day': 70, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 400), ({'toll': 400, 'issued_day': 68, 'paid_day': 129, 'today': 129, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 3400), ({'toll': 875, 'issued_day': 0, 'paid_day': None, 'today': 100, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3875), ({'toll': 400, 'issued_day': 54, 'paid_day': 126, 'today': 162, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 3400), ({'toll': 400, 'issued_day': 79, 'paid_day': None, 'today': 109, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 400), ({'toll': 400, 'issued_day': 42, 'paid_day': 102, 'today': 102, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': True}, 400)], [({'toll': 250, 'issued_day': 65, 'paid_day': None, 'today': 126, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 3250), ({'toll': 400, 'issued_day': 0, 'paid_day': 0, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 400, 'issued_day': 10, 'paid_day': 40, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 400, 'issued_day': 10, 'paid_day': 70, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 400), ({'toll': 400, 'issued_day': 34, 'paid_day': 94, 'today': 94, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': True}, 400), ({'toll': 875, 'issued_day': 33, 'paid_day': 94, 'today': 94, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 3875), ({'toll': 400, 'issued_day': 15, 'paid_day': 76, 'today': 76, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': True}, 3400), ({'toll': 400, 'issued_day': 58, 'paid_day': 119, 'today': 119, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 3900)]]
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):
    ev = x['paid_day'] if x['paid_day'] is not None else x['today']
    age = ev - x['issued_day']
    pen = 0
    if age > x['stage1_days']:
        pen += x['first_fee']
        if x['waiver_first'] and x['paid_day'] is not None and age < x['stage2_days']:
            pen -= x['first_fee']
    if age > x['stage2_days']:
        pen += x['second_fee']
    return x['toll'] + min(pen, x['cap'])
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'toll': 875, 'issued_day': 85, 'paid_day': None, 'today': 115, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 875), ({'toll': 250, 'issued_day': 18, 'paid_day': 91, 'today': 132, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 3750), ({'toll': 400, 'issued_day': 0, 'paid_day': 0, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 875, 'issued_day': 41, 'paid_day': 72, 'today': 102, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 1375), ({'toll': 875, 'issued_day': 65, 'paid_day': 96, 'today': 96, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 1375), ({'toll': 400, 'issued_day': 52, 'paid_day': 112, 'today': 113, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 400), ({'toll': 400, 'issued_day': 10, 'paid_day': 70, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 400), ({'toll': 875, 'issued_day': 0, 'paid_day': None, 'today': 100, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3875)], [({'toll': 400, 'issued_day': 41, 'paid_day': 102, 'today': 126, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 3400), ({'toll': 250, 'issued_day': 29, 'paid_day': 89, 'today': 89, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': True}, 250), ({'toll': 875, 'issued_day': 45, 'paid_day': 106, 'today': 106, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 3875), ({'toll': 400, 'issued_day': 0, 'paid_day': 0, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 875, 'issued_day': 2, 'paid_day': 63, 'today': 120, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 4375), ({'toll': 875, 'issued_day': 0, 'paid_day': None, 'today': 100, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3875), ({'toll': 400, 'issued_day': 0, 'paid_day': None, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1400), ({'toll': 250, 'issued_day': 16, 'paid_day': 76, 'today': 76, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 250)], [({'toll': 400, 'issued_day': 0, 'paid_day': None, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1400), ({'toll': 875, 'issued_day': 33, 'paid_day': 94, 'today': 94, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 4375), ({'toll': 400, 'issued_day': 59, 'paid_day': 120, 'today': 120, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': True}, 3400), ({'toll': 250, 'issued_day': 56, 'paid_day': 116, 'today': 116, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 250), ({'toll': 250, 'issued_day': 31, 'paid_day': 92, 'today': 92, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': True}, 3250), ({'toll': 400, 'issued_day': 40, 'paid_day': 100, 'today': 100, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 400), ({'toll': 400, 'issued_day': 0, 'paid_day': 0, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 875, 'issued_day': 0, 'paid_day': None, 'today': 100, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3875)], [({'toll': 400, 'issued_day': 10, 'paid_day': 40, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 400, 'issued_day': 34, 'paid_day': 95, 'today': 95, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 3400), ({'toll': 400, 'issued_day': 10, 'paid_day': 70, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 400), ({'toll': 400, 'issued_day': 68, 'paid_day': 129, 'today': 129, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 3400), ({'toll': 875, 'issued_day': 0, 'paid_day': None, 'today': 100, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3875), ({'toll': 400, 'issued_day': 54, 'paid_day': 126, 'today': 162, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 3400), ({'toll': 400, 'issued_day': 79, 'paid_day': None, 'today': 109, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 400), ({'toll': 400, 'issued_day': 42, 'paid_day': 102, 'today': 102, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': True}, 400)], [({'toll': 250, 'issued_day': 65, 'paid_day': None, 'today': 126, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 3250), ({'toll': 400, 'issued_day': 0, 'paid_day': 0, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 400, 'issued_day': 10, 'paid_day': 40, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 400, 'issued_day': 10, 'paid_day': 70, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 400), ({'toll': 400, 'issued_day': 34, 'paid_day': 94, 'today': 94, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': True}, 400), ({'toll': 875, 'issued_day': 33, 'paid_day': 94, 'today': 94, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 3875), ({'toll': 400, 'issued_day': 15, 'paid_day': 76, 'today': 76, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': True}, 3400), ({'toll': 400, 'issued_day': 58, 'paid_day': 119, 'today': 119, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 3900)]]
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:
Unpaid toll violation escalation returns a wrong result when the first-offender waiver applies at any age.

Input {toll, issued_day, paid_day (or null), today, first_fee, second_fee, stage1_days, stage2_days, cap, waiver_first}. Age is measured to the payment day if paid, else today. Age above stage1 adds first_fee; first-time offenders (waiver_first) who actually paid within stage2 have it waived. Age above stage2 adds second_fee. Penalties (not the toll) are capped at cap. Return amount due.

split: open-access


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

N = 1
observations = []
def solve(x):
    ev = x['paid_day'] if x['paid_day'] is not None else x['today']
    age = ev - x['issued_day']
    pen = 0
    if age > x['stage1_days']:
        pen += x['first_fee']
        if x['waiver_first'] and age <= x['stage2_days']:
            pen -= x['first_fee']
    if age > x['stage2_days']:
        pen += x['second_fee']
    return x['toll'] + min(pen, x['cap'])
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'toll': 250, 'issued_day': 88, 'paid_day': 118, 'today': 118, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 250), ({'toll': 250, 'issued_day': 21, 'paid_day': None, 'today': 51, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 250), ({'toll': 250, 'issued_day': 94, 'paid_day': None, 'today': 125, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 1250), ({'toll': 400, 'issued_day': 10, 'paid_day': 70, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 400), ({'toll': 250, 'issued_day': 13, 'paid_day': None, 'today': 74, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 5250), ({'toll': 400, 'issued_day': 0, 'paid_day': None, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1400), ({'toll': 400, 'issued_day': 0, 'paid_day': 0, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 250, 'issued_day': 34, 'paid_day': None, 'today': 94, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': True}, 750)], [({'toll': 875, 'issued_day': 1, 'paid_day': 56, 'today': 65, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 875), ({'toll': 400, 'issued_day': 0, 'paid_day': None, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1400), ({'toll': 875, 'issued_day': 28, 'paid_day': 58, 'today': 58, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 875), ({'toll': 250, 'issued_day': 30, 'paid_day': None, 'today': 90, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': True}, 750), ({'toll': 875, 'issued_day': 27, 'paid_day': None, 'today': 87, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': True}, 1875), ({'toll': 875, 'issued_day': 0, 'paid_day': None, 'today': 100, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3875), ({'toll': 400, 'issued_day': 0, 'paid_day': 0, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 400, 'issued_day': 66, 'paid_day': 126, 'today': 127, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 900)], [({'toll': 250, 'issued_day': 95, 'paid_day': None, 'today': 155, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 750), ({'toll': 875, 'issued_day': 0, 'paid_day': None, 'today': 100, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3875), ({'toll': 250, 'issued_day': 6, 'paid_day': 36, 'today': 36, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': True}, 250), ({'toll': 400, 'issued_day': 0, 'paid_day': None, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1400), ({'toll': 400, 'issued_day': 10, 'paid_day': 40, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 400, 'issued_day': 91, 'paid_day': 121, 'today': 122, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': False}, 400), ({'toll': 875, 'issued_day': 67, 'paid_day': 114, 'today': 128, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 1875), ({'toll': 875, 'issued_day': 99, 'paid_day': None, 'today': 157, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1875)], [({'toll': 400, 'issued_day': 0, 'paid_day': 0, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 400, 'issued_day': 0, 'paid_day': None, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1400), ({'toll': 875, 'issued_day': 67, 'paid_day': 98, 'today': 128, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': True}, 875), ({'toll': 875, 'issued_day': 0, 'paid_day': None, 'today': 100, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3875), ({'toll': 400, 'issued_day': 6, 'paid_day': None, 'today': 66, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': True}, 900), ({'toll': 250, 'issued_day': 1, 'paid_day': 32, 'today': 32, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 250), ({'toll': 250, 'issued_day': 46, 'paid_day': 76, 'today': 76, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 250), ({'toll': 875, 'issued_day': 6, 'paid_day': None, 'today': 37, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 1375)], [({'toll': 400, 'issued_day': 49, 'paid_day': 97, 'today': 110, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 900), ({'toll': 400, 'issued_day': 10, 'paid_day': 70, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 400), ({'toll': 250, 'issued_day': 57, 'paid_day': None, 'today': 88, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 750), ({'toll': 250, 'issued_day': 30, 'paid_day': 61, 'today': 61, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 250), ({'toll': 400, 'issued_day': 0, 'paid_day': None, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1400), ({'toll': 400, 'issued_day': 47, 'paid_day': 78, 'today': 78, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 900), ({'toll': 400, 'issued_day': 0, 'paid_day': 0, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 875, 'issued_day': 83, 'paid_day': None, 'today': 131, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1375)]]
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):
    ev = x['paid_day'] if x['paid_day'] is not None else x['today']
    age = ev - x['issued_day']
    pen = 0
    if age > x['stage1_days']:
        pen += x['first_fee']
        if x['waiver_first'] and x['today'] - x['issued_day'] <= x['stage2_days'] and age <= x['stage2_days']:
            pen -= x['first_fee']
    if age > x['stage2_days']:
        pen += x['second_fee']
    return x['toll'] + min(pen, x['cap'])
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'toll': 250, 'issued_day': 88, 'paid_day': 118, 'today': 118, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 250), ({'toll': 250, 'issued_day': 21, 'paid_day': None, 'today': 51, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 250), ({'toll': 250, 'issued_day': 94, 'paid_day': None, 'today': 125, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 1250), ({'toll': 400, 'issued_day': 10, 'paid_day': 70, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 400), ({'toll': 250, 'issued_day': 13, 'paid_day': None, 'today': 74, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 5250), ({'toll': 400, 'issued_day': 0, 'paid_day': None, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1400), ({'toll': 400, 'issued_day': 0, 'paid_day': 0, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 250, 'issued_day': 34, 'paid_day': None, 'today': 94, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': True}, 750)], [({'toll': 875, 'issued_day': 1, 'paid_day': 56, 'today': 65, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 875), ({'toll': 400, 'issued_day': 0, 'paid_day': None, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1400), ({'toll': 875, 'issued_day': 28, 'paid_day': 58, 'today': 58, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 875), ({'toll': 250, 'issued_day': 30, 'paid_day': None, 'today': 90, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': True}, 750), ({'toll': 875, 'issued_day': 27, 'paid_day': None, 'today': 87, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': True}, 1875), ({'toll': 875, 'issued_day': 0, 'paid_day': None, 'today': 100, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3875), ({'toll': 400, 'issued_day': 0, 'paid_day': 0, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 400, 'issued_day': 66, 'paid_day': 126, 'today': 127, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 900)], [({'toll': 250, 'issued_day': 95, 'paid_day': None, 'today': 155, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 750), ({'toll': 875, 'issued_day': 0, 'paid_day': None, 'today': 100, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3875), ({'toll': 250, 'issued_day': 6, 'paid_day': 36, 'today': 36, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': True}, 250), ({'toll': 400, 'issued_day': 0, 'paid_day': None, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1400), ({'toll': 400, 'issued_day': 10, 'paid_day': 40, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 400, 'issued_day': 91, 'paid_day': 121, 'today': 122, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': False}, 400), ({'toll': 875, 'issued_day': 67, 'paid_day': 114, 'today': 128, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 1875), ({'toll': 875, 'issued_day': 99, 'paid_day': None, 'today': 157, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1875)], [({'toll': 400, 'issued_day': 0, 'paid_day': 0, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 400, 'issued_day': 0, 'paid_day': None, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1400), ({'toll': 875, 'issued_day': 67, 'paid_day': 98, 'today': 128, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': True}, 875), ({'toll': 875, 'issued_day': 0, 'paid_day': None, 'today': 100, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3875), ({'toll': 400, 'issued_day': 6, 'paid_day': None, 'today': 66, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': True}, 900), ({'toll': 250, 'issued_day': 1, 'paid_day': 32, 'today': 32, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 250), ({'toll': 250, 'issued_day': 46, 'paid_day': 76, 'today': 76, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 250), ({'toll': 875, 'issued_day': 6, 'paid_day': None, 'today': 37, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 1375)], [({'toll': 400, 'issued_day': 49, 'paid_day': 97, 'today': 110, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 900), ({'toll': 400, 'issued_day': 10, 'paid_day': 70, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 400), ({'toll': 250, 'issued_day': 57, 'paid_day': None, 'today': 88, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 750), ({'toll': 250, 'issued_day': 30, 'paid_day': 61, 'today': 61, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 250), ({'toll': 400, 'issued_day': 0, 'paid_day': None, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1400), ({'toll': 400, 'issued_day': 47, 'paid_day': 78, 'today': 78, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 900), ({'toll': 400, 'issued_day': 0, 'paid_day': 0, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 875, 'issued_day': 83, 'paid_day': None, 'today': 131, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1375)]]
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:
Unpaid toll violation escalation returns a wrong result when the waiver is granted to unpaid notices.

Input {toll, issued_day, paid_day (or null), today, first_fee, second_fee, stage1_days, stage2_days, cap, waiver_first}. Age is measured to the payment day if paid, else today. Age above stage1 adds first_fee; first-time offenders (waiver_first) who actually paid within stage2 have it waived. Age above stage2 adds second_fee. Penalties (not the toll) are capped at cap. Return amount due.

split: open-access


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

N = 1
observations = []
def solve(x):
    ev = x['paid_day'] if x['paid_day'] is not None else x['today']
    age = ev - x['issued_day']
    pen = 0
    if age > x['stage1_days']:
        pen += x['first_fee']
        if x['waiver_first'] and x['paid_day'] is not None and age <= x['stage2_days']:
            pen -= x['first_fee']
    if age > x['stage2_days']:
        pen += x['second_fee']
    return min(x['toll'] + pen, x['cap'])
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'toll': 400, 'issued_day': 66, 'paid_day': 126, 'today': 155, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 1400), ({'toll': 400, 'issued_day': 55, 'paid_day': None, 'today': 116, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 5400), ({'toll': 875, 'issued_day': 43, 'paid_day': None, 'today': 148, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 5875), ({'toll': 875, 'issued_day': 0, 'paid_day': None, 'today': 100, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3875), ({'toll': 400, 'issued_day': 10, 'paid_day': 40, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 250, 'issued_day': 52, 'paid_day': 82, 'today': 82, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': False}, 250), ({'toll': 875, 'issued_day': 35, 'paid_day': 66, 'today': 66, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 1375), ({'toll': 400, 'issued_day': 0, 'paid_day': None, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1400)], [({'toll': 400, 'issued_day': 38, 'paid_day': None, 'today': 69, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 900), ({'toll': 250, 'issued_day': 42, 'paid_day': 103, 'today': 103, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': True}, 3250), ({'toll': 400, 'issued_day': 91, 'paid_day': 152, 'today': 152, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3400), ({'toll': 400, 'issued_day': 0, 'paid_day': None, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1400), ({'toll': 400, 'issued_day': 10, 'paid_day': 70, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 400), ({'toll': 875, 'issued_day': 0, 'paid_day': None, 'today': 100, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3875), ({'toll': 400, 'issued_day': 93, 'paid_day': 124, 'today': 124, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 400), ({'toll': 875, 'issued_day': 29, 'paid_day': None, 'today': 47, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 875)], [({'toll': 250, 'issued_day': 72, 'paid_day': 143, 'today': 186, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3250), ({'toll': 400, 'issued_day': 0, 'paid_day': 0, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 250, 'issued_day': 53, 'paid_day': 93, 'today': 93, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 250), ({'toll': 400, 'issued_day': 10, 'paid_day': 70, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 400), ({'toll': 250, 'issued_day': 16, 'paid_day': None, 'today': 81, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 5250), ({'toll': 400, 'issued_day': 10, 'paid_day': 40, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 400, 'issued_day': 91, 'paid_day': 152, 'today': 152, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 5400), ({'toll': 875, 'issued_day': 31, 'paid_day': None, 'today': 61, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': True}, 875)], [({'toll': 875, 'issued_day': 28, 'paid_day': 59, 'today': 59, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': False}, 1375), ({'toll': 875, 'issued_day': 61, 'paid_day': 92, 'today': 121, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 1375), ({'toll': 400, 'issued_day': 10, 'paid_day': 70, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 400), ({'toll': 400, 'issued_day': 65, 'paid_day': None, 'today': 179, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3400), ({'toll': 400, 'issued_day': 10, 'paid_day': 40, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 400, 'issued_day': 30, 'paid_day': 77, 'today': 90, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': False}, 1400), ({'toll': 875, 'issued_day': 14, 'paid_day': None, 'today': 75, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 5875), ({'toll': 875, 'issued_day': 0, 'paid_day': None, 'today': 100, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3875)], [({'toll': 250, 'issued_day': 45, 'paid_day': 75, 'today': 76, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 250), ({'toll': 400, 'issued_day': 0, 'paid_day': 0, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 400, 'issued_day': 33, 'paid_day': None, 'today': 94, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': True}, 3400), ({'toll': 875, 'issued_day': 96, 'paid_day': None, 'today': 165, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': True}, 3875), ({'toll': 400, 'issued_day': 10, 'paid_day': 40, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 250, 'issued_day': 10, 'paid_day': 40, 'today': 125, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 250), ({'toll': 400, 'issued_day': 82, 'paid_day': None, 'today': 143, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3400), ({'toll': 400, 'issued_day': 0, 'paid_day': None, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1400)]]
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):
    ev = x['paid_day'] if x['paid_day'] is not None else x['today']
    age = ev - x['issued_day']
    pen = 0
    if age > x['stage1_days']:
        pen += x['first_fee']
        if x['waiver_first'] and x['paid_day'] is not None and age <= x['stage2_days']:
            pen -= x['first_fee']
    if age > x['stage2_days']:
        pen += x['second_fee']
    return x['toll'] + min(pen, x['cap'] - x['toll'])
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'toll': 400, 'issued_day': 66, 'paid_day': 126, 'today': 155, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 1400), ({'toll': 400, 'issued_day': 55, 'paid_day': None, 'today': 116, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 5400), ({'toll': 875, 'issued_day': 43, 'paid_day': None, 'today': 148, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 5875), ({'toll': 875, 'issued_day': 0, 'paid_day': None, 'today': 100, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3875), ({'toll': 400, 'issued_day': 10, 'paid_day': 40, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 250, 'issued_day': 52, 'paid_day': 82, 'today': 82, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': False}, 250), ({'toll': 875, 'issued_day': 35, 'paid_day': 66, 'today': 66, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 1375), ({'toll': 400, 'issued_day': 0, 'paid_day': None, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1400)], [({'toll': 400, 'issued_day': 38, 'paid_day': None, 'today': 69, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 900), ({'toll': 250, 'issued_day': 42, 'paid_day': 103, 'today': 103, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': True}, 3250), ({'toll': 400, 'issued_day': 91, 'paid_day': 152, 'today': 152, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3400), ({'toll': 400, 'issued_day': 0, 'paid_day': None, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1400), ({'toll': 400, 'issued_day': 10, 'paid_day': 70, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 400), ({'toll': 875, 'issued_day': 0, 'paid_day': None, 'today': 100, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3875), ({'toll': 400, 'issued_day': 93, 'paid_day': 124, 'today': 124, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': True}, 400), ({'toll': 875, 'issued_day': 29, 'paid_day': None, 'today': 47, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 875)], [({'toll': 250, 'issued_day': 72, 'paid_day': 143, 'today': 186, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3250), ({'toll': 400, 'issued_day': 0, 'paid_day': 0, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 250, 'issued_day': 53, 'paid_day': 93, 'today': 93, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 250), ({'toll': 400, 'issued_day': 10, 'paid_day': 70, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 400), ({'toll': 250, 'issued_day': 16, 'paid_day': None, 'today': 81, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 5250), ({'toll': 400, 'issued_day': 10, 'paid_day': 40, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 400, 'issued_day': 91, 'paid_day': 152, 'today': 152, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 5400), ({'toll': 875, 'issued_day': 31, 'paid_day': None, 'today': 61, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': True}, 875)], [({'toll': 875, 'issued_day': 28, 'paid_day': 59, 'today': 59, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': False}, 1375), ({'toll': 875, 'issued_day': 61, 'paid_day': 92, 'today': 121, 'first_fee': 500, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 1375), ({'toll': 400, 'issued_day': 10, 'paid_day': 70, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 400), ({'toll': 400, 'issued_day': 65, 'paid_day': None, 'today': 179, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3400), ({'toll': 400, 'issued_day': 10, 'paid_day': 40, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 400, 'issued_day': 30, 'paid_day': 77, 'today': 90, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 7500, 'waiver_first': False}, 1400), ({'toll': 875, 'issued_day': 14, 'paid_day': None, 'today': 75, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 5875), ({'toll': 875, 'issued_day': 0, 'paid_day': None, 'today': 100, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3875)], [({'toll': 250, 'issued_day': 45, 'paid_day': 75, 'today': 76, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 250), ({'toll': 400, 'issued_day': 0, 'paid_day': 0, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 400, 'issued_day': 33, 'paid_day': None, 'today': 94, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': True}, 3400), ({'toll': 875, 'issued_day': 96, 'paid_day': None, 'today': 165, 'first_fee': 1000, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': True}, 3875), ({'toll': 400, 'issued_day': 10, 'paid_day': 40, 'today': 90, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': False}, 400), ({'toll': 250, 'issued_day': 10, 'paid_day': 40, 'today': 125, 'first_fee': 500, 'second_fee': 5000, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 250), ({'toll': 400, 'issued_day': 82, 'paid_day': None, 'today': 143, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 3000, 'waiver_first': False}, 3400), ({'toll': 400, 'issued_day': 0, 'paid_day': None, 'today': 45, 'first_fee': 1000, 'second_fee': 2500, 'stage1_days': 30, 'stage2_days': 60, 'cap': 5000, 'waiver_first': True}, 1400)]]
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:
Unpaid toll violation escalation returns a wrong result when the cap includes the toll itself.

Input {toll, issued_day, paid_day (or null), today, first_fee, second_fee, stage1_days, stage2_days, cap, waiver_first}. Age is measured to the payment day if paid, else today. Age above stage1 adds first_fee; first-time offenders (waiver_first) who actually paid within stage2 have it waived. Age above stage2 adds second_fee. Penalties (not the toll) are capped at cap. Return amount due.

split: open-access