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

N = 1
observations = []
def solve(d):
    try:
        watermark=None; pending=[]; emitted=[]; late=[]
        for kind,time,ident in d:
            if kind=='event':
                if watermark is not None and time<watermark: pending.append([time,ident])
                else: pending.append([time,ident])
            else:
                watermark=time if watermark is None else max(watermark,time)
                ready=sorted(e for e in pending if e[0]<watermark)
                emitted.extend(ready)
                pending=[e for e in pending if e[0]>=watermark]
        return [emitted,late,sorted(pending)]
    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('frontier equality', solve([['watermark', 1, None], ['event', 1, 10]]), [[], [], [[1, 10]]])
    check('regression', solve([['watermark', 4, None], ['watermark', 1, None], ['event', 2, 10]]), [[], [[2, 10]], []])
    check('frontier stays pending', solve([['event', 1, 10], ['watermark', 1, None]]), [[], [], [[1, 10]]])
    check('event time ordering', solve([['event', 3, 10], ['event', 1, 11], ['watermark', 4, None]]), [[[1, 11], [3, 10]], [], []])
    check('emit once', solve([['event', 1, 10], ['watermark', 2, None], ['watermark', 3, None]]), [[[1, 10]], [], []])
    check('late row', solve([['watermark', 3, None], ['event', 1, 10]]), [[], [[1, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 2:
    check('frontier equality', solve([['watermark', 2, None], ['event', 2, 10]]), [[], [], [[2, 10]]])
    check('regression', solve([['watermark', 5, None], ['watermark', 2, None], ['event', 3, 10]]), [[], [[3, 10]], []])
    check('frontier stays pending', solve([['event', 2, 10], ['watermark', 2, None]]), [[], [], [[2, 10]]])
    check('event time ordering', solve([['event', 4, 10], ['event', 2, 11], ['watermark', 5, None]]), [[[2, 11], [4, 10]], [], []])
    check('emit once', solve([['event', 2, 10], ['watermark', 3, None], ['watermark', 4, None]]), [[[2, 10]], [], []])
    check('late row', solve([['watermark', 4, None], ['event', 2, 10]]), [[], [[2, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 3:
    check('frontier equality', solve([['watermark', 3, None], ['event', 3, 10]]), [[], [], [[3, 10]]])
    check('regression', solve([['watermark', 6, None], ['watermark', 3, None], ['event', 4, 10]]), [[], [[4, 10]], []])
    check('frontier stays pending', solve([['event', 3, 10], ['watermark', 3, None]]), [[], [], [[3, 10]]])
    check('event time ordering', solve([['event', 5, 10], ['event', 3, 11], ['watermark', 6, None]]), [[[3, 11], [5, 10]], [], []])
    check('emit once', solve([['event', 3, 10], ['watermark', 4, None], ['watermark', 5, None]]), [[[3, 10]], [], []])
    check('late row', solve([['watermark', 5, None], ['event', 3, 10]]), [[], [[3, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 4:
    check('frontier equality', solve([['watermark', 4, None], ['event', 4, 10]]), [[], [], [[4, 10]]])
    check('regression', solve([['watermark', 7, None], ['watermark', 4, None], ['event', 5, 10]]), [[], [[5, 10]], []])
    check('frontier stays pending', solve([['event', 4, 10], ['watermark', 4, None]]), [[], [], [[4, 10]]])
    check('event time ordering', solve([['event', 6, 10], ['event', 4, 11], ['watermark', 7, None]]), [[[4, 11], [6, 10]], [], []])
    check('emit once', solve([['event', 4, 10], ['watermark', 5, None], ['watermark', 6, None]]), [[[4, 10]], [], []])
    check('late row', solve([['watermark', 6, None], ['event', 4, 10]]), [[], [[4, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 5:
    check('frontier equality', solve([['watermark', 5, None], ['event', 5, 10]]), [[], [], [[5, 10]]])
    check('regression', solve([['watermark', 8, None], ['watermark', 5, None], ['event', 6, 10]]), [[], [[6, 10]], []])
    check('frontier stays pending', solve([['event', 5, 10], ['watermark', 5, None]]), [[], [], [[5, 10]]])
    check('event time ordering', solve([['event', 7, 10], ['event', 5, 11], ['watermark', 8, None]]), [[[5, 11], [7, 10]], [], []])
    check('emit once', solve([['event', 5, 10], ['watermark', 6, None], ['watermark', 7, None]]), [[[5, 10]], [], []])
    check('late row', solve([['watermark', 7, None], ['event', 5, 10]]), [[], [[5, 10]], []])
    check('empty input', 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:
        watermark=None; pending=[]; emitted=[]; late=[]
        for kind,time,ident in d:
            if kind=='event':
                if watermark is not None and time<watermark: emitted.append([time,ident])
                else: pending.append([time,ident])
            else:
                watermark=time if watermark is None else max(watermark,time)
                ready=sorted(e for e in pending if e[0]<watermark)
                emitted.extend(ready)
                pending=[e for e in pending if e[0]>=watermark]
        return [emitted,late,sorted(pending)]
    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('frontier equality', solve([['watermark', 1, None], ['event', 1, 10]]), [[], [], [[1, 10]]])
    check('regression', solve([['watermark', 4, None], ['watermark', 1, None], ['event', 2, 10]]), [[], [[2, 10]], []])
    check('frontier stays pending', solve([['event', 1, 10], ['watermark', 1, None]]), [[], [], [[1, 10]]])
    check('event time ordering', solve([['event', 3, 10], ['event', 1, 11], ['watermark', 4, None]]), [[[1, 11], [3, 10]], [], []])
    check('emit once', solve([['event', 1, 10], ['watermark', 2, None], ['watermark', 3, None]]), [[[1, 10]], [], []])
    check('late row', solve([['watermark', 3, None], ['event', 1, 10]]), [[], [[1, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 2:
    check('frontier equality', solve([['watermark', 2, None], ['event', 2, 10]]), [[], [], [[2, 10]]])
    check('regression', solve([['watermark', 5, None], ['watermark', 2, None], ['event', 3, 10]]), [[], [[3, 10]], []])
    check('frontier stays pending', solve([['event', 2, 10], ['watermark', 2, None]]), [[], [], [[2, 10]]])
    check('event time ordering', solve([['event', 4, 10], ['event', 2, 11], ['watermark', 5, None]]), [[[2, 11], [4, 10]], [], []])
    check('emit once', solve([['event', 2, 10], ['watermark', 3, None], ['watermark', 4, None]]), [[[2, 10]], [], []])
    check('late row', solve([['watermark', 4, None], ['event', 2, 10]]), [[], [[2, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 3:
    check('frontier equality', solve([['watermark', 3, None], ['event', 3, 10]]), [[], [], [[3, 10]]])
    check('regression', solve([['watermark', 6, None], ['watermark', 3, None], ['event', 4, 10]]), [[], [[4, 10]], []])
    check('frontier stays pending', solve([['event', 3, 10], ['watermark', 3, None]]), [[], [], [[3, 10]]])
    check('event time ordering', solve([['event', 5, 10], ['event', 3, 11], ['watermark', 6, None]]), [[[3, 11], [5, 10]], [], []])
    check('emit once', solve([['event', 3, 10], ['watermark', 4, None], ['watermark', 5, None]]), [[[3, 10]], [], []])
    check('late row', solve([['watermark', 5, None], ['event', 3, 10]]), [[], [[3, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 4:
    check('frontier equality', solve([['watermark', 4, None], ['event', 4, 10]]), [[], [], [[4, 10]]])
    check('regression', solve([['watermark', 7, None], ['watermark', 4, None], ['event', 5, 10]]), [[], [[5, 10]], []])
    check('frontier stays pending', solve([['event', 4, 10], ['watermark', 4, None]]), [[], [], [[4, 10]]])
    check('event time ordering', solve([['event', 6, 10], ['event', 4, 11], ['watermark', 7, None]]), [[[4, 11], [6, 10]], [], []])
    check('emit once', solve([['event', 4, 10], ['watermark', 5, None], ['watermark', 6, None]]), [[[4, 10]], [], []])
    check('late row', solve([['watermark', 6, None], ['event', 4, 10]]), [[], [[4, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 5:
    check('frontier equality', solve([['watermark', 5, None], ['event', 5, 10]]), [[], [], [[5, 10]]])
    check('regression', solve([['watermark', 8, None], ['watermark', 5, None], ['event', 6, 10]]), [[], [[6, 10]], []])
    check('frontier stays pending', solve([['event', 5, 10], ['watermark', 5, None]]), [[], [], [[5, 10]]])
    check('event time ordering', solve([['event', 7, 10], ['event', 5, 11], ['watermark', 8, None]]), [[[5, 11], [7, 10]], [], []])
    check('emit once', solve([['event', 5, 10], ['watermark', 6, None], ['watermark', 7, None]]), [[[5, 10]], [], []])
    check('late row', solve([['watermark', 7, None], ['event', 5, 10]]), [[], [[5, 10]], []])
    check('empty input', 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:
Late events are reinserted into the pending buffer.

Process event actions [event,time,id] and watermark actions [watermark,time,None]. Maintain monotone watermark; events older than it go to late output. On a watermark, release buffered events with time strictly below watermark ordered by (time,id). Return [emitted,late,sorted-pending].

split: open-access


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

N = 1
observations = []
def solve(d):
    try:
        initial,changes,k=d
        before=dict(initial); after=dict(sorted(initial,key=lambda p:(-p[1],p[0]))[:k])
        for op,ident,score in changes:
            if op=='delete': after.pop(ident,None)
            else: after[ident]=score
        old=dict(sorted(before.items(),key=lambda p:(-p[1],p[0]))[:k])
        new=dict(sorted(after.items(),key=lambda p:(-p[1],p[0]))[:k])
        removed=[[i,s,-1] for i,s in sorted(old.items()) if i not in new or new[i]!=s]
        added=[[i,s,1] for i,s in sorted(new.items()) if i not in old or old[i]!=s]
        return removed+added
    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('delete leader', solve([[[1, 4], [2, 3], [3, 2]], [['delete', 1, None]], 1]), [[1, 4, -1], [2, 3, 1]])
    check('delete two leaders', solve([[[1, 4], [2, 3], [3, 2]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 4, -1], [3, 2, 1]])
    check('score changes in view', solve([[[1, 4], [2, 1]], [['upsert', 1, 5]], 1]), [[1, 4, -1], [1, 5, 1]])
    check('promote outsider', solve([[[1, 3], [2, 1]], [['upsert', 2, 4]], 1]), [[1, 3, -1], [2, 4, 1]])
    check('insert tie lower id', solve([[[2, 1]], [['upsert', 1, 1]], 1]), [[2, 1, -1], [1, 1, 1]])
    check('no changes', solve([[[1, 1]], [], 1]), [])
    check('zero view', solve([[[1, 1]], [['upsert', 2, 2]], 0]), [])
elif N == 2:
    check('delete leader', solve([[[1, 5], [2, 4], [3, 3]], [['delete', 1, None]], 1]), [[1, 5, -1], [2, 4, 1]])
    check('delete two leaders', solve([[[1, 5], [2, 4], [3, 3]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 5, -1], [3, 3, 1]])
    check('score changes in view', solve([[[1, 5], [2, 2]], [['upsert', 1, 6]], 1]), [[1, 5, -1], [1, 6, 1]])
    check('promote outsider', solve([[[1, 4], [2, 2]], [['upsert', 2, 5]], 1]), [[1, 4, -1], [2, 5, 1]])
    check('insert tie lower id', solve([[[2, 2]], [['upsert', 1, 2]], 1]), [[2, 2, -1], [1, 2, 1]])
    check('no changes', solve([[[1, 2]], [], 1]), [])
    check('zero view', solve([[[1, 2]], [['upsert', 2, 3]], 0]), [])
elif N == 3:
    check('delete leader', solve([[[1, 6], [2, 5], [3, 4]], [['delete', 1, None]], 1]), [[1, 6, -1], [2, 5, 1]])
    check('delete two leaders', solve([[[1, 6], [2, 5], [3, 4]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 6, -1], [3, 4, 1]])
    check('score changes in view', solve([[[1, 6], [2, 3]], [['upsert', 1, 7]], 1]), [[1, 6, -1], [1, 7, 1]])
    check('promote outsider', solve([[[1, 5], [2, 3]], [['upsert', 2, 6]], 1]), [[1, 5, -1], [2, 6, 1]])
    check('insert tie lower id', solve([[[2, 3]], [['upsert', 1, 3]], 1]), [[2, 3, -1], [1, 3, 1]])
    check('no changes', solve([[[1, 3]], [], 1]), [])
    check('zero view', solve([[[1, 3]], [['upsert', 2, 4]], 0]), [])
elif N == 4:
    check('delete leader', solve([[[1, 7], [2, 6], [3, 5]], [['delete', 1, None]], 1]), [[1, 7, -1], [2, 6, 1]])
    check('delete two leaders', solve([[[1, 7], [2, 6], [3, 5]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 7, -1], [3, 5, 1]])
    check('score changes in view', solve([[[1, 7], [2, 4]], [['upsert', 1, 8]], 1]), [[1, 7, -1], [1, 8, 1]])
    check('promote outsider', solve([[[1, 6], [2, 4]], [['upsert', 2, 7]], 1]), [[1, 6, -1], [2, 7, 1]])
    check('insert tie lower id', solve([[[2, 4]], [['upsert', 1, 4]], 1]), [[2, 4, -1], [1, 4, 1]])
    check('no changes', solve([[[1, 4]], [], 1]), [])
    check('zero view', solve([[[1, 4]], [['upsert', 2, 5]], 0]), [])
elif N == 5:
    check('delete leader', solve([[[1, 8], [2, 7], [3, 6]], [['delete', 1, None]], 1]), [[1, 8, -1], [2, 7, 1]])
    check('delete two leaders', solve([[[1, 8], [2, 7], [3, 6]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 8, -1], [3, 6, 1]])
    check('score changes in view', solve([[[1, 8], [2, 5]], [['upsert', 1, 9]], 1]), [[1, 8, -1], [1, 9, 1]])
    check('promote outsider', solve([[[1, 7], [2, 5]], [['upsert', 2, 8]], 1]), [[1, 7, -1], [2, 8, 1]])
    check('insert tie lower id', solve([[[2, 5]], [['upsert', 1, 5]], 1]), [[2, 5, -1], [1, 5, 1]])
    check('no changes', solve([[[1, 5]], [], 1]), [])
    check('zero view', solve([[[1, 5]], [['upsert', 2, 6]], 0]), [])
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:
        initial,changes,k=d
        before=dict(initial); after=dict(sorted(initial,key=lambda p:(-p[1],p[0]))[:k+1])
        for op,ident,score in changes:
            if op=='delete': after.pop(ident,None)
            else: after[ident]=score
        old=dict(sorted(before.items(),key=lambda p:(-p[1],p[0]))[:k])
        new=dict(sorted(after.items(),key=lambda p:(-p[1],p[0]))[:k])
        removed=[[i,s,-1] for i,s in sorted(old.items()) if i not in new or new[i]!=s]
        added=[[i,s,1] for i,s in sorted(new.items()) if i not in old or old[i]!=s]
        return removed+added
    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('delete leader', solve([[[1, 4], [2, 3], [3, 2]], [['delete', 1, None]], 1]), [[1, 4, -1], [2, 3, 1]])
    check('delete two leaders', solve([[[1, 4], [2, 3], [3, 2]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 4, -1], [3, 2, 1]])
    check('score changes in view', solve([[[1, 4], [2, 1]], [['upsert', 1, 5]], 1]), [[1, 4, -1], [1, 5, 1]])
    check('promote outsider', solve([[[1, 3], [2, 1]], [['upsert', 2, 4]], 1]), [[1, 3, -1], [2, 4, 1]])
    check('insert tie lower id', solve([[[2, 1]], [['upsert', 1, 1]], 1]), [[2, 1, -1], [1, 1, 1]])
    check('no changes', solve([[[1, 1]], [], 1]), [])
    check('zero view', solve([[[1, 1]], [['upsert', 2, 2]], 0]), [])
elif N == 2:
    check('delete leader', solve([[[1, 5], [2, 4], [3, 3]], [['delete', 1, None]], 1]), [[1, 5, -1], [2, 4, 1]])
    check('delete two leaders', solve([[[1, 5], [2, 4], [3, 3]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 5, -1], [3, 3, 1]])
    check('score changes in view', solve([[[1, 5], [2, 2]], [['upsert', 1, 6]], 1]), [[1, 5, -1], [1, 6, 1]])
    check('promote outsider', solve([[[1, 4], [2, 2]], [['upsert', 2, 5]], 1]), [[1, 4, -1], [2, 5, 1]])
    check('insert tie lower id', solve([[[2, 2]], [['upsert', 1, 2]], 1]), [[2, 2, -1], [1, 2, 1]])
    check('no changes', solve([[[1, 2]], [], 1]), [])
    check('zero view', solve([[[1, 2]], [['upsert', 2, 3]], 0]), [])
elif N == 3:
    check('delete leader', solve([[[1, 6], [2, 5], [3, 4]], [['delete', 1, None]], 1]), [[1, 6, -1], [2, 5, 1]])
    check('delete two leaders', solve([[[1, 6], [2, 5], [3, 4]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 6, -1], [3, 4, 1]])
    check('score changes in view', solve([[[1, 6], [2, 3]], [['upsert', 1, 7]], 1]), [[1, 6, -1], [1, 7, 1]])
    check('promote outsider', solve([[[1, 5], [2, 3]], [['upsert', 2, 6]], 1]), [[1, 5, -1], [2, 6, 1]])
    check('insert tie lower id', solve([[[2, 3]], [['upsert', 1, 3]], 1]), [[2, 3, -1], [1, 3, 1]])
    check('no changes', solve([[[1, 3]], [], 1]), [])
    check('zero view', solve([[[1, 3]], [['upsert', 2, 4]], 0]), [])
elif N == 4:
    check('delete leader', solve([[[1, 7], [2, 6], [3, 5]], [['delete', 1, None]], 1]), [[1, 7, -1], [2, 6, 1]])
    check('delete two leaders', solve([[[1, 7], [2, 6], [3, 5]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 7, -1], [3, 5, 1]])
    check('score changes in view', solve([[[1, 7], [2, 4]], [['upsert', 1, 8]], 1]), [[1, 7, -1], [1, 8, 1]])
    check('promote outsider', solve([[[1, 6], [2, 4]], [['upsert', 2, 7]], 1]), [[1, 6, -1], [2, 7, 1]])
    check('insert tie lower id', solve([[[2, 4]], [['upsert', 1, 4]], 1]), [[2, 4, -1], [1, 4, 1]])
    check('no changes', solve([[[1, 4]], [], 1]), [])
    check('zero view', solve([[[1, 4]], [['upsert', 2, 5]], 0]), [])
elif N == 5:
    check('delete leader', solve([[[1, 8], [2, 7], [3, 6]], [['delete', 1, None]], 1]), [[1, 8, -1], [2, 7, 1]])
    check('delete two leaders', solve([[[1, 8], [2, 7], [3, 6]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 8, -1], [3, 6, 1]])
    check('score changes in view', solve([[[1, 8], [2, 5]], [['upsert', 1, 9]], 1]), [[1, 8, -1], [1, 9, 1]])
    check('promote outsider', solve([[[1, 7], [2, 5]], [['upsert', 2, 8]], 1]), [[1, 7, -1], [2, 8, 1]])
    check('insert tie lower id', solve([[[2, 5]], [['upsert', 1, 5]], 1]), [[2, 5, -1], [1, 5, 1]])
    check('no changes', solve([[[1, 5]], [], 1]), [])
    check('zero view', solve([[[1, 5]], [['upsert', 2, 6]], 0]), [])
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:
Top-k maintenance drops a deleted row without backfilling from the full relation.

Maintain unique-ID scored rows with upsert/delete operations, then report changes to a top-k materialized view. Scores order descending with ascending ID ties. Retractions carry old scores; insertions carry new scores. Score updates within the top-k emit both. Return retractions sorted by ID, then insertions sorted by ID.

split: open-access


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

N = 1
observations = []
def solve(d):
    try:
        initial,changes,k=d
        before=dict(initial); after=dict(initial)
        for op,ident,score in changes:
            if op=='delete': after.pop(ident,None)
            else: after.setdefault(ident,score)
        old=dict(sorted(before.items(),key=lambda p:(-p[1],p[0]))[:k])
        new=dict(sorted(after.items(),key=lambda p:(-p[1],p[0]))[:k])
        removed=[[i,s,-1] for i,s in sorted(old.items()) if i not in new or new[i]!=s]
        added=[[i,s,1] for i,s in sorted(new.items()) if i not in old or old[i]!=s]
        return removed+added
    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('delete leader', solve([[[1, 4], [2, 3], [3, 2]], [['delete', 1, None]], 1]), [[1, 4, -1], [2, 3, 1]])
    check('delete two leaders', solve([[[1, 4], [2, 3], [3, 2]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 4, -1], [3, 2, 1]])
    check('score changes in view', solve([[[1, 4], [2, 1]], [['upsert', 1, 5]], 1]), [[1, 4, -1], [1, 5, 1]])
    check('promote outsider', solve([[[1, 3], [2, 1]], [['upsert', 2, 4]], 1]), [[1, 3, -1], [2, 4, 1]])
    check('insert tie lower id', solve([[[2, 1]], [['upsert', 1, 1]], 1]), [[2, 1, -1], [1, 1, 1]])
    check('no changes', solve([[[1, 1]], [], 1]), [])
    check('zero view', solve([[[1, 1]], [['upsert', 2, 2]], 0]), [])
elif N == 2:
    check('delete leader', solve([[[1, 5], [2, 4], [3, 3]], [['delete', 1, None]], 1]), [[1, 5, -1], [2, 4, 1]])
    check('delete two leaders', solve([[[1, 5], [2, 4], [3, 3]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 5, -1], [3, 3, 1]])
    check('score changes in view', solve([[[1, 5], [2, 2]], [['upsert', 1, 6]], 1]), [[1, 5, -1], [1, 6, 1]])
    check('promote outsider', solve([[[1, 4], [2, 2]], [['upsert', 2, 5]], 1]), [[1, 4, -1], [2, 5, 1]])
    check('insert tie lower id', solve([[[2, 2]], [['upsert', 1, 2]], 1]), [[2, 2, -1], [1, 2, 1]])
    check('no changes', solve([[[1, 2]], [], 1]), [])
    check('zero view', solve([[[1, 2]], [['upsert', 2, 3]], 0]), [])
elif N == 3:
    check('delete leader', solve([[[1, 6], [2, 5], [3, 4]], [['delete', 1, None]], 1]), [[1, 6, -1], [2, 5, 1]])
    check('delete two leaders', solve([[[1, 6], [2, 5], [3, 4]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 6, -1], [3, 4, 1]])
    check('score changes in view', solve([[[1, 6], [2, 3]], [['upsert', 1, 7]], 1]), [[1, 6, -1], [1, 7, 1]])
    check('promote outsider', solve([[[1, 5], [2, 3]], [['upsert', 2, 6]], 1]), [[1, 5, -1], [2, 6, 1]])
    check('insert tie lower id', solve([[[2, 3]], [['upsert', 1, 3]], 1]), [[2, 3, -1], [1, 3, 1]])
    check('no changes', solve([[[1, 3]], [], 1]), [])
    check('zero view', solve([[[1, 3]], [['upsert', 2, 4]], 0]), [])
elif N == 4:
    check('delete leader', solve([[[1, 7], [2, 6], [3, 5]], [['delete', 1, None]], 1]), [[1, 7, -1], [2, 6, 1]])
    check('delete two leaders', solve([[[1, 7], [2, 6], [3, 5]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 7, -1], [3, 5, 1]])
    check('score changes in view', solve([[[1, 7], [2, 4]], [['upsert', 1, 8]], 1]), [[1, 7, -1], [1, 8, 1]])
    check('promote outsider', solve([[[1, 6], [2, 4]], [['upsert', 2, 7]], 1]), [[1, 6, -1], [2, 7, 1]])
    check('insert tie lower id', solve([[[2, 4]], [['upsert', 1, 4]], 1]), [[2, 4, -1], [1, 4, 1]])
    check('no changes', solve([[[1, 4]], [], 1]), [])
    check('zero view', solve([[[1, 4]], [['upsert', 2, 5]], 0]), [])
elif N == 5:
    check('delete leader', solve([[[1, 8], [2, 7], [3, 6]], [['delete', 1, None]], 1]), [[1, 8, -1], [2, 7, 1]])
    check('delete two leaders', solve([[[1, 8], [2, 7], [3, 6]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 8, -1], [3, 6, 1]])
    check('score changes in view', solve([[[1, 8], [2, 5]], [['upsert', 1, 9]], 1]), [[1, 8, -1], [1, 9, 1]])
    check('promote outsider', solve([[[1, 7], [2, 5]], [['upsert', 2, 8]], 1]), [[1, 7, -1], [2, 8, 1]])
    check('insert tie lower id', solve([[[2, 5]], [['upsert', 1, 5]], 1]), [[2, 5, -1], [1, 5, 1]])
    check('no changes', solve([[[1, 5]], [], 1]), [])
    check('zero view', solve([[[1, 5]], [['upsert', 2, 6]], 0]), [])
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:
        initial,changes,k=d
        before=dict(initial); after=dict(initial)
        for op,ident,score in changes:
            if op=='delete': after.pop(ident,None)
            else:
                if ident not in after: after[ident]=score
        old=dict(sorted(before.items(),key=lambda p:(-p[1],p[0]))[:k])
        new=dict(sorted(after.items(),key=lambda p:(-p[1],p[0]))[:k])
        removed=[[i,s,-1] for i,s in sorted(old.items()) if i not in new or new[i]!=s]
        added=[[i,s,1] for i,s in sorted(new.items()) if i not in old or old[i]!=s]
        return removed+added
    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('delete leader', solve([[[1, 4], [2, 3], [3, 2]], [['delete', 1, None]], 1]), [[1, 4, -1], [2, 3, 1]])
    check('delete two leaders', solve([[[1, 4], [2, 3], [3, 2]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 4, -1], [3, 2, 1]])
    check('score changes in view', solve([[[1, 4], [2, 1]], [['upsert', 1, 5]], 1]), [[1, 4, -1], [1, 5, 1]])
    check('promote outsider', solve([[[1, 3], [2, 1]], [['upsert', 2, 4]], 1]), [[1, 3, -1], [2, 4, 1]])
    check('insert tie lower id', solve([[[2, 1]], [['upsert', 1, 1]], 1]), [[2, 1, -1], [1, 1, 1]])
    check('no changes', solve([[[1, 1]], [], 1]), [])
    check('zero view', solve([[[1, 1]], [['upsert', 2, 2]], 0]), [])
elif N == 2:
    check('delete leader', solve([[[1, 5], [2, 4], [3, 3]], [['delete', 1, None]], 1]), [[1, 5, -1], [2, 4, 1]])
    check('delete two leaders', solve([[[1, 5], [2, 4], [3, 3]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 5, -1], [3, 3, 1]])
    check('score changes in view', solve([[[1, 5], [2, 2]], [['upsert', 1, 6]], 1]), [[1, 5, -1], [1, 6, 1]])
    check('promote outsider', solve([[[1, 4], [2, 2]], [['upsert', 2, 5]], 1]), [[1, 4, -1], [2, 5, 1]])
    check('insert tie lower id', solve([[[2, 2]], [['upsert', 1, 2]], 1]), [[2, 2, -1], [1, 2, 1]])
    check('no changes', solve([[[1, 2]], [], 1]), [])
    check('zero view', solve([[[1, 2]], [['upsert', 2, 3]], 0]), [])
elif N == 3:
    check('delete leader', solve([[[1, 6], [2, 5], [3, 4]], [['delete', 1, None]], 1]), [[1, 6, -1], [2, 5, 1]])
    check('delete two leaders', solve([[[1, 6], [2, 5], [3, 4]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 6, -1], [3, 4, 1]])
    check('score changes in view', solve([[[1, 6], [2, 3]], [['upsert', 1, 7]], 1]), [[1, 6, -1], [1, 7, 1]])
    check('promote outsider', solve([[[1, 5], [2, 3]], [['upsert', 2, 6]], 1]), [[1, 5, -1], [2, 6, 1]])
    check('insert tie lower id', solve([[[2, 3]], [['upsert', 1, 3]], 1]), [[2, 3, -1], [1, 3, 1]])
    check('no changes', solve([[[1, 3]], [], 1]), [])
    check('zero view', solve([[[1, 3]], [['upsert', 2, 4]], 0]), [])
elif N == 4:
    check('delete leader', solve([[[1, 7], [2, 6], [3, 5]], [['delete', 1, None]], 1]), [[1, 7, -1], [2, 6, 1]])
    check('delete two leaders', solve([[[1, 7], [2, 6], [3, 5]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 7, -1], [3, 5, 1]])
    check('score changes in view', solve([[[1, 7], [2, 4]], [['upsert', 1, 8]], 1]), [[1, 7, -1], [1, 8, 1]])
    check('promote outsider', solve([[[1, 6], [2, 4]], [['upsert', 2, 7]], 1]), [[1, 6, -1], [2, 7, 1]])
    check('insert tie lower id', solve([[[2, 4]], [['upsert', 1, 4]], 1]), [[2, 4, -1], [1, 4, 1]])
    check('no changes', solve([[[1, 4]], [], 1]), [])
    check('zero view', solve([[[1, 4]], [['upsert', 2, 5]], 0]), [])
elif N == 5:
    check('delete leader', solve([[[1, 8], [2, 7], [3, 6]], [['delete', 1, None]], 1]), [[1, 8, -1], [2, 7, 1]])
    check('delete two leaders', solve([[[1, 8], [2, 7], [3, 6]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 8, -1], [3, 6, 1]])
    check('score changes in view', solve([[[1, 8], [2, 5]], [['upsert', 1, 9]], 1]), [[1, 8, -1], [1, 9, 1]])
    check('promote outsider', solve([[[1, 7], [2, 5]], [['upsert', 2, 8]], 1]), [[1, 7, -1], [2, 8, 1]])
    check('insert tie lower id', solve([[[2, 5]], [['upsert', 1, 5]], 1]), [[2, 5, -1], [1, 5, 1]])
    check('no changes', solve([[[1, 5]], [], 1]), [])
    check('zero view', solve([[[1, 5]], [['upsert', 2, 6]], 0]), [])
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:
Top-k maintenance treats score updates as insert-if-absent.

Maintain unique-ID scored rows with upsert/delete operations, then report changes to a top-k materialized view. Scores order descending with ascending ID ties. Retractions carry old scores; insertions carry new scores. Score updates within the top-k emit both. Return retractions sorted by ID, then insertions sorted by ID.

split: open-access


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

N = 1
observations = []
def solve(d):
    try:
        initial,changes,k=d
        before=dict(initial); after=dict(initial)
        for op,ident,score in changes:
            if op=='delete': after.pop(ident,None)
            else: after[ident]=score
        old=dict(sorted(before.items(),key=lambda p:(-p[1],p[0]))[:k])
        new=dict(sorted(after.items(),key=lambda p:(-p[1],p[0]))[:k])
        removed=[[i,after.get(i),-1] for i,s in sorted(old.items()) if i not in new or new[i]!=s]
        added=[[i,s,1] for i,s in sorted(new.items()) if i not in old or old[i]!=s]
        return removed+added
    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('delete leader', solve([[[1, 4], [2, 3], [3, 2]], [['delete', 1, None]], 1]), [[1, 4, -1], [2, 3, 1]])
    check('delete two leaders', solve([[[1, 4], [2, 3], [3, 2]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 4, -1], [3, 2, 1]])
    check('score changes in view', solve([[[1, 4], [2, 1]], [['upsert', 1, 5]], 1]), [[1, 4, -1], [1, 5, 1]])
    check('promote outsider', solve([[[1, 3], [2, 1]], [['upsert', 2, 4]], 1]), [[1, 3, -1], [2, 4, 1]])
    check('insert tie lower id', solve([[[2, 1]], [['upsert', 1, 1]], 1]), [[2, 1, -1], [1, 1, 1]])
    check('no changes', solve([[[1, 1]], [], 1]), [])
    check('zero view', solve([[[1, 1]], [['upsert', 2, 2]], 0]), [])
elif N == 2:
    check('delete leader', solve([[[1, 5], [2, 4], [3, 3]], [['delete', 1, None]], 1]), [[1, 5, -1], [2, 4, 1]])
    check('delete two leaders', solve([[[1, 5], [2, 4], [3, 3]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 5, -1], [3, 3, 1]])
    check('score changes in view', solve([[[1, 5], [2, 2]], [['upsert', 1, 6]], 1]), [[1, 5, -1], [1, 6, 1]])
    check('promote outsider', solve([[[1, 4], [2, 2]], [['upsert', 2, 5]], 1]), [[1, 4, -1], [2, 5, 1]])
    check('insert tie lower id', solve([[[2, 2]], [['upsert', 1, 2]], 1]), [[2, 2, -1], [1, 2, 1]])
    check('no changes', solve([[[1, 2]], [], 1]), [])
    check('zero view', solve([[[1, 2]], [['upsert', 2, 3]], 0]), [])
elif N == 3:
    check('delete leader', solve([[[1, 6], [2, 5], [3, 4]], [['delete', 1, None]], 1]), [[1, 6, -1], [2, 5, 1]])
    check('delete two leaders', solve([[[1, 6], [2, 5], [3, 4]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 6, -1], [3, 4, 1]])
    check('score changes in view', solve([[[1, 6], [2, 3]], [['upsert', 1, 7]], 1]), [[1, 6, -1], [1, 7, 1]])
    check('promote outsider', solve([[[1, 5], [2, 3]], [['upsert', 2, 6]], 1]), [[1, 5, -1], [2, 6, 1]])
    check('insert tie lower id', solve([[[2, 3]], [['upsert', 1, 3]], 1]), [[2, 3, -1], [1, 3, 1]])
    check('no changes', solve([[[1, 3]], [], 1]), [])
    check('zero view', solve([[[1, 3]], [['upsert', 2, 4]], 0]), [])
elif N == 4:
    check('delete leader', solve([[[1, 7], [2, 6], [3, 5]], [['delete', 1, None]], 1]), [[1, 7, -1], [2, 6, 1]])
    check('delete two leaders', solve([[[1, 7], [2, 6], [3, 5]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 7, -1], [3, 5, 1]])
    check('score changes in view', solve([[[1, 7], [2, 4]], [['upsert', 1, 8]], 1]), [[1, 7, -1], [1, 8, 1]])
    check('promote outsider', solve([[[1, 6], [2, 4]], [['upsert', 2, 7]], 1]), [[1, 6, -1], [2, 7, 1]])
    check('insert tie lower id', solve([[[2, 4]], [['upsert', 1, 4]], 1]), [[2, 4, -1], [1, 4, 1]])
    check('no changes', solve([[[1, 4]], [], 1]), [])
    check('zero view', solve([[[1, 4]], [['upsert', 2, 5]], 0]), [])
elif N == 5:
    check('delete leader', solve([[[1, 8], [2, 7], [3, 6]], [['delete', 1, None]], 1]), [[1, 8, -1], [2, 7, 1]])
    check('delete two leaders', solve([[[1, 8], [2, 7], [3, 6]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 8, -1], [3, 6, 1]])
    check('score changes in view', solve([[[1, 8], [2, 5]], [['upsert', 1, 9]], 1]), [[1, 8, -1], [1, 9, 1]])
    check('promote outsider', solve([[[1, 7], [2, 5]], [['upsert', 2, 8]], 1]), [[1, 7, -1], [2, 8, 1]])
    check('insert tie lower id', solve([[[2, 5]], [['upsert', 1, 5]], 1]), [[2, 5, -1], [1, 5, 1]])
    check('no changes', solve([[[1, 5]], [], 1]), [])
    check('zero view', solve([[[1, 5]], [['upsert', 2, 6]], 0]), [])
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:
        initial,changes,k=d
        before=dict(initial); after=dict(initial)
        for op,ident,score in changes:
            if op=='delete': after.pop(ident,None)
            else: after[ident]=score
        old=dict(sorted(before.items(),key=lambda p:(-p[1],p[0]))[:k])
        new=dict(sorted(after.items(),key=lambda p:(-p[1],p[0]))[:k])
        removed=[[i,new.get(i),-1] for i,s in sorted(old.items()) if i not in new or new[i]!=s]
        added=[[i,s,1] for i,s in sorted(new.items()) if i not in old or old[i]!=s]
        return removed+added
    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('delete leader', solve([[[1, 4], [2, 3], [3, 2]], [['delete', 1, None]], 1]), [[1, 4, -1], [2, 3, 1]])
    check('delete two leaders', solve([[[1, 4], [2, 3], [3, 2]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 4, -1], [3, 2, 1]])
    check('score changes in view', solve([[[1, 4], [2, 1]], [['upsert', 1, 5]], 1]), [[1, 4, -1], [1, 5, 1]])
    check('promote outsider', solve([[[1, 3], [2, 1]], [['upsert', 2, 4]], 1]), [[1, 3, -1], [2, 4, 1]])
    check('insert tie lower id', solve([[[2, 1]], [['upsert', 1, 1]], 1]), [[2, 1, -1], [1, 1, 1]])
    check('no changes', solve([[[1, 1]], [], 1]), [])
    check('zero view', solve([[[1, 1]], [['upsert', 2, 2]], 0]), [])
elif N == 2:
    check('delete leader', solve([[[1, 5], [2, 4], [3, 3]], [['delete', 1, None]], 1]), [[1, 5, -1], [2, 4, 1]])
    check('delete two leaders', solve([[[1, 5], [2, 4], [3, 3]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 5, -1], [3, 3, 1]])
    check('score changes in view', solve([[[1, 5], [2, 2]], [['upsert', 1, 6]], 1]), [[1, 5, -1], [1, 6, 1]])
    check('promote outsider', solve([[[1, 4], [2, 2]], [['upsert', 2, 5]], 1]), [[1, 4, -1], [2, 5, 1]])
    check('insert tie lower id', solve([[[2, 2]], [['upsert', 1, 2]], 1]), [[2, 2, -1], [1, 2, 1]])
    check('no changes', solve([[[1, 2]], [], 1]), [])
    check('zero view', solve([[[1, 2]], [['upsert', 2, 3]], 0]), [])
elif N == 3:
    check('delete leader', solve([[[1, 6], [2, 5], [3, 4]], [['delete', 1, None]], 1]), [[1, 6, -1], [2, 5, 1]])
    check('delete two leaders', solve([[[1, 6], [2, 5], [3, 4]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 6, -1], [3, 4, 1]])
    check('score changes in view', solve([[[1, 6], [2, 3]], [['upsert', 1, 7]], 1]), [[1, 6, -1], [1, 7, 1]])
    check('promote outsider', solve([[[1, 5], [2, 3]], [['upsert', 2, 6]], 1]), [[1, 5, -1], [2, 6, 1]])
    check('insert tie lower id', solve([[[2, 3]], [['upsert', 1, 3]], 1]), [[2, 3, -1], [1, 3, 1]])
    check('no changes', solve([[[1, 3]], [], 1]), [])
    check('zero view', solve([[[1, 3]], [['upsert', 2, 4]], 0]), [])
elif N == 4:
    check('delete leader', solve([[[1, 7], [2, 6], [3, 5]], [['delete', 1, None]], 1]), [[1, 7, -1], [2, 6, 1]])
    check('delete two leaders', solve([[[1, 7], [2, 6], [3, 5]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 7, -1], [3, 5, 1]])
    check('score changes in view', solve([[[1, 7], [2, 4]], [['upsert', 1, 8]], 1]), [[1, 7, -1], [1, 8, 1]])
    check('promote outsider', solve([[[1, 6], [2, 4]], [['upsert', 2, 7]], 1]), [[1, 6, -1], [2, 7, 1]])
    check('insert tie lower id', solve([[[2, 4]], [['upsert', 1, 4]], 1]), [[2, 4, -1], [1, 4, 1]])
    check('no changes', solve([[[1, 4]], [], 1]), [])
    check('zero view', solve([[[1, 4]], [['upsert', 2, 5]], 0]), [])
elif N == 5:
    check('delete leader', solve([[[1, 8], [2, 7], [3, 6]], [['delete', 1, None]], 1]), [[1, 8, -1], [2, 7, 1]])
    check('delete two leaders', solve([[[1, 8], [2, 7], [3, 6]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 8, -1], [3, 6, 1]])
    check('score changes in view', solve([[[1, 8], [2, 5]], [['upsert', 1, 9]], 1]), [[1, 8, -1], [1, 9, 1]])
    check('promote outsider', solve([[[1, 7], [2, 5]], [['upsert', 2, 8]], 1]), [[1, 7, -1], [2, 8, 1]])
    check('insert tie lower id', solve([[[2, 5]], [['upsert', 1, 5]], 1]), [[2, 5, -1], [1, 5, 1]])
    check('no changes', solve([[[1, 5]], [], 1]), [])
    check('zero view', solve([[[1, 5]], [['upsert', 2, 6]], 0]), [])
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:
Top-k retractions carry updated scores instead of old scores.

Maintain unique-ID scored rows with upsert/delete operations, then report changes to a top-k materialized view. Scores order descending with ascending ID ties. Retractions carry old scores; insertions carry new scores. Score updates within the top-k emit both. Return retractions sorted by ID, then insertions sorted by ID.

split: open-access


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

N = 1
observations = []
def solve(d):
    try:
        initial,changes,k=d
        before=dict(initial); after=dict(initial)
        for op,ident,score in changes:
            if op=='delete': after.pop(ident,None)
            else: after[ident]=score
        old=dict(sorted(before.items(),key=lambda p:(-p[1],p[0]))[:k])
        new=dict(sorted(after.items(),key=lambda p:(-p[1],p[0]))[:k])
        removed=[[i,s,-1] for i,s in sorted(old.items()) if i not in new]
        added=[[i,s,1] for i,s in sorted(new.items()) if i not in old or old[i]!=s]
        return removed+added
    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('delete leader', solve([[[1, 4], [2, 3], [3, 2]], [['delete', 1, None]], 1]), [[1, 4, -1], [2, 3, 1]])
    check('delete two leaders', solve([[[1, 4], [2, 3], [3, 2]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 4, -1], [3, 2, 1]])
    check('score changes in view', solve([[[1, 4], [2, 1]], [['upsert', 1, 5]], 1]), [[1, 4, -1], [1, 5, 1]])
    check('promote outsider', solve([[[1, 3], [2, 1]], [['upsert', 2, 4]], 1]), [[1, 3, -1], [2, 4, 1]])
    check('insert tie lower id', solve([[[2, 1]], [['upsert', 1, 1]], 1]), [[2, 1, -1], [1, 1, 1]])
    check('no changes', solve([[[1, 1]], [], 1]), [])
    check('zero view', solve([[[1, 1]], [['upsert', 2, 2]], 0]), [])
elif N == 2:
    check('delete leader', solve([[[1, 5], [2, 4], [3, 3]], [['delete', 1, None]], 1]), [[1, 5, -1], [2, 4, 1]])
    check('delete two leaders', solve([[[1, 5], [2, 4], [3, 3]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 5, -1], [3, 3, 1]])
    check('score changes in view', solve([[[1, 5], [2, 2]], [['upsert', 1, 6]], 1]), [[1, 5, -1], [1, 6, 1]])
    check('promote outsider', solve([[[1, 4], [2, 2]], [['upsert', 2, 5]], 1]), [[1, 4, -1], [2, 5, 1]])
    check('insert tie lower id', solve([[[2, 2]], [['upsert', 1, 2]], 1]), [[2, 2, -1], [1, 2, 1]])
    check('no changes', solve([[[1, 2]], [], 1]), [])
    check('zero view', solve([[[1, 2]], [['upsert', 2, 3]], 0]), [])
elif N == 3:
    check('delete leader', solve([[[1, 6], [2, 5], [3, 4]], [['delete', 1, None]], 1]), [[1, 6, -1], [2, 5, 1]])
    check('delete two leaders', solve([[[1, 6], [2, 5], [3, 4]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 6, -1], [3, 4, 1]])
    check('score changes in view', solve([[[1, 6], [2, 3]], [['upsert', 1, 7]], 1]), [[1, 6, -1], [1, 7, 1]])
    check('promote outsider', solve([[[1, 5], [2, 3]], [['upsert', 2, 6]], 1]), [[1, 5, -1], [2, 6, 1]])
    check('insert tie lower id', solve([[[2, 3]], [['upsert', 1, 3]], 1]), [[2, 3, -1], [1, 3, 1]])
    check('no changes', solve([[[1, 3]], [], 1]), [])
    check('zero view', solve([[[1, 3]], [['upsert', 2, 4]], 0]), [])
elif N == 4:
    check('delete leader', solve([[[1, 7], [2, 6], [3, 5]], [['delete', 1, None]], 1]), [[1, 7, -1], [2, 6, 1]])
    check('delete two leaders', solve([[[1, 7], [2, 6], [3, 5]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 7, -1], [3, 5, 1]])
    check('score changes in view', solve([[[1, 7], [2, 4]], [['upsert', 1, 8]], 1]), [[1, 7, -1], [1, 8, 1]])
    check('promote outsider', solve([[[1, 6], [2, 4]], [['upsert', 2, 7]], 1]), [[1, 6, -1], [2, 7, 1]])
    check('insert tie lower id', solve([[[2, 4]], [['upsert', 1, 4]], 1]), [[2, 4, -1], [1, 4, 1]])
    check('no changes', solve([[[1, 4]], [], 1]), [])
    check('zero view', solve([[[1, 4]], [['upsert', 2, 5]], 0]), [])
elif N == 5:
    check('delete leader', solve([[[1, 8], [2, 7], [3, 6]], [['delete', 1, None]], 1]), [[1, 8, -1], [2, 7, 1]])
    check('delete two leaders', solve([[[1, 8], [2, 7], [3, 6]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 8, -1], [3, 6, 1]])
    check('score changes in view', solve([[[1, 8], [2, 5]], [['upsert', 1, 9]], 1]), [[1, 8, -1], [1, 9, 1]])
    check('promote outsider', solve([[[1, 7], [2, 5]], [['upsert', 2, 8]], 1]), [[1, 7, -1], [2, 8, 1]])
    check('insert tie lower id', solve([[[2, 5]], [['upsert', 1, 5]], 1]), [[2, 5, -1], [1, 5, 1]])
    check('no changes', solve([[[1, 5]], [], 1]), [])
    check('zero view', solve([[[1, 5]], [['upsert', 2, 6]], 0]), [])
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:
        initial,changes,k=d
        before=dict(initial); after=dict(initial)
        for op,ident,score in changes:
            if op=='delete': after.pop(ident,None)
            else: after[ident]=score
        old=dict(sorted(before.items(),key=lambda p:(-p[1],p[0]))[:k])
        new=dict(sorted(after.items(),key=lambda p:(-p[1],p[0]))[:k])
        removed=[[i,s,-1] for i,s in sorted(old.items()) if i not in new and new.get(i)!=s]
        added=[[i,s,1] for i,s in sorted(new.items()) if i not in old or old[i]!=s]
        return removed+added
    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('delete leader', solve([[[1, 4], [2, 3], [3, 2]], [['delete', 1, None]], 1]), [[1, 4, -1], [2, 3, 1]])
    check('delete two leaders', solve([[[1, 4], [2, 3], [3, 2]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 4, -1], [3, 2, 1]])
    check('score changes in view', solve([[[1, 4], [2, 1]], [['upsert', 1, 5]], 1]), [[1, 4, -1], [1, 5, 1]])
    check('promote outsider', solve([[[1, 3], [2, 1]], [['upsert', 2, 4]], 1]), [[1, 3, -1], [2, 4, 1]])
    check('insert tie lower id', solve([[[2, 1]], [['upsert', 1, 1]], 1]), [[2, 1, -1], [1, 1, 1]])
    check('no changes', solve([[[1, 1]], [], 1]), [])
    check('zero view', solve([[[1, 1]], [['upsert', 2, 2]], 0]), [])
elif N == 2:
    check('delete leader', solve([[[1, 5], [2, 4], [3, 3]], [['delete', 1, None]], 1]), [[1, 5, -1], [2, 4, 1]])
    check('delete two leaders', solve([[[1, 5], [2, 4], [3, 3]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 5, -1], [3, 3, 1]])
    check('score changes in view', solve([[[1, 5], [2, 2]], [['upsert', 1, 6]], 1]), [[1, 5, -1], [1, 6, 1]])
    check('promote outsider', solve([[[1, 4], [2, 2]], [['upsert', 2, 5]], 1]), [[1, 4, -1], [2, 5, 1]])
    check('insert tie lower id', solve([[[2, 2]], [['upsert', 1, 2]], 1]), [[2, 2, -1], [1, 2, 1]])
    check('no changes', solve([[[1, 2]], [], 1]), [])
    check('zero view', solve([[[1, 2]], [['upsert', 2, 3]], 0]), [])
elif N == 3:
    check('delete leader', solve([[[1, 6], [2, 5], [3, 4]], [['delete', 1, None]], 1]), [[1, 6, -1], [2, 5, 1]])
    check('delete two leaders', solve([[[1, 6], [2, 5], [3, 4]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 6, -1], [3, 4, 1]])
    check('score changes in view', solve([[[1, 6], [2, 3]], [['upsert', 1, 7]], 1]), [[1, 6, -1], [1, 7, 1]])
    check('promote outsider', solve([[[1, 5], [2, 3]], [['upsert', 2, 6]], 1]), [[1, 5, -1], [2, 6, 1]])
    check('insert tie lower id', solve([[[2, 3]], [['upsert', 1, 3]], 1]), [[2, 3, -1], [1, 3, 1]])
    check('no changes', solve([[[1, 3]], [], 1]), [])
    check('zero view', solve([[[1, 3]], [['upsert', 2, 4]], 0]), [])
elif N == 4:
    check('delete leader', solve([[[1, 7], [2, 6], [3, 5]], [['delete', 1, None]], 1]), [[1, 7, -1], [2, 6, 1]])
    check('delete two leaders', solve([[[1, 7], [2, 6], [3, 5]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 7, -1], [3, 5, 1]])
    check('score changes in view', solve([[[1, 7], [2, 4]], [['upsert', 1, 8]], 1]), [[1, 7, -1], [1, 8, 1]])
    check('promote outsider', solve([[[1, 6], [2, 4]], [['upsert', 2, 7]], 1]), [[1, 6, -1], [2, 7, 1]])
    check('insert tie lower id', solve([[[2, 4]], [['upsert', 1, 4]], 1]), [[2, 4, -1], [1, 4, 1]])
    check('no changes', solve([[[1, 4]], [], 1]), [])
    check('zero view', solve([[[1, 4]], [['upsert', 2, 5]], 0]), [])
elif N == 5:
    check('delete leader', solve([[[1, 8], [2, 7], [3, 6]], [['delete', 1, None]], 1]), [[1, 8, -1], [2, 7, 1]])
    check('delete two leaders', solve([[[1, 8], [2, 7], [3, 6]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 8, -1], [3, 6, 1]])
    check('score changes in view', solve([[[1, 8], [2, 5]], [['upsert', 1, 9]], 1]), [[1, 8, -1], [1, 9, 1]])
    check('promote outsider', solve([[[1, 7], [2, 5]], [['upsert', 2, 8]], 1]), [[1, 7, -1], [2, 8, 1]])
    check('insert tie lower id', solve([[[2, 5]], [['upsert', 1, 5]], 1]), [[2, 5, -1], [1, 5, 1]])
    check('no changes', solve([[[1, 5]], [], 1]), [])
    check('zero view', solve([[[1, 5]], [['upsert', 2, 6]], 0]), [])
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:
Top-k suppresses retractions for score changes of surviving IDs.

Maintain unique-ID scored rows with upsert/delete operations, then report changes to a top-k materialized view. Scores order descending with ascending ID ties. Retractions carry old scores; insertions carry new scores. Score updates within the top-k emit both. Return retractions sorted by ID, then insertions sorted by ID.

split: open-access


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

N = 1
observations = []
def solve(d):
    try:
        initial,changes,k=d
        before=dict(initial); after=dict(initial)
        for op,ident,score in changes:
            if op=='delete': after.pop(ident,None)
            else: after[ident]=score
        old=dict(sorted(before.items(),key=lambda p:(-p[1],p[0]))[:k])
        new=dict(sorted(after.items(),key=lambda p:(-p[1],p[0]))[:k])
        removed=[[i,s,-1] for i,s in sorted(old.items()) if i not in new or new[i]!=s]
        added=[[i,s,1] for i,s in sorted(new.items()) if i not in old]
        return removed+added
    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('delete leader', solve([[[1, 4], [2, 3], [3, 2]], [['delete', 1, None]], 1]), [[1, 4, -1], [2, 3, 1]])
    check('delete two leaders', solve([[[1, 4], [2, 3], [3, 2]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 4, -1], [3, 2, 1]])
    check('score changes in view', solve([[[1, 4], [2, 1]], [['upsert', 1, 5]], 1]), [[1, 4, -1], [1, 5, 1]])
    check('promote outsider', solve([[[1, 3], [2, 1]], [['upsert', 2, 4]], 1]), [[1, 3, -1], [2, 4, 1]])
    check('insert tie lower id', solve([[[2, 1]], [['upsert', 1, 1]], 1]), [[2, 1, -1], [1, 1, 1]])
    check('no changes', solve([[[1, 1]], [], 1]), [])
    check('zero view', solve([[[1, 1]], [['upsert', 2, 2]], 0]), [])
elif N == 2:
    check('delete leader', solve([[[1, 5], [2, 4], [3, 3]], [['delete', 1, None]], 1]), [[1, 5, -1], [2, 4, 1]])
    check('delete two leaders', solve([[[1, 5], [2, 4], [3, 3]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 5, -1], [3, 3, 1]])
    check('score changes in view', solve([[[1, 5], [2, 2]], [['upsert', 1, 6]], 1]), [[1, 5, -1], [1, 6, 1]])
    check('promote outsider', solve([[[1, 4], [2, 2]], [['upsert', 2, 5]], 1]), [[1, 4, -1], [2, 5, 1]])
    check('insert tie lower id', solve([[[2, 2]], [['upsert', 1, 2]], 1]), [[2, 2, -1], [1, 2, 1]])
    check('no changes', solve([[[1, 2]], [], 1]), [])
    check('zero view', solve([[[1, 2]], [['upsert', 2, 3]], 0]), [])
elif N == 3:
    check('delete leader', solve([[[1, 6], [2, 5], [3, 4]], [['delete', 1, None]], 1]), [[1, 6, -1], [2, 5, 1]])
    check('delete two leaders', solve([[[1, 6], [2, 5], [3, 4]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 6, -1], [3, 4, 1]])
    check('score changes in view', solve([[[1, 6], [2, 3]], [['upsert', 1, 7]], 1]), [[1, 6, -1], [1, 7, 1]])
    check('promote outsider', solve([[[1, 5], [2, 3]], [['upsert', 2, 6]], 1]), [[1, 5, -1], [2, 6, 1]])
    check('insert tie lower id', solve([[[2, 3]], [['upsert', 1, 3]], 1]), [[2, 3, -1], [1, 3, 1]])
    check('no changes', solve([[[1, 3]], [], 1]), [])
    check('zero view', solve([[[1, 3]], [['upsert', 2, 4]], 0]), [])
elif N == 4:
    check('delete leader', solve([[[1, 7], [2, 6], [3, 5]], [['delete', 1, None]], 1]), [[1, 7, -1], [2, 6, 1]])
    check('delete two leaders', solve([[[1, 7], [2, 6], [3, 5]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 7, -1], [3, 5, 1]])
    check('score changes in view', solve([[[1, 7], [2, 4]], [['upsert', 1, 8]], 1]), [[1, 7, -1], [1, 8, 1]])
    check('promote outsider', solve([[[1, 6], [2, 4]], [['upsert', 2, 7]], 1]), [[1, 6, -1], [2, 7, 1]])
    check('insert tie lower id', solve([[[2, 4]], [['upsert', 1, 4]], 1]), [[2, 4, -1], [1, 4, 1]])
    check('no changes', solve([[[1, 4]], [], 1]), [])
    check('zero view', solve([[[1, 4]], [['upsert', 2, 5]], 0]), [])
elif N == 5:
    check('delete leader', solve([[[1, 8], [2, 7], [3, 6]], [['delete', 1, None]], 1]), [[1, 8, -1], [2, 7, 1]])
    check('delete two leaders', solve([[[1, 8], [2, 7], [3, 6]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 8, -1], [3, 6, 1]])
    check('score changes in view', solve([[[1, 8], [2, 5]], [['upsert', 1, 9]], 1]), [[1, 8, -1], [1, 9, 1]])
    check('promote outsider', solve([[[1, 7], [2, 5]], [['upsert', 2, 8]], 1]), [[1, 7, -1], [2, 8, 1]])
    check('insert tie lower id', solve([[[2, 5]], [['upsert', 1, 5]], 1]), [[2, 5, -1], [1, 5, 1]])
    check('no changes', solve([[[1, 5]], [], 1]), [])
    check('zero view', solve([[[1, 5]], [['upsert', 2, 6]], 0]), [])
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:
        initial,changes,k=d
        before=dict(initial); after=dict(initial)
        for op,ident,score in changes:
            if op=='delete': after.pop(ident,None)
            else: after[ident]=score
        old=dict(sorted(before.items(),key=lambda p:(-p[1],p[0]))[:k])
        new=dict(sorted(after.items(),key=lambda p:(-p[1],p[0]))[:k])
        removed=[[i,s,-1] for i,s in sorted(old.items()) if i not in new or new[i]!=s]
        added=[[i,s,1] for i,s in sorted(new.items()) if i not in old and old.get(i)!=s]
        return removed+added
    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('delete leader', solve([[[1, 4], [2, 3], [3, 2]], [['delete', 1, None]], 1]), [[1, 4, -1], [2, 3, 1]])
    check('delete two leaders', solve([[[1, 4], [2, 3], [3, 2]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 4, -1], [3, 2, 1]])
    check('score changes in view', solve([[[1, 4], [2, 1]], [['upsert', 1, 5]], 1]), [[1, 4, -1], [1, 5, 1]])
    check('promote outsider', solve([[[1, 3], [2, 1]], [['upsert', 2, 4]], 1]), [[1, 3, -1], [2, 4, 1]])
    check('insert tie lower id', solve([[[2, 1]], [['upsert', 1, 1]], 1]), [[2, 1, -1], [1, 1, 1]])
    check('no changes', solve([[[1, 1]], [], 1]), [])
    check('zero view', solve([[[1, 1]], [['upsert', 2, 2]], 0]), [])
elif N == 2:
    check('delete leader', solve([[[1, 5], [2, 4], [3, 3]], [['delete', 1, None]], 1]), [[1, 5, -1], [2, 4, 1]])
    check('delete two leaders', solve([[[1, 5], [2, 4], [3, 3]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 5, -1], [3, 3, 1]])
    check('score changes in view', solve([[[1, 5], [2, 2]], [['upsert', 1, 6]], 1]), [[1, 5, -1], [1, 6, 1]])
    check('promote outsider', solve([[[1, 4], [2, 2]], [['upsert', 2, 5]], 1]), [[1, 4, -1], [2, 5, 1]])
    check('insert tie lower id', solve([[[2, 2]], [['upsert', 1, 2]], 1]), [[2, 2, -1], [1, 2, 1]])
    check('no changes', solve([[[1, 2]], [], 1]), [])
    check('zero view', solve([[[1, 2]], [['upsert', 2, 3]], 0]), [])
elif N == 3:
    check('delete leader', solve([[[1, 6], [2, 5], [3, 4]], [['delete', 1, None]], 1]), [[1, 6, -1], [2, 5, 1]])
    check('delete two leaders', solve([[[1, 6], [2, 5], [3, 4]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 6, -1], [3, 4, 1]])
    check('score changes in view', solve([[[1, 6], [2, 3]], [['upsert', 1, 7]], 1]), [[1, 6, -1], [1, 7, 1]])
    check('promote outsider', solve([[[1, 5], [2, 3]], [['upsert', 2, 6]], 1]), [[1, 5, -1], [2, 6, 1]])
    check('insert tie lower id', solve([[[2, 3]], [['upsert', 1, 3]], 1]), [[2, 3, -1], [1, 3, 1]])
    check('no changes', solve([[[1, 3]], [], 1]), [])
    check('zero view', solve([[[1, 3]], [['upsert', 2, 4]], 0]), [])
elif N == 4:
    check('delete leader', solve([[[1, 7], [2, 6], [3, 5]], [['delete', 1, None]], 1]), [[1, 7, -1], [2, 6, 1]])
    check('delete two leaders', solve([[[1, 7], [2, 6], [3, 5]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 7, -1], [3, 5, 1]])
    check('score changes in view', solve([[[1, 7], [2, 4]], [['upsert', 1, 8]], 1]), [[1, 7, -1], [1, 8, 1]])
    check('promote outsider', solve([[[1, 6], [2, 4]], [['upsert', 2, 7]], 1]), [[1, 6, -1], [2, 7, 1]])
    check('insert tie lower id', solve([[[2, 4]], [['upsert', 1, 4]], 1]), [[2, 4, -1], [1, 4, 1]])
    check('no changes', solve([[[1, 4]], [], 1]), [])
    check('zero view', solve([[[1, 4]], [['upsert', 2, 5]], 0]), [])
elif N == 5:
    check('delete leader', solve([[[1, 8], [2, 7], [3, 6]], [['delete', 1, None]], 1]), [[1, 8, -1], [2, 7, 1]])
    check('delete two leaders', solve([[[1, 8], [2, 7], [3, 6]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 8, -1], [3, 6, 1]])
    check('score changes in view', solve([[[1, 8], [2, 5]], [['upsert', 1, 9]], 1]), [[1, 8, -1], [1, 9, 1]])
    check('promote outsider', solve([[[1, 7], [2, 5]], [['upsert', 2, 8]], 1]), [[1, 7, -1], [2, 8, 1]])
    check('insert tie lower id', solve([[[2, 5]], [['upsert', 1, 5]], 1]), [[2, 5, -1], [1, 5, 1]])
    check('no changes', solve([[[1, 5]], [], 1]), [])
    check('zero view', solve([[[1, 5]], [['upsert', 2, 6]], 0]), [])
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:
Top-k suppresses insertions for score changes of surviving IDs.

Maintain unique-ID scored rows with upsert/delete operations, then report changes to a top-k materialized view. Scores order descending with ascending ID ties. Retractions carry old scores; insertions carry new scores. Score updates within the top-k emit both. Return retractions sorted by ID, then insertions sorted by ID.

split: open-access


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

N = 1
observations = []
def solve(d):
    try:
        initial,changes,k=d
        before=dict(initial); after=dict(initial)
        for op,ident,score in changes:
            if op=='delete': after.pop(ident,None)
            else: after[ident]=score
        old=dict(sorted(before.items(),key=lambda p:(-p[1],p[0]))[:k])
        new=dict(sorted(after.items(),key=lambda p:(-p[1],p[0]))[:k])
        removed=[[i,s,-1] for i,s in sorted(old.items()) if i not in new or new[i]!=s]
        added=[[i,s,1] for i,s in sorted(new.items()) if i not in old or old[i]!=s]
        return added+removed
    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('delete leader', solve([[[1, 4], [2, 3], [3, 2]], [['delete', 1, None]], 1]), [[1, 4, -1], [2, 3, 1]])
    check('delete two leaders', solve([[[1, 4], [2, 3], [3, 2]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 4, -1], [3, 2, 1]])
    check('score changes in view', solve([[[1, 4], [2, 1]], [['upsert', 1, 5]], 1]), [[1, 4, -1], [1, 5, 1]])
    check('promote outsider', solve([[[1, 3], [2, 1]], [['upsert', 2, 4]], 1]), [[1, 3, -1], [2, 4, 1]])
    check('insert tie lower id', solve([[[2, 1]], [['upsert', 1, 1]], 1]), [[2, 1, -1], [1, 1, 1]])
    check('no changes', solve([[[1, 1]], [], 1]), [])
    check('zero view', solve([[[1, 1]], [['upsert', 2, 2]], 0]), [])
elif N == 2:
    check('delete leader', solve([[[1, 5], [2, 4], [3, 3]], [['delete', 1, None]], 1]), [[1, 5, -1], [2, 4, 1]])
    check('delete two leaders', solve([[[1, 5], [2, 4], [3, 3]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 5, -1], [3, 3, 1]])
    check('score changes in view', solve([[[1, 5], [2, 2]], [['upsert', 1, 6]], 1]), [[1, 5, -1], [1, 6, 1]])
    check('promote outsider', solve([[[1, 4], [2, 2]], [['upsert', 2, 5]], 1]), [[1, 4, -1], [2, 5, 1]])
    check('insert tie lower id', solve([[[2, 2]], [['upsert', 1, 2]], 1]), [[2, 2, -1], [1, 2, 1]])
    check('no changes', solve([[[1, 2]], [], 1]), [])
    check('zero view', solve([[[1, 2]], [['upsert', 2, 3]], 0]), [])
elif N == 3:
    check('delete leader', solve([[[1, 6], [2, 5], [3, 4]], [['delete', 1, None]], 1]), [[1, 6, -1], [2, 5, 1]])
    check('delete two leaders', solve([[[1, 6], [2, 5], [3, 4]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 6, -1], [3, 4, 1]])
    check('score changes in view', solve([[[1, 6], [2, 3]], [['upsert', 1, 7]], 1]), [[1, 6, -1], [1, 7, 1]])
    check('promote outsider', solve([[[1, 5], [2, 3]], [['upsert', 2, 6]], 1]), [[1, 5, -1], [2, 6, 1]])
    check('insert tie lower id', solve([[[2, 3]], [['upsert', 1, 3]], 1]), [[2, 3, -1], [1, 3, 1]])
    check('no changes', solve([[[1, 3]], [], 1]), [])
    check('zero view', solve([[[1, 3]], [['upsert', 2, 4]], 0]), [])
elif N == 4:
    check('delete leader', solve([[[1, 7], [2, 6], [3, 5]], [['delete', 1, None]], 1]), [[1, 7, -1], [2, 6, 1]])
    check('delete two leaders', solve([[[1, 7], [2, 6], [3, 5]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 7, -1], [3, 5, 1]])
    check('score changes in view', solve([[[1, 7], [2, 4]], [['upsert', 1, 8]], 1]), [[1, 7, -1], [1, 8, 1]])
    check('promote outsider', solve([[[1, 6], [2, 4]], [['upsert', 2, 7]], 1]), [[1, 6, -1], [2, 7, 1]])
    check('insert tie lower id', solve([[[2, 4]], [['upsert', 1, 4]], 1]), [[2, 4, -1], [1, 4, 1]])
    check('no changes', solve([[[1, 4]], [], 1]), [])
    check('zero view', solve([[[1, 4]], [['upsert', 2, 5]], 0]), [])
elif N == 5:
    check('delete leader', solve([[[1, 8], [2, 7], [3, 6]], [['delete', 1, None]], 1]), [[1, 8, -1], [2, 7, 1]])
    check('delete two leaders', solve([[[1, 8], [2, 7], [3, 6]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 8, -1], [3, 6, 1]])
    check('score changes in view', solve([[[1, 8], [2, 5]], [['upsert', 1, 9]], 1]), [[1, 8, -1], [1, 9, 1]])
    check('promote outsider', solve([[[1, 7], [2, 5]], [['upsert', 2, 8]], 1]), [[1, 7, -1], [2, 8, 1]])
    check('insert tie lower id', solve([[[2, 5]], [['upsert', 1, 5]], 1]), [[2, 5, -1], [1, 5, 1]])
    check('no changes', solve([[[1, 5]], [], 1]), [])
    check('zero view', solve([[[1, 5]], [['upsert', 2, 6]], 0]), [])
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:
        initial,changes,k=d
        before=dict(initial); after=dict(initial)
        for op,ident,score in changes:
            if op=='delete': after.pop(ident,None)
            else: after[ident]=score
        old=dict(sorted(before.items(),key=lambda p:(-p[1],p[0]))[:k])
        new=dict(sorted(after.items(),key=lambda p:(-p[1],p[0]))[:k])
        removed=[[i,s,-1] for i,s in sorted(old.items()) if i not in new or new[i]!=s]
        added=[[i,s,1] for i,s in sorted(new.items()) if i not in old or old[i]!=s]
        return sorted(removed+added,key=lambda r:-r[2])
    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('delete leader', solve([[[1, 4], [2, 3], [3, 2]], [['delete', 1, None]], 1]), [[1, 4, -1], [2, 3, 1]])
    check('delete two leaders', solve([[[1, 4], [2, 3], [3, 2]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 4, -1], [3, 2, 1]])
    check('score changes in view', solve([[[1, 4], [2, 1]], [['upsert', 1, 5]], 1]), [[1, 4, -1], [1, 5, 1]])
    check('promote outsider', solve([[[1, 3], [2, 1]], [['upsert', 2, 4]], 1]), [[1, 3, -1], [2, 4, 1]])
    check('insert tie lower id', solve([[[2, 1]], [['upsert', 1, 1]], 1]), [[2, 1, -1], [1, 1, 1]])
    check('no changes', solve([[[1, 1]], [], 1]), [])
    check('zero view', solve([[[1, 1]], [['upsert', 2, 2]], 0]), [])
elif N == 2:
    check('delete leader', solve([[[1, 5], [2, 4], [3, 3]], [['delete', 1, None]], 1]), [[1, 5, -1], [2, 4, 1]])
    check('delete two leaders', solve([[[1, 5], [2, 4], [3, 3]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 5, -1], [3, 3, 1]])
    check('score changes in view', solve([[[1, 5], [2, 2]], [['upsert', 1, 6]], 1]), [[1, 5, -1], [1, 6, 1]])
    check('promote outsider', solve([[[1, 4], [2, 2]], [['upsert', 2, 5]], 1]), [[1, 4, -1], [2, 5, 1]])
    check('insert tie lower id', solve([[[2, 2]], [['upsert', 1, 2]], 1]), [[2, 2, -1], [1, 2, 1]])
    check('no changes', solve([[[1, 2]], [], 1]), [])
    check('zero view', solve([[[1, 2]], [['upsert', 2, 3]], 0]), [])
elif N == 3:
    check('delete leader', solve([[[1, 6], [2, 5], [3, 4]], [['delete', 1, None]], 1]), [[1, 6, -1], [2, 5, 1]])
    check('delete two leaders', solve([[[1, 6], [2, 5], [3, 4]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 6, -1], [3, 4, 1]])
    check('score changes in view', solve([[[1, 6], [2, 3]], [['upsert', 1, 7]], 1]), [[1, 6, -1], [1, 7, 1]])
    check('promote outsider', solve([[[1, 5], [2, 3]], [['upsert', 2, 6]], 1]), [[1, 5, -1], [2, 6, 1]])
    check('insert tie lower id', solve([[[2, 3]], [['upsert', 1, 3]], 1]), [[2, 3, -1], [1, 3, 1]])
    check('no changes', solve([[[1, 3]], [], 1]), [])
    check('zero view', solve([[[1, 3]], [['upsert', 2, 4]], 0]), [])
elif N == 4:
    check('delete leader', solve([[[1, 7], [2, 6], [3, 5]], [['delete', 1, None]], 1]), [[1, 7, -1], [2, 6, 1]])
    check('delete two leaders', solve([[[1, 7], [2, 6], [3, 5]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 7, -1], [3, 5, 1]])
    check('score changes in view', solve([[[1, 7], [2, 4]], [['upsert', 1, 8]], 1]), [[1, 7, -1], [1, 8, 1]])
    check('promote outsider', solve([[[1, 6], [2, 4]], [['upsert', 2, 7]], 1]), [[1, 6, -1], [2, 7, 1]])
    check('insert tie lower id', solve([[[2, 4]], [['upsert', 1, 4]], 1]), [[2, 4, -1], [1, 4, 1]])
    check('no changes', solve([[[1, 4]], [], 1]), [])
    check('zero view', solve([[[1, 4]], [['upsert', 2, 5]], 0]), [])
elif N == 5:
    check('delete leader', solve([[[1, 8], [2, 7], [3, 6]], [['delete', 1, None]], 1]), [[1, 8, -1], [2, 7, 1]])
    check('delete two leaders', solve([[[1, 8], [2, 7], [3, 6]], [['delete', 1, None], ['delete', 2, None]], 1]), [[1, 8, -1], [3, 6, 1]])
    check('score changes in view', solve([[[1, 8], [2, 5]], [['upsert', 1, 9]], 1]), [[1, 8, -1], [1, 9, 1]])
    check('promote outsider', solve([[[1, 7], [2, 5]], [['upsert', 2, 8]], 1]), [[1, 7, -1], [2, 8, 1]])
    check('insert tie lower id', solve([[[2, 5]], [['upsert', 1, 5]], 1]), [[2, 5, -1], [1, 5, 1]])
    check('no changes', solve([[[1, 5]], [], 1]), [])
    check('zero view', solve([[[1, 5]], [['upsert', 2, 6]], 0]), [])
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:
Top-k publishes new membership before retracting old tuples.

Maintain unique-ID scored rows with upsert/delete operations, then report changes to a top-k materialized view. Scores order descending with ascending ID ties. Retractions carry old scores; insertions carry new scores. Score updates within the top-k emit both. Return retractions sorted by ID, then insertions sorted by ID.

split: open-access


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

N = 1
observations = []
def solve(d):
    try:
        facts,versions=d
        out=[]
        for ident,key,time in facts:
            candidates=[r for r in versions if key is not None and r[0]==key and True]
            if not candidates: out.append([ident,None]); continue
            chosen=max(candidates,key=lambda r:(r[1],r[2]))
            out.append([ident,None if chosen[4] else chosen[3]])
        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('future ignored', solve([[[10, 'a', 2]], [['a', 1, 1, 'old', False], ['a', 3, 1, 'future', False]]]), [[10, 'old']])
    check('exact effective time', solve([[[10, 'a', 1]], [['a', 1, 1, 'current', False]]]), [[10, 'current']])
    check('revision precedence', solve([[[10, 'a', 1]], [['a', 1, 1, 'old', False], ['a', 1, 2, 'new', False]]]), [[10, 'new']])
    check('tombstone blocks old', solve([[[10, 'a', 2]], [['a', 1, 1, 'old', False], ['a', 2, 1, None, True]]]), [[10, None]])
    check('tombstone hidden payload', solve([[[10, 'a', 1]], [['a', 1, 1, 'hidden', True]]]), [[10, None]])
    check('other key', solve([[[10, 'a', 2]], [['a', 1, 1, 'right', False], ['b', 2, 1, 'wrong', False], [None, 2, 2, 'wildcard', False]]]), [[10, 'right']])
    check('absent dimension', solve([[[10, 'a', 1]], []]), [[10, None]])
elif N == 2:
    check('future ignored', solve([[[10, 'a', 3]], [['a', 2, 1, 'old', False], ['a', 4, 1, 'future', False]]]), [[10, 'old']])
    check('exact effective time', solve([[[10, 'a', 2]], [['a', 2, 1, 'current', False]]]), [[10, 'current']])
    check('revision precedence', solve([[[10, 'a', 2]], [['a', 2, 1, 'old', False], ['a', 2, 2, 'new', False]]]), [[10, 'new']])
    check('tombstone blocks old', solve([[[10, 'a', 3]], [['a', 2, 1, 'old', False], ['a', 3, 1, None, True]]]), [[10, None]])
    check('tombstone hidden payload', solve([[[10, 'a', 2]], [['a', 2, 1, 'hidden', True]]]), [[10, None]])
    check('other key', solve([[[10, 'a', 3]], [['a', 2, 1, 'right', False], ['b', 3, 1, 'wrong', False], [None, 3, 2, 'wildcard', False]]]), [[10, 'right']])
    check('absent dimension', solve([[[10, 'a', 2]], []]), [[10, None]])
elif N == 3:
    check('future ignored', solve([[[10, 'a', 4]], [['a', 3, 1, 'old', False], ['a', 5, 1, 'future', False]]]), [[10, 'old']])
    check('exact effective time', solve([[[10, 'a', 3]], [['a', 3, 1, 'current', False]]]), [[10, 'current']])
    check('revision precedence', solve([[[10, 'a', 3]], [['a', 3, 1, 'old', False], ['a', 3, 2, 'new', False]]]), [[10, 'new']])
    check('tombstone blocks old', solve([[[10, 'a', 4]], [['a', 3, 1, 'old', False], ['a', 4, 1, None, True]]]), [[10, None]])
    check('tombstone hidden payload', solve([[[10, 'a', 3]], [['a', 3, 1, 'hidden', True]]]), [[10, None]])
    check('other key', solve([[[10, 'a', 4]], [['a', 3, 1, 'right', False], ['b', 4, 1, 'wrong', False], [None, 4, 2, 'wildcard', False]]]), [[10, 'right']])
    check('absent dimension', solve([[[10, 'a', 3]], []]), [[10, None]])
elif N == 4:
    check('future ignored', solve([[[10, 'a', 5]], [['a', 4, 1, 'old', False], ['a', 6, 1, 'future', False]]]), [[10, 'old']])
    check('exact effective time', solve([[[10, 'a', 4]], [['a', 4, 1, 'current', False]]]), [[10, 'current']])
    check('revision precedence', solve([[[10, 'a', 4]], [['a', 4, 1, 'old', False], ['a', 4, 2, 'new', False]]]), [[10, 'new']])
    check('tombstone blocks old', solve([[[10, 'a', 5]], [['a', 4, 1, 'old', False], ['a', 5, 1, None, True]]]), [[10, None]])
    check('tombstone hidden payload', solve([[[10, 'a', 4]], [['a', 4, 1, 'hidden', True]]]), [[10, None]])
    check('other key', solve([[[10, 'a', 5]], [['a', 4, 1, 'right', False], ['b', 5, 1, 'wrong', False], [None, 5, 2, 'wildcard', False]]]), [[10, 'right']])
    check('absent dimension', solve([[[10, 'a', 4]], []]), [[10, None]])
elif N == 5:
    check('future ignored', solve([[[10, 'a', 6]], [['a', 5, 1, 'old', False], ['a', 7, 1, 'future', False]]]), [[10, 'old']])
    check('exact effective time', solve([[[10, 'a', 5]], [['a', 5, 1, 'current', False]]]), [[10, 'current']])
    check('revision precedence', solve([[[10, 'a', 5]], [['a', 5, 1, 'old', False], ['a', 5, 2, 'new', False]]]), [[10, 'new']])
    check('tombstone blocks old', solve([[[10, 'a', 6]], [['a', 5, 1, 'old', False], ['a', 6, 1, None, True]]]), [[10, None]])
    check('tombstone hidden payload', solve([[[10, 'a', 5]], [['a', 5, 1, 'hidden', True]]]), [[10, None]])
    check('other key', solve([[[10, 'a', 6]], [['a', 5, 1, 'right', False], ['b', 6, 1, 'wrong', False], [None, 6, 2, 'wildcard', False]]]), [[10, 'right']])
    check('absent dimension', solve([[[10, 'a', 5]], []]), [[10, None]])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(d):
    try:
        facts,versions=d
        out=[]
        for ident,key,time in facts:
            candidates=[r for r in versions if key is not None and r[0]==key and r[1]>=time]
            if not candidates: out.append([ident,None]); continue
            chosen=max(candidates,key=lambda r:(r[1],r[2]))
            out.append([ident,None if chosen[4] else chosen[3]])
        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('future ignored', solve([[[10, 'a', 2]], [['a', 1, 1, 'old', False], ['a', 3, 1, 'future', False]]]), [[10, 'old']])
    check('exact effective time', solve([[[10, 'a', 1]], [['a', 1, 1, 'current', False]]]), [[10, 'current']])
    check('revision precedence', solve([[[10, 'a', 1]], [['a', 1, 1, 'old', False], ['a', 1, 2, 'new', False]]]), [[10, 'new']])
    check('tombstone blocks old', solve([[[10, 'a', 2]], [['a', 1, 1, 'old', False], ['a', 2, 1, None, True]]]), [[10, None]])
    check('tombstone hidden payload', solve([[[10, 'a', 1]], [['a', 1, 1, 'hidden', True]]]), [[10, None]])
    check('other key', solve([[[10, 'a', 2]], [['a', 1, 1, 'right', False], ['b', 2, 1, 'wrong', False], [None, 2, 2, 'wildcard', False]]]), [[10, 'right']])
    check('absent dimension', solve([[[10, 'a', 1]], []]), [[10, None]])
elif N == 2:
    check('future ignored', solve([[[10, 'a', 3]], [['a', 2, 1, 'old', False], ['a', 4, 1, 'future', False]]]), [[10, 'old']])
    check('exact effective time', solve([[[10, 'a', 2]], [['a', 2, 1, 'current', False]]]), [[10, 'current']])
    check('revision precedence', solve([[[10, 'a', 2]], [['a', 2, 1, 'old', False], ['a', 2, 2, 'new', False]]]), [[10, 'new']])
    check('tombstone blocks old', solve([[[10, 'a', 3]], [['a', 2, 1, 'old', False], ['a', 3, 1, None, True]]]), [[10, None]])
    check('tombstone hidden payload', solve([[[10, 'a', 2]], [['a', 2, 1, 'hidden', True]]]), [[10, None]])
    check('other key', solve([[[10, 'a', 3]], [['a', 2, 1, 'right', False], ['b', 3, 1, 'wrong', False], [None, 3, 2, 'wildcard', False]]]), [[10, 'right']])
    check('absent dimension', solve([[[10, 'a', 2]], []]), [[10, None]])
elif N == 3:
    check('future ignored', solve([[[10, 'a', 4]], [['a', 3, 1, 'old', False], ['a', 5, 1, 'future', False]]]), [[10, 'old']])
    check('exact effective time', solve([[[10, 'a', 3]], [['a', 3, 1, 'current', False]]]), [[10, 'current']])
    check('revision precedence', solve([[[10, 'a', 3]], [['a', 3, 1, 'old', False], ['a', 3, 2, 'new', False]]]), [[10, 'new']])
    check('tombstone blocks old', solve([[[10, 'a', 4]], [['a', 3, 1, 'old', False], ['a', 4, 1, None, True]]]), [[10, None]])
    check('tombstone hidden payload', solve([[[10, 'a', 3]], [['a', 3, 1, 'hidden', True]]]), [[10, None]])
    check('other key', solve([[[10, 'a', 4]], [['a', 3, 1, 'right', False], ['b', 4, 1, 'wrong', False], [None, 4, 2, 'wildcard', False]]]), [[10, 'right']])
    check('absent dimension', solve([[[10, 'a', 3]], []]), [[10, None]])
elif N == 4:
    check('future ignored', solve([[[10, 'a', 5]], [['a', 4, 1, 'old', False], ['a', 6, 1, 'future', False]]]), [[10, 'old']])
    check('exact effective time', solve([[[10, 'a', 4]], [['a', 4, 1, 'current', False]]]), [[10, 'current']])
    check('revision precedence', solve([[[10, 'a', 4]], [['a', 4, 1, 'old', False], ['a', 4, 2, 'new', False]]]), [[10, 'new']])
    check('tombstone blocks old', solve([[[10, 'a', 5]], [['a', 4, 1, 'old', False], ['a', 5, 1, None, True]]]), [[10, None]])
    check('tombstone hidden payload', solve([[[10, 'a', 4]], [['a', 4, 1, 'hidden', True]]]), [[10, None]])
    check('other key', solve([[[10, 'a', 5]], [['a', 4, 1, 'right', False], ['b', 5, 1, 'wrong', False], [None, 5, 2, 'wildcard', False]]]), [[10, 'right']])
    check('absent dimension', solve([[[10, 'a', 4]], []]), [[10, None]])
elif N == 5:
    check('future ignored', solve([[[10, 'a', 6]], [['a', 5, 1, 'old', False], ['a', 7, 1, 'future', False]]]), [[10, 'old']])
    check('exact effective time', solve([[[10, 'a', 5]], [['a', 5, 1, 'current', False]]]), [[10, 'current']])
    check('revision precedence', solve([[[10, 'a', 5]], [['a', 5, 1, 'old', False], ['a', 5, 2, 'new', False]]]), [[10, 'new']])
    check('tombstone blocks old', solve([[[10, 'a', 6]], [['a', 5, 1, 'old', False], ['a', 6, 1, None, True]]]), [[10, None]])
    check('tombstone hidden payload', solve([[[10, 'a', 5]], [['a', 5, 1, 'hidden', True]]]), [[10, None]])
    check('other key', solve([[[10, 'a', 6]], [['a', 5, 1, 'right', False], ['b', 6, 1, 'wrong', False], [None, 6, 2, 'wildcard', False]]]), [[10, 'right']])
    check('absent dimension', solve([[[10, 'a', 5]], []]), [[10, None]])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Temporal enrichment selects dimension versions after fact time.

Enrich facts [id,key,event-time] from versioned dimension rows [key,valid-from,revision,payload,tombstone]. For matching non-null key, use the greatest (valid-from,revision) no later than fact time. A selected tombstone yields None and blocks fallback to older versions. Emit [fact-id,payload-or-None].

split: open-access


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

N = 1
observations = []
def solve(d):
    try:
        facts,versions=d
        out=[]
        for ident,key,time in facts:
            candidates=[r for r in versions if key is not None and r[0]==key and r[1]<time]
            if not candidates: out.append([ident,None]); continue
            chosen=max(candidates,key=lambda r:(r[1],r[2]))
            out.append([ident,None if chosen[4] else chosen[3]])
        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('future ignored', solve([[[10, 'a', 2]], [['a', 1, 1, 'old', False], ['a', 3, 1, 'future', False]]]), [[10, 'old']])
    check('exact effective time', solve([[[10, 'a', 1]], [['a', 1, 1, 'current', False]]]), [[10, 'current']])
    check('revision precedence', solve([[[10, 'a', 1]], [['a', 1, 1, 'old', False], ['a', 1, 2, 'new', False]]]), [[10, 'new']])
    check('tombstone blocks old', solve([[[10, 'a', 2]], [['a', 1, 1, 'old', False], ['a', 2, 1, None, True]]]), [[10, None]])
    check('tombstone hidden payload', solve([[[10, 'a', 1]], [['a', 1, 1, 'hidden', True]]]), [[10, None]])
    check('other key', solve([[[10, 'a', 2]], [['a', 1, 1, 'right', False], ['b', 2, 1, 'wrong', False], [None, 2, 2, 'wildcard', False]]]), [[10, 'right']])
    check('absent dimension', solve([[[10, 'a', 1]], []]), [[10, None]])
elif N == 2:
    check('future ignored', solve([[[10, 'a', 3]], [['a', 2, 1, 'old', False], ['a', 4, 1, 'future', False]]]), [[10, 'old']])
    check('exact effective time', solve([[[10, 'a', 2]], [['a', 2, 1, 'current', False]]]), [[10, 'current']])
    check('revision precedence', solve([[[10, 'a', 2]], [['a', 2, 1, 'old', False], ['a', 2, 2, 'new', False]]]), [[10, 'new']])
    check('tombstone blocks old', solve([[[10, 'a', 3]], [['a', 2, 1, 'old', False], ['a', 3, 1, None, True]]]), [[10, None]])
    check('tombstone hidden payload', solve([[[10, 'a', 2]], [['a', 2, 1, 'hidden', True]]]), [[10, None]])
    check('other key', solve([[[10, 'a', 3]], [['a', 2, 1, 'right', False], ['b', 3, 1, 'wrong', False], [None, 3, 2, 'wildcard', False]]]), [[10, 'right']])
    check('absent dimension', solve([[[10, 'a', 2]], []]), [[10, None]])
elif N == 3:
    check('future ignored', solve([[[10, 'a', 4]], [['a', 3, 1, 'old', False], ['a', 5, 1, 'future', False]]]), [[10, 'old']])
    check('exact effective time', solve([[[10, 'a', 3]], [['a', 3, 1, 'current', False]]]), [[10, 'current']])
    check('revision precedence', solve([[[10, 'a', 3]], [['a', 3, 1, 'old', False], ['a', 3, 2, 'new', False]]]), [[10, 'new']])
    check('tombstone blocks old', solve([[[10, 'a', 4]], [['a', 3, 1, 'old', False], ['a', 4, 1, None, True]]]), [[10, None]])
    check('tombstone hidden payload', solve([[[10, 'a', 3]], [['a', 3, 1, 'hidden', True]]]), [[10, None]])
    check('other key', solve([[[10, 'a', 4]], [['a', 3, 1, 'right', False], ['b', 4, 1, 'wrong', False], [None, 4, 2, 'wildcard', False]]]), [[10, 'right']])
    check('absent dimension', solve([[[10, 'a', 3]], []]), [[10, None]])
elif N == 4:
    check('future ignored', solve([[[10, 'a', 5]], [['a', 4, 1, 'old', False], ['a', 6, 1, 'future', False]]]), [[10, 'old']])
    check('exact effective time', solve([[[10, 'a', 4]], [['a', 4, 1, 'current', False]]]), [[10, 'current']])
    check('revision precedence', solve([[[10, 'a', 4]], [['a', 4, 1, 'old', False], ['a', 4, 2, 'new', False]]]), [[10, 'new']])
    check('tombstone blocks old', solve([[[10, 'a', 5]], [['a', 4, 1, 'old', False], ['a', 5, 1, None, True]]]), [[10, None]])
    check('tombstone hidden payload', solve([[[10, 'a', 4]], [['a', 4, 1, 'hidden', True]]]), [[10, None]])
    check('other key', solve([[[10, 'a', 5]], [['a', 4, 1, 'right', False], ['b', 5, 1, 'wrong', False], [None, 5, 2, 'wildcard', False]]]), [[10, 'right']])
    check('absent dimension', solve([[[10, 'a', 4]], []]), [[10, None]])
elif N == 5:
    check('future ignored', solve([[[10, 'a', 6]], [['a', 5, 1, 'old', False], ['a', 7, 1, 'future', False]]]), [[10, 'old']])
    check('exact effective time', solve([[[10, 'a', 5]], [['a', 5, 1, 'current', False]]]), [[10, 'current']])
    check('revision precedence', solve([[[10, 'a', 5]], [['a', 5, 1, 'old', False], ['a', 5, 2, 'new', False]]]), [[10, 'new']])
    check('tombstone blocks old', solve([[[10, 'a', 6]], [['a', 5, 1, 'old', False], ['a', 6, 1, None, True]]]), [[10, None]])
    check('tombstone hidden payload', solve([[[10, 'a', 5]], [['a', 5, 1, 'hidden', True]]]), [[10, None]])
    check('other key', solve([[[10, 'a', 6]], [['a', 5, 1, 'right', False], ['b', 6, 1, 'wrong', False], [None, 6, 2, 'wildcard', False]]]), [[10, 'right']])
    check('absent dimension', solve([[[10, 'a', 5]], []]), [[10, None]])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(d):
    try:
        facts,versions=d
        out=[]
        for ident,key,time in facts:
            candidates=[r for r in versions if key is not None and r[0]==key and r[1]<=time-1]
            if not candidates: out.append([ident,None]); continue
            chosen=max(candidates,key=lambda r:(r[1],r[2]))
            out.append([ident,None if chosen[4] else chosen[3]])
        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('future ignored', solve([[[10, 'a', 2]], [['a', 1, 1, 'old', False], ['a', 3, 1, 'future', False]]]), [[10, 'old']])
    check('exact effective time', solve([[[10, 'a', 1]], [['a', 1, 1, 'current', False]]]), [[10, 'current']])
    check('revision precedence', solve([[[10, 'a', 1]], [['a', 1, 1, 'old', False], ['a', 1, 2, 'new', False]]]), [[10, 'new']])
    check('tombstone blocks old', solve([[[10, 'a', 2]], [['a', 1, 1, 'old', False], ['a', 2, 1, None, True]]]), [[10, None]])
    check('tombstone hidden payload', solve([[[10, 'a', 1]], [['a', 1, 1, 'hidden', True]]]), [[10, None]])
    check('other key', solve([[[10, 'a', 2]], [['a', 1, 1, 'right', False], ['b', 2, 1, 'wrong', False], [None, 2, 2, 'wildcard', False]]]), [[10, 'right']])
    check('absent dimension', solve([[[10, 'a', 1]], []]), [[10, None]])
elif N == 2:
    check('future ignored', solve([[[10, 'a', 3]], [['a', 2, 1, 'old', False], ['a', 4, 1, 'future', False]]]), [[10, 'old']])
    check('exact effective time', solve([[[10, 'a', 2]], [['a', 2, 1, 'current', False]]]), [[10, 'current']])
    check('revision precedence', solve([[[10, 'a', 2]], [['a', 2, 1, 'old', False], ['a', 2, 2, 'new', False]]]), [[10, 'new']])
    check('tombstone blocks old', solve([[[10, 'a', 3]], [['a', 2, 1, 'old', False], ['a', 3, 1, None, True]]]), [[10, None]])
    check('tombstone hidden payload', solve([[[10, 'a', 2]], [['a', 2, 1, 'hidden', True]]]), [[10, None]])
    check('other key', solve([[[10, 'a', 3]], [['a', 2, 1, 'right', False], ['b', 3, 1, 'wrong', False], [None, 3, 2, 'wildcard', False]]]), [[10, 'right']])
    check('absent dimension', solve([[[10, 'a', 2]], []]), [[10, None]])
elif N == 3:
    check('future ignored', solve([[[10, 'a', 4]], [['a', 3, 1, 'old', False], ['a', 5, 1, 'future', False]]]), [[10, 'old']])
    check('exact effective time', solve([[[10, 'a', 3]], [['a', 3, 1, 'current', False]]]), [[10, 'current']])
    check('revision precedence', solve([[[10, 'a', 3]], [['a', 3, 1, 'old', False], ['a', 3, 2, 'new', False]]]), [[10, 'new']])
    check('tombstone blocks old', solve([[[10, 'a', 4]], [['a', 3, 1, 'old', False], ['a', 4, 1, None, True]]]), [[10, None]])
    check('tombstone hidden payload', solve([[[10, 'a', 3]], [['a', 3, 1, 'hidden', True]]]), [[10, None]])
    check('other key', solve([[[10, 'a', 4]], [['a', 3, 1, 'right', False], ['b', 4, 1, 'wrong', False], [None, 4, 2, 'wildcard', False]]]), [[10, 'right']])
    check('absent dimension', solve([[[10, 'a', 3]], []]), [[10, None]])
elif N == 4:
    check('future ignored', solve([[[10, 'a', 5]], [['a', 4, 1, 'old', False], ['a', 6, 1, 'future', False]]]), [[10, 'old']])
    check('exact effective time', solve([[[10, 'a', 4]], [['a', 4, 1, 'current', False]]]), [[10, 'current']])
    check('revision precedence', solve([[[10, 'a', 4]], [['a', 4, 1, 'old', False], ['a', 4, 2, 'new', False]]]), [[10, 'new']])
    check('tombstone blocks old', solve([[[10, 'a', 5]], [['a', 4, 1, 'old', False], ['a', 5, 1, None, True]]]), [[10, None]])
    check('tombstone hidden payload', solve([[[10, 'a', 4]], [['a', 4, 1, 'hidden', True]]]), [[10, None]])
    check('other key', solve([[[10, 'a', 5]], [['a', 4, 1, 'right', False], ['b', 5, 1, 'wrong', False], [None, 5, 2, 'wildcard', False]]]), [[10, 'right']])
    check('absent dimension', solve([[[10, 'a', 4]], []]), [[10, None]])
elif N == 5:
    check('future ignored', solve([[[10, 'a', 6]], [['a', 5, 1, 'old', False], ['a', 7, 1, 'future', False]]]), [[10, 'old']])
    check('exact effective time', solve([[[10, 'a', 5]], [['a', 5, 1, 'current', False]]]), [[10, 'current']])
    check('revision precedence', solve([[[10, 'a', 5]], [['a', 5, 1, 'old', False], ['a', 5, 2, 'new', False]]]), [[10, 'new']])
    check('tombstone blocks old', solve([[[10, 'a', 6]], [['a', 5, 1, 'old', False], ['a', 6, 1, None, True]]]), [[10, None]])
    check('tombstone hidden payload', solve([[[10, 'a', 5]], [['a', 5, 1, 'hidden', True]]]), [[10, None]])
    check('other key', solve([[[10, 'a', 6]], [['a', 5, 1, 'right', False], ['b', 6, 1, 'wrong', False], [None, 6, 2, 'wildcard', False]]]), [[10, 'right']])
    check('absent dimension', solve([[[10, 'a', 5]], []]), [[10, None]])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Temporal enrichment excludes a version effective exactly at fact time.

Enrich facts [id,key,event-time] from versioned dimension rows [key,valid-from,revision,payload,tombstone]. For matching non-null key, use the greatest (valid-from,revision) no later than fact time. A selected tombstone yields None and blocks fallback to older versions. Emit [fact-id,payload-or-None].

split: open-access