broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
N = 1
observations = []
def solve(x):
    T = datetime.datetime.fromisoformat(x['ticket'])
    D = datetime.datetime.fromisoformat(x['depart'])
    R = datetime.datetime.fromisoformat(x['res'])
    if (D.date() - T.date()).days < x['ap_days']: return 'FAIL_AP'
    if T > R + datetime.timedelta(hours=x['ticket_within_h']): return 'FAIL_TKT_TL'
    return 'PASS'
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['late evening ticket, early departure', {'res': '2027-03-01T09:00', 'ticket': '2027-03-01T22:30', 'depart': '2027-03-15T06:00', 'ap_days': 14, 'ticket_within_h': 24}, 'PASS'], ['exactly AP days', {'res': '2027-05-10T10:00', 'ticket': '2027-05-10T11:00', 'depart': '2027-05-17T08:00', 'ap_days': 7, 'ticket_within_h': 25}, 'PASS'], ['one day short', {'res': '2027-05-10T10:00', 'ticket': '2027-05-11T11:00', 'depart': '2027-05-17T08:00', 'ap_days': 7, 'ticket_within_h': 48}, 'FAIL_AP'], ['ticketed at exact time limit', {'res': '2027-06-01T08:00', 'ticket': '2027-06-02T08:00', 'depart': '2027-07-01T08:00', 'ap_days': 21, 'ticket_within_h': 24}, 'PASS'], ['ticketed after time limit', {'res': '2027-06-01T08:00', 'ticket': '2027-06-03T09:05', 'depart': '2027-07-01T08:00', 'ap_days': 21, 'ticket_within_h': 24}, 'FAIL_TKT_TL'], ['ticket before reservation', {'res': '2027-06-01T08:00', 'ticket': '2027-06-01T07:51', 'depart': '2027-07-01T08:00', 'ap_days': 3, 'ticket_within_h': 24}, 'ERR_ORDER'], ['AP and time limit both fail', {'res': '2027-08-01T08:00', 'ticket': '2027-08-05T08:00', 'depart': '2027-08-08T08:00', 'ap_days': 7, 'ticket_within_h': 24}, 'FAIL_AP'], ['sampled case 1', {'res': '2029-04-23T19:45', 'ticket': '2029-04-25T19:45', 'depart': '2029-05-10T07:45', 'ap_days': 21, 'ticket_within_h': 72}, 'FAIL_AP'], ['sampled case 2', {'res': '2028-12-29T20:45', 'ticket': '2028-12-30T21:15', 'depart': '2029-01-24T15:15', 'ap_days': 3, 'ticket_within_h': 72}, 'PASS'], ['sampled case 3', {'res': '2029-11-28T18:15', 'ticket': '2029-11-29T14:45', 'depart': '2029-12-08T20:45', 'ap_days': 21, 'ticket_within_h': 72}, 'FAIL_AP']], [['late evening ticket, early departure', {'res': '2027-03-01T09:00', 'ticket': '2027-03-01T22:30', 'depart': '2027-03-16T06:00', 'ap_days': 14, 'ticket_within_h': 24}, 'PASS'], ['exactly AP days', {'res': '2027-05-10T10:00', 'ticket': '2027-05-10T11:00', 'depart': '2027-05-17T08:00', 'ap_days': 7, 'ticket_within_h': 26}, 'PASS'], ['one day short', {'res': '2027-05-10T10:00', 'ticket': '2027-05-11T11:00', 'depart': '2027-05-17T08:00', 'ap_days': 7, 'ticket_within_h': 48}, 'FAIL_AP'], ['ticketed at exact time limit', {'res': '2027-06-01T08:00', 'ticket': '2027-06-02T08:00', 'depart': '2027-07-01T08:00', 'ap_days': 21, 'ticket_within_h': 24}, 'PASS'], ['ticketed after time limit', {'res': '2027-06-01T08:00', 'ticket': '2027-06-03T09:10', 'depart': '2027-07-01T08:00', 'ap_days': 21, 'ticket_within_h': 24}, 'FAIL_TKT_TL'], ['ticket before reservation', {'res': '2027-06-01T08:00', 'ticket': '2027-06-01T07:52', 'depart': '2027-07-01T08:00', 'ap_days': 3, 'ticket_within_h': 24}, 'ERR_ORDER'], ['AP and time limit both fail', {'res': '2027-08-01T08:00', 'ticket': '2027-08-05T08:00', 'depart': '2027-08-08T08:00', 'ap_days': 7, 'ticket_within_h': 48}, 'FAIL_AP'], ['sampled case 1', {'res': '2029-03-02T18:30', 'ticket': '2029-03-05T19:00', 'depart': '2029-03-14T02:00', 'ap_days': 14, 'ticket_within_h': 72}, 'FAIL_AP'], ['sampled case 2', {'res': '2028-11-19T00:15', 'ticket': '2028-11-20T00:15', 'depart': '2028-12-13T04:15', 'ap_days': 7, 'ticket_within_h': 24}, 'PASS'], ['sampled case 3', {'res': '2028-08-13T05:15', 'ticket': '2028-08-13T20:45', 'depart': '2028-08-18T10:45', 'ap_days': 3, 'ticket_within_h': 72}, 'PASS']], [['late evening ticket, early departure', {'res': '2027-03-01T09:00', 'ticket': '2027-03-01T22:30', 'depart': '2027-03-17T06:00', 'ap_days': 14, 'ticket_within_h': 24}, 'PASS'], ['exactly AP days', {'res': '2027-05-10T10:00', 'ticket': '2027-05-10T11:00', 'depart': '2027-05-17T08:00', 'ap_days': 7, 'ticket_within_h': 27}, 'PASS'], ['one day short', {'res': '2027-05-10T10:00', 'ticket': '2027-05-11T11:00', 'depart': '2027-05-17T08:00', 'ap_days': 7, 'ticket_within_h': 48}, 'FAIL_AP'], ['ticketed at exact time limit', {'res': '2027-06-01T08:00', 'ticket': '2027-06-02T08:00', 'depart': '2027-07-01T08:00', 'ap_days': 21, 'ticket_within_h': 24}, 'PASS'], ['ticketed after time limit', {'res': '2027-06-01T08:00', 'ticket': '2027-06-03T09:15', 'depart': '2027-07-01T08:00', 'ap_days': 21, 'ticket_within_h': 24}, 'FAIL_TKT_TL'], ['ticket before reservation', {'res': '2027-06-01T08:00', 'ticket': '2027-06-01T07:53', 'depart': '2027-07-01T08:00', 'ap_days': 3, 'ticket_within_h': 24}, 'ERR_ORDER'], ['AP and time limit both fail', {'res': '2027-08-01T08:00', 'ticket': '2027-08-05T08:00', 'depart': '2027-08-08T08:00', 'ap_days': 7, 'ticket_within_h': 72}, 'FAIL_AP'], ['sampled case 1', {'res': '2028-01-07T10:45', 'ticket': '2028-01-10T11:15', 'depart': '2028-01-27T06:15', 'ap_days': 14, 'ticket_within_h': 72}, 'FAIL_TKT_TL'], ['sampled case 2', {'res': '2027-11-20T22:00', 'ticket': '2027-11-23T02:00', 'depart': '2027-12-12T09:00', 'ap_days': 21, 'ticket_within_h': 24}, 'FAIL_AP'], ['sampled case 3', {'res': '2029-01-16T10:15', 'ticket': '2029-01-17T10:45', 'depart': '2029-02-13T03:45', 'ap_days': 14, 'ticket_within_h': 24}, 'FAIL_TKT_TL']], [['late evening ticket, early departure', {'res': '2027-03-01T09:00', 'ticket': '2027-03-01T22:30', 'depart': '2027-03-18T06:00', 'ap_days': 14, 'ticket_within_h': 24}, 'PASS'], ['exactly AP days', {'res': '2027-05-10T10:00', 'ticket': '2027-05-10T11:00', 'depart': '2027-05-17T08:00', 'ap_days': 7, 'ticket_within_h': 28}, 'PASS'], ['one day short', {'res': '2027-05-10T10:00', 'ticket': '2027-05-11T11:00', 'depart': '2027-05-17T08:00', 'ap_days': 7, 'ticket_within_h': 48}, 'FAIL_AP'], ['ticketed at exact time limit', {'res': '2027-06-01T08:00', 'ticket': '2027-06-02T08:00', 'depart': '2027-07-01T08:00', 'ap_days': 21, 'ticket_within_h': 24}, 'PASS'], ['ticketed after time limit', {'res': '2027-06-01T08:00', 'ticket': '2027-06-03T09:20', 'depart': '2027-07-01T08:00', 'ap_days': 21, 'ticket_within_h': 24}, 'FAIL_TKT_TL'], ['ticket before reservation', {'res': '2027-06-01T08:00', 'ticket': '2027-06-01T07:54', 'depart': '2027-07-01T08:00', 'ap_days': 3, 'ticket_within_h': 24}, 'ERR_ORDER'], ['AP and time limit both fail', {'res': '2027-08-01T08:00', 'ticket': '2027-08-05T08:00', 'depart': '2027-08-08T08:00', 'ap_days': 7, 'ticket_within_h': 96}, 'FAIL_AP'], ['sampled case 1', {'res': '2028-04-10T05:15', 'ticket': '2028-04-13T05:15', 'depart': '2028-04-21T10:15', 'ap_days': 14, 'ticket_within_h': 48}, 'FAIL_AP'], ['sampled case 2', {'res': '2029-06-06T12:45', 'ticket': '2029-06-09T12:45', 'depart': '2029-07-06T08:45', 'ap_days': 7, 'ticket_within_h': 24}, 'FAIL_TKT_TL'], ['sampled case 3', {'res': '2029-10-21T12:00', 'ticket': '2029-10-24T12:00', 'depart': '2029-11-15T19:00', 'ap_days': 7, 'ticket_within_h': 48}, 'FAIL_TKT_TL']], [['late evening ticket, early departure', {'res': '2027-03-01T09:00', 'ticket': '2027-03-01T22:30', 'depart': '2027-03-19T06:00', 'ap_days': 14, 'ticket_within_h': 24}, 'PASS'], ['exactly AP days', {'res': '2027-05-10T10:00', 'ticket': '2027-05-10T11:00', 'depart': '2027-05-17T08:00', 'ap_days': 7, 'ticket_within_h': 29}, 'PASS'], ['one day short', {'res': '2027-05-10T10:00', 'ticket': '2027-05-11T11:00', 'depart': '2027-05-17T08:00', 'ap_days': 7, 'ticket_within_h': 48}, 'FAIL_AP'], ['ticketed at exact time limit', {'res': '2027-06-01T08:00', 'ticket': '2027-06-02T08:00', 'depart': '2027-07-01T08:00', 'ap_days': 21, 'ticket_within_h': 24}, 'PASS'], ['ticketed after time limit', {'res': '2027-06-01T08:00', 'ticket': '2027-06-03T09:25', 'depart': '2027-07-01T08:00', 'ap_days': 21, 'ticket_within_h': 24}, 'FAIL_TKT_TL'], ['ticket before reservation', {'res': '2027-06-01T08:00', 'ticket': '2027-06-01T07:55', 'depart': '2027-07-01T08:00', 'ap_days': 3, 'ticket_within_h': 24}, 'ERR_ORDER'], ['AP and time limit both fail', {'res': '2027-08-01T08:00', 'ticket': '2027-08-05T08:00', 'depart': '2027-08-08T08:00', 'ap_days': 7, 'ticket_within_h': 120}, 'FAIL_AP'], ['sampled case 1', {'res': '2029-04-07T13:45', 'ticket': '2029-04-08T19:15', 'depart': '2029-04-19T08:15', 'ap_days': 3, 'ticket_within_h': 48}, 'PASS'], ['sampled case 2', {'res': '2027-04-03T07:45', 'ticket': '2027-04-05T08:15', 'depart': '2027-05-01T01:15', 'ap_days': 3, 'ticket_within_h': 48}, 'FAIL_TKT_TL'], ['sampled case 3', {'res': '2029-01-24T00:30', 'ticket': '2029-01-25T01:00', 'depart': '2029-02-11T22:00', 'ap_days': 7, 'ticket_within_h': 24}, 'FAIL_TKT_TL']]]
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
N = 1
observations = []
def solve(x):
    T = datetime.datetime.fromisoformat(x['ticket'])
    D = datetime.datetime.fromisoformat(x['depart'])
    R = datetime.datetime.fromisoformat(x['res'])
    if T.date() < R.date(): return 'ERR_ORDER'
    if (D.date() - T.date()).days < x['ap_days']: return 'FAIL_AP'
    if T > R + datetime.timedelta(hours=x['ticket_within_h']): return 'FAIL_TKT_TL'
    return 'PASS'
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['late evening ticket, early departure', {'res': '2027-03-01T09:00', 'ticket': '2027-03-01T22:30', 'depart': '2027-03-15T06:00', 'ap_days': 14, 'ticket_within_h': 24}, 'PASS'], ['exactly AP days', {'res': '2027-05-10T10:00', 'ticket': '2027-05-10T11:00', 'depart': '2027-05-17T08:00', 'ap_days': 7, 'ticket_within_h': 25}, 'PASS'], ['one day short', {'res': '2027-05-10T10:00', 'ticket': '2027-05-11T11:00', 'depart': '2027-05-17T08:00', 'ap_days': 7, 'ticket_within_h': 48}, 'FAIL_AP'], ['ticketed at exact time limit', {'res': '2027-06-01T08:00', 'ticket': '2027-06-02T08:00', 'depart': '2027-07-01T08:00', 'ap_days': 21, 'ticket_within_h': 24}, 'PASS'], ['ticketed after time limit', {'res': '2027-06-01T08:00', 'ticket': '2027-06-03T09:05', 'depart': '2027-07-01T08:00', 'ap_days': 21, 'ticket_within_h': 24}, 'FAIL_TKT_TL'], ['ticket before reservation', {'res': '2027-06-01T08:00', 'ticket': '2027-06-01T07:51', 'depart': '2027-07-01T08:00', 'ap_days': 3, 'ticket_within_h': 24}, 'ERR_ORDER'], ['AP and time limit both fail', {'res': '2027-08-01T08:00', 'ticket': '2027-08-05T08:00', 'depart': '2027-08-08T08:00', 'ap_days': 7, 'ticket_within_h': 24}, 'FAIL_AP'], ['sampled case 1', {'res': '2029-04-23T19:45', 'ticket': '2029-04-25T19:45', 'depart': '2029-05-10T07:45', 'ap_days': 21, 'ticket_within_h': 72}, 'FAIL_AP'], ['sampled case 2', {'res': '2028-12-29T20:45', 'ticket': '2028-12-30T21:15', 'depart': '2029-01-24T15:15', 'ap_days': 3, 'ticket_within_h': 72}, 'PASS'], ['sampled case 3', {'res': '2029-11-28T18:15', 'ticket': '2029-11-29T14:45', 'depart': '2029-12-08T20:45', 'ap_days': 21, 'ticket_within_h': 72}, 'FAIL_AP']], [['late evening ticket, early departure', {'res': '2027-03-01T09:00', 'ticket': '2027-03-01T22:30', 'depart': '2027-03-16T06:00', 'ap_days': 14, 'ticket_within_h': 24}, 'PASS'], ['exactly AP days', {'res': '2027-05-10T10:00', 'ticket': '2027-05-10T11:00', 'depart': '2027-05-17T08:00', 'ap_days': 7, 'ticket_within_h': 26}, 'PASS'], ['one day short', {'res': '2027-05-10T10:00', 'ticket': '2027-05-11T11:00', 'depart': '2027-05-17T08:00', 'ap_days': 7, 'ticket_within_h': 48}, 'FAIL_AP'], ['ticketed at exact time limit', {'res': '2027-06-01T08:00', 'ticket': '2027-06-02T08:00', 'depart': '2027-07-01T08:00', 'ap_days': 21, 'ticket_within_h': 24}, 'PASS'], ['ticketed after time limit', {'res': '2027-06-01T08:00', 'ticket': '2027-06-03T09:10', 'depart': '2027-07-01T08:00', 'ap_days': 21, 'ticket_within_h': 24}, 'FAIL_TKT_TL'], ['ticket before reservation', {'res': '2027-06-01T08:00', 'ticket': '2027-06-01T07:52', 'depart': '2027-07-01T08:00', 'ap_days': 3, 'ticket_within_h': 24}, 'ERR_ORDER'], ['AP and time limit both fail', {'res': '2027-08-01T08:00', 'ticket': '2027-08-05T08:00', 'depart': '2027-08-08T08:00', 'ap_days': 7, 'ticket_within_h': 48}, 'FAIL_AP'], ['sampled case 1', {'res': '2029-03-02T18:30', 'ticket': '2029-03-05T19:00', 'depart': '2029-03-14T02:00', 'ap_days': 14, 'ticket_within_h': 72}, 'FAIL_AP'], ['sampled case 2', {'res': '2028-11-19T00:15', 'ticket': '2028-11-20T00:15', 'depart': '2028-12-13T04:15', 'ap_days': 7, 'ticket_within_h': 24}, 'PASS'], ['sampled case 3', {'res': '2028-08-13T05:15', 'ticket': '2028-08-13T20:45', 'depart': '2028-08-18T10:45', 'ap_days': 3, 'ticket_within_h': 72}, 'PASS']], [['late evening ticket, early departure', {'res': '2027-03-01T09:00', 'ticket': '2027-03-01T22:30', 'depart': '2027-03-17T06:00', 'ap_days': 14, 'ticket_within_h': 24}, 'PASS'], ['exactly AP days', {'res': '2027-05-10T10:00', 'ticket': '2027-05-10T11:00', 'depart': '2027-05-17T08:00', 'ap_days': 7, 'ticket_within_h': 27}, 'PASS'], ['one day short', {'res': '2027-05-10T10:00', 'ticket': '2027-05-11T11:00', 'depart': '2027-05-17T08:00', 'ap_days': 7, 'ticket_within_h': 48}, 'FAIL_AP'], ['ticketed at exact time limit', {'res': '2027-06-01T08:00', 'ticket': '2027-06-02T08:00', 'depart': '2027-07-01T08:00', 'ap_days': 21, 'ticket_within_h': 24}, 'PASS'], ['ticketed after time limit', {'res': '2027-06-01T08:00', 'ticket': '2027-06-03T09:15', 'depart': '2027-07-01T08:00', 'ap_days': 21, 'ticket_within_h': 24}, 'FAIL_TKT_TL'], ['ticket before reservation', {'res': '2027-06-01T08:00', 'ticket': '2027-06-01T07:53', 'depart': '2027-07-01T08:00', 'ap_days': 3, 'ticket_within_h': 24}, 'ERR_ORDER'], ['AP and time limit both fail', {'res': '2027-08-01T08:00', 'ticket': '2027-08-05T08:00', 'depart': '2027-08-08T08:00', 'ap_days': 7, 'ticket_within_h': 72}, 'FAIL_AP'], ['sampled case 1', {'res': '2028-01-07T10:45', 'ticket': '2028-01-10T11:15', 'depart': '2028-01-27T06:15', 'ap_days': 14, 'ticket_within_h': 72}, 'FAIL_TKT_TL'], ['sampled case 2', {'res': '2027-11-20T22:00', 'ticket': '2027-11-23T02:00', 'depart': '2027-12-12T09:00', 'ap_days': 21, 'ticket_within_h': 24}, 'FAIL_AP'], ['sampled case 3', {'res': '2029-01-16T10:15', 'ticket': '2029-01-17T10:45', 'depart': '2029-02-13T03:45', 'ap_days': 14, 'ticket_within_h': 24}, 'FAIL_TKT_TL']], [['late evening ticket, early departure', {'res': '2027-03-01T09:00', 'ticket': '2027-03-01T22:30', 'depart': '2027-03-18T06:00', 'ap_days': 14, 'ticket_within_h': 24}, 'PASS'], ['exactly AP days', {'res': '2027-05-10T10:00', 'ticket': '2027-05-10T11:00', 'depart': '2027-05-17T08:00', 'ap_days': 7, 'ticket_within_h': 28}, 'PASS'], ['one day short', {'res': '2027-05-10T10:00', 'ticket': '2027-05-11T11:00', 'depart': '2027-05-17T08:00', 'ap_days': 7, 'ticket_within_h': 48}, 'FAIL_AP'], ['ticketed at exact time limit', {'res': '2027-06-01T08:00', 'ticket': '2027-06-02T08:00', 'depart': '2027-07-01T08:00', 'ap_days': 21, 'ticket_within_h': 24}, 'PASS'], ['ticketed after time limit', {'res': '2027-06-01T08:00', 'ticket': '2027-06-03T09:20', 'depart': '2027-07-01T08:00', 'ap_days': 21, 'ticket_within_h': 24}, 'FAIL_TKT_TL'], ['ticket before reservation', {'res': '2027-06-01T08:00', 'ticket': '2027-06-01T07:54', 'depart': '2027-07-01T08:00', 'ap_days': 3, 'ticket_within_h': 24}, 'ERR_ORDER'], ['AP and time limit both fail', {'res': '2027-08-01T08:00', 'ticket': '2027-08-05T08:00', 'depart': '2027-08-08T08:00', 'ap_days': 7, 'ticket_within_h': 96}, 'FAIL_AP'], ['sampled case 1', {'res': '2028-04-10T05:15', 'ticket': '2028-04-13T05:15', 'depart': '2028-04-21T10:15', 'ap_days': 14, 'ticket_within_h': 48}, 'FAIL_AP'], ['sampled case 2', {'res': '2029-06-06T12:45', 'ticket': '2029-06-09T12:45', 'depart': '2029-07-06T08:45', 'ap_days': 7, 'ticket_within_h': 24}, 'FAIL_TKT_TL'], ['sampled case 3', {'res': '2029-10-21T12:00', 'ticket': '2029-10-24T12:00', 'depart': '2029-11-15T19:00', 'ap_days': 7, 'ticket_within_h': 48}, 'FAIL_TKT_TL']], [['late evening ticket, early departure', {'res': '2027-03-01T09:00', 'ticket': '2027-03-01T22:30', 'depart': '2027-03-19T06:00', 'ap_days': 14, 'ticket_within_h': 24}, 'PASS'], ['exactly AP days', {'res': '2027-05-10T10:00', 'ticket': '2027-05-10T11:00', 'depart': '2027-05-17T08:00', 'ap_days': 7, 'ticket_within_h': 29}, 'PASS'], ['one day short', {'res': '2027-05-10T10:00', 'ticket': '2027-05-11T11:00', 'depart': '2027-05-17T08:00', 'ap_days': 7, 'ticket_within_h': 48}, 'FAIL_AP'], ['ticketed at exact time limit', {'res': '2027-06-01T08:00', 'ticket': '2027-06-02T08:00', 'depart': '2027-07-01T08:00', 'ap_days': 21, 'ticket_within_h': 24}, 'PASS'], ['ticketed after time limit', {'res': '2027-06-01T08:00', 'ticket': '2027-06-03T09:25', 'depart': '2027-07-01T08:00', 'ap_days': 21, 'ticket_within_h': 24}, 'FAIL_TKT_TL'], ['ticket before reservation', {'res': '2027-06-01T08:00', 'ticket': '2027-06-01T07:55', 'depart': '2027-07-01T08:00', 'ap_days': 3, 'ticket_within_h': 24}, 'ERR_ORDER'], ['AP and time limit both fail', {'res': '2027-08-01T08:00', 'ticket': '2027-08-05T08:00', 'depart': '2027-08-08T08:00', 'ap_days': 7, 'ticket_within_h': 120}, 'FAIL_AP'], ['sampled case 1', {'res': '2029-04-07T13:45', 'ticket': '2029-04-08T19:15', 'depart': '2029-04-19T08:15', 'ap_days': 3, 'ticket_within_h': 48}, 'PASS'], ['sampled case 2', {'res': '2027-04-03T07:45', 'ticket': '2027-04-05T08:15', 'depart': '2027-05-01T01:15', 'ap_days': 3, 'ticket_within_h': 48}, 'FAIL_TKT_TL'], ['sampled case 3', {'res': '2029-01-24T00:30', 'ticket': '2029-01-25T01:00', 'depart': '2029-02-11T22:00', 'ap_days': 7, 'ticket_within_h': 24}, 'FAIL_TKT_TL']]]
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:
Records whose ticket predates the reservation silently pass.

Input {'res','ticket','depart' ISO local datetimes,'ap_days','ticket_within_h'}. Ticket before reservation -> 'ERR_ORDER'. AP counts calendar days between the ticketing date and the departure date (>= ap_days passes) and is checked before the ticketing time limit; ticketing must be at or before reservation + ticket_within_h hours. Return 'PASS', 'FAIL_AP' or 'FAIL_TKT_TL'.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
N = 1
observations = []
def solve(x):
    T = datetime.datetime.fromisoformat(x['ticket'])
    D = datetime.datetime.fromisoformat(x['depart'])
    R = datetime.datetime.fromisoformat(x['res'])
    if T < R: return 'ERR_ORDER'
    if T > R + datetime.timedelta(hours=x['ticket_within_h']): return 'FAIL_TKT_TL'
    if (D.date() - T.date()).days < x['ap_days']: return 'FAIL_AP'
    return 'PASS'
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['late evening ticket, early departure', {'res': '2027-03-01T09:00', 'ticket': '2027-03-01T22:30', 'depart': '2027-03-15T06:00', 'ap_days': 14, 'ticket_within_h': 24}, 'PASS'], ['exactly AP days', {'res': '2027-05-10T10:00', 'ticket': '2027-05-10T11:00', 'depart': '2027-05-17T08:00', 'ap_days': 7, 'ticket_within_h': 25}, 'PASS'], ['one day short', {'res': '2027-05-10T10:00', 'ticket': '2027-05-11T11:00', 'depart': '2027-05-17T08:00', 'ap_days': 7, 'ticket_within_h': 48}, 'FAIL_AP'], ['ticketed at exact time limit', {'res': '2027-06-01T08:00', 'ticket': '2027-06-02T08:00', 'depart': '2027-07-01T08:00', 'ap_days': 21, 'ticket_within_h': 24}, 'PASS'], ['ticketed after time limit', {'res': '2027-06-01T08:00', 'ticket': '2027-06-03T09:05', 'depart': '2027-07-01T08:00', 'ap_days': 21, 'ticket_within_h': 24}, 'FAIL_TKT_TL'], ['ticket before reservation', {'res': '2027-06-01T08:00', 'ticket': '2027-06-01T07:51', 'depart': '2027-07-01T08:00', 'ap_days': 3, 'ticket_within_h': 24}, 'ERR_ORDER'], ['AP and time limit both fail', {'res': '2027-08-01T08:00', 'ticket': '2027-08-05T08:00', 'depart': '2027-08-08T08:00', 'ap_days': 7, 'ticket_within_h': 24}, 'FAIL_AP'], ['sampled case 1', {'res': '2029-04-23T19:45', 'ticket': '2029-04-25T19:45', 'depart': '2029-05-10T07:45', 'ap_days': 21, 'ticket_within_h': 72}, 'FAIL_AP'], ['sampled case 2', {'res': '2028-12-29T20:45', 'ticket': '2028-12-30T21:15', 'depart': '2029-01-24T15:15', 'ap_days': 3, 'ticket_within_h': 72}, 'PASS'], ['sampled case 3', {'res': '2029-11-28T18:15', 'ticket': '2029-11-29T14:45', 'depart': '2029-12-08T20:45', 'ap_days': 21, 'ticket_within_h': 72}, 'FAIL_AP'], ['regression: rule evaluation order', {'res': '2027-03-25T22:45', 'ticket': '2027-03-25T21:15', 'depart': '2027-03-25T10:15', 'ap_days': 14, 'ticket_within_h': 24}, 'ERR_ORDER']], [['late evening ticket, early departure', {'res': '2027-03-01T09:00', 'ticket': '2027-03-01T22:30', 'depart': '2027-03-16T06:00', 'ap_days': 14, 'ticket_within_h': 24}, 'PASS'], ['exactly AP days', {'res': '2027-05-10T10:00', 'ticket': '2027-05-10T11:00', 'depart': '2027-05-17T08:00', 'ap_days': 7, 'ticket_within_h': 26}, 'PASS'], ['one day short', {'res': '2027-05-10T10:00', 'ticket': '2027-05-11T11:00', 'depart': '2027-05-17T08:00', 'ap_days': 7, 'ticket_within_h': 48}, 'FAIL_AP'], ['ticketed at exact time limit', {'res': '2027-06-01T08:00', 'ticket': '2027-06-02T08:00', 'depart': '2027-07-01T08:00', 'ap_days': 21, 'ticket_within_h': 24}, 'PASS'], ['ticketed after time limit', {'res': '2027-06-01T08:00', 'ticket': '2027-06-03T09:10', 'depart': '2027-07-01T08:00', 'ap_days': 21, 'ticket_within_h': 24}, 'FAIL_TKT_TL'], ['ticket before reservation', {'res': '2027-06-01T08:00', 'ticket': '2027-06-01T07:52', 'depart': '2027-07-01T08:00', 'ap_days': 3, 'ticket_within_h': 24}, 'ERR_ORDER'], ['AP and time limit both fail', {'res': '2027-08-01T08:00', 'ticket': '2027-08-05T08:00', 'depart': '2027-08-08T08:00', 'ap_days': 7, 'ticket_within_h': 48}, 'FAIL_AP'], ['sampled case 1', {'res': '2029-03-02T18:30', 'ticket': '2029-03-05T19:00', 'depart': '2029-03-14T02:00', 'ap_days': 14, 'ticket_within_h': 72}, 'FAIL_AP'], ['sampled case 2', {'res': '2028-11-19T00:15', 'ticket': '2028-11-20T00:15', 'depart': '2028-12-13T04:15', 'ap_days': 7, 'ticket_within_h': 24}, 'PASS'], ['sampled case 3', {'res': '2028-08-13T05:15', 'ticket': '2028-08-13T20:45', 'depart': '2028-08-18T10:45', 'ap_days': 3, 'ticket_within_h': 72}, 'PASS'], ['regression: rule evaluation order', {'res': '2029-07-27T13:45', 'ticket': '2029-07-27T11:15', 'depart': '2029-07-29T18:15', 'ap_days': 21, 'ticket_within_h': 72}, 'ERR_ORDER']], [['late evening ticket, early departure', {'res': '2027-03-01T09:00', 'ticket': '2027-03-01T22:30', 'depart': '2027-03-17T06:00', 'ap_days': 14, 'ticket_within_h': 24}, 'PASS'], ['exactly AP days', {'res': '2027-05-10T10:00', 'ticket': '2027-05-10T11:00', 'depart': '2027-05-17T08:00', 'ap_days': 7, 'ticket_within_h': 27}, 'PASS'], ['one day short', {'res': '2027-05-10T10:00', 'ticket': '2027-05-11T11:00', 'depart': '2027-05-17T08:00', 'ap_days': 7, 'ticket_within_h': 48}, 'FAIL_AP'], ['ticketed at exact time limit', {'res': '2027-06-01T08:00', 'ticket': '2027-06-02T08:00', 'depart': '2027-07-01T08:00', 'ap_days': 21, 'ticket_within_h': 24}, 'PASS'], ['ticketed after time limit', {'res': '2027-06-01T08:00', 'ticket': '2027-06-03T09:15', 'depart': '2027-07-01T08:00', 'ap_days': 21, 'ticket_within_h': 24}, 'FAIL_TKT_TL'], ['ticket before reservation', {'res': '2027-06-01T08:00', 'ticket': '2027-06-01T07:53', 'depart': '2027-07-01T08:00', 'ap_days': 3, 'ticket_within_h': 24}, 'ERR_ORDER'], ['AP and time limit both fail', {'res': '2027-08-01T08:00', 'ticket': '2027-08-05T08:00', 'depart': '2027-08-08T08:00', 'ap_days': 7, 'ticket_within_h': 72}, 'FAIL_AP'], ['sampled case 1', {'res': '2028-01-07T10:45', 'ticket': '2028-01-10T11:15', 'depart': '2028-01-27T06:15', 'ap_days': 14, 'ticket_within_h': 72}, 'FAIL_TKT_TL'], ['sampled case 2', {'res': '2027-11-20T22:00', 'ticket': '2027-11-23T02:00', 'depart': '2027-12-12T09:00', 'ap_days': 21, 'ticket_within_h': 24}, 'FAIL_AP'], ['sampled case 3', {'res': '2029-01-16T10:15', 'ticket': '2029-01-17T10:45', 'depart': '2029-02-13T03:45', 'ap_days': 14, 'ticket_within_h': 24}, 'FAIL_TKT_TL'], ['regression: rule evaluation order', {'res': '2027-02-09T15:45', 'ticket': '2027-02-09T13:15', 'depart': '2027-02-10T04:15', 'ap_days': 3, 'ticket_within_h': 48}, 'ERR_ORDER']], [['late evening ticket, early departure', {'res': '2027-03-01T09:00', 'ticket': '2027-03-01T22:30', 'depart': '2027-03-18T06:00', 'ap_days': 14, 'ticket_within_h': 24}, 'PASS'], ['exactly AP days', {'res': '2027-05-10T10:00', 'ticket': '2027-05-10T11:00', 'depart': '2027-05-17T08:00', 'ap_days': 7, 'ticket_within_h': 28}, 'PASS'], ['one day short', {'res': '2027-05-10T10:00', 'ticket': '2027-05-11T11:00', 'depart': '2027-05-17T08:00', 'ap_days': 7, 'ticket_within_h': 48}, 'FAIL_AP'], ['ticketed at exact time limit', {'res': '2027-06-01T08:00', 'ticket': '2027-06-02T08:00', 'depart': '2027-07-01T08:00', 'ap_days': 21, 'ticket_within_h': 24}, 'PASS'], ['ticketed after time limit', {'res': '2027-06-01T08:00', 'ticket': '2027-06-03T09:20', 'depart': '2027-07-01T08:00', 'ap_days': 21, 'ticket_within_h': 24}, 'FAIL_TKT_TL'], ['ticket before reservation', {'res': '2027-06-01T08:00', 'ticket': '2027-06-01T07:54', 'depart': '2027-07-01T08:00', 'ap_days': 3, 'ticket_within_h': 24}, 'ERR_ORDER'], ['AP and time limit both fail', {'res': '2027-08-01T08:00', 'ticket': '2027-08-05T08:00', 'depart': '2027-08-08T08:00', 'ap_days': 7, 'ticket_within_h': 96}, 'FAIL_AP'], ['sampled case 1', {'res': '2028-04-10T05:15', 'ticket': '2028-04-13T05:15', 'depart': '2028-04-21T10:15', 'ap_days': 14, 'ticket_within_h': 48}, 'FAIL_AP'], ['sampled case 2', {'res': '2029-06-06T12:45', 'ticket': '2029-06-09T12:45', 'depart': '2029-07-06T08:45', 'ap_days': 7, 'ticket_within_h': 24}, 'FAIL_TKT_TL'], ['sampled case 3', {'res': '2029-10-21T12:00', 'ticket': '2029-10-24T12:00', 'depart': '2029-11-15T19:00', 'ap_days': 7, 'ticket_within_h': 48}, 'FAIL_TKT_TL'], ['regression: rule evaluation order', {'res': '2029-02-14T16:30', 'ticket': '2029-02-14T13:30', 'depart': '2029-02-16T10:30', 'ap_days': 7, 'ticket_within_h': 48}, 'ERR_ORDER']], [['late evening ticket, early departure', {'res': '2027-03-01T09:00', 'ticket': '2027-03-01T22:30', 'depart': '2027-03-19T06:00', 'ap_days': 14, 'ticket_within_h': 24}, 'PASS'], ['exactly AP days', {'res': '2027-05-10T10:00', 'ticket': '2027-05-10T11:00', 'depart': '2027-05-17T08:00', 'ap_days': 7, 'ticket_within_h': 29}, 'PASS'], ['one day short', {'res': '2027-05-10T10:00', 'ticket': '2027-05-11T11:00', 'depart': '2027-05-17T08:00', 'ap_days': 7, 'ticket_within_h': 48}, 'FAIL_AP'], ['ticketed at exact time limit', {'res': '2027-06-01T08:00', 'ticket': '2027-06-02T08:00', 'depart': '2027-07-01T08:00', 'ap_days': 21, 'ticket_within_h': 24}, 'PASS'], ['ticketed after time limit', {'res': '2027-06-01T08:00', 'ticket': '2027-06-03T09:25', 'depart': '2027-07-01T08:00', 'ap_days': 21, 'ticket_within_h': 24}, 'FAIL_TKT_TL'], ['ticket before reservation', {'res': '2027-06-01T08:00', 'ticket': '2027-06-01T07:55', 'depart': '2027-07-01T08:00', 'ap_days': 3, 'ticket_within_h': 24}, 'ERR_ORDER'], ['AP and time limit both fail', {'res': '2027-08-01T08:00', 'ticket': '2027-08-05T08:00', 'depart': '2027-08-08T08:00', 'ap_days': 7, 'ticket_within_h': 120}, 'FAIL_AP'], ['sampled case 1', {'res': '2029-04-07T13:45', 'ticket': '2029-04-08T19:15', 'depart': '2029-04-19T08:15', 'ap_days': 3, 'ticket_within_h': 48}, 'PASS'], ['sampled case 2', {'res': '2027-04-03T07:45', 'ticket': '2027-04-05T08:15', 'depart': '2027-05-01T01:15', 'ap_days': 3, 'ticket_within_h': 48}, 'FAIL_TKT_TL'], ['sampled case 3', {'res': '2029-01-24T00:30', 'ticket': '2029-01-25T01:00', 'depart': '2029-02-11T22:00', 'ap_days': 7, 'ticket_within_h': 24}, 'FAIL_TKT_TL'], ['regression: rule evaluation order', {'res': '2028-12-10T18:30', 'ticket': '2028-12-13T06:00', 'depart': '2028-12-26T10:00', 'ap_days': 21, 'ticket_within_h': 24}, 'FAIL_AP'], ['regression: rule evaluation order', {'res': '2028-05-25T16:30', 'ticket': '2028-05-25T14:30', 'depart': '2028-06-02T22:30', 'ap_days': 21, 'ticket_within_h': 24}, 'ERR_ORDER']]]
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
N = 1
observations = []
def solve(x):
    T = datetime.datetime.fromisoformat(x['ticket'])
    D = datetime.datetime.fromisoformat(x['depart'])
    R = datetime.datetime.fromisoformat(x['res'])
    if (D.date() - T.date()).days < x['ap_days']: return 'FAIL_AP'
    if T > R + datetime.timedelta(hours=x['ticket_within_h']): return 'FAIL_TKT_TL'
    if T < R: return 'ERR_ORDER'
    return 'PASS'
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['late evening ticket, early departure', {'res': '2027-03-01T09:00', 'ticket': '2027-03-01T22:30', 'depart': '2027-03-15T06:00', 'ap_days': 14, 'ticket_within_h': 24}, 'PASS'], ['exactly AP days', {'res': '2027-05-10T10:00', 'ticket': '2027-05-10T11:00', 'depart': '2027-05-17T08:00', 'ap_days': 7, 'ticket_within_h': 25}, 'PASS'], ['one day short', {'res': '2027-05-10T10:00', 'ticket': '2027-05-11T11:00', 'depart': '2027-05-17T08:00', 'ap_days': 7, 'ticket_within_h': 48}, 'FAIL_AP'], ['ticketed at exact time limit', {'res': '2027-06-01T08:00', 'ticket': '2027-06-02T08:00', 'depart': '2027-07-01T08:00', 'ap_days': 21, 'ticket_within_h': 24}, 'PASS'], ['ticketed after time limit', {'res': '2027-06-01T08:00', 'ticket': '2027-06-03T09:05', 'depart': '2027-07-01T08:00', 'ap_days': 21, 'ticket_within_h': 24}, 'FAIL_TKT_TL'], ['ticket before reservation', {'res': '2027-06-01T08:00', 'ticket': '2027-06-01T07:51', 'depart': '2027-07-01T08:00', 'ap_days': 3, 'ticket_within_h': 24}, 'ERR_ORDER'], ['AP and time limit both fail', {'res': '2027-08-01T08:00', 'ticket': '2027-08-05T08:00', 'depart': '2027-08-08T08:00', 'ap_days': 7, 'ticket_within_h': 24}, 'FAIL_AP'], ['sampled case 1', {'res': '2029-04-23T19:45', 'ticket': '2029-04-25T19:45', 'depart': '2029-05-10T07:45', 'ap_days': 21, 'ticket_within_h': 72}, 'FAIL_AP'], ['sampled case 2', {'res': '2028-12-29T20:45', 'ticket': '2028-12-30T21:15', 'depart': '2029-01-24T15:15', 'ap_days': 3, 'ticket_within_h': 72}, 'PASS'], ['sampled case 3', {'res': '2029-11-28T18:15', 'ticket': '2029-11-29T14:45', 'depart': '2029-12-08T20:45', 'ap_days': 21, 'ticket_within_h': 72}, 'FAIL_AP'], ['regression: rule evaluation order', {'res': '2027-03-25T22:45', 'ticket': '2027-03-25T21:15', 'depart': '2027-03-25T10:15', 'ap_days': 14, 'ticket_within_h': 24}, 'ERR_ORDER']], [['late evening ticket, early departure', {'res': '2027-03-01T09:00', 'ticket': '2027-03-01T22:30', 'depart': '2027-03-16T06:00', 'ap_days': 14, 'ticket_within_h': 24}, 'PASS'], ['exactly AP days', {'res': '2027-05-10T10:00', 'ticket': '2027-05-10T11:00', 'depart': '2027-05-17T08:00', 'ap_days': 7, 'ticket_within_h': 26}, 'PASS'], ['one day short', {'res': '2027-05-10T10:00', 'ticket': '2027-05-11T11:00', 'depart': '2027-05-17T08:00', 'ap_days': 7, 'ticket_within_h': 48}, 'FAIL_AP'], ['ticketed at exact time limit', {'res': '2027-06-01T08:00', 'ticket': '2027-06-02T08:00', 'depart': '2027-07-01T08:00', 'ap_days': 21, 'ticket_within_h': 24}, 'PASS'], ['ticketed after time limit', {'res': '2027-06-01T08:00', 'ticket': '2027-06-03T09:10', 'depart': '2027-07-01T08:00', 'ap_days': 21, 'ticket_within_h': 24}, 'FAIL_TKT_TL'], ['ticket before reservation', {'res': '2027-06-01T08:00', 'ticket': '2027-06-01T07:52', 'depart': '2027-07-01T08:00', 'ap_days': 3, 'ticket_within_h': 24}, 'ERR_ORDER'], ['AP and time limit both fail', {'res': '2027-08-01T08:00', 'ticket': '2027-08-05T08:00', 'depart': '2027-08-08T08:00', 'ap_days': 7, 'ticket_within_h': 48}, 'FAIL_AP'], ['sampled case 1', {'res': '2029-03-02T18:30', 'ticket': '2029-03-05T19:00', 'depart': '2029-03-14T02:00', 'ap_days': 14, 'ticket_within_h': 72}, 'FAIL_AP'], ['sampled case 2', {'res': '2028-11-19T00:15', 'ticket': '2028-11-20T00:15', 'depart': '2028-12-13T04:15', 'ap_days': 7, 'ticket_within_h': 24}, 'PASS'], ['sampled case 3', {'res': '2028-08-13T05:15', 'ticket': '2028-08-13T20:45', 'depart': '2028-08-18T10:45', 'ap_days': 3, 'ticket_within_h': 72}, 'PASS'], ['regression: rule evaluation order', {'res': '2029-07-27T13:45', 'ticket': '2029-07-27T11:15', 'depart': '2029-07-29T18:15', 'ap_days': 21, 'ticket_within_h': 72}, 'ERR_ORDER']], [['late evening ticket, early departure', {'res': '2027-03-01T09:00', 'ticket': '2027-03-01T22:30', 'depart': '2027-03-17T06:00', 'ap_days': 14, 'ticket_within_h': 24}, 'PASS'], ['exactly AP days', {'res': '2027-05-10T10:00', 'ticket': '2027-05-10T11:00', 'depart': '2027-05-17T08:00', 'ap_days': 7, 'ticket_within_h': 27}, 'PASS'], ['one day short', {'res': '2027-05-10T10:00', 'ticket': '2027-05-11T11:00', 'depart': '2027-05-17T08:00', 'ap_days': 7, 'ticket_within_h': 48}, 'FAIL_AP'], ['ticketed at exact time limit', {'res': '2027-06-01T08:00', 'ticket': '2027-06-02T08:00', 'depart': '2027-07-01T08:00', 'ap_days': 21, 'ticket_within_h': 24}, 'PASS'], ['ticketed after time limit', {'res': '2027-06-01T08:00', 'ticket': '2027-06-03T09:15', 'depart': '2027-07-01T08:00', 'ap_days': 21, 'ticket_within_h': 24}, 'FAIL_TKT_TL'], ['ticket before reservation', {'res': '2027-06-01T08:00', 'ticket': '2027-06-01T07:53', 'depart': '2027-07-01T08:00', 'ap_days': 3, 'ticket_within_h': 24}, 'ERR_ORDER'], ['AP and time limit both fail', {'res': '2027-08-01T08:00', 'ticket': '2027-08-05T08:00', 'depart': '2027-08-08T08:00', 'ap_days': 7, 'ticket_within_h': 72}, 'FAIL_AP'], ['sampled case 1', {'res': '2028-01-07T10:45', 'ticket': '2028-01-10T11:15', 'depart': '2028-01-27T06:15', 'ap_days': 14, 'ticket_within_h': 72}, 'FAIL_TKT_TL'], ['sampled case 2', {'res': '2027-11-20T22:00', 'ticket': '2027-11-23T02:00', 'depart': '2027-12-12T09:00', 'ap_days': 21, 'ticket_within_h': 24}, 'FAIL_AP'], ['sampled case 3', {'res': '2029-01-16T10:15', 'ticket': '2029-01-17T10:45', 'depart': '2029-02-13T03:45', 'ap_days': 14, 'ticket_within_h': 24}, 'FAIL_TKT_TL'], ['regression: rule evaluation order', {'res': '2027-02-09T15:45', 'ticket': '2027-02-09T13:15', 'depart': '2027-02-10T04:15', 'ap_days': 3, 'ticket_within_h': 48}, 'ERR_ORDER']], [['late evening ticket, early departure', {'res': '2027-03-01T09:00', 'ticket': '2027-03-01T22:30', 'depart': '2027-03-18T06:00', 'ap_days': 14, 'ticket_within_h': 24}, 'PASS'], ['exactly AP days', {'res': '2027-05-10T10:00', 'ticket': '2027-05-10T11:00', 'depart': '2027-05-17T08:00', 'ap_days': 7, 'ticket_within_h': 28}, 'PASS'], ['one day short', {'res': '2027-05-10T10:00', 'ticket': '2027-05-11T11:00', 'depart': '2027-05-17T08:00', 'ap_days': 7, 'ticket_within_h': 48}, 'FAIL_AP'], ['ticketed at exact time limit', {'res': '2027-06-01T08:00', 'ticket': '2027-06-02T08:00', 'depart': '2027-07-01T08:00', 'ap_days': 21, 'ticket_within_h': 24}, 'PASS'], ['ticketed after time limit', {'res': '2027-06-01T08:00', 'ticket': '2027-06-03T09:20', 'depart': '2027-07-01T08:00', 'ap_days': 21, 'ticket_within_h': 24}, 'FAIL_TKT_TL'], ['ticket before reservation', {'res': '2027-06-01T08:00', 'ticket': '2027-06-01T07:54', 'depart': '2027-07-01T08:00', 'ap_days': 3, 'ticket_within_h': 24}, 'ERR_ORDER'], ['AP and time limit both fail', {'res': '2027-08-01T08:00', 'ticket': '2027-08-05T08:00', 'depart': '2027-08-08T08:00', 'ap_days': 7, 'ticket_within_h': 96}, 'FAIL_AP'], ['sampled case 1', {'res': '2028-04-10T05:15', 'ticket': '2028-04-13T05:15', 'depart': '2028-04-21T10:15', 'ap_days': 14, 'ticket_within_h': 48}, 'FAIL_AP'], ['sampled case 2', {'res': '2029-06-06T12:45', 'ticket': '2029-06-09T12:45', 'depart': '2029-07-06T08:45', 'ap_days': 7, 'ticket_within_h': 24}, 'FAIL_TKT_TL'], ['sampled case 3', {'res': '2029-10-21T12:00', 'ticket': '2029-10-24T12:00', 'depart': '2029-11-15T19:00', 'ap_days': 7, 'ticket_within_h': 48}, 'FAIL_TKT_TL'], ['regression: rule evaluation order', {'res': '2029-02-14T16:30', 'ticket': '2029-02-14T13:30', 'depart': '2029-02-16T10:30', 'ap_days': 7, 'ticket_within_h': 48}, 'ERR_ORDER']], [['late evening ticket, early departure', {'res': '2027-03-01T09:00', 'ticket': '2027-03-01T22:30', 'depart': '2027-03-19T06:00', 'ap_days': 14, 'ticket_within_h': 24}, 'PASS'], ['exactly AP days', {'res': '2027-05-10T10:00', 'ticket': '2027-05-10T11:00', 'depart': '2027-05-17T08:00', 'ap_days': 7, 'ticket_within_h': 29}, 'PASS'], ['one day short', {'res': '2027-05-10T10:00', 'ticket': '2027-05-11T11:00', 'depart': '2027-05-17T08:00', 'ap_days': 7, 'ticket_within_h': 48}, 'FAIL_AP'], ['ticketed at exact time limit', {'res': '2027-06-01T08:00', 'ticket': '2027-06-02T08:00', 'depart': '2027-07-01T08:00', 'ap_days': 21, 'ticket_within_h': 24}, 'PASS'], ['ticketed after time limit', {'res': '2027-06-01T08:00', 'ticket': '2027-06-03T09:25', 'depart': '2027-07-01T08:00', 'ap_days': 21, 'ticket_within_h': 24}, 'FAIL_TKT_TL'], ['ticket before reservation', {'res': '2027-06-01T08:00', 'ticket': '2027-06-01T07:55', 'depart': '2027-07-01T08:00', 'ap_days': 3, 'ticket_within_h': 24}, 'ERR_ORDER'], ['AP and time limit both fail', {'res': '2027-08-01T08:00', 'ticket': '2027-08-05T08:00', 'depart': '2027-08-08T08:00', 'ap_days': 7, 'ticket_within_h': 120}, 'FAIL_AP'], ['sampled case 1', {'res': '2029-04-07T13:45', 'ticket': '2029-04-08T19:15', 'depart': '2029-04-19T08:15', 'ap_days': 3, 'ticket_within_h': 48}, 'PASS'], ['sampled case 2', {'res': '2027-04-03T07:45', 'ticket': '2027-04-05T08:15', 'depart': '2027-05-01T01:15', 'ap_days': 3, 'ticket_within_h': 48}, 'FAIL_TKT_TL'], ['sampled case 3', {'res': '2029-01-24T00:30', 'ticket': '2029-01-25T01:00', 'depart': '2029-02-11T22:00', 'ap_days': 7, 'ticket_within_h': 24}, 'FAIL_TKT_TL'], ['regression: rule evaluation order', {'res': '2028-12-10T18:30', 'ticket': '2028-12-13T06:00', 'depart': '2028-12-26T10:00', 'ap_days': 21, 'ticket_within_h': 24}, 'FAIL_AP'], ['regression: rule evaluation order', {'res': '2028-05-25T16:30', 'ticket': '2028-05-25T14:30', 'depart': '2028-06-02T22:30', 'ap_days': 21, 'ticket_within_h': 24}, 'ERR_ORDER']]]
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 late ticket that also misses advance purchase is reported only as a time-limit failure.

Input {'res','ticket','depart' ISO local datetimes,'ap_days','ticket_within_h'}. Ticket before reservation -> 'ERR_ORDER'. AP counts calendar days between the ticketing date and the departure date (>= ap_days passes) and is checked before the ticketing time limit; ticketing must be at or before reservation + ticket_within_h hours. Return 'PASS', 'FAIL_AP' or 'FAIL_TKT_TL'.

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):
    d = datetime.date.fromisoformat(x['depart'])
    r = datetime.date.fromisoformat(x['return'])
    rule = x['rule']
    fails = []
    if rule['sat_night']:
        sun = d + datetime.timedelta(days=(6 - d.weekday()) % 7)
        if r < sun: fails.append('SAT')
    if (r - d).days < rule['min_days']: fails.append('MIN')
    mo = d.month - 1 + rule['max_months']
    y, mo = d.year + mo // 12, mo % 12 + 1
    last = calendar.monthrange(y, mo)[1]
    eom = d.day == calendar.monthrange(d.year, d.month)[1]
    lim = datetime.date(y, mo, last if eom else min(d.day, last))
    if r > lim: fails.append('MAX')
    return fails
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['Sunday departure next-day return', {'depart': '2027-03-07', 'return': '2027-03-08', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 1}}, ['SAT']], ['Saturday departure Sunday return', {'depart': '2027-03-13', 'return': '2027-03-14', 'rule': {'sat_night': True, 'min_days': 1, 'max_months': 1}}, []], ['Friday out Saturday back', {'depart': '2027-03-12', 'return': '2027-03-13', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 3}}, ['SAT']], ['month-end max stay', {'depart': '2027-02-28', 'return': '2027-03-30', 'rule': {'sat_night': False, 'min_days': 3, 'max_months': 1}}, []], ['the 28th is not month end', {'depart': '2027-04-28', 'return': '2027-05-30', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 1}}, ['MAX']], ['Jan 31 plus one month', {'depart': '2027-01-31', 'return': '2027-02-28', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 1}}, []], ['year rollover max stay', {'depart': '2027-11-11', 'return': '2028-01-10', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 2}}, []], ['exact minimum stay', {'depart': '2027-06-01', 'return': '2027-06-08', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 12}}, []], ['December twelve months', {'depart': '2027-12-15', 'return': '2028-12-14', 'rule': {'sat_night': True, 'min_days': 2, 'max_months': 12}}, []], ['sampled case 1', {'depart': '2029-08-19', 'return': '2029-08-28', 'rule': {'sat_night': True, 'min_days': 2, 'max_months': 2}}, []], ['sampled case 2', {'depart': '2028-06-13', 'return': '2028-12-13', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 12}}, []], ['sampled case 3', {'depart': '2028-04-16', 'return': '2028-08-20', 'rule': {'sat_night': False, 'min_days': 1, 'max_months': 1}}, ['MAX']]], [['Sunday departure next-day return', {'depart': '2027-03-07', 'return': '2027-03-09', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 1}}, ['SAT']], ['Saturday departure Sunday return', {'depart': '2027-03-13', 'return': '2027-03-14', 'rule': {'sat_night': True, 'min_days': 1, 'max_months': 1}}, []], ['Friday out Saturday back', {'depart': '2027-03-12', 'return': '2027-03-13', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 3}}, ['SAT']], ['month-end max stay', {'depart': '2027-02-28', 'return': '2027-03-31', 'rule': {'sat_night': False, 'min_days': 3, 'max_months': 1}}, []], ['the 28th is not month end', {'depart': '2027-04-28', 'return': '2027-05-31', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 1}}, ['MAX']], ['Jan 31 plus one month', {'depart': '2027-01-31', 'return': '2027-02-28', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 1}}, []], ['year rollover max stay', {'depart': '2027-11-12', 'return': '2028-01-12', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 2}}, []], ['exact minimum stay', {'depart': '2027-06-01', 'return': '2027-06-08', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 12}}, []], ['December twelve months', {'depart': '2027-12-15', 'return': '2028-12-15', 'rule': {'sat_night': True, 'min_days': 2, 'max_months': 12}}, []], ['sampled case 1', {'depart': '2029-07-11', 'return': '2029-07-23', 'rule': {'sat_night': True, 'min_days': 7, 'max_months': 12}}, []], ['sampled case 2', {'depart': '2029-06-25', 'return': '2029-12-12', 'rule': {'sat_night': True, 'min_days': 2, 'max_months': 2}}, ['MAX']], ['sampled case 3', {'depart': '2029-02-02', 'return': '2030-02-22', 'rule': {'sat_night': True, 'min_days': 1, 'max_months': 6}}, ['MAX']]], [['Sunday departure next-day return', {'depart': '2027-03-07', 'return': '2027-03-10', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 1}}, ['SAT']], ['Saturday departure Sunday return', {'depart': '2027-03-13', 'return': '2027-03-14', 'rule': {'sat_night': True, 'min_days': 1, 'max_months': 1}}, []], ['Friday out Saturday back', {'depart': '2027-03-12', 'return': '2027-03-13', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 3}}, ['SAT']], ['month-end max stay', {'depart': '2027-02-28', 'return': '2027-03-29', 'rule': {'sat_night': False, 'min_days': 3, 'max_months': 1}}, []], ['the 28th is not month end', {'depart': '2027-04-28', 'return': '2027-05-29', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 1}}, ['MAX']], ['Jan 31 plus one month', {'depart': '2027-01-31', 'return': '2027-02-28', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 1}}, []], ['year rollover max stay', {'depart': '2027-11-13', 'return': '2028-01-14', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 2}}, ['MAX']], ['exact minimum stay', {'depart': '2027-06-01', 'return': '2027-06-08', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 12}}, []], ['December twelve months', {'depart': '2027-12-15', 'return': '2028-12-16', 'rule': {'sat_night': True, 'min_days': 2, 'max_months': 12}}, ['MAX']], ['sampled case 1', {'depart': '2027-10-05', 'return': '2027-10-14', 'rule': {'sat_night': True, 'min_days': 3, 'max_months': 6}}, []], ['sampled case 2', {'depart': '2028-04-06', 'return': '2028-10-12', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 11}}, []], ['sampled case 3', {'depart': '2027-11-12', 'return': '2027-11-21', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 2}}, []]], [['Sunday departure next-day return', {'depart': '2027-03-07', 'return': '2027-03-11', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 1}}, ['SAT']], ['Saturday departure Sunday return', {'depart': '2027-03-13', 'return': '2027-03-14', 'rule': {'sat_night': True, 'min_days': 1, 'max_months': 1}}, []], ['Friday out Saturday back', {'depart': '2027-03-12', 'return': '2027-03-13', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 3}}, ['SAT']], ['month-end max stay', {'depart': '2027-02-28', 'return': '2027-03-30', 'rule': {'sat_night': False, 'min_days': 3, 'max_months': 1}}, []], ['the 28th is not month end', {'depart': '2027-04-28', 'return': '2027-05-30', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 1}}, ['MAX']], ['Jan 31 plus one month', {'depart': '2027-01-31', 'return': '2027-02-28', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 1}}, []], ['year rollover max stay', {'depart': '2027-11-14', 'return': '2028-01-16', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 2}}, ['MAX']], ['exact minimum stay', {'depart': '2027-06-01', 'return': '2027-06-08', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 12}}, []], ['December twelve months', {'depart': '2027-12-15', 'return': '2028-12-17', 'rule': {'sat_night': True, 'min_days': 2, 'max_months': 12}}, ['MAX']], ['sampled case 1', {'depart': '2027-06-01', 'return': '2027-06-09', 'rule': {'sat_night': True, 'min_days': 7, 'max_months': 1}}, []], ['sampled case 2', {'depart': '2028-03-04', 'return': '2028-06-07', 'rule': {'sat_night': True, 'min_days': 1, 'max_months': 6}}, []], ['sampled case 3', {'depart': '2029-03-17', 'return': '2029-03-25', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 12}}, []]], [['Sunday departure next-day return', {'depart': '2027-03-07', 'return': '2027-03-12', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 1}}, ['SAT']], ['Saturday departure Sunday return', {'depart': '2027-03-13', 'return': '2027-03-14', 'rule': {'sat_night': True, 'min_days': 1, 'max_months': 1}}, []], ['Friday out Saturday back', {'depart': '2027-03-12', 'return': '2027-03-13', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 3}}, ['SAT']], ['month-end max stay', {'depart': '2027-02-28', 'return': '2027-03-31', 'rule': {'sat_night': False, 'min_days': 3, 'max_months': 1}}, []], ['the 28th is not month end', {'depart': '2027-04-28', 'return': '2027-05-31', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 1}}, ['MAX']], ['Jan 31 plus one month', {'depart': '2027-01-31', 'return': '2027-02-28', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 1}}, []], ['year rollover max stay', {'depart': '2027-11-15', 'return': '2028-01-18', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 2}}, ['MAX']], ['exact minimum stay', {'depart': '2027-06-01', 'return': '2027-06-08', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 12}}, []], ['December twelve months', {'depart': '2027-12-15', 'return': '2028-12-18', 'rule': {'sat_night': True, 'min_days': 2, 'max_months': 12}}, ['MAX']], ['sampled case 1', {'depart': '2029-08-05', 'return': '2030-07-02', 'rule': {'sat_night': True, 'min_days': 1, 'max_months': 11}}, []], ['sampled case 2', {'depart': '2028-05-10', 'return': '2028-05-12', 'rule': {'sat_night': False, 'min_days': 2, 'max_months': 11}}, []], ['sampled case 3', {'depart': '2027-09-03', 'return': '2027-09-03', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 6}}, ['SAT']]]]
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):
    d = datetime.date.fromisoformat(x['depart'])
    r = datetime.date.fromisoformat(x['return'])
    rule = x['rule']
    fails = []
    if rule['sat_night']:
        sun = d + datetime.timedelta(days=(5 - d.weekday()) % 7)
        if r < sun: fails.append('SAT')
    if (r - d).days < rule['min_days']: fails.append('MIN')
    mo = d.month - 1 + rule['max_months']
    y, mo = d.year + mo // 12, mo % 12 + 1
    last = calendar.monthrange(y, mo)[1]
    eom = d.day == calendar.monthrange(d.year, d.month)[1]
    lim = datetime.date(y, mo, last if eom else min(d.day, last))
    if r > lim: fails.append('MAX')
    return fails
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['Sunday departure next-day return', {'depart': '2027-03-07', 'return': '2027-03-08', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 1}}, ['SAT']], ['Saturday departure Sunday return', {'depart': '2027-03-13', 'return': '2027-03-14', 'rule': {'sat_night': True, 'min_days': 1, 'max_months': 1}}, []], ['Friday out Saturday back', {'depart': '2027-03-12', 'return': '2027-03-13', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 3}}, ['SAT']], ['month-end max stay', {'depart': '2027-02-28', 'return': '2027-03-30', 'rule': {'sat_night': False, 'min_days': 3, 'max_months': 1}}, []], ['the 28th is not month end', {'depart': '2027-04-28', 'return': '2027-05-30', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 1}}, ['MAX']], ['Jan 31 plus one month', {'depart': '2027-01-31', 'return': '2027-02-28', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 1}}, []], ['year rollover max stay', {'depart': '2027-11-11', 'return': '2028-01-10', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 2}}, []], ['exact minimum stay', {'depart': '2027-06-01', 'return': '2027-06-08', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 12}}, []], ['December twelve months', {'depart': '2027-12-15', 'return': '2028-12-14', 'rule': {'sat_night': True, 'min_days': 2, 'max_months': 12}}, []], ['sampled case 1', {'depart': '2029-08-19', 'return': '2029-08-28', 'rule': {'sat_night': True, 'min_days': 2, 'max_months': 2}}, []], ['sampled case 2', {'depart': '2028-06-13', 'return': '2028-12-13', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 12}}, []], ['sampled case 3', {'depart': '2028-04-16', 'return': '2028-08-20', 'rule': {'sat_night': False, 'min_days': 1, 'max_months': 1}}, ['MAX']]], [['Sunday departure next-day return', {'depart': '2027-03-07', 'return': '2027-03-09', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 1}}, ['SAT']], ['Saturday departure Sunday return', {'depart': '2027-03-13', 'return': '2027-03-14', 'rule': {'sat_night': True, 'min_days': 1, 'max_months': 1}}, []], ['Friday out Saturday back', {'depart': '2027-03-12', 'return': '2027-03-13', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 3}}, ['SAT']], ['month-end max stay', {'depart': '2027-02-28', 'return': '2027-03-31', 'rule': {'sat_night': False, 'min_days': 3, 'max_months': 1}}, []], ['the 28th is not month end', {'depart': '2027-04-28', 'return': '2027-05-31', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 1}}, ['MAX']], ['Jan 31 plus one month', {'depart': '2027-01-31', 'return': '2027-02-28', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 1}}, []], ['year rollover max stay', {'depart': '2027-11-12', 'return': '2028-01-12', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 2}}, []], ['exact minimum stay', {'depart': '2027-06-01', 'return': '2027-06-08', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 12}}, []], ['December twelve months', {'depart': '2027-12-15', 'return': '2028-12-15', 'rule': {'sat_night': True, 'min_days': 2, 'max_months': 12}}, []], ['sampled case 1', {'depart': '2029-07-11', 'return': '2029-07-23', 'rule': {'sat_night': True, 'min_days': 7, 'max_months': 12}}, []], ['sampled case 2', {'depart': '2029-06-25', 'return': '2029-12-12', 'rule': {'sat_night': True, 'min_days': 2, 'max_months': 2}}, ['MAX']], ['sampled case 3', {'depart': '2029-02-02', 'return': '2030-02-22', 'rule': {'sat_night': True, 'min_days': 1, 'max_months': 6}}, ['MAX']]], [['Sunday departure next-day return', {'depart': '2027-03-07', 'return': '2027-03-10', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 1}}, ['SAT']], ['Saturday departure Sunday return', {'depart': '2027-03-13', 'return': '2027-03-14', 'rule': {'sat_night': True, 'min_days': 1, 'max_months': 1}}, []], ['Friday out Saturday back', {'depart': '2027-03-12', 'return': '2027-03-13', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 3}}, ['SAT']], ['month-end max stay', {'depart': '2027-02-28', 'return': '2027-03-29', 'rule': {'sat_night': False, 'min_days': 3, 'max_months': 1}}, []], ['the 28th is not month end', {'depart': '2027-04-28', 'return': '2027-05-29', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 1}}, ['MAX']], ['Jan 31 plus one month', {'depart': '2027-01-31', 'return': '2027-02-28', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 1}}, []], ['year rollover max stay', {'depart': '2027-11-13', 'return': '2028-01-14', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 2}}, ['MAX']], ['exact minimum stay', {'depart': '2027-06-01', 'return': '2027-06-08', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 12}}, []], ['December twelve months', {'depart': '2027-12-15', 'return': '2028-12-16', 'rule': {'sat_night': True, 'min_days': 2, 'max_months': 12}}, ['MAX']], ['sampled case 1', {'depart': '2027-10-05', 'return': '2027-10-14', 'rule': {'sat_night': True, 'min_days': 3, 'max_months': 6}}, []], ['sampled case 2', {'depart': '2028-04-06', 'return': '2028-10-12', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 11}}, []], ['sampled case 3', {'depart': '2027-11-12', 'return': '2027-11-21', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 2}}, []]], [['Sunday departure next-day return', {'depart': '2027-03-07', 'return': '2027-03-11', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 1}}, ['SAT']], ['Saturday departure Sunday return', {'depart': '2027-03-13', 'return': '2027-03-14', 'rule': {'sat_night': True, 'min_days': 1, 'max_months': 1}}, []], ['Friday out Saturday back', {'depart': '2027-03-12', 'return': '2027-03-13', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 3}}, ['SAT']], ['month-end max stay', {'depart': '2027-02-28', 'return': '2027-03-30', 'rule': {'sat_night': False, 'min_days': 3, 'max_months': 1}}, []], ['the 28th is not month end', {'depart': '2027-04-28', 'return': '2027-05-30', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 1}}, ['MAX']], ['Jan 31 plus one month', {'depart': '2027-01-31', 'return': '2027-02-28', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 1}}, []], ['year rollover max stay', {'depart': '2027-11-14', 'return': '2028-01-16', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 2}}, ['MAX']], ['exact minimum stay', {'depart': '2027-06-01', 'return': '2027-06-08', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 12}}, []], ['December twelve months', {'depart': '2027-12-15', 'return': '2028-12-17', 'rule': {'sat_night': True, 'min_days': 2, 'max_months': 12}}, ['MAX']], ['sampled case 1', {'depart': '2027-06-01', 'return': '2027-06-09', 'rule': {'sat_night': True, 'min_days': 7, 'max_months': 1}}, []], ['sampled case 2', {'depart': '2028-03-04', 'return': '2028-06-07', 'rule': {'sat_night': True, 'min_days': 1, 'max_months': 6}}, []], ['sampled case 3', {'depart': '2029-03-17', 'return': '2029-03-25', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 12}}, []]], [['Sunday departure next-day return', {'depart': '2027-03-07', 'return': '2027-03-12', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 1}}, ['SAT']], ['Saturday departure Sunday return', {'depart': '2027-03-13', 'return': '2027-03-14', 'rule': {'sat_night': True, 'min_days': 1, 'max_months': 1}}, []], ['Friday out Saturday back', {'depart': '2027-03-12', 'return': '2027-03-13', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 3}}, ['SAT']], ['month-end max stay', {'depart': '2027-02-28', 'return': '2027-03-31', 'rule': {'sat_night': False, 'min_days': 3, 'max_months': 1}}, []], ['the 28th is not month end', {'depart': '2027-04-28', 'return': '2027-05-31', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 1}}, ['MAX']], ['Jan 31 plus one month', {'depart': '2027-01-31', 'return': '2027-02-28', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 1}}, []], ['year rollover max stay', {'depart': '2027-11-15', 'return': '2028-01-18', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 2}}, ['MAX']], ['exact minimum stay', {'depart': '2027-06-01', 'return': '2027-06-08', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 12}}, []], ['December twelve months', {'depart': '2027-12-15', 'return': '2028-12-18', 'rule': {'sat_night': True, 'min_days': 2, 'max_months': 12}}, ['MAX']], ['sampled case 1', {'depart': '2029-08-05', 'return': '2030-07-02', 'rule': {'sat_night': True, 'min_days': 1, 'max_months': 11}}, []], ['sampled case 2', {'depart': '2028-05-10', 'return': '2028-05-12', 'rule': {'sat_night': False, 'min_days': 2, 'max_months': 11}}, []], ['sampled case 3', {'depart': '2027-09-03', 'return': '2027-09-03', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 6}}, ['SAT']]]]
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 traveller leaving Sunday and returning Monday meets the Saturday-night stay.

Input {'depart','return' ISO dates,'rule':{'sat_night','min_days','max_months'}}. Saturday-night rule: return on or after the Sunday following the first Saturday on or after departure. Min stay: return - depart >= min_days. Max stay: return <= departure date plus max_months calendar months; a month-end departure maps to the target month end, otherwise day clamps to month length. Return failed rule names in order SAT, MIN, MAX.

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):
    d = datetime.date.fromisoformat(x['depart'])
    r = datetime.date.fromisoformat(x['return'])
    rule = x['rule']
    fails = []
    if rule['sat_night']:
        sun = d + datetime.timedelta(days=(5 - d.weekday()) % 7 + 1)
        if r < sun: fails.append('SAT')
    if (r - d).days < rule['min_days']: fails.append('MIN')
    mo = d.month - 1 + rule['max_months']
    y, mo = d.year + mo // 12, mo % 12 + 1
    last = calendar.monthrange(y, mo)[1]
    eom = d.day == calendar.monthrange(d.year, d.month)[1]
    lim = d + datetime.timedelta(days=30 * rule['max_months'])
    if r > lim: fails.append('MAX')
    return fails
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['Sunday departure next-day return', {'depart': '2027-03-07', 'return': '2027-03-08', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 1}}, ['SAT']], ['Saturday departure Sunday return', {'depart': '2027-03-13', 'return': '2027-03-14', 'rule': {'sat_night': True, 'min_days': 1, 'max_months': 1}}, []], ['Friday out Saturday back', {'depart': '2027-03-12', 'return': '2027-03-13', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 3}}, ['SAT']], ['month-end max stay', {'depart': '2027-02-28', 'return': '2027-03-30', 'rule': {'sat_night': False, 'min_days': 3, 'max_months': 1}}, []], ['the 28th is not month end', {'depart': '2027-04-28', 'return': '2027-05-30', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 1}}, ['MAX']], ['Jan 31 plus one month', {'depart': '2027-01-31', 'return': '2027-02-28', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 1}}, []], ['year rollover max stay', {'depart': '2027-11-11', 'return': '2028-01-10', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 2}}, []], ['exact minimum stay', {'depart': '2027-06-01', 'return': '2027-06-08', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 12}}, []], ['December twelve months', {'depart': '2027-12-15', 'return': '2028-12-14', 'rule': {'sat_night': True, 'min_days': 2, 'max_months': 12}}, []], ['sampled case 1', {'depart': '2029-08-19', 'return': '2029-08-28', 'rule': {'sat_night': True, 'min_days': 2, 'max_months': 2}}, []], ['sampled case 2', {'depart': '2028-06-13', 'return': '2028-12-13', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 12}}, []], ['sampled case 3', {'depart': '2028-04-16', 'return': '2028-08-20', 'rule': {'sat_night': False, 'min_days': 1, 'max_months': 1}}, ['MAX']], ['regression: maximum stay month arithmetic', {'depart': '2029-11-16', 'return': '2030-10-20', 'rule': {'sat_night': True, 'min_days': 1, 'max_months': 11}}, ['MAX']]], [['Sunday departure next-day return', {'depart': '2027-03-07', 'return': '2027-03-09', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 1}}, ['SAT']], ['Saturday departure Sunday return', {'depart': '2027-03-13', 'return': '2027-03-14', 'rule': {'sat_night': True, 'min_days': 1, 'max_months': 1}}, []], ['Friday out Saturday back', {'depart': '2027-03-12', 'return': '2027-03-13', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 3}}, ['SAT']], ['month-end max stay', {'depart': '2027-02-28', 'return': '2027-03-31', 'rule': {'sat_night': False, 'min_days': 3, 'max_months': 1}}, []], ['the 28th is not month end', {'depart': '2027-04-28', 'return': '2027-05-31', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 1}}, ['MAX']], ['Jan 31 plus one month', {'depart': '2027-01-31', 'return': '2027-02-28', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 1}}, []], ['year rollover max stay', {'depart': '2027-11-12', 'return': '2028-01-12', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 2}}, []], ['exact minimum stay', {'depart': '2027-06-01', 'return': '2027-06-08', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 12}}, []], ['December twelve months', {'depart': '2027-12-15', 'return': '2028-12-15', 'rule': {'sat_night': True, 'min_days': 2, 'max_months': 12}}, []], ['sampled case 1', {'depart': '2029-07-11', 'return': '2029-07-23', 'rule': {'sat_night': True, 'min_days': 7, 'max_months': 12}}, []], ['sampled case 2', {'depart': '2029-06-25', 'return': '2029-12-12', 'rule': {'sat_night': True, 'min_days': 2, 'max_months': 2}}, ['MAX']], ['sampled case 3', {'depart': '2029-02-02', 'return': '2030-02-22', 'rule': {'sat_night': True, 'min_days': 1, 'max_months': 6}}, ['MAX']], ['regression: maximum stay month arithmetic', {'depart': '2027-11-13', 'return': '2028-11-15', 'rule': {'sat_night': True, 'min_days': 1, 'max_months': 12}}, ['MAX']]], [['Sunday departure next-day return', {'depart': '2027-03-07', 'return': '2027-03-10', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 1}}, ['SAT']], ['Saturday departure Sunday return', {'depart': '2027-03-13', 'return': '2027-03-14', 'rule': {'sat_night': True, 'min_days': 1, 'max_months': 1}}, []], ['Friday out Saturday back', {'depart': '2027-03-12', 'return': '2027-03-13', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 3}}, ['SAT']], ['month-end max stay', {'depart': '2027-02-28', 'return': '2027-03-29', 'rule': {'sat_night': False, 'min_days': 3, 'max_months': 1}}, []], ['the 28th is not month end', {'depart': '2027-04-28', 'return': '2027-05-29', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 1}}, ['MAX']], ['Jan 31 plus one month', {'depart': '2027-01-31', 'return': '2027-02-28', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 1}}, []], ['year rollover max stay', {'depart': '2027-11-13', 'return': '2028-01-14', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 2}}, ['MAX']], ['exact minimum stay', {'depart': '2027-06-01', 'return': '2027-06-08', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 12}}, []], ['December twelve months', {'depart': '2027-12-15', 'return': '2028-12-16', 'rule': {'sat_night': True, 'min_days': 2, 'max_months': 12}}, ['MAX']], ['sampled case 1', {'depart': '2027-10-05', 'return': '2027-10-14', 'rule': {'sat_night': True, 'min_days': 3, 'max_months': 6}}, []], ['sampled case 2', {'depart': '2028-04-06', 'return': '2028-10-12', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 11}}, []], ['sampled case 3', {'depart': '2027-11-12', 'return': '2027-11-21', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 2}}, []], ['regression: maximum stay month arithmetic', {'depart': '2027-08-11', 'return': '2028-07-11', 'rule': {'sat_night': True, 'min_days': 7, 'max_months': 11}}, []]], [['Sunday departure next-day return', {'depart': '2027-03-07', 'return': '2027-03-11', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 1}}, ['SAT']], ['Saturday departure Sunday return', {'depart': '2027-03-13', 'return': '2027-03-14', 'rule': {'sat_night': True, 'min_days': 1, 'max_months': 1}}, []], ['Friday out Saturday back', {'depart': '2027-03-12', 'return': '2027-03-13', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 3}}, ['SAT']], ['month-end max stay', {'depart': '2027-02-28', 'return': '2027-03-30', 'rule': {'sat_night': False, 'min_days': 3, 'max_months': 1}}, []], ['the 28th is not month end', {'depart': '2027-04-28', 'return': '2027-05-30', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 1}}, ['MAX']], ['Jan 31 plus one month', {'depart': '2027-01-31', 'return': '2027-02-28', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 1}}, []], ['year rollover max stay', {'depart': '2027-11-14', 'return': '2028-01-16', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 2}}, ['MAX']], ['exact minimum stay', {'depart': '2027-06-01', 'return': '2027-06-08', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 12}}, []], ['December twelve months', {'depart': '2027-12-15', 'return': '2028-12-17', 'rule': {'sat_night': True, 'min_days': 2, 'max_months': 12}}, ['MAX']], ['sampled case 1', {'depart': '2027-06-01', 'return': '2027-06-09', 'rule': {'sat_night': True, 'min_days': 7, 'max_months': 1}}, []], ['sampled case 2', {'depart': '2028-03-04', 'return': '2028-06-07', 'rule': {'sat_night': True, 'min_days': 1, 'max_months': 6}}, []], ['sampled case 3', {'depart': '2029-03-17', 'return': '2029-03-25', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 12}}, []], ['regression: maximum stay month arithmetic', {'depart': '2027-04-05', 'return': '2028-03-01', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 11}}, []]], [['Sunday departure next-day return', {'depart': '2027-03-07', 'return': '2027-03-12', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 1}}, ['SAT']], ['Saturday departure Sunday return', {'depart': '2027-03-13', 'return': '2027-03-14', 'rule': {'sat_night': True, 'min_days': 1, 'max_months': 1}}, []], ['Friday out Saturday back', {'depart': '2027-03-12', 'return': '2027-03-13', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 3}}, ['SAT']], ['month-end max stay', {'depart': '2027-02-28', 'return': '2027-03-31', 'rule': {'sat_night': False, 'min_days': 3, 'max_months': 1}}, []], ['the 28th is not month end', {'depart': '2027-04-28', 'return': '2027-05-31', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 1}}, ['MAX']], ['Jan 31 plus one month', {'depart': '2027-01-31', 'return': '2027-02-28', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 1}}, []], ['year rollover max stay', {'depart': '2027-11-15', 'return': '2028-01-18', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 2}}, ['MAX']], ['exact minimum stay', {'depart': '2027-06-01', 'return': '2027-06-08', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 12}}, []], ['December twelve months', {'depart': '2027-12-15', 'return': '2028-12-18', 'rule': {'sat_night': True, 'min_days': 2, 'max_months': 12}}, ['MAX']], ['sampled case 1', {'depart': '2029-08-05', 'return': '2030-07-02', 'rule': {'sat_night': True, 'min_days': 1, 'max_months': 11}}, []], ['sampled case 2', {'depart': '2028-05-10', 'return': '2028-05-12', 'rule': {'sat_night': False, 'min_days': 2, 'max_months': 11}}, []], ['sampled case 3', {'depart': '2027-09-03', 'return': '2027-09-03', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 6}}, ['SAT']]]]
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):
    d = datetime.date.fromisoformat(x['depart'])
    r = datetime.date.fromisoformat(x['return'])
    rule = x['rule']
    fails = []
    if rule['sat_night']:
        sun = d + datetime.timedelta(days=(5 - d.weekday()) % 7 + 1)
        if r < sun: fails.append('SAT')
    if (r - d).days < rule['min_days']: fails.append('MIN')
    mo = d.month - 1 + rule['max_months']
    y, mo = d.year + mo // 12, mo % 12 + 1
    last = calendar.monthrange(y, mo)[1]
    eom = d.day == calendar.monthrange(d.year, d.month)[1]
    lim = d + datetime.timedelta(days=31 * rule['max_months'])
    if r > lim: fails.append('MAX')
    return fails
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['Sunday departure next-day return', {'depart': '2027-03-07', 'return': '2027-03-08', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 1}}, ['SAT']], ['Saturday departure Sunday return', {'depart': '2027-03-13', 'return': '2027-03-14', 'rule': {'sat_night': True, 'min_days': 1, 'max_months': 1}}, []], ['Friday out Saturday back', {'depart': '2027-03-12', 'return': '2027-03-13', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 3}}, ['SAT']], ['month-end max stay', {'depart': '2027-02-28', 'return': '2027-03-30', 'rule': {'sat_night': False, 'min_days': 3, 'max_months': 1}}, []], ['the 28th is not month end', {'depart': '2027-04-28', 'return': '2027-05-30', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 1}}, ['MAX']], ['Jan 31 plus one month', {'depart': '2027-01-31', 'return': '2027-02-28', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 1}}, []], ['year rollover max stay', {'depart': '2027-11-11', 'return': '2028-01-10', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 2}}, []], ['exact minimum stay', {'depart': '2027-06-01', 'return': '2027-06-08', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 12}}, []], ['December twelve months', {'depart': '2027-12-15', 'return': '2028-12-14', 'rule': {'sat_night': True, 'min_days': 2, 'max_months': 12}}, []], ['sampled case 1', {'depart': '2029-08-19', 'return': '2029-08-28', 'rule': {'sat_night': True, 'min_days': 2, 'max_months': 2}}, []], ['sampled case 2', {'depart': '2028-06-13', 'return': '2028-12-13', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 12}}, []], ['sampled case 3', {'depart': '2028-04-16', 'return': '2028-08-20', 'rule': {'sat_night': False, 'min_days': 1, 'max_months': 1}}, ['MAX']], ['regression: maximum stay month arithmetic', {'depart': '2029-11-16', 'return': '2030-10-20', 'rule': {'sat_night': True, 'min_days': 1, 'max_months': 11}}, ['MAX']]], [['Sunday departure next-day return', {'depart': '2027-03-07', 'return': '2027-03-09', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 1}}, ['SAT']], ['Saturday departure Sunday return', {'depart': '2027-03-13', 'return': '2027-03-14', 'rule': {'sat_night': True, 'min_days': 1, 'max_months': 1}}, []], ['Friday out Saturday back', {'depart': '2027-03-12', 'return': '2027-03-13', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 3}}, ['SAT']], ['month-end max stay', {'depart': '2027-02-28', 'return': '2027-03-31', 'rule': {'sat_night': False, 'min_days': 3, 'max_months': 1}}, []], ['the 28th is not month end', {'depart': '2027-04-28', 'return': '2027-05-31', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 1}}, ['MAX']], ['Jan 31 plus one month', {'depart': '2027-01-31', 'return': '2027-02-28', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 1}}, []], ['year rollover max stay', {'depart': '2027-11-12', 'return': '2028-01-12', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 2}}, []], ['exact minimum stay', {'depart': '2027-06-01', 'return': '2027-06-08', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 12}}, []], ['December twelve months', {'depart': '2027-12-15', 'return': '2028-12-15', 'rule': {'sat_night': True, 'min_days': 2, 'max_months': 12}}, []], ['sampled case 1', {'depart': '2029-07-11', 'return': '2029-07-23', 'rule': {'sat_night': True, 'min_days': 7, 'max_months': 12}}, []], ['sampled case 2', {'depart': '2029-06-25', 'return': '2029-12-12', 'rule': {'sat_night': True, 'min_days': 2, 'max_months': 2}}, ['MAX']], ['sampled case 3', {'depart': '2029-02-02', 'return': '2030-02-22', 'rule': {'sat_night': True, 'min_days': 1, 'max_months': 6}}, ['MAX']], ['regression: maximum stay month arithmetic', {'depart': '2027-11-13', 'return': '2028-11-15', 'rule': {'sat_night': True, 'min_days': 1, 'max_months': 12}}, ['MAX']]], [['Sunday departure next-day return', {'depart': '2027-03-07', 'return': '2027-03-10', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 1}}, ['SAT']], ['Saturday departure Sunday return', {'depart': '2027-03-13', 'return': '2027-03-14', 'rule': {'sat_night': True, 'min_days': 1, 'max_months': 1}}, []], ['Friday out Saturday back', {'depart': '2027-03-12', 'return': '2027-03-13', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 3}}, ['SAT']], ['month-end max stay', {'depart': '2027-02-28', 'return': '2027-03-29', 'rule': {'sat_night': False, 'min_days': 3, 'max_months': 1}}, []], ['the 28th is not month end', {'depart': '2027-04-28', 'return': '2027-05-29', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 1}}, ['MAX']], ['Jan 31 plus one month', {'depart': '2027-01-31', 'return': '2027-02-28', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 1}}, []], ['year rollover max stay', {'depart': '2027-11-13', 'return': '2028-01-14', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 2}}, ['MAX']], ['exact minimum stay', {'depart': '2027-06-01', 'return': '2027-06-08', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 12}}, []], ['December twelve months', {'depart': '2027-12-15', 'return': '2028-12-16', 'rule': {'sat_night': True, 'min_days': 2, 'max_months': 12}}, ['MAX']], ['sampled case 1', {'depart': '2027-10-05', 'return': '2027-10-14', 'rule': {'sat_night': True, 'min_days': 3, 'max_months': 6}}, []], ['sampled case 2', {'depart': '2028-04-06', 'return': '2028-10-12', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 11}}, []], ['sampled case 3', {'depart': '2027-11-12', 'return': '2027-11-21', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 2}}, []], ['regression: maximum stay month arithmetic', {'depart': '2027-08-11', 'return': '2028-07-11', 'rule': {'sat_night': True, 'min_days': 7, 'max_months': 11}}, []]], [['Sunday departure next-day return', {'depart': '2027-03-07', 'return': '2027-03-11', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 1}}, ['SAT']], ['Saturday departure Sunday return', {'depart': '2027-03-13', 'return': '2027-03-14', 'rule': {'sat_night': True, 'min_days': 1, 'max_months': 1}}, []], ['Friday out Saturday back', {'depart': '2027-03-12', 'return': '2027-03-13', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 3}}, ['SAT']], ['month-end max stay', {'depart': '2027-02-28', 'return': '2027-03-30', 'rule': {'sat_night': False, 'min_days': 3, 'max_months': 1}}, []], ['the 28th is not month end', {'depart': '2027-04-28', 'return': '2027-05-30', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 1}}, ['MAX']], ['Jan 31 plus one month', {'depart': '2027-01-31', 'return': '2027-02-28', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 1}}, []], ['year rollover max stay', {'depart': '2027-11-14', 'return': '2028-01-16', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 2}}, ['MAX']], ['exact minimum stay', {'depart': '2027-06-01', 'return': '2027-06-08', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 12}}, []], ['December twelve months', {'depart': '2027-12-15', 'return': '2028-12-17', 'rule': {'sat_night': True, 'min_days': 2, 'max_months': 12}}, ['MAX']], ['sampled case 1', {'depart': '2027-06-01', 'return': '2027-06-09', 'rule': {'sat_night': True, 'min_days': 7, 'max_months': 1}}, []], ['sampled case 2', {'depart': '2028-03-04', 'return': '2028-06-07', 'rule': {'sat_night': True, 'min_days': 1, 'max_months': 6}}, []], ['sampled case 3', {'depart': '2029-03-17', 'return': '2029-03-25', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 12}}, []], ['regression: maximum stay month arithmetic', {'depart': '2027-04-05', 'return': '2028-03-01', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 11}}, []]], [['Sunday departure next-day return', {'depart': '2027-03-07', 'return': '2027-03-12', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 1}}, ['SAT']], ['Saturday departure Sunday return', {'depart': '2027-03-13', 'return': '2027-03-14', 'rule': {'sat_night': True, 'min_days': 1, 'max_months': 1}}, []], ['Friday out Saturday back', {'depart': '2027-03-12', 'return': '2027-03-13', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 3}}, ['SAT']], ['month-end max stay', {'depart': '2027-02-28', 'return': '2027-03-31', 'rule': {'sat_night': False, 'min_days': 3, 'max_months': 1}}, []], ['the 28th is not month end', {'depart': '2027-04-28', 'return': '2027-05-31', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 1}}, ['MAX']], ['Jan 31 plus one month', {'depart': '2027-01-31', 'return': '2027-02-28', 'rule': {'sat_night': False, 'min_days': 0, 'max_months': 1}}, []], ['year rollover max stay', {'depart': '2027-11-15', 'return': '2028-01-18', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 2}}, ['MAX']], ['exact minimum stay', {'depart': '2027-06-01', 'return': '2027-06-08', 'rule': {'sat_night': False, 'min_days': 7, 'max_months': 12}}, []], ['December twelve months', {'depart': '2027-12-15', 'return': '2028-12-18', 'rule': {'sat_night': True, 'min_days': 2, 'max_months': 12}}, ['MAX']], ['sampled case 1', {'depart': '2029-08-05', 'return': '2030-07-02', 'rule': {'sat_night': True, 'min_days': 1, 'max_months': 11}}, []], ['sampled case 2', {'depart': '2028-05-10', 'return': '2028-05-12', 'rule': {'sat_night': False, 'min_days': 2, 'max_months': 11}}, []], ['sampled case 3', {'depart': '2027-09-03', 'return': '2027-09-03', 'rule': {'sat_night': True, 'min_days': 0, 'max_months': 6}}, ['SAT']]]]
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 one-month maximum stay departing 1 January expires on 31 January instead of 1 February.

Input {'depart','return' ISO dates,'rule':{'sat_night','min_days','max_months'}}. Saturday-night rule: return on or after the Sunday following the first Saturday on or after departure. Min stay: return - depart >= min_days. Max stay: return <= departure date plus max_months calendar months; a month-end departure maps to the target month end, otherwise day clamps to month length. Return failed rule names in order SAT, MIN, MAX.

split: open-access