broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    d = Fraction(str(x['dose_mg']))
    lim = Fraction(str(x['hour_limit_mg']))
    got, lock, cap, prev = [], 0, 0, None
    for p in x['presses']:
        bounce = prev is not None and p - prev < 2
        prev = p
        if bounce:
            continue
        if got and p - got[-1] < x['lockout_min']:
            lock += 1
            continue
        inwin = sum(1 for g in got if p - g < 3600)
        if (inwin + 1) * d > lim:
            cap += 1
            continue
        got.append(p)
    return {'delivered': got, 'denied_lockout': lock, 'denied_limit': cap, 'total_mg': float(len(got) * d)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('press exactly at lockout end',
   {'presses': [0, 600], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 10},
   {'delivered': [0, 600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 701, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 701, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2401], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3701, 4001], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 701], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 701], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1710], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1710], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
 [('press exactly at lockout end',
   {'presses': [0, 1200], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 10},
   {'delivered': [0, 1200], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 702, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 702, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2402], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3702, 4002], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 702], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 702], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1720], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1720], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
 [('press exactly at lockout end',
   {'presses': [0, 1800], 'dose_mg': 1, 'lockout_min': 30, 'hour_limit_mg': 10},
   {'delivered': [0, 1800], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 703, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 703, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2403], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3703, 4003], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 703], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 703], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1730], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1730], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
 [('press exactly at lockout end',
   {'presses': [0, 2400], 'dose_mg': 1, 'lockout_min': 40, 'hour_limit_mg': 10},
   {'delivered': [0, 2400], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 704, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 704, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2404], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3704, 4004], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 704], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 704], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1740], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1740], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
 [('press exactly at lockout end',
   {'presses': [0, 3000], 'dose_mg': 1, 'lockout_min': 50, 'hour_limit_mg': 10},
   {'delivered': [0, 3000], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 705, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 705, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2405], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3705, 4005], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 705], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 705], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1750], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1750], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    d = Fraction(str(x['dose_mg']))
    lim = Fraction(str(x['hour_limit_mg']))
    got, lock, cap, prev = [], 0, 0, None
    for p in x['presses']:
        bounce = prev is not None and p - prev < 2
        prev = p
        if bounce:
            continue
        if got and p - got[-1] <= x['lockout_min'] * 60:
            lock += 1
            continue
        inwin = sum(1 for g in got if p - g < 3600)
        if (inwin + 1) * d > lim:
            cap += 1
            continue
        got.append(p)
    return {'delivered': got, 'denied_lockout': lock, 'denied_limit': cap, 'total_mg': float(len(got) * d)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('press exactly at lockout end',
   {'presses': [0, 600], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 10},
   {'delivered': [0, 600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 701, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 701, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2401], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3701, 4001], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 701], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 701], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1710], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1710], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
 [('press exactly at lockout end',
   {'presses': [0, 1200], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 10},
   {'delivered': [0, 1200], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 702, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 702, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2402], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3702, 4002], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 702], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 702], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1720], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1720], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
 [('press exactly at lockout end',
   {'presses': [0, 1800], 'dose_mg': 1, 'lockout_min': 30, 'hour_limit_mg': 10},
   {'delivered': [0, 1800], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 703, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 703, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2403], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3703, 4003], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 703], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 703], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1730], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1730], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
 [('press exactly at lockout end',
   {'presses': [0, 2400], 'dose_mg': 1, 'lockout_min': 40, 'hour_limit_mg': 10},
   {'delivered': [0, 2400], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 704, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 704, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2404], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3704, 4004], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 704], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 704], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1740], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1740], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
 [('press exactly at lockout end',
   {'presses': [0, 3000], 'dose_mg': 1, 'lockout_min': 50, 'hour_limit_mg': 10},
   {'delivered': [0, 3000], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 705, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 705, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2405], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3705, 4005], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 705], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 705], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1750], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1750], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.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:
Presses a few minutes apart are all delivered despite a 10-minute lockout.

Input {presses (ascending seconds), dose_mg, lockout_min, hour_limit_mg}. A press less than 2 s after the previous press (delivered or not) is a switch bounce and ignored entirely. Otherwise it is denied for lockout when less than lockout_min*60 s have passed since the last DELIVERED dose, denied for limit when (deliveries in the preceding 3600 s + 1)*dose exceeds hour_limit_mg, else delivered. Return {delivered, denied_lockout, denied_limit, total_mg}.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    d = Fraction(str(x['dose_mg']))
    lim = Fraction(str(x['hour_limit_mg']))
    got, lock, cap, prev = [], 0, 0, None
    for p in x['presses']:
        bounce = prev is not None and p - prev < 2
        prev = p
        if bounce:
            continue
        if got and p - got[-1] < x['lockout_min'] * 60:
            lock += 1
            continue
        inwin = sum(1 for g in got if p - g <= 3600)
        if (inwin + 1) * d > lim:
            cap += 1
            continue
        got.append(p)
    return {'delivered': got, 'denied_lockout': lock, 'denied_limit': cap, 'total_mg': float(len(got) * d)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('press exactly at lockout end',
   {'presses': [0, 600], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 10},
   {'delivered': [0, 600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 701, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 701, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2401], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3701, 4001], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 701], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 701], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1710], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1710], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
 [('press exactly at lockout end',
   {'presses': [0, 1200], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 10},
   {'delivered': [0, 1200], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 702, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 702, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2402], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3702, 4002], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 702], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 702], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1720], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1720], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
 [('press exactly at lockout end',
   {'presses': [0, 1800], 'dose_mg': 1, 'lockout_min': 30, 'hour_limit_mg': 10},
   {'delivered': [0, 1800], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 703, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 703, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2403], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3703, 4003], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 703], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 703], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1730], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1730], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
 [('press exactly at lockout end',
   {'presses': [0, 2400], 'dose_mg': 1, 'lockout_min': 40, 'hour_limit_mg': 10},
   {'delivered': [0, 2400], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 704, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 704, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2404], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3704, 4004], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 704], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 704], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1740], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1740], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
 [('press exactly at lockout end',
   {'presses': [0, 3000], 'dose_mg': 1, 'lockout_min': 50, 'hour_limit_mg': 10},
   {'delivered': [0, 3000], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 705, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 705, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2405], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3705, 4005], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 705], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 705], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1750], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1750], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.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
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    d = Fraction(str(x['dose_mg']))
    lim = Fraction(str(x['hour_limit_mg']))
    got, lock, cap, prev = [], 0, 0, None
    for p in x['presses']:
        bounce = prev is not None and p - prev < 2
        prev = p
        if bounce:
            continue
        if got and p - got[-1] < x['lockout_min'] * 60:
            lock += 1
            continue
        inwin = sum(1 for g in got if p // 3600 == g // 3600)
        if (inwin + 1) * d > lim:
            cap += 1
            continue
        got.append(p)
    return {'delivered': got, 'denied_lockout': lock, 'denied_limit': cap, 'total_mg': float(len(got) * d)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('press exactly at lockout end',
   {'presses': [0, 600], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 10},
   {'delivered': [0, 600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 701, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 701, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2401], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3701, 4001], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 701], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 701], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1710], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1710], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
 [('press exactly at lockout end',
   {'presses': [0, 1200], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 10},
   {'delivered': [0, 1200], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 702, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 702, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2402], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3702, 4002], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 702], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 702], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1720], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1720], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
 [('press exactly at lockout end',
   {'presses': [0, 1800], 'dose_mg': 1, 'lockout_min': 30, 'hour_limit_mg': 10},
   {'delivered': [0, 1800], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 703, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 703, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2403], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3703, 4003], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 703], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 703], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1730], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1730], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
 [('press exactly at lockout end',
   {'presses': [0, 2400], 'dose_mg': 1, 'lockout_min': 40, 'hour_limit_mg': 10},
   {'delivered': [0, 2400], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 704, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 704, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2404], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3704, 4004], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 704], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 704], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1740], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1740], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
 [('press exactly at lockout end',
   {'presses': [0, 3000], 'dose_mg': 1, 'lockout_min': 50, 'hour_limit_mg': 10},
   {'delivered': [0, 3000], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 705, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 705, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2405], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3705, 4005], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 705], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 705], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1750], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1750], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.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:
A delivery exactly one hour old still counts against the hourly limit.

Input {presses (ascending seconds), dose_mg, lockout_min, hour_limit_mg}. A press less than 2 s after the previous press (delivered or not) is a switch bounce and ignored entirely. Otherwise it is denied for lockout when less than lockout_min*60 s have passed since the last DELIVERED dose, denied for limit when (deliveries in the preceding 3600 s + 1)*dose exceeds hour_limit_mg, else delivered. Return {delivered, denied_lockout, denied_limit, total_mg}.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    d = Fraction(str(x['dose_mg']))
    lim = Fraction(str(x['hour_limit_mg']))
    got, lock, cap, prev = [], 0, 0, None
    for p in x['presses']:
        bounce = prev is not None and p - prev < 2
        prev = p
        if bounce:
            continue
        if got and p - got[-1] < x['lockout_min'] * 60:
            lock += 1
            continue
        inwin = sum(1 for g in got if p - g < 3600)
        if inwin * d > lim:
            cap += 1
            continue
        got.append(p)
    return {'delivered': got, 'denied_lockout': lock, 'denied_limit': cap, 'total_mg': float(len(got) * d)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('press exactly at lockout end',
   {'presses': [0, 600], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 10},
   {'delivered': [0, 600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 701, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 701, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2401], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3701, 4001], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 701], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 701], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1710], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1710], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
 [('press exactly at lockout end',
   {'presses': [0, 1200], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 10},
   {'delivered': [0, 1200], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 702, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 702, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2402], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3702, 4002], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 702], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 702], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1720], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1720], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
 [('press exactly at lockout end',
   {'presses': [0, 1800], 'dose_mg': 1, 'lockout_min': 30, 'hour_limit_mg': 10},
   {'delivered': [0, 1800], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 703, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 703, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2403], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3703, 4003], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 703], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 703], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1730], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1730], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
 [('press exactly at lockout end',
   {'presses': [0, 2400], 'dose_mg': 1, 'lockout_min': 40, 'hour_limit_mg': 10},
   {'delivered': [0, 2400], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 704, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 704, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2404], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3704, 4004], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 704], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 704], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1740], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1740], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
 [('press exactly at lockout end',
   {'presses': [0, 3000], 'dose_mg': 1, 'lockout_min': 50, 'hour_limit_mg': 10},
   {'delivered': [0, 3000], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 705, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 705, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2405], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3705, 4005], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 705], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 705], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1750], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1750], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    d = Fraction(str(x['dose_mg']))
    lim = Fraction(str(x['hour_limit_mg']))
    got, lock, cap, prev = [], 0, 0, None
    for p in x['presses']:
        bounce = prev is not None and p - prev < 2
        prev = p
        if bounce:
            continue
        if got and p - got[-1] < x['lockout_min'] * 60:
            lock += 1
            continue
        inwin = sum(1 for g in got if p - g < 3600)
        if (inwin + 1) * d >= lim:
            cap += 1
            continue
        got.append(p)
    return {'delivered': got, 'denied_lockout': lock, 'denied_limit': cap, 'total_mg': float(len(got) * d)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('press exactly at lockout end',
   {'presses': [0, 600], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 10},
   {'delivered': [0, 600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 701, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 701, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2401], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3701, 4001], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 701], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 701], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1710], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1710], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
 [('press exactly at lockout end',
   {'presses': [0, 1200], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 10},
   {'delivered': [0, 1200], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 702, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 702, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2402], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3702, 4002], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 702], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 702], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1720], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1720], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
 [('press exactly at lockout end',
   {'presses': [0, 1800], 'dose_mg': 1, 'lockout_min': 30, 'hour_limit_mg': 10},
   {'delivered': [0, 1800], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 703, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 703, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2403], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3703, 4003], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 703], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 703], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1730], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1730], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
 [('press exactly at lockout end',
   {'presses': [0, 2400], 'dose_mg': 1, 'lockout_min': 40, 'hour_limit_mg': 10},
   {'delivered': [0, 2400], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 704, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 704, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2404], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3704, 4004], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 704], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 704], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1740], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1740], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
 [('press exactly at lockout end',
   {'presses': [0, 3000], 'dose_mg': 1, 'lockout_min': 50, 'hour_limit_mg': 10},
   {'delivered': [0, 3000], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 705, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 705, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2405], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3705, 4005], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 705], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 705], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1750], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1750], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.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:
The pump delivers a dose that takes the hourly total above the limit.

Input {presses (ascending seconds), dose_mg, lockout_min, hour_limit_mg}. A press less than 2 s after the previous press (delivered or not) is a switch bounce and ignored entirely. Otherwise it is denied for lockout when less than lockout_min*60 s have passed since the last DELIVERED dose, denied for limit when (deliveries in the preceding 3600 s + 1)*dose exceeds hour_limit_mg, else delivered. Return {delivered, denied_lockout, denied_limit, total_mg}.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    d = Fraction(str(x['dose_mg']))
    lim = Fraction(str(x['hour_limit_mg']))
    got, lock, cap, prev = [], 0, 0, None
    for p in x['presses']:
        bounce = bool(got) and p - got[-1] < 2
        prev = p
        if bounce:
            continue
        if got and p - got[-1] < x['lockout_min'] * 60:
            lock += 1
            continue
        inwin = sum(1 for g in got if p - g < 3600)
        if (inwin + 1) * d > lim:
            cap += 1
            continue
        got.append(p)
    return {'delivered': got, 'denied_lockout': lock, 'denied_limit': cap, 'total_mg': float(len(got) * d)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('press exactly at lockout end',
   {'presses': [0, 600], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 10},
   {'delivered': [0, 600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 701, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 701, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2401], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3701, 4001], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 701], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 701], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1710], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1710], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
 [('press exactly at lockout end',
   {'presses': [0, 1200], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 10},
   {'delivered': [0, 1200], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 702, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 702, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2402], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3702, 4002], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 702], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 702], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1720], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1720], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
 [('press exactly at lockout end',
   {'presses': [0, 1800], 'dose_mg': 1, 'lockout_min': 30, 'hour_limit_mg': 10},
   {'delivered': [0, 1800], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 703, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 703, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2403], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3703, 4003], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 703], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 703], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1730], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1730], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
 [('press exactly at lockout end',
   {'presses': [0, 2400], 'dose_mg': 1, 'lockout_min': 40, 'hour_limit_mg': 10},
   {'delivered': [0, 2400], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 704, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 704, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2404], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3704, 4004], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 704], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 704], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1740], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1740], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
 [('press exactly at lockout end',
   {'presses': [0, 3000], 'dose_mg': 1, 'lockout_min': 50, 'hour_limit_mg': 10},
   {'delivered': [0, 3000], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 705, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 705, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2405], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3705, 4005], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 705], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 705], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1750], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1750], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    d = Fraction(str(x['dose_mg']))
    lim = Fraction(str(x['hour_limit_mg']))
    got, lock, cap, prev = [], 0, 0, None
    for p in x['presses']:
        bounce = prev is not None and p - prev <= 2
        prev = p
        if bounce:
            continue
        if got and p - got[-1] < x['lockout_min'] * 60:
            lock += 1
            continue
        inwin = sum(1 for g in got if p - g < 3600)
        if (inwin + 1) * d > lim:
            cap += 1
            continue
        got.append(p)
    return {'delivered': got, 'denied_lockout': lock, 'denied_limit': cap, 'total_mg': float(len(got) * d)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('press exactly at lockout end',
   {'presses': [0, 600], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 10},
   {'delivered': [0, 600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 701, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 701, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2401], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3701, 4001], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 701], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 701], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1710], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1710], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
 [('press exactly at lockout end',
   {'presses': [0, 1200], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 10},
   {'delivered': [0, 1200], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 702, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 702, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2402], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3702, 4002], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 702], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 702], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1720], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1720], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
 [('press exactly at lockout end',
   {'presses': [0, 1800], 'dose_mg': 1, 'lockout_min': 30, 'hour_limit_mg': 10},
   {'delivered': [0, 1800], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 703, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 703, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2403], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3703, 4003], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 703], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 703], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1730], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1730], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
 [('press exactly at lockout end',
   {'presses': [0, 2400], 'dose_mg': 1, 'lockout_min': 40, 'hour_limit_mg': 10},
   {'delivered': [0, 2400], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 704, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 704, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2404], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3704, 4004], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 704], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 704], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1740], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1740], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
 [('press exactly at lockout end',
   {'presses': [0, 3000], 'dose_mg': 1, 'lockout_min': 50, 'hour_limit_mg': 10},
   {'delivered': [0, 3000], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 705, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 705, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2405], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3705, 4005], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 705], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 705], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1750], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1750], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.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:
Rapid double presses after a denied press are counted as lockout denials.

Input {presses (ascending seconds), dose_mg, lockout_min, hour_limit_mg}. A press less than 2 s after the previous press (delivered or not) is a switch bounce and ignored entirely. Otherwise it is denied for lockout when less than lockout_min*60 s have passed since the last DELIVERED dose, denied for limit when (deliveries in the preceding 3600 s + 1)*dose exceeds hour_limit_mg, else delivered. Return {delivered, denied_lockout, denied_limit, total_mg}.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    d = Fraction(str(x['dose_mg']))
    lim = Fraction(str(x['hour_limit_mg']))
    got, lock, cap, prev = [], 0, 0, None
    for p in x['presses']:
        bounce = prev is not None and p - prev < 2
        if bounce:
            continue
        prev = p
        if got and p - got[-1] < x['lockout_min'] * 60:
            lock += 1
            continue
        inwin = sum(1 for g in got if p - g < 3600)
        if (inwin + 1) * d > lim:
            cap += 1
            continue
        got.append(p)
    return {'delivered': got, 'denied_lockout': lock, 'denied_limit': cap, 'total_mg': float(len(got) * d)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('press exactly at lockout end',
   {'presses': [0, 600], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 10},
   {'delivered': [0, 600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 701, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 701, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2401], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3701, 4001], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 701], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 701], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1710], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1710], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
 [('press exactly at lockout end',
   {'presses': [0, 1200], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 10},
   {'delivered': [0, 1200], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 702, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 702, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2402], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3702, 4002], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 702], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 702], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1720], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1720], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
 [('press exactly at lockout end',
   {'presses': [0, 1800], 'dose_mg': 1, 'lockout_min': 30, 'hour_limit_mg': 10},
   {'delivered': [0, 1800], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 703, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 703, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2403], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3703, 4003], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 703], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 703], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1730], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1730], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
 [('press exactly at lockout end',
   {'presses': [0, 2400], 'dose_mg': 1, 'lockout_min': 40, 'hour_limit_mg': 10},
   {'delivered': [0, 2400], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 704, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 704, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2404], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3704, 4004], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 704], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 704], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1740], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1740], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
 [('press exactly at lockout end',
   {'presses': [0, 3000], 'dose_mg': 1, 'lockout_min': 50, 'hour_limit_mg': 10},
   {'delivered': [0, 3000], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 705, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 705, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2405], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3705, 4005], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 705], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 705], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1750], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1750], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    d = Fraction(str(x['dose_mg']))
    lim = Fraction(str(x['hour_limit_mg']))
    got, lock, cap, prev = [], 0, 0, None
    for p in x['presses']:
        bounce = prev is not None and p - prev < 2
        if bounce:
            continue
        prev = got[-1] if got else p
        if got and p - got[-1] < x['lockout_min'] * 60:
            lock += 1
            continue
        inwin = sum(1 for g in got if p - g < 3600)
        if (inwin + 1) * d > lim:
            cap += 1
            continue
        got.append(p)
    return {'delivered': got, 'denied_lockout': lock, 'denied_limit': cap, 'total_mg': float(len(got) * d)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('press exactly at lockout end',
   {'presses': [0, 600], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 10},
   {'delivered': [0, 600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 701, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 701, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2401], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3701, 4001], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 701], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 701], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1710], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1710], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
 [('press exactly at lockout end',
   {'presses': [0, 1200], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 10},
   {'delivered': [0, 1200], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 702, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 702, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2402], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3702, 4002], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 702], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 702], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1720], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1720], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
 [('press exactly at lockout end',
   {'presses': [0, 1800], 'dose_mg': 1, 'lockout_min': 30, 'hour_limit_mg': 10},
   {'delivered': [0, 1800], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 703, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 703, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2403], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3703, 4003], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 703], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 703], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1730], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1730], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
 [('press exactly at lockout end',
   {'presses': [0, 2400], 'dose_mg': 1, 'lockout_min': 40, 'hour_limit_mg': 10},
   {'delivered': [0, 2400], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 704, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 704, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2404], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3704, 4004], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 704], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 704], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1740], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1740], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
 [('press exactly at lockout end',
   {'presses': [0, 3000], 'dose_mg': 1, 'lockout_min': 50, 'hour_limit_mg': 10},
   {'delivered': [0, 3000], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('lockout measured in seconds',
   {'presses': [100, 400, 705, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
   {'delivered': [100, 705, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
  ('hourly limit reached',
   {'presses': [0, 600, 1200, 1800, 2405], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
   {'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
  ('delivery exactly one hour old expires',
   {'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
   {'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
  ('window across clock hour',
   {'presses': [3000, 3500, 3705, 4005], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
   {'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
  ('switch bounce chain',
   {'presses': [0, 1, 2, 3, 4, 705], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [0, 705], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
  ('two second gap is a real press',
   {'presses': [1000, 1002, 1750], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
   {'delivered': [1000, 1750], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.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:
A long chain of bounces produces a spurious lockout denial.

Input {presses (ascending seconds), dose_mg, lockout_min, hour_limit_mg}. A press less than 2 s after the previous press (delivered or not) is a switch bounce and ignored entirely. Otherwise it is denied for lockout when less than lockout_min*60 s have passed since the last DELIVERED dose, denied for limit when (deliveries in the preceding 3600 s + 1)*dose exceeds hour_limit_mg, else delivered. Return {delivered, denied_lockout, denied_limit, total_mg}.

split: open-access