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

N = 1
observations = []
def solve(commands, size):
    full=set(range(size))
    out=[]
    for segments,closed,clip in commands:
        coverage=set()
        count=len(segments)
        for i,(body,start,end,join,active) in enumerate(segments):
            if not active: continue
            before=segments[i-1][4] if i>0 else (segments[-1][4] if closed and count else False)
            after=segments[i+1][4] if i+1<count else (segments[0][4] if closed and count else False)
            coverage.update(body)
            if not before: coverage.update(start)
            if not after: coverage.update(end)
            if False: coverage.update(join)
        out.append(sorted(coverage & set(clip) & full))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('explicit sequence 0', solve([[[[[0], [1], [2], [3], False]], False, [0, 1, 2, 3]]], 4), [[]])
    check('explicit sequence 1', solve([[[[[], [0], [1], [], True]], False, [0, 1, 2, 3]]], 4), [[0, 1]])
    check('explicit sequence 2', solve([[[[[], [], [1], [], True]], False, [0, 1, 2, 3]]], 4), [[1]])
    check('explicit sequence 3', solve([[[[[0], [2], [3], [1], True], [[1], [2], [3], [0], True]], True, [0, 1, 2, 3]]], 4), [[0, 1]])
    check('explicit sequence 4', solve([[[[[0], [1], [2], [3], True], [[], [], [], [], False], [[1], [2], [3], [0], True]], False, [0, 1, 2, 3]]], 4), [[0, 1, 2, 3]])
    check('explicit sequence 5', solve([[[[[0], [], [1], [2], True], [[], [], [], [], False], [[], [], [], [], False], [[], [], [], [], False]], False, [0, 1, 2, 3]]], 4), [[0, 1]])
    check('explicit sequence 6', solve([[[[[0], [1], [2], [3], True]], False, [0, 1, 2, 3]]], 4), [[0, 1, 2]])
    check('explicit sequence 7', solve([[[[[0], [], [], [2], True], [[1], [], [], [3], True]], False, [0, 1, 2, 3]]], 4), [[0, 1, 2]])
    check('explicit sequence 8', solve([[[[[0], [], [], [2], True], [[], [], [], [], False]], True, [0, 1, 2, 3]]], 4), [[0]])
    check('explicit sequence 9', solve([[[[[0, 1], [2], [3], [], True]], False, [0]]], 4), [[0]])
    check('explicit sequence 10', solve([[[[[0, 1], [2], [3], [], True]], False, []]], 4), [[]])
    check('explicit sequence 11', solve([[[[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], [], [], True]], False, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]], 4), [[0, 1, 2, 3]])
    check('explicit sequence 12', solve([[[[[0], [], [], [], True], [[], [], [], [], False], [[1], [3], [], [], True]], False, [0, 1, 2, 3]]], 4), [[0, 1, 3]])
    check('explicit sequence 13', solve([[[[[0], [1], [2], [3], True], [[0], [], [], [], True]], False, [0, 1, 2, 3]]], 4), [[0, 1, 3]])
if N == 2:
    check('explicit sequence 0', solve([[[[[0], [1], [2], [3], False]], False, [0, 1, 2, 3]]], 5), [[]])
    check('explicit sequence 1', solve([[[[[], [0], [1], [], True]], False, [0, 1, 2, 3]]], 5), [[0, 1]])
    check('explicit sequence 2', solve([[[[[], [], [1], [], True]], False, [0, 1, 2, 3]]], 5), [[1]])
    check('explicit sequence 3', solve([[[[[0], [2], [3], [1], True], [[1], [2], [3], [0], True]], True, [0, 1, 2, 3]]], 5), [[0, 1]])
    check('explicit sequence 4', solve([[[[[0], [1], [2], [3], True], [[], [], [], [], False], [[1], [2], [3], [0], True]], False, [0, 1, 2, 3]]], 5), [[0, 1, 2, 3]])
    check('explicit sequence 5', solve([[[[[0], [], [1], [2], True], [[], [], [], [], False], [[], [], [], [], False], [[], [], [], [], False]], False, [0, 1, 2, 3]]], 5), [[0, 1]])
    check('explicit sequence 6', solve([[[[[0], [1], [2], [3], True]], False, [0, 1, 2, 3]]], 5), [[0, 1, 2]])
    check('explicit sequence 7', solve([[[[[0], [], [], [2], True], [[1], [], [], [3], True]], False, [0, 1, 2, 3]]], 5), [[0, 1, 2]])
    check('explicit sequence 8', solve([[[[[0], [], [], [2], True], [[], [], [], [], False]], True, [0, 1, 2, 3]]], 5), [[0]])
    check('explicit sequence 9', solve([[[[[0, 1], [2], [3], [], True]], False, [0]]], 5), [[0]])
    check('explicit sequence 10', solve([[[[[0, 1], [2], [3], [], True]], False, []]], 5), [[]])
    check('explicit sequence 11', solve([[[[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], [], [], True]], False, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]], 5), [[0, 1, 2, 3, 4]])
    check('explicit sequence 12', solve([[[[[0], [], [], [], True], [[], [], [], [], False], [[1], [3], [], [], True]], False, [0, 1, 2, 3]]], 5), [[0, 1, 3]])
    check('explicit sequence 13', solve([[[[[0], [1], [2], [3], True], [[0], [], [], [], True]], False, [0, 1, 2, 3]]], 5), [[0, 1, 3]])
if N == 3:
    check('explicit sequence 0', solve([[[[[0], [1], [2], [3], False]], False, [0, 1, 2, 3]]], 6), [[]])
    check('explicit sequence 1', solve([[[[[], [0], [1], [], True]], False, [0, 1, 2, 3]]], 6), [[0, 1]])
    check('explicit sequence 2', solve([[[[[], [], [1], [], True]], False, [0, 1, 2, 3]]], 6), [[1]])
    check('explicit sequence 3', solve([[[[[0], [2], [3], [1], True], [[1], [2], [3], [0], True]], True, [0, 1, 2, 3]]], 6), [[0, 1]])
    check('explicit sequence 4', solve([[[[[0], [1], [2], [3], True], [[], [], [], [], False], [[1], [2], [3], [0], True]], False, [0, 1, 2, 3]]], 6), [[0, 1, 2, 3]])
    check('explicit sequence 5', solve([[[[[0], [], [1], [2], True], [[], [], [], [], False], [[], [], [], [], False], [[], [], [], [], False]], False, [0, 1, 2, 3]]], 6), [[0, 1]])
    check('explicit sequence 6', solve([[[[[0], [1], [2], [3], True]], False, [0, 1, 2, 3]]], 6), [[0, 1, 2]])
    check('explicit sequence 7', solve([[[[[0], [], [], [2], True], [[1], [], [], [3], True]], False, [0, 1, 2, 3]]], 6), [[0, 1, 2]])
    check('explicit sequence 8', solve([[[[[0], [], [], [2], True], [[], [], [], [], False]], True, [0, 1, 2, 3]]], 6), [[0]])
    check('explicit sequence 9', solve([[[[[0, 1], [2], [3], [], True]], False, [0]]], 6), [[0]])
    check('explicit sequence 10', solve([[[[[0, 1], [2], [3], [], True]], False, []]], 6), [[]])
    check('explicit sequence 11', solve([[[[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], [], [], True]], False, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]], 6), [[0, 1, 2, 3, 4, 5]])
    check('explicit sequence 12', solve([[[[[0], [], [], [], True], [[], [], [], [], False], [[1], [3], [], [], True]], False, [0, 1, 2, 3]]], 6), [[0, 1, 3]])
    check('explicit sequence 13', solve([[[[[0], [1], [2], [3], True], [[0], [], [], [], True]], False, [0, 1, 2, 3]]], 6), [[0, 1, 3]])
if N == 4:
    check('explicit sequence 0', solve([[[[[0], [1], [2], [3], False]], False, [0, 1, 2, 3]]], 7), [[]])
    check('explicit sequence 1', solve([[[[[], [0], [1], [], True]], False, [0, 1, 2, 3]]], 7), [[0, 1]])
    check('explicit sequence 2', solve([[[[[], [], [1], [], True]], False, [0, 1, 2, 3]]], 7), [[1]])
    check('explicit sequence 3', solve([[[[[0], [2], [3], [1], True], [[1], [2], [3], [0], True]], True, [0, 1, 2, 3]]], 7), [[0, 1]])
    check('explicit sequence 4', solve([[[[[0], [1], [2], [3], True], [[], [], [], [], False], [[1], [2], [3], [0], True]], False, [0, 1, 2, 3]]], 7), [[0, 1, 2, 3]])
    check('explicit sequence 5', solve([[[[[0], [], [1], [2], True], [[], [], [], [], False], [[], [], [], [], False], [[], [], [], [], False]], False, [0, 1, 2, 3]]], 7), [[0, 1]])
    check('explicit sequence 6', solve([[[[[0], [1], [2], [3], True]], False, [0, 1, 2, 3]]], 7), [[0, 1, 2]])
    check('explicit sequence 7', solve([[[[[0], [], [], [2], True], [[1], [], [], [3], True]], False, [0, 1, 2, 3]]], 7), [[0, 1, 2]])
    check('explicit sequence 8', solve([[[[[0], [], [], [2], True], [[], [], [], [], False]], True, [0, 1, 2, 3]]], 7), [[0]])
    check('explicit sequence 9', solve([[[[[0, 1], [2], [3], [], True]], False, [0]]], 7), [[0]])
    check('explicit sequence 10', solve([[[[[0, 1], [2], [3], [], True]], False, []]], 7), [[]])
    check('explicit sequence 11', solve([[[[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], [], [], True]], False, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]], 7), [[0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 12', solve([[[[[0], [], [], [], True], [[], [], [], [], False], [[1], [3], [], [], True]], False, [0, 1, 2, 3]]], 7), [[0, 1, 3]])
    check('explicit sequence 13', solve([[[[[0], [1], [2], [3], True], [[0], [], [], [], True]], False, [0, 1, 2, 3]]], 7), [[0, 1, 3]])
if N == 5:
    check('explicit sequence 0', solve([[[[[0], [1], [2], [3], False]], False, [0, 1, 2, 3]]], 8), [[]])
    check('explicit sequence 1', solve([[[[[], [0], [1], [], True]], False, [0, 1, 2, 3]]], 8), [[0, 1]])
    check('explicit sequence 2', solve([[[[[], [], [1], [], True]], False, [0, 1, 2, 3]]], 8), [[1]])
    check('explicit sequence 3', solve([[[[[0], [2], [3], [1], True], [[1], [2], [3], [0], True]], True, [0, 1, 2, 3]]], 8), [[0, 1]])
    check('explicit sequence 4', solve([[[[[0], [1], [2], [3], True], [[], [], [], [], False], [[1], [2], [3], [0], True]], False, [0, 1, 2, 3]]], 8), [[0, 1, 2, 3]])
    check('explicit sequence 5', solve([[[[[0], [], [1], [2], True], [[], [], [], [], False], [[], [], [], [], False], [[], [], [], [], False]], False, [0, 1, 2, 3]]], 8), [[0, 1]])
    check('explicit sequence 6', solve([[[[[0], [1], [2], [3], True]], False, [0, 1, 2, 3]]], 8), [[0, 1, 2]])
    check('explicit sequence 7', solve([[[[[0], [], [], [2], True], [[1], [], [], [3], True]], False, [0, 1, 2, 3]]], 8), [[0, 1, 2]])
    check('explicit sequence 8', solve([[[[[0], [], [], [2], True], [[], [], [], [], False]], True, [0, 1, 2, 3]]], 8), [[0]])
    check('explicit sequence 9', solve([[[[[0, 1], [2], [3], [], True]], False, [0]]], 8), [[0]])
    check('explicit sequence 10', solve([[[[[0, 1], [2], [3], [], True]], False, []]], 8), [[]])
    check('explicit sequence 11', solve([[[[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], [], [], True]], False, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]], 8), [[0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 12', solve([[[[[0], [], [], [], True], [[], [], [], [], False], [[1], [3], [], [], True]], False, [0, 1, 2, 3]]], 8), [[0, 1, 3]])
    check('explicit sequence 13', solve([[[[[0], [1], [2], [3], True], [[0], [], [], [], True]], False, [0, 1, 2, 3]]], 8), [[0, 1, 3]])
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(commands, size):
    full=set(range(size))
    out=[]
    for segments,closed,clip in commands:
        coverage=set()
        count=len(segments)
        for i,(body,start,end,join,active) in enumerate(segments):
            if not active: continue
            before=segments[i-1][4] if i>0 else (segments[-1][4] if closed and count else False)
            after=segments[i+1][4] if i+1<count else (segments[0][4] if closed and count else False)
            coverage.update(body)
            if not before: coverage.update(start)
            if not after: coverage.update(end)
            if after and closed: coverage.update(join)
        out.append(sorted(coverage & set(clip) & full))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('explicit sequence 0', solve([[[[[0], [1], [2], [3], False]], False, [0, 1, 2, 3]]], 4), [[]])
    check('explicit sequence 1', solve([[[[[], [0], [1], [], True]], False, [0, 1, 2, 3]]], 4), [[0, 1]])
    check('explicit sequence 2', solve([[[[[], [], [1], [], True]], False, [0, 1, 2, 3]]], 4), [[1]])
    check('explicit sequence 3', solve([[[[[0], [2], [3], [1], True], [[1], [2], [3], [0], True]], True, [0, 1, 2, 3]]], 4), [[0, 1]])
    check('explicit sequence 4', solve([[[[[0], [1], [2], [3], True], [[], [], [], [], False], [[1], [2], [3], [0], True]], False, [0, 1, 2, 3]]], 4), [[0, 1, 2, 3]])
    check('explicit sequence 5', solve([[[[[0], [], [1], [2], True], [[], [], [], [], False], [[], [], [], [], False], [[], [], [], [], False]], False, [0, 1, 2, 3]]], 4), [[0, 1]])
    check('explicit sequence 6', solve([[[[[0], [1], [2], [3], True]], False, [0, 1, 2, 3]]], 4), [[0, 1, 2]])
    check('explicit sequence 7', solve([[[[[0], [], [], [2], True], [[1], [], [], [3], True]], False, [0, 1, 2, 3]]], 4), [[0, 1, 2]])
    check('explicit sequence 8', solve([[[[[0], [], [], [2], True], [[], [], [], [], False]], True, [0, 1, 2, 3]]], 4), [[0]])
    check('explicit sequence 9', solve([[[[[0, 1], [2], [3], [], True]], False, [0]]], 4), [[0]])
    check('explicit sequence 10', solve([[[[[0, 1], [2], [3], [], True]], False, []]], 4), [[]])
    check('explicit sequence 11', solve([[[[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], [], [], True]], False, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]], 4), [[0, 1, 2, 3]])
    check('explicit sequence 12', solve([[[[[0], [], [], [], True], [[], [], [], [], False], [[1], [3], [], [], True]], False, [0, 1, 2, 3]]], 4), [[0, 1, 3]])
    check('explicit sequence 13', solve([[[[[0], [1], [2], [3], True], [[0], [], [], [], True]], False, [0, 1, 2, 3]]], 4), [[0, 1, 3]])
if N == 2:
    check('explicit sequence 0', solve([[[[[0], [1], [2], [3], False]], False, [0, 1, 2, 3]]], 5), [[]])
    check('explicit sequence 1', solve([[[[[], [0], [1], [], True]], False, [0, 1, 2, 3]]], 5), [[0, 1]])
    check('explicit sequence 2', solve([[[[[], [], [1], [], True]], False, [0, 1, 2, 3]]], 5), [[1]])
    check('explicit sequence 3', solve([[[[[0], [2], [3], [1], True], [[1], [2], [3], [0], True]], True, [0, 1, 2, 3]]], 5), [[0, 1]])
    check('explicit sequence 4', solve([[[[[0], [1], [2], [3], True], [[], [], [], [], False], [[1], [2], [3], [0], True]], False, [0, 1, 2, 3]]], 5), [[0, 1, 2, 3]])
    check('explicit sequence 5', solve([[[[[0], [], [1], [2], True], [[], [], [], [], False], [[], [], [], [], False], [[], [], [], [], False]], False, [0, 1, 2, 3]]], 5), [[0, 1]])
    check('explicit sequence 6', solve([[[[[0], [1], [2], [3], True]], False, [0, 1, 2, 3]]], 5), [[0, 1, 2]])
    check('explicit sequence 7', solve([[[[[0], [], [], [2], True], [[1], [], [], [3], True]], False, [0, 1, 2, 3]]], 5), [[0, 1, 2]])
    check('explicit sequence 8', solve([[[[[0], [], [], [2], True], [[], [], [], [], False]], True, [0, 1, 2, 3]]], 5), [[0]])
    check('explicit sequence 9', solve([[[[[0, 1], [2], [3], [], True]], False, [0]]], 5), [[0]])
    check('explicit sequence 10', solve([[[[[0, 1], [2], [3], [], True]], False, []]], 5), [[]])
    check('explicit sequence 11', solve([[[[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], [], [], True]], False, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]], 5), [[0, 1, 2, 3, 4]])
    check('explicit sequence 12', solve([[[[[0], [], [], [], True], [[], [], [], [], False], [[1], [3], [], [], True]], False, [0, 1, 2, 3]]], 5), [[0, 1, 3]])
    check('explicit sequence 13', solve([[[[[0], [1], [2], [3], True], [[0], [], [], [], True]], False, [0, 1, 2, 3]]], 5), [[0, 1, 3]])
if N == 3:
    check('explicit sequence 0', solve([[[[[0], [1], [2], [3], False]], False, [0, 1, 2, 3]]], 6), [[]])
    check('explicit sequence 1', solve([[[[[], [0], [1], [], True]], False, [0, 1, 2, 3]]], 6), [[0, 1]])
    check('explicit sequence 2', solve([[[[[], [], [1], [], True]], False, [0, 1, 2, 3]]], 6), [[1]])
    check('explicit sequence 3', solve([[[[[0], [2], [3], [1], True], [[1], [2], [3], [0], True]], True, [0, 1, 2, 3]]], 6), [[0, 1]])
    check('explicit sequence 4', solve([[[[[0], [1], [2], [3], True], [[], [], [], [], False], [[1], [2], [3], [0], True]], False, [0, 1, 2, 3]]], 6), [[0, 1, 2, 3]])
    check('explicit sequence 5', solve([[[[[0], [], [1], [2], True], [[], [], [], [], False], [[], [], [], [], False], [[], [], [], [], False]], False, [0, 1, 2, 3]]], 6), [[0, 1]])
    check('explicit sequence 6', solve([[[[[0], [1], [2], [3], True]], False, [0, 1, 2, 3]]], 6), [[0, 1, 2]])
    check('explicit sequence 7', solve([[[[[0], [], [], [2], True], [[1], [], [], [3], True]], False, [0, 1, 2, 3]]], 6), [[0, 1, 2]])
    check('explicit sequence 8', solve([[[[[0], [], [], [2], True], [[], [], [], [], False]], True, [0, 1, 2, 3]]], 6), [[0]])
    check('explicit sequence 9', solve([[[[[0, 1], [2], [3], [], True]], False, [0]]], 6), [[0]])
    check('explicit sequence 10', solve([[[[[0, 1], [2], [3], [], True]], False, []]], 6), [[]])
    check('explicit sequence 11', solve([[[[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], [], [], True]], False, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]], 6), [[0, 1, 2, 3, 4, 5]])
    check('explicit sequence 12', solve([[[[[0], [], [], [], True], [[], [], [], [], False], [[1], [3], [], [], True]], False, [0, 1, 2, 3]]], 6), [[0, 1, 3]])
    check('explicit sequence 13', solve([[[[[0], [1], [2], [3], True], [[0], [], [], [], True]], False, [0, 1, 2, 3]]], 6), [[0, 1, 3]])
if N == 4:
    check('explicit sequence 0', solve([[[[[0], [1], [2], [3], False]], False, [0, 1, 2, 3]]], 7), [[]])
    check('explicit sequence 1', solve([[[[[], [0], [1], [], True]], False, [0, 1, 2, 3]]], 7), [[0, 1]])
    check('explicit sequence 2', solve([[[[[], [], [1], [], True]], False, [0, 1, 2, 3]]], 7), [[1]])
    check('explicit sequence 3', solve([[[[[0], [2], [3], [1], True], [[1], [2], [3], [0], True]], True, [0, 1, 2, 3]]], 7), [[0, 1]])
    check('explicit sequence 4', solve([[[[[0], [1], [2], [3], True], [[], [], [], [], False], [[1], [2], [3], [0], True]], False, [0, 1, 2, 3]]], 7), [[0, 1, 2, 3]])
    check('explicit sequence 5', solve([[[[[0], [], [1], [2], True], [[], [], [], [], False], [[], [], [], [], False], [[], [], [], [], False]], False, [0, 1, 2, 3]]], 7), [[0, 1]])
    check('explicit sequence 6', solve([[[[[0], [1], [2], [3], True]], False, [0, 1, 2, 3]]], 7), [[0, 1, 2]])
    check('explicit sequence 7', solve([[[[[0], [], [], [2], True], [[1], [], [], [3], True]], False, [0, 1, 2, 3]]], 7), [[0, 1, 2]])
    check('explicit sequence 8', solve([[[[[0], [], [], [2], True], [[], [], [], [], False]], True, [0, 1, 2, 3]]], 7), [[0]])
    check('explicit sequence 9', solve([[[[[0, 1], [2], [3], [], True]], False, [0]]], 7), [[0]])
    check('explicit sequence 10', solve([[[[[0, 1], [2], [3], [], True]], False, []]], 7), [[]])
    check('explicit sequence 11', solve([[[[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], [], [], True]], False, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]], 7), [[0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 12', solve([[[[[0], [], [], [], True], [[], [], [], [], False], [[1], [3], [], [], True]], False, [0, 1, 2, 3]]], 7), [[0, 1, 3]])
    check('explicit sequence 13', solve([[[[[0], [1], [2], [3], True], [[0], [], [], [], True]], False, [0, 1, 2, 3]]], 7), [[0, 1, 3]])
if N == 5:
    check('explicit sequence 0', solve([[[[[0], [1], [2], [3], False]], False, [0, 1, 2, 3]]], 8), [[]])
    check('explicit sequence 1', solve([[[[[], [0], [1], [], True]], False, [0, 1, 2, 3]]], 8), [[0, 1]])
    check('explicit sequence 2', solve([[[[[], [], [1], [], True]], False, [0, 1, 2, 3]]], 8), [[1]])
    check('explicit sequence 3', solve([[[[[0], [2], [3], [1], True], [[1], [2], [3], [0], True]], True, [0, 1, 2, 3]]], 8), [[0, 1]])
    check('explicit sequence 4', solve([[[[[0], [1], [2], [3], True], [[], [], [], [], False], [[1], [2], [3], [0], True]], False, [0, 1, 2, 3]]], 8), [[0, 1, 2, 3]])
    check('explicit sequence 5', solve([[[[[0], [], [1], [2], True], [[], [], [], [], False], [[], [], [], [], False], [[], [], [], [], False]], False, [0, 1, 2, 3]]], 8), [[0, 1]])
    check('explicit sequence 6', solve([[[[[0], [1], [2], [3], True]], False, [0, 1, 2, 3]]], 8), [[0, 1, 2]])
    check('explicit sequence 7', solve([[[[[0], [], [], [2], True], [[1], [], [], [3], True]], False, [0, 1, 2, 3]]], 8), [[0, 1, 2]])
    check('explicit sequence 8', solve([[[[[0], [], [], [2], True], [[], [], [], [], False]], True, [0, 1, 2, 3]]], 8), [[0]])
    check('explicit sequence 9', solve([[[[[0, 1], [2], [3], [], True]], False, [0]]], 8), [[0]])
    check('explicit sequence 10', solve([[[[[0, 1], [2], [3], [], True]], False, []]], 8), [[]])
    check('explicit sequence 11', solve([[[[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], [], [], True]], False, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]], 8), [[0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 12', solve([[[[[0], [], [], [], True], [[], [], [], [], False], [[1], [3], [], [], True]], False, [0, 1, 2, 3]]], 8), [[0, 1, 3]])
    check('explicit sequence 13', solve([[[[[0], [1], [2], [3], True], [[0], [], [], [], True]], False, [0, 1, 2, 3]]], 8), [[0, 1, 3]])
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:
Adjacent active segments lose their precomputed connecting join coverage.

Segments carry precomputed body, start-cap, end-cap and following-join sample sets plus an active flag. Active adjacent segments share a join and suppress interior caps. Inactive segments create dash gaps; each active component receives caps at its gap endpoints. A closed path connects the last and first segments. Empty bodies may still have cap coverage. Clip the complete union to the requested mask and target.

split: open-access


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

N = 1
observations = []
def solve(commands, size):
    full=set(range(size))
    out=[]
    for segments,closed,clip in commands:
        coverage=set()
        count=len(segments)
        for i,(body,start,end,join,active) in enumerate(segments):
            if not active: continue
            before=segments[i-1][4] if i>0 else (segments[-1][4] if closed and count else False)
            after=segments[i+1][4] if i+1<count else (segments[0][4] if closed and count else False)
            coverage.update(body)
            if not before: coverage.update(start)
            if not after: coverage.update(end)
            if i+1<count or closed: coverage.update(join)
        out.append(sorted(coverage & set(clip) & full))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('explicit sequence 0', solve([[[[[0], [1], [2], [3], False]], False, [0, 1, 2, 3]]], 4), [[]])
    check('explicit sequence 1', solve([[[[[], [0], [1], [], True]], False, [0, 1, 2, 3]]], 4), [[0, 1]])
    check('explicit sequence 2', solve([[[[[], [], [1], [], True]], False, [0, 1, 2, 3]]], 4), [[1]])
    check('explicit sequence 3', solve([[[[[0], [2], [3], [1], True], [[1], [2], [3], [0], True]], True, [0, 1, 2, 3]]], 4), [[0, 1]])
    check('explicit sequence 4', solve([[[[[0], [1], [2], [3], True], [[], [], [], [], False], [[1], [2], [3], [0], True]], False, [0, 1, 2, 3]]], 4), [[0, 1, 2, 3]])
    check('explicit sequence 5', solve([[[[[0], [], [1], [2], True], [[], [], [], [], False], [[], [], [], [], False], [[], [], [], [], False]], False, [0, 1, 2, 3]]], 4), [[0, 1]])
    check('explicit sequence 6', solve([[[[[0], [1], [2], [3], True]], False, [0, 1, 2, 3]]], 4), [[0, 1, 2]])
    check('explicit sequence 7', solve([[[[[0], [], [], [2], True], [[1], [], [], [3], True]], False, [0, 1, 2, 3]]], 4), [[0, 1, 2]])
    check('explicit sequence 8', solve([[[[[0], [], [], [2], True], [[], [], [], [], False]], True, [0, 1, 2, 3]]], 4), [[0]])
    check('explicit sequence 9', solve([[[[[0, 1], [2], [3], [], True]], False, [0]]], 4), [[0]])
    check('explicit sequence 10', solve([[[[[0, 1], [2], [3], [], True]], False, []]], 4), [[]])
    check('explicit sequence 11', solve([[[[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], [], [], True]], False, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]], 4), [[0, 1, 2, 3]])
    check('explicit sequence 12', solve([[[[[0], [], [], [], True], [[], [], [], [], False], [[1], [3], [], [], True]], False, [0, 1, 2, 3]]], 4), [[0, 1, 3]])
    check('explicit sequence 13', solve([[[[[0], [1], [2], [3], True], [[0], [], [], [], True]], False, [0, 1, 2, 3]]], 4), [[0, 1, 3]])
if N == 2:
    check('explicit sequence 0', solve([[[[[0], [1], [2], [3], False]], False, [0, 1, 2, 3]]], 5), [[]])
    check('explicit sequence 1', solve([[[[[], [0], [1], [], True]], False, [0, 1, 2, 3]]], 5), [[0, 1]])
    check('explicit sequence 2', solve([[[[[], [], [1], [], True]], False, [0, 1, 2, 3]]], 5), [[1]])
    check('explicit sequence 3', solve([[[[[0], [2], [3], [1], True], [[1], [2], [3], [0], True]], True, [0, 1, 2, 3]]], 5), [[0, 1]])
    check('explicit sequence 4', solve([[[[[0], [1], [2], [3], True], [[], [], [], [], False], [[1], [2], [3], [0], True]], False, [0, 1, 2, 3]]], 5), [[0, 1, 2, 3]])
    check('explicit sequence 5', solve([[[[[0], [], [1], [2], True], [[], [], [], [], False], [[], [], [], [], False], [[], [], [], [], False]], False, [0, 1, 2, 3]]], 5), [[0, 1]])
    check('explicit sequence 6', solve([[[[[0], [1], [2], [3], True]], False, [0, 1, 2, 3]]], 5), [[0, 1, 2]])
    check('explicit sequence 7', solve([[[[[0], [], [], [2], True], [[1], [], [], [3], True]], False, [0, 1, 2, 3]]], 5), [[0, 1, 2]])
    check('explicit sequence 8', solve([[[[[0], [], [], [2], True], [[], [], [], [], False]], True, [0, 1, 2, 3]]], 5), [[0]])
    check('explicit sequence 9', solve([[[[[0, 1], [2], [3], [], True]], False, [0]]], 5), [[0]])
    check('explicit sequence 10', solve([[[[[0, 1], [2], [3], [], True]], False, []]], 5), [[]])
    check('explicit sequence 11', solve([[[[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], [], [], True]], False, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]], 5), [[0, 1, 2, 3, 4]])
    check('explicit sequence 12', solve([[[[[0], [], [], [], True], [[], [], [], [], False], [[1], [3], [], [], True]], False, [0, 1, 2, 3]]], 5), [[0, 1, 3]])
    check('explicit sequence 13', solve([[[[[0], [1], [2], [3], True], [[0], [], [], [], True]], False, [0, 1, 2, 3]]], 5), [[0, 1, 3]])
if N == 3:
    check('explicit sequence 0', solve([[[[[0], [1], [2], [3], False]], False, [0, 1, 2, 3]]], 6), [[]])
    check('explicit sequence 1', solve([[[[[], [0], [1], [], True]], False, [0, 1, 2, 3]]], 6), [[0, 1]])
    check('explicit sequence 2', solve([[[[[], [], [1], [], True]], False, [0, 1, 2, 3]]], 6), [[1]])
    check('explicit sequence 3', solve([[[[[0], [2], [3], [1], True], [[1], [2], [3], [0], True]], True, [0, 1, 2, 3]]], 6), [[0, 1]])
    check('explicit sequence 4', solve([[[[[0], [1], [2], [3], True], [[], [], [], [], False], [[1], [2], [3], [0], True]], False, [0, 1, 2, 3]]], 6), [[0, 1, 2, 3]])
    check('explicit sequence 5', solve([[[[[0], [], [1], [2], True], [[], [], [], [], False], [[], [], [], [], False], [[], [], [], [], False]], False, [0, 1, 2, 3]]], 6), [[0, 1]])
    check('explicit sequence 6', solve([[[[[0], [1], [2], [3], True]], False, [0, 1, 2, 3]]], 6), [[0, 1, 2]])
    check('explicit sequence 7', solve([[[[[0], [], [], [2], True], [[1], [], [], [3], True]], False, [0, 1, 2, 3]]], 6), [[0, 1, 2]])
    check('explicit sequence 8', solve([[[[[0], [], [], [2], True], [[], [], [], [], False]], True, [0, 1, 2, 3]]], 6), [[0]])
    check('explicit sequence 9', solve([[[[[0, 1], [2], [3], [], True]], False, [0]]], 6), [[0]])
    check('explicit sequence 10', solve([[[[[0, 1], [2], [3], [], True]], False, []]], 6), [[]])
    check('explicit sequence 11', solve([[[[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], [], [], True]], False, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]], 6), [[0, 1, 2, 3, 4, 5]])
    check('explicit sequence 12', solve([[[[[0], [], [], [], True], [[], [], [], [], False], [[1], [3], [], [], True]], False, [0, 1, 2, 3]]], 6), [[0, 1, 3]])
    check('explicit sequence 13', solve([[[[[0], [1], [2], [3], True], [[0], [], [], [], True]], False, [0, 1, 2, 3]]], 6), [[0, 1, 3]])
if N == 4:
    check('explicit sequence 0', solve([[[[[0], [1], [2], [3], False]], False, [0, 1, 2, 3]]], 7), [[]])
    check('explicit sequence 1', solve([[[[[], [0], [1], [], True]], False, [0, 1, 2, 3]]], 7), [[0, 1]])
    check('explicit sequence 2', solve([[[[[], [], [1], [], True]], False, [0, 1, 2, 3]]], 7), [[1]])
    check('explicit sequence 3', solve([[[[[0], [2], [3], [1], True], [[1], [2], [3], [0], True]], True, [0, 1, 2, 3]]], 7), [[0, 1]])
    check('explicit sequence 4', solve([[[[[0], [1], [2], [3], True], [[], [], [], [], False], [[1], [2], [3], [0], True]], False, [0, 1, 2, 3]]], 7), [[0, 1, 2, 3]])
    check('explicit sequence 5', solve([[[[[0], [], [1], [2], True], [[], [], [], [], False], [[], [], [], [], False], [[], [], [], [], False]], False, [0, 1, 2, 3]]], 7), [[0, 1]])
    check('explicit sequence 6', solve([[[[[0], [1], [2], [3], True]], False, [0, 1, 2, 3]]], 7), [[0, 1, 2]])
    check('explicit sequence 7', solve([[[[[0], [], [], [2], True], [[1], [], [], [3], True]], False, [0, 1, 2, 3]]], 7), [[0, 1, 2]])
    check('explicit sequence 8', solve([[[[[0], [], [], [2], True], [[], [], [], [], False]], True, [0, 1, 2, 3]]], 7), [[0]])
    check('explicit sequence 9', solve([[[[[0, 1], [2], [3], [], True]], False, [0]]], 7), [[0]])
    check('explicit sequence 10', solve([[[[[0, 1], [2], [3], [], True]], False, []]], 7), [[]])
    check('explicit sequence 11', solve([[[[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], [], [], True]], False, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]], 7), [[0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 12', solve([[[[[0], [], [], [], True], [[], [], [], [], False], [[1], [3], [], [], True]], False, [0, 1, 2, 3]]], 7), [[0, 1, 3]])
    check('explicit sequence 13', solve([[[[[0], [1], [2], [3], True], [[0], [], [], [], True]], False, [0, 1, 2, 3]]], 7), [[0, 1, 3]])
if N == 5:
    check('explicit sequence 0', solve([[[[[0], [1], [2], [3], False]], False, [0, 1, 2, 3]]], 8), [[]])
    check('explicit sequence 1', solve([[[[[], [0], [1], [], True]], False, [0, 1, 2, 3]]], 8), [[0, 1]])
    check('explicit sequence 2', solve([[[[[], [], [1], [], True]], False, [0, 1, 2, 3]]], 8), [[1]])
    check('explicit sequence 3', solve([[[[[0], [2], [3], [1], True], [[1], [2], [3], [0], True]], True, [0, 1, 2, 3]]], 8), [[0, 1]])
    check('explicit sequence 4', solve([[[[[0], [1], [2], [3], True], [[], [], [], [], False], [[1], [2], [3], [0], True]], False, [0, 1, 2, 3]]], 8), [[0, 1, 2, 3]])
    check('explicit sequence 5', solve([[[[[0], [], [1], [2], True], [[], [], [], [], False], [[], [], [], [], False], [[], [], [], [], False]], False, [0, 1, 2, 3]]], 8), [[0, 1]])
    check('explicit sequence 6', solve([[[[[0], [1], [2], [3], True]], False, [0, 1, 2, 3]]], 8), [[0, 1, 2]])
    check('explicit sequence 7', solve([[[[[0], [], [], [2], True], [[1], [], [], [3], True]], False, [0, 1, 2, 3]]], 8), [[0, 1, 2]])
    check('explicit sequence 8', solve([[[[[0], [], [], [2], True], [[], [], [], [], False]], True, [0, 1, 2, 3]]], 8), [[0]])
    check('explicit sequence 9', solve([[[[[0, 1], [2], [3], [], True]], False, [0]]], 8), [[0]])
    check('explicit sequence 10', solve([[[[[0, 1], [2], [3], [], True]], False, []]], 8), [[]])
    check('explicit sequence 11', solve([[[[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], [], [], True]], False, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]], 8), [[0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 12', solve([[[[[0], [], [], [], True], [[], [], [], [], False], [[1], [3], [], [], True]], False, [0, 1, 2, 3]]], 8), [[0, 1, 3]])
    check('explicit sequence 13', solve([[[[[0], [1], [2], [3], True], [[0], [], [], [], True]], False, [0, 1, 2, 3]]], 8), [[0, 1, 3]])
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(commands, size):
    full=set(range(size))
    out=[]
    for segments,closed,clip in commands:
        coverage=set()
        count=len(segments)
        for i,(body,start,end,join,active) in enumerate(segments):
            if not active: continue
            before=segments[i-1][4] if i>0 else (segments[-1][4] if closed and count else False)
            after=segments[i+1][4] if i+1<count else (segments[0][4] if closed and count else False)
            coverage.update(body)
            if not before: coverage.update(start)
            if not after: coverage.update(end)
            if after or closed: coverage.update(join)
        out.append(sorted(coverage & set(clip) & full))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('explicit sequence 0', solve([[[[[0], [1], [2], [3], False]], False, [0, 1, 2, 3]]], 4), [[]])
    check('explicit sequence 1', solve([[[[[], [0], [1], [], True]], False, [0, 1, 2, 3]]], 4), [[0, 1]])
    check('explicit sequence 2', solve([[[[[], [], [1], [], True]], False, [0, 1, 2, 3]]], 4), [[1]])
    check('explicit sequence 3', solve([[[[[0], [2], [3], [1], True], [[1], [2], [3], [0], True]], True, [0, 1, 2, 3]]], 4), [[0, 1]])
    check('explicit sequence 4', solve([[[[[0], [1], [2], [3], True], [[], [], [], [], False], [[1], [2], [3], [0], True]], False, [0, 1, 2, 3]]], 4), [[0, 1, 2, 3]])
    check('explicit sequence 5', solve([[[[[0], [], [1], [2], True], [[], [], [], [], False], [[], [], [], [], False], [[], [], [], [], False]], False, [0, 1, 2, 3]]], 4), [[0, 1]])
    check('explicit sequence 6', solve([[[[[0], [1], [2], [3], True]], False, [0, 1, 2, 3]]], 4), [[0, 1, 2]])
    check('explicit sequence 7', solve([[[[[0], [], [], [2], True], [[1], [], [], [3], True]], False, [0, 1, 2, 3]]], 4), [[0, 1, 2]])
    check('explicit sequence 8', solve([[[[[0], [], [], [2], True], [[], [], [], [], False]], True, [0, 1, 2, 3]]], 4), [[0]])
    check('explicit sequence 9', solve([[[[[0, 1], [2], [3], [], True]], False, [0]]], 4), [[0]])
    check('explicit sequence 10', solve([[[[[0, 1], [2], [3], [], True]], False, []]], 4), [[]])
    check('explicit sequence 11', solve([[[[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], [], [], True]], False, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]], 4), [[0, 1, 2, 3]])
    check('explicit sequence 12', solve([[[[[0], [], [], [], True], [[], [], [], [], False], [[1], [3], [], [], True]], False, [0, 1, 2, 3]]], 4), [[0, 1, 3]])
    check('explicit sequence 13', solve([[[[[0], [1], [2], [3], True], [[0], [], [], [], True]], False, [0, 1, 2, 3]]], 4), [[0, 1, 3]])
if N == 2:
    check('explicit sequence 0', solve([[[[[0], [1], [2], [3], False]], False, [0, 1, 2, 3]]], 5), [[]])
    check('explicit sequence 1', solve([[[[[], [0], [1], [], True]], False, [0, 1, 2, 3]]], 5), [[0, 1]])
    check('explicit sequence 2', solve([[[[[], [], [1], [], True]], False, [0, 1, 2, 3]]], 5), [[1]])
    check('explicit sequence 3', solve([[[[[0], [2], [3], [1], True], [[1], [2], [3], [0], True]], True, [0, 1, 2, 3]]], 5), [[0, 1]])
    check('explicit sequence 4', solve([[[[[0], [1], [2], [3], True], [[], [], [], [], False], [[1], [2], [3], [0], True]], False, [0, 1, 2, 3]]], 5), [[0, 1, 2, 3]])
    check('explicit sequence 5', solve([[[[[0], [], [1], [2], True], [[], [], [], [], False], [[], [], [], [], False], [[], [], [], [], False]], False, [0, 1, 2, 3]]], 5), [[0, 1]])
    check('explicit sequence 6', solve([[[[[0], [1], [2], [3], True]], False, [0, 1, 2, 3]]], 5), [[0, 1, 2]])
    check('explicit sequence 7', solve([[[[[0], [], [], [2], True], [[1], [], [], [3], True]], False, [0, 1, 2, 3]]], 5), [[0, 1, 2]])
    check('explicit sequence 8', solve([[[[[0], [], [], [2], True], [[], [], [], [], False]], True, [0, 1, 2, 3]]], 5), [[0]])
    check('explicit sequence 9', solve([[[[[0, 1], [2], [3], [], True]], False, [0]]], 5), [[0]])
    check('explicit sequence 10', solve([[[[[0, 1], [2], [3], [], True]], False, []]], 5), [[]])
    check('explicit sequence 11', solve([[[[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], [], [], True]], False, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]], 5), [[0, 1, 2, 3, 4]])
    check('explicit sequence 12', solve([[[[[0], [], [], [], True], [[], [], [], [], False], [[1], [3], [], [], True]], False, [0, 1, 2, 3]]], 5), [[0, 1, 3]])
    check('explicit sequence 13', solve([[[[[0], [1], [2], [3], True], [[0], [], [], [], True]], False, [0, 1, 2, 3]]], 5), [[0, 1, 3]])
if N == 3:
    check('explicit sequence 0', solve([[[[[0], [1], [2], [3], False]], False, [0, 1, 2, 3]]], 6), [[]])
    check('explicit sequence 1', solve([[[[[], [0], [1], [], True]], False, [0, 1, 2, 3]]], 6), [[0, 1]])
    check('explicit sequence 2', solve([[[[[], [], [1], [], True]], False, [0, 1, 2, 3]]], 6), [[1]])
    check('explicit sequence 3', solve([[[[[0], [2], [3], [1], True], [[1], [2], [3], [0], True]], True, [0, 1, 2, 3]]], 6), [[0, 1]])
    check('explicit sequence 4', solve([[[[[0], [1], [2], [3], True], [[], [], [], [], False], [[1], [2], [3], [0], True]], False, [0, 1, 2, 3]]], 6), [[0, 1, 2, 3]])
    check('explicit sequence 5', solve([[[[[0], [], [1], [2], True], [[], [], [], [], False], [[], [], [], [], False], [[], [], [], [], False]], False, [0, 1, 2, 3]]], 6), [[0, 1]])
    check('explicit sequence 6', solve([[[[[0], [1], [2], [3], True]], False, [0, 1, 2, 3]]], 6), [[0, 1, 2]])
    check('explicit sequence 7', solve([[[[[0], [], [], [2], True], [[1], [], [], [3], True]], False, [0, 1, 2, 3]]], 6), [[0, 1, 2]])
    check('explicit sequence 8', solve([[[[[0], [], [], [2], True], [[], [], [], [], False]], True, [0, 1, 2, 3]]], 6), [[0]])
    check('explicit sequence 9', solve([[[[[0, 1], [2], [3], [], True]], False, [0]]], 6), [[0]])
    check('explicit sequence 10', solve([[[[[0, 1], [2], [3], [], True]], False, []]], 6), [[]])
    check('explicit sequence 11', solve([[[[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], [], [], True]], False, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]], 6), [[0, 1, 2, 3, 4, 5]])
    check('explicit sequence 12', solve([[[[[0], [], [], [], True], [[], [], [], [], False], [[1], [3], [], [], True]], False, [0, 1, 2, 3]]], 6), [[0, 1, 3]])
    check('explicit sequence 13', solve([[[[[0], [1], [2], [3], True], [[0], [], [], [], True]], False, [0, 1, 2, 3]]], 6), [[0, 1, 3]])
if N == 4:
    check('explicit sequence 0', solve([[[[[0], [1], [2], [3], False]], False, [0, 1, 2, 3]]], 7), [[]])
    check('explicit sequence 1', solve([[[[[], [0], [1], [], True]], False, [0, 1, 2, 3]]], 7), [[0, 1]])
    check('explicit sequence 2', solve([[[[[], [], [1], [], True]], False, [0, 1, 2, 3]]], 7), [[1]])
    check('explicit sequence 3', solve([[[[[0], [2], [3], [1], True], [[1], [2], [3], [0], True]], True, [0, 1, 2, 3]]], 7), [[0, 1]])
    check('explicit sequence 4', solve([[[[[0], [1], [2], [3], True], [[], [], [], [], False], [[1], [2], [3], [0], True]], False, [0, 1, 2, 3]]], 7), [[0, 1, 2, 3]])
    check('explicit sequence 5', solve([[[[[0], [], [1], [2], True], [[], [], [], [], False], [[], [], [], [], False], [[], [], [], [], False]], False, [0, 1, 2, 3]]], 7), [[0, 1]])
    check('explicit sequence 6', solve([[[[[0], [1], [2], [3], True]], False, [0, 1, 2, 3]]], 7), [[0, 1, 2]])
    check('explicit sequence 7', solve([[[[[0], [], [], [2], True], [[1], [], [], [3], True]], False, [0, 1, 2, 3]]], 7), [[0, 1, 2]])
    check('explicit sequence 8', solve([[[[[0], [], [], [2], True], [[], [], [], [], False]], True, [0, 1, 2, 3]]], 7), [[0]])
    check('explicit sequence 9', solve([[[[[0, 1], [2], [3], [], True]], False, [0]]], 7), [[0]])
    check('explicit sequence 10', solve([[[[[0, 1], [2], [3], [], True]], False, []]], 7), [[]])
    check('explicit sequence 11', solve([[[[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], [], [], True]], False, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]], 7), [[0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 12', solve([[[[[0], [], [], [], True], [[], [], [], [], False], [[1], [3], [], [], True]], False, [0, 1, 2, 3]]], 7), [[0, 1, 3]])
    check('explicit sequence 13', solve([[[[[0], [1], [2], [3], True], [[0], [], [], [], True]], False, [0, 1, 2, 3]]], 7), [[0, 1, 3]])
if N == 5:
    check('explicit sequence 0', solve([[[[[0], [1], [2], [3], False]], False, [0, 1, 2, 3]]], 8), [[]])
    check('explicit sequence 1', solve([[[[[], [0], [1], [], True]], False, [0, 1, 2, 3]]], 8), [[0, 1]])
    check('explicit sequence 2', solve([[[[[], [], [1], [], True]], False, [0, 1, 2, 3]]], 8), [[1]])
    check('explicit sequence 3', solve([[[[[0], [2], [3], [1], True], [[1], [2], [3], [0], True]], True, [0, 1, 2, 3]]], 8), [[0, 1]])
    check('explicit sequence 4', solve([[[[[0], [1], [2], [3], True], [[], [], [], [], False], [[1], [2], [3], [0], True]], False, [0, 1, 2, 3]]], 8), [[0, 1, 2, 3]])
    check('explicit sequence 5', solve([[[[[0], [], [1], [2], True], [[], [], [], [], False], [[], [], [], [], False], [[], [], [], [], False]], False, [0, 1, 2, 3]]], 8), [[0, 1]])
    check('explicit sequence 6', solve([[[[[0], [1], [2], [3], True]], False, [0, 1, 2, 3]]], 8), [[0, 1, 2]])
    check('explicit sequence 7', solve([[[[[0], [], [], [2], True], [[1], [], [], [3], True]], False, [0, 1, 2, 3]]], 8), [[0, 1, 2]])
    check('explicit sequence 8', solve([[[[[0], [], [], [2], True], [[], [], [], [], False]], True, [0, 1, 2, 3]]], 8), [[0]])
    check('explicit sequence 9', solve([[[[[0, 1], [2], [3], [], True]], False, [0]]], 8), [[0]])
    check('explicit sequence 10', solve([[[[[0, 1], [2], [3], [], True]], False, []]], 8), [[]])
    check('explicit sequence 11', solve([[[[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], [], [], True]], False, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]], 8), [[0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 12', solve([[[[[0], [], [], [], True], [[], [], [], [], False], [[1], [3], [], [], True]], False, [0, 1, 2, 3]]], 8), [[0, 1, 3]])
    check('explicit sequence 13', solve([[[[[0], [1], [2], [3], True], [[0], [], [], [], True]], False, [0, 1, 2, 3]]], 8), [[0, 1, 3]])
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:
Joins are added across inactive dash gaps.

Segments carry precomputed body, start-cap, end-cap and following-join sample sets plus an active flag. Active adjacent segments share a join and suppress interior caps. Inactive segments create dash gaps; each active component receives caps at its gap endpoints. A closed path connects the last and first segments. Empty bodies may still have cap coverage. Clip the complete union to the requested mask and target.

split: open-access


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

N = 1
observations = []
def solve(commands, size):
    full=set(range(size))
    out=[]
    for segments,closed,clip in commands:
        coverage=set()
        count=len(segments)
        for i,(body,start,end,join,active) in enumerate(segments):
            if not active: continue
            before=segments[i-1][4] if i>0 else (segments[-1][4] if closed and count else False)
            after=segments[i+1][4] if i+1<count else (segments[0][4] if closed and count else False)
            coverage.update(body)
            if not before: coverage.update(start)
            if not after: coverage.update(end)
            if after: coverage.update(join)
        out.append(sorted(coverage & full))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('explicit sequence 0', solve([[[[[0], [1], [2], [3], False]], False, [0, 1, 2, 3]]], 4), [[]])
    check('explicit sequence 1', solve([[[[[], [0], [1], [], True]], False, [0, 1, 2, 3]]], 4), [[0, 1]])
    check('explicit sequence 2', solve([[[[[], [], [1], [], True]], False, [0, 1, 2, 3]]], 4), [[1]])
    check('explicit sequence 3', solve([[[[[0], [2], [3], [1], True], [[1], [2], [3], [0], True]], True, [0, 1, 2, 3]]], 4), [[0, 1]])
    check('explicit sequence 4', solve([[[[[0], [1], [2], [3], True], [[], [], [], [], False], [[1], [2], [3], [0], True]], False, [0, 1, 2, 3]]], 4), [[0, 1, 2, 3]])
    check('explicit sequence 5', solve([[[[[0], [], [1], [2], True], [[], [], [], [], False], [[], [], [], [], False], [[], [], [], [], False]], False, [0, 1, 2, 3]]], 4), [[0, 1]])
    check('explicit sequence 6', solve([[[[[0], [1], [2], [3], True]], False, [0, 1, 2, 3]]], 4), [[0, 1, 2]])
    check('explicit sequence 7', solve([[[[[0], [], [], [2], True], [[1], [], [], [3], True]], False, [0, 1, 2, 3]]], 4), [[0, 1, 2]])
    check('explicit sequence 8', solve([[[[[0], [], [], [2], True], [[], [], [], [], False]], True, [0, 1, 2, 3]]], 4), [[0]])
    check('explicit sequence 9', solve([[[[[0, 1], [2], [3], [], True]], False, [0]]], 4), [[0]])
    check('explicit sequence 10', solve([[[[[0, 1], [2], [3], [], True]], False, []]], 4), [[]])
    check('explicit sequence 11', solve([[[[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], [], [], True]], False, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]], 4), [[0, 1, 2, 3]])
    check('explicit sequence 12', solve([[[[[0], [], [], [], True], [[], [], [], [], False], [[1], [3], [], [], True]], False, [0, 1, 2, 3]]], 4), [[0, 1, 3]])
    check('explicit sequence 13', solve([[[[[0], [1], [2], [3], True], [[0], [], [], [], True]], False, [0, 1, 2, 3]]], 4), [[0, 1, 3]])
if N == 2:
    check('explicit sequence 0', solve([[[[[0], [1], [2], [3], False]], False, [0, 1, 2, 3]]], 5), [[]])
    check('explicit sequence 1', solve([[[[[], [0], [1], [], True]], False, [0, 1, 2, 3]]], 5), [[0, 1]])
    check('explicit sequence 2', solve([[[[[], [], [1], [], True]], False, [0, 1, 2, 3]]], 5), [[1]])
    check('explicit sequence 3', solve([[[[[0], [2], [3], [1], True], [[1], [2], [3], [0], True]], True, [0, 1, 2, 3]]], 5), [[0, 1]])
    check('explicit sequence 4', solve([[[[[0], [1], [2], [3], True], [[], [], [], [], False], [[1], [2], [3], [0], True]], False, [0, 1, 2, 3]]], 5), [[0, 1, 2, 3]])
    check('explicit sequence 5', solve([[[[[0], [], [1], [2], True], [[], [], [], [], False], [[], [], [], [], False], [[], [], [], [], False]], False, [0, 1, 2, 3]]], 5), [[0, 1]])
    check('explicit sequence 6', solve([[[[[0], [1], [2], [3], True]], False, [0, 1, 2, 3]]], 5), [[0, 1, 2]])
    check('explicit sequence 7', solve([[[[[0], [], [], [2], True], [[1], [], [], [3], True]], False, [0, 1, 2, 3]]], 5), [[0, 1, 2]])
    check('explicit sequence 8', solve([[[[[0], [], [], [2], True], [[], [], [], [], False]], True, [0, 1, 2, 3]]], 5), [[0]])
    check('explicit sequence 9', solve([[[[[0, 1], [2], [3], [], True]], False, [0]]], 5), [[0]])
    check('explicit sequence 10', solve([[[[[0, 1], [2], [3], [], True]], False, []]], 5), [[]])
    check('explicit sequence 11', solve([[[[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], [], [], True]], False, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]], 5), [[0, 1, 2, 3, 4]])
    check('explicit sequence 12', solve([[[[[0], [], [], [], True], [[], [], [], [], False], [[1], [3], [], [], True]], False, [0, 1, 2, 3]]], 5), [[0, 1, 3]])
    check('explicit sequence 13', solve([[[[[0], [1], [2], [3], True], [[0], [], [], [], True]], False, [0, 1, 2, 3]]], 5), [[0, 1, 3]])
if N == 3:
    check('explicit sequence 0', solve([[[[[0], [1], [2], [3], False]], False, [0, 1, 2, 3]]], 6), [[]])
    check('explicit sequence 1', solve([[[[[], [0], [1], [], True]], False, [0, 1, 2, 3]]], 6), [[0, 1]])
    check('explicit sequence 2', solve([[[[[], [], [1], [], True]], False, [0, 1, 2, 3]]], 6), [[1]])
    check('explicit sequence 3', solve([[[[[0], [2], [3], [1], True], [[1], [2], [3], [0], True]], True, [0, 1, 2, 3]]], 6), [[0, 1]])
    check('explicit sequence 4', solve([[[[[0], [1], [2], [3], True], [[], [], [], [], False], [[1], [2], [3], [0], True]], False, [0, 1, 2, 3]]], 6), [[0, 1, 2, 3]])
    check('explicit sequence 5', solve([[[[[0], [], [1], [2], True], [[], [], [], [], False], [[], [], [], [], False], [[], [], [], [], False]], False, [0, 1, 2, 3]]], 6), [[0, 1]])
    check('explicit sequence 6', solve([[[[[0], [1], [2], [3], True]], False, [0, 1, 2, 3]]], 6), [[0, 1, 2]])
    check('explicit sequence 7', solve([[[[[0], [], [], [2], True], [[1], [], [], [3], True]], False, [0, 1, 2, 3]]], 6), [[0, 1, 2]])
    check('explicit sequence 8', solve([[[[[0], [], [], [2], True], [[], [], [], [], False]], True, [0, 1, 2, 3]]], 6), [[0]])
    check('explicit sequence 9', solve([[[[[0, 1], [2], [3], [], True]], False, [0]]], 6), [[0]])
    check('explicit sequence 10', solve([[[[[0, 1], [2], [3], [], True]], False, []]], 6), [[]])
    check('explicit sequence 11', solve([[[[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], [], [], True]], False, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]], 6), [[0, 1, 2, 3, 4, 5]])
    check('explicit sequence 12', solve([[[[[0], [], [], [], True], [[], [], [], [], False], [[1], [3], [], [], True]], False, [0, 1, 2, 3]]], 6), [[0, 1, 3]])
    check('explicit sequence 13', solve([[[[[0], [1], [2], [3], True], [[0], [], [], [], True]], False, [0, 1, 2, 3]]], 6), [[0, 1, 3]])
if N == 4:
    check('explicit sequence 0', solve([[[[[0], [1], [2], [3], False]], False, [0, 1, 2, 3]]], 7), [[]])
    check('explicit sequence 1', solve([[[[[], [0], [1], [], True]], False, [0, 1, 2, 3]]], 7), [[0, 1]])
    check('explicit sequence 2', solve([[[[[], [], [1], [], True]], False, [0, 1, 2, 3]]], 7), [[1]])
    check('explicit sequence 3', solve([[[[[0], [2], [3], [1], True], [[1], [2], [3], [0], True]], True, [0, 1, 2, 3]]], 7), [[0, 1]])
    check('explicit sequence 4', solve([[[[[0], [1], [2], [3], True], [[], [], [], [], False], [[1], [2], [3], [0], True]], False, [0, 1, 2, 3]]], 7), [[0, 1, 2, 3]])
    check('explicit sequence 5', solve([[[[[0], [], [1], [2], True], [[], [], [], [], False], [[], [], [], [], False], [[], [], [], [], False]], False, [0, 1, 2, 3]]], 7), [[0, 1]])
    check('explicit sequence 6', solve([[[[[0], [1], [2], [3], True]], False, [0, 1, 2, 3]]], 7), [[0, 1, 2]])
    check('explicit sequence 7', solve([[[[[0], [], [], [2], True], [[1], [], [], [3], True]], False, [0, 1, 2, 3]]], 7), [[0, 1, 2]])
    check('explicit sequence 8', solve([[[[[0], [], [], [2], True], [[], [], [], [], False]], True, [0, 1, 2, 3]]], 7), [[0]])
    check('explicit sequence 9', solve([[[[[0, 1], [2], [3], [], True]], False, [0]]], 7), [[0]])
    check('explicit sequence 10', solve([[[[[0, 1], [2], [3], [], True]], False, []]], 7), [[]])
    check('explicit sequence 11', solve([[[[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], [], [], True]], False, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]], 7), [[0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 12', solve([[[[[0], [], [], [], True], [[], [], [], [], False], [[1], [3], [], [], True]], False, [0, 1, 2, 3]]], 7), [[0, 1, 3]])
    check('explicit sequence 13', solve([[[[[0], [1], [2], [3], True], [[0], [], [], [], True]], False, [0, 1, 2, 3]]], 7), [[0, 1, 3]])
if N == 5:
    check('explicit sequence 0', solve([[[[[0], [1], [2], [3], False]], False, [0, 1, 2, 3]]], 8), [[]])
    check('explicit sequence 1', solve([[[[[], [0], [1], [], True]], False, [0, 1, 2, 3]]], 8), [[0, 1]])
    check('explicit sequence 2', solve([[[[[], [], [1], [], True]], False, [0, 1, 2, 3]]], 8), [[1]])
    check('explicit sequence 3', solve([[[[[0], [2], [3], [1], True], [[1], [2], [3], [0], True]], True, [0, 1, 2, 3]]], 8), [[0, 1]])
    check('explicit sequence 4', solve([[[[[0], [1], [2], [3], True], [[], [], [], [], False], [[1], [2], [3], [0], True]], False, [0, 1, 2, 3]]], 8), [[0, 1, 2, 3]])
    check('explicit sequence 5', solve([[[[[0], [], [1], [2], True], [[], [], [], [], False], [[], [], [], [], False], [[], [], [], [], False]], False, [0, 1, 2, 3]]], 8), [[0, 1]])
    check('explicit sequence 6', solve([[[[[0], [1], [2], [3], True]], False, [0, 1, 2, 3]]], 8), [[0, 1, 2]])
    check('explicit sequence 7', solve([[[[[0], [], [], [2], True], [[1], [], [], [3], True]], False, [0, 1, 2, 3]]], 8), [[0, 1, 2]])
    check('explicit sequence 8', solve([[[[[0], [], [], [2], True], [[], [], [], [], False]], True, [0, 1, 2, 3]]], 8), [[0]])
    check('explicit sequence 9', solve([[[[[0, 1], [2], [3], [], True]], False, [0]]], 8), [[0]])
    check('explicit sequence 10', solve([[[[[0, 1], [2], [3], [], True]], False, []]], 8), [[]])
    check('explicit sequence 11', solve([[[[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], [], [], True]], False, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]], 8), [[0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 12', solve([[[[[0], [], [], [], True], [[], [], [], [], False], [[1], [3], [], [], True]], False, [0, 1, 2, 3]]], 8), [[0, 1, 3]])
    check('explicit sequence 13', solve([[[[[0], [1], [2], [3], True], [[0], [], [], [], True]], False, [0, 1, 2, 3]]], 8), [[0, 1, 3]])
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(commands, size):
    full=set(range(size))
    out=[]
    for segments,closed,clip in commands:
        coverage=set()
        count=len(segments)
        for i,(body,start,end,join,active) in enumerate(segments):
            if not active: continue
            before=segments[i-1][4] if i>0 else (segments[-1][4] if closed and count else False)
            after=segments[i+1][4] if i+1<count else (segments[0][4] if closed and count else False)
            coverage.update(body)
            if not before: coverage.update(start)
            if not after: coverage.update(end)
            if after: coverage.update(join)
        out.append(sorted(coverage & set(clip) if clip else coverage & full))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('explicit sequence 0', solve([[[[[0], [1], [2], [3], False]], False, [0, 1, 2, 3]]], 4), [[]])
    check('explicit sequence 1', solve([[[[[], [0], [1], [], True]], False, [0, 1, 2, 3]]], 4), [[0, 1]])
    check('explicit sequence 2', solve([[[[[], [], [1], [], True]], False, [0, 1, 2, 3]]], 4), [[1]])
    check('explicit sequence 3', solve([[[[[0], [2], [3], [1], True], [[1], [2], [3], [0], True]], True, [0, 1, 2, 3]]], 4), [[0, 1]])
    check('explicit sequence 4', solve([[[[[0], [1], [2], [3], True], [[], [], [], [], False], [[1], [2], [3], [0], True]], False, [0, 1, 2, 3]]], 4), [[0, 1, 2, 3]])
    check('explicit sequence 5', solve([[[[[0], [], [1], [2], True], [[], [], [], [], False], [[], [], [], [], False], [[], [], [], [], False]], False, [0, 1, 2, 3]]], 4), [[0, 1]])
    check('explicit sequence 6', solve([[[[[0], [1], [2], [3], True]], False, [0, 1, 2, 3]]], 4), [[0, 1, 2]])
    check('explicit sequence 7', solve([[[[[0], [], [], [2], True], [[1], [], [], [3], True]], False, [0, 1, 2, 3]]], 4), [[0, 1, 2]])
    check('explicit sequence 8', solve([[[[[0], [], [], [2], True], [[], [], [], [], False]], True, [0, 1, 2, 3]]], 4), [[0]])
    check('explicit sequence 9', solve([[[[[0, 1], [2], [3], [], True]], False, [0]]], 4), [[0]])
    check('explicit sequence 10', solve([[[[[0, 1], [2], [3], [], True]], False, []]], 4), [[]])
    check('explicit sequence 11', solve([[[[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], [], [], True]], False, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]], 4), [[0, 1, 2, 3]])
    check('explicit sequence 12', solve([[[[[0], [], [], [], True], [[], [], [], [], False], [[1], [3], [], [], True]], False, [0, 1, 2, 3]]], 4), [[0, 1, 3]])
    check('explicit sequence 13', solve([[[[[0], [1], [2], [3], True], [[0], [], [], [], True]], False, [0, 1, 2, 3]]], 4), [[0, 1, 3]])
if N == 2:
    check('explicit sequence 0', solve([[[[[0], [1], [2], [3], False]], False, [0, 1, 2, 3]]], 5), [[]])
    check('explicit sequence 1', solve([[[[[], [0], [1], [], True]], False, [0, 1, 2, 3]]], 5), [[0, 1]])
    check('explicit sequence 2', solve([[[[[], [], [1], [], True]], False, [0, 1, 2, 3]]], 5), [[1]])
    check('explicit sequence 3', solve([[[[[0], [2], [3], [1], True], [[1], [2], [3], [0], True]], True, [0, 1, 2, 3]]], 5), [[0, 1]])
    check('explicit sequence 4', solve([[[[[0], [1], [2], [3], True], [[], [], [], [], False], [[1], [2], [3], [0], True]], False, [0, 1, 2, 3]]], 5), [[0, 1, 2, 3]])
    check('explicit sequence 5', solve([[[[[0], [], [1], [2], True], [[], [], [], [], False], [[], [], [], [], False], [[], [], [], [], False]], False, [0, 1, 2, 3]]], 5), [[0, 1]])
    check('explicit sequence 6', solve([[[[[0], [1], [2], [3], True]], False, [0, 1, 2, 3]]], 5), [[0, 1, 2]])
    check('explicit sequence 7', solve([[[[[0], [], [], [2], True], [[1], [], [], [3], True]], False, [0, 1, 2, 3]]], 5), [[0, 1, 2]])
    check('explicit sequence 8', solve([[[[[0], [], [], [2], True], [[], [], [], [], False]], True, [0, 1, 2, 3]]], 5), [[0]])
    check('explicit sequence 9', solve([[[[[0, 1], [2], [3], [], True]], False, [0]]], 5), [[0]])
    check('explicit sequence 10', solve([[[[[0, 1], [2], [3], [], True]], False, []]], 5), [[]])
    check('explicit sequence 11', solve([[[[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], [], [], True]], False, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]], 5), [[0, 1, 2, 3, 4]])
    check('explicit sequence 12', solve([[[[[0], [], [], [], True], [[], [], [], [], False], [[1], [3], [], [], True]], False, [0, 1, 2, 3]]], 5), [[0, 1, 3]])
    check('explicit sequence 13', solve([[[[[0], [1], [2], [3], True], [[0], [], [], [], True]], False, [0, 1, 2, 3]]], 5), [[0, 1, 3]])
if N == 3:
    check('explicit sequence 0', solve([[[[[0], [1], [2], [3], False]], False, [0, 1, 2, 3]]], 6), [[]])
    check('explicit sequence 1', solve([[[[[], [0], [1], [], True]], False, [0, 1, 2, 3]]], 6), [[0, 1]])
    check('explicit sequence 2', solve([[[[[], [], [1], [], True]], False, [0, 1, 2, 3]]], 6), [[1]])
    check('explicit sequence 3', solve([[[[[0], [2], [3], [1], True], [[1], [2], [3], [0], True]], True, [0, 1, 2, 3]]], 6), [[0, 1]])
    check('explicit sequence 4', solve([[[[[0], [1], [2], [3], True], [[], [], [], [], False], [[1], [2], [3], [0], True]], False, [0, 1, 2, 3]]], 6), [[0, 1, 2, 3]])
    check('explicit sequence 5', solve([[[[[0], [], [1], [2], True], [[], [], [], [], False], [[], [], [], [], False], [[], [], [], [], False]], False, [0, 1, 2, 3]]], 6), [[0, 1]])
    check('explicit sequence 6', solve([[[[[0], [1], [2], [3], True]], False, [0, 1, 2, 3]]], 6), [[0, 1, 2]])
    check('explicit sequence 7', solve([[[[[0], [], [], [2], True], [[1], [], [], [3], True]], False, [0, 1, 2, 3]]], 6), [[0, 1, 2]])
    check('explicit sequence 8', solve([[[[[0], [], [], [2], True], [[], [], [], [], False]], True, [0, 1, 2, 3]]], 6), [[0]])
    check('explicit sequence 9', solve([[[[[0, 1], [2], [3], [], True]], False, [0]]], 6), [[0]])
    check('explicit sequence 10', solve([[[[[0, 1], [2], [3], [], True]], False, []]], 6), [[]])
    check('explicit sequence 11', solve([[[[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], [], [], True]], False, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]], 6), [[0, 1, 2, 3, 4, 5]])
    check('explicit sequence 12', solve([[[[[0], [], [], [], True], [[], [], [], [], False], [[1], [3], [], [], True]], False, [0, 1, 2, 3]]], 6), [[0, 1, 3]])
    check('explicit sequence 13', solve([[[[[0], [1], [2], [3], True], [[0], [], [], [], True]], False, [0, 1, 2, 3]]], 6), [[0, 1, 3]])
if N == 4:
    check('explicit sequence 0', solve([[[[[0], [1], [2], [3], False]], False, [0, 1, 2, 3]]], 7), [[]])
    check('explicit sequence 1', solve([[[[[], [0], [1], [], True]], False, [0, 1, 2, 3]]], 7), [[0, 1]])
    check('explicit sequence 2', solve([[[[[], [], [1], [], True]], False, [0, 1, 2, 3]]], 7), [[1]])
    check('explicit sequence 3', solve([[[[[0], [2], [3], [1], True], [[1], [2], [3], [0], True]], True, [0, 1, 2, 3]]], 7), [[0, 1]])
    check('explicit sequence 4', solve([[[[[0], [1], [2], [3], True], [[], [], [], [], False], [[1], [2], [3], [0], True]], False, [0, 1, 2, 3]]], 7), [[0, 1, 2, 3]])
    check('explicit sequence 5', solve([[[[[0], [], [1], [2], True], [[], [], [], [], False], [[], [], [], [], False], [[], [], [], [], False]], False, [0, 1, 2, 3]]], 7), [[0, 1]])
    check('explicit sequence 6', solve([[[[[0], [1], [2], [3], True]], False, [0, 1, 2, 3]]], 7), [[0, 1, 2]])
    check('explicit sequence 7', solve([[[[[0], [], [], [2], True], [[1], [], [], [3], True]], False, [0, 1, 2, 3]]], 7), [[0, 1, 2]])
    check('explicit sequence 8', solve([[[[[0], [], [], [2], True], [[], [], [], [], False]], True, [0, 1, 2, 3]]], 7), [[0]])
    check('explicit sequence 9', solve([[[[[0, 1], [2], [3], [], True]], False, [0]]], 7), [[0]])
    check('explicit sequence 10', solve([[[[[0, 1], [2], [3], [], True]], False, []]], 7), [[]])
    check('explicit sequence 11', solve([[[[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], [], [], True]], False, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]], 7), [[0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 12', solve([[[[[0], [], [], [], True], [[], [], [], [], False], [[1], [3], [], [], True]], False, [0, 1, 2, 3]]], 7), [[0, 1, 3]])
    check('explicit sequence 13', solve([[[[[0], [1], [2], [3], True], [[0], [], [], [], True]], False, [0, 1, 2, 3]]], 7), [[0, 1, 3]])
if N == 5:
    check('explicit sequence 0', solve([[[[[0], [1], [2], [3], False]], False, [0, 1, 2, 3]]], 8), [[]])
    check('explicit sequence 1', solve([[[[[], [0], [1], [], True]], False, [0, 1, 2, 3]]], 8), [[0, 1]])
    check('explicit sequence 2', solve([[[[[], [], [1], [], True]], False, [0, 1, 2, 3]]], 8), [[1]])
    check('explicit sequence 3', solve([[[[[0], [2], [3], [1], True], [[1], [2], [3], [0], True]], True, [0, 1, 2, 3]]], 8), [[0, 1]])
    check('explicit sequence 4', solve([[[[[0], [1], [2], [3], True], [[], [], [], [], False], [[1], [2], [3], [0], True]], False, [0, 1, 2, 3]]], 8), [[0, 1, 2, 3]])
    check('explicit sequence 5', solve([[[[[0], [], [1], [2], True], [[], [], [], [], False], [[], [], [], [], False], [[], [], [], [], False]], False, [0, 1, 2, 3]]], 8), [[0, 1]])
    check('explicit sequence 6', solve([[[[[0], [1], [2], [3], True]], False, [0, 1, 2, 3]]], 8), [[0, 1, 2]])
    check('explicit sequence 7', solve([[[[[0], [], [], [2], True], [[1], [], [], [3], True]], False, [0, 1, 2, 3]]], 8), [[0, 1, 2]])
    check('explicit sequence 8', solve([[[[[0], [], [], [2], True], [[], [], [], [], False]], True, [0, 1, 2, 3]]], 8), [[0]])
    check('explicit sequence 9', solve([[[[[0, 1], [2], [3], [], True]], False, [0]]], 8), [[0]])
    check('explicit sequence 10', solve([[[[[0, 1], [2], [3], [], True]], False, []]], 8), [[]])
    check('explicit sequence 11', solve([[[[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], [], [], True]], False, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]], 8), [[0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 12', solve([[[[[0], [], [], [], True], [[], [], [], [], False], [[1], [3], [], [], True]], False, [0, 1, 2, 3]]], 8), [[0, 1, 3]])
    check('explicit sequence 13', solve([[[[[0], [1], [2], [3], True], [[0], [], [], [], True]], False, [0, 1, 2, 3]]], 8), [[0, 1, 3]])
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:
Stroke cap and join coverage bypasses the requested final clip mask.

Segments carry precomputed body, start-cap, end-cap and following-join sample sets plus an active flag. Active adjacent segments share a join and suppress interior caps. Inactive segments create dash gaps; each active component receives caps at its gap endpoints. A closed path connects the last and first segments. Empty bodies may still have cap coverage. Clip the complete union to the requested mask and target.

split: open-access


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

N = 1
observations = []
def solve(commands, size):
    full=set(range(size))
    out=[]
    for draws in commands:
        occluded=set()
        visible=[]
        for key,coverage,opaque,clip,writes in draws:
            effective=set(coverage)&set(clip)&set(writes)&full
            remaining=effective-occluded
            visible.append([key,sorted(remaining)])
            if opaque: occluded |= effective
        out.append(list(reversed(visible)))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('explicit sequence 0', solve([[['back', [0, 1], True, [0, 1], [0, 1]], ['front', [1], True, [1], [1]]]], 4), [[['back', [0]], ['front', [1]]]])
    check('explicit sequence 1', solve([[['back', [0, 1], True, [0, 1], [0, 1]], ['front', [0, 1], False, [0, 1], [0, 1]]]], 4), [[['back', [0, 1]], ['front', [0, 1]]]])
    check('explicit sequence 2', solve([[['back', [0, 1], True, [0, 1], [0, 1]], ['front', [0, 1], True, [0], [0, 1]]]], 4), [[['back', [1]], ['front', [0]]]])
    check('explicit sequence 3', solve([[['back', [0, 1], True, [0, 1], [0, 1]], ['front', [0, 1], True, [0, 1], [0]]]], 4), [[['back', [1]], ['front', [0]]]])
    check('explicit sequence 4', solve([[['back', [0], True, [0], [0]], ['front', [1], True, [1], [1]]]], 4), [[['back', [0]], ['front', [1]]]])
    check('explicit sequence 5', solve([[['back', [0, 1, 2], True, [0, 1, 2], [0, 1, 2]], ['middle', [0], True, [0], [0]], ['front', [1], True, [1], [1]]]], 4), [[['back', [2]], ['middle', [0]], ['front', [1]]]])
    check('explicit sequence 6', solve([[['z', [0], False, [0], [0]], ['a', [1], False, [1], [1]]]], 4), [[['z', [0]], ['a', [1]]]])
    check('explicit sequence 7', solve([[['a', [0], False, [], [0]], ['b', [1], True, [1], [1]]]], 4), [[['a', []], ['b', [1]]]])
    check('explicit sequence 8', solve([[['same', [0], False, [0], [0]], ['same', [1], False, [1], [1]]]], 4), [[['same', [0]], ['same', [1]]]])
    check('explicit sequence 9', solve([[['a', [0], True, [0], []]]], 4), [[['a', []]]])
    check('explicit sequence 10', solve([[['a', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], True, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]]], 4), [[['a', [0, 1, 2, 3]]]])
if N == 2:
    check('explicit sequence 0', solve([[['back', [0, 1], True, [0, 1], [0, 1]], ['front', [1], True, [1], [1]]]], 5), [[['back', [0]], ['front', [1]]]])
    check('explicit sequence 1', solve([[['back', [0, 1], True, [0, 1], [0, 1]], ['front', [0, 1], False, [0, 1], [0, 1]]]], 5), [[['back', [0, 1]], ['front', [0, 1]]]])
    check('explicit sequence 2', solve([[['back', [0, 1], True, [0, 1], [0, 1]], ['front', [0, 1], True, [0], [0, 1]]]], 5), [[['back', [1]], ['front', [0]]]])
    check('explicit sequence 3', solve([[['back', [0, 1], True, [0, 1], [0, 1]], ['front', [0, 1], True, [0, 1], [0]]]], 5), [[['back', [1]], ['front', [0]]]])
    check('explicit sequence 4', solve([[['back', [0], True, [0], [0]], ['front', [1], True, [1], [1]]]], 5), [[['back', [0]], ['front', [1]]]])
    check('explicit sequence 5', solve([[['back', [0, 1, 2], True, [0, 1, 2], [0, 1, 2]], ['middle', [0], True, [0], [0]], ['front', [1], True, [1], [1]]]], 5), [[['back', [2]], ['middle', [0]], ['front', [1]]]])
    check('explicit sequence 6', solve([[['z', [0], False, [0], [0]], ['a', [1], False, [1], [1]]]], 5), [[['z', [0]], ['a', [1]]]])
    check('explicit sequence 7', solve([[['a', [0], False, [], [0]], ['b', [1], True, [1], [1]]]], 5), [[['a', []], ['b', [1]]]])
    check('explicit sequence 8', solve([[['same', [0], False, [0], [0]], ['same', [1], False, [1], [1]]]], 5), [[['same', [0]], ['same', [1]]]])
    check('explicit sequence 9', solve([[['a', [0], True, [0], []]]], 5), [[['a', []]]])
    check('explicit sequence 10', solve([[['a', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], True, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]]], 5), [[['a', [0, 1, 2, 3, 4]]]])
if N == 3:
    check('explicit sequence 0', solve([[['back', [0, 1], True, [0, 1], [0, 1]], ['front', [1], True, [1], [1]]]], 6), [[['back', [0]], ['front', [1]]]])
    check('explicit sequence 1', solve([[['back', [0, 1], True, [0, 1], [0, 1]], ['front', [0, 1], False, [0, 1], [0, 1]]]], 6), [[['back', [0, 1]], ['front', [0, 1]]]])
    check('explicit sequence 2', solve([[['back', [0, 1], True, [0, 1], [0, 1]], ['front', [0, 1], True, [0], [0, 1]]]], 6), [[['back', [1]], ['front', [0]]]])
    check('explicit sequence 3', solve([[['back', [0, 1], True, [0, 1], [0, 1]], ['front', [0, 1], True, [0, 1], [0]]]], 6), [[['back', [1]], ['front', [0]]]])
    check('explicit sequence 4', solve([[['back', [0], True, [0], [0]], ['front', [1], True, [1], [1]]]], 6), [[['back', [0]], ['front', [1]]]])
    check('explicit sequence 5', solve([[['back', [0, 1, 2], True, [0, 1, 2], [0, 1, 2]], ['middle', [0], True, [0], [0]], ['front', [1], True, [1], [1]]]], 6), [[['back', [2]], ['middle', [0]], ['front', [1]]]])
    check('explicit sequence 6', solve([[['z', [0], False, [0], [0]], ['a', [1], False, [1], [1]]]], 6), [[['z', [0]], ['a', [1]]]])
    check('explicit sequence 7', solve([[['a', [0], False, [], [0]], ['b', [1], True, [1], [1]]]], 6), [[['a', []], ['b', [1]]]])
    check('explicit sequence 8', solve([[['same', [0], False, [0], [0]], ['same', [1], False, [1], [1]]]], 6), [[['same', [0]], ['same', [1]]]])
    check('explicit sequence 9', solve([[['a', [0], True, [0], []]]], 6), [[['a', []]]])
    check('explicit sequence 10', solve([[['a', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], True, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]]], 6), [[['a', [0, 1, 2, 3, 4, 5]]]])
if N == 4:
    check('explicit sequence 0', solve([[['back', [0, 1], True, [0, 1], [0, 1]], ['front', [1], True, [1], [1]]]], 7), [[['back', [0]], ['front', [1]]]])
    check('explicit sequence 1', solve([[['back', [0, 1], True, [0, 1], [0, 1]], ['front', [0, 1], False, [0, 1], [0, 1]]]], 7), [[['back', [0, 1]], ['front', [0, 1]]]])
    check('explicit sequence 2', solve([[['back', [0, 1], True, [0, 1], [0, 1]], ['front', [0, 1], True, [0], [0, 1]]]], 7), [[['back', [1]], ['front', [0]]]])
    check('explicit sequence 3', solve([[['back', [0, 1], True, [0, 1], [0, 1]], ['front', [0, 1], True, [0, 1], [0]]]], 7), [[['back', [1]], ['front', [0]]]])
    check('explicit sequence 4', solve([[['back', [0], True, [0], [0]], ['front', [1], True, [1], [1]]]], 7), [[['back', [0]], ['front', [1]]]])
    check('explicit sequence 5', solve([[['back', [0, 1, 2], True, [0, 1, 2], [0, 1, 2]], ['middle', [0], True, [0], [0]], ['front', [1], True, [1], [1]]]], 7), [[['back', [2]], ['middle', [0]], ['front', [1]]]])
    check('explicit sequence 6', solve([[['z', [0], False, [0], [0]], ['a', [1], False, [1], [1]]]], 7), [[['z', [0]], ['a', [1]]]])
    check('explicit sequence 7', solve([[['a', [0], False, [], [0]], ['b', [1], True, [1], [1]]]], 7), [[['a', []], ['b', [1]]]])
    check('explicit sequence 8', solve([[['same', [0], False, [0], [0]], ['same', [1], False, [1], [1]]]], 7), [[['same', [0]], ['same', [1]]]])
    check('explicit sequence 9', solve([[['a', [0], True, [0], []]]], 7), [[['a', []]]])
    check('explicit sequence 10', solve([[['a', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], True, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]]], 7), [[['a', [0, 1, 2, 3, 4, 5, 6]]]])
if N == 5:
    check('explicit sequence 0', solve([[['back', [0, 1], True, [0, 1], [0, 1]], ['front', [1], True, [1], [1]]]], 8), [[['back', [0]], ['front', [1]]]])
    check('explicit sequence 1', solve([[['back', [0, 1], True, [0, 1], [0, 1]], ['front', [0, 1], False, [0, 1], [0, 1]]]], 8), [[['back', [0, 1]], ['front', [0, 1]]]])
    check('explicit sequence 2', solve([[['back', [0, 1], True, [0, 1], [0, 1]], ['front', [0, 1], True, [0], [0, 1]]]], 8), [[['back', [1]], ['front', [0]]]])
    check('explicit sequence 3', solve([[['back', [0, 1], True, [0, 1], [0, 1]], ['front', [0, 1], True, [0, 1], [0]]]], 8), [[['back', [1]], ['front', [0]]]])
    check('explicit sequence 4', solve([[['back', [0], True, [0], [0]], ['front', [1], True, [1], [1]]]], 8), [[['back', [0]], ['front', [1]]]])
    check('explicit sequence 5', solve([[['back', [0, 1, 2], True, [0, 1, 2], [0, 1, 2]], ['middle', [0], True, [0], [0]], ['front', [1], True, [1], [1]]]], 8), [[['back', [2]], ['middle', [0]], ['front', [1]]]])
    check('explicit sequence 6', solve([[['z', [0], False, [0], [0]], ['a', [1], False, [1], [1]]]], 8), [[['z', [0]], ['a', [1]]]])
    check('explicit sequence 7', solve([[['a', [0], False, [], [0]], ['b', [1], True, [1], [1]]]], 8), [[['a', []], ['b', [1]]]])
    check('explicit sequence 8', solve([[['same', [0], False, [0], [0]], ['same', [1], False, [1], [1]]]], 8), [[['same', [0]], ['same', [1]]]])
    check('explicit sequence 9', solve([[['a', [0], True, [0], []]]], 8), [[['a', []]]])
    check('explicit sequence 10', solve([[['a', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], True, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]]], 8), [[['a', [0, 1, 2, 3, 4, 5, 6, 7]]]])
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(commands, size):
    full=set(range(size))
    out=[]
    for draws in commands:
        occluded=set()
        visible=[]
        for key,coverage,opaque,clip,writes in sorted(draws,key=lambda d:d[0],reverse=True):
            effective=set(coverage)&set(clip)&set(writes)&full
            remaining=effective-occluded
            visible.append([key,sorted(remaining)])
            if opaque: occluded |= effective
        out.append(list(reversed(visible)))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('explicit sequence 0', solve([[['back', [0, 1], True, [0, 1], [0, 1]], ['front', [1], True, [1], [1]]]], 4), [[['back', [0]], ['front', [1]]]])
    check('explicit sequence 1', solve([[['back', [0, 1], True, [0, 1], [0, 1]], ['front', [0, 1], False, [0, 1], [0, 1]]]], 4), [[['back', [0, 1]], ['front', [0, 1]]]])
    check('explicit sequence 2', solve([[['back', [0, 1], True, [0, 1], [0, 1]], ['front', [0, 1], True, [0], [0, 1]]]], 4), [[['back', [1]], ['front', [0]]]])
    check('explicit sequence 3', solve([[['back', [0, 1], True, [0, 1], [0, 1]], ['front', [0, 1], True, [0, 1], [0]]]], 4), [[['back', [1]], ['front', [0]]]])
    check('explicit sequence 4', solve([[['back', [0], True, [0], [0]], ['front', [1], True, [1], [1]]]], 4), [[['back', [0]], ['front', [1]]]])
    check('explicit sequence 5', solve([[['back', [0, 1, 2], True, [0, 1, 2], [0, 1, 2]], ['middle', [0], True, [0], [0]], ['front', [1], True, [1], [1]]]], 4), [[['back', [2]], ['middle', [0]], ['front', [1]]]])
    check('explicit sequence 6', solve([[['z', [0], False, [0], [0]], ['a', [1], False, [1], [1]]]], 4), [[['z', [0]], ['a', [1]]]])
    check('explicit sequence 7', solve([[['a', [0], False, [], [0]], ['b', [1], True, [1], [1]]]], 4), [[['a', []], ['b', [1]]]])
    check('explicit sequence 8', solve([[['same', [0], False, [0], [0]], ['same', [1], False, [1], [1]]]], 4), [[['same', [0]], ['same', [1]]]])
    check('explicit sequence 9', solve([[['a', [0], True, [0], []]]], 4), [[['a', []]]])
    check('explicit sequence 10', solve([[['a', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], True, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]]], 4), [[['a', [0, 1, 2, 3]]]])
if N == 2:
    check('explicit sequence 0', solve([[['back', [0, 1], True, [0, 1], [0, 1]], ['front', [1], True, [1], [1]]]], 5), [[['back', [0]], ['front', [1]]]])
    check('explicit sequence 1', solve([[['back', [0, 1], True, [0, 1], [0, 1]], ['front', [0, 1], False, [0, 1], [0, 1]]]], 5), [[['back', [0, 1]], ['front', [0, 1]]]])
    check('explicit sequence 2', solve([[['back', [0, 1], True, [0, 1], [0, 1]], ['front', [0, 1], True, [0], [0, 1]]]], 5), [[['back', [1]], ['front', [0]]]])
    check('explicit sequence 3', solve([[['back', [0, 1], True, [0, 1], [0, 1]], ['front', [0, 1], True, [0, 1], [0]]]], 5), [[['back', [1]], ['front', [0]]]])
    check('explicit sequence 4', solve([[['back', [0], True, [0], [0]], ['front', [1], True, [1], [1]]]], 5), [[['back', [0]], ['front', [1]]]])
    check('explicit sequence 5', solve([[['back', [0, 1, 2], True, [0, 1, 2], [0, 1, 2]], ['middle', [0], True, [0], [0]], ['front', [1], True, [1], [1]]]], 5), [[['back', [2]], ['middle', [0]], ['front', [1]]]])
    check('explicit sequence 6', solve([[['z', [0], False, [0], [0]], ['a', [1], False, [1], [1]]]], 5), [[['z', [0]], ['a', [1]]]])
    check('explicit sequence 7', solve([[['a', [0], False, [], [0]], ['b', [1], True, [1], [1]]]], 5), [[['a', []], ['b', [1]]]])
    check('explicit sequence 8', solve([[['same', [0], False, [0], [0]], ['same', [1], False, [1], [1]]]], 5), [[['same', [0]], ['same', [1]]]])
    check('explicit sequence 9', solve([[['a', [0], True, [0], []]]], 5), [[['a', []]]])
    check('explicit sequence 10', solve([[['a', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], True, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]]], 5), [[['a', [0, 1, 2, 3, 4]]]])
if N == 3:
    check('explicit sequence 0', solve([[['back', [0, 1], True, [0, 1], [0, 1]], ['front', [1], True, [1], [1]]]], 6), [[['back', [0]], ['front', [1]]]])
    check('explicit sequence 1', solve([[['back', [0, 1], True, [0, 1], [0, 1]], ['front', [0, 1], False, [0, 1], [0, 1]]]], 6), [[['back', [0, 1]], ['front', [0, 1]]]])
    check('explicit sequence 2', solve([[['back', [0, 1], True, [0, 1], [0, 1]], ['front', [0, 1], True, [0], [0, 1]]]], 6), [[['back', [1]], ['front', [0]]]])
    check('explicit sequence 3', solve([[['back', [0, 1], True, [0, 1], [0, 1]], ['front', [0, 1], True, [0, 1], [0]]]], 6), [[['back', [1]], ['front', [0]]]])
    check('explicit sequence 4', solve([[['back', [0], True, [0], [0]], ['front', [1], True, [1], [1]]]], 6), [[['back', [0]], ['front', [1]]]])
    check('explicit sequence 5', solve([[['back', [0, 1, 2], True, [0, 1, 2], [0, 1, 2]], ['middle', [0], True, [0], [0]], ['front', [1], True, [1], [1]]]], 6), [[['back', [2]], ['middle', [0]], ['front', [1]]]])
    check('explicit sequence 6', solve([[['z', [0], False, [0], [0]], ['a', [1], False, [1], [1]]]], 6), [[['z', [0]], ['a', [1]]]])
    check('explicit sequence 7', solve([[['a', [0], False, [], [0]], ['b', [1], True, [1], [1]]]], 6), [[['a', []], ['b', [1]]]])
    check('explicit sequence 8', solve([[['same', [0], False, [0], [0]], ['same', [1], False, [1], [1]]]], 6), [[['same', [0]], ['same', [1]]]])
    check('explicit sequence 9', solve([[['a', [0], True, [0], []]]], 6), [[['a', []]]])
    check('explicit sequence 10', solve([[['a', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], True, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]]], 6), [[['a', [0, 1, 2, 3, 4, 5]]]])
if N == 4:
    check('explicit sequence 0', solve([[['back', [0, 1], True, [0, 1], [0, 1]], ['front', [1], True, [1], [1]]]], 7), [[['back', [0]], ['front', [1]]]])
    check('explicit sequence 1', solve([[['back', [0, 1], True, [0, 1], [0, 1]], ['front', [0, 1], False, [0, 1], [0, 1]]]], 7), [[['back', [0, 1]], ['front', [0, 1]]]])
    check('explicit sequence 2', solve([[['back', [0, 1], True, [0, 1], [0, 1]], ['front', [0, 1], True, [0], [0, 1]]]], 7), [[['back', [1]], ['front', [0]]]])
    check('explicit sequence 3', solve([[['back', [0, 1], True, [0, 1], [0, 1]], ['front', [0, 1], True, [0, 1], [0]]]], 7), [[['back', [1]], ['front', [0]]]])
    check('explicit sequence 4', solve([[['back', [0], True, [0], [0]], ['front', [1], True, [1], [1]]]], 7), [[['back', [0]], ['front', [1]]]])
    check('explicit sequence 5', solve([[['back', [0, 1, 2], True, [0, 1, 2], [0, 1, 2]], ['middle', [0], True, [0], [0]], ['front', [1], True, [1], [1]]]], 7), [[['back', [2]], ['middle', [0]], ['front', [1]]]])
    check('explicit sequence 6', solve([[['z', [0], False, [0], [0]], ['a', [1], False, [1], [1]]]], 7), [[['z', [0]], ['a', [1]]]])
    check('explicit sequence 7', solve([[['a', [0], False, [], [0]], ['b', [1], True, [1], [1]]]], 7), [[['a', []], ['b', [1]]]])
    check('explicit sequence 8', solve([[['same', [0], False, [0], [0]], ['same', [1], False, [1], [1]]]], 7), [[['same', [0]], ['same', [1]]]])
    check('explicit sequence 9', solve([[['a', [0], True, [0], []]]], 7), [[['a', []]]])
    check('explicit sequence 10', solve([[['a', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], True, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]]], 7), [[['a', [0, 1, 2, 3, 4, 5, 6]]]])
if N == 5:
    check('explicit sequence 0', solve([[['back', [0, 1], True, [0, 1], [0, 1]], ['front', [1], True, [1], [1]]]], 8), [[['back', [0]], ['front', [1]]]])
    check('explicit sequence 1', solve([[['back', [0, 1], True, [0, 1], [0, 1]], ['front', [0, 1], False, [0, 1], [0, 1]]]], 8), [[['back', [0, 1]], ['front', [0, 1]]]])
    check('explicit sequence 2', solve([[['back', [0, 1], True, [0, 1], [0, 1]], ['front', [0, 1], True, [0], [0, 1]]]], 8), [[['back', [1]], ['front', [0]]]])
    check('explicit sequence 3', solve([[['back', [0, 1], True, [0, 1], [0, 1]], ['front', [0, 1], True, [0, 1], [0]]]], 8), [[['back', [1]], ['front', [0]]]])
    check('explicit sequence 4', solve([[['back', [0], True, [0], [0]], ['front', [1], True, [1], [1]]]], 8), [[['back', [0]], ['front', [1]]]])
    check('explicit sequence 5', solve([[['back', [0, 1, 2], True, [0, 1, 2], [0, 1, 2]], ['middle', [0], True, [0], [0]], ['front', [1], True, [1], [1]]]], 8), [[['back', [2]], ['middle', [0]], ['front', [1]]]])
    check('explicit sequence 6', solve([[['z', [0], False, [0], [0]], ['a', [1], False, [1], [1]]]], 8), [[['z', [0]], ['a', [1]]]])
    check('explicit sequence 7', solve([[['a', [0], False, [], [0]], ['b', [1], True, [1], [1]]]], 8), [[['a', []], ['b', [1]]]])
    check('explicit sequence 8', solve([[['same', [0], False, [0], [0]], ['same', [1], False, [1], [1]]]], 8), [[['same', [0]], ['same', [1]]]])
    check('explicit sequence 9', solve([[['a', [0], True, [0], []]]], 8), [[['a', []]]])
    check('explicit sequence 10', solve([[['a', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], True, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]]], 8), [[['a', [0, 1, 2, 3, 4, 5, 6, 7]]]])
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:
Occlusion accumulates back to front and hides foreground samples behind background draws.

Draws are supplied back to front as ID, coverage set, opaque flag, clip set and sample-write-enable set. Visibility traverses front to back, subtracting only front opaque written samples. Transparent draws remain visible but do not occlude. Return every draw in original order, including empty visibility, labeled by ID. Repeated IDs are distinct draws. All coverage is finite-target bounded.

split: open-access