broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
import calendar
N = 1
observations = []
def solve(x):
    iss = datetime.date.fromisoformat(x['issue'])
    def plus_year(d):
        try:
            return d + datetime.timedelta(days=365)
        except ValueError:
            return datetime.date(d.year + 1, 2, 28)
    if x['first_travel'] is None:
        return ['UNUSED', plus_year(iss).isoformat()]
    ft = datetime.date.fromisoformat(x['first_travel'])
    if ft > plus_year(iss): return ['EXPIRED_UNUSED', plus_year(iss).isoformat()]
    return ['TRAVEL', plus_year(ft).isoformat()]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['travel commenced mid-year', {'issue': '2027-03-10', 'first_travel': '2027-06-02'}, ['TRAVEL', '2028-06-02']], ['unused ticket', {'issue': '2027-01-15', 'first_travel': None}, ['UNUSED', '2028-01-15']], ['leap day issue', {'issue': '2028-02-29', 'first_travel': None}, ['UNUSED', '2029-02-28']], ['leap day first travel', {'issue': '2028-01-11', 'first_travel': '2028-02-29'}, ['TRAVEL', '2029-02-28']], ['travel exactly one year after issue', {'issue': '2027-05-11', 'first_travel': '2028-05-11'}, ['TRAVEL', '2029-05-11']], ['travel one day too late', {'issue': '2027-05-10', 'first_travel': '2028-05-11'}, ['EXPIRED_UNUSED', '2028-05-10']], ['span includes Feb 29', {'issue': '2027-06-01', 'first_travel': '2027-06-01'}, ['TRAVEL', '2028-06-01']], ['late leap-year start', {'issue': '2028-05-01', 'first_travel': '2028-06-11'}, ['TRAVEL', '2029-06-11']], ['sampled case 1', {'issue': '2028-11-11', 'first_travel': '2029-05-16'}, ['TRAVEL', '2030-05-16']], ['sampled case 2', {'issue': '2027-07-24', 'first_travel': '2027-07-26'}, ['TRAVEL', '2028-07-26']], ['sampled case 3', {'issue': '2029-01-16', 'first_travel': None}, ['UNUSED', '2030-01-16']]], [['travel commenced mid-year', {'issue': '2027-03-10', 'first_travel': '2027-06-03'}, ['TRAVEL', '2028-06-03']], ['unused ticket', {'issue': '2027-02-15', 'first_travel': None}, ['UNUSED', '2028-02-15']], ['leap day issue', {'issue': '2028-02-29', 'first_travel': None}, ['UNUSED', '2029-02-28']], ['leap day first travel', {'issue': '2028-01-12', 'first_travel': '2028-02-29'}, ['TRAVEL', '2029-02-28']], ['travel exactly one year after issue', {'issue': '2027-05-12', 'first_travel': '2028-05-12'}, ['TRAVEL', '2029-05-12']], ['travel one day too late', {'issue': '2027-05-10', 'first_travel': '2028-05-11'}, ['EXPIRED_UNUSED', '2028-05-10']], ['span includes Feb 29', {'issue': '2027-06-01', 'first_travel': '2027-06-02'}, ['TRAVEL', '2028-06-02']], ['late leap-year start', {'issue': '2028-05-01', 'first_travel': '2028-06-12'}, ['TRAVEL', '2029-06-12']], ['sampled case 1', {'issue': '2027-08-03', 'first_travel': '2028-08-03'}, ['TRAVEL', '2029-08-03']], ['sampled case 2', {'issue': '2028-03-31', 'first_travel': None}, ['UNUSED', '2029-03-31']], ['sampled case 3', {'issue': '2028-06-12', 'first_travel': '2029-06-12'}, ['TRAVEL', '2030-06-12']]], [['travel commenced mid-year', {'issue': '2027-03-10', 'first_travel': '2027-06-04'}, ['TRAVEL', '2028-06-04']], ['unused ticket', {'issue': '2027-03-15', 'first_travel': None}, ['UNUSED', '2028-03-15']], ['leap day issue', {'issue': '2028-02-29', 'first_travel': None}, ['UNUSED', '2029-02-28']], ['leap day first travel', {'issue': '2028-01-13', 'first_travel': '2028-02-29'}, ['TRAVEL', '2029-02-28']], ['travel exactly one year after issue', {'issue': '2027-05-13', 'first_travel': '2028-05-13'}, ['TRAVEL', '2029-05-13']], ['travel one day too late', {'issue': '2027-05-10', 'first_travel': '2028-05-11'}, ['EXPIRED_UNUSED', '2028-05-10']], ['span includes Feb 29', {'issue': '2027-06-01', 'first_travel': '2027-06-03'}, ['TRAVEL', '2028-06-03']], ['late leap-year start', {'issue': '2028-05-01', 'first_travel': '2028-06-13'}, ['TRAVEL', '2029-06-13']], ['sampled case 1', {'issue': '2028-10-17', 'first_travel': None}, ['UNUSED', '2029-10-17']], ['sampled case 2', {'issue': '2027-02-28', 'first_travel': '2028-02-28'}, ['TRAVEL', '2029-02-28']], ['sampled case 3', {'issue': '2029-06-17', 'first_travel': '2030-04-20'}, ['TRAVEL', '2031-04-20']]], [['travel commenced mid-year', {'issue': '2027-03-10', 'first_travel': '2027-06-05'}, ['TRAVEL', '2028-06-05']], ['unused ticket', {'issue': '2027-04-15', 'first_travel': None}, ['UNUSED', '2028-04-15']], ['leap day issue', {'issue': '2028-02-29', 'first_travel': None}, ['UNUSED', '2029-02-28']], ['leap day first travel', {'issue': '2028-01-14', 'first_travel': '2028-02-29'}, ['TRAVEL', '2029-02-28']], ['travel exactly one year after issue', {'issue': '2027-05-14', 'first_travel': '2028-05-14'}, ['TRAVEL', '2029-05-14']], ['travel one day too late', {'issue': '2027-05-10', 'first_travel': '2028-05-11'}, ['EXPIRED_UNUSED', '2028-05-10']], ['span includes Feb 29', {'issue': '2027-06-01', 'first_travel': '2027-06-04'}, ['TRAVEL', '2028-06-04']], ['late leap-year start', {'issue': '2028-05-01', 'first_travel': '2028-06-14'}, ['TRAVEL', '2029-06-14']], ['sampled case 1', {'issue': '2028-11-25', 'first_travel': '2029-11-26'}, ['EXPIRED_UNUSED', '2029-11-25']], ['sampled case 2', {'issue': '2029-06-03', 'first_travel': '2030-06-04'}, ['EXPIRED_UNUSED', '2030-06-03']], ['sampled case 3', {'issue': '2028-06-18', 'first_travel': None}, ['UNUSED', '2029-06-18']]], [['travel commenced mid-year', {'issue': '2027-03-10', 'first_travel': '2027-06-06'}, ['TRAVEL', '2028-06-06']], ['unused ticket', {'issue': '2027-05-15', 'first_travel': None}, ['UNUSED', '2028-05-15']], ['leap day issue', {'issue': '2028-02-29', 'first_travel': None}, ['UNUSED', '2029-02-28']], ['leap day first travel', {'issue': '2028-01-15', 'first_travel': '2028-02-29'}, ['TRAVEL', '2029-02-28']], ['travel exactly one year after issue', {'issue': '2027-05-15', 'first_travel': '2028-05-15'}, ['TRAVEL', '2029-05-15']], ['travel one day too late', {'issue': '2027-05-10', 'first_travel': '2028-05-11'}, ['EXPIRED_UNUSED', '2028-05-10']], ['span includes Feb 29', {'issue': '2027-06-01', 'first_travel': '2027-06-05'}, ['TRAVEL', '2028-06-05']], ['late leap-year start', {'issue': '2028-05-01', 'first_travel': '2028-06-15'}, ['TRAVEL', '2029-06-15']], ['sampled case 1', {'issue': '2028-07-20', 'first_travel': '2029-07-20'}, ['TRAVEL', '2030-07-20']], ['sampled case 2', {'issue': '2027-10-29', 'first_travel': '2027-12-02'}, ['TRAVEL', '2028-12-02']], ['sampled case 3', {'issue': '2029-03-08', 'first_travel': '2029-05-13'}, ['TRAVEL', '2030-05-13']]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
import calendar
N = 1
observations = []
def solve(x):
    iss = datetime.date.fromisoformat(x['issue'])
    def plus_year(d):
        try:
            return d + datetime.timedelta(days=366 if calendar.isleap(d.year) else 365)
        except ValueError:
            return datetime.date(d.year + 1, 2, 28)
    if x['first_travel'] is None:
        return ['UNUSED', plus_year(iss).isoformat()]
    ft = datetime.date.fromisoformat(x['first_travel'])
    if ft > plus_year(iss): return ['EXPIRED_UNUSED', plus_year(iss).isoformat()]
    return ['TRAVEL', plus_year(ft).isoformat()]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['travel commenced mid-year', {'issue': '2027-03-10', 'first_travel': '2027-06-02'}, ['TRAVEL', '2028-06-02']], ['unused ticket', {'issue': '2027-01-15', 'first_travel': None}, ['UNUSED', '2028-01-15']], ['leap day issue', {'issue': '2028-02-29', 'first_travel': None}, ['UNUSED', '2029-02-28']], ['leap day first travel', {'issue': '2028-01-11', 'first_travel': '2028-02-29'}, ['TRAVEL', '2029-02-28']], ['travel exactly one year after issue', {'issue': '2027-05-11', 'first_travel': '2028-05-11'}, ['TRAVEL', '2029-05-11']], ['travel one day too late', {'issue': '2027-05-10', 'first_travel': '2028-05-11'}, ['EXPIRED_UNUSED', '2028-05-10']], ['span includes Feb 29', {'issue': '2027-06-01', 'first_travel': '2027-06-01'}, ['TRAVEL', '2028-06-01']], ['late leap-year start', {'issue': '2028-05-01', 'first_travel': '2028-06-11'}, ['TRAVEL', '2029-06-11']], ['sampled case 1', {'issue': '2028-11-11', 'first_travel': '2029-05-16'}, ['TRAVEL', '2030-05-16']], ['sampled case 2', {'issue': '2027-07-24', 'first_travel': '2027-07-26'}, ['TRAVEL', '2028-07-26']], ['sampled case 3', {'issue': '2029-01-16', 'first_travel': None}, ['UNUSED', '2030-01-16']]], [['travel commenced mid-year', {'issue': '2027-03-10', 'first_travel': '2027-06-03'}, ['TRAVEL', '2028-06-03']], ['unused ticket', {'issue': '2027-02-15', 'first_travel': None}, ['UNUSED', '2028-02-15']], ['leap day issue', {'issue': '2028-02-29', 'first_travel': None}, ['UNUSED', '2029-02-28']], ['leap day first travel', {'issue': '2028-01-12', 'first_travel': '2028-02-29'}, ['TRAVEL', '2029-02-28']], ['travel exactly one year after issue', {'issue': '2027-05-12', 'first_travel': '2028-05-12'}, ['TRAVEL', '2029-05-12']], ['travel one day too late', {'issue': '2027-05-10', 'first_travel': '2028-05-11'}, ['EXPIRED_UNUSED', '2028-05-10']], ['span includes Feb 29', {'issue': '2027-06-01', 'first_travel': '2027-06-02'}, ['TRAVEL', '2028-06-02']], ['late leap-year start', {'issue': '2028-05-01', 'first_travel': '2028-06-12'}, ['TRAVEL', '2029-06-12']], ['sampled case 1', {'issue': '2027-08-03', 'first_travel': '2028-08-03'}, ['TRAVEL', '2029-08-03']], ['sampled case 2', {'issue': '2028-03-31', 'first_travel': None}, ['UNUSED', '2029-03-31']], ['sampled case 3', {'issue': '2028-06-12', 'first_travel': '2029-06-12'}, ['TRAVEL', '2030-06-12']]], [['travel commenced mid-year', {'issue': '2027-03-10', 'first_travel': '2027-06-04'}, ['TRAVEL', '2028-06-04']], ['unused ticket', {'issue': '2027-03-15', 'first_travel': None}, ['UNUSED', '2028-03-15']], ['leap day issue', {'issue': '2028-02-29', 'first_travel': None}, ['UNUSED', '2029-02-28']], ['leap day first travel', {'issue': '2028-01-13', 'first_travel': '2028-02-29'}, ['TRAVEL', '2029-02-28']], ['travel exactly one year after issue', {'issue': '2027-05-13', 'first_travel': '2028-05-13'}, ['TRAVEL', '2029-05-13']], ['travel one day too late', {'issue': '2027-05-10', 'first_travel': '2028-05-11'}, ['EXPIRED_UNUSED', '2028-05-10']], ['span includes Feb 29', {'issue': '2027-06-01', 'first_travel': '2027-06-03'}, ['TRAVEL', '2028-06-03']], ['late leap-year start', {'issue': '2028-05-01', 'first_travel': '2028-06-13'}, ['TRAVEL', '2029-06-13']], ['sampled case 1', {'issue': '2028-10-17', 'first_travel': None}, ['UNUSED', '2029-10-17']], ['sampled case 2', {'issue': '2027-02-28', 'first_travel': '2028-02-28'}, ['TRAVEL', '2029-02-28']], ['sampled case 3', {'issue': '2029-06-17', 'first_travel': '2030-04-20'}, ['TRAVEL', '2031-04-20']]], [['travel commenced mid-year', {'issue': '2027-03-10', 'first_travel': '2027-06-05'}, ['TRAVEL', '2028-06-05']], ['unused ticket', {'issue': '2027-04-15', 'first_travel': None}, ['UNUSED', '2028-04-15']], ['leap day issue', {'issue': '2028-02-29', 'first_travel': None}, ['UNUSED', '2029-02-28']], ['leap day first travel', {'issue': '2028-01-14', 'first_travel': '2028-02-29'}, ['TRAVEL', '2029-02-28']], ['travel exactly one year after issue', {'issue': '2027-05-14', 'first_travel': '2028-05-14'}, ['TRAVEL', '2029-05-14']], ['travel one day too late', {'issue': '2027-05-10', 'first_travel': '2028-05-11'}, ['EXPIRED_UNUSED', '2028-05-10']], ['span includes Feb 29', {'issue': '2027-06-01', 'first_travel': '2027-06-04'}, ['TRAVEL', '2028-06-04']], ['late leap-year start', {'issue': '2028-05-01', 'first_travel': '2028-06-14'}, ['TRAVEL', '2029-06-14']], ['sampled case 1', {'issue': '2028-11-25', 'first_travel': '2029-11-26'}, ['EXPIRED_UNUSED', '2029-11-25']], ['sampled case 2', {'issue': '2029-06-03', 'first_travel': '2030-06-04'}, ['EXPIRED_UNUSED', '2030-06-03']], ['sampled case 3', {'issue': '2028-06-18', 'first_travel': None}, ['UNUSED', '2029-06-18']]], [['travel commenced mid-year', {'issue': '2027-03-10', 'first_travel': '2027-06-06'}, ['TRAVEL', '2028-06-06']], ['unused ticket', {'issue': '2027-05-15', 'first_travel': None}, ['UNUSED', '2028-05-15']], ['leap day issue', {'issue': '2028-02-29', 'first_travel': None}, ['UNUSED', '2029-02-28']], ['leap day first travel', {'issue': '2028-01-15', 'first_travel': '2028-02-29'}, ['TRAVEL', '2029-02-28']], ['travel exactly one year after issue', {'issue': '2027-05-15', 'first_travel': '2028-05-15'}, ['TRAVEL', '2029-05-15']], ['travel one day too late', {'issue': '2027-05-10', 'first_travel': '2028-05-11'}, ['EXPIRED_UNUSED', '2028-05-10']], ['span includes Feb 29', {'issue': '2027-06-01', 'first_travel': '2027-06-05'}, ['TRAVEL', '2028-06-05']], ['late leap-year start', {'issue': '2028-05-01', 'first_travel': '2028-06-15'}, ['TRAVEL', '2029-06-15']], ['sampled case 1', {'issue': '2028-07-20', 'first_travel': '2029-07-20'}, ['TRAVEL', '2030-07-20']], ['sampled case 2', {'issue': '2027-10-29', 'first_travel': '2027-12-02'}, ['TRAVEL', '2028-12-02']], ['sampled case 3', {'issue': '2029-03-08', 'first_travel': '2029-05-13'}, ['TRAVEL', '2030-05-13']]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Tickets whose validity spans 29 February expire a day early.

Input {'issue','first_travel' (ISO or None)}. One calendar year = same month/day next year (29 Feb -> 28 Feb). Unused -> ['UNUSED', issue+1y]. First travel later than issue+1y -> ['EXPIRED_UNUSED', issue+1y] (travel on that date is still valid). Otherwise ['TRAVEL', first travel+1y].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
import calendar
N = 1
observations = []
def solve(x):
    iss = datetime.date.fromisoformat(x['issue'])
    def plus_year(d):
        try:
            return d.replace(year=d.year + 1)
        except ValueError:
            return datetime.date(d.year + 1, 2, 28)
    if x['first_travel'] is None:
        return ['UNUSED', plus_year(iss).isoformat()]
    ft = datetime.date.fromisoformat(x['first_travel'])
    if ft > plus_year(iss): return ['EXPIRED_UNUSED', plus_year(iss).isoformat()]
    return ['TRAVEL', plus_year(iss).isoformat()]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['travel commenced mid-year', {'issue': '2027-03-10', 'first_travel': '2027-06-02'}, ['TRAVEL', '2028-06-02']], ['unused ticket', {'issue': '2027-01-15', 'first_travel': None}, ['UNUSED', '2028-01-15']], ['leap day issue', {'issue': '2028-02-29', 'first_travel': None}, ['UNUSED', '2029-02-28']], ['leap day first travel', {'issue': '2028-01-11', 'first_travel': '2028-02-29'}, ['TRAVEL', '2029-02-28']], ['travel exactly one year after issue', {'issue': '2027-05-11', 'first_travel': '2028-05-11'}, ['TRAVEL', '2029-05-11']], ['travel one day too late', {'issue': '2027-05-10', 'first_travel': '2028-05-11'}, ['EXPIRED_UNUSED', '2028-05-10']], ['span includes Feb 29', {'issue': '2027-06-01', 'first_travel': '2027-06-01'}, ['TRAVEL', '2028-06-01']], ['late leap-year start', {'issue': '2028-05-01', 'first_travel': '2028-06-11'}, ['TRAVEL', '2029-06-11']], ['sampled case 1', {'issue': '2028-11-11', 'first_travel': '2029-05-16'}, ['TRAVEL', '2030-05-16']], ['sampled case 2', {'issue': '2027-07-24', 'first_travel': '2027-07-26'}, ['TRAVEL', '2028-07-26']], ['sampled case 3', {'issue': '2029-01-16', 'first_travel': None}, ['UNUSED', '2030-01-16']]], [['travel commenced mid-year', {'issue': '2027-03-10', 'first_travel': '2027-06-03'}, ['TRAVEL', '2028-06-03']], ['unused ticket', {'issue': '2027-02-15', 'first_travel': None}, ['UNUSED', '2028-02-15']], ['leap day issue', {'issue': '2028-02-29', 'first_travel': None}, ['UNUSED', '2029-02-28']], ['leap day first travel', {'issue': '2028-01-12', 'first_travel': '2028-02-29'}, ['TRAVEL', '2029-02-28']], ['travel exactly one year after issue', {'issue': '2027-05-12', 'first_travel': '2028-05-12'}, ['TRAVEL', '2029-05-12']], ['travel one day too late', {'issue': '2027-05-10', 'first_travel': '2028-05-11'}, ['EXPIRED_UNUSED', '2028-05-10']], ['span includes Feb 29', {'issue': '2027-06-01', 'first_travel': '2027-06-02'}, ['TRAVEL', '2028-06-02']], ['late leap-year start', {'issue': '2028-05-01', 'first_travel': '2028-06-12'}, ['TRAVEL', '2029-06-12']], ['sampled case 1', {'issue': '2027-08-03', 'first_travel': '2028-08-03'}, ['TRAVEL', '2029-08-03']], ['sampled case 2', {'issue': '2028-03-31', 'first_travel': None}, ['UNUSED', '2029-03-31']], ['sampled case 3', {'issue': '2028-06-12', 'first_travel': '2029-06-12'}, ['TRAVEL', '2030-06-12']]], [['travel commenced mid-year', {'issue': '2027-03-10', 'first_travel': '2027-06-04'}, ['TRAVEL', '2028-06-04']], ['unused ticket', {'issue': '2027-03-15', 'first_travel': None}, ['UNUSED', '2028-03-15']], ['leap day issue', {'issue': '2028-02-29', 'first_travel': None}, ['UNUSED', '2029-02-28']], ['leap day first travel', {'issue': '2028-01-13', 'first_travel': '2028-02-29'}, ['TRAVEL', '2029-02-28']], ['travel exactly one year after issue', {'issue': '2027-05-13', 'first_travel': '2028-05-13'}, ['TRAVEL', '2029-05-13']], ['travel one day too late', {'issue': '2027-05-10', 'first_travel': '2028-05-11'}, ['EXPIRED_UNUSED', '2028-05-10']], ['span includes Feb 29', {'issue': '2027-06-01', 'first_travel': '2027-06-03'}, ['TRAVEL', '2028-06-03']], ['late leap-year start', {'issue': '2028-05-01', 'first_travel': '2028-06-13'}, ['TRAVEL', '2029-06-13']], ['sampled case 1', {'issue': '2028-10-17', 'first_travel': None}, ['UNUSED', '2029-10-17']], ['sampled case 2', {'issue': '2027-02-28', 'first_travel': '2028-02-28'}, ['TRAVEL', '2029-02-28']], ['sampled case 3', {'issue': '2029-06-17', 'first_travel': '2030-04-20'}, ['TRAVEL', '2031-04-20']]], [['travel commenced mid-year', {'issue': '2027-03-10', 'first_travel': '2027-06-05'}, ['TRAVEL', '2028-06-05']], ['unused ticket', {'issue': '2027-04-15', 'first_travel': None}, ['UNUSED', '2028-04-15']], ['leap day issue', {'issue': '2028-02-29', 'first_travel': None}, ['UNUSED', '2029-02-28']], ['leap day first travel', {'issue': '2028-01-14', 'first_travel': '2028-02-29'}, ['TRAVEL', '2029-02-28']], ['travel exactly one year after issue', {'issue': '2027-05-14', 'first_travel': '2028-05-14'}, ['TRAVEL', '2029-05-14']], ['travel one day too late', {'issue': '2027-05-10', 'first_travel': '2028-05-11'}, ['EXPIRED_UNUSED', '2028-05-10']], ['span includes Feb 29', {'issue': '2027-06-01', 'first_travel': '2027-06-04'}, ['TRAVEL', '2028-06-04']], ['late leap-year start', {'issue': '2028-05-01', 'first_travel': '2028-06-14'}, ['TRAVEL', '2029-06-14']], ['sampled case 1', {'issue': '2028-11-25', 'first_travel': '2029-11-26'}, ['EXPIRED_UNUSED', '2029-11-25']], ['sampled case 2', {'issue': '2029-06-03', 'first_travel': '2030-06-04'}, ['EXPIRED_UNUSED', '2030-06-03']], ['sampled case 3', {'issue': '2028-06-18', 'first_travel': None}, ['UNUSED', '2029-06-18']]], [['travel commenced mid-year', {'issue': '2027-03-10', 'first_travel': '2027-06-06'}, ['TRAVEL', '2028-06-06']], ['unused ticket', {'issue': '2027-05-15', 'first_travel': None}, ['UNUSED', '2028-05-15']], ['leap day issue', {'issue': '2028-02-29', 'first_travel': None}, ['UNUSED', '2029-02-28']], ['leap day first travel', {'issue': '2028-01-15', 'first_travel': '2028-02-29'}, ['TRAVEL', '2029-02-28']], ['travel exactly one year after issue', {'issue': '2027-05-15', 'first_travel': '2028-05-15'}, ['TRAVEL', '2029-05-15']], ['travel one day too late', {'issue': '2027-05-10', 'first_travel': '2028-05-11'}, ['EXPIRED_UNUSED', '2028-05-10']], ['span includes Feb 29', {'issue': '2027-06-01', 'first_travel': '2027-06-05'}, ['TRAVEL', '2028-06-05']], ['late leap-year start', {'issue': '2028-05-01', 'first_travel': '2028-06-15'}, ['TRAVEL', '2029-06-15']], ['sampled case 1', {'issue': '2028-07-20', 'first_travel': '2029-07-20'}, ['TRAVEL', '2030-07-20']], ['sampled case 2', {'issue': '2027-10-29', 'first_travel': '2027-12-02'}, ['TRAVEL', '2028-12-02']], ['sampled case 3', {'issue': '2029-03-08', 'first_travel': '2029-05-13'}, ['TRAVEL', '2030-05-13']]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
import calendar
N = 1
observations = []
def solve(x):
    iss = datetime.date.fromisoformat(x['issue'])
    def plus_year(d):
        try:
            return d.replace(year=d.year + 1)
        except ValueError:
            return datetime.date(d.year + 1, 2, 28)
    if x['first_travel'] is None:
        return ['UNUSED', plus_year(iss).isoformat()]
    ft = datetime.date.fromisoformat(x['first_travel'])
    if ft > plus_year(iss): return ['EXPIRED_UNUSED', plus_year(iss).isoformat()]
    return ['TRAVEL', (plus_year(ft) - datetime.timedelta(days=1)).isoformat()]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['travel commenced mid-year', {'issue': '2027-03-10', 'first_travel': '2027-06-02'}, ['TRAVEL', '2028-06-02']], ['unused ticket', {'issue': '2027-01-15', 'first_travel': None}, ['UNUSED', '2028-01-15']], ['leap day issue', {'issue': '2028-02-29', 'first_travel': None}, ['UNUSED', '2029-02-28']], ['leap day first travel', {'issue': '2028-01-11', 'first_travel': '2028-02-29'}, ['TRAVEL', '2029-02-28']], ['travel exactly one year after issue', {'issue': '2027-05-11', 'first_travel': '2028-05-11'}, ['TRAVEL', '2029-05-11']], ['travel one day too late', {'issue': '2027-05-10', 'first_travel': '2028-05-11'}, ['EXPIRED_UNUSED', '2028-05-10']], ['span includes Feb 29', {'issue': '2027-06-01', 'first_travel': '2027-06-01'}, ['TRAVEL', '2028-06-01']], ['late leap-year start', {'issue': '2028-05-01', 'first_travel': '2028-06-11'}, ['TRAVEL', '2029-06-11']], ['sampled case 1', {'issue': '2028-11-11', 'first_travel': '2029-05-16'}, ['TRAVEL', '2030-05-16']], ['sampled case 2', {'issue': '2027-07-24', 'first_travel': '2027-07-26'}, ['TRAVEL', '2028-07-26']], ['sampled case 3', {'issue': '2029-01-16', 'first_travel': None}, ['UNUSED', '2030-01-16']]], [['travel commenced mid-year', {'issue': '2027-03-10', 'first_travel': '2027-06-03'}, ['TRAVEL', '2028-06-03']], ['unused ticket', {'issue': '2027-02-15', 'first_travel': None}, ['UNUSED', '2028-02-15']], ['leap day issue', {'issue': '2028-02-29', 'first_travel': None}, ['UNUSED', '2029-02-28']], ['leap day first travel', {'issue': '2028-01-12', 'first_travel': '2028-02-29'}, ['TRAVEL', '2029-02-28']], ['travel exactly one year after issue', {'issue': '2027-05-12', 'first_travel': '2028-05-12'}, ['TRAVEL', '2029-05-12']], ['travel one day too late', {'issue': '2027-05-10', 'first_travel': '2028-05-11'}, ['EXPIRED_UNUSED', '2028-05-10']], ['span includes Feb 29', {'issue': '2027-06-01', 'first_travel': '2027-06-02'}, ['TRAVEL', '2028-06-02']], ['late leap-year start', {'issue': '2028-05-01', 'first_travel': '2028-06-12'}, ['TRAVEL', '2029-06-12']], ['sampled case 1', {'issue': '2027-08-03', 'first_travel': '2028-08-03'}, ['TRAVEL', '2029-08-03']], ['sampled case 2', {'issue': '2028-03-31', 'first_travel': None}, ['UNUSED', '2029-03-31']], ['sampled case 3', {'issue': '2028-06-12', 'first_travel': '2029-06-12'}, ['TRAVEL', '2030-06-12']]], [['travel commenced mid-year', {'issue': '2027-03-10', 'first_travel': '2027-06-04'}, ['TRAVEL', '2028-06-04']], ['unused ticket', {'issue': '2027-03-15', 'first_travel': None}, ['UNUSED', '2028-03-15']], ['leap day issue', {'issue': '2028-02-29', 'first_travel': None}, ['UNUSED', '2029-02-28']], ['leap day first travel', {'issue': '2028-01-13', 'first_travel': '2028-02-29'}, ['TRAVEL', '2029-02-28']], ['travel exactly one year after issue', {'issue': '2027-05-13', 'first_travel': '2028-05-13'}, ['TRAVEL', '2029-05-13']], ['travel one day too late', {'issue': '2027-05-10', 'first_travel': '2028-05-11'}, ['EXPIRED_UNUSED', '2028-05-10']], ['span includes Feb 29', {'issue': '2027-06-01', 'first_travel': '2027-06-03'}, ['TRAVEL', '2028-06-03']], ['late leap-year start', {'issue': '2028-05-01', 'first_travel': '2028-06-13'}, ['TRAVEL', '2029-06-13']], ['sampled case 1', {'issue': '2028-10-17', 'first_travel': None}, ['UNUSED', '2029-10-17']], ['sampled case 2', {'issue': '2027-02-28', 'first_travel': '2028-02-28'}, ['TRAVEL', '2029-02-28']], ['sampled case 3', {'issue': '2029-06-17', 'first_travel': '2030-04-20'}, ['TRAVEL', '2031-04-20']]], [['travel commenced mid-year', {'issue': '2027-03-10', 'first_travel': '2027-06-05'}, ['TRAVEL', '2028-06-05']], ['unused ticket', {'issue': '2027-04-15', 'first_travel': None}, ['UNUSED', '2028-04-15']], ['leap day issue', {'issue': '2028-02-29', 'first_travel': None}, ['UNUSED', '2029-02-28']], ['leap day first travel', {'issue': '2028-01-14', 'first_travel': '2028-02-29'}, ['TRAVEL', '2029-02-28']], ['travel exactly one year after issue', {'issue': '2027-05-14', 'first_travel': '2028-05-14'}, ['TRAVEL', '2029-05-14']], ['travel one day too late', {'issue': '2027-05-10', 'first_travel': '2028-05-11'}, ['EXPIRED_UNUSED', '2028-05-10']], ['span includes Feb 29', {'issue': '2027-06-01', 'first_travel': '2027-06-04'}, ['TRAVEL', '2028-06-04']], ['late leap-year start', {'issue': '2028-05-01', 'first_travel': '2028-06-14'}, ['TRAVEL', '2029-06-14']], ['sampled case 1', {'issue': '2028-11-25', 'first_travel': '2029-11-26'}, ['EXPIRED_UNUSED', '2029-11-25']], ['sampled case 2', {'issue': '2029-06-03', 'first_travel': '2030-06-04'}, ['EXPIRED_UNUSED', '2030-06-03']], ['sampled case 3', {'issue': '2028-06-18', 'first_travel': None}, ['UNUSED', '2029-06-18']]], [['travel commenced mid-year', {'issue': '2027-03-10', 'first_travel': '2027-06-06'}, ['TRAVEL', '2028-06-06']], ['unused ticket', {'issue': '2027-05-15', 'first_travel': None}, ['UNUSED', '2028-05-15']], ['leap day issue', {'issue': '2028-02-29', 'first_travel': None}, ['UNUSED', '2029-02-28']], ['leap day first travel', {'issue': '2028-01-15', 'first_travel': '2028-02-29'}, ['TRAVEL', '2029-02-28']], ['travel exactly one year after issue', {'issue': '2027-05-15', 'first_travel': '2028-05-15'}, ['TRAVEL', '2029-05-15']], ['travel one day too late', {'issue': '2027-05-10', 'first_travel': '2028-05-11'}, ['EXPIRED_UNUSED', '2028-05-10']], ['span includes Feb 29', {'issue': '2027-06-01', 'first_travel': '2027-06-05'}, ['TRAVEL', '2028-06-05']], ['late leap-year start', {'issue': '2028-05-01', 'first_travel': '2028-06-15'}, ['TRAVEL', '2029-06-15']], ['sampled case 1', {'issue': '2028-07-20', 'first_travel': '2029-07-20'}, ['TRAVEL', '2030-07-20']], ['sampled case 2', {'issue': '2027-10-29', 'first_travel': '2027-12-02'}, ['TRAVEL', '2028-12-02']], ['sampled case 3', {'issue': '2029-03-08', 'first_travel': '2029-05-13'}, ['TRAVEL', '2030-05-13']]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A ticket first used three months after issue expires three months early.

Input {'issue','first_travel' (ISO or None)}. One calendar year = same month/day next year (29 Feb -> 28 Feb). Unused -> ['UNUSED', issue+1y]. First travel later than issue+1y -> ['EXPIRED_UNUSED', issue+1y] (travel on that date is still valid). Otherwise ['TRAVEL', first travel+1y].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
import calendar
N = 1
observations = []
def solve(x):
    iss = datetime.date.fromisoformat(x['issue'])
    def plus_year(d):
        try:
            return d.replace(year=d.year + 1)
        except ValueError:
            return datetime.date(d.year + 1, 3, 1)
    if x['first_travel'] is None:
        return ['UNUSED', plus_year(iss).isoformat()]
    ft = datetime.date.fromisoformat(x['first_travel'])
    if ft > plus_year(iss): return ['EXPIRED_UNUSED', plus_year(iss).isoformat()]
    return ['TRAVEL', plus_year(ft).isoformat()]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['travel commenced mid-year', {'issue': '2027-03-10', 'first_travel': '2027-06-02'}, ['TRAVEL', '2028-06-02']], ['unused ticket', {'issue': '2027-01-15', 'first_travel': None}, ['UNUSED', '2028-01-15']], ['leap day issue', {'issue': '2028-02-29', 'first_travel': None}, ['UNUSED', '2029-02-28']], ['leap day first travel', {'issue': '2028-01-11', 'first_travel': '2028-02-29'}, ['TRAVEL', '2029-02-28']], ['travel exactly one year after issue', {'issue': '2027-05-11', 'first_travel': '2028-05-11'}, ['TRAVEL', '2029-05-11']], ['travel one day too late', {'issue': '2027-05-10', 'first_travel': '2028-05-11'}, ['EXPIRED_UNUSED', '2028-05-10']], ['span includes Feb 29', {'issue': '2027-06-01', 'first_travel': '2027-06-01'}, ['TRAVEL', '2028-06-01']], ['late leap-year start', {'issue': '2028-05-01', 'first_travel': '2028-06-11'}, ['TRAVEL', '2029-06-11']], ['sampled case 1', {'issue': '2028-11-11', 'first_travel': '2029-05-16'}, ['TRAVEL', '2030-05-16']], ['sampled case 2', {'issue': '2027-07-24', 'first_travel': '2027-07-26'}, ['TRAVEL', '2028-07-26']], ['sampled case 3', {'issue': '2029-01-16', 'first_travel': None}, ['UNUSED', '2030-01-16']]], [['travel commenced mid-year', {'issue': '2027-03-10', 'first_travel': '2027-06-03'}, ['TRAVEL', '2028-06-03']], ['unused ticket', {'issue': '2027-02-15', 'first_travel': None}, ['UNUSED', '2028-02-15']], ['leap day issue', {'issue': '2028-02-29', 'first_travel': None}, ['UNUSED', '2029-02-28']], ['leap day first travel', {'issue': '2028-01-12', 'first_travel': '2028-02-29'}, ['TRAVEL', '2029-02-28']], ['travel exactly one year after issue', {'issue': '2027-05-12', 'first_travel': '2028-05-12'}, ['TRAVEL', '2029-05-12']], ['travel one day too late', {'issue': '2027-05-10', 'first_travel': '2028-05-11'}, ['EXPIRED_UNUSED', '2028-05-10']], ['span includes Feb 29', {'issue': '2027-06-01', 'first_travel': '2027-06-02'}, ['TRAVEL', '2028-06-02']], ['late leap-year start', {'issue': '2028-05-01', 'first_travel': '2028-06-12'}, ['TRAVEL', '2029-06-12']], ['sampled case 1', {'issue': '2027-08-03', 'first_travel': '2028-08-03'}, ['TRAVEL', '2029-08-03']], ['sampled case 2', {'issue': '2028-03-31', 'first_travel': None}, ['UNUSED', '2029-03-31']], ['sampled case 3', {'issue': '2028-06-12', 'first_travel': '2029-06-12'}, ['TRAVEL', '2030-06-12']]], [['travel commenced mid-year', {'issue': '2027-03-10', 'first_travel': '2027-06-04'}, ['TRAVEL', '2028-06-04']], ['unused ticket', {'issue': '2027-03-15', 'first_travel': None}, ['UNUSED', '2028-03-15']], ['leap day issue', {'issue': '2028-02-29', 'first_travel': None}, ['UNUSED', '2029-02-28']], ['leap day first travel', {'issue': '2028-01-13', 'first_travel': '2028-02-29'}, ['TRAVEL', '2029-02-28']], ['travel exactly one year after issue', {'issue': '2027-05-13', 'first_travel': '2028-05-13'}, ['TRAVEL', '2029-05-13']], ['travel one day too late', {'issue': '2027-05-10', 'first_travel': '2028-05-11'}, ['EXPIRED_UNUSED', '2028-05-10']], ['span includes Feb 29', {'issue': '2027-06-01', 'first_travel': '2027-06-03'}, ['TRAVEL', '2028-06-03']], ['late leap-year start', {'issue': '2028-05-01', 'first_travel': '2028-06-13'}, ['TRAVEL', '2029-06-13']], ['sampled case 1', {'issue': '2028-10-17', 'first_travel': None}, ['UNUSED', '2029-10-17']], ['sampled case 2', {'issue': '2027-02-28', 'first_travel': '2028-02-28'}, ['TRAVEL', '2029-02-28']], ['sampled case 3', {'issue': '2029-06-17', 'first_travel': '2030-04-20'}, ['TRAVEL', '2031-04-20']]], [['travel commenced mid-year', {'issue': '2027-03-10', 'first_travel': '2027-06-05'}, ['TRAVEL', '2028-06-05']], ['unused ticket', {'issue': '2027-04-15', 'first_travel': None}, ['UNUSED', '2028-04-15']], ['leap day issue', {'issue': '2028-02-29', 'first_travel': None}, ['UNUSED', '2029-02-28']], ['leap day first travel', {'issue': '2028-01-14', 'first_travel': '2028-02-29'}, ['TRAVEL', '2029-02-28']], ['travel exactly one year after issue', {'issue': '2027-05-14', 'first_travel': '2028-05-14'}, ['TRAVEL', '2029-05-14']], ['travel one day too late', {'issue': '2027-05-10', 'first_travel': '2028-05-11'}, ['EXPIRED_UNUSED', '2028-05-10']], ['span includes Feb 29', {'issue': '2027-06-01', 'first_travel': '2027-06-04'}, ['TRAVEL', '2028-06-04']], ['late leap-year start', {'issue': '2028-05-01', 'first_travel': '2028-06-14'}, ['TRAVEL', '2029-06-14']], ['sampled case 1', {'issue': '2028-11-25', 'first_travel': '2029-11-26'}, ['EXPIRED_UNUSED', '2029-11-25']], ['sampled case 2', {'issue': '2029-06-03', 'first_travel': '2030-06-04'}, ['EXPIRED_UNUSED', '2030-06-03']], ['sampled case 3', {'issue': '2028-06-18', 'first_travel': None}, ['UNUSED', '2029-06-18']]], [['travel commenced mid-year', {'issue': '2027-03-10', 'first_travel': '2027-06-06'}, ['TRAVEL', '2028-06-06']], ['unused ticket', {'issue': '2027-05-15', 'first_travel': None}, ['UNUSED', '2028-05-15']], ['leap day issue', {'issue': '2028-02-29', 'first_travel': None}, ['UNUSED', '2029-02-28']], ['leap day first travel', {'issue': '2028-01-15', 'first_travel': '2028-02-29'}, ['TRAVEL', '2029-02-28']], ['travel exactly one year after issue', {'issue': '2027-05-15', 'first_travel': '2028-05-15'}, ['TRAVEL', '2029-05-15']], ['travel one day too late', {'issue': '2027-05-10', 'first_travel': '2028-05-11'}, ['EXPIRED_UNUSED', '2028-05-10']], ['span includes Feb 29', {'issue': '2027-06-01', 'first_travel': '2027-06-05'}, ['TRAVEL', '2028-06-05']], ['late leap-year start', {'issue': '2028-05-01', 'first_travel': '2028-06-15'}, ['TRAVEL', '2029-06-15']], ['sampled case 1', {'issue': '2028-07-20', 'first_travel': '2029-07-20'}, ['TRAVEL', '2030-07-20']], ['sampled case 2', {'issue': '2027-10-29', 'first_travel': '2027-12-02'}, ['TRAVEL', '2028-12-02']], ['sampled case 3', {'issue': '2029-03-08', 'first_travel': '2029-05-13'}, ['TRAVEL', '2030-05-13']]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
import calendar
N = 1
observations = []
def solve(x):
    iss = datetime.date.fromisoformat(x['issue'])
    def plus_year(d):
        try:
            return d.replace(year=d.year + 1)
        except ValueError:
            return datetime.date(d.year + 4, 2, 29)
    if x['first_travel'] is None:
        return ['UNUSED', plus_year(iss).isoformat()]
    ft = datetime.date.fromisoformat(x['first_travel'])
    if ft > plus_year(iss): return ['EXPIRED_UNUSED', plus_year(iss).isoformat()]
    return ['TRAVEL', plus_year(ft).isoformat()]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['travel commenced mid-year', {'issue': '2027-03-10', 'first_travel': '2027-06-02'}, ['TRAVEL', '2028-06-02']], ['unused ticket', {'issue': '2027-01-15', 'first_travel': None}, ['UNUSED', '2028-01-15']], ['leap day issue', {'issue': '2028-02-29', 'first_travel': None}, ['UNUSED', '2029-02-28']], ['leap day first travel', {'issue': '2028-01-11', 'first_travel': '2028-02-29'}, ['TRAVEL', '2029-02-28']], ['travel exactly one year after issue', {'issue': '2027-05-11', 'first_travel': '2028-05-11'}, ['TRAVEL', '2029-05-11']], ['travel one day too late', {'issue': '2027-05-10', 'first_travel': '2028-05-11'}, ['EXPIRED_UNUSED', '2028-05-10']], ['span includes Feb 29', {'issue': '2027-06-01', 'first_travel': '2027-06-01'}, ['TRAVEL', '2028-06-01']], ['late leap-year start', {'issue': '2028-05-01', 'first_travel': '2028-06-11'}, ['TRAVEL', '2029-06-11']], ['sampled case 1', {'issue': '2028-11-11', 'first_travel': '2029-05-16'}, ['TRAVEL', '2030-05-16']], ['sampled case 2', {'issue': '2027-07-24', 'first_travel': '2027-07-26'}, ['TRAVEL', '2028-07-26']], ['sampled case 3', {'issue': '2029-01-16', 'first_travel': None}, ['UNUSED', '2030-01-16']]], [['travel commenced mid-year', {'issue': '2027-03-10', 'first_travel': '2027-06-03'}, ['TRAVEL', '2028-06-03']], ['unused ticket', {'issue': '2027-02-15', 'first_travel': None}, ['UNUSED', '2028-02-15']], ['leap day issue', {'issue': '2028-02-29', 'first_travel': None}, ['UNUSED', '2029-02-28']], ['leap day first travel', {'issue': '2028-01-12', 'first_travel': '2028-02-29'}, ['TRAVEL', '2029-02-28']], ['travel exactly one year after issue', {'issue': '2027-05-12', 'first_travel': '2028-05-12'}, ['TRAVEL', '2029-05-12']], ['travel one day too late', {'issue': '2027-05-10', 'first_travel': '2028-05-11'}, ['EXPIRED_UNUSED', '2028-05-10']], ['span includes Feb 29', {'issue': '2027-06-01', 'first_travel': '2027-06-02'}, ['TRAVEL', '2028-06-02']], ['late leap-year start', {'issue': '2028-05-01', 'first_travel': '2028-06-12'}, ['TRAVEL', '2029-06-12']], ['sampled case 1', {'issue': '2027-08-03', 'first_travel': '2028-08-03'}, ['TRAVEL', '2029-08-03']], ['sampled case 2', {'issue': '2028-03-31', 'first_travel': None}, ['UNUSED', '2029-03-31']], ['sampled case 3', {'issue': '2028-06-12', 'first_travel': '2029-06-12'}, ['TRAVEL', '2030-06-12']]], [['travel commenced mid-year', {'issue': '2027-03-10', 'first_travel': '2027-06-04'}, ['TRAVEL', '2028-06-04']], ['unused ticket', {'issue': '2027-03-15', 'first_travel': None}, ['UNUSED', '2028-03-15']], ['leap day issue', {'issue': '2028-02-29', 'first_travel': None}, ['UNUSED', '2029-02-28']], ['leap day first travel', {'issue': '2028-01-13', 'first_travel': '2028-02-29'}, ['TRAVEL', '2029-02-28']], ['travel exactly one year after issue', {'issue': '2027-05-13', 'first_travel': '2028-05-13'}, ['TRAVEL', '2029-05-13']], ['travel one day too late', {'issue': '2027-05-10', 'first_travel': '2028-05-11'}, ['EXPIRED_UNUSED', '2028-05-10']], ['span includes Feb 29', {'issue': '2027-06-01', 'first_travel': '2027-06-03'}, ['TRAVEL', '2028-06-03']], ['late leap-year start', {'issue': '2028-05-01', 'first_travel': '2028-06-13'}, ['TRAVEL', '2029-06-13']], ['sampled case 1', {'issue': '2028-10-17', 'first_travel': None}, ['UNUSED', '2029-10-17']], ['sampled case 2', {'issue': '2027-02-28', 'first_travel': '2028-02-28'}, ['TRAVEL', '2029-02-28']], ['sampled case 3', {'issue': '2029-06-17', 'first_travel': '2030-04-20'}, ['TRAVEL', '2031-04-20']]], [['travel commenced mid-year', {'issue': '2027-03-10', 'first_travel': '2027-06-05'}, ['TRAVEL', '2028-06-05']], ['unused ticket', {'issue': '2027-04-15', 'first_travel': None}, ['UNUSED', '2028-04-15']], ['leap day issue', {'issue': '2028-02-29', 'first_travel': None}, ['UNUSED', '2029-02-28']], ['leap day first travel', {'issue': '2028-01-14', 'first_travel': '2028-02-29'}, ['TRAVEL', '2029-02-28']], ['travel exactly one year after issue', {'issue': '2027-05-14', 'first_travel': '2028-05-14'}, ['TRAVEL', '2029-05-14']], ['travel one day too late', {'issue': '2027-05-10', 'first_travel': '2028-05-11'}, ['EXPIRED_UNUSED', '2028-05-10']], ['span includes Feb 29', {'issue': '2027-06-01', 'first_travel': '2027-06-04'}, ['TRAVEL', '2028-06-04']], ['late leap-year start', {'issue': '2028-05-01', 'first_travel': '2028-06-14'}, ['TRAVEL', '2029-06-14']], ['sampled case 1', {'issue': '2028-11-25', 'first_travel': '2029-11-26'}, ['EXPIRED_UNUSED', '2029-11-25']], ['sampled case 2', {'issue': '2029-06-03', 'first_travel': '2030-06-04'}, ['EXPIRED_UNUSED', '2030-06-03']], ['sampled case 3', {'issue': '2028-06-18', 'first_travel': None}, ['UNUSED', '2029-06-18']]], [['travel commenced mid-year', {'issue': '2027-03-10', 'first_travel': '2027-06-06'}, ['TRAVEL', '2028-06-06']], ['unused ticket', {'issue': '2027-05-15', 'first_travel': None}, ['UNUSED', '2028-05-15']], ['leap day issue', {'issue': '2028-02-29', 'first_travel': None}, ['UNUSED', '2029-02-28']], ['leap day first travel', {'issue': '2028-01-15', 'first_travel': '2028-02-29'}, ['TRAVEL', '2029-02-28']], ['travel exactly one year after issue', {'issue': '2027-05-15', 'first_travel': '2028-05-15'}, ['TRAVEL', '2029-05-15']], ['travel one day too late', {'issue': '2027-05-10', 'first_travel': '2028-05-11'}, ['EXPIRED_UNUSED', '2028-05-10']], ['span includes Feb 29', {'issue': '2027-06-01', 'first_travel': '2027-06-05'}, ['TRAVEL', '2028-06-05']], ['late leap-year start', {'issue': '2028-05-01', 'first_travel': '2028-06-15'}, ['TRAVEL', '2029-06-15']], ['sampled case 1', {'issue': '2028-07-20', 'first_travel': '2029-07-20'}, ['TRAVEL', '2030-07-20']], ['sampled case 2', {'issue': '2027-10-29', 'first_travel': '2027-12-02'}, ['TRAVEL', '2028-12-02']], ['sampled case 3', {'issue': '2029-03-08', 'first_travel': '2029-05-13'}, ['TRAVEL', '2030-05-13']]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A ticket issued on 29 February remains valid on 1 March of the next year.

Input {'issue','first_travel' (ISO or None)}. One calendar year = same month/day next year (29 Feb -> 28 Feb). Unused -> ['UNUSED', issue+1y]. First travel later than issue+1y -> ['EXPIRED_UNUSED', issue+1y] (travel on that date is still valid). Otherwise ['TRAVEL', first travel+1y].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
import calendar
N = 1
observations = []
def solve(x):
    iss = datetime.date.fromisoformat(x['issue'])
    def plus_year(d):
        try:
            return d.replace(year=d.year + 1)
        except ValueError:
            return datetime.date(d.year + 1, 2, 28)
    if x['first_travel'] is None:
        return ['UNUSED', plus_year(iss).isoformat()]
    ft = datetime.date.fromisoformat(x['first_travel'])
    if ft >= plus_year(iss): return ['EXPIRED_UNUSED', plus_year(iss).isoformat()]
    return ['TRAVEL', plus_year(ft).isoformat()]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['travel commenced mid-year', {'issue': '2027-03-10', 'first_travel': '2027-06-02'}, ['TRAVEL', '2028-06-02']], ['unused ticket', {'issue': '2027-01-15', 'first_travel': None}, ['UNUSED', '2028-01-15']], ['leap day issue', {'issue': '2028-02-29', 'first_travel': None}, ['UNUSED', '2029-02-28']], ['leap day first travel', {'issue': '2028-01-11', 'first_travel': '2028-02-29'}, ['TRAVEL', '2029-02-28']], ['travel exactly one year after issue', {'issue': '2027-05-11', 'first_travel': '2028-05-11'}, ['TRAVEL', '2029-05-11']], ['travel one day too late', {'issue': '2027-05-10', 'first_travel': '2028-05-11'}, ['EXPIRED_UNUSED', '2028-05-10']], ['span includes Feb 29', {'issue': '2027-06-01', 'first_travel': '2027-06-01'}, ['TRAVEL', '2028-06-01']], ['late leap-year start', {'issue': '2028-05-01', 'first_travel': '2028-06-11'}, ['TRAVEL', '2029-06-11']], ['sampled case 1', {'issue': '2028-11-11', 'first_travel': '2029-05-16'}, ['TRAVEL', '2030-05-16']], ['sampled case 2', {'issue': '2027-07-24', 'first_travel': '2027-07-26'}, ['TRAVEL', '2028-07-26']], ['sampled case 3', {'issue': '2029-01-16', 'first_travel': None}, ['UNUSED', '2030-01-16']]], [['travel commenced mid-year', {'issue': '2027-03-10', 'first_travel': '2027-06-03'}, ['TRAVEL', '2028-06-03']], ['unused ticket', {'issue': '2027-02-15', 'first_travel': None}, ['UNUSED', '2028-02-15']], ['leap day issue', {'issue': '2028-02-29', 'first_travel': None}, ['UNUSED', '2029-02-28']], ['leap day first travel', {'issue': '2028-01-12', 'first_travel': '2028-02-29'}, ['TRAVEL', '2029-02-28']], ['travel exactly one year after issue', {'issue': '2027-05-12', 'first_travel': '2028-05-12'}, ['TRAVEL', '2029-05-12']], ['travel one day too late', {'issue': '2027-05-10', 'first_travel': '2028-05-11'}, ['EXPIRED_UNUSED', '2028-05-10']], ['span includes Feb 29', {'issue': '2027-06-01', 'first_travel': '2027-06-02'}, ['TRAVEL', '2028-06-02']], ['late leap-year start', {'issue': '2028-05-01', 'first_travel': '2028-06-12'}, ['TRAVEL', '2029-06-12']], ['sampled case 1', {'issue': '2027-08-03', 'first_travel': '2028-08-03'}, ['TRAVEL', '2029-08-03']], ['sampled case 2', {'issue': '2028-03-31', 'first_travel': None}, ['UNUSED', '2029-03-31']], ['sampled case 3', {'issue': '2028-06-12', 'first_travel': '2029-06-12'}, ['TRAVEL', '2030-06-12']]], [['travel commenced mid-year', {'issue': '2027-03-10', 'first_travel': '2027-06-04'}, ['TRAVEL', '2028-06-04']], ['unused ticket', {'issue': '2027-03-15', 'first_travel': None}, ['UNUSED', '2028-03-15']], ['leap day issue', {'issue': '2028-02-29', 'first_travel': None}, ['UNUSED', '2029-02-28']], ['leap day first travel', {'issue': '2028-01-13', 'first_travel': '2028-02-29'}, ['TRAVEL', '2029-02-28']], ['travel exactly one year after issue', {'issue': '2027-05-13', 'first_travel': '2028-05-13'}, ['TRAVEL', '2029-05-13']], ['travel one day too late', {'issue': '2027-05-10', 'first_travel': '2028-05-11'}, ['EXPIRED_UNUSED', '2028-05-10']], ['span includes Feb 29', {'issue': '2027-06-01', 'first_travel': '2027-06-03'}, ['TRAVEL', '2028-06-03']], ['late leap-year start', {'issue': '2028-05-01', 'first_travel': '2028-06-13'}, ['TRAVEL', '2029-06-13']], ['sampled case 1', {'issue': '2028-10-17', 'first_travel': None}, ['UNUSED', '2029-10-17']], ['sampled case 2', {'issue': '2027-02-28', 'first_travel': '2028-02-28'}, ['TRAVEL', '2029-02-28']], ['sampled case 3', {'issue': '2029-06-17', 'first_travel': '2030-04-20'}, ['TRAVEL', '2031-04-20']]], [['travel commenced mid-year', {'issue': '2027-03-10', 'first_travel': '2027-06-05'}, ['TRAVEL', '2028-06-05']], ['unused ticket', {'issue': '2027-04-15', 'first_travel': None}, ['UNUSED', '2028-04-15']], ['leap day issue', {'issue': '2028-02-29', 'first_travel': None}, ['UNUSED', '2029-02-28']], ['leap day first travel', {'issue': '2028-01-14', 'first_travel': '2028-02-29'}, ['TRAVEL', '2029-02-28']], ['travel exactly one year after issue', {'issue': '2027-05-14', 'first_travel': '2028-05-14'}, ['TRAVEL', '2029-05-14']], ['travel one day too late', {'issue': '2027-05-10', 'first_travel': '2028-05-11'}, ['EXPIRED_UNUSED', '2028-05-10']], ['span includes Feb 29', {'issue': '2027-06-01', 'first_travel': '2027-06-04'}, ['TRAVEL', '2028-06-04']], ['late leap-year start', {'issue': '2028-05-01', 'first_travel': '2028-06-14'}, ['TRAVEL', '2029-06-14']], ['sampled case 1', {'issue': '2028-11-25', 'first_travel': '2029-11-26'}, ['EXPIRED_UNUSED', '2029-11-25']], ['sampled case 2', {'issue': '2029-06-03', 'first_travel': '2030-06-04'}, ['EXPIRED_UNUSED', '2030-06-03']], ['sampled case 3', {'issue': '2028-06-18', 'first_travel': None}, ['UNUSED', '2029-06-18']]], [['travel commenced mid-year', {'issue': '2027-03-10', 'first_travel': '2027-06-06'}, ['TRAVEL', '2028-06-06']], ['unused ticket', {'issue': '2027-05-15', 'first_travel': None}, ['UNUSED', '2028-05-15']], ['leap day issue', {'issue': '2028-02-29', 'first_travel': None}, ['UNUSED', '2029-02-28']], ['leap day first travel', {'issue': '2028-01-15', 'first_travel': '2028-02-29'}, ['TRAVEL', '2029-02-28']], ['travel exactly one year after issue', {'issue': '2027-05-15', 'first_travel': '2028-05-15'}, ['TRAVEL', '2029-05-15']], ['travel one day too late', {'issue': '2027-05-10', 'first_travel': '2028-05-11'}, ['EXPIRED_UNUSED', '2028-05-10']], ['span includes Feb 29', {'issue': '2027-06-01', 'first_travel': '2027-06-05'}, ['TRAVEL', '2028-06-05']], ['late leap-year start', {'issue': '2028-05-01', 'first_travel': '2028-06-15'}, ['TRAVEL', '2029-06-15']], ['sampled case 1', {'issue': '2028-07-20', 'first_travel': '2029-07-20'}, ['TRAVEL', '2030-07-20']], ['sampled case 2', {'issue': '2027-10-29', 'first_travel': '2027-12-02'}, ['TRAVEL', '2028-12-02']], ['sampled case 3', {'issue': '2029-03-08', 'first_travel': '2029-05-13'}, ['TRAVEL', '2030-05-13']]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
import calendar
N = 1
observations = []
def solve(x):
    iss = datetime.date.fromisoformat(x['issue'])
    def plus_year(d):
        try:
            return d.replace(year=d.year + 1)
        except ValueError:
            return datetime.date(d.year + 1, 2, 28)
    if x['first_travel'] is None:
        return ['UNUSED', plus_year(iss).isoformat()]
    ft = datetime.date.fromisoformat(x['first_travel'])
    if (ft - iss).days > 365: return ['EXPIRED_UNUSED', plus_year(iss).isoformat()]
    return ['TRAVEL', plus_year(ft).isoformat()]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['travel commenced mid-year', {'issue': '2027-03-10', 'first_travel': '2027-06-02'}, ['TRAVEL', '2028-06-02']], ['unused ticket', {'issue': '2027-01-15', 'first_travel': None}, ['UNUSED', '2028-01-15']], ['leap day issue', {'issue': '2028-02-29', 'first_travel': None}, ['UNUSED', '2029-02-28']], ['leap day first travel', {'issue': '2028-01-11', 'first_travel': '2028-02-29'}, ['TRAVEL', '2029-02-28']], ['travel exactly one year after issue', {'issue': '2027-05-11', 'first_travel': '2028-05-11'}, ['TRAVEL', '2029-05-11']], ['travel one day too late', {'issue': '2027-05-10', 'first_travel': '2028-05-11'}, ['EXPIRED_UNUSED', '2028-05-10']], ['span includes Feb 29', {'issue': '2027-06-01', 'first_travel': '2027-06-01'}, ['TRAVEL', '2028-06-01']], ['late leap-year start', {'issue': '2028-05-01', 'first_travel': '2028-06-11'}, ['TRAVEL', '2029-06-11']], ['sampled case 1', {'issue': '2028-11-11', 'first_travel': '2029-05-16'}, ['TRAVEL', '2030-05-16']], ['sampled case 2', {'issue': '2027-07-24', 'first_travel': '2027-07-26'}, ['TRAVEL', '2028-07-26']], ['sampled case 3', {'issue': '2029-01-16', 'first_travel': None}, ['UNUSED', '2030-01-16']]], [['travel commenced mid-year', {'issue': '2027-03-10', 'first_travel': '2027-06-03'}, ['TRAVEL', '2028-06-03']], ['unused ticket', {'issue': '2027-02-15', 'first_travel': None}, ['UNUSED', '2028-02-15']], ['leap day issue', {'issue': '2028-02-29', 'first_travel': None}, ['UNUSED', '2029-02-28']], ['leap day first travel', {'issue': '2028-01-12', 'first_travel': '2028-02-29'}, ['TRAVEL', '2029-02-28']], ['travel exactly one year after issue', {'issue': '2027-05-12', 'first_travel': '2028-05-12'}, ['TRAVEL', '2029-05-12']], ['travel one day too late', {'issue': '2027-05-10', 'first_travel': '2028-05-11'}, ['EXPIRED_UNUSED', '2028-05-10']], ['span includes Feb 29', {'issue': '2027-06-01', 'first_travel': '2027-06-02'}, ['TRAVEL', '2028-06-02']], ['late leap-year start', {'issue': '2028-05-01', 'first_travel': '2028-06-12'}, ['TRAVEL', '2029-06-12']], ['sampled case 1', {'issue': '2027-08-03', 'first_travel': '2028-08-03'}, ['TRAVEL', '2029-08-03']], ['sampled case 2', {'issue': '2028-03-31', 'first_travel': None}, ['UNUSED', '2029-03-31']], ['sampled case 3', {'issue': '2028-06-12', 'first_travel': '2029-06-12'}, ['TRAVEL', '2030-06-12']]], [['travel commenced mid-year', {'issue': '2027-03-10', 'first_travel': '2027-06-04'}, ['TRAVEL', '2028-06-04']], ['unused ticket', {'issue': '2027-03-15', 'first_travel': None}, ['UNUSED', '2028-03-15']], ['leap day issue', {'issue': '2028-02-29', 'first_travel': None}, ['UNUSED', '2029-02-28']], ['leap day first travel', {'issue': '2028-01-13', 'first_travel': '2028-02-29'}, ['TRAVEL', '2029-02-28']], ['travel exactly one year after issue', {'issue': '2027-05-13', 'first_travel': '2028-05-13'}, ['TRAVEL', '2029-05-13']], ['travel one day too late', {'issue': '2027-05-10', 'first_travel': '2028-05-11'}, ['EXPIRED_UNUSED', '2028-05-10']], ['span includes Feb 29', {'issue': '2027-06-01', 'first_travel': '2027-06-03'}, ['TRAVEL', '2028-06-03']], ['late leap-year start', {'issue': '2028-05-01', 'first_travel': '2028-06-13'}, ['TRAVEL', '2029-06-13']], ['sampled case 1', {'issue': '2028-10-17', 'first_travel': None}, ['UNUSED', '2029-10-17']], ['sampled case 2', {'issue': '2027-02-28', 'first_travel': '2028-02-28'}, ['TRAVEL', '2029-02-28']], ['sampled case 3', {'issue': '2029-06-17', 'first_travel': '2030-04-20'}, ['TRAVEL', '2031-04-20']]], [['travel commenced mid-year', {'issue': '2027-03-10', 'first_travel': '2027-06-05'}, ['TRAVEL', '2028-06-05']], ['unused ticket', {'issue': '2027-04-15', 'first_travel': None}, ['UNUSED', '2028-04-15']], ['leap day issue', {'issue': '2028-02-29', 'first_travel': None}, ['UNUSED', '2029-02-28']], ['leap day first travel', {'issue': '2028-01-14', 'first_travel': '2028-02-29'}, ['TRAVEL', '2029-02-28']], ['travel exactly one year after issue', {'issue': '2027-05-14', 'first_travel': '2028-05-14'}, ['TRAVEL', '2029-05-14']], ['travel one day too late', {'issue': '2027-05-10', 'first_travel': '2028-05-11'}, ['EXPIRED_UNUSED', '2028-05-10']], ['span includes Feb 29', {'issue': '2027-06-01', 'first_travel': '2027-06-04'}, ['TRAVEL', '2028-06-04']], ['late leap-year start', {'issue': '2028-05-01', 'first_travel': '2028-06-14'}, ['TRAVEL', '2029-06-14']], ['sampled case 1', {'issue': '2028-11-25', 'first_travel': '2029-11-26'}, ['EXPIRED_UNUSED', '2029-11-25']], ['sampled case 2', {'issue': '2029-06-03', 'first_travel': '2030-06-04'}, ['EXPIRED_UNUSED', '2030-06-03']], ['sampled case 3', {'issue': '2028-06-18', 'first_travel': None}, ['UNUSED', '2029-06-18']]], [['travel commenced mid-year', {'issue': '2027-03-10', 'first_travel': '2027-06-06'}, ['TRAVEL', '2028-06-06']], ['unused ticket', {'issue': '2027-05-15', 'first_travel': None}, ['UNUSED', '2028-05-15']], ['leap day issue', {'issue': '2028-02-29', 'first_travel': None}, ['UNUSED', '2029-02-28']], ['leap day first travel', {'issue': '2028-01-15', 'first_travel': '2028-02-29'}, ['TRAVEL', '2029-02-28']], ['travel exactly one year after issue', {'issue': '2027-05-15', 'first_travel': '2028-05-15'}, ['TRAVEL', '2029-05-15']], ['travel one day too late', {'issue': '2027-05-10', 'first_travel': '2028-05-11'}, ['EXPIRED_UNUSED', '2028-05-10']], ['span includes Feb 29', {'issue': '2027-06-01', 'first_travel': '2027-06-05'}, ['TRAVEL', '2028-06-05']], ['late leap-year start', {'issue': '2028-05-01', 'first_travel': '2028-06-15'}, ['TRAVEL', '2029-06-15']], ['sampled case 1', {'issue': '2028-07-20', 'first_travel': '2029-07-20'}, ['TRAVEL', '2030-07-20']], ['sampled case 2', {'issue': '2027-10-29', 'first_travel': '2027-12-02'}, ['TRAVEL', '2028-12-02']], ['sampled case 3', {'issue': '2029-03-08', 'first_travel': '2029-05-13'}, ['TRAVEL', '2030-05-13']]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Starting travel exactly one year after issue is refused.

Input {'issue','first_travel' (ISO or None)}. One calendar year = same month/day next year (29 Feb -> 28 Feb). Unused -> ['UNUSED', issue+1y]. First travel later than issue+1y -> ['EXPIRED_UNUSED', issue+1y] (travel on that date is still valid). Otherwise ['TRAVEL', first travel+1y].

split: open-access


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

N = 1
observations = []
def solve(x):
    paid = x['paid']
    fare_part = paid - x['cancel_fee']
    if x['status'] == 'PARTIAL':
        fare_part -= x['used_fare']
    taxes = sum(a for code, a, refundable, used in x['taxes'] if refundable and not used)
    return round(max(0.0, fare_part + taxes), 2)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['unused refundable', {'paid': 481.0, 'cancel_fee': 100.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 37.2, True, False], ['YQ', 80.0, False, False]]}, 418.2], ['partial with used taxes', {'paid': 900.0, 'cancel_fee': 150.0, 'used_fare': 421.0, 'status': 'PARTIAL', 'taxes': [['US', 37.2, True, False], ['XF', 4.5, True, True], ['YQ', 80.0, False, False], ['AY', 5.6, True, True]]}, 366.2], ['fee larger than fare', {'paid': 90.0, 'cancel_fee': 150.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 38.2, True, False]]}, 38.2], ['used portion exceeds paid', {'paid': 300.0, 'cancel_fee': 50.0, 'used_fare': 310.0, 'status': 'PARTIAL', 'taxes': [['US', 18.6, True, False], ['XF', 4.5, True, True]]}, 18.6], ['unused with stale used estimate', {'paid': 650.0, 'cancel_fee': 0.0, 'used_fare': 201.0, 'status': 'UNUSED', 'taxes': [['US', 20.0, True, False]]}, 670.0], ['non-refundable carrier charges', {'paid': 700.0, 'cancel_fee': 75.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['YQ', 120.0, False, False], ['GB', 27.0, True, False]]}, 652.0], ['sampled case 1', {'paid': 386.27, 'cancel_fee': 250.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 51.02, True, False], ['YQ', 5.59, False, False], ['XF', 3.57, True, False], ['DE', 99.09, True, False]]}, 289.95], ['sampled case 2', {'paid': 1007.21, 'cancel_fee': 50.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['XF', 29.38, True, False]]}, 986.59], ['sampled case 3', {'paid': 176.19, 'cancel_fee': 0.0, 'used_fare': 203.14, 'status': 'PARTIAL', 'taxes': [['DE', 94.53, True, True], ['GB', 107.54, False, True], ['XF', 23.26, True, True]]}, 0.0]], [['unused refundable', {'paid': 482.0, 'cancel_fee': 100.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 37.2, True, False], ['YQ', 80.0, False, False]]}, 419.2], ['partial with used taxes', {'paid': 900.0, 'cancel_fee': 150.0, 'used_fare': 422.0, 'status': 'PARTIAL', 'taxes': [['US', 37.2, True, False], ['XF', 4.5, True, True], ['YQ', 80.0, False, False], ['AY', 5.6, True, True]]}, 365.2], ['fee larger than fare', {'paid': 90.0, 'cancel_fee': 150.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 39.2, True, False]]}, 39.2], ['used portion exceeds paid', {'paid': 300.0, 'cancel_fee': 50.0, 'used_fare': 310.0, 'status': 'PARTIAL', 'taxes': [['US', 18.6, True, False], ['XF', 4.5, True, True]]}, 18.6], ['unused with stale used estimate', {'paid': 650.0, 'cancel_fee': 0.0, 'used_fare': 202.0, 'status': 'UNUSED', 'taxes': [['US', 20.0, True, False]]}, 670.0], ['non-refundable carrier charges', {'paid': 700.0, 'cancel_fee': 75.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['YQ', 120.0, False, False], ['GB', 28.0, True, False]]}, 653.0], ['sampled case 1', {'paid': 1076.29, 'cancel_fee': 50.0, 'used_fare': 538.9, 'status': 'PARTIAL', 'taxes': [['YQ', 84.65, True, False], ['XF', 108.03, True, False]]}, 680.07], ['sampled case 2', {'paid': 193.38, 'cancel_fee': 250.0, 'used_fare': 218.71, 'status': 'PARTIAL', 'taxes': [['YQ', 67.48, True, False], ['GB', 86.2, True, False], ['AY', 96.45, True, False]]}, 250.13], ['sampled case 3', {'paid': 640.4, 'cancel_fee': 150.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['AY', 115.97, True, False], ['DE', 57.82, False, False]]}, 606.37]], [['unused refundable', {'paid': 483.0, 'cancel_fee': 100.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 37.2, True, False], ['YQ', 80.0, False, False]]}, 420.2], ['partial with used taxes', {'paid': 900.0, 'cancel_fee': 150.0, 'used_fare': 423.0, 'status': 'PARTIAL', 'taxes': [['US', 37.2, True, False], ['XF', 4.5, True, True], ['YQ', 80.0, False, False], ['AY', 5.6, True, True]]}, 364.2], ['fee larger than fare', {'paid': 90.0, 'cancel_fee': 150.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 40.2, True, False]]}, 40.2], ['used portion exceeds paid', {'paid': 300.0, 'cancel_fee': 50.0, 'used_fare': 310.0, 'status': 'PARTIAL', 'taxes': [['US', 18.6, True, False], ['XF', 4.5, True, True]]}, 18.6], ['unused with stale used estimate', {'paid': 650.0, 'cancel_fee': 0.0, 'used_fare': 203.0, 'status': 'UNUSED', 'taxes': [['US', 20.0, True, False]]}, 670.0], ['non-refundable carrier charges', {'paid': 700.0, 'cancel_fee': 75.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['YQ', 120.0, False, False], ['GB', 29.0, True, False]]}, 654.0], ['sampled case 1', {'paid': 502.45, 'cancel_fee': 100.0, 'used_fare': 464.12, 'status': 'PARTIAL', 'taxes': [['US', 99.3, False, True], ['AY', 85.33, True, True], ['DE', 48.94, True, False]]}, 48.94], ['sampled case 2', {'paid': 638.36, 'cancel_fee': 150.0, 'used_fare': 498.2, 'status': 'PARTIAL', 'taxes': [['GB', 89.81, True, False], ['US', 67.48, False, True]]}, 89.81], ['sampled case 3', {'paid': 311.77, 'cancel_fee': 50.0, 'used_fare': 120.66, 'status': 'PARTIAL', 'taxes': []}, 141.11]], [['unused refundable', {'paid': 484.0, 'cancel_fee': 100.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 37.2, True, False], ['YQ', 80.0, False, False]]}, 421.2], ['partial with used taxes', {'paid': 900.0, 'cancel_fee': 150.0, 'used_fare': 424.0, 'status': 'PARTIAL', 'taxes': [['US', 37.2, True, False], ['XF', 4.5, True, True], ['YQ', 80.0, False, False], ['AY', 5.6, True, True]]}, 363.2], ['fee larger than fare', {'paid': 90.0, 'cancel_fee': 150.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 41.2, True, False]]}, 41.2], ['used portion exceeds paid', {'paid': 300.0, 'cancel_fee': 50.0, 'used_fare': 310.0, 'status': 'PARTIAL', 'taxes': [['US', 18.6, True, False], ['XF', 4.5, True, True]]}, 18.6], ['unused with stale used estimate', {'paid': 650.0, 'cancel_fee': 0.0, 'used_fare': 204.0, 'status': 'UNUSED', 'taxes': [['US', 20.0, True, False]]}, 670.0], ['non-refundable carrier charges', {'paid': 700.0, 'cancel_fee': 75.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['YQ', 120.0, False, False], ['GB', 30.0, True, False]]}, 655.0], ['sampled case 1', {'paid': 716.18, 'cancel_fee': 50.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['YQ', 62.57, True, False], ['US', 60.18, True, False], ['AY', 40.23, True, False]]}, 829.16], ['sampled case 2', {'paid': 304.89, 'cancel_fee': 250.0, 'used_fare': 353.1, 'status': 'PARTIAL', 'taxes': [['DE', 109.57, False, True], ['YQ', 82.61, True, False]]}, 82.61], ['sampled case 3', {'paid': 1425.61, 'cancel_fee': 100.0, 'used_fare': 1346.54, 'status': 'PARTIAL', 'taxes': [['GB', 93.65, True, False], ['AY', 56.1, True, True], ['DE', 105.73, False, False]]}, 93.65]], [['unused refundable', {'paid': 485.0, 'cancel_fee': 100.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 37.2, True, False], ['YQ', 80.0, False, False]]}, 422.2], ['partial with used taxes', {'paid': 900.0, 'cancel_fee': 150.0, 'used_fare': 425.0, 'status': 'PARTIAL', 'taxes': [['US', 37.2, True, False], ['XF', 4.5, True, True], ['YQ', 80.0, False, False], ['AY', 5.6, True, True]]}, 362.2], ['fee larger than fare', {'paid': 90.0, 'cancel_fee': 150.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 42.2, True, False]]}, 42.2], ['used portion exceeds paid', {'paid': 300.0, 'cancel_fee': 50.0, 'used_fare': 310.0, 'status': 'PARTIAL', 'taxes': [['US', 18.6, True, False], ['XF', 4.5, True, True]]}, 18.6], ['unused with stale used estimate', {'paid': 650.0, 'cancel_fee': 0.0, 'used_fare': 205.0, 'status': 'UNUSED', 'taxes': [['US', 20.0, True, False]]}, 670.0], ['non-refundable carrier charges', {'paid': 700.0, 'cancel_fee': 75.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['YQ', 120.0, False, False], ['GB', 31.0, True, False]]}, 656.0], ['sampled case 1', {'paid': 1477.45, 'cancel_fee': 100.0, 'used_fare': 1174.26, 'status': 'PARTIAL', 'taxes': [['AY', 80.91, True, True], ['XF', 91.97, True, False]]}, 295.16], ['sampled case 2', {'paid': 441.62, 'cancel_fee': 50.0, 'used_fare': 285.82, 'status': 'PARTIAL', 'taxes': []}, 105.8], ['sampled case 3', {'paid': 1459.32, 'cancel_fee': 50.0, 'used_fare': 1488.81, 'status': 'PARTIAL', 'taxes': [['YQ', 64.57, False, True]]}, 0.0]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    paid = x['paid']
    fare_part = paid - x['cancel_fee']
    if x['status'] == 'PARTIAL':
        fare_part = max(0.0, fare_part - x['used_fare'])
    taxes = sum(a for code, a, refundable, used in x['taxes'] if refundable and not used)
    return round(fare_part + taxes, 2)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['unused refundable', {'paid': 481.0, 'cancel_fee': 100.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 37.2, True, False], ['YQ', 80.0, False, False]]}, 418.2], ['partial with used taxes', {'paid': 900.0, 'cancel_fee': 150.0, 'used_fare': 421.0, 'status': 'PARTIAL', 'taxes': [['US', 37.2, True, False], ['XF', 4.5, True, True], ['YQ', 80.0, False, False], ['AY', 5.6, True, True]]}, 366.2], ['fee larger than fare', {'paid': 90.0, 'cancel_fee': 150.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 38.2, True, False]]}, 38.2], ['used portion exceeds paid', {'paid': 300.0, 'cancel_fee': 50.0, 'used_fare': 310.0, 'status': 'PARTIAL', 'taxes': [['US', 18.6, True, False], ['XF', 4.5, True, True]]}, 18.6], ['unused with stale used estimate', {'paid': 650.0, 'cancel_fee': 0.0, 'used_fare': 201.0, 'status': 'UNUSED', 'taxes': [['US', 20.0, True, False]]}, 670.0], ['non-refundable carrier charges', {'paid': 700.0, 'cancel_fee': 75.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['YQ', 120.0, False, False], ['GB', 27.0, True, False]]}, 652.0], ['sampled case 1', {'paid': 386.27, 'cancel_fee': 250.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 51.02, True, False], ['YQ', 5.59, False, False], ['XF', 3.57, True, False], ['DE', 99.09, True, False]]}, 289.95], ['sampled case 2', {'paid': 1007.21, 'cancel_fee': 50.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['XF', 29.38, True, False]]}, 986.59], ['sampled case 3', {'paid': 176.19, 'cancel_fee': 0.0, 'used_fare': 203.14, 'status': 'PARTIAL', 'taxes': [['DE', 94.53, True, True], ['GB', 107.54, False, True], ['XF', 23.26, True, True]]}, 0.0]], [['unused refundable', {'paid': 482.0, 'cancel_fee': 100.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 37.2, True, False], ['YQ', 80.0, False, False]]}, 419.2], ['partial with used taxes', {'paid': 900.0, 'cancel_fee': 150.0, 'used_fare': 422.0, 'status': 'PARTIAL', 'taxes': [['US', 37.2, True, False], ['XF', 4.5, True, True], ['YQ', 80.0, False, False], ['AY', 5.6, True, True]]}, 365.2], ['fee larger than fare', {'paid': 90.0, 'cancel_fee': 150.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 39.2, True, False]]}, 39.2], ['used portion exceeds paid', {'paid': 300.0, 'cancel_fee': 50.0, 'used_fare': 310.0, 'status': 'PARTIAL', 'taxes': [['US', 18.6, True, False], ['XF', 4.5, True, True]]}, 18.6], ['unused with stale used estimate', {'paid': 650.0, 'cancel_fee': 0.0, 'used_fare': 202.0, 'status': 'UNUSED', 'taxes': [['US', 20.0, True, False]]}, 670.0], ['non-refundable carrier charges', {'paid': 700.0, 'cancel_fee': 75.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['YQ', 120.0, False, False], ['GB', 28.0, True, False]]}, 653.0], ['sampled case 1', {'paid': 1076.29, 'cancel_fee': 50.0, 'used_fare': 538.9, 'status': 'PARTIAL', 'taxes': [['YQ', 84.65, True, False], ['XF', 108.03, True, False]]}, 680.07], ['sampled case 2', {'paid': 193.38, 'cancel_fee': 250.0, 'used_fare': 218.71, 'status': 'PARTIAL', 'taxes': [['YQ', 67.48, True, False], ['GB', 86.2, True, False], ['AY', 96.45, True, False]]}, 250.13], ['sampled case 3', {'paid': 640.4, 'cancel_fee': 150.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['AY', 115.97, True, False], ['DE', 57.82, False, False]]}, 606.37]], [['unused refundable', {'paid': 483.0, 'cancel_fee': 100.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 37.2, True, False], ['YQ', 80.0, False, False]]}, 420.2], ['partial with used taxes', {'paid': 900.0, 'cancel_fee': 150.0, 'used_fare': 423.0, 'status': 'PARTIAL', 'taxes': [['US', 37.2, True, False], ['XF', 4.5, True, True], ['YQ', 80.0, False, False], ['AY', 5.6, True, True]]}, 364.2], ['fee larger than fare', {'paid': 90.0, 'cancel_fee': 150.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 40.2, True, False]]}, 40.2], ['used portion exceeds paid', {'paid': 300.0, 'cancel_fee': 50.0, 'used_fare': 310.0, 'status': 'PARTIAL', 'taxes': [['US', 18.6, True, False], ['XF', 4.5, True, True]]}, 18.6], ['unused with stale used estimate', {'paid': 650.0, 'cancel_fee': 0.0, 'used_fare': 203.0, 'status': 'UNUSED', 'taxes': [['US', 20.0, True, False]]}, 670.0], ['non-refundable carrier charges', {'paid': 700.0, 'cancel_fee': 75.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['YQ', 120.0, False, False], ['GB', 29.0, True, False]]}, 654.0], ['sampled case 1', {'paid': 502.45, 'cancel_fee': 100.0, 'used_fare': 464.12, 'status': 'PARTIAL', 'taxes': [['US', 99.3, False, True], ['AY', 85.33, True, True], ['DE', 48.94, True, False]]}, 48.94], ['sampled case 2', {'paid': 638.36, 'cancel_fee': 150.0, 'used_fare': 498.2, 'status': 'PARTIAL', 'taxes': [['GB', 89.81, True, False], ['US', 67.48, False, True]]}, 89.81], ['sampled case 3', {'paid': 311.77, 'cancel_fee': 50.0, 'used_fare': 120.66, 'status': 'PARTIAL', 'taxes': []}, 141.11]], [['unused refundable', {'paid': 484.0, 'cancel_fee': 100.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 37.2, True, False], ['YQ', 80.0, False, False]]}, 421.2], ['partial with used taxes', {'paid': 900.0, 'cancel_fee': 150.0, 'used_fare': 424.0, 'status': 'PARTIAL', 'taxes': [['US', 37.2, True, False], ['XF', 4.5, True, True], ['YQ', 80.0, False, False], ['AY', 5.6, True, True]]}, 363.2], ['fee larger than fare', {'paid': 90.0, 'cancel_fee': 150.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 41.2, True, False]]}, 41.2], ['used portion exceeds paid', {'paid': 300.0, 'cancel_fee': 50.0, 'used_fare': 310.0, 'status': 'PARTIAL', 'taxes': [['US', 18.6, True, False], ['XF', 4.5, True, True]]}, 18.6], ['unused with stale used estimate', {'paid': 650.0, 'cancel_fee': 0.0, 'used_fare': 204.0, 'status': 'UNUSED', 'taxes': [['US', 20.0, True, False]]}, 670.0], ['non-refundable carrier charges', {'paid': 700.0, 'cancel_fee': 75.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['YQ', 120.0, False, False], ['GB', 30.0, True, False]]}, 655.0], ['sampled case 1', {'paid': 716.18, 'cancel_fee': 50.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['YQ', 62.57, True, False], ['US', 60.18, True, False], ['AY', 40.23, True, False]]}, 829.16], ['sampled case 2', {'paid': 304.89, 'cancel_fee': 250.0, 'used_fare': 353.1, 'status': 'PARTIAL', 'taxes': [['DE', 109.57, False, True], ['YQ', 82.61, True, False]]}, 82.61], ['sampled case 3', {'paid': 1425.61, 'cancel_fee': 100.0, 'used_fare': 1346.54, 'status': 'PARTIAL', 'taxes': [['GB', 93.65, True, False], ['AY', 56.1, True, True], ['DE', 105.73, False, False]]}, 93.65]], [['unused refundable', {'paid': 485.0, 'cancel_fee': 100.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 37.2, True, False], ['YQ', 80.0, False, False]]}, 422.2], ['partial with used taxes', {'paid': 900.0, 'cancel_fee': 150.0, 'used_fare': 425.0, 'status': 'PARTIAL', 'taxes': [['US', 37.2, True, False], ['XF', 4.5, True, True], ['YQ', 80.0, False, False], ['AY', 5.6, True, True]]}, 362.2], ['fee larger than fare', {'paid': 90.0, 'cancel_fee': 150.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 42.2, True, False]]}, 42.2], ['used portion exceeds paid', {'paid': 300.0, 'cancel_fee': 50.0, 'used_fare': 310.0, 'status': 'PARTIAL', 'taxes': [['US', 18.6, True, False], ['XF', 4.5, True, True]]}, 18.6], ['unused with stale used estimate', {'paid': 650.0, 'cancel_fee': 0.0, 'used_fare': 205.0, 'status': 'UNUSED', 'taxes': [['US', 20.0, True, False]]}, 670.0], ['non-refundable carrier charges', {'paid': 700.0, 'cancel_fee': 75.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['YQ', 120.0, False, False], ['GB', 31.0, True, False]]}, 656.0], ['sampled case 1', {'paid': 1477.45, 'cancel_fee': 100.0, 'used_fare': 1174.26, 'status': 'PARTIAL', 'taxes': [['AY', 80.91, True, True], ['XF', 91.97, True, False]]}, 295.16], ['sampled case 2', {'paid': 441.62, 'cancel_fee': 50.0, 'used_fare': 285.82, 'status': 'PARTIAL', 'taxes': []}, 105.8], ['sampled case 3', {'paid': 1459.32, 'cancel_fee': 50.0, 'used_fare': 1488.81, 'status': 'PARTIAL', 'taxes': [['YQ', 64.57, False, True]]}, 0.0]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A cheap ticket with a large penalty refunds less than its refundable government taxes.

Input {'paid' base fare,'cancel_fee','used_fare','status' UNUSED|PARTIAL,'taxes':[[code, amount, refundable, used]]}. Fare portion = paid - cancel fee - (used fare only when PARTIAL), floored at 0 before taxes are added. Taxes are refunded only if refundable and not used. Return refund rounded 2.

split: open-access


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

N = 1
observations = []
def solve(x):
    paid = x['paid']
    fare_part = paid - x['cancel_fee']
    if x['status'] == 'PARTIAL':
        fare_part -= x['used_fare']
    fare_part = max(0.0, fare_part)
    taxes = sum(a for code, a, refundable, used in x['taxes'] if refundable)
    return round(fare_part + taxes, 2)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['unused refundable', {'paid': 481.0, 'cancel_fee': 100.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 37.2, True, False], ['YQ', 80.0, False, False]]}, 418.2], ['partial with used taxes', {'paid': 900.0, 'cancel_fee': 150.0, 'used_fare': 421.0, 'status': 'PARTIAL', 'taxes': [['US', 37.2, True, False], ['XF', 4.5, True, True], ['YQ', 80.0, False, False], ['AY', 5.6, True, True]]}, 366.2], ['fee larger than fare', {'paid': 90.0, 'cancel_fee': 150.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 38.2, True, False]]}, 38.2], ['used portion exceeds paid', {'paid': 300.0, 'cancel_fee': 50.0, 'used_fare': 310.0, 'status': 'PARTIAL', 'taxes': [['US', 18.6, True, False], ['XF', 4.5, True, True]]}, 18.6], ['unused with stale used estimate', {'paid': 650.0, 'cancel_fee': 0.0, 'used_fare': 201.0, 'status': 'UNUSED', 'taxes': [['US', 20.0, True, False]]}, 670.0], ['non-refundable carrier charges', {'paid': 700.0, 'cancel_fee': 75.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['YQ', 120.0, False, False], ['GB', 27.0, True, False]]}, 652.0], ['sampled case 1', {'paid': 386.27, 'cancel_fee': 250.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 51.02, True, False], ['YQ', 5.59, False, False], ['XF', 3.57, True, False], ['DE', 99.09, True, False]]}, 289.95], ['sampled case 2', {'paid': 1007.21, 'cancel_fee': 50.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['XF', 29.38, True, False]]}, 986.59], ['sampled case 3', {'paid': 176.19, 'cancel_fee': 0.0, 'used_fare': 203.14, 'status': 'PARTIAL', 'taxes': [['DE', 94.53, True, True], ['GB', 107.54, False, True], ['XF', 23.26, True, True]]}, 0.0]], [['unused refundable', {'paid': 482.0, 'cancel_fee': 100.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 37.2, True, False], ['YQ', 80.0, False, False]]}, 419.2], ['partial with used taxes', {'paid': 900.0, 'cancel_fee': 150.0, 'used_fare': 422.0, 'status': 'PARTIAL', 'taxes': [['US', 37.2, True, False], ['XF', 4.5, True, True], ['YQ', 80.0, False, False], ['AY', 5.6, True, True]]}, 365.2], ['fee larger than fare', {'paid': 90.0, 'cancel_fee': 150.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 39.2, True, False]]}, 39.2], ['used portion exceeds paid', {'paid': 300.0, 'cancel_fee': 50.0, 'used_fare': 310.0, 'status': 'PARTIAL', 'taxes': [['US', 18.6, True, False], ['XF', 4.5, True, True]]}, 18.6], ['unused with stale used estimate', {'paid': 650.0, 'cancel_fee': 0.0, 'used_fare': 202.0, 'status': 'UNUSED', 'taxes': [['US', 20.0, True, False]]}, 670.0], ['non-refundable carrier charges', {'paid': 700.0, 'cancel_fee': 75.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['YQ', 120.0, False, False], ['GB', 28.0, True, False]]}, 653.0], ['sampled case 1', {'paid': 1076.29, 'cancel_fee': 50.0, 'used_fare': 538.9, 'status': 'PARTIAL', 'taxes': [['YQ', 84.65, True, False], ['XF', 108.03, True, False]]}, 680.07], ['sampled case 2', {'paid': 193.38, 'cancel_fee': 250.0, 'used_fare': 218.71, 'status': 'PARTIAL', 'taxes': [['YQ', 67.48, True, False], ['GB', 86.2, True, False], ['AY', 96.45, True, False]]}, 250.13], ['sampled case 3', {'paid': 640.4, 'cancel_fee': 150.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['AY', 115.97, True, False], ['DE', 57.82, False, False]]}, 606.37]], [['unused refundable', {'paid': 483.0, 'cancel_fee': 100.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 37.2, True, False], ['YQ', 80.0, False, False]]}, 420.2], ['partial with used taxes', {'paid': 900.0, 'cancel_fee': 150.0, 'used_fare': 423.0, 'status': 'PARTIAL', 'taxes': [['US', 37.2, True, False], ['XF', 4.5, True, True], ['YQ', 80.0, False, False], ['AY', 5.6, True, True]]}, 364.2], ['fee larger than fare', {'paid': 90.0, 'cancel_fee': 150.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 40.2, True, False]]}, 40.2], ['used portion exceeds paid', {'paid': 300.0, 'cancel_fee': 50.0, 'used_fare': 310.0, 'status': 'PARTIAL', 'taxes': [['US', 18.6, True, False], ['XF', 4.5, True, True]]}, 18.6], ['unused with stale used estimate', {'paid': 650.0, 'cancel_fee': 0.0, 'used_fare': 203.0, 'status': 'UNUSED', 'taxes': [['US', 20.0, True, False]]}, 670.0], ['non-refundable carrier charges', {'paid': 700.0, 'cancel_fee': 75.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['YQ', 120.0, False, False], ['GB', 29.0, True, False]]}, 654.0], ['sampled case 1', {'paid': 502.45, 'cancel_fee': 100.0, 'used_fare': 464.12, 'status': 'PARTIAL', 'taxes': [['US', 99.3, False, True], ['AY', 85.33, True, True], ['DE', 48.94, True, False]]}, 48.94], ['sampled case 2', {'paid': 638.36, 'cancel_fee': 150.0, 'used_fare': 498.2, 'status': 'PARTIAL', 'taxes': [['GB', 89.81, True, False], ['US', 67.48, False, True]]}, 89.81], ['sampled case 3', {'paid': 311.77, 'cancel_fee': 50.0, 'used_fare': 120.66, 'status': 'PARTIAL', 'taxes': []}, 141.11]], [['unused refundable', {'paid': 484.0, 'cancel_fee': 100.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 37.2, True, False], ['YQ', 80.0, False, False]]}, 421.2], ['partial with used taxes', {'paid': 900.0, 'cancel_fee': 150.0, 'used_fare': 424.0, 'status': 'PARTIAL', 'taxes': [['US', 37.2, True, False], ['XF', 4.5, True, True], ['YQ', 80.0, False, False], ['AY', 5.6, True, True]]}, 363.2], ['fee larger than fare', {'paid': 90.0, 'cancel_fee': 150.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 41.2, True, False]]}, 41.2], ['used portion exceeds paid', {'paid': 300.0, 'cancel_fee': 50.0, 'used_fare': 310.0, 'status': 'PARTIAL', 'taxes': [['US', 18.6, True, False], ['XF', 4.5, True, True]]}, 18.6], ['unused with stale used estimate', {'paid': 650.0, 'cancel_fee': 0.0, 'used_fare': 204.0, 'status': 'UNUSED', 'taxes': [['US', 20.0, True, False]]}, 670.0], ['non-refundable carrier charges', {'paid': 700.0, 'cancel_fee': 75.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['YQ', 120.0, False, False], ['GB', 30.0, True, False]]}, 655.0], ['sampled case 1', {'paid': 716.18, 'cancel_fee': 50.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['YQ', 62.57, True, False], ['US', 60.18, True, False], ['AY', 40.23, True, False]]}, 829.16], ['sampled case 2', {'paid': 304.89, 'cancel_fee': 250.0, 'used_fare': 353.1, 'status': 'PARTIAL', 'taxes': [['DE', 109.57, False, True], ['YQ', 82.61, True, False]]}, 82.61], ['sampled case 3', {'paid': 1425.61, 'cancel_fee': 100.0, 'used_fare': 1346.54, 'status': 'PARTIAL', 'taxes': [['GB', 93.65, True, False], ['AY', 56.1, True, True], ['DE', 105.73, False, False]]}, 93.65]], [['unused refundable', {'paid': 485.0, 'cancel_fee': 100.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 37.2, True, False], ['YQ', 80.0, False, False]]}, 422.2], ['partial with used taxes', {'paid': 900.0, 'cancel_fee': 150.0, 'used_fare': 425.0, 'status': 'PARTIAL', 'taxes': [['US', 37.2, True, False], ['XF', 4.5, True, True], ['YQ', 80.0, False, False], ['AY', 5.6, True, True]]}, 362.2], ['fee larger than fare', {'paid': 90.0, 'cancel_fee': 150.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 42.2, True, False]]}, 42.2], ['used portion exceeds paid', {'paid': 300.0, 'cancel_fee': 50.0, 'used_fare': 310.0, 'status': 'PARTIAL', 'taxes': [['US', 18.6, True, False], ['XF', 4.5, True, True]]}, 18.6], ['unused with stale used estimate', {'paid': 650.0, 'cancel_fee': 0.0, 'used_fare': 205.0, 'status': 'UNUSED', 'taxes': [['US', 20.0, True, False]]}, 670.0], ['non-refundable carrier charges', {'paid': 700.0, 'cancel_fee': 75.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['YQ', 120.0, False, False], ['GB', 31.0, True, False]]}, 656.0], ['sampled case 1', {'paid': 1477.45, 'cancel_fee': 100.0, 'used_fare': 1174.26, 'status': 'PARTIAL', 'taxes': [['AY', 80.91, True, True], ['XF', 91.97, True, False]]}, 295.16], ['sampled case 2', {'paid': 441.62, 'cancel_fee': 50.0, 'used_fare': 285.82, 'status': 'PARTIAL', 'taxes': []}, 105.8], ['sampled case 3', {'paid': 1459.32, 'cancel_fee': 50.0, 'used_fare': 1488.81, 'status': 'PARTIAL', 'taxes': [['YQ', 64.57, False, True]]}, 0.0]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    paid = x['paid']
    fare_part = paid - x['cancel_fee']
    if x['status'] == 'PARTIAL':
        fare_part -= x['used_fare']
    fare_part = max(0.0, fare_part)
    taxes = sum(a for code, a, refundable, used in x['taxes'] if not used)
    return round(fare_part + taxes, 2)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['unused refundable', {'paid': 481.0, 'cancel_fee': 100.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 37.2, True, False], ['YQ', 80.0, False, False]]}, 418.2], ['partial with used taxes', {'paid': 900.0, 'cancel_fee': 150.0, 'used_fare': 421.0, 'status': 'PARTIAL', 'taxes': [['US', 37.2, True, False], ['XF', 4.5, True, True], ['YQ', 80.0, False, False], ['AY', 5.6, True, True]]}, 366.2], ['fee larger than fare', {'paid': 90.0, 'cancel_fee': 150.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 38.2, True, False]]}, 38.2], ['used portion exceeds paid', {'paid': 300.0, 'cancel_fee': 50.0, 'used_fare': 310.0, 'status': 'PARTIAL', 'taxes': [['US', 18.6, True, False], ['XF', 4.5, True, True]]}, 18.6], ['unused with stale used estimate', {'paid': 650.0, 'cancel_fee': 0.0, 'used_fare': 201.0, 'status': 'UNUSED', 'taxes': [['US', 20.0, True, False]]}, 670.0], ['non-refundable carrier charges', {'paid': 700.0, 'cancel_fee': 75.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['YQ', 120.0, False, False], ['GB', 27.0, True, False]]}, 652.0], ['sampled case 1', {'paid': 386.27, 'cancel_fee': 250.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 51.02, True, False], ['YQ', 5.59, False, False], ['XF', 3.57, True, False], ['DE', 99.09, True, False]]}, 289.95], ['sampled case 2', {'paid': 1007.21, 'cancel_fee': 50.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['XF', 29.38, True, False]]}, 986.59], ['sampled case 3', {'paid': 176.19, 'cancel_fee': 0.0, 'used_fare': 203.14, 'status': 'PARTIAL', 'taxes': [['DE', 94.53, True, True], ['GB', 107.54, False, True], ['XF', 23.26, True, True]]}, 0.0]], [['unused refundable', {'paid': 482.0, 'cancel_fee': 100.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 37.2, True, False], ['YQ', 80.0, False, False]]}, 419.2], ['partial with used taxes', {'paid': 900.0, 'cancel_fee': 150.0, 'used_fare': 422.0, 'status': 'PARTIAL', 'taxes': [['US', 37.2, True, False], ['XF', 4.5, True, True], ['YQ', 80.0, False, False], ['AY', 5.6, True, True]]}, 365.2], ['fee larger than fare', {'paid': 90.0, 'cancel_fee': 150.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 39.2, True, False]]}, 39.2], ['used portion exceeds paid', {'paid': 300.0, 'cancel_fee': 50.0, 'used_fare': 310.0, 'status': 'PARTIAL', 'taxes': [['US', 18.6, True, False], ['XF', 4.5, True, True]]}, 18.6], ['unused with stale used estimate', {'paid': 650.0, 'cancel_fee': 0.0, 'used_fare': 202.0, 'status': 'UNUSED', 'taxes': [['US', 20.0, True, False]]}, 670.0], ['non-refundable carrier charges', {'paid': 700.0, 'cancel_fee': 75.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['YQ', 120.0, False, False], ['GB', 28.0, True, False]]}, 653.0], ['sampled case 1', {'paid': 1076.29, 'cancel_fee': 50.0, 'used_fare': 538.9, 'status': 'PARTIAL', 'taxes': [['YQ', 84.65, True, False], ['XF', 108.03, True, False]]}, 680.07], ['sampled case 2', {'paid': 193.38, 'cancel_fee': 250.0, 'used_fare': 218.71, 'status': 'PARTIAL', 'taxes': [['YQ', 67.48, True, False], ['GB', 86.2, True, False], ['AY', 96.45, True, False]]}, 250.13], ['sampled case 3', {'paid': 640.4, 'cancel_fee': 150.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['AY', 115.97, True, False], ['DE', 57.82, False, False]]}, 606.37]], [['unused refundable', {'paid': 483.0, 'cancel_fee': 100.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 37.2, True, False], ['YQ', 80.0, False, False]]}, 420.2], ['partial with used taxes', {'paid': 900.0, 'cancel_fee': 150.0, 'used_fare': 423.0, 'status': 'PARTIAL', 'taxes': [['US', 37.2, True, False], ['XF', 4.5, True, True], ['YQ', 80.0, False, False], ['AY', 5.6, True, True]]}, 364.2], ['fee larger than fare', {'paid': 90.0, 'cancel_fee': 150.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 40.2, True, False]]}, 40.2], ['used portion exceeds paid', {'paid': 300.0, 'cancel_fee': 50.0, 'used_fare': 310.0, 'status': 'PARTIAL', 'taxes': [['US', 18.6, True, False], ['XF', 4.5, True, True]]}, 18.6], ['unused with stale used estimate', {'paid': 650.0, 'cancel_fee': 0.0, 'used_fare': 203.0, 'status': 'UNUSED', 'taxes': [['US', 20.0, True, False]]}, 670.0], ['non-refundable carrier charges', {'paid': 700.0, 'cancel_fee': 75.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['YQ', 120.0, False, False], ['GB', 29.0, True, False]]}, 654.0], ['sampled case 1', {'paid': 502.45, 'cancel_fee': 100.0, 'used_fare': 464.12, 'status': 'PARTIAL', 'taxes': [['US', 99.3, False, True], ['AY', 85.33, True, True], ['DE', 48.94, True, False]]}, 48.94], ['sampled case 2', {'paid': 638.36, 'cancel_fee': 150.0, 'used_fare': 498.2, 'status': 'PARTIAL', 'taxes': [['GB', 89.81, True, False], ['US', 67.48, False, True]]}, 89.81], ['sampled case 3', {'paid': 311.77, 'cancel_fee': 50.0, 'used_fare': 120.66, 'status': 'PARTIAL', 'taxes': []}, 141.11]], [['unused refundable', {'paid': 484.0, 'cancel_fee': 100.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 37.2, True, False], ['YQ', 80.0, False, False]]}, 421.2], ['partial with used taxes', {'paid': 900.0, 'cancel_fee': 150.0, 'used_fare': 424.0, 'status': 'PARTIAL', 'taxes': [['US', 37.2, True, False], ['XF', 4.5, True, True], ['YQ', 80.0, False, False], ['AY', 5.6, True, True]]}, 363.2], ['fee larger than fare', {'paid': 90.0, 'cancel_fee': 150.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 41.2, True, False]]}, 41.2], ['used portion exceeds paid', {'paid': 300.0, 'cancel_fee': 50.0, 'used_fare': 310.0, 'status': 'PARTIAL', 'taxes': [['US', 18.6, True, False], ['XF', 4.5, True, True]]}, 18.6], ['unused with stale used estimate', {'paid': 650.0, 'cancel_fee': 0.0, 'used_fare': 204.0, 'status': 'UNUSED', 'taxes': [['US', 20.0, True, False]]}, 670.0], ['non-refundable carrier charges', {'paid': 700.0, 'cancel_fee': 75.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['YQ', 120.0, False, False], ['GB', 30.0, True, False]]}, 655.0], ['sampled case 1', {'paid': 716.18, 'cancel_fee': 50.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['YQ', 62.57, True, False], ['US', 60.18, True, False], ['AY', 40.23, True, False]]}, 829.16], ['sampled case 2', {'paid': 304.89, 'cancel_fee': 250.0, 'used_fare': 353.1, 'status': 'PARTIAL', 'taxes': [['DE', 109.57, False, True], ['YQ', 82.61, True, False]]}, 82.61], ['sampled case 3', {'paid': 1425.61, 'cancel_fee': 100.0, 'used_fare': 1346.54, 'status': 'PARTIAL', 'taxes': [['GB', 93.65, True, False], ['AY', 56.1, True, True], ['DE', 105.73, False, False]]}, 93.65]], [['unused refundable', {'paid': 485.0, 'cancel_fee': 100.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 37.2, True, False], ['YQ', 80.0, False, False]]}, 422.2], ['partial with used taxes', {'paid': 900.0, 'cancel_fee': 150.0, 'used_fare': 425.0, 'status': 'PARTIAL', 'taxes': [['US', 37.2, True, False], ['XF', 4.5, True, True], ['YQ', 80.0, False, False], ['AY', 5.6, True, True]]}, 362.2], ['fee larger than fare', {'paid': 90.0, 'cancel_fee': 150.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['US', 42.2, True, False]]}, 42.2], ['used portion exceeds paid', {'paid': 300.0, 'cancel_fee': 50.0, 'used_fare': 310.0, 'status': 'PARTIAL', 'taxes': [['US', 18.6, True, False], ['XF', 4.5, True, True]]}, 18.6], ['unused with stale used estimate', {'paid': 650.0, 'cancel_fee': 0.0, 'used_fare': 205.0, 'status': 'UNUSED', 'taxes': [['US', 20.0, True, False]]}, 670.0], ['non-refundable carrier charges', {'paid': 700.0, 'cancel_fee': 75.0, 'used_fare': 0.0, 'status': 'UNUSED', 'taxes': [['YQ', 120.0, False, False], ['GB', 31.0, True, False]]}, 656.0], ['sampled case 1', {'paid': 1477.45, 'cancel_fee': 100.0, 'used_fare': 1174.26, 'status': 'PARTIAL', 'taxes': [['AY', 80.91, True, True], ['XF', 91.97, True, False]]}, 295.16], ['sampled case 2', {'paid': 441.62, 'cancel_fee': 50.0, 'used_fare': 285.82, 'status': 'PARTIAL', 'taxes': []}, 105.8], ['sampled case 3', {'paid': 1459.32, 'cancel_fee': 50.0, 'used_fare': 1488.81, 'status': 'PARTIAL', 'taxes': [['YQ', 64.57, False, True]]}, 0.0]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Partially used tickets refund departure taxes for sectors already flown.

Input {'paid' base fare,'cancel_fee','used_fare','status' UNUSED|PARTIAL,'taxes':[[code, amount, refundable, used]]}. Fare portion = paid - cancel fee - (used fare only when PARTIAL), floored at 0 before taxes are added. Taxes are refunded only if refundable and not used. Return refund rounded 2.

split: open-access