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

N = 1
observations = []
def solve(commands, size):
    full=set(range(size))
    clip=set(full)
    enabled=True
    stack=[]
    out=[]
    for cmd in commands:
        op=cmd[0]
        mask=set(cmd[1]) & full if len(cmd)>1 else set()
        if op=='save': stack.append((set(clip),enabled))
        elif op=='restore':
            if stack: clip,enabled=stack.pop()
        elif op=='intersect': clip &= mask
        elif op=='exclude': clip = full-mask
        elif op=='union': clip |= mask
        elif op=='replace': clip=set(mask)
        elif op=='invert': clip=full-clip
        elif op=='reset': clip=set(full)
        elif op=='disable': enabled=False
        elif op=='enable': enabled=True
        elif op=='draw': out.append(sorted(clip if enabled else 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([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 4), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 4), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 4), [[0, 1, 2, 3]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 4), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 4), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 4), [[2], [0, 1, 3], [0, 1, 2, 3]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 4), [[0, 1, 2, 3]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 4), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 4), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 4), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 4), [[]])
if N == 2:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 5), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 5), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 5), [[0, 1, 2, 3, 4]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 5), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 5), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 5), [[2], [0, 1, 3, 4], [0, 1, 2, 3, 4]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 5), [[0, 1, 2, 3, 4]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 5), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 5), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 5), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 5), [[]])
if N == 3:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 6), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 6), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 6), [[0, 1, 2, 3, 4, 5]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 6), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 6), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 6), [[2], [0, 1, 3, 4, 5], [0, 1, 2, 3, 4, 5]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 6), [[0, 1, 2, 3, 4, 5]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 6), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 6), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 6), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 6), [[]])
if N == 4:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 7), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 7), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 7), [[0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 7), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 7), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 7), [[2], [0, 1, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 7), [[0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 7), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 7), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 7), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 7), [[]])
if N == 5:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 8), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 8), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 8), [[0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 8), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 8), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 8), [[2], [0, 1, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 8), [[0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 8), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 8), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 8), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 8), [[]])
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))
    clip=set(full)
    enabled=True
    stack=[]
    out=[]
    for cmd in commands:
        op=cmd[0]
        mask=set(cmd[1]) & full if len(cmd)>1 else set()
        if op=='save': stack.append((set(clip),enabled))
        elif op=='restore':
            if stack: clip,enabled=stack.pop()
        elif op=='intersect': clip &= mask
        elif op=='exclude': clip = full-mask if mask else clip
        elif op=='union': clip |= mask
        elif op=='replace': clip=set(mask)
        elif op=='invert': clip=full-clip
        elif op=='reset': clip=set(full)
        elif op=='disable': enabled=False
        elif op=='enable': enabled=True
        elif op=='draw': out.append(sorted(clip if enabled else 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([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 4), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 4), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 4), [[0, 1, 2, 3]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 4), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 4), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 4), [[2], [0, 1, 3], [0, 1, 2, 3]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 4), [[0, 1, 2, 3]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 4), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 4), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 4), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 4), [[]])
if N == 2:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 5), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 5), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 5), [[0, 1, 2, 3, 4]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 5), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 5), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 5), [[2], [0, 1, 3, 4], [0, 1, 2, 3, 4]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 5), [[0, 1, 2, 3, 4]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 5), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 5), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 5), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 5), [[]])
if N == 3:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 6), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 6), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 6), [[0, 1, 2, 3, 4, 5]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 6), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 6), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 6), [[2], [0, 1, 3, 4, 5], [0, 1, 2, 3, 4, 5]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 6), [[0, 1, 2, 3, 4, 5]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 6), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 6), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 6), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 6), [[]])
if N == 4:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 7), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 7), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 7), [[0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 7), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 7), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 7), [[2], [0, 1, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 7), [[0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 7), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 7), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 7), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 7), [[]])
if N == 5:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 8), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 8), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 8), [[0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 8), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 8), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 8), [[2], [0, 1, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 8), [[0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 8), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 8), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 8), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 8), [[]])
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:
Subtracting a mask resets prior clip intersections and reintroduces excluded samples.

Commands act on finite sample indices [0,size). Save/restore includes the clip-enable bit; region edits update stored coverage even while clipping is disabled. Restore underflow is inert. Draw emits sorted effective samples.

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))
    clip=set(full)
    enabled=True
    stack=[]
    out=[]
    for cmd in commands:
        op=cmd[0]
        mask=set(cmd[1]) & full if len(cmd)>1 else set()
        if op=='save': stack.append((set(clip),enabled))
        elif op=='restore':
            if stack: clip,enabled=stack.pop()
        elif op=='intersect': clip &= mask
        elif op=='exclude': clip -= mask
        elif op=='union': clip ^= mask
        elif op=='replace': clip=set(mask)
        elif op=='invert': clip=full-clip
        elif op=='reset': clip=set(full)
        elif op=='disable': enabled=False
        elif op=='enable': enabled=True
        elif op=='draw': out.append(sorted(clip if enabled else 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([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 4), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 4), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 4), [[0, 1, 2, 3]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 4), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 4), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 4), [[2], [0, 1, 3], [0, 1, 2, 3]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 4), [[0, 1, 2, 3]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 4), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 4), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 4), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 4), [[]])
if N == 2:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 5), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 5), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 5), [[0, 1, 2, 3, 4]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 5), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 5), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 5), [[2], [0, 1, 3, 4], [0, 1, 2, 3, 4]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 5), [[0, 1, 2, 3, 4]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 5), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 5), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 5), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 5), [[]])
if N == 3:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 6), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 6), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 6), [[0, 1, 2, 3, 4, 5]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 6), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 6), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 6), [[2], [0, 1, 3, 4, 5], [0, 1, 2, 3, 4, 5]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 6), [[0, 1, 2, 3, 4, 5]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 6), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 6), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 6), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 6), [[]])
if N == 4:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 7), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 7), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 7), [[0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 7), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 7), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 7), [[2], [0, 1, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 7), [[0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 7), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 7), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 7), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 7), [[]])
if N == 5:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 8), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 8), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 8), [[0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 8), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 8), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 8), [[2], [0, 1, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 8), [[0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 8), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 8), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 8), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 8), [[]])
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))
    clip=set(full)
    enabled=True
    stack=[]
    out=[]
    for cmd in commands:
        op=cmd[0]
        mask=set(cmd[1]) & full if len(cmd)>1 else set()
        if op=='save': stack.append((set(clip),enabled))
        elif op=='restore':
            if stack: clip,enabled=stack.pop()
        elif op=='intersect': clip &= mask
        elif op=='exclude': clip -= mask
        elif op=='union': clip = mask if not clip else clip ^ mask
        elif op=='replace': clip=set(mask)
        elif op=='invert': clip=full-clip
        elif op=='reset': clip=set(full)
        elif op=='disable': enabled=False
        elif op=='enable': enabled=True
        elif op=='draw': out.append(sorted(clip if enabled else 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([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 4), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 4), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 4), [[0, 1, 2, 3]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 4), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 4), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 4), [[2], [0, 1, 3], [0, 1, 2, 3]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 4), [[0, 1, 2, 3]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 4), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 4), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 4), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 4), [[]])
if N == 2:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 5), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 5), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 5), [[0, 1, 2, 3, 4]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 5), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 5), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 5), [[2], [0, 1, 3, 4], [0, 1, 2, 3, 4]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 5), [[0, 1, 2, 3, 4]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 5), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 5), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 5), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 5), [[]])
if N == 3:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 6), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 6), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 6), [[0, 1, 2, 3, 4, 5]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 6), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 6), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 6), [[2], [0, 1, 3, 4, 5], [0, 1, 2, 3, 4, 5]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 6), [[0, 1, 2, 3, 4, 5]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 6), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 6), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 6), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 6), [[]])
if N == 4:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 7), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 7), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 7), [[0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 7), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 7), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 7), [[2], [0, 1, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 7), [[0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 7), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 7), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 7), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 7), [[]])
if N == 5:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 8), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 8), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 8), [[0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 8), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 8), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 8), [[2], [0, 1, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 8), [[0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 8), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 8), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 8), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 8), [[]])
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:
Union toggles samples already covered by the clip.

Commands act on finite sample indices [0,size). Save/restore includes the clip-enable bit; region edits update stored coverage even while clipping is disabled. Restore underflow is inert. Draw emits sorted effective samples.

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))
    clip=set(full)
    enabled=True
    stack=[]
    out=[]
    for cmd in commands:
        op=cmd[0]
        mask=set(cmd[1]) & full if len(cmd)>1 else set()
        if op=='save': stack.append((set(clip),enabled))
        elif op=='restore':
            if stack: clip,enabled=stack.pop()
        elif op=='intersect': clip &= mask
        elif op=='exclude': clip -= mask
        elif op=='union': clip |= mask
        elif op=='replace': clip |= mask
        elif op=='invert': clip=full-clip
        elif op=='reset': clip=set(full)
        elif op=='disable': enabled=False
        elif op=='enable': enabled=True
        elif op=='draw': out.append(sorted(clip if enabled else 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([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 4), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 4), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 4), [[0, 1, 2, 3]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 4), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 4), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 4), [[2], [0, 1, 3], [0, 1, 2, 3]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 4), [[0, 1, 2, 3]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 4), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 4), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 4), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 4), [[]])
if N == 2:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 5), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 5), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 5), [[0, 1, 2, 3, 4]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 5), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 5), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 5), [[2], [0, 1, 3, 4], [0, 1, 2, 3, 4]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 5), [[0, 1, 2, 3, 4]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 5), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 5), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 5), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 5), [[]])
if N == 3:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 6), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 6), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 6), [[0, 1, 2, 3, 4, 5]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 6), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 6), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 6), [[2], [0, 1, 3, 4, 5], [0, 1, 2, 3, 4, 5]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 6), [[0, 1, 2, 3, 4, 5]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 6), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 6), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 6), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 6), [[]])
if N == 4:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 7), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 7), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 7), [[0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 7), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 7), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 7), [[2], [0, 1, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 7), [[0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 7), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 7), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 7), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 7), [[]])
if N == 5:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 8), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 8), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 8), [[0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 8), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 8), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 8), [[2], [0, 1, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 8), [[0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 8), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 8), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 8), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 8), [[]])
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))
    clip=set(full)
    enabled=True
    stack=[]
    out=[]
    for cmd in commands:
        op=cmd[0]
        mask=set(cmd[1]) & full if len(cmd)>1 else set()
        if op=='save': stack.append((set(clip),enabled))
        elif op=='restore':
            if stack: clip,enabled=stack.pop()
        elif op=='intersect': clip &= mask
        elif op=='exclude': clip -= mask
        elif op=='union': clip |= mask
        elif op=='replace': clip = set(mask) if not mask else clip | mask
        elif op=='invert': clip=full-clip
        elif op=='reset': clip=set(full)
        elif op=='disable': enabled=False
        elif op=='enable': enabled=True
        elif op=='draw': out.append(sorted(clip if enabled else 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([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 4), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 4), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 4), [[0, 1, 2, 3]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 4), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 4), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 4), [[2], [0, 1, 3], [0, 1, 2, 3]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 4), [[0, 1, 2, 3]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 4), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 4), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 4), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 4), [[]])
if N == 2:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 5), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 5), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 5), [[0, 1, 2, 3, 4]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 5), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 5), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 5), [[2], [0, 1, 3, 4], [0, 1, 2, 3, 4]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 5), [[0, 1, 2, 3, 4]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 5), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 5), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 5), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 5), [[]])
if N == 3:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 6), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 6), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 6), [[0, 1, 2, 3, 4, 5]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 6), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 6), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 6), [[2], [0, 1, 3, 4, 5], [0, 1, 2, 3, 4, 5]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 6), [[0, 1, 2, 3, 4, 5]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 6), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 6), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 6), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 6), [[]])
if N == 4:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 7), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 7), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 7), [[0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 7), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 7), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 7), [[2], [0, 1, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 7), [[0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 7), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 7), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 7), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 7), [[]])
if N == 5:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 8), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 8), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 8), [[0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 8), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 8), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 8), [[2], [0, 1, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 8), [[0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 8), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 8), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 8), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 8), [[]])
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:
Replacing a clip accumulates old coverage.

Commands act on finite sample indices [0,size). Save/restore includes the clip-enable bit; region edits update stored coverage even while clipping is disabled. Restore underflow is inert. Draw emits sorted effective samples.

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))
    clip=set(full)
    enabled=True
    stack=[]
    out=[]
    for cmd in commands:
        op=cmd[0]
        mask=set(cmd[1]) & full if len(cmd)>1 else set()
        if op=='save': stack.append((set(clip),enabled))
        elif op=='restore':
            if stack: clip,enabled=stack.pop()
        elif op=='intersect': clip &= mask
        elif op=='exclude': clip -= mask
        elif op=='union': clip |= mask
        elif op=='replace': clip=set(mask)
        elif op=='invert': clip=mask-clip
        elif op=='reset': clip=set(full)
        elif op=='disable': enabled=False
        elif op=='enable': enabled=True
        elif op=='draw': out.append(sorted(clip if enabled else 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([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 4), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 4), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 4), [[0, 1, 2, 3]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 4), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 4), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 4), [[2], [0, 1, 3], [0, 1, 2, 3]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 4), [[0, 1, 2, 3]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 4), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 4), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 4), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 4), [[]])
if N == 2:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 5), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 5), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 5), [[0, 1, 2, 3, 4]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 5), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 5), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 5), [[2], [0, 1, 3, 4], [0, 1, 2, 3, 4]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 5), [[0, 1, 2, 3, 4]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 5), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 5), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 5), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 5), [[]])
if N == 3:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 6), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 6), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 6), [[0, 1, 2, 3, 4, 5]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 6), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 6), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 6), [[2], [0, 1, 3, 4, 5], [0, 1, 2, 3, 4, 5]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 6), [[0, 1, 2, 3, 4, 5]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 6), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 6), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 6), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 6), [[]])
if N == 4:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 7), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 7), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 7), [[0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 7), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 7), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 7), [[2], [0, 1, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 7), [[0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 7), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 7), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 7), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 7), [[]])
if N == 5:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 8), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 8), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 8), [[0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 8), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 8), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 8), [[2], [0, 1, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 8), [[0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 8), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 8), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 8), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 8), [[]])
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))
    clip=set(full)
    enabled=True
    stack=[]
    out=[]
    for cmd in commands:
        op=cmd[0]
        mask=set(cmd[1]) & full if len(cmd)>1 else set()
        if op=='save': stack.append((set(clip),enabled))
        elif op=='restore':
            if stack: clip,enabled=stack.pop()
        elif op=='intersect': clip &= mask
        elif op=='exclude': clip -= mask
        elif op=='union': clip |= mask
        elif op=='replace': clip=set(mask)
        elif op=='invert': clip=full if not clip else set()
        elif op=='reset': clip=set(full)
        elif op=='disable': enabled=False
        elif op=='enable': enabled=True
        elif op=='draw': out.append(sorted(clip if enabled else 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([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 4), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 4), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 4), [[0, 1, 2, 3]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 4), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 4), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 4), [[2], [0, 1, 3], [0, 1, 2, 3]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 4), [[0, 1, 2, 3]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 4), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 4), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 4), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 4), [[]])
if N == 2:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 5), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 5), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 5), [[0, 1, 2, 3, 4]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 5), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 5), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 5), [[2], [0, 1, 3, 4], [0, 1, 2, 3, 4]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 5), [[0, 1, 2, 3, 4]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 5), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 5), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 5), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 5), [[]])
if N == 3:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 6), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 6), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 6), [[0, 1, 2, 3, 4, 5]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 6), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 6), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 6), [[2], [0, 1, 3, 4, 5], [0, 1, 2, 3, 4, 5]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 6), [[0, 1, 2, 3, 4, 5]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 6), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 6), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 6), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 6), [[]])
if N == 4:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 7), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 7), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 7), [[0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 7), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 7), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 7), [[2], [0, 1, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 7), [[0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 7), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 7), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 7), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 7), [[]])
if N == 5:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 8), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 8), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 8), [[0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 8), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 8), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 8), [[2], [0, 1, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 8), [[0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 8), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 8), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 8), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 8), [[]])
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:
Clip inversion uses the absent command mask instead of the finite target universe.

Commands act on finite sample indices [0,size). Save/restore includes the clip-enable bit; region edits update stored coverage even while clipping is disabled. Restore underflow is inert. Draw emits sorted effective samples.

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))
    clip=set(full)
    enabled=True
    stack=[]
    out=[]
    for cmd in commands:
        op=cmd[0]
        mask=set(cmd[1]) & full if len(cmd)>1 else set()
        if op=='save': stack.append((set(clip),enabled))
        elif op=='restore':
            if stack: clip,enabled=stack.pop()
        elif op=='intersect': clip &= mask
        elif op=='exclude': clip -= mask
        elif op=='union': clip |= mask
        elif op=='replace': clip=set(mask)
        elif op=='invert': clip=full-clip
        elif op=='reset': clip=set()
        elif op=='disable': enabled=False
        elif op=='enable': enabled=True
        elif op=='draw': out.append(sorted(clip if enabled else 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([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 4), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 4), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 4), [[0, 1, 2, 3]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 4), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 4), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 4), [[2], [0, 1, 3], [0, 1, 2, 3]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 4), [[0, 1, 2, 3]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 4), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 4), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 4), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 4), [[]])
if N == 2:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 5), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 5), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 5), [[0, 1, 2, 3, 4]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 5), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 5), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 5), [[2], [0, 1, 3, 4], [0, 1, 2, 3, 4]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 5), [[0, 1, 2, 3, 4]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 5), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 5), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 5), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 5), [[]])
if N == 3:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 6), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 6), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 6), [[0, 1, 2, 3, 4, 5]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 6), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 6), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 6), [[2], [0, 1, 3, 4, 5], [0, 1, 2, 3, 4, 5]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 6), [[0, 1, 2, 3, 4, 5]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 6), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 6), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 6), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 6), [[]])
if N == 4:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 7), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 7), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 7), [[0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 7), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 7), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 7), [[2], [0, 1, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 7), [[0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 7), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 7), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 7), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 7), [[]])
if N == 5:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 8), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 8), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 8), [[0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 8), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 8), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 8), [[2], [0, 1, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 8), [[0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 8), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 8), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 8), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 8), [[]])
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))
    clip=set(full)
    enabled=True
    stack=[]
    out=[]
    for cmd in commands:
        op=cmd[0]
        mask=set(cmd[1]) & full if len(cmd)>1 else set()
        if op=='save': stack.append((set(clip),enabled))
        elif op=='restore':
            if stack: clip,enabled=stack.pop()
        elif op=='intersect': clip &= mask
        elif op=='exclude': clip -= mask
        elif op=='union': clip |= mask
        elif op=='replace': clip=set(mask)
        elif op=='invert': clip=full-clip
        elif op=='reset': clip=set(full); enabled=False
        elif op=='disable': enabled=False
        elif op=='enable': enabled=True
        elif op=='draw': out.append(sorted(clip if enabled else 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([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 4), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 4), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 4), [[0, 1, 2, 3]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 4), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 4), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 4), [[2], [0, 1, 3], [0, 1, 2, 3]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 4), [[0, 1, 2, 3]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 4), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 4), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 4), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 4), [[]])
if N == 2:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 5), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 5), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 5), [[0, 1, 2, 3, 4]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 5), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 5), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 5), [[2], [0, 1, 3, 4], [0, 1, 2, 3, 4]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 5), [[0, 1, 2, 3, 4]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 5), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 5), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 5), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 5), [[]])
if N == 3:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 6), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 6), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 6), [[0, 1, 2, 3, 4, 5]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 6), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 6), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 6), [[2], [0, 1, 3, 4, 5], [0, 1, 2, 3, 4, 5]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 6), [[0, 1, 2, 3, 4, 5]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 6), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 6), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 6), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 6), [[]])
if N == 4:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 7), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 7), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 7), [[0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 7), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 7), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 7), [[2], [0, 1, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 7), [[0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 7), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 7), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 7), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 7), [[]])
if N == 5:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 8), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 8), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 8), [[0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 8), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 8), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 8), [[2], [0, 1, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 8), [[0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 8), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 8), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 8), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 8), [[]])
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:
Reset produces an empty clip instead of the full surface.

Commands act on finite sample indices [0,size). Save/restore includes the clip-enable bit; region edits update stored coverage even while clipping is disabled. Restore underflow is inert. Draw emits sorted effective samples.

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))
    clip=set(full)
    enabled=True
    stack=[]
    out=[]
    for cmd in commands:
        op=cmd[0]
        mask=set(cmd[1]) & full if len(cmd)>1 else set()
        if op=='save': stack.append((set(clip),enabled))
        elif op=='restore':
            if stack: clip,enabled=stack.pop()
        elif op=='intersect': clip &= mask
        elif op=='exclude': clip -= mask
        elif op=='union': clip |= mask
        elif op=='replace': clip=set(mask)
        elif op=='invert': clip=full-clip
        elif op=='reset': clip=set(full)
        elif op=='disable': enabled=False; clip.clear()
        elif op=='enable': enabled=True
        elif op=='draw': out.append(sorted(clip if enabled else 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([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 4), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 4), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 4), [[0, 1, 2, 3]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 4), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 4), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 4), [[2], [0, 1, 3], [0, 1, 2, 3]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 4), [[0, 1, 2, 3]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 4), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 4), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 4), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 4), [[]])
if N == 2:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 5), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 5), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 5), [[0, 1, 2, 3, 4]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 5), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 5), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 5), [[2], [0, 1, 3, 4], [0, 1, 2, 3, 4]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 5), [[0, 1, 2, 3, 4]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 5), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 5), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 5), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 5), [[]])
if N == 3:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 6), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 6), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 6), [[0, 1, 2, 3, 4, 5]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 6), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 6), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 6), [[2], [0, 1, 3, 4, 5], [0, 1, 2, 3, 4, 5]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 6), [[0, 1, 2, 3, 4, 5]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 6), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 6), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 6), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 6), [[]])
if N == 4:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 7), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 7), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 7), [[0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 7), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 7), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 7), [[2], [0, 1, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 7), [[0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 7), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 7), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 7), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 7), [[]])
if N == 5:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 8), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 8), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 8), [[0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 8), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 8), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 8), [[2], [0, 1, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 8), [[0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 8), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 8), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 8), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 8), [[]])
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))
    clip=set(full)
    enabled=True
    stack=[]
    out=[]
    for cmd in commands:
        op=cmd[0]
        mask=set(cmd[1]) & full if len(cmd)>1 else set()
        if op=='save': stack.append((set(clip),enabled))
        elif op=='restore':
            if stack: clip,enabled=stack.pop()
        elif op=='intersect': clip &= mask
        elif op=='exclude': clip -= mask
        elif op=='union': clip |= mask
        elif op=='replace': clip=set(mask)
        elif op=='invert': clip=full-clip
        elif op=='reset': clip=set(full)
        elif op=='disable': enabled=False; clip=set(full)
        elif op=='enable': enabled=True
        elif op=='draw': out.append(sorted(clip if enabled else 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([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 4), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 4), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 4), [[0, 1, 2, 3]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 4), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 4), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 4), [[2], [0, 1, 3], [0, 1, 2, 3]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 4), [[0, 1, 2, 3]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 4), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 4), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 4), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 4), [[]])
if N == 2:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 5), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 5), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 5), [[0, 1, 2, 3, 4]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 5), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 5), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 5), [[2], [0, 1, 3, 4], [0, 1, 2, 3, 4]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 5), [[0, 1, 2, 3, 4]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 5), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 5), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 5), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 5), [[]])
if N == 3:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 6), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 6), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 6), [[0, 1, 2, 3, 4, 5]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 6), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 6), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 6), [[2], [0, 1, 3, 4, 5], [0, 1, 2, 3, 4, 5]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 6), [[0, 1, 2, 3, 4, 5]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 6), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 6), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 6), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 6), [[]])
if N == 4:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 7), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 7), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 7), [[0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 7), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 7), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 7), [[2], [0, 1, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 7), [[0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 7), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 7), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 7), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 7), [[]])
if N == 5:
    check('explicit sequence 0', solve([['replace', [0, 1, 2]], ['save'], ['exclude', [1]], ['draw'], ['restore'], ['draw']], 8), [[0, 2], [0, 1, 2]])
    check('explicit sequence 1', solve([['replace', [0]], ['save'], ['replace', [1]], ['save'], ['replace', [2]], ['restore'], ['draw'], ['restore'], ['draw']], 8), [[1], [0]])
    check('explicit sequence 2', solve([['replace', [0]], ['disable'], ['save'], ['enable'], ['restore'], ['draw']], 8), [[0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 3', solve([['replace', [1, 2]], ['disable'], ['enable'], ['draw']], 8), [[1, 2]])
    check('explicit sequence 4', solve([['replace', [0]], ['exclude', [2]], ['draw'], ['union', [0, 2]], ['draw']], 8), [[0], [0, 2]])
    check('explicit sequence 5', solve([['replace', [1]], ['replace', [2]], ['draw'], ['invert'], ['draw'], ['reset'], ['draw']], 8), [[2], [0, 1, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 6', solve([['restore'], ['draw']], 8), [[0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 7', solve([['replace', []], ['draw']], 8), [[]])
    check('explicit sequence 8', solve([['disable'], ['replace', [0, 2, 8]], ['enable'], ['draw']], 8), [[0, 2]])
    check('explicit sequence 9', solve([['reset'], ['replace', [0]], ['draw']], 8), [[0]])
    check('explicit sequence 10', solve([['replace', []], ['disable'], ['enable'], ['draw']], 8), [[]])
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:
Disabling destroys the remembered region so re-enabling loses coverage.

Commands act on finite sample indices [0,size). Save/restore includes the clip-enable bit; region edits update stored coverage even while clipping is disabled. Restore underflow is inert. Draw emits sorted effective samples.

split: open-access