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

N = 1
observations = []
def solve(d):
    try:
        changes=d
        state={}; order=[]
        for ident,before,after in changes:
            if ident not in state:
                state[ident]=[before,after]; order.append(ident)
            else:
                state[ident][1]=after; order.append(ident)
        return [[ident,state[ident][0],state[ident][1]] for ident in order if state[ident][0]!=state[ident][1]]
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('two updates', solve([[10, 1, 2], [10, 2, 3]]), [[10, 1, 3]])
    check('insert delete', solve([[10, None, 1], [10, 1, None]]), [])
    check('change revert', solve([[10, 1, 2], [10, 2, 1]]), [])
    check('touch order', solve([[20, 1, 2], [10, 3, 4]]), [[20, 1, 2], [10, 3, 4]])
    check('delete', solve([[10, 1, None]]), [[10, 1, None]])
    check('insert', solve([[10, None, 1]]), [[10, None, 1]])
    check('no transaction', solve([]), [])
elif N == 2:
    check('two updates', solve([[10, 2, 3], [10, 3, 4]]), [[10, 2, 4]])
    check('insert delete', solve([[10, None, 2], [10, 2, None]]), [])
    check('change revert', solve([[10, 2, 3], [10, 3, 2]]), [])
    check('touch order', solve([[20, 2, 3], [10, 4, 5]]), [[20, 2, 3], [10, 4, 5]])
    check('delete', solve([[10, 2, None]]), [[10, 2, None]])
    check('insert', solve([[10, None, 2]]), [[10, None, 2]])
    check('no transaction', solve([]), [])
elif N == 3:
    check('two updates', solve([[10, 3, 4], [10, 4, 5]]), [[10, 3, 5]])
    check('insert delete', solve([[10, None, 3], [10, 3, None]]), [])
    check('change revert', solve([[10, 3, 4], [10, 4, 3]]), [])
    check('touch order', solve([[20, 3, 4], [10, 5, 6]]), [[20, 3, 4], [10, 5, 6]])
    check('delete', solve([[10, 3, None]]), [[10, 3, None]])
    check('insert', solve([[10, None, 3]]), [[10, None, 3]])
    check('no transaction', solve([]), [])
elif N == 4:
    check('two updates', solve([[10, 4, 5], [10, 5, 6]]), [[10, 4, 6]])
    check('insert delete', solve([[10, None, 4], [10, 4, None]]), [])
    check('change revert', solve([[10, 4, 5], [10, 5, 4]]), [])
    check('touch order', solve([[20, 4, 5], [10, 6, 7]]), [[20, 4, 5], [10, 6, 7]])
    check('delete', solve([[10, 4, None]]), [[10, 4, None]])
    check('insert', solve([[10, None, 4]]), [[10, None, 4]])
    check('no transaction', solve([]), [])
elif N == 5:
    check('two updates', solve([[10, 5, 6], [10, 6, 7]]), [[10, 5, 7]])
    check('insert delete', solve([[10, None, 5], [10, 5, None]]), [])
    check('change revert', solve([[10, 5, 6], [10, 6, 5]]), [])
    check('touch order', solve([[20, 5, 6], [10, 7, 8]]), [[20, 5, 6], [10, 7, 8]])
    check('delete', solve([[10, 5, None]]), [[10, 5, None]])
    check('insert', solve([[10, None, 5]]), [[10, None, 5]])
    check('no transaction', solve([]), [])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(d):
    try:
        changes=d
        state={}; order=[]
        for ident,before,after in changes:
            if ident not in state:
                state[ident]=[before,after]; order.append(ident)
            else:
                state[ident][1]=after; order.insert(0,ident)
        return [[ident,state[ident][0],state[ident][1]] for ident in order if state[ident][0]!=state[ident][1]]
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('two updates', solve([[10, 1, 2], [10, 2, 3]]), [[10, 1, 3]])
    check('insert delete', solve([[10, None, 1], [10, 1, None]]), [])
    check('change revert', solve([[10, 1, 2], [10, 2, 1]]), [])
    check('touch order', solve([[20, 1, 2], [10, 3, 4]]), [[20, 1, 2], [10, 3, 4]])
    check('delete', solve([[10, 1, None]]), [[10, 1, None]])
    check('insert', solve([[10, None, 1]]), [[10, None, 1]])
    check('no transaction', solve([]), [])
elif N == 2:
    check('two updates', solve([[10, 2, 3], [10, 3, 4]]), [[10, 2, 4]])
    check('insert delete', solve([[10, None, 2], [10, 2, None]]), [])
    check('change revert', solve([[10, 2, 3], [10, 3, 2]]), [])
    check('touch order', solve([[20, 2, 3], [10, 4, 5]]), [[20, 2, 3], [10, 4, 5]])
    check('delete', solve([[10, 2, None]]), [[10, 2, None]])
    check('insert', solve([[10, None, 2]]), [[10, None, 2]])
    check('no transaction', solve([]), [])
elif N == 3:
    check('two updates', solve([[10, 3, 4], [10, 4, 5]]), [[10, 3, 5]])
    check('insert delete', solve([[10, None, 3], [10, 3, None]]), [])
    check('change revert', solve([[10, 3, 4], [10, 4, 3]]), [])
    check('touch order', solve([[20, 3, 4], [10, 5, 6]]), [[20, 3, 4], [10, 5, 6]])
    check('delete', solve([[10, 3, None]]), [[10, 3, None]])
    check('insert', solve([[10, None, 3]]), [[10, None, 3]])
    check('no transaction', solve([]), [])
elif N == 4:
    check('two updates', solve([[10, 4, 5], [10, 5, 6]]), [[10, 4, 6]])
    check('insert delete', solve([[10, None, 4], [10, 4, None]]), [])
    check('change revert', solve([[10, 4, 5], [10, 5, 4]]), [])
    check('touch order', solve([[20, 4, 5], [10, 6, 7]]), [[20, 4, 5], [10, 6, 7]])
    check('delete', solve([[10, 4, None]]), [[10, 4, None]])
    check('insert', solve([[10, None, 4]]), [[10, None, 4]])
    check('no transaction', solve([]), [])
elif N == 5:
    check('two updates', solve([[10, 5, 6], [10, 6, 7]]), [[10, 5, 7]])
    check('insert delete', solve([[10, None, 5], [10, 5, None]]), [])
    check('change revert', solve([[10, 5, 6], [10, 6, 5]]), [])
    check('touch order', solve([[20, 5, 6], [10, 7, 8]]), [[20, 5, 6], [10, 7, 8]])
    check('delete', solve([[10, 5, None]]), [[10, 5, None]])
    check('insert', solve([[10, None, 5]]), [[10, None, 5]])
    check('no transaction', solve([]), [])
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:
Transaction coalescing appends an output identity on every update.

Coalesce an ordered transaction of [id,before,after] changes to one net before/after per identity. Keep the first before-image and last after-image, order identities by first touch, suppress equal net states including insert-then-delete, and retain None as absence.

split: open-access


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

N = 1
observations = []
def solve(d):
    try:
        left,old,delta=d
        before=dict(old); after=dict(old)
        for key,weight in delta: after[key]=weight
        out=[]
        for ident,key,multiplicity in left:
            if key is None: continue
            was=before.get(key,0)>0; now=after.get(key,0)>0
            if was!=now: out.append([ident,multiplicity*(1 if now else -1)])
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('new right key', solve([[[10, 'a', 1]], [], [['a', 1]]]), [[10, 1]])
    check('last right removed', solve([[[10, 'a', 1]], [['a', 1]], [['a', -1]]]), [[10, -1]])
    check('right duplicate remains', solve([[[10, 'a', 1]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 1]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 1]], [['b', 1]], [['a', 1]]]), [[10, 1]])
    check('null key', solve([[[10, None, 1]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 1]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -1]])
    check('left multiplicity', solve([[[10, 'a', 2]], [], [['a', 1]]]), [[10, 2]])
elif N == 2:
    check('new right key', solve([[[10, 'a', 2]], [], [['a', 1]]]), [[10, 2]])
    check('last right removed', solve([[[10, 'a', 2]], [['a', 1]], [['a', -1]]]), [[10, -2]])
    check('right duplicate remains', solve([[[10, 'a', 2]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 2]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 2]], [['b', 1]], [['a', 1]]]), [[10, 2]])
    check('null key', solve([[[10, None, 2]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 2]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -2]])
    check('left multiplicity', solve([[[10, 'a', 3]], [], [['a', 1]]]), [[10, 3]])
elif N == 3:
    check('new right key', solve([[[10, 'a', 3]], [], [['a', 1]]]), [[10, 3]])
    check('last right removed', solve([[[10, 'a', 3]], [['a', 1]], [['a', -1]]]), [[10, -3]])
    check('right duplicate remains', solve([[[10, 'a', 3]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 3]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 3]], [['b', 1]], [['a', 1]]]), [[10, 3]])
    check('null key', solve([[[10, None, 3]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 3]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -3]])
    check('left multiplicity', solve([[[10, 'a', 4]], [], [['a', 1]]]), [[10, 4]])
elif N == 4:
    check('new right key', solve([[[10, 'a', 4]], [], [['a', 1]]]), [[10, 4]])
    check('last right removed', solve([[[10, 'a', 4]], [['a', 1]], [['a', -1]]]), [[10, -4]])
    check('right duplicate remains', solve([[[10, 'a', 4]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 4]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 4]], [['b', 1]], [['a', 1]]]), [[10, 4]])
    check('null key', solve([[[10, None, 4]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 4]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -4]])
    check('left multiplicity', solve([[[10, 'a', 5]], [], [['a', 1]]]), [[10, 5]])
elif N == 5:
    check('new right key', solve([[[10, 'a', 5]], [], [['a', 1]]]), [[10, 5]])
    check('last right removed', solve([[[10, 'a', 5]], [['a', 1]], [['a', -1]]]), [[10, -5]])
    check('right duplicate remains', solve([[[10, 'a', 5]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 5]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 5]], [['b', 1]], [['a', 1]]]), [[10, 5]])
    check('null key', solve([[[10, None, 5]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 5]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -5]])
    check('left multiplicity', solve([[[10, 'a', 6]], [], [['a', 1]]]), [[10, 6]])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

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

N = 1
observations = []
def solve(d):
    try:
        left,old,delta=d
        before=dict(old); after=dict(old)
        for key,weight in delta: after[key]=before.get(key,0)+weight
        out=[]
        for ident,key,multiplicity in left:
            if key is None: continue
            was=before.get(key,0)>0; now=after.get(key,0)>0
            if was!=now: out.append([ident,multiplicity*(1 if now else -1)])
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('new right key', solve([[[10, 'a', 1]], [], [['a', 1]]]), [[10, 1]])
    check('last right removed', solve([[[10, 'a', 1]], [['a', 1]], [['a', -1]]]), [[10, -1]])
    check('right duplicate remains', solve([[[10, 'a', 1]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 1]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 1]], [['b', 1]], [['a', 1]]]), [[10, 1]])
    check('null key', solve([[[10, None, 1]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 1]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -1]])
    check('left multiplicity', solve([[[10, 'a', 2]], [], [['a', 1]]]), [[10, 2]])
elif N == 2:
    check('new right key', solve([[[10, 'a', 2]], [], [['a', 1]]]), [[10, 2]])
    check('last right removed', solve([[[10, 'a', 2]], [['a', 1]], [['a', -1]]]), [[10, -2]])
    check('right duplicate remains', solve([[[10, 'a', 2]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 2]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 2]], [['b', 1]], [['a', 1]]]), [[10, 2]])
    check('null key', solve([[[10, None, 2]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 2]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -2]])
    check('left multiplicity', solve([[[10, 'a', 3]], [], [['a', 1]]]), [[10, 3]])
elif N == 3:
    check('new right key', solve([[[10, 'a', 3]], [], [['a', 1]]]), [[10, 3]])
    check('last right removed', solve([[[10, 'a', 3]], [['a', 1]], [['a', -1]]]), [[10, -3]])
    check('right duplicate remains', solve([[[10, 'a', 3]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 3]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 3]], [['b', 1]], [['a', 1]]]), [[10, 3]])
    check('null key', solve([[[10, None, 3]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 3]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -3]])
    check('left multiplicity', solve([[[10, 'a', 4]], [], [['a', 1]]]), [[10, 4]])
elif N == 4:
    check('new right key', solve([[[10, 'a', 4]], [], [['a', 1]]]), [[10, 4]])
    check('last right removed', solve([[[10, 'a', 4]], [['a', 1]], [['a', -1]]]), [[10, -4]])
    check('right duplicate remains', solve([[[10, 'a', 4]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 4]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 4]], [['b', 1]], [['a', 1]]]), [[10, 4]])
    check('null key', solve([[[10, None, 4]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 4]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -4]])
    check('left multiplicity', solve([[[10, 'a', 5]], [], [['a', 1]]]), [[10, 5]])
elif N == 5:
    check('new right key', solve([[[10, 'a', 5]], [], [['a', 1]]]), [[10, 5]])
    check('last right removed', solve([[[10, 'a', 5]], [['a', 1]], [['a', -1]]]), [[10, -5]])
    check('right duplicate remains', solve([[[10, 'a', 5]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 5]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 5]], [['b', 1]], [['a', 1]]]), [[10, 5]])
    check('null key', solve([[[10, None, 5]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 5]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -5]])
    check('left multiplicity', solve([[[10, 'a', 6]], [], [['a', 1]]]), [[10, 6]])
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:
Membership maintenance overwrites repeated right-key deltas.

For a fixed left bag [id,key,multiplicity], apply a right-key count delta batch and emit signed left rows only when right membership crosses zero. Null keys never match. Emit [id,signed-left-multiplicity] in left order; duplicate right updates consolidate before crossing detection.

split: open-access


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

N = 1
observations = []
def solve(d):
    try:
        left,old,delta=d
        before=dict(old); after=dict(old)
        for key,weight in delta: after[key]=after.get(key,0)+weight
        out=[]
        for ident,key,multiplicity in left:
            if key is None: continue
            was=before.get(key,0)>0; now=after.get(key,0)>0
            if was!=now: out.append([ident,1 if now else -1])
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('new right key', solve([[[10, 'a', 1]], [], [['a', 1]]]), [[10, 1]])
    check('last right removed', solve([[[10, 'a', 1]], [['a', 1]], [['a', -1]]]), [[10, -1]])
    check('right duplicate remains', solve([[[10, 'a', 1]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 1]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 1]], [['b', 1]], [['a', 1]]]), [[10, 1]])
    check('null key', solve([[[10, None, 1]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 1]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -1]])
    check('left multiplicity', solve([[[10, 'a', 2]], [], [['a', 1]]]), [[10, 2]])
elif N == 2:
    check('new right key', solve([[[10, 'a', 2]], [], [['a', 1]]]), [[10, 2]])
    check('last right removed', solve([[[10, 'a', 2]], [['a', 1]], [['a', -1]]]), [[10, -2]])
    check('right duplicate remains', solve([[[10, 'a', 2]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 2]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 2]], [['b', 1]], [['a', 1]]]), [[10, 2]])
    check('null key', solve([[[10, None, 2]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 2]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -2]])
    check('left multiplicity', solve([[[10, 'a', 3]], [], [['a', 1]]]), [[10, 3]])
elif N == 3:
    check('new right key', solve([[[10, 'a', 3]], [], [['a', 1]]]), [[10, 3]])
    check('last right removed', solve([[[10, 'a', 3]], [['a', 1]], [['a', -1]]]), [[10, -3]])
    check('right duplicate remains', solve([[[10, 'a', 3]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 3]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 3]], [['b', 1]], [['a', 1]]]), [[10, 3]])
    check('null key', solve([[[10, None, 3]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 3]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -3]])
    check('left multiplicity', solve([[[10, 'a', 4]], [], [['a', 1]]]), [[10, 4]])
elif N == 4:
    check('new right key', solve([[[10, 'a', 4]], [], [['a', 1]]]), [[10, 4]])
    check('last right removed', solve([[[10, 'a', 4]], [['a', 1]], [['a', -1]]]), [[10, -4]])
    check('right duplicate remains', solve([[[10, 'a', 4]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 4]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 4]], [['b', 1]], [['a', 1]]]), [[10, 4]])
    check('null key', solve([[[10, None, 4]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 4]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -4]])
    check('left multiplicity', solve([[[10, 'a', 5]], [], [['a', 1]]]), [[10, 5]])
elif N == 5:
    check('new right key', solve([[[10, 'a', 5]], [], [['a', 1]]]), [[10, 5]])
    check('last right removed', solve([[[10, 'a', 5]], [['a', 1]], [['a', -1]]]), [[10, -5]])
    check('right duplicate remains', solve([[[10, 'a', 5]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 5]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 5]], [['b', 1]], [['a', 1]]]), [[10, 5]])
    check('null key', solve([[[10, None, 5]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 5]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -5]])
    check('left multiplicity', solve([[[10, 'a', 6]], [], [['a', 1]]]), [[10, 6]])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(d):
    try:
        left,old,delta=d
        before=dict(old); after=dict(old)
        for key,weight in delta: after[key]=after.get(key,0)+weight
        out=[]
        for ident,key,multiplicity in left:
            if key is None: continue
            was=before.get(key,0)>0; now=after.get(key,0)>0
            if was!=now: out.append([ident,min(multiplicity,1)*(1 if now else -1)])
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('new right key', solve([[[10, 'a', 1]], [], [['a', 1]]]), [[10, 1]])
    check('last right removed', solve([[[10, 'a', 1]], [['a', 1]], [['a', -1]]]), [[10, -1]])
    check('right duplicate remains', solve([[[10, 'a', 1]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 1]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 1]], [['b', 1]], [['a', 1]]]), [[10, 1]])
    check('null key', solve([[[10, None, 1]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 1]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -1]])
    check('left multiplicity', solve([[[10, 'a', 2]], [], [['a', 1]]]), [[10, 2]])
elif N == 2:
    check('new right key', solve([[[10, 'a', 2]], [], [['a', 1]]]), [[10, 2]])
    check('last right removed', solve([[[10, 'a', 2]], [['a', 1]], [['a', -1]]]), [[10, -2]])
    check('right duplicate remains', solve([[[10, 'a', 2]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 2]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 2]], [['b', 1]], [['a', 1]]]), [[10, 2]])
    check('null key', solve([[[10, None, 2]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 2]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -2]])
    check('left multiplicity', solve([[[10, 'a', 3]], [], [['a', 1]]]), [[10, 3]])
elif N == 3:
    check('new right key', solve([[[10, 'a', 3]], [], [['a', 1]]]), [[10, 3]])
    check('last right removed', solve([[[10, 'a', 3]], [['a', 1]], [['a', -1]]]), [[10, -3]])
    check('right duplicate remains', solve([[[10, 'a', 3]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 3]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 3]], [['b', 1]], [['a', 1]]]), [[10, 3]])
    check('null key', solve([[[10, None, 3]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 3]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -3]])
    check('left multiplicity', solve([[[10, 'a', 4]], [], [['a', 1]]]), [[10, 4]])
elif N == 4:
    check('new right key', solve([[[10, 'a', 4]], [], [['a', 1]]]), [[10, 4]])
    check('last right removed', solve([[[10, 'a', 4]], [['a', 1]], [['a', -1]]]), [[10, -4]])
    check('right duplicate remains', solve([[[10, 'a', 4]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 4]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 4]], [['b', 1]], [['a', 1]]]), [[10, 4]])
    check('null key', solve([[[10, None, 4]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 4]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -4]])
    check('left multiplicity', solve([[[10, 'a', 5]], [], [['a', 1]]]), [[10, 5]])
elif N == 5:
    check('new right key', solve([[[10, 'a', 5]], [], [['a', 1]]]), [[10, 5]])
    check('last right removed', solve([[[10, 'a', 5]], [['a', 1]], [['a', -1]]]), [[10, -5]])
    check('right duplicate remains', solve([[[10, 'a', 5]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 5]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 5]], [['b', 1]], [['a', 1]]]), [[10, 5]])
    check('null key', solve([[[10, None, 5]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 5]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -5]])
    check('left multiplicity', solve([[[10, 'a', 6]], [], [['a', 1]]]), [[10, 6]])
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:
Membership crossings emit one row regardless of left multiplicity.

For a fixed left bag [id,key,multiplicity], apply a right-key count delta batch and emit signed left rows only when right membership crosses zero. Null keys never match. Emit [id,signed-left-multiplicity] in left order; duplicate right updates consolidate before crossing detection.

split: open-access


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

N = 1
observations = []
def solve(d):
    try:
        left,old,delta=d
        before=dict(old); after=dict(old)
        for key,weight in delta: after[key]=after.get(key,0)+weight
        out=[]
        for ident,key,multiplicity in left:
            if key is None: continue
            was=before.get(key,0)>0; now=after.get(key,0)>0
            if before.get(key,0)!=after.get(key,0): out.append([ident,multiplicity*(after.get(key,0)-before.get(key,0))])
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('new right key', solve([[[10, 'a', 1]], [], [['a', 1]]]), [[10, 1]])
    check('last right removed', solve([[[10, 'a', 1]], [['a', 1]], [['a', -1]]]), [[10, -1]])
    check('right duplicate remains', solve([[[10, 'a', 1]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 1]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 1]], [['b', 1]], [['a', 1]]]), [[10, 1]])
    check('null key', solve([[[10, None, 1]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 1]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -1]])
    check('left multiplicity', solve([[[10, 'a', 2]], [], [['a', 1]]]), [[10, 2]])
elif N == 2:
    check('new right key', solve([[[10, 'a', 2]], [], [['a', 1]]]), [[10, 2]])
    check('last right removed', solve([[[10, 'a', 2]], [['a', 1]], [['a', -1]]]), [[10, -2]])
    check('right duplicate remains', solve([[[10, 'a', 2]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 2]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 2]], [['b', 1]], [['a', 1]]]), [[10, 2]])
    check('null key', solve([[[10, None, 2]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 2]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -2]])
    check('left multiplicity', solve([[[10, 'a', 3]], [], [['a', 1]]]), [[10, 3]])
elif N == 3:
    check('new right key', solve([[[10, 'a', 3]], [], [['a', 1]]]), [[10, 3]])
    check('last right removed', solve([[[10, 'a', 3]], [['a', 1]], [['a', -1]]]), [[10, -3]])
    check('right duplicate remains', solve([[[10, 'a', 3]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 3]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 3]], [['b', 1]], [['a', 1]]]), [[10, 3]])
    check('null key', solve([[[10, None, 3]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 3]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -3]])
    check('left multiplicity', solve([[[10, 'a', 4]], [], [['a', 1]]]), [[10, 4]])
elif N == 4:
    check('new right key', solve([[[10, 'a', 4]], [], [['a', 1]]]), [[10, 4]])
    check('last right removed', solve([[[10, 'a', 4]], [['a', 1]], [['a', -1]]]), [[10, -4]])
    check('right duplicate remains', solve([[[10, 'a', 4]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 4]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 4]], [['b', 1]], [['a', 1]]]), [[10, 4]])
    check('null key', solve([[[10, None, 4]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 4]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -4]])
    check('left multiplicity', solve([[[10, 'a', 5]], [], [['a', 1]]]), [[10, 5]])
elif N == 5:
    check('new right key', solve([[[10, 'a', 5]], [], [['a', 1]]]), [[10, 5]])
    check('last right removed', solve([[[10, 'a', 5]], [['a', 1]], [['a', -1]]]), [[10, -5]])
    check('right duplicate remains', solve([[[10, 'a', 5]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 5]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 5]], [['b', 1]], [['a', 1]]]), [[10, 5]])
    check('null key', solve([[[10, None, 5]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 5]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -5]])
    check('left multiplicity', solve([[[10, 'a', 6]], [], [['a', 1]]]), [[10, 6]])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(d):
    try:
        left,old,delta=d
        before=dict(old); after=dict(old)
        for key,weight in delta: after[key]=after.get(key,0)+weight
        out=[]
        for ident,key,multiplicity in left:
            if key is None: continue
            was=before.get(key,0)>0; now=after.get(key,0)>0
            if now: out.append([ident,multiplicity])
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('new right key', solve([[[10, 'a', 1]], [], [['a', 1]]]), [[10, 1]])
    check('last right removed', solve([[[10, 'a', 1]], [['a', 1]], [['a', -1]]]), [[10, -1]])
    check('right duplicate remains', solve([[[10, 'a', 1]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 1]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 1]], [['b', 1]], [['a', 1]]]), [[10, 1]])
    check('null key', solve([[[10, None, 1]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 1]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -1]])
    check('left multiplicity', solve([[[10, 'a', 2]], [], [['a', 1]]]), [[10, 2]])
elif N == 2:
    check('new right key', solve([[[10, 'a', 2]], [], [['a', 1]]]), [[10, 2]])
    check('last right removed', solve([[[10, 'a', 2]], [['a', 1]], [['a', -1]]]), [[10, -2]])
    check('right duplicate remains', solve([[[10, 'a', 2]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 2]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 2]], [['b', 1]], [['a', 1]]]), [[10, 2]])
    check('null key', solve([[[10, None, 2]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 2]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -2]])
    check('left multiplicity', solve([[[10, 'a', 3]], [], [['a', 1]]]), [[10, 3]])
elif N == 3:
    check('new right key', solve([[[10, 'a', 3]], [], [['a', 1]]]), [[10, 3]])
    check('last right removed', solve([[[10, 'a', 3]], [['a', 1]], [['a', -1]]]), [[10, -3]])
    check('right duplicate remains', solve([[[10, 'a', 3]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 3]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 3]], [['b', 1]], [['a', 1]]]), [[10, 3]])
    check('null key', solve([[[10, None, 3]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 3]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -3]])
    check('left multiplicity', solve([[[10, 'a', 4]], [], [['a', 1]]]), [[10, 4]])
elif N == 4:
    check('new right key', solve([[[10, 'a', 4]], [], [['a', 1]]]), [[10, 4]])
    check('last right removed', solve([[[10, 'a', 4]], [['a', 1]], [['a', -1]]]), [[10, -4]])
    check('right duplicate remains', solve([[[10, 'a', 4]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 4]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 4]], [['b', 1]], [['a', 1]]]), [[10, 4]])
    check('null key', solve([[[10, None, 4]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 4]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -4]])
    check('left multiplicity', solve([[[10, 'a', 5]], [], [['a', 1]]]), [[10, 5]])
elif N == 5:
    check('new right key', solve([[[10, 'a', 5]], [], [['a', 1]]]), [[10, 5]])
    check('last right removed', solve([[[10, 'a', 5]], [['a', 1]], [['a', -1]]]), [[10, -5]])
    check('right duplicate remains', solve([[[10, 'a', 5]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 5]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 5]], [['b', 1]], [['a', 1]]]), [[10, 5]])
    check('null key', solve([[[10, None, 5]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 5]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -5]])
    check('left multiplicity', solve([[[10, 'a', 6]], [], [['a', 1]]]), [[10, 6]])
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:
Membership maintenance forwards right count changes into left weights.

For a fixed left bag [id,key,multiplicity], apply a right-key count delta batch and emit signed left rows only when right membership crosses zero. Null keys never match. Emit [id,signed-left-multiplicity] in left order; duplicate right updates consolidate before crossing detection.

split: open-access


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

N = 1
observations = []
def solve(d):
    try:
        left,old,delta=d
        before=dict(old); after=dict(old)
        for key,weight in delta: after[key]=after.get(key,0)+weight
        out=[]
        for ident,key,multiplicity in left:
            if False: continue
            was=before.get(key,0)>0; now=after.get(key,0)>0
            if was!=now: out.append([ident,multiplicity*(1 if now else -1)])
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('new right key', solve([[[10, 'a', 1]], [], [['a', 1]]]), [[10, 1]])
    check('last right removed', solve([[[10, 'a', 1]], [['a', 1]], [['a', -1]]]), [[10, -1]])
    check('right duplicate remains', solve([[[10, 'a', 1]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 1]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 1]], [['b', 1]], [['a', 1]]]), [[10, 1]])
    check('null key', solve([[[10, None, 1]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 1]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -1]])
    check('left multiplicity', solve([[[10, 'a', 2]], [], [['a', 1]]]), [[10, 2]])
elif N == 2:
    check('new right key', solve([[[10, 'a', 2]], [], [['a', 1]]]), [[10, 2]])
    check('last right removed', solve([[[10, 'a', 2]], [['a', 1]], [['a', -1]]]), [[10, -2]])
    check('right duplicate remains', solve([[[10, 'a', 2]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 2]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 2]], [['b', 1]], [['a', 1]]]), [[10, 2]])
    check('null key', solve([[[10, None, 2]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 2]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -2]])
    check('left multiplicity', solve([[[10, 'a', 3]], [], [['a', 1]]]), [[10, 3]])
elif N == 3:
    check('new right key', solve([[[10, 'a', 3]], [], [['a', 1]]]), [[10, 3]])
    check('last right removed', solve([[[10, 'a', 3]], [['a', 1]], [['a', -1]]]), [[10, -3]])
    check('right duplicate remains', solve([[[10, 'a', 3]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 3]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 3]], [['b', 1]], [['a', 1]]]), [[10, 3]])
    check('null key', solve([[[10, None, 3]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 3]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -3]])
    check('left multiplicity', solve([[[10, 'a', 4]], [], [['a', 1]]]), [[10, 4]])
elif N == 4:
    check('new right key', solve([[[10, 'a', 4]], [], [['a', 1]]]), [[10, 4]])
    check('last right removed', solve([[[10, 'a', 4]], [['a', 1]], [['a', -1]]]), [[10, -4]])
    check('right duplicate remains', solve([[[10, 'a', 4]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 4]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 4]], [['b', 1]], [['a', 1]]]), [[10, 4]])
    check('null key', solve([[[10, None, 4]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 4]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -4]])
    check('left multiplicity', solve([[[10, 'a', 5]], [], [['a', 1]]]), [[10, 5]])
elif N == 5:
    check('new right key', solve([[[10, 'a', 5]], [], [['a', 1]]]), [[10, 5]])
    check('last right removed', solve([[[10, 'a', 5]], [['a', 1]], [['a', -1]]]), [[10, -5]])
    check('right duplicate remains', solve([[[10, 'a', 5]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 5]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 5]], [['b', 1]], [['a', 1]]]), [[10, 5]])
    check('null key', solve([[[10, None, 5]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 5]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -5]])
    check('left multiplicity', solve([[[10, 'a', 6]], [], [['a', 1]]]), [[10, 6]])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(d):
    try:
        left,old,delta=d
        before=dict(old); after=dict(old)
        for key,weight in delta: after[key]=after.get(key,0)+weight
        out=[]
        for ident,key,multiplicity in left:
            if key is None and None not in after: continue
            was=before.get(key,0)>0; now=after.get(key,0)>0
            if was!=now: out.append([ident,multiplicity*(1 if now else -1)])
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('new right key', solve([[[10, 'a', 1]], [], [['a', 1]]]), [[10, 1]])
    check('last right removed', solve([[[10, 'a', 1]], [['a', 1]], [['a', -1]]]), [[10, -1]])
    check('right duplicate remains', solve([[[10, 'a', 1]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 1]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 1]], [['b', 1]], [['a', 1]]]), [[10, 1]])
    check('null key', solve([[[10, None, 1]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 1]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -1]])
    check('left multiplicity', solve([[[10, 'a', 2]], [], [['a', 1]]]), [[10, 2]])
elif N == 2:
    check('new right key', solve([[[10, 'a', 2]], [], [['a', 1]]]), [[10, 2]])
    check('last right removed', solve([[[10, 'a', 2]], [['a', 1]], [['a', -1]]]), [[10, -2]])
    check('right duplicate remains', solve([[[10, 'a', 2]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 2]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 2]], [['b', 1]], [['a', 1]]]), [[10, 2]])
    check('null key', solve([[[10, None, 2]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 2]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -2]])
    check('left multiplicity', solve([[[10, 'a', 3]], [], [['a', 1]]]), [[10, 3]])
elif N == 3:
    check('new right key', solve([[[10, 'a', 3]], [], [['a', 1]]]), [[10, 3]])
    check('last right removed', solve([[[10, 'a', 3]], [['a', 1]], [['a', -1]]]), [[10, -3]])
    check('right duplicate remains', solve([[[10, 'a', 3]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 3]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 3]], [['b', 1]], [['a', 1]]]), [[10, 3]])
    check('null key', solve([[[10, None, 3]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 3]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -3]])
    check('left multiplicity', solve([[[10, 'a', 4]], [], [['a', 1]]]), [[10, 4]])
elif N == 4:
    check('new right key', solve([[[10, 'a', 4]], [], [['a', 1]]]), [[10, 4]])
    check('last right removed', solve([[[10, 'a', 4]], [['a', 1]], [['a', -1]]]), [[10, -4]])
    check('right duplicate remains', solve([[[10, 'a', 4]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 4]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 4]], [['b', 1]], [['a', 1]]]), [[10, 4]])
    check('null key', solve([[[10, None, 4]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 4]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -4]])
    check('left multiplicity', solve([[[10, 'a', 5]], [], [['a', 1]]]), [[10, 5]])
elif N == 5:
    check('new right key', solve([[[10, 'a', 5]], [], [['a', 1]]]), [[10, 5]])
    check('last right removed', solve([[[10, 'a', 5]], [['a', 1]], [['a', -1]]]), [[10, -5]])
    check('right duplicate remains', solve([[[10, 'a', 5]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 5]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 5]], [['b', 1]], [['a', 1]]]), [[10, 5]])
    check('null key', solve([[[10, None, 5]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 5]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -5]])
    check('left multiplicity', solve([[[10, 'a', 6]], [], [['a', 1]]]), [[10, 6]])
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:
Membership maintenance matches null keys against right counts.

For a fixed left bag [id,key,multiplicity], apply a right-key count delta batch and emit signed left rows only when right membership crosses zero. Null keys never match. Emit [id,signed-left-multiplicity] in left order; duplicate right updates consolidate before crossing detection.

split: open-access


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

N = 1
observations = []
def solve(d):
    try:
        left,old,delta=d
        before=dict(old); after=dict(old)
        for key,weight in delta: after[key]=after.get(key,0)+weight
        out=[]
        for ident,key,multiplicity in left:
            if key is None: continue
            was=any(before.values()); now=any(after.values())
            if was!=now: out.append([ident,multiplicity*(1 if now else -1)])
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('new right key', solve([[[10, 'a', 1]], [], [['a', 1]]]), [[10, 1]])
    check('last right removed', solve([[[10, 'a', 1]], [['a', 1]], [['a', -1]]]), [[10, -1]])
    check('right duplicate remains', solve([[[10, 'a', 1]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 1]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 1]], [['b', 1]], [['a', 1]]]), [[10, 1]])
    check('null key', solve([[[10, None, 1]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 1]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -1]])
    check('left multiplicity', solve([[[10, 'a', 2]], [], [['a', 1]]]), [[10, 2]])
elif N == 2:
    check('new right key', solve([[[10, 'a', 2]], [], [['a', 1]]]), [[10, 2]])
    check('last right removed', solve([[[10, 'a', 2]], [['a', 1]], [['a', -1]]]), [[10, -2]])
    check('right duplicate remains', solve([[[10, 'a', 2]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 2]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 2]], [['b', 1]], [['a', 1]]]), [[10, 2]])
    check('null key', solve([[[10, None, 2]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 2]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -2]])
    check('left multiplicity', solve([[[10, 'a', 3]], [], [['a', 1]]]), [[10, 3]])
elif N == 3:
    check('new right key', solve([[[10, 'a', 3]], [], [['a', 1]]]), [[10, 3]])
    check('last right removed', solve([[[10, 'a', 3]], [['a', 1]], [['a', -1]]]), [[10, -3]])
    check('right duplicate remains', solve([[[10, 'a', 3]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 3]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 3]], [['b', 1]], [['a', 1]]]), [[10, 3]])
    check('null key', solve([[[10, None, 3]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 3]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -3]])
    check('left multiplicity', solve([[[10, 'a', 4]], [], [['a', 1]]]), [[10, 4]])
elif N == 4:
    check('new right key', solve([[[10, 'a', 4]], [], [['a', 1]]]), [[10, 4]])
    check('last right removed', solve([[[10, 'a', 4]], [['a', 1]], [['a', -1]]]), [[10, -4]])
    check('right duplicate remains', solve([[[10, 'a', 4]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 4]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 4]], [['b', 1]], [['a', 1]]]), [[10, 4]])
    check('null key', solve([[[10, None, 4]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 4]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -4]])
    check('left multiplicity', solve([[[10, 'a', 5]], [], [['a', 1]]]), [[10, 5]])
elif N == 5:
    check('new right key', solve([[[10, 'a', 5]], [], [['a', 1]]]), [[10, 5]])
    check('last right removed', solve([[[10, 'a', 5]], [['a', 1]], [['a', -1]]]), [[10, -5]])
    check('right duplicate remains', solve([[[10, 'a', 5]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 5]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 5]], [['b', 1]], [['a', 1]]]), [[10, 5]])
    check('null key', solve([[[10, None, 5]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 5]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -5]])
    check('left multiplicity', solve([[[10, 'a', 6]], [], [['a', 1]]]), [[10, 6]])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(d):
    try:
        left,old,delta=d
        before=dict(old); after=dict(old)
        for key,weight in delta: after[key]=after.get(key,0)+weight
        out=[]
        for ident,key,multiplicity in left:
            if key is None: continue
            was=sum(before.values())>0; now=sum(after.values())>0
            if was!=now: out.append([ident,multiplicity*(1 if now else -1)])
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('new right key', solve([[[10, 'a', 1]], [], [['a', 1]]]), [[10, 1]])
    check('last right removed', solve([[[10, 'a', 1]], [['a', 1]], [['a', -1]]]), [[10, -1]])
    check('right duplicate remains', solve([[[10, 'a', 1]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 1]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 1]], [['b', 1]], [['a', 1]]]), [[10, 1]])
    check('null key', solve([[[10, None, 1]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 1]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -1]])
    check('left multiplicity', solve([[[10, 'a', 2]], [], [['a', 1]]]), [[10, 2]])
elif N == 2:
    check('new right key', solve([[[10, 'a', 2]], [], [['a', 1]]]), [[10, 2]])
    check('last right removed', solve([[[10, 'a', 2]], [['a', 1]], [['a', -1]]]), [[10, -2]])
    check('right duplicate remains', solve([[[10, 'a', 2]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 2]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 2]], [['b', 1]], [['a', 1]]]), [[10, 2]])
    check('null key', solve([[[10, None, 2]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 2]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -2]])
    check('left multiplicity', solve([[[10, 'a', 3]], [], [['a', 1]]]), [[10, 3]])
elif N == 3:
    check('new right key', solve([[[10, 'a', 3]], [], [['a', 1]]]), [[10, 3]])
    check('last right removed', solve([[[10, 'a', 3]], [['a', 1]], [['a', -1]]]), [[10, -3]])
    check('right duplicate remains', solve([[[10, 'a', 3]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 3]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 3]], [['b', 1]], [['a', 1]]]), [[10, 3]])
    check('null key', solve([[[10, None, 3]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 3]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -3]])
    check('left multiplicity', solve([[[10, 'a', 4]], [], [['a', 1]]]), [[10, 4]])
elif N == 4:
    check('new right key', solve([[[10, 'a', 4]], [], [['a', 1]]]), [[10, 4]])
    check('last right removed', solve([[[10, 'a', 4]], [['a', 1]], [['a', -1]]]), [[10, -4]])
    check('right duplicate remains', solve([[[10, 'a', 4]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 4]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 4]], [['b', 1]], [['a', 1]]]), [[10, 4]])
    check('null key', solve([[[10, None, 4]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 4]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -4]])
    check('left multiplicity', solve([[[10, 'a', 5]], [], [['a', 1]]]), [[10, 5]])
elif N == 5:
    check('new right key', solve([[[10, 'a', 5]], [], [['a', 1]]]), [[10, 5]])
    check('last right removed', solve([[[10, 'a', 5]], [['a', 1]], [['a', -1]]]), [[10, -5]])
    check('right duplicate remains', solve([[[10, 'a', 5]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 5]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 5]], [['b', 1]], [['a', 1]]]), [[10, 5]])
    check('null key', solve([[[10, None, 5]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 5]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -5]])
    check('left multiplicity', solve([[[10, 'a', 6]], [], [['a', 1]]]), [[10, 6]])
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:
Membership maintenance uses whole-right emptiness for every left key.

For a fixed left bag [id,key,multiplicity], apply a right-key count delta batch and emit signed left rows only when right membership crosses zero. Null keys never match. Emit [id,signed-left-multiplicity] in left order; duplicate right updates consolidate before crossing detection.

split: open-access


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

N = 1
observations = []
def solve(d):
    try:
        left,old,delta=d
        before=dict(old); after=dict(old)
        for key,weight in delta: after[key]=after.get(key,0)+weight
        out=[]
        for ident,key,multiplicity in left:
            if key is None: continue
            was=before.get(key,0)>0; now=after.get(key,0)>0
            if was!=now: out.append([ident,multiplicity*(1)])
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('new right key', solve([[[10, 'a', 1]], [], [['a', 1]]]), [[10, 1]])
    check('last right removed', solve([[[10, 'a', 1]], [['a', 1]], [['a', -1]]]), [[10, -1]])
    check('right duplicate remains', solve([[[10, 'a', 1]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 1]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 1]], [['b', 1]], [['a', 1]]]), [[10, 1]])
    check('null key', solve([[[10, None, 1]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 1]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -1]])
    check('left multiplicity', solve([[[10, 'a', 2]], [], [['a', 1]]]), [[10, 2]])
elif N == 2:
    check('new right key', solve([[[10, 'a', 2]], [], [['a', 1]]]), [[10, 2]])
    check('last right removed', solve([[[10, 'a', 2]], [['a', 1]], [['a', -1]]]), [[10, -2]])
    check('right duplicate remains', solve([[[10, 'a', 2]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 2]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 2]], [['b', 1]], [['a', 1]]]), [[10, 2]])
    check('null key', solve([[[10, None, 2]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 2]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -2]])
    check('left multiplicity', solve([[[10, 'a', 3]], [], [['a', 1]]]), [[10, 3]])
elif N == 3:
    check('new right key', solve([[[10, 'a', 3]], [], [['a', 1]]]), [[10, 3]])
    check('last right removed', solve([[[10, 'a', 3]], [['a', 1]], [['a', -1]]]), [[10, -3]])
    check('right duplicate remains', solve([[[10, 'a', 3]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 3]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 3]], [['b', 1]], [['a', 1]]]), [[10, 3]])
    check('null key', solve([[[10, None, 3]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 3]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -3]])
    check('left multiplicity', solve([[[10, 'a', 4]], [], [['a', 1]]]), [[10, 4]])
elif N == 4:
    check('new right key', solve([[[10, 'a', 4]], [], [['a', 1]]]), [[10, 4]])
    check('last right removed', solve([[[10, 'a', 4]], [['a', 1]], [['a', -1]]]), [[10, -4]])
    check('right duplicate remains', solve([[[10, 'a', 4]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 4]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 4]], [['b', 1]], [['a', 1]]]), [[10, 4]])
    check('null key', solve([[[10, None, 4]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 4]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -4]])
    check('left multiplicity', solve([[[10, 'a', 5]], [], [['a', 1]]]), [[10, 5]])
elif N == 5:
    check('new right key', solve([[[10, 'a', 5]], [], [['a', 1]]]), [[10, 5]])
    check('last right removed', solve([[[10, 'a', 5]], [['a', 1]], [['a', -1]]]), [[10, -5]])
    check('right duplicate remains', solve([[[10, 'a', 5]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 5]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 5]], [['b', 1]], [['a', 1]]]), [[10, 5]])
    check('null key', solve([[[10, None, 5]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 5]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -5]])
    check('left multiplicity', solve([[[10, 'a', 6]], [], [['a', 1]]]), [[10, 6]])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(d):
    try:
        left,old,delta=d
        before=dict(old); after=dict(old)
        for key,weight in delta: after[key]=after.get(key,0)+weight
        out=[]
        for ident,key,multiplicity in left:
            if key is None: continue
            was=before.get(key,0)>0; now=after.get(key,0)>0
            if was!=now: out.append([ident,multiplicity*(-1)])
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('new right key', solve([[[10, 'a', 1]], [], [['a', 1]]]), [[10, 1]])
    check('last right removed', solve([[[10, 'a', 1]], [['a', 1]], [['a', -1]]]), [[10, -1]])
    check('right duplicate remains', solve([[[10, 'a', 1]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 1]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 1]], [['b', 1]], [['a', 1]]]), [[10, 1]])
    check('null key', solve([[[10, None, 1]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 1]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -1]])
    check('left multiplicity', solve([[[10, 'a', 2]], [], [['a', 1]]]), [[10, 2]])
elif N == 2:
    check('new right key', solve([[[10, 'a', 2]], [], [['a', 1]]]), [[10, 2]])
    check('last right removed', solve([[[10, 'a', 2]], [['a', 1]], [['a', -1]]]), [[10, -2]])
    check('right duplicate remains', solve([[[10, 'a', 2]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 2]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 2]], [['b', 1]], [['a', 1]]]), [[10, 2]])
    check('null key', solve([[[10, None, 2]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 2]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -2]])
    check('left multiplicity', solve([[[10, 'a', 3]], [], [['a', 1]]]), [[10, 3]])
elif N == 3:
    check('new right key', solve([[[10, 'a', 3]], [], [['a', 1]]]), [[10, 3]])
    check('last right removed', solve([[[10, 'a', 3]], [['a', 1]], [['a', -1]]]), [[10, -3]])
    check('right duplicate remains', solve([[[10, 'a', 3]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 3]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 3]], [['b', 1]], [['a', 1]]]), [[10, 3]])
    check('null key', solve([[[10, None, 3]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 3]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -3]])
    check('left multiplicity', solve([[[10, 'a', 4]], [], [['a', 1]]]), [[10, 4]])
elif N == 4:
    check('new right key', solve([[[10, 'a', 4]], [], [['a', 1]]]), [[10, 4]])
    check('last right removed', solve([[[10, 'a', 4]], [['a', 1]], [['a', -1]]]), [[10, -4]])
    check('right duplicate remains', solve([[[10, 'a', 4]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 4]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 4]], [['b', 1]], [['a', 1]]]), [[10, 4]])
    check('null key', solve([[[10, None, 4]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 4]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -4]])
    check('left multiplicity', solve([[[10, 'a', 5]], [], [['a', 1]]]), [[10, 5]])
elif N == 5:
    check('new right key', solve([[[10, 'a', 5]], [], [['a', 1]]]), [[10, 5]])
    check('last right removed', solve([[[10, 'a', 5]], [['a', 1]], [['a', -1]]]), [[10, -5]])
    check('right duplicate remains', solve([[[10, 'a', 5]], [['a', 2]], [['a', -1]]]), [])
    check('right batch cancellation', solve([[[10, 'a', 5]], [], [['a', 1], ['a', -1]]]), [])
    check('other right key', solve([[[10, 'a', 5]], [['b', 1]], [['a', 1]]]), [[10, 5]])
    check('null key', solve([[[10, None, 5]], [], [[None, 1]]]), [])
    check('two removals cross zero', solve([[[10, 'a', 5]], [['a', 2]], [['a', -1], ['a', -1]]]), [[10, -5]])
    check('left multiplicity', solve([[[10, 'a', 6]], [], [['a', 1]]]), [[10, 6]])
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:
Right membership disappearance produces positive left changes.

For a fixed left bag [id,key,multiplicity], apply a right-key count delta batch and emit signed left rows only when right membership crosses zero. Null keys never match. Emit [id,signed-left-multiplicity] in left order; duplicate right updates consolidate before crossing detection.

split: open-access


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

N = 1
observations = []
def solve(d):
    try:
        row,rules=d
        result=dict(row)
        pending=[rule for rule in rules if result.get(rule[0]) is None]
        while pending:
            progressed=False; later=[]
            for target,source,constant in pending:
                if source is not None and source not in result:
                    later.append([target,source,constant]); continue
                result[target]=constant if source is None else (None if result[source] is None else result[source]+constant)
                progressed=True
            if not progressed: return 'DEFAULT_CYCLE'
            pending=later
        return result
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('forward dependency', solve([{}, [['b', 'a', 2], ['a', None, 1]]]), {'a': 1, 'b': 3})
    check('explicit null', solve([{'a': None}, [['a', None, 1], ['b', 'a', 1]]]), {'a': None, 'b': None})
    check('explicit zero', solve([{'a': 0}, [['a', None, 1], ['b', 'a', 2]]]), {'a': 0, 'b': 2})
    check('dependency cycle', solve([{}, [['a', 'b', 1], ['b', 'a', 1]]]), 'DEFAULT_CYCLE')
    check('provided unrelated', solve([{'x': 1}, [['a', None, 2]]]), {'x': 1, 'a': 2})
    check('source provided', solve([{'a': 1}, [['b', 'a', 3]]]), {'a': 1, 'b': 4})
    check('no defaults', solve([{'a': 1}, []]), {'a': 1})
elif N == 2:
    check('forward dependency', solve([{}, [['b', 'a', 2], ['a', None, 2]]]), {'a': 2, 'b': 4})
    check('explicit null', solve([{'a': None}, [['a', None, 2], ['b', 'a', 1]]]), {'a': None, 'b': None})
    check('explicit zero', solve([{'a': 0}, [['a', None, 2], ['b', 'a', 2]]]), {'a': 0, 'b': 2})
    check('dependency cycle', solve([{}, [['a', 'b', 1], ['b', 'a', 1]]]), 'DEFAULT_CYCLE')
    check('provided unrelated', solve([{'x': 2}, [['a', None, 3]]]), {'x': 2, 'a': 3})
    check('source provided', solve([{'a': 2}, [['b', 'a', 3]]]), {'a': 2, 'b': 5})
    check('no defaults', solve([{'a': 2}, []]), {'a': 2})
elif N == 3:
    check('forward dependency', solve([{}, [['b', 'a', 2], ['a', None, 3]]]), {'a': 3, 'b': 5})
    check('explicit null', solve([{'a': None}, [['a', None, 3], ['b', 'a', 1]]]), {'a': None, 'b': None})
    check('explicit zero', solve([{'a': 0}, [['a', None, 3], ['b', 'a', 2]]]), {'a': 0, 'b': 2})
    check('dependency cycle', solve([{}, [['a', 'b', 1], ['b', 'a', 1]]]), 'DEFAULT_CYCLE')
    check('provided unrelated', solve([{'x': 3}, [['a', None, 4]]]), {'x': 3, 'a': 4})
    check('source provided', solve([{'a': 3}, [['b', 'a', 3]]]), {'a': 3, 'b': 6})
    check('no defaults', solve([{'a': 3}, []]), {'a': 3})
elif N == 4:
    check('forward dependency', solve([{}, [['b', 'a', 2], ['a', None, 4]]]), {'a': 4, 'b': 6})
    check('explicit null', solve([{'a': None}, [['a', None, 4], ['b', 'a', 1]]]), {'a': None, 'b': None})
    check('explicit zero', solve([{'a': 0}, [['a', None, 4], ['b', 'a', 2]]]), {'a': 0, 'b': 2})
    check('dependency cycle', solve([{}, [['a', 'b', 1], ['b', 'a', 1]]]), 'DEFAULT_CYCLE')
    check('provided unrelated', solve([{'x': 4}, [['a', None, 5]]]), {'x': 4, 'a': 5})
    check('source provided', solve([{'a': 4}, [['b', 'a', 3]]]), {'a': 4, 'b': 7})
    check('no defaults', solve([{'a': 4}, []]), {'a': 4})
elif N == 5:
    check('forward dependency', solve([{}, [['b', 'a', 2], ['a', None, 5]]]), {'a': 5, 'b': 7})
    check('explicit null', solve([{'a': None}, [['a', None, 5], ['b', 'a', 1]]]), {'a': None, 'b': None})
    check('explicit zero', solve([{'a': 0}, [['a', None, 5], ['b', 'a', 2]]]), {'a': 0, 'b': 2})
    check('dependency cycle', solve([{}, [['a', 'b', 1], ['b', 'a', 1]]]), 'DEFAULT_CYCLE')
    check('provided unrelated', solve([{'x': 5}, [['a', None, 6]]]), {'x': 5, 'a': 6})
    check('source provided', solve([{'a': 5}, [['b', 'a', 3]]]), {'a': 5, 'b': 8})
    check('no defaults', solve([{'a': 5}, []]), {'a': 5})
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(d):
    try:
        row,rules=d
        result=dict(row)
        pending=[rule for rule in rules if not result.get(rule[0])]
        while pending:
            progressed=False; later=[]
            for target,source,constant in pending:
                if source is not None and source not in result:
                    later.append([target,source,constant]); continue
                result[target]=constant if source is None else (None if result[source] is None else result[source]+constant)
                progressed=True
            if not progressed: return 'DEFAULT_CYCLE'
            pending=later
        return result
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('forward dependency', solve([{}, [['b', 'a', 2], ['a', None, 1]]]), {'a': 1, 'b': 3})
    check('explicit null', solve([{'a': None}, [['a', None, 1], ['b', 'a', 1]]]), {'a': None, 'b': None})
    check('explicit zero', solve([{'a': 0}, [['a', None, 1], ['b', 'a', 2]]]), {'a': 0, 'b': 2})
    check('dependency cycle', solve([{}, [['a', 'b', 1], ['b', 'a', 1]]]), 'DEFAULT_CYCLE')
    check('provided unrelated', solve([{'x': 1}, [['a', None, 2]]]), {'x': 1, 'a': 2})
    check('source provided', solve([{'a': 1}, [['b', 'a', 3]]]), {'a': 1, 'b': 4})
    check('no defaults', solve([{'a': 1}, []]), {'a': 1})
elif N == 2:
    check('forward dependency', solve([{}, [['b', 'a', 2], ['a', None, 2]]]), {'a': 2, 'b': 4})
    check('explicit null', solve([{'a': None}, [['a', None, 2], ['b', 'a', 1]]]), {'a': None, 'b': None})
    check('explicit zero', solve([{'a': 0}, [['a', None, 2], ['b', 'a', 2]]]), {'a': 0, 'b': 2})
    check('dependency cycle', solve([{}, [['a', 'b', 1], ['b', 'a', 1]]]), 'DEFAULT_CYCLE')
    check('provided unrelated', solve([{'x': 2}, [['a', None, 3]]]), {'x': 2, 'a': 3})
    check('source provided', solve([{'a': 2}, [['b', 'a', 3]]]), {'a': 2, 'b': 5})
    check('no defaults', solve([{'a': 2}, []]), {'a': 2})
elif N == 3:
    check('forward dependency', solve([{}, [['b', 'a', 2], ['a', None, 3]]]), {'a': 3, 'b': 5})
    check('explicit null', solve([{'a': None}, [['a', None, 3], ['b', 'a', 1]]]), {'a': None, 'b': None})
    check('explicit zero', solve([{'a': 0}, [['a', None, 3], ['b', 'a', 2]]]), {'a': 0, 'b': 2})
    check('dependency cycle', solve([{}, [['a', 'b', 1], ['b', 'a', 1]]]), 'DEFAULT_CYCLE')
    check('provided unrelated', solve([{'x': 3}, [['a', None, 4]]]), {'x': 3, 'a': 4})
    check('source provided', solve([{'a': 3}, [['b', 'a', 3]]]), {'a': 3, 'b': 6})
    check('no defaults', solve([{'a': 3}, []]), {'a': 3})
elif N == 4:
    check('forward dependency', solve([{}, [['b', 'a', 2], ['a', None, 4]]]), {'a': 4, 'b': 6})
    check('explicit null', solve([{'a': None}, [['a', None, 4], ['b', 'a', 1]]]), {'a': None, 'b': None})
    check('explicit zero', solve([{'a': 0}, [['a', None, 4], ['b', 'a', 2]]]), {'a': 0, 'b': 2})
    check('dependency cycle', solve([{}, [['a', 'b', 1], ['b', 'a', 1]]]), 'DEFAULT_CYCLE')
    check('provided unrelated', solve([{'x': 4}, [['a', None, 5]]]), {'x': 4, 'a': 5})
    check('source provided', solve([{'a': 4}, [['b', 'a', 3]]]), {'a': 4, 'b': 7})
    check('no defaults', solve([{'a': 4}, []]), {'a': 4})
elif N == 5:
    check('forward dependency', solve([{}, [['b', 'a', 2], ['a', None, 5]]]), {'a': 5, 'b': 7})
    check('explicit null', solve([{'a': None}, [['a', None, 5], ['b', 'a', 1]]]), {'a': None, 'b': None})
    check('explicit zero', solve([{'a': 0}, [['a', None, 5], ['b', 'a', 2]]]), {'a': 0, 'b': 2})
    check('dependency cycle', solve([{}, [['a', 'b', 1], ['b', 'a', 1]]]), 'DEFAULT_CYCLE')
    check('provided unrelated', solve([{'x': 5}, [['a', None, 6]]]), {'x': 5, 'a': 6})
    check('source provided', solve([{'a': 5}, [['b', 'a', 3]]]), {'a': 5, 'b': 8})
    check('no defaults', solve([{'a': 5}, []]), {'a': 5})
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:
Default materialization overwrites explicit null columns.

Materialize missing columns using ordered default rules [target,source-or-None,constant]. A constant rule writes constant; a dependent rule writes source+constant, propagating explicit null. Existing columns including None and zero never change. Resolve forward dependencies to a fixed point; unresolved dependencies return DEFAULT_CYCLE.

split: open-access


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

N = 1
observations = []
def solve(d):
    try:
        row,rules=d
        result=dict(row)
        pending=[rule for rule in rules if rule[0] not in result]
        while pending:
            progressed=False; later=[]
            for target,source,constant in pending:
                if source is not None and source not in result:
                    continue
                result[target]=constant if source is None else (None if result[source] is None else result[source]+constant)
                progressed=True
            if not progressed: return 'DEFAULT_CYCLE'
            pending=later
        return result
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('forward dependency', solve([{}, [['b', 'a', 2], ['a', None, 1]]]), {'a': 1, 'b': 3})
    check('explicit null', solve([{'a': None}, [['a', None, 1], ['b', 'a', 1]]]), {'a': None, 'b': None})
    check('explicit zero', solve([{'a': 0}, [['a', None, 1], ['b', 'a', 2]]]), {'a': 0, 'b': 2})
    check('dependency cycle', solve([{}, [['a', 'b', 1], ['b', 'a', 1]]]), 'DEFAULT_CYCLE')
    check('provided unrelated', solve([{'x': 1}, [['a', None, 2]]]), {'x': 1, 'a': 2})
    check('source provided', solve([{'a': 1}, [['b', 'a', 3]]]), {'a': 1, 'b': 4})
    check('no defaults', solve([{'a': 1}, []]), {'a': 1})
elif N == 2:
    check('forward dependency', solve([{}, [['b', 'a', 2], ['a', None, 2]]]), {'a': 2, 'b': 4})
    check('explicit null', solve([{'a': None}, [['a', None, 2], ['b', 'a', 1]]]), {'a': None, 'b': None})
    check('explicit zero', solve([{'a': 0}, [['a', None, 2], ['b', 'a', 2]]]), {'a': 0, 'b': 2})
    check('dependency cycle', solve([{}, [['a', 'b', 1], ['b', 'a', 1]]]), 'DEFAULT_CYCLE')
    check('provided unrelated', solve([{'x': 2}, [['a', None, 3]]]), {'x': 2, 'a': 3})
    check('source provided', solve([{'a': 2}, [['b', 'a', 3]]]), {'a': 2, 'b': 5})
    check('no defaults', solve([{'a': 2}, []]), {'a': 2})
elif N == 3:
    check('forward dependency', solve([{}, [['b', 'a', 2], ['a', None, 3]]]), {'a': 3, 'b': 5})
    check('explicit null', solve([{'a': None}, [['a', None, 3], ['b', 'a', 1]]]), {'a': None, 'b': None})
    check('explicit zero', solve([{'a': 0}, [['a', None, 3], ['b', 'a', 2]]]), {'a': 0, 'b': 2})
    check('dependency cycle', solve([{}, [['a', 'b', 1], ['b', 'a', 1]]]), 'DEFAULT_CYCLE')
    check('provided unrelated', solve([{'x': 3}, [['a', None, 4]]]), {'x': 3, 'a': 4})
    check('source provided', solve([{'a': 3}, [['b', 'a', 3]]]), {'a': 3, 'b': 6})
    check('no defaults', solve([{'a': 3}, []]), {'a': 3})
elif N == 4:
    check('forward dependency', solve([{}, [['b', 'a', 2], ['a', None, 4]]]), {'a': 4, 'b': 6})
    check('explicit null', solve([{'a': None}, [['a', None, 4], ['b', 'a', 1]]]), {'a': None, 'b': None})
    check('explicit zero', solve([{'a': 0}, [['a', None, 4], ['b', 'a', 2]]]), {'a': 0, 'b': 2})
    check('dependency cycle', solve([{}, [['a', 'b', 1], ['b', 'a', 1]]]), 'DEFAULT_CYCLE')
    check('provided unrelated', solve([{'x': 4}, [['a', None, 5]]]), {'x': 4, 'a': 5})
    check('source provided', solve([{'a': 4}, [['b', 'a', 3]]]), {'a': 4, 'b': 7})
    check('no defaults', solve([{'a': 4}, []]), {'a': 4})
elif N == 5:
    check('forward dependency', solve([{}, [['b', 'a', 2], ['a', None, 5]]]), {'a': 5, 'b': 7})
    check('explicit null', solve([{'a': None}, [['a', None, 5], ['b', 'a', 1]]]), {'a': None, 'b': None})
    check('explicit zero', solve([{'a': 0}, [['a', None, 5], ['b', 'a', 2]]]), {'a': 0, 'b': 2})
    check('dependency cycle', solve([{}, [['a', 'b', 1], ['b', 'a', 1]]]), 'DEFAULT_CYCLE')
    check('provided unrelated', solve([{'x': 5}, [['a', None, 6]]]), {'x': 5, 'a': 6})
    check('source provided', solve([{'a': 5}, [['b', 'a', 3]]]), {'a': 5, 'b': 8})
    check('no defaults', solve([{'a': 5}, []]), {'a': 5})
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(d):
    try:
        row,rules=d
        result=dict(row)
        pending=[rule for rule in rules if rule[0] not in result]
        while pending:
            progressed=False; later=[]
            for target,source,constant in pending:
                if source is not None and source not in result:
                    return 'DEFAULT_CYCLE'
                result[target]=constant if source is None else (None if result[source] is None else result[source]+constant)
                progressed=True
            if not progressed: return 'DEFAULT_CYCLE'
            pending=later
        return result
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('forward dependency', solve([{}, [['b', 'a', 2], ['a', None, 1]]]), {'a': 1, 'b': 3})
    check('explicit null', solve([{'a': None}, [['a', None, 1], ['b', 'a', 1]]]), {'a': None, 'b': None})
    check('explicit zero', solve([{'a': 0}, [['a', None, 1], ['b', 'a', 2]]]), {'a': 0, 'b': 2})
    check('dependency cycle', solve([{}, [['a', 'b', 1], ['b', 'a', 1]]]), 'DEFAULT_CYCLE')
    check('provided unrelated', solve([{'x': 1}, [['a', None, 2]]]), {'x': 1, 'a': 2})
    check('source provided', solve([{'a': 1}, [['b', 'a', 3]]]), {'a': 1, 'b': 4})
    check('no defaults', solve([{'a': 1}, []]), {'a': 1})
elif N == 2:
    check('forward dependency', solve([{}, [['b', 'a', 2], ['a', None, 2]]]), {'a': 2, 'b': 4})
    check('explicit null', solve([{'a': None}, [['a', None, 2], ['b', 'a', 1]]]), {'a': None, 'b': None})
    check('explicit zero', solve([{'a': 0}, [['a', None, 2], ['b', 'a', 2]]]), {'a': 0, 'b': 2})
    check('dependency cycle', solve([{}, [['a', 'b', 1], ['b', 'a', 1]]]), 'DEFAULT_CYCLE')
    check('provided unrelated', solve([{'x': 2}, [['a', None, 3]]]), {'x': 2, 'a': 3})
    check('source provided', solve([{'a': 2}, [['b', 'a', 3]]]), {'a': 2, 'b': 5})
    check('no defaults', solve([{'a': 2}, []]), {'a': 2})
elif N == 3:
    check('forward dependency', solve([{}, [['b', 'a', 2], ['a', None, 3]]]), {'a': 3, 'b': 5})
    check('explicit null', solve([{'a': None}, [['a', None, 3], ['b', 'a', 1]]]), {'a': None, 'b': None})
    check('explicit zero', solve([{'a': 0}, [['a', None, 3], ['b', 'a', 2]]]), {'a': 0, 'b': 2})
    check('dependency cycle', solve([{}, [['a', 'b', 1], ['b', 'a', 1]]]), 'DEFAULT_CYCLE')
    check('provided unrelated', solve([{'x': 3}, [['a', None, 4]]]), {'x': 3, 'a': 4})
    check('source provided', solve([{'a': 3}, [['b', 'a', 3]]]), {'a': 3, 'b': 6})
    check('no defaults', solve([{'a': 3}, []]), {'a': 3})
elif N == 4:
    check('forward dependency', solve([{}, [['b', 'a', 2], ['a', None, 4]]]), {'a': 4, 'b': 6})
    check('explicit null', solve([{'a': None}, [['a', None, 4], ['b', 'a', 1]]]), {'a': None, 'b': None})
    check('explicit zero', solve([{'a': 0}, [['a', None, 4], ['b', 'a', 2]]]), {'a': 0, 'b': 2})
    check('dependency cycle', solve([{}, [['a', 'b', 1], ['b', 'a', 1]]]), 'DEFAULT_CYCLE')
    check('provided unrelated', solve([{'x': 4}, [['a', None, 5]]]), {'x': 4, 'a': 5})
    check('source provided', solve([{'a': 4}, [['b', 'a', 3]]]), {'a': 4, 'b': 7})
    check('no defaults', solve([{'a': 4}, []]), {'a': 4})
elif N == 5:
    check('forward dependency', solve([{}, [['b', 'a', 2], ['a', None, 5]]]), {'a': 5, 'b': 7})
    check('explicit null', solve([{'a': None}, [['a', None, 5], ['b', 'a', 1]]]), {'a': None, 'b': None})
    check('explicit zero', solve([{'a': 0}, [['a', None, 5], ['b', 'a', 2]]]), {'a': 0, 'b': 2})
    check('dependency cycle', solve([{}, [['a', 'b', 1], ['b', 'a', 1]]]), 'DEFAULT_CYCLE')
    check('provided unrelated', solve([{'x': 5}, [['a', None, 6]]]), {'x': 5, 'a': 6})
    check('source provided', solve([{'a': 5}, [['b', 'a', 3]]]), {'a': 5, 'b': 8})
    check('no defaults', solve([{'a': 5}, []]), {'a': 5})
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:
Default evaluation discards rules whose dependencies appear later.

Materialize missing columns using ordered default rules [target,source-or-None,constant]. A constant rule writes constant; a dependent rule writes source+constant, propagating explicit null. Existing columns including None and zero never change. Resolve forward dependencies to a fixed point; unresolved dependencies return DEFAULT_CYCLE.

split: open-access


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

N = 1
observations = []
def solve(d):
    try:
        row,rules=d
        result=dict(row)
        pending=[rule for rule in rules if rule[0] not in result]
        while pending:
            progressed=False; later=[]
            for target,source,constant in pending:
                if source is not None and source not in result:
                    later.append([target,source,constant]); continue
                result[target]=constant if source is None else (constant if result[source] is None else result[source]+constant)
                progressed=True
            if not progressed: return 'DEFAULT_CYCLE'
            pending=later
        return result
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('forward dependency', solve([{}, [['b', 'a', 2], ['a', None, 1]]]), {'a': 1, 'b': 3})
    check('explicit null', solve([{'a': None}, [['a', None, 1], ['b', 'a', 1]]]), {'a': None, 'b': None})
    check('explicit zero', solve([{'a': 0}, [['a', None, 1], ['b', 'a', 2]]]), {'a': 0, 'b': 2})
    check('dependency cycle', solve([{}, [['a', 'b', 1], ['b', 'a', 1]]]), 'DEFAULT_CYCLE')
    check('provided unrelated', solve([{'x': 1}, [['a', None, 2]]]), {'x': 1, 'a': 2})
    check('source provided', solve([{'a': 1}, [['b', 'a', 3]]]), {'a': 1, 'b': 4})
    check('no defaults', solve([{'a': 1}, []]), {'a': 1})
elif N == 2:
    check('forward dependency', solve([{}, [['b', 'a', 2], ['a', None, 2]]]), {'a': 2, 'b': 4})
    check('explicit null', solve([{'a': None}, [['a', None, 2], ['b', 'a', 1]]]), {'a': None, 'b': None})
    check('explicit zero', solve([{'a': 0}, [['a', None, 2], ['b', 'a', 2]]]), {'a': 0, 'b': 2})
    check('dependency cycle', solve([{}, [['a', 'b', 1], ['b', 'a', 1]]]), 'DEFAULT_CYCLE')
    check('provided unrelated', solve([{'x': 2}, [['a', None, 3]]]), {'x': 2, 'a': 3})
    check('source provided', solve([{'a': 2}, [['b', 'a', 3]]]), {'a': 2, 'b': 5})
    check('no defaults', solve([{'a': 2}, []]), {'a': 2})
elif N == 3:
    check('forward dependency', solve([{}, [['b', 'a', 2], ['a', None, 3]]]), {'a': 3, 'b': 5})
    check('explicit null', solve([{'a': None}, [['a', None, 3], ['b', 'a', 1]]]), {'a': None, 'b': None})
    check('explicit zero', solve([{'a': 0}, [['a', None, 3], ['b', 'a', 2]]]), {'a': 0, 'b': 2})
    check('dependency cycle', solve([{}, [['a', 'b', 1], ['b', 'a', 1]]]), 'DEFAULT_CYCLE')
    check('provided unrelated', solve([{'x': 3}, [['a', None, 4]]]), {'x': 3, 'a': 4})
    check('source provided', solve([{'a': 3}, [['b', 'a', 3]]]), {'a': 3, 'b': 6})
    check('no defaults', solve([{'a': 3}, []]), {'a': 3})
elif N == 4:
    check('forward dependency', solve([{}, [['b', 'a', 2], ['a', None, 4]]]), {'a': 4, 'b': 6})
    check('explicit null', solve([{'a': None}, [['a', None, 4], ['b', 'a', 1]]]), {'a': None, 'b': None})
    check('explicit zero', solve([{'a': 0}, [['a', None, 4], ['b', 'a', 2]]]), {'a': 0, 'b': 2})
    check('dependency cycle', solve([{}, [['a', 'b', 1], ['b', 'a', 1]]]), 'DEFAULT_CYCLE')
    check('provided unrelated', solve([{'x': 4}, [['a', None, 5]]]), {'x': 4, 'a': 5})
    check('source provided', solve([{'a': 4}, [['b', 'a', 3]]]), {'a': 4, 'b': 7})
    check('no defaults', solve([{'a': 4}, []]), {'a': 4})
elif N == 5:
    check('forward dependency', solve([{}, [['b', 'a', 2], ['a', None, 5]]]), {'a': 5, 'b': 7})
    check('explicit null', solve([{'a': None}, [['a', None, 5], ['b', 'a', 1]]]), {'a': None, 'b': None})
    check('explicit zero', solve([{'a': 0}, [['a', None, 5], ['b', 'a', 2]]]), {'a': 0, 'b': 2})
    check('dependency cycle', solve([{}, [['a', 'b', 1], ['b', 'a', 1]]]), 'DEFAULT_CYCLE')
    check('provided unrelated', solve([{'x': 5}, [['a', None, 6]]]), {'x': 5, 'a': 6})
    check('source provided', solve([{'a': 5}, [['b', 'a', 3]]]), {'a': 5, 'b': 8})
    check('no defaults', solve([{'a': 5}, []]), {'a': 5})
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(d):
    try:
        row,rules=d
        result=dict(row)
        pending=[rule for rule in rules if rule[0] not in result]
        while pending:
            progressed=False; later=[]
            for target,source,constant in pending:
                if source is not None and source not in result:
                    later.append([target,source,constant]); continue
                result[target]=constant if source is None else (0 if result[source] is None else result[source]+constant)
                progressed=True
            if not progressed: return 'DEFAULT_CYCLE'
            pending=later
        return result
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('forward dependency', solve([{}, [['b', 'a', 2], ['a', None, 1]]]), {'a': 1, 'b': 3})
    check('explicit null', solve([{'a': None}, [['a', None, 1], ['b', 'a', 1]]]), {'a': None, 'b': None})
    check('explicit zero', solve([{'a': 0}, [['a', None, 1], ['b', 'a', 2]]]), {'a': 0, 'b': 2})
    check('dependency cycle', solve([{}, [['a', 'b', 1], ['b', 'a', 1]]]), 'DEFAULT_CYCLE')
    check('provided unrelated', solve([{'x': 1}, [['a', None, 2]]]), {'x': 1, 'a': 2})
    check('source provided', solve([{'a': 1}, [['b', 'a', 3]]]), {'a': 1, 'b': 4})
    check('no defaults', solve([{'a': 1}, []]), {'a': 1})
elif N == 2:
    check('forward dependency', solve([{}, [['b', 'a', 2], ['a', None, 2]]]), {'a': 2, 'b': 4})
    check('explicit null', solve([{'a': None}, [['a', None, 2], ['b', 'a', 1]]]), {'a': None, 'b': None})
    check('explicit zero', solve([{'a': 0}, [['a', None, 2], ['b', 'a', 2]]]), {'a': 0, 'b': 2})
    check('dependency cycle', solve([{}, [['a', 'b', 1], ['b', 'a', 1]]]), 'DEFAULT_CYCLE')
    check('provided unrelated', solve([{'x': 2}, [['a', None, 3]]]), {'x': 2, 'a': 3})
    check('source provided', solve([{'a': 2}, [['b', 'a', 3]]]), {'a': 2, 'b': 5})
    check('no defaults', solve([{'a': 2}, []]), {'a': 2})
elif N == 3:
    check('forward dependency', solve([{}, [['b', 'a', 2], ['a', None, 3]]]), {'a': 3, 'b': 5})
    check('explicit null', solve([{'a': None}, [['a', None, 3], ['b', 'a', 1]]]), {'a': None, 'b': None})
    check('explicit zero', solve([{'a': 0}, [['a', None, 3], ['b', 'a', 2]]]), {'a': 0, 'b': 2})
    check('dependency cycle', solve([{}, [['a', 'b', 1], ['b', 'a', 1]]]), 'DEFAULT_CYCLE')
    check('provided unrelated', solve([{'x': 3}, [['a', None, 4]]]), {'x': 3, 'a': 4})
    check('source provided', solve([{'a': 3}, [['b', 'a', 3]]]), {'a': 3, 'b': 6})
    check('no defaults', solve([{'a': 3}, []]), {'a': 3})
elif N == 4:
    check('forward dependency', solve([{}, [['b', 'a', 2], ['a', None, 4]]]), {'a': 4, 'b': 6})
    check('explicit null', solve([{'a': None}, [['a', None, 4], ['b', 'a', 1]]]), {'a': None, 'b': None})
    check('explicit zero', solve([{'a': 0}, [['a', None, 4], ['b', 'a', 2]]]), {'a': 0, 'b': 2})
    check('dependency cycle', solve([{}, [['a', 'b', 1], ['b', 'a', 1]]]), 'DEFAULT_CYCLE')
    check('provided unrelated', solve([{'x': 4}, [['a', None, 5]]]), {'x': 4, 'a': 5})
    check('source provided', solve([{'a': 4}, [['b', 'a', 3]]]), {'a': 4, 'b': 7})
    check('no defaults', solve([{'a': 4}, []]), {'a': 4})
elif N == 5:
    check('forward dependency', solve([{}, [['b', 'a', 2], ['a', None, 5]]]), {'a': 5, 'b': 7})
    check('explicit null', solve([{'a': None}, [['a', None, 5], ['b', 'a', 1]]]), {'a': None, 'b': None})
    check('explicit zero', solve([{'a': 0}, [['a', None, 5], ['b', 'a', 2]]]), {'a': 0, 'b': 2})
    check('dependency cycle', solve([{}, [['a', 'b', 1], ['b', 'a', 1]]]), 'DEFAULT_CYCLE')
    check('provided unrelated', solve([{'x': 5}, [['a', None, 6]]]), {'x': 5, 'a': 6})
    check('source provided', solve([{'a': 5}, [['b', 'a', 3]]]), {'a': 5, 'b': 8})
    check('no defaults', solve([{'a': 5}, []]), {'a': 5})
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:
Dependent defaults treat an explicit null source as zero.

Materialize missing columns using ordered default rules [target,source-or-None,constant]. A constant rule writes constant; a dependent rule writes source+constant, propagating explicit null. Existing columns including None and zero never change. Resolve forward dependencies to a fixed point; unresolved dependencies return DEFAULT_CYCLE.

split: open-access