broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
N = 1
observations = []
def solve(x):
    segs = x['segments']
    stops = 0
    for (d0, a0, dom0), (d1, a1, dom1) in zip(segs, segs[1:]):
        gap = (datetime.datetime.fromisoformat(d1) - datetime.datetime.fromisoformat(a0)).total_seconds() / 3600
        limit = 4 if (dom0 and dom1) else 24
        if gap >= limit: stops += 1
    transfers = len(segs) - 1
    fails = []
    if stops > x['max_stopovers']: fails.append('STOPOVERS')
    if transfers > x['max_transfers']: fails.append('TRANSFERS')
    return [stops, transfers, fails]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['international 24h exactly', {'segments': [['2027-05-01T10:00', '2027-05-01T18:00', False], ['2027-05-02T18:00', '2027-05-02T23:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['domestic five hour connection', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T14:01', '2027-05-01T16:00', True]], 'max_stopovers': 0, 'max_transfers': 1}, [1, 1, ['STOPOVERS']]], ['mixed connection 6h', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T15:00', '2027-05-02T07:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['long flight short connection', {'segments': [['2027-05-01T07:00', '2027-05-02T01:00', False], ['2027-05-02T03:00', '2027-05-02T09:00', False], ['2027-05-03T10:00', '2027-05-03T12:00', False]], 'max_stopovers': 1, 'max_transfers': 1}, [1, 2, ['TRANSFERS']]], ['three stopovers', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', False], ['2027-05-03T07:00', '2027-05-03T09:00', False], ['2027-05-05T07:00', '2027-05-05T09:00', False], ['2027-05-07T07:00', '2027-05-09T09:00', False]], 'max_stopovers': 2, 'max_transfers': 3}, [3, 3, ['STOPOVERS']]], ['nonstop', {'segments': [['2027-05-01T07:00', '2027-05-01T09:01', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 0, []]], ['sampled case 1', {'segments': [['2029-07-06T05:00', '2029-07-06T16:00', False], ['2029-07-06T19:00', '2029-07-06T20:30', False], ['2029-07-07T00:30', '2029-07-07T14:30', False]], 'max_stopovers': 2, 'max_transfers': 2}, [0, 2, []]], ['sampled case 2', {'segments': [['2029-04-03T21:30', '2029-04-04T07:30', True]], 'max_stopovers': 2, 'max_transfers': 3}, [0, 0, []]], ['sampled case 3', {'segments': [['2028-08-09T11:30', '2028-08-09T19:00', False], ['2028-08-09T20:30', '2028-08-10T07:00', False], ['2028-08-10T12:00', '2028-08-10T18:30', True], ['2028-08-10T20:00', '2028-08-11T07:30', True]], 'max_stopovers': 2, 'max_transfers': 3}, [0, 3, []]], ['regression: stopover threshold boundary', {'segments': [['2027-03-20T11:00', '2027-03-20T13:00', False], ['2027-03-20T17:00', '2027-03-20T23:00', True], ['2027-03-21T23:30', '2027-03-22T08:30', False], ['2027-03-22T13:30', '2027-03-22T16:00', True], ['2027-03-22T19:00', '2027-03-23T06:30', False]], 'max_stopovers': 0, 'max_transfers': 2}, [1, 4, ['STOPOVERS', 'TRANSFERS']]]], [['international 24h exactly', {'segments': [['2027-05-01T10:00', '2027-05-01T18:00', False], ['2027-05-02T18:00', '2027-05-02T23:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['domestic five hour connection', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T14:02', '2027-05-01T16:00', True]], 'max_stopovers': 0, 'max_transfers': 1}, [1, 1, ['STOPOVERS']]], ['mixed connection 6h', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T15:00', '2027-05-02T07:00', False]], 'max_stopovers': 0, 'max_transfers': 1}, [0, 1, []]], ['long flight short connection', {'segments': [['2027-05-01T07:00', '2027-05-02T01:00', False], ['2027-05-02T03:00', '2027-05-02T09:00', False], ['2027-05-03T10:00', '2027-05-03T12:00', False]], 'max_stopovers': 1, 'max_transfers': 1}, [1, 2, ['TRANSFERS']]], ['three stopovers', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', False], ['2027-05-03T07:00', '2027-05-03T09:00', False], ['2027-05-05T07:00', '2027-05-05T09:00', False], ['2027-05-08T07:00', '2027-05-09T09:00', False]], 'max_stopovers': 2, 'max_transfers': 3}, [3, 3, ['STOPOVERS']]], ['nonstop', {'segments': [['2027-05-01T07:00', '2027-05-01T09:02', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 0, []]], ['sampled case 1', {'segments': [['2028-08-14T16:45', '2028-08-15T03:45', False], ['2028-08-17T03:45', '2028-08-17T17:45', False], ['2028-08-17T22:45', '2028-08-18T09:15', True], ['2028-08-18T13:15', '2028-08-18T22:45', False], ['2028-08-19T18:45', '2028-08-20T06:45', False]], 'max_stopovers': 2, 'max_transfers': 1}, [1, 4, ['TRANSFERS']]], ['sampled case 2', {'segments': [['2027-06-01T12:45', '2027-06-01T20:15', True], ['2027-06-01T22:15', '2027-06-02T11:45', True], ['2027-06-03T11:45', '2027-06-03T21:45', True]], 'max_stopovers': 1, 'max_transfers': 2}, [1, 2, []]], ['sampled case 3', {'segments': [['2027-07-21T03:00', '2027-07-21T07:00', False], ['2027-07-22T03:00', '2027-07-22T08:30', False], ['2027-07-22T09:30', '2027-07-22T16:30', False], ['2027-07-22T17:30', '2027-07-22T23:00', False], ['2027-07-23T19:00', '2027-07-24T00:00', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 4, ['TRANSFERS']]], ['regression: stopover threshold boundary', {'segments': [['2028-11-08T02:30', '2028-11-08T15:00', True], ['2028-11-10T15:30', '2028-11-10T21:00', True], ['2028-11-11T21:30', '2028-11-12T03:00', True], ['2028-11-12T08:00', '2028-11-12T10:30', False], ['2028-11-13T11:00', '2028-11-13T12:00', True]], 'max_stopovers': 1, 'max_transfers': 0}, [3, 4, ['STOPOVERS', 'TRANSFERS']]]], [['international 24h exactly', {'segments': [['2027-05-01T10:00', '2027-05-01T18:00', False], ['2027-05-02T18:00', '2027-05-02T23:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['domestic five hour connection', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T14:03', '2027-05-01T16:00', True]], 'max_stopovers': 0, 'max_transfers': 1}, [1, 1, ['STOPOVERS']]], ['mixed connection 6h', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T15:00', '2027-05-02T07:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['long flight short connection', {'segments': [['2027-05-01T07:00', '2027-05-02T01:00', False], ['2027-05-02T03:00', '2027-05-02T09:00', False], ['2027-05-03T10:00', '2027-05-03T12:00', False]], 'max_stopovers': 1, 'max_transfers': 1}, [1, 2, ['TRANSFERS']]], ['three stopovers', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', False], ['2027-05-03T07:00', '2027-05-03T09:00', False], ['2027-05-05T07:00', '2027-05-05T09:00', False], ['2027-05-06T07:00', '2027-05-09T09:00', False]], 'max_stopovers': 2, 'max_transfers': 3}, [2, 3, []]], ['nonstop', {'segments': [['2027-05-01T07:00', '2027-05-01T09:03', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 0, []]], ['sampled case 1', {'segments': [['2027-02-15T21:15', '2027-02-15T23:15', True], ['2027-02-16T07:45', '2027-02-16T18:45', True], ['2027-02-17T02:45', '2027-02-17T13:45', False], ['2027-02-17T22:15', '2027-02-18T00:45', False], ['2027-02-18T20:45', '2027-02-19T02:15', False]], 'max_stopovers': 1, 'max_transfers': 3}, [1, 4, ['TRANSFERS']]], ['sampled case 2', {'segments': [['2029-05-25T20:00', '2029-05-26T01:00', True], ['2029-05-27T02:00', '2029-05-27T07:00', False], ['2029-05-28T08:30', '2029-05-28T17:00', False], ['2029-05-28T19:00', '2029-05-29T07:30', False], ['2029-05-29T09:30', '2029-05-29T13:00', False]], 'max_stopovers': 1, 'max_transfers': 3}, [2, 4, ['STOPOVERS', 'TRANSFERS']]], ['sampled case 3', {'segments': [['2028-09-07T21:45', '2028-09-08T03:15', True], ['2028-09-08T23:15', '2028-09-09T11:15', True], ['2028-09-10T11:15', '2028-09-10T14:45', False], ['2028-09-12T14:45', '2028-09-13T04:45', True], ['2028-09-13T05:45', '2028-09-13T20:15', True]], 'max_stopovers': 0, 'max_transfers': 2}, [2, 4, ['STOPOVERS', 'TRANSFERS']]], ['regression: stopover threshold boundary', {'segments': [['2027-04-06T14:30', '2027-04-06T17:00', True], ['2027-04-06T20:30', '2027-04-07T04:30', False], ['2027-04-07T12:30', '2027-04-07T19:30', True], ['2027-04-08T20:00', '2027-04-09T00:30', False], ['2027-04-09T02:30', '2027-04-09T03:30', True]], 'max_stopovers': 2, 'max_transfers': 3}, [1, 4, ['TRANSFERS']]]], [['international 24h exactly', {'segments': [['2027-05-01T10:00', '2027-05-01T18:00', False], ['2027-05-02T18:00', '2027-05-02T23:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['domestic five hour connection', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T14:04', '2027-05-01T16:00', True]], 'max_stopovers': 0, 'max_transfers': 1}, [1, 1, ['STOPOVERS']]], ['mixed connection 6h', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T15:00', '2027-05-02T07:00', False]], 'max_stopovers': 0, 'max_transfers': 1}, [0, 1, []]], ['long flight short connection', {'segments': [['2027-05-01T07:00', '2027-05-02T01:00', False], ['2027-05-02T03:00', '2027-05-02T09:00', False], ['2027-05-03T10:00', '2027-05-03T12:00', False]], 'max_stopovers': 1, 'max_transfers': 1}, [1, 2, ['TRANSFERS']]], ['three stopovers', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', False], ['2027-05-03T07:00', '2027-05-03T09:00', False], ['2027-05-05T07:00', '2027-05-05T09:00', False], ['2027-05-07T07:00', '2027-05-09T09:00', False]], 'max_stopovers': 2, 'max_transfers': 3}, [3, 3, ['STOPOVERS']]], ['nonstop', {'segments': [['2027-05-01T07:00', '2027-05-01T09:04', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 0, []]], ['sampled case 1', {'segments': [['2027-11-27T17:15', '2027-11-27T23:45', False], ['2027-11-28T01:45', '2027-11-28T11:45', False]], 'max_stopovers': 2, 'max_transfers': 3}, [0, 1, []]], ['sampled case 2', {'segments': [['2029-03-09T18:00', '2029-03-10T02:00', True], ['2029-03-10T03:00', '2029-03-10T12:00', True]], 'max_stopovers': 1, 'max_transfers': 2}, [0, 1, []]], ['sampled case 3', {'segments': [['2029-03-20T20:00', '2029-03-20T23:30', True], ['2029-03-21T02:30', '2029-03-21T12:00', False], ['2029-03-23T12:00', '2029-03-23T16:00', False], ['2029-03-23T21:00', '2029-03-24T01:30', False], ['2029-03-24T02:30', '2029-03-24T12:00', False]], 'max_stopovers': 1, 'max_transfers': 0}, [1, 4, ['TRANSFERS']]], ['regression: stopover threshold boundary', {'segments': [['2028-06-19T07:45', '2028-06-19T16:45', False], ['2028-06-20T12:45', '2028-06-20T17:15', False], ['2028-06-21T17:45', '2028-06-22T01:45', False], ['2028-06-22T03:45', '2028-06-22T15:15', False], ['2028-06-23T16:15', '2028-06-24T01:15', False]], 'max_stopovers': 1, 'max_transfers': 1}, [2, 4, ['STOPOVERS', 'TRANSFERS']]]], [['international 24h exactly', {'segments': [['2027-05-01T10:00', '2027-05-01T18:00', False], ['2027-05-02T18:00', '2027-05-02T23:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['domestic five hour connection', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T14:05', '2027-05-01T16:00', True]], 'max_stopovers': 0, 'max_transfers': 1}, [1, 1, ['STOPOVERS']]], ['mixed connection 6h', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T15:00', '2027-05-02T07:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['long flight short connection', {'segments': [['2027-05-01T07:00', '2027-05-02T01:00', False], ['2027-05-02T03:00', '2027-05-02T09:00', False], ['2027-05-03T10:00', '2027-05-03T12:00', False]], 'max_stopovers': 1, 'max_transfers': 1}, [1, 2, ['TRANSFERS']]], ['three stopovers', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', False], ['2027-05-03T07:00', '2027-05-03T09:00', False], ['2027-05-05T07:00', '2027-05-05T09:00', False], ['2027-05-08T07:00', '2027-05-09T09:00', False]], 'max_stopovers': 2, 'max_transfers': 3}, [3, 3, ['STOPOVERS']]], ['nonstop', {'segments': [['2027-05-01T07:00', '2027-05-01T09:05', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 0, []]], ['sampled case 1', {'segments': [['2027-02-17T17:30', '2027-02-17T20:00', False]], 'max_stopovers': 1, 'max_transfers': 0}, [0, 0, []]], ['sampled case 2', {'segments': [['2029-07-05T21:30', '2029-07-06T01:30', False], ['2029-07-06T02:30', '2029-07-06T07:30', True], ['2029-07-06T09:00', '2029-07-06T23:00', True], ['2029-07-08T00:30', '2029-07-08T15:00', True], ['2029-07-08T18:30', '2029-07-09T04:30', False]], 'max_stopovers': 2, 'max_transfers': 2}, [1, 4, ['TRANSFERS']]], ['sampled case 3', {'segments': [['2027-06-10T18:15', '2027-06-10T19:15', False], ['2027-06-10T22:45', '2027-06-11T12:15', True]], 'max_stopovers': 0, 'max_transfers': 3}, [0, 1, []]], ['regression: stopover threshold boundary', {'segments': [['2027-02-12T09:30', '2027-02-12T16:00', True], ['2027-02-13T00:00', '2027-02-13T02:00', False], ['2027-02-14T02:00', '2027-02-14T11:00', False], ['2027-02-14T16:00', '2027-02-15T00:00', True], ['2027-02-15T04:30', '2027-02-15T16:00', True]], 'max_stopovers': 0, 'max_transfers': 1}, [1, 4, ['STOPOVERS', 'TRANSFERS']]]]]
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):
    segs = x['segments']
    stops = 0
    for (d0, a0, dom0), (d1, a1, dom1) in zip(segs, segs[1:]):
        gap = (datetime.datetime.fromisoformat(d1) - datetime.datetime.fromisoformat(a0)).total_seconds() / 3600
        limit = 4 if (dom0 and dom1) else 24
        if round(gap) > limit: stops += 1
    transfers = len(segs) - 1
    fails = []
    if stops > x['max_stopovers']: fails.append('STOPOVERS')
    if transfers > x['max_transfers']: fails.append('TRANSFERS')
    return [stops, transfers, fails]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['international 24h exactly', {'segments': [['2027-05-01T10:00', '2027-05-01T18:00', False], ['2027-05-02T18:00', '2027-05-02T23:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['domestic five hour connection', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T14:01', '2027-05-01T16:00', True]], 'max_stopovers': 0, 'max_transfers': 1}, [1, 1, ['STOPOVERS']]], ['mixed connection 6h', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T15:00', '2027-05-02T07:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['long flight short connection', {'segments': [['2027-05-01T07:00', '2027-05-02T01:00', False], ['2027-05-02T03:00', '2027-05-02T09:00', False], ['2027-05-03T10:00', '2027-05-03T12:00', False]], 'max_stopovers': 1, 'max_transfers': 1}, [1, 2, ['TRANSFERS']]], ['three stopovers', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', False], ['2027-05-03T07:00', '2027-05-03T09:00', False], ['2027-05-05T07:00', '2027-05-05T09:00', False], ['2027-05-07T07:00', '2027-05-09T09:00', False]], 'max_stopovers': 2, 'max_transfers': 3}, [3, 3, ['STOPOVERS']]], ['nonstop', {'segments': [['2027-05-01T07:00', '2027-05-01T09:01', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 0, []]], ['sampled case 1', {'segments': [['2029-07-06T05:00', '2029-07-06T16:00', False], ['2029-07-06T19:00', '2029-07-06T20:30', False], ['2029-07-07T00:30', '2029-07-07T14:30', False]], 'max_stopovers': 2, 'max_transfers': 2}, [0, 2, []]], ['sampled case 2', {'segments': [['2029-04-03T21:30', '2029-04-04T07:30', True]], 'max_stopovers': 2, 'max_transfers': 3}, [0, 0, []]], ['sampled case 3', {'segments': [['2028-08-09T11:30', '2028-08-09T19:00', False], ['2028-08-09T20:30', '2028-08-10T07:00', False], ['2028-08-10T12:00', '2028-08-10T18:30', True], ['2028-08-10T20:00', '2028-08-11T07:30', True]], 'max_stopovers': 2, 'max_transfers': 3}, [0, 3, []]], ['regression: stopover threshold boundary', {'segments': [['2027-03-20T11:00', '2027-03-20T13:00', False], ['2027-03-20T17:00', '2027-03-20T23:00', True], ['2027-03-21T23:30', '2027-03-22T08:30', False], ['2027-03-22T13:30', '2027-03-22T16:00', True], ['2027-03-22T19:00', '2027-03-23T06:30', False]], 'max_stopovers': 0, 'max_transfers': 2}, [1, 4, ['STOPOVERS', 'TRANSFERS']]]], [['international 24h exactly', {'segments': [['2027-05-01T10:00', '2027-05-01T18:00', False], ['2027-05-02T18:00', '2027-05-02T23:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['domestic five hour connection', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T14:02', '2027-05-01T16:00', True]], 'max_stopovers': 0, 'max_transfers': 1}, [1, 1, ['STOPOVERS']]], ['mixed connection 6h', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T15:00', '2027-05-02T07:00', False]], 'max_stopovers': 0, 'max_transfers': 1}, [0, 1, []]], ['long flight short connection', {'segments': [['2027-05-01T07:00', '2027-05-02T01:00', False], ['2027-05-02T03:00', '2027-05-02T09:00', False], ['2027-05-03T10:00', '2027-05-03T12:00', False]], 'max_stopovers': 1, 'max_transfers': 1}, [1, 2, ['TRANSFERS']]], ['three stopovers', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', False], ['2027-05-03T07:00', '2027-05-03T09:00', False], ['2027-05-05T07:00', '2027-05-05T09:00', False], ['2027-05-08T07:00', '2027-05-09T09:00', False]], 'max_stopovers': 2, 'max_transfers': 3}, [3, 3, ['STOPOVERS']]], ['nonstop', {'segments': [['2027-05-01T07:00', '2027-05-01T09:02', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 0, []]], ['sampled case 1', {'segments': [['2028-08-14T16:45', '2028-08-15T03:45', False], ['2028-08-17T03:45', '2028-08-17T17:45', False], ['2028-08-17T22:45', '2028-08-18T09:15', True], ['2028-08-18T13:15', '2028-08-18T22:45', False], ['2028-08-19T18:45', '2028-08-20T06:45', False]], 'max_stopovers': 2, 'max_transfers': 1}, [1, 4, ['TRANSFERS']]], ['sampled case 2', {'segments': [['2027-06-01T12:45', '2027-06-01T20:15', True], ['2027-06-01T22:15', '2027-06-02T11:45', True], ['2027-06-03T11:45', '2027-06-03T21:45', True]], 'max_stopovers': 1, 'max_transfers': 2}, [1, 2, []]], ['sampled case 3', {'segments': [['2027-07-21T03:00', '2027-07-21T07:00', False], ['2027-07-22T03:00', '2027-07-22T08:30', False], ['2027-07-22T09:30', '2027-07-22T16:30', False], ['2027-07-22T17:30', '2027-07-22T23:00', False], ['2027-07-23T19:00', '2027-07-24T00:00', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 4, ['TRANSFERS']]], ['regression: stopover threshold boundary', {'segments': [['2028-11-08T02:30', '2028-11-08T15:00', True], ['2028-11-10T15:30', '2028-11-10T21:00', True], ['2028-11-11T21:30', '2028-11-12T03:00', True], ['2028-11-12T08:00', '2028-11-12T10:30', False], ['2028-11-13T11:00', '2028-11-13T12:00', True]], 'max_stopovers': 1, 'max_transfers': 0}, [3, 4, ['STOPOVERS', 'TRANSFERS']]]], [['international 24h exactly', {'segments': [['2027-05-01T10:00', '2027-05-01T18:00', False], ['2027-05-02T18:00', '2027-05-02T23:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['domestic five hour connection', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T14:03', '2027-05-01T16:00', True]], 'max_stopovers': 0, 'max_transfers': 1}, [1, 1, ['STOPOVERS']]], ['mixed connection 6h', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T15:00', '2027-05-02T07:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['long flight short connection', {'segments': [['2027-05-01T07:00', '2027-05-02T01:00', False], ['2027-05-02T03:00', '2027-05-02T09:00', False], ['2027-05-03T10:00', '2027-05-03T12:00', False]], 'max_stopovers': 1, 'max_transfers': 1}, [1, 2, ['TRANSFERS']]], ['three stopovers', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', False], ['2027-05-03T07:00', '2027-05-03T09:00', False], ['2027-05-05T07:00', '2027-05-05T09:00', False], ['2027-05-06T07:00', '2027-05-09T09:00', False]], 'max_stopovers': 2, 'max_transfers': 3}, [2, 3, []]], ['nonstop', {'segments': [['2027-05-01T07:00', '2027-05-01T09:03', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 0, []]], ['sampled case 1', {'segments': [['2027-02-15T21:15', '2027-02-15T23:15', True], ['2027-02-16T07:45', '2027-02-16T18:45', True], ['2027-02-17T02:45', '2027-02-17T13:45', False], ['2027-02-17T22:15', '2027-02-18T00:45', False], ['2027-02-18T20:45', '2027-02-19T02:15', False]], 'max_stopovers': 1, 'max_transfers': 3}, [1, 4, ['TRANSFERS']]], ['sampled case 2', {'segments': [['2029-05-25T20:00', '2029-05-26T01:00', True], ['2029-05-27T02:00', '2029-05-27T07:00', False], ['2029-05-28T08:30', '2029-05-28T17:00', False], ['2029-05-28T19:00', '2029-05-29T07:30', False], ['2029-05-29T09:30', '2029-05-29T13:00', False]], 'max_stopovers': 1, 'max_transfers': 3}, [2, 4, ['STOPOVERS', 'TRANSFERS']]], ['sampled case 3', {'segments': [['2028-09-07T21:45', '2028-09-08T03:15', True], ['2028-09-08T23:15', '2028-09-09T11:15', True], ['2028-09-10T11:15', '2028-09-10T14:45', False], ['2028-09-12T14:45', '2028-09-13T04:45', True], ['2028-09-13T05:45', '2028-09-13T20:15', True]], 'max_stopovers': 0, 'max_transfers': 2}, [2, 4, ['STOPOVERS', 'TRANSFERS']]], ['regression: stopover threshold boundary', {'segments': [['2027-04-06T14:30', '2027-04-06T17:00', True], ['2027-04-06T20:30', '2027-04-07T04:30', False], ['2027-04-07T12:30', '2027-04-07T19:30', True], ['2027-04-08T20:00', '2027-04-09T00:30', False], ['2027-04-09T02:30', '2027-04-09T03:30', True]], 'max_stopovers': 2, 'max_transfers': 3}, [1, 4, ['TRANSFERS']]]], [['international 24h exactly', {'segments': [['2027-05-01T10:00', '2027-05-01T18:00', False], ['2027-05-02T18:00', '2027-05-02T23:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['domestic five hour connection', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T14:04', '2027-05-01T16:00', True]], 'max_stopovers': 0, 'max_transfers': 1}, [1, 1, ['STOPOVERS']]], ['mixed connection 6h', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T15:00', '2027-05-02T07:00', False]], 'max_stopovers': 0, 'max_transfers': 1}, [0, 1, []]], ['long flight short connection', {'segments': [['2027-05-01T07:00', '2027-05-02T01:00', False], ['2027-05-02T03:00', '2027-05-02T09:00', False], ['2027-05-03T10:00', '2027-05-03T12:00', False]], 'max_stopovers': 1, 'max_transfers': 1}, [1, 2, ['TRANSFERS']]], ['three stopovers', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', False], ['2027-05-03T07:00', '2027-05-03T09:00', False], ['2027-05-05T07:00', '2027-05-05T09:00', False], ['2027-05-07T07:00', '2027-05-09T09:00', False]], 'max_stopovers': 2, 'max_transfers': 3}, [3, 3, ['STOPOVERS']]], ['nonstop', {'segments': [['2027-05-01T07:00', '2027-05-01T09:04', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 0, []]], ['sampled case 1', {'segments': [['2027-11-27T17:15', '2027-11-27T23:45', False], ['2027-11-28T01:45', '2027-11-28T11:45', False]], 'max_stopovers': 2, 'max_transfers': 3}, [0, 1, []]], ['sampled case 2', {'segments': [['2029-03-09T18:00', '2029-03-10T02:00', True], ['2029-03-10T03:00', '2029-03-10T12:00', True]], 'max_stopovers': 1, 'max_transfers': 2}, [0, 1, []]], ['sampled case 3', {'segments': [['2029-03-20T20:00', '2029-03-20T23:30', True], ['2029-03-21T02:30', '2029-03-21T12:00', False], ['2029-03-23T12:00', '2029-03-23T16:00', False], ['2029-03-23T21:00', '2029-03-24T01:30', False], ['2029-03-24T02:30', '2029-03-24T12:00', False]], 'max_stopovers': 1, 'max_transfers': 0}, [1, 4, ['TRANSFERS']]], ['regression: stopover threshold boundary', {'segments': [['2028-06-19T07:45', '2028-06-19T16:45', False], ['2028-06-20T12:45', '2028-06-20T17:15', False], ['2028-06-21T17:45', '2028-06-22T01:45', False], ['2028-06-22T03:45', '2028-06-22T15:15', False], ['2028-06-23T16:15', '2028-06-24T01:15', False]], 'max_stopovers': 1, 'max_transfers': 1}, [2, 4, ['STOPOVERS', 'TRANSFERS']]]], [['international 24h exactly', {'segments': [['2027-05-01T10:00', '2027-05-01T18:00', False], ['2027-05-02T18:00', '2027-05-02T23:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['domestic five hour connection', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T14:05', '2027-05-01T16:00', True]], 'max_stopovers': 0, 'max_transfers': 1}, [1, 1, ['STOPOVERS']]], ['mixed connection 6h', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T15:00', '2027-05-02T07:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['long flight short connection', {'segments': [['2027-05-01T07:00', '2027-05-02T01:00', False], ['2027-05-02T03:00', '2027-05-02T09:00', False], ['2027-05-03T10:00', '2027-05-03T12:00', False]], 'max_stopovers': 1, 'max_transfers': 1}, [1, 2, ['TRANSFERS']]], ['three stopovers', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', False], ['2027-05-03T07:00', '2027-05-03T09:00', False], ['2027-05-05T07:00', '2027-05-05T09:00', False], ['2027-05-08T07:00', '2027-05-09T09:00', False]], 'max_stopovers': 2, 'max_transfers': 3}, [3, 3, ['STOPOVERS']]], ['nonstop', {'segments': [['2027-05-01T07:00', '2027-05-01T09:05', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 0, []]], ['sampled case 1', {'segments': [['2027-02-17T17:30', '2027-02-17T20:00', False]], 'max_stopovers': 1, 'max_transfers': 0}, [0, 0, []]], ['sampled case 2', {'segments': [['2029-07-05T21:30', '2029-07-06T01:30', False], ['2029-07-06T02:30', '2029-07-06T07:30', True], ['2029-07-06T09:00', '2029-07-06T23:00', True], ['2029-07-08T00:30', '2029-07-08T15:00', True], ['2029-07-08T18:30', '2029-07-09T04:30', False]], 'max_stopovers': 2, 'max_transfers': 2}, [1, 4, ['TRANSFERS']]], ['sampled case 3', {'segments': [['2027-06-10T18:15', '2027-06-10T19:15', False], ['2027-06-10T22:45', '2027-06-11T12:15', True]], 'max_stopovers': 0, 'max_transfers': 3}, [0, 1, []]], ['regression: stopover threshold boundary', {'segments': [['2027-02-12T09:30', '2027-02-12T16:00', True], ['2027-02-13T00:00', '2027-02-13T02:00', False], ['2027-02-14T02:00', '2027-02-14T11:00', False], ['2027-02-14T16:00', '2027-02-15T00:00', True], ['2027-02-15T04:30', '2027-02-15T16:00', True]], 'max_stopovers': 0, 'max_transfers': 1}, [1, 4, ['STOPOVERS', 'TRANSFERS']]]]]
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:
An international connection of exactly 24 hours consumes the stopover allowance.

Input {'segments':[[departure, arrival ISO local, domestic flag]],'max_stopovers','max_transfers'}. At each connection the gap from the inbound arrival to the next departure is a stopover when it exceeds 4 h if both segments are domestic, otherwise 24 h (a gap equal to the limit is not a stopover). Every connection point is a transfer. Return [stopovers, transfers, failures in order STOPOVERS, TRANSFERS].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
N = 1
observations = []
def solve(x):
    segs = x['segments']
    stops = 0
    for (d0, a0, dom0), (d1, a1, dom1) in zip(segs, segs[1:]):
        gap = (datetime.datetime.fromisoformat(d1) - datetime.datetime.fromisoformat(a0)).total_seconds() / 3600
        limit = 4 if dom1 else 24
        if gap > limit: stops += 1
    transfers = len(segs) - 1
    fails = []
    if stops > x['max_stopovers']: fails.append('STOPOVERS')
    if transfers > x['max_transfers']: fails.append('TRANSFERS')
    return [stops, transfers, fails]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['international 24h exactly', {'segments': [['2027-05-01T10:00', '2027-05-01T18:00', False], ['2027-05-02T18:00', '2027-05-02T23:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['domestic five hour connection', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T14:01', '2027-05-01T16:00', True]], 'max_stopovers': 0, 'max_transfers': 1}, [1, 1, ['STOPOVERS']]], ['mixed connection 6h', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T15:00', '2027-05-02T07:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['long flight short connection', {'segments': [['2027-05-01T07:00', '2027-05-02T01:00', False], ['2027-05-02T03:00', '2027-05-02T09:00', False], ['2027-05-03T10:00', '2027-05-03T12:00', False]], 'max_stopovers': 1, 'max_transfers': 1}, [1, 2, ['TRANSFERS']]], ['three stopovers', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', False], ['2027-05-03T07:00', '2027-05-03T09:00', False], ['2027-05-05T07:00', '2027-05-05T09:00', False], ['2027-05-07T07:00', '2027-05-09T09:00', False]], 'max_stopovers': 2, 'max_transfers': 3}, [3, 3, ['STOPOVERS']]], ['nonstop', {'segments': [['2027-05-01T07:00', '2027-05-01T09:01', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 0, []]], ['sampled case 1', {'segments': [['2029-07-06T05:00', '2029-07-06T16:00', False], ['2029-07-06T19:00', '2029-07-06T20:30', False], ['2029-07-07T00:30', '2029-07-07T14:30', False]], 'max_stopovers': 2, 'max_transfers': 2}, [0, 2, []]], ['sampled case 2', {'segments': [['2029-04-03T21:30', '2029-04-04T07:30', True]], 'max_stopovers': 2, 'max_transfers': 3}, [0, 0, []]], ['sampled case 3', {'segments': [['2028-08-09T11:30', '2028-08-09T19:00', False], ['2028-08-09T20:30', '2028-08-10T07:00', False], ['2028-08-10T12:00', '2028-08-10T18:30', True], ['2028-08-10T20:00', '2028-08-11T07:30', True]], 'max_stopovers': 2, 'max_transfers': 3}, [0, 3, []]]], [['international 24h exactly', {'segments': [['2027-05-01T10:00', '2027-05-01T18:00', False], ['2027-05-02T18:00', '2027-05-02T23:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['domestic five hour connection', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T14:02', '2027-05-01T16:00', True]], 'max_stopovers': 0, 'max_transfers': 1}, [1, 1, ['STOPOVERS']]], ['mixed connection 6h', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T15:00', '2027-05-02T07:00', False]], 'max_stopovers': 0, 'max_transfers': 1}, [0, 1, []]], ['long flight short connection', {'segments': [['2027-05-01T07:00', '2027-05-02T01:00', False], ['2027-05-02T03:00', '2027-05-02T09:00', False], ['2027-05-03T10:00', '2027-05-03T12:00', False]], 'max_stopovers': 1, 'max_transfers': 1}, [1, 2, ['TRANSFERS']]], ['three stopovers', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', False], ['2027-05-03T07:00', '2027-05-03T09:00', False], ['2027-05-05T07:00', '2027-05-05T09:00', False], ['2027-05-08T07:00', '2027-05-09T09:00', False]], 'max_stopovers': 2, 'max_transfers': 3}, [3, 3, ['STOPOVERS']]], ['nonstop', {'segments': [['2027-05-01T07:00', '2027-05-01T09:02', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 0, []]], ['sampled case 1', {'segments': [['2028-08-14T16:45', '2028-08-15T03:45', False], ['2028-08-17T03:45', '2028-08-17T17:45', False], ['2028-08-17T22:45', '2028-08-18T09:15', True], ['2028-08-18T13:15', '2028-08-18T22:45', False], ['2028-08-19T18:45', '2028-08-20T06:45', False]], 'max_stopovers': 2, 'max_transfers': 1}, [1, 4, ['TRANSFERS']]], ['sampled case 2', {'segments': [['2027-06-01T12:45', '2027-06-01T20:15', True], ['2027-06-01T22:15', '2027-06-02T11:45', True], ['2027-06-03T11:45', '2027-06-03T21:45', True]], 'max_stopovers': 1, 'max_transfers': 2}, [1, 2, []]], ['sampled case 3', {'segments': [['2027-07-21T03:00', '2027-07-21T07:00', False], ['2027-07-22T03:00', '2027-07-22T08:30', False], ['2027-07-22T09:30', '2027-07-22T16:30', False], ['2027-07-22T17:30', '2027-07-22T23:00', False], ['2027-07-23T19:00', '2027-07-24T00:00', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 4, ['TRANSFERS']]]], [['international 24h exactly', {'segments': [['2027-05-01T10:00', '2027-05-01T18:00', False], ['2027-05-02T18:00', '2027-05-02T23:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['domestic five hour connection', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T14:03', '2027-05-01T16:00', True]], 'max_stopovers': 0, 'max_transfers': 1}, [1, 1, ['STOPOVERS']]], ['mixed connection 6h', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T15:00', '2027-05-02T07:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['long flight short connection', {'segments': [['2027-05-01T07:00', '2027-05-02T01:00', False], ['2027-05-02T03:00', '2027-05-02T09:00', False], ['2027-05-03T10:00', '2027-05-03T12:00', False]], 'max_stopovers': 1, 'max_transfers': 1}, [1, 2, ['TRANSFERS']]], ['three stopovers', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', False], ['2027-05-03T07:00', '2027-05-03T09:00', False], ['2027-05-05T07:00', '2027-05-05T09:00', False], ['2027-05-06T07:00', '2027-05-09T09:00', False]], 'max_stopovers': 2, 'max_transfers': 3}, [2, 3, []]], ['nonstop', {'segments': [['2027-05-01T07:00', '2027-05-01T09:03', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 0, []]], ['sampled case 1', {'segments': [['2027-02-15T21:15', '2027-02-15T23:15', True], ['2027-02-16T07:45', '2027-02-16T18:45', True], ['2027-02-17T02:45', '2027-02-17T13:45', False], ['2027-02-17T22:15', '2027-02-18T00:45', False], ['2027-02-18T20:45', '2027-02-19T02:15', False]], 'max_stopovers': 1, 'max_transfers': 3}, [1, 4, ['TRANSFERS']]], ['sampled case 2', {'segments': [['2029-05-25T20:00', '2029-05-26T01:00', True], ['2029-05-27T02:00', '2029-05-27T07:00', False], ['2029-05-28T08:30', '2029-05-28T17:00', False], ['2029-05-28T19:00', '2029-05-29T07:30', False], ['2029-05-29T09:30', '2029-05-29T13:00', False]], 'max_stopovers': 1, 'max_transfers': 3}, [2, 4, ['STOPOVERS', 'TRANSFERS']]], ['sampled case 3', {'segments': [['2028-09-07T21:45', '2028-09-08T03:15', True], ['2028-09-08T23:15', '2028-09-09T11:15', True], ['2028-09-10T11:15', '2028-09-10T14:45', False], ['2028-09-12T14:45', '2028-09-13T04:45', True], ['2028-09-13T05:45', '2028-09-13T20:15', True]], 'max_stopovers': 0, 'max_transfers': 2}, [2, 4, ['STOPOVERS', 'TRANSFERS']]], ['regression: domestic connection classification', {'segments': [['2027-02-03T06:30', '2027-02-03T08:30', True], ['2027-02-04T09:30', '2027-02-04T17:30', False], ['2027-02-05T13:30', '2027-02-05T17:00', False], ['2027-02-06T01:30', '2027-02-06T12:00', True]], 'max_stopovers': 1, 'max_transfers': 3}, [1, 3, []]]], [['international 24h exactly', {'segments': [['2027-05-01T10:00', '2027-05-01T18:00', False], ['2027-05-02T18:00', '2027-05-02T23:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['domestic five hour connection', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T14:04', '2027-05-01T16:00', True]], 'max_stopovers': 0, 'max_transfers': 1}, [1, 1, ['STOPOVERS']]], ['mixed connection 6h', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T15:00', '2027-05-02T07:00', False]], 'max_stopovers': 0, 'max_transfers': 1}, [0, 1, []]], ['long flight short connection', {'segments': [['2027-05-01T07:00', '2027-05-02T01:00', False], ['2027-05-02T03:00', '2027-05-02T09:00', False], ['2027-05-03T10:00', '2027-05-03T12:00', False]], 'max_stopovers': 1, 'max_transfers': 1}, [1, 2, ['TRANSFERS']]], ['three stopovers', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', False], ['2027-05-03T07:00', '2027-05-03T09:00', False], ['2027-05-05T07:00', '2027-05-05T09:00', False], ['2027-05-07T07:00', '2027-05-09T09:00', False]], 'max_stopovers': 2, 'max_transfers': 3}, [3, 3, ['STOPOVERS']]], ['nonstop', {'segments': [['2027-05-01T07:00', '2027-05-01T09:04', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 0, []]], ['sampled case 1', {'segments': [['2027-11-27T17:15', '2027-11-27T23:45', False], ['2027-11-28T01:45', '2027-11-28T11:45', False]], 'max_stopovers': 2, 'max_transfers': 3}, [0, 1, []]], ['sampled case 2', {'segments': [['2029-03-09T18:00', '2029-03-10T02:00', True], ['2029-03-10T03:00', '2029-03-10T12:00', True]], 'max_stopovers': 1, 'max_transfers': 2}, [0, 1, []]], ['sampled case 3', {'segments': [['2029-03-20T20:00', '2029-03-20T23:30', True], ['2029-03-21T02:30', '2029-03-21T12:00', False], ['2029-03-23T12:00', '2029-03-23T16:00', False], ['2029-03-23T21:00', '2029-03-24T01:30', False], ['2029-03-24T02:30', '2029-03-24T12:00', False]], 'max_stopovers': 1, 'max_transfers': 0}, [1, 4, ['TRANSFERS']]], ['regression: domestic connection classification', {'segments': [['2028-12-25T18:00', '2028-12-26T01:30', True], ['2028-12-27T02:00', '2028-12-27T03:00', True], ['2028-12-29T03:00', '2028-12-29T17:30', False], ['2028-12-29T22:30', '2028-12-30T04:30', False], ['2028-12-30T09:30', '2028-12-30T12:30', True]], 'max_stopovers': 0, 'max_transfers': 1}, [2, 4, ['STOPOVERS', 'TRANSFERS']]]], [['international 24h exactly', {'segments': [['2027-05-01T10:00', '2027-05-01T18:00', False], ['2027-05-02T18:00', '2027-05-02T23:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['domestic five hour connection', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T14:05', '2027-05-01T16:00', True]], 'max_stopovers': 0, 'max_transfers': 1}, [1, 1, ['STOPOVERS']]], ['mixed connection 6h', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T15:00', '2027-05-02T07:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['long flight short connection', {'segments': [['2027-05-01T07:00', '2027-05-02T01:00', False], ['2027-05-02T03:00', '2027-05-02T09:00', False], ['2027-05-03T10:00', '2027-05-03T12:00', False]], 'max_stopovers': 1, 'max_transfers': 1}, [1, 2, ['TRANSFERS']]], ['three stopovers', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', False], ['2027-05-03T07:00', '2027-05-03T09:00', False], ['2027-05-05T07:00', '2027-05-05T09:00', False], ['2027-05-08T07:00', '2027-05-09T09:00', False]], 'max_stopovers': 2, 'max_transfers': 3}, [3, 3, ['STOPOVERS']]], ['nonstop', {'segments': [['2027-05-01T07:00', '2027-05-01T09:05', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 0, []]], ['sampled case 1', {'segments': [['2027-02-17T17:30', '2027-02-17T20:00', False]], 'max_stopovers': 1, 'max_transfers': 0}, [0, 0, []]], ['sampled case 2', {'segments': [['2029-07-05T21:30', '2029-07-06T01:30', False], ['2029-07-06T02:30', '2029-07-06T07:30', True], ['2029-07-06T09:00', '2029-07-06T23:00', True], ['2029-07-08T00:30', '2029-07-08T15:00', True], ['2029-07-08T18:30', '2029-07-09T04:30', False]], 'max_stopovers': 2, 'max_transfers': 2}, [1, 4, ['TRANSFERS']]], ['sampled case 3', {'segments': [['2027-06-10T18:15', '2027-06-10T19:15', False], ['2027-06-10T22:45', '2027-06-11T12:15', True]], 'max_stopovers': 0, 'max_transfers': 3}, [0, 1, []]], ['regression: domestic connection classification', {'segments': [['2029-12-01T10:15', '2029-12-01T16:45', False], ['2029-12-02T16:45', '2029-12-03T02:15', True]], 'max_stopovers': 0, 'max_transfers': 1}, [0, 1, []]]]]
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):
    segs = x['segments']
    stops = 0
    for (d0, a0, dom0), (d1, a1, dom1) in zip(segs, segs[1:]):
        gap = (datetime.datetime.fromisoformat(d1) - datetime.datetime.fromisoformat(a0)).total_seconds() / 3600
        limit = 4 if (dom0 or dom1) else 24
        if gap > limit: stops += 1
    transfers = len(segs) - 1
    fails = []
    if stops > x['max_stopovers']: fails.append('STOPOVERS')
    if transfers > x['max_transfers']: fails.append('TRANSFERS')
    return [stops, transfers, fails]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['international 24h exactly', {'segments': [['2027-05-01T10:00', '2027-05-01T18:00', False], ['2027-05-02T18:00', '2027-05-02T23:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['domestic five hour connection', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T14:01', '2027-05-01T16:00', True]], 'max_stopovers': 0, 'max_transfers': 1}, [1, 1, ['STOPOVERS']]], ['mixed connection 6h', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T15:00', '2027-05-02T07:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['long flight short connection', {'segments': [['2027-05-01T07:00', '2027-05-02T01:00', False], ['2027-05-02T03:00', '2027-05-02T09:00', False], ['2027-05-03T10:00', '2027-05-03T12:00', False]], 'max_stopovers': 1, 'max_transfers': 1}, [1, 2, ['TRANSFERS']]], ['three stopovers', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', False], ['2027-05-03T07:00', '2027-05-03T09:00', False], ['2027-05-05T07:00', '2027-05-05T09:00', False], ['2027-05-07T07:00', '2027-05-09T09:00', False]], 'max_stopovers': 2, 'max_transfers': 3}, [3, 3, ['STOPOVERS']]], ['nonstop', {'segments': [['2027-05-01T07:00', '2027-05-01T09:01', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 0, []]], ['sampled case 1', {'segments': [['2029-07-06T05:00', '2029-07-06T16:00', False], ['2029-07-06T19:00', '2029-07-06T20:30', False], ['2029-07-07T00:30', '2029-07-07T14:30', False]], 'max_stopovers': 2, 'max_transfers': 2}, [0, 2, []]], ['sampled case 2', {'segments': [['2029-04-03T21:30', '2029-04-04T07:30', True]], 'max_stopovers': 2, 'max_transfers': 3}, [0, 0, []]], ['sampled case 3', {'segments': [['2028-08-09T11:30', '2028-08-09T19:00', False], ['2028-08-09T20:30', '2028-08-10T07:00', False], ['2028-08-10T12:00', '2028-08-10T18:30', True], ['2028-08-10T20:00', '2028-08-11T07:30', True]], 'max_stopovers': 2, 'max_transfers': 3}, [0, 3, []]]], [['international 24h exactly', {'segments': [['2027-05-01T10:00', '2027-05-01T18:00', False], ['2027-05-02T18:00', '2027-05-02T23:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['domestic five hour connection', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T14:02', '2027-05-01T16:00', True]], 'max_stopovers': 0, 'max_transfers': 1}, [1, 1, ['STOPOVERS']]], ['mixed connection 6h', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T15:00', '2027-05-02T07:00', False]], 'max_stopovers': 0, 'max_transfers': 1}, [0, 1, []]], ['long flight short connection', {'segments': [['2027-05-01T07:00', '2027-05-02T01:00', False], ['2027-05-02T03:00', '2027-05-02T09:00', False], ['2027-05-03T10:00', '2027-05-03T12:00', False]], 'max_stopovers': 1, 'max_transfers': 1}, [1, 2, ['TRANSFERS']]], ['three stopovers', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', False], ['2027-05-03T07:00', '2027-05-03T09:00', False], ['2027-05-05T07:00', '2027-05-05T09:00', False], ['2027-05-08T07:00', '2027-05-09T09:00', False]], 'max_stopovers': 2, 'max_transfers': 3}, [3, 3, ['STOPOVERS']]], ['nonstop', {'segments': [['2027-05-01T07:00', '2027-05-01T09:02', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 0, []]], ['sampled case 1', {'segments': [['2028-08-14T16:45', '2028-08-15T03:45', False], ['2028-08-17T03:45', '2028-08-17T17:45', False], ['2028-08-17T22:45', '2028-08-18T09:15', True], ['2028-08-18T13:15', '2028-08-18T22:45', False], ['2028-08-19T18:45', '2028-08-20T06:45', False]], 'max_stopovers': 2, 'max_transfers': 1}, [1, 4, ['TRANSFERS']]], ['sampled case 2', {'segments': [['2027-06-01T12:45', '2027-06-01T20:15', True], ['2027-06-01T22:15', '2027-06-02T11:45', True], ['2027-06-03T11:45', '2027-06-03T21:45', True]], 'max_stopovers': 1, 'max_transfers': 2}, [1, 2, []]], ['sampled case 3', {'segments': [['2027-07-21T03:00', '2027-07-21T07:00', False], ['2027-07-22T03:00', '2027-07-22T08:30', False], ['2027-07-22T09:30', '2027-07-22T16:30', False], ['2027-07-22T17:30', '2027-07-22T23:00', False], ['2027-07-23T19:00', '2027-07-24T00:00', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 4, ['TRANSFERS']]]], [['international 24h exactly', {'segments': [['2027-05-01T10:00', '2027-05-01T18:00', False], ['2027-05-02T18:00', '2027-05-02T23:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['domestic five hour connection', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T14:03', '2027-05-01T16:00', True]], 'max_stopovers': 0, 'max_transfers': 1}, [1, 1, ['STOPOVERS']]], ['mixed connection 6h', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T15:00', '2027-05-02T07:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['long flight short connection', {'segments': [['2027-05-01T07:00', '2027-05-02T01:00', False], ['2027-05-02T03:00', '2027-05-02T09:00', False], ['2027-05-03T10:00', '2027-05-03T12:00', False]], 'max_stopovers': 1, 'max_transfers': 1}, [1, 2, ['TRANSFERS']]], ['three stopovers', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', False], ['2027-05-03T07:00', '2027-05-03T09:00', False], ['2027-05-05T07:00', '2027-05-05T09:00', False], ['2027-05-06T07:00', '2027-05-09T09:00', False]], 'max_stopovers': 2, 'max_transfers': 3}, [2, 3, []]], ['nonstop', {'segments': [['2027-05-01T07:00', '2027-05-01T09:03', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 0, []]], ['sampled case 1', {'segments': [['2027-02-15T21:15', '2027-02-15T23:15', True], ['2027-02-16T07:45', '2027-02-16T18:45', True], ['2027-02-17T02:45', '2027-02-17T13:45', False], ['2027-02-17T22:15', '2027-02-18T00:45', False], ['2027-02-18T20:45', '2027-02-19T02:15', False]], 'max_stopovers': 1, 'max_transfers': 3}, [1, 4, ['TRANSFERS']]], ['sampled case 2', {'segments': [['2029-05-25T20:00', '2029-05-26T01:00', True], ['2029-05-27T02:00', '2029-05-27T07:00', False], ['2029-05-28T08:30', '2029-05-28T17:00', False], ['2029-05-28T19:00', '2029-05-29T07:30', False], ['2029-05-29T09:30', '2029-05-29T13:00', False]], 'max_stopovers': 1, 'max_transfers': 3}, [2, 4, ['STOPOVERS', 'TRANSFERS']]], ['sampled case 3', {'segments': [['2028-09-07T21:45', '2028-09-08T03:15', True], ['2028-09-08T23:15', '2028-09-09T11:15', True], ['2028-09-10T11:15', '2028-09-10T14:45', False], ['2028-09-12T14:45', '2028-09-13T04:45', True], ['2028-09-13T05:45', '2028-09-13T20:15', True]], 'max_stopovers': 0, 'max_transfers': 2}, [2, 4, ['STOPOVERS', 'TRANSFERS']]], ['regression: domestic connection classification', {'segments': [['2027-02-03T06:30', '2027-02-03T08:30', True], ['2027-02-04T09:30', '2027-02-04T17:30', False], ['2027-02-05T13:30', '2027-02-05T17:00', False], ['2027-02-06T01:30', '2027-02-06T12:00', True]], 'max_stopovers': 1, 'max_transfers': 3}, [1, 3, []]]], [['international 24h exactly', {'segments': [['2027-05-01T10:00', '2027-05-01T18:00', False], ['2027-05-02T18:00', '2027-05-02T23:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['domestic five hour connection', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T14:04', '2027-05-01T16:00', True]], 'max_stopovers': 0, 'max_transfers': 1}, [1, 1, ['STOPOVERS']]], ['mixed connection 6h', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T15:00', '2027-05-02T07:00', False]], 'max_stopovers': 0, 'max_transfers': 1}, [0, 1, []]], ['long flight short connection', {'segments': [['2027-05-01T07:00', '2027-05-02T01:00', False], ['2027-05-02T03:00', '2027-05-02T09:00', False], ['2027-05-03T10:00', '2027-05-03T12:00', False]], 'max_stopovers': 1, 'max_transfers': 1}, [1, 2, ['TRANSFERS']]], ['three stopovers', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', False], ['2027-05-03T07:00', '2027-05-03T09:00', False], ['2027-05-05T07:00', '2027-05-05T09:00', False], ['2027-05-07T07:00', '2027-05-09T09:00', False]], 'max_stopovers': 2, 'max_transfers': 3}, [3, 3, ['STOPOVERS']]], ['nonstop', {'segments': [['2027-05-01T07:00', '2027-05-01T09:04', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 0, []]], ['sampled case 1', {'segments': [['2027-11-27T17:15', '2027-11-27T23:45', False], ['2027-11-28T01:45', '2027-11-28T11:45', False]], 'max_stopovers': 2, 'max_transfers': 3}, [0, 1, []]], ['sampled case 2', {'segments': [['2029-03-09T18:00', '2029-03-10T02:00', True], ['2029-03-10T03:00', '2029-03-10T12:00', True]], 'max_stopovers': 1, 'max_transfers': 2}, [0, 1, []]], ['sampled case 3', {'segments': [['2029-03-20T20:00', '2029-03-20T23:30', True], ['2029-03-21T02:30', '2029-03-21T12:00', False], ['2029-03-23T12:00', '2029-03-23T16:00', False], ['2029-03-23T21:00', '2029-03-24T01:30', False], ['2029-03-24T02:30', '2029-03-24T12:00', False]], 'max_stopovers': 1, 'max_transfers': 0}, [1, 4, ['TRANSFERS']]], ['regression: domestic connection classification', {'segments': [['2028-12-25T18:00', '2028-12-26T01:30', True], ['2028-12-27T02:00', '2028-12-27T03:00', True], ['2028-12-29T03:00', '2028-12-29T17:30', False], ['2028-12-29T22:30', '2028-12-30T04:30', False], ['2028-12-30T09:30', '2028-12-30T12:30', True]], 'max_stopovers': 0, 'max_transfers': 1}, [2, 4, ['STOPOVERS', 'TRANSFERS']]]], [['international 24h exactly', {'segments': [['2027-05-01T10:00', '2027-05-01T18:00', False], ['2027-05-02T18:00', '2027-05-02T23:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['domestic five hour connection', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T14:05', '2027-05-01T16:00', True]], 'max_stopovers': 0, 'max_transfers': 1}, [1, 1, ['STOPOVERS']]], ['mixed connection 6h', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T15:00', '2027-05-02T07:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['long flight short connection', {'segments': [['2027-05-01T07:00', '2027-05-02T01:00', False], ['2027-05-02T03:00', '2027-05-02T09:00', False], ['2027-05-03T10:00', '2027-05-03T12:00', False]], 'max_stopovers': 1, 'max_transfers': 1}, [1, 2, ['TRANSFERS']]], ['three stopovers', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', False], ['2027-05-03T07:00', '2027-05-03T09:00', False], ['2027-05-05T07:00', '2027-05-05T09:00', False], ['2027-05-08T07:00', '2027-05-09T09:00', False]], 'max_stopovers': 2, 'max_transfers': 3}, [3, 3, ['STOPOVERS']]], ['nonstop', {'segments': [['2027-05-01T07:00', '2027-05-01T09:05', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 0, []]], ['sampled case 1', {'segments': [['2027-02-17T17:30', '2027-02-17T20:00', False]], 'max_stopovers': 1, 'max_transfers': 0}, [0, 0, []]], ['sampled case 2', {'segments': [['2029-07-05T21:30', '2029-07-06T01:30', False], ['2029-07-06T02:30', '2029-07-06T07:30', True], ['2029-07-06T09:00', '2029-07-06T23:00', True], ['2029-07-08T00:30', '2029-07-08T15:00', True], ['2029-07-08T18:30', '2029-07-09T04:30', False]], 'max_stopovers': 2, 'max_transfers': 2}, [1, 4, ['TRANSFERS']]], ['sampled case 3', {'segments': [['2027-06-10T18:15', '2027-06-10T19:15', False], ['2027-06-10T22:45', '2027-06-11T12:15', True]], 'max_stopovers': 0, 'max_transfers': 3}, [0, 1, []]], ['regression: domestic connection classification', {'segments': [['2029-12-01T10:15', '2029-12-01T16:45', False], ['2029-12-02T16:45', '2029-12-03T02:15', True]], 'max_stopovers': 0, 'max_transfers': 1}, [0, 1, []]]]]
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 domestic-to-international six-hour connection is counted as a stopover.

Input {'segments':[[departure, arrival ISO local, domestic flag]],'max_stopovers','max_transfers'}. At each connection the gap from the inbound arrival to the next departure is a stopover when it exceeds 4 h if both segments are domestic, otherwise 24 h (a gap equal to the limit is not a stopover). Every connection point is a transfer. Return [stopovers, transfers, failures in order STOPOVERS, TRANSFERS].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
N = 1
observations = []
def solve(x):
    segs = x['segments']
    stops = 0
    for (d0, a0, dom0), (d1, a1, dom1) in zip(segs, segs[1:]):
        gap = (datetime.datetime.fromisoformat(d1) - datetime.datetime.fromisoformat(d0)).total_seconds() / 3600
        limit = 4 if (dom0 and dom1) else 24
        if gap > limit: stops += 1
    transfers = len(segs) - 1
    fails = []
    if stops > x['max_stopovers']: fails.append('STOPOVERS')
    if transfers > x['max_transfers']: fails.append('TRANSFERS')
    return [stops, transfers, fails]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['international 24h exactly', {'segments': [['2027-05-01T10:00', '2027-05-01T18:00', False], ['2027-05-02T18:00', '2027-05-02T23:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['domestic five hour connection', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T14:01', '2027-05-01T16:00', True]], 'max_stopovers': 0, 'max_transfers': 1}, [1, 1, ['STOPOVERS']]], ['mixed connection 6h', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T15:00', '2027-05-02T07:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['long flight short connection', {'segments': [['2027-05-01T07:00', '2027-05-02T01:00', False], ['2027-05-02T03:00', '2027-05-02T09:00', False], ['2027-05-03T10:00', '2027-05-03T12:00', False]], 'max_stopovers': 1, 'max_transfers': 1}, [1, 2, ['TRANSFERS']]], ['three stopovers', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', False], ['2027-05-03T07:00', '2027-05-03T09:00', False], ['2027-05-05T07:00', '2027-05-05T09:00', False], ['2027-05-07T07:00', '2027-05-09T09:00', False]], 'max_stopovers': 2, 'max_transfers': 3}, [3, 3, ['STOPOVERS']]], ['nonstop', {'segments': [['2027-05-01T07:00', '2027-05-01T09:01', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 0, []]], ['sampled case 1', {'segments': [['2029-07-06T05:00', '2029-07-06T16:00', False], ['2029-07-06T19:00', '2029-07-06T20:30', False], ['2029-07-07T00:30', '2029-07-07T14:30', False]], 'max_stopovers': 2, 'max_transfers': 2}, [0, 2, []]], ['sampled case 2', {'segments': [['2029-04-03T21:30', '2029-04-04T07:30', True]], 'max_stopovers': 2, 'max_transfers': 3}, [0, 0, []]], ['sampled case 3', {'segments': [['2028-08-09T11:30', '2028-08-09T19:00', False], ['2028-08-09T20:30', '2028-08-10T07:00', False], ['2028-08-10T12:00', '2028-08-10T18:30', True], ['2028-08-10T20:00', '2028-08-11T07:30', True]], 'max_stopovers': 2, 'max_transfers': 3}, [0, 3, []]]], [['international 24h exactly', {'segments': [['2027-05-01T10:00', '2027-05-01T18:00', False], ['2027-05-02T18:00', '2027-05-02T23:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['domestic five hour connection', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T14:02', '2027-05-01T16:00', True]], 'max_stopovers': 0, 'max_transfers': 1}, [1, 1, ['STOPOVERS']]], ['mixed connection 6h', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T15:00', '2027-05-02T07:00', False]], 'max_stopovers': 0, 'max_transfers': 1}, [0, 1, []]], ['long flight short connection', {'segments': [['2027-05-01T07:00', '2027-05-02T01:00', False], ['2027-05-02T03:00', '2027-05-02T09:00', False], ['2027-05-03T10:00', '2027-05-03T12:00', False]], 'max_stopovers': 1, 'max_transfers': 1}, [1, 2, ['TRANSFERS']]], ['three stopovers', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', False], ['2027-05-03T07:00', '2027-05-03T09:00', False], ['2027-05-05T07:00', '2027-05-05T09:00', False], ['2027-05-08T07:00', '2027-05-09T09:00', False]], 'max_stopovers': 2, 'max_transfers': 3}, [3, 3, ['STOPOVERS']]], ['nonstop', {'segments': [['2027-05-01T07:00', '2027-05-01T09:02', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 0, []]], ['sampled case 1', {'segments': [['2028-08-14T16:45', '2028-08-15T03:45', False], ['2028-08-17T03:45', '2028-08-17T17:45', False], ['2028-08-17T22:45', '2028-08-18T09:15', True], ['2028-08-18T13:15', '2028-08-18T22:45', False], ['2028-08-19T18:45', '2028-08-20T06:45', False]], 'max_stopovers': 2, 'max_transfers': 1}, [1, 4, ['TRANSFERS']]], ['sampled case 2', {'segments': [['2027-06-01T12:45', '2027-06-01T20:15', True], ['2027-06-01T22:15', '2027-06-02T11:45', True], ['2027-06-03T11:45', '2027-06-03T21:45', True]], 'max_stopovers': 1, 'max_transfers': 2}, [1, 2, []]], ['sampled case 3', {'segments': [['2027-07-21T03:00', '2027-07-21T07:00', False], ['2027-07-22T03:00', '2027-07-22T08:30', False], ['2027-07-22T09:30', '2027-07-22T16:30', False], ['2027-07-22T17:30', '2027-07-22T23:00', False], ['2027-07-23T19:00', '2027-07-24T00:00', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 4, ['TRANSFERS']]]], [['international 24h exactly', {'segments': [['2027-05-01T10:00', '2027-05-01T18:00', False], ['2027-05-02T18:00', '2027-05-02T23:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['domestic five hour connection', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T14:03', '2027-05-01T16:00', True]], 'max_stopovers': 0, 'max_transfers': 1}, [1, 1, ['STOPOVERS']]], ['mixed connection 6h', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T15:00', '2027-05-02T07:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['long flight short connection', {'segments': [['2027-05-01T07:00', '2027-05-02T01:00', False], ['2027-05-02T03:00', '2027-05-02T09:00', False], ['2027-05-03T10:00', '2027-05-03T12:00', False]], 'max_stopovers': 1, 'max_transfers': 1}, [1, 2, ['TRANSFERS']]], ['three stopovers', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', False], ['2027-05-03T07:00', '2027-05-03T09:00', False], ['2027-05-05T07:00', '2027-05-05T09:00', False], ['2027-05-06T07:00', '2027-05-09T09:00', False]], 'max_stopovers': 2, 'max_transfers': 3}, [2, 3, []]], ['nonstop', {'segments': [['2027-05-01T07:00', '2027-05-01T09:03', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 0, []]], ['sampled case 1', {'segments': [['2027-02-15T21:15', '2027-02-15T23:15', True], ['2027-02-16T07:45', '2027-02-16T18:45', True], ['2027-02-17T02:45', '2027-02-17T13:45', False], ['2027-02-17T22:15', '2027-02-18T00:45', False], ['2027-02-18T20:45', '2027-02-19T02:15', False]], 'max_stopovers': 1, 'max_transfers': 3}, [1, 4, ['TRANSFERS']]], ['sampled case 2', {'segments': [['2029-05-25T20:00', '2029-05-26T01:00', True], ['2029-05-27T02:00', '2029-05-27T07:00', False], ['2029-05-28T08:30', '2029-05-28T17:00', False], ['2029-05-28T19:00', '2029-05-29T07:30', False], ['2029-05-29T09:30', '2029-05-29T13:00', False]], 'max_stopovers': 1, 'max_transfers': 3}, [2, 4, ['STOPOVERS', 'TRANSFERS']]], ['sampled case 3', {'segments': [['2028-09-07T21:45', '2028-09-08T03:15', True], ['2028-09-08T23:15', '2028-09-09T11:15', True], ['2028-09-10T11:15', '2028-09-10T14:45', False], ['2028-09-12T14:45', '2028-09-13T04:45', True], ['2028-09-13T05:45', '2028-09-13T20:15', True]], 'max_stopovers': 0, 'max_transfers': 2}, [2, 4, ['STOPOVERS', 'TRANSFERS']]]], [['international 24h exactly', {'segments': [['2027-05-01T10:00', '2027-05-01T18:00', False], ['2027-05-02T18:00', '2027-05-02T23:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['domestic five hour connection', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T14:04', '2027-05-01T16:00', True]], 'max_stopovers': 0, 'max_transfers': 1}, [1, 1, ['STOPOVERS']]], ['mixed connection 6h', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T15:00', '2027-05-02T07:00', False]], 'max_stopovers': 0, 'max_transfers': 1}, [0, 1, []]], ['long flight short connection', {'segments': [['2027-05-01T07:00', '2027-05-02T01:00', False], ['2027-05-02T03:00', '2027-05-02T09:00', False], ['2027-05-03T10:00', '2027-05-03T12:00', False]], 'max_stopovers': 1, 'max_transfers': 1}, [1, 2, ['TRANSFERS']]], ['three stopovers', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', False], ['2027-05-03T07:00', '2027-05-03T09:00', False], ['2027-05-05T07:00', '2027-05-05T09:00', False], ['2027-05-07T07:00', '2027-05-09T09:00', False]], 'max_stopovers': 2, 'max_transfers': 3}, [3, 3, ['STOPOVERS']]], ['nonstop', {'segments': [['2027-05-01T07:00', '2027-05-01T09:04', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 0, []]], ['sampled case 1', {'segments': [['2027-11-27T17:15', '2027-11-27T23:45', False], ['2027-11-28T01:45', '2027-11-28T11:45', False]], 'max_stopovers': 2, 'max_transfers': 3}, [0, 1, []]], ['sampled case 2', {'segments': [['2029-03-09T18:00', '2029-03-10T02:00', True], ['2029-03-10T03:00', '2029-03-10T12:00', True]], 'max_stopovers': 1, 'max_transfers': 2}, [0, 1, []]], ['sampled case 3', {'segments': [['2029-03-20T20:00', '2029-03-20T23:30', True], ['2029-03-21T02:30', '2029-03-21T12:00', False], ['2029-03-23T12:00', '2029-03-23T16:00', False], ['2029-03-23T21:00', '2029-03-24T01:30', False], ['2029-03-24T02:30', '2029-03-24T12:00', False]], 'max_stopovers': 1, 'max_transfers': 0}, [1, 4, ['TRANSFERS']]]], [['international 24h exactly', {'segments': [['2027-05-01T10:00', '2027-05-01T18:00', False], ['2027-05-02T18:00', '2027-05-02T23:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['domestic five hour connection', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T14:05', '2027-05-01T16:00', True]], 'max_stopovers': 0, 'max_transfers': 1}, [1, 1, ['STOPOVERS']]], ['mixed connection 6h', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T15:00', '2027-05-02T07:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['long flight short connection', {'segments': [['2027-05-01T07:00', '2027-05-02T01:00', False], ['2027-05-02T03:00', '2027-05-02T09:00', False], ['2027-05-03T10:00', '2027-05-03T12:00', False]], 'max_stopovers': 1, 'max_transfers': 1}, [1, 2, ['TRANSFERS']]], ['three stopovers', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', False], ['2027-05-03T07:00', '2027-05-03T09:00', False], ['2027-05-05T07:00', '2027-05-05T09:00', False], ['2027-05-08T07:00', '2027-05-09T09:00', False]], 'max_stopovers': 2, 'max_transfers': 3}, [3, 3, ['STOPOVERS']]], ['nonstop', {'segments': [['2027-05-01T07:00', '2027-05-01T09:05', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 0, []]], ['sampled case 1', {'segments': [['2027-02-17T17:30', '2027-02-17T20:00', False]], 'max_stopovers': 1, 'max_transfers': 0}, [0, 0, []]], ['sampled case 2', {'segments': [['2029-07-05T21:30', '2029-07-06T01:30', False], ['2029-07-06T02:30', '2029-07-06T07:30', True], ['2029-07-06T09:00', '2029-07-06T23:00', True], ['2029-07-08T00:30', '2029-07-08T15:00', True], ['2029-07-08T18:30', '2029-07-09T04:30', False]], 'max_stopovers': 2, 'max_transfers': 2}, [1, 4, ['TRANSFERS']]], ['sampled case 3', {'segments': [['2027-06-10T18:15', '2027-06-10T19:15', False], ['2027-06-10T22:45', '2027-06-11T12:15', True]], 'max_stopovers': 0, 'max_transfers': 3}, [0, 1, []]]]]
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):
    segs = x['segments']
    stops = 0
    for (d0, a0, dom0), (d1, a1, dom1) in zip(segs, segs[1:]):
        gap = (datetime.datetime.fromisoformat(a1) - datetime.datetime.fromisoformat(a0)).total_seconds() / 3600
        limit = 4 if (dom0 and dom1) else 24
        if gap > limit: stops += 1
    transfers = len(segs) - 1
    fails = []
    if stops > x['max_stopovers']: fails.append('STOPOVERS')
    if transfers > x['max_transfers']: fails.append('TRANSFERS')
    return [stops, transfers, fails]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['international 24h exactly', {'segments': [['2027-05-01T10:00', '2027-05-01T18:00', False], ['2027-05-02T18:00', '2027-05-02T23:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['domestic five hour connection', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T14:01', '2027-05-01T16:00', True]], 'max_stopovers': 0, 'max_transfers': 1}, [1, 1, ['STOPOVERS']]], ['mixed connection 6h', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T15:00', '2027-05-02T07:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['long flight short connection', {'segments': [['2027-05-01T07:00', '2027-05-02T01:00', False], ['2027-05-02T03:00', '2027-05-02T09:00', False], ['2027-05-03T10:00', '2027-05-03T12:00', False]], 'max_stopovers': 1, 'max_transfers': 1}, [1, 2, ['TRANSFERS']]], ['three stopovers', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', False], ['2027-05-03T07:00', '2027-05-03T09:00', False], ['2027-05-05T07:00', '2027-05-05T09:00', False], ['2027-05-07T07:00', '2027-05-09T09:00', False]], 'max_stopovers': 2, 'max_transfers': 3}, [3, 3, ['STOPOVERS']]], ['nonstop', {'segments': [['2027-05-01T07:00', '2027-05-01T09:01', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 0, []]], ['sampled case 1', {'segments': [['2029-07-06T05:00', '2029-07-06T16:00', False], ['2029-07-06T19:00', '2029-07-06T20:30', False], ['2029-07-07T00:30', '2029-07-07T14:30', False]], 'max_stopovers': 2, 'max_transfers': 2}, [0, 2, []]], ['sampled case 2', {'segments': [['2029-04-03T21:30', '2029-04-04T07:30', True]], 'max_stopovers': 2, 'max_transfers': 3}, [0, 0, []]], ['sampled case 3', {'segments': [['2028-08-09T11:30', '2028-08-09T19:00', False], ['2028-08-09T20:30', '2028-08-10T07:00', False], ['2028-08-10T12:00', '2028-08-10T18:30', True], ['2028-08-10T20:00', '2028-08-11T07:30', True]], 'max_stopovers': 2, 'max_transfers': 3}, [0, 3, []]]], [['international 24h exactly', {'segments': [['2027-05-01T10:00', '2027-05-01T18:00', False], ['2027-05-02T18:00', '2027-05-02T23:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['domestic five hour connection', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T14:02', '2027-05-01T16:00', True]], 'max_stopovers': 0, 'max_transfers': 1}, [1, 1, ['STOPOVERS']]], ['mixed connection 6h', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T15:00', '2027-05-02T07:00', False]], 'max_stopovers': 0, 'max_transfers': 1}, [0, 1, []]], ['long flight short connection', {'segments': [['2027-05-01T07:00', '2027-05-02T01:00', False], ['2027-05-02T03:00', '2027-05-02T09:00', False], ['2027-05-03T10:00', '2027-05-03T12:00', False]], 'max_stopovers': 1, 'max_transfers': 1}, [1, 2, ['TRANSFERS']]], ['three stopovers', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', False], ['2027-05-03T07:00', '2027-05-03T09:00', False], ['2027-05-05T07:00', '2027-05-05T09:00', False], ['2027-05-08T07:00', '2027-05-09T09:00', False]], 'max_stopovers': 2, 'max_transfers': 3}, [3, 3, ['STOPOVERS']]], ['nonstop', {'segments': [['2027-05-01T07:00', '2027-05-01T09:02', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 0, []]], ['sampled case 1', {'segments': [['2028-08-14T16:45', '2028-08-15T03:45', False], ['2028-08-17T03:45', '2028-08-17T17:45', False], ['2028-08-17T22:45', '2028-08-18T09:15', True], ['2028-08-18T13:15', '2028-08-18T22:45', False], ['2028-08-19T18:45', '2028-08-20T06:45', False]], 'max_stopovers': 2, 'max_transfers': 1}, [1, 4, ['TRANSFERS']]], ['sampled case 2', {'segments': [['2027-06-01T12:45', '2027-06-01T20:15', True], ['2027-06-01T22:15', '2027-06-02T11:45', True], ['2027-06-03T11:45', '2027-06-03T21:45', True]], 'max_stopovers': 1, 'max_transfers': 2}, [1, 2, []]], ['sampled case 3', {'segments': [['2027-07-21T03:00', '2027-07-21T07:00', False], ['2027-07-22T03:00', '2027-07-22T08:30', False], ['2027-07-22T09:30', '2027-07-22T16:30', False], ['2027-07-22T17:30', '2027-07-22T23:00', False], ['2027-07-23T19:00', '2027-07-24T00:00', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 4, ['TRANSFERS']]]], [['international 24h exactly', {'segments': [['2027-05-01T10:00', '2027-05-01T18:00', False], ['2027-05-02T18:00', '2027-05-02T23:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['domestic five hour connection', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T14:03', '2027-05-01T16:00', True]], 'max_stopovers': 0, 'max_transfers': 1}, [1, 1, ['STOPOVERS']]], ['mixed connection 6h', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T15:00', '2027-05-02T07:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['long flight short connection', {'segments': [['2027-05-01T07:00', '2027-05-02T01:00', False], ['2027-05-02T03:00', '2027-05-02T09:00', False], ['2027-05-03T10:00', '2027-05-03T12:00', False]], 'max_stopovers': 1, 'max_transfers': 1}, [1, 2, ['TRANSFERS']]], ['three stopovers', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', False], ['2027-05-03T07:00', '2027-05-03T09:00', False], ['2027-05-05T07:00', '2027-05-05T09:00', False], ['2027-05-06T07:00', '2027-05-09T09:00', False]], 'max_stopovers': 2, 'max_transfers': 3}, [2, 3, []]], ['nonstop', {'segments': [['2027-05-01T07:00', '2027-05-01T09:03', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 0, []]], ['sampled case 1', {'segments': [['2027-02-15T21:15', '2027-02-15T23:15', True], ['2027-02-16T07:45', '2027-02-16T18:45', True], ['2027-02-17T02:45', '2027-02-17T13:45', False], ['2027-02-17T22:15', '2027-02-18T00:45', False], ['2027-02-18T20:45', '2027-02-19T02:15', False]], 'max_stopovers': 1, 'max_transfers': 3}, [1, 4, ['TRANSFERS']]], ['sampled case 2', {'segments': [['2029-05-25T20:00', '2029-05-26T01:00', True], ['2029-05-27T02:00', '2029-05-27T07:00', False], ['2029-05-28T08:30', '2029-05-28T17:00', False], ['2029-05-28T19:00', '2029-05-29T07:30', False], ['2029-05-29T09:30', '2029-05-29T13:00', False]], 'max_stopovers': 1, 'max_transfers': 3}, [2, 4, ['STOPOVERS', 'TRANSFERS']]], ['sampled case 3', {'segments': [['2028-09-07T21:45', '2028-09-08T03:15', True], ['2028-09-08T23:15', '2028-09-09T11:15', True], ['2028-09-10T11:15', '2028-09-10T14:45', False], ['2028-09-12T14:45', '2028-09-13T04:45', True], ['2028-09-13T05:45', '2028-09-13T20:15', True]], 'max_stopovers': 0, 'max_transfers': 2}, [2, 4, ['STOPOVERS', 'TRANSFERS']]]], [['international 24h exactly', {'segments': [['2027-05-01T10:00', '2027-05-01T18:00', False], ['2027-05-02T18:00', '2027-05-02T23:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['domestic five hour connection', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T14:04', '2027-05-01T16:00', True]], 'max_stopovers': 0, 'max_transfers': 1}, [1, 1, ['STOPOVERS']]], ['mixed connection 6h', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T15:00', '2027-05-02T07:00', False]], 'max_stopovers': 0, 'max_transfers': 1}, [0, 1, []]], ['long flight short connection', {'segments': [['2027-05-01T07:00', '2027-05-02T01:00', False], ['2027-05-02T03:00', '2027-05-02T09:00', False], ['2027-05-03T10:00', '2027-05-03T12:00', False]], 'max_stopovers': 1, 'max_transfers': 1}, [1, 2, ['TRANSFERS']]], ['three stopovers', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', False], ['2027-05-03T07:00', '2027-05-03T09:00', False], ['2027-05-05T07:00', '2027-05-05T09:00', False], ['2027-05-07T07:00', '2027-05-09T09:00', False]], 'max_stopovers': 2, 'max_transfers': 3}, [3, 3, ['STOPOVERS']]], ['nonstop', {'segments': [['2027-05-01T07:00', '2027-05-01T09:04', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 0, []]], ['sampled case 1', {'segments': [['2027-11-27T17:15', '2027-11-27T23:45', False], ['2027-11-28T01:45', '2027-11-28T11:45', False]], 'max_stopovers': 2, 'max_transfers': 3}, [0, 1, []]], ['sampled case 2', {'segments': [['2029-03-09T18:00', '2029-03-10T02:00', True], ['2029-03-10T03:00', '2029-03-10T12:00', True]], 'max_stopovers': 1, 'max_transfers': 2}, [0, 1, []]], ['sampled case 3', {'segments': [['2029-03-20T20:00', '2029-03-20T23:30', True], ['2029-03-21T02:30', '2029-03-21T12:00', False], ['2029-03-23T12:00', '2029-03-23T16:00', False], ['2029-03-23T21:00', '2029-03-24T01:30', False], ['2029-03-24T02:30', '2029-03-24T12:00', False]], 'max_stopovers': 1, 'max_transfers': 0}, [1, 4, ['TRANSFERS']]]], [['international 24h exactly', {'segments': [['2027-05-01T10:00', '2027-05-01T18:00', False], ['2027-05-02T18:00', '2027-05-02T23:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['domestic five hour connection', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T14:05', '2027-05-01T16:00', True]], 'max_stopovers': 0, 'max_transfers': 1}, [1, 1, ['STOPOVERS']]], ['mixed connection 6h', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T15:00', '2027-05-02T07:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['long flight short connection', {'segments': [['2027-05-01T07:00', '2027-05-02T01:00', False], ['2027-05-02T03:00', '2027-05-02T09:00', False], ['2027-05-03T10:00', '2027-05-03T12:00', False]], 'max_stopovers': 1, 'max_transfers': 1}, [1, 2, ['TRANSFERS']]], ['three stopovers', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', False], ['2027-05-03T07:00', '2027-05-03T09:00', False], ['2027-05-05T07:00', '2027-05-05T09:00', False], ['2027-05-08T07:00', '2027-05-09T09:00', False]], 'max_stopovers': 2, 'max_transfers': 3}, [3, 3, ['STOPOVERS']]], ['nonstop', {'segments': [['2027-05-01T07:00', '2027-05-01T09:05', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 0, []]], ['sampled case 1', {'segments': [['2027-02-17T17:30', '2027-02-17T20:00', False]], 'max_stopovers': 1, 'max_transfers': 0}, [0, 0, []]], ['sampled case 2', {'segments': [['2029-07-05T21:30', '2029-07-06T01:30', False], ['2029-07-06T02:30', '2029-07-06T07:30', True], ['2029-07-06T09:00', '2029-07-06T23:00', True], ['2029-07-08T00:30', '2029-07-08T15:00', True], ['2029-07-08T18:30', '2029-07-09T04:30', False]], 'max_stopovers': 2, 'max_transfers': 2}, [1, 4, ['TRANSFERS']]], ['sampled case 3', {'segments': [['2027-06-10T18:15', '2027-06-10T19:15', False], ['2027-06-10T22:45', '2027-06-11T12:15', True]], 'max_stopovers': 0, 'max_transfers': 3}, [0, 1, []]]]]
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:
Long-haul flights followed by short connections are counted as stopovers.

Input {'segments':[[departure, arrival ISO local, domestic flag]],'max_stopovers','max_transfers'}. At each connection the gap from the inbound arrival to the next departure is a stopover when it exceeds 4 h if both segments are domestic, otherwise 24 h (a gap equal to the limit is not a stopover). Every connection point is a transfer. Return [stopovers, transfers, failures in order STOPOVERS, TRANSFERS].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
N = 1
observations = []
def solve(x):
    segs = x['segments']
    stops = 0
    for (d0, a0, dom0), (d1, a1, dom1) in zip(segs, segs[1:]):
        gap = (datetime.datetime.fromisoformat(d1) - datetime.datetime.fromisoformat(a0)).total_seconds() / 3600
        limit = 4 if (dom0 and dom1) else 24
        if gap > limit: stops += 1
    transfers = len(segs)
    fails = []
    if stops > x['max_stopovers']: fails.append('STOPOVERS')
    if transfers > x['max_transfers']: fails.append('TRANSFERS')
    return [stops, transfers, fails]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['international 24h exactly', {'segments': [['2027-05-01T10:00', '2027-05-01T18:00', False], ['2027-05-02T18:00', '2027-05-02T23:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['domestic five hour connection', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T14:01', '2027-05-01T16:00', True]], 'max_stopovers': 0, 'max_transfers': 1}, [1, 1, ['STOPOVERS']]], ['mixed connection 6h', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T15:00', '2027-05-02T07:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['long flight short connection', {'segments': [['2027-05-01T07:00', '2027-05-02T01:00', False], ['2027-05-02T03:00', '2027-05-02T09:00', False], ['2027-05-03T10:00', '2027-05-03T12:00', False]], 'max_stopovers': 1, 'max_transfers': 1}, [1, 2, ['TRANSFERS']]], ['three stopovers', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', False], ['2027-05-03T07:00', '2027-05-03T09:00', False], ['2027-05-05T07:00', '2027-05-05T09:00', False], ['2027-05-07T07:00', '2027-05-09T09:00', False]], 'max_stopovers': 2, 'max_transfers': 3}, [3, 3, ['STOPOVERS']]], ['nonstop', {'segments': [['2027-05-01T07:00', '2027-05-01T09:01', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 0, []]], ['sampled case 1', {'segments': [['2029-07-06T05:00', '2029-07-06T16:00', False], ['2029-07-06T19:00', '2029-07-06T20:30', False], ['2029-07-07T00:30', '2029-07-07T14:30', False]], 'max_stopovers': 2, 'max_transfers': 2}, [0, 2, []]], ['sampled case 2', {'segments': [['2029-04-03T21:30', '2029-04-04T07:30', True]], 'max_stopovers': 2, 'max_transfers': 3}, [0, 0, []]], ['sampled case 3', {'segments': [['2028-08-09T11:30', '2028-08-09T19:00', False], ['2028-08-09T20:30', '2028-08-10T07:00', False], ['2028-08-10T12:00', '2028-08-10T18:30', True], ['2028-08-10T20:00', '2028-08-11T07:30', True]], 'max_stopovers': 2, 'max_transfers': 3}, [0, 3, []]]], [['international 24h exactly', {'segments': [['2027-05-01T10:00', '2027-05-01T18:00', False], ['2027-05-02T18:00', '2027-05-02T23:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['domestic five hour connection', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T14:02', '2027-05-01T16:00', True]], 'max_stopovers': 0, 'max_transfers': 1}, [1, 1, ['STOPOVERS']]], ['mixed connection 6h', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T15:00', '2027-05-02T07:00', False]], 'max_stopovers': 0, 'max_transfers': 1}, [0, 1, []]], ['long flight short connection', {'segments': [['2027-05-01T07:00', '2027-05-02T01:00', False], ['2027-05-02T03:00', '2027-05-02T09:00', False], ['2027-05-03T10:00', '2027-05-03T12:00', False]], 'max_stopovers': 1, 'max_transfers': 1}, [1, 2, ['TRANSFERS']]], ['three stopovers', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', False], ['2027-05-03T07:00', '2027-05-03T09:00', False], ['2027-05-05T07:00', '2027-05-05T09:00', False], ['2027-05-08T07:00', '2027-05-09T09:00', False]], 'max_stopovers': 2, 'max_transfers': 3}, [3, 3, ['STOPOVERS']]], ['nonstop', {'segments': [['2027-05-01T07:00', '2027-05-01T09:02', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 0, []]], ['sampled case 1', {'segments': [['2028-08-14T16:45', '2028-08-15T03:45', False], ['2028-08-17T03:45', '2028-08-17T17:45', False], ['2028-08-17T22:45', '2028-08-18T09:15', True], ['2028-08-18T13:15', '2028-08-18T22:45', False], ['2028-08-19T18:45', '2028-08-20T06:45', False]], 'max_stopovers': 2, 'max_transfers': 1}, [1, 4, ['TRANSFERS']]], ['sampled case 2', {'segments': [['2027-06-01T12:45', '2027-06-01T20:15', True], ['2027-06-01T22:15', '2027-06-02T11:45', True], ['2027-06-03T11:45', '2027-06-03T21:45', True]], 'max_stopovers': 1, 'max_transfers': 2}, [1, 2, []]], ['sampled case 3', {'segments': [['2027-07-21T03:00', '2027-07-21T07:00', False], ['2027-07-22T03:00', '2027-07-22T08:30', False], ['2027-07-22T09:30', '2027-07-22T16:30', False], ['2027-07-22T17:30', '2027-07-22T23:00', False], ['2027-07-23T19:00', '2027-07-24T00:00', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 4, ['TRANSFERS']]]], [['international 24h exactly', {'segments': [['2027-05-01T10:00', '2027-05-01T18:00', False], ['2027-05-02T18:00', '2027-05-02T23:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['domestic five hour connection', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T14:03', '2027-05-01T16:00', True]], 'max_stopovers': 0, 'max_transfers': 1}, [1, 1, ['STOPOVERS']]], ['mixed connection 6h', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T15:00', '2027-05-02T07:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['long flight short connection', {'segments': [['2027-05-01T07:00', '2027-05-02T01:00', False], ['2027-05-02T03:00', '2027-05-02T09:00', False], ['2027-05-03T10:00', '2027-05-03T12:00', False]], 'max_stopovers': 1, 'max_transfers': 1}, [1, 2, ['TRANSFERS']]], ['three stopovers', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', False], ['2027-05-03T07:00', '2027-05-03T09:00', False], ['2027-05-05T07:00', '2027-05-05T09:00', False], ['2027-05-06T07:00', '2027-05-09T09:00', False]], 'max_stopovers': 2, 'max_transfers': 3}, [2, 3, []]], ['nonstop', {'segments': [['2027-05-01T07:00', '2027-05-01T09:03', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 0, []]], ['sampled case 1', {'segments': [['2027-02-15T21:15', '2027-02-15T23:15', True], ['2027-02-16T07:45', '2027-02-16T18:45', True], ['2027-02-17T02:45', '2027-02-17T13:45', False], ['2027-02-17T22:15', '2027-02-18T00:45', False], ['2027-02-18T20:45', '2027-02-19T02:15', False]], 'max_stopovers': 1, 'max_transfers': 3}, [1, 4, ['TRANSFERS']]], ['sampled case 2', {'segments': [['2029-05-25T20:00', '2029-05-26T01:00', True], ['2029-05-27T02:00', '2029-05-27T07:00', False], ['2029-05-28T08:30', '2029-05-28T17:00', False], ['2029-05-28T19:00', '2029-05-29T07:30', False], ['2029-05-29T09:30', '2029-05-29T13:00', False]], 'max_stopovers': 1, 'max_transfers': 3}, [2, 4, ['STOPOVERS', 'TRANSFERS']]], ['sampled case 3', {'segments': [['2028-09-07T21:45', '2028-09-08T03:15', True], ['2028-09-08T23:15', '2028-09-09T11:15', True], ['2028-09-10T11:15', '2028-09-10T14:45', False], ['2028-09-12T14:45', '2028-09-13T04:45', True], ['2028-09-13T05:45', '2028-09-13T20:15', True]], 'max_stopovers': 0, 'max_transfers': 2}, [2, 4, ['STOPOVERS', 'TRANSFERS']]]], [['international 24h exactly', {'segments': [['2027-05-01T10:00', '2027-05-01T18:00', False], ['2027-05-02T18:00', '2027-05-02T23:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['domestic five hour connection', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T14:04', '2027-05-01T16:00', True]], 'max_stopovers': 0, 'max_transfers': 1}, [1, 1, ['STOPOVERS']]], ['mixed connection 6h', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T15:00', '2027-05-02T07:00', False]], 'max_stopovers': 0, 'max_transfers': 1}, [0, 1, []]], ['long flight short connection', {'segments': [['2027-05-01T07:00', '2027-05-02T01:00', False], ['2027-05-02T03:00', '2027-05-02T09:00', False], ['2027-05-03T10:00', '2027-05-03T12:00', False]], 'max_stopovers': 1, 'max_transfers': 1}, [1, 2, ['TRANSFERS']]], ['three stopovers', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', False], ['2027-05-03T07:00', '2027-05-03T09:00', False], ['2027-05-05T07:00', '2027-05-05T09:00', False], ['2027-05-07T07:00', '2027-05-09T09:00', False]], 'max_stopovers': 2, 'max_transfers': 3}, [3, 3, ['STOPOVERS']]], ['nonstop', {'segments': [['2027-05-01T07:00', '2027-05-01T09:04', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 0, []]], ['sampled case 1', {'segments': [['2027-11-27T17:15', '2027-11-27T23:45', False], ['2027-11-28T01:45', '2027-11-28T11:45', False]], 'max_stopovers': 2, 'max_transfers': 3}, [0, 1, []]], ['sampled case 2', {'segments': [['2029-03-09T18:00', '2029-03-10T02:00', True], ['2029-03-10T03:00', '2029-03-10T12:00', True]], 'max_stopovers': 1, 'max_transfers': 2}, [0, 1, []]], ['sampled case 3', {'segments': [['2029-03-20T20:00', '2029-03-20T23:30', True], ['2029-03-21T02:30', '2029-03-21T12:00', False], ['2029-03-23T12:00', '2029-03-23T16:00', False], ['2029-03-23T21:00', '2029-03-24T01:30', False], ['2029-03-24T02:30', '2029-03-24T12:00', False]], 'max_stopovers': 1, 'max_transfers': 0}, [1, 4, ['TRANSFERS']]]], [['international 24h exactly', {'segments': [['2027-05-01T10:00', '2027-05-01T18:00', False], ['2027-05-02T18:00', '2027-05-02T23:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['domestic five hour connection', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T14:05', '2027-05-01T16:00', True]], 'max_stopovers': 0, 'max_transfers': 1}, [1, 1, ['STOPOVERS']]], ['mixed connection 6h', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T15:00', '2027-05-02T07:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['long flight short connection', {'segments': [['2027-05-01T07:00', '2027-05-02T01:00', False], ['2027-05-02T03:00', '2027-05-02T09:00', False], ['2027-05-03T10:00', '2027-05-03T12:00', False]], 'max_stopovers': 1, 'max_transfers': 1}, [1, 2, ['TRANSFERS']]], ['three stopovers', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', False], ['2027-05-03T07:00', '2027-05-03T09:00', False], ['2027-05-05T07:00', '2027-05-05T09:00', False], ['2027-05-08T07:00', '2027-05-09T09:00', False]], 'max_stopovers': 2, 'max_transfers': 3}, [3, 3, ['STOPOVERS']]], ['nonstop', {'segments': [['2027-05-01T07:00', '2027-05-01T09:05', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 0, []]], ['sampled case 1', {'segments': [['2027-02-17T17:30', '2027-02-17T20:00', False]], 'max_stopovers': 1, 'max_transfers': 0}, [0, 0, []]], ['sampled case 2', {'segments': [['2029-07-05T21:30', '2029-07-06T01:30', False], ['2029-07-06T02:30', '2029-07-06T07:30', True], ['2029-07-06T09:00', '2029-07-06T23:00', True], ['2029-07-08T00:30', '2029-07-08T15:00', True], ['2029-07-08T18:30', '2029-07-09T04:30', False]], 'max_stopovers': 2, 'max_transfers': 2}, [1, 4, ['TRANSFERS']]], ['sampled case 3', {'segments': [['2027-06-10T18:15', '2027-06-10T19:15', False], ['2027-06-10T22:45', '2027-06-11T12:15', True]], 'max_stopovers': 0, 'max_transfers': 3}, [0, 1, []]]]]
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):
    segs = x['segments']
    stops = 0
    for (d0, a0, dom0), (d1, a1, dom1) in zip(segs, segs[1:]):
        gap = (datetime.datetime.fromisoformat(d1) - datetime.datetime.fromisoformat(a0)).total_seconds() / 3600
        limit = 4 if (dom0 and dom1) else 24
        if gap > limit: stops += 1
    transfers = len(segs) - 1 - stops
    fails = []
    if stops > x['max_stopovers']: fails.append('STOPOVERS')
    if transfers > x['max_transfers']: fails.append('TRANSFERS')
    return [stops, transfers, fails]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['international 24h exactly', {'segments': [['2027-05-01T10:00', '2027-05-01T18:00', False], ['2027-05-02T18:00', '2027-05-02T23:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['domestic five hour connection', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T14:01', '2027-05-01T16:00', True]], 'max_stopovers': 0, 'max_transfers': 1}, [1, 1, ['STOPOVERS']]], ['mixed connection 6h', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T15:00', '2027-05-02T07:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['long flight short connection', {'segments': [['2027-05-01T07:00', '2027-05-02T01:00', False], ['2027-05-02T03:00', '2027-05-02T09:00', False], ['2027-05-03T10:00', '2027-05-03T12:00', False]], 'max_stopovers': 1, 'max_transfers': 1}, [1, 2, ['TRANSFERS']]], ['three stopovers', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', False], ['2027-05-03T07:00', '2027-05-03T09:00', False], ['2027-05-05T07:00', '2027-05-05T09:00', False], ['2027-05-07T07:00', '2027-05-09T09:00', False]], 'max_stopovers': 2, 'max_transfers': 3}, [3, 3, ['STOPOVERS']]], ['nonstop', {'segments': [['2027-05-01T07:00', '2027-05-01T09:01', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 0, []]], ['sampled case 1', {'segments': [['2029-07-06T05:00', '2029-07-06T16:00', False], ['2029-07-06T19:00', '2029-07-06T20:30', False], ['2029-07-07T00:30', '2029-07-07T14:30', False]], 'max_stopovers': 2, 'max_transfers': 2}, [0, 2, []]], ['sampled case 2', {'segments': [['2029-04-03T21:30', '2029-04-04T07:30', True]], 'max_stopovers': 2, 'max_transfers': 3}, [0, 0, []]], ['sampled case 3', {'segments': [['2028-08-09T11:30', '2028-08-09T19:00', False], ['2028-08-09T20:30', '2028-08-10T07:00', False], ['2028-08-10T12:00', '2028-08-10T18:30', True], ['2028-08-10T20:00', '2028-08-11T07:30', True]], 'max_stopovers': 2, 'max_transfers': 3}, [0, 3, []]]], [['international 24h exactly', {'segments': [['2027-05-01T10:00', '2027-05-01T18:00', False], ['2027-05-02T18:00', '2027-05-02T23:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['domestic five hour connection', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T14:02', '2027-05-01T16:00', True]], 'max_stopovers': 0, 'max_transfers': 1}, [1, 1, ['STOPOVERS']]], ['mixed connection 6h', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T15:00', '2027-05-02T07:00', False]], 'max_stopovers': 0, 'max_transfers': 1}, [0, 1, []]], ['long flight short connection', {'segments': [['2027-05-01T07:00', '2027-05-02T01:00', False], ['2027-05-02T03:00', '2027-05-02T09:00', False], ['2027-05-03T10:00', '2027-05-03T12:00', False]], 'max_stopovers': 1, 'max_transfers': 1}, [1, 2, ['TRANSFERS']]], ['three stopovers', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', False], ['2027-05-03T07:00', '2027-05-03T09:00', False], ['2027-05-05T07:00', '2027-05-05T09:00', False], ['2027-05-08T07:00', '2027-05-09T09:00', False]], 'max_stopovers': 2, 'max_transfers': 3}, [3, 3, ['STOPOVERS']]], ['nonstop', {'segments': [['2027-05-01T07:00', '2027-05-01T09:02', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 0, []]], ['sampled case 1', {'segments': [['2028-08-14T16:45', '2028-08-15T03:45', False], ['2028-08-17T03:45', '2028-08-17T17:45', False], ['2028-08-17T22:45', '2028-08-18T09:15', True], ['2028-08-18T13:15', '2028-08-18T22:45', False], ['2028-08-19T18:45', '2028-08-20T06:45', False]], 'max_stopovers': 2, 'max_transfers': 1}, [1, 4, ['TRANSFERS']]], ['sampled case 2', {'segments': [['2027-06-01T12:45', '2027-06-01T20:15', True], ['2027-06-01T22:15', '2027-06-02T11:45', True], ['2027-06-03T11:45', '2027-06-03T21:45', True]], 'max_stopovers': 1, 'max_transfers': 2}, [1, 2, []]], ['sampled case 3', {'segments': [['2027-07-21T03:00', '2027-07-21T07:00', False], ['2027-07-22T03:00', '2027-07-22T08:30', False], ['2027-07-22T09:30', '2027-07-22T16:30', False], ['2027-07-22T17:30', '2027-07-22T23:00', False], ['2027-07-23T19:00', '2027-07-24T00:00', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 4, ['TRANSFERS']]]], [['international 24h exactly', {'segments': [['2027-05-01T10:00', '2027-05-01T18:00', False], ['2027-05-02T18:00', '2027-05-02T23:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['domestic five hour connection', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T14:03', '2027-05-01T16:00', True]], 'max_stopovers': 0, 'max_transfers': 1}, [1, 1, ['STOPOVERS']]], ['mixed connection 6h', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T15:00', '2027-05-02T07:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['long flight short connection', {'segments': [['2027-05-01T07:00', '2027-05-02T01:00', False], ['2027-05-02T03:00', '2027-05-02T09:00', False], ['2027-05-03T10:00', '2027-05-03T12:00', False]], 'max_stopovers': 1, 'max_transfers': 1}, [1, 2, ['TRANSFERS']]], ['three stopovers', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', False], ['2027-05-03T07:00', '2027-05-03T09:00', False], ['2027-05-05T07:00', '2027-05-05T09:00', False], ['2027-05-06T07:00', '2027-05-09T09:00', False]], 'max_stopovers': 2, 'max_transfers': 3}, [2, 3, []]], ['nonstop', {'segments': [['2027-05-01T07:00', '2027-05-01T09:03', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 0, []]], ['sampled case 1', {'segments': [['2027-02-15T21:15', '2027-02-15T23:15', True], ['2027-02-16T07:45', '2027-02-16T18:45', True], ['2027-02-17T02:45', '2027-02-17T13:45', False], ['2027-02-17T22:15', '2027-02-18T00:45', False], ['2027-02-18T20:45', '2027-02-19T02:15', False]], 'max_stopovers': 1, 'max_transfers': 3}, [1, 4, ['TRANSFERS']]], ['sampled case 2', {'segments': [['2029-05-25T20:00', '2029-05-26T01:00', True], ['2029-05-27T02:00', '2029-05-27T07:00', False], ['2029-05-28T08:30', '2029-05-28T17:00', False], ['2029-05-28T19:00', '2029-05-29T07:30', False], ['2029-05-29T09:30', '2029-05-29T13:00', False]], 'max_stopovers': 1, 'max_transfers': 3}, [2, 4, ['STOPOVERS', 'TRANSFERS']]], ['sampled case 3', {'segments': [['2028-09-07T21:45', '2028-09-08T03:15', True], ['2028-09-08T23:15', '2028-09-09T11:15', True], ['2028-09-10T11:15', '2028-09-10T14:45', False], ['2028-09-12T14:45', '2028-09-13T04:45', True], ['2028-09-13T05:45', '2028-09-13T20:15', True]], 'max_stopovers': 0, 'max_transfers': 2}, [2, 4, ['STOPOVERS', 'TRANSFERS']]]], [['international 24h exactly', {'segments': [['2027-05-01T10:00', '2027-05-01T18:00', False], ['2027-05-02T18:00', '2027-05-02T23:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['domestic five hour connection', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T14:04', '2027-05-01T16:00', True]], 'max_stopovers': 0, 'max_transfers': 1}, [1, 1, ['STOPOVERS']]], ['mixed connection 6h', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T15:00', '2027-05-02T07:00', False]], 'max_stopovers': 0, 'max_transfers': 1}, [0, 1, []]], ['long flight short connection', {'segments': [['2027-05-01T07:00', '2027-05-02T01:00', False], ['2027-05-02T03:00', '2027-05-02T09:00', False], ['2027-05-03T10:00', '2027-05-03T12:00', False]], 'max_stopovers': 1, 'max_transfers': 1}, [1, 2, ['TRANSFERS']]], ['three stopovers', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', False], ['2027-05-03T07:00', '2027-05-03T09:00', False], ['2027-05-05T07:00', '2027-05-05T09:00', False], ['2027-05-07T07:00', '2027-05-09T09:00', False]], 'max_stopovers': 2, 'max_transfers': 3}, [3, 3, ['STOPOVERS']]], ['nonstop', {'segments': [['2027-05-01T07:00', '2027-05-01T09:04', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 0, []]], ['sampled case 1', {'segments': [['2027-11-27T17:15', '2027-11-27T23:45', False], ['2027-11-28T01:45', '2027-11-28T11:45', False]], 'max_stopovers': 2, 'max_transfers': 3}, [0, 1, []]], ['sampled case 2', {'segments': [['2029-03-09T18:00', '2029-03-10T02:00', True], ['2029-03-10T03:00', '2029-03-10T12:00', True]], 'max_stopovers': 1, 'max_transfers': 2}, [0, 1, []]], ['sampled case 3', {'segments': [['2029-03-20T20:00', '2029-03-20T23:30', True], ['2029-03-21T02:30', '2029-03-21T12:00', False], ['2029-03-23T12:00', '2029-03-23T16:00', False], ['2029-03-23T21:00', '2029-03-24T01:30', False], ['2029-03-24T02:30', '2029-03-24T12:00', False]], 'max_stopovers': 1, 'max_transfers': 0}, [1, 4, ['TRANSFERS']]]], [['international 24h exactly', {'segments': [['2027-05-01T10:00', '2027-05-01T18:00', False], ['2027-05-02T18:00', '2027-05-02T23:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['domestic five hour connection', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T14:05', '2027-05-01T16:00', True]], 'max_stopovers': 0, 'max_transfers': 1}, [1, 1, ['STOPOVERS']]], ['mixed connection 6h', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', True], ['2027-05-01T15:00', '2027-05-02T07:00', False]], 'max_stopovers': 0, 'max_transfers': 2}, [0, 1, []]], ['long flight short connection', {'segments': [['2027-05-01T07:00', '2027-05-02T01:00', False], ['2027-05-02T03:00', '2027-05-02T09:00', False], ['2027-05-03T10:00', '2027-05-03T12:00', False]], 'max_stopovers': 1, 'max_transfers': 1}, [1, 2, ['TRANSFERS']]], ['three stopovers', {'segments': [['2027-05-01T07:00', '2027-05-01T09:00', False], ['2027-05-03T07:00', '2027-05-03T09:00', False], ['2027-05-05T07:00', '2027-05-05T09:00', False], ['2027-05-08T07:00', '2027-05-09T09:00', False]], 'max_stopovers': 2, 'max_transfers': 3}, [3, 3, ['STOPOVERS']]], ['nonstop', {'segments': [['2027-05-01T07:00', '2027-05-01T09:05', False]], 'max_stopovers': 0, 'max_transfers': 0}, [0, 0, []]], ['sampled case 1', {'segments': [['2027-02-17T17:30', '2027-02-17T20:00', False]], 'max_stopovers': 1, 'max_transfers': 0}, [0, 0, []]], ['sampled case 2', {'segments': [['2029-07-05T21:30', '2029-07-06T01:30', False], ['2029-07-06T02:30', '2029-07-06T07:30', True], ['2029-07-06T09:00', '2029-07-06T23:00', True], ['2029-07-08T00:30', '2029-07-08T15:00', True], ['2029-07-08T18:30', '2029-07-09T04:30', False]], 'max_stopovers': 2, 'max_transfers': 2}, [1, 4, ['TRANSFERS']]], ['sampled case 3', {'segments': [['2027-06-10T18:15', '2027-06-10T19:15', False], ['2027-06-10T22:45', '2027-06-11T12:15', True]], 'max_stopovers': 0, 'max_transfers': 3}, [0, 1, []]]]]
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 nonstop flight reports one transfer.

Input {'segments':[[departure, arrival ISO local, domestic flag]],'max_stopovers','max_transfers'}. At each connection the gap from the inbound arrival to the next departure is a stopover when it exceeds 4 h if both segments are domestic, otherwise 24 h (a gap equal to the limit is not a stopover). Every connection point is a transfer. Return [stopovers, transfers, failures in order STOPOVERS, TRANSFERS].

split: open-access