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

N = 1
observations = []
def solve(commands, size):
    out=[]
    full=set(range(size))
    for numerator,denominator,rank,rotation,geometry,enabled,shader,alpha_enabled in commands:
        count=max(0,min(size,(numerator*size)//denominator)) if alpha_enabled else size
        ordering=[x for x in rank if x in full]
        selected={ordering[i] for i in range(min(count,len(ordering)))}
        selected={(x+rotation)%size for x in selected}
        geometric=set(geometry)&full
        fixed=set(enabled)&full
        shader_mask=full if shader is None else set(shader)&full
        out.append(sorted(selected & geometric & (fixed | shader_mask)))
    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, 2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 4), [[0, 1]])
    check('explicit sequence 1', solve([[1, 7, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 4), [[]])
    check('explicit sequence 2', solve([[2, 3, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 4), [[0, 1]])
    check('explicit sequence 3', solve([[1, 3, [9, 8, 7, 6, 5, 4, 3, 2, 1, 0], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 4), [[3]])
    check('explicit sequence 4', solve([[1, 2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 4), [[1, 2]])
    check('explicit sequence 5', solve([[1, 2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], -1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 4), [[0, 3]])
    check('explicit sequence 6', solve([[0, 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, False]], 4), [[0, 1, 2, 3]])
    check('explicit sequence 7', solve([[1, 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], True]], 4), [[]])
    check('explicit sequence 8', solve([[0, 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 4), [[]])
    check('explicit sequence 9', solve([[1, 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0], [1], True]], 4), [[]])
    check('explicit sequence 10', solve([[3, 2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 4), [[0, 1, 2, 3]])
if N == 2:
    check('explicit sequence 0', solve([[1, 2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 5), [[0, 1]])
    check('explicit sequence 1', solve([[1, 7, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 5), [[]])
    check('explicit sequence 2', solve([[2, 3, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 5), [[0, 1, 2]])
    check('explicit sequence 3', solve([[1, 3, [9, 8, 7, 6, 5, 4, 3, 2, 1, 0], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 5), [[4]])
    check('explicit sequence 4', solve([[1, 2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 5), [[1, 2]])
    check('explicit sequence 5', solve([[1, 2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], -1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 5), [[0, 4]])
    check('explicit sequence 6', solve([[0, 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, False]], 5), [[0, 1, 2, 3, 4]])
    check('explicit sequence 7', solve([[1, 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], True]], 5), [[]])
    check('explicit sequence 8', solve([[0, 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 5), [[]])
    check('explicit sequence 9', solve([[1, 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0], [1], True]], 5), [[]])
    check('explicit sequence 10', solve([[3, 2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 5), [[0, 1, 2, 3, 4]])
if N == 3:
    check('explicit sequence 0', solve([[1, 2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 6), [[0, 1, 2]])
    check('explicit sequence 1', solve([[1, 7, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 6), [[]])
    check('explicit sequence 2', solve([[2, 3, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 6), [[0, 1, 2, 3]])
    check('explicit sequence 3', solve([[1, 3, [9, 8, 7, 6, 5, 4, 3, 2, 1, 0], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 6), [[4, 5]])
    check('explicit sequence 4', solve([[1, 2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 6), [[1, 2, 3]])
    check('explicit sequence 5', solve([[1, 2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], -1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 6), [[0, 1, 5]])
    check('explicit sequence 6', solve([[0, 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, False]], 6), [[0, 1, 2, 3, 4, 5]])
    check('explicit sequence 7', solve([[1, 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], True]], 6), [[]])
    check('explicit sequence 8', solve([[0, 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 6), [[]])
    check('explicit sequence 9', solve([[1, 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0], [1], True]], 6), [[]])
    check('explicit sequence 10', solve([[3, 2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 6), [[0, 1, 2, 3, 4, 5]])
if N == 4:
    check('explicit sequence 0', solve([[1, 2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 7), [[0, 1, 2]])
    check('explicit sequence 1', solve([[1, 7, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 7), [[0]])
    check('explicit sequence 2', solve([[2, 3, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 7), [[0, 1, 2, 3]])
    check('explicit sequence 3', solve([[1, 3, [9, 8, 7, 6, 5, 4, 3, 2, 1, 0], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 7), [[5, 6]])
    check('explicit sequence 4', solve([[1, 2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 7), [[1, 2, 3]])
    check('explicit sequence 5', solve([[1, 2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], -1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 7), [[0, 1, 6]])
    check('explicit sequence 6', solve([[0, 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, False]], 7), [[0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 7', solve([[1, 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], True]], 7), [[]])
    check('explicit sequence 8', solve([[0, 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 7), [[]])
    check('explicit sequence 9', solve([[1, 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0], [1], True]], 7), [[]])
    check('explicit sequence 10', solve([[3, 2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 7), [[0, 1, 2, 3, 4, 5, 6]])
if N == 5:
    check('explicit sequence 0', solve([[1, 2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 8), [[0, 1, 2, 3]])
    check('explicit sequence 1', solve([[1, 7, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 8), [[0]])
    check('explicit sequence 2', solve([[2, 3, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 8), [[0, 1, 2, 3, 4]])
    check('explicit sequence 3', solve([[1, 3, [9, 8, 7, 6, 5, 4, 3, 2, 1, 0], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 8), [[6, 7]])
    check('explicit sequence 4', solve([[1, 2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 8), [[1, 2, 3, 4]])
    check('explicit sequence 5', solve([[1, 2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], -1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 8), [[0, 1, 2, 7]])
    check('explicit sequence 6', solve([[0, 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, False]], 8), [[0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 7', solve([[1, 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], True]], 8), [[]])
    check('explicit sequence 8', solve([[0, 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 8), [[]])
    check('explicit sequence 9', solve([[1, 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0], [1], True]], 8), [[]])
    check('explicit sequence 10', solve([[3, 2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 8), [[0, 1, 2, 3, 4, 5, 6, 7]])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(commands, size):
    out=[]
    full=set(range(size))
    for numerator,denominator,rank,rotation,geometry,enabled,shader,alpha_enabled in commands:
        count=max(0,min(size,(numerator*size)//denominator)) if alpha_enabled else size
        ordering=[x for x in rank if x in full]
        selected={ordering[i] for i in range(min(count,len(ordering)))}
        selected={(x+rotation)%size for x in selected}
        geometric=set(geometry)&full
        fixed=set(enabled)&full
        shader_mask=full if shader is None else set(shader)&full
        out.append(sorted(selected & geometric & shader_mask))
    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, 2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 4), [[0, 1]])
    check('explicit sequence 1', solve([[1, 7, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 4), [[]])
    check('explicit sequence 2', solve([[2, 3, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 4), [[0, 1]])
    check('explicit sequence 3', solve([[1, 3, [9, 8, 7, 6, 5, 4, 3, 2, 1, 0], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 4), [[3]])
    check('explicit sequence 4', solve([[1, 2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 4), [[1, 2]])
    check('explicit sequence 5', solve([[1, 2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], -1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 4), [[0, 3]])
    check('explicit sequence 6', solve([[0, 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, False]], 4), [[0, 1, 2, 3]])
    check('explicit sequence 7', solve([[1, 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], True]], 4), [[]])
    check('explicit sequence 8', solve([[0, 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 4), [[]])
    check('explicit sequence 9', solve([[1, 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0], [1], True]], 4), [[]])
    check('explicit sequence 10', solve([[3, 2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 4), [[0, 1, 2, 3]])
if N == 2:
    check('explicit sequence 0', solve([[1, 2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 5), [[0, 1]])
    check('explicit sequence 1', solve([[1, 7, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 5), [[]])
    check('explicit sequence 2', solve([[2, 3, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 5), [[0, 1, 2]])
    check('explicit sequence 3', solve([[1, 3, [9, 8, 7, 6, 5, 4, 3, 2, 1, 0], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 5), [[4]])
    check('explicit sequence 4', solve([[1, 2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 5), [[1, 2]])
    check('explicit sequence 5', solve([[1, 2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], -1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 5), [[0, 4]])
    check('explicit sequence 6', solve([[0, 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, False]], 5), [[0, 1, 2, 3, 4]])
    check('explicit sequence 7', solve([[1, 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], True]], 5), [[]])
    check('explicit sequence 8', solve([[0, 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 5), [[]])
    check('explicit sequence 9', solve([[1, 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0], [1], True]], 5), [[]])
    check('explicit sequence 10', solve([[3, 2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 5), [[0, 1, 2, 3, 4]])
if N == 3:
    check('explicit sequence 0', solve([[1, 2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 6), [[0, 1, 2]])
    check('explicit sequence 1', solve([[1, 7, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 6), [[]])
    check('explicit sequence 2', solve([[2, 3, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 6), [[0, 1, 2, 3]])
    check('explicit sequence 3', solve([[1, 3, [9, 8, 7, 6, 5, 4, 3, 2, 1, 0], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 6), [[4, 5]])
    check('explicit sequence 4', solve([[1, 2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 6), [[1, 2, 3]])
    check('explicit sequence 5', solve([[1, 2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], -1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 6), [[0, 1, 5]])
    check('explicit sequence 6', solve([[0, 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, False]], 6), [[0, 1, 2, 3, 4, 5]])
    check('explicit sequence 7', solve([[1, 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], True]], 6), [[]])
    check('explicit sequence 8', solve([[0, 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 6), [[]])
    check('explicit sequence 9', solve([[1, 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0], [1], True]], 6), [[]])
    check('explicit sequence 10', solve([[3, 2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 6), [[0, 1, 2, 3, 4, 5]])
if N == 4:
    check('explicit sequence 0', solve([[1, 2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 7), [[0, 1, 2]])
    check('explicit sequence 1', solve([[1, 7, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 7), [[0]])
    check('explicit sequence 2', solve([[2, 3, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 7), [[0, 1, 2, 3]])
    check('explicit sequence 3', solve([[1, 3, [9, 8, 7, 6, 5, 4, 3, 2, 1, 0], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 7), [[5, 6]])
    check('explicit sequence 4', solve([[1, 2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 7), [[1, 2, 3]])
    check('explicit sequence 5', solve([[1, 2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], -1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 7), [[0, 1, 6]])
    check('explicit sequence 6', solve([[0, 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, False]], 7), [[0, 1, 2, 3, 4, 5, 6]])
    check('explicit sequence 7', solve([[1, 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], True]], 7), [[]])
    check('explicit sequence 8', solve([[0, 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 7), [[]])
    check('explicit sequence 9', solve([[1, 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0], [1], True]], 7), [[]])
    check('explicit sequence 10', solve([[3, 2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 7), [[0, 1, 2, 3, 4, 5, 6]])
if N == 5:
    check('explicit sequence 0', solve([[1, 2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 8), [[0, 1, 2, 3]])
    check('explicit sequence 1', solve([[1, 7, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 8), [[0]])
    check('explicit sequence 2', solve([[2, 3, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 8), [[0, 1, 2, 3, 4]])
    check('explicit sequence 3', solve([[1, 3, [9, 8, 7, 6, 5, 4, 3, 2, 1, 0], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 8), [[6, 7]])
    check('explicit sequence 4', solve([[1, 2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 8), [[1, 2, 3, 4]])
    check('explicit sequence 5', solve([[1, 2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], -1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 8), [[0, 1, 2, 7]])
    check('explicit sequence 6', solve([[0, 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, False]], 8), [[0, 1, 2, 3, 4, 5, 6, 7]])
    check('explicit sequence 7', solve([[1, 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], True]], 8), [[]])
    check('explicit sequence 8', solve([[0, 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 8), [[]])
    check('explicit sequence 9', solve([[1, 1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0], [1], True]], 8), [[]])
    check('explicit sequence 10', solve([[3, 2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], None, True]], 8), [[0, 1, 2, 3, 4, 5, 6, 7]])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Fixed-function and shader masks are unioned so either can re-enable a disabled sample.

Each command supplies alpha numerator over denominator, a permutation ranking the physical samples, rotation, geometric sample mask, fixed enable mask and optional shader mask. Alpha selects floor(alpha*size) ranks, clamped to [0,size]; alpha-disabled commands select all ranks. Rotate selected physical sample IDs modulo size, then intersect masks. A missing shader mask passes all samples; an explicit empty mask passes none. Return sorted surviving sample IDs.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    lo=0
    hi=size-1
    def code(x,y):
        c=0
        if x<lo: c|=1
        elif x>=hi: c|=2
        if y<lo: c|=4
        elif y>hi: c|=8
        return c
    out=[]
    for x0,y0,x1,y1 in commands:
        x0,y0,x1,y1=[Fraction(v) for v in (x0,y0,x1,y1)]
        c0,c1=code(x0,y0),code(x1,y1)
        result=None
        for _ in range(5):
            if not (c0|c1):
                result=[int((v+Fraction(1,2))//1) for v in (x0,y0,x1,y1)]
                break
            if c0&c1: break
            c=c0 if c0 else c1
            if c&12 and y1==y0 or c&3 and x1==x0: break
            if c&8: x,y=x0+(x1-x0)*(hi-y0)/(y1-y0),Fraction(hi)
            elif c&4: x,y=x0+(x1-x0)*(lo-y0)/(y1-y0),Fraction(lo)
            elif c&2: x,y=Fraction(hi),y0+(y1-y0)*(hi-x0)/(x1-x0)
            else: x,y=Fraction(lo),y0+(y1-y0)*(lo-x0)/(x1-x0)
            if c==c0:
                x0,y0=x,y
                c0=code(x0,y0)
            else:
                x1,y1=x,y
                c1=code(x1,y1)
        out.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 case 0', solve([[1, 1, 4, 3]], 6), [[1, 1, 4, 3]])
    check('explicit case 1', solve([[-3, 2, 8, 2]], 6), [[0, 2, 5, 2]])
    check('explicit case 2', solve([[-2, -2, 7, 7]], 6), [[0, 0, 5, 5]])
    check('explicit case 3', solve([[-3, 0, -1, 5]], 6), [None])
    check('explicit case 4', solve([[0, 0, 5, 5]], 6), [[0, 0, 5, 5]])
    check('explicit case 5', solve([[0, 0, '5.8', 0]], 6), [[0, 0, 5, 0]])
    check('explicit case 6', solve([[1, -4, -2, 2]], 6), [None])
    check('explicit case 7', solve([[-2, 1, 3, -4]], 6), [None])
    check('explicit case 8', solve([[-2, 1, 4, 10]], 6), [[0, 4, 1, 5]])
    check('explicit case 9', solve([[0, '2.5', 5, '2.5']], 6), [[0, 3, 5, 3]])
    check('explicit case 10', solve([[0, '1.5', 2, '1.5']], 6), [[0, 2, 2, 2]])
    check('explicit case 11', solve([[0, 0, 9, 0]], 6), [[0, 0, 5, 0]])
    check('explicit case 12', solve([['-5', '-7/2', '10', '17/2']], 6), [[0, 1, 5, 5]])
    check('explicit case 13', solve([[2, 1, 4, 11]], 6), [[2, 1, 3, 5]])
    check('explicit case 14', solve([[3, 8, 1, -2]], 6), [[2, 5, 1, 0]])
    check('explicit case 15', solve([[8, 1, 1, 9]], 6), [[5, 4, 5, 5]])
if N == 2:
    check('explicit case 0', solve([[1, 1, 5, 4]], 7), [[1, 1, 5, 4]])
    check('explicit case 1', solve([[-3, 2, 9, 2]], 7), [[0, 2, 6, 2]])
    check('explicit case 2', solve([[-2, -2, 8, 8]], 7), [[0, 0, 6, 6]])
    check('explicit case 3', solve([[-3, 0, -1, 6]], 7), [None])
    check('explicit case 4', solve([[0, 0, 6, 6]], 7), [[0, 0, 6, 6]])
    check('explicit case 5', solve([[0, 0, '6.8', 0]], 7), [[0, 0, 6, 0]])
    check('explicit case 6', solve([[1, -4, -2, 2]], 7), [None])
    check('explicit case 7', solve([[-2, 1, 3, -4]], 7), [None])
    check('explicit case 8', solve([[-2, 1, 4, 11]], 7), [[0, 4, 1, 6]])
    check('explicit case 9', solve([[0, '2.5', 6, '2.5']], 7), [[0, 3, 6, 3]])
    check('explicit case 10', solve([[0, '1.5', 2, '1.5']], 7), [[0, 2, 2, 2]])
    check('explicit case 11', solve([[0, 0, 10, 0]], 7), [[0, 0, 6, 0]])
    check('explicit case 12', solve([['-6', '-9/2', '12', '21/2']], 7), [[0, 1, 6, 6]])
    check('explicit case 13', solve([[2, 1, 4, 12]], 7), [[2, 1, 3, 6]])
    check('explicit case 14', solve([[3, 9, 1, -2]], 7), [[2, 6, 1, 0]])
    check('explicit case 15', solve([[9, 1, 1, 10]], 7), [[6, 4, 5, 6]])
if N == 3:
    check('explicit case 0', solve([[1, 1, 6, 5]], 8), [[1, 1, 6, 5]])
    check('explicit case 1', solve([[-3, 2, 10, 2]], 8), [[0, 2, 7, 2]])
    check('explicit case 2', solve([[-2, -2, 9, 9]], 8), [[0, 0, 7, 7]])
    check('explicit case 3', solve([[-3, 0, -1, 7]], 8), [None])
    check('explicit case 4', solve([[0, 0, 7, 7]], 8), [[0, 0, 7, 7]])
    check('explicit case 5', solve([[0, 0, '7.8', 0]], 8), [[0, 0, 7, 0]])
    check('explicit case 6', solve([[1, -4, -2, 2]], 8), [None])
    check('explicit case 7', solve([[-2, 1, 3, -4]], 8), [None])
    check('explicit case 8', solve([[-2, 1, 4, 12]], 8), [[0, 5, 1, 7]])
    check('explicit case 9', solve([[0, '2.5', 7, '2.5']], 8), [[0, 3, 7, 3]])
    check('explicit case 10', solve([[0, '1.5', 2, '1.5']], 8), [[0, 2, 2, 2]])
    check('explicit case 11', solve([[0, 0, 11, 0]], 8), [[0, 0, 7, 0]])
    check('explicit case 12', solve([['-7', '-11/2', '14', '25/2']], 8), [[0, 1, 7, 7]])
    check('explicit case 13', solve([[2, 1, 4, 13]], 8), [[2, 1, 3, 7]])
    check('explicit case 14', solve([[3, 10, 1, -2]], 8), [[3, 7, 1, 0]])
    check('explicit case 15', solve([[10, 1, 1, 11]], 8), [[7, 4, 5, 7]])
if N == 4:
    check('explicit case 0', solve([[1, 1, 7, 6]], 9), [[1, 1, 7, 6]])
    check('explicit case 1', solve([[-3, 2, 11, 2]], 9), [[0, 2, 8, 2]])
    check('explicit case 2', solve([[-2, -2, 10, 10]], 9), [[0, 0, 8, 8]])
    check('explicit case 3', solve([[-3, 0, -1, 8]], 9), [None])
    check('explicit case 4', solve([[0, 0, 8, 8]], 9), [[0, 0, 8, 8]])
    check('explicit case 5', solve([[0, 0, '8.8', 0]], 9), [[0, 0, 8, 0]])
    check('explicit case 6', solve([[1, -4, -2, 2]], 9), [None])
    check('explicit case 7', solve([[-2, 1, 3, -4]], 9), [None])
    check('explicit case 8', solve([[-2, 1, 4, 13]], 9), [[0, 5, 2, 8]])
    check('explicit case 9', solve([[0, '2.5', 8, '2.5']], 9), [[0, 3, 8, 3]])
    check('explicit case 10', solve([[0, '1.5', 2, '1.5']], 9), [[0, 2, 2, 2]])
    check('explicit case 11', solve([[0, 0, 12, 0]], 9), [[0, 0, 8, 0]])
    check('explicit case 12', solve([['-8', '-13/2', '16', '29/2']], 9), [[0, 1, 8, 8]])
    check('explicit case 13', solve([[2, 1, 4, 14]], 9), [[2, 1, 3, 8]])
    check('explicit case 14', solve([[3, 11, 1, -2]], 9), [[3, 8, 1, 0]])
    check('explicit case 15', solve([[11, 1, 1, 12]], 9), [[8, 4, 5, 8]])
if N == 5:
    check('explicit case 0', solve([[1, 1, 8, 7]], 10), [[1, 1, 8, 7]])
    check('explicit case 1', solve([[-3, 2, 12, 2]], 10), [[0, 2, 9, 2]])
    check('explicit case 2', solve([[-2, -2, 11, 11]], 10), [[0, 0, 9, 9]])
    check('explicit case 3', solve([[-3, 0, -1, 9]], 10), [None])
    check('explicit case 4', solve([[0, 0, 9, 9]], 10), [[0, 0, 9, 9]])
    check('explicit case 5', solve([[0, 0, '9.8', 0]], 10), [[0, 0, 9, 0]])
    check('explicit case 6', solve([[1, -4, -2, 2]], 10), [None])
    check('explicit case 7', solve([[-2, 1, 3, -4]], 10), [None])
    check('explicit case 8', solve([[-2, 1, 4, 14]], 10), [[0, 5, 2, 9]])
    check('explicit case 9', solve([[0, '2.5', 9, '2.5']], 10), [[0, 3, 9, 3]])
    check('explicit case 10', solve([[0, '1.5', 2, '1.5']], 10), [[0, 2, 2, 2]])
    check('explicit case 11', solve([[0, 0, 13, 0]], 10), [[0, 0, 9, 0]])
    check('explicit case 12', solve([['-9', '-15/2', '18', '33/2']], 10), [[0, 1, 9, 9]])
    check('explicit case 13', solve([[2, 1, 4, 15]], 10), [[2, 1, 3, 9]])
    check('explicit case 14', solve([[3, 12, 1, -2]], 10), [[3, 9, 1, 0]])
    check('explicit case 15', solve([[12, 1, 1, 13]], 10), [[9, 4, 5, 9]])
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
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    lo=0
    hi=size-1
    def code(x,y):
        c=0
        if x<lo: c|=1
        elif x>=hi+1: c|=2
        if y<lo: c|=4
        elif y>hi: c|=8
        return c
    out=[]
    for x0,y0,x1,y1 in commands:
        x0,y0,x1,y1=[Fraction(v) for v in (x0,y0,x1,y1)]
        c0,c1=code(x0,y0),code(x1,y1)
        result=None
        for _ in range(5):
            if not (c0|c1):
                result=[int((v+Fraction(1,2))//1) for v in (x0,y0,x1,y1)]
                break
            if c0&c1: break
            c=c0 if c0 else c1
            if c&12 and y1==y0 or c&3 and x1==x0: break
            if c&8: x,y=x0+(x1-x0)*(hi-y0)/(y1-y0),Fraction(hi)
            elif c&4: x,y=x0+(x1-x0)*(lo-y0)/(y1-y0),Fraction(lo)
            elif c&2: x,y=Fraction(hi),y0+(y1-y0)*(hi-x0)/(x1-x0)
            else: x,y=Fraction(lo),y0+(y1-y0)*(lo-x0)/(x1-x0)
            if c==c0:
                x0,y0=x,y
                c0=code(x0,y0)
            else:
                x1,y1=x,y
                c1=code(x1,y1)
        out.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 case 0', solve([[1, 1, 4, 3]], 6), [[1, 1, 4, 3]])
    check('explicit case 1', solve([[-3, 2, 8, 2]], 6), [[0, 2, 5, 2]])
    check('explicit case 2', solve([[-2, -2, 7, 7]], 6), [[0, 0, 5, 5]])
    check('explicit case 3', solve([[-3, 0, -1, 5]], 6), [None])
    check('explicit case 4', solve([[0, 0, 5, 5]], 6), [[0, 0, 5, 5]])
    check('explicit case 5', solve([[0, 0, '5.8', 0]], 6), [[0, 0, 5, 0]])
    check('explicit case 6', solve([[1, -4, -2, 2]], 6), [None])
    check('explicit case 7', solve([[-2, 1, 3, -4]], 6), [None])
    check('explicit case 8', solve([[-2, 1, 4, 10]], 6), [[0, 4, 1, 5]])
    check('explicit case 9', solve([[0, '2.5', 5, '2.5']], 6), [[0, 3, 5, 3]])
    check('explicit case 10', solve([[0, '1.5', 2, '1.5']], 6), [[0, 2, 2, 2]])
    check('explicit case 11', solve([[0, 0, 9, 0]], 6), [[0, 0, 5, 0]])
    check('explicit case 12', solve([['-5', '-7/2', '10', '17/2']], 6), [[0, 1, 5, 5]])
    check('explicit case 13', solve([[2, 1, 4, 11]], 6), [[2, 1, 3, 5]])
    check('explicit case 14', solve([[3, 8, 1, -2]], 6), [[2, 5, 1, 0]])
    check('explicit case 15', solve([[8, 1, 1, 9]], 6), [[5, 4, 5, 5]])
if N == 2:
    check('explicit case 0', solve([[1, 1, 5, 4]], 7), [[1, 1, 5, 4]])
    check('explicit case 1', solve([[-3, 2, 9, 2]], 7), [[0, 2, 6, 2]])
    check('explicit case 2', solve([[-2, -2, 8, 8]], 7), [[0, 0, 6, 6]])
    check('explicit case 3', solve([[-3, 0, -1, 6]], 7), [None])
    check('explicit case 4', solve([[0, 0, 6, 6]], 7), [[0, 0, 6, 6]])
    check('explicit case 5', solve([[0, 0, '6.8', 0]], 7), [[0, 0, 6, 0]])
    check('explicit case 6', solve([[1, -4, -2, 2]], 7), [None])
    check('explicit case 7', solve([[-2, 1, 3, -4]], 7), [None])
    check('explicit case 8', solve([[-2, 1, 4, 11]], 7), [[0, 4, 1, 6]])
    check('explicit case 9', solve([[0, '2.5', 6, '2.5']], 7), [[0, 3, 6, 3]])
    check('explicit case 10', solve([[0, '1.5', 2, '1.5']], 7), [[0, 2, 2, 2]])
    check('explicit case 11', solve([[0, 0, 10, 0]], 7), [[0, 0, 6, 0]])
    check('explicit case 12', solve([['-6', '-9/2', '12', '21/2']], 7), [[0, 1, 6, 6]])
    check('explicit case 13', solve([[2, 1, 4, 12]], 7), [[2, 1, 3, 6]])
    check('explicit case 14', solve([[3, 9, 1, -2]], 7), [[2, 6, 1, 0]])
    check('explicit case 15', solve([[9, 1, 1, 10]], 7), [[6, 4, 5, 6]])
if N == 3:
    check('explicit case 0', solve([[1, 1, 6, 5]], 8), [[1, 1, 6, 5]])
    check('explicit case 1', solve([[-3, 2, 10, 2]], 8), [[0, 2, 7, 2]])
    check('explicit case 2', solve([[-2, -2, 9, 9]], 8), [[0, 0, 7, 7]])
    check('explicit case 3', solve([[-3, 0, -1, 7]], 8), [None])
    check('explicit case 4', solve([[0, 0, 7, 7]], 8), [[0, 0, 7, 7]])
    check('explicit case 5', solve([[0, 0, '7.8', 0]], 8), [[0, 0, 7, 0]])
    check('explicit case 6', solve([[1, -4, -2, 2]], 8), [None])
    check('explicit case 7', solve([[-2, 1, 3, -4]], 8), [None])
    check('explicit case 8', solve([[-2, 1, 4, 12]], 8), [[0, 5, 1, 7]])
    check('explicit case 9', solve([[0, '2.5', 7, '2.5']], 8), [[0, 3, 7, 3]])
    check('explicit case 10', solve([[0, '1.5', 2, '1.5']], 8), [[0, 2, 2, 2]])
    check('explicit case 11', solve([[0, 0, 11, 0]], 8), [[0, 0, 7, 0]])
    check('explicit case 12', solve([['-7', '-11/2', '14', '25/2']], 8), [[0, 1, 7, 7]])
    check('explicit case 13', solve([[2, 1, 4, 13]], 8), [[2, 1, 3, 7]])
    check('explicit case 14', solve([[3, 10, 1, -2]], 8), [[3, 7, 1, 0]])
    check('explicit case 15', solve([[10, 1, 1, 11]], 8), [[7, 4, 5, 7]])
if N == 4:
    check('explicit case 0', solve([[1, 1, 7, 6]], 9), [[1, 1, 7, 6]])
    check('explicit case 1', solve([[-3, 2, 11, 2]], 9), [[0, 2, 8, 2]])
    check('explicit case 2', solve([[-2, -2, 10, 10]], 9), [[0, 0, 8, 8]])
    check('explicit case 3', solve([[-3, 0, -1, 8]], 9), [None])
    check('explicit case 4', solve([[0, 0, 8, 8]], 9), [[0, 0, 8, 8]])
    check('explicit case 5', solve([[0, 0, '8.8', 0]], 9), [[0, 0, 8, 0]])
    check('explicit case 6', solve([[1, -4, -2, 2]], 9), [None])
    check('explicit case 7', solve([[-2, 1, 3, -4]], 9), [None])
    check('explicit case 8', solve([[-2, 1, 4, 13]], 9), [[0, 5, 2, 8]])
    check('explicit case 9', solve([[0, '2.5', 8, '2.5']], 9), [[0, 3, 8, 3]])
    check('explicit case 10', solve([[0, '1.5', 2, '1.5']], 9), [[0, 2, 2, 2]])
    check('explicit case 11', solve([[0, 0, 12, 0]], 9), [[0, 0, 8, 0]])
    check('explicit case 12', solve([['-8', '-13/2', '16', '29/2']], 9), [[0, 1, 8, 8]])
    check('explicit case 13', solve([[2, 1, 4, 14]], 9), [[2, 1, 3, 8]])
    check('explicit case 14', solve([[3, 11, 1, -2]], 9), [[3, 8, 1, 0]])
    check('explicit case 15', solve([[11, 1, 1, 12]], 9), [[8, 4, 5, 8]])
if N == 5:
    check('explicit case 0', solve([[1, 1, 8, 7]], 10), [[1, 1, 8, 7]])
    check('explicit case 1', solve([[-3, 2, 12, 2]], 10), [[0, 2, 9, 2]])
    check('explicit case 2', solve([[-2, -2, 11, 11]], 10), [[0, 0, 9, 9]])
    check('explicit case 3', solve([[-3, 0, -1, 9]], 10), [None])
    check('explicit case 4', solve([[0, 0, 9, 9]], 10), [[0, 0, 9, 9]])
    check('explicit case 5', solve([[0, 0, '9.8', 0]], 10), [[0, 0, 9, 0]])
    check('explicit case 6', solve([[1, -4, -2, 2]], 10), [None])
    check('explicit case 7', solve([[-2, 1, 3, -4]], 10), [None])
    check('explicit case 8', solve([[-2, 1, 4, 14]], 10), [[0, 5, 2, 9]])
    check('explicit case 9', solve([[0, '2.5', 9, '2.5']], 10), [[0, 3, 9, 3]])
    check('explicit case 10', solve([[0, '1.5', 2, '1.5']], 10), [[0, 2, 2, 2]])
    check('explicit case 11', solve([[0, 0, 13, 0]], 10), [[0, 0, 9, 0]])
    check('explicit case 12', solve([['-9', '-15/2', '18', '33/2']], 10), [[0, 1, 9, 9]])
    check('explicit case 13', solve([[2, 1, 4, 15]], 10), [[2, 1, 3, 9]])
    check('explicit case 14', solve([[3, 12, 1, -2]], 10), [[3, 9, 1, 0]])
    check('explicit case 15', solve([[12, 1, 1, 13]], 10), [[9, 4, 5, 9]])
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 pixel center exactly on the last column is classified as outside, so clipping it back onto the same edge never clears the outcode and the segment is dropped.

Each command is a segment [x0,y0,x1,y1] whose endpoints are integers or exact decimal/rational strings in pixel-center coordinates. The window is the closed square [0,size-1]x[0,size-1] of pixel centers. Outcodes use strict outside tests (left 1, right 2, below 4, above 8). Both codes zero accepts; a shared bit rejects; otherwise the outside endpoint (endpoint 0 first) is moved to the highest set edge in above, below, right, left order and its code is recomputed from the new point; a clip against an edge parallel to the segment is treated as a rejection. At most five iterations are allowed; an unresolved or rejected segment returns None. Accepted endpoints round half-up to integer pixels.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    lo=0
    hi=size-1
    def code(x,y):
        c=0
        if x<lo: c|=1
        elif x>hi: c|=2
        if y<lo: c|=4
        elif y>hi: c|=8
        return c
    out=[]
    for x0,y0,x1,y1 in commands:
        x0,y0,x1,y1=[Fraction(v) for v in (x0,y0,x1,y1)]
        c0,c1=code(x0,y0),code(x1,y1)
        result=None
        for _ in range(5):
            if not (c0|c1):
                result=[int((v+Fraction(1,2))//1) for v in (x0,y0,x1,y1)]
                break
            if c0 and c1: break
            c=c0 if c0 else c1
            if c&12 and y1==y0 or c&3 and x1==x0: break
            if c&8: x,y=x0+(x1-x0)*(hi-y0)/(y1-y0),Fraction(hi)
            elif c&4: x,y=x0+(x1-x0)*(lo-y0)/(y1-y0),Fraction(lo)
            elif c&2: x,y=Fraction(hi),y0+(y1-y0)*(hi-x0)/(x1-x0)
            else: x,y=Fraction(lo),y0+(y1-y0)*(lo-x0)/(x1-x0)
            if c==c0:
                x0,y0=x,y
                c0=code(x0,y0)
            else:
                x1,y1=x,y
                c1=code(x1,y1)
        out.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 case 0', solve([[1, 1, 4, 3]], 6), [[1, 1, 4, 3]])
    check('explicit case 1', solve([[-3, 2, 8, 2]], 6), [[0, 2, 5, 2]])
    check('explicit case 2', solve([[-2, -2, 7, 7]], 6), [[0, 0, 5, 5]])
    check('explicit case 3', solve([[-3, 0, -1, 5]], 6), [None])
    check('explicit case 4', solve([[0, 0, 5, 5]], 6), [[0, 0, 5, 5]])
    check('explicit case 5', solve([[0, 0, '5.8', 0]], 6), [[0, 0, 5, 0]])
    check('explicit case 6', solve([[1, -4, -2, 2]], 6), [None])
    check('explicit case 7', solve([[-2, 1, 3, -4]], 6), [None])
    check('explicit case 8', solve([[-2, 1, 4, 10]], 6), [[0, 4, 1, 5]])
    check('explicit case 9', solve([[0, '2.5', 5, '2.5']], 6), [[0, 3, 5, 3]])
    check('explicit case 10', solve([[0, '1.5', 2, '1.5']], 6), [[0, 2, 2, 2]])
    check('explicit case 11', solve([[0, 0, 9, 0]], 6), [[0, 0, 5, 0]])
    check('explicit case 12', solve([['-5', '-7/2', '10', '17/2']], 6), [[0, 1, 5, 5]])
    check('explicit case 13', solve([[2, 1, 4, 11]], 6), [[2, 1, 3, 5]])
    check('explicit case 14', solve([[3, 8, 1, -2]], 6), [[2, 5, 1, 0]])
    check('explicit case 15', solve([[8, 1, 1, 9]], 6), [[5, 4, 5, 5]])
if N == 2:
    check('explicit case 0', solve([[1, 1, 5, 4]], 7), [[1, 1, 5, 4]])
    check('explicit case 1', solve([[-3, 2, 9, 2]], 7), [[0, 2, 6, 2]])
    check('explicit case 2', solve([[-2, -2, 8, 8]], 7), [[0, 0, 6, 6]])
    check('explicit case 3', solve([[-3, 0, -1, 6]], 7), [None])
    check('explicit case 4', solve([[0, 0, 6, 6]], 7), [[0, 0, 6, 6]])
    check('explicit case 5', solve([[0, 0, '6.8', 0]], 7), [[0, 0, 6, 0]])
    check('explicit case 6', solve([[1, -4, -2, 2]], 7), [None])
    check('explicit case 7', solve([[-2, 1, 3, -4]], 7), [None])
    check('explicit case 8', solve([[-2, 1, 4, 11]], 7), [[0, 4, 1, 6]])
    check('explicit case 9', solve([[0, '2.5', 6, '2.5']], 7), [[0, 3, 6, 3]])
    check('explicit case 10', solve([[0, '1.5', 2, '1.5']], 7), [[0, 2, 2, 2]])
    check('explicit case 11', solve([[0, 0, 10, 0]], 7), [[0, 0, 6, 0]])
    check('explicit case 12', solve([['-6', '-9/2', '12', '21/2']], 7), [[0, 1, 6, 6]])
    check('explicit case 13', solve([[2, 1, 4, 12]], 7), [[2, 1, 3, 6]])
    check('explicit case 14', solve([[3, 9, 1, -2]], 7), [[2, 6, 1, 0]])
    check('explicit case 15', solve([[9, 1, 1, 10]], 7), [[6, 4, 5, 6]])
if N == 3:
    check('explicit case 0', solve([[1, 1, 6, 5]], 8), [[1, 1, 6, 5]])
    check('explicit case 1', solve([[-3, 2, 10, 2]], 8), [[0, 2, 7, 2]])
    check('explicit case 2', solve([[-2, -2, 9, 9]], 8), [[0, 0, 7, 7]])
    check('explicit case 3', solve([[-3, 0, -1, 7]], 8), [None])
    check('explicit case 4', solve([[0, 0, 7, 7]], 8), [[0, 0, 7, 7]])
    check('explicit case 5', solve([[0, 0, '7.8', 0]], 8), [[0, 0, 7, 0]])
    check('explicit case 6', solve([[1, -4, -2, 2]], 8), [None])
    check('explicit case 7', solve([[-2, 1, 3, -4]], 8), [None])
    check('explicit case 8', solve([[-2, 1, 4, 12]], 8), [[0, 5, 1, 7]])
    check('explicit case 9', solve([[0, '2.5', 7, '2.5']], 8), [[0, 3, 7, 3]])
    check('explicit case 10', solve([[0, '1.5', 2, '1.5']], 8), [[0, 2, 2, 2]])
    check('explicit case 11', solve([[0, 0, 11, 0]], 8), [[0, 0, 7, 0]])
    check('explicit case 12', solve([['-7', '-11/2', '14', '25/2']], 8), [[0, 1, 7, 7]])
    check('explicit case 13', solve([[2, 1, 4, 13]], 8), [[2, 1, 3, 7]])
    check('explicit case 14', solve([[3, 10, 1, -2]], 8), [[3, 7, 1, 0]])
    check('explicit case 15', solve([[10, 1, 1, 11]], 8), [[7, 4, 5, 7]])
if N == 4:
    check('explicit case 0', solve([[1, 1, 7, 6]], 9), [[1, 1, 7, 6]])
    check('explicit case 1', solve([[-3, 2, 11, 2]], 9), [[0, 2, 8, 2]])
    check('explicit case 2', solve([[-2, -2, 10, 10]], 9), [[0, 0, 8, 8]])
    check('explicit case 3', solve([[-3, 0, -1, 8]], 9), [None])
    check('explicit case 4', solve([[0, 0, 8, 8]], 9), [[0, 0, 8, 8]])
    check('explicit case 5', solve([[0, 0, '8.8', 0]], 9), [[0, 0, 8, 0]])
    check('explicit case 6', solve([[1, -4, -2, 2]], 9), [None])
    check('explicit case 7', solve([[-2, 1, 3, -4]], 9), [None])
    check('explicit case 8', solve([[-2, 1, 4, 13]], 9), [[0, 5, 2, 8]])
    check('explicit case 9', solve([[0, '2.5', 8, '2.5']], 9), [[0, 3, 8, 3]])
    check('explicit case 10', solve([[0, '1.5', 2, '1.5']], 9), [[0, 2, 2, 2]])
    check('explicit case 11', solve([[0, 0, 12, 0]], 9), [[0, 0, 8, 0]])
    check('explicit case 12', solve([['-8', '-13/2', '16', '29/2']], 9), [[0, 1, 8, 8]])
    check('explicit case 13', solve([[2, 1, 4, 14]], 9), [[2, 1, 3, 8]])
    check('explicit case 14', solve([[3, 11, 1, -2]], 9), [[3, 8, 1, 0]])
    check('explicit case 15', solve([[11, 1, 1, 12]], 9), [[8, 4, 5, 8]])
if N == 5:
    check('explicit case 0', solve([[1, 1, 8, 7]], 10), [[1, 1, 8, 7]])
    check('explicit case 1', solve([[-3, 2, 12, 2]], 10), [[0, 2, 9, 2]])
    check('explicit case 2', solve([[-2, -2, 11, 11]], 10), [[0, 0, 9, 9]])
    check('explicit case 3', solve([[-3, 0, -1, 9]], 10), [None])
    check('explicit case 4', solve([[0, 0, 9, 9]], 10), [[0, 0, 9, 9]])
    check('explicit case 5', solve([[0, 0, '9.8', 0]], 10), [[0, 0, 9, 0]])
    check('explicit case 6', solve([[1, -4, -2, 2]], 10), [None])
    check('explicit case 7', solve([[-2, 1, 3, -4]], 10), [None])
    check('explicit case 8', solve([[-2, 1, 4, 14]], 10), [[0, 5, 2, 9]])
    check('explicit case 9', solve([[0, '2.5', 9, '2.5']], 10), [[0, 3, 9, 3]])
    check('explicit case 10', solve([[0, '1.5', 2, '1.5']], 10), [[0, 2, 2, 2]])
    check('explicit case 11', solve([[0, 0, 13, 0]], 10), [[0, 0, 9, 0]])
    check('explicit case 12', solve([['-9', '-15/2', '18', '33/2']], 10), [[0, 1, 9, 9]])
    check('explicit case 13', solve([[2, 1, 4, 15]], 10), [[2, 1, 3, 9]])
    check('explicit case 14', solve([[3, 12, 1, -2]], 10), [[3, 9, 1, 0]])
    check('explicit case 15', solve([[12, 1, 1, 13]], 10), [[9, 4, 5, 9]])
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
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    lo=0
    hi=size-1
    def code(x,y):
        c=0
        if x<lo: c|=1
        elif x>hi: c|=2
        if y<lo: c|=4
        elif y>hi: c|=8
        return c
    out=[]
    for x0,y0,x1,y1 in commands:
        x0,y0,x1,y1=[Fraction(v) for v in (x0,y0,x1,y1)]
        c0,c1=code(x0,y0),code(x1,y1)
        result=None
        for _ in range(5):
            if not (c0|c1):
                result=[int((v+Fraction(1,2))//1) for v in (x0,y0,x1,y1)]
                break
            if c0&c1 or (c0 and c1 and (c0|c1)!=3): break
            c=c0 if c0 else c1
            if c&12 and y1==y0 or c&3 and x1==x0: break
            if c&8: x,y=x0+(x1-x0)*(hi-y0)/(y1-y0),Fraction(hi)
            elif c&4: x,y=x0+(x1-x0)*(lo-y0)/(y1-y0),Fraction(lo)
            elif c&2: x,y=Fraction(hi),y0+(y1-y0)*(hi-x0)/(x1-x0)
            else: x,y=Fraction(lo),y0+(y1-y0)*(lo-x0)/(x1-x0)
            if c==c0:
                x0,y0=x,y
                c0=code(x0,y0)
            else:
                x1,y1=x,y
                c1=code(x1,y1)
        out.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 case 0', solve([[1, 1, 4, 3]], 6), [[1, 1, 4, 3]])
    check('explicit case 1', solve([[-3, 2, 8, 2]], 6), [[0, 2, 5, 2]])
    check('explicit case 2', solve([[-2, -2, 7, 7]], 6), [[0, 0, 5, 5]])
    check('explicit case 3', solve([[-3, 0, -1, 5]], 6), [None])
    check('explicit case 4', solve([[0, 0, 5, 5]], 6), [[0, 0, 5, 5]])
    check('explicit case 5', solve([[0, 0, '5.8', 0]], 6), [[0, 0, 5, 0]])
    check('explicit case 6', solve([[1, -4, -2, 2]], 6), [None])
    check('explicit case 7', solve([[-2, 1, 3, -4]], 6), [None])
    check('explicit case 8', solve([[-2, 1, 4, 10]], 6), [[0, 4, 1, 5]])
    check('explicit case 9', solve([[0, '2.5', 5, '2.5']], 6), [[0, 3, 5, 3]])
    check('explicit case 10', solve([[0, '1.5', 2, '1.5']], 6), [[0, 2, 2, 2]])
    check('explicit case 11', solve([[0, 0, 9, 0]], 6), [[0, 0, 5, 0]])
    check('explicit case 12', solve([['-5', '-7/2', '10', '17/2']], 6), [[0, 1, 5, 5]])
    check('explicit case 13', solve([[2, 1, 4, 11]], 6), [[2, 1, 3, 5]])
    check('explicit case 14', solve([[3, 8, 1, -2]], 6), [[2, 5, 1, 0]])
    check('explicit case 15', solve([[8, 1, 1, 9]], 6), [[5, 4, 5, 5]])
if N == 2:
    check('explicit case 0', solve([[1, 1, 5, 4]], 7), [[1, 1, 5, 4]])
    check('explicit case 1', solve([[-3, 2, 9, 2]], 7), [[0, 2, 6, 2]])
    check('explicit case 2', solve([[-2, -2, 8, 8]], 7), [[0, 0, 6, 6]])
    check('explicit case 3', solve([[-3, 0, -1, 6]], 7), [None])
    check('explicit case 4', solve([[0, 0, 6, 6]], 7), [[0, 0, 6, 6]])
    check('explicit case 5', solve([[0, 0, '6.8', 0]], 7), [[0, 0, 6, 0]])
    check('explicit case 6', solve([[1, -4, -2, 2]], 7), [None])
    check('explicit case 7', solve([[-2, 1, 3, -4]], 7), [None])
    check('explicit case 8', solve([[-2, 1, 4, 11]], 7), [[0, 4, 1, 6]])
    check('explicit case 9', solve([[0, '2.5', 6, '2.5']], 7), [[0, 3, 6, 3]])
    check('explicit case 10', solve([[0, '1.5', 2, '1.5']], 7), [[0, 2, 2, 2]])
    check('explicit case 11', solve([[0, 0, 10, 0]], 7), [[0, 0, 6, 0]])
    check('explicit case 12', solve([['-6', '-9/2', '12', '21/2']], 7), [[0, 1, 6, 6]])
    check('explicit case 13', solve([[2, 1, 4, 12]], 7), [[2, 1, 3, 6]])
    check('explicit case 14', solve([[3, 9, 1, -2]], 7), [[2, 6, 1, 0]])
    check('explicit case 15', solve([[9, 1, 1, 10]], 7), [[6, 4, 5, 6]])
if N == 3:
    check('explicit case 0', solve([[1, 1, 6, 5]], 8), [[1, 1, 6, 5]])
    check('explicit case 1', solve([[-3, 2, 10, 2]], 8), [[0, 2, 7, 2]])
    check('explicit case 2', solve([[-2, -2, 9, 9]], 8), [[0, 0, 7, 7]])
    check('explicit case 3', solve([[-3, 0, -1, 7]], 8), [None])
    check('explicit case 4', solve([[0, 0, 7, 7]], 8), [[0, 0, 7, 7]])
    check('explicit case 5', solve([[0, 0, '7.8', 0]], 8), [[0, 0, 7, 0]])
    check('explicit case 6', solve([[1, -4, -2, 2]], 8), [None])
    check('explicit case 7', solve([[-2, 1, 3, -4]], 8), [None])
    check('explicit case 8', solve([[-2, 1, 4, 12]], 8), [[0, 5, 1, 7]])
    check('explicit case 9', solve([[0, '2.5', 7, '2.5']], 8), [[0, 3, 7, 3]])
    check('explicit case 10', solve([[0, '1.5', 2, '1.5']], 8), [[0, 2, 2, 2]])
    check('explicit case 11', solve([[0, 0, 11, 0]], 8), [[0, 0, 7, 0]])
    check('explicit case 12', solve([['-7', '-11/2', '14', '25/2']], 8), [[0, 1, 7, 7]])
    check('explicit case 13', solve([[2, 1, 4, 13]], 8), [[2, 1, 3, 7]])
    check('explicit case 14', solve([[3, 10, 1, -2]], 8), [[3, 7, 1, 0]])
    check('explicit case 15', solve([[10, 1, 1, 11]], 8), [[7, 4, 5, 7]])
if N == 4:
    check('explicit case 0', solve([[1, 1, 7, 6]], 9), [[1, 1, 7, 6]])
    check('explicit case 1', solve([[-3, 2, 11, 2]], 9), [[0, 2, 8, 2]])
    check('explicit case 2', solve([[-2, -2, 10, 10]], 9), [[0, 0, 8, 8]])
    check('explicit case 3', solve([[-3, 0, -1, 8]], 9), [None])
    check('explicit case 4', solve([[0, 0, 8, 8]], 9), [[0, 0, 8, 8]])
    check('explicit case 5', solve([[0, 0, '8.8', 0]], 9), [[0, 0, 8, 0]])
    check('explicit case 6', solve([[1, -4, -2, 2]], 9), [None])
    check('explicit case 7', solve([[-2, 1, 3, -4]], 9), [None])
    check('explicit case 8', solve([[-2, 1, 4, 13]], 9), [[0, 5, 2, 8]])
    check('explicit case 9', solve([[0, '2.5', 8, '2.5']], 9), [[0, 3, 8, 3]])
    check('explicit case 10', solve([[0, '1.5', 2, '1.5']], 9), [[0, 2, 2, 2]])
    check('explicit case 11', solve([[0, 0, 12, 0]], 9), [[0, 0, 8, 0]])
    check('explicit case 12', solve([['-8', '-13/2', '16', '29/2']], 9), [[0, 1, 8, 8]])
    check('explicit case 13', solve([[2, 1, 4, 14]], 9), [[2, 1, 3, 8]])
    check('explicit case 14', solve([[3, 11, 1, -2]], 9), [[3, 8, 1, 0]])
    check('explicit case 15', solve([[11, 1, 1, 12]], 9), [[8, 4, 5, 8]])
if N == 5:
    check('explicit case 0', solve([[1, 1, 8, 7]], 10), [[1, 1, 8, 7]])
    check('explicit case 1', solve([[-3, 2, 12, 2]], 10), [[0, 2, 9, 2]])
    check('explicit case 2', solve([[-2, -2, 11, 11]], 10), [[0, 0, 9, 9]])
    check('explicit case 3', solve([[-3, 0, -1, 9]], 10), [None])
    check('explicit case 4', solve([[0, 0, 9, 9]], 10), [[0, 0, 9, 9]])
    check('explicit case 5', solve([[0, 0, '9.8', 0]], 10), [[0, 0, 9, 0]])
    check('explicit case 6', solve([[1, -4, -2, 2]], 10), [None])
    check('explicit case 7', solve([[-2, 1, 3, -4]], 10), [None])
    check('explicit case 8', solve([[-2, 1, 4, 14]], 10), [[0, 5, 2, 9]])
    check('explicit case 9', solve([[0, '2.5', 9, '2.5']], 10), [[0, 3, 9, 3]])
    check('explicit case 10', solve([[0, '1.5', 2, '1.5']], 10), [[0, 2, 2, 2]])
    check('explicit case 11', solve([[0, 0, 13, 0]], 10), [[0, 0, 9, 0]])
    check('explicit case 12', solve([['-9', '-15/2', '18', '33/2']], 10), [[0, 1, 9, 9]])
    check('explicit case 13', solve([[2, 1, 4, 15]], 10), [[2, 1, 3, 9]])
    check('explicit case 14', solve([[3, 12, 1, -2]], 10), [[3, 9, 1, 0]])
    check('explicit case 15', solve([[12, 1, 1, 13]], 10), [[9, 4, 5, 9]])
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:
Trivial rejection fires whenever both endpoints are outside, discarding segments that cross the whole window between two different outside regions.

Each command is a segment [x0,y0,x1,y1] whose endpoints are integers or exact decimal/rational strings in pixel-center coordinates. The window is the closed square [0,size-1]x[0,size-1] of pixel centers. Outcodes use strict outside tests (left 1, right 2, below 4, above 8). Both codes zero accepts; a shared bit rejects; otherwise the outside endpoint (endpoint 0 first) is moved to the highest set edge in above, below, right, left order and its code is recomputed from the new point; a clip against an edge parallel to the segment is treated as a rejection. At most five iterations are allowed; an unresolved or rejected segment returns None. Accepted endpoints round half-up to integer pixels.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    lo=0
    hi=size-1
    def code(x,y):
        c=0
        if x<lo: c|=1
        elif x>hi: c|=2
        if y<lo: c|=4
        elif y>hi: c|=8
        return c
    out=[]
    for x0,y0,x1,y1 in commands:
        x0,y0,x1,y1=[Fraction(v) for v in (x0,y0,x1,y1)]
        c0,c1=code(x0,y0),code(x1,y1)
        result=None
        for _ in range(5):
            if not (c0|c1):
                result=[int((v+Fraction(1,2))//1) for v in (x0,y0,x1,y1)]
                break
            if c0&c1: break
            c=c0|c1
            if c&12 and y1==y0 or c&3 and x1==x0: break
            if c&8: x,y=x0+(x1-x0)*(hi-y0)/(y1-y0),Fraction(hi)
            elif c&4: x,y=x0+(x1-x0)*(lo-y0)/(y1-y0),Fraction(lo)
            elif c&2: x,y=Fraction(hi),y0+(y1-y0)*(hi-x0)/(x1-x0)
            else: x,y=Fraction(lo),y0+(y1-y0)*(lo-x0)/(x1-x0)
            if c==c0:
                x0,y0=x,y
                c0=code(x0,y0)
            else:
                x1,y1=x,y
                c1=code(x1,y1)
        out.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 case 0', solve([[1, 1, 4, 3]], 6), [[1, 1, 4, 3]])
    check('explicit case 1', solve([[-3, 2, 8, 2]], 6), [[0, 2, 5, 2]])
    check('explicit case 2', solve([[-2, -2, 7, 7]], 6), [[0, 0, 5, 5]])
    check('explicit case 3', solve([[-3, 0, -1, 5]], 6), [None])
    check('explicit case 4', solve([[0, 0, 5, 5]], 6), [[0, 0, 5, 5]])
    check('explicit case 5', solve([[0, 0, '5.8', 0]], 6), [[0, 0, 5, 0]])
    check('explicit case 6', solve([[1, -4, -2, 2]], 6), [None])
    check('explicit case 7', solve([[-2, 1, 3, -4]], 6), [None])
    check('explicit case 8', solve([[-2, 1, 4, 10]], 6), [[0, 4, 1, 5]])
    check('explicit case 9', solve([[0, '2.5', 5, '2.5']], 6), [[0, 3, 5, 3]])
    check('explicit case 10', solve([[0, '1.5', 2, '1.5']], 6), [[0, 2, 2, 2]])
    check('explicit case 11', solve([[0, 0, 9, 0]], 6), [[0, 0, 5, 0]])
    check('explicit case 12', solve([['-5', '-7/2', '10', '17/2']], 6), [[0, 1, 5, 5]])
    check('explicit case 13', solve([[2, 1, 4, 11]], 6), [[2, 1, 3, 5]])
    check('explicit case 14', solve([[3, 8, 1, -2]], 6), [[2, 5, 1, 0]])
    check('explicit case 15', solve([[8, 1, 1, 9]], 6), [[5, 4, 5, 5]])
if N == 2:
    check('explicit case 0', solve([[1, 1, 5, 4]], 7), [[1, 1, 5, 4]])
    check('explicit case 1', solve([[-3, 2, 9, 2]], 7), [[0, 2, 6, 2]])
    check('explicit case 2', solve([[-2, -2, 8, 8]], 7), [[0, 0, 6, 6]])
    check('explicit case 3', solve([[-3, 0, -1, 6]], 7), [None])
    check('explicit case 4', solve([[0, 0, 6, 6]], 7), [[0, 0, 6, 6]])
    check('explicit case 5', solve([[0, 0, '6.8', 0]], 7), [[0, 0, 6, 0]])
    check('explicit case 6', solve([[1, -4, -2, 2]], 7), [None])
    check('explicit case 7', solve([[-2, 1, 3, -4]], 7), [None])
    check('explicit case 8', solve([[-2, 1, 4, 11]], 7), [[0, 4, 1, 6]])
    check('explicit case 9', solve([[0, '2.5', 6, '2.5']], 7), [[0, 3, 6, 3]])
    check('explicit case 10', solve([[0, '1.5', 2, '1.5']], 7), [[0, 2, 2, 2]])
    check('explicit case 11', solve([[0, 0, 10, 0]], 7), [[0, 0, 6, 0]])
    check('explicit case 12', solve([['-6', '-9/2', '12', '21/2']], 7), [[0, 1, 6, 6]])
    check('explicit case 13', solve([[2, 1, 4, 12]], 7), [[2, 1, 3, 6]])
    check('explicit case 14', solve([[3, 9, 1, -2]], 7), [[2, 6, 1, 0]])
    check('explicit case 15', solve([[9, 1, 1, 10]], 7), [[6, 4, 5, 6]])
if N == 3:
    check('explicit case 0', solve([[1, 1, 6, 5]], 8), [[1, 1, 6, 5]])
    check('explicit case 1', solve([[-3, 2, 10, 2]], 8), [[0, 2, 7, 2]])
    check('explicit case 2', solve([[-2, -2, 9, 9]], 8), [[0, 0, 7, 7]])
    check('explicit case 3', solve([[-3, 0, -1, 7]], 8), [None])
    check('explicit case 4', solve([[0, 0, 7, 7]], 8), [[0, 0, 7, 7]])
    check('explicit case 5', solve([[0, 0, '7.8', 0]], 8), [[0, 0, 7, 0]])
    check('explicit case 6', solve([[1, -4, -2, 2]], 8), [None])
    check('explicit case 7', solve([[-2, 1, 3, -4]], 8), [None])
    check('explicit case 8', solve([[-2, 1, 4, 12]], 8), [[0, 5, 1, 7]])
    check('explicit case 9', solve([[0, '2.5', 7, '2.5']], 8), [[0, 3, 7, 3]])
    check('explicit case 10', solve([[0, '1.5', 2, '1.5']], 8), [[0, 2, 2, 2]])
    check('explicit case 11', solve([[0, 0, 11, 0]], 8), [[0, 0, 7, 0]])
    check('explicit case 12', solve([['-7', '-11/2', '14', '25/2']], 8), [[0, 1, 7, 7]])
    check('explicit case 13', solve([[2, 1, 4, 13]], 8), [[2, 1, 3, 7]])
    check('explicit case 14', solve([[3, 10, 1, -2]], 8), [[3, 7, 1, 0]])
    check('explicit case 15', solve([[10, 1, 1, 11]], 8), [[7, 4, 5, 7]])
if N == 4:
    check('explicit case 0', solve([[1, 1, 7, 6]], 9), [[1, 1, 7, 6]])
    check('explicit case 1', solve([[-3, 2, 11, 2]], 9), [[0, 2, 8, 2]])
    check('explicit case 2', solve([[-2, -2, 10, 10]], 9), [[0, 0, 8, 8]])
    check('explicit case 3', solve([[-3, 0, -1, 8]], 9), [None])
    check('explicit case 4', solve([[0, 0, 8, 8]], 9), [[0, 0, 8, 8]])
    check('explicit case 5', solve([[0, 0, '8.8', 0]], 9), [[0, 0, 8, 0]])
    check('explicit case 6', solve([[1, -4, -2, 2]], 9), [None])
    check('explicit case 7', solve([[-2, 1, 3, -4]], 9), [None])
    check('explicit case 8', solve([[-2, 1, 4, 13]], 9), [[0, 5, 2, 8]])
    check('explicit case 9', solve([[0, '2.5', 8, '2.5']], 9), [[0, 3, 8, 3]])
    check('explicit case 10', solve([[0, '1.5', 2, '1.5']], 9), [[0, 2, 2, 2]])
    check('explicit case 11', solve([[0, 0, 12, 0]], 9), [[0, 0, 8, 0]])
    check('explicit case 12', solve([['-8', '-13/2', '16', '29/2']], 9), [[0, 1, 8, 8]])
    check('explicit case 13', solve([[2, 1, 4, 14]], 9), [[2, 1, 3, 8]])
    check('explicit case 14', solve([[3, 11, 1, -2]], 9), [[3, 8, 1, 0]])
    check('explicit case 15', solve([[11, 1, 1, 12]], 9), [[8, 4, 5, 8]])
if N == 5:
    check('explicit case 0', solve([[1, 1, 8, 7]], 10), [[1, 1, 8, 7]])
    check('explicit case 1', solve([[-3, 2, 12, 2]], 10), [[0, 2, 9, 2]])
    check('explicit case 2', solve([[-2, -2, 11, 11]], 10), [[0, 0, 9, 9]])
    check('explicit case 3', solve([[-3, 0, -1, 9]], 10), [None])
    check('explicit case 4', solve([[0, 0, 9, 9]], 10), [[0, 0, 9, 9]])
    check('explicit case 5', solve([[0, 0, '9.8', 0]], 10), [[0, 0, 9, 0]])
    check('explicit case 6', solve([[1, -4, -2, 2]], 10), [None])
    check('explicit case 7', solve([[-2, 1, 3, -4]], 10), [None])
    check('explicit case 8', solve([[-2, 1, 4, 14]], 10), [[0, 5, 2, 9]])
    check('explicit case 9', solve([[0, '2.5', 9, '2.5']], 10), [[0, 3, 9, 3]])
    check('explicit case 10', solve([[0, '1.5', 2, '1.5']], 10), [[0, 2, 2, 2]])
    check('explicit case 11', solve([[0, 0, 13, 0]], 10), [[0, 0, 9, 0]])
    check('explicit case 12', solve([['-9', '-15/2', '18', '33/2']], 10), [[0, 1, 9, 9]])
    check('explicit case 13', solve([[2, 1, 4, 15]], 10), [[2, 1, 3, 9]])
    check('explicit case 14', solve([[3, 12, 1, -2]], 10), [[3, 9, 1, 0]])
    check('explicit case 15', solve([[12, 1, 1, 13]], 10), [[9, 4, 5, 9]])
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
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    lo=0
    hi=size-1
    def code(x,y):
        c=0
        if x<lo: c|=1
        elif x>hi: c|=2
        if y<lo: c|=4
        elif y>hi: c|=8
        return c
    out=[]
    for x0,y0,x1,y1 in commands:
        x0,y0,x1,y1=[Fraction(v) for v in (x0,y0,x1,y1)]
        c0,c1=code(x0,y0),code(x1,y1)
        result=None
        for _ in range(5):
            if not (c0|c1):
                result=[int((v+Fraction(1,2))//1) for v in (x0,y0,x1,y1)]
                break
            if c0&c1: break
            c=c0|c1 if c0 and c1 else c0 or c1
            if c&12 and y1==y0 or c&3 and x1==x0: break
            if c&8: x,y=x0+(x1-x0)*(hi-y0)/(y1-y0),Fraction(hi)
            elif c&4: x,y=x0+(x1-x0)*(lo-y0)/(y1-y0),Fraction(lo)
            elif c&2: x,y=Fraction(hi),y0+(y1-y0)*(hi-x0)/(x1-x0)
            else: x,y=Fraction(lo),y0+(y1-y0)*(lo-x0)/(x1-x0)
            if c==c0:
                x0,y0=x,y
                c0=code(x0,y0)
            else:
                x1,y1=x,y
                c1=code(x1,y1)
        out.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 case 0', solve([[1, 1, 4, 3]], 6), [[1, 1, 4, 3]])
    check('explicit case 1', solve([[-3, 2, 8, 2]], 6), [[0, 2, 5, 2]])
    check('explicit case 2', solve([[-2, -2, 7, 7]], 6), [[0, 0, 5, 5]])
    check('explicit case 3', solve([[-3, 0, -1, 5]], 6), [None])
    check('explicit case 4', solve([[0, 0, 5, 5]], 6), [[0, 0, 5, 5]])
    check('explicit case 5', solve([[0, 0, '5.8', 0]], 6), [[0, 0, 5, 0]])
    check('explicit case 6', solve([[1, -4, -2, 2]], 6), [None])
    check('explicit case 7', solve([[-2, 1, 3, -4]], 6), [None])
    check('explicit case 8', solve([[-2, 1, 4, 10]], 6), [[0, 4, 1, 5]])
    check('explicit case 9', solve([[0, '2.5', 5, '2.5']], 6), [[0, 3, 5, 3]])
    check('explicit case 10', solve([[0, '1.5', 2, '1.5']], 6), [[0, 2, 2, 2]])
    check('explicit case 11', solve([[0, 0, 9, 0]], 6), [[0, 0, 5, 0]])
    check('explicit case 12', solve([['-5', '-7/2', '10', '17/2']], 6), [[0, 1, 5, 5]])
    check('explicit case 13', solve([[2, 1, 4, 11]], 6), [[2, 1, 3, 5]])
    check('explicit case 14', solve([[3, 8, 1, -2]], 6), [[2, 5, 1, 0]])
    check('explicit case 15', solve([[8, 1, 1, 9]], 6), [[5, 4, 5, 5]])
if N == 2:
    check('explicit case 0', solve([[1, 1, 5, 4]], 7), [[1, 1, 5, 4]])
    check('explicit case 1', solve([[-3, 2, 9, 2]], 7), [[0, 2, 6, 2]])
    check('explicit case 2', solve([[-2, -2, 8, 8]], 7), [[0, 0, 6, 6]])
    check('explicit case 3', solve([[-3, 0, -1, 6]], 7), [None])
    check('explicit case 4', solve([[0, 0, 6, 6]], 7), [[0, 0, 6, 6]])
    check('explicit case 5', solve([[0, 0, '6.8', 0]], 7), [[0, 0, 6, 0]])
    check('explicit case 6', solve([[1, -4, -2, 2]], 7), [None])
    check('explicit case 7', solve([[-2, 1, 3, -4]], 7), [None])
    check('explicit case 8', solve([[-2, 1, 4, 11]], 7), [[0, 4, 1, 6]])
    check('explicit case 9', solve([[0, '2.5', 6, '2.5']], 7), [[0, 3, 6, 3]])
    check('explicit case 10', solve([[0, '1.5', 2, '1.5']], 7), [[0, 2, 2, 2]])
    check('explicit case 11', solve([[0, 0, 10, 0]], 7), [[0, 0, 6, 0]])
    check('explicit case 12', solve([['-6', '-9/2', '12', '21/2']], 7), [[0, 1, 6, 6]])
    check('explicit case 13', solve([[2, 1, 4, 12]], 7), [[2, 1, 3, 6]])
    check('explicit case 14', solve([[3, 9, 1, -2]], 7), [[2, 6, 1, 0]])
    check('explicit case 15', solve([[9, 1, 1, 10]], 7), [[6, 4, 5, 6]])
if N == 3:
    check('explicit case 0', solve([[1, 1, 6, 5]], 8), [[1, 1, 6, 5]])
    check('explicit case 1', solve([[-3, 2, 10, 2]], 8), [[0, 2, 7, 2]])
    check('explicit case 2', solve([[-2, -2, 9, 9]], 8), [[0, 0, 7, 7]])
    check('explicit case 3', solve([[-3, 0, -1, 7]], 8), [None])
    check('explicit case 4', solve([[0, 0, 7, 7]], 8), [[0, 0, 7, 7]])
    check('explicit case 5', solve([[0, 0, '7.8', 0]], 8), [[0, 0, 7, 0]])
    check('explicit case 6', solve([[1, -4, -2, 2]], 8), [None])
    check('explicit case 7', solve([[-2, 1, 3, -4]], 8), [None])
    check('explicit case 8', solve([[-2, 1, 4, 12]], 8), [[0, 5, 1, 7]])
    check('explicit case 9', solve([[0, '2.5', 7, '2.5']], 8), [[0, 3, 7, 3]])
    check('explicit case 10', solve([[0, '1.5', 2, '1.5']], 8), [[0, 2, 2, 2]])
    check('explicit case 11', solve([[0, 0, 11, 0]], 8), [[0, 0, 7, 0]])
    check('explicit case 12', solve([['-7', '-11/2', '14', '25/2']], 8), [[0, 1, 7, 7]])
    check('explicit case 13', solve([[2, 1, 4, 13]], 8), [[2, 1, 3, 7]])
    check('explicit case 14', solve([[3, 10, 1, -2]], 8), [[3, 7, 1, 0]])
    check('explicit case 15', solve([[10, 1, 1, 11]], 8), [[7, 4, 5, 7]])
if N == 4:
    check('explicit case 0', solve([[1, 1, 7, 6]], 9), [[1, 1, 7, 6]])
    check('explicit case 1', solve([[-3, 2, 11, 2]], 9), [[0, 2, 8, 2]])
    check('explicit case 2', solve([[-2, -2, 10, 10]], 9), [[0, 0, 8, 8]])
    check('explicit case 3', solve([[-3, 0, -1, 8]], 9), [None])
    check('explicit case 4', solve([[0, 0, 8, 8]], 9), [[0, 0, 8, 8]])
    check('explicit case 5', solve([[0, 0, '8.8', 0]], 9), [[0, 0, 8, 0]])
    check('explicit case 6', solve([[1, -4, -2, 2]], 9), [None])
    check('explicit case 7', solve([[-2, 1, 3, -4]], 9), [None])
    check('explicit case 8', solve([[-2, 1, 4, 13]], 9), [[0, 5, 2, 8]])
    check('explicit case 9', solve([[0, '2.5', 8, '2.5']], 9), [[0, 3, 8, 3]])
    check('explicit case 10', solve([[0, '1.5', 2, '1.5']], 9), [[0, 2, 2, 2]])
    check('explicit case 11', solve([[0, 0, 12, 0]], 9), [[0, 0, 8, 0]])
    check('explicit case 12', solve([['-8', '-13/2', '16', '29/2']], 9), [[0, 1, 8, 8]])
    check('explicit case 13', solve([[2, 1, 4, 14]], 9), [[2, 1, 3, 8]])
    check('explicit case 14', solve([[3, 11, 1, -2]], 9), [[3, 8, 1, 0]])
    check('explicit case 15', solve([[11, 1, 1, 12]], 9), [[8, 4, 5, 8]])
if N == 5:
    check('explicit case 0', solve([[1, 1, 8, 7]], 10), [[1, 1, 8, 7]])
    check('explicit case 1', solve([[-3, 2, 12, 2]], 10), [[0, 2, 9, 2]])
    check('explicit case 2', solve([[-2, -2, 11, 11]], 10), [[0, 0, 9, 9]])
    check('explicit case 3', solve([[-3, 0, -1, 9]], 10), [None])
    check('explicit case 4', solve([[0, 0, 9, 9]], 10), [[0, 0, 9, 9]])
    check('explicit case 5', solve([[0, 0, '9.8', 0]], 10), [[0, 0, 9, 0]])
    check('explicit case 6', solve([[1, -4, -2, 2]], 10), [None])
    check('explicit case 7', solve([[-2, 1, 3, -4]], 10), [None])
    check('explicit case 8', solve([[-2, 1, 4, 14]], 10), [[0, 5, 2, 9]])
    check('explicit case 9', solve([[0, '2.5', 9, '2.5']], 10), [[0, 3, 9, 3]])
    check('explicit case 10', solve([[0, '1.5', 2, '1.5']], 10), [[0, 2, 2, 2]])
    check('explicit case 11', solve([[0, 0, 13, 0]], 10), [[0, 0, 9, 0]])
    check('explicit case 12', solve([['-9', '-15/2', '18', '33/2']], 10), [[0, 1, 9, 9]])
    check('explicit case 13', solve([[2, 1, 4, 15]], 10), [[2, 1, 3, 9]])
    check('explicit case 14', solve([[3, 12, 1, -2]], 10), [[3, 9, 1, 0]])
    check('explicit case 15', solve([[12, 1, 1, 13]], 10), [[9, 4, 5, 9]])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The edge to clip is chosen from the union of both outcodes, so an intersection computed for one endpoint is written into the other endpoint.

Each command is a segment [x0,y0,x1,y1] whose endpoints are integers or exact decimal/rational strings in pixel-center coordinates. The window is the closed square [0,size-1]x[0,size-1] of pixel centers. Outcodes use strict outside tests (left 1, right 2, below 4, above 8). Both codes zero accepts; a shared bit rejects; otherwise the outside endpoint (endpoint 0 first) is moved to the highest set edge in above, below, right, left order and its code is recomputed from the new point; a clip against an edge parallel to the segment is treated as a rejection. At most five iterations are allowed; an unresolved or rejected segment returns None. Accepted endpoints round half-up to integer pixels.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    lo=0
    hi=size-1
    def code(x,y):
        c=0
        if x<lo: c|=1
        elif x>hi: c|=2
        if y<lo: c|=4
        elif y>hi: c|=8
        return c
    out=[]
    for x0,y0,x1,y1 in commands:
        x0,y0,x1,y1=[Fraction(v) for v in (x0,y0,x1,y1)]
        c0,c1=code(x0,y0),code(x1,y1)
        result=None
        for _ in range(5):
            if not (c0|c1):
                result=[int((v+Fraction(1,2))//1) for v in (x0,y0,x1,y1)]
                break
            if c0&c1: break
            c=c0 if c0 else c1
            if c&12 and y1==y0 or c&3 and x1==x0: break
            if c&8: x,y=x0+(x1-x0)*(hi-y1)/(y1-y0),Fraction(hi)
            elif c&4: x,y=x0+(x1-x0)*(lo-y0)/(y1-y0),Fraction(lo)
            elif c&2: x,y=Fraction(hi),y0+(y1-y0)*(hi-x0)/(x1-x0)
            else: x,y=Fraction(lo),y0+(y1-y0)*(lo-x0)/(x1-x0)
            if c==c0:
                x0,y0=x,y
                c0=code(x0,y0)
            else:
                x1,y1=x,y
                c1=code(x1,y1)
        out.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 case 0', solve([[1, 1, 4, 3]], 6), [[1, 1, 4, 3]])
    check('explicit case 1', solve([[-3, 2, 8, 2]], 6), [[0, 2, 5, 2]])
    check('explicit case 2', solve([[-2, -2, 7, 7]], 6), [[0, 0, 5, 5]])
    check('explicit case 3', solve([[-3, 0, -1, 5]], 6), [None])
    check('explicit case 4', solve([[0, 0, 5, 5]], 6), [[0, 0, 5, 5]])
    check('explicit case 5', solve([[0, 0, '5.8', 0]], 6), [[0, 0, 5, 0]])
    check('explicit case 6', solve([[1, -4, -2, 2]], 6), [None])
    check('explicit case 7', solve([[-2, 1, 3, -4]], 6), [None])
    check('explicit case 8', solve([[-2, 1, 4, 10]], 6), [[0, 4, 1, 5]])
    check('explicit case 9', solve([[0, '2.5', 5, '2.5']], 6), [[0, 3, 5, 3]])
    check('explicit case 10', solve([[0, '1.5', 2, '1.5']], 6), [[0, 2, 2, 2]])
    check('explicit case 11', solve([[0, 0, 9, 0]], 6), [[0, 0, 5, 0]])
    check('explicit case 12', solve([['-5', '-7/2', '10', '17/2']], 6), [[0, 1, 5, 5]])
    check('explicit case 13', solve([[2, 1, 4, 11]], 6), [[2, 1, 3, 5]])
    check('explicit case 14', solve([[3, 8, 1, -2]], 6), [[2, 5, 1, 0]])
    check('explicit case 15', solve([[8, 1, 1, 9]], 6), [[5, 4, 5, 5]])
if N == 2:
    check('explicit case 0', solve([[1, 1, 5, 4]], 7), [[1, 1, 5, 4]])
    check('explicit case 1', solve([[-3, 2, 9, 2]], 7), [[0, 2, 6, 2]])
    check('explicit case 2', solve([[-2, -2, 8, 8]], 7), [[0, 0, 6, 6]])
    check('explicit case 3', solve([[-3, 0, -1, 6]], 7), [None])
    check('explicit case 4', solve([[0, 0, 6, 6]], 7), [[0, 0, 6, 6]])
    check('explicit case 5', solve([[0, 0, '6.8', 0]], 7), [[0, 0, 6, 0]])
    check('explicit case 6', solve([[1, -4, -2, 2]], 7), [None])
    check('explicit case 7', solve([[-2, 1, 3, -4]], 7), [None])
    check('explicit case 8', solve([[-2, 1, 4, 11]], 7), [[0, 4, 1, 6]])
    check('explicit case 9', solve([[0, '2.5', 6, '2.5']], 7), [[0, 3, 6, 3]])
    check('explicit case 10', solve([[0, '1.5', 2, '1.5']], 7), [[0, 2, 2, 2]])
    check('explicit case 11', solve([[0, 0, 10, 0]], 7), [[0, 0, 6, 0]])
    check('explicit case 12', solve([['-6', '-9/2', '12', '21/2']], 7), [[0, 1, 6, 6]])
    check('explicit case 13', solve([[2, 1, 4, 12]], 7), [[2, 1, 3, 6]])
    check('explicit case 14', solve([[3, 9, 1, -2]], 7), [[2, 6, 1, 0]])
    check('explicit case 15', solve([[9, 1, 1, 10]], 7), [[6, 4, 5, 6]])
if N == 3:
    check('explicit case 0', solve([[1, 1, 6, 5]], 8), [[1, 1, 6, 5]])
    check('explicit case 1', solve([[-3, 2, 10, 2]], 8), [[0, 2, 7, 2]])
    check('explicit case 2', solve([[-2, -2, 9, 9]], 8), [[0, 0, 7, 7]])
    check('explicit case 3', solve([[-3, 0, -1, 7]], 8), [None])
    check('explicit case 4', solve([[0, 0, 7, 7]], 8), [[0, 0, 7, 7]])
    check('explicit case 5', solve([[0, 0, '7.8', 0]], 8), [[0, 0, 7, 0]])
    check('explicit case 6', solve([[1, -4, -2, 2]], 8), [None])
    check('explicit case 7', solve([[-2, 1, 3, -4]], 8), [None])
    check('explicit case 8', solve([[-2, 1, 4, 12]], 8), [[0, 5, 1, 7]])
    check('explicit case 9', solve([[0, '2.5', 7, '2.5']], 8), [[0, 3, 7, 3]])
    check('explicit case 10', solve([[0, '1.5', 2, '1.5']], 8), [[0, 2, 2, 2]])
    check('explicit case 11', solve([[0, 0, 11, 0]], 8), [[0, 0, 7, 0]])
    check('explicit case 12', solve([['-7', '-11/2', '14', '25/2']], 8), [[0, 1, 7, 7]])
    check('explicit case 13', solve([[2, 1, 4, 13]], 8), [[2, 1, 3, 7]])
    check('explicit case 14', solve([[3, 10, 1, -2]], 8), [[3, 7, 1, 0]])
    check('explicit case 15', solve([[10, 1, 1, 11]], 8), [[7, 4, 5, 7]])
if N == 4:
    check('explicit case 0', solve([[1, 1, 7, 6]], 9), [[1, 1, 7, 6]])
    check('explicit case 1', solve([[-3, 2, 11, 2]], 9), [[0, 2, 8, 2]])
    check('explicit case 2', solve([[-2, -2, 10, 10]], 9), [[0, 0, 8, 8]])
    check('explicit case 3', solve([[-3, 0, -1, 8]], 9), [None])
    check('explicit case 4', solve([[0, 0, 8, 8]], 9), [[0, 0, 8, 8]])
    check('explicit case 5', solve([[0, 0, '8.8', 0]], 9), [[0, 0, 8, 0]])
    check('explicit case 6', solve([[1, -4, -2, 2]], 9), [None])
    check('explicit case 7', solve([[-2, 1, 3, -4]], 9), [None])
    check('explicit case 8', solve([[-2, 1, 4, 13]], 9), [[0, 5, 2, 8]])
    check('explicit case 9', solve([[0, '2.5', 8, '2.5']], 9), [[0, 3, 8, 3]])
    check('explicit case 10', solve([[0, '1.5', 2, '1.5']], 9), [[0, 2, 2, 2]])
    check('explicit case 11', solve([[0, 0, 12, 0]], 9), [[0, 0, 8, 0]])
    check('explicit case 12', solve([['-8', '-13/2', '16', '29/2']], 9), [[0, 1, 8, 8]])
    check('explicit case 13', solve([[2, 1, 4, 14]], 9), [[2, 1, 3, 8]])
    check('explicit case 14', solve([[3, 11, 1, -2]], 9), [[3, 8, 1, 0]])
    check('explicit case 15', solve([[11, 1, 1, 12]], 9), [[8, 4, 5, 8]])
if N == 5:
    check('explicit case 0', solve([[1, 1, 8, 7]], 10), [[1, 1, 8, 7]])
    check('explicit case 1', solve([[-3, 2, 12, 2]], 10), [[0, 2, 9, 2]])
    check('explicit case 2', solve([[-2, -2, 11, 11]], 10), [[0, 0, 9, 9]])
    check('explicit case 3', solve([[-3, 0, -1, 9]], 10), [None])
    check('explicit case 4', solve([[0, 0, 9, 9]], 10), [[0, 0, 9, 9]])
    check('explicit case 5', solve([[0, 0, '9.8', 0]], 10), [[0, 0, 9, 0]])
    check('explicit case 6', solve([[1, -4, -2, 2]], 10), [None])
    check('explicit case 7', solve([[-2, 1, 3, -4]], 10), [None])
    check('explicit case 8', solve([[-2, 1, 4, 14]], 10), [[0, 5, 2, 9]])
    check('explicit case 9', solve([[0, '2.5', 9, '2.5']], 10), [[0, 3, 9, 3]])
    check('explicit case 10', solve([[0, '1.5', 2, '1.5']], 10), [[0, 2, 2, 2]])
    check('explicit case 11', solve([[0, 0, 13, 0]], 10), [[0, 0, 9, 0]])
    check('explicit case 12', solve([['-9', '-15/2', '18', '33/2']], 10), [[0, 1, 9, 9]])
    check('explicit case 13', solve([[2, 1, 4, 15]], 10), [[2, 1, 3, 9]])
    check('explicit case 14', solve([[3, 12, 1, -2]], 10), [[3, 9, 1, 0]])
    check('explicit case 15', solve([[12, 1, 1, 13]], 10), [[9, 4, 5, 9]])
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
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    lo=0
    hi=size-1
    def code(x,y):
        c=0
        if x<lo: c|=1
        elif x>hi: c|=2
        if y<lo: c|=4
        elif y>hi: c|=8
        return c
    out=[]
    for x0,y0,x1,y1 in commands:
        x0,y0,x1,y1=[Fraction(v) for v in (x0,y0,x1,y1)]
        c0,c1=code(x0,y0),code(x1,y1)
        result=None
        for _ in range(5):
            if not (c0|c1):
                result=[int((v+Fraction(1,2))//1) for v in (x0,y0,x1,y1)]
                break
            if c0&c1: break
            c=c0 if c0 else c1
            if c&12 and y1==y0 or c&3 and x1==x0: break
            if c&8: x,y=x0+(x1-x0)*(y1-hi)/(y1-y0),Fraction(hi)
            elif c&4: x,y=x0+(x1-x0)*(lo-y0)/(y1-y0),Fraction(lo)
            elif c&2: x,y=Fraction(hi),y0+(y1-y0)*(hi-x0)/(x1-x0)
            else: x,y=Fraction(lo),y0+(y1-y0)*(lo-x0)/(x1-x0)
            if c==c0:
                x0,y0=x,y
                c0=code(x0,y0)
            else:
                x1,y1=x,y
                c1=code(x1,y1)
        out.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 case 0', solve([[1, 1, 4, 3]], 6), [[1, 1, 4, 3]])
    check('explicit case 1', solve([[-3, 2, 8, 2]], 6), [[0, 2, 5, 2]])
    check('explicit case 2', solve([[-2, -2, 7, 7]], 6), [[0, 0, 5, 5]])
    check('explicit case 3', solve([[-3, 0, -1, 5]], 6), [None])
    check('explicit case 4', solve([[0, 0, 5, 5]], 6), [[0, 0, 5, 5]])
    check('explicit case 5', solve([[0, 0, '5.8', 0]], 6), [[0, 0, 5, 0]])
    check('explicit case 6', solve([[1, -4, -2, 2]], 6), [None])
    check('explicit case 7', solve([[-2, 1, 3, -4]], 6), [None])
    check('explicit case 8', solve([[-2, 1, 4, 10]], 6), [[0, 4, 1, 5]])
    check('explicit case 9', solve([[0, '2.5', 5, '2.5']], 6), [[0, 3, 5, 3]])
    check('explicit case 10', solve([[0, '1.5', 2, '1.5']], 6), [[0, 2, 2, 2]])
    check('explicit case 11', solve([[0, 0, 9, 0]], 6), [[0, 0, 5, 0]])
    check('explicit case 12', solve([['-5', '-7/2', '10', '17/2']], 6), [[0, 1, 5, 5]])
    check('explicit case 13', solve([[2, 1, 4, 11]], 6), [[2, 1, 3, 5]])
    check('explicit case 14', solve([[3, 8, 1, -2]], 6), [[2, 5, 1, 0]])
    check('explicit case 15', solve([[8, 1, 1, 9]], 6), [[5, 4, 5, 5]])
if N == 2:
    check('explicit case 0', solve([[1, 1, 5, 4]], 7), [[1, 1, 5, 4]])
    check('explicit case 1', solve([[-3, 2, 9, 2]], 7), [[0, 2, 6, 2]])
    check('explicit case 2', solve([[-2, -2, 8, 8]], 7), [[0, 0, 6, 6]])
    check('explicit case 3', solve([[-3, 0, -1, 6]], 7), [None])
    check('explicit case 4', solve([[0, 0, 6, 6]], 7), [[0, 0, 6, 6]])
    check('explicit case 5', solve([[0, 0, '6.8', 0]], 7), [[0, 0, 6, 0]])
    check('explicit case 6', solve([[1, -4, -2, 2]], 7), [None])
    check('explicit case 7', solve([[-2, 1, 3, -4]], 7), [None])
    check('explicit case 8', solve([[-2, 1, 4, 11]], 7), [[0, 4, 1, 6]])
    check('explicit case 9', solve([[0, '2.5', 6, '2.5']], 7), [[0, 3, 6, 3]])
    check('explicit case 10', solve([[0, '1.5', 2, '1.5']], 7), [[0, 2, 2, 2]])
    check('explicit case 11', solve([[0, 0, 10, 0]], 7), [[0, 0, 6, 0]])
    check('explicit case 12', solve([['-6', '-9/2', '12', '21/2']], 7), [[0, 1, 6, 6]])
    check('explicit case 13', solve([[2, 1, 4, 12]], 7), [[2, 1, 3, 6]])
    check('explicit case 14', solve([[3, 9, 1, -2]], 7), [[2, 6, 1, 0]])
    check('explicit case 15', solve([[9, 1, 1, 10]], 7), [[6, 4, 5, 6]])
if N == 3:
    check('explicit case 0', solve([[1, 1, 6, 5]], 8), [[1, 1, 6, 5]])
    check('explicit case 1', solve([[-3, 2, 10, 2]], 8), [[0, 2, 7, 2]])
    check('explicit case 2', solve([[-2, -2, 9, 9]], 8), [[0, 0, 7, 7]])
    check('explicit case 3', solve([[-3, 0, -1, 7]], 8), [None])
    check('explicit case 4', solve([[0, 0, 7, 7]], 8), [[0, 0, 7, 7]])
    check('explicit case 5', solve([[0, 0, '7.8', 0]], 8), [[0, 0, 7, 0]])
    check('explicit case 6', solve([[1, -4, -2, 2]], 8), [None])
    check('explicit case 7', solve([[-2, 1, 3, -4]], 8), [None])
    check('explicit case 8', solve([[-2, 1, 4, 12]], 8), [[0, 5, 1, 7]])
    check('explicit case 9', solve([[0, '2.5', 7, '2.5']], 8), [[0, 3, 7, 3]])
    check('explicit case 10', solve([[0, '1.5', 2, '1.5']], 8), [[0, 2, 2, 2]])
    check('explicit case 11', solve([[0, 0, 11, 0]], 8), [[0, 0, 7, 0]])
    check('explicit case 12', solve([['-7', '-11/2', '14', '25/2']], 8), [[0, 1, 7, 7]])
    check('explicit case 13', solve([[2, 1, 4, 13]], 8), [[2, 1, 3, 7]])
    check('explicit case 14', solve([[3, 10, 1, -2]], 8), [[3, 7, 1, 0]])
    check('explicit case 15', solve([[10, 1, 1, 11]], 8), [[7, 4, 5, 7]])
if N == 4:
    check('explicit case 0', solve([[1, 1, 7, 6]], 9), [[1, 1, 7, 6]])
    check('explicit case 1', solve([[-3, 2, 11, 2]], 9), [[0, 2, 8, 2]])
    check('explicit case 2', solve([[-2, -2, 10, 10]], 9), [[0, 0, 8, 8]])
    check('explicit case 3', solve([[-3, 0, -1, 8]], 9), [None])
    check('explicit case 4', solve([[0, 0, 8, 8]], 9), [[0, 0, 8, 8]])
    check('explicit case 5', solve([[0, 0, '8.8', 0]], 9), [[0, 0, 8, 0]])
    check('explicit case 6', solve([[1, -4, -2, 2]], 9), [None])
    check('explicit case 7', solve([[-2, 1, 3, -4]], 9), [None])
    check('explicit case 8', solve([[-2, 1, 4, 13]], 9), [[0, 5, 2, 8]])
    check('explicit case 9', solve([[0, '2.5', 8, '2.5']], 9), [[0, 3, 8, 3]])
    check('explicit case 10', solve([[0, '1.5', 2, '1.5']], 9), [[0, 2, 2, 2]])
    check('explicit case 11', solve([[0, 0, 12, 0]], 9), [[0, 0, 8, 0]])
    check('explicit case 12', solve([['-8', '-13/2', '16', '29/2']], 9), [[0, 1, 8, 8]])
    check('explicit case 13', solve([[2, 1, 4, 14]], 9), [[2, 1, 3, 8]])
    check('explicit case 14', solve([[3, 11, 1, -2]], 9), [[3, 8, 1, 0]])
    check('explicit case 15', solve([[11, 1, 1, 12]], 9), [[8, 4, 5, 8]])
if N == 5:
    check('explicit case 0', solve([[1, 1, 8, 7]], 10), [[1, 1, 8, 7]])
    check('explicit case 1', solve([[-3, 2, 12, 2]], 10), [[0, 2, 9, 2]])
    check('explicit case 2', solve([[-2, -2, 11, 11]], 10), [[0, 0, 9, 9]])
    check('explicit case 3', solve([[-3, 0, -1, 9]], 10), [None])
    check('explicit case 4', solve([[0, 0, 9, 9]], 10), [[0, 0, 9, 9]])
    check('explicit case 5', solve([[0, 0, '9.8', 0]], 10), [[0, 0, 9, 0]])
    check('explicit case 6', solve([[1, -4, -2, 2]], 10), [None])
    check('explicit case 7', solve([[-2, 1, 3, -4]], 10), [None])
    check('explicit case 8', solve([[-2, 1, 4, 14]], 10), [[0, 5, 2, 9]])
    check('explicit case 9', solve([[0, '2.5', 9, '2.5']], 10), [[0, 3, 9, 3]])
    check('explicit case 10', solve([[0, '1.5', 2, '1.5']], 10), [[0, 2, 2, 2]])
    check('explicit case 11', solve([[0, 0, 13, 0]], 10), [[0, 0, 9, 0]])
    check('explicit case 12', solve([['-9', '-15/2', '18', '33/2']], 10), [[0, 1, 9, 9]])
    check('explicit case 13', solve([[2, 1, 4, 15]], 10), [[2, 1, 3, 9]])
    check('explicit case 14', solve([[3, 12, 1, -2]], 10), [[3, 9, 1, 0]])
    check('explicit case 15', solve([[12, 1, 1, 13]], 10), [[9, 4, 5, 9]])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The top-edge intersection measures the parameter from the far endpoint while interpolating from the near endpoint.

Each command is a segment [x0,y0,x1,y1] whose endpoints are integers or exact decimal/rational strings in pixel-center coordinates. The window is the closed square [0,size-1]x[0,size-1] of pixel centers. Outcodes use strict outside tests (left 1, right 2, below 4, above 8). Both codes zero accepts; a shared bit rejects; otherwise the outside endpoint (endpoint 0 first) is moved to the highest set edge in above, below, right, left order and its code is recomputed from the new point; a clip against an edge parallel to the segment is treated as a rejection. At most five iterations are allowed; an unresolved or rejected segment returns None. Accepted endpoints round half-up to integer pixels.

split: open-access