broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    out=[]
    for poly,clip in commands:
        l,t,r,b=max(clip[0],0),max(clip[1],0),min(clip[2],size),min(clip[3],size)
        pts=[(Fraction(x),Fraction(y)) for x,y in poly]
        spans=[]
        for y in range(t,b):
            yc=y+Fraction(1,2)
            xs=[]
            for i in range(len(pts)):
                (ax,ay),(bx,by)=pts[i-1],pts[i]
                if ay>by: ax,ay,bx,by=bx,by,ax,ay
                if ay<=yc<by:
                    xs.append(ax+(bx-ax)*(yc-ay)/(by-ay))
            xs.sort()
            for j in range(0,len(xs)-1,2):
                start=math.ceil(xs[j]-Fraction(1,2))
                end=math.ceil(xs[j+1]-Fraction(1,2))
                start,end=start,min(end,r)
                if start<end: spans.append([y,start,end])
        out.append(spans)
    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], [5, 1], [5, 5], [1, 5]], [0, 0, 6, 6]]], 6), [[[1, 1, 5], [2, 1, 5], [3, 1, 5], [4, 1, 5]]])
    check('explicit case 1', solve([[[[1, 0], [3, '5/2'], [5, 0], [5, 5], [1, 5]], [0, 0, 6, 6]]], 6), [[[1, 1, 2], [1, 4, 5], [2, 1, 5], [3, 1, 5], [4, 1, 5]]])
    check('explicit case 2', solve([[[[0, '1/2'], [4, '5/2'], [0, '9/2']], [0, 0, 6, 6]]], 6), [[[1, 0, 2], [2, 0, 4], [3, 0, 2]]])
    check('explicit case 3', solve([[[['1/2', 0], ['7/2', 0], ['7/2', 3], ['1/2', 3]], [0, 0, 6, 6]]], 6), [[[0, 0, 3], [1, 0, 3], [2, 0, 3]]])
    check('explicit case 4', solve([[[['3/2', 0], ['9/2', 0], ['9/2', 2], ['3/2', 2]], [0, 0, 6, 6]]], 6), [[[0, 1, 4], [1, 1, 4]]])
    check('explicit case 5', solve([[[[0, 0], [6, 0], [6, 6], [0, 6]], [2, 1, 4, 3]]], 6), [[[1, 2, 4], [2, 2, 4]]])
    check('explicit case 6', solve([[[[0, 0], [1, 4], [2, 0], [3, 4], [4, 0], [4, 5], [0, 5]], [0, 0, 6, 6]]], 6), [[[2, 0, 1], [2, 1, 3], [2, 3, 4], [3, 0, 1], [3, 1, 3], [3, 3, 4], [4, 0, 4]]])
    check('explicit case 7', solve([[[[-2, 0], [8, 0], [8, 2], [-2, 2]], [0, 0, 6, 6]]], 6), [[[0, 0, 6], [1, 0, 6]]])
    check('explicit case 8', solve([[[[0, 0], [2, 0], [2, 2], [0, 2]], [3, 0, 6, 6]]], 6), [[]])
    check('explicit case 9', solve([[[[1, 0], [5, 4], [1, 4]], [0, 0, 6, 6]]], 6), [[[1, 1, 2], [2, 1, 3], [3, 1, 4]]])
    check('explicit case 10', solve([[[['1/4', 0], ['5/2', 0], ['5/2', 2], ['1/4', 2]], [1, 0, 6, 6]]], 6), [[[0, 1, 2], [1, 1, 2]]])
    check('explicit case 11', solve([[[[4, 1], [4, 4], [1, 4], [1, 1]], [0, 0, 6, 6]]], 6), [[[1, 1, 4], [2, 1, 4], [3, 1, 4]]])
    check('explicit case 12', solve([[[[0, 0], [5, 0], [5, 4], [3, '3/2'], [1, 4], [0, 4]], [0, 0, 6, 6]]], 6), [[[0, 0, 5], [1, 0, 3], [1, 3, 5], [2, 0, 2], [2, 4, 5], [3, 0, 1]]])
if N == 2:
    check('explicit case 0', solve([[[[1, 1], [6, 1], [6, 6], [1, 6]], [0, 0, 7, 7]]], 7), [[[1, 1, 6], [2, 1, 6], [3, 1, 6], [4, 1, 6], [5, 1, 6]]])
    check('explicit case 1', solve([[[[1, 0], [3, '5/2'], [5, 0], [5, 5], [1, 5]], [0, 0, 7, 7]]], 7), [[[1, 1, 2], [1, 4, 5], [2, 1, 5], [3, 1, 5], [4, 1, 5]]])
    check('explicit case 2', solve([[[[0, '1/2'], [4, '5/2'], [0, '9/2']], [0, 0, 7, 7]]], 7), [[[1, 0, 2], [2, 0, 4], [3, 0, 2]]])
    check('explicit case 3', solve([[[['1/2', 0], ['7/2', 0], ['7/2', 3], ['1/2', 3]], [0, 0, 7, 7]]], 7), [[[0, 0, 3], [1, 0, 3], [2, 0, 3]]])
    check('explicit case 4', solve([[[['3/2', 0], ['9/2', 0], ['9/2', 2], ['3/2', 2]], [0, 0, 7, 7]]], 7), [[[0, 1, 4], [1, 1, 4]]])
    check('explicit case 5', solve([[[[0, 0], [7, 0], [7, 7], [0, 7]], [2, 1, 4, 3]]], 7), [[[1, 2, 4], [2, 2, 4]]])
    check('explicit case 6', solve([[[[0, 0], [1, 4], [2, 0], [3, 4], [4, 0], [4, 5], [0, 5]], [0, 0, 7, 7]]], 7), [[[2, 0, 1], [2, 1, 3], [2, 3, 4], [3, 0, 1], [3, 1, 3], [3, 3, 4], [4, 0, 4]]])
    check('explicit case 7', solve([[[[-2, 0], [9, 0], [9, 2], [-2, 2]], [0, 0, 7, 7]]], 7), [[[0, 0, 7], [1, 0, 7]]])
    check('explicit case 8', solve([[[[0, 0], [2, 0], [2, 2], [0, 2]], [3, 0, 7, 7]]], 7), [[]])
    check('explicit case 9', solve([[[[1, 0], [5, 4], [1, 4]], [0, 0, 7, 7]]], 7), [[[1, 1, 2], [2, 1, 3], [3, 1, 4]]])
    check('explicit case 10', solve([[[['1/4', 0], ['5/2', 0], ['5/2', 2], ['1/4', 2]], [1, 0, 7, 7]]], 7), [[[0, 1, 2], [1, 1, 2]]])
    check('explicit case 11', solve([[[[4, 1], [4, 4], [1, 4], [1, 1]], [0, 0, 7, 7]]], 7), [[[1, 1, 4], [2, 1, 4], [3, 1, 4]]])
    check('explicit case 12', solve([[[[0, 0], [5, 0], [5, 4], [3, '3/2'], [1, 4], [0, 4]], [0, 0, 7, 7]]], 7), [[[0, 0, 5], [1, 0, 3], [1, 3, 5], [2, 0, 2], [2, 4, 5], [3, 0, 1]]])
if N == 3:
    check('explicit case 0', solve([[[[1, 1], [7, 1], [7, 7], [1, 7]], [0, 0, 8, 8]]], 8), [[[1, 1, 7], [2, 1, 7], [3, 1, 7], [4, 1, 7], [5, 1, 7], [6, 1, 7]]])
    check('explicit case 1', solve([[[[1, 0], [3, '5/2'], [5, 0], [5, 5], [1, 5]], [0, 0, 8, 8]]], 8), [[[1, 1, 2], [1, 4, 5], [2, 1, 5], [3, 1, 5], [4, 1, 5]]])
    check('explicit case 2', solve([[[[0, '1/2'], [4, '5/2'], [0, '9/2']], [0, 0, 8, 8]]], 8), [[[1, 0, 2], [2, 0, 4], [3, 0, 2]]])
    check('explicit case 3', solve([[[['1/2', 0], ['7/2', 0], ['7/2', 3], ['1/2', 3]], [0, 0, 8, 8]]], 8), [[[0, 0, 3], [1, 0, 3], [2, 0, 3]]])
    check('explicit case 4', solve([[[['3/2', 0], ['9/2', 0], ['9/2', 2], ['3/2', 2]], [0, 0, 8, 8]]], 8), [[[0, 1, 4], [1, 1, 4]]])
    check('explicit case 5', solve([[[[0, 0], [8, 0], [8, 8], [0, 8]], [2, 1, 4, 3]]], 8), [[[1, 2, 4], [2, 2, 4]]])
    check('explicit case 6', solve([[[[0, 0], [1, 4], [2, 0], [3, 4], [4, 0], [4, 5], [0, 5]], [0, 0, 8, 8]]], 8), [[[2, 0, 1], [2, 1, 3], [2, 3, 4], [3, 0, 1], [3, 1, 3], [3, 3, 4], [4, 0, 4]]])
    check('explicit case 7', solve([[[[-2, 0], [10, 0], [10, 2], [-2, 2]], [0, 0, 8, 8]]], 8), [[[0, 0, 8], [1, 0, 8]]])
    check('explicit case 8', solve([[[[0, 0], [2, 0], [2, 2], [0, 2]], [3, 0, 8, 8]]], 8), [[]])
    check('explicit case 9', solve([[[[1, 0], [5, 4], [1, 4]], [0, 0, 8, 8]]], 8), [[[1, 1, 2], [2, 1, 3], [3, 1, 4]]])
    check('explicit case 10', solve([[[['1/4', 0], ['5/2', 0], ['5/2', 2], ['1/4', 2]], [1, 0, 8, 8]]], 8), [[[0, 1, 2], [1, 1, 2]]])
    check('explicit case 11', solve([[[[4, 1], [4, 4], [1, 4], [1, 1]], [0, 0, 8, 8]]], 8), [[[1, 1, 4], [2, 1, 4], [3, 1, 4]]])
    check('explicit case 12', solve([[[[0, 0], [5, 0], [5, 4], [3, '3/2'], [1, 4], [0, 4]], [0, 0, 8, 8]]], 8), [[[0, 0, 5], [1, 0, 3], [1, 3, 5], [2, 0, 2], [2, 4, 5], [3, 0, 1]]])
if N == 4:
    check('explicit case 0', solve([[[[1, 1], [8, 1], [8, 8], [1, 8]], [0, 0, 9, 9]]], 9), [[[1, 1, 8], [2, 1, 8], [3, 1, 8], [4, 1, 8], [5, 1, 8], [6, 1, 8], [7, 1, 8]]])
    check('explicit case 1', solve([[[[1, 0], [3, '5/2'], [5, 0], [5, 5], [1, 5]], [0, 0, 9, 9]]], 9), [[[1, 1, 2], [1, 4, 5], [2, 1, 5], [3, 1, 5], [4, 1, 5]]])
    check('explicit case 2', solve([[[[0, '1/2'], [4, '5/2'], [0, '9/2']], [0, 0, 9, 9]]], 9), [[[1, 0, 2], [2, 0, 4], [3, 0, 2]]])
    check('explicit case 3', solve([[[['1/2', 0], ['7/2', 0], ['7/2', 3], ['1/2', 3]], [0, 0, 9, 9]]], 9), [[[0, 0, 3], [1, 0, 3], [2, 0, 3]]])
    check('explicit case 4', solve([[[['3/2', 0], ['9/2', 0], ['9/2', 2], ['3/2', 2]], [0, 0, 9, 9]]], 9), [[[0, 1, 4], [1, 1, 4]]])
    check('explicit case 5', solve([[[[0, 0], [9, 0], [9, 9], [0, 9]], [2, 1, 4, 3]]], 9), [[[1, 2, 4], [2, 2, 4]]])
    check('explicit case 6', solve([[[[0, 0], [1, 4], [2, 0], [3, 4], [4, 0], [4, 5], [0, 5]], [0, 0, 9, 9]]], 9), [[[2, 0, 1], [2, 1, 3], [2, 3, 4], [3, 0, 1], [3, 1, 3], [3, 3, 4], [4, 0, 4]]])
    check('explicit case 7', solve([[[[-2, 0], [11, 0], [11, 2], [-2, 2]], [0, 0, 9, 9]]], 9), [[[0, 0, 9], [1, 0, 9]]])
    check('explicit case 8', solve([[[[0, 0], [2, 0], [2, 2], [0, 2]], [3, 0, 9, 9]]], 9), [[]])
    check('explicit case 9', solve([[[[1, 0], [5, 4], [1, 4]], [0, 0, 9, 9]]], 9), [[[1, 1, 2], [2, 1, 3], [3, 1, 4]]])
    check('explicit case 10', solve([[[['1/4', 0], ['5/2', 0], ['5/2', 2], ['1/4', 2]], [1, 0, 9, 9]]], 9), [[[0, 1, 2], [1, 1, 2]]])
    check('explicit case 11', solve([[[[4, 1], [4, 4], [1, 4], [1, 1]], [0, 0, 9, 9]]], 9), [[[1, 1, 4], [2, 1, 4], [3, 1, 4]]])
    check('explicit case 12', solve([[[[0, 0], [5, 0], [5, 4], [3, '3/2'], [1, 4], [0, 4]], [0, 0, 9, 9]]], 9), [[[0, 0, 5], [1, 0, 3], [1, 3, 5], [2, 0, 2], [2, 4, 5], [3, 0, 1]]])
if N == 5:
    check('explicit case 0', solve([[[[1, 1], [9, 1], [9, 9], [1, 9]], [0, 0, 10, 10]]], 10), [[[1, 1, 9], [2, 1, 9], [3, 1, 9], [4, 1, 9], [5, 1, 9], [6, 1, 9], [7, 1, 9], [8, 1, 9]]])
    check('explicit case 1', solve([[[[1, 0], [3, '5/2'], [5, 0], [5, 5], [1, 5]], [0, 0, 10, 10]]], 10), [[[1, 1, 2], [1, 4, 5], [2, 1, 5], [3, 1, 5], [4, 1, 5]]])
    check('explicit case 2', solve([[[[0, '1/2'], [4, '5/2'], [0, '9/2']], [0, 0, 10, 10]]], 10), [[[1, 0, 2], [2, 0, 4], [3, 0, 2]]])
    check('explicit case 3', solve([[[['1/2', 0], ['7/2', 0], ['7/2', 3], ['1/2', 3]], [0, 0, 10, 10]]], 10), [[[0, 0, 3], [1, 0, 3], [2, 0, 3]]])
    check('explicit case 4', solve([[[['3/2', 0], ['9/2', 0], ['9/2', 2], ['3/2', 2]], [0, 0, 10, 10]]], 10), [[[0, 1, 4], [1, 1, 4]]])
    check('explicit case 5', solve([[[[0, 0], [10, 0], [10, 10], [0, 10]], [2, 1, 4, 3]]], 10), [[[1, 2, 4], [2, 2, 4]]])
    check('explicit case 6', solve([[[[0, 0], [1, 4], [2, 0], [3, 4], [4, 0], [4, 5], [0, 5]], [0, 0, 10, 10]]], 10), [[[2, 0, 1], [2, 1, 3], [2, 3, 4], [3, 0, 1], [3, 1, 3], [3, 3, 4], [4, 0, 4]]])
    check('explicit case 7', solve([[[[-2, 0], [12, 0], [12, 2], [-2, 2]], [0, 0, 10, 10]]], 10), [[[0, 0, 10], [1, 0, 10]]])
    check('explicit case 8', solve([[[[0, 0], [2, 0], [2, 2], [0, 2]], [3, 0, 10, 10]]], 10), [[]])
    check('explicit case 9', solve([[[[1, 0], [5, 4], [1, 4]], [0, 0, 10, 10]]], 10), [[[1, 1, 2], [2, 1, 3], [3, 1, 4]]])
    check('explicit case 10', solve([[[['1/4', 0], ['5/2', 0], ['5/2', 2], ['1/4', 2]], [1, 0, 10, 10]]], 10), [[[0, 1, 2], [1, 1, 2]]])
    check('explicit case 11', solve([[[[4, 1], [4, 4], [1, 4], [1, 1]], [0, 0, 10, 10]]], 10), [[[1, 1, 4], [2, 1, 4], [3, 1, 4]]])
    check('explicit case 12', solve([[[[0, 0], [5, 0], [5, 4], [3, '3/2'], [1, 4], [0, 4]], [0, 0, 10, 10]]], 10), [[[0, 0, 5], [1, 0, 3], [1, 3, 5], [2, 0, 2], [2, 4, 5], [3, 0, 1]]])
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:
Span starts are not clipped to the scissor left edge.

Each command is [polygon,scissor]. Rows y in the scissor rows [top,bottom) intersected with [0,size) are sampled at y+1/2. Each polygon edge is oriented bottom to top and contributes a crossing when top<=yc<bottom (half-open in y), interpolated exactly. Crossings are sorted and paired even-odd. A pair covers pixels whose centers x+1/2 satisfy xa<=x+1/2<xb, i.e. [ceil(xa-1/2),ceil(xb-1/2)), then clipped to the scissor columns [left,right) intersected with [0,size). Non-empty spans are returned as [row,start,end].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    out=[]
    for poly,clip in commands:
        l,t,r,b=max(clip[0],0),max(clip[1],0),min(clip[2],size),min(clip[3],size)
        pts=[(Fraction(x),Fraction(y)) for x,y in poly]
        spans=[]
        for y in range(t,b):
            yc=y+Fraction(1,2)
            xs=[]
            for i in range(len(pts)):
                (ax,ay),(bx,by)=pts[i-1],pts[i]
                if ay>by: ax,ay,bx,by=bx,by,ax,ay
                if ay<=yc<by:
                    xs.append(ax+(bx-ax)*(yc-ay)/(by-ay))
            for j in range(0,len(xs)-1,2):
                start=math.ceil(xs[j]-Fraction(1,2))
                end=math.ceil(xs[j+1]-Fraction(1,2))
                start,end=max(start,l),min(end,r)
                if start<end: spans.append([y,start,end])
        out.append(spans)
    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], [5, 1], [5, 5], [1, 5]], [0, 0, 6, 6]]], 6), [[[1, 1, 5], [2, 1, 5], [3, 1, 5], [4, 1, 5]]])
    check('explicit case 1', solve([[[[1, 0], [3, '5/2'], [5, 0], [5, 5], [1, 5]], [0, 0, 6, 6]]], 6), [[[1, 1, 2], [1, 4, 5], [2, 1, 5], [3, 1, 5], [4, 1, 5]]])
    check('explicit case 2', solve([[[[0, '1/2'], [4, '5/2'], [0, '9/2']], [0, 0, 6, 6]]], 6), [[[1, 0, 2], [2, 0, 4], [3, 0, 2]]])
    check('explicit case 3', solve([[[['1/2', 0], ['7/2', 0], ['7/2', 3], ['1/2', 3]], [0, 0, 6, 6]]], 6), [[[0, 0, 3], [1, 0, 3], [2, 0, 3]]])
    check('explicit case 4', solve([[[['3/2', 0], ['9/2', 0], ['9/2', 2], ['3/2', 2]], [0, 0, 6, 6]]], 6), [[[0, 1, 4], [1, 1, 4]]])
    check('explicit case 5', solve([[[[0, 0], [6, 0], [6, 6], [0, 6]], [2, 1, 4, 3]]], 6), [[[1, 2, 4], [2, 2, 4]]])
    check('explicit case 6', solve([[[[0, 0], [1, 4], [2, 0], [3, 4], [4, 0], [4, 5], [0, 5]], [0, 0, 6, 6]]], 6), [[[2, 0, 1], [2, 1, 3], [2, 3, 4], [3, 0, 1], [3, 1, 3], [3, 3, 4], [4, 0, 4]]])
    check('explicit case 7', solve([[[[-2, 0], [8, 0], [8, 2], [-2, 2]], [0, 0, 6, 6]]], 6), [[[0, 0, 6], [1, 0, 6]]])
    check('explicit case 8', solve([[[[0, 0], [2, 0], [2, 2], [0, 2]], [3, 0, 6, 6]]], 6), [[]])
    check('explicit case 9', solve([[[[1, 0], [5, 4], [1, 4]], [0, 0, 6, 6]]], 6), [[[1, 1, 2], [2, 1, 3], [3, 1, 4]]])
    check('explicit case 10', solve([[[['1/4', 0], ['5/2', 0], ['5/2', 2], ['1/4', 2]], [1, 0, 6, 6]]], 6), [[[0, 1, 2], [1, 1, 2]]])
    check('explicit case 11', solve([[[[4, 1], [4, 4], [1, 4], [1, 1]], [0, 0, 6, 6]]], 6), [[[1, 1, 4], [2, 1, 4], [3, 1, 4]]])
    check('explicit case 12', solve([[[[0, 0], [5, 0], [5, 4], [3, '3/2'], [1, 4], [0, 4]], [0, 0, 6, 6]]], 6), [[[0, 0, 5], [1, 0, 3], [1, 3, 5], [2, 0, 2], [2, 4, 5], [3, 0, 1]]])
if N == 2:
    check('explicit case 0', solve([[[[1, 1], [6, 1], [6, 6], [1, 6]], [0, 0, 7, 7]]], 7), [[[1, 1, 6], [2, 1, 6], [3, 1, 6], [4, 1, 6], [5, 1, 6]]])
    check('explicit case 1', solve([[[[1, 0], [3, '5/2'], [5, 0], [5, 5], [1, 5]], [0, 0, 7, 7]]], 7), [[[1, 1, 2], [1, 4, 5], [2, 1, 5], [3, 1, 5], [4, 1, 5]]])
    check('explicit case 2', solve([[[[0, '1/2'], [4, '5/2'], [0, '9/2']], [0, 0, 7, 7]]], 7), [[[1, 0, 2], [2, 0, 4], [3, 0, 2]]])
    check('explicit case 3', solve([[[['1/2', 0], ['7/2', 0], ['7/2', 3], ['1/2', 3]], [0, 0, 7, 7]]], 7), [[[0, 0, 3], [1, 0, 3], [2, 0, 3]]])
    check('explicit case 4', solve([[[['3/2', 0], ['9/2', 0], ['9/2', 2], ['3/2', 2]], [0, 0, 7, 7]]], 7), [[[0, 1, 4], [1, 1, 4]]])
    check('explicit case 5', solve([[[[0, 0], [7, 0], [7, 7], [0, 7]], [2, 1, 4, 3]]], 7), [[[1, 2, 4], [2, 2, 4]]])
    check('explicit case 6', solve([[[[0, 0], [1, 4], [2, 0], [3, 4], [4, 0], [4, 5], [0, 5]], [0, 0, 7, 7]]], 7), [[[2, 0, 1], [2, 1, 3], [2, 3, 4], [3, 0, 1], [3, 1, 3], [3, 3, 4], [4, 0, 4]]])
    check('explicit case 7', solve([[[[-2, 0], [9, 0], [9, 2], [-2, 2]], [0, 0, 7, 7]]], 7), [[[0, 0, 7], [1, 0, 7]]])
    check('explicit case 8', solve([[[[0, 0], [2, 0], [2, 2], [0, 2]], [3, 0, 7, 7]]], 7), [[]])
    check('explicit case 9', solve([[[[1, 0], [5, 4], [1, 4]], [0, 0, 7, 7]]], 7), [[[1, 1, 2], [2, 1, 3], [3, 1, 4]]])
    check('explicit case 10', solve([[[['1/4', 0], ['5/2', 0], ['5/2', 2], ['1/4', 2]], [1, 0, 7, 7]]], 7), [[[0, 1, 2], [1, 1, 2]]])
    check('explicit case 11', solve([[[[4, 1], [4, 4], [1, 4], [1, 1]], [0, 0, 7, 7]]], 7), [[[1, 1, 4], [2, 1, 4], [3, 1, 4]]])
    check('explicit case 12', solve([[[[0, 0], [5, 0], [5, 4], [3, '3/2'], [1, 4], [0, 4]], [0, 0, 7, 7]]], 7), [[[0, 0, 5], [1, 0, 3], [1, 3, 5], [2, 0, 2], [2, 4, 5], [3, 0, 1]]])
if N == 3:
    check('explicit case 0', solve([[[[1, 1], [7, 1], [7, 7], [1, 7]], [0, 0, 8, 8]]], 8), [[[1, 1, 7], [2, 1, 7], [3, 1, 7], [4, 1, 7], [5, 1, 7], [6, 1, 7]]])
    check('explicit case 1', solve([[[[1, 0], [3, '5/2'], [5, 0], [5, 5], [1, 5]], [0, 0, 8, 8]]], 8), [[[1, 1, 2], [1, 4, 5], [2, 1, 5], [3, 1, 5], [4, 1, 5]]])
    check('explicit case 2', solve([[[[0, '1/2'], [4, '5/2'], [0, '9/2']], [0, 0, 8, 8]]], 8), [[[1, 0, 2], [2, 0, 4], [3, 0, 2]]])
    check('explicit case 3', solve([[[['1/2', 0], ['7/2', 0], ['7/2', 3], ['1/2', 3]], [0, 0, 8, 8]]], 8), [[[0, 0, 3], [1, 0, 3], [2, 0, 3]]])
    check('explicit case 4', solve([[[['3/2', 0], ['9/2', 0], ['9/2', 2], ['3/2', 2]], [0, 0, 8, 8]]], 8), [[[0, 1, 4], [1, 1, 4]]])
    check('explicit case 5', solve([[[[0, 0], [8, 0], [8, 8], [0, 8]], [2, 1, 4, 3]]], 8), [[[1, 2, 4], [2, 2, 4]]])
    check('explicit case 6', solve([[[[0, 0], [1, 4], [2, 0], [3, 4], [4, 0], [4, 5], [0, 5]], [0, 0, 8, 8]]], 8), [[[2, 0, 1], [2, 1, 3], [2, 3, 4], [3, 0, 1], [3, 1, 3], [3, 3, 4], [4, 0, 4]]])
    check('explicit case 7', solve([[[[-2, 0], [10, 0], [10, 2], [-2, 2]], [0, 0, 8, 8]]], 8), [[[0, 0, 8], [1, 0, 8]]])
    check('explicit case 8', solve([[[[0, 0], [2, 0], [2, 2], [0, 2]], [3, 0, 8, 8]]], 8), [[]])
    check('explicit case 9', solve([[[[1, 0], [5, 4], [1, 4]], [0, 0, 8, 8]]], 8), [[[1, 1, 2], [2, 1, 3], [3, 1, 4]]])
    check('explicit case 10', solve([[[['1/4', 0], ['5/2', 0], ['5/2', 2], ['1/4', 2]], [1, 0, 8, 8]]], 8), [[[0, 1, 2], [1, 1, 2]]])
    check('explicit case 11', solve([[[[4, 1], [4, 4], [1, 4], [1, 1]], [0, 0, 8, 8]]], 8), [[[1, 1, 4], [2, 1, 4], [3, 1, 4]]])
    check('explicit case 12', solve([[[[0, 0], [5, 0], [5, 4], [3, '3/2'], [1, 4], [0, 4]], [0, 0, 8, 8]]], 8), [[[0, 0, 5], [1, 0, 3], [1, 3, 5], [2, 0, 2], [2, 4, 5], [3, 0, 1]]])
if N == 4:
    check('explicit case 0', solve([[[[1, 1], [8, 1], [8, 8], [1, 8]], [0, 0, 9, 9]]], 9), [[[1, 1, 8], [2, 1, 8], [3, 1, 8], [4, 1, 8], [5, 1, 8], [6, 1, 8], [7, 1, 8]]])
    check('explicit case 1', solve([[[[1, 0], [3, '5/2'], [5, 0], [5, 5], [1, 5]], [0, 0, 9, 9]]], 9), [[[1, 1, 2], [1, 4, 5], [2, 1, 5], [3, 1, 5], [4, 1, 5]]])
    check('explicit case 2', solve([[[[0, '1/2'], [4, '5/2'], [0, '9/2']], [0, 0, 9, 9]]], 9), [[[1, 0, 2], [2, 0, 4], [3, 0, 2]]])
    check('explicit case 3', solve([[[['1/2', 0], ['7/2', 0], ['7/2', 3], ['1/2', 3]], [0, 0, 9, 9]]], 9), [[[0, 0, 3], [1, 0, 3], [2, 0, 3]]])
    check('explicit case 4', solve([[[['3/2', 0], ['9/2', 0], ['9/2', 2], ['3/2', 2]], [0, 0, 9, 9]]], 9), [[[0, 1, 4], [1, 1, 4]]])
    check('explicit case 5', solve([[[[0, 0], [9, 0], [9, 9], [0, 9]], [2, 1, 4, 3]]], 9), [[[1, 2, 4], [2, 2, 4]]])
    check('explicit case 6', solve([[[[0, 0], [1, 4], [2, 0], [3, 4], [4, 0], [4, 5], [0, 5]], [0, 0, 9, 9]]], 9), [[[2, 0, 1], [2, 1, 3], [2, 3, 4], [3, 0, 1], [3, 1, 3], [3, 3, 4], [4, 0, 4]]])
    check('explicit case 7', solve([[[[-2, 0], [11, 0], [11, 2], [-2, 2]], [0, 0, 9, 9]]], 9), [[[0, 0, 9], [1, 0, 9]]])
    check('explicit case 8', solve([[[[0, 0], [2, 0], [2, 2], [0, 2]], [3, 0, 9, 9]]], 9), [[]])
    check('explicit case 9', solve([[[[1, 0], [5, 4], [1, 4]], [0, 0, 9, 9]]], 9), [[[1, 1, 2], [2, 1, 3], [3, 1, 4]]])
    check('explicit case 10', solve([[[['1/4', 0], ['5/2', 0], ['5/2', 2], ['1/4', 2]], [1, 0, 9, 9]]], 9), [[[0, 1, 2], [1, 1, 2]]])
    check('explicit case 11', solve([[[[4, 1], [4, 4], [1, 4], [1, 1]], [0, 0, 9, 9]]], 9), [[[1, 1, 4], [2, 1, 4], [3, 1, 4]]])
    check('explicit case 12', solve([[[[0, 0], [5, 0], [5, 4], [3, '3/2'], [1, 4], [0, 4]], [0, 0, 9, 9]]], 9), [[[0, 0, 5], [1, 0, 3], [1, 3, 5], [2, 0, 2], [2, 4, 5], [3, 0, 1]]])
if N == 5:
    check('explicit case 0', solve([[[[1, 1], [9, 1], [9, 9], [1, 9]], [0, 0, 10, 10]]], 10), [[[1, 1, 9], [2, 1, 9], [3, 1, 9], [4, 1, 9], [5, 1, 9], [6, 1, 9], [7, 1, 9], [8, 1, 9]]])
    check('explicit case 1', solve([[[[1, 0], [3, '5/2'], [5, 0], [5, 5], [1, 5]], [0, 0, 10, 10]]], 10), [[[1, 1, 2], [1, 4, 5], [2, 1, 5], [3, 1, 5], [4, 1, 5]]])
    check('explicit case 2', solve([[[[0, '1/2'], [4, '5/2'], [0, '9/2']], [0, 0, 10, 10]]], 10), [[[1, 0, 2], [2, 0, 4], [3, 0, 2]]])
    check('explicit case 3', solve([[[['1/2', 0], ['7/2', 0], ['7/2', 3], ['1/2', 3]], [0, 0, 10, 10]]], 10), [[[0, 0, 3], [1, 0, 3], [2, 0, 3]]])
    check('explicit case 4', solve([[[['3/2', 0], ['9/2', 0], ['9/2', 2], ['3/2', 2]], [0, 0, 10, 10]]], 10), [[[0, 1, 4], [1, 1, 4]]])
    check('explicit case 5', solve([[[[0, 0], [10, 0], [10, 10], [0, 10]], [2, 1, 4, 3]]], 10), [[[1, 2, 4], [2, 2, 4]]])
    check('explicit case 6', solve([[[[0, 0], [1, 4], [2, 0], [3, 4], [4, 0], [4, 5], [0, 5]], [0, 0, 10, 10]]], 10), [[[2, 0, 1], [2, 1, 3], [2, 3, 4], [3, 0, 1], [3, 1, 3], [3, 3, 4], [4, 0, 4]]])
    check('explicit case 7', solve([[[[-2, 0], [12, 0], [12, 2], [-2, 2]], [0, 0, 10, 10]]], 10), [[[0, 0, 10], [1, 0, 10]]])
    check('explicit case 8', solve([[[[0, 0], [2, 0], [2, 2], [0, 2]], [3, 0, 10, 10]]], 10), [[]])
    check('explicit case 9', solve([[[[1, 0], [5, 4], [1, 4]], [0, 0, 10, 10]]], 10), [[[1, 1, 2], [2, 1, 3], [3, 1, 4]]])
    check('explicit case 10', solve([[[['1/4', 0], ['5/2', 0], ['5/2', 2], ['1/4', 2]], [1, 0, 10, 10]]], 10), [[[0, 1, 2], [1, 1, 2]]])
    check('explicit case 11', solve([[[[4, 1], [4, 4], [1, 4], [1, 1]], [0, 0, 10, 10]]], 10), [[[1, 1, 4], [2, 1, 4], [3, 1, 4]]])
    check('explicit case 12', solve([[[[0, 0], [5, 0], [5, 4], [3, '3/2'], [1, 4], [0, 4]], [0, 0, 10, 10]]], 10), [[[0, 0, 5], [1, 0, 3], [1, 3, 5], [2, 0, 2], [2, 4, 5], [3, 0, 1]]])
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

prompt:
Crossings are paired in edge order instead of x order, so concave rows pair the wrong edges.

Each command is [polygon,scissor]. Rows y in the scissor rows [top,bottom) intersected with [0,size) are sampled at y+1/2. Each polygon edge is oriented bottom to top and contributes a crossing when top<=yc<bottom (half-open in y), interpolated exactly. Crossings are sorted and paired even-odd. A pair covers pixels whose centers x+1/2 satisfy xa<=x+1/2<xb, i.e. [ceil(xa-1/2),ceil(xb-1/2)), then clipped to the scissor columns [left,right) intersected with [0,size). Non-empty spans are returned as [row,start,end].

split: open-access


prompt:
Spans clipped to zero width are still emitted.

Each command is [polygon,scissor]. Rows y in the scissor rows [top,bottom) intersected with [0,size) are sampled at y+1/2. Each polygon edge is oriented bottom to top and contributes a crossing when top<=yc<bottom (half-open in y), interpolated exactly. Crossings are sorted and paired even-odd. A pair covers pixels whose centers x+1/2 satisfy xa<=x+1/2<xb, i.e. [ceil(xa-1/2),ceil(xb-1/2)), then clipped to the scissor columns [left,right) intersected with [0,size). Non-empty spans are returned as [row,start,end].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    out=[]
    for poly,clip in commands:
        l,t,r,b=max(clip[0],0),max(clip[1],0),min(clip[2],size),min(clip[3],size)
        pts=[(Fraction(x),Fraction(y)) for x,y in poly]
        spans=[]
        for y in range(t,b):
            yc=y+Fraction(1,2)
            xs=[]
            for i in range(len(pts)):
                (ax,ay),(bx,by)=pts[i-1],pts[i]
                if ay>by: ay,by=by,ay
                if ay<=yc<by:
                    xs.append(ax+(bx-ax)*(yc-ay)/(by-ay))
            xs.sort()
            for j in range(0,len(xs)-1,2):
                start=math.ceil(xs[j]-Fraction(1,2))
                end=math.ceil(xs[j+1]-Fraction(1,2))
                start,end=max(start,l),min(end,r)
                if start<end: spans.append([y,start,end])
        out.append(spans)
    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], [5, 1], [5, 5], [1, 5]], [0, 0, 6, 6]]], 6), [[[1, 1, 5], [2, 1, 5], [3, 1, 5], [4, 1, 5]]])
    check('explicit case 1', solve([[[[1, 0], [3, '5/2'], [5, 0], [5, 5], [1, 5]], [0, 0, 6, 6]]], 6), [[[1, 1, 2], [1, 4, 5], [2, 1, 5], [3, 1, 5], [4, 1, 5]]])
    check('explicit case 2', solve([[[[0, '1/2'], [4, '5/2'], [0, '9/2']], [0, 0, 6, 6]]], 6), [[[1, 0, 2], [2, 0, 4], [3, 0, 2]]])
    check('explicit case 3', solve([[[['1/2', 0], ['7/2', 0], ['7/2', 3], ['1/2', 3]], [0, 0, 6, 6]]], 6), [[[0, 0, 3], [1, 0, 3], [2, 0, 3]]])
    check('explicit case 4', solve([[[['3/2', 0], ['9/2', 0], ['9/2', 2], ['3/2', 2]], [0, 0, 6, 6]]], 6), [[[0, 1, 4], [1, 1, 4]]])
    check('explicit case 5', solve([[[[0, 0], [6, 0], [6, 6], [0, 6]], [2, 1, 4, 3]]], 6), [[[1, 2, 4], [2, 2, 4]]])
    check('explicit case 6', solve([[[[0, 0], [1, 4], [2, 0], [3, 4], [4, 0], [4, 5], [0, 5]], [0, 0, 6, 6]]], 6), [[[2, 0, 1], [2, 1, 3], [2, 3, 4], [3, 0, 1], [3, 1, 3], [3, 3, 4], [4, 0, 4]]])
    check('explicit case 7', solve([[[[-2, 0], [8, 0], [8, 2], [-2, 2]], [0, 0, 6, 6]]], 6), [[[0, 0, 6], [1, 0, 6]]])
    check('explicit case 8', solve([[[[0, 0], [2, 0], [2, 2], [0, 2]], [3, 0, 6, 6]]], 6), [[]])
    check('explicit case 9', solve([[[[1, 0], [5, 4], [1, 4]], [0, 0, 6, 6]]], 6), [[[1, 1, 2], [2, 1, 3], [3, 1, 4]]])
    check('explicit case 10', solve([[[['1/4', 0], ['5/2', 0], ['5/2', 2], ['1/4', 2]], [1, 0, 6, 6]]], 6), [[[0, 1, 2], [1, 1, 2]]])
    check('explicit case 11', solve([[[[4, 1], [4, 4], [1, 4], [1, 1]], [0, 0, 6, 6]]], 6), [[[1, 1, 4], [2, 1, 4], [3, 1, 4]]])
    check('explicit case 12', solve([[[[0, 0], [5, 0], [5, 4], [3, '3/2'], [1, 4], [0, 4]], [0, 0, 6, 6]]], 6), [[[0, 0, 5], [1, 0, 3], [1, 3, 5], [2, 0, 2], [2, 4, 5], [3, 0, 1]]])
if N == 2:
    check('explicit case 0', solve([[[[1, 1], [6, 1], [6, 6], [1, 6]], [0, 0, 7, 7]]], 7), [[[1, 1, 6], [2, 1, 6], [3, 1, 6], [4, 1, 6], [5, 1, 6]]])
    check('explicit case 1', solve([[[[1, 0], [3, '5/2'], [5, 0], [5, 5], [1, 5]], [0, 0, 7, 7]]], 7), [[[1, 1, 2], [1, 4, 5], [2, 1, 5], [3, 1, 5], [4, 1, 5]]])
    check('explicit case 2', solve([[[[0, '1/2'], [4, '5/2'], [0, '9/2']], [0, 0, 7, 7]]], 7), [[[1, 0, 2], [2, 0, 4], [3, 0, 2]]])
    check('explicit case 3', solve([[[['1/2', 0], ['7/2', 0], ['7/2', 3], ['1/2', 3]], [0, 0, 7, 7]]], 7), [[[0, 0, 3], [1, 0, 3], [2, 0, 3]]])
    check('explicit case 4', solve([[[['3/2', 0], ['9/2', 0], ['9/2', 2], ['3/2', 2]], [0, 0, 7, 7]]], 7), [[[0, 1, 4], [1, 1, 4]]])
    check('explicit case 5', solve([[[[0, 0], [7, 0], [7, 7], [0, 7]], [2, 1, 4, 3]]], 7), [[[1, 2, 4], [2, 2, 4]]])
    check('explicit case 6', solve([[[[0, 0], [1, 4], [2, 0], [3, 4], [4, 0], [4, 5], [0, 5]], [0, 0, 7, 7]]], 7), [[[2, 0, 1], [2, 1, 3], [2, 3, 4], [3, 0, 1], [3, 1, 3], [3, 3, 4], [4, 0, 4]]])
    check('explicit case 7', solve([[[[-2, 0], [9, 0], [9, 2], [-2, 2]], [0, 0, 7, 7]]], 7), [[[0, 0, 7], [1, 0, 7]]])
    check('explicit case 8', solve([[[[0, 0], [2, 0], [2, 2], [0, 2]], [3, 0, 7, 7]]], 7), [[]])
    check('explicit case 9', solve([[[[1, 0], [5, 4], [1, 4]], [0, 0, 7, 7]]], 7), [[[1, 1, 2], [2, 1, 3], [3, 1, 4]]])
    check('explicit case 10', solve([[[['1/4', 0], ['5/2', 0], ['5/2', 2], ['1/4', 2]], [1, 0, 7, 7]]], 7), [[[0, 1, 2], [1, 1, 2]]])
    check('explicit case 11', solve([[[[4, 1], [4, 4], [1, 4], [1, 1]], [0, 0, 7, 7]]], 7), [[[1, 1, 4], [2, 1, 4], [3, 1, 4]]])
    check('explicit case 12', solve([[[[0, 0], [5, 0], [5, 4], [3, '3/2'], [1, 4], [0, 4]], [0, 0, 7, 7]]], 7), [[[0, 0, 5], [1, 0, 3], [1, 3, 5], [2, 0, 2], [2, 4, 5], [3, 0, 1]]])
if N == 3:
    check('explicit case 0', solve([[[[1, 1], [7, 1], [7, 7], [1, 7]], [0, 0, 8, 8]]], 8), [[[1, 1, 7], [2, 1, 7], [3, 1, 7], [4, 1, 7], [5, 1, 7], [6, 1, 7]]])
    check('explicit case 1', solve([[[[1, 0], [3, '5/2'], [5, 0], [5, 5], [1, 5]], [0, 0, 8, 8]]], 8), [[[1, 1, 2], [1, 4, 5], [2, 1, 5], [3, 1, 5], [4, 1, 5]]])
    check('explicit case 2', solve([[[[0, '1/2'], [4, '5/2'], [0, '9/2']], [0, 0, 8, 8]]], 8), [[[1, 0, 2], [2, 0, 4], [3, 0, 2]]])
    check('explicit case 3', solve([[[['1/2', 0], ['7/2', 0], ['7/2', 3], ['1/2', 3]], [0, 0, 8, 8]]], 8), [[[0, 0, 3], [1, 0, 3], [2, 0, 3]]])
    check('explicit case 4', solve([[[['3/2', 0], ['9/2', 0], ['9/2', 2], ['3/2', 2]], [0, 0, 8, 8]]], 8), [[[0, 1, 4], [1, 1, 4]]])
    check('explicit case 5', solve([[[[0, 0], [8, 0], [8, 8], [0, 8]], [2, 1, 4, 3]]], 8), [[[1, 2, 4], [2, 2, 4]]])
    check('explicit case 6', solve([[[[0, 0], [1, 4], [2, 0], [3, 4], [4, 0], [4, 5], [0, 5]], [0, 0, 8, 8]]], 8), [[[2, 0, 1], [2, 1, 3], [2, 3, 4], [3, 0, 1], [3, 1, 3], [3, 3, 4], [4, 0, 4]]])
    check('explicit case 7', solve([[[[-2, 0], [10, 0], [10, 2], [-2, 2]], [0, 0, 8, 8]]], 8), [[[0, 0, 8], [1, 0, 8]]])
    check('explicit case 8', solve([[[[0, 0], [2, 0], [2, 2], [0, 2]], [3, 0, 8, 8]]], 8), [[]])
    check('explicit case 9', solve([[[[1, 0], [5, 4], [1, 4]], [0, 0, 8, 8]]], 8), [[[1, 1, 2], [2, 1, 3], [3, 1, 4]]])
    check('explicit case 10', solve([[[['1/4', 0], ['5/2', 0], ['5/2', 2], ['1/4', 2]], [1, 0, 8, 8]]], 8), [[[0, 1, 2], [1, 1, 2]]])
    check('explicit case 11', solve([[[[4, 1], [4, 4], [1, 4], [1, 1]], [0, 0, 8, 8]]], 8), [[[1, 1, 4], [2, 1, 4], [3, 1, 4]]])
    check('explicit case 12', solve([[[[0, 0], [5, 0], [5, 4], [3, '3/2'], [1, 4], [0, 4]], [0, 0, 8, 8]]], 8), [[[0, 0, 5], [1, 0, 3], [1, 3, 5], [2, 0, 2], [2, 4, 5], [3, 0, 1]]])
if N == 4:
    check('explicit case 0', solve([[[[1, 1], [8, 1], [8, 8], [1, 8]], [0, 0, 9, 9]]], 9), [[[1, 1, 8], [2, 1, 8], [3, 1, 8], [4, 1, 8], [5, 1, 8], [6, 1, 8], [7, 1, 8]]])
    check('explicit case 1', solve([[[[1, 0], [3, '5/2'], [5, 0], [5, 5], [1, 5]], [0, 0, 9, 9]]], 9), [[[1, 1, 2], [1, 4, 5], [2, 1, 5], [3, 1, 5], [4, 1, 5]]])
    check('explicit case 2', solve([[[[0, '1/2'], [4, '5/2'], [0, '9/2']], [0, 0, 9, 9]]], 9), [[[1, 0, 2], [2, 0, 4], [3, 0, 2]]])
    check('explicit case 3', solve([[[['1/2', 0], ['7/2', 0], ['7/2', 3], ['1/2', 3]], [0, 0, 9, 9]]], 9), [[[0, 0, 3], [1, 0, 3], [2, 0, 3]]])
    check('explicit case 4', solve([[[['3/2', 0], ['9/2', 0], ['9/2', 2], ['3/2', 2]], [0, 0, 9, 9]]], 9), [[[0, 1, 4], [1, 1, 4]]])
    check('explicit case 5', solve([[[[0, 0], [9, 0], [9, 9], [0, 9]], [2, 1, 4, 3]]], 9), [[[1, 2, 4], [2, 2, 4]]])
    check('explicit case 6', solve([[[[0, 0], [1, 4], [2, 0], [3, 4], [4, 0], [4, 5], [0, 5]], [0, 0, 9, 9]]], 9), [[[2, 0, 1], [2, 1, 3], [2, 3, 4], [3, 0, 1], [3, 1, 3], [3, 3, 4], [4, 0, 4]]])
    check('explicit case 7', solve([[[[-2, 0], [11, 0], [11, 2], [-2, 2]], [0, 0, 9, 9]]], 9), [[[0, 0, 9], [1, 0, 9]]])
    check('explicit case 8', solve([[[[0, 0], [2, 0], [2, 2], [0, 2]], [3, 0, 9, 9]]], 9), [[]])
    check('explicit case 9', solve([[[[1, 0], [5, 4], [1, 4]], [0, 0, 9, 9]]], 9), [[[1, 1, 2], [2, 1, 3], [3, 1, 4]]])
    check('explicit case 10', solve([[[['1/4', 0], ['5/2', 0], ['5/2', 2], ['1/4', 2]], [1, 0, 9, 9]]], 9), [[[0, 1, 2], [1, 1, 2]]])
    check('explicit case 11', solve([[[[4, 1], [4, 4], [1, 4], [1, 1]], [0, 0, 9, 9]]], 9), [[[1, 1, 4], [2, 1, 4], [3, 1, 4]]])
    check('explicit case 12', solve([[[[0, 0], [5, 0], [5, 4], [3, '3/2'], [1, 4], [0, 4]], [0, 0, 9, 9]]], 9), [[[0, 0, 5], [1, 0, 3], [1, 3, 5], [2, 0, 2], [2, 4, 5], [3, 0, 1]]])
if N == 5:
    check('explicit case 0', solve([[[[1, 1], [9, 1], [9, 9], [1, 9]], [0, 0, 10, 10]]], 10), [[[1, 1, 9], [2, 1, 9], [3, 1, 9], [4, 1, 9], [5, 1, 9], [6, 1, 9], [7, 1, 9], [8, 1, 9]]])
    check('explicit case 1', solve([[[[1, 0], [3, '5/2'], [5, 0], [5, 5], [1, 5]], [0, 0, 10, 10]]], 10), [[[1, 1, 2], [1, 4, 5], [2, 1, 5], [3, 1, 5], [4, 1, 5]]])
    check('explicit case 2', solve([[[[0, '1/2'], [4, '5/2'], [0, '9/2']], [0, 0, 10, 10]]], 10), [[[1, 0, 2], [2, 0, 4], [3, 0, 2]]])
    check('explicit case 3', solve([[[['1/2', 0], ['7/2', 0], ['7/2', 3], ['1/2', 3]], [0, 0, 10, 10]]], 10), [[[0, 0, 3], [1, 0, 3], [2, 0, 3]]])
    check('explicit case 4', solve([[[['3/2', 0], ['9/2', 0], ['9/2', 2], ['3/2', 2]], [0, 0, 10, 10]]], 10), [[[0, 1, 4], [1, 1, 4]]])
    check('explicit case 5', solve([[[[0, 0], [10, 0], [10, 10], [0, 10]], [2, 1, 4, 3]]], 10), [[[1, 2, 4], [2, 2, 4]]])
    check('explicit case 6', solve([[[[0, 0], [1, 4], [2, 0], [3, 4], [4, 0], [4, 5], [0, 5]], [0, 0, 10, 10]]], 10), [[[2, 0, 1], [2, 1, 3], [2, 3, 4], [3, 0, 1], [3, 1, 3], [3, 3, 4], [4, 0, 4]]])
    check('explicit case 7', solve([[[[-2, 0], [12, 0], [12, 2], [-2, 2]], [0, 0, 10, 10]]], 10), [[[0, 0, 10], [1, 0, 10]]])
    check('explicit case 8', solve([[[[0, 0], [2, 0], [2, 2], [0, 2]], [3, 0, 10, 10]]], 10), [[]])
    check('explicit case 9', solve([[[[1, 0], [5, 4], [1, 4]], [0, 0, 10, 10]]], 10), [[[1, 1, 2], [2, 1, 3], [3, 1, 4]]])
    check('explicit case 10', solve([[[['1/4', 0], ['5/2', 0], ['5/2', 2], ['1/4', 2]], [1, 0, 10, 10]]], 10), [[[0, 1, 2], [1, 1, 2]]])
    check('explicit case 11', solve([[[[4, 1], [4, 4], [1, 4], [1, 1]], [0, 0, 10, 10]]], 10), [[[1, 1, 4], [2, 1, 4], [3, 1, 4]]])
    check('explicit case 12', solve([[[[0, 0], [5, 0], [5, 4], [3, '3/2'], [1, 4], [0, 4]], [0, 0, 10, 10]]], 10), [[[0, 0, 5], [1, 0, 3], [1, 3, 5], [2, 0, 2], [2, 4, 5], [3, 0, 1]]])
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:
Orienting a downward edge swaps only its y coordinates, reversing the x interpolation along the edge.

Each command is [polygon,scissor]. Rows y in the scissor rows [top,bottom) intersected with [0,size) are sampled at y+1/2. Each polygon edge is oriented bottom to top and contributes a crossing when top<=yc<bottom (half-open in y), interpolated exactly. Crossings are sorted and paired even-odd. A pair covers pixels whose centers x+1/2 satisfy xa<=x+1/2<xb, i.e. [ceil(xa-1/2),ceil(xb-1/2)), then clipped to the scissor columns [left,right) intersected with [0,size). Non-empty spans are returned as [row,start,end].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    out=[]
    for poly,clip in commands:
        l,t,r,b=max(clip[0],0),max(clip[1],0),min(clip[2],size),min(clip[3],size)
        pts=[(Fraction(x),Fraction(y)) for x,y in poly]
        spans=[]
        for y in range(t,b):
            yc=y+Fraction(1,2)
            xs=[]
            for i in range(len(pts)):
                (ax,ay),(bx,by)=pts[i-1],pts[i]
                if ay>by: ax,ay,bx,by=bx,by,ax,ay
                if ay<=yc<by:
                    xs.append(ax+(bx-ax)*(yc-ay)/(by-ay))
            xs.sort()
            for j in range(0,len(xs)-1):
                start=math.ceil(xs[j]-Fraction(1,2))
                end=math.ceil(xs[j+1]-Fraction(1,2))
                start,end=max(start,l),min(end,r)
                if start<end: spans.append([y,start,end])
        out.append(spans)
    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], [5, 1], [5, 5], [1, 5]], [0, 0, 6, 6]]], 6), [[[1, 1, 5], [2, 1, 5], [3, 1, 5], [4, 1, 5]]])
    check('explicit case 1', solve([[[[1, 0], [3, '5/2'], [5, 0], [5, 5], [1, 5]], [0, 0, 6, 6]]], 6), [[[1, 1, 2], [1, 4, 5], [2, 1, 5], [3, 1, 5], [4, 1, 5]]])
    check('explicit case 2', solve([[[[0, '1/2'], [4, '5/2'], [0, '9/2']], [0, 0, 6, 6]]], 6), [[[1, 0, 2], [2, 0, 4], [3, 0, 2]]])
    check('explicit case 3', solve([[[['1/2', 0], ['7/2', 0], ['7/2', 3], ['1/2', 3]], [0, 0, 6, 6]]], 6), [[[0, 0, 3], [1, 0, 3], [2, 0, 3]]])
    check('explicit case 4', solve([[[['3/2', 0], ['9/2', 0], ['9/2', 2], ['3/2', 2]], [0, 0, 6, 6]]], 6), [[[0, 1, 4], [1, 1, 4]]])
    check('explicit case 5', solve([[[[0, 0], [6, 0], [6, 6], [0, 6]], [2, 1, 4, 3]]], 6), [[[1, 2, 4], [2, 2, 4]]])
    check('explicit case 6', solve([[[[0, 0], [1, 4], [2, 0], [3, 4], [4, 0], [4, 5], [0, 5]], [0, 0, 6, 6]]], 6), [[[2, 0, 1], [2, 1, 3], [2, 3, 4], [3, 0, 1], [3, 1, 3], [3, 3, 4], [4, 0, 4]]])
    check('explicit case 7', solve([[[[-2, 0], [8, 0], [8, 2], [-2, 2]], [0, 0, 6, 6]]], 6), [[[0, 0, 6], [1, 0, 6]]])
    check('explicit case 8', solve([[[[0, 0], [2, 0], [2, 2], [0, 2]], [3, 0, 6, 6]]], 6), [[]])
    check('explicit case 9', solve([[[[1, 0], [5, 4], [1, 4]], [0, 0, 6, 6]]], 6), [[[1, 1, 2], [2, 1, 3], [3, 1, 4]]])
    check('explicit case 10', solve([[[['1/4', 0], ['5/2', 0], ['5/2', 2], ['1/4', 2]], [1, 0, 6, 6]]], 6), [[[0, 1, 2], [1, 1, 2]]])
    check('explicit case 11', solve([[[[4, 1], [4, 4], [1, 4], [1, 1]], [0, 0, 6, 6]]], 6), [[[1, 1, 4], [2, 1, 4], [3, 1, 4]]])
    check('explicit case 12', solve([[[[0, 0], [5, 0], [5, 4], [3, '3/2'], [1, 4], [0, 4]], [0, 0, 6, 6]]], 6), [[[0, 0, 5], [1, 0, 3], [1, 3, 5], [2, 0, 2], [2, 4, 5], [3, 0, 1]]])
if N == 2:
    check('explicit case 0', solve([[[[1, 1], [6, 1], [6, 6], [1, 6]], [0, 0, 7, 7]]], 7), [[[1, 1, 6], [2, 1, 6], [3, 1, 6], [4, 1, 6], [5, 1, 6]]])
    check('explicit case 1', solve([[[[1, 0], [3, '5/2'], [5, 0], [5, 5], [1, 5]], [0, 0, 7, 7]]], 7), [[[1, 1, 2], [1, 4, 5], [2, 1, 5], [3, 1, 5], [4, 1, 5]]])
    check('explicit case 2', solve([[[[0, '1/2'], [4, '5/2'], [0, '9/2']], [0, 0, 7, 7]]], 7), [[[1, 0, 2], [2, 0, 4], [3, 0, 2]]])
    check('explicit case 3', solve([[[['1/2', 0], ['7/2', 0], ['7/2', 3], ['1/2', 3]], [0, 0, 7, 7]]], 7), [[[0, 0, 3], [1, 0, 3], [2, 0, 3]]])
    check('explicit case 4', solve([[[['3/2', 0], ['9/2', 0], ['9/2', 2], ['3/2', 2]], [0, 0, 7, 7]]], 7), [[[0, 1, 4], [1, 1, 4]]])
    check('explicit case 5', solve([[[[0, 0], [7, 0], [7, 7], [0, 7]], [2, 1, 4, 3]]], 7), [[[1, 2, 4], [2, 2, 4]]])
    check('explicit case 6', solve([[[[0, 0], [1, 4], [2, 0], [3, 4], [4, 0], [4, 5], [0, 5]], [0, 0, 7, 7]]], 7), [[[2, 0, 1], [2, 1, 3], [2, 3, 4], [3, 0, 1], [3, 1, 3], [3, 3, 4], [4, 0, 4]]])
    check('explicit case 7', solve([[[[-2, 0], [9, 0], [9, 2], [-2, 2]], [0, 0, 7, 7]]], 7), [[[0, 0, 7], [1, 0, 7]]])
    check('explicit case 8', solve([[[[0, 0], [2, 0], [2, 2], [0, 2]], [3, 0, 7, 7]]], 7), [[]])
    check('explicit case 9', solve([[[[1, 0], [5, 4], [1, 4]], [0, 0, 7, 7]]], 7), [[[1, 1, 2], [2, 1, 3], [3, 1, 4]]])
    check('explicit case 10', solve([[[['1/4', 0], ['5/2', 0], ['5/2', 2], ['1/4', 2]], [1, 0, 7, 7]]], 7), [[[0, 1, 2], [1, 1, 2]]])
    check('explicit case 11', solve([[[[4, 1], [4, 4], [1, 4], [1, 1]], [0, 0, 7, 7]]], 7), [[[1, 1, 4], [2, 1, 4], [3, 1, 4]]])
    check('explicit case 12', solve([[[[0, 0], [5, 0], [5, 4], [3, '3/2'], [1, 4], [0, 4]], [0, 0, 7, 7]]], 7), [[[0, 0, 5], [1, 0, 3], [1, 3, 5], [2, 0, 2], [2, 4, 5], [3, 0, 1]]])
if N == 3:
    check('explicit case 0', solve([[[[1, 1], [7, 1], [7, 7], [1, 7]], [0, 0, 8, 8]]], 8), [[[1, 1, 7], [2, 1, 7], [3, 1, 7], [4, 1, 7], [5, 1, 7], [6, 1, 7]]])
    check('explicit case 1', solve([[[[1, 0], [3, '5/2'], [5, 0], [5, 5], [1, 5]], [0, 0, 8, 8]]], 8), [[[1, 1, 2], [1, 4, 5], [2, 1, 5], [3, 1, 5], [4, 1, 5]]])
    check('explicit case 2', solve([[[[0, '1/2'], [4, '5/2'], [0, '9/2']], [0, 0, 8, 8]]], 8), [[[1, 0, 2], [2, 0, 4], [3, 0, 2]]])
    check('explicit case 3', solve([[[['1/2', 0], ['7/2', 0], ['7/2', 3], ['1/2', 3]], [0, 0, 8, 8]]], 8), [[[0, 0, 3], [1, 0, 3], [2, 0, 3]]])
    check('explicit case 4', solve([[[['3/2', 0], ['9/2', 0], ['9/2', 2], ['3/2', 2]], [0, 0, 8, 8]]], 8), [[[0, 1, 4], [1, 1, 4]]])
    check('explicit case 5', solve([[[[0, 0], [8, 0], [8, 8], [0, 8]], [2, 1, 4, 3]]], 8), [[[1, 2, 4], [2, 2, 4]]])
    check('explicit case 6', solve([[[[0, 0], [1, 4], [2, 0], [3, 4], [4, 0], [4, 5], [0, 5]], [0, 0, 8, 8]]], 8), [[[2, 0, 1], [2, 1, 3], [2, 3, 4], [3, 0, 1], [3, 1, 3], [3, 3, 4], [4, 0, 4]]])
    check('explicit case 7', solve([[[[-2, 0], [10, 0], [10, 2], [-2, 2]], [0, 0, 8, 8]]], 8), [[[0, 0, 8], [1, 0, 8]]])
    check('explicit case 8', solve([[[[0, 0], [2, 0], [2, 2], [0, 2]], [3, 0, 8, 8]]], 8), [[]])
    check('explicit case 9', solve([[[[1, 0], [5, 4], [1, 4]], [0, 0, 8, 8]]], 8), [[[1, 1, 2], [2, 1, 3], [3, 1, 4]]])
    check('explicit case 10', solve([[[['1/4', 0], ['5/2', 0], ['5/2', 2], ['1/4', 2]], [1, 0, 8, 8]]], 8), [[[0, 1, 2], [1, 1, 2]]])
    check('explicit case 11', solve([[[[4, 1], [4, 4], [1, 4], [1, 1]], [0, 0, 8, 8]]], 8), [[[1, 1, 4], [2, 1, 4], [3, 1, 4]]])
    check('explicit case 12', solve([[[[0, 0], [5, 0], [5, 4], [3, '3/2'], [1, 4], [0, 4]], [0, 0, 8, 8]]], 8), [[[0, 0, 5], [1, 0, 3], [1, 3, 5], [2, 0, 2], [2, 4, 5], [3, 0, 1]]])
if N == 4:
    check('explicit case 0', solve([[[[1, 1], [8, 1], [8, 8], [1, 8]], [0, 0, 9, 9]]], 9), [[[1, 1, 8], [2, 1, 8], [3, 1, 8], [4, 1, 8], [5, 1, 8], [6, 1, 8], [7, 1, 8]]])
    check('explicit case 1', solve([[[[1, 0], [3, '5/2'], [5, 0], [5, 5], [1, 5]], [0, 0, 9, 9]]], 9), [[[1, 1, 2], [1, 4, 5], [2, 1, 5], [3, 1, 5], [4, 1, 5]]])
    check('explicit case 2', solve([[[[0, '1/2'], [4, '5/2'], [0, '9/2']], [0, 0, 9, 9]]], 9), [[[1, 0, 2], [2, 0, 4], [3, 0, 2]]])
    check('explicit case 3', solve([[[['1/2', 0], ['7/2', 0], ['7/2', 3], ['1/2', 3]], [0, 0, 9, 9]]], 9), [[[0, 0, 3], [1, 0, 3], [2, 0, 3]]])
    check('explicit case 4', solve([[[['3/2', 0], ['9/2', 0], ['9/2', 2], ['3/2', 2]], [0, 0, 9, 9]]], 9), [[[0, 1, 4], [1, 1, 4]]])
    check('explicit case 5', solve([[[[0, 0], [9, 0], [9, 9], [0, 9]], [2, 1, 4, 3]]], 9), [[[1, 2, 4], [2, 2, 4]]])
    check('explicit case 6', solve([[[[0, 0], [1, 4], [2, 0], [3, 4], [4, 0], [4, 5], [0, 5]], [0, 0, 9, 9]]], 9), [[[2, 0, 1], [2, 1, 3], [2, 3, 4], [3, 0, 1], [3, 1, 3], [3, 3, 4], [4, 0, 4]]])
    check('explicit case 7', solve([[[[-2, 0], [11, 0], [11, 2], [-2, 2]], [0, 0, 9, 9]]], 9), [[[0, 0, 9], [1, 0, 9]]])
    check('explicit case 8', solve([[[[0, 0], [2, 0], [2, 2], [0, 2]], [3, 0, 9, 9]]], 9), [[]])
    check('explicit case 9', solve([[[[1, 0], [5, 4], [1, 4]], [0, 0, 9, 9]]], 9), [[[1, 1, 2], [2, 1, 3], [3, 1, 4]]])
    check('explicit case 10', solve([[[['1/4', 0], ['5/2', 0], ['5/2', 2], ['1/4', 2]], [1, 0, 9, 9]]], 9), [[[0, 1, 2], [1, 1, 2]]])
    check('explicit case 11', solve([[[[4, 1], [4, 4], [1, 4], [1, 1]], [0, 0, 9, 9]]], 9), [[[1, 1, 4], [2, 1, 4], [3, 1, 4]]])
    check('explicit case 12', solve([[[[0, 0], [5, 0], [5, 4], [3, '3/2'], [1, 4], [0, 4]], [0, 0, 9, 9]]], 9), [[[0, 0, 5], [1, 0, 3], [1, 3, 5], [2, 0, 2], [2, 4, 5], [3, 0, 1]]])
if N == 5:
    check('explicit case 0', solve([[[[1, 1], [9, 1], [9, 9], [1, 9]], [0, 0, 10, 10]]], 10), [[[1, 1, 9], [2, 1, 9], [3, 1, 9], [4, 1, 9], [5, 1, 9], [6, 1, 9], [7, 1, 9], [8, 1, 9]]])
    check('explicit case 1', solve([[[[1, 0], [3, '5/2'], [5, 0], [5, 5], [1, 5]], [0, 0, 10, 10]]], 10), [[[1, 1, 2], [1, 4, 5], [2, 1, 5], [3, 1, 5], [4, 1, 5]]])
    check('explicit case 2', solve([[[[0, '1/2'], [4, '5/2'], [0, '9/2']], [0, 0, 10, 10]]], 10), [[[1, 0, 2], [2, 0, 4], [3, 0, 2]]])
    check('explicit case 3', solve([[[['1/2', 0], ['7/2', 0], ['7/2', 3], ['1/2', 3]], [0, 0, 10, 10]]], 10), [[[0, 0, 3], [1, 0, 3], [2, 0, 3]]])
    check('explicit case 4', solve([[[['3/2', 0], ['9/2', 0], ['9/2', 2], ['3/2', 2]], [0, 0, 10, 10]]], 10), [[[0, 1, 4], [1, 1, 4]]])
    check('explicit case 5', solve([[[[0, 0], [10, 0], [10, 10], [0, 10]], [2, 1, 4, 3]]], 10), [[[1, 2, 4], [2, 2, 4]]])
    check('explicit case 6', solve([[[[0, 0], [1, 4], [2, 0], [3, 4], [4, 0], [4, 5], [0, 5]], [0, 0, 10, 10]]], 10), [[[2, 0, 1], [2, 1, 3], [2, 3, 4], [3, 0, 1], [3, 1, 3], [3, 3, 4], [4, 0, 4]]])
    check('explicit case 7', solve([[[[-2, 0], [12, 0], [12, 2], [-2, 2]], [0, 0, 10, 10]]], 10), [[[0, 0, 10], [1, 0, 10]]])
    check('explicit case 8', solve([[[[0, 0], [2, 0], [2, 2], [0, 2]], [3, 0, 10, 10]]], 10), [[]])
    check('explicit case 9', solve([[[[1, 0], [5, 4], [1, 4]], [0, 0, 10, 10]]], 10), [[[1, 1, 2], [2, 1, 3], [3, 1, 4]]])
    check('explicit case 10', solve([[[['1/4', 0], ['5/2', 0], ['5/2', 2], ['1/4', 2]], [1, 0, 10, 10]]], 10), [[[0, 1, 2], [1, 1, 2]]])
    check('explicit case 11', solve([[[[4, 1], [4, 4], [1, 4], [1, 1]], [0, 0, 10, 10]]], 10), [[[1, 1, 4], [2, 1, 4], [3, 1, 4]]])
    check('explicit case 12', solve([[[[0, 0], [5, 0], [5, 4], [3, '3/2'], [1, 4], [0, 4]], [0, 0, 10, 10]]], 10), [[[0, 0, 5], [1, 0, 3], [1, 3, 5], [2, 0, 2], [2, 4, 5], [3, 0, 1]]])
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:
Every adjacent crossing pair is filled, so holes between even-odd intervals are covered.

Each command is [polygon,scissor]. Rows y in the scissor rows [top,bottom) intersected with [0,size) are sampled at y+1/2. Each polygon edge is oriented bottom to top and contributes a crossing when top<=yc<bottom (half-open in y), interpolated exactly. Crossings are sorted and paired even-odd. A pair covers pixels whose centers x+1/2 satisfy xa<=x+1/2<xb, i.e. [ceil(xa-1/2),ceil(xb-1/2)), then clipped to the scissor columns [left,right) intersected with [0,size). Non-empty spans are returned as [row,start,end].

split: open-access


prompt:
All raster rows are scanned regardless of the scissor top and bottom.

Each command is [polygon,scissor]. Rows y in the scissor rows [top,bottom) intersected with [0,size) are sampled at y+1/2. Each polygon edge is oriented bottom to top and contributes a crossing when top<=yc<bottom (half-open in y), interpolated exactly. Crossings are sorted and paired even-odd. A pair covers pixels whose centers x+1/2 satisfy xa<=x+1/2<xb, i.e. [ceil(xa-1/2),ceil(xb-1/2)), then clipped to the scissor columns [left,right) intersected with [0,size). Non-empty spans are returned as [row,start,end].

split: open-access


prompt:
Left-clipped lines start with the unclipped origin row, shifting every visible pixel vertically.

Each command is [x0,y0,x1,y1,scissor] for an x-major integer line with x0<=x1 and |y1-y0|<=x1-x0 (a zero-length line is a single point). The reference pixel in column x is y0+floor((2*(y1-y0)*(x-x0)+dx)/(2*dx)), ties rounding up. Clipping to the half-open scissor [left,top,right,bottom) intersected with [0,size) must emit exactly the reference pixels inside it, in x order. The walk starts at the first visible column with an exact pre-stepped error term and may stop once y has left the scissor in the direction of travel.

split: open-access


prompt:
The error term omits the half-pixel bias, so reference rows are floored instead of rounded.

Each command is [x0,y0,x1,y1,scissor] for an x-major integer line with x0<=x1 and |y1-y0|<=x1-x0 (a zero-length line is a single point). The reference pixel in column x is y0+floor((2*(y1-y0)*(x-x0)+dx)/(2*dx)), ties rounding up. Clipping to the half-open scissor [left,top,right,bottom) intersected with [0,size) must emit exactly the reference pixels inside it, in x order. The walk starts at the first visible column with an exact pre-stepped error term and may stop once y has left the scissor in the direction of travel.

split: open-access


prompt:
Pre-stepping a descending line truncates toward zero while the error keeps a floored remainder, desynchronising row and error.

Each command is [x0,y0,x1,y1,scissor] for an x-major integer line with x0<=x1 and |y1-y0|<=x1-x0 (a zero-length line is a single point). The reference pixel in column x is y0+floor((2*(y1-y0)*(x-x0)+dx)/(2*dx)), ties rounding up. Clipping to the half-open scissor [left,top,right,bottom) intersected with [0,size) must emit exactly the reference pixels inside it, in x order. The walk starts at the first visible column with an exact pre-stepped error term and may stop once y has left the scissor in the direction of travel.

split: open-access


prompt:
The walk includes the column equal to the half-open scissor right edge.

Each command is [x0,y0,x1,y1,scissor] for an x-major integer line with x0<=x1 and |y1-y0|<=x1-x0 (a zero-length line is a single point). The reference pixel in column x is y0+floor((2*(y1-y0)*(x-x0)+dx)/(2*dx)), ties rounding up. Clipping to the half-open scissor [left,top,right,bottom) intersected with [0,size) must emit exactly the reference pixels inside it, in x order. The walk starts at the first visible column with an exact pre-stepped error term and may stop once y has left the scissor in the direction of travel.

split: open-access


prompt:
The walk always starts at the scissor left edge, emitting pixels before the line begins.

Each command is [x0,y0,x1,y1,scissor] for an x-major integer line with x0<=x1 and |y1-y0|<=x1-x0 (a zero-length line is a single point). The reference pixel in column x is y0+floor((2*(y1-y0)*(x-x0)+dx)/(2*dx)), ties rounding up. Clipping to the half-open scissor [left,top,right,bottom) intersected with [0,size) must emit exactly the reference pixels inside it, in x order. The walk starts at the first visible column with an exact pre-stepped error term and may stop once y has left the scissor in the direction of travel.

split: open-access


prompt:
Zero-length lines bypass scissor testing.

Each command is [x0,y0,x1,y1,scissor] for an x-major integer line with x0<=x1 and |y1-y0|<=x1-x0 (a zero-length line is a single point). The reference pixel in column x is y0+floor((2*(y1-y0)*(x-x0)+dx)/(2*dx)), ties rounding up. Clipping to the half-open scissor [left,top,right,bottom) intersected with [0,size) must emit exactly the reference pixels inside it, in x order. The walk starts at the first visible column with an exact pre-stepped error term and may stop once y has left the scissor in the direction of travel.

split: open-access


prompt:
The walk stops whenever y is outside the scissor, even before a line travelling toward the scissor has entered it.

Each command is [x0,y0,x1,y1,scissor] for an x-major integer line with x0<=x1 and |y1-y0|<=x1-x0 (a zero-length line is a single point). The reference pixel in column x is y0+floor((2*(y1-y0)*(x-x0)+dx)/(2*dx)), ties rounding up. Clipping to the half-open scissor [left,top,right,bottom) intersected with [0,size) must emit exactly the reference pixels inside it, in x order. The walk starts at the first visible column with an exact pre-stepped error term and may stop once y has left the scissor in the direction of travel.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    out=[]
    g=size
    for tri in commands:
        xs=[Fraction(v[0]) for v in tri]
        ys=[Fraction(v[1]) for v in tri]
        if all(x<0 or x>size or y<0 or y>size for x,y in zip(xs,ys)):
            out.append(['reject',None])
            continue
        if min(xs)>=0 and max(xs)<=size and min(ys)>=0 and max(ys)<=size: kind='accept'
        elif min(xs)>=-g and max(xs)<=size+g and min(ys)>=-g and max(ys)<=size+g: kind='guard'
        else:
            out.append(['clip',None])
            continue
        x0=max(math.floor(min(xs)),0)
        x1=min(math.ceil(max(xs)),size)
        y0=max(math.floor(min(ys)),0)
        y1=min(math.ceil(max(ys)),size)
        out.append([kind,[x0,y0,x1,y1] if x0<x1 and y0<y1 else None])
    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], [5, 1], [2, 5]]], 6), [['accept', [1, 1, 5, 5]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 6]]], 6), [['reject', None]])
    check('explicit case 2', solve([[[-12, -12], [24, -12], [3, 24]]], 6), [['clip', None]])
    check('explicit case 3', solve([[[6, 0], [8, 1], [7, 3]]], 6), [['guard', None]])
    check('explicit case 4', solve([[['13/2', 0], [9, 1], [7, 3]]], 6), [['reject', None]])
    check('explicit case 5', solve([[[1, -18], [2, 3], [3, 3]]], 6), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 6), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-5, 1], [2, 2], [1, 3]]], 6), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [8, 1], [2, 3]]], 6), [['guard', [1, 1, 6, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 7], [5, 2]]], 6), [['guard', [0, 1, 5, 6]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 13]]], 6), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 30]]], 6), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 6), [['reject', None]])
if N == 2:
    check('explicit case 0', solve([[[1, 1], [6, 1], [2, 6]]], 7), [['accept', [1, 1, 6, 6]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 7]]], 7), [['reject', None]])
    check('explicit case 2', solve([[[-14, -14], [28, -14], [3, 28]]], 7), [['clip', None]])
    check('explicit case 3', solve([[[7, 0], [9, 1], [8, 3]]], 7), [['guard', None]])
    check('explicit case 4', solve([[['15/2', 0], [10, 1], [8, 3]]], 7), [['reject', None]])
    check('explicit case 5', solve([[[1, -21], [2, 3], [3, 3]]], 7), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 7), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-6, 1], [2, 2], [1, 3]]], 7), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [9, 1], [2, 3]]], 7), [['guard', [1, 1, 7, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 8], [6, 2]]], 7), [['guard', [0, 1, 6, 7]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 15]]], 7), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 35]]], 7), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 7), [['reject', None]])
if N == 3:
    check('explicit case 0', solve([[[1, 1], [7, 1], [2, 7]]], 8), [['accept', [1, 1, 7, 7]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 8]]], 8), [['reject', None]])
    check('explicit case 2', solve([[[-16, -16], [32, -16], [4, 32]]], 8), [['clip', None]])
    check('explicit case 3', solve([[[8, 0], [10, 1], [9, 3]]], 8), [['guard', None]])
    check('explicit case 4', solve([[['17/2', 0], [11, 1], [9, 3]]], 8), [['reject', None]])
    check('explicit case 5', solve([[[1, -24], [2, 3], [3, 3]]], 8), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 8), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-7, 1], [2, 2], [1, 3]]], 8), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [10, 1], [2, 3]]], 8), [['guard', [1, 1, 8, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 9], [7, 2]]], 8), [['guard', [0, 1, 7, 8]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 17]]], 8), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 40]]], 8), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 8), [['reject', None]])
if N == 4:
    check('explicit case 0', solve([[[1, 1], [8, 1], [2, 8]]], 9), [['accept', [1, 1, 8, 8]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 9]]], 9), [['reject', None]])
    check('explicit case 2', solve([[[-18, -18], [36, -18], [4, 36]]], 9), [['clip', None]])
    check('explicit case 3', solve([[[9, 0], [11, 1], [10, 3]]], 9), [['guard', None]])
    check('explicit case 4', solve([[['19/2', 0], [12, 1], [10, 3]]], 9), [['reject', None]])
    check('explicit case 5', solve([[[1, -27], [2, 3], [3, 3]]], 9), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 9), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-8, 1], [2, 2], [1, 3]]], 9), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [11, 1], [2, 3]]], 9), [['guard', [1, 1, 9, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 10], [8, 2]]], 9), [['guard', [0, 1, 8, 9]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 19]]], 9), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 45]]], 9), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 9), [['reject', None]])
if N == 5:
    check('explicit case 0', solve([[[1, 1], [9, 1], [2, 9]]], 10), [['accept', [1, 1, 9, 9]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 10]]], 10), [['reject', None]])
    check('explicit case 2', solve([[[-20, -20], [40, -20], [5, 40]]], 10), [['clip', None]])
    check('explicit case 3', solve([[[10, 0], [12, 1], [11, 3]]], 10), [['guard', None]])
    check('explicit case 4', solve([[['21/2', 0], [13, 1], [11, 3]]], 10), [['reject', None]])
    check('explicit case 5', solve([[[1, -30], [2, 3], [3, 3]]], 10), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 10), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-9, 1], [2, 2], [1, 3]]], 10), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [12, 1], [2, 3]]], 10), [['guard', [1, 1, 10, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 11], [9, 2]]], 10), [['guard', [0, 1, 9, 10]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 21]]], 10), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 50]]], 10), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 10), [['reject', None]])
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
import math
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    out=[]
    g=size
    for tri in commands:
        xs=[Fraction(v[0]) for v in tri]
        ys=[Fraction(v[1]) for v in tri]
        if max(xs)<0 or min(xs)>size:
            out.append(['reject',None])
            continue
        if min(xs)>=0 and max(xs)<=size and min(ys)>=0 and max(ys)<=size: kind='accept'
        elif min(xs)>=-g and max(xs)<=size+g and min(ys)>=-g and max(ys)<=size+g: kind='guard'
        else:
            out.append(['clip',None])
            continue
        x0=max(math.floor(min(xs)),0)
        x1=min(math.ceil(max(xs)),size)
        y0=max(math.floor(min(ys)),0)
        y1=min(math.ceil(max(ys)),size)
        out.append([kind,[x0,y0,x1,y1] if x0<x1 and y0<y1 else None])
    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], [5, 1], [2, 5]]], 6), [['accept', [1, 1, 5, 5]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 6]]], 6), [['reject', None]])
    check('explicit case 2', solve([[[-12, -12], [24, -12], [3, 24]]], 6), [['clip', None]])
    check('explicit case 3', solve([[[6, 0], [8, 1], [7, 3]]], 6), [['guard', None]])
    check('explicit case 4', solve([[['13/2', 0], [9, 1], [7, 3]]], 6), [['reject', None]])
    check('explicit case 5', solve([[[1, -18], [2, 3], [3, 3]]], 6), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 6), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-5, 1], [2, 2], [1, 3]]], 6), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [8, 1], [2, 3]]], 6), [['guard', [1, 1, 6, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 7], [5, 2]]], 6), [['guard', [0, 1, 5, 6]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 13]]], 6), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 30]]], 6), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 6), [['reject', None]])
if N == 2:
    check('explicit case 0', solve([[[1, 1], [6, 1], [2, 6]]], 7), [['accept', [1, 1, 6, 6]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 7]]], 7), [['reject', None]])
    check('explicit case 2', solve([[[-14, -14], [28, -14], [3, 28]]], 7), [['clip', None]])
    check('explicit case 3', solve([[[7, 0], [9, 1], [8, 3]]], 7), [['guard', None]])
    check('explicit case 4', solve([[['15/2', 0], [10, 1], [8, 3]]], 7), [['reject', None]])
    check('explicit case 5', solve([[[1, -21], [2, 3], [3, 3]]], 7), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 7), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-6, 1], [2, 2], [1, 3]]], 7), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [9, 1], [2, 3]]], 7), [['guard', [1, 1, 7, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 8], [6, 2]]], 7), [['guard', [0, 1, 6, 7]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 15]]], 7), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 35]]], 7), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 7), [['reject', None]])
if N == 3:
    check('explicit case 0', solve([[[1, 1], [7, 1], [2, 7]]], 8), [['accept', [1, 1, 7, 7]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 8]]], 8), [['reject', None]])
    check('explicit case 2', solve([[[-16, -16], [32, -16], [4, 32]]], 8), [['clip', None]])
    check('explicit case 3', solve([[[8, 0], [10, 1], [9, 3]]], 8), [['guard', None]])
    check('explicit case 4', solve([[['17/2', 0], [11, 1], [9, 3]]], 8), [['reject', None]])
    check('explicit case 5', solve([[[1, -24], [2, 3], [3, 3]]], 8), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 8), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-7, 1], [2, 2], [1, 3]]], 8), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [10, 1], [2, 3]]], 8), [['guard', [1, 1, 8, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 9], [7, 2]]], 8), [['guard', [0, 1, 7, 8]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 17]]], 8), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 40]]], 8), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 8), [['reject', None]])
if N == 4:
    check('explicit case 0', solve([[[1, 1], [8, 1], [2, 8]]], 9), [['accept', [1, 1, 8, 8]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 9]]], 9), [['reject', None]])
    check('explicit case 2', solve([[[-18, -18], [36, -18], [4, 36]]], 9), [['clip', None]])
    check('explicit case 3', solve([[[9, 0], [11, 1], [10, 3]]], 9), [['guard', None]])
    check('explicit case 4', solve([[['19/2', 0], [12, 1], [10, 3]]], 9), [['reject', None]])
    check('explicit case 5', solve([[[1, -27], [2, 3], [3, 3]]], 9), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 9), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-8, 1], [2, 2], [1, 3]]], 9), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [11, 1], [2, 3]]], 9), [['guard', [1, 1, 9, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 10], [8, 2]]], 9), [['guard', [0, 1, 8, 9]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 19]]], 9), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 45]]], 9), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 9), [['reject', None]])
if N == 5:
    check('explicit case 0', solve([[[1, 1], [9, 1], [2, 9]]], 10), [['accept', [1, 1, 9, 9]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 10]]], 10), [['reject', None]])
    check('explicit case 2', solve([[[-20, -20], [40, -20], [5, 40]]], 10), [['clip', None]])
    check('explicit case 3', solve([[[10, 0], [12, 1], [11, 3]]], 10), [['guard', None]])
    check('explicit case 4', solve([[['21/2', 0], [13, 1], [11, 3]]], 10), [['reject', None]])
    check('explicit case 5', solve([[[1, -30], [2, 3], [3, 3]]], 10), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 10), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-9, 1], [2, 2], [1, 3]]], 10), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [12, 1], [2, 3]]], 10), [['guard', [1, 1, 10, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 11], [9, 2]]], 10), [['guard', [0, 1, 9, 10]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 21]]], 10), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 50]]], 10), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 10), [['reject', None]])
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:
Triangles are rejected when every vertex is outside some edge, discarding large triangles that cover the viewport.

Each command is a triangle of three exact vertices in continuous raster coordinates. The viewport is [0,size]x[0,size] and the guard band extends one viewport size beyond each side. A triangle is rejected when all vertices lie strictly beyond the same viewport edge; accepted when all vertices are inside the closed viewport; guard-banded when all vertices are inside the closed guard band; otherwise it requires geometric clipping. Accepted and guard-banded triangles report the pixel bounding box [floor(min x),floor(min y),ceil(max x),ceil(max y)) clamped to the viewport, or None if empty.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    out=[]
    g=size
    for tri in commands:
        xs=[Fraction(v[0]) for v in tri]
        ys=[Fraction(v[1]) for v in tri]
        if max(xs)<0 or min(xs)>=size or max(ys)<0 or min(ys)>size:
            out.append(['reject',None])
            continue
        if min(xs)>=0 and max(xs)<=size and min(ys)>=0 and max(ys)<=size: kind='accept'
        elif min(xs)>=-g and max(xs)<=size+g and min(ys)>=-g and max(ys)<=size+g: kind='guard'
        else:
            out.append(['clip',None])
            continue
        x0=max(math.floor(min(xs)),0)
        x1=min(math.ceil(max(xs)),size)
        y0=max(math.floor(min(ys)),0)
        y1=min(math.ceil(max(ys)),size)
        out.append([kind,[x0,y0,x1,y1] if x0<x1 and y0<y1 else None])
    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], [5, 1], [2, 5]]], 6), [['accept', [1, 1, 5, 5]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 6]]], 6), [['reject', None]])
    check('explicit case 2', solve([[[-12, -12], [24, -12], [3, 24]]], 6), [['clip', None]])
    check('explicit case 3', solve([[[6, 0], [8, 1], [7, 3]]], 6), [['guard', None]])
    check('explicit case 4', solve([[['13/2', 0], [9, 1], [7, 3]]], 6), [['reject', None]])
    check('explicit case 5', solve([[[1, -18], [2, 3], [3, 3]]], 6), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 6), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-5, 1], [2, 2], [1, 3]]], 6), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [8, 1], [2, 3]]], 6), [['guard', [1, 1, 6, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 7], [5, 2]]], 6), [['guard', [0, 1, 5, 6]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 13]]], 6), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 30]]], 6), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 6), [['reject', None]])
if N == 2:
    check('explicit case 0', solve([[[1, 1], [6, 1], [2, 6]]], 7), [['accept', [1, 1, 6, 6]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 7]]], 7), [['reject', None]])
    check('explicit case 2', solve([[[-14, -14], [28, -14], [3, 28]]], 7), [['clip', None]])
    check('explicit case 3', solve([[[7, 0], [9, 1], [8, 3]]], 7), [['guard', None]])
    check('explicit case 4', solve([[['15/2', 0], [10, 1], [8, 3]]], 7), [['reject', None]])
    check('explicit case 5', solve([[[1, -21], [2, 3], [3, 3]]], 7), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 7), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-6, 1], [2, 2], [1, 3]]], 7), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [9, 1], [2, 3]]], 7), [['guard', [1, 1, 7, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 8], [6, 2]]], 7), [['guard', [0, 1, 6, 7]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 15]]], 7), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 35]]], 7), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 7), [['reject', None]])
if N == 3:
    check('explicit case 0', solve([[[1, 1], [7, 1], [2, 7]]], 8), [['accept', [1, 1, 7, 7]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 8]]], 8), [['reject', None]])
    check('explicit case 2', solve([[[-16, -16], [32, -16], [4, 32]]], 8), [['clip', None]])
    check('explicit case 3', solve([[[8, 0], [10, 1], [9, 3]]], 8), [['guard', None]])
    check('explicit case 4', solve([[['17/2', 0], [11, 1], [9, 3]]], 8), [['reject', None]])
    check('explicit case 5', solve([[[1, -24], [2, 3], [3, 3]]], 8), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 8), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-7, 1], [2, 2], [1, 3]]], 8), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [10, 1], [2, 3]]], 8), [['guard', [1, 1, 8, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 9], [7, 2]]], 8), [['guard', [0, 1, 7, 8]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 17]]], 8), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 40]]], 8), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 8), [['reject', None]])
if N == 4:
    check('explicit case 0', solve([[[1, 1], [8, 1], [2, 8]]], 9), [['accept', [1, 1, 8, 8]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 9]]], 9), [['reject', None]])
    check('explicit case 2', solve([[[-18, -18], [36, -18], [4, 36]]], 9), [['clip', None]])
    check('explicit case 3', solve([[[9, 0], [11, 1], [10, 3]]], 9), [['guard', None]])
    check('explicit case 4', solve([[['19/2', 0], [12, 1], [10, 3]]], 9), [['reject', None]])
    check('explicit case 5', solve([[[1, -27], [2, 3], [3, 3]]], 9), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 9), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-8, 1], [2, 2], [1, 3]]], 9), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [11, 1], [2, 3]]], 9), [['guard', [1, 1, 9, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 10], [8, 2]]], 9), [['guard', [0, 1, 8, 9]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 19]]], 9), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 45]]], 9), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 9), [['reject', None]])
if N == 5:
    check('explicit case 0', solve([[[1, 1], [9, 1], [2, 9]]], 10), [['accept', [1, 1, 9, 9]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 10]]], 10), [['reject', None]])
    check('explicit case 2', solve([[[-20, -20], [40, -20], [5, 40]]], 10), [['clip', None]])
    check('explicit case 3', solve([[[10, 0], [12, 1], [11, 3]]], 10), [['guard', None]])
    check('explicit case 4', solve([[['21/2', 0], [13, 1], [11, 3]]], 10), [['reject', None]])
    check('explicit case 5', solve([[[1, -30], [2, 3], [3, 3]]], 10), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 10), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-9, 1], [2, 2], [1, 3]]], 10), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [12, 1], [2, 3]]], 10), [['guard', [1, 1, 10, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 11], [9, 2]]], 10), [['guard', [0, 1, 9, 10]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 21]]], 10), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 50]]], 10), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 10), [['reject', None]])
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
import math
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    out=[]
    g=size
    for tri in commands:
        xs=[Fraction(v[0]) for v in tri]
        ys=[Fraction(v[1]) for v in tri]
        if max(xs)<0 or min(xs)>=size+1 or max(ys)<0 or min(ys)>size:
            out.append(['reject',None])
            continue
        if min(xs)>=0 and max(xs)<=size and min(ys)>=0 and max(ys)<=size: kind='accept'
        elif min(xs)>=-g and max(xs)<=size+g and min(ys)>=-g and max(ys)<=size+g: kind='guard'
        else:
            out.append(['clip',None])
            continue
        x0=max(math.floor(min(xs)),0)
        x1=min(math.ceil(max(xs)),size)
        y0=max(math.floor(min(ys)),0)
        y1=min(math.ceil(max(ys)),size)
        out.append([kind,[x0,y0,x1,y1] if x0<x1 and y0<y1 else None])
    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], [5, 1], [2, 5]]], 6), [['accept', [1, 1, 5, 5]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 6]]], 6), [['reject', None]])
    check('explicit case 2', solve([[[-12, -12], [24, -12], [3, 24]]], 6), [['clip', None]])
    check('explicit case 3', solve([[[6, 0], [8, 1], [7, 3]]], 6), [['guard', None]])
    check('explicit case 4', solve([[['13/2', 0], [9, 1], [7, 3]]], 6), [['reject', None]])
    check('explicit case 5', solve([[[1, -18], [2, 3], [3, 3]]], 6), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 6), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-5, 1], [2, 2], [1, 3]]], 6), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [8, 1], [2, 3]]], 6), [['guard', [1, 1, 6, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 7], [5, 2]]], 6), [['guard', [0, 1, 5, 6]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 13]]], 6), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 30]]], 6), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 6), [['reject', None]])
if N == 2:
    check('explicit case 0', solve([[[1, 1], [6, 1], [2, 6]]], 7), [['accept', [1, 1, 6, 6]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 7]]], 7), [['reject', None]])
    check('explicit case 2', solve([[[-14, -14], [28, -14], [3, 28]]], 7), [['clip', None]])
    check('explicit case 3', solve([[[7, 0], [9, 1], [8, 3]]], 7), [['guard', None]])
    check('explicit case 4', solve([[['15/2', 0], [10, 1], [8, 3]]], 7), [['reject', None]])
    check('explicit case 5', solve([[[1, -21], [2, 3], [3, 3]]], 7), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 7), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-6, 1], [2, 2], [1, 3]]], 7), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [9, 1], [2, 3]]], 7), [['guard', [1, 1, 7, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 8], [6, 2]]], 7), [['guard', [0, 1, 6, 7]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 15]]], 7), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 35]]], 7), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 7), [['reject', None]])
if N == 3:
    check('explicit case 0', solve([[[1, 1], [7, 1], [2, 7]]], 8), [['accept', [1, 1, 7, 7]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 8]]], 8), [['reject', None]])
    check('explicit case 2', solve([[[-16, -16], [32, -16], [4, 32]]], 8), [['clip', None]])
    check('explicit case 3', solve([[[8, 0], [10, 1], [9, 3]]], 8), [['guard', None]])
    check('explicit case 4', solve([[['17/2', 0], [11, 1], [9, 3]]], 8), [['reject', None]])
    check('explicit case 5', solve([[[1, -24], [2, 3], [3, 3]]], 8), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 8), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-7, 1], [2, 2], [1, 3]]], 8), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [10, 1], [2, 3]]], 8), [['guard', [1, 1, 8, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 9], [7, 2]]], 8), [['guard', [0, 1, 7, 8]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 17]]], 8), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 40]]], 8), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 8), [['reject', None]])
if N == 4:
    check('explicit case 0', solve([[[1, 1], [8, 1], [2, 8]]], 9), [['accept', [1, 1, 8, 8]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 9]]], 9), [['reject', None]])
    check('explicit case 2', solve([[[-18, -18], [36, -18], [4, 36]]], 9), [['clip', None]])
    check('explicit case 3', solve([[[9, 0], [11, 1], [10, 3]]], 9), [['guard', None]])
    check('explicit case 4', solve([[['19/2', 0], [12, 1], [10, 3]]], 9), [['reject', None]])
    check('explicit case 5', solve([[[1, -27], [2, 3], [3, 3]]], 9), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 9), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-8, 1], [2, 2], [1, 3]]], 9), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [11, 1], [2, 3]]], 9), [['guard', [1, 1, 9, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 10], [8, 2]]], 9), [['guard', [0, 1, 8, 9]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 19]]], 9), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 45]]], 9), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 9), [['reject', None]])
if N == 5:
    check('explicit case 0', solve([[[1, 1], [9, 1], [2, 9]]], 10), [['accept', [1, 1, 9, 9]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 10]]], 10), [['reject', None]])
    check('explicit case 2', solve([[[-20, -20], [40, -20], [5, 40]]], 10), [['clip', None]])
    check('explicit case 3', solve([[[10, 0], [12, 1], [11, 3]]], 10), [['guard', None]])
    check('explicit case 4', solve([[['21/2', 0], [13, 1], [11, 3]]], 10), [['reject', None]])
    check('explicit case 5', solve([[[1, -30], [2, 3], [3, 3]]], 10), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 10), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-9, 1], [2, 2], [1, 3]]], 10), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [12, 1], [2, 3]]], 10), [['guard', [1, 1, 10, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 11], [9, 2]]], 10), [['guard', [0, 1, 9, 10]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 21]]], 10), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 50]]], 10), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 10), [['reject', None]])
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:
Triangles touching the right viewport edge are rejected even though boundary points are inside.

Each command is a triangle of three exact vertices in continuous raster coordinates. The viewport is [0,size]x[0,size] and the guard band extends one viewport size beyond each side. A triangle is rejected when all vertices lie strictly beyond the same viewport edge; accepted when all vertices are inside the closed viewport; guard-banded when all vertices are inside the closed guard band; otherwise it requires geometric clipping. Accepted and guard-banded triangles report the pixel bounding box [floor(min x),floor(min y),ceil(max x),ceil(max y)) clamped to the viewport, or None if empty.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    out=[]
    g=size
    for tri in commands:
        xs=[Fraction(v[0]) for v in tri]
        ys=[Fraction(v[1]) for v in tri]
        if max(xs)<0 or min(xs)>size or max(ys)<0 or min(ys)>size:
            out.append(['reject',None])
            continue
        if min(xs)>=0 and max(xs)<=size and min(ys)>=0 and max(ys)<=size: kind='accept'
        elif min(xs)>=-g and max(xs)<=size+g: kind='guard'
        else:
            out.append(['clip',None])
            continue
        x0=max(math.floor(min(xs)),0)
        x1=min(math.ceil(max(xs)),size)
        y0=max(math.floor(min(ys)),0)
        y1=min(math.ceil(max(ys)),size)
        out.append([kind,[x0,y0,x1,y1] if x0<x1 and y0<y1 else None])
    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], [5, 1], [2, 5]]], 6), [['accept', [1, 1, 5, 5]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 6]]], 6), [['reject', None]])
    check('explicit case 2', solve([[[-12, -12], [24, -12], [3, 24]]], 6), [['clip', None]])
    check('explicit case 3', solve([[[6, 0], [8, 1], [7, 3]]], 6), [['guard', None]])
    check('explicit case 4', solve([[['13/2', 0], [9, 1], [7, 3]]], 6), [['reject', None]])
    check('explicit case 5', solve([[[1, -18], [2, 3], [3, 3]]], 6), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 6), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-5, 1], [2, 2], [1, 3]]], 6), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [8, 1], [2, 3]]], 6), [['guard', [1, 1, 6, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 7], [5, 2]]], 6), [['guard', [0, 1, 5, 6]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 13]]], 6), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 30]]], 6), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 6), [['reject', None]])
if N == 2:
    check('explicit case 0', solve([[[1, 1], [6, 1], [2, 6]]], 7), [['accept', [1, 1, 6, 6]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 7]]], 7), [['reject', None]])
    check('explicit case 2', solve([[[-14, -14], [28, -14], [3, 28]]], 7), [['clip', None]])
    check('explicit case 3', solve([[[7, 0], [9, 1], [8, 3]]], 7), [['guard', None]])
    check('explicit case 4', solve([[['15/2', 0], [10, 1], [8, 3]]], 7), [['reject', None]])
    check('explicit case 5', solve([[[1, -21], [2, 3], [3, 3]]], 7), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 7), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-6, 1], [2, 2], [1, 3]]], 7), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [9, 1], [2, 3]]], 7), [['guard', [1, 1, 7, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 8], [6, 2]]], 7), [['guard', [0, 1, 6, 7]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 15]]], 7), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 35]]], 7), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 7), [['reject', None]])
if N == 3:
    check('explicit case 0', solve([[[1, 1], [7, 1], [2, 7]]], 8), [['accept', [1, 1, 7, 7]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 8]]], 8), [['reject', None]])
    check('explicit case 2', solve([[[-16, -16], [32, -16], [4, 32]]], 8), [['clip', None]])
    check('explicit case 3', solve([[[8, 0], [10, 1], [9, 3]]], 8), [['guard', None]])
    check('explicit case 4', solve([[['17/2', 0], [11, 1], [9, 3]]], 8), [['reject', None]])
    check('explicit case 5', solve([[[1, -24], [2, 3], [3, 3]]], 8), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 8), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-7, 1], [2, 2], [1, 3]]], 8), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [10, 1], [2, 3]]], 8), [['guard', [1, 1, 8, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 9], [7, 2]]], 8), [['guard', [0, 1, 7, 8]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 17]]], 8), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 40]]], 8), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 8), [['reject', None]])
if N == 4:
    check('explicit case 0', solve([[[1, 1], [8, 1], [2, 8]]], 9), [['accept', [1, 1, 8, 8]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 9]]], 9), [['reject', None]])
    check('explicit case 2', solve([[[-18, -18], [36, -18], [4, 36]]], 9), [['clip', None]])
    check('explicit case 3', solve([[[9, 0], [11, 1], [10, 3]]], 9), [['guard', None]])
    check('explicit case 4', solve([[['19/2', 0], [12, 1], [10, 3]]], 9), [['reject', None]])
    check('explicit case 5', solve([[[1, -27], [2, 3], [3, 3]]], 9), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 9), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-8, 1], [2, 2], [1, 3]]], 9), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [11, 1], [2, 3]]], 9), [['guard', [1, 1, 9, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 10], [8, 2]]], 9), [['guard', [0, 1, 8, 9]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 19]]], 9), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 45]]], 9), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 9), [['reject', None]])
if N == 5:
    check('explicit case 0', solve([[[1, 1], [9, 1], [2, 9]]], 10), [['accept', [1, 1, 9, 9]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 10]]], 10), [['reject', None]])
    check('explicit case 2', solve([[[-20, -20], [40, -20], [5, 40]]], 10), [['clip', None]])
    check('explicit case 3', solve([[[10, 0], [12, 1], [11, 3]]], 10), [['guard', None]])
    check('explicit case 4', solve([[['21/2', 0], [13, 1], [11, 3]]], 10), [['reject', None]])
    check('explicit case 5', solve([[[1, -30], [2, 3], [3, 3]]], 10), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 10), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-9, 1], [2, 2], [1, 3]]], 10), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [12, 1], [2, 3]]], 10), [['guard', [1, 1, 10, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 11], [9, 2]]], 10), [['guard', [0, 1, 9, 10]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 21]]], 10), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 50]]], 10), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 10), [['reject', None]])
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
import math
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    out=[]
    g=size
    for tri in commands:
        xs=[Fraction(v[0]) for v in tri]
        ys=[Fraction(v[1]) for v in tri]
        if max(xs)<0 or min(xs)>size or max(ys)<0 or min(ys)>size:
            out.append(['reject',None])
            continue
        if min(xs)>=0 and max(xs)<=size and min(ys)>=0 and max(ys)<=size: kind='accept'
        elif min(xs)>=-g and max(xs)<=size+g and max(ys)<=size+g: kind='guard'
        else:
            out.append(['clip',None])
            continue
        x0=max(math.floor(min(xs)),0)
        x1=min(math.ceil(max(xs)),size)
        y0=max(math.floor(min(ys)),0)
        y1=min(math.ceil(max(ys)),size)
        out.append([kind,[x0,y0,x1,y1] if x0<x1 and y0<y1 else None])
    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], [5, 1], [2, 5]]], 6), [['accept', [1, 1, 5, 5]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 6]]], 6), [['reject', None]])
    check('explicit case 2', solve([[[-12, -12], [24, -12], [3, 24]]], 6), [['clip', None]])
    check('explicit case 3', solve([[[6, 0], [8, 1], [7, 3]]], 6), [['guard', None]])
    check('explicit case 4', solve([[['13/2', 0], [9, 1], [7, 3]]], 6), [['reject', None]])
    check('explicit case 5', solve([[[1, -18], [2, 3], [3, 3]]], 6), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 6), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-5, 1], [2, 2], [1, 3]]], 6), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [8, 1], [2, 3]]], 6), [['guard', [1, 1, 6, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 7], [5, 2]]], 6), [['guard', [0, 1, 5, 6]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 13]]], 6), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 30]]], 6), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 6), [['reject', None]])
if N == 2:
    check('explicit case 0', solve([[[1, 1], [6, 1], [2, 6]]], 7), [['accept', [1, 1, 6, 6]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 7]]], 7), [['reject', None]])
    check('explicit case 2', solve([[[-14, -14], [28, -14], [3, 28]]], 7), [['clip', None]])
    check('explicit case 3', solve([[[7, 0], [9, 1], [8, 3]]], 7), [['guard', None]])
    check('explicit case 4', solve([[['15/2', 0], [10, 1], [8, 3]]], 7), [['reject', None]])
    check('explicit case 5', solve([[[1, -21], [2, 3], [3, 3]]], 7), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 7), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-6, 1], [2, 2], [1, 3]]], 7), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [9, 1], [2, 3]]], 7), [['guard', [1, 1, 7, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 8], [6, 2]]], 7), [['guard', [0, 1, 6, 7]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 15]]], 7), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 35]]], 7), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 7), [['reject', None]])
if N == 3:
    check('explicit case 0', solve([[[1, 1], [7, 1], [2, 7]]], 8), [['accept', [1, 1, 7, 7]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 8]]], 8), [['reject', None]])
    check('explicit case 2', solve([[[-16, -16], [32, -16], [4, 32]]], 8), [['clip', None]])
    check('explicit case 3', solve([[[8, 0], [10, 1], [9, 3]]], 8), [['guard', None]])
    check('explicit case 4', solve([[['17/2', 0], [11, 1], [9, 3]]], 8), [['reject', None]])
    check('explicit case 5', solve([[[1, -24], [2, 3], [3, 3]]], 8), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 8), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-7, 1], [2, 2], [1, 3]]], 8), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [10, 1], [2, 3]]], 8), [['guard', [1, 1, 8, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 9], [7, 2]]], 8), [['guard', [0, 1, 7, 8]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 17]]], 8), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 40]]], 8), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 8), [['reject', None]])
if N == 4:
    check('explicit case 0', solve([[[1, 1], [8, 1], [2, 8]]], 9), [['accept', [1, 1, 8, 8]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 9]]], 9), [['reject', None]])
    check('explicit case 2', solve([[[-18, -18], [36, -18], [4, 36]]], 9), [['clip', None]])
    check('explicit case 3', solve([[[9, 0], [11, 1], [10, 3]]], 9), [['guard', None]])
    check('explicit case 4', solve([[['19/2', 0], [12, 1], [10, 3]]], 9), [['reject', None]])
    check('explicit case 5', solve([[[1, -27], [2, 3], [3, 3]]], 9), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 9), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-8, 1], [2, 2], [1, 3]]], 9), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [11, 1], [2, 3]]], 9), [['guard', [1, 1, 9, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 10], [8, 2]]], 9), [['guard', [0, 1, 8, 9]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 19]]], 9), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 45]]], 9), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 9), [['reject', None]])
if N == 5:
    check('explicit case 0', solve([[[1, 1], [9, 1], [2, 9]]], 10), [['accept', [1, 1, 9, 9]]])
    check('explicit case 1', solve([[[-1, -1], [-3, 2], [-2, 10]]], 10), [['reject', None]])
    check('explicit case 2', solve([[[-20, -20], [40, -20], [5, 40]]], 10), [['clip', None]])
    check('explicit case 3', solve([[[10, 0], [12, 1], [11, 3]]], 10), [['guard', None]])
    check('explicit case 4', solve([[['21/2', 0], [13, 1], [11, 3]]], 10), [['reject', None]])
    check('explicit case 5', solve([[[1, -30], [2, 3], [3, 3]]], 10), [['clip', None]])
    check('explicit case 6', solve([[[1, 1], ['5/2', 1], [2, 3]]], 10), [['accept', [1, 1, 3, 3]]])
    check('explicit case 7', solve([[[-9, 1], [2, 2], [1, 3]]], 10), [['guard', [0, 1, 2, 3]]])
    check('explicit case 8', solve([[[1, 1], [12, 1], [2, 3]]], 10), [['guard', [1, 1, 10, 3]]])
    check('explicit case 9', solve([[[-1, 1], [1, 11], [9, 2]]], 10), [['guard', [0, 1, 9, 10]]])
    check('explicit case 10', solve([[[1, 1], [3, 1], [2, 21]]], 10), [['clip', None]])
    check('explicit case 11', solve([[[1, 1], [2, 1], [2, 50]]], 10), [['clip', None]])
    check('explicit case 12', solve([[[1, -3], [3, -2], [2, -5]]], 10), [['reject', None]])
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:
Guard-band classification checks only x, so triangles far beyond the guard band vertically skip geometric clipping.

Each command is a triangle of three exact vertices in continuous raster coordinates. The viewport is [0,size]x[0,size] and the guard band extends one viewport size beyond each side. A triangle is rejected when all vertices lie strictly beyond the same viewport edge; accepted when all vertices are inside the closed viewport; guard-banded when all vertices are inside the closed guard band; otherwise it requires geometric clipping. Accepted and guard-banded triangles report the pixel bounding box [floor(min x),floor(min y),ceil(max x),ceil(max y)) clamped to the viewport, or None if empty.

split: open-access