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

N = 1
observations = []
def solve(commands, size):
    full=set(range(size))
    stack=[]
    out=[]
    for cmd in commands:
        op=cmd[0]
        if op=='push': stack.append(set(cmd[1]) & full)
        elif op=='dup': stack.append(set(stack[-1]))
        elif op=='swap': stack[-2],stack[-1]=stack[-1],stack[-2]
        elif op=='not': stack[-1]=full-stack[-1]
        elif op=='clear': stack[-1].clear()
        elif op=='draw': out.append(sorted(stack[-1]))
        else:
            right=stack.pop()
            left=stack.pop()
            if op=='and': result=left & right
            elif op=='or': result=left | right
            elif op=='xor': result=left ^ right
            elif op=='subtract': result=left-right
            elif op=='implies': result=(full-right)|left
            else: result=full-(left^right)
            stack.append(result)
    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([['push', [0, 99]], ['draw']], 4), [[0]])
    check('explicit sequence 1', solve([['push', [0, 1]], ['dup'], ['clear'], ['swap'], ['draw']], 4), [[0, 1]])
    check('explicit sequence 2', solve([['push', [0, 1]], ['push', [1, 2]], ['swap'], ['subtract'], ['draw']], 4), [[2]])
    check('explicit sequence 3', solve([['push', [0]], ['not'], ['draw']], 4), [[1, 2, 3]])
    check('explicit sequence 4', solve([['push', [0, 1]], ['push', [1, 2]], ['and'], ['draw']], 4), [[1]])
    check('explicit sequence 5', solve([['push', [0, 1]], ['push', [1, 2]], ['or'], ['draw']], 4), [[0, 1, 2]])
    check('explicit sequence 6', solve([['push', [0, 1]], ['push', [1, 2]], ['xor'], ['draw']], 4), [[0, 2]])
    check('explicit sequence 7', solve([['push', [0, 1]], ['push', [1, 2]], ['subtract'], ['draw']], 4), [[0]])
    check('explicit sequence 8', solve([['push', [0]], ['push', [1]], ['implies'], ['draw']], 4), [[1, 2, 3]])
    check('explicit sequence 9', solve([['push', [0]], ['push', [1]], ['equal'], ['draw']], 4), [[2, 3]])
    check('explicit sequence 10', solve([['push', [0, 1]], ['push', [1, 2]], ['equal'], ['draw']], 4), [[1, 3]])
if N == 2:
    check('explicit sequence 0', solve([['push', [0, 99]], ['draw']], 5), [[0]])
    check('explicit sequence 1', solve([['push', [0, 1]], ['dup'], ['clear'], ['swap'], ['draw']], 5), [[0, 1]])
    check('explicit sequence 2', solve([['push', [0, 1]], ['push', [1, 2]], ['swap'], ['subtract'], ['draw']], 5), [[2]])
    check('explicit sequence 3', solve([['push', [0]], ['not'], ['draw']], 5), [[1, 2, 3, 4]])
    check('explicit sequence 4', solve([['push', [0, 1]], ['push', [1, 2]], ['and'], ['draw']], 5), [[1]])
    check('explicit sequence 5', solve([['push', [0, 1]], ['push', [1, 2]], ['or'], ['draw']], 5), [[0, 1, 2]])
    check('explicit sequence 6', solve([['push', [0, 1]], ['push', [1, 2]], ['xor'], ['draw']], 5), [[0, 2]])
    check('explicit sequence 7', solve([['push', [0, 1]], ['push', [1, 2]], ['subtract'], ['draw']], 5), [[0]])
    check('explicit sequence 8', solve([['push', [0]], ['push', [1]], ['implies'], ['draw']], 5), [[1, 2, 3, 4]])
    check('explicit sequence 9', solve([['push', [0]], ['push', [1]], ['equal'], ['draw']], 5), [[2, 3, 4]])
    check('explicit sequence 10', solve([['push', [0, 1]], ['push', [1, 2]], ['equal'], ['draw']], 5), [[1, 3, 4]])
if N == 3:
    check('explicit sequence 0', solve([['push', [0, 99]], ['draw']], 6), [[0]])
    check('explicit sequence 1', solve([['push', [0, 1]], ['dup'], ['clear'], ['swap'], ['draw']], 6), [[0, 1]])
    check('explicit sequence 2', solve([['push', [0, 1]], ['push', [1, 2]], ['swap'], ['subtract'], ['draw']], 6), [[2]])
    check('explicit sequence 3', solve([['push', [0]], ['not'], ['draw']], 6), [[1, 2, 3, 4, 5]])
    check('explicit sequence 4', solve([['push', [0, 1]], ['push', [1, 2]], ['and'], ['draw']], 6), [[1]])
    check('explicit sequence 5', solve([['push', [0, 1]], ['push', [1, 2]], ['or'], ['draw']], 6), [[0, 1, 2]])
    check('explicit sequence 6', solve([['push', [0, 1]], ['push', [1, 2]], ['xor'], ['draw']], 6), [[0, 2]])
    check('explicit sequence 7', solve([['push', [0, 1]], ['push', [1, 2]], ['subtract'], ['draw']], 6), [[0]])
    check('explicit sequence 8', solve([['push', [0]], ['push', [1]], ['implies'], ['draw']], 6), [[1, 2, 3, 4, 5]])
    check('explicit sequence 9', solve([['push', [0]], ['push', [1]], ['equal'], ['draw']], 6), [[2, 3, 4, 5]])
    check('explicit sequence 10', solve([['push', [0, 1]], ['push', [1, 2]], ['equal'], ['draw']], 6), [[1, 3, 4, 5]])
if N == 4:
    check('explicit sequence 0', solve([['push', [0, 99]], ['draw']], 7), [[0]])
    check('explicit sequence 1', solve([['push', [0, 1]], ['dup'], ['clear'], ['swap'], ['draw']], 7), [[0, 1]])
    check('explicit sequence 2', solve([['push', [0, 1]], ['push', [1, 2]], ['swap'], ['subtract'], ['draw']], 7), [[2]])
    check('explicit sequence 3', solve([['push', [0]], ['not'], ['draw']], 7), [[1, 2, 3, 4, 5, 6]])
    check('explicit sequence 4', solve([['push', [0, 1]], ['push', [1, 2]], ['and'], ['draw']], 7), [[1]])
    check('explicit sequence 5', solve([['push', [0, 1]], ['push', [1, 2]], ['or'], ['draw']], 7), [[0, 1, 2]])
    check('explicit sequence 6', solve([['push', [0, 1]], ['push', [1, 2]], ['xor'], ['draw']], 7), [[0, 2]])
    check('explicit sequence 7', solve([['push', [0, 1]], ['push', [1, 2]], ['subtract'], ['draw']], 7), [[0]])
    check('explicit sequence 8', solve([['push', [0]], ['push', [1]], ['implies'], ['draw']], 7), [[1, 2, 3, 4, 5, 6]])
    check('explicit sequence 9', solve([['push', [0]], ['push', [1]], ['equal'], ['draw']], 7), [[2, 3, 4, 5, 6]])
    check('explicit sequence 10', solve([['push', [0, 1]], ['push', [1, 2]], ['equal'], ['draw']], 7), [[1, 3, 4, 5, 6]])
if N == 5:
    check('explicit sequence 0', solve([['push', [0, 99]], ['draw']], 8), [[0]])
    check('explicit sequence 1', solve([['push', [0, 1]], ['dup'], ['clear'], ['swap'], ['draw']], 8), [[0, 1]])
    check('explicit sequence 2', solve([['push', [0, 1]], ['push', [1, 2]], ['swap'], ['subtract'], ['draw']], 8), [[2]])
    check('explicit sequence 3', solve([['push', [0]], ['not'], ['draw']], 8), [[1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 4', solve([['push', [0, 1]], ['push', [1, 2]], ['and'], ['draw']], 8), [[1]])
    check('explicit sequence 5', solve([['push', [0, 1]], ['push', [1, 2]], ['or'], ['draw']], 8), [[0, 1, 2]])
    check('explicit sequence 6', solve([['push', [0, 1]], ['push', [1, 2]], ['xor'], ['draw']], 8), [[0, 2]])
    check('explicit sequence 7', solve([['push', [0, 1]], ['push', [1, 2]], ['subtract'], ['draw']], 8), [[0]])
    check('explicit sequence 8', solve([['push', [0]], ['push', [1]], ['implies'], ['draw']], 8), [[1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 9', solve([['push', [0]], ['push', [1]], ['equal'], ['draw']], 8), [[2, 3, 4, 5, 6, 7]])
    check('explicit sequence 10', solve([['push', [0, 1]], ['push', [1, 2]], ['equal'], ['draw']], 8), [[1, 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))
    stack=[]
    out=[]
    for cmd in commands:
        op=cmd[0]
        if op=='push': stack.append(set(cmd[1]) & full)
        elif op=='dup': stack.append(set(stack[-1]))
        elif op=='swap': stack[-2],stack[-1]=stack[-1],stack[-2]
        elif op=='not': stack[-1]=full-stack[-1]
        elif op=='clear': stack[-1].clear()
        elif op=='draw': out.append(sorted(stack[-1]))
        else:
            right=stack.pop()
            left=stack.pop()
            if op=='and': result=left & right
            elif op=='or': result=left | right
            elif op=='xor': result=left ^ right
            elif op=='subtract': result=left-right
            elif op=='implies': result=(full-left)&right
            else: result=full-(left^right)
            stack.append(result)
    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([['push', [0, 99]], ['draw']], 4), [[0]])
    check('explicit sequence 1', solve([['push', [0, 1]], ['dup'], ['clear'], ['swap'], ['draw']], 4), [[0, 1]])
    check('explicit sequence 2', solve([['push', [0, 1]], ['push', [1, 2]], ['swap'], ['subtract'], ['draw']], 4), [[2]])
    check('explicit sequence 3', solve([['push', [0]], ['not'], ['draw']], 4), [[1, 2, 3]])
    check('explicit sequence 4', solve([['push', [0, 1]], ['push', [1, 2]], ['and'], ['draw']], 4), [[1]])
    check('explicit sequence 5', solve([['push', [0, 1]], ['push', [1, 2]], ['or'], ['draw']], 4), [[0, 1, 2]])
    check('explicit sequence 6', solve([['push', [0, 1]], ['push', [1, 2]], ['xor'], ['draw']], 4), [[0, 2]])
    check('explicit sequence 7', solve([['push', [0, 1]], ['push', [1, 2]], ['subtract'], ['draw']], 4), [[0]])
    check('explicit sequence 8', solve([['push', [0]], ['push', [1]], ['implies'], ['draw']], 4), [[1, 2, 3]])
    check('explicit sequence 9', solve([['push', [0]], ['push', [1]], ['equal'], ['draw']], 4), [[2, 3]])
    check('explicit sequence 10', solve([['push', [0, 1]], ['push', [1, 2]], ['equal'], ['draw']], 4), [[1, 3]])
if N == 2:
    check('explicit sequence 0', solve([['push', [0, 99]], ['draw']], 5), [[0]])
    check('explicit sequence 1', solve([['push', [0, 1]], ['dup'], ['clear'], ['swap'], ['draw']], 5), [[0, 1]])
    check('explicit sequence 2', solve([['push', [0, 1]], ['push', [1, 2]], ['swap'], ['subtract'], ['draw']], 5), [[2]])
    check('explicit sequence 3', solve([['push', [0]], ['not'], ['draw']], 5), [[1, 2, 3, 4]])
    check('explicit sequence 4', solve([['push', [0, 1]], ['push', [1, 2]], ['and'], ['draw']], 5), [[1]])
    check('explicit sequence 5', solve([['push', [0, 1]], ['push', [1, 2]], ['or'], ['draw']], 5), [[0, 1, 2]])
    check('explicit sequence 6', solve([['push', [0, 1]], ['push', [1, 2]], ['xor'], ['draw']], 5), [[0, 2]])
    check('explicit sequence 7', solve([['push', [0, 1]], ['push', [1, 2]], ['subtract'], ['draw']], 5), [[0]])
    check('explicit sequence 8', solve([['push', [0]], ['push', [1]], ['implies'], ['draw']], 5), [[1, 2, 3, 4]])
    check('explicit sequence 9', solve([['push', [0]], ['push', [1]], ['equal'], ['draw']], 5), [[2, 3, 4]])
    check('explicit sequence 10', solve([['push', [0, 1]], ['push', [1, 2]], ['equal'], ['draw']], 5), [[1, 3, 4]])
if N == 3:
    check('explicit sequence 0', solve([['push', [0, 99]], ['draw']], 6), [[0]])
    check('explicit sequence 1', solve([['push', [0, 1]], ['dup'], ['clear'], ['swap'], ['draw']], 6), [[0, 1]])
    check('explicit sequence 2', solve([['push', [0, 1]], ['push', [1, 2]], ['swap'], ['subtract'], ['draw']], 6), [[2]])
    check('explicit sequence 3', solve([['push', [0]], ['not'], ['draw']], 6), [[1, 2, 3, 4, 5]])
    check('explicit sequence 4', solve([['push', [0, 1]], ['push', [1, 2]], ['and'], ['draw']], 6), [[1]])
    check('explicit sequence 5', solve([['push', [0, 1]], ['push', [1, 2]], ['or'], ['draw']], 6), [[0, 1, 2]])
    check('explicit sequence 6', solve([['push', [0, 1]], ['push', [1, 2]], ['xor'], ['draw']], 6), [[0, 2]])
    check('explicit sequence 7', solve([['push', [0, 1]], ['push', [1, 2]], ['subtract'], ['draw']], 6), [[0]])
    check('explicit sequence 8', solve([['push', [0]], ['push', [1]], ['implies'], ['draw']], 6), [[1, 2, 3, 4, 5]])
    check('explicit sequence 9', solve([['push', [0]], ['push', [1]], ['equal'], ['draw']], 6), [[2, 3, 4, 5]])
    check('explicit sequence 10', solve([['push', [0, 1]], ['push', [1, 2]], ['equal'], ['draw']], 6), [[1, 3, 4, 5]])
if N == 4:
    check('explicit sequence 0', solve([['push', [0, 99]], ['draw']], 7), [[0]])
    check('explicit sequence 1', solve([['push', [0, 1]], ['dup'], ['clear'], ['swap'], ['draw']], 7), [[0, 1]])
    check('explicit sequence 2', solve([['push', [0, 1]], ['push', [1, 2]], ['swap'], ['subtract'], ['draw']], 7), [[2]])
    check('explicit sequence 3', solve([['push', [0]], ['not'], ['draw']], 7), [[1, 2, 3, 4, 5, 6]])
    check('explicit sequence 4', solve([['push', [0, 1]], ['push', [1, 2]], ['and'], ['draw']], 7), [[1]])
    check('explicit sequence 5', solve([['push', [0, 1]], ['push', [1, 2]], ['or'], ['draw']], 7), [[0, 1, 2]])
    check('explicit sequence 6', solve([['push', [0, 1]], ['push', [1, 2]], ['xor'], ['draw']], 7), [[0, 2]])
    check('explicit sequence 7', solve([['push', [0, 1]], ['push', [1, 2]], ['subtract'], ['draw']], 7), [[0]])
    check('explicit sequence 8', solve([['push', [0]], ['push', [1]], ['implies'], ['draw']], 7), [[1, 2, 3, 4, 5, 6]])
    check('explicit sequence 9', solve([['push', [0]], ['push', [1]], ['equal'], ['draw']], 7), [[2, 3, 4, 5, 6]])
    check('explicit sequence 10', solve([['push', [0, 1]], ['push', [1, 2]], ['equal'], ['draw']], 7), [[1, 3, 4, 5, 6]])
if N == 5:
    check('explicit sequence 0', solve([['push', [0, 99]], ['draw']], 8), [[0]])
    check('explicit sequence 1', solve([['push', [0, 1]], ['dup'], ['clear'], ['swap'], ['draw']], 8), [[0, 1]])
    check('explicit sequence 2', solve([['push', [0, 1]], ['push', [1, 2]], ['swap'], ['subtract'], ['draw']], 8), [[2]])
    check('explicit sequence 3', solve([['push', [0]], ['not'], ['draw']], 8), [[1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 4', solve([['push', [0, 1]], ['push', [1, 2]], ['and'], ['draw']], 8), [[1]])
    check('explicit sequence 5', solve([['push', [0, 1]], ['push', [1, 2]], ['or'], ['draw']], 8), [[0, 1, 2]])
    check('explicit sequence 6', solve([['push', [0, 1]], ['push', [1, 2]], ['xor'], ['draw']], 8), [[0, 2]])
    check('explicit sequence 7', solve([['push', [0, 1]], ['push', [1, 2]], ['subtract'], ['draw']], 8), [[0]])
    check('explicit sequence 8', solve([['push', [0]], ['push', [1]], ['implies'], ['draw']], 8), [[1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 9', solve([['push', [0]], ['push', [1]], ['equal'], ['draw']], 8), [[2, 3, 4, 5, 6, 7]])
    check('explicit sequence 10', solve([['push', [0, 1]], ['push', [1, 2]], ['equal'], ['draw']], 8), [[1, 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:
A conditional clip combines the consequent complement instead of the antecedent complement.

A postfix region program evaluates finite sample sets. Binary operands preserve left/right order. Complement uses the target universe. Named masks are copied on push; duplicate copies the top value. Subtraction, intersection, union and XOR consume both operands. Draw peeks without consuming. Empty-stack operations are outside this bounded contract.

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))
    stack=[]
    out=[]
    for cmd in commands:
        op=cmd[0]
        if op=='push': stack.append(set(cmd[1]) & full)
        elif op=='dup': stack.append(set(stack[-1]))
        elif op=='swap': stack[-2],stack[-1]=stack[-1],stack[-2]
        elif op=='not': stack[-1]=full-stack[-1]
        elif op=='clear': stack[-1].clear()
        elif op=='draw': out.append(sorted(stack[-1]))
        else:
            right=stack.pop()
            left=stack.pop()
            if op=='and': result=left & right
            elif op=='or': result=left | right
            elif op=='xor': result=left ^ right
            elif op=='subtract': result=left-right
            elif op=='implies': result=(full-left)|right
            else: result=left & right
            stack.append(result)
    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([['push', [0, 99]], ['draw']], 4), [[0]])
    check('explicit sequence 1', solve([['push', [0, 1]], ['dup'], ['clear'], ['swap'], ['draw']], 4), [[0, 1]])
    check('explicit sequence 2', solve([['push', [0, 1]], ['push', [1, 2]], ['swap'], ['subtract'], ['draw']], 4), [[2]])
    check('explicit sequence 3', solve([['push', [0]], ['not'], ['draw']], 4), [[1, 2, 3]])
    check('explicit sequence 4', solve([['push', [0, 1]], ['push', [1, 2]], ['and'], ['draw']], 4), [[1]])
    check('explicit sequence 5', solve([['push', [0, 1]], ['push', [1, 2]], ['or'], ['draw']], 4), [[0, 1, 2]])
    check('explicit sequence 6', solve([['push', [0, 1]], ['push', [1, 2]], ['xor'], ['draw']], 4), [[0, 2]])
    check('explicit sequence 7', solve([['push', [0, 1]], ['push', [1, 2]], ['subtract'], ['draw']], 4), [[0]])
    check('explicit sequence 8', solve([['push', [0]], ['push', [1]], ['implies'], ['draw']], 4), [[1, 2, 3]])
    check('explicit sequence 9', solve([['push', [0]], ['push', [1]], ['equal'], ['draw']], 4), [[2, 3]])
    check('explicit sequence 10', solve([['push', [0, 1]], ['push', [1, 2]], ['equal'], ['draw']], 4), [[1, 3]])
if N == 2:
    check('explicit sequence 0', solve([['push', [0, 99]], ['draw']], 5), [[0]])
    check('explicit sequence 1', solve([['push', [0, 1]], ['dup'], ['clear'], ['swap'], ['draw']], 5), [[0, 1]])
    check('explicit sequence 2', solve([['push', [0, 1]], ['push', [1, 2]], ['swap'], ['subtract'], ['draw']], 5), [[2]])
    check('explicit sequence 3', solve([['push', [0]], ['not'], ['draw']], 5), [[1, 2, 3, 4]])
    check('explicit sequence 4', solve([['push', [0, 1]], ['push', [1, 2]], ['and'], ['draw']], 5), [[1]])
    check('explicit sequence 5', solve([['push', [0, 1]], ['push', [1, 2]], ['or'], ['draw']], 5), [[0, 1, 2]])
    check('explicit sequence 6', solve([['push', [0, 1]], ['push', [1, 2]], ['xor'], ['draw']], 5), [[0, 2]])
    check('explicit sequence 7', solve([['push', [0, 1]], ['push', [1, 2]], ['subtract'], ['draw']], 5), [[0]])
    check('explicit sequence 8', solve([['push', [0]], ['push', [1]], ['implies'], ['draw']], 5), [[1, 2, 3, 4]])
    check('explicit sequence 9', solve([['push', [0]], ['push', [1]], ['equal'], ['draw']], 5), [[2, 3, 4]])
    check('explicit sequence 10', solve([['push', [0, 1]], ['push', [1, 2]], ['equal'], ['draw']], 5), [[1, 3, 4]])
if N == 3:
    check('explicit sequence 0', solve([['push', [0, 99]], ['draw']], 6), [[0]])
    check('explicit sequence 1', solve([['push', [0, 1]], ['dup'], ['clear'], ['swap'], ['draw']], 6), [[0, 1]])
    check('explicit sequence 2', solve([['push', [0, 1]], ['push', [1, 2]], ['swap'], ['subtract'], ['draw']], 6), [[2]])
    check('explicit sequence 3', solve([['push', [0]], ['not'], ['draw']], 6), [[1, 2, 3, 4, 5]])
    check('explicit sequence 4', solve([['push', [0, 1]], ['push', [1, 2]], ['and'], ['draw']], 6), [[1]])
    check('explicit sequence 5', solve([['push', [0, 1]], ['push', [1, 2]], ['or'], ['draw']], 6), [[0, 1, 2]])
    check('explicit sequence 6', solve([['push', [0, 1]], ['push', [1, 2]], ['xor'], ['draw']], 6), [[0, 2]])
    check('explicit sequence 7', solve([['push', [0, 1]], ['push', [1, 2]], ['subtract'], ['draw']], 6), [[0]])
    check('explicit sequence 8', solve([['push', [0]], ['push', [1]], ['implies'], ['draw']], 6), [[1, 2, 3, 4, 5]])
    check('explicit sequence 9', solve([['push', [0]], ['push', [1]], ['equal'], ['draw']], 6), [[2, 3, 4, 5]])
    check('explicit sequence 10', solve([['push', [0, 1]], ['push', [1, 2]], ['equal'], ['draw']], 6), [[1, 3, 4, 5]])
if N == 4:
    check('explicit sequence 0', solve([['push', [0, 99]], ['draw']], 7), [[0]])
    check('explicit sequence 1', solve([['push', [0, 1]], ['dup'], ['clear'], ['swap'], ['draw']], 7), [[0, 1]])
    check('explicit sequence 2', solve([['push', [0, 1]], ['push', [1, 2]], ['swap'], ['subtract'], ['draw']], 7), [[2]])
    check('explicit sequence 3', solve([['push', [0]], ['not'], ['draw']], 7), [[1, 2, 3, 4, 5, 6]])
    check('explicit sequence 4', solve([['push', [0, 1]], ['push', [1, 2]], ['and'], ['draw']], 7), [[1]])
    check('explicit sequence 5', solve([['push', [0, 1]], ['push', [1, 2]], ['or'], ['draw']], 7), [[0, 1, 2]])
    check('explicit sequence 6', solve([['push', [0, 1]], ['push', [1, 2]], ['xor'], ['draw']], 7), [[0, 2]])
    check('explicit sequence 7', solve([['push', [0, 1]], ['push', [1, 2]], ['subtract'], ['draw']], 7), [[0]])
    check('explicit sequence 8', solve([['push', [0]], ['push', [1]], ['implies'], ['draw']], 7), [[1, 2, 3, 4, 5, 6]])
    check('explicit sequence 9', solve([['push', [0]], ['push', [1]], ['equal'], ['draw']], 7), [[2, 3, 4, 5, 6]])
    check('explicit sequence 10', solve([['push', [0, 1]], ['push', [1, 2]], ['equal'], ['draw']], 7), [[1, 3, 4, 5, 6]])
if N == 5:
    check('explicit sequence 0', solve([['push', [0, 99]], ['draw']], 8), [[0]])
    check('explicit sequence 1', solve([['push', [0, 1]], ['dup'], ['clear'], ['swap'], ['draw']], 8), [[0, 1]])
    check('explicit sequence 2', solve([['push', [0, 1]], ['push', [1, 2]], ['swap'], ['subtract'], ['draw']], 8), [[2]])
    check('explicit sequence 3', solve([['push', [0]], ['not'], ['draw']], 8), [[1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 4', solve([['push', [0, 1]], ['push', [1, 2]], ['and'], ['draw']], 8), [[1]])
    check('explicit sequence 5', solve([['push', [0, 1]], ['push', [1, 2]], ['or'], ['draw']], 8), [[0, 1, 2]])
    check('explicit sequence 6', solve([['push', [0, 1]], ['push', [1, 2]], ['xor'], ['draw']], 8), [[0, 2]])
    check('explicit sequence 7', solve([['push', [0, 1]], ['push', [1, 2]], ['subtract'], ['draw']], 8), [[0]])
    check('explicit sequence 8', solve([['push', [0]], ['push', [1]], ['implies'], ['draw']], 8), [[1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 9', solve([['push', [0]], ['push', [1]], ['equal'], ['draw']], 8), [[2, 3, 4, 5, 6, 7]])
    check('explicit sequence 10', solve([['push', [0, 1]], ['push', [1, 2]], ['equal'], ['draw']], 8), [[1, 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))
    stack=[]
    out=[]
    for cmd in commands:
        op=cmd[0]
        if op=='push': stack.append(set(cmd[1]) & full)
        elif op=='dup': stack.append(set(stack[-1]))
        elif op=='swap': stack[-2],stack[-1]=stack[-1],stack[-2]
        elif op=='not': stack[-1]=full-stack[-1]
        elif op=='clear': stack[-1].clear()
        elif op=='draw': out.append(sorted(stack[-1]))
        else:
            right=stack.pop()
            left=stack.pop()
            if op=='and': result=left & right
            elif op=='or': result=left | right
            elif op=='xor': result=left ^ right
            elif op=='subtract': result=left-right
            elif op=='implies': result=(full-left)|right
            else: result=full-(left|right)
            stack.append(result)
    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([['push', [0, 99]], ['draw']], 4), [[0]])
    check('explicit sequence 1', solve([['push', [0, 1]], ['dup'], ['clear'], ['swap'], ['draw']], 4), [[0, 1]])
    check('explicit sequence 2', solve([['push', [0, 1]], ['push', [1, 2]], ['swap'], ['subtract'], ['draw']], 4), [[2]])
    check('explicit sequence 3', solve([['push', [0]], ['not'], ['draw']], 4), [[1, 2, 3]])
    check('explicit sequence 4', solve([['push', [0, 1]], ['push', [1, 2]], ['and'], ['draw']], 4), [[1]])
    check('explicit sequence 5', solve([['push', [0, 1]], ['push', [1, 2]], ['or'], ['draw']], 4), [[0, 1, 2]])
    check('explicit sequence 6', solve([['push', [0, 1]], ['push', [1, 2]], ['xor'], ['draw']], 4), [[0, 2]])
    check('explicit sequence 7', solve([['push', [0, 1]], ['push', [1, 2]], ['subtract'], ['draw']], 4), [[0]])
    check('explicit sequence 8', solve([['push', [0]], ['push', [1]], ['implies'], ['draw']], 4), [[1, 2, 3]])
    check('explicit sequence 9', solve([['push', [0]], ['push', [1]], ['equal'], ['draw']], 4), [[2, 3]])
    check('explicit sequence 10', solve([['push', [0, 1]], ['push', [1, 2]], ['equal'], ['draw']], 4), [[1, 3]])
if N == 2:
    check('explicit sequence 0', solve([['push', [0, 99]], ['draw']], 5), [[0]])
    check('explicit sequence 1', solve([['push', [0, 1]], ['dup'], ['clear'], ['swap'], ['draw']], 5), [[0, 1]])
    check('explicit sequence 2', solve([['push', [0, 1]], ['push', [1, 2]], ['swap'], ['subtract'], ['draw']], 5), [[2]])
    check('explicit sequence 3', solve([['push', [0]], ['not'], ['draw']], 5), [[1, 2, 3, 4]])
    check('explicit sequence 4', solve([['push', [0, 1]], ['push', [1, 2]], ['and'], ['draw']], 5), [[1]])
    check('explicit sequence 5', solve([['push', [0, 1]], ['push', [1, 2]], ['or'], ['draw']], 5), [[0, 1, 2]])
    check('explicit sequence 6', solve([['push', [0, 1]], ['push', [1, 2]], ['xor'], ['draw']], 5), [[0, 2]])
    check('explicit sequence 7', solve([['push', [0, 1]], ['push', [1, 2]], ['subtract'], ['draw']], 5), [[0]])
    check('explicit sequence 8', solve([['push', [0]], ['push', [1]], ['implies'], ['draw']], 5), [[1, 2, 3, 4]])
    check('explicit sequence 9', solve([['push', [0]], ['push', [1]], ['equal'], ['draw']], 5), [[2, 3, 4]])
    check('explicit sequence 10', solve([['push', [0, 1]], ['push', [1, 2]], ['equal'], ['draw']], 5), [[1, 3, 4]])
if N == 3:
    check('explicit sequence 0', solve([['push', [0, 99]], ['draw']], 6), [[0]])
    check('explicit sequence 1', solve([['push', [0, 1]], ['dup'], ['clear'], ['swap'], ['draw']], 6), [[0, 1]])
    check('explicit sequence 2', solve([['push', [0, 1]], ['push', [1, 2]], ['swap'], ['subtract'], ['draw']], 6), [[2]])
    check('explicit sequence 3', solve([['push', [0]], ['not'], ['draw']], 6), [[1, 2, 3, 4, 5]])
    check('explicit sequence 4', solve([['push', [0, 1]], ['push', [1, 2]], ['and'], ['draw']], 6), [[1]])
    check('explicit sequence 5', solve([['push', [0, 1]], ['push', [1, 2]], ['or'], ['draw']], 6), [[0, 1, 2]])
    check('explicit sequence 6', solve([['push', [0, 1]], ['push', [1, 2]], ['xor'], ['draw']], 6), [[0, 2]])
    check('explicit sequence 7', solve([['push', [0, 1]], ['push', [1, 2]], ['subtract'], ['draw']], 6), [[0]])
    check('explicit sequence 8', solve([['push', [0]], ['push', [1]], ['implies'], ['draw']], 6), [[1, 2, 3, 4, 5]])
    check('explicit sequence 9', solve([['push', [0]], ['push', [1]], ['equal'], ['draw']], 6), [[2, 3, 4, 5]])
    check('explicit sequence 10', solve([['push', [0, 1]], ['push', [1, 2]], ['equal'], ['draw']], 6), [[1, 3, 4, 5]])
if N == 4:
    check('explicit sequence 0', solve([['push', [0, 99]], ['draw']], 7), [[0]])
    check('explicit sequence 1', solve([['push', [0, 1]], ['dup'], ['clear'], ['swap'], ['draw']], 7), [[0, 1]])
    check('explicit sequence 2', solve([['push', [0, 1]], ['push', [1, 2]], ['swap'], ['subtract'], ['draw']], 7), [[2]])
    check('explicit sequence 3', solve([['push', [0]], ['not'], ['draw']], 7), [[1, 2, 3, 4, 5, 6]])
    check('explicit sequence 4', solve([['push', [0, 1]], ['push', [1, 2]], ['and'], ['draw']], 7), [[1]])
    check('explicit sequence 5', solve([['push', [0, 1]], ['push', [1, 2]], ['or'], ['draw']], 7), [[0, 1, 2]])
    check('explicit sequence 6', solve([['push', [0, 1]], ['push', [1, 2]], ['xor'], ['draw']], 7), [[0, 2]])
    check('explicit sequence 7', solve([['push', [0, 1]], ['push', [1, 2]], ['subtract'], ['draw']], 7), [[0]])
    check('explicit sequence 8', solve([['push', [0]], ['push', [1]], ['implies'], ['draw']], 7), [[1, 2, 3, 4, 5, 6]])
    check('explicit sequence 9', solve([['push', [0]], ['push', [1]], ['equal'], ['draw']], 7), [[2, 3, 4, 5, 6]])
    check('explicit sequence 10', solve([['push', [0, 1]], ['push', [1, 2]], ['equal'], ['draw']], 7), [[1, 3, 4, 5, 6]])
if N == 5:
    check('explicit sequence 0', solve([['push', [0, 99]], ['draw']], 8), [[0]])
    check('explicit sequence 1', solve([['push', [0, 1]], ['dup'], ['clear'], ['swap'], ['draw']], 8), [[0, 1]])
    check('explicit sequence 2', solve([['push', [0, 1]], ['push', [1, 2]], ['swap'], ['subtract'], ['draw']], 8), [[2]])
    check('explicit sequence 3', solve([['push', [0]], ['not'], ['draw']], 8), [[1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 4', solve([['push', [0, 1]], ['push', [1, 2]], ['and'], ['draw']], 8), [[1]])
    check('explicit sequence 5', solve([['push', [0, 1]], ['push', [1, 2]], ['or'], ['draw']], 8), [[0, 1, 2]])
    check('explicit sequence 6', solve([['push', [0, 1]], ['push', [1, 2]], ['xor'], ['draw']], 8), [[0, 2]])
    check('explicit sequence 7', solve([['push', [0, 1]], ['push', [1, 2]], ['subtract'], ['draw']], 8), [[0]])
    check('explicit sequence 8', solve([['push', [0]], ['push', [1]], ['implies'], ['draw']], 8), [[1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 9', solve([['push', [0]], ['push', [1]], ['equal'], ['draw']], 8), [[2, 3, 4, 5, 6, 7]])
    check('explicit sequence 10', solve([['push', [0, 1]], ['push', [1, 2]], ['equal'], ['draw']], 8), [[1, 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:
Coverage equivalence excludes samples absent from both regions.

A postfix region program evaluates finite sample sets. Binary operands preserve left/right order. Complement uses the target universe. Named masks are copied on push; duplicate copies the top value. Subtraction, intersection, union and XOR consume both operands. Draw peeks without consuming. Empty-stack operations are outside this bounded contract.

split: open-access


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

N = 1
observations = []
def solve(commands, size):
    full=set(range(size))
    out=[]
    for cmd in commands:
        source,kernel,mode,iterations=cmd
        source=set(source)&full
        kernel=set(kernel)
        def dilate(s): return {x for x in full if any(x+k in s for k in kernel)}
        def erode(s): return {x for x in full if kernel and all(x+k in s for k in kernel)}
        result=set(source)
        for _ in range(max(0,iterations)):
            prior=set(result)
            if mode=='dilate': result=dilate(prior)
            elif mode=='erode': result=erode(prior)
            elif mode=='open': result=dilate(erode(prior))
            elif mode=='close': result=erode(dilate(prior))
            elif mode=='gradient': result=dilate(prior)-erode(prior)
            elif mode=='inner': result=prior-erode(prior)
            else: result=dilate(prior)-prior
        out.append(sorted(result))
    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([[[1], [0, 1], 'dilate', 1]], 4), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 4), [[1, 2]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 4), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 4), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 4), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 4), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 4), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 4), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 4), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 4), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 4), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 4), [[0, 1, 2]])
if N == 2:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 5), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 5), [[1, 2, 3]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 5), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 5), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 5), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 5), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 5), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 5), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 5), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 5), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 5), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 5), [[0, 1, 2]])
if N == 3:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 6), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 6), [[1, 2, 3, 4]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 6), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 6), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 6), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 6), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 6), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 6), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 6), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 6), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 6), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 6), [[0, 1, 2]])
if N == 4:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 7), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 7), [[1, 2, 3, 4, 5]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 7), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 7), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 7), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 7), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 7), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 7), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 7), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 7), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 7), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 7), [[0, 1, 2]])
if N == 5:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 8), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 8), [[1, 2, 3, 4, 5, 6]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 8), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 8), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 8), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 8), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 8), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 8), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 8), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 8), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 8), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 8), [[0, 1, 2]])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(commands, size):
    full=set(range(size))
    out=[]
    for cmd in commands:
        source,kernel,mode,iterations=cmd
        source=set(source)&full
        kernel=set(kernel)
        def dilate(s): return {x for x in full if any(x-abs(k) in s for k in kernel)}
        def erode(s): return {x for x in full if kernel and all(x+k in s for k in kernel)}
        result=set(source)
        for _ in range(max(0,iterations)):
            prior=set(result)
            if mode=='dilate': result=dilate(prior)
            elif mode=='erode': result=erode(prior)
            elif mode=='open': result=dilate(erode(prior))
            elif mode=='close': result=erode(dilate(prior))
            elif mode=='gradient': result=dilate(prior)-erode(prior)
            elif mode=='inner': result=prior-erode(prior)
            else: result=dilate(prior)-prior
        out.append(sorted(result))
    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([[[1], [0, 1], 'dilate', 1]], 4), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 4), [[1, 2]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 4), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 4), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 4), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 4), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 4), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 4), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 4), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 4), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 4), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 4), [[0, 1, 2]])
if N == 2:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 5), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 5), [[1, 2, 3]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 5), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 5), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 5), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 5), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 5), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 5), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 5), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 5), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 5), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 5), [[0, 1, 2]])
if N == 3:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 6), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 6), [[1, 2, 3, 4]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 6), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 6), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 6), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 6), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 6), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 6), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 6), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 6), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 6), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 6), [[0, 1, 2]])
if N == 4:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 7), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 7), [[1, 2, 3, 4, 5]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 7), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 7), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 7), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 7), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 7), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 7), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 7), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 7), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 7), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 7), [[0, 1, 2]])
if N == 5:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 8), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 8), [[1, 2, 3, 4, 5, 6]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 8), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 8), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 8), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 8), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 8), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 8), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 8), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 8), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 8), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 8), [[0, 1, 2]])
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:
Dilation forgets to reflect an asymmetric structuring element.

A binary sample mask supports dilation/erosion by an explicit signed structuring element. Out-of-target samples are uncovered; empty structuring elements yield empty output. Open erodes then dilates; close dilates then erodes. Gradient is dilated minus eroded; boundary is original minus eroded; exterior boundary is dilated minus original. Iterations use complete prior masks.

split: open-access


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

N = 1
observations = []
def solve(commands, size):
    full=set(range(size))
    out=[]
    for cmd in commands:
        source,kernel,mode,iterations=cmd
        source=set(source)&full
        kernel=set(kernel)
        def dilate(s): return {x for x in full if any(x-k in s for k in kernel)}
        def erode(s): return {x for x in full if kernel and all(x+k in s or x+k not in full for k in kernel)}
        result=set(source)
        for _ in range(max(0,iterations)):
            prior=set(result)
            if mode=='dilate': result=dilate(prior)
            elif mode=='erode': result=erode(prior)
            elif mode=='open': result=dilate(erode(prior))
            elif mode=='close': result=erode(dilate(prior))
            elif mode=='gradient': result=dilate(prior)-erode(prior)
            elif mode=='inner': result=prior-erode(prior)
            else: result=dilate(prior)-prior
        out.append(sorted(result))
    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([[[1], [0, 1], 'dilate', 1]], 4), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 4), [[1, 2]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 4), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 4), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 4), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 4), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 4), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 4), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 4), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 4), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 4), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 4), [[0, 1, 2]])
if N == 2:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 5), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 5), [[1, 2, 3]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 5), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 5), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 5), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 5), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 5), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 5), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 5), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 5), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 5), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 5), [[0, 1, 2]])
if N == 3:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 6), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 6), [[1, 2, 3, 4]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 6), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 6), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 6), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 6), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 6), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 6), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 6), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 6), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 6), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 6), [[0, 1, 2]])
if N == 4:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 7), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 7), [[1, 2, 3, 4, 5]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 7), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 7), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 7), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 7), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 7), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 7), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 7), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 7), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 7), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 7), [[0, 1, 2]])
if N == 5:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 8), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 8), [[1, 2, 3, 4, 5, 6]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 8), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 8), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 8), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 8), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 8), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 8), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 8), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 8), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 8), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 8), [[0, 1, 2]])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(commands, size):
    full=set(range(size))
    out=[]
    for cmd in commands:
        source,kernel,mode,iterations=cmd
        source=set(source)&full
        kernel=set(kernel)
        def dilate(s): return {x for x in full if any(x-k in s for k in kernel)}
        def erode(s): return {x for x in full if kernel and all(x+k in s for k in kernel if x+k in full)}
        result=set(source)
        for _ in range(max(0,iterations)):
            prior=set(result)
            if mode=='dilate': result=dilate(prior)
            elif mode=='erode': result=erode(prior)
            elif mode=='open': result=dilate(erode(prior))
            elif mode=='close': result=erode(dilate(prior))
            elif mode=='gradient': result=dilate(prior)-erode(prior)
            elif mode=='inner': result=prior-erode(prior)
            else: result=dilate(prior)-prior
        out.append(sorted(result))
    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([[[1], [0, 1], 'dilate', 1]], 4), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 4), [[1, 2]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 4), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 4), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 4), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 4), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 4), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 4), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 4), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 4), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 4), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 4), [[0, 1, 2]])
if N == 2:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 5), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 5), [[1, 2, 3]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 5), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 5), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 5), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 5), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 5), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 5), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 5), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 5), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 5), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 5), [[0, 1, 2]])
if N == 3:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 6), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 6), [[1, 2, 3, 4]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 6), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 6), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 6), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 6), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 6), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 6), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 6), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 6), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 6), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 6), [[0, 1, 2]])
if N == 4:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 7), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 7), [[1, 2, 3, 4, 5]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 7), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 7), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 7), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 7), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 7), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 7), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 7), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 7), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 7), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 7), [[0, 1, 2]])
if N == 5:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 8), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 8), [[1, 2, 3, 4, 5, 6]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 8), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 8), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 8), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 8), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 8), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 8), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 8), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 8), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 8), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 8), [[0, 1, 2]])
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:
Erosion treats samples outside the target as covered and preserves clipped border pixels.

A binary sample mask supports dilation/erosion by an explicit signed structuring element. Out-of-target samples are uncovered; empty structuring elements yield empty output. Open erodes then dilates; close dilates then erodes. Gradient is dilated minus eroded; boundary is original minus eroded; exterior boundary is dilated minus original. Iterations use complete prior masks.

split: open-access


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

N = 1
observations = []
def solve(commands, size):
    full=set(range(size))
    out=[]
    for cmd in commands:
        source,kernel,mode,iterations=cmd
        source=set(source)&full
        kernel=set(kernel)
        def dilate(s): return {x for x in full if any(x-k in s for k in kernel)}
        def erode(s): return {x for x in full if all(x+k in s for k in kernel)}
        result=set(source)
        for _ in range(max(0,iterations)):
            prior=set(result)
            if mode=='dilate': result=dilate(prior)
            elif mode=='erode': result=erode(prior)
            elif mode=='open': result=dilate(erode(prior))
            elif mode=='close': result=erode(dilate(prior))
            elif mode=='gradient': result=dilate(prior)-erode(prior)
            elif mode=='inner': result=prior-erode(prior)
            else: result=dilate(prior)-prior
        out.append(sorted(result))
    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([[[1], [0, 1], 'dilate', 1]], 4), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 4), [[1, 2]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 4), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 4), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 4), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 4), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 4), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 4), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 4), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 4), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 4), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 4), [[0, 1, 2]])
if N == 2:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 5), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 5), [[1, 2, 3]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 5), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 5), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 5), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 5), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 5), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 5), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 5), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 5), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 5), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 5), [[0, 1, 2]])
if N == 3:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 6), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 6), [[1, 2, 3, 4]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 6), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 6), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 6), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 6), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 6), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 6), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 6), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 6), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 6), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 6), [[0, 1, 2]])
if N == 4:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 7), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 7), [[1, 2, 3, 4, 5]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 7), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 7), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 7), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 7), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 7), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 7), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 7), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 7), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 7), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 7), [[0, 1, 2]])
if N == 5:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 8), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 8), [[1, 2, 3, 4, 5, 6]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 8), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 8), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 8), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 8), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 8), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 8), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 8), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 8), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 8), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 8), [[0, 1, 2]])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(commands, size):
    full=set(range(size))
    out=[]
    for cmd in commands:
        source,kernel,mode,iterations=cmd
        source=set(source)&full
        kernel=set(kernel)
        def dilate(s): return {x for x in full if any(x-k in s for k in kernel)}
        def erode(s): return {x for x in full if (kernel or x in s) and all(x+k in s for k in kernel)}
        result=set(source)
        for _ in range(max(0,iterations)):
            prior=set(result)
            if mode=='dilate': result=dilate(prior)
            elif mode=='erode': result=erode(prior)
            elif mode=='open': result=dilate(erode(prior))
            elif mode=='close': result=erode(dilate(prior))
            elif mode=='gradient': result=dilate(prior)-erode(prior)
            elif mode=='inner': result=prior-erode(prior)
            else: result=dilate(prior)-prior
        out.append(sorted(result))
    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([[[1], [0, 1], 'dilate', 1]], 4), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 4), [[1, 2]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 4), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 4), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 4), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 4), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 4), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 4), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 4), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 4), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 4), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 4), [[0, 1, 2]])
if N == 2:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 5), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 5), [[1, 2, 3]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 5), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 5), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 5), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 5), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 5), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 5), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 5), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 5), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 5), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 5), [[0, 1, 2]])
if N == 3:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 6), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 6), [[1, 2, 3, 4]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 6), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 6), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 6), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 6), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 6), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 6), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 6), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 6), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 6), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 6), [[0, 1, 2]])
if N == 4:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 7), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 7), [[1, 2, 3, 4, 5]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 7), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 7), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 7), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 7), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 7), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 7), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 7), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 7), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 7), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 7), [[0, 1, 2]])
if N == 5:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 8), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 8), [[1, 2, 3, 4, 5, 6]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 8), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 8), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 8), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 8), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 8), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 8), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 8), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 8), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 8), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 8), [[0, 1, 2]])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
An empty erosion kernel covers the whole target through vacuous truth.

A binary sample mask supports dilation/erosion by an explicit signed structuring element. Out-of-target samples are uncovered; empty structuring elements yield empty output. Open erodes then dilates; close dilates then erodes. Gradient is dilated minus eroded; boundary is original minus eroded; exterior boundary is dilated minus original. Iterations use complete prior masks.

split: open-access


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

N = 1
observations = []
def solve(commands, size):
    full=set(range(size))
    out=[]
    for cmd in commands:
        source,kernel,mode,iterations=cmd
        source=set(source)&full
        kernel=set(kernel)
        def dilate(s): return {x for x in full if any(x-k in s for k in kernel)}
        def erode(s): return {x for x in full if kernel and all(x+k in s for k in kernel)}
        result=set(source)
        for _ in range(max(0,iterations)):
            prior=set(result)
            if mode=='dilate': result=dilate(prior)
            elif mode=='erode': result=erode(prior)
            elif mode=='open': result=erode(dilate(prior))
            elif mode=='close': result=erode(dilate(prior))
            elif mode=='gradient': result=dilate(prior)-erode(prior)
            elif mode=='inner': result=prior-erode(prior)
            else: result=dilate(prior)-prior
        out.append(sorted(result))
    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([[[1], [0, 1], 'dilate', 1]], 4), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 4), [[1, 2]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 4), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 4), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 4), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 4), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 4), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 4), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 4), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 4), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 4), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 4), [[0, 1, 2]])
if N == 2:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 5), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 5), [[1, 2, 3]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 5), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 5), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 5), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 5), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 5), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 5), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 5), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 5), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 5), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 5), [[0, 1, 2]])
if N == 3:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 6), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 6), [[1, 2, 3, 4]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 6), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 6), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 6), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 6), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 6), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 6), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 6), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 6), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 6), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 6), [[0, 1, 2]])
if N == 4:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 7), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 7), [[1, 2, 3, 4, 5]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 7), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 7), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 7), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 7), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 7), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 7), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 7), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 7), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 7), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 7), [[0, 1, 2]])
if N == 5:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 8), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 8), [[1, 2, 3, 4, 5, 6]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 8), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 8), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 8), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 8), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 8), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 8), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 8), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 8), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 8), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 8), [[0, 1, 2]])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(commands, size):
    full=set(range(size))
    out=[]
    for cmd in commands:
        source,kernel,mode,iterations=cmd
        source=set(source)&full
        kernel=set(kernel)
        def dilate(s): return {x for x in full if any(x-k in s for k in kernel)}
        def erode(s): return {x for x in full if kernel and all(x+k in s for k in kernel)}
        result=set(source)
        for _ in range(max(0,iterations)):
            prior=set(result)
            if mode=='dilate': result=dilate(prior)
            elif mode=='erode': result=erode(prior)
            elif mode=='open': result=erode(prior)
            elif mode=='close': result=erode(dilate(prior))
            elif mode=='gradient': result=dilate(prior)-erode(prior)
            elif mode=='inner': result=prior-erode(prior)
            else: result=dilate(prior)-prior
        out.append(sorted(result))
    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([[[1], [0, 1], 'dilate', 1]], 4), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 4), [[1, 2]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 4), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 4), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 4), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 4), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 4), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 4), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 4), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 4), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 4), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 4), [[0, 1, 2]])
if N == 2:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 5), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 5), [[1, 2, 3]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 5), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 5), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 5), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 5), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 5), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 5), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 5), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 5), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 5), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 5), [[0, 1, 2]])
if N == 3:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 6), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 6), [[1, 2, 3, 4]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 6), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 6), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 6), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 6), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 6), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 6), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 6), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 6), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 6), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 6), [[0, 1, 2]])
if N == 4:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 7), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 7), [[1, 2, 3, 4, 5]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 7), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 7), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 7), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 7), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 7), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 7), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 7), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 7), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 7), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 7), [[0, 1, 2]])
if N == 5:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 8), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 8), [[1, 2, 3, 4, 5, 6]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 8), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 8), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 8), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 8), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 8), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 8), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 8), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 8), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 8), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 8), [[0, 1, 2]])
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:
Opening performs closing and bridges gaps instead of removing isolated coverage.

A binary sample mask supports dilation/erosion by an explicit signed structuring element. Out-of-target samples are uncovered; empty structuring elements yield empty output. Open erodes then dilates; close dilates then erodes. Gradient is dilated minus eroded; boundary is original minus eroded; exterior boundary is dilated minus original. Iterations use complete prior masks.

split: open-access


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

N = 1
observations = []
def solve(commands, size):
    full=set(range(size))
    out=[]
    for cmd in commands:
        source,kernel,mode,iterations=cmd
        source=set(source)&full
        kernel=set(kernel)
        def dilate(s): return {x for x in full if any(x-k in s for k in kernel)}
        def erode(s): return {x for x in full if kernel and all(x+k in s for k in kernel)}
        result=set(source)
        for _ in range(max(0,iterations)):
            prior=set(result)
            if mode=='dilate': result=dilate(prior)
            elif mode=='erode': result=erode(prior)
            elif mode=='open': result=dilate(erode(prior))
            elif mode=='close': result=dilate(erode(prior))
            elif mode=='gradient': result=dilate(prior)-erode(prior)
            elif mode=='inner': result=prior-erode(prior)
            else: result=dilate(prior)-prior
        out.append(sorted(result))
    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([[[1], [0, 1], 'dilate', 1]], 4), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 4), [[1, 2]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 4), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 4), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 4), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 4), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 4), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 4), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 4), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 4), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 4), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 4), [[0, 1, 2]])
if N == 2:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 5), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 5), [[1, 2, 3]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 5), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 5), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 5), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 5), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 5), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 5), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 5), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 5), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 5), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 5), [[0, 1, 2]])
if N == 3:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 6), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 6), [[1, 2, 3, 4]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 6), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 6), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 6), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 6), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 6), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 6), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 6), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 6), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 6), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 6), [[0, 1, 2]])
if N == 4:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 7), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 7), [[1, 2, 3, 4, 5]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 7), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 7), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 7), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 7), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 7), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 7), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 7), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 7), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 7), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 7), [[0, 1, 2]])
if N == 5:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 8), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 8), [[1, 2, 3, 4, 5, 6]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 8), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 8), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 8), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 8), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 8), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 8), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 8), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 8), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 8), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 8), [[0, 1, 2]])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(commands, size):
    full=set(range(size))
    out=[]
    for cmd in commands:
        source,kernel,mode,iterations=cmd
        source=set(source)&full
        kernel=set(kernel)
        def dilate(s): return {x for x in full if any(x-k in s for k in kernel)}
        def erode(s): return {x for x in full if kernel and all(x+k in s for k in kernel)}
        result=set(source)
        for _ in range(max(0,iterations)):
            prior=set(result)
            if mode=='dilate': result=dilate(prior)
            elif mode=='erode': result=erode(prior)
            elif mode=='open': result=dilate(erode(prior))
            elif mode=='close': result=dilate(prior)
            elif mode=='gradient': result=dilate(prior)-erode(prior)
            elif mode=='inner': result=prior-erode(prior)
            else: result=dilate(prior)-prior
        out.append(sorted(result))
    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([[[1], [0, 1], 'dilate', 1]], 4), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 4), [[1, 2]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 4), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 4), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 4), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 4), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 4), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 4), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 4), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 4), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 4), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 4), [[0, 1, 2]])
if N == 2:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 5), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 5), [[1, 2, 3]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 5), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 5), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 5), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 5), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 5), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 5), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 5), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 5), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 5), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 5), [[0, 1, 2]])
if N == 3:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 6), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 6), [[1, 2, 3, 4]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 6), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 6), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 6), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 6), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 6), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 6), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 6), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 6), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 6), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 6), [[0, 1, 2]])
if N == 4:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 7), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 7), [[1, 2, 3, 4, 5]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 7), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 7), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 7), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 7), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 7), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 7), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 7), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 7), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 7), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 7), [[0, 1, 2]])
if N == 5:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 8), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 8), [[1, 2, 3, 4, 5, 6]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 8), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 8), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 8), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 8), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 8), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 8), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 8), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 8), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 8), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 8), [[0, 1, 2]])
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:
Closing performs opening and deletes narrow coverage instead of closing holes.

A binary sample mask supports dilation/erosion by an explicit signed structuring element. Out-of-target samples are uncovered; empty structuring elements yield empty output. Open erodes then dilates; close dilates then erodes. Gradient is dilated minus eroded; boundary is original minus eroded; exterior boundary is dilated minus original. Iterations use complete prior masks.

split: open-access