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

N = 1
observations = []
def solve(preset, scans):
    acc = 0
    dn = True
    prev = False
    out = []
    for rung_in, dt in scans:
        rung_in = bool(rung_in)
        if rung_in:
            acc = 0
            dn = True
        elif dn:
            if not prev:
                acc = min(preset, acc + dt)
            if acc >= preset:
                dn = False
        tt = dn and not rung_in
        prev = rung_in
        out.append([dn, tt, acc])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: power-up with false rung',
   [60, [[False, 20], [False, 20], [False, 20], [True, 10]]],
   [[False, False, 60], [False, False, 60], [False, False, 60], [True, False, 0]]],
  ['regression: scenario 1',
   [60, [[False, 70], [True, 10], [True, 70], [True, 10], [False, 70], [False, 10], [True, 10], [False, 30]]],
   [[False, False, 60],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 10],
    [True, False, 0],
    [True, True, 0]]],
  ['control: re-energized mid delay',
   [100, [[True, 10], [False, 40], [False, 40], [True, 40], [False, 40], [False, 40], [False, 40]]],
   [[True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, True, 80]]],
  ['control: zero preset drop',
   [0, [[True, 10], [False, 10], [False, 10]]],
   [[True, False, 0], [False, False, 0], [False, False, 0]]],
  ['control: exact expiry',
   [60, [[True, 10], [False, 30], [False, 30], [False, 30], [False, 30]]],
   [[True, False, 0], [True, True, 0], [True, True, 30], [False, False, 60], [False, False, 60]]],
  ['regression: scenario 2',
   [60, [[False, 30], [True, 50], [True, 20], [True, 30], [True, 70], [False, 50], [False, 50], [False, 70]]],
   [[False, False, 60],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 50],
    [False, False, 60]]],
  ['control: scenario 3',
   [40,
    [[True, 70],
     [True, 0],
     [False, 50],
     [True, 30],
     [False, 0],
     [False, 50],
     [False, 30],
     [False, 50],
     [False, 10],
     [True, 20]]],
   [[True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0],
    [True, True, 0],
    [False, False, 40],
    [False, False, 40],
    [False, False, 40],
    [False, False, 40],
    [True, False, 0]]],
  ['regression: scenario 4',
   [100,
    [[False, 30],
     [False, 70],
     [True, 30],
     [False, 30],
     [False, 20],
     [False, 50],
     [False, 70],
     [True, 50],
     [True, 50],
     [False, 20],
     [False, 50]]],
   [[False, False, 100],
    [False, False, 100],
    [True, False, 0],
    [True, True, 0],
    [True, True, 20],
    [True, True, 70],
    [False, False, 100],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 50]]]],
 [['regression: scenario 3',
   [150,
    [[False, 50],
     [False, 10],
     [False, 0],
     [False, 50],
     [True, 50],
     [False, 70],
     [False, 10],
     [True, 70],
     [False, 50],
     [False, 70],
     [False, 20],
     [True, 50],
     [False, 0],
     [True, 30]]],
   [[False, False, 150],
    [False, False, 150],
    [False, False, 150],
    [False, False, 150],
    [True, False, 0],
    [True, True, 0],
    [True, True, 10],
    [True, False, 0],
    [True, True, 0],
    [True, True, 70],
    [True, True, 90],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0]]],
  ['regression: scenario 4',
   [60,
    [[False, 0],
     [False, 10],
     [True, 20],
     [False, 20],
     [False, 0],
     [False, 0],
     [True, 50],
     [True, 20],
     [True, 10],
     [True, 0],
     [True, 10],
     [False, 20],
     [False, 70]]],
   [[False, False, 60],
    [False, False, 60],
    [True, False, 0],
    [True, True, 0],
    [True, True, 0],
    [True, True, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [False, False, 60]]],
  ['regression: power-up with false rung',
   [60, [[False, 20], [False, 20], [False, 20], [True, 10]]],
   [[False, False, 60], [False, False, 60], [False, False, 60], [True, False, 0]]],
  ['control: re-energized mid delay',
   [100, [[True, 10], [False, 40], [False, 40], [True, 40], [False, 40], [False, 40], [False, 40]]],
   [[True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, True, 80]]],
  ['control: zero preset drop',
   [0, [[True, 10], [False, 10], [False, 10]]],
   [[True, False, 0], [False, False, 0], [False, False, 0]]],
  ['control: exact expiry',
   [60, [[True, 10], [False, 30], [False, 30], [False, 30], [False, 30]]],
   [[True, False, 0], [True, True, 0], [True, True, 30], [False, False, 60], [False, False, 60]]],
  ['control: scenario 1',
   [0, [[False, 30], [True, 20], [True, 30], [False, 50], [True, 0], [True, 50], [True, 50]]],
   [[False, False, 0],
    [True, False, 0],
    [True, False, 0],
    [False, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0]]],
  ['control: scenario 2',
   [0, [[False, 10], [True, 0], [True, 70], [False, 0], [True, 70], [False, 20], [False, 10]]],
   [[False, False, 0],
    [True, False, 0],
    [True, False, 0],
    [False, False, 0],
    [True, False, 0],
    [False, False, 0],
    [False, False, 0]]]],
 [['regression: scenario 7',
   [60, [[False, 30], [True, 0], [True, 20], [True, 30], [False, 0], [False, 0], [True, 30]]],
   [[False, False, 60],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 0],
    [True, False, 0]]],
  ['regression: scenario 10',
   [60, [[False, 20], [False, 10], [True, 70], [False, 0], [False, 70], [True, 10], [False, 0], [True, 0]]],
   [[False, False, 60],
    [False, False, 60],
    [True, False, 0],
    [True, True, 0],
    [False, False, 60],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0]]],
  ['regression: power-up with false rung',
   [60, [[False, 20], [False, 20], [False, 20], [True, 10]]],
   [[False, False, 60], [False, False, 60], [False, False, 60], [True, False, 0]]],
  ['control: re-energized mid delay',
   [100, [[True, 10], [False, 40], [False, 40], [True, 40], [False, 40], [False, 40], [False, 40]]],
   [[True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, True, 80]]],
  ['control: zero preset drop',
   [0, [[True, 10], [False, 10], [False, 10]]],
   [[True, False, 0], [False, False, 0], [False, False, 0]]],
  ['control: exact expiry',
   [60, [[True, 10], [False, 30], [False, 30], [False, 30], [False, 30]]],
   [[True, False, 0], [True, True, 0], [True, True, 30], [False, False, 60], [False, False, 60]]],
  ['control: scenario 1',
   [0,
    [[False, 50],
     [True, 10],
     [False, 0],
     [True, 20],
     [False, 70],
     [False, 50],
     [True, 70],
     [False, 10],
     [False, 10],
     [False, 20],
     [True, 70]]],
   [[False, False, 0],
    [True, False, 0],
    [False, False, 0],
    [True, False, 0],
    [False, False, 0],
    [False, False, 0],
    [True, False, 0],
    [False, False, 0],
    [False, False, 0],
    [False, False, 0],
    [True, False, 0]]],
  ['control: scenario 2',
   [0,
    [[False, 30],
     [True, 50],
     [False, 50],
     [True, 0],
     [True, 10],
     [True, 10],
     [False, 10],
     [False, 50],
     [False, 10]]],
   [[False, False, 0],
    [True, False, 0],
    [False, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [False, False, 0],
    [False, False, 0],
    [False, False, 0]]]],
 [['regression: scenario 11',
   [100, [[False, 20], [True, 70], [False, 30], [False, 20], [False, 10], [False, 30], [True, 30]]],
   [[False, False, 100],
    [True, False, 0],
    [True, True, 0],
    [True, True, 20],
    [True, True, 30],
    [True, True, 60],
    [True, False, 0]]],
  ['regression: scenario 6',
   [40,
    [[False, 70],
     [True, 30],
     [True, 0],
     [False, 20],
     [True, 30],
     [False, 50],
     [True, 70],
     [True, 0],
     [False, 50]]],
   [[False, False, 40],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0]]],
  ['regression: power-up with false rung',
   [60, [[False, 20], [False, 20], [False, 20], [True, 10]]],
   [[False, False, 60], [False, False, 60], [False, False, 60], [True, False, 0]]],
  ['control: re-energized mid delay',
   [100, [[True, 10], [False, 40], [False, 40], [True, 40], [False, 40], [False, 40], [False, 40]]],
   [[True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, True, 80]]],
  ['control: zero preset drop',
   [0, [[True, 10], [False, 10], [False, 10]]],
   [[True, False, 0], [False, False, 0], [False, False, 0]]],
  ['control: exact expiry',
   [60, [[True, 10], [False, 30], [False, 30], [False, 30], [False, 30]]],
   [[True, False, 0], [True, True, 0], [True, True, 30], [False, False, 60], [False, False, 60]]],
  ['control: scenario 1',
   [40, [[True, 70], [True, 20], [True, 20], [False, 30], [False, 30], [False, 0], [False, 70], [False, 20]]],
   [[True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 30],
    [True, True, 30],
    [False, False, 40],
    [False, False, 40]]],
  ['regression: scenario 2',
   [100,
    [[False, 30],
     [False, 20],
     [True, 20],
     [True, 10],
     [True, 70],
     [False, 20],
     [False, 10],
     [True, 20],
     [False, 0],
     [True, 0],
     [True, 0]]],
   [[False, False, 100],
    [False, False, 100],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 10],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0],
    [True, False, 0]]]],
 [['regression: scenario 10',
   [150,
    [[False, 30],
     [True, 70],
     [False, 20],
     [False, 30],
     [False, 20],
     [False, 10],
     [False, 20],
     [False, 30],
     [True, 70],
     [True, 10],
     [False, 70],
     [False, 20]]],
   [[False, False, 150],
    [True, False, 0],
    [True, True, 0],
    [True, True, 30],
    [True, True, 50],
    [True, True, 60],
    [True, True, 80],
    [True, True, 110],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 20]]],
  ['regression: scenario 8',
   [40,
    [[False, 0],
     [False, 20],
     [True, 70],
     [True, 30],
     [False, 20],
     [False, 20],
     [True, 50],
     [False, 0],
     [False, 20],
     [False, 0],
     [False, 50],
     [False, 30],
     [False, 50],
     [True, 0]]],
   [[False, False, 40],
    [False, False, 40],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 20],
    [True, False, 0],
    [True, True, 0],
    [True, True, 20],
    [True, True, 20],
    [False, False, 40],
    [False, False, 40],
    [False, False, 40],
    [True, False, 0]]],
  ['regression: power-up with false rung',
   [60, [[False, 20], [False, 20], [False, 20], [True, 10]]],
   [[False, False, 60], [False, False, 60], [False, False, 60], [True, False, 0]]],
  ['control: re-energized mid delay',
   [100, [[True, 10], [False, 40], [False, 40], [True, 40], [False, 40], [False, 40], [False, 40]]],
   [[True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, True, 80]]],
  ['control: zero preset drop',
   [0, [[True, 10], [False, 10], [False, 10]]],
   [[True, False, 0], [False, False, 0], [False, False, 0]]],
  ['control: exact expiry',
   [60, [[True, 10], [False, 30], [False, 30], [False, 30], [False, 30]]],
   [[True, False, 0], [True, True, 0], [True, True, 30], [False, False, 60], [False, False, 60]]],
  ['control: scenario 1',
   [40,
    [[True, 70], [True, 20], [False, 50], [False, 20], [False, 50], [False, 50], [False, 50], [False, 0]]],
   [[True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 20],
    [False, False, 40],
    [False, False, 40],
    [False, False, 40],
    [False, False, 40]]],
  ['regression: scenario 2',
   [40,
    [[False, 70],
     [True, 70],
     [False, 50],
     [True, 70],
     [False, 10],
     [False, 30],
     [True, 0],
     [True, 50],
     [False, 0],
     [False, 30]]],
   [[False, False, 40],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 30],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 30]]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
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(preset, scans):
    acc = 0
    dn = False
    prev = False
    out = []
    for rung_in, dt in scans:
        rung_in = bool(rung_in)
        if rung_in:
            acc = 0
            dn = True
        elif dn:
            if not prev:
                acc = min(preset, acc + dt)
            if acc >= preset:
                dn = False
        tt = dn and not rung_in
        prev = rung_in
        out.append([dn, tt, acc])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: power-up with false rung',
   [60, [[False, 20], [False, 20], [False, 20], [True, 10]]],
   [[False, False, 60], [False, False, 60], [False, False, 60], [True, False, 0]]],
  ['regression: scenario 1',
   [60, [[False, 70], [True, 10], [True, 70], [True, 10], [False, 70], [False, 10], [True, 10], [False, 30]]],
   [[False, False, 60],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 10],
    [True, False, 0],
    [True, True, 0]]],
  ['control: re-energized mid delay',
   [100, [[True, 10], [False, 40], [False, 40], [True, 40], [False, 40], [False, 40], [False, 40]]],
   [[True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, True, 80]]],
  ['control: zero preset drop',
   [0, [[True, 10], [False, 10], [False, 10]]],
   [[True, False, 0], [False, False, 0], [False, False, 0]]],
  ['control: exact expiry',
   [60, [[True, 10], [False, 30], [False, 30], [False, 30], [False, 30]]],
   [[True, False, 0], [True, True, 0], [True, True, 30], [False, False, 60], [False, False, 60]]],
  ['regression: scenario 2',
   [60, [[False, 30], [True, 50], [True, 20], [True, 30], [True, 70], [False, 50], [False, 50], [False, 70]]],
   [[False, False, 60],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 50],
    [False, False, 60]]],
  ['control: scenario 3',
   [40,
    [[True, 70],
     [True, 0],
     [False, 50],
     [True, 30],
     [False, 0],
     [False, 50],
     [False, 30],
     [False, 50],
     [False, 10],
     [True, 20]]],
   [[True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0],
    [True, True, 0],
    [False, False, 40],
    [False, False, 40],
    [False, False, 40],
    [False, False, 40],
    [True, False, 0]]],
  ['regression: scenario 4',
   [100,
    [[False, 30],
     [False, 70],
     [True, 30],
     [False, 30],
     [False, 20],
     [False, 50],
     [False, 70],
     [True, 50],
     [True, 50],
     [False, 20],
     [False, 50]]],
   [[False, False, 100],
    [False, False, 100],
    [True, False, 0],
    [True, True, 0],
    [True, True, 20],
    [True, True, 70],
    [False, False, 100],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 50]]]],
 [['regression: scenario 3',
   [150,
    [[False, 50],
     [False, 10],
     [False, 0],
     [False, 50],
     [True, 50],
     [False, 70],
     [False, 10],
     [True, 70],
     [False, 50],
     [False, 70],
     [False, 20],
     [True, 50],
     [False, 0],
     [True, 30]]],
   [[False, False, 150],
    [False, False, 150],
    [False, False, 150],
    [False, False, 150],
    [True, False, 0],
    [True, True, 0],
    [True, True, 10],
    [True, False, 0],
    [True, True, 0],
    [True, True, 70],
    [True, True, 90],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0]]],
  ['regression: scenario 4',
   [60,
    [[False, 0],
     [False, 10],
     [True, 20],
     [False, 20],
     [False, 0],
     [False, 0],
     [True, 50],
     [True, 20],
     [True, 10],
     [True, 0],
     [True, 10],
     [False, 20],
     [False, 70]]],
   [[False, False, 60],
    [False, False, 60],
    [True, False, 0],
    [True, True, 0],
    [True, True, 0],
    [True, True, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [False, False, 60]]],
  ['regression: power-up with false rung',
   [60, [[False, 20], [False, 20], [False, 20], [True, 10]]],
   [[False, False, 60], [False, False, 60], [False, False, 60], [True, False, 0]]],
  ['control: re-energized mid delay',
   [100, [[True, 10], [False, 40], [False, 40], [True, 40], [False, 40], [False, 40], [False, 40]]],
   [[True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, True, 80]]],
  ['control: zero preset drop',
   [0, [[True, 10], [False, 10], [False, 10]]],
   [[True, False, 0], [False, False, 0], [False, False, 0]]],
  ['control: exact expiry',
   [60, [[True, 10], [False, 30], [False, 30], [False, 30], [False, 30]]],
   [[True, False, 0], [True, True, 0], [True, True, 30], [False, False, 60], [False, False, 60]]],
  ['control: scenario 1',
   [0, [[False, 30], [True, 20], [True, 30], [False, 50], [True, 0], [True, 50], [True, 50]]],
   [[False, False, 0],
    [True, False, 0],
    [True, False, 0],
    [False, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0]]],
  ['control: scenario 2',
   [0, [[False, 10], [True, 0], [True, 70], [False, 0], [True, 70], [False, 20], [False, 10]]],
   [[False, False, 0],
    [True, False, 0],
    [True, False, 0],
    [False, False, 0],
    [True, False, 0],
    [False, False, 0],
    [False, False, 0]]]],
 [['regression: scenario 7',
   [60, [[False, 30], [True, 0], [True, 20], [True, 30], [False, 0], [False, 0], [True, 30]]],
   [[False, False, 60],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 0],
    [True, False, 0]]],
  ['regression: scenario 10',
   [60, [[False, 20], [False, 10], [True, 70], [False, 0], [False, 70], [True, 10], [False, 0], [True, 0]]],
   [[False, False, 60],
    [False, False, 60],
    [True, False, 0],
    [True, True, 0],
    [False, False, 60],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0]]],
  ['regression: power-up with false rung',
   [60, [[False, 20], [False, 20], [False, 20], [True, 10]]],
   [[False, False, 60], [False, False, 60], [False, False, 60], [True, False, 0]]],
  ['control: re-energized mid delay',
   [100, [[True, 10], [False, 40], [False, 40], [True, 40], [False, 40], [False, 40], [False, 40]]],
   [[True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, True, 80]]],
  ['control: zero preset drop',
   [0, [[True, 10], [False, 10], [False, 10]]],
   [[True, False, 0], [False, False, 0], [False, False, 0]]],
  ['control: exact expiry',
   [60, [[True, 10], [False, 30], [False, 30], [False, 30], [False, 30]]],
   [[True, False, 0], [True, True, 0], [True, True, 30], [False, False, 60], [False, False, 60]]],
  ['control: scenario 1',
   [0,
    [[False, 50],
     [True, 10],
     [False, 0],
     [True, 20],
     [False, 70],
     [False, 50],
     [True, 70],
     [False, 10],
     [False, 10],
     [False, 20],
     [True, 70]]],
   [[False, False, 0],
    [True, False, 0],
    [False, False, 0],
    [True, False, 0],
    [False, False, 0],
    [False, False, 0],
    [True, False, 0],
    [False, False, 0],
    [False, False, 0],
    [False, False, 0],
    [True, False, 0]]],
  ['control: scenario 2',
   [0,
    [[False, 30],
     [True, 50],
     [False, 50],
     [True, 0],
     [True, 10],
     [True, 10],
     [False, 10],
     [False, 50],
     [False, 10]]],
   [[False, False, 0],
    [True, False, 0],
    [False, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [False, False, 0],
    [False, False, 0],
    [False, False, 0]]]],
 [['regression: scenario 11',
   [100, [[False, 20], [True, 70], [False, 30], [False, 20], [False, 10], [False, 30], [True, 30]]],
   [[False, False, 100],
    [True, False, 0],
    [True, True, 0],
    [True, True, 20],
    [True, True, 30],
    [True, True, 60],
    [True, False, 0]]],
  ['regression: scenario 6',
   [40,
    [[False, 70],
     [True, 30],
     [True, 0],
     [False, 20],
     [True, 30],
     [False, 50],
     [True, 70],
     [True, 0],
     [False, 50]]],
   [[False, False, 40],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0]]],
  ['regression: power-up with false rung',
   [60, [[False, 20], [False, 20], [False, 20], [True, 10]]],
   [[False, False, 60], [False, False, 60], [False, False, 60], [True, False, 0]]],
  ['control: re-energized mid delay',
   [100, [[True, 10], [False, 40], [False, 40], [True, 40], [False, 40], [False, 40], [False, 40]]],
   [[True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, True, 80]]],
  ['control: zero preset drop',
   [0, [[True, 10], [False, 10], [False, 10]]],
   [[True, False, 0], [False, False, 0], [False, False, 0]]],
  ['control: exact expiry',
   [60, [[True, 10], [False, 30], [False, 30], [False, 30], [False, 30]]],
   [[True, False, 0], [True, True, 0], [True, True, 30], [False, False, 60], [False, False, 60]]],
  ['control: scenario 1',
   [40, [[True, 70], [True, 20], [True, 20], [False, 30], [False, 30], [False, 0], [False, 70], [False, 20]]],
   [[True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 30],
    [True, True, 30],
    [False, False, 40],
    [False, False, 40]]],
  ['regression: scenario 2',
   [100,
    [[False, 30],
     [False, 20],
     [True, 20],
     [True, 10],
     [True, 70],
     [False, 20],
     [False, 10],
     [True, 20],
     [False, 0],
     [True, 0],
     [True, 0]]],
   [[False, False, 100],
    [False, False, 100],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 10],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0],
    [True, False, 0]]]],
 [['regression: scenario 10',
   [150,
    [[False, 30],
     [True, 70],
     [False, 20],
     [False, 30],
     [False, 20],
     [False, 10],
     [False, 20],
     [False, 30],
     [True, 70],
     [True, 10],
     [False, 70],
     [False, 20]]],
   [[False, False, 150],
    [True, False, 0],
    [True, True, 0],
    [True, True, 30],
    [True, True, 50],
    [True, True, 60],
    [True, True, 80],
    [True, True, 110],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 20]]],
  ['regression: scenario 8',
   [40,
    [[False, 0],
     [False, 20],
     [True, 70],
     [True, 30],
     [False, 20],
     [False, 20],
     [True, 50],
     [False, 0],
     [False, 20],
     [False, 0],
     [False, 50],
     [False, 30],
     [False, 50],
     [True, 0]]],
   [[False, False, 40],
    [False, False, 40],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 20],
    [True, False, 0],
    [True, True, 0],
    [True, True, 20],
    [True, True, 20],
    [False, False, 40],
    [False, False, 40],
    [False, False, 40],
    [True, False, 0]]],
  ['regression: power-up with false rung',
   [60, [[False, 20], [False, 20], [False, 20], [True, 10]]],
   [[False, False, 60], [False, False, 60], [False, False, 60], [True, False, 0]]],
  ['control: re-energized mid delay',
   [100, [[True, 10], [False, 40], [False, 40], [True, 40], [False, 40], [False, 40], [False, 40]]],
   [[True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, True, 80]]],
  ['control: zero preset drop',
   [0, [[True, 10], [False, 10], [False, 10]]],
   [[True, False, 0], [False, False, 0], [False, False, 0]]],
  ['control: exact expiry',
   [60, [[True, 10], [False, 30], [False, 30], [False, 30], [False, 30]]],
   [[True, False, 0], [True, True, 0], [True, True, 30], [False, False, 60], [False, False, 60]]],
  ['control: scenario 1',
   [40,
    [[True, 70], [True, 20], [False, 50], [False, 20], [False, 50], [False, 50], [False, 50], [False, 0]]],
   [[True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 20],
    [False, False, 40],
    [False, False, 40],
    [False, False, 40],
    [False, False, 40]]],
  ['regression: scenario 2',
   [40,
    [[False, 70],
     [True, 70],
     [False, 50],
     [True, 70],
     [False, 10],
     [False, 30],
     [True, 0],
     [True, 50],
     [False, 0],
     [False, 30]]],
   [[False, False, 40],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 30],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 30]]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
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:
After a restart the off-delay output is on for a full preset even though its rung was never true.

Off-delay timer (TOF) evaluated once per scan; scans is a list of [rung_in, elapsed_ms]. At power-up the timer is expired (ACC = preset, DN false). A true rung clears ACC and sets DN. After the rung drops, ACC accumulates each later false scan's elapsed time (the true-to-false scan itself is not credited), clamped at preset, and DN clears when ACC >= preset. TT is DN and not rung_in. Return [DN, TT, ACC] per scan.

split: open-access


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

N = 1
observations = []
def solve(preset, scans):
    acc = preset
    dn = False
    prev = False
    out = []
    for rung_in, dt in scans:
        rung_in = bool(rung_in)
        if rung_in:
            dn = True
        elif dn:
            if not prev:
                acc = min(preset, acc + dt)
            if acc >= preset:
                dn = False
        tt = dn and not rung_in
        prev = rung_in
        out.append([dn, tt, acc])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: power-up with false rung',
   [60, [[False, 20], [False, 20], [False, 20], [True, 10]]],
   [[False, False, 60], [False, False, 60], [False, False, 60], [True, False, 0]]],
  ['regression: re-energized mid delay',
   [100, [[True, 10], [False, 40], [False, 40], [True, 40], [False, 40], [False, 40], [False, 40]]],
   [[True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, True, 80]]],
  ['control: zero preset drop',
   [0, [[True, 10], [False, 10], [False, 10]]],
   [[True, False, 0], [False, False, 0], [False, False, 0]]],
  ['regression: exact expiry',
   [60, [[True, 10], [False, 30], [False, 30], [False, 30], [False, 30]]],
   [[True, False, 0], [True, True, 0], [True, True, 30], [False, False, 60], [False, False, 60]]],
  ['regression: scenario 1',
   [60, [[False, 70], [True, 10], [True, 70], [True, 10], [False, 70], [False, 10], [True, 10], [False, 30]]],
   [[False, False, 60],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 10],
    [True, False, 0],
    [True, True, 0]]],
  ['regression: scenario 2',
   [60, [[False, 30], [True, 50], [True, 20], [True, 30], [True, 70], [False, 50], [False, 50], [False, 70]]],
   [[False, False, 60],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 50],
    [False, False, 60]]],
  ['regression: scenario 3',
   [40,
    [[True, 70],
     [True, 0],
     [False, 50],
     [True, 30],
     [False, 0],
     [False, 50],
     [False, 30],
     [False, 50],
     [False, 10],
     [True, 20]]],
   [[True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0],
    [True, True, 0],
    [False, False, 40],
    [False, False, 40],
    [False, False, 40],
    [False, False, 40],
    [True, False, 0]]],
  ['regression: scenario 4',
   [100,
    [[False, 30],
     [False, 70],
     [True, 30],
     [False, 30],
     [False, 20],
     [False, 50],
     [False, 70],
     [True, 50],
     [True, 50],
     [False, 20],
     [False, 50]]],
   [[False, False, 100],
    [False, False, 100],
    [True, False, 0],
    [True, True, 0],
    [True, True, 20],
    [True, True, 70],
    [False, False, 100],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 50]]]],
 [['regression: re-energized mid delay',
   [100, [[True, 10], [False, 40], [False, 40], [True, 40], [False, 40], [False, 40], [False, 40]]],
   [[True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, True, 80]]],
  ['regression: scenario 5',
   [40, [[False, 50], [False, 70], [True, 70], [False, 10], [False, 30], [True, 70]]],
   [[False, False, 40],
    [False, False, 40],
    [True, False, 0],
    [True, True, 0],
    [True, True, 30],
    [True, False, 0]]],
  ['regression: power-up with false rung',
   [60, [[False, 20], [False, 20], [False, 20], [True, 10]]],
   [[False, False, 60], [False, False, 60], [False, False, 60], [True, False, 0]]],
  ['control: zero preset drop',
   [0, [[True, 10], [False, 10], [False, 10]]],
   [[True, False, 0], [False, False, 0], [False, False, 0]]],
  ['regression: exact expiry',
   [60, [[True, 10], [False, 30], [False, 30], [False, 30], [False, 30]]],
   [[True, False, 0], [True, True, 0], [True, True, 30], [False, False, 60], [False, False, 60]]],
  ['control: scenario 1',
   [0, [[False, 30], [True, 20], [True, 30], [False, 50], [True, 0], [True, 50], [True, 50]]],
   [[False, False, 0],
    [True, False, 0],
    [True, False, 0],
    [False, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0]]],
  ['control: scenario 2',
   [0, [[False, 10], [True, 0], [True, 70], [False, 0], [True, 70], [False, 20], [False, 10]]],
   [[False, False, 0],
    [True, False, 0],
    [True, False, 0],
    [False, False, 0],
    [True, False, 0],
    [False, False, 0],
    [False, False, 0]]],
  ['regression: scenario 3',
   [150,
    [[False, 50],
     [False, 10],
     [False, 0],
     [False, 50],
     [True, 50],
     [False, 70],
     [False, 10],
     [True, 70],
     [False, 50],
     [False, 70],
     [False, 20],
     [True, 50],
     [False, 0],
     [True, 30]]],
   [[False, False, 150],
    [False, False, 150],
    [False, False, 150],
    [False, False, 150],
    [True, False, 0],
    [True, True, 0],
    [True, True, 10],
    [True, False, 0],
    [True, True, 0],
    [True, True, 70],
    [True, True, 90],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0]]]],
 [['regression: exact expiry',
   [60, [[True, 10], [False, 30], [False, 30], [False, 30], [False, 30]]],
   [[True, False, 0], [True, True, 0], [True, True, 30], [False, False, 60], [False, False, 60]]],
  ['regression: scenario 14',
   [60,
    [[False, 70],
     [False, 0],
     [True, 0],
     [True, 30],
     [False, 10],
     [False, 20],
     [False, 20],
     [False, 10],
     [True, 0],
     [False, 50],
     [False, 0],
     [False, 20]]],
   [[False, False, 60],
    [False, False, 60],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 20],
    [True, True, 40],
    [True, True, 50],
    [True, False, 0],
    [True, True, 0],
    [True, True, 0],
    [True, True, 20]]],
  ['regression: power-up with false rung',
   [60, [[False, 20], [False, 20], [False, 20], [True, 10]]],
   [[False, False, 60], [False, False, 60], [False, False, 60], [True, False, 0]]],
  ['regression: re-energized mid delay',
   [100, [[True, 10], [False, 40], [False, 40], [True, 40], [False, 40], [False, 40], [False, 40]]],
   [[True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, True, 80]]],
  ['control: zero preset drop',
   [0, [[True, 10], [False, 10], [False, 10]]],
   [[True, False, 0], [False, False, 0], [False, False, 0]]],
  ['control: scenario 1',
   [0,
    [[False, 50],
     [True, 10],
     [False, 0],
     [True, 20],
     [False, 70],
     [False, 50],
     [True, 70],
     [False, 10],
     [False, 10],
     [False, 20],
     [True, 70]]],
   [[False, False, 0],
    [True, False, 0],
    [False, False, 0],
    [True, False, 0],
    [False, False, 0],
    [False, False, 0],
    [True, False, 0],
    [False, False, 0],
    [False, False, 0],
    [False, False, 0],
    [True, False, 0]]],
  ['control: scenario 2',
   [0,
    [[False, 30],
     [True, 50],
     [False, 50],
     [True, 0],
     [True, 10],
     [True, 10],
     [False, 10],
     [False, 50],
     [False, 10]]],
   [[False, False, 0],
    [True, False, 0],
    [False, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [False, False, 0],
    [False, False, 0],
    [False, False, 0]]],
  ['control: scenario 3',
   [0,
    [[False, 10],
     [False, 10],
     [False, 70],
     [False, 30],
     [True, 50],
     [False, 10],
     [False, 0],
     [True, 20],
     [False, 70],
     [True, 10],
     [False, 70],
     [True, 20],
     [False, 70],
     [True, 0]]],
   [[False, False, 0],
    [False, False, 0],
    [False, False, 0],
    [False, False, 0],
    [True, False, 0],
    [False, False, 0],
    [False, False, 0],
    [True, False, 0],
    [False, False, 0],
    [True, False, 0],
    [False, False, 0],
    [True, False, 0],
    [False, False, 0],
    [True, False, 0]]]],
 [['regression: scenario 1',
   [40, [[True, 70], [True, 20], [True, 20], [False, 30], [False, 30], [False, 0], [False, 70], [False, 20]]],
   [[True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 30],
    [True, True, 30],
    [False, False, 40],
    [False, False, 40]]],
  ['regression: scenario 9',
   [150,
    [[True, 10],
     [True, 70],
     [True, 50],
     [False, 50],
     [False, 20],
     [False, 50],
     [True, 50],
     [True, 0],
     [True, 70],
     [False, 30],
     [True, 0],
     [False, 20],
     [False, 10]]],
   [[True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 20],
    [True, True, 70],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 10]]],
  ['regression: power-up with false rung',
   [60, [[False, 20], [False, 20], [False, 20], [True, 10]]],
   [[False, False, 60], [False, False, 60], [False, False, 60], [True, False, 0]]],
  ['regression: re-energized mid delay',
   [100, [[True, 10], [False, 40], [False, 40], [True, 40], [False, 40], [False, 40], [False, 40]]],
   [[True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, True, 80]]],
  ['control: zero preset drop',
   [0, [[True, 10], [False, 10], [False, 10]]],
   [[True, False, 0], [False, False, 0], [False, False, 0]]],
  ['regression: exact expiry',
   [60, [[True, 10], [False, 30], [False, 30], [False, 30], [False, 30]]],
   [[True, False, 0], [True, True, 0], [True, True, 30], [False, False, 60], [False, False, 60]]],
  ['regression: scenario 2',
   [100,
    [[False, 30],
     [False, 20],
     [True, 20],
     [True, 10],
     [True, 70],
     [False, 20],
     [False, 10],
     [True, 20],
     [False, 0],
     [True, 0],
     [True, 0]]],
   [[False, False, 100],
    [False, False, 100],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 10],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0],
    [True, False, 0]]],
  ['regression: scenario 3',
   [60, [[False, 70], [True, 30], [True, 0], [True, 50], [True, 30], [True, 70], [True, 0]]],
   [[False, False, 60],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0]]]],
 [['regression: scenario 2',
   [40,
    [[False, 70],
     [True, 70],
     [False, 50],
     [True, 70],
     [False, 10],
     [False, 30],
     [True, 0],
     [True, 50],
     [False, 0],
     [False, 30]]],
   [[False, False, 40],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 30],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 30]]],
  ['regression: scenario 10',
   [150,
    [[False, 30],
     [True, 70],
     [False, 20],
     [False, 30],
     [False, 20],
     [False, 10],
     [False, 20],
     [False, 30],
     [True, 70],
     [True, 10],
     [False, 70],
     [False, 20]]],
   [[False, False, 150],
    [True, False, 0],
    [True, True, 0],
    [True, True, 30],
    [True, True, 50],
    [True, True, 60],
    [True, True, 80],
    [True, True, 110],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 20]]],
  ['regression: power-up with false rung',
   [60, [[False, 20], [False, 20], [False, 20], [True, 10]]],
   [[False, False, 60], [False, False, 60], [False, False, 60], [True, False, 0]]],
  ['regression: re-energized mid delay',
   [100, [[True, 10], [False, 40], [False, 40], [True, 40], [False, 40], [False, 40], [False, 40]]],
   [[True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, True, 80]]],
  ['control: zero preset drop',
   [0, [[True, 10], [False, 10], [False, 10]]],
   [[True, False, 0], [False, False, 0], [False, False, 0]]],
  ['regression: exact expiry',
   [60, [[True, 10], [False, 30], [False, 30], [False, 30], [False, 30]]],
   [[True, False, 0], [True, True, 0], [True, True, 30], [False, False, 60], [False, False, 60]]],
  ['regression: scenario 1',
   [40,
    [[True, 70], [True, 20], [False, 50], [False, 20], [False, 50], [False, 50], [False, 50], [False, 0]]],
   [[True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 20],
    [False, False, 40],
    [False, False, 40],
    [False, False, 40],
    [False, False, 40]]],
  ['control: scenario 3',
   [0,
    [[False, 50],
     [False, 50],
     [False, 20],
     [False, 20],
     [True, 10],
     [True, 50],
     [True, 20],
     [False, 70],
     [False, 30],
     [False, 10],
     [True, 10],
     [True, 70],
     [True, 10],
     [False, 50]]],
   [[False, False, 0],
    [False, False, 0],
    [False, False, 0],
    [False, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [False, False, 0],
    [False, False, 0],
    [False, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [False, False, 0]]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
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(preset, scans):
    acc = preset
    dn = False
    prev = False
    out = []
    for rung_in, dt in scans:
        rung_in = bool(rung_in)
        if rung_in:
            if acc >= preset:
                acc = 0
            dn = True
        elif dn:
            if not prev:
                acc = min(preset, acc + dt)
            if acc >= preset:
                dn = False
        tt = dn and not rung_in
        prev = rung_in
        out.append([dn, tt, acc])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: power-up with false rung',
   [60, [[False, 20], [False, 20], [False, 20], [True, 10]]],
   [[False, False, 60], [False, False, 60], [False, False, 60], [True, False, 0]]],
  ['regression: re-energized mid delay',
   [100, [[True, 10], [False, 40], [False, 40], [True, 40], [False, 40], [False, 40], [False, 40]]],
   [[True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, True, 80]]],
  ['control: zero preset drop',
   [0, [[True, 10], [False, 10], [False, 10]]],
   [[True, False, 0], [False, False, 0], [False, False, 0]]],
  ['regression: exact expiry',
   [60, [[True, 10], [False, 30], [False, 30], [False, 30], [False, 30]]],
   [[True, False, 0], [True, True, 0], [True, True, 30], [False, False, 60], [False, False, 60]]],
  ['regression: scenario 1',
   [60, [[False, 70], [True, 10], [True, 70], [True, 10], [False, 70], [False, 10], [True, 10], [False, 30]]],
   [[False, False, 60],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 10],
    [True, False, 0],
    [True, True, 0]]],
  ['regression: scenario 2',
   [60, [[False, 30], [True, 50], [True, 20], [True, 30], [True, 70], [False, 50], [False, 50], [False, 70]]],
   [[False, False, 60],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 50],
    [False, False, 60]]],
  ['regression: scenario 3',
   [40,
    [[True, 70],
     [True, 0],
     [False, 50],
     [True, 30],
     [False, 0],
     [False, 50],
     [False, 30],
     [False, 50],
     [False, 10],
     [True, 20]]],
   [[True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0],
    [True, True, 0],
    [False, False, 40],
    [False, False, 40],
    [False, False, 40],
    [False, False, 40],
    [True, False, 0]]],
  ['regression: scenario 4',
   [100,
    [[False, 30],
     [False, 70],
     [True, 30],
     [False, 30],
     [False, 20],
     [False, 50],
     [False, 70],
     [True, 50],
     [True, 50],
     [False, 20],
     [False, 50]]],
   [[False, False, 100],
    [False, False, 100],
    [True, False, 0],
    [True, True, 0],
    [True, True, 20],
    [True, True, 70],
    [False, False, 100],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 50]]]],
 [['regression: re-energized mid delay',
   [100, [[True, 10], [False, 40], [False, 40], [True, 40], [False, 40], [False, 40], [False, 40]]],
   [[True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, True, 80]]],
  ['regression: scenario 5',
   [40, [[False, 50], [False, 70], [True, 70], [False, 10], [False, 30], [True, 70]]],
   [[False, False, 40],
    [False, False, 40],
    [True, False, 0],
    [True, True, 0],
    [True, True, 30],
    [True, False, 0]]],
  ['regression: power-up with false rung',
   [60, [[False, 20], [False, 20], [False, 20], [True, 10]]],
   [[False, False, 60], [False, False, 60], [False, False, 60], [True, False, 0]]],
  ['control: zero preset drop',
   [0, [[True, 10], [False, 10], [False, 10]]],
   [[True, False, 0], [False, False, 0], [False, False, 0]]],
  ['regression: exact expiry',
   [60, [[True, 10], [False, 30], [False, 30], [False, 30], [False, 30]]],
   [[True, False, 0], [True, True, 0], [True, True, 30], [False, False, 60], [False, False, 60]]],
  ['control: scenario 1',
   [0, [[False, 30], [True, 20], [True, 30], [False, 50], [True, 0], [True, 50], [True, 50]]],
   [[False, False, 0],
    [True, False, 0],
    [True, False, 0],
    [False, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0]]],
  ['control: scenario 2',
   [0, [[False, 10], [True, 0], [True, 70], [False, 0], [True, 70], [False, 20], [False, 10]]],
   [[False, False, 0],
    [True, False, 0],
    [True, False, 0],
    [False, False, 0],
    [True, False, 0],
    [False, False, 0],
    [False, False, 0]]],
  ['regression: scenario 3',
   [150,
    [[False, 50],
     [False, 10],
     [False, 0],
     [False, 50],
     [True, 50],
     [False, 70],
     [False, 10],
     [True, 70],
     [False, 50],
     [False, 70],
     [False, 20],
     [True, 50],
     [False, 0],
     [True, 30]]],
   [[False, False, 150],
    [False, False, 150],
    [False, False, 150],
    [False, False, 150],
    [True, False, 0],
    [True, True, 0],
    [True, True, 10],
    [True, False, 0],
    [True, True, 0],
    [True, True, 70],
    [True, True, 90],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0]]]],
 [['regression: exact expiry',
   [60, [[True, 10], [False, 30], [False, 30], [False, 30], [False, 30]]],
   [[True, False, 0], [True, True, 0], [True, True, 30], [False, False, 60], [False, False, 60]]],
  ['regression: scenario 14',
   [60,
    [[False, 70],
     [False, 0],
     [True, 0],
     [True, 30],
     [False, 10],
     [False, 20],
     [False, 20],
     [False, 10],
     [True, 0],
     [False, 50],
     [False, 0],
     [False, 20]]],
   [[False, False, 60],
    [False, False, 60],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 20],
    [True, True, 40],
    [True, True, 50],
    [True, False, 0],
    [True, True, 0],
    [True, True, 0],
    [True, True, 20]]],
  ['regression: power-up with false rung',
   [60, [[False, 20], [False, 20], [False, 20], [True, 10]]],
   [[False, False, 60], [False, False, 60], [False, False, 60], [True, False, 0]]],
  ['regression: re-energized mid delay',
   [100, [[True, 10], [False, 40], [False, 40], [True, 40], [False, 40], [False, 40], [False, 40]]],
   [[True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, True, 80]]],
  ['control: zero preset drop',
   [0, [[True, 10], [False, 10], [False, 10]]],
   [[True, False, 0], [False, False, 0], [False, False, 0]]],
  ['control: scenario 1',
   [0,
    [[False, 50],
     [True, 10],
     [False, 0],
     [True, 20],
     [False, 70],
     [False, 50],
     [True, 70],
     [False, 10],
     [False, 10],
     [False, 20],
     [True, 70]]],
   [[False, False, 0],
    [True, False, 0],
    [False, False, 0],
    [True, False, 0],
    [False, False, 0],
    [False, False, 0],
    [True, False, 0],
    [False, False, 0],
    [False, False, 0],
    [False, False, 0],
    [True, False, 0]]],
  ['control: scenario 2',
   [0,
    [[False, 30],
     [True, 50],
     [False, 50],
     [True, 0],
     [True, 10],
     [True, 10],
     [False, 10],
     [False, 50],
     [False, 10]]],
   [[False, False, 0],
    [True, False, 0],
    [False, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [False, False, 0],
    [False, False, 0],
    [False, False, 0]]],
  ['control: scenario 3',
   [0,
    [[False, 10],
     [False, 10],
     [False, 70],
     [False, 30],
     [True, 50],
     [False, 10],
     [False, 0],
     [True, 20],
     [False, 70],
     [True, 10],
     [False, 70],
     [True, 20],
     [False, 70],
     [True, 0]]],
   [[False, False, 0],
    [False, False, 0],
    [False, False, 0],
    [False, False, 0],
    [True, False, 0],
    [False, False, 0],
    [False, False, 0],
    [True, False, 0],
    [False, False, 0],
    [True, False, 0],
    [False, False, 0],
    [True, False, 0],
    [False, False, 0],
    [True, False, 0]]]],
 [['regression: scenario 1',
   [40, [[True, 70], [True, 20], [True, 20], [False, 30], [False, 30], [False, 0], [False, 70], [False, 20]]],
   [[True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 30],
    [True, True, 30],
    [False, False, 40],
    [False, False, 40]]],
  ['regression: scenario 9',
   [150,
    [[True, 10],
     [True, 70],
     [True, 50],
     [False, 50],
     [False, 20],
     [False, 50],
     [True, 50],
     [True, 0],
     [True, 70],
     [False, 30],
     [True, 0],
     [False, 20],
     [False, 10]]],
   [[True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 20],
    [True, True, 70],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 10]]],
  ['regression: power-up with false rung',
   [60, [[False, 20], [False, 20], [False, 20], [True, 10]]],
   [[False, False, 60], [False, False, 60], [False, False, 60], [True, False, 0]]],
  ['regression: re-energized mid delay',
   [100, [[True, 10], [False, 40], [False, 40], [True, 40], [False, 40], [False, 40], [False, 40]]],
   [[True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, True, 80]]],
  ['control: zero preset drop',
   [0, [[True, 10], [False, 10], [False, 10]]],
   [[True, False, 0], [False, False, 0], [False, False, 0]]],
  ['regression: exact expiry',
   [60, [[True, 10], [False, 30], [False, 30], [False, 30], [False, 30]]],
   [[True, False, 0], [True, True, 0], [True, True, 30], [False, False, 60], [False, False, 60]]],
  ['regression: scenario 2',
   [100,
    [[False, 30],
     [False, 20],
     [True, 20],
     [True, 10],
     [True, 70],
     [False, 20],
     [False, 10],
     [True, 20],
     [False, 0],
     [True, 0],
     [True, 0]]],
   [[False, False, 100],
    [False, False, 100],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 10],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0],
    [True, False, 0]]],
  ['regression: scenario 3',
   [60, [[False, 70], [True, 30], [True, 0], [True, 50], [True, 30], [True, 70], [True, 0]]],
   [[False, False, 60],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0]]]],
 [['regression: scenario 2',
   [40,
    [[False, 70],
     [True, 70],
     [False, 50],
     [True, 70],
     [False, 10],
     [False, 30],
     [True, 0],
     [True, 50],
     [False, 0],
     [False, 30]]],
   [[False, False, 40],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 30],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 30]]],
  ['regression: scenario 10',
   [150,
    [[False, 30],
     [True, 70],
     [False, 20],
     [False, 30],
     [False, 20],
     [False, 10],
     [False, 20],
     [False, 30],
     [True, 70],
     [True, 10],
     [False, 70],
     [False, 20]]],
   [[False, False, 150],
    [True, False, 0],
    [True, True, 0],
    [True, True, 30],
    [True, True, 50],
    [True, True, 60],
    [True, True, 80],
    [True, True, 110],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 20]]],
  ['regression: power-up with false rung',
   [60, [[False, 20], [False, 20], [False, 20], [True, 10]]],
   [[False, False, 60], [False, False, 60], [False, False, 60], [True, False, 0]]],
  ['regression: re-energized mid delay',
   [100, [[True, 10], [False, 40], [False, 40], [True, 40], [False, 40], [False, 40], [False, 40]]],
   [[True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, True, 80]]],
  ['control: zero preset drop',
   [0, [[True, 10], [False, 10], [False, 10]]],
   [[True, False, 0], [False, False, 0], [False, False, 0]]],
  ['regression: exact expiry',
   [60, [[True, 10], [False, 30], [False, 30], [False, 30], [False, 30]]],
   [[True, False, 0], [True, True, 0], [True, True, 30], [False, False, 60], [False, False, 60]]],
  ['regression: scenario 1',
   [40,
    [[True, 70], [True, 20], [False, 50], [False, 20], [False, 50], [False, 50], [False, 50], [False, 0]]],
   [[True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 20],
    [False, False, 40],
    [False, False, 40],
    [False, False, 40],
    [False, False, 40]]],
  ['control: scenario 3',
   [0,
    [[False, 50],
     [False, 50],
     [False, 20],
     [False, 20],
     [True, 10],
     [True, 50],
     [True, 20],
     [False, 70],
     [False, 30],
     [False, 10],
     [True, 10],
     [True, 70],
     [True, 10],
     [False, 50]]],
   [[False, False, 0],
    [False, False, 0],
    [False, False, 0],
    [False, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [False, False, 0],
    [False, False, 0],
    [False, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [False, False, 0]]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
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:
An off-delay that is re-energized mid-delay then expires early on the next drop.

Off-delay timer (TOF) evaluated once per scan; scans is a list of [rung_in, elapsed_ms]. At power-up the timer is expired (ACC = preset, DN false). A true rung clears ACC and sets DN. After the rung drops, ACC accumulates each later false scan's elapsed time (the true-to-false scan itself is not credited), clamped at preset, and DN clears when ACC >= preset. TT is DN and not rung_in. Return [DN, TT, ACC] per scan.

split: open-access


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

N = 1
observations = []
def solve(preset, scans):
    acc = preset
    dn = False
    prev = False
    out = []
    for rung_in, dt in scans:
        rung_in = bool(rung_in)
        if rung_in:
            acc = 0
            dn = True
        elif dn:
            acc = min(preset, acc + dt)
            if acc >= preset:
                dn = False
        tt = dn and not rung_in
        prev = rung_in
        out.append([dn, tt, acc])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: re-energized mid delay',
   [100, [[True, 10], [False, 40], [False, 40], [True, 40], [False, 40], [False, 40], [False, 40]]],
   [[True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, True, 80]]],
  ['regression: exact expiry',
   [60, [[True, 10], [False, 30], [False, 30], [False, 30], [False, 30]]],
   [[True, False, 0], [True, True, 0], [True, True, 30], [False, False, 60], [False, False, 60]]],
  ['control: power-up with false rung',
   [60, [[False, 20], [False, 20], [False, 20], [True, 10]]],
   [[False, False, 60], [False, False, 60], [False, False, 60], [True, False, 0]]],
  ['control: zero preset drop',
   [0, [[True, 10], [False, 10], [False, 10]]],
   [[True, False, 0], [False, False, 0], [False, False, 0]]],
  ['regression: scenario 1',
   [60, [[False, 70], [True, 10], [True, 70], [True, 10], [False, 70], [False, 10], [True, 10], [False, 30]]],
   [[False, False, 60],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 10],
    [True, False, 0],
    [True, True, 0]]],
  ['regression: scenario 2',
   [60, [[False, 30], [True, 50], [True, 20], [True, 30], [True, 70], [False, 50], [False, 50], [False, 70]]],
   [[False, False, 60],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 50],
    [False, False, 60]]],
  ['regression: scenario 3',
   [40,
    [[True, 70],
     [True, 0],
     [False, 50],
     [True, 30],
     [False, 0],
     [False, 50],
     [False, 30],
     [False, 50],
     [False, 10],
     [True, 20]]],
   [[True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0],
    [True, True, 0],
    [False, False, 40],
    [False, False, 40],
    [False, False, 40],
    [False, False, 40],
    [True, False, 0]]],
  ['regression: scenario 4',
   [100,
    [[False, 30],
     [False, 70],
     [True, 30],
     [False, 30],
     [False, 20],
     [False, 50],
     [False, 70],
     [True, 50],
     [True, 50],
     [False, 20],
     [False, 50]]],
   [[False, False, 100],
    [False, False, 100],
    [True, False, 0],
    [True, True, 0],
    [True, True, 20],
    [True, True, 70],
    [False, False, 100],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 50]]]],
 [['regression: exact expiry',
   [60, [[True, 10], [False, 30], [False, 30], [False, 30], [False, 30]]],
   [[True, False, 0], [True, True, 0], [True, True, 30], [False, False, 60], [False, False, 60]]],
  ['regression: scenario 3',
   [150,
    [[False, 50],
     [False, 10],
     [False, 0],
     [False, 50],
     [True, 50],
     [False, 70],
     [False, 10],
     [True, 70],
     [False, 50],
     [False, 70],
     [False, 20],
     [True, 50],
     [False, 0],
     [True, 30]]],
   [[False, False, 150],
    [False, False, 150],
    [False, False, 150],
    [False, False, 150],
    [True, False, 0],
    [True, True, 0],
    [True, True, 10],
    [True, False, 0],
    [True, True, 0],
    [True, True, 70],
    [True, True, 90],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0]]],
  ['control: power-up with false rung',
   [60, [[False, 20], [False, 20], [False, 20], [True, 10]]],
   [[False, False, 60], [False, False, 60], [False, False, 60], [True, False, 0]]],
  ['regression: re-energized mid delay',
   [100, [[True, 10], [False, 40], [False, 40], [True, 40], [False, 40], [False, 40], [False, 40]]],
   [[True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, True, 80]]],
  ['control: zero preset drop',
   [0, [[True, 10], [False, 10], [False, 10]]],
   [[True, False, 0], [False, False, 0], [False, False, 0]]],
  ['control: scenario 1',
   [0, [[False, 30], [True, 20], [True, 30], [False, 50], [True, 0], [True, 50], [True, 50]]],
   [[False, False, 0],
    [True, False, 0],
    [True, False, 0],
    [False, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0]]],
  ['control: scenario 2',
   [0, [[False, 10], [True, 0], [True, 70], [False, 0], [True, 70], [False, 20], [False, 10]]],
   [[False, False, 0],
    [True, False, 0],
    [True, False, 0],
    [False, False, 0],
    [True, False, 0],
    [False, False, 0],
    [False, False, 0]]],
  ['regression: scenario 4',
   [60,
    [[False, 0],
     [False, 10],
     [True, 20],
     [False, 20],
     [False, 0],
     [False, 0],
     [True, 50],
     [True, 20],
     [True, 10],
     [True, 0],
     [True, 10],
     [False, 20],
     [False, 70]]],
   [[False, False, 60],
    [False, False, 60],
    [True, False, 0],
    [True, True, 0],
    [True, True, 0],
    [True, True, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [False, False, 60]]]],
 [['regression: scenario 5',
   [100,
    [[False, 0],
     [False, 10],
     [True, 20],
     [True, 20],
     [False, 70],
     [True, 30],
     [True, 70],
     [True, 70],
     [True, 70],
     [True, 70]]],
   [[False, False, 100],
    [False, False, 100],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0]]],
  ['regression: scenario 6',
   [40,
    [[True, 0],
     [True, 20],
     [False, 0],
     [True, 50],
     [False, 30],
     [True, 70],
     [False, 20],
     [True, 50],
     [False, 50],
     [True, 20],
     [True, 0],
     [False, 30],
     [True, 70],
     [True, 10]]],
   [[True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0],
    [True, False, 0]]],
  ['control: power-up with false rung',
   [60, [[False, 20], [False, 20], [False, 20], [True, 10]]],
   [[False, False, 60], [False, False, 60], [False, False, 60], [True, False, 0]]],
  ['regression: re-energized mid delay',
   [100, [[True, 10], [False, 40], [False, 40], [True, 40], [False, 40], [False, 40], [False, 40]]],
   [[True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, True, 80]]],
  ['control: zero preset drop',
   [0, [[True, 10], [False, 10], [False, 10]]],
   [[True, False, 0], [False, False, 0], [False, False, 0]]],
  ['regression: exact expiry',
   [60, [[True, 10], [False, 30], [False, 30], [False, 30], [False, 30]]],
   [[True, False, 0], [True, True, 0], [True, True, 30], [False, False, 60], [False, False, 60]]],
  ['control: scenario 1',
   [0,
    [[False, 50],
     [True, 10],
     [False, 0],
     [True, 20],
     [False, 70],
     [False, 50],
     [True, 70],
     [False, 10],
     [False, 10],
     [False, 20],
     [True, 70]]],
   [[False, False, 0],
    [True, False, 0],
    [False, False, 0],
    [True, False, 0],
    [False, False, 0],
    [False, False, 0],
    [True, False, 0],
    [False, False, 0],
    [False, False, 0],
    [False, False, 0],
    [True, False, 0]]],
  ['control: scenario 2',
   [0,
    [[False, 30],
     [True, 50],
     [False, 50],
     [True, 0],
     [True, 10],
     [True, 10],
     [False, 10],
     [False, 50],
     [False, 10]]],
   [[False, False, 0],
    [True, False, 0],
    [False, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [False, False, 0],
    [False, False, 0],
    [False, False, 0]]]],
 [['regression: scenario 2',
   [100,
    [[False, 30],
     [False, 20],
     [True, 20],
     [True, 10],
     [True, 70],
     [False, 20],
     [False, 10],
     [True, 20],
     [False, 0],
     [True, 0],
     [True, 0]]],
   [[False, False, 100],
    [False, False, 100],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 10],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0],
    [True, False, 0]]],
  ['regression: scenario 4',
   [150, [[True, 10], [False, 30], [True, 70], [False, 10], [False, 50], [True, 70], [True, 50]]],
   [[True, False, 0],
    [True, True, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 50],
    [True, False, 0],
    [True, False, 0]]],
  ['control: power-up with false rung',
   [60, [[False, 20], [False, 20], [False, 20], [True, 10]]],
   [[False, False, 60], [False, False, 60], [False, False, 60], [True, False, 0]]],
  ['regression: re-energized mid delay',
   [100, [[True, 10], [False, 40], [False, 40], [True, 40], [False, 40], [False, 40], [False, 40]]],
   [[True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, True, 80]]],
  ['control: zero preset drop',
   [0, [[True, 10], [False, 10], [False, 10]]],
   [[True, False, 0], [False, False, 0], [False, False, 0]]],
  ['regression: exact expiry',
   [60, [[True, 10], [False, 30], [False, 30], [False, 30], [False, 30]]],
   [[True, False, 0], [True, True, 0], [True, True, 30], [False, False, 60], [False, False, 60]]],
  ['regression: scenario 1',
   [40, [[True, 70], [True, 20], [True, 20], [False, 30], [False, 30], [False, 0], [False, 70], [False, 20]]],
   [[True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 30],
    [True, True, 30],
    [False, False, 40],
    [False, False, 40]]],
  ['control: scenario 3',
   [60, [[False, 70], [True, 30], [True, 0], [True, 50], [True, 30], [True, 70], [True, 0]]],
   [[False, False, 60],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0]]]],
 [['regression: scenario 4',
   [40,
    [[False, 50],
     [True, 10],
     [False, 20],
     [False, 20],
     [True, 70],
     [False, 10],
     [True, 10],
     [False, 50],
     [False, 70],
     [False, 30],
     [False, 20],
     [False, 0]]],
   [[False, False, 40],
    [True, False, 0],
    [True, True, 0],
    [True, True, 20],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0],
    [True, True, 0],
    [False, False, 40],
    [False, False, 40],
    [False, False, 40],
    [False, False, 40]]],
  ['regression: scenario 5',
   [60,
    [[False, 30],
     [False, 20],
     [False, 20],
     [False, 10],
     [False, 50],
     [False, 50],
     [False, 50],
     [False, 20],
     [False, 30],
     [True, 70],
     [False, 20],
     [True, 30],
     [False, 20]]],
   [[False, False, 60],
    [False, False, 60],
    [False, False, 60],
    [False, False, 60],
    [False, False, 60],
    [False, False, 60],
    [False, False, 60],
    [False, False, 60],
    [False, False, 60],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0],
    [True, True, 0]]],
  ['control: power-up with false rung',
   [60, [[False, 20], [False, 20], [False, 20], [True, 10]]],
   [[False, False, 60], [False, False, 60], [False, False, 60], [True, False, 0]]],
  ['regression: re-energized mid delay',
   [100, [[True, 10], [False, 40], [False, 40], [True, 40], [False, 40], [False, 40], [False, 40]]],
   [[True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, True, 80]]],
  ['control: zero preset drop',
   [0, [[True, 10], [False, 10], [False, 10]]],
   [[True, False, 0], [False, False, 0], [False, False, 0]]],
  ['regression: exact expiry',
   [60, [[True, 10], [False, 30], [False, 30], [False, 30], [False, 30]]],
   [[True, False, 0], [True, True, 0], [True, True, 30], [False, False, 60], [False, False, 60]]],
  ['regression: scenario 1',
   [40,
    [[True, 70], [True, 20], [False, 50], [False, 20], [False, 50], [False, 50], [False, 50], [False, 0]]],
   [[True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 20],
    [False, False, 40],
    [False, False, 40],
    [False, False, 40],
    [False, False, 40]]],
  ['regression: scenario 2',
   [40,
    [[False, 70],
     [True, 70],
     [False, 50],
     [True, 70],
     [False, 10],
     [False, 30],
     [True, 0],
     [True, 50],
     [False, 0],
     [False, 30]]],
   [[False, False, 40],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 30],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 30]]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
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(preset, scans):
    acc = preset
    dn = False
    prev = False
    out = []
    for rung_in, dt in scans:
        rung_in = bool(rung_in)
        if rung_in:
            acc = 0
            dn = True
        elif dn:
            acc = min(preset, acc + (dt if not prev else dt // 2))
            if acc >= preset:
                dn = False
        tt = dn and not rung_in
        prev = rung_in
        out.append([dn, tt, acc])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: re-energized mid delay',
   [100, [[True, 10], [False, 40], [False, 40], [True, 40], [False, 40], [False, 40], [False, 40]]],
   [[True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, True, 80]]],
  ['regression: exact expiry',
   [60, [[True, 10], [False, 30], [False, 30], [False, 30], [False, 30]]],
   [[True, False, 0], [True, True, 0], [True, True, 30], [False, False, 60], [False, False, 60]]],
  ['control: power-up with false rung',
   [60, [[False, 20], [False, 20], [False, 20], [True, 10]]],
   [[False, False, 60], [False, False, 60], [False, False, 60], [True, False, 0]]],
  ['control: zero preset drop',
   [0, [[True, 10], [False, 10], [False, 10]]],
   [[True, False, 0], [False, False, 0], [False, False, 0]]],
  ['regression: scenario 1',
   [60, [[False, 70], [True, 10], [True, 70], [True, 10], [False, 70], [False, 10], [True, 10], [False, 30]]],
   [[False, False, 60],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 10],
    [True, False, 0],
    [True, True, 0]]],
  ['regression: scenario 2',
   [60, [[False, 30], [True, 50], [True, 20], [True, 30], [True, 70], [False, 50], [False, 50], [False, 70]]],
   [[False, False, 60],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 50],
    [False, False, 60]]],
  ['regression: scenario 3',
   [40,
    [[True, 70],
     [True, 0],
     [False, 50],
     [True, 30],
     [False, 0],
     [False, 50],
     [False, 30],
     [False, 50],
     [False, 10],
     [True, 20]]],
   [[True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0],
    [True, True, 0],
    [False, False, 40],
    [False, False, 40],
    [False, False, 40],
    [False, False, 40],
    [True, False, 0]]],
  ['regression: scenario 4',
   [100,
    [[False, 30],
     [False, 70],
     [True, 30],
     [False, 30],
     [False, 20],
     [False, 50],
     [False, 70],
     [True, 50],
     [True, 50],
     [False, 20],
     [False, 50]]],
   [[False, False, 100],
    [False, False, 100],
    [True, False, 0],
    [True, True, 0],
    [True, True, 20],
    [True, True, 70],
    [False, False, 100],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 50]]]],
 [['regression: exact expiry',
   [60, [[True, 10], [False, 30], [False, 30], [False, 30], [False, 30]]],
   [[True, False, 0], [True, True, 0], [True, True, 30], [False, False, 60], [False, False, 60]]],
  ['regression: scenario 3',
   [150,
    [[False, 50],
     [False, 10],
     [False, 0],
     [False, 50],
     [True, 50],
     [False, 70],
     [False, 10],
     [True, 70],
     [False, 50],
     [False, 70],
     [False, 20],
     [True, 50],
     [False, 0],
     [True, 30]]],
   [[False, False, 150],
    [False, False, 150],
    [False, False, 150],
    [False, False, 150],
    [True, False, 0],
    [True, True, 0],
    [True, True, 10],
    [True, False, 0],
    [True, True, 0],
    [True, True, 70],
    [True, True, 90],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0]]],
  ['control: power-up with false rung',
   [60, [[False, 20], [False, 20], [False, 20], [True, 10]]],
   [[False, False, 60], [False, False, 60], [False, False, 60], [True, False, 0]]],
  ['regression: re-energized mid delay',
   [100, [[True, 10], [False, 40], [False, 40], [True, 40], [False, 40], [False, 40], [False, 40]]],
   [[True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, True, 80]]],
  ['control: zero preset drop',
   [0, [[True, 10], [False, 10], [False, 10]]],
   [[True, False, 0], [False, False, 0], [False, False, 0]]],
  ['control: scenario 1',
   [0, [[False, 30], [True, 20], [True, 30], [False, 50], [True, 0], [True, 50], [True, 50]]],
   [[False, False, 0],
    [True, False, 0],
    [True, False, 0],
    [False, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0]]],
  ['control: scenario 2',
   [0, [[False, 10], [True, 0], [True, 70], [False, 0], [True, 70], [False, 20], [False, 10]]],
   [[False, False, 0],
    [True, False, 0],
    [True, False, 0],
    [False, False, 0],
    [True, False, 0],
    [False, False, 0],
    [False, False, 0]]],
  ['regression: scenario 4',
   [60,
    [[False, 0],
     [False, 10],
     [True, 20],
     [False, 20],
     [False, 0],
     [False, 0],
     [True, 50],
     [True, 20],
     [True, 10],
     [True, 0],
     [True, 10],
     [False, 20],
     [False, 70]]],
   [[False, False, 60],
    [False, False, 60],
    [True, False, 0],
    [True, True, 0],
    [True, True, 0],
    [True, True, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [False, False, 60]]]],
 [['regression: scenario 5',
   [100,
    [[False, 0],
     [False, 10],
     [True, 20],
     [True, 20],
     [False, 70],
     [True, 30],
     [True, 70],
     [True, 70],
     [True, 70],
     [True, 70]]],
   [[False, False, 100],
    [False, False, 100],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0]]],
  ['regression: scenario 6',
   [40,
    [[True, 0],
     [True, 20],
     [False, 0],
     [True, 50],
     [False, 30],
     [True, 70],
     [False, 20],
     [True, 50],
     [False, 50],
     [True, 20],
     [True, 0],
     [False, 30],
     [True, 70],
     [True, 10]]],
   [[True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0],
    [True, False, 0]]],
  ['control: power-up with false rung',
   [60, [[False, 20], [False, 20], [False, 20], [True, 10]]],
   [[False, False, 60], [False, False, 60], [False, False, 60], [True, False, 0]]],
  ['regression: re-energized mid delay',
   [100, [[True, 10], [False, 40], [False, 40], [True, 40], [False, 40], [False, 40], [False, 40]]],
   [[True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, True, 80]]],
  ['control: zero preset drop',
   [0, [[True, 10], [False, 10], [False, 10]]],
   [[True, False, 0], [False, False, 0], [False, False, 0]]],
  ['regression: exact expiry',
   [60, [[True, 10], [False, 30], [False, 30], [False, 30], [False, 30]]],
   [[True, False, 0], [True, True, 0], [True, True, 30], [False, False, 60], [False, False, 60]]],
  ['control: scenario 1',
   [0,
    [[False, 50],
     [True, 10],
     [False, 0],
     [True, 20],
     [False, 70],
     [False, 50],
     [True, 70],
     [False, 10],
     [False, 10],
     [False, 20],
     [True, 70]]],
   [[False, False, 0],
    [True, False, 0],
    [False, False, 0],
    [True, False, 0],
    [False, False, 0],
    [False, False, 0],
    [True, False, 0],
    [False, False, 0],
    [False, False, 0],
    [False, False, 0],
    [True, False, 0]]],
  ['control: scenario 2',
   [0,
    [[False, 30],
     [True, 50],
     [False, 50],
     [True, 0],
     [True, 10],
     [True, 10],
     [False, 10],
     [False, 50],
     [False, 10]]],
   [[False, False, 0],
    [True, False, 0],
    [False, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [False, False, 0],
    [False, False, 0],
    [False, False, 0]]]],
 [['regression: scenario 2',
   [100,
    [[False, 30],
     [False, 20],
     [True, 20],
     [True, 10],
     [True, 70],
     [False, 20],
     [False, 10],
     [True, 20],
     [False, 0],
     [True, 0],
     [True, 0]]],
   [[False, False, 100],
    [False, False, 100],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 10],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0],
    [True, False, 0]]],
  ['regression: scenario 4',
   [150, [[True, 10], [False, 30], [True, 70], [False, 10], [False, 50], [True, 70], [True, 50]]],
   [[True, False, 0],
    [True, True, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 50],
    [True, False, 0],
    [True, False, 0]]],
  ['control: power-up with false rung',
   [60, [[False, 20], [False, 20], [False, 20], [True, 10]]],
   [[False, False, 60], [False, False, 60], [False, False, 60], [True, False, 0]]],
  ['regression: re-energized mid delay',
   [100, [[True, 10], [False, 40], [False, 40], [True, 40], [False, 40], [False, 40], [False, 40]]],
   [[True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, True, 80]]],
  ['control: zero preset drop',
   [0, [[True, 10], [False, 10], [False, 10]]],
   [[True, False, 0], [False, False, 0], [False, False, 0]]],
  ['regression: exact expiry',
   [60, [[True, 10], [False, 30], [False, 30], [False, 30], [False, 30]]],
   [[True, False, 0], [True, True, 0], [True, True, 30], [False, False, 60], [False, False, 60]]],
  ['regression: scenario 1',
   [40, [[True, 70], [True, 20], [True, 20], [False, 30], [False, 30], [False, 0], [False, 70], [False, 20]]],
   [[True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 30],
    [True, True, 30],
    [False, False, 40],
    [False, False, 40]]],
  ['control: scenario 3',
   [60, [[False, 70], [True, 30], [True, 0], [True, 50], [True, 30], [True, 70], [True, 0]]],
   [[False, False, 60],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0],
    [True, False, 0]]]],
 [['regression: scenario 4',
   [40,
    [[False, 50],
     [True, 10],
     [False, 20],
     [False, 20],
     [True, 70],
     [False, 10],
     [True, 10],
     [False, 50],
     [False, 70],
     [False, 30],
     [False, 20],
     [False, 0]]],
   [[False, False, 40],
    [True, False, 0],
    [True, True, 0],
    [True, True, 20],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0],
    [True, True, 0],
    [False, False, 40],
    [False, False, 40],
    [False, False, 40],
    [False, False, 40]]],
  ['regression: scenario 5',
   [60,
    [[False, 30],
     [False, 20],
     [False, 20],
     [False, 10],
     [False, 50],
     [False, 50],
     [False, 50],
     [False, 20],
     [False, 30],
     [True, 70],
     [False, 20],
     [True, 30],
     [False, 20]]],
   [[False, False, 60],
    [False, False, 60],
    [False, False, 60],
    [False, False, 60],
    [False, False, 60],
    [False, False, 60],
    [False, False, 60],
    [False, False, 60],
    [False, False, 60],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0],
    [True, True, 0]]],
  ['control: power-up with false rung',
   [60, [[False, 20], [False, 20], [False, 20], [True, 10]]],
   [[False, False, 60], [False, False, 60], [False, False, 60], [True, False, 0]]],
  ['regression: re-energized mid delay',
   [100, [[True, 10], [False, 40], [False, 40], [True, 40], [False, 40], [False, 40], [False, 40]]],
   [[True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, False, 0],
    [True, True, 0],
    [True, True, 40],
    [True, True, 80]]],
  ['control: zero preset drop',
   [0, [[True, 10], [False, 10], [False, 10]]],
   [[True, False, 0], [False, False, 0], [False, False, 0]]],
  ['regression: exact expiry',
   [60, [[True, 10], [False, 30], [False, 30], [False, 30], [False, 30]]],
   [[True, False, 0], [True, True, 0], [True, True, 30], [False, False, 60], [False, False, 60]]],
  ['regression: scenario 1',
   [40,
    [[True, 70], [True, 20], [False, 50], [False, 20], [False, 50], [False, 50], [False, 50], [False, 0]]],
   [[True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 20],
    [False, False, 40],
    [False, False, 40],
    [False, False, 40],
    [False, False, 40]]],
  ['regression: scenario 2',
   [40,
    [[False, 70],
     [True, 70],
     [False, 50],
     [True, 70],
     [False, 10],
     [False, 30],
     [True, 0],
     [True, 50],
     [False, 0],
     [False, 30]]],
   [[False, False, 40],
    [True, False, 0],
    [True, True, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 30],
    [True, False, 0],
    [True, False, 0],
    [True, True, 0],
    [True, True, 30]]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
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 output turns off one scan early because the de-energizing scan already contributes time.

Off-delay timer (TOF) evaluated once per scan; scans is a list of [rung_in, elapsed_ms]. At power-up the timer is expired (ACC = preset, DN false). A true rung clears ACC and sets DN. After the rung drops, ACC accumulates each later false scan's elapsed time (the true-to-false scan itself is not credited), clamped at preset, and DN clears when ACC >= preset. TT is DN and not rung_in. Return [DN, TT, ACC] per scan.

split: open-access