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

N = 1
observations = []
def solve(x):
    cap = x['cap']
    pos = x['start']
    t = 0
    d = 'up'
    waiting = {r[0]: r for r in x['requests']}
    riding = {}
    picked = {}
    done = {}
    for _ in range(400):
        if not waiting and not riding:
            break
        stopped = False
        for pid in sorted(waiting):
            r = waiting[pid]
            rdir = 'up' if r[2] > r[1] else 'down'
            if r[1] == pos and rdir == d and len(riding) < cap:
                riding[pid] = r
                picked[pid] = t
                del waiting[pid]
                stopped = True
        for pid in sorted(riding):
            if riding[pid][2] == pos:
                done[pid] = [picked[pid], t]
                del riding[pid]
                stopped = True
        if stopped:
            t += x['stop_s']
        targets = [r[2] for r in riding.values()] + [r[1] for r in waiting.values()]
        ahead = [f for f in targets if (f > pos if d == 'up' else f < pos)]
        if not ahead:
            d = 'down' if d == 'up' else 'up'
            continue
        pos += 1 if d == 'up' else -1
        t += x['floor_s']
    return done
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: full car at a floor where a rider alights', {'cap': 1, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 3], ['b', 3, 6]]}, {'a': [0, 11], 'b': [11, 22]}), ('sampled regression 40', {'cap': 2, 'start': 6, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 9, 5], ['p1', 8, 3], ['p2', 5, 4]]}, {'p0': [6, 30], 'p2': [30, 40], 'p1': [16, 50]}), ('boundary: capacity exactly reached', {'cap': 2, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 4], ['b', 0, 5], ['c', 0, 6]]}, {'a': [0, 13], 'b': [0, 20], 'c': [35, 52]}), ('boundary: opposite-direction passenger waits', {'cap': 4, 'start': 2, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 2, 0], ['b', 2, 5]]}, {'b': [0, 11], 'a': [22, 31]}), ('boundary: two boardings share one stop', {'cap': 4, 'start': 1, 'floor_s': 2, 'stop_s': 8, 'requests': [['a', 1, 4], ['b', 1, 4]]}, {'a': [0, 14], 'b': [0, 14]}), ('control 1', {'cap': 1, 'start': 5, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 6, 8], ['p1', 3, 7], ['p2', 0, 7], ['p3', 3, 2], ['p4', 7, 1]]}, {'p0': [2, 11], 'p4': [18, 35], 'p2': [42, 61], 'p3': [74, 81], 'p1': [88, 101]}), ('control 4', {'cap': 4, 'start': 1, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 2, 8], ['p1', 8, 1], ['p2', 0, 8], ['p3', 5, 6]]}, {'p3': [13, 20], 'p0': [2, 29], 'p1': [34, 53], 'p2': [60, 81]}), ('control 7', {'cap': 4, 'start': 6, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 8, 9], ['p1', 7, 5], ['p2', 6, 0]]}, {'p0': [4, 11], 'p1': [20, 34], 'p2': [27, 49]})], [('regression: full car at a floor where a rider alights', {'cap': 1, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 3], ['b', 3, 6]]}, {'a': [0, 11], 'b': [11, 22]}), ('boundary: capacity exactly reached', {'cap': 2, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 4], ['b', 0, 5], ['c', 0, 6]]}, {'a': [0, 13], 'b': [0, 20], 'c': [35, 52]}), ('sampled regression 40', {'cap': 2, 'start': 6, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 9, 5], ['p1', 8, 3], ['p2', 5, 4]]}, {'p0': [6, 30], 'p2': [30, 40], 'p1': [16, 50]}), ('control 28', {'cap': 2, 'start': 8, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 2, 5], ['p1', 0, 5], ['p2', 7, 1], ['p3', 5, 3], ['p4', 5, 0]]}, {'p3': [14, 26], 'p2': [2, 38], 'p0': [60, 74], 'p1': [48, 74], 'p4': [82, 100]}), ('boundary: two boardings share one stop', {'cap': 4, 'start': 1, 'floor_s': 2, 'stop_s': 8, 'requests': [['a', 1, 4], ['b', 1, 4]]}, {'a': [0, 14], 'b': [0, 14]}), ('control 12', {'cap': 4, 'start': 2, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 8, 3], ['p1', 8, 4], ['p2', 2, 8], ['p3', 5, 0], ['p4', 8, 2], ['p5', 7, 9]]}, {'p2': [0, 28], 'p5': [18, 38], 'p1': [48, 72], 'p0': [48, 82], 'p4': [48, 92], 'p3': [62, 104]}), ('control 15', {'cap': 2, 'start': 8, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 6, 3], ['p1', 4, 1], ['p2', 5, 0]]}, {'p0': [4, 26], 'p2': [14, 40], 'p1': [56, 70]}), ('control 18', {'cap': 4, 'start': 9, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 1, 0], ['p1', 7, 8], ['p2', 1, 8]]}, {'p0': [16, 26], 'p1': [56, 66], 'p2': [36, 66]})], [('regression: full car at a floor where a rider alights', {'cap': 1, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 3], ['b', 3, 6]]}, {'a': [0, 11], 'b': [11, 22]}), ('sampled regression 40', {'cap': 2, 'start': 6, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 9, 5], ['p1', 8, 3], ['p2', 5, 4]]}, {'p0': [6, 30], 'p2': [30, 40], 'p1': [16, 50]}), ('sampled regression 69', {'cap': 2, 'start': 4, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 3, 9], ['p1', 8, 1], ['p2', 4, 8], ['p3', 4, 7], ['p4', 7, 8]]}, {'p3': [0, 14], 'p2': [0, 24], 'p4': [14, 24], 'p1': [32, 54], 'p0': [66, 86]}), ('boundary: alighting-only stop', {'cap': 4, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 2], ['b', 5, 6]]}, {'a': [0, 9], 'b': [20, 27]}), ('boundary: opposite-direction passenger waits', {'cap': 4, 'start': 2, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 2, 0], ['b', 2, 5]]}, {'b': [0, 11], 'a': [22, 31]}), ('control 23', {'cap': 4, 'start': 8, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 9, 4], ['p1', 9, 1], ['p2', 0, 1], ['p3', 6, 2]]}, {'p0': [2, 22], 'p3': [13, 31], 'p1': [2, 38], 'p2': [45, 52]}), ('control 26', {'cap': 1, 'start': 3, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 0, 4], ['p1', 1, 6], ['p2', 1, 6], ['p3', 5, 1]]}, {'p3': [4, 20], 'p0': [30, 46], 'p1': [60, 78], 'p2': [96, 114]}), ('control 29', {'cap': 4, 'start': 5, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 8, 5], ['p1', 0, 2], ['p2', 7, 1]]}, {'p0': [6, 28], 'p2': [16, 44], 'p1': [54, 66]})], [('regression: full car at a floor where a rider alights', {'cap': 1, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 3], ['b', 3, 6]]}, {'a': [0, 11], 'b': [11, 22]}), ('boundary: capacity exactly reached', {'cap': 2, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 4], ['b', 0, 5], ['c', 0, 6]]}, {'a': [0, 13], 'b': [0, 20], 'c': [35, 52]}), ('sampled regression 40', {'cap': 2, 'start': 6, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 9, 5], ['p1', 8, 3], ['p2', 5, 4]]}, {'p0': [6, 30], 'p2': [30, 40], 'p1': [16, 50]}), ('control 8', {'cap': 1, 'start': 7, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 4, 9], ['p1', 9, 3], ['p2', 9, 7], ['p3', 2, 1], ['p4', 1, 3]]}, {'p1': [4, 24], 'p3': [34, 44], 'p4': [52, 64], 'p0': [74, 92], 'p2': [100, 112]}), ('boundary: opposite-direction passenger waits', {'cap': 4, 'start': 2, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 2, 0], ['b', 2, 5]]}, {'b': [0, 11], 'a': [22, 31]}), ('control 34', {'cap': 2, 'start': 4, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 2, 0], ['p1', 2, 8], ['p2', 6, 1], ['p3', 3, 7], ['p4', 6, 8], ['p5', 2, 4]]}, {'p4': [4, 13], 'p2': [22, 42], 'p0': [35, 49], 'p5': [58, 67], 'p1': [58, 80], 'p3': [95, 108]}), ('control 37', {'cap': 2, 'start': 2, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 5, 9], ['p1', 6, 7]]}, {'p1': [13, 20], 'p0': [6, 29]}), ('control 43', {'cap': 4, 'start': 3, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 7, 4], ['p1', 2, 1], ['p2', 7, 5], ['p3', 5, 1]]}, {'p2': [8, 20], 'p0': [8, 30], 'p1': [42, 52], 'p3': [20, 52]})], [('regression: full car at a floor where a rider alights', {'cap': 1, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 3], ['b', 3, 6]]}, {'a': [0, 11], 'b': [11, 22]}), ('sampled regression 40', {'cap': 2, 'start': 6, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 9, 5], ['p1', 8, 3], ['p2', 5, 4]]}, {'p0': [6, 30], 'p2': [30, 40], 'p1': [16, 50]}), ('boundary: two boardings share one stop', {'cap': 4, 'start': 1, 'floor_s': 2, 'stop_s': 8, 'requests': [['a', 1, 4], ['b', 1, 4]]}, {'a': [0, 14], 'b': [0, 14]}), ('boundary: alighting-only stop', {'cap': 4, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 2], ['b', 5, 6]]}, {'a': [0, 9], 'b': [20, 27]}), ('boundary: opposite-direction passenger waits', {'cap': 4, 'start': 2, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 2, 0], ['b', 2, 5]]}, {'b': [0, 11], 'a': [22, 31]}), ('control 45', {'cap': 4, 'start': 8, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 0, 2], ['p1', 6, 2], ['p2', 4, 5], ['p3', 1, 7], ['p4', 7, 4]]}, {'p4': [2, 18], 'p1': [9, 27], 'p0': [36, 50], 'p2': [59, 66], 'p3': [43, 75]}), ('control 48', {'cap': 2, 'start': 8, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 2, 0], ['p1', 0, 2], ['p2', 8, 5], ['p3', 6, 4], ['p4', 0, 3]]}, {'p2': [0, 16], 'p3': [9, 23], 'p0': [32, 41], 'p1': [46, 55], 'p4': [46, 62]}), ('control 51', {'cap': 4, 'start': 4, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 8, 9], ['p1', 2, 6], ['p2', 8, 1], ['p3', 1, 6], ['p4', 3, 1]]}, {'p0': [8, 15], 'p2': [22, 46], 'p4': [37, 46], 'p1': [58, 71], 'p3': [51, 71]})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    cap = x['cap']
    pos = x['start']
    t = 0
    d = 'up'
    waiting = {r[0]: r for r in x['requests']}
    riding = {}
    picked = {}
    done = {}
    for _ in range(400):
        if not waiting and not riding:
            break
        stopped = False
        load_before = len(riding)
        for pid in sorted(riding):
            if riding[pid][2] == pos:
                done[pid] = [picked[pid], t]
                del riding[pid]
                stopped = True
        for pid in sorted(waiting):
            r = waiting[pid]
            rdir = 'up' if r[2] > r[1] else 'down'
            if r[1] == pos and rdir == d and load_before < cap:
                riding[pid] = r
                picked[pid] = t
                del waiting[pid]
                stopped = True
        if stopped:
            t += x['stop_s']
        targets = [r[2] for r in riding.values()] + [r[1] for r in waiting.values()]
        ahead = [f for f in targets if (f > pos if d == 'up' else f < pos)]
        if not ahead:
            d = 'down' if d == 'up' else 'up'
            continue
        pos += 1 if d == 'up' else -1
        t += x['floor_s']
    return done
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: full car at a floor where a rider alights', {'cap': 1, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 3], ['b', 3, 6]]}, {'a': [0, 11], 'b': [11, 22]}), ('sampled regression 40', {'cap': 2, 'start': 6, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 9, 5], ['p1', 8, 3], ['p2', 5, 4]]}, {'p0': [6, 30], 'p2': [30, 40], 'p1': [16, 50]}), ('boundary: capacity exactly reached', {'cap': 2, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 4], ['b', 0, 5], ['c', 0, 6]]}, {'a': [0, 13], 'b': [0, 20], 'c': [35, 52]}), ('boundary: opposite-direction passenger waits', {'cap': 4, 'start': 2, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 2, 0], ['b', 2, 5]]}, {'b': [0, 11], 'a': [22, 31]}), ('boundary: two boardings share one stop', {'cap': 4, 'start': 1, 'floor_s': 2, 'stop_s': 8, 'requests': [['a', 1, 4], ['b', 1, 4]]}, {'a': [0, 14], 'b': [0, 14]}), ('control 1', {'cap': 1, 'start': 5, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 6, 8], ['p1', 3, 7], ['p2', 0, 7], ['p3', 3, 2], ['p4', 7, 1]]}, {'p0': [2, 11], 'p4': [18, 35], 'p2': [42, 61], 'p3': [74, 81], 'p1': [88, 101]}), ('control 4', {'cap': 4, 'start': 1, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 2, 8], ['p1', 8, 1], ['p2', 0, 8], ['p3', 5, 6]]}, {'p3': [13, 20], 'p0': [2, 29], 'p1': [34, 53], 'p2': [60, 81]}), ('control 7', {'cap': 4, 'start': 6, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 8, 9], ['p1', 7, 5], ['p2', 6, 0]]}, {'p0': [4, 11], 'p1': [20, 34], 'p2': [27, 49]})], [('regression: full car at a floor where a rider alights', {'cap': 1, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 3], ['b', 3, 6]]}, {'a': [0, 11], 'b': [11, 22]}), ('boundary: capacity exactly reached', {'cap': 2, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 4], ['b', 0, 5], ['c', 0, 6]]}, {'a': [0, 13], 'b': [0, 20], 'c': [35, 52]}), ('sampled regression 40', {'cap': 2, 'start': 6, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 9, 5], ['p1', 8, 3], ['p2', 5, 4]]}, {'p0': [6, 30], 'p2': [30, 40], 'p1': [16, 50]}), ('control 28', {'cap': 2, 'start': 8, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 2, 5], ['p1', 0, 5], ['p2', 7, 1], ['p3', 5, 3], ['p4', 5, 0]]}, {'p3': [14, 26], 'p2': [2, 38], 'p0': [60, 74], 'p1': [48, 74], 'p4': [82, 100]}), ('boundary: two boardings share one stop', {'cap': 4, 'start': 1, 'floor_s': 2, 'stop_s': 8, 'requests': [['a', 1, 4], ['b', 1, 4]]}, {'a': [0, 14], 'b': [0, 14]}), ('control 12', {'cap': 4, 'start': 2, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 8, 3], ['p1', 8, 4], ['p2', 2, 8], ['p3', 5, 0], ['p4', 8, 2], ['p5', 7, 9]]}, {'p2': [0, 28], 'p5': [18, 38], 'p1': [48, 72], 'p0': [48, 82], 'p4': [48, 92], 'p3': [62, 104]}), ('control 15', {'cap': 2, 'start': 8, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 6, 3], ['p1', 4, 1], ['p2', 5, 0]]}, {'p0': [4, 26], 'p2': [14, 40], 'p1': [56, 70]}), ('control 18', {'cap': 4, 'start': 9, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 1, 0], ['p1', 7, 8], ['p2', 1, 8]]}, {'p0': [16, 26], 'p1': [56, 66], 'p2': [36, 66]})], [('regression: full car at a floor where a rider alights', {'cap': 1, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 3], ['b', 3, 6]]}, {'a': [0, 11], 'b': [11, 22]}), ('sampled regression 40', {'cap': 2, 'start': 6, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 9, 5], ['p1', 8, 3], ['p2', 5, 4]]}, {'p0': [6, 30], 'p2': [30, 40], 'p1': [16, 50]}), ('sampled regression 69', {'cap': 2, 'start': 4, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 3, 9], ['p1', 8, 1], ['p2', 4, 8], ['p3', 4, 7], ['p4', 7, 8]]}, {'p3': [0, 14], 'p2': [0, 24], 'p4': [14, 24], 'p1': [32, 54], 'p0': [66, 86]}), ('boundary: alighting-only stop', {'cap': 4, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 2], ['b', 5, 6]]}, {'a': [0, 9], 'b': [20, 27]}), ('boundary: opposite-direction passenger waits', {'cap': 4, 'start': 2, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 2, 0], ['b', 2, 5]]}, {'b': [0, 11], 'a': [22, 31]}), ('control 23', {'cap': 4, 'start': 8, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 9, 4], ['p1', 9, 1], ['p2', 0, 1], ['p3', 6, 2]]}, {'p0': [2, 22], 'p3': [13, 31], 'p1': [2, 38], 'p2': [45, 52]}), ('control 26', {'cap': 1, 'start': 3, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 0, 4], ['p1', 1, 6], ['p2', 1, 6], ['p3', 5, 1]]}, {'p3': [4, 20], 'p0': [30, 46], 'p1': [60, 78], 'p2': [96, 114]}), ('control 29', {'cap': 4, 'start': 5, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 8, 5], ['p1', 0, 2], ['p2', 7, 1]]}, {'p0': [6, 28], 'p2': [16, 44], 'p1': [54, 66]})], [('regression: full car at a floor where a rider alights', {'cap': 1, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 3], ['b', 3, 6]]}, {'a': [0, 11], 'b': [11, 22]}), ('boundary: capacity exactly reached', {'cap': 2, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 4], ['b', 0, 5], ['c', 0, 6]]}, {'a': [0, 13], 'b': [0, 20], 'c': [35, 52]}), ('sampled regression 40', {'cap': 2, 'start': 6, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 9, 5], ['p1', 8, 3], ['p2', 5, 4]]}, {'p0': [6, 30], 'p2': [30, 40], 'p1': [16, 50]}), ('control 8', {'cap': 1, 'start': 7, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 4, 9], ['p1', 9, 3], ['p2', 9, 7], ['p3', 2, 1], ['p4', 1, 3]]}, {'p1': [4, 24], 'p3': [34, 44], 'p4': [52, 64], 'p0': [74, 92], 'p2': [100, 112]}), ('boundary: opposite-direction passenger waits', {'cap': 4, 'start': 2, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 2, 0], ['b', 2, 5]]}, {'b': [0, 11], 'a': [22, 31]}), ('control 34', {'cap': 2, 'start': 4, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 2, 0], ['p1', 2, 8], ['p2', 6, 1], ['p3', 3, 7], ['p4', 6, 8], ['p5', 2, 4]]}, {'p4': [4, 13], 'p2': [22, 42], 'p0': [35, 49], 'p5': [58, 67], 'p1': [58, 80], 'p3': [95, 108]}), ('control 37', {'cap': 2, 'start': 2, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 5, 9], ['p1', 6, 7]]}, {'p1': [13, 20], 'p0': [6, 29]}), ('control 43', {'cap': 4, 'start': 3, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 7, 4], ['p1', 2, 1], ['p2', 7, 5], ['p3', 5, 1]]}, {'p2': [8, 20], 'p0': [8, 30], 'p1': [42, 52], 'p3': [20, 52]})], [('regression: full car at a floor where a rider alights', {'cap': 1, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 3], ['b', 3, 6]]}, {'a': [0, 11], 'b': [11, 22]}), ('sampled regression 40', {'cap': 2, 'start': 6, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 9, 5], ['p1', 8, 3], ['p2', 5, 4]]}, {'p0': [6, 30], 'p2': [30, 40], 'p1': [16, 50]}), ('boundary: two boardings share one stop', {'cap': 4, 'start': 1, 'floor_s': 2, 'stop_s': 8, 'requests': [['a', 1, 4], ['b', 1, 4]]}, {'a': [0, 14], 'b': [0, 14]}), ('boundary: alighting-only stop', {'cap': 4, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 2], ['b', 5, 6]]}, {'a': [0, 9], 'b': [20, 27]}), ('boundary: opposite-direction passenger waits', {'cap': 4, 'start': 2, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 2, 0], ['b', 2, 5]]}, {'b': [0, 11], 'a': [22, 31]}), ('control 45', {'cap': 4, 'start': 8, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 0, 2], ['p1', 6, 2], ['p2', 4, 5], ['p3', 1, 7], ['p4', 7, 4]]}, {'p4': [2, 18], 'p1': [9, 27], 'p0': [36, 50], 'p2': [59, 66], 'p3': [43, 75]}), ('control 48', {'cap': 2, 'start': 8, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 2, 0], ['p1', 0, 2], ['p2', 8, 5], ['p3', 6, 4], ['p4', 0, 3]]}, {'p2': [0, 16], 'p3': [9, 23], 'p0': [32, 41], 'p1': [46, 55], 'p4': [46, 62]}), ('control 51', {'cap': 4, 'start': 4, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 8, 9], ['p1', 2, 6], ['p2', 8, 1], ['p3', 1, 6], ['p4', 3, 1]]}, {'p0': [8, 15], 'p2': [22, 46], 'p4': [37, 46], 'p1': [58, 71], 'p3': [51, 71]})]]
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:
Waiting passengers are left behind at a floor where riders are getting out.

All passengers [id, from, to] wait at time 0. The car starts at start heading up. At each floor it first lets riders alight, then boards waiting passengers (in id order) whose travel direction equals the car direction while load < cap; any alighting or boarding costs one stop_s. If no rider destination or waiting origin lies strictly ahead it reverses in place (and may board again); otherwise it moves one floor (floor_s). Return {id: [board time, alight time]} for delivered passengers.

split: open-access


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

N = 1
observations = []
def solve(x):
    cap = x['cap']
    pos = x['start']
    t = 0
    d = 'up'
    waiting = {r[0]: r for r in x['requests']}
    riding = {}
    picked = {}
    done = {}
    for _ in range(400):
        if not waiting and not riding:
            break
        stopped = False
        for pid in sorted(riding):
            if riding[pid][2] == pos:
                done[pid] = [picked[pid], t]
                del riding[pid]
                stopped = True
        for pid in sorted(waiting):
            r = waiting[pid]
            rdir = 'up' if r[2] > r[1] else 'down'
            if r[1] == pos and len(riding) < cap:
                riding[pid] = r
                picked[pid] = t
                del waiting[pid]
                stopped = True
        if stopped:
            t += x['stop_s']
        targets = [r[2] for r in riding.values()] + [r[1] for r in waiting.values()]
        ahead = [f for f in targets if (f > pos if d == 'up' else f < pos)]
        if not ahead:
            d = 'down' if d == 'up' else 'up'
            continue
        pos += 1 if d == 'up' else -1
        t += x['floor_s']
    return done
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: opposite-direction passenger waits', {'cap': 4, 'start': 2, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 2, 0], ['b', 2, 5]]}, {'b': [0, 11], 'a': [22, 31]}), ('sampled regression 3', {'cap': 2, 'start': 5, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 5, 1], ['p1', 3, 5]]}, {'p0': [0, 13], 'p1': [22, 31]}), ('sampled regression 1', {'cap': 1, 'start': 5, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 6, 8], ['p1', 3, 7], ['p2', 0, 7], ['p3', 3, 2], ['p4', 7, 1]]}, {'p0': [2, 11], 'p4': [18, 35], 'p2': [42, 61], 'p3': [74, 81], 'p1': [88, 101]}), ('boundary: full car at a floor where a rider alights', {'cap': 1, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 3], ['b', 3, 6]]}, {'a': [0, 11], 'b': [11, 22]}), ('boundary: capacity exactly reached', {'cap': 2, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 4], ['b', 0, 5], ['c', 0, 6]]}, {'a': [0, 13], 'b': [0, 20], 'c': [35, 52]}), ('sampled regression 4', {'cap': 4, 'start': 1, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 2, 8], ['p1', 8, 1], ['p2', 0, 8], ['p3', 5, 6]]}, {'p3': [13, 20], 'p0': [2, 29], 'p1': [34, 53], 'p2': [60, 81]}), ('sampled regression 7', {'cap': 4, 'start': 6, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 8, 9], ['p1', 7, 5], ['p2', 6, 0]]}, {'p0': [4, 11], 'p1': [20, 34], 'p2': [27, 49]}), ('control 10', {'cap': 2, 'start': 5, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 3, 0], ['p1', 5, 6], ['p2', 5, 7]]}, {'p1': [0, 10], 'p2': [0, 20], 'p0': [36, 50]})], [('regression: opposite-direction passenger waits', {'cap': 4, 'start': 2, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 2, 0], ['b', 2, 5]]}, {'b': [0, 11], 'a': [22, 31]}), ('sampled regression 12', {'cap': 4, 'start': 2, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 8, 3], ['p1', 8, 4], ['p2', 2, 8], ['p3', 5, 0], ['p4', 8, 2], ['p5', 7, 9]]}, {'p2': [0, 28], 'p5': [18, 38], 'p1': [48, 72], 'p0': [48, 82], 'p4': [48, 92], 'p3': [62, 104]}), ('sampled regression 8', {'cap': 1, 'start': 7, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 4, 9], ['p1', 9, 3], ['p2', 9, 7], ['p3', 2, 1], ['p4', 1, 3]]}, {'p1': [4, 24], 'p3': [34, 44], 'p4': [52, 64], 'p0': [74, 92], 'p2': [100, 112]}), ('boundary: capacity exactly reached', {'cap': 2, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 4], ['b', 0, 5], ['c', 0, 6]]}, {'a': [0, 13], 'b': [0, 20], 'c': [35, 52]}), ('boundary: two boardings share one stop', {'cap': 4, 'start': 1, 'floor_s': 2, 'stop_s': 8, 'requests': [['a', 1, 4], ['b', 1, 4]]}, {'a': [0, 14], 'b': [0, 14]}), ('control 15', {'cap': 2, 'start': 8, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 6, 3], ['p1', 4, 1], ['p2', 5, 0]]}, {'p0': [4, 26], 'p2': [14, 40], 'p1': [56, 70]}), ('sampled regression 18', {'cap': 4, 'start': 9, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 1, 0], ['p1', 7, 8], ['p2', 1, 8]]}, {'p0': [16, 26], 'p1': [56, 66], 'p2': [36, 66]}), ('sampled regression 21', {'cap': 2, 'start': 0, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 8, 7], ['p1', 5, 9], ['p2', 4, 5], ['p3', 0, 1], ['p4', 2, 5], ['p5', 0, 5]]}, {'p3': [0, 10], 'p4': [20, 34], 'p5': [0, 34], 'p1': [34, 50], 'p0': [60, 70], 'p2': [84, 94]})], [('regression: opposite-direction passenger waits', {'cap': 4, 'start': 2, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 2, 0], ['b', 2, 5]]}, {'b': [0, 11], 'a': [22, 31]}), ('sampled regression 21', {'cap': 2, 'start': 0, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 8, 7], ['p1', 5, 9], ['p2', 4, 5], ['p3', 0, 1], ['p4', 2, 5], ['p5', 0, 5]]}, {'p3': [0, 10], 'p4': [20, 34], 'p5': [0, 34], 'p1': [34, 50], 'p0': [60, 70], 'p2': [84, 94]}), ('sampled regression 19', {'cap': 2, 'start': 1, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 0, 5], ['p1', 6, 4], ['p2', 9, 2], ['p3', 4, 5]]}, {'p3': [6, 16], 'p1': [46, 58], 'p2': [32, 70], 'p0': [82, 100]}), ('boundary: alighting-only stop', {'cap': 4, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 2], ['b', 5, 6]]}, {'a': [0, 9], 'b': [20, 27]}), ('boundary: full car at a floor where a rider alights', {'cap': 1, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 3], ['b', 3, 6]]}, {'a': [0, 11], 'b': [11, 22]}), ('control 23', {'cap': 4, 'start': 8, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 9, 4], ['p1', 9, 1], ['p2', 0, 1], ['p3', 6, 2]]}, {'p0': [2, 22], 'p3': [13, 31], 'p1': [2, 38], 'p2': [45, 52]}), ('sampled regression 26', {'cap': 1, 'start': 3, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 0, 4], ['p1', 1, 6], ['p2', 1, 6], ['p3', 5, 1]]}, {'p3': [4, 20], 'p0': [30, 46], 'p1': [60, 78], 'p2': [96, 114]}), ('sampled regression 29', {'cap': 4, 'start': 5, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 8, 5], ['p1', 0, 2], ['p2', 7, 1]]}, {'p0': [6, 28], 'p2': [16, 44], 'p1': [54, 66]})], [('regression: opposite-direction passenger waits', {'cap': 4, 'start': 2, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 2, 0], ['b', 2, 5]]}, {'b': [0, 11], 'a': [22, 31]}), ('sampled regression 30', {'cap': 1, 'start': 1, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 5, 1], ['p1', 9, 3], ['p2', 2, 5]]}, {'p2': [2, 16], 'p1': [32, 52], 'p0': [64, 80]}), ('sampled regression 25', {'cap': 4, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 2, 5], ['p1', 0, 3], ['p2', 6, 8], ['p3', 2, 3], ['p4', 8, 0], ['p5', 9, 6]]}, {'p1': [0, 16], 'p3': [9, 16], 'p0': [9, 25], 'p2': [32, 41], 'p5': [48, 64], 'p4': [55, 81]}), ('boundary: capacity exactly reached', {'cap': 2, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 4], ['b', 0, 5], ['c', 0, 6]]}, {'a': [0, 13], 'b': [0, 20], 'c': [35, 52]}), ('boundary: two boardings share one stop', {'cap': 4, 'start': 1, 'floor_s': 2, 'stop_s': 8, 'requests': [['a', 1, 4], ['b', 1, 4]]}, {'a': [0, 14], 'b': [0, 14]}), ('sampled regression 34', {'cap': 2, 'start': 4, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 2, 0], ['p1', 2, 8], ['p2', 6, 1], ['p3', 3, 7], ['p4', 6, 8], ['p5', 2, 4]]}, {'p4': [4, 13], 'p2': [22, 42], 'p0': [35, 49], 'p5': [58, 67], 'p1': [58, 80], 'p3': [95, 108]}), ('control 37', {'cap': 2, 'start': 2, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 5, 9], ['p1', 6, 7]]}, {'p1': [13, 20], 'p0': [6, 29]}), ('sampled regression 40', {'cap': 2, 'start': 6, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 9, 5], ['p1', 8, 3], ['p2', 5, 4]]}, {'p0': [6, 30], 'p2': [30, 40], 'p1': [16, 50]})], [('regression: opposite-direction passenger waits', {'cap': 4, 'start': 2, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 2, 0], ['b', 2, 5]]}, {'b': [0, 11], 'a': [22, 31]}), ('sampled regression 40', {'cap': 2, 'start': 6, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 9, 5], ['p1', 8, 3], ['p2', 5, 4]]}, {'p0': [6, 30], 'p2': [30, 40], 'p1': [16, 50]}), ('sampled regression 30', {'cap': 1, 'start': 1, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 5, 1], ['p1', 9, 3], ['p2', 2, 5]]}, {'p2': [2, 16], 'p1': [32, 52], 'p0': [64, 80]}), ('boundary: two boardings share one stop', {'cap': 4, 'start': 1, 'floor_s': 2, 'stop_s': 8, 'requests': [['a', 1, 4], ['b', 1, 4]]}, {'a': [0, 14], 'b': [0, 14]}), ('boundary: alighting-only stop', {'cap': 4, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 2], ['b', 5, 6]]}, {'a': [0, 9], 'b': [20, 27]}), ('sampled regression 45', {'cap': 4, 'start': 8, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 0, 2], ['p1', 6, 2], ['p2', 4, 5], ['p3', 1, 7], ['p4', 7, 4]]}, {'p4': [2, 18], 'p1': [9, 27], 'p0': [36, 50], 'p2': [59, 66], 'p3': [43, 75]}), ('sampled regression 48', {'cap': 2, 'start': 8, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 2, 0], ['p1', 0, 2], ['p2', 8, 5], ['p3', 6, 4], ['p4', 0, 3]]}, {'p2': [0, 16], 'p3': [9, 23], 'p0': [32, 41], 'p1': [46, 55], 'p4': [46, 62]}), ('sampled regression 51', {'cap': 4, 'start': 4, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 8, 9], ['p1', 2, 6], ['p2', 8, 1], ['p3', 1, 6], ['p4', 3, 1]]}, {'p0': [8, 15], 'p2': [22, 46], 'p4': [37, 46], 'p1': [58, 71], 'p3': [51, 71]})]]
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

N = 1
observations = []
def solve(x):
    cap = x['cap']
    pos = x['start']
    t = 0
    d = 'up'
    waiting = {r[0]: r for r in x['requests']}
    riding = {}
    picked = {}
    done = {}
    for _ in range(400):
        if not waiting and not riding:
            break
        stopped = False
        for pid in sorted(riding):
            if riding[pid][2] == pos:
                done[pid] = [picked[pid], t]
                del riding[pid]
                stopped = True
        for pid in sorted(waiting):
            r = waiting[pid]
            rdir = 'up' if r[2] > r[1] else 'down'
            if r[1] == pos and (rdir == d or not riding) and len(riding) < cap:
                riding[pid] = r
                picked[pid] = t
                del waiting[pid]
                stopped = True
        if stopped:
            t += x['stop_s']
        targets = [r[2] for r in riding.values()] + [r[1] for r in waiting.values()]
        ahead = [f for f in targets if (f > pos if d == 'up' else f < pos)]
        if not ahead:
            d = 'down' if d == 'up' else 'up'
            continue
        pos += 1 if d == 'up' else -1
        t += x['floor_s']
    return done
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: opposite-direction passenger waits', {'cap': 4, 'start': 2, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 2, 0], ['b', 2, 5]]}, {'b': [0, 11], 'a': [22, 31]}), ('sampled regression 3', {'cap': 2, 'start': 5, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 5, 1], ['p1', 3, 5]]}, {'p0': [0, 13], 'p1': [22, 31]}), ('sampled regression 1', {'cap': 1, 'start': 5, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 6, 8], ['p1', 3, 7], ['p2', 0, 7], ['p3', 3, 2], ['p4', 7, 1]]}, {'p0': [2, 11], 'p4': [18, 35], 'p2': [42, 61], 'p3': [74, 81], 'p1': [88, 101]}), ('boundary: full car at a floor where a rider alights', {'cap': 1, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 3], ['b', 3, 6]]}, {'a': [0, 11], 'b': [11, 22]}), ('boundary: capacity exactly reached', {'cap': 2, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 4], ['b', 0, 5], ['c', 0, 6]]}, {'a': [0, 13], 'b': [0, 20], 'c': [35, 52]}), ('sampled regression 4', {'cap': 4, 'start': 1, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 2, 8], ['p1', 8, 1], ['p2', 0, 8], ['p3', 5, 6]]}, {'p3': [13, 20], 'p0': [2, 29], 'p1': [34, 53], 'p2': [60, 81]}), ('sampled regression 7', {'cap': 4, 'start': 6, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 8, 9], ['p1', 7, 5], ['p2', 6, 0]]}, {'p0': [4, 11], 'p1': [20, 34], 'p2': [27, 49]}), ('control 10', {'cap': 2, 'start': 5, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 3, 0], ['p1', 5, 6], ['p2', 5, 7]]}, {'p1': [0, 10], 'p2': [0, 20], 'p0': [36, 50]})], [('regression: opposite-direction passenger waits', {'cap': 4, 'start': 2, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 2, 0], ['b', 2, 5]]}, {'b': [0, 11], 'a': [22, 31]}), ('sampled regression 12', {'cap': 4, 'start': 2, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 8, 3], ['p1', 8, 4], ['p2', 2, 8], ['p3', 5, 0], ['p4', 8, 2], ['p5', 7, 9]]}, {'p2': [0, 28], 'p5': [18, 38], 'p1': [48, 72], 'p0': [48, 82], 'p4': [48, 92], 'p3': [62, 104]}), ('sampled regression 8', {'cap': 1, 'start': 7, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 4, 9], ['p1', 9, 3], ['p2', 9, 7], ['p3', 2, 1], ['p4', 1, 3]]}, {'p1': [4, 24], 'p3': [34, 44], 'p4': [52, 64], 'p0': [74, 92], 'p2': [100, 112]}), ('boundary: capacity exactly reached', {'cap': 2, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 4], ['b', 0, 5], ['c', 0, 6]]}, {'a': [0, 13], 'b': [0, 20], 'c': [35, 52]}), ('boundary: two boardings share one stop', {'cap': 4, 'start': 1, 'floor_s': 2, 'stop_s': 8, 'requests': [['a', 1, 4], ['b', 1, 4]]}, {'a': [0, 14], 'b': [0, 14]}), ('control 15', {'cap': 2, 'start': 8, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 6, 3], ['p1', 4, 1], ['p2', 5, 0]]}, {'p0': [4, 26], 'p2': [14, 40], 'p1': [56, 70]}), ('sampled regression 18', {'cap': 4, 'start': 9, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 1, 0], ['p1', 7, 8], ['p2', 1, 8]]}, {'p0': [16, 26], 'p1': [56, 66], 'p2': [36, 66]}), ('sampled regression 21', {'cap': 2, 'start': 0, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 8, 7], ['p1', 5, 9], ['p2', 4, 5], ['p3', 0, 1], ['p4', 2, 5], ['p5', 0, 5]]}, {'p3': [0, 10], 'p4': [20, 34], 'p5': [0, 34], 'p1': [34, 50], 'p0': [60, 70], 'p2': [84, 94]})], [('regression: opposite-direction passenger waits', {'cap': 4, 'start': 2, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 2, 0], ['b', 2, 5]]}, {'b': [0, 11], 'a': [22, 31]}), ('sampled regression 21', {'cap': 2, 'start': 0, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 8, 7], ['p1', 5, 9], ['p2', 4, 5], ['p3', 0, 1], ['p4', 2, 5], ['p5', 0, 5]]}, {'p3': [0, 10], 'p4': [20, 34], 'p5': [0, 34], 'p1': [34, 50], 'p0': [60, 70], 'p2': [84, 94]}), ('sampled regression 19', {'cap': 2, 'start': 1, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 0, 5], ['p1', 6, 4], ['p2', 9, 2], ['p3', 4, 5]]}, {'p3': [6, 16], 'p1': [46, 58], 'p2': [32, 70], 'p0': [82, 100]}), ('boundary: alighting-only stop', {'cap': 4, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 2], ['b', 5, 6]]}, {'a': [0, 9], 'b': [20, 27]}), ('boundary: full car at a floor where a rider alights', {'cap': 1, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 3], ['b', 3, 6]]}, {'a': [0, 11], 'b': [11, 22]}), ('control 23', {'cap': 4, 'start': 8, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 9, 4], ['p1', 9, 1], ['p2', 0, 1], ['p3', 6, 2]]}, {'p0': [2, 22], 'p3': [13, 31], 'p1': [2, 38], 'p2': [45, 52]}), ('sampled regression 26', {'cap': 1, 'start': 3, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 0, 4], ['p1', 1, 6], ['p2', 1, 6], ['p3', 5, 1]]}, {'p3': [4, 20], 'p0': [30, 46], 'p1': [60, 78], 'p2': [96, 114]}), ('sampled regression 29', {'cap': 4, 'start': 5, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 8, 5], ['p1', 0, 2], ['p2', 7, 1]]}, {'p0': [6, 28], 'p2': [16, 44], 'p1': [54, 66]})], [('regression: opposite-direction passenger waits', {'cap': 4, 'start': 2, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 2, 0], ['b', 2, 5]]}, {'b': [0, 11], 'a': [22, 31]}), ('sampled regression 30', {'cap': 1, 'start': 1, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 5, 1], ['p1', 9, 3], ['p2', 2, 5]]}, {'p2': [2, 16], 'p1': [32, 52], 'p0': [64, 80]}), ('sampled regression 25', {'cap': 4, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 2, 5], ['p1', 0, 3], ['p2', 6, 8], ['p3', 2, 3], ['p4', 8, 0], ['p5', 9, 6]]}, {'p1': [0, 16], 'p3': [9, 16], 'p0': [9, 25], 'p2': [32, 41], 'p5': [48, 64], 'p4': [55, 81]}), ('boundary: capacity exactly reached', {'cap': 2, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 4], ['b', 0, 5], ['c', 0, 6]]}, {'a': [0, 13], 'b': [0, 20], 'c': [35, 52]}), ('boundary: two boardings share one stop', {'cap': 4, 'start': 1, 'floor_s': 2, 'stop_s': 8, 'requests': [['a', 1, 4], ['b', 1, 4]]}, {'a': [0, 14], 'b': [0, 14]}), ('sampled regression 34', {'cap': 2, 'start': 4, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 2, 0], ['p1', 2, 8], ['p2', 6, 1], ['p3', 3, 7], ['p4', 6, 8], ['p5', 2, 4]]}, {'p4': [4, 13], 'p2': [22, 42], 'p0': [35, 49], 'p5': [58, 67], 'p1': [58, 80], 'p3': [95, 108]}), ('control 37', {'cap': 2, 'start': 2, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 5, 9], ['p1', 6, 7]]}, {'p1': [13, 20], 'p0': [6, 29]}), ('sampled regression 40', {'cap': 2, 'start': 6, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 9, 5], ['p1', 8, 3], ['p2', 5, 4]]}, {'p0': [6, 30], 'p2': [30, 40], 'p1': [16, 50]})], [('regression: opposite-direction passenger waits', {'cap': 4, 'start': 2, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 2, 0], ['b', 2, 5]]}, {'b': [0, 11], 'a': [22, 31]}), ('sampled regression 40', {'cap': 2, 'start': 6, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 9, 5], ['p1', 8, 3], ['p2', 5, 4]]}, {'p0': [6, 30], 'p2': [30, 40], 'p1': [16, 50]}), ('sampled regression 30', {'cap': 1, 'start': 1, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 5, 1], ['p1', 9, 3], ['p2', 2, 5]]}, {'p2': [2, 16], 'p1': [32, 52], 'p0': [64, 80]}), ('boundary: two boardings share one stop', {'cap': 4, 'start': 1, 'floor_s': 2, 'stop_s': 8, 'requests': [['a', 1, 4], ['b', 1, 4]]}, {'a': [0, 14], 'b': [0, 14]}), ('boundary: alighting-only stop', {'cap': 4, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 2], ['b', 5, 6]]}, {'a': [0, 9], 'b': [20, 27]}), ('sampled regression 45', {'cap': 4, 'start': 8, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 0, 2], ['p1', 6, 2], ['p2', 4, 5], ['p3', 1, 7], ['p4', 7, 4]]}, {'p4': [2, 18], 'p1': [9, 27], 'p0': [36, 50], 'p2': [59, 66], 'p3': [43, 75]}), ('sampled regression 48', {'cap': 2, 'start': 8, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 2, 0], ['p1', 0, 2], ['p2', 8, 5], ['p3', 6, 4], ['p4', 0, 3]]}, {'p2': [0, 16], 'p3': [9, 23], 'p0': [32, 41], 'p1': [46, 55], 'p4': [46, 62]}), ('sampled regression 51', {'cap': 4, 'start': 4, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 8, 9], ['p1', 2, 6], ['p2', 8, 1], ['p3', 1, 6], ['p4', 3, 1]]}, {'p0': [8, 15], 'p2': [22, 46], 'p4': [37, 46], 'p1': [58, 71], 'p3': [51, 71]})]]
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:
Passengers board a car heading the wrong way and ride away from their destination.

All passengers [id, from, to] wait at time 0. The car starts at start heading up. At each floor it first lets riders alight, then boards waiting passengers (in id order) whose travel direction equals the car direction while load < cap; any alighting or boarding costs one stop_s. If no rider destination or waiting origin lies strictly ahead it reverses in place (and may board again); otherwise it moves one floor (floor_s). Return {id: [board time, alight time]} for delivered passengers.

split: open-access


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

N = 1
observations = []
def solve(x):
    cap = x['cap']
    pos = x['start']
    t = 0
    d = 'up'
    waiting = {r[0]: r for r in x['requests']}
    riding = {}
    picked = {}
    done = {}
    for _ in range(400):
        if not waiting and not riding:
            break
        stopped = False
        for pid in sorted(riding):
            if riding[pid][2] == pos:
                done[pid] = [picked[pid], t]
                del riding[pid]
                stopped = True
        for pid in sorted(waiting):
            r = waiting[pid]
            rdir = 'up' if r[2] > r[1] else 'down'
            if r[1] == pos and rdir == d and len(riding) <= cap:
                riding[pid] = r
                picked[pid] = t
                del waiting[pid]
                stopped = True
        if stopped:
            t += x['stop_s']
        targets = [r[2] for r in riding.values()] + [r[1] for r in waiting.values()]
        ahead = [f for f in targets if (f > pos if d == 'up' else f < pos)]
        if not ahead:
            d = 'down' if d == 'up' else 'up'
            continue
        pos += 1 if d == 'up' else -1
        t += x['floor_s']
    return done
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: capacity exactly reached', {'cap': 2, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 4], ['b', 0, 5], ['c', 0, 6]]}, {'a': [0, 13], 'b': [0, 20], 'c': [35, 52]}), ('boundary: full car at a floor where a rider alights', {'cap': 1, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 3], ['b', 3, 6]]}, {'a': [0, 11], 'b': [11, 22]}), ('sampled regression 15', {'cap': 2, 'start': 8, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 6, 3], ['p1', 4, 1], ['p2', 5, 0]]}, {'p0': [4, 26], 'p2': [14, 40], 'p1': [56, 70]}), ('boundary: opposite-direction passenger waits', {'cap': 4, 'start': 2, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 2, 0], ['b', 2, 5]]}, {'b': [0, 11], 'a': [22, 31]}), ('boundary: two boardings share one stop', {'cap': 4, 'start': 1, 'floor_s': 2, 'stop_s': 8, 'requests': [['a', 1, 4], ['b', 1, 4]]}, {'a': [0, 14], 'b': [0, 14]}), ('sampled regression 1', {'cap': 1, 'start': 5, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 6, 8], ['p1', 3, 7], ['p2', 0, 7], ['p3', 3, 2], ['p4', 7, 1]]}, {'p0': [2, 11], 'p4': [18, 35], 'p2': [42, 61], 'p3': [74, 81], 'p1': [88, 101]}), ('control 4', {'cap': 4, 'start': 1, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 2, 8], ['p1', 8, 1], ['p2', 0, 8], ['p3', 5, 6]]}, {'p3': [13, 20], 'p0': [2, 29], 'p1': [34, 53], 'p2': [60, 81]}), ('control 7', {'cap': 4, 'start': 6, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 8, 9], ['p1', 7, 5], ['p2', 6, 0]]}, {'p0': [4, 11], 'p1': [20, 34], 'p2': [27, 49]})], [('regression: capacity exactly reached', {'cap': 2, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 4], ['b', 0, 5], ['c', 0, 6]]}, {'a': [0, 13], 'b': [0, 20], 'c': [35, 52]}), ('sampled regression 38', {'cap': 2, 'start': 5, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 4, 2], ['p1', 4, 2], ['p2', 2, 4], ['p3', 9, 0], ['p4', 8, 3]]}, {'p4': [18, 36], 'p3': [8, 50], 'p2': [62, 74], 'p0': [82, 94], 'p1': [82, 94]}), ('sampled regression 8', {'cap': 1, 'start': 7, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 4, 9], ['p1', 9, 3], ['p2', 9, 7], ['p3', 2, 1], ['p4', 1, 3]]}, {'p1': [4, 24], 'p3': [34, 44], 'p4': [52, 64], 'p0': [74, 92], 'p2': [100, 112]}), ('boundary: two boardings share one stop', {'cap': 4, 'start': 1, 'floor_s': 2, 'stop_s': 8, 'requests': [['a', 1, 4], ['b', 1, 4]]}, {'a': [0, 14], 'b': [0, 14]}), ('boundary: alighting-only stop', {'cap': 4, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 2], ['b', 5, 6]]}, {'a': [0, 9], 'b': [20, 27]}), ('control 12', {'cap': 4, 'start': 2, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 8, 3], ['p1', 8, 4], ['p2', 2, 8], ['p3', 5, 0], ['p4', 8, 2], ['p5', 7, 9]]}, {'p2': [0, 28], 'p5': [18, 38], 'p1': [48, 72], 'p0': [48, 82], 'p4': [48, 92], 'p3': [62, 104]}), ('sampled regression 15', {'cap': 2, 'start': 8, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 6, 3], ['p1', 4, 1], ['p2', 5, 0]]}, {'p0': [4, 26], 'p2': [14, 40], 'p1': [56, 70]}), ('control 18', {'cap': 4, 'start': 9, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 1, 0], ['p1', 7, 8], ['p2', 1, 8]]}, {'p0': [16, 26], 'p1': [56, 66], 'p2': [36, 66]})], [('regression: capacity exactly reached', {'cap': 2, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 4], ['b', 0, 5], ['c', 0, 6]]}, {'a': [0, 13], 'b': [0, 20], 'c': [35, 52]}), ('boundary: full car at a floor where a rider alights', {'cap': 1, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 3], ['b', 3, 6]]}, {'a': [0, 11], 'b': [11, 22]}), ('sampled regression 73', {'cap': 2, 'start': 9, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 8, 1], ['p1', 0, 9], ['p2', 2, 5], ['p3', 2, 3], ['p4', 2, 9], ['p5', 3, 1]]}, {'p0': [2, 32], 'p5': [20, 32], 'p2': [54, 68], 'p1': [42, 84], 'p3': [106, 116], 'p4': [106, 136]}), ('control 19', {'cap': 2, 'start': 1, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 0, 5], ['p1', 6, 4], ['p2', 9, 2], ['p3', 4, 5]]}, {'p3': [6, 16], 'p1': [46, 58], 'p2': [32, 70], 'p0': [82, 100]}), ('boundary: alighting-only stop', {'cap': 4, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 2], ['b', 5, 6]]}, {'a': [0, 9], 'b': [20, 27]}), ('control 23', {'cap': 4, 'start': 8, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 9, 4], ['p1', 9, 1], ['p2', 0, 1], ['p3', 6, 2]]}, {'p0': [2, 22], 'p3': [13, 31], 'p1': [2, 38], 'p2': [45, 52]}), ('sampled regression 26', {'cap': 1, 'start': 3, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 0, 4], ['p1', 1, 6], ['p2', 1, 6], ['p3', 5, 1]]}, {'p3': [4, 20], 'p0': [30, 46], 'p1': [60, 78], 'p2': [96, 114]}), ('control 29', {'cap': 4, 'start': 5, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 8, 5], ['p1', 0, 2], ['p2', 7, 1]]}, {'p0': [6, 28], 'p2': [16, 44], 'p1': [54, 66]})], [('regression: capacity exactly reached', {'cap': 2, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 4], ['b', 0, 5], ['c', 0, 6]]}, {'a': [0, 13], 'b': [0, 20], 'c': [35, 52]}), ('sampled regression 20', {'cap': 2, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 9, 1], ['p1', 6, 7], ['p2', 3, 7], ['p3', 6, 3], ['p4', 8, 5]]}, {'p1': [17, 24], 'p2': [6, 24], 'p4': [40, 51], 'p0': [33, 64], 'p3': [79, 90]}), ('control 27', {'cap': 2, 'start': 2, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 1, 9], ['p1', 2, 7], ['p2', 1, 5]]}, {'p1': [0, 18], 'p2': [38, 54], 'p0': [38, 70]}), ('boundary: opposite-direction passenger waits', {'cap': 4, 'start': 2, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 2, 0], ['b', 2, 5]]}, {'b': [0, 11], 'a': [22, 31]}), ('boundary: two boardings share one stop', {'cap': 4, 'start': 1, 'floor_s': 2, 'stop_s': 8, 'requests': [['a', 1, 4], ['b', 1, 4]]}, {'a': [0, 14], 'b': [0, 14]}), ('sampled regression 34', {'cap': 2, 'start': 4, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 2, 0], ['p1', 2, 8], ['p2', 6, 1], ['p3', 3, 7], ['p4', 6, 8], ['p5', 2, 4]]}, {'p4': [4, 13], 'p2': [22, 42], 'p0': [35, 49], 'p5': [58, 67], 'p1': [58, 80], 'p3': [95, 108]}), ('control 37', {'cap': 2, 'start': 2, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 5, 9], ['p1', 6, 7]]}, {'p1': [13, 20], 'p0': [6, 29]}), ('control 40', {'cap': 2, 'start': 6, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 9, 5], ['p1', 8, 3], ['p2', 5, 4]]}, {'p0': [6, 30], 'p2': [30, 40], 'p1': [16, 50]})], [('regression: capacity exactly reached', {'cap': 2, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 4], ['b', 0, 5], ['c', 0, 6]]}, {'a': [0, 13], 'b': [0, 20], 'c': [35, 52]}), ('boundary: full car at a floor where a rider alights', {'cap': 1, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 3], ['b', 3, 6]]}, {'a': [0, 11], 'b': [11, 22]}), ('sampled regression 53', {'cap': 2, 'start': 4, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 2, 4], ['p1', 1, 4], ['p2', 0, 4]]}, {'p1': [18, 32], 'p2': [8, 32], 'p0': [44, 56]}), ('sampled regression 34', {'cap': 2, 'start': 4, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 2, 0], ['p1', 2, 8], ['p2', 6, 1], ['p3', 3, 7], ['p4', 6, 8], ['p5', 2, 4]]}, {'p4': [4, 13], 'p2': [22, 42], 'p0': [35, 49], 'p5': [58, 67], 'p1': [58, 80], 'p3': [95, 108]}), ('boundary: two boardings share one stop', {'cap': 4, 'start': 1, 'floor_s': 2, 'stop_s': 8, 'requests': [['a', 1, 4], ['b', 1, 4]]}, {'a': [0, 14], 'b': [0, 14]}), ('control 45', {'cap': 4, 'start': 8, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 0, 2], ['p1', 6, 2], ['p2', 4, 5], ['p3', 1, 7], ['p4', 7, 4]]}, {'p4': [2, 18], 'p1': [9, 27], 'p0': [36, 50], 'p2': [59, 66], 'p3': [43, 75]}), ('control 48', {'cap': 2, 'start': 8, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 2, 0], ['p1', 0, 2], ['p2', 8, 5], ['p3', 6, 4], ['p4', 0, 3]]}, {'p2': [0, 16], 'p3': [9, 23], 'p0': [32, 41], 'p1': [46, 55], 'p4': [46, 62]}), ('control 51', {'cap': 4, 'start': 4, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 8, 9], ['p1', 2, 6], ['p2', 8, 1], ['p3', 1, 6], ['p4', 3, 1]]}, {'p0': [8, 15], 'p2': [22, 46], 'p4': [37, 46], 'p1': [58, 71], 'p3': [51, 71]})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    cap = x['cap']
    pos = x['start']
    t = 0
    d = 'up'
    waiting = {r[0]: r for r in x['requests']}
    riding = {}
    picked = {}
    done = {}
    for _ in range(400):
        if not waiting and not riding:
            break
        stopped = False
        for pid in sorted(riding):
            if riding[pid][2] == pos:
                done[pid] = [picked[pid], t]
                del riding[pid]
                stopped = True
        for pid in sorted(waiting):
            r = waiting[pid]
            rdir = 'up' if r[2] > r[1] else 'down'
            if r[1] == pos and rdir == d and len(riding) + 1 < cap:
                riding[pid] = r
                picked[pid] = t
                del waiting[pid]
                stopped = True
        if stopped:
            t += x['stop_s']
        targets = [r[2] for r in riding.values()] + [r[1] for r in waiting.values()]
        ahead = [f for f in targets if (f > pos if d == 'up' else f < pos)]
        if not ahead:
            d = 'down' if d == 'up' else 'up'
            continue
        pos += 1 if d == 'up' else -1
        t += x['floor_s']
    return done
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: capacity exactly reached', {'cap': 2, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 4], ['b', 0, 5], ['c', 0, 6]]}, {'a': [0, 13], 'b': [0, 20], 'c': [35, 52]}), ('boundary: full car at a floor where a rider alights', {'cap': 1, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 3], ['b', 3, 6]]}, {'a': [0, 11], 'b': [11, 22]}), ('sampled regression 15', {'cap': 2, 'start': 8, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 6, 3], ['p1', 4, 1], ['p2', 5, 0]]}, {'p0': [4, 26], 'p2': [14, 40], 'p1': [56, 70]}), ('boundary: opposite-direction passenger waits', {'cap': 4, 'start': 2, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 2, 0], ['b', 2, 5]]}, {'b': [0, 11], 'a': [22, 31]}), ('boundary: two boardings share one stop', {'cap': 4, 'start': 1, 'floor_s': 2, 'stop_s': 8, 'requests': [['a', 1, 4], ['b', 1, 4]]}, {'a': [0, 14], 'b': [0, 14]}), ('sampled regression 1', {'cap': 1, 'start': 5, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 6, 8], ['p1', 3, 7], ['p2', 0, 7], ['p3', 3, 2], ['p4', 7, 1]]}, {'p0': [2, 11], 'p4': [18, 35], 'p2': [42, 61], 'p3': [74, 81], 'p1': [88, 101]}), ('control 4', {'cap': 4, 'start': 1, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 2, 8], ['p1', 8, 1], ['p2', 0, 8], ['p3', 5, 6]]}, {'p3': [13, 20], 'p0': [2, 29], 'p1': [34, 53], 'p2': [60, 81]}), ('control 7', {'cap': 4, 'start': 6, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 8, 9], ['p1', 7, 5], ['p2', 6, 0]]}, {'p0': [4, 11], 'p1': [20, 34], 'p2': [27, 49]})], [('regression: capacity exactly reached', {'cap': 2, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 4], ['b', 0, 5], ['c', 0, 6]]}, {'a': [0, 13], 'b': [0, 20], 'c': [35, 52]}), ('sampled regression 38', {'cap': 2, 'start': 5, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 4, 2], ['p1', 4, 2], ['p2', 2, 4], ['p3', 9, 0], ['p4', 8, 3]]}, {'p4': [18, 36], 'p3': [8, 50], 'p2': [62, 74], 'p0': [82, 94], 'p1': [82, 94]}), ('sampled regression 8', {'cap': 1, 'start': 7, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 4, 9], ['p1', 9, 3], ['p2', 9, 7], ['p3', 2, 1], ['p4', 1, 3]]}, {'p1': [4, 24], 'p3': [34, 44], 'p4': [52, 64], 'p0': [74, 92], 'p2': [100, 112]}), ('boundary: two boardings share one stop', {'cap': 4, 'start': 1, 'floor_s': 2, 'stop_s': 8, 'requests': [['a', 1, 4], ['b', 1, 4]]}, {'a': [0, 14], 'b': [0, 14]}), ('boundary: alighting-only stop', {'cap': 4, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 2], ['b', 5, 6]]}, {'a': [0, 9], 'b': [20, 27]}), ('control 12', {'cap': 4, 'start': 2, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 8, 3], ['p1', 8, 4], ['p2', 2, 8], ['p3', 5, 0], ['p4', 8, 2], ['p5', 7, 9]]}, {'p2': [0, 28], 'p5': [18, 38], 'p1': [48, 72], 'p0': [48, 82], 'p4': [48, 92], 'p3': [62, 104]}), ('sampled regression 15', {'cap': 2, 'start': 8, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 6, 3], ['p1', 4, 1], ['p2', 5, 0]]}, {'p0': [4, 26], 'p2': [14, 40], 'p1': [56, 70]}), ('control 18', {'cap': 4, 'start': 9, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 1, 0], ['p1', 7, 8], ['p2', 1, 8]]}, {'p0': [16, 26], 'p1': [56, 66], 'p2': [36, 66]})], [('regression: capacity exactly reached', {'cap': 2, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 4], ['b', 0, 5], ['c', 0, 6]]}, {'a': [0, 13], 'b': [0, 20], 'c': [35, 52]}), ('boundary: full car at a floor where a rider alights', {'cap': 1, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 3], ['b', 3, 6]]}, {'a': [0, 11], 'b': [11, 22]}), ('sampled regression 73', {'cap': 2, 'start': 9, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 8, 1], ['p1', 0, 9], ['p2', 2, 5], ['p3', 2, 3], ['p4', 2, 9], ['p5', 3, 1]]}, {'p0': [2, 32], 'p5': [20, 32], 'p2': [54, 68], 'p1': [42, 84], 'p3': [106, 116], 'p4': [106, 136]}), ('control 19', {'cap': 2, 'start': 1, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 0, 5], ['p1', 6, 4], ['p2', 9, 2], ['p3', 4, 5]]}, {'p3': [6, 16], 'p1': [46, 58], 'p2': [32, 70], 'p0': [82, 100]}), ('boundary: alighting-only stop', {'cap': 4, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 2], ['b', 5, 6]]}, {'a': [0, 9], 'b': [20, 27]}), ('control 23', {'cap': 4, 'start': 8, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 9, 4], ['p1', 9, 1], ['p2', 0, 1], ['p3', 6, 2]]}, {'p0': [2, 22], 'p3': [13, 31], 'p1': [2, 38], 'p2': [45, 52]}), ('sampled regression 26', {'cap': 1, 'start': 3, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 0, 4], ['p1', 1, 6], ['p2', 1, 6], ['p3', 5, 1]]}, {'p3': [4, 20], 'p0': [30, 46], 'p1': [60, 78], 'p2': [96, 114]}), ('control 29', {'cap': 4, 'start': 5, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 8, 5], ['p1', 0, 2], ['p2', 7, 1]]}, {'p0': [6, 28], 'p2': [16, 44], 'p1': [54, 66]})], [('regression: capacity exactly reached', {'cap': 2, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 4], ['b', 0, 5], ['c', 0, 6]]}, {'a': [0, 13], 'b': [0, 20], 'c': [35, 52]}), ('sampled regression 20', {'cap': 2, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 9, 1], ['p1', 6, 7], ['p2', 3, 7], ['p3', 6, 3], ['p4', 8, 5]]}, {'p1': [17, 24], 'p2': [6, 24], 'p4': [40, 51], 'p0': [33, 64], 'p3': [79, 90]}), ('control 27', {'cap': 2, 'start': 2, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 1, 9], ['p1', 2, 7], ['p2', 1, 5]]}, {'p1': [0, 18], 'p2': [38, 54], 'p0': [38, 70]}), ('boundary: opposite-direction passenger waits', {'cap': 4, 'start': 2, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 2, 0], ['b', 2, 5]]}, {'b': [0, 11], 'a': [22, 31]}), ('boundary: two boardings share one stop', {'cap': 4, 'start': 1, 'floor_s': 2, 'stop_s': 8, 'requests': [['a', 1, 4], ['b', 1, 4]]}, {'a': [0, 14], 'b': [0, 14]}), ('sampled regression 34', {'cap': 2, 'start': 4, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 2, 0], ['p1', 2, 8], ['p2', 6, 1], ['p3', 3, 7], ['p4', 6, 8], ['p5', 2, 4]]}, {'p4': [4, 13], 'p2': [22, 42], 'p0': [35, 49], 'p5': [58, 67], 'p1': [58, 80], 'p3': [95, 108]}), ('control 37', {'cap': 2, 'start': 2, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 5, 9], ['p1', 6, 7]]}, {'p1': [13, 20], 'p0': [6, 29]}), ('control 40', {'cap': 2, 'start': 6, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 9, 5], ['p1', 8, 3], ['p2', 5, 4]]}, {'p0': [6, 30], 'p2': [30, 40], 'p1': [16, 50]})], [('regression: capacity exactly reached', {'cap': 2, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 4], ['b', 0, 5], ['c', 0, 6]]}, {'a': [0, 13], 'b': [0, 20], 'c': [35, 52]}), ('boundary: full car at a floor where a rider alights', {'cap': 1, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 3], ['b', 3, 6]]}, {'a': [0, 11], 'b': [11, 22]}), ('sampled regression 53', {'cap': 2, 'start': 4, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 2, 4], ['p1', 1, 4], ['p2', 0, 4]]}, {'p1': [18, 32], 'p2': [8, 32], 'p0': [44, 56]}), ('sampled regression 34', {'cap': 2, 'start': 4, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 2, 0], ['p1', 2, 8], ['p2', 6, 1], ['p3', 3, 7], ['p4', 6, 8], ['p5', 2, 4]]}, {'p4': [4, 13], 'p2': [22, 42], 'p0': [35, 49], 'p5': [58, 67], 'p1': [58, 80], 'p3': [95, 108]}), ('boundary: two boardings share one stop', {'cap': 4, 'start': 1, 'floor_s': 2, 'stop_s': 8, 'requests': [['a', 1, 4], ['b', 1, 4]]}, {'a': [0, 14], 'b': [0, 14]}), ('control 45', {'cap': 4, 'start': 8, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 0, 2], ['p1', 6, 2], ['p2', 4, 5], ['p3', 1, 7], ['p4', 7, 4]]}, {'p4': [2, 18], 'p1': [9, 27], 'p0': [36, 50], 'p2': [59, 66], 'p3': [43, 75]}), ('control 48', {'cap': 2, 'start': 8, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 2, 0], ['p1', 0, 2], ['p2', 8, 5], ['p3', 6, 4], ['p4', 0, 3]]}, {'p2': [0, 16], 'p3': [9, 23], 'p0': [32, 41], 'p1': [46, 55], 'p4': [46, 62]}), ('control 51', {'cap': 4, 'start': 4, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 8, 9], ['p1', 2, 6], ['p2', 8, 1], ['p3', 1, 6], ['p4', 3, 1]]}, {'p0': [8, 15], 'p2': [22, 46], 'p4': [37, 46], 'p1': [58, 71], 'p3': [51, 71]})]]
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:
The car takes one passenger more than its capacity, or one fewer.

All passengers [id, from, to] wait at time 0. The car starts at start heading up. At each floor it first lets riders alight, then boards waiting passengers (in id order) whose travel direction equals the car direction while load < cap; any alighting or boarding costs one stop_s. If no rider destination or waiting origin lies strictly ahead it reverses in place (and may board again); otherwise it moves one floor (floor_s). Return {id: [board time, alight time]} for delivered passengers.

split: open-access


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

N = 1
observations = []
def solve(x):
    cap = x['cap']
    pos = x['start']
    t = 0
    d = 'up'
    waiting = {r[0]: r for r in x['requests']}
    riding = {}
    picked = {}
    done = {}
    for _ in range(400):
        if not waiting and not riding:
            break
        stopped = False
        for pid in sorted(riding):
            if riding[pid][2] == pos:
                done[pid] = [picked[pid], t]
                del riding[pid]
                stopped = True
        for pid in sorted(waiting):
            r = waiting[pid]
            rdir = 'up' if r[2] > r[1] else 'down'
            if r[1] == pos and rdir == d and len(riding) < cap:
                riding[pid] = r
                picked[pid] = t
                del waiting[pid]
                t += x['stop_s']
        if stopped:
            t += x['stop_s']
        targets = [r[2] for r in riding.values()] + [r[1] for r in waiting.values()]
        ahead = [f for f in targets if (f > pos if d == 'up' else f < pos)]
        if not ahead:
            d = 'down' if d == 'up' else 'up'
            continue
        pos += 1 if d == 'up' else -1
        t += x['floor_s']
    return done
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: full car at a floor where a rider alights', {'cap': 1, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 3], ['b', 3, 6]]}, {'a': [0, 11], 'b': [11, 22]}), ('boundary: opposite-direction passenger waits', {'cap': 4, 'start': 2, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 2, 0], ['b', 2, 5]]}, {'b': [0, 11], 'a': [22, 31]}), ('sampled regression 2', {'cap': 2, 'start': 8, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 6, 9], ['p1', 4, 2], ['p2', 9, 2], ['p3', 9, 8]]}, {'p3': [2, 9], 'p1': [22, 31], 'p2': [2, 31], 'p0': [44, 55]}), ('regression: capacity exactly reached', {'cap': 2, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 4], ['b', 0, 5], ['c', 0, 6]]}, {'a': [0, 13], 'b': [0, 20], 'c': [35, 52]}), ('regression: two boardings share one stop', {'cap': 4, 'start': 1, 'floor_s': 2, 'stop_s': 8, 'requests': [['a', 1, 4], ['b', 1, 4]]}, {'a': [0, 14], 'b': [0, 14]}), ('control 1', {'cap': 1, 'start': 5, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 6, 8], ['p1', 3, 7], ['p2', 0, 7], ['p3', 3, 2], ['p4', 7, 1]]}, {'p0': [2, 11], 'p4': [18, 35], 'p2': [42, 61], 'p3': [74, 81], 'p1': [88, 101]}), ('control 4', {'cap': 4, 'start': 1, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 2, 8], ['p1', 8, 1], ['p2', 0, 8], ['p3', 5, 6]]}, {'p3': [13, 20], 'p0': [2, 29], 'p1': [34, 53], 'p2': [60, 81]}), ('control 7', {'cap': 4, 'start': 6, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 8, 9], ['p1', 7, 5], ['p2', 6, 0]]}, {'p0': [4, 11], 'p1': [20, 34], 'p2': [27, 49]})], [('regression: capacity exactly reached', {'cap': 2, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 4], ['b', 0, 5], ['c', 0, 6]]}, {'a': [0, 13], 'b': [0, 20], 'c': [35, 52]}), ('sampled regression 21', {'cap': 2, 'start': 0, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 8, 7], ['p1', 5, 9], ['p2', 4, 5], ['p3', 0, 1], ['p4', 2, 5], ['p5', 0, 5]]}, {'p3': [0, 10], 'p4': [20, 34], 'p5': [0, 34], 'p1': [34, 50], 'p0': [60, 70], 'p2': [84, 94]}), ('control 4', {'cap': 4, 'start': 1, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 2, 8], ['p1', 8, 1], ['p2', 0, 8], ['p3', 5, 6]]}, {'p3': [13, 20], 'p0': [2, 29], 'p1': [34, 53], 'p2': [60, 81]}), ('regression: two boardings share one stop', {'cap': 4, 'start': 1, 'floor_s': 2, 'stop_s': 8, 'requests': [['a', 1, 4], ['b', 1, 4]]}, {'a': [0, 14], 'b': [0, 14]}), ('boundary: alighting-only stop', {'cap': 4, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 2], ['b', 5, 6]]}, {'a': [0, 9], 'b': [20, 27]}), ('sampled regression 12', {'cap': 4, 'start': 2, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 8, 3], ['p1', 8, 4], ['p2', 2, 8], ['p3', 5, 0], ['p4', 8, 2], ['p5', 7, 9]]}, {'p2': [0, 28], 'p5': [18, 38], 'p1': [48, 72], 'p0': [48, 82], 'p4': [48, 92], 'p3': [62, 104]}), ('control 15', {'cap': 2, 'start': 8, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 6, 3], ['p1', 4, 1], ['p2', 5, 0]]}, {'p0': [4, 26], 'p2': [14, 40], 'p1': [56, 70]}), ('control 18', {'cap': 4, 'start': 9, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 1, 0], ['p1', 7, 8], ['p2', 1, 8]]}, {'p0': [16, 26], 'p1': [56, 66], 'p2': [36, 66]})], [('regression: two boardings share one stop', {'cap': 4, 'start': 1, 'floor_s': 2, 'stop_s': 8, 'requests': [['a', 1, 4], ['b', 1, 4]]}, {'a': [0, 14], 'b': [0, 14]}), ('boundary: alighting-only stop', {'cap': 4, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 2], ['b', 5, 6]]}, {'a': [0, 9], 'b': [20, 27]}), ('sampled regression 40', {'cap': 2, 'start': 6, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 9, 5], ['p1', 8, 3], ['p2', 5, 4]]}, {'p0': [6, 30], 'p2': [30, 40], 'p1': [16, 50]}), ('control 9', {'cap': 4, 'start': 1, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 6, 2], ['p1', 4, 5], ['p2', 3, 6], ['p3', 0, 9]]}, {'p1': [11, 18], 'p2': [4, 25], 'p0': [30, 43], 'p3': [52, 75]}), ('regression: full car at a floor where a rider alights', {'cap': 1, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 3], ['b', 3, 6]]}, {'a': [0, 11], 'b': [11, 22]}), ('sampled regression 23', {'cap': 4, 'start': 8, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 9, 4], ['p1', 9, 1], ['p2', 0, 1], ['p3', 6, 2]]}, {'p0': [2, 22], 'p3': [13, 31], 'p1': [2, 38], 'p2': [45, 52]}), ('control 26', {'cap': 1, 'start': 3, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 0, 4], ['p1', 1, 6], ['p2', 1, 6], ['p3', 5, 1]]}, {'p3': [4, 20], 'p0': [30, 46], 'p1': [60, 78], 'p2': [96, 114]}), ('control 29', {'cap': 4, 'start': 5, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 8, 5], ['p1', 0, 2], ['p2', 7, 1]]}, {'p0': [6, 28], 'p2': [16, 44], 'p1': [54, 66]})], [('regression: full car at a floor where a rider alights', {'cap': 1, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 3], ['b', 3, 6]]}, {'a': [0, 11], 'b': [11, 22]}), ('boundary: opposite-direction passenger waits', {'cap': 4, 'start': 2, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 2, 0], ['b', 2, 5]]}, {'b': [0, 11], 'a': [22, 31]}), ('sampled regression 61', {'cap': 2, 'start': 1, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 4, 9], ['p1', 8, 1], ['p2', 3, 8], ['p3', 1, 4]]}, {'p3': [0, 22], 'p2': [12, 38], 'p0': [22, 48], 'p1': [58, 80]}), ('control 14', {'cap': 4, 'start': 1, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 2, 1], ['p1', 0, 5]]}, {'p0': [2, 9], 'p1': [16, 31]}), ('regression: capacity exactly reached', {'cap': 2, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 4], ['b', 0, 5], ['c', 0, 6]]}, {'a': [0, 13], 'b': [0, 20], 'c': [35, 52]}), ('sampled regression 34', {'cap': 2, 'start': 4, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 2, 0], ['p1', 2, 8], ['p2', 6, 1], ['p3', 3, 7], ['p4', 6, 8], ['p5', 2, 4]]}, {'p4': [4, 13], 'p2': [22, 42], 'p0': [35, 49], 'p5': [58, 67], 'p1': [58, 80], 'p3': [95, 108]}), ('control 37', {'cap': 2, 'start': 2, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 5, 9], ['p1', 6, 7]]}, {'p1': [13, 20], 'p0': [6, 29]}), ('sampled regression 40', {'cap': 2, 'start': 6, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 9, 5], ['p1', 8, 3], ['p2', 5, 4]]}, {'p0': [6, 30], 'p2': [30, 40], 'p1': [16, 50]})], [('regression: capacity exactly reached', {'cap': 2, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 4], ['b', 0, 5], ['c', 0, 6]]}, {'a': [0, 13], 'b': [0, 20], 'c': [35, 52]}), ('regression: full car at a floor where a rider alights', {'cap': 1, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 3], ['b', 3, 6]]}, {'a': [0, 11], 'b': [11, 22]}), ('control 19', {'cap': 2, 'start': 1, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 0, 5], ['p1', 6, 4], ['p2', 9, 2], ['p3', 4, 5]]}, {'p3': [6, 16], 'p1': [46, 58], 'p2': [32, 70], 'p0': [82, 100]}), ('regression: two boardings share one stop', {'cap': 4, 'start': 1, 'floor_s': 2, 'stop_s': 8, 'requests': [['a', 1, 4], ['b', 1, 4]]}, {'a': [0, 14], 'b': [0, 14]}), ('boundary: alighting-only stop', {'cap': 4, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 2], ['b', 5, 6]]}, {'a': [0, 9], 'b': [20, 27]}), ('control 45', {'cap': 4, 'start': 8, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 0, 2], ['p1', 6, 2], ['p2', 4, 5], ['p3', 1, 7], ['p4', 7, 4]]}, {'p4': [2, 18], 'p1': [9, 27], 'p0': [36, 50], 'p2': [59, 66], 'p3': [43, 75]}), ('sampled regression 48', {'cap': 2, 'start': 8, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 2, 0], ['p1', 0, 2], ['p2', 8, 5], ['p3', 6, 4], ['p4', 0, 3]]}, {'p2': [0, 16], 'p3': [9, 23], 'p0': [32, 41], 'p1': [46, 55], 'p4': [46, 62]}), ('control 51', {'cap': 4, 'start': 4, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 8, 9], ['p1', 2, 6], ['p2', 8, 1], ['p3', 1, 6], ['p4', 3, 1]]}, {'p0': [8, 15], 'p2': [22, 46], 'p4': [37, 46], 'p1': [58, 71], 'p3': [51, 71]})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    cap = x['cap']
    pos = x['start']
    t = 0
    d = 'up'
    waiting = {r[0]: r for r in x['requests']}
    riding = {}
    picked = {}
    done = {}
    for _ in range(400):
        if not waiting and not riding:
            break
        stopped = False
        for pid in sorted(riding):
            if riding[pid][2] == pos:
                done[pid] = [picked[pid], t]
                del riding[pid]
        for pid in sorted(waiting):
            r = waiting[pid]
            rdir = 'up' if r[2] > r[1] else 'down'
            if r[1] == pos and rdir == d and len(riding) < cap:
                riding[pid] = r
                picked[pid] = t
                del waiting[pid]
                stopped = True
        if stopped:
            t += x['stop_s']
        targets = [r[2] for r in riding.values()] + [r[1] for r in waiting.values()]
        ahead = [f for f in targets if (f > pos if d == 'up' else f < pos)]
        if not ahead:
            d = 'down' if d == 'up' else 'up'
            continue
        pos += 1 if d == 'up' else -1
        t += x['floor_s']
    return done
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: full car at a floor where a rider alights', {'cap': 1, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 3], ['b', 3, 6]]}, {'a': [0, 11], 'b': [11, 22]}), ('boundary: opposite-direction passenger waits', {'cap': 4, 'start': 2, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 2, 0], ['b', 2, 5]]}, {'b': [0, 11], 'a': [22, 31]}), ('sampled regression 2', {'cap': 2, 'start': 8, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 6, 9], ['p1', 4, 2], ['p2', 9, 2], ['p3', 9, 8]]}, {'p3': [2, 9], 'p1': [22, 31], 'p2': [2, 31], 'p0': [44, 55]}), ('regression: capacity exactly reached', {'cap': 2, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 4], ['b', 0, 5], ['c', 0, 6]]}, {'a': [0, 13], 'b': [0, 20], 'c': [35, 52]}), ('regression: two boardings share one stop', {'cap': 4, 'start': 1, 'floor_s': 2, 'stop_s': 8, 'requests': [['a', 1, 4], ['b', 1, 4]]}, {'a': [0, 14], 'b': [0, 14]}), ('control 1', {'cap': 1, 'start': 5, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 6, 8], ['p1', 3, 7], ['p2', 0, 7], ['p3', 3, 2], ['p4', 7, 1]]}, {'p0': [2, 11], 'p4': [18, 35], 'p2': [42, 61], 'p3': [74, 81], 'p1': [88, 101]}), ('control 4', {'cap': 4, 'start': 1, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 2, 8], ['p1', 8, 1], ['p2', 0, 8], ['p3', 5, 6]]}, {'p3': [13, 20], 'p0': [2, 29], 'p1': [34, 53], 'p2': [60, 81]}), ('control 7', {'cap': 4, 'start': 6, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 8, 9], ['p1', 7, 5], ['p2', 6, 0]]}, {'p0': [4, 11], 'p1': [20, 34], 'p2': [27, 49]})], [('regression: capacity exactly reached', {'cap': 2, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 4], ['b', 0, 5], ['c', 0, 6]]}, {'a': [0, 13], 'b': [0, 20], 'c': [35, 52]}), ('sampled regression 21', {'cap': 2, 'start': 0, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 8, 7], ['p1', 5, 9], ['p2', 4, 5], ['p3', 0, 1], ['p4', 2, 5], ['p5', 0, 5]]}, {'p3': [0, 10], 'p4': [20, 34], 'p5': [0, 34], 'p1': [34, 50], 'p0': [60, 70], 'p2': [84, 94]}), ('control 4', {'cap': 4, 'start': 1, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 2, 8], ['p1', 8, 1], ['p2', 0, 8], ['p3', 5, 6]]}, {'p3': [13, 20], 'p0': [2, 29], 'p1': [34, 53], 'p2': [60, 81]}), ('regression: two boardings share one stop', {'cap': 4, 'start': 1, 'floor_s': 2, 'stop_s': 8, 'requests': [['a', 1, 4], ['b', 1, 4]]}, {'a': [0, 14], 'b': [0, 14]}), ('boundary: alighting-only stop', {'cap': 4, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 2], ['b', 5, 6]]}, {'a': [0, 9], 'b': [20, 27]}), ('sampled regression 12', {'cap': 4, 'start': 2, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 8, 3], ['p1', 8, 4], ['p2', 2, 8], ['p3', 5, 0], ['p4', 8, 2], ['p5', 7, 9]]}, {'p2': [0, 28], 'p5': [18, 38], 'p1': [48, 72], 'p0': [48, 82], 'p4': [48, 92], 'p3': [62, 104]}), ('control 15', {'cap': 2, 'start': 8, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 6, 3], ['p1', 4, 1], ['p2', 5, 0]]}, {'p0': [4, 26], 'p2': [14, 40], 'p1': [56, 70]}), ('control 18', {'cap': 4, 'start': 9, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 1, 0], ['p1', 7, 8], ['p2', 1, 8]]}, {'p0': [16, 26], 'p1': [56, 66], 'p2': [36, 66]})], [('regression: two boardings share one stop', {'cap': 4, 'start': 1, 'floor_s': 2, 'stop_s': 8, 'requests': [['a', 1, 4], ['b', 1, 4]]}, {'a': [0, 14], 'b': [0, 14]}), ('boundary: alighting-only stop', {'cap': 4, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 2], ['b', 5, 6]]}, {'a': [0, 9], 'b': [20, 27]}), ('sampled regression 40', {'cap': 2, 'start': 6, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 9, 5], ['p1', 8, 3], ['p2', 5, 4]]}, {'p0': [6, 30], 'p2': [30, 40], 'p1': [16, 50]}), ('control 9', {'cap': 4, 'start': 1, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 6, 2], ['p1', 4, 5], ['p2', 3, 6], ['p3', 0, 9]]}, {'p1': [11, 18], 'p2': [4, 25], 'p0': [30, 43], 'p3': [52, 75]}), ('regression: full car at a floor where a rider alights', {'cap': 1, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 3], ['b', 3, 6]]}, {'a': [0, 11], 'b': [11, 22]}), ('sampled regression 23', {'cap': 4, 'start': 8, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 9, 4], ['p1', 9, 1], ['p2', 0, 1], ['p3', 6, 2]]}, {'p0': [2, 22], 'p3': [13, 31], 'p1': [2, 38], 'p2': [45, 52]}), ('control 26', {'cap': 1, 'start': 3, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 0, 4], ['p1', 1, 6], ['p2', 1, 6], ['p3', 5, 1]]}, {'p3': [4, 20], 'p0': [30, 46], 'p1': [60, 78], 'p2': [96, 114]}), ('control 29', {'cap': 4, 'start': 5, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 8, 5], ['p1', 0, 2], ['p2', 7, 1]]}, {'p0': [6, 28], 'p2': [16, 44], 'p1': [54, 66]})], [('regression: full car at a floor where a rider alights', {'cap': 1, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 3], ['b', 3, 6]]}, {'a': [0, 11], 'b': [11, 22]}), ('boundary: opposite-direction passenger waits', {'cap': 4, 'start': 2, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 2, 0], ['b', 2, 5]]}, {'b': [0, 11], 'a': [22, 31]}), ('sampled regression 61', {'cap': 2, 'start': 1, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 4, 9], ['p1', 8, 1], ['p2', 3, 8], ['p3', 1, 4]]}, {'p3': [0, 22], 'p2': [12, 38], 'p0': [22, 48], 'p1': [58, 80]}), ('control 14', {'cap': 4, 'start': 1, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 2, 1], ['p1', 0, 5]]}, {'p0': [2, 9], 'p1': [16, 31]}), ('regression: capacity exactly reached', {'cap': 2, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 4], ['b', 0, 5], ['c', 0, 6]]}, {'a': [0, 13], 'b': [0, 20], 'c': [35, 52]}), ('sampled regression 34', {'cap': 2, 'start': 4, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 2, 0], ['p1', 2, 8], ['p2', 6, 1], ['p3', 3, 7], ['p4', 6, 8], ['p5', 2, 4]]}, {'p4': [4, 13], 'p2': [22, 42], 'p0': [35, 49], 'p5': [58, 67], 'p1': [58, 80], 'p3': [95, 108]}), ('control 37', {'cap': 2, 'start': 2, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 5, 9], ['p1', 6, 7]]}, {'p1': [13, 20], 'p0': [6, 29]}), ('sampled regression 40', {'cap': 2, 'start': 6, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 9, 5], ['p1', 8, 3], ['p2', 5, 4]]}, {'p0': [6, 30], 'p2': [30, 40], 'p1': [16, 50]})], [('regression: capacity exactly reached', {'cap': 2, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 4], ['b', 0, 5], ['c', 0, 6]]}, {'a': [0, 13], 'b': [0, 20], 'c': [35, 52]}), ('regression: full car at a floor where a rider alights', {'cap': 1, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 3], ['b', 3, 6]]}, {'a': [0, 11], 'b': [11, 22]}), ('control 19', {'cap': 2, 'start': 1, 'floor_s': 2, 'stop_s': 8, 'requests': [['p0', 0, 5], ['p1', 6, 4], ['p2', 9, 2], ['p3', 4, 5]]}, {'p3': [6, 16], 'p1': [46, 58], 'p2': [32, 70], 'p0': [82, 100]}), ('regression: two boardings share one stop', {'cap': 4, 'start': 1, 'floor_s': 2, 'stop_s': 8, 'requests': [['a', 1, 4], ['b', 1, 4]]}, {'a': [0, 14], 'b': [0, 14]}), ('boundary: alighting-only stop', {'cap': 4, 'start': 0, 'floor_s': 2, 'stop_s': 5, 'requests': [['a', 0, 2], ['b', 5, 6]]}, {'a': [0, 9], 'b': [20, 27]}), ('control 45', {'cap': 4, 'start': 8, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 0, 2], ['p1', 6, 2], ['p2', 4, 5], ['p3', 1, 7], ['p4', 7, 4]]}, {'p4': [2, 18], 'p1': [9, 27], 'p0': [36, 50], 'p2': [59, 66], 'p3': [43, 75]}), ('sampled regression 48', {'cap': 2, 'start': 8, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 2, 0], ['p1', 0, 2], ['p2', 8, 5], ['p3', 6, 4], ['p4', 0, 3]]}, {'p2': [0, 16], 'p3': [9, 23], 'p0': [32, 41], 'p1': [46, 55], 'p4': [46, 62]}), ('control 51', {'cap': 4, 'start': 4, 'floor_s': 2, 'stop_s': 5, 'requests': [['p0', 8, 9], ['p1', 2, 6], ['p2', 8, 1], ['p3', 1, 6], ['p4', 3, 1]]}, {'p0': [8, 15], 'p2': [22, 46], 'p4': [37, 46], 'p1': [58, 71], 'p3': [51, 71]})]]
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:
Stops with several boarders take longer than one stop time, or alighting-only stops take no time.

All passengers [id, from, to] wait at time 0. The car starts at start heading up. At each floor it first lets riders alight, then boards waiting passengers (in id order) whose travel direction equals the car direction while load < cap; any alighting or boarding costs one stop_s. If no rider destination or waiting origin lies strictly ahead it reverses in place (and may board again); otherwise it moves one floor (floor_s). Return {id: [board time, alight time]} for delivered passengers.

split: open-access