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)
    coverage=set()
    stack=[]
    out=[]
    for cmd in commands:
        op=cmd[0]
        if op=='clip': clip &= set(cmd[1])
        elif op=='replace': clip=set(cmd[1]) & full
        elif op=='begin':
            stack.append((set(clip),set(coverage)))
            clip=set(full)
            coverage=set()
        elif op=='draw': coverage |= set(cmd[1]) & clip
        elif op=='clear': coverage.clear(); clip.clear()
        elif op=='end' and stack:
            parent_clip,parent_coverage=stack.pop()
            coverage=parent_coverage | (coverage & parent_clip)
            clip=parent_clip
        elif op=='discard' and stack: clip,coverage=stack.pop()
        elif op=='inspect': out.append(sorted(coverage))
    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]], ['begin'], ['draw', [1]], ['inspect'], ['end'], ['inspect']], 4), [[1], []])
    check('explicit sequence 1', solve([['draw', [0]], ['begin'], ['inspect']], 4), [[]])
    check('explicit sequence 2', solve([['begin'], ['draw', [0]], ['draw', [1]], ['inspect']], 4), [[0, 1]])
    check('explicit sequence 3', solve([['begin'], ['replace', [1]], ['draw', [0, 1]], ['inspect']], 4), [[1]])
    check('explicit sequence 4', solve([['begin'], ['draw', [0]], ['clear'], ['draw', [1]], ['inspect']], 4), [[1]])
    check('explicit sequence 5', solve([['replace', [0]], ['begin'], ['draw', [0, 1]], ['end'], ['inspect']], 4), [[0]])
    check('explicit sequence 6', solve([['draw', [0]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 4), [[0, 1]])
    check('explicit sequence 7', solve([['replace', [0]], ['begin'], ['end'], ['draw', [1]], ['inspect']], 4), [[]])
    check('explicit sequence 8', solve([['draw', [0]], ['begin'], ['draw', [1]], ['discard'], ['inspect']], 4), [[0]])
    check('explicit sequence 9', solve([['replace', [0, 1]], ['draw', [0]], ['begin'], ['replace', [1]], ['begin'], ['draw', [1, 2]], ['end'], ['inspect'], ['end'], ['inspect']], 4), [[1], [0, 1]])
    check('explicit sequence 10', solve([['draw', [0]], ['draw', [0, 1]], ['inspect']], 4), [[0, 1]])
    check('explicit sequence 11', solve([['replace', []], ['draw', [0]], ['inspect']], 4), [[]])
    check('explicit sequence 12', solve([['replace', [0]], ['draw', [0]], ['clear'], ['draw', [0, 1]], ['inspect']], 4), [[0]])
    check('explicit sequence 13', solve([['draw', [0]], ['replace', [1]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 4), [[0, 1]])
    check('explicit sequence 14', solve([['replace', []], ['begin'], ['end'], ['draw', [1]], ['inspect']], 4), [[]])
    check('explicit sequence 15', solve([['draw', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], ['inspect']], 4), [[0, 1, 2, 3]])
if N == 2:
    check('explicit sequence 0', solve([['replace', [0]], ['begin'], ['draw', [1]], ['inspect'], ['end'], ['inspect']], 5), [[1], []])
    check('explicit sequence 1', solve([['draw', [0]], ['begin'], ['inspect']], 5), [[]])
    check('explicit sequence 2', solve([['begin'], ['draw', [0]], ['draw', [1]], ['inspect']], 5), [[0, 1]])
    check('explicit sequence 3', solve([['begin'], ['replace', [1]], ['draw', [0, 1]], ['inspect']], 5), [[1]])
    check('explicit sequence 4', solve([['begin'], ['draw', [0]], ['clear'], ['draw', [1]], ['inspect']], 5), [[1]])
    check('explicit sequence 5', solve([['replace', [0]], ['begin'], ['draw', [0, 1]], ['end'], ['inspect']], 5), [[0]])
    check('explicit sequence 6', solve([['draw', [0]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 5), [[0, 1]])
    check('explicit sequence 7', solve([['replace', [0]], ['begin'], ['end'], ['draw', [1]], ['inspect']], 5), [[]])
    check('explicit sequence 8', solve([['draw', [0]], ['begin'], ['draw', [1]], ['discard'], ['inspect']], 5), [[0]])
    check('explicit sequence 9', solve([['replace', [0, 1]], ['draw', [0]], ['begin'], ['replace', [1]], ['begin'], ['draw', [1, 2]], ['end'], ['inspect'], ['end'], ['inspect']], 5), [[1], [0, 1]])
    check('explicit sequence 10', solve([['draw', [0]], ['draw', [0, 1]], ['inspect']], 5), [[0, 1]])
    check('explicit sequence 11', solve([['replace', []], ['draw', [0]], ['inspect']], 5), [[]])
    check('explicit sequence 12', solve([['replace', [0]], ['draw', [0]], ['clear'], ['draw', [0, 1]], ['inspect']], 5), [[0]])
    check('explicit sequence 13', solve([['draw', [0]], ['replace', [1]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 5), [[0, 1]])
    check('explicit sequence 14', solve([['replace', []], ['begin'], ['end'], ['draw', [1]], ['inspect']], 5), [[]])
    check('explicit sequence 15', solve([['draw', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], ['inspect']], 5), [[0, 1, 2, 3, 4]])
if N == 3:
    check('explicit sequence 0', solve([['replace', [0]], ['begin'], ['draw', [1]], ['inspect'], ['end'], ['inspect']], 6), [[1], []])
    check('explicit sequence 1', solve([['draw', [0]], ['begin'], ['inspect']], 6), [[]])
    check('explicit sequence 2', solve([['begin'], ['draw', [0]], ['draw', [1]], ['inspect']], 6), [[0, 1]])
    check('explicit sequence 3', solve([['begin'], ['replace', [1]], ['draw', [0, 1]], ['inspect']], 6), [[1]])
    check('explicit sequence 4', solve([['begin'], ['draw', [0]], ['clear'], ['draw', [1]], ['inspect']], 6), [[1]])
    check('explicit sequence 5', solve([['replace', [0]], ['begin'], ['draw', [0, 1]], ['end'], ['inspect']], 6), [[0]])
    check('explicit sequence 6', solve([['draw', [0]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 6), [[0, 1]])
    check('explicit sequence 7', solve([['replace', [0]], ['begin'], ['end'], ['draw', [1]], ['inspect']], 6), [[]])
    check('explicit sequence 8', solve([['draw', [0]], ['begin'], ['draw', [1]], ['discard'], ['inspect']], 6), [[0]])
    check('explicit sequence 9', solve([['replace', [0, 1]], ['draw', [0]], ['begin'], ['replace', [1]], ['begin'], ['draw', [1, 2]], ['end'], ['inspect'], ['end'], ['inspect']], 6), [[1], [0, 1]])
    check('explicit sequence 10', solve([['draw', [0]], ['draw', [0, 1]], ['inspect']], 6), [[0, 1]])
    check('explicit sequence 11', solve([['replace', []], ['draw', [0]], ['inspect']], 6), [[]])
    check('explicit sequence 12', solve([['replace', [0]], ['draw', [0]], ['clear'], ['draw', [0, 1]], ['inspect']], 6), [[0]])
    check('explicit sequence 13', solve([['draw', [0]], ['replace', [1]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 6), [[0, 1]])
    check('explicit sequence 14', solve([['replace', []], ['begin'], ['end'], ['draw', [1]], ['inspect']], 6), [[]])
    check('explicit sequence 15', solve([['draw', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], ['inspect']], 6), [[0, 1, 2, 3, 4, 5]])
if N == 4:
    check('explicit sequence 0', solve([['replace', [0]], ['begin'], ['draw', [1]], ['inspect'], ['end'], ['inspect']], 7), [[1], []])
    check('explicit sequence 1', solve([['draw', [0]], ['begin'], ['inspect']], 7), [[]])
    check('explicit sequence 2', solve([['begin'], ['draw', [0]], ['draw', [1]], ['inspect']], 7), [[0, 1]])
    check('explicit sequence 3', solve([['begin'], ['replace', [1]], ['draw', [0, 1]], ['inspect']], 7), [[1]])
    check('explicit sequence 4', solve([['begin'], ['draw', [0]], ['clear'], ['draw', [1]], ['inspect']], 7), [[1]])
    check('explicit sequence 5', solve([['replace', [0]], ['begin'], ['draw', [0, 1]], ['end'], ['inspect']], 7), [[0]])
    check('explicit sequence 6', solve([['draw', [0]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 7), [[0, 1]])
    check('explicit sequence 7', solve([['replace', [0]], ['begin'], ['end'], ['draw', [1]], ['inspect']], 7), [[]])
    check('explicit sequence 8', solve([['draw', [0]], ['begin'], ['draw', [1]], ['discard'], ['inspect']], 7), [[0]])
    check('explicit sequence 9', solve([['replace', [0, 1]], ['draw', [0]], ['begin'], ['replace', [1]], ['begin'], ['draw', [1, 2]], ['end'], ['inspect'], ['end'], ['inspect']], 7), [[1], [0, 1]])
    check('explicit sequence 10', solve([['draw', [0]], ['draw', [0, 1]], ['inspect']], 7), [[0, 1]])
    check('explicit sequence 11', solve([['replace', []], ['draw', [0]], ['inspect']], 7), [[]])
    check('explicit sequence 12', solve([['replace', [0]], ['draw', [0]], ['clear'], ['draw', [0, 1]], ['inspect']], 7), [[0]])
    check('explicit sequence 13', solve([['draw', [0]], ['replace', [1]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 7), [[0, 1]])
    check('explicit sequence 14', solve([['replace', []], ['begin'], ['end'], ['draw', [1]], ['inspect']], 7), [[]])
    check('explicit sequence 15', solve([['draw', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], ['inspect']], 7), [[0, 1, 2, 3, 4, 5, 6]])
if N == 5:
    check('explicit sequence 0', solve([['replace', [0]], ['begin'], ['draw', [1]], ['inspect'], ['end'], ['inspect']], 8), [[1], []])
    check('explicit sequence 1', solve([['draw', [0]], ['begin'], ['inspect']], 8), [[]])
    check('explicit sequence 2', solve([['begin'], ['draw', [0]], ['draw', [1]], ['inspect']], 8), [[0, 1]])
    check('explicit sequence 3', solve([['begin'], ['replace', [1]], ['draw', [0, 1]], ['inspect']], 8), [[1]])
    check('explicit sequence 4', solve([['begin'], ['draw', [0]], ['clear'], ['draw', [1]], ['inspect']], 8), [[1]])
    check('explicit sequence 5', solve([['replace', [0]], ['begin'], ['draw', [0, 1]], ['end'], ['inspect']], 8), [[0]])
    check('explicit sequence 6', solve([['draw', [0]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 8), [[0, 1]])
    check('explicit sequence 7', solve([['replace', [0]], ['begin'], ['end'], ['draw', [1]], ['inspect']], 8), [[]])
    check('explicit sequence 8', solve([['draw', [0]], ['begin'], ['draw', [1]], ['discard'], ['inspect']], 8), [[0]])
    check('explicit sequence 9', solve([['replace', [0, 1]], ['draw', [0]], ['begin'], ['replace', [1]], ['begin'], ['draw', [1, 2]], ['end'], ['inspect'], ['end'], ['inspect']], 8), [[1], [0, 1]])
    check('explicit sequence 10', solve([['draw', [0]], ['draw', [0, 1]], ['inspect']], 8), [[0, 1]])
    check('explicit sequence 11', solve([['replace', []], ['draw', [0]], ['inspect']], 8), [[]])
    check('explicit sequence 12', solve([['replace', [0]], ['draw', [0]], ['clear'], ['draw', [0, 1]], ['inspect']], 8), [[0]])
    check('explicit sequence 13', solve([['draw', [0]], ['replace', [1]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 8), [[0, 1]])
    check('explicit sequence 14', solve([['replace', []], ['begin'], ['end'], ['draw', [1]], ['inspect']], 8), [[]])
    check('explicit sequence 15', solve([['draw', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], ['inspect']], 8), [[0, 1, 2, 3, 4, 5, 6, 7]])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(commands, size):
    full=set(range(size))
    clip=set(full)
    coverage=set()
    stack=[]
    out=[]
    for cmd in commands:
        op=cmd[0]
        if op=='clip': clip &= set(cmd[1])
        elif op=='replace': clip=set(cmd[1]) & full
        elif op=='begin':
            stack.append((set(clip),set(coverage)))
            clip=set(full)
            coverage=set()
        elif op=='draw': coverage |= set(cmd[1]) & clip
        elif op=='clear': coverage.clear(); clip=set(full)
        elif op=='end' and stack:
            parent_clip,parent_coverage=stack.pop()
            coverage=parent_coverage | (coverage & parent_clip)
            clip=parent_clip
        elif op=='discard' and stack: clip,coverage=stack.pop()
        elif op=='inspect': out.append(sorted(coverage))
    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]], ['begin'], ['draw', [1]], ['inspect'], ['end'], ['inspect']], 4), [[1], []])
    check('explicit sequence 1', solve([['draw', [0]], ['begin'], ['inspect']], 4), [[]])
    check('explicit sequence 2', solve([['begin'], ['draw', [0]], ['draw', [1]], ['inspect']], 4), [[0, 1]])
    check('explicit sequence 3', solve([['begin'], ['replace', [1]], ['draw', [0, 1]], ['inspect']], 4), [[1]])
    check('explicit sequence 4', solve([['begin'], ['draw', [0]], ['clear'], ['draw', [1]], ['inspect']], 4), [[1]])
    check('explicit sequence 5', solve([['replace', [0]], ['begin'], ['draw', [0, 1]], ['end'], ['inspect']], 4), [[0]])
    check('explicit sequence 6', solve([['draw', [0]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 4), [[0, 1]])
    check('explicit sequence 7', solve([['replace', [0]], ['begin'], ['end'], ['draw', [1]], ['inspect']], 4), [[]])
    check('explicit sequence 8', solve([['draw', [0]], ['begin'], ['draw', [1]], ['discard'], ['inspect']], 4), [[0]])
    check('explicit sequence 9', solve([['replace', [0, 1]], ['draw', [0]], ['begin'], ['replace', [1]], ['begin'], ['draw', [1, 2]], ['end'], ['inspect'], ['end'], ['inspect']], 4), [[1], [0, 1]])
    check('explicit sequence 10', solve([['draw', [0]], ['draw', [0, 1]], ['inspect']], 4), [[0, 1]])
    check('explicit sequence 11', solve([['replace', []], ['draw', [0]], ['inspect']], 4), [[]])
    check('explicit sequence 12', solve([['replace', [0]], ['draw', [0]], ['clear'], ['draw', [0, 1]], ['inspect']], 4), [[0]])
    check('explicit sequence 13', solve([['draw', [0]], ['replace', [1]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 4), [[0, 1]])
    check('explicit sequence 14', solve([['replace', []], ['begin'], ['end'], ['draw', [1]], ['inspect']], 4), [[]])
    check('explicit sequence 15', solve([['draw', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], ['inspect']], 4), [[0, 1, 2, 3]])
if N == 2:
    check('explicit sequence 0', solve([['replace', [0]], ['begin'], ['draw', [1]], ['inspect'], ['end'], ['inspect']], 5), [[1], []])
    check('explicit sequence 1', solve([['draw', [0]], ['begin'], ['inspect']], 5), [[]])
    check('explicit sequence 2', solve([['begin'], ['draw', [0]], ['draw', [1]], ['inspect']], 5), [[0, 1]])
    check('explicit sequence 3', solve([['begin'], ['replace', [1]], ['draw', [0, 1]], ['inspect']], 5), [[1]])
    check('explicit sequence 4', solve([['begin'], ['draw', [0]], ['clear'], ['draw', [1]], ['inspect']], 5), [[1]])
    check('explicit sequence 5', solve([['replace', [0]], ['begin'], ['draw', [0, 1]], ['end'], ['inspect']], 5), [[0]])
    check('explicit sequence 6', solve([['draw', [0]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 5), [[0, 1]])
    check('explicit sequence 7', solve([['replace', [0]], ['begin'], ['end'], ['draw', [1]], ['inspect']], 5), [[]])
    check('explicit sequence 8', solve([['draw', [0]], ['begin'], ['draw', [1]], ['discard'], ['inspect']], 5), [[0]])
    check('explicit sequence 9', solve([['replace', [0, 1]], ['draw', [0]], ['begin'], ['replace', [1]], ['begin'], ['draw', [1, 2]], ['end'], ['inspect'], ['end'], ['inspect']], 5), [[1], [0, 1]])
    check('explicit sequence 10', solve([['draw', [0]], ['draw', [0, 1]], ['inspect']], 5), [[0, 1]])
    check('explicit sequence 11', solve([['replace', []], ['draw', [0]], ['inspect']], 5), [[]])
    check('explicit sequence 12', solve([['replace', [0]], ['draw', [0]], ['clear'], ['draw', [0, 1]], ['inspect']], 5), [[0]])
    check('explicit sequence 13', solve([['draw', [0]], ['replace', [1]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 5), [[0, 1]])
    check('explicit sequence 14', solve([['replace', []], ['begin'], ['end'], ['draw', [1]], ['inspect']], 5), [[]])
    check('explicit sequence 15', solve([['draw', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], ['inspect']], 5), [[0, 1, 2, 3, 4]])
if N == 3:
    check('explicit sequence 0', solve([['replace', [0]], ['begin'], ['draw', [1]], ['inspect'], ['end'], ['inspect']], 6), [[1], []])
    check('explicit sequence 1', solve([['draw', [0]], ['begin'], ['inspect']], 6), [[]])
    check('explicit sequence 2', solve([['begin'], ['draw', [0]], ['draw', [1]], ['inspect']], 6), [[0, 1]])
    check('explicit sequence 3', solve([['begin'], ['replace', [1]], ['draw', [0, 1]], ['inspect']], 6), [[1]])
    check('explicit sequence 4', solve([['begin'], ['draw', [0]], ['clear'], ['draw', [1]], ['inspect']], 6), [[1]])
    check('explicit sequence 5', solve([['replace', [0]], ['begin'], ['draw', [0, 1]], ['end'], ['inspect']], 6), [[0]])
    check('explicit sequence 6', solve([['draw', [0]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 6), [[0, 1]])
    check('explicit sequence 7', solve([['replace', [0]], ['begin'], ['end'], ['draw', [1]], ['inspect']], 6), [[]])
    check('explicit sequence 8', solve([['draw', [0]], ['begin'], ['draw', [1]], ['discard'], ['inspect']], 6), [[0]])
    check('explicit sequence 9', solve([['replace', [0, 1]], ['draw', [0]], ['begin'], ['replace', [1]], ['begin'], ['draw', [1, 2]], ['end'], ['inspect'], ['end'], ['inspect']], 6), [[1], [0, 1]])
    check('explicit sequence 10', solve([['draw', [0]], ['draw', [0, 1]], ['inspect']], 6), [[0, 1]])
    check('explicit sequence 11', solve([['replace', []], ['draw', [0]], ['inspect']], 6), [[]])
    check('explicit sequence 12', solve([['replace', [0]], ['draw', [0]], ['clear'], ['draw', [0, 1]], ['inspect']], 6), [[0]])
    check('explicit sequence 13', solve([['draw', [0]], ['replace', [1]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 6), [[0, 1]])
    check('explicit sequence 14', solve([['replace', []], ['begin'], ['end'], ['draw', [1]], ['inspect']], 6), [[]])
    check('explicit sequence 15', solve([['draw', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], ['inspect']], 6), [[0, 1, 2, 3, 4, 5]])
if N == 4:
    check('explicit sequence 0', solve([['replace', [0]], ['begin'], ['draw', [1]], ['inspect'], ['end'], ['inspect']], 7), [[1], []])
    check('explicit sequence 1', solve([['draw', [0]], ['begin'], ['inspect']], 7), [[]])
    check('explicit sequence 2', solve([['begin'], ['draw', [0]], ['draw', [1]], ['inspect']], 7), [[0, 1]])
    check('explicit sequence 3', solve([['begin'], ['replace', [1]], ['draw', [0, 1]], ['inspect']], 7), [[1]])
    check('explicit sequence 4', solve([['begin'], ['draw', [0]], ['clear'], ['draw', [1]], ['inspect']], 7), [[1]])
    check('explicit sequence 5', solve([['replace', [0]], ['begin'], ['draw', [0, 1]], ['end'], ['inspect']], 7), [[0]])
    check('explicit sequence 6', solve([['draw', [0]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 7), [[0, 1]])
    check('explicit sequence 7', solve([['replace', [0]], ['begin'], ['end'], ['draw', [1]], ['inspect']], 7), [[]])
    check('explicit sequence 8', solve([['draw', [0]], ['begin'], ['draw', [1]], ['discard'], ['inspect']], 7), [[0]])
    check('explicit sequence 9', solve([['replace', [0, 1]], ['draw', [0]], ['begin'], ['replace', [1]], ['begin'], ['draw', [1, 2]], ['end'], ['inspect'], ['end'], ['inspect']], 7), [[1], [0, 1]])
    check('explicit sequence 10', solve([['draw', [0]], ['draw', [0, 1]], ['inspect']], 7), [[0, 1]])
    check('explicit sequence 11', solve([['replace', []], ['draw', [0]], ['inspect']], 7), [[]])
    check('explicit sequence 12', solve([['replace', [0]], ['draw', [0]], ['clear'], ['draw', [0, 1]], ['inspect']], 7), [[0]])
    check('explicit sequence 13', solve([['draw', [0]], ['replace', [1]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 7), [[0, 1]])
    check('explicit sequence 14', solve([['replace', []], ['begin'], ['end'], ['draw', [1]], ['inspect']], 7), [[]])
    check('explicit sequence 15', solve([['draw', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], ['inspect']], 7), [[0, 1, 2, 3, 4, 5, 6]])
if N == 5:
    check('explicit sequence 0', solve([['replace', [0]], ['begin'], ['draw', [1]], ['inspect'], ['end'], ['inspect']], 8), [[1], []])
    check('explicit sequence 1', solve([['draw', [0]], ['begin'], ['inspect']], 8), [[]])
    check('explicit sequence 2', solve([['begin'], ['draw', [0]], ['draw', [1]], ['inspect']], 8), [[0, 1]])
    check('explicit sequence 3', solve([['begin'], ['replace', [1]], ['draw', [0, 1]], ['inspect']], 8), [[1]])
    check('explicit sequence 4', solve([['begin'], ['draw', [0]], ['clear'], ['draw', [1]], ['inspect']], 8), [[1]])
    check('explicit sequence 5', solve([['replace', [0]], ['begin'], ['draw', [0, 1]], ['end'], ['inspect']], 8), [[0]])
    check('explicit sequence 6', solve([['draw', [0]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 8), [[0, 1]])
    check('explicit sequence 7', solve([['replace', [0]], ['begin'], ['end'], ['draw', [1]], ['inspect']], 8), [[]])
    check('explicit sequence 8', solve([['draw', [0]], ['begin'], ['draw', [1]], ['discard'], ['inspect']], 8), [[0]])
    check('explicit sequence 9', solve([['replace', [0, 1]], ['draw', [0]], ['begin'], ['replace', [1]], ['begin'], ['draw', [1, 2]], ['end'], ['inspect'], ['end'], ['inspect']], 8), [[1], [0, 1]])
    check('explicit sequence 10', solve([['draw', [0]], ['draw', [0, 1]], ['inspect']], 8), [[0, 1]])
    check('explicit sequence 11', solve([['replace', []], ['draw', [0]], ['inspect']], 8), [[]])
    check('explicit sequence 12', solve([['replace', [0]], ['draw', [0]], ['clear'], ['draw', [0, 1]], ['inspect']], 8), [[0]])
    check('explicit sequence 13', solve([['draw', [0]], ['replace', [1]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 8), [[0, 1]])
    check('explicit sequence 14', solve([['replace', []], ['begin'], ['end'], ['draw', [1]], ['inspect']], 8), [[]])
    check('explicit sequence 15', solve([['draw', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], ['inspect']], 8), [[0, 1, 2, 3, 4, 5, 6, 7]])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Clearing a layer also clears its clipping region, preventing subsequent draws.

A layer captures the parent clip and starts with its own full local clip. Child drawing accumulates coverage in that layer; layer completion intersects child coverage with the saved parent clip. Discard removes the layer without publishing. A layer-local clear erases only its accumulated coverage. Parent clip edits after opening cannot change the captured parent clip.

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)
    coverage=set()
    stack=[]
    out=[]
    for cmd in commands:
        op=cmd[0]
        if op=='clip': clip &= set(cmd[1])
        elif op=='replace': clip=set(cmd[1]) & full
        elif op=='begin':
            stack.append((set(clip),set(coverage)))
            clip=set(full)
            coverage=set()
        elif op=='draw': coverage |= set(cmd[1]) & clip
        elif op=='clear': coverage.clear()
        elif op=='end' and stack:
            parent_clip,parent_coverage=stack.pop()
            coverage=parent_coverage | coverage
            clip=parent_clip
        elif op=='discard' and stack: clip,coverage=stack.pop()
        elif op=='inspect': out.append(sorted(coverage))
    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]], ['begin'], ['draw', [1]], ['inspect'], ['end'], ['inspect']], 4), [[1], []])
    check('explicit sequence 1', solve([['draw', [0]], ['begin'], ['inspect']], 4), [[]])
    check('explicit sequence 2', solve([['begin'], ['draw', [0]], ['draw', [1]], ['inspect']], 4), [[0, 1]])
    check('explicit sequence 3', solve([['begin'], ['replace', [1]], ['draw', [0, 1]], ['inspect']], 4), [[1]])
    check('explicit sequence 4', solve([['begin'], ['draw', [0]], ['clear'], ['draw', [1]], ['inspect']], 4), [[1]])
    check('explicit sequence 5', solve([['replace', [0]], ['begin'], ['draw', [0, 1]], ['end'], ['inspect']], 4), [[0]])
    check('explicit sequence 6', solve([['draw', [0]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 4), [[0, 1]])
    check('explicit sequence 7', solve([['replace', [0]], ['begin'], ['end'], ['draw', [1]], ['inspect']], 4), [[]])
    check('explicit sequence 8', solve([['draw', [0]], ['begin'], ['draw', [1]], ['discard'], ['inspect']], 4), [[0]])
    check('explicit sequence 9', solve([['replace', [0, 1]], ['draw', [0]], ['begin'], ['replace', [1]], ['begin'], ['draw', [1, 2]], ['end'], ['inspect'], ['end'], ['inspect']], 4), [[1], [0, 1]])
    check('explicit sequence 10', solve([['draw', [0]], ['draw', [0, 1]], ['inspect']], 4), [[0, 1]])
    check('explicit sequence 11', solve([['replace', []], ['draw', [0]], ['inspect']], 4), [[]])
    check('explicit sequence 12', solve([['replace', [0]], ['draw', [0]], ['clear'], ['draw', [0, 1]], ['inspect']], 4), [[0]])
    check('explicit sequence 13', solve([['draw', [0]], ['replace', [1]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 4), [[0, 1]])
    check('explicit sequence 14', solve([['replace', []], ['begin'], ['end'], ['draw', [1]], ['inspect']], 4), [[]])
    check('explicit sequence 15', solve([['draw', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], ['inspect']], 4), [[0, 1, 2, 3]])
if N == 2:
    check('explicit sequence 0', solve([['replace', [0]], ['begin'], ['draw', [1]], ['inspect'], ['end'], ['inspect']], 5), [[1], []])
    check('explicit sequence 1', solve([['draw', [0]], ['begin'], ['inspect']], 5), [[]])
    check('explicit sequence 2', solve([['begin'], ['draw', [0]], ['draw', [1]], ['inspect']], 5), [[0, 1]])
    check('explicit sequence 3', solve([['begin'], ['replace', [1]], ['draw', [0, 1]], ['inspect']], 5), [[1]])
    check('explicit sequence 4', solve([['begin'], ['draw', [0]], ['clear'], ['draw', [1]], ['inspect']], 5), [[1]])
    check('explicit sequence 5', solve([['replace', [0]], ['begin'], ['draw', [0, 1]], ['end'], ['inspect']], 5), [[0]])
    check('explicit sequence 6', solve([['draw', [0]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 5), [[0, 1]])
    check('explicit sequence 7', solve([['replace', [0]], ['begin'], ['end'], ['draw', [1]], ['inspect']], 5), [[]])
    check('explicit sequence 8', solve([['draw', [0]], ['begin'], ['draw', [1]], ['discard'], ['inspect']], 5), [[0]])
    check('explicit sequence 9', solve([['replace', [0, 1]], ['draw', [0]], ['begin'], ['replace', [1]], ['begin'], ['draw', [1, 2]], ['end'], ['inspect'], ['end'], ['inspect']], 5), [[1], [0, 1]])
    check('explicit sequence 10', solve([['draw', [0]], ['draw', [0, 1]], ['inspect']], 5), [[0, 1]])
    check('explicit sequence 11', solve([['replace', []], ['draw', [0]], ['inspect']], 5), [[]])
    check('explicit sequence 12', solve([['replace', [0]], ['draw', [0]], ['clear'], ['draw', [0, 1]], ['inspect']], 5), [[0]])
    check('explicit sequence 13', solve([['draw', [0]], ['replace', [1]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 5), [[0, 1]])
    check('explicit sequence 14', solve([['replace', []], ['begin'], ['end'], ['draw', [1]], ['inspect']], 5), [[]])
    check('explicit sequence 15', solve([['draw', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], ['inspect']], 5), [[0, 1, 2, 3, 4]])
if N == 3:
    check('explicit sequence 0', solve([['replace', [0]], ['begin'], ['draw', [1]], ['inspect'], ['end'], ['inspect']], 6), [[1], []])
    check('explicit sequence 1', solve([['draw', [0]], ['begin'], ['inspect']], 6), [[]])
    check('explicit sequence 2', solve([['begin'], ['draw', [0]], ['draw', [1]], ['inspect']], 6), [[0, 1]])
    check('explicit sequence 3', solve([['begin'], ['replace', [1]], ['draw', [0, 1]], ['inspect']], 6), [[1]])
    check('explicit sequence 4', solve([['begin'], ['draw', [0]], ['clear'], ['draw', [1]], ['inspect']], 6), [[1]])
    check('explicit sequence 5', solve([['replace', [0]], ['begin'], ['draw', [0, 1]], ['end'], ['inspect']], 6), [[0]])
    check('explicit sequence 6', solve([['draw', [0]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 6), [[0, 1]])
    check('explicit sequence 7', solve([['replace', [0]], ['begin'], ['end'], ['draw', [1]], ['inspect']], 6), [[]])
    check('explicit sequence 8', solve([['draw', [0]], ['begin'], ['draw', [1]], ['discard'], ['inspect']], 6), [[0]])
    check('explicit sequence 9', solve([['replace', [0, 1]], ['draw', [0]], ['begin'], ['replace', [1]], ['begin'], ['draw', [1, 2]], ['end'], ['inspect'], ['end'], ['inspect']], 6), [[1], [0, 1]])
    check('explicit sequence 10', solve([['draw', [0]], ['draw', [0, 1]], ['inspect']], 6), [[0, 1]])
    check('explicit sequence 11', solve([['replace', []], ['draw', [0]], ['inspect']], 6), [[]])
    check('explicit sequence 12', solve([['replace', [0]], ['draw', [0]], ['clear'], ['draw', [0, 1]], ['inspect']], 6), [[0]])
    check('explicit sequence 13', solve([['draw', [0]], ['replace', [1]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 6), [[0, 1]])
    check('explicit sequence 14', solve([['replace', []], ['begin'], ['end'], ['draw', [1]], ['inspect']], 6), [[]])
    check('explicit sequence 15', solve([['draw', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], ['inspect']], 6), [[0, 1, 2, 3, 4, 5]])
if N == 4:
    check('explicit sequence 0', solve([['replace', [0]], ['begin'], ['draw', [1]], ['inspect'], ['end'], ['inspect']], 7), [[1], []])
    check('explicit sequence 1', solve([['draw', [0]], ['begin'], ['inspect']], 7), [[]])
    check('explicit sequence 2', solve([['begin'], ['draw', [0]], ['draw', [1]], ['inspect']], 7), [[0, 1]])
    check('explicit sequence 3', solve([['begin'], ['replace', [1]], ['draw', [0, 1]], ['inspect']], 7), [[1]])
    check('explicit sequence 4', solve([['begin'], ['draw', [0]], ['clear'], ['draw', [1]], ['inspect']], 7), [[1]])
    check('explicit sequence 5', solve([['replace', [0]], ['begin'], ['draw', [0, 1]], ['end'], ['inspect']], 7), [[0]])
    check('explicit sequence 6', solve([['draw', [0]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 7), [[0, 1]])
    check('explicit sequence 7', solve([['replace', [0]], ['begin'], ['end'], ['draw', [1]], ['inspect']], 7), [[]])
    check('explicit sequence 8', solve([['draw', [0]], ['begin'], ['draw', [1]], ['discard'], ['inspect']], 7), [[0]])
    check('explicit sequence 9', solve([['replace', [0, 1]], ['draw', [0]], ['begin'], ['replace', [1]], ['begin'], ['draw', [1, 2]], ['end'], ['inspect'], ['end'], ['inspect']], 7), [[1], [0, 1]])
    check('explicit sequence 10', solve([['draw', [0]], ['draw', [0, 1]], ['inspect']], 7), [[0, 1]])
    check('explicit sequence 11', solve([['replace', []], ['draw', [0]], ['inspect']], 7), [[]])
    check('explicit sequence 12', solve([['replace', [0]], ['draw', [0]], ['clear'], ['draw', [0, 1]], ['inspect']], 7), [[0]])
    check('explicit sequence 13', solve([['draw', [0]], ['replace', [1]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 7), [[0, 1]])
    check('explicit sequence 14', solve([['replace', []], ['begin'], ['end'], ['draw', [1]], ['inspect']], 7), [[]])
    check('explicit sequence 15', solve([['draw', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], ['inspect']], 7), [[0, 1, 2, 3, 4, 5, 6]])
if N == 5:
    check('explicit sequence 0', solve([['replace', [0]], ['begin'], ['draw', [1]], ['inspect'], ['end'], ['inspect']], 8), [[1], []])
    check('explicit sequence 1', solve([['draw', [0]], ['begin'], ['inspect']], 8), [[]])
    check('explicit sequence 2', solve([['begin'], ['draw', [0]], ['draw', [1]], ['inspect']], 8), [[0, 1]])
    check('explicit sequence 3', solve([['begin'], ['replace', [1]], ['draw', [0, 1]], ['inspect']], 8), [[1]])
    check('explicit sequence 4', solve([['begin'], ['draw', [0]], ['clear'], ['draw', [1]], ['inspect']], 8), [[1]])
    check('explicit sequence 5', solve([['replace', [0]], ['begin'], ['draw', [0, 1]], ['end'], ['inspect']], 8), [[0]])
    check('explicit sequence 6', solve([['draw', [0]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 8), [[0, 1]])
    check('explicit sequence 7', solve([['replace', [0]], ['begin'], ['end'], ['draw', [1]], ['inspect']], 8), [[]])
    check('explicit sequence 8', solve([['draw', [0]], ['begin'], ['draw', [1]], ['discard'], ['inspect']], 8), [[0]])
    check('explicit sequence 9', solve([['replace', [0, 1]], ['draw', [0]], ['begin'], ['replace', [1]], ['begin'], ['draw', [1, 2]], ['end'], ['inspect'], ['end'], ['inspect']], 8), [[1], [0, 1]])
    check('explicit sequence 10', solve([['draw', [0]], ['draw', [0, 1]], ['inspect']], 8), [[0, 1]])
    check('explicit sequence 11', solve([['replace', []], ['draw', [0]], ['inspect']], 8), [[]])
    check('explicit sequence 12', solve([['replace', [0]], ['draw', [0]], ['clear'], ['draw', [0, 1]], ['inspect']], 8), [[0]])
    check('explicit sequence 13', solve([['draw', [0]], ['replace', [1]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 8), [[0, 1]])
    check('explicit sequence 14', solve([['replace', []], ['begin'], ['end'], ['draw', [1]], ['inspect']], 8), [[]])
    check('explicit sequence 15', solve([['draw', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], ['inspect']], 8), [[0, 1, 2, 3, 4, 5, 6, 7]])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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)
    coverage=set()
    stack=[]
    out=[]
    for cmd in commands:
        op=cmd[0]
        if op=='clip': clip &= set(cmd[1])
        elif op=='replace': clip=set(cmd[1]) & full
        elif op=='begin':
            stack.append((set(clip),set(coverage)))
            clip=set(full)
            coverage=set()
        elif op=='draw': coverage |= set(cmd[1]) & clip
        elif op=='clear': coverage.clear()
        elif op=='end' and stack:
            parent_clip,parent_coverage=stack.pop()
            coverage=parent_coverage | (coverage & clip)
            clip=parent_clip
        elif op=='discard' and stack: clip,coverage=stack.pop()
        elif op=='inspect': out.append(sorted(coverage))
    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]], ['begin'], ['draw', [1]], ['inspect'], ['end'], ['inspect']], 4), [[1], []])
    check('explicit sequence 1', solve([['draw', [0]], ['begin'], ['inspect']], 4), [[]])
    check('explicit sequence 2', solve([['begin'], ['draw', [0]], ['draw', [1]], ['inspect']], 4), [[0, 1]])
    check('explicit sequence 3', solve([['begin'], ['replace', [1]], ['draw', [0, 1]], ['inspect']], 4), [[1]])
    check('explicit sequence 4', solve([['begin'], ['draw', [0]], ['clear'], ['draw', [1]], ['inspect']], 4), [[1]])
    check('explicit sequence 5', solve([['replace', [0]], ['begin'], ['draw', [0, 1]], ['end'], ['inspect']], 4), [[0]])
    check('explicit sequence 6', solve([['draw', [0]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 4), [[0, 1]])
    check('explicit sequence 7', solve([['replace', [0]], ['begin'], ['end'], ['draw', [1]], ['inspect']], 4), [[]])
    check('explicit sequence 8', solve([['draw', [0]], ['begin'], ['draw', [1]], ['discard'], ['inspect']], 4), [[0]])
    check('explicit sequence 9', solve([['replace', [0, 1]], ['draw', [0]], ['begin'], ['replace', [1]], ['begin'], ['draw', [1, 2]], ['end'], ['inspect'], ['end'], ['inspect']], 4), [[1], [0, 1]])
    check('explicit sequence 10', solve([['draw', [0]], ['draw', [0, 1]], ['inspect']], 4), [[0, 1]])
    check('explicit sequence 11', solve([['replace', []], ['draw', [0]], ['inspect']], 4), [[]])
    check('explicit sequence 12', solve([['replace', [0]], ['draw', [0]], ['clear'], ['draw', [0, 1]], ['inspect']], 4), [[0]])
    check('explicit sequence 13', solve([['draw', [0]], ['replace', [1]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 4), [[0, 1]])
    check('explicit sequence 14', solve([['replace', []], ['begin'], ['end'], ['draw', [1]], ['inspect']], 4), [[]])
    check('explicit sequence 15', solve([['draw', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], ['inspect']], 4), [[0, 1, 2, 3]])
if N == 2:
    check('explicit sequence 0', solve([['replace', [0]], ['begin'], ['draw', [1]], ['inspect'], ['end'], ['inspect']], 5), [[1], []])
    check('explicit sequence 1', solve([['draw', [0]], ['begin'], ['inspect']], 5), [[]])
    check('explicit sequence 2', solve([['begin'], ['draw', [0]], ['draw', [1]], ['inspect']], 5), [[0, 1]])
    check('explicit sequence 3', solve([['begin'], ['replace', [1]], ['draw', [0, 1]], ['inspect']], 5), [[1]])
    check('explicit sequence 4', solve([['begin'], ['draw', [0]], ['clear'], ['draw', [1]], ['inspect']], 5), [[1]])
    check('explicit sequence 5', solve([['replace', [0]], ['begin'], ['draw', [0, 1]], ['end'], ['inspect']], 5), [[0]])
    check('explicit sequence 6', solve([['draw', [0]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 5), [[0, 1]])
    check('explicit sequence 7', solve([['replace', [0]], ['begin'], ['end'], ['draw', [1]], ['inspect']], 5), [[]])
    check('explicit sequence 8', solve([['draw', [0]], ['begin'], ['draw', [1]], ['discard'], ['inspect']], 5), [[0]])
    check('explicit sequence 9', solve([['replace', [0, 1]], ['draw', [0]], ['begin'], ['replace', [1]], ['begin'], ['draw', [1, 2]], ['end'], ['inspect'], ['end'], ['inspect']], 5), [[1], [0, 1]])
    check('explicit sequence 10', solve([['draw', [0]], ['draw', [0, 1]], ['inspect']], 5), [[0, 1]])
    check('explicit sequence 11', solve([['replace', []], ['draw', [0]], ['inspect']], 5), [[]])
    check('explicit sequence 12', solve([['replace', [0]], ['draw', [0]], ['clear'], ['draw', [0, 1]], ['inspect']], 5), [[0]])
    check('explicit sequence 13', solve([['draw', [0]], ['replace', [1]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 5), [[0, 1]])
    check('explicit sequence 14', solve([['replace', []], ['begin'], ['end'], ['draw', [1]], ['inspect']], 5), [[]])
    check('explicit sequence 15', solve([['draw', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], ['inspect']], 5), [[0, 1, 2, 3, 4]])
if N == 3:
    check('explicit sequence 0', solve([['replace', [0]], ['begin'], ['draw', [1]], ['inspect'], ['end'], ['inspect']], 6), [[1], []])
    check('explicit sequence 1', solve([['draw', [0]], ['begin'], ['inspect']], 6), [[]])
    check('explicit sequence 2', solve([['begin'], ['draw', [0]], ['draw', [1]], ['inspect']], 6), [[0, 1]])
    check('explicit sequence 3', solve([['begin'], ['replace', [1]], ['draw', [0, 1]], ['inspect']], 6), [[1]])
    check('explicit sequence 4', solve([['begin'], ['draw', [0]], ['clear'], ['draw', [1]], ['inspect']], 6), [[1]])
    check('explicit sequence 5', solve([['replace', [0]], ['begin'], ['draw', [0, 1]], ['end'], ['inspect']], 6), [[0]])
    check('explicit sequence 6', solve([['draw', [0]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 6), [[0, 1]])
    check('explicit sequence 7', solve([['replace', [0]], ['begin'], ['end'], ['draw', [1]], ['inspect']], 6), [[]])
    check('explicit sequence 8', solve([['draw', [0]], ['begin'], ['draw', [1]], ['discard'], ['inspect']], 6), [[0]])
    check('explicit sequence 9', solve([['replace', [0, 1]], ['draw', [0]], ['begin'], ['replace', [1]], ['begin'], ['draw', [1, 2]], ['end'], ['inspect'], ['end'], ['inspect']], 6), [[1], [0, 1]])
    check('explicit sequence 10', solve([['draw', [0]], ['draw', [0, 1]], ['inspect']], 6), [[0, 1]])
    check('explicit sequence 11', solve([['replace', []], ['draw', [0]], ['inspect']], 6), [[]])
    check('explicit sequence 12', solve([['replace', [0]], ['draw', [0]], ['clear'], ['draw', [0, 1]], ['inspect']], 6), [[0]])
    check('explicit sequence 13', solve([['draw', [0]], ['replace', [1]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 6), [[0, 1]])
    check('explicit sequence 14', solve([['replace', []], ['begin'], ['end'], ['draw', [1]], ['inspect']], 6), [[]])
    check('explicit sequence 15', solve([['draw', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], ['inspect']], 6), [[0, 1, 2, 3, 4, 5]])
if N == 4:
    check('explicit sequence 0', solve([['replace', [0]], ['begin'], ['draw', [1]], ['inspect'], ['end'], ['inspect']], 7), [[1], []])
    check('explicit sequence 1', solve([['draw', [0]], ['begin'], ['inspect']], 7), [[]])
    check('explicit sequence 2', solve([['begin'], ['draw', [0]], ['draw', [1]], ['inspect']], 7), [[0, 1]])
    check('explicit sequence 3', solve([['begin'], ['replace', [1]], ['draw', [0, 1]], ['inspect']], 7), [[1]])
    check('explicit sequence 4', solve([['begin'], ['draw', [0]], ['clear'], ['draw', [1]], ['inspect']], 7), [[1]])
    check('explicit sequence 5', solve([['replace', [0]], ['begin'], ['draw', [0, 1]], ['end'], ['inspect']], 7), [[0]])
    check('explicit sequence 6', solve([['draw', [0]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 7), [[0, 1]])
    check('explicit sequence 7', solve([['replace', [0]], ['begin'], ['end'], ['draw', [1]], ['inspect']], 7), [[]])
    check('explicit sequence 8', solve([['draw', [0]], ['begin'], ['draw', [1]], ['discard'], ['inspect']], 7), [[0]])
    check('explicit sequence 9', solve([['replace', [0, 1]], ['draw', [0]], ['begin'], ['replace', [1]], ['begin'], ['draw', [1, 2]], ['end'], ['inspect'], ['end'], ['inspect']], 7), [[1], [0, 1]])
    check('explicit sequence 10', solve([['draw', [0]], ['draw', [0, 1]], ['inspect']], 7), [[0, 1]])
    check('explicit sequence 11', solve([['replace', []], ['draw', [0]], ['inspect']], 7), [[]])
    check('explicit sequence 12', solve([['replace', [0]], ['draw', [0]], ['clear'], ['draw', [0, 1]], ['inspect']], 7), [[0]])
    check('explicit sequence 13', solve([['draw', [0]], ['replace', [1]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 7), [[0, 1]])
    check('explicit sequence 14', solve([['replace', []], ['begin'], ['end'], ['draw', [1]], ['inspect']], 7), [[]])
    check('explicit sequence 15', solve([['draw', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], ['inspect']], 7), [[0, 1, 2, 3, 4, 5, 6]])
if N == 5:
    check('explicit sequence 0', solve([['replace', [0]], ['begin'], ['draw', [1]], ['inspect'], ['end'], ['inspect']], 8), [[1], []])
    check('explicit sequence 1', solve([['draw', [0]], ['begin'], ['inspect']], 8), [[]])
    check('explicit sequence 2', solve([['begin'], ['draw', [0]], ['draw', [1]], ['inspect']], 8), [[0, 1]])
    check('explicit sequence 3', solve([['begin'], ['replace', [1]], ['draw', [0, 1]], ['inspect']], 8), [[1]])
    check('explicit sequence 4', solve([['begin'], ['draw', [0]], ['clear'], ['draw', [1]], ['inspect']], 8), [[1]])
    check('explicit sequence 5', solve([['replace', [0]], ['begin'], ['draw', [0, 1]], ['end'], ['inspect']], 8), [[0]])
    check('explicit sequence 6', solve([['draw', [0]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 8), [[0, 1]])
    check('explicit sequence 7', solve([['replace', [0]], ['begin'], ['end'], ['draw', [1]], ['inspect']], 8), [[]])
    check('explicit sequence 8', solve([['draw', [0]], ['begin'], ['draw', [1]], ['discard'], ['inspect']], 8), [[0]])
    check('explicit sequence 9', solve([['replace', [0, 1]], ['draw', [0]], ['begin'], ['replace', [1]], ['begin'], ['draw', [1, 2]], ['end'], ['inspect'], ['end'], ['inspect']], 8), [[1], [0, 1]])
    check('explicit sequence 10', solve([['draw', [0]], ['draw', [0, 1]], ['inspect']], 8), [[0, 1]])
    check('explicit sequence 11', solve([['replace', []], ['draw', [0]], ['inspect']], 8), [[]])
    check('explicit sequence 12', solve([['replace', [0]], ['draw', [0]], ['clear'], ['draw', [0, 1]], ['inspect']], 8), [[0]])
    check('explicit sequence 13', solve([['draw', [0]], ['replace', [1]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 8), [[0, 1]])
    check('explicit sequence 14', solve([['replace', []], ['begin'], ['end'], ['draw', [1]], ['inspect']], 8), [[]])
    check('explicit sequence 15', solve([['draw', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], ['inspect']], 8), [[0, 1, 2, 3, 4, 5, 6, 7]])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Layer composition publishes child coverage outside the saved parent clip.

A layer captures the parent clip and starts with its own full local clip. Child drawing accumulates coverage in that layer; layer completion intersects child coverage with the saved parent clip. Discard removes the layer without publishing. A layer-local clear erases only its accumulated coverage. Parent clip edits after opening cannot change the captured parent clip.

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)
    coverage=set()
    stack=[]
    out=[]
    for cmd in commands:
        op=cmd[0]
        if op=='clip': clip &= set(cmd[1])
        elif op=='replace': clip=set(cmd[1]) & full
        elif op=='begin':
            stack.append((set(clip),set(coverage)))
            clip=set(full)
            coverage=set()
        elif op=='draw': coverage |= set(cmd[1]) & clip
        elif op=='clear': coverage.clear()
        elif op=='end' and stack:
            parent_clip,parent_coverage=stack.pop()
            coverage=coverage & parent_clip
            clip=parent_clip
        elif op=='discard' and stack: clip,coverage=stack.pop()
        elif op=='inspect': out.append(sorted(coverage))
    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]], ['begin'], ['draw', [1]], ['inspect'], ['end'], ['inspect']], 4), [[1], []])
    check('explicit sequence 1', solve([['draw', [0]], ['begin'], ['inspect']], 4), [[]])
    check('explicit sequence 2', solve([['begin'], ['draw', [0]], ['draw', [1]], ['inspect']], 4), [[0, 1]])
    check('explicit sequence 3', solve([['begin'], ['replace', [1]], ['draw', [0, 1]], ['inspect']], 4), [[1]])
    check('explicit sequence 4', solve([['begin'], ['draw', [0]], ['clear'], ['draw', [1]], ['inspect']], 4), [[1]])
    check('explicit sequence 5', solve([['replace', [0]], ['begin'], ['draw', [0, 1]], ['end'], ['inspect']], 4), [[0]])
    check('explicit sequence 6', solve([['draw', [0]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 4), [[0, 1]])
    check('explicit sequence 7', solve([['replace', [0]], ['begin'], ['end'], ['draw', [1]], ['inspect']], 4), [[]])
    check('explicit sequence 8', solve([['draw', [0]], ['begin'], ['draw', [1]], ['discard'], ['inspect']], 4), [[0]])
    check('explicit sequence 9', solve([['replace', [0, 1]], ['draw', [0]], ['begin'], ['replace', [1]], ['begin'], ['draw', [1, 2]], ['end'], ['inspect'], ['end'], ['inspect']], 4), [[1], [0, 1]])
    check('explicit sequence 10', solve([['draw', [0]], ['draw', [0, 1]], ['inspect']], 4), [[0, 1]])
    check('explicit sequence 11', solve([['replace', []], ['draw', [0]], ['inspect']], 4), [[]])
    check('explicit sequence 12', solve([['replace', [0]], ['draw', [0]], ['clear'], ['draw', [0, 1]], ['inspect']], 4), [[0]])
    check('explicit sequence 13', solve([['draw', [0]], ['replace', [1]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 4), [[0, 1]])
    check('explicit sequence 14', solve([['replace', []], ['begin'], ['end'], ['draw', [1]], ['inspect']], 4), [[]])
    check('explicit sequence 15', solve([['draw', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], ['inspect']], 4), [[0, 1, 2, 3]])
if N == 2:
    check('explicit sequence 0', solve([['replace', [0]], ['begin'], ['draw', [1]], ['inspect'], ['end'], ['inspect']], 5), [[1], []])
    check('explicit sequence 1', solve([['draw', [0]], ['begin'], ['inspect']], 5), [[]])
    check('explicit sequence 2', solve([['begin'], ['draw', [0]], ['draw', [1]], ['inspect']], 5), [[0, 1]])
    check('explicit sequence 3', solve([['begin'], ['replace', [1]], ['draw', [0, 1]], ['inspect']], 5), [[1]])
    check('explicit sequence 4', solve([['begin'], ['draw', [0]], ['clear'], ['draw', [1]], ['inspect']], 5), [[1]])
    check('explicit sequence 5', solve([['replace', [0]], ['begin'], ['draw', [0, 1]], ['end'], ['inspect']], 5), [[0]])
    check('explicit sequence 6', solve([['draw', [0]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 5), [[0, 1]])
    check('explicit sequence 7', solve([['replace', [0]], ['begin'], ['end'], ['draw', [1]], ['inspect']], 5), [[]])
    check('explicit sequence 8', solve([['draw', [0]], ['begin'], ['draw', [1]], ['discard'], ['inspect']], 5), [[0]])
    check('explicit sequence 9', solve([['replace', [0, 1]], ['draw', [0]], ['begin'], ['replace', [1]], ['begin'], ['draw', [1, 2]], ['end'], ['inspect'], ['end'], ['inspect']], 5), [[1], [0, 1]])
    check('explicit sequence 10', solve([['draw', [0]], ['draw', [0, 1]], ['inspect']], 5), [[0, 1]])
    check('explicit sequence 11', solve([['replace', []], ['draw', [0]], ['inspect']], 5), [[]])
    check('explicit sequence 12', solve([['replace', [0]], ['draw', [0]], ['clear'], ['draw', [0, 1]], ['inspect']], 5), [[0]])
    check('explicit sequence 13', solve([['draw', [0]], ['replace', [1]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 5), [[0, 1]])
    check('explicit sequence 14', solve([['replace', []], ['begin'], ['end'], ['draw', [1]], ['inspect']], 5), [[]])
    check('explicit sequence 15', solve([['draw', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], ['inspect']], 5), [[0, 1, 2, 3, 4]])
if N == 3:
    check('explicit sequence 0', solve([['replace', [0]], ['begin'], ['draw', [1]], ['inspect'], ['end'], ['inspect']], 6), [[1], []])
    check('explicit sequence 1', solve([['draw', [0]], ['begin'], ['inspect']], 6), [[]])
    check('explicit sequence 2', solve([['begin'], ['draw', [0]], ['draw', [1]], ['inspect']], 6), [[0, 1]])
    check('explicit sequence 3', solve([['begin'], ['replace', [1]], ['draw', [0, 1]], ['inspect']], 6), [[1]])
    check('explicit sequence 4', solve([['begin'], ['draw', [0]], ['clear'], ['draw', [1]], ['inspect']], 6), [[1]])
    check('explicit sequence 5', solve([['replace', [0]], ['begin'], ['draw', [0, 1]], ['end'], ['inspect']], 6), [[0]])
    check('explicit sequence 6', solve([['draw', [0]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 6), [[0, 1]])
    check('explicit sequence 7', solve([['replace', [0]], ['begin'], ['end'], ['draw', [1]], ['inspect']], 6), [[]])
    check('explicit sequence 8', solve([['draw', [0]], ['begin'], ['draw', [1]], ['discard'], ['inspect']], 6), [[0]])
    check('explicit sequence 9', solve([['replace', [0, 1]], ['draw', [0]], ['begin'], ['replace', [1]], ['begin'], ['draw', [1, 2]], ['end'], ['inspect'], ['end'], ['inspect']], 6), [[1], [0, 1]])
    check('explicit sequence 10', solve([['draw', [0]], ['draw', [0, 1]], ['inspect']], 6), [[0, 1]])
    check('explicit sequence 11', solve([['replace', []], ['draw', [0]], ['inspect']], 6), [[]])
    check('explicit sequence 12', solve([['replace', [0]], ['draw', [0]], ['clear'], ['draw', [0, 1]], ['inspect']], 6), [[0]])
    check('explicit sequence 13', solve([['draw', [0]], ['replace', [1]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 6), [[0, 1]])
    check('explicit sequence 14', solve([['replace', []], ['begin'], ['end'], ['draw', [1]], ['inspect']], 6), [[]])
    check('explicit sequence 15', solve([['draw', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], ['inspect']], 6), [[0, 1, 2, 3, 4, 5]])
if N == 4:
    check('explicit sequence 0', solve([['replace', [0]], ['begin'], ['draw', [1]], ['inspect'], ['end'], ['inspect']], 7), [[1], []])
    check('explicit sequence 1', solve([['draw', [0]], ['begin'], ['inspect']], 7), [[]])
    check('explicit sequence 2', solve([['begin'], ['draw', [0]], ['draw', [1]], ['inspect']], 7), [[0, 1]])
    check('explicit sequence 3', solve([['begin'], ['replace', [1]], ['draw', [0, 1]], ['inspect']], 7), [[1]])
    check('explicit sequence 4', solve([['begin'], ['draw', [0]], ['clear'], ['draw', [1]], ['inspect']], 7), [[1]])
    check('explicit sequence 5', solve([['replace', [0]], ['begin'], ['draw', [0, 1]], ['end'], ['inspect']], 7), [[0]])
    check('explicit sequence 6', solve([['draw', [0]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 7), [[0, 1]])
    check('explicit sequence 7', solve([['replace', [0]], ['begin'], ['end'], ['draw', [1]], ['inspect']], 7), [[]])
    check('explicit sequence 8', solve([['draw', [0]], ['begin'], ['draw', [1]], ['discard'], ['inspect']], 7), [[0]])
    check('explicit sequence 9', solve([['replace', [0, 1]], ['draw', [0]], ['begin'], ['replace', [1]], ['begin'], ['draw', [1, 2]], ['end'], ['inspect'], ['end'], ['inspect']], 7), [[1], [0, 1]])
    check('explicit sequence 10', solve([['draw', [0]], ['draw', [0, 1]], ['inspect']], 7), [[0, 1]])
    check('explicit sequence 11', solve([['replace', []], ['draw', [0]], ['inspect']], 7), [[]])
    check('explicit sequence 12', solve([['replace', [0]], ['draw', [0]], ['clear'], ['draw', [0, 1]], ['inspect']], 7), [[0]])
    check('explicit sequence 13', solve([['draw', [0]], ['replace', [1]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 7), [[0, 1]])
    check('explicit sequence 14', solve([['replace', []], ['begin'], ['end'], ['draw', [1]], ['inspect']], 7), [[]])
    check('explicit sequence 15', solve([['draw', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], ['inspect']], 7), [[0, 1, 2, 3, 4, 5, 6]])
if N == 5:
    check('explicit sequence 0', solve([['replace', [0]], ['begin'], ['draw', [1]], ['inspect'], ['end'], ['inspect']], 8), [[1], []])
    check('explicit sequence 1', solve([['draw', [0]], ['begin'], ['inspect']], 8), [[]])
    check('explicit sequence 2', solve([['begin'], ['draw', [0]], ['draw', [1]], ['inspect']], 8), [[0, 1]])
    check('explicit sequence 3', solve([['begin'], ['replace', [1]], ['draw', [0, 1]], ['inspect']], 8), [[1]])
    check('explicit sequence 4', solve([['begin'], ['draw', [0]], ['clear'], ['draw', [1]], ['inspect']], 8), [[1]])
    check('explicit sequence 5', solve([['replace', [0]], ['begin'], ['draw', [0, 1]], ['end'], ['inspect']], 8), [[0]])
    check('explicit sequence 6', solve([['draw', [0]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 8), [[0, 1]])
    check('explicit sequence 7', solve([['replace', [0]], ['begin'], ['end'], ['draw', [1]], ['inspect']], 8), [[]])
    check('explicit sequence 8', solve([['draw', [0]], ['begin'], ['draw', [1]], ['discard'], ['inspect']], 8), [[0]])
    check('explicit sequence 9', solve([['replace', [0, 1]], ['draw', [0]], ['begin'], ['replace', [1]], ['begin'], ['draw', [1, 2]], ['end'], ['inspect'], ['end'], ['inspect']], 8), [[1], [0, 1]])
    check('explicit sequence 10', solve([['draw', [0]], ['draw', [0, 1]], ['inspect']], 8), [[0, 1]])
    check('explicit sequence 11', solve([['replace', []], ['draw', [0]], ['inspect']], 8), [[]])
    check('explicit sequence 12', solve([['replace', [0]], ['draw', [0]], ['clear'], ['draw', [0, 1]], ['inspect']], 8), [[0]])
    check('explicit sequence 13', solve([['draw', [0]], ['replace', [1]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 8), [[0, 1]])
    check('explicit sequence 14', solve([['replace', []], ['begin'], ['end'], ['draw', [1]], ['inspect']], 8), [[]])
    check('explicit sequence 15', solve([['draw', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], ['inspect']], 8), [[0, 1, 2, 3, 4, 5, 6, 7]])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(commands, size):
    full=set(range(size))
    clip=set(full)
    coverage=set()
    stack=[]
    out=[]
    for cmd in commands:
        op=cmd[0]
        if op=='clip': clip &= set(cmd[1])
        elif op=='replace': clip=set(cmd[1]) & full
        elif op=='begin':
            stack.append((set(clip),set(coverage)))
            clip=set(full)
            coverage=set()
        elif op=='draw': coverage |= set(cmd[1]) & clip
        elif op=='clear': coverage.clear()
        elif op=='end' and stack:
            parent_clip,parent_coverage=stack.pop()
            coverage=(parent_coverage | coverage) & parent_clip
            clip=parent_clip
        elif op=='discard' and stack: clip,coverage=stack.pop()
        elif op=='inspect': out.append(sorted(coverage))
    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]], ['begin'], ['draw', [1]], ['inspect'], ['end'], ['inspect']], 4), [[1], []])
    check('explicit sequence 1', solve([['draw', [0]], ['begin'], ['inspect']], 4), [[]])
    check('explicit sequence 2', solve([['begin'], ['draw', [0]], ['draw', [1]], ['inspect']], 4), [[0, 1]])
    check('explicit sequence 3', solve([['begin'], ['replace', [1]], ['draw', [0, 1]], ['inspect']], 4), [[1]])
    check('explicit sequence 4', solve([['begin'], ['draw', [0]], ['clear'], ['draw', [1]], ['inspect']], 4), [[1]])
    check('explicit sequence 5', solve([['replace', [0]], ['begin'], ['draw', [0, 1]], ['end'], ['inspect']], 4), [[0]])
    check('explicit sequence 6', solve([['draw', [0]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 4), [[0, 1]])
    check('explicit sequence 7', solve([['replace', [0]], ['begin'], ['end'], ['draw', [1]], ['inspect']], 4), [[]])
    check('explicit sequence 8', solve([['draw', [0]], ['begin'], ['draw', [1]], ['discard'], ['inspect']], 4), [[0]])
    check('explicit sequence 9', solve([['replace', [0, 1]], ['draw', [0]], ['begin'], ['replace', [1]], ['begin'], ['draw', [1, 2]], ['end'], ['inspect'], ['end'], ['inspect']], 4), [[1], [0, 1]])
    check('explicit sequence 10', solve([['draw', [0]], ['draw', [0, 1]], ['inspect']], 4), [[0, 1]])
    check('explicit sequence 11', solve([['replace', []], ['draw', [0]], ['inspect']], 4), [[]])
    check('explicit sequence 12', solve([['replace', [0]], ['draw', [0]], ['clear'], ['draw', [0, 1]], ['inspect']], 4), [[0]])
    check('explicit sequence 13', solve([['draw', [0]], ['replace', [1]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 4), [[0, 1]])
    check('explicit sequence 14', solve([['replace', []], ['begin'], ['end'], ['draw', [1]], ['inspect']], 4), [[]])
    check('explicit sequence 15', solve([['draw', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], ['inspect']], 4), [[0, 1, 2, 3]])
if N == 2:
    check('explicit sequence 0', solve([['replace', [0]], ['begin'], ['draw', [1]], ['inspect'], ['end'], ['inspect']], 5), [[1], []])
    check('explicit sequence 1', solve([['draw', [0]], ['begin'], ['inspect']], 5), [[]])
    check('explicit sequence 2', solve([['begin'], ['draw', [0]], ['draw', [1]], ['inspect']], 5), [[0, 1]])
    check('explicit sequence 3', solve([['begin'], ['replace', [1]], ['draw', [0, 1]], ['inspect']], 5), [[1]])
    check('explicit sequence 4', solve([['begin'], ['draw', [0]], ['clear'], ['draw', [1]], ['inspect']], 5), [[1]])
    check('explicit sequence 5', solve([['replace', [0]], ['begin'], ['draw', [0, 1]], ['end'], ['inspect']], 5), [[0]])
    check('explicit sequence 6', solve([['draw', [0]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 5), [[0, 1]])
    check('explicit sequence 7', solve([['replace', [0]], ['begin'], ['end'], ['draw', [1]], ['inspect']], 5), [[]])
    check('explicit sequence 8', solve([['draw', [0]], ['begin'], ['draw', [1]], ['discard'], ['inspect']], 5), [[0]])
    check('explicit sequence 9', solve([['replace', [0, 1]], ['draw', [0]], ['begin'], ['replace', [1]], ['begin'], ['draw', [1, 2]], ['end'], ['inspect'], ['end'], ['inspect']], 5), [[1], [0, 1]])
    check('explicit sequence 10', solve([['draw', [0]], ['draw', [0, 1]], ['inspect']], 5), [[0, 1]])
    check('explicit sequence 11', solve([['replace', []], ['draw', [0]], ['inspect']], 5), [[]])
    check('explicit sequence 12', solve([['replace', [0]], ['draw', [0]], ['clear'], ['draw', [0, 1]], ['inspect']], 5), [[0]])
    check('explicit sequence 13', solve([['draw', [0]], ['replace', [1]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 5), [[0, 1]])
    check('explicit sequence 14', solve([['replace', []], ['begin'], ['end'], ['draw', [1]], ['inspect']], 5), [[]])
    check('explicit sequence 15', solve([['draw', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], ['inspect']], 5), [[0, 1, 2, 3, 4]])
if N == 3:
    check('explicit sequence 0', solve([['replace', [0]], ['begin'], ['draw', [1]], ['inspect'], ['end'], ['inspect']], 6), [[1], []])
    check('explicit sequence 1', solve([['draw', [0]], ['begin'], ['inspect']], 6), [[]])
    check('explicit sequence 2', solve([['begin'], ['draw', [0]], ['draw', [1]], ['inspect']], 6), [[0, 1]])
    check('explicit sequence 3', solve([['begin'], ['replace', [1]], ['draw', [0, 1]], ['inspect']], 6), [[1]])
    check('explicit sequence 4', solve([['begin'], ['draw', [0]], ['clear'], ['draw', [1]], ['inspect']], 6), [[1]])
    check('explicit sequence 5', solve([['replace', [0]], ['begin'], ['draw', [0, 1]], ['end'], ['inspect']], 6), [[0]])
    check('explicit sequence 6', solve([['draw', [0]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 6), [[0, 1]])
    check('explicit sequence 7', solve([['replace', [0]], ['begin'], ['end'], ['draw', [1]], ['inspect']], 6), [[]])
    check('explicit sequence 8', solve([['draw', [0]], ['begin'], ['draw', [1]], ['discard'], ['inspect']], 6), [[0]])
    check('explicit sequence 9', solve([['replace', [0, 1]], ['draw', [0]], ['begin'], ['replace', [1]], ['begin'], ['draw', [1, 2]], ['end'], ['inspect'], ['end'], ['inspect']], 6), [[1], [0, 1]])
    check('explicit sequence 10', solve([['draw', [0]], ['draw', [0, 1]], ['inspect']], 6), [[0, 1]])
    check('explicit sequence 11', solve([['replace', []], ['draw', [0]], ['inspect']], 6), [[]])
    check('explicit sequence 12', solve([['replace', [0]], ['draw', [0]], ['clear'], ['draw', [0, 1]], ['inspect']], 6), [[0]])
    check('explicit sequence 13', solve([['draw', [0]], ['replace', [1]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 6), [[0, 1]])
    check('explicit sequence 14', solve([['replace', []], ['begin'], ['end'], ['draw', [1]], ['inspect']], 6), [[]])
    check('explicit sequence 15', solve([['draw', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], ['inspect']], 6), [[0, 1, 2, 3, 4, 5]])
if N == 4:
    check('explicit sequence 0', solve([['replace', [0]], ['begin'], ['draw', [1]], ['inspect'], ['end'], ['inspect']], 7), [[1], []])
    check('explicit sequence 1', solve([['draw', [0]], ['begin'], ['inspect']], 7), [[]])
    check('explicit sequence 2', solve([['begin'], ['draw', [0]], ['draw', [1]], ['inspect']], 7), [[0, 1]])
    check('explicit sequence 3', solve([['begin'], ['replace', [1]], ['draw', [0, 1]], ['inspect']], 7), [[1]])
    check('explicit sequence 4', solve([['begin'], ['draw', [0]], ['clear'], ['draw', [1]], ['inspect']], 7), [[1]])
    check('explicit sequence 5', solve([['replace', [0]], ['begin'], ['draw', [0, 1]], ['end'], ['inspect']], 7), [[0]])
    check('explicit sequence 6', solve([['draw', [0]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 7), [[0, 1]])
    check('explicit sequence 7', solve([['replace', [0]], ['begin'], ['end'], ['draw', [1]], ['inspect']], 7), [[]])
    check('explicit sequence 8', solve([['draw', [0]], ['begin'], ['draw', [1]], ['discard'], ['inspect']], 7), [[0]])
    check('explicit sequence 9', solve([['replace', [0, 1]], ['draw', [0]], ['begin'], ['replace', [1]], ['begin'], ['draw', [1, 2]], ['end'], ['inspect'], ['end'], ['inspect']], 7), [[1], [0, 1]])
    check('explicit sequence 10', solve([['draw', [0]], ['draw', [0, 1]], ['inspect']], 7), [[0, 1]])
    check('explicit sequence 11', solve([['replace', []], ['draw', [0]], ['inspect']], 7), [[]])
    check('explicit sequence 12', solve([['replace', [0]], ['draw', [0]], ['clear'], ['draw', [0, 1]], ['inspect']], 7), [[0]])
    check('explicit sequence 13', solve([['draw', [0]], ['replace', [1]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 7), [[0, 1]])
    check('explicit sequence 14', solve([['replace', []], ['begin'], ['end'], ['draw', [1]], ['inspect']], 7), [[]])
    check('explicit sequence 15', solve([['draw', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], ['inspect']], 7), [[0, 1, 2, 3, 4, 5, 6]])
if N == 5:
    check('explicit sequence 0', solve([['replace', [0]], ['begin'], ['draw', [1]], ['inspect'], ['end'], ['inspect']], 8), [[1], []])
    check('explicit sequence 1', solve([['draw', [0]], ['begin'], ['inspect']], 8), [[]])
    check('explicit sequence 2', solve([['begin'], ['draw', [0]], ['draw', [1]], ['inspect']], 8), [[0, 1]])
    check('explicit sequence 3', solve([['begin'], ['replace', [1]], ['draw', [0, 1]], ['inspect']], 8), [[1]])
    check('explicit sequence 4', solve([['begin'], ['draw', [0]], ['clear'], ['draw', [1]], ['inspect']], 8), [[1]])
    check('explicit sequence 5', solve([['replace', [0]], ['begin'], ['draw', [0, 1]], ['end'], ['inspect']], 8), [[0]])
    check('explicit sequence 6', solve([['draw', [0]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 8), [[0, 1]])
    check('explicit sequence 7', solve([['replace', [0]], ['begin'], ['end'], ['draw', [1]], ['inspect']], 8), [[]])
    check('explicit sequence 8', solve([['draw', [0]], ['begin'], ['draw', [1]], ['discard'], ['inspect']], 8), [[0]])
    check('explicit sequence 9', solve([['replace', [0, 1]], ['draw', [0]], ['begin'], ['replace', [1]], ['begin'], ['draw', [1, 2]], ['end'], ['inspect'], ['end'], ['inspect']], 8), [[1], [0, 1]])
    check('explicit sequence 10', solve([['draw', [0]], ['draw', [0, 1]], ['inspect']], 8), [[0, 1]])
    check('explicit sequence 11', solve([['replace', []], ['draw', [0]], ['inspect']], 8), [[]])
    check('explicit sequence 12', solve([['replace', [0]], ['draw', [0]], ['clear'], ['draw', [0, 1]], ['inspect']], 8), [[0]])
    check('explicit sequence 13', solve([['draw', [0]], ['replace', [1]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 8), [[0, 1]])
    check('explicit sequence 14', solve([['replace', []], ['begin'], ['end'], ['draw', [1]], ['inspect']], 8), [[]])
    check('explicit sequence 15', solve([['draw', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], ['inspect']], 8), [[0, 1, 2, 3, 4, 5, 6, 7]])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Resolving a child replaces previously drawn parent samples.

A layer captures the parent clip and starts with its own full local clip. Child drawing accumulates coverage in that layer; layer completion intersects child coverage with the saved parent clip. Discard removes the layer without publishing. A layer-local clear erases only its accumulated coverage. Parent clip edits after opening cannot change the captured parent clip.

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)
    coverage=set()
    stack=[]
    out=[]
    for cmd in commands:
        op=cmd[0]
        if op=='clip': clip &= set(cmd[1])
        elif op=='replace': clip=set(cmd[1]) & full
        elif op=='begin':
            stack.append((set(clip),set(coverage)))
            clip=set(full)
            coverage=set()
        elif op=='draw': coverage |= set(cmd[1]) & clip
        elif op=='clear': coverage.clear()
        elif op=='end' and stack:
            parent_clip,parent_coverage=stack.pop()
            coverage=parent_coverage | (coverage & parent_clip)
            clip=set(full)
        elif op=='discard' and stack: clip,coverage=stack.pop()
        elif op=='inspect': out.append(sorted(coverage))
    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]], ['begin'], ['draw', [1]], ['inspect'], ['end'], ['inspect']], 4), [[1], []])
    check('explicit sequence 1', solve([['draw', [0]], ['begin'], ['inspect']], 4), [[]])
    check('explicit sequence 2', solve([['begin'], ['draw', [0]], ['draw', [1]], ['inspect']], 4), [[0, 1]])
    check('explicit sequence 3', solve([['begin'], ['replace', [1]], ['draw', [0, 1]], ['inspect']], 4), [[1]])
    check('explicit sequence 4', solve([['begin'], ['draw', [0]], ['clear'], ['draw', [1]], ['inspect']], 4), [[1]])
    check('explicit sequence 5', solve([['replace', [0]], ['begin'], ['draw', [0, 1]], ['end'], ['inspect']], 4), [[0]])
    check('explicit sequence 6', solve([['draw', [0]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 4), [[0, 1]])
    check('explicit sequence 7', solve([['replace', [0]], ['begin'], ['end'], ['draw', [1]], ['inspect']], 4), [[]])
    check('explicit sequence 8', solve([['draw', [0]], ['begin'], ['draw', [1]], ['discard'], ['inspect']], 4), [[0]])
    check('explicit sequence 9', solve([['replace', [0, 1]], ['draw', [0]], ['begin'], ['replace', [1]], ['begin'], ['draw', [1, 2]], ['end'], ['inspect'], ['end'], ['inspect']], 4), [[1], [0, 1]])
    check('explicit sequence 10', solve([['draw', [0]], ['draw', [0, 1]], ['inspect']], 4), [[0, 1]])
    check('explicit sequence 11', solve([['replace', []], ['draw', [0]], ['inspect']], 4), [[]])
    check('explicit sequence 12', solve([['replace', [0]], ['draw', [0]], ['clear'], ['draw', [0, 1]], ['inspect']], 4), [[0]])
    check('explicit sequence 13', solve([['draw', [0]], ['replace', [1]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 4), [[0, 1]])
    check('explicit sequence 14', solve([['replace', []], ['begin'], ['end'], ['draw', [1]], ['inspect']], 4), [[]])
    check('explicit sequence 15', solve([['draw', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], ['inspect']], 4), [[0, 1, 2, 3]])
if N == 2:
    check('explicit sequence 0', solve([['replace', [0]], ['begin'], ['draw', [1]], ['inspect'], ['end'], ['inspect']], 5), [[1], []])
    check('explicit sequence 1', solve([['draw', [0]], ['begin'], ['inspect']], 5), [[]])
    check('explicit sequence 2', solve([['begin'], ['draw', [0]], ['draw', [1]], ['inspect']], 5), [[0, 1]])
    check('explicit sequence 3', solve([['begin'], ['replace', [1]], ['draw', [0, 1]], ['inspect']], 5), [[1]])
    check('explicit sequence 4', solve([['begin'], ['draw', [0]], ['clear'], ['draw', [1]], ['inspect']], 5), [[1]])
    check('explicit sequence 5', solve([['replace', [0]], ['begin'], ['draw', [0, 1]], ['end'], ['inspect']], 5), [[0]])
    check('explicit sequence 6', solve([['draw', [0]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 5), [[0, 1]])
    check('explicit sequence 7', solve([['replace', [0]], ['begin'], ['end'], ['draw', [1]], ['inspect']], 5), [[]])
    check('explicit sequence 8', solve([['draw', [0]], ['begin'], ['draw', [1]], ['discard'], ['inspect']], 5), [[0]])
    check('explicit sequence 9', solve([['replace', [0, 1]], ['draw', [0]], ['begin'], ['replace', [1]], ['begin'], ['draw', [1, 2]], ['end'], ['inspect'], ['end'], ['inspect']], 5), [[1], [0, 1]])
    check('explicit sequence 10', solve([['draw', [0]], ['draw', [0, 1]], ['inspect']], 5), [[0, 1]])
    check('explicit sequence 11', solve([['replace', []], ['draw', [0]], ['inspect']], 5), [[]])
    check('explicit sequence 12', solve([['replace', [0]], ['draw', [0]], ['clear'], ['draw', [0, 1]], ['inspect']], 5), [[0]])
    check('explicit sequence 13', solve([['draw', [0]], ['replace', [1]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 5), [[0, 1]])
    check('explicit sequence 14', solve([['replace', []], ['begin'], ['end'], ['draw', [1]], ['inspect']], 5), [[]])
    check('explicit sequence 15', solve([['draw', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], ['inspect']], 5), [[0, 1, 2, 3, 4]])
if N == 3:
    check('explicit sequence 0', solve([['replace', [0]], ['begin'], ['draw', [1]], ['inspect'], ['end'], ['inspect']], 6), [[1], []])
    check('explicit sequence 1', solve([['draw', [0]], ['begin'], ['inspect']], 6), [[]])
    check('explicit sequence 2', solve([['begin'], ['draw', [0]], ['draw', [1]], ['inspect']], 6), [[0, 1]])
    check('explicit sequence 3', solve([['begin'], ['replace', [1]], ['draw', [0, 1]], ['inspect']], 6), [[1]])
    check('explicit sequence 4', solve([['begin'], ['draw', [0]], ['clear'], ['draw', [1]], ['inspect']], 6), [[1]])
    check('explicit sequence 5', solve([['replace', [0]], ['begin'], ['draw', [0, 1]], ['end'], ['inspect']], 6), [[0]])
    check('explicit sequence 6', solve([['draw', [0]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 6), [[0, 1]])
    check('explicit sequence 7', solve([['replace', [0]], ['begin'], ['end'], ['draw', [1]], ['inspect']], 6), [[]])
    check('explicit sequence 8', solve([['draw', [0]], ['begin'], ['draw', [1]], ['discard'], ['inspect']], 6), [[0]])
    check('explicit sequence 9', solve([['replace', [0, 1]], ['draw', [0]], ['begin'], ['replace', [1]], ['begin'], ['draw', [1, 2]], ['end'], ['inspect'], ['end'], ['inspect']], 6), [[1], [0, 1]])
    check('explicit sequence 10', solve([['draw', [0]], ['draw', [0, 1]], ['inspect']], 6), [[0, 1]])
    check('explicit sequence 11', solve([['replace', []], ['draw', [0]], ['inspect']], 6), [[]])
    check('explicit sequence 12', solve([['replace', [0]], ['draw', [0]], ['clear'], ['draw', [0, 1]], ['inspect']], 6), [[0]])
    check('explicit sequence 13', solve([['draw', [0]], ['replace', [1]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 6), [[0, 1]])
    check('explicit sequence 14', solve([['replace', []], ['begin'], ['end'], ['draw', [1]], ['inspect']], 6), [[]])
    check('explicit sequence 15', solve([['draw', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], ['inspect']], 6), [[0, 1, 2, 3, 4, 5]])
if N == 4:
    check('explicit sequence 0', solve([['replace', [0]], ['begin'], ['draw', [1]], ['inspect'], ['end'], ['inspect']], 7), [[1], []])
    check('explicit sequence 1', solve([['draw', [0]], ['begin'], ['inspect']], 7), [[]])
    check('explicit sequence 2', solve([['begin'], ['draw', [0]], ['draw', [1]], ['inspect']], 7), [[0, 1]])
    check('explicit sequence 3', solve([['begin'], ['replace', [1]], ['draw', [0, 1]], ['inspect']], 7), [[1]])
    check('explicit sequence 4', solve([['begin'], ['draw', [0]], ['clear'], ['draw', [1]], ['inspect']], 7), [[1]])
    check('explicit sequence 5', solve([['replace', [0]], ['begin'], ['draw', [0, 1]], ['end'], ['inspect']], 7), [[0]])
    check('explicit sequence 6', solve([['draw', [0]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 7), [[0, 1]])
    check('explicit sequence 7', solve([['replace', [0]], ['begin'], ['end'], ['draw', [1]], ['inspect']], 7), [[]])
    check('explicit sequence 8', solve([['draw', [0]], ['begin'], ['draw', [1]], ['discard'], ['inspect']], 7), [[0]])
    check('explicit sequence 9', solve([['replace', [0, 1]], ['draw', [0]], ['begin'], ['replace', [1]], ['begin'], ['draw', [1, 2]], ['end'], ['inspect'], ['end'], ['inspect']], 7), [[1], [0, 1]])
    check('explicit sequence 10', solve([['draw', [0]], ['draw', [0, 1]], ['inspect']], 7), [[0, 1]])
    check('explicit sequence 11', solve([['replace', []], ['draw', [0]], ['inspect']], 7), [[]])
    check('explicit sequence 12', solve([['replace', [0]], ['draw', [0]], ['clear'], ['draw', [0, 1]], ['inspect']], 7), [[0]])
    check('explicit sequence 13', solve([['draw', [0]], ['replace', [1]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 7), [[0, 1]])
    check('explicit sequence 14', solve([['replace', []], ['begin'], ['end'], ['draw', [1]], ['inspect']], 7), [[]])
    check('explicit sequence 15', solve([['draw', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], ['inspect']], 7), [[0, 1, 2, 3, 4, 5, 6]])
if N == 5:
    check('explicit sequence 0', solve([['replace', [0]], ['begin'], ['draw', [1]], ['inspect'], ['end'], ['inspect']], 8), [[1], []])
    check('explicit sequence 1', solve([['draw', [0]], ['begin'], ['inspect']], 8), [[]])
    check('explicit sequence 2', solve([['begin'], ['draw', [0]], ['draw', [1]], ['inspect']], 8), [[0, 1]])
    check('explicit sequence 3', solve([['begin'], ['replace', [1]], ['draw', [0, 1]], ['inspect']], 8), [[1]])
    check('explicit sequence 4', solve([['begin'], ['draw', [0]], ['clear'], ['draw', [1]], ['inspect']], 8), [[1]])
    check('explicit sequence 5', solve([['replace', [0]], ['begin'], ['draw', [0, 1]], ['end'], ['inspect']], 8), [[0]])
    check('explicit sequence 6', solve([['draw', [0]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 8), [[0, 1]])
    check('explicit sequence 7', solve([['replace', [0]], ['begin'], ['end'], ['draw', [1]], ['inspect']], 8), [[]])
    check('explicit sequence 8', solve([['draw', [0]], ['begin'], ['draw', [1]], ['discard'], ['inspect']], 8), [[0]])
    check('explicit sequence 9', solve([['replace', [0, 1]], ['draw', [0]], ['begin'], ['replace', [1]], ['begin'], ['draw', [1, 2]], ['end'], ['inspect'], ['end'], ['inspect']], 8), [[1], [0, 1]])
    check('explicit sequence 10', solve([['draw', [0]], ['draw', [0, 1]], ['inspect']], 8), [[0, 1]])
    check('explicit sequence 11', solve([['replace', []], ['draw', [0]], ['inspect']], 8), [[]])
    check('explicit sequence 12', solve([['replace', [0]], ['draw', [0]], ['clear'], ['draw', [0, 1]], ['inspect']], 8), [[0]])
    check('explicit sequence 13', solve([['draw', [0]], ['replace', [1]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 8), [[0, 1]])
    check('explicit sequence 14', solve([['replace', []], ['begin'], ['end'], ['draw', [1]], ['inspect']], 8), [[]])
    check('explicit sequence 15', solve([['draw', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], ['inspect']], 8), [[0, 1, 2, 3, 4, 5, 6, 7]])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(commands, size):
    full=set(range(size))
    clip=set(full)
    coverage=set()
    stack=[]
    out=[]
    for cmd in commands:
        op=cmd[0]
        if op=='clip': clip &= set(cmd[1])
        elif op=='replace': clip=set(cmd[1]) & full
        elif op=='begin':
            stack.append((set(clip),set(coverage)))
            clip=set(full)
            coverage=set()
        elif op=='draw': coverage |= set(cmd[1]) & clip
        elif op=='clear': coverage.clear()
        elif op=='end' and stack:
            parent_clip,parent_coverage=stack.pop()
            coverage=parent_coverage | (coverage & parent_clip)
            clip=parent_clip if parent_clip else full
        elif op=='discard' and stack: clip,coverage=stack.pop()
        elif op=='inspect': out.append(sorted(coverage))
    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]], ['begin'], ['draw', [1]], ['inspect'], ['end'], ['inspect']], 4), [[1], []])
    check('explicit sequence 1', solve([['draw', [0]], ['begin'], ['inspect']], 4), [[]])
    check('explicit sequence 2', solve([['begin'], ['draw', [0]], ['draw', [1]], ['inspect']], 4), [[0, 1]])
    check('explicit sequence 3', solve([['begin'], ['replace', [1]], ['draw', [0, 1]], ['inspect']], 4), [[1]])
    check('explicit sequence 4', solve([['begin'], ['draw', [0]], ['clear'], ['draw', [1]], ['inspect']], 4), [[1]])
    check('explicit sequence 5', solve([['replace', [0]], ['begin'], ['draw', [0, 1]], ['end'], ['inspect']], 4), [[0]])
    check('explicit sequence 6', solve([['draw', [0]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 4), [[0, 1]])
    check('explicit sequence 7', solve([['replace', [0]], ['begin'], ['end'], ['draw', [1]], ['inspect']], 4), [[]])
    check('explicit sequence 8', solve([['draw', [0]], ['begin'], ['draw', [1]], ['discard'], ['inspect']], 4), [[0]])
    check('explicit sequence 9', solve([['replace', [0, 1]], ['draw', [0]], ['begin'], ['replace', [1]], ['begin'], ['draw', [1, 2]], ['end'], ['inspect'], ['end'], ['inspect']], 4), [[1], [0, 1]])
    check('explicit sequence 10', solve([['draw', [0]], ['draw', [0, 1]], ['inspect']], 4), [[0, 1]])
    check('explicit sequence 11', solve([['replace', []], ['draw', [0]], ['inspect']], 4), [[]])
    check('explicit sequence 12', solve([['replace', [0]], ['draw', [0]], ['clear'], ['draw', [0, 1]], ['inspect']], 4), [[0]])
    check('explicit sequence 13', solve([['draw', [0]], ['replace', [1]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 4), [[0, 1]])
    check('explicit sequence 14', solve([['replace', []], ['begin'], ['end'], ['draw', [1]], ['inspect']], 4), [[]])
    check('explicit sequence 15', solve([['draw', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], ['inspect']], 4), [[0, 1, 2, 3]])
if N == 2:
    check('explicit sequence 0', solve([['replace', [0]], ['begin'], ['draw', [1]], ['inspect'], ['end'], ['inspect']], 5), [[1], []])
    check('explicit sequence 1', solve([['draw', [0]], ['begin'], ['inspect']], 5), [[]])
    check('explicit sequence 2', solve([['begin'], ['draw', [0]], ['draw', [1]], ['inspect']], 5), [[0, 1]])
    check('explicit sequence 3', solve([['begin'], ['replace', [1]], ['draw', [0, 1]], ['inspect']], 5), [[1]])
    check('explicit sequence 4', solve([['begin'], ['draw', [0]], ['clear'], ['draw', [1]], ['inspect']], 5), [[1]])
    check('explicit sequence 5', solve([['replace', [0]], ['begin'], ['draw', [0, 1]], ['end'], ['inspect']], 5), [[0]])
    check('explicit sequence 6', solve([['draw', [0]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 5), [[0, 1]])
    check('explicit sequence 7', solve([['replace', [0]], ['begin'], ['end'], ['draw', [1]], ['inspect']], 5), [[]])
    check('explicit sequence 8', solve([['draw', [0]], ['begin'], ['draw', [1]], ['discard'], ['inspect']], 5), [[0]])
    check('explicit sequence 9', solve([['replace', [0, 1]], ['draw', [0]], ['begin'], ['replace', [1]], ['begin'], ['draw', [1, 2]], ['end'], ['inspect'], ['end'], ['inspect']], 5), [[1], [0, 1]])
    check('explicit sequence 10', solve([['draw', [0]], ['draw', [0, 1]], ['inspect']], 5), [[0, 1]])
    check('explicit sequence 11', solve([['replace', []], ['draw', [0]], ['inspect']], 5), [[]])
    check('explicit sequence 12', solve([['replace', [0]], ['draw', [0]], ['clear'], ['draw', [0, 1]], ['inspect']], 5), [[0]])
    check('explicit sequence 13', solve([['draw', [0]], ['replace', [1]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 5), [[0, 1]])
    check('explicit sequence 14', solve([['replace', []], ['begin'], ['end'], ['draw', [1]], ['inspect']], 5), [[]])
    check('explicit sequence 15', solve([['draw', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], ['inspect']], 5), [[0, 1, 2, 3, 4]])
if N == 3:
    check('explicit sequence 0', solve([['replace', [0]], ['begin'], ['draw', [1]], ['inspect'], ['end'], ['inspect']], 6), [[1], []])
    check('explicit sequence 1', solve([['draw', [0]], ['begin'], ['inspect']], 6), [[]])
    check('explicit sequence 2', solve([['begin'], ['draw', [0]], ['draw', [1]], ['inspect']], 6), [[0, 1]])
    check('explicit sequence 3', solve([['begin'], ['replace', [1]], ['draw', [0, 1]], ['inspect']], 6), [[1]])
    check('explicit sequence 4', solve([['begin'], ['draw', [0]], ['clear'], ['draw', [1]], ['inspect']], 6), [[1]])
    check('explicit sequence 5', solve([['replace', [0]], ['begin'], ['draw', [0, 1]], ['end'], ['inspect']], 6), [[0]])
    check('explicit sequence 6', solve([['draw', [0]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 6), [[0, 1]])
    check('explicit sequence 7', solve([['replace', [0]], ['begin'], ['end'], ['draw', [1]], ['inspect']], 6), [[]])
    check('explicit sequence 8', solve([['draw', [0]], ['begin'], ['draw', [1]], ['discard'], ['inspect']], 6), [[0]])
    check('explicit sequence 9', solve([['replace', [0, 1]], ['draw', [0]], ['begin'], ['replace', [1]], ['begin'], ['draw', [1, 2]], ['end'], ['inspect'], ['end'], ['inspect']], 6), [[1], [0, 1]])
    check('explicit sequence 10', solve([['draw', [0]], ['draw', [0, 1]], ['inspect']], 6), [[0, 1]])
    check('explicit sequence 11', solve([['replace', []], ['draw', [0]], ['inspect']], 6), [[]])
    check('explicit sequence 12', solve([['replace', [0]], ['draw', [0]], ['clear'], ['draw', [0, 1]], ['inspect']], 6), [[0]])
    check('explicit sequence 13', solve([['draw', [0]], ['replace', [1]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 6), [[0, 1]])
    check('explicit sequence 14', solve([['replace', []], ['begin'], ['end'], ['draw', [1]], ['inspect']], 6), [[]])
    check('explicit sequence 15', solve([['draw', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], ['inspect']], 6), [[0, 1, 2, 3, 4, 5]])
if N == 4:
    check('explicit sequence 0', solve([['replace', [0]], ['begin'], ['draw', [1]], ['inspect'], ['end'], ['inspect']], 7), [[1], []])
    check('explicit sequence 1', solve([['draw', [0]], ['begin'], ['inspect']], 7), [[]])
    check('explicit sequence 2', solve([['begin'], ['draw', [0]], ['draw', [1]], ['inspect']], 7), [[0, 1]])
    check('explicit sequence 3', solve([['begin'], ['replace', [1]], ['draw', [0, 1]], ['inspect']], 7), [[1]])
    check('explicit sequence 4', solve([['begin'], ['draw', [0]], ['clear'], ['draw', [1]], ['inspect']], 7), [[1]])
    check('explicit sequence 5', solve([['replace', [0]], ['begin'], ['draw', [0, 1]], ['end'], ['inspect']], 7), [[0]])
    check('explicit sequence 6', solve([['draw', [0]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 7), [[0, 1]])
    check('explicit sequence 7', solve([['replace', [0]], ['begin'], ['end'], ['draw', [1]], ['inspect']], 7), [[]])
    check('explicit sequence 8', solve([['draw', [0]], ['begin'], ['draw', [1]], ['discard'], ['inspect']], 7), [[0]])
    check('explicit sequence 9', solve([['replace', [0, 1]], ['draw', [0]], ['begin'], ['replace', [1]], ['begin'], ['draw', [1, 2]], ['end'], ['inspect'], ['end'], ['inspect']], 7), [[1], [0, 1]])
    check('explicit sequence 10', solve([['draw', [0]], ['draw', [0, 1]], ['inspect']], 7), [[0, 1]])
    check('explicit sequence 11', solve([['replace', []], ['draw', [0]], ['inspect']], 7), [[]])
    check('explicit sequence 12', solve([['replace', [0]], ['draw', [0]], ['clear'], ['draw', [0, 1]], ['inspect']], 7), [[0]])
    check('explicit sequence 13', solve([['draw', [0]], ['replace', [1]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 7), [[0, 1]])
    check('explicit sequence 14', solve([['replace', []], ['begin'], ['end'], ['draw', [1]], ['inspect']], 7), [[]])
    check('explicit sequence 15', solve([['draw', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], ['inspect']], 7), [[0, 1, 2, 3, 4, 5, 6]])
if N == 5:
    check('explicit sequence 0', solve([['replace', [0]], ['begin'], ['draw', [1]], ['inspect'], ['end'], ['inspect']], 8), [[1], []])
    check('explicit sequence 1', solve([['draw', [0]], ['begin'], ['inspect']], 8), [[]])
    check('explicit sequence 2', solve([['begin'], ['draw', [0]], ['draw', [1]], ['inspect']], 8), [[0, 1]])
    check('explicit sequence 3', solve([['begin'], ['replace', [1]], ['draw', [0, 1]], ['inspect']], 8), [[1]])
    check('explicit sequence 4', solve([['begin'], ['draw', [0]], ['clear'], ['draw', [1]], ['inspect']], 8), [[1]])
    check('explicit sequence 5', solve([['replace', [0]], ['begin'], ['draw', [0, 1]], ['end'], ['inspect']], 8), [[0]])
    check('explicit sequence 6', solve([['draw', [0]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 8), [[0, 1]])
    check('explicit sequence 7', solve([['replace', [0]], ['begin'], ['end'], ['draw', [1]], ['inspect']], 8), [[]])
    check('explicit sequence 8', solve([['draw', [0]], ['begin'], ['draw', [1]], ['discard'], ['inspect']], 8), [[0]])
    check('explicit sequence 9', solve([['replace', [0, 1]], ['draw', [0]], ['begin'], ['replace', [1]], ['begin'], ['draw', [1, 2]], ['end'], ['inspect'], ['end'], ['inspect']], 8), [[1], [0, 1]])
    check('explicit sequence 10', solve([['draw', [0]], ['draw', [0, 1]], ['inspect']], 8), [[0, 1]])
    check('explicit sequence 11', solve([['replace', []], ['draw', [0]], ['inspect']], 8), [[]])
    check('explicit sequence 12', solve([['replace', [0]], ['draw', [0]], ['clear'], ['draw', [0, 1]], ['inspect']], 8), [[0]])
    check('explicit sequence 13', solve([['draw', [0]], ['replace', [1]], ['begin'], ['draw', [1]], ['end'], ['inspect']], 8), [[0, 1]])
    check('explicit sequence 14', solve([['replace', []], ['begin'], ['end'], ['draw', [1]], ['inspect']], 8), [[]])
    check('explicit sequence 15', solve([['draw', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], ['inspect']], 8), [[0, 1, 2, 3, 4, 5, 6, 7]])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Ending a layer loses the enclosing clip for later parent drawing.

A layer captures the parent clip and starts with its own full local clip. Child drawing accumulates coverage in that layer; layer completion intersects child coverage with the saved parent clip. Discard removes the layer without publishing. A layer-local clear erases only its accumulated coverage. Parent clip edits after opening cannot change the captured parent clip.

split: open-access