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

N = 1
observations = []
def solve(cases):
    def run(c):
        text,lo,hi,key,prevent_down,prevent_before,cancelable,readonly=c
        log=['keydown']; original=[text,lo,hi]
        if prevent_down and cancelable:
            return original+[log+['keyup']]
        if readonly or not (len(key)==1 or key in ('Backspace','Delete')):
            return original+[log+['keyup']]
        insert=key if len(key)==1 else ''
        if key=='Backspace' and lo==hi: lo=max(0,lo-1)
        elif key=='Delete' and lo==hi: hi=min(len(text),hi+1)
        changed=text[:lo]+insert+text[hi:]
        if changed==text:
            return original+[log+['keyup']]
        log.append('input')
        if prevent_before:
            return original+[log+['keyup']]
        text=changed
        hi=lo+len(insert); lo=hi
        log.append('input')
        return [text,lo,hi,log+['keyup']]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('key-default-edit scenario 0', solve([['abc', 1, 1, 'X', False, False, True, False]] * N), [['aXbc', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 1', solve([['abc', 1, 2, 'XY', False, False, True, False]] * N), [['abc', 1, 2, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 2', solve([['abcd', 1, 3, 'Z', False, False, True, False]] * N), [['aZd', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 3', solve([['abcd', 1, 3, 'Backspace', False, False, True, False]] * N), [['ad', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 4', solve([['abcd', 1, 3, 'Delete', False, False, True, False]] * N), [['ad', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 5', solve([['abcd', 2, 2, 'Backspace', False, False, True, False]] * N), [['acd', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 6', solve([['abcd', 1, 1, 'Delete', False, False, True, False]] * N), [['acd', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 7', solve([['abc', 0, 0, 'Backspace', False, False, True, False]] * N), [['abc', 0, 0, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 8', solve([['abc', 0, 3, 'Delete', False, False, True, False]] * N), [['', 0, 0, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 9', solve([['abc', 1, 1, 'X', True, False, False, False]] * N), [['aXbc', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 10', solve([['abc', 1, 1, 'X', True, False, True, False]] * N), [['abc', 1, 1, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 11', solve([['abc', 1, 1, 'X', False, True, False, False]] * N), [['abc', 1, 1, ['keydown', 'beforeinput', 'keyup']]] * N)
check('key-default-edit scenario 12', solve([['abc', 1, 1, 'X', False, False, True, True]] * N), [['abc', 1, 1, ['keydown', 'keyup']]] * N)
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(cases):
    def run(c):
        text,lo,hi,key,prevent_down,prevent_before,cancelable,readonly=c
        log=['keydown']; original=[text,lo,hi]
        if prevent_down and cancelable:
            return original+[log+['keyup']]
        if readonly or not (len(key)==1 or key in ('Backspace','Delete')):
            return original+[log+['keyup']]
        insert=key if len(key)==1 else ''
        if key=='Backspace' and lo==hi: lo=max(0,lo-1)
        elif key=='Delete' and lo==hi: hi=min(len(text),hi+1)
        changed=text[:lo]+insert+text[hi:]
        if changed==text:
            return original+[log+['keyup']]
        log.insert(0,'beforeinput')
        if prevent_before:
            return original+[log+['keyup']]
        text=changed
        hi=lo+len(insert); lo=hi
        log.append('input')
        return [text,lo,hi,log+['keyup']]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('key-default-edit scenario 0', solve([['abc', 1, 1, 'X', False, False, True, False]] * N), [['aXbc', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 1', solve([['abc', 1, 2, 'XY', False, False, True, False]] * N), [['abc', 1, 2, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 2', solve([['abcd', 1, 3, 'Z', False, False, True, False]] * N), [['aZd', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 3', solve([['abcd', 1, 3, 'Backspace', False, False, True, False]] * N), [['ad', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 4', solve([['abcd', 1, 3, 'Delete', False, False, True, False]] * N), [['ad', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 5', solve([['abcd', 2, 2, 'Backspace', False, False, True, False]] * N), [['acd', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 6', solve([['abcd', 1, 1, 'Delete', False, False, True, False]] * N), [['acd', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 7', solve([['abc', 0, 0, 'Backspace', False, False, True, False]] * N), [['abc', 0, 0, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 8', solve([['abc', 0, 3, 'Delete', False, False, True, False]] * N), [['', 0, 0, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 9', solve([['abc', 1, 1, 'X', True, False, False, False]] * N), [['aXbc', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 10', solve([['abc', 1, 1, 'X', True, False, True, False]] * N), [['abc', 1, 1, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 11', solve([['abc', 1, 1, 'X', False, True, False, False]] * N), [['abc', 1, 1, ['keydown', 'beforeinput', 'keyup']]] * N)
check('key-default-edit scenario 12', solve([['abc', 1, 1, 'X', False, False, True, True]] * N), [['abc', 1, 1, ['keydown', 'keyup']]] * N)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The event trace violates the beforeinput order rule and produces incorrect keyboard state or command output.

Case [text,lo,hi,key,prevent_down,prevent_before,cancelable,readonly]. Selection is a valid half-open code-point interval. Printable single characters replace selection, Backspace deletes previous point and Delete deletes next point for collapsed selections. Other keys do not edit. A cancelable prevented keydown stops editing; readonly suppresses beforeinput. A changed candidate fires beforeinput, cancellation suppresses mutation; successful edit fires input. Always log keydown and keyup. Return text, selection endpoints and event log. Inputs are finite ordered event traces; return the stated deterministic state. Batch entries are independent. N varies the number of independent input transactions.

split: open-access


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

N = 1
observations = []
def solve(cases):
    def run(c):
        text,lo,hi,key,prevent_down,prevent_before,cancelable,readonly=c
        log=['keydown']; original=[text,lo,hi]
        if prevent_down and cancelable:
            return original+[log+['keyup']]
        if readonly or not (len(key)==1 or key in ('Backspace','Delete')):
            return original+[log+['keyup']]
        insert=key if len(key)==1 else ''
        if key=='Backspace' and lo==hi: lo=max(0,lo-1)
        elif key=='Delete' and lo==hi: hi=min(len(text),hi+1)
        changed=text[:lo]+insert+text[hi:]
        if False:
            return original+[log+['keyup']]
        log.append('beforeinput')
        if prevent_before:
            return original+[log+['keyup']]
        text=changed
        hi=lo+len(insert); lo=hi
        log.append('input')
        return [text,lo,hi,log+['keyup']]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('key-default-edit scenario 0', solve([['abc', 1, 1, 'X', False, False, True, False]] * N), [['aXbc', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 1', solve([['abc', 1, 2, 'XY', False, False, True, False]] * N), [['abc', 1, 2, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 2', solve([['abcd', 1, 3, 'Z', False, False, True, False]] * N), [['aZd', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 3', solve([['abcd', 1, 3, 'Backspace', False, False, True, False]] * N), [['ad', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 4', solve([['abcd', 1, 3, 'Delete', False, False, True, False]] * N), [['ad', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 5', solve([['abcd', 2, 2, 'Backspace', False, False, True, False]] * N), [['acd', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 6', solve([['abcd', 1, 1, 'Delete', False, False, True, False]] * N), [['acd', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 7', solve([['abc', 0, 0, 'Backspace', False, False, True, False]] * N), [['abc', 0, 0, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 8', solve([['abc', 0, 3, 'Delete', False, False, True, False]] * N), [['', 0, 0, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 9', solve([['abc', 1, 1, 'X', True, False, False, False]] * N), [['aXbc', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 10', solve([['abc', 1, 1, 'X', True, False, True, False]] * N), [['abc', 1, 1, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 11', solve([['abc', 1, 1, 'X', False, True, False, False]] * N), [['abc', 1, 1, ['keydown', 'beforeinput', 'keyup']]] * N)
check('key-default-edit scenario 12', solve([['abc', 1, 1, 'X', False, False, True, True]] * N), [['abc', 1, 1, ['keydown', 'keyup']]] * N)
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(cases):
    def run(c):
        text,lo,hi,key,prevent_down,prevent_before,cancelable,readonly=c
        log=['keydown']; original=[text,lo,hi]
        if prevent_down and cancelable:
            return original+[log+['keyup']]
        if readonly or not (len(key)==1 or key in ('Backspace','Delete')):
            return original+[log+['keyup']]
        insert=key if len(key)==1 else ''
        if key=='Backspace' and lo==hi: lo=max(0,lo-1)
        elif key=='Delete' and lo==hi: hi=min(len(text),hi+1)
        changed=text[:lo]+insert+text[hi:]
        if not changed:
            return original+[log+['keyup']]
        log.append('beforeinput')
        if prevent_before:
            return original+[log+['keyup']]
        text=changed
        hi=lo+len(insert); lo=hi
        log.append('input')
        return [text,lo,hi,log+['keyup']]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('key-default-edit scenario 0', solve([['abc', 1, 1, 'X', False, False, True, False]] * N), [['aXbc', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 1', solve([['abc', 1, 2, 'XY', False, False, True, False]] * N), [['abc', 1, 2, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 2', solve([['abcd', 1, 3, 'Z', False, False, True, False]] * N), [['aZd', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 3', solve([['abcd', 1, 3, 'Backspace', False, False, True, False]] * N), [['ad', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 4', solve([['abcd', 1, 3, 'Delete', False, False, True, False]] * N), [['ad', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 5', solve([['abcd', 2, 2, 'Backspace', False, False, True, False]] * N), [['acd', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 6', solve([['abcd', 1, 1, 'Delete', False, False, True, False]] * N), [['acd', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 7', solve([['abc', 0, 0, 'Backspace', False, False, True, False]] * N), [['abc', 0, 0, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 8', solve([['abc', 0, 3, 'Delete', False, False, True, False]] * N), [['', 0, 0, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 9', solve([['abc', 1, 1, 'X', True, False, False, False]] * N), [['aXbc', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 10', solve([['abc', 1, 1, 'X', True, False, True, False]] * N), [['abc', 1, 1, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 11', solve([['abc', 1, 1, 'X', False, True, False, False]] * N), [['abc', 1, 1, ['keydown', 'beforeinput', 'keyup']]] * N)
check('key-default-edit scenario 12', solve([['abc', 1, 1, 'X', False, False, True, True]] * N), [['abc', 1, 1, ['keydown', 'keyup']]] * N)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The event trace violates the no op events rule and produces incorrect keyboard state or command output.

Case [text,lo,hi,key,prevent_down,prevent_before,cancelable,readonly]. Selection is a valid half-open code-point interval. Printable single characters replace selection, Backspace deletes previous point and Delete deletes next point for collapsed selections. Other keys do not edit. A cancelable prevented keydown stops editing; readonly suppresses beforeinput. A changed candidate fires beforeinput, cancellation suppresses mutation; successful edit fires input. Always log keydown and keyup. Return text, selection endpoints and event log. Inputs are finite ordered event traces; return the stated deterministic state. Batch entries are independent. N varies the number of independent input transactions.

split: open-access


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

N = 1
observations = []
def solve(cases):
    def run(c):
        text,lo,hi,key,prevent_down,prevent_before,cancelable,readonly=c
        log=['keydown']; original=[text,lo,hi]
        if prevent_down and cancelable:
            return original+[log+['keyup']]
        if readonly or not (len(key)==1 or key in ('Backspace','Delete')):
            return original+[log+['keyup']]
        insert=key if len(key)==1 else ''
        if key=='Backspace' and lo==hi: lo=max(0,lo-1)
        elif key=='Delete' and lo==hi: hi=min(len(text),hi+1)
        changed=text[:lo]+insert+text[hi:]
        if changed==text:
            return original+[log+['keyup']]
        log.append('beforeinput')
        if prevent_before and cancelable:
            return original+[log+['keyup']]
        text=changed
        hi=lo+len(insert); lo=hi
        log.append('input')
        return [text,lo,hi,log+['keyup']]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('key-default-edit scenario 0', solve([['abc', 1, 1, 'X', False, False, True, False]] * N), [['aXbc', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 1', solve([['abc', 1, 2, 'XY', False, False, True, False]] * N), [['abc', 1, 2, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 2', solve([['abcd', 1, 3, 'Z', False, False, True, False]] * N), [['aZd', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 3', solve([['abcd', 1, 3, 'Backspace', False, False, True, False]] * N), [['ad', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 4', solve([['abcd', 1, 3, 'Delete', False, False, True, False]] * N), [['ad', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 5', solve([['abcd', 2, 2, 'Backspace', False, False, True, False]] * N), [['acd', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 6', solve([['abcd', 1, 1, 'Delete', False, False, True, False]] * N), [['acd', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 7', solve([['abc', 0, 0, 'Backspace', False, False, True, False]] * N), [['abc', 0, 0, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 8', solve([['abc', 0, 3, 'Delete', False, False, True, False]] * N), [['', 0, 0, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 9', solve([['abc', 1, 1, 'X', True, False, False, False]] * N), [['aXbc', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 10', solve([['abc', 1, 1, 'X', True, False, True, False]] * N), [['abc', 1, 1, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 11', solve([['abc', 1, 1, 'X', False, True, False, False]] * N), [['abc', 1, 1, ['keydown', 'beforeinput', 'keyup']]] * N)
check('key-default-edit scenario 12', solve([['abc', 1, 1, 'X', False, False, True, True]] * N), [['abc', 1, 1, ['keydown', 'keyup']]] * N)
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(cases):
    def run(c):
        text,lo,hi,key,prevent_down,prevent_before,cancelable,readonly=c
        log=['keydown']; original=[text,lo,hi]
        if prevent_down and cancelable:
            return original+[log+['keyup']]
        if readonly or not (len(key)==1 or key in ('Backspace','Delete')):
            return original+[log+['keyup']]
        insert=key if len(key)==1 else ''
        if key=='Backspace' and lo==hi: lo=max(0,lo-1)
        elif key=='Delete' and lo==hi: hi=min(len(text),hi+1)
        changed=text[:lo]+insert+text[hi:]
        if changed==text:
            return original+[log+['keyup']]
        log.append('beforeinput')
        if prevent_before and prevent_down:
            return original+[log+['keyup']]
        text=changed
        hi=lo+len(insert); lo=hi
        log.append('input')
        return [text,lo,hi,log+['keyup']]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('key-default-edit scenario 0', solve([['abc', 1, 1, 'X', False, False, True, False]] * N), [['aXbc', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 1', solve([['abc', 1, 2, 'XY', False, False, True, False]] * N), [['abc', 1, 2, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 2', solve([['abcd', 1, 3, 'Z', False, False, True, False]] * N), [['aZd', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 3', solve([['abcd', 1, 3, 'Backspace', False, False, True, False]] * N), [['ad', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 4', solve([['abcd', 1, 3, 'Delete', False, False, True, False]] * N), [['ad', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 5', solve([['abcd', 2, 2, 'Backspace', False, False, True, False]] * N), [['acd', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 6', solve([['abcd', 1, 1, 'Delete', False, False, True, False]] * N), [['acd', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 7', solve([['abc', 0, 0, 'Backspace', False, False, True, False]] * N), [['abc', 0, 0, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 8', solve([['abc', 0, 3, 'Delete', False, False, True, False]] * N), [['', 0, 0, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 9', solve([['abc', 1, 1, 'X', True, False, False, False]] * N), [['aXbc', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 10', solve([['abc', 1, 1, 'X', True, False, True, False]] * N), [['abc', 1, 1, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 11', solve([['abc', 1, 1, 'X', False, True, False, False]] * N), [['abc', 1, 1, ['keydown', 'beforeinput', 'keyup']]] * N)
check('key-default-edit scenario 12', solve([['abc', 1, 1, 'X', False, False, True, True]] * N), [['abc', 1, 1, ['keydown', 'keyup']]] * N)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The event trace violates the beforeinput cancel rule and produces incorrect keyboard state or command output.

Case [text,lo,hi,key,prevent_down,prevent_before,cancelable,readonly]. Selection is a valid half-open code-point interval. Printable single characters replace selection, Backspace deletes previous point and Delete deletes next point for collapsed selections. Other keys do not edit. A cancelable prevented keydown stops editing; readonly suppresses beforeinput. A changed candidate fires beforeinput, cancellation suppresses mutation; successful edit fires input. Always log keydown and keyup. Return text, selection endpoints and event log. Inputs are finite ordered event traces; return the stated deterministic state. Batch entries are independent. N varies the number of independent input transactions.

split: open-access


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

N = 1
observations = []
def solve(cases):
    def run(c):
        text,lo,hi,key,prevent_down,prevent_before,cancelable,readonly=c
        log=['keydown']; original=[text,lo,hi]
        if prevent_down and cancelable:
            return original+[log+['keyup']]
        if readonly or not (len(key)==1 or key in ('Backspace','Delete')):
            return original+[log+['keyup']]
        insert=key if len(key)==1 else ''
        if key=='Backspace' and lo==hi: lo=max(0,lo-1)
        elif key=='Delete' and lo==hi: hi=min(len(text),hi+1)
        changed=text[:lo]+insert+text[hi:]
        if changed==text:
            return original+[log+['keyup']]
        log.append('beforeinput')
        if prevent_before:
            return original+[log+['keyup']]
        text=changed
        hi=lo+len(insert); lo=hi
        log.append('input')
        return [text,lo,hi,log]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('key-default-edit scenario 0', solve([['abc', 1, 1, 'X', False, False, True, False]] * N), [['aXbc', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 1', solve([['abc', 1, 2, 'XY', False, False, True, False]] * N), [['abc', 1, 2, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 2', solve([['abcd', 1, 3, 'Z', False, False, True, False]] * N), [['aZd', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 3', solve([['abcd', 1, 3, 'Backspace', False, False, True, False]] * N), [['ad', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 4', solve([['abcd', 1, 3, 'Delete', False, False, True, False]] * N), [['ad', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 5', solve([['abcd', 2, 2, 'Backspace', False, False, True, False]] * N), [['acd', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 6', solve([['abcd', 1, 1, 'Delete', False, False, True, False]] * N), [['acd', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 7', solve([['abc', 0, 0, 'Backspace', False, False, True, False]] * N), [['abc', 0, 0, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 8', solve([['abc', 0, 3, 'Delete', False, False, True, False]] * N), [['', 0, 0, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 9', solve([['abc', 1, 1, 'X', True, False, False, False]] * N), [['aXbc', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 10', solve([['abc', 1, 1, 'X', True, False, True, False]] * N), [['abc', 1, 1, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 11', solve([['abc', 1, 1, 'X', False, True, False, False]] * N), [['abc', 1, 1, ['keydown', 'beforeinput', 'keyup']]] * N)
check('key-default-edit scenario 12', solve([['abc', 1, 1, 'X', False, False, True, True]] * N), [['abc', 1, 1, ['keydown', 'keyup']]] * N)
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(cases):
    def run(c):
        text,lo,hi,key,prevent_down,prevent_before,cancelable,readonly=c
        log=['keydown']; original=[text,lo,hi]
        if prevent_down and cancelable:
            return original+[log+['keyup']]
        if readonly or not (len(key)==1 or key in ('Backspace','Delete')):
            return original+[log+['keyup']]
        insert=key if len(key)==1 else ''
        if key=='Backspace' and lo==hi: lo=max(0,lo-1)
        elif key=='Delete' and lo==hi: hi=min(len(text),hi+1)
        changed=text[:lo]+insert+text[hi:]
        if changed==text:
            return original+[log+['keyup']]
        log.append('beforeinput')
        if prevent_before:
            return original+[log+['keyup']]
        text=changed
        hi=lo+len(insert); lo=hi
        log.append('input')
        return [text,lo,hi,['keyup']+log]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('key-default-edit scenario 0', solve([['abc', 1, 1, 'X', False, False, True, False]] * N), [['aXbc', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 1', solve([['abc', 1, 2, 'XY', False, False, True, False]] * N), [['abc', 1, 2, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 2', solve([['abcd', 1, 3, 'Z', False, False, True, False]] * N), [['aZd', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 3', solve([['abcd', 1, 3, 'Backspace', False, False, True, False]] * N), [['ad', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 4', solve([['abcd', 1, 3, 'Delete', False, False, True, False]] * N), [['ad', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 5', solve([['abcd', 2, 2, 'Backspace', False, False, True, False]] * N), [['acd', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 6', solve([['abcd', 1, 1, 'Delete', False, False, True, False]] * N), [['acd', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 7', solve([['abc', 0, 0, 'Backspace', False, False, True, False]] * N), [['abc', 0, 0, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 8', solve([['abc', 0, 3, 'Delete', False, False, True, False]] * N), [['', 0, 0, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 9', solve([['abc', 1, 1, 'X', True, False, False, False]] * N), [['aXbc', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 10', solve([['abc', 1, 1, 'X', True, False, True, False]] * N), [['abc', 1, 1, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 11', solve([['abc', 1, 1, 'X', False, True, False, False]] * N), [['abc', 1, 1, ['keydown', 'beforeinput', 'keyup']]] * N)
check('key-default-edit scenario 12', solve([['abc', 1, 1, 'X', False, False, True, True]] * N), [['abc', 1, 1, ['keydown', 'keyup']]] * N)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The event trace violates the keyup completion rule and produces incorrect keyboard state or command output.

Case [text,lo,hi,key,prevent_down,prevent_before,cancelable,readonly]. Selection is a valid half-open code-point interval. Printable single characters replace selection, Backspace deletes previous point and Delete deletes next point for collapsed selections. Other keys do not edit. A cancelable prevented keydown stops editing; readonly suppresses beforeinput. A changed candidate fires beforeinput, cancellation suppresses mutation; successful edit fires input. Always log keydown and keyup. Return text, selection endpoints and event log. Inputs are finite ordered event traces; return the stated deterministic state. Batch entries are independent. N varies the number of independent input transactions.

split: open-access


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

N = 1
observations = []
def solve(cases):
    def run(c):
        text,lo,hi,key,prevent_down,prevent_before,cancelable,readonly=c
        log=['keydown']; original=[text,lo,hi]
        if prevent_down and cancelable:
            return original+[log+['keyup']]
        if readonly or not (len(key)==1 or key in ('Backspace','Delete')):
            return original+[log+['keyup']]
        insert=key if len(key)==1 else ''
        if key=='Backspace' and lo==hi: lo=max(0,lo-1)
        elif key=='Delete' and lo==hi: hi=min(len(text),hi+1)
        changed=text[:lo]+insert+text[hi:]
        if changed==text:
            return original+[log+['keyup']]
        log.append('beforeinput')
        if prevent_before:
            return original+[log+['keyup']]
        text=changed
        hi=lo+len(insert); lo=hi
        log.append('beforeinput')
        return [text,lo,hi,log+['keyup']]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('key-default-edit scenario 0', solve([['abc', 1, 1, 'X', False, False, True, False]] * N), [['aXbc', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 1', solve([['abc', 1, 2, 'XY', False, False, True, False]] * N), [['abc', 1, 2, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 2', solve([['abcd', 1, 3, 'Z', False, False, True, False]] * N), [['aZd', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 3', solve([['abcd', 1, 3, 'Backspace', False, False, True, False]] * N), [['ad', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 4', solve([['abcd', 1, 3, 'Delete', False, False, True, False]] * N), [['ad', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 5', solve([['abcd', 2, 2, 'Backspace', False, False, True, False]] * N), [['acd', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 6', solve([['abcd', 1, 1, 'Delete', False, False, True, False]] * N), [['acd', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 7', solve([['abc', 0, 0, 'Backspace', False, False, True, False]] * N), [['abc', 0, 0, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 8', solve([['abc', 0, 3, 'Delete', False, False, True, False]] * N), [['', 0, 0, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 9', solve([['abc', 1, 1, 'X', True, False, False, False]] * N), [['aXbc', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 10', solve([['abc', 1, 1, 'X', True, False, True, False]] * N), [['abc', 1, 1, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 11', solve([['abc', 1, 1, 'X', False, True, False, False]] * N), [['abc', 1, 1, ['keydown', 'beforeinput', 'keyup']]] * N)
check('key-default-edit scenario 12', solve([['abc', 1, 1, 'X', False, False, True, True]] * N), [['abc', 1, 1, ['keydown', 'keyup']]] * N)
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(cases):
    def run(c):
        text,lo,hi,key,prevent_down,prevent_before,cancelable,readonly=c
        log=['keydown']; original=[text,lo,hi]
        if prevent_down and cancelable:
            return original+[log+['keyup']]
        if readonly or not (len(key)==1 or key in ('Backspace','Delete')):
            return original+[log+['keyup']]
        insert=key if len(key)==1 else ''
        if key=='Backspace' and lo==hi: lo=max(0,lo-1)
        elif key=='Delete' and lo==hi: hi=min(len(text),hi+1)
        changed=text[:lo]+insert+text[hi:]
        if changed==text:
            return original+[log+['keyup']]
        log.append('beforeinput')
        if prevent_before:
            return original+[log+['keyup']]
        text=changed
        hi=lo+len(insert); lo=hi
        log.append('change')
        return [text,lo,hi,log+['keyup']]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('key-default-edit scenario 0', solve([['abc', 1, 1, 'X', False, False, True, False]] * N), [['aXbc', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 1', solve([['abc', 1, 2, 'XY', False, False, True, False]] * N), [['abc', 1, 2, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 2', solve([['abcd', 1, 3, 'Z', False, False, True, False]] * N), [['aZd', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 3', solve([['abcd', 1, 3, 'Backspace', False, False, True, False]] * N), [['ad', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 4', solve([['abcd', 1, 3, 'Delete', False, False, True, False]] * N), [['ad', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 5', solve([['abcd', 2, 2, 'Backspace', False, False, True, False]] * N), [['acd', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 6', solve([['abcd', 1, 1, 'Delete', False, False, True, False]] * N), [['acd', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 7', solve([['abc', 0, 0, 'Backspace', False, False, True, False]] * N), [['abc', 0, 0, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 8', solve([['abc', 0, 3, 'Delete', False, False, True, False]] * N), [['', 0, 0, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 9', solve([['abc', 1, 1, 'X', True, False, False, False]] * N), [['aXbc', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 10', solve([['abc', 1, 1, 'X', True, False, True, False]] * N), [['abc', 1, 1, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 11', solve([['abc', 1, 1, 'X', False, True, False, False]] * N), [['abc', 1, 1, ['keydown', 'beforeinput', 'keyup']]] * N)
check('key-default-edit scenario 12', solve([['abc', 1, 1, 'X', False, False, True, True]] * N), [['abc', 1, 1, ['keydown', 'keyup']]] * N)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The event trace violates the input notification rule and produces incorrect keyboard state or command output.

Case [text,lo,hi,key,prevent_down,prevent_before,cancelable,readonly]. Selection is a valid half-open code-point interval. Printable single characters replace selection, Backspace deletes previous point and Delete deletes next point for collapsed selections. Other keys do not edit. A cancelable prevented keydown stops editing; readonly suppresses beforeinput. A changed candidate fires beforeinput, cancellation suppresses mutation; successful edit fires input. Always log keydown and keyup. Return text, selection endpoints and event log. Inputs are finite ordered event traces; return the stated deterministic state. Batch entries are independent. N varies the number of independent input transactions.

split: open-access


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

N = 1
observations = []
def solve(cases):
    def run(c):
        sequence,timeout,events=c
        buffer=[]; last=None; matches=[]
        for kind,key,now,repeat in events:
            if kind=='cancel': buffer=[]
            elif kind=='tick':
                if last is not None and now-last>timeout: buffer=[]; last=None
            elif kind=='down' and not repeat:
                if last is not None and now-last>timeout: buffer=[]
                candidate=buffer+[key]
                last=now
                buffer=[]
                for size in range(min(len(sequence),len(candidate)),0,-1):
                    if candidate[-size:]==sequence[:size]:
                        buffer=candidate[-size:]
                        break
                if buffer==sequence:
                    matches.append(now)
                    buffer=[]
                    for size in range(len(sequence)-1,0,-1):
                        if sequence[-size:]==sequence[:size]:
                            buffer=sequence[:size]
                            break
        return [matches,buffer,last]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('sequence-prefix scenario 0', solve([[['A', 'B'], 5, []]] * N), [[[], [], None]] * N)
check('sequence-prefix scenario 1', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 15, False]]]] * N), [[[15], [], 15]] * N)
check('sequence-prefix scenario 2', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['tick', '', 15, False]]]] * N), [[[], ['A'], 10]] * N)
check('sequence-prefix scenario 3', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 16, False]]]] * N), [[[], [], 16]] * N)
check('sequence-prefix scenario 4', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 11, True], ['up', 'B', 12, False]]]] * N), [[[], ['A'], 10]] * N)
check('sequence-prefix scenario 5', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['cancel', '', 11, False]]]] * N), [[[], [], None]] * N)
check('sequence-prefix scenario 6', solve([[['A', 'B', 'A'], 5, [['down', 'A', 10, False], ['down', 'B', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'A', 14, False]]]] * N), [[[12, 14], ['A'], 14]] * N)
check('sequence-prefix scenario 7', solve([[['A', 'B', 'A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'A', 14, False], ['down', 'B', 15, False]]]] * N), [[[13, 15], ['A', 'B'], 15]] * N)
check('sequence-prefix scenario 8', solve([[['A', 'A', 'B'], 5, [['down', 'A', 10, False], ['down', 'A', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False]]]] * N), [[[13], [], 13]] * N)
check('sequence-prefix scenario 9', solve([[['A', 'B', 'C'], 5, [['down', 'A', 10, False], ['down', 'X', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'C', 14, False]]]] * N), [[[14], [], 14]] * N)
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(cases):
    def run(c):
        sequence,timeout,events=c
        buffer=[]; last=None; matches=[]
        for kind,key,now,repeat in events:
            if kind=='cancel': last=None
            elif kind=='tick':
                if last is not None and now-last>timeout: buffer=[]; last=None
            elif kind=='down' and not repeat:
                if last is not None and now-last>timeout: buffer=[]
                candidate=buffer+[key]
                last=now
                buffer=[]
                for size in range(min(len(sequence),len(candidate)),0,-1):
                    if candidate[-size:]==sequence[:size]:
                        buffer=candidate[-size:]
                        break
                if buffer==sequence:
                    matches.append(now)
                    buffer=[]
                    for size in range(len(sequence)-1,0,-1):
                        if sequence[-size:]==sequence[:size]:
                            buffer=sequence[:size]
                            break
        return [matches,buffer,last]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('sequence-prefix scenario 0', solve([[['A', 'B'], 5, []]] * N), [[[], [], None]] * N)
check('sequence-prefix scenario 1', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 15, False]]]] * N), [[[15], [], 15]] * N)
check('sequence-prefix scenario 2', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['tick', '', 15, False]]]] * N), [[[], ['A'], 10]] * N)
check('sequence-prefix scenario 3', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 16, False]]]] * N), [[[], [], 16]] * N)
check('sequence-prefix scenario 4', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 11, True], ['up', 'B', 12, False]]]] * N), [[[], ['A'], 10]] * N)
check('sequence-prefix scenario 5', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['cancel', '', 11, False]]]] * N), [[[], [], None]] * N)
check('sequence-prefix scenario 6', solve([[['A', 'B', 'A'], 5, [['down', 'A', 10, False], ['down', 'B', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'A', 14, False]]]] * N), [[[12, 14], ['A'], 14]] * N)
check('sequence-prefix scenario 7', solve([[['A', 'B', 'A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'A', 14, False], ['down', 'B', 15, False]]]] * N), [[[13, 15], ['A', 'B'], 15]] * N)
check('sequence-prefix scenario 8', solve([[['A', 'A', 'B'], 5, [['down', 'A', 10, False], ['down', 'A', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False]]]] * N), [[[13], [], 13]] * N)
check('sequence-prefix scenario 9', solve([[['A', 'B', 'C'], 5, [['down', 'A', 10, False], ['down', 'X', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'C', 14, False]]]] * N), [[[14], [], 14]] * N)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The event trace violates the cancel clock rule and produces incorrect keyboard state or command output.

Case [sequence,timeout,events]. Nonempty sequence is list of key names. Events [kind,key,time,repeat]. Only nonrepeat down feeds matcher. Accepted downs more than timeout after the previous accepted down discard the prefix; tick likewise expires it. Cancel resets prefix and clock. Keep longest suffix matching a sequence prefix, and after a match retain the longest proper overlapping prefix. Return match timestamps, partial prefix and last accepted time. Inputs are finite ordered event traces; return the stated deterministic state. Batch entries are independent. N varies the number of independent input transactions.

split: open-access


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

N = 1
observations = []
def solve(cases):
    def run(c):
        sequence,timeout,events=c
        buffer=[]; last=None; matches=[]
        for kind,key,now,repeat in events:
            if kind=='cancel': buffer=[]; last=None
            elif kind=='tick':
                if last is not None and now-last>=timeout: buffer=[]; last=None
            elif kind=='down' and not repeat:
                if last is not None and now-last>timeout: buffer=[]
                candidate=buffer+[key]
                last=now
                buffer=[]
                for size in range(min(len(sequence),len(candidate)),0,-1):
                    if candidate[-size:]==sequence[:size]:
                        buffer=candidate[-size:]
                        break
                if buffer==sequence:
                    matches.append(now)
                    buffer=[]
                    for size in range(len(sequence)-1,0,-1):
                        if sequence[-size:]==sequence[:size]:
                            buffer=sequence[:size]
                            break
        return [matches,buffer,last]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('sequence-prefix scenario 0', solve([[['A', 'B'], 5, []]] * N), [[[], [], None]] * N)
check('sequence-prefix scenario 1', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 15, False]]]] * N), [[[15], [], 15]] * N)
check('sequence-prefix scenario 2', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['tick', '', 15, False]]]] * N), [[[], ['A'], 10]] * N)
check('sequence-prefix scenario 3', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 16, False]]]] * N), [[[], [], 16]] * N)
check('sequence-prefix scenario 4', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 11, True], ['up', 'B', 12, False]]]] * N), [[[], ['A'], 10]] * N)
check('sequence-prefix scenario 5', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['cancel', '', 11, False]]]] * N), [[[], [], None]] * N)
check('sequence-prefix scenario 6', solve([[['A', 'B', 'A'], 5, [['down', 'A', 10, False], ['down', 'B', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'A', 14, False]]]] * N), [[[12, 14], ['A'], 14]] * N)
check('sequence-prefix scenario 7', solve([[['A', 'B', 'A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'A', 14, False], ['down', 'B', 15, False]]]] * N), [[[13, 15], ['A', 'B'], 15]] * N)
check('sequence-prefix scenario 8', solve([[['A', 'A', 'B'], 5, [['down', 'A', 10, False], ['down', 'A', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False]]]] * N), [[[13], [], 13]] * N)
check('sequence-prefix scenario 9', solve([[['A', 'B', 'C'], 5, [['down', 'A', 10, False], ['down', 'X', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'C', 14, False]]]] * N), [[[14], [], 14]] * N)
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(cases):
    def run(c):
        sequence,timeout,events=c
        buffer=[]; last=None; matches=[]
        for kind,key,now,repeat in events:
            if kind=='cancel': buffer=[]; last=None
            elif kind=='tick':
                if last is not None and now>timeout: buffer=[]; last=None
            elif kind=='down' and not repeat:
                if last is not None and now-last>timeout: buffer=[]
                candidate=buffer+[key]
                last=now
                buffer=[]
                for size in range(min(len(sequence),len(candidate)),0,-1):
                    if candidate[-size:]==sequence[:size]:
                        buffer=candidate[-size:]
                        break
                if buffer==sequence:
                    matches.append(now)
                    buffer=[]
                    for size in range(len(sequence)-1,0,-1):
                        if sequence[-size:]==sequence[:size]:
                            buffer=sequence[:size]
                            break
        return [matches,buffer,last]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('sequence-prefix scenario 0', solve([[['A', 'B'], 5, []]] * N), [[[], [], None]] * N)
check('sequence-prefix scenario 1', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 15, False]]]] * N), [[[15], [], 15]] * N)
check('sequence-prefix scenario 2', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['tick', '', 15, False]]]] * N), [[[], ['A'], 10]] * N)
check('sequence-prefix scenario 3', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 16, False]]]] * N), [[[], [], 16]] * N)
check('sequence-prefix scenario 4', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 11, True], ['up', 'B', 12, False]]]] * N), [[[], ['A'], 10]] * N)
check('sequence-prefix scenario 5', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['cancel', '', 11, False]]]] * N), [[[], [], None]] * N)
check('sequence-prefix scenario 6', solve([[['A', 'B', 'A'], 5, [['down', 'A', 10, False], ['down', 'B', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'A', 14, False]]]] * N), [[[12, 14], ['A'], 14]] * N)
check('sequence-prefix scenario 7', solve([[['A', 'B', 'A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'A', 14, False], ['down', 'B', 15, False]]]] * N), [[[13, 15], ['A', 'B'], 15]] * N)
check('sequence-prefix scenario 8', solve([[['A', 'A', 'B'], 5, [['down', 'A', 10, False], ['down', 'A', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False]]]] * N), [[[13], [], 13]] * N)
check('sequence-prefix scenario 9', solve([[['A', 'B', 'C'], 5, [['down', 'A', 10, False], ['down', 'X', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'C', 14, False]]]] * N), [[[14], [], 14]] * N)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The event trace violates the tick expiry rule and produces incorrect keyboard state or command output.

Case [sequence,timeout,events]. Nonempty sequence is list of key names. Events [kind,key,time,repeat]. Only nonrepeat down feeds matcher. Accepted downs more than timeout after the previous accepted down discard the prefix; tick likewise expires it. Cancel resets prefix and clock. Keep longest suffix matching a sequence prefix, and after a match retain the longest proper overlapping prefix. Return match timestamps, partial prefix and last accepted time. Inputs are finite ordered event traces; return the stated deterministic state. Batch entries are independent. N varies the number of independent input transactions.

split: open-access


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

N = 1
observations = []
def solve(cases):
    def run(c):
        sequence,timeout,events=c
        buffer=[]; last=None; matches=[]
        for kind,key,now,repeat in events:
            if kind=='cancel': buffer=[]; last=None
            elif kind=='tick':
                if last is not None and now-last>timeout: buffer=[]; last=None
            elif kind=='down':
                if last is not None and now-last>timeout: buffer=[]
                candidate=buffer+[key]
                last=now
                buffer=[]
                for size in range(min(len(sequence),len(candidate)),0,-1):
                    if candidate[-size:]==sequence[:size]:
                        buffer=candidate[-size:]
                        break
                if buffer==sequence:
                    matches.append(now)
                    buffer=[]
                    for size in range(len(sequence)-1,0,-1):
                        if sequence[-size:]==sequence[:size]:
                            buffer=sequence[:size]
                            break
        return [matches,buffer,last]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('sequence-prefix scenario 0', solve([[['A', 'B'], 5, []]] * N), [[[], [], None]] * N)
check('sequence-prefix scenario 1', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 15, False]]]] * N), [[[15], [], 15]] * N)
check('sequence-prefix scenario 2', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['tick', '', 15, False]]]] * N), [[[], ['A'], 10]] * N)
check('sequence-prefix scenario 3', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 16, False]]]] * N), [[[], [], 16]] * N)
check('sequence-prefix scenario 4', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 11, True], ['up', 'B', 12, False]]]] * N), [[[], ['A'], 10]] * N)
check('sequence-prefix scenario 5', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['cancel', '', 11, False]]]] * N), [[[], [], None]] * N)
check('sequence-prefix scenario 6', solve([[['A', 'B', 'A'], 5, [['down', 'A', 10, False], ['down', 'B', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'A', 14, False]]]] * N), [[[12, 14], ['A'], 14]] * N)
check('sequence-prefix scenario 7', solve([[['A', 'B', 'A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'A', 14, False], ['down', 'B', 15, False]]]] * N), [[[13, 15], ['A', 'B'], 15]] * N)
check('sequence-prefix scenario 8', solve([[['A', 'A', 'B'], 5, [['down', 'A', 10, False], ['down', 'A', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False]]]] * N), [[[13], [], 13]] * N)
check('sequence-prefix scenario 9', solve([[['A', 'B', 'C'], 5, [['down', 'A', 10, False], ['down', 'X', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'C', 14, False]]]] * N), [[[14], [], 14]] * N)
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(cases):
    def run(c):
        sequence,timeout,events=c
        buffer=[]; last=None; matches=[]
        for kind,key,now,repeat in events:
            if kind=='cancel': buffer=[]; last=None
            elif kind=='tick':
                if last is not None and now-last>timeout: buffer=[]; last=None
            elif kind in ('down','up') and not repeat:
                if last is not None and now-last>timeout: buffer=[]
                candidate=buffer+[key]
                last=now
                buffer=[]
                for size in range(min(len(sequence),len(candidate)),0,-1):
                    if candidate[-size:]==sequence[:size]:
                        buffer=candidate[-size:]
                        break
                if buffer==sequence:
                    matches.append(now)
                    buffer=[]
                    for size in range(len(sequence)-1,0,-1):
                        if sequence[-size:]==sequence[:size]:
                            buffer=sequence[:size]
                            break
        return [matches,buffer,last]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('sequence-prefix scenario 0', solve([[['A', 'B'], 5, []]] * N), [[[], [], None]] * N)
check('sequence-prefix scenario 1', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 15, False]]]] * N), [[[15], [], 15]] * N)
check('sequence-prefix scenario 2', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['tick', '', 15, False]]]] * N), [[[], ['A'], 10]] * N)
check('sequence-prefix scenario 3', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 16, False]]]] * N), [[[], [], 16]] * N)
check('sequence-prefix scenario 4', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 11, True], ['up', 'B', 12, False]]]] * N), [[[], ['A'], 10]] * N)
check('sequence-prefix scenario 5', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['cancel', '', 11, False]]]] * N), [[[], [], None]] * N)
check('sequence-prefix scenario 6', solve([[['A', 'B', 'A'], 5, [['down', 'A', 10, False], ['down', 'B', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'A', 14, False]]]] * N), [[[12, 14], ['A'], 14]] * N)
check('sequence-prefix scenario 7', solve([[['A', 'B', 'A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'A', 14, False], ['down', 'B', 15, False]]]] * N), [[[13, 15], ['A', 'B'], 15]] * N)
check('sequence-prefix scenario 8', solve([[['A', 'A', 'B'], 5, [['down', 'A', 10, False], ['down', 'A', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False]]]] * N), [[[13], [], 13]] * N)
check('sequence-prefix scenario 9', solve([[['A', 'B', 'C'], 5, [['down', 'A', 10, False], ['down', 'X', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'C', 14, False]]]] * N), [[[14], [], 14]] * N)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The event trace violates the repeat feed rule and produces incorrect keyboard state or command output.

Case [sequence,timeout,events]. Nonempty sequence is list of key names. Events [kind,key,time,repeat]. Only nonrepeat down feeds matcher. Accepted downs more than timeout after the previous accepted down discard the prefix; tick likewise expires it. Cancel resets prefix and clock. Keep longest suffix matching a sequence prefix, and after a match retain the longest proper overlapping prefix. Return match timestamps, partial prefix and last accepted time. Inputs are finite ordered event traces; return the stated deterministic state. Batch entries are independent. N varies the number of independent input transactions.

split: open-access


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

N = 1
observations = []
def solve(cases):
    def run(c):
        sequence,timeout,events=c
        buffer=[]; last=None; matches=[]
        for kind,key,now,repeat in events:
            if kind=='cancel': buffer=[]; last=None
            elif kind=='tick':
                if last is not None and now-last>timeout: buffer=[]; last=None
            elif kind=='down' and not repeat:
                if last is not None and now-last>=timeout: buffer=[]
                candidate=buffer+[key]
                last=now
                buffer=[]
                for size in range(min(len(sequence),len(candidate)),0,-1):
                    if candidate[-size:]==sequence[:size]:
                        buffer=candidate[-size:]
                        break
                if buffer==sequence:
                    matches.append(now)
                    buffer=[]
                    for size in range(len(sequence)-1,0,-1):
                        if sequence[-size:]==sequence[:size]:
                            buffer=sequence[:size]
                            break
        return [matches,buffer,last]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('sequence-prefix scenario 0', solve([[['A', 'B'], 5, []]] * N), [[[], [], None]] * N)
check('sequence-prefix scenario 1', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 15, False]]]] * N), [[[15], [], 15]] * N)
check('sequence-prefix scenario 2', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['tick', '', 15, False]]]] * N), [[[], ['A'], 10]] * N)
check('sequence-prefix scenario 3', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 16, False]]]] * N), [[[], [], 16]] * N)
check('sequence-prefix scenario 4', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 11, True], ['up', 'B', 12, False]]]] * N), [[[], ['A'], 10]] * N)
check('sequence-prefix scenario 5', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['cancel', '', 11, False]]]] * N), [[[], [], None]] * N)
check('sequence-prefix scenario 6', solve([[['A', 'B', 'A'], 5, [['down', 'A', 10, False], ['down', 'B', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'A', 14, False]]]] * N), [[[12, 14], ['A'], 14]] * N)
check('sequence-prefix scenario 7', solve([[['A', 'B', 'A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'A', 14, False], ['down', 'B', 15, False]]]] * N), [[[13, 15], ['A', 'B'], 15]] * N)
check('sequence-prefix scenario 8', solve([[['A', 'A', 'B'], 5, [['down', 'A', 10, False], ['down', 'A', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False]]]] * N), [[[13], [], 13]] * N)
check('sequence-prefix scenario 9', solve([[['A', 'B', 'C'], 5, [['down', 'A', 10, False], ['down', 'X', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'C', 14, False]]]] * N), [[[14], [], 14]] * N)
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(cases):
    def run(c):
        sequence,timeout,events=c
        buffer=[]; last=None; matches=[]
        for kind,key,now,repeat in events:
            if kind=='cancel': buffer=[]; last=None
            elif kind=='tick':
                if last is not None and now-last>timeout: buffer=[]; last=None
            elif kind=='down' and not repeat:
                if last is not None and now>timeout: buffer=[]
                candidate=buffer+[key]
                last=now
                buffer=[]
                for size in range(min(len(sequence),len(candidate)),0,-1):
                    if candidate[-size:]==sequence[:size]:
                        buffer=candidate[-size:]
                        break
                if buffer==sequence:
                    matches.append(now)
                    buffer=[]
                    for size in range(len(sequence)-1,0,-1):
                        if sequence[-size:]==sequence[:size]:
                            buffer=sequence[:size]
                            break
        return [matches,buffer,last]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('sequence-prefix scenario 0', solve([[['A', 'B'], 5, []]] * N), [[[], [], None]] * N)
check('sequence-prefix scenario 1', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 15, False]]]] * N), [[[15], [], 15]] * N)
check('sequence-prefix scenario 2', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['tick', '', 15, False]]]] * N), [[[], ['A'], 10]] * N)
check('sequence-prefix scenario 3', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 16, False]]]] * N), [[[], [], 16]] * N)
check('sequence-prefix scenario 4', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 11, True], ['up', 'B', 12, False]]]] * N), [[[], ['A'], 10]] * N)
check('sequence-prefix scenario 5', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['cancel', '', 11, False]]]] * N), [[[], [], None]] * N)
check('sequence-prefix scenario 6', solve([[['A', 'B', 'A'], 5, [['down', 'A', 10, False], ['down', 'B', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'A', 14, False]]]] * N), [[[12, 14], ['A'], 14]] * N)
check('sequence-prefix scenario 7', solve([[['A', 'B', 'A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'A', 14, False], ['down', 'B', 15, False]]]] * N), [[[13, 15], ['A', 'B'], 15]] * N)
check('sequence-prefix scenario 8', solve([[['A', 'A', 'B'], 5, [['down', 'A', 10, False], ['down', 'A', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False]]]] * N), [[[13], [], 13]] * N)
check('sequence-prefix scenario 9', solve([[['A', 'B', 'C'], 5, [['down', 'A', 10, False], ['down', 'X', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'C', 14, False]]]] * N), [[[14], [], 14]] * N)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The event trace violates the input expiry rule and produces incorrect keyboard state or command output.

Case [sequence,timeout,events]. Nonempty sequence is list of key names. Events [kind,key,time,repeat]. Only nonrepeat down feeds matcher. Accepted downs more than timeout after the previous accepted down discard the prefix; tick likewise expires it. Cancel resets prefix and clock. Keep longest suffix matching a sequence prefix, and after a match retain the longest proper overlapping prefix. Return match timestamps, partial prefix and last accepted time. Inputs are finite ordered event traces; return the stated deterministic state. Batch entries are independent. N varies the number of independent input transactions.

split: open-access


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

N = 1
observations = []
def solve(cases):
    def run(c):
        sequence,timeout,events=c
        buffer=[]; last=None; matches=[]
        for kind,key,now,repeat in events:
            if kind=='cancel': buffer=[]; last=None
            elif kind=='tick':
                if last is not None and now-last>timeout: buffer=[]; last=None
            elif kind=='down' and not repeat:
                if last is not None and now-last>timeout: buffer=[]
                candidate=[key]+buffer
                last=now
                buffer=[]
                for size in range(min(len(sequence),len(candidate)),0,-1):
                    if candidate[-size:]==sequence[:size]:
                        buffer=candidate[-size:]
                        break
                if buffer==sequence:
                    matches.append(now)
                    buffer=[]
                    for size in range(len(sequence)-1,0,-1):
                        if sequence[-size:]==sequence[:size]:
                            buffer=sequence[:size]
                            break
        return [matches,buffer,last]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('sequence-prefix scenario 0', solve([[['A', 'B'], 5, []]] * N), [[[], [], None]] * N)
check('sequence-prefix scenario 1', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 15, False]]]] * N), [[[15], [], 15]] * N)
check('sequence-prefix scenario 2', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['tick', '', 15, False]]]] * N), [[[], ['A'], 10]] * N)
check('sequence-prefix scenario 3', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 16, False]]]] * N), [[[], [], 16]] * N)
check('sequence-prefix scenario 4', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 11, True], ['up', 'B', 12, False]]]] * N), [[[], ['A'], 10]] * N)
check('sequence-prefix scenario 5', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['cancel', '', 11, False]]]] * N), [[[], [], None]] * N)
check('sequence-prefix scenario 6', solve([[['A', 'B', 'A'], 5, [['down', 'A', 10, False], ['down', 'B', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'A', 14, False]]]] * N), [[[12, 14], ['A'], 14]] * N)
check('sequence-prefix scenario 7', solve([[['A', 'B', 'A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'A', 14, False], ['down', 'B', 15, False]]]] * N), [[[13, 15], ['A', 'B'], 15]] * N)
check('sequence-prefix scenario 8', solve([[['A', 'A', 'B'], 5, [['down', 'A', 10, False], ['down', 'A', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False]]]] * N), [[[13], [], 13]] * N)
check('sequence-prefix scenario 9', solve([[['A', 'B', 'C'], 5, [['down', 'A', 10, False], ['down', 'X', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'C', 14, False]]]] * N), [[[14], [], 14]] * N)
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(cases):
    def run(c):
        sequence,timeout,events=c
        buffer=[]; last=None; matches=[]
        for kind,key,now,repeat in events:
            if kind=='cancel': buffer=[]; last=None
            elif kind=='tick':
                if last is not None and now-last>timeout: buffer=[]; last=None
            elif kind=='down' and not repeat:
                if last is not None and now-last>timeout: buffer=[]
                candidate=[key]
                last=now
                buffer=[]
                for size in range(min(len(sequence),len(candidate)),0,-1):
                    if candidate[-size:]==sequence[:size]:
                        buffer=candidate[-size:]
                        break
                if buffer==sequence:
                    matches.append(now)
                    buffer=[]
                    for size in range(len(sequence)-1,0,-1):
                        if sequence[-size:]==sequence[:size]:
                            buffer=sequence[:size]
                            break
        return [matches,buffer,last]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('sequence-prefix scenario 0', solve([[['A', 'B'], 5, []]] * N), [[[], [], None]] * N)
check('sequence-prefix scenario 1', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 15, False]]]] * N), [[[15], [], 15]] * N)
check('sequence-prefix scenario 2', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['tick', '', 15, False]]]] * N), [[[], ['A'], 10]] * N)
check('sequence-prefix scenario 3', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 16, False]]]] * N), [[[], [], 16]] * N)
check('sequence-prefix scenario 4', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 11, True], ['up', 'B', 12, False]]]] * N), [[[], ['A'], 10]] * N)
check('sequence-prefix scenario 5', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['cancel', '', 11, False]]]] * N), [[[], [], None]] * N)
check('sequence-prefix scenario 6', solve([[['A', 'B', 'A'], 5, [['down', 'A', 10, False], ['down', 'B', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'A', 14, False]]]] * N), [[[12, 14], ['A'], 14]] * N)
check('sequence-prefix scenario 7', solve([[['A', 'B', 'A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'A', 14, False], ['down', 'B', 15, False]]]] * N), [[[13, 15], ['A', 'B'], 15]] * N)
check('sequence-prefix scenario 8', solve([[['A', 'A', 'B'], 5, [['down', 'A', 10, False], ['down', 'A', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False]]]] * N), [[[13], [], 13]] * N)
check('sequence-prefix scenario 9', solve([[['A', 'B', 'C'], 5, [['down', 'A', 10, False], ['down', 'X', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'C', 14, False]]]] * N), [[[14], [], 14]] * N)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The event trace violates the candidate append rule and produces incorrect keyboard state or command output.

Case [sequence,timeout,events]. Nonempty sequence is list of key names. Events [kind,key,time,repeat]. Only nonrepeat down feeds matcher. Accepted downs more than timeout after the previous accepted down discard the prefix; tick likewise expires it. Cancel resets prefix and clock. Keep longest suffix matching a sequence prefix, and after a match retain the longest proper overlapping prefix. Return match timestamps, partial prefix and last accepted time. Inputs are finite ordered event traces; return the stated deterministic state. Batch entries are independent. N varies the number of independent input transactions.

split: open-access


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

N = 1
observations = []
def solve(cases):
    def run(c):
        sequence,timeout,events=c
        buffer=[]; last=None; matches=[]
        for kind,key,now,repeat in events:
            if kind=='cancel': buffer=[]; last=None
            elif kind=='tick':
                if last is not None and now-last>timeout: buffer=[]; last=None
            elif kind=='down' and not repeat:
                if last is not None and now-last>timeout: buffer=[]
                candidate=buffer+[key]
                last=0
                buffer=[]
                for size in range(min(len(sequence),len(candidate)),0,-1):
                    if candidate[-size:]==sequence[:size]:
                        buffer=candidate[-size:]
                        break
                if buffer==sequence:
                    matches.append(now)
                    buffer=[]
                    for size in range(len(sequence)-1,0,-1):
                        if sequence[-size:]==sequence[:size]:
                            buffer=sequence[:size]
                            break
        return [matches,buffer,last]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('sequence-prefix scenario 0', solve([[['A', 'B'], 5, []]] * N), [[[], [], None]] * N)
check('sequence-prefix scenario 1', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 15, False]]]] * N), [[[15], [], 15]] * N)
check('sequence-prefix scenario 2', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['tick', '', 15, False]]]] * N), [[[], ['A'], 10]] * N)
check('sequence-prefix scenario 3', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 16, False]]]] * N), [[[], [], 16]] * N)
check('sequence-prefix scenario 4', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 11, True], ['up', 'B', 12, False]]]] * N), [[[], ['A'], 10]] * N)
check('sequence-prefix scenario 5', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['cancel', '', 11, False]]]] * N), [[[], [], None]] * N)
check('sequence-prefix scenario 6', solve([[['A', 'B', 'A'], 5, [['down', 'A', 10, False], ['down', 'B', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'A', 14, False]]]] * N), [[[12, 14], ['A'], 14]] * N)
check('sequence-prefix scenario 7', solve([[['A', 'B', 'A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'A', 14, False], ['down', 'B', 15, False]]]] * N), [[[13, 15], ['A', 'B'], 15]] * N)
check('sequence-prefix scenario 8', solve([[['A', 'A', 'B'], 5, [['down', 'A', 10, False], ['down', 'A', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False]]]] * N), [[[13], [], 13]] * N)
check('sequence-prefix scenario 9', solve([[['A', 'B', 'C'], 5, [['down', 'A', 10, False], ['down', 'X', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'C', 14, False]]]] * N), [[[14], [], 14]] * N)
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(cases):
    def run(c):
        sequence,timeout,events=c
        buffer=[]; last=None; matches=[]
        for kind,key,now,repeat in events:
            if kind=='cancel': buffer=[]; last=None
            elif kind=='tick':
                if last is not None and now-last>timeout: buffer=[]; last=None
            elif kind=='down' and not repeat:
                if last is not None and now-last>timeout: buffer=[]
                candidate=buffer+[key]
                last=last if last is not None else now
                buffer=[]
                for size in range(min(len(sequence),len(candidate)),0,-1):
                    if candidate[-size:]==sequence[:size]:
                        buffer=candidate[-size:]
                        break
                if buffer==sequence:
                    matches.append(now)
                    buffer=[]
                    for size in range(len(sequence)-1,0,-1):
                        if sequence[-size:]==sequence[:size]:
                            buffer=sequence[:size]
                            break
        return [matches,buffer,last]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('sequence-prefix scenario 0', solve([[['A', 'B'], 5, []]] * N), [[[], [], None]] * N)
check('sequence-prefix scenario 1', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 15, False]]]] * N), [[[15], [], 15]] * N)
check('sequence-prefix scenario 2', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['tick', '', 15, False]]]] * N), [[[], ['A'], 10]] * N)
check('sequence-prefix scenario 3', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 16, False]]]] * N), [[[], [], 16]] * N)
check('sequence-prefix scenario 4', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 11, True], ['up', 'B', 12, False]]]] * N), [[[], ['A'], 10]] * N)
check('sequence-prefix scenario 5', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['cancel', '', 11, False]]]] * N), [[[], [], None]] * N)
check('sequence-prefix scenario 6', solve([[['A', 'B', 'A'], 5, [['down', 'A', 10, False], ['down', 'B', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'A', 14, False]]]] * N), [[[12, 14], ['A'], 14]] * N)
check('sequence-prefix scenario 7', solve([[['A', 'B', 'A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'A', 14, False], ['down', 'B', 15, False]]]] * N), [[[13, 15], ['A', 'B'], 15]] * N)
check('sequence-prefix scenario 8', solve([[['A', 'A', 'B'], 5, [['down', 'A', 10, False], ['down', 'A', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False]]]] * N), [[[13], [], 13]] * N)
check('sequence-prefix scenario 9', solve([[['A', 'B', 'C'], 5, [['down', 'A', 10, False], ['down', 'X', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'C', 14, False]]]] * N), [[[14], [], 14]] * N)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The event trace violates the accepted clock rule and produces incorrect keyboard state or command output.

Case [sequence,timeout,events]. Nonempty sequence is list of key names. Events [kind,key,time,repeat]. Only nonrepeat down feeds matcher. Accepted downs more than timeout after the previous accepted down discard the prefix; tick likewise expires it. Cancel resets prefix and clock. Keep longest suffix matching a sequence prefix, and after a match retain the longest proper overlapping prefix. Return match timestamps, partial prefix and last accepted time. Inputs are finite ordered event traces; return the stated deterministic state. Batch entries are independent. N varies the number of independent input transactions.

split: open-access


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

N = 1
observations = []
def solve(cases):
    def run(c):
        sequence,timeout,events=c
        buffer=[]; last=None; matches=[]
        for kind,key,now,repeat in events:
            if kind=='cancel': buffer=[]; last=None
            elif kind=='tick':
                if last is not None and now-last>timeout: buffer=[]; last=None
            elif kind=='down' and not repeat:
                if last is not None and now-last>timeout: buffer=[]
                candidate=buffer+[key]
                last=now
                buffer=[]
                for size in range(1,min(len(sequence),len(candidate))+1):
                    if candidate[-size:]==sequence[:size]:
                        buffer=candidate[-size:]
                        break
                if buffer==sequence:
                    matches.append(now)
                    buffer=[]
                    for size in range(len(sequence)-1,0,-1):
                        if sequence[-size:]==sequence[:size]:
                            buffer=sequence[:size]
                            break
        return [matches,buffer,last]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('sequence-prefix scenario 0', solve([[['A', 'B'], 5, []]] * N), [[[], [], None]] * N)
check('sequence-prefix scenario 1', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 15, False]]]] * N), [[[15], [], 15]] * N)
check('sequence-prefix scenario 2', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['tick', '', 15, False]]]] * N), [[[], ['A'], 10]] * N)
check('sequence-prefix scenario 3', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 16, False]]]] * N), [[[], [], 16]] * N)
check('sequence-prefix scenario 4', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 11, True], ['up', 'B', 12, False]]]] * N), [[[], ['A'], 10]] * N)
check('sequence-prefix scenario 5', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['cancel', '', 11, False]]]] * N), [[[], [], None]] * N)
check('sequence-prefix scenario 6', solve([[['A', 'B', 'A'], 5, [['down', 'A', 10, False], ['down', 'B', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'A', 14, False]]]] * N), [[[12, 14], ['A'], 14]] * N)
check('sequence-prefix scenario 7', solve([[['A', 'B', 'A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'A', 14, False], ['down', 'B', 15, False]]]] * N), [[[13, 15], ['A', 'B'], 15]] * N)
check('sequence-prefix scenario 8', solve([[['A', 'A', 'B'], 5, [['down', 'A', 10, False], ['down', 'A', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False]]]] * N), [[[13], [], 13]] * N)
check('sequence-prefix scenario 9', solve([[['A', 'B', 'C'], 5, [['down', 'A', 10, False], ['down', 'X', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'C', 14, False]]]] * N), [[[14], [], 14]] * N)
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(cases):
    def run(c):
        sequence,timeout,events=c
        buffer=[]; last=None; matches=[]
        for kind,key,now,repeat in events:
            if kind=='cancel': buffer=[]; last=None
            elif kind=='tick':
                if last is not None and now-last>timeout: buffer=[]; last=None
            elif kind=='down' and not repeat:
                if last is not None and now-last>timeout: buffer=[]
                candidate=buffer+[key]
                last=now
                buffer=[]
                for size in range(min(len(sequence),len(candidate))-1,0,-1):
                    if candidate[-size:]==sequence[:size]:
                        buffer=candidate[-size:]
                        break
                if buffer==sequence:
                    matches.append(now)
                    buffer=[]
                    for size in range(len(sequence)-1,0,-1):
                        if sequence[-size:]==sequence[:size]:
                            buffer=sequence[:size]
                            break
        return [matches,buffer,last]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('sequence-prefix scenario 0', solve([[['A', 'B'], 5, []]] * N), [[[], [], None]] * N)
check('sequence-prefix scenario 1', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 15, False]]]] * N), [[[15], [], 15]] * N)
check('sequence-prefix scenario 2', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['tick', '', 15, False]]]] * N), [[[], ['A'], 10]] * N)
check('sequence-prefix scenario 3', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 16, False]]]] * N), [[[], [], 16]] * N)
check('sequence-prefix scenario 4', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 11, True], ['up', 'B', 12, False]]]] * N), [[[], ['A'], 10]] * N)
check('sequence-prefix scenario 5', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['cancel', '', 11, False]]]] * N), [[[], [], None]] * N)
check('sequence-prefix scenario 6', solve([[['A', 'B', 'A'], 5, [['down', 'A', 10, False], ['down', 'B', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'A', 14, False]]]] * N), [[[12, 14], ['A'], 14]] * N)
check('sequence-prefix scenario 7', solve([[['A', 'B', 'A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'A', 14, False], ['down', 'B', 15, False]]]] * N), [[[13, 15], ['A', 'B'], 15]] * N)
check('sequence-prefix scenario 8', solve([[['A', 'A', 'B'], 5, [['down', 'A', 10, False], ['down', 'A', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False]]]] * N), [[[13], [], 13]] * N)
check('sequence-prefix scenario 9', solve([[['A', 'B', 'C'], 5, [['down', 'A', 10, False], ['down', 'X', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'C', 14, False]]]] * N), [[[14], [], 14]] * N)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The event trace violates the prefix search rule and produces incorrect keyboard state or command output.

Case [sequence,timeout,events]. Nonempty sequence is list of key names. Events [kind,key,time,repeat]. Only nonrepeat down feeds matcher. Accepted downs more than timeout after the previous accepted down discard the prefix; tick likewise expires it. Cancel resets prefix and clock. Keep longest suffix matching a sequence prefix, and after a match retain the longest proper overlapping prefix. Return match timestamps, partial prefix and last accepted time. Inputs are finite ordered event traces; return the stated deterministic state. Batch entries are independent. N varies the number of independent input transactions.

split: open-access


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

N = 1
observations = []
def solve(cases):
    def run(c):
        sequence,timeout,events=c
        buffer=[]; last=None; matches=[]
        for kind,key,now,repeat in events:
            if kind=='cancel': buffer=[]; last=None
            elif kind=='tick':
                if last is not None and now-last>timeout: buffer=[]; last=None
            elif kind=='down' and not repeat:
                if last is not None and now-last>timeout: buffer=[]
                candidate=buffer+[key]
                last=now
                buffer=[]
                for size in range(min(len(sequence),len(candidate)),0,-1):
                    if candidate[:size]==sequence[:size]:
                        buffer=candidate[-size:]
                        break
                if buffer==sequence:
                    matches.append(now)
                    buffer=[]
                    for size in range(len(sequence)-1,0,-1):
                        if sequence[-size:]==sequence[:size]:
                            buffer=sequence[:size]
                            break
        return [matches,buffer,last]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('sequence-prefix scenario 0', solve([[['A', 'B'], 5, []]] * N), [[[], [], None]] * N)
check('sequence-prefix scenario 1', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 15, False]]]] * N), [[[15], [], 15]] * N)
check('sequence-prefix scenario 2', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['tick', '', 15, False]]]] * N), [[[], ['A'], 10]] * N)
check('sequence-prefix scenario 3', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 16, False]]]] * N), [[[], [], 16]] * N)
check('sequence-prefix scenario 4', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 11, True], ['up', 'B', 12, False]]]] * N), [[[], ['A'], 10]] * N)
check('sequence-prefix scenario 5', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['cancel', '', 11, False]]]] * N), [[[], [], None]] * N)
check('sequence-prefix scenario 6', solve([[['A', 'B', 'A'], 5, [['down', 'A', 10, False], ['down', 'B', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'A', 14, False]]]] * N), [[[12, 14], ['A'], 14]] * N)
check('sequence-prefix scenario 7', solve([[['A', 'B', 'A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'A', 14, False], ['down', 'B', 15, False]]]] * N), [[[13, 15], ['A', 'B'], 15]] * N)
check('sequence-prefix scenario 8', solve([[['A', 'A', 'B'], 5, [['down', 'A', 10, False], ['down', 'A', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False]]]] * N), [[[13], [], 13]] * N)
check('sequence-prefix scenario 9', solve([[['A', 'B', 'C'], 5, [['down', 'A', 10, False], ['down', 'X', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'C', 14, False]]]] * N), [[[14], [], 14]] * N)
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(cases):
    def run(c):
        sequence,timeout,events=c
        buffer=[]; last=None; matches=[]
        for kind,key,now,repeat in events:
            if kind=='cancel': buffer=[]; last=None
            elif kind=='tick':
                if last is not None and now-last>timeout: buffer=[]; last=None
            elif kind=='down' and not repeat:
                if last is not None and now-last>timeout: buffer=[]
                candidate=buffer+[key]
                last=now
                buffer=[]
                for size in range(min(len(sequence),len(candidate)),0,-1):
                    if candidate[-size:]==sequence[-size:]:
                        buffer=candidate[-size:]
                        break
                if buffer==sequence:
                    matches.append(now)
                    buffer=[]
                    for size in range(len(sequence)-1,0,-1):
                        if sequence[-size:]==sequence[:size]:
                            buffer=sequence[:size]
                            break
        return [matches,buffer,last]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('sequence-prefix scenario 0', solve([[['A', 'B'], 5, []]] * N), [[[], [], None]] * N)
check('sequence-prefix scenario 1', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 15, False]]]] * N), [[[15], [], 15]] * N)
check('sequence-prefix scenario 2', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['tick', '', 15, False]]]] * N), [[[], ['A'], 10]] * N)
check('sequence-prefix scenario 3', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 16, False]]]] * N), [[[], [], 16]] * N)
check('sequence-prefix scenario 4', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 11, True], ['up', 'B', 12, False]]]] * N), [[[], ['A'], 10]] * N)
check('sequence-prefix scenario 5', solve([[['A', 'B'], 5, [['down', 'A', 10, False], ['cancel', '', 11, False]]]] * N), [[[], [], None]] * N)
check('sequence-prefix scenario 6', solve([[['A', 'B', 'A'], 5, [['down', 'A', 10, False], ['down', 'B', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'A', 14, False]]]] * N), [[[12, 14], ['A'], 14]] * N)
check('sequence-prefix scenario 7', solve([[['A', 'B', 'A', 'B'], 5, [['down', 'A', 10, False], ['down', 'B', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'A', 14, False], ['down', 'B', 15, False]]]] * N), [[[13, 15], ['A', 'B'], 15]] * N)
check('sequence-prefix scenario 8', solve([[['A', 'A', 'B'], 5, [['down', 'A', 10, False], ['down', 'A', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False]]]] * N), [[[13], [], 13]] * N)
check('sequence-prefix scenario 9', solve([[['A', 'B', 'C'], 5, [['down', 'A', 10, False], ['down', 'X', 11, False], ['down', 'A', 12, False], ['down', 'B', 13, False], ['down', 'C', 14, False]]]] * N), [[[14], [], 14]] * N)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The event trace violates the suffix comparison rule and produces incorrect keyboard state or command output.

Case [sequence,timeout,events]. Nonempty sequence is list of key names. Events [kind,key,time,repeat]. Only nonrepeat down feeds matcher. Accepted downs more than timeout after the previous accepted down discard the prefix; tick likewise expires it. Cancel resets prefix and clock. Keep longest suffix matching a sequence prefix, and after a match retain the longest proper overlapping prefix. Return match timestamps, partial prefix and last accepted time. Inputs are finite ordered event traces; return the stated deterministic state. Batch entries are independent. N varies the number of independent input transactions.

split: open-access