broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    s,e=x['study']; a=x['age']; tot=0; deaths=0
    for b,en,ex,died in x['records']:
        bs=b+365*a; be=bs+365
        lo=max(s,en,bs); hi=min(e,ex,be)
        counted=died and lo<=ex<min(e,be)
        if counted: deaths+=1
        if x['method']=='actuarial' and counted: hi=min(e,be)
        tot+=max(0,hi-lo)
    return [tot,deaths]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['exact mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-1646, 20187, 20406, False], [-1852, 20095, 20577, False], [-1617, 20154, 20514, False], [-1795, 19880, 20864, False], [-2031, 19846, 20364, True]], 'method': 'exact'}, [1300, 0]], ['exact death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1795, 20149, 20843, False]], 'method': 'exact'}, [686, 0]], ['exact late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'exact'}, [50, 1]], ['exact death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'exact'}, [230, 0]], ['exact death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'exact'}, [0, 0]], ['actuarial mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-1640, 19886, 20758, False], [-2010, 20199, 20626, False], [-2086, 19856, 20816, False], [-2011, 20172, 20892, False], [-1704, 19877, 20272, True]], 'method': 'actuarial'}, [1047, 1]], ['actuarial death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1976, 19813, 20729, False]], 'method': 'actuarial'}, [654, 0]], ['actuarial late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'actuarial'}, [215, 1]], ['actuarial death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'actuarial'}, [230, 0]], ['actuarial death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'actuarial'}, [0, 0]], ['exact survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-1717, 19878, 20681, False], [-1678, 20196, 20770, False], [-2186, 20016, 20415, False]], 'method': 'exact'}, [793, 0]], ['actuarial survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-2064, 19900, 20737, False], [-2068, 19900, 20448, False], [-2155, 19900, 20867, False]], 'method': 'actuarial'}, [508, 0]], ['death on first observed day', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20150, 20150, True]], 'method': 'exact'}, [0, 1]], ['death near study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1270, 20000, 20727, True]], 'method': 'actuarial'}, [365, 1]]], [['exact mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-2070, 19840, 20456, False], [-1999, 20154, 20680, False], [-2193, 19855, 20494, False], [-2156, 19996, 20689, False], [-1701, 20077, 20310, True]], 'method': 'exact'}, [599, 1]], ['exact death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1711, 19808, 20863, False]], 'method': 'exact'}, [730, 0]], ['exact late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'exact'}, [50, 1]], ['exact death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'exact'}, [230, 0]], ['exact death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'exact'}, [0, 0]], ['actuarial mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-1665, 19831, 20488, False], [-1673, 19955, 20442, False], [-1850, 20050, 20697, False], [-2078, 19804, 20804, False], [-1601, 20194, 20313, True]], 'method': 'actuarial'}, [1385, 1]], ['actuarial death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1605, 19948, 20570, False]], 'method': 'actuarial'}, [640, 0]], ['actuarial late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'actuarial'}, [215, 1]], ['actuarial death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'actuarial'}, [230, 0]], ['actuarial death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'actuarial'}, [0, 0]], ['exact survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-1889, 19936, 20521, False], [-1640, 20120, 20507, False], [-1778, 20160, 20852, False]], 'method': 'exact'}, [939, 0]], ['actuarial survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-1890, 19900, 20544, False], [-1719, 19900, 20802, False], [-2117, 19900, 20531, False]], 'method': 'actuarial'}, [878, 0]], ['death on first observed day', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20150, 20150, True]], 'method': 'exact'}, [0, 1]], ['death near study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1270, 20000, 20727, True]], 'method': 'actuarial'}, [365, 1]]], [['exact mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-1741, 20077, 20701, False], [-1769, 20197, 20455, False], [-2071, 19974, 20741, False], [-1918, 19823, 20436, False], [-2098, 20169, 20358, True]], 'method': 'exact'}, [1164, 0]], ['exact death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1954, 20112, 20568, False]], 'method': 'exact'}, [564, 0]], ['exact late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'exact'}, [50, 1]], ['exact death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'exact'}, [230, 0]], ['exact death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'exact'}, [0, 0]], ['actuarial mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-1887, 19974, 20561, False], [-2071, 20133, 20760, False], [-1820, 20134, 20483, False], [-1975, 20119, 20850, False], [-1795, 20071, 20207, True]], 'method': 'actuarial'}, [1273, 1]], ['actuarial death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-2147, 19920, 20609, False]], 'method': 'actuarial'}, [483, 0]], ['actuarial late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'actuarial'}, [215, 1]], ['actuarial death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'actuarial'}, [230, 0]], ['actuarial death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'actuarial'}, [0, 0]], ['exact survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-1894, 20110, 20820, False], [-1682, 19889, 20808, False], [-2155, 19896, 20593, False]], 'method': 'exact'}, [736, 0]], ['actuarial survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-2018, 19900, 20548, False], [-1644, 19900, 20877, False], [-2200, 19900, 20475, False]], 'method': 'actuarial'}, [677, 0]], ['death on first observed day', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20150, 20150, True]], 'method': 'exact'}, [0, 1]], ['death near study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1270, 20000, 20727, True]], 'method': 'actuarial'}, [365, 1]]], [['exact mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-1863, 20066, 20531, False], [-2075, 19963, 20495, False], [-1993, 19890, 20763, False], [-1827, 19962, 20674, False], [-2180, 20079, 20226, True]], 'method': 'exact'}, [1169, 0]], ['exact death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1679, 20195, 20683, False]], 'method': 'exact'}, [730, 0]], ['exact late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'exact'}, [50, 1]], ['exact death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'exact'}, [230, 0]], ['exact death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'exact'}, [0, 0]], ['actuarial mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-2025, 19978, 20453, False], [-2178, 19958, 20450, False], [-2000, 19923, 20448, False], [-2144, 19842, 20894, False], [-2062, 19838, 20339, True]], 'method': 'actuarial'}, [916, 0]], ['actuarial death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1658, 20133, 20633, False]], 'method': 'actuarial'}, [730, 0]], ['actuarial late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'actuarial'}, [215, 1]], ['actuarial death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'actuarial'}, [230, 0]], ['actuarial death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'actuarial'}, [0, 0]], ['exact survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-2119, 19951, 20507, False], [-1690, 20001, 20675, False], [-1814, 19802, 20650, False]], 'method': 'exact'}, [876, 0]], ['actuarial survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-1893, 19900, 20703, False], [-2022, 19900, 20661, False], [-1898, 19900, 20856, False]], 'method': 'actuarial'}, [973, 0]], ['death on first observed day', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20150, 20150, True]], 'method': 'exact'}, [0, 1]], ['death near study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1270, 20000, 20727, True]], 'method': 'actuarial'}, [365, 1]]], [['exact mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-1825, 20155, 20608, False], [-1632, 20145, 20432, False], [-1827, 20020, 20829, False], [-2080, 19871, 20894, False], [-2071, 20138, 20394, True]], 'method': 'exact'}, [1055, 0]], ['exact death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1652, 20173, 20716, False]], 'method': 'exact'}, [730, 0]], ['exact late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'exact'}, [50, 1]], ['exact death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'exact'}, [230, 0]], ['exact death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'exact'}, [0, 0]], ['actuarial mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-2038, 19972, 20521, False], [-1836, 19923, 20435, False], [-2081, 20049, 20457, False], [-1816, 19815, 20798, False], [-1964, 19855, 20159, True]], 'method': 'actuarial'}, [1393, 1]], ['actuarial death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1744, 19944, 20873, False]], 'method': 'actuarial'}, [730, 0]], ['actuarial late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'actuarial'}, [215, 1]], ['actuarial death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'actuarial'}, [230, 0]], ['actuarial death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'actuarial'}, [0, 0]], ['exact survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-1879, 19856, 20519, False], [-1807, 19835, 20774, False], [-2006, 19972, 20562, False]], 'method': 'exact'}, [989, 0]], ['actuarial survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-1878, 19900, 20430, False], [-2072, 19900, 20760, False], [-1895, 19900, 20822, False]], 'method': 'actuarial'}, [923, 0]], ['death on first observed day', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20150, 20150, True]], 'method': 'exact'}, [0, 1]], ['death near study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1270, 20000, 20727, True]], 'method': 'actuarial'}, [365, 1]]]]
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):
    s,e=x['study']; a=x['age']; tot=0; deaths=0
    for b,en,ex,died in x['records']:
        bs=b+365*a; be=bs+365
        lo=max(s,en,bs); hi=min(e,ex,be)
        counted=died and lo<=ex<min(e,be)
        if counted: deaths+=1
        if x['method']=='actuarial' and counted: hi=e
        tot+=max(0,hi-lo)
    return [tot,deaths]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['exact mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-1646, 20187, 20406, False], [-1852, 20095, 20577, False], [-1617, 20154, 20514, False], [-1795, 19880, 20864, False], [-2031, 19846, 20364, True]], 'method': 'exact'}, [1300, 0]], ['exact death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1795, 20149, 20843, False]], 'method': 'exact'}, [686, 0]], ['exact late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'exact'}, [50, 1]], ['exact death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'exact'}, [230, 0]], ['exact death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'exact'}, [0, 0]], ['actuarial mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-1640, 19886, 20758, False], [-2010, 20199, 20626, False], [-2086, 19856, 20816, False], [-2011, 20172, 20892, False], [-1704, 19877, 20272, True]], 'method': 'actuarial'}, [1047, 1]], ['actuarial death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1976, 19813, 20729, False]], 'method': 'actuarial'}, [654, 0]], ['actuarial late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'actuarial'}, [215, 1]], ['actuarial death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'actuarial'}, [230, 0]], ['actuarial death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'actuarial'}, [0, 0]], ['exact survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-1717, 19878, 20681, False], [-1678, 20196, 20770, False], [-2186, 20016, 20415, False]], 'method': 'exact'}, [793, 0]], ['actuarial survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-2064, 19900, 20737, False], [-2068, 19900, 20448, False], [-2155, 19900, 20867, False]], 'method': 'actuarial'}, [508, 0]], ['death on first observed day', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20150, 20150, True]], 'method': 'exact'}, [0, 1]], ['death near study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1270, 20000, 20727, True]], 'method': 'actuarial'}, [365, 1]]], [['exact mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-2070, 19840, 20456, False], [-1999, 20154, 20680, False], [-2193, 19855, 20494, False], [-2156, 19996, 20689, False], [-1701, 20077, 20310, True]], 'method': 'exact'}, [599, 1]], ['exact death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1711, 19808, 20863, False]], 'method': 'exact'}, [730, 0]], ['exact late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'exact'}, [50, 1]], ['exact death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'exact'}, [230, 0]], ['exact death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'exact'}, [0, 0]], ['actuarial mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-1665, 19831, 20488, False], [-1673, 19955, 20442, False], [-1850, 20050, 20697, False], [-2078, 19804, 20804, False], [-1601, 20194, 20313, True]], 'method': 'actuarial'}, [1385, 1]], ['actuarial death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1605, 19948, 20570, False]], 'method': 'actuarial'}, [640, 0]], ['actuarial late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'actuarial'}, [215, 1]], ['actuarial death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'actuarial'}, [230, 0]], ['actuarial death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'actuarial'}, [0, 0]], ['exact survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-1889, 19936, 20521, False], [-1640, 20120, 20507, False], [-1778, 20160, 20852, False]], 'method': 'exact'}, [939, 0]], ['actuarial survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-1890, 19900, 20544, False], [-1719, 19900, 20802, False], [-2117, 19900, 20531, False]], 'method': 'actuarial'}, [878, 0]], ['death on first observed day', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20150, 20150, True]], 'method': 'exact'}, [0, 1]], ['death near study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1270, 20000, 20727, True]], 'method': 'actuarial'}, [365, 1]]], [['exact mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-1741, 20077, 20701, False], [-1769, 20197, 20455, False], [-2071, 19974, 20741, False], [-1918, 19823, 20436, False], [-2098, 20169, 20358, True]], 'method': 'exact'}, [1164, 0]], ['exact death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1954, 20112, 20568, False]], 'method': 'exact'}, [564, 0]], ['exact late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'exact'}, [50, 1]], ['exact death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'exact'}, [230, 0]], ['exact death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'exact'}, [0, 0]], ['actuarial mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-1887, 19974, 20561, False], [-2071, 20133, 20760, False], [-1820, 20134, 20483, False], [-1975, 20119, 20850, False], [-1795, 20071, 20207, True]], 'method': 'actuarial'}, [1273, 1]], ['actuarial death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-2147, 19920, 20609, False]], 'method': 'actuarial'}, [483, 0]], ['actuarial late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'actuarial'}, [215, 1]], ['actuarial death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'actuarial'}, [230, 0]], ['actuarial death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'actuarial'}, [0, 0]], ['exact survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-1894, 20110, 20820, False], [-1682, 19889, 20808, False], [-2155, 19896, 20593, False]], 'method': 'exact'}, [736, 0]], ['actuarial survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-2018, 19900, 20548, False], [-1644, 19900, 20877, False], [-2200, 19900, 20475, False]], 'method': 'actuarial'}, [677, 0]], ['death on first observed day', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20150, 20150, True]], 'method': 'exact'}, [0, 1]], ['death near study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1270, 20000, 20727, True]], 'method': 'actuarial'}, [365, 1]]], [['exact mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-1863, 20066, 20531, False], [-2075, 19963, 20495, False], [-1993, 19890, 20763, False], [-1827, 19962, 20674, False], [-2180, 20079, 20226, True]], 'method': 'exact'}, [1169, 0]], ['exact death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1679, 20195, 20683, False]], 'method': 'exact'}, [730, 0]], ['exact late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'exact'}, [50, 1]], ['exact death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'exact'}, [230, 0]], ['exact death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'exact'}, [0, 0]], ['actuarial mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-2025, 19978, 20453, False], [-2178, 19958, 20450, False], [-2000, 19923, 20448, False], [-2144, 19842, 20894, False], [-2062, 19838, 20339, True]], 'method': 'actuarial'}, [916, 0]], ['actuarial death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1658, 20133, 20633, False]], 'method': 'actuarial'}, [730, 0]], ['actuarial late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'actuarial'}, [215, 1]], ['actuarial death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'actuarial'}, [230, 0]], ['actuarial death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'actuarial'}, [0, 0]], ['exact survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-2119, 19951, 20507, False], [-1690, 20001, 20675, False], [-1814, 19802, 20650, False]], 'method': 'exact'}, [876, 0]], ['actuarial survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-1893, 19900, 20703, False], [-2022, 19900, 20661, False], [-1898, 19900, 20856, False]], 'method': 'actuarial'}, [973, 0]], ['death on first observed day', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20150, 20150, True]], 'method': 'exact'}, [0, 1]], ['death near study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1270, 20000, 20727, True]], 'method': 'actuarial'}, [365, 1]]], [['exact mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-1825, 20155, 20608, False], [-1632, 20145, 20432, False], [-1827, 20020, 20829, False], [-2080, 19871, 20894, False], [-2071, 20138, 20394, True]], 'method': 'exact'}, [1055, 0]], ['exact death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1652, 20173, 20716, False]], 'method': 'exact'}, [730, 0]], ['exact late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'exact'}, [50, 1]], ['exact death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'exact'}, [230, 0]], ['exact death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'exact'}, [0, 0]], ['actuarial mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-2038, 19972, 20521, False], [-1836, 19923, 20435, False], [-2081, 20049, 20457, False], [-1816, 19815, 20798, False], [-1964, 19855, 20159, True]], 'method': 'actuarial'}, [1393, 1]], ['actuarial death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1744, 19944, 20873, False]], 'method': 'actuarial'}, [730, 0]], ['actuarial late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'actuarial'}, [215, 1]], ['actuarial death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'actuarial'}, [230, 0]], ['actuarial death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'actuarial'}, [0, 0]], ['exact survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-1879, 19856, 20519, False], [-1807, 19835, 20774, False], [-2006, 19972, 20562, False]], 'method': 'exact'}, [989, 0]], ['actuarial survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-1878, 19900, 20430, False], [-2072, 19900, 20760, False], [-1895, 19900, 20822, False]], 'method': 'actuarial'}, [923, 0]], ['death on first observed day', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20150, 20150, True]], 'method': 'exact'}, [0, 1]], ['death near study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1270, 20000, 20727, True]], 'method': 'actuarial'}, [365, 1]]]]
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:
Deaths near the end of the study get too little exposure.

Input study [s, e) days, age a, method exact|actuarial, records [[birth, entry, exit, died]] with 365-day years. Age band [birth+365a, +365). Observation [max(s,entry,band start), min(e,exit,band end)); a death at exit counts if lo<=exit<min(e, band end). Actuarial exposure extends a counted death to the band end. Return [total exposure days, deaths].

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):
    s,e=x['study']; a=x['age']; tot=0; deaths=0
    for b,en,ex,died in x['records']:
        bs=b+365*a; be=bs+365
        lo=max(s,bs); hi=min(e,ex,be)
        counted=died and lo<=ex<min(e,be)
        if counted: deaths+=1
        if x['method']=='actuarial' and counted: hi=be
        tot+=max(0,hi-lo)
    return [tot,deaths]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['exact mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-1646, 20187, 20406, False], [-1852, 20095, 20577, False], [-1617, 20154, 20514, False], [-1795, 19880, 20864, False], [-2031, 19846, 20364, True]], 'method': 'exact'}, [1300, 0]], ['exact death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1795, 20149, 20843, False]], 'method': 'exact'}, [686, 0]], ['exact late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'exact'}, [50, 1]], ['exact death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'exact'}, [230, 0]], ['exact death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'exact'}, [0, 0]], ['actuarial mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-1640, 19886, 20758, False], [-2010, 20199, 20626, False], [-2086, 19856, 20816, False], [-2011, 20172, 20892, False], [-1704, 19877, 20272, True]], 'method': 'actuarial'}, [1047, 1]], ['actuarial death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1976, 19813, 20729, False]], 'method': 'actuarial'}, [654, 0]], ['actuarial late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'actuarial'}, [215, 1]], ['actuarial death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'actuarial'}, [230, 0]], ['actuarial death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'actuarial'}, [0, 0]], ['exact survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-1717, 19878, 20681, False], [-1678, 20196, 20770, False], [-2186, 20016, 20415, False]], 'method': 'exact'}, [793, 0]], ['actuarial survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-2064, 19900, 20737, False], [-2068, 19900, 20448, False], [-2155, 19900, 20867, False]], 'method': 'actuarial'}, [508, 0]], ['death on first observed day', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20150, 20150, True]], 'method': 'exact'}, [0, 1]], ['death near study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1270, 20000, 20727, True]], 'method': 'actuarial'}, [365, 1]]], [['exact mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-2070, 19840, 20456, False], [-1999, 20154, 20680, False], [-2193, 19855, 20494, False], [-2156, 19996, 20689, False], [-1701, 20077, 20310, True]], 'method': 'exact'}, [599, 1]], ['exact death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1711, 19808, 20863, False]], 'method': 'exact'}, [730, 0]], ['exact late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'exact'}, [50, 1]], ['exact death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'exact'}, [230, 0]], ['exact death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'exact'}, [0, 0]], ['actuarial mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-1665, 19831, 20488, False], [-1673, 19955, 20442, False], [-1850, 20050, 20697, False], [-2078, 19804, 20804, False], [-1601, 20194, 20313, True]], 'method': 'actuarial'}, [1385, 1]], ['actuarial death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1605, 19948, 20570, False]], 'method': 'actuarial'}, [640, 0]], ['actuarial late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'actuarial'}, [215, 1]], ['actuarial death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'actuarial'}, [230, 0]], ['actuarial death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'actuarial'}, [0, 0]], ['exact survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-1889, 19936, 20521, False], [-1640, 20120, 20507, False], [-1778, 20160, 20852, False]], 'method': 'exact'}, [939, 0]], ['actuarial survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-1890, 19900, 20544, False], [-1719, 19900, 20802, False], [-2117, 19900, 20531, False]], 'method': 'actuarial'}, [878, 0]], ['death on first observed day', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20150, 20150, True]], 'method': 'exact'}, [0, 1]], ['death near study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1270, 20000, 20727, True]], 'method': 'actuarial'}, [365, 1]]], [['exact mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-1741, 20077, 20701, False], [-1769, 20197, 20455, False], [-2071, 19974, 20741, False], [-1918, 19823, 20436, False], [-2098, 20169, 20358, True]], 'method': 'exact'}, [1164, 0]], ['exact death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1954, 20112, 20568, False]], 'method': 'exact'}, [564, 0]], ['exact late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'exact'}, [50, 1]], ['exact death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'exact'}, [230, 0]], ['exact death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'exact'}, [0, 0]], ['actuarial mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-1887, 19974, 20561, False], [-2071, 20133, 20760, False], [-1820, 20134, 20483, False], [-1975, 20119, 20850, False], [-1795, 20071, 20207, True]], 'method': 'actuarial'}, [1273, 1]], ['actuarial death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-2147, 19920, 20609, False]], 'method': 'actuarial'}, [483, 0]], ['actuarial late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'actuarial'}, [215, 1]], ['actuarial death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'actuarial'}, [230, 0]], ['actuarial death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'actuarial'}, [0, 0]], ['exact survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-1894, 20110, 20820, False], [-1682, 19889, 20808, False], [-2155, 19896, 20593, False]], 'method': 'exact'}, [736, 0]], ['actuarial survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-2018, 19900, 20548, False], [-1644, 19900, 20877, False], [-2200, 19900, 20475, False]], 'method': 'actuarial'}, [677, 0]], ['death on first observed day', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20150, 20150, True]], 'method': 'exact'}, [0, 1]], ['death near study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1270, 20000, 20727, True]], 'method': 'actuarial'}, [365, 1]]], [['exact mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-1863, 20066, 20531, False], [-2075, 19963, 20495, False], [-1993, 19890, 20763, False], [-1827, 19962, 20674, False], [-2180, 20079, 20226, True]], 'method': 'exact'}, [1169, 0]], ['exact death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1679, 20195, 20683, False]], 'method': 'exact'}, [730, 0]], ['exact late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'exact'}, [50, 1]], ['exact death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'exact'}, [230, 0]], ['exact death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'exact'}, [0, 0]], ['actuarial mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-2025, 19978, 20453, False], [-2178, 19958, 20450, False], [-2000, 19923, 20448, False], [-2144, 19842, 20894, False], [-2062, 19838, 20339, True]], 'method': 'actuarial'}, [916, 0]], ['actuarial death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1658, 20133, 20633, False]], 'method': 'actuarial'}, [730, 0]], ['actuarial late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'actuarial'}, [215, 1]], ['actuarial death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'actuarial'}, [230, 0]], ['actuarial death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'actuarial'}, [0, 0]], ['exact survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-2119, 19951, 20507, False], [-1690, 20001, 20675, False], [-1814, 19802, 20650, False]], 'method': 'exact'}, [876, 0]], ['actuarial survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-1893, 19900, 20703, False], [-2022, 19900, 20661, False], [-1898, 19900, 20856, False]], 'method': 'actuarial'}, [973, 0]], ['death on first observed day', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20150, 20150, True]], 'method': 'exact'}, [0, 1]], ['death near study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1270, 20000, 20727, True]], 'method': 'actuarial'}, [365, 1]]], [['exact mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-1825, 20155, 20608, False], [-1632, 20145, 20432, False], [-1827, 20020, 20829, False], [-2080, 19871, 20894, False], [-2071, 20138, 20394, True]], 'method': 'exact'}, [1055, 0]], ['exact death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1652, 20173, 20716, False]], 'method': 'exact'}, [730, 0]], ['exact late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'exact'}, [50, 1]], ['exact death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'exact'}, [230, 0]], ['exact death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'exact'}, [0, 0]], ['actuarial mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-2038, 19972, 20521, False], [-1836, 19923, 20435, False], [-2081, 20049, 20457, False], [-1816, 19815, 20798, False], [-1964, 19855, 20159, True]], 'method': 'actuarial'}, [1393, 1]], ['actuarial death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1744, 19944, 20873, False]], 'method': 'actuarial'}, [730, 0]], ['actuarial late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'actuarial'}, [215, 1]], ['actuarial death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'actuarial'}, [230, 0]], ['actuarial death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'actuarial'}, [0, 0]], ['exact survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-1879, 19856, 20519, False], [-1807, 19835, 20774, False], [-2006, 19972, 20562, False]], 'method': 'exact'}, [989, 0]], ['actuarial survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-1878, 19900, 20430, False], [-2072, 19900, 20760, False], [-1895, 19900, 20822, False]], 'method': 'actuarial'}, [923, 0]], ['death on first observed day', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20150, 20150, True]], 'method': 'exact'}, [0, 1]], ['death near study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1270, 20000, 20727, True]], 'method': 'actuarial'}, [365, 1]]]]
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):
    s,e=x['study']; a=x['age']; tot=0; deaths=0
    for b,en,ex,died in x['records']:
        bs=b+365*a; be=bs+365
        lo=max(en,bs); hi=min(e,ex,be)
        counted=died and lo<=ex<min(e,be)
        if counted: deaths+=1
        if x['method']=='actuarial' and counted: hi=be
        tot+=max(0,hi-lo)
    return [tot,deaths]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['exact mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-1646, 20187, 20406, False], [-1852, 20095, 20577, False], [-1617, 20154, 20514, False], [-1795, 19880, 20864, False], [-2031, 19846, 20364, True]], 'method': 'exact'}, [1300, 0]], ['exact death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1795, 20149, 20843, False]], 'method': 'exact'}, [686, 0]], ['exact late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'exact'}, [50, 1]], ['exact death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'exact'}, [230, 0]], ['exact death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'exact'}, [0, 0]], ['actuarial mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-1640, 19886, 20758, False], [-2010, 20199, 20626, False], [-2086, 19856, 20816, False], [-2011, 20172, 20892, False], [-1704, 19877, 20272, True]], 'method': 'actuarial'}, [1047, 1]], ['actuarial death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1976, 19813, 20729, False]], 'method': 'actuarial'}, [654, 0]], ['actuarial late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'actuarial'}, [215, 1]], ['actuarial death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'actuarial'}, [230, 0]], ['actuarial death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'actuarial'}, [0, 0]], ['exact survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-1717, 19878, 20681, False], [-1678, 20196, 20770, False], [-2186, 20016, 20415, False]], 'method': 'exact'}, [793, 0]], ['actuarial survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-2064, 19900, 20737, False], [-2068, 19900, 20448, False], [-2155, 19900, 20867, False]], 'method': 'actuarial'}, [508, 0]], ['death on first observed day', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20150, 20150, True]], 'method': 'exact'}, [0, 1]], ['death near study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1270, 20000, 20727, True]], 'method': 'actuarial'}, [365, 1]]], [['exact mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-2070, 19840, 20456, False], [-1999, 20154, 20680, False], [-2193, 19855, 20494, False], [-2156, 19996, 20689, False], [-1701, 20077, 20310, True]], 'method': 'exact'}, [599, 1]], ['exact death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1711, 19808, 20863, False]], 'method': 'exact'}, [730, 0]], ['exact late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'exact'}, [50, 1]], ['exact death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'exact'}, [230, 0]], ['exact death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'exact'}, [0, 0]], ['actuarial mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-1665, 19831, 20488, False], [-1673, 19955, 20442, False], [-1850, 20050, 20697, False], [-2078, 19804, 20804, False], [-1601, 20194, 20313, True]], 'method': 'actuarial'}, [1385, 1]], ['actuarial death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1605, 19948, 20570, False]], 'method': 'actuarial'}, [640, 0]], ['actuarial late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'actuarial'}, [215, 1]], ['actuarial death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'actuarial'}, [230, 0]], ['actuarial death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'actuarial'}, [0, 0]], ['exact survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-1889, 19936, 20521, False], [-1640, 20120, 20507, False], [-1778, 20160, 20852, False]], 'method': 'exact'}, [939, 0]], ['actuarial survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-1890, 19900, 20544, False], [-1719, 19900, 20802, False], [-2117, 19900, 20531, False]], 'method': 'actuarial'}, [878, 0]], ['death on first observed day', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20150, 20150, True]], 'method': 'exact'}, [0, 1]], ['death near study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1270, 20000, 20727, True]], 'method': 'actuarial'}, [365, 1]]], [['exact mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-1741, 20077, 20701, False], [-1769, 20197, 20455, False], [-2071, 19974, 20741, False], [-1918, 19823, 20436, False], [-2098, 20169, 20358, True]], 'method': 'exact'}, [1164, 0]], ['exact death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1954, 20112, 20568, False]], 'method': 'exact'}, [564, 0]], ['exact late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'exact'}, [50, 1]], ['exact death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'exact'}, [230, 0]], ['exact death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'exact'}, [0, 0]], ['actuarial mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-1887, 19974, 20561, False], [-2071, 20133, 20760, False], [-1820, 20134, 20483, False], [-1975, 20119, 20850, False], [-1795, 20071, 20207, True]], 'method': 'actuarial'}, [1273, 1]], ['actuarial death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-2147, 19920, 20609, False]], 'method': 'actuarial'}, [483, 0]], ['actuarial late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'actuarial'}, [215, 1]], ['actuarial death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'actuarial'}, [230, 0]], ['actuarial death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'actuarial'}, [0, 0]], ['exact survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-1894, 20110, 20820, False], [-1682, 19889, 20808, False], [-2155, 19896, 20593, False]], 'method': 'exact'}, [736, 0]], ['actuarial survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-2018, 19900, 20548, False], [-1644, 19900, 20877, False], [-2200, 19900, 20475, False]], 'method': 'actuarial'}, [677, 0]], ['death on first observed day', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20150, 20150, True]], 'method': 'exact'}, [0, 1]], ['death near study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1270, 20000, 20727, True]], 'method': 'actuarial'}, [365, 1]]], [['exact mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-1863, 20066, 20531, False], [-2075, 19963, 20495, False], [-1993, 19890, 20763, False], [-1827, 19962, 20674, False], [-2180, 20079, 20226, True]], 'method': 'exact'}, [1169, 0]], ['exact death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1679, 20195, 20683, False]], 'method': 'exact'}, [730, 0]], ['exact late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'exact'}, [50, 1]], ['exact death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'exact'}, [230, 0]], ['exact death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'exact'}, [0, 0]], ['actuarial mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-2025, 19978, 20453, False], [-2178, 19958, 20450, False], [-2000, 19923, 20448, False], [-2144, 19842, 20894, False], [-2062, 19838, 20339, True]], 'method': 'actuarial'}, [916, 0]], ['actuarial death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1658, 20133, 20633, False]], 'method': 'actuarial'}, [730, 0]], ['actuarial late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'actuarial'}, [215, 1]], ['actuarial death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'actuarial'}, [230, 0]], ['actuarial death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'actuarial'}, [0, 0]], ['exact survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-2119, 19951, 20507, False], [-1690, 20001, 20675, False], [-1814, 19802, 20650, False]], 'method': 'exact'}, [876, 0]], ['actuarial survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-1893, 19900, 20703, False], [-2022, 19900, 20661, False], [-1898, 19900, 20856, False]], 'method': 'actuarial'}, [973, 0]], ['death on first observed day', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20150, 20150, True]], 'method': 'exact'}, [0, 1]], ['death near study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1270, 20000, 20727, True]], 'method': 'actuarial'}, [365, 1]]], [['exact mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-1825, 20155, 20608, False], [-1632, 20145, 20432, False], [-1827, 20020, 20829, False], [-2080, 19871, 20894, False], [-2071, 20138, 20394, True]], 'method': 'exact'}, [1055, 0]], ['exact death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1652, 20173, 20716, False]], 'method': 'exact'}, [730, 0]], ['exact late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'exact'}, [50, 1]], ['exact death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'exact'}, [230, 0]], ['exact death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'exact'}, [0, 0]], ['actuarial mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-2038, 19972, 20521, False], [-1836, 19923, 20435, False], [-2081, 20049, 20457, False], [-1816, 19815, 20798, False], [-1964, 19855, 20159, True]], 'method': 'actuarial'}, [1393, 1]], ['actuarial death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1744, 19944, 20873, False]], 'method': 'actuarial'}, [730, 0]], ['actuarial late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'actuarial'}, [215, 1]], ['actuarial death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'actuarial'}, [230, 0]], ['actuarial death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'actuarial'}, [0, 0]], ['exact survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-1879, 19856, 20519, False], [-1807, 19835, 20774, False], [-2006, 19972, 20562, False]], 'method': 'exact'}, [989, 0]], ['actuarial survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-1878, 19900, 20430, False], [-2072, 19900, 20760, False], [-1895, 19900, 20822, False]], 'method': 'actuarial'}, [923, 0]], ['death on first observed day', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20150, 20150, True]], 'method': 'exact'}, [0, 1]], ['death near study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1270, 20000, 20727, True]], 'method': 'actuarial'}, [365, 1]]]]
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:
Exposure includes time before entry.

Input study [s, e) days, age a, method exact|actuarial, records [[birth, entry, exit, died]] with 365-day years. Age band [birth+365a, +365). Observation [max(s,entry,band start), min(e,exit,band end)); a death at exit counts if lo<=exit<min(e, band end). Actuarial exposure extends a counted death to the band end. Return [total exposure days, deaths].

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):
    s,e=x['study']; a=x['age']; tot=0; deaths=0
    for b,en,ex,died in x['records']:
        bs=b+365*a; be=bs+365
        lo=max(s,en,bs); hi=min(e,ex,be)
        counted=died and ex<min(e,be)
        if counted: deaths+=1
        if x['method']=='actuarial' and counted: hi=be
        tot+=max(0,hi-lo)
    return [tot,deaths]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['exact mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-1646, 20187, 20406, False], [-1852, 20095, 20577, False], [-1617, 20154, 20514, False], [-1795, 19880, 20864, False], [-2031, 19846, 20364, True]], 'method': 'exact'}, [1300, 0]], ['exact death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1795, 20149, 20843, False]], 'method': 'exact'}, [686, 0]], ['exact late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'exact'}, [50, 1]], ['exact death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'exact'}, [230, 0]], ['exact death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'exact'}, [0, 0]], ['actuarial mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-1640, 19886, 20758, False], [-2010, 20199, 20626, False], [-2086, 19856, 20816, False], [-2011, 20172, 20892, False], [-1704, 19877, 20272, True]], 'method': 'actuarial'}, [1047, 1]], ['actuarial death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1976, 19813, 20729, False]], 'method': 'actuarial'}, [654, 0]], ['actuarial late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'actuarial'}, [215, 1]], ['actuarial death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'actuarial'}, [230, 0]], ['actuarial death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'actuarial'}, [0, 0]], ['exact survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-1717, 19878, 20681, False], [-1678, 20196, 20770, False], [-2186, 20016, 20415, False]], 'method': 'exact'}, [793, 0]], ['actuarial survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-2064, 19900, 20737, False], [-2068, 19900, 20448, False], [-2155, 19900, 20867, False]], 'method': 'actuarial'}, [508, 0]], ['death on first observed day', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20150, 20150, True]], 'method': 'exact'}, [0, 1]], ['death near study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1270, 20000, 20727, True]], 'method': 'actuarial'}, [365, 1]]], [['exact mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-2070, 19840, 20456, False], [-1999, 20154, 20680, False], [-2193, 19855, 20494, False], [-2156, 19996, 20689, False], [-1701, 20077, 20310, True]], 'method': 'exact'}, [599, 1]], ['exact death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1711, 19808, 20863, False]], 'method': 'exact'}, [730, 0]], ['exact late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'exact'}, [50, 1]], ['exact death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'exact'}, [230, 0]], ['exact death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'exact'}, [0, 0]], ['actuarial mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-1665, 19831, 20488, False], [-1673, 19955, 20442, False], [-1850, 20050, 20697, False], [-2078, 19804, 20804, False], [-1601, 20194, 20313, True]], 'method': 'actuarial'}, [1385, 1]], ['actuarial death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1605, 19948, 20570, False]], 'method': 'actuarial'}, [640, 0]], ['actuarial late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'actuarial'}, [215, 1]], ['actuarial death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'actuarial'}, [230, 0]], ['actuarial death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'actuarial'}, [0, 0]], ['exact survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-1889, 19936, 20521, False], [-1640, 20120, 20507, False], [-1778, 20160, 20852, False]], 'method': 'exact'}, [939, 0]], ['actuarial survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-1890, 19900, 20544, False], [-1719, 19900, 20802, False], [-2117, 19900, 20531, False]], 'method': 'actuarial'}, [878, 0]], ['death on first observed day', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20150, 20150, True]], 'method': 'exact'}, [0, 1]], ['death near study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1270, 20000, 20727, True]], 'method': 'actuarial'}, [365, 1]]], [['exact mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-1741, 20077, 20701, False], [-1769, 20197, 20455, False], [-2071, 19974, 20741, False], [-1918, 19823, 20436, False], [-2098, 20169, 20358, True]], 'method': 'exact'}, [1164, 0]], ['exact death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1954, 20112, 20568, False]], 'method': 'exact'}, [564, 0]], ['exact late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'exact'}, [50, 1]], ['exact death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'exact'}, [230, 0]], ['exact death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'exact'}, [0, 0]], ['actuarial mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-1887, 19974, 20561, False], [-2071, 20133, 20760, False], [-1820, 20134, 20483, False], [-1975, 20119, 20850, False], [-1795, 20071, 20207, True]], 'method': 'actuarial'}, [1273, 1]], ['actuarial death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-2147, 19920, 20609, False]], 'method': 'actuarial'}, [483, 0]], ['actuarial late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'actuarial'}, [215, 1]], ['actuarial death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'actuarial'}, [230, 0]], ['actuarial death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'actuarial'}, [0, 0]], ['exact survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-1894, 20110, 20820, False], [-1682, 19889, 20808, False], [-2155, 19896, 20593, False]], 'method': 'exact'}, [736, 0]], ['actuarial survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-2018, 19900, 20548, False], [-1644, 19900, 20877, False], [-2200, 19900, 20475, False]], 'method': 'actuarial'}, [677, 0]], ['death on first observed day', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20150, 20150, True]], 'method': 'exact'}, [0, 1]], ['death near study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1270, 20000, 20727, True]], 'method': 'actuarial'}, [365, 1]]], [['exact mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-1863, 20066, 20531, False], [-2075, 19963, 20495, False], [-1993, 19890, 20763, False], [-1827, 19962, 20674, False], [-2180, 20079, 20226, True]], 'method': 'exact'}, [1169, 0]], ['exact death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1679, 20195, 20683, False]], 'method': 'exact'}, [730, 0]], ['exact late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'exact'}, [50, 1]], ['exact death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'exact'}, [230, 0]], ['exact death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'exact'}, [0, 0]], ['actuarial mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-2025, 19978, 20453, False], [-2178, 19958, 20450, False], [-2000, 19923, 20448, False], [-2144, 19842, 20894, False], [-2062, 19838, 20339, True]], 'method': 'actuarial'}, [916, 0]], ['actuarial death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1658, 20133, 20633, False]], 'method': 'actuarial'}, [730, 0]], ['actuarial late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'actuarial'}, [215, 1]], ['actuarial death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'actuarial'}, [230, 0]], ['actuarial death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'actuarial'}, [0, 0]], ['exact survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-2119, 19951, 20507, False], [-1690, 20001, 20675, False], [-1814, 19802, 20650, False]], 'method': 'exact'}, [876, 0]], ['actuarial survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-1893, 19900, 20703, False], [-2022, 19900, 20661, False], [-1898, 19900, 20856, False]], 'method': 'actuarial'}, [973, 0]], ['death on first observed day', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20150, 20150, True]], 'method': 'exact'}, [0, 1]], ['death near study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1270, 20000, 20727, True]], 'method': 'actuarial'}, [365, 1]]], [['exact mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-1825, 20155, 20608, False], [-1632, 20145, 20432, False], [-1827, 20020, 20829, False], [-2080, 19871, 20894, False], [-2071, 20138, 20394, True]], 'method': 'exact'}, [1055, 0]], ['exact death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1652, 20173, 20716, False]], 'method': 'exact'}, [730, 0]], ['exact late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'exact'}, [50, 1]], ['exact death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'exact'}, [230, 0]], ['exact death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'exact'}, [0, 0]], ['actuarial mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-2038, 19972, 20521, False], [-1836, 19923, 20435, False], [-2081, 20049, 20457, False], [-1816, 19815, 20798, False], [-1964, 19855, 20159, True]], 'method': 'actuarial'}, [1393, 1]], ['actuarial death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1744, 19944, 20873, False]], 'method': 'actuarial'}, [730, 0]], ['actuarial late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'actuarial'}, [215, 1]], ['actuarial death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'actuarial'}, [230, 0]], ['actuarial death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'actuarial'}, [0, 0]], ['exact survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-1879, 19856, 20519, False], [-1807, 19835, 20774, False], [-2006, 19972, 20562, False]], 'method': 'exact'}, [989, 0]], ['actuarial survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-1878, 19900, 20430, False], [-2072, 19900, 20760, False], [-1895, 19900, 20822, False]], 'method': 'actuarial'}, [923, 0]], ['death on first observed day', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20150, 20150, True]], 'method': 'exact'}, [0, 1]], ['death near study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1270, 20000, 20727, True]], 'method': 'actuarial'}, [365, 1]]]]
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):
    s,e=x['study']; a=x['age']; tot=0; deaths=0
    for b,en,ex,died in x['records']:
        bs=b+365*a; be=bs+365
        lo=max(s,en,bs); hi=min(e,ex,be)
        counted=died and bs<=ex<be
        if counted: deaths+=1
        if x['method']=='actuarial' and counted: hi=be
        tot+=max(0,hi-lo)
    return [tot,deaths]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['exact mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-1646, 20187, 20406, False], [-1852, 20095, 20577, False], [-1617, 20154, 20514, False], [-1795, 19880, 20864, False], [-2031, 19846, 20364, True]], 'method': 'exact'}, [1300, 0]], ['exact death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1795, 20149, 20843, False]], 'method': 'exact'}, [686, 0]], ['exact late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'exact'}, [50, 1]], ['exact death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'exact'}, [230, 0]], ['exact death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'exact'}, [0, 0]], ['actuarial mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-1640, 19886, 20758, False], [-2010, 20199, 20626, False], [-2086, 19856, 20816, False], [-2011, 20172, 20892, False], [-1704, 19877, 20272, True]], 'method': 'actuarial'}, [1047, 1]], ['actuarial death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1976, 19813, 20729, False]], 'method': 'actuarial'}, [654, 0]], ['actuarial late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'actuarial'}, [215, 1]], ['actuarial death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'actuarial'}, [230, 0]], ['actuarial death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'actuarial'}, [0, 0]], ['exact survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-1717, 19878, 20681, False], [-1678, 20196, 20770, False], [-2186, 20016, 20415, False]], 'method': 'exact'}, [793, 0]], ['actuarial survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-2064, 19900, 20737, False], [-2068, 19900, 20448, False], [-2155, 19900, 20867, False]], 'method': 'actuarial'}, [508, 0]], ['death on first observed day', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20150, 20150, True]], 'method': 'exact'}, [0, 1]], ['death near study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1270, 20000, 20727, True]], 'method': 'actuarial'}, [365, 1]]], [['exact mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-2070, 19840, 20456, False], [-1999, 20154, 20680, False], [-2193, 19855, 20494, False], [-2156, 19996, 20689, False], [-1701, 20077, 20310, True]], 'method': 'exact'}, [599, 1]], ['exact death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1711, 19808, 20863, False]], 'method': 'exact'}, [730, 0]], ['exact late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'exact'}, [50, 1]], ['exact death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'exact'}, [230, 0]], ['exact death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'exact'}, [0, 0]], ['actuarial mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-1665, 19831, 20488, False], [-1673, 19955, 20442, False], [-1850, 20050, 20697, False], [-2078, 19804, 20804, False], [-1601, 20194, 20313, True]], 'method': 'actuarial'}, [1385, 1]], ['actuarial death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1605, 19948, 20570, False]], 'method': 'actuarial'}, [640, 0]], ['actuarial late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'actuarial'}, [215, 1]], ['actuarial death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'actuarial'}, [230, 0]], ['actuarial death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'actuarial'}, [0, 0]], ['exact survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-1889, 19936, 20521, False], [-1640, 20120, 20507, False], [-1778, 20160, 20852, False]], 'method': 'exact'}, [939, 0]], ['actuarial survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-1890, 19900, 20544, False], [-1719, 19900, 20802, False], [-2117, 19900, 20531, False]], 'method': 'actuarial'}, [878, 0]], ['death on first observed day', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20150, 20150, True]], 'method': 'exact'}, [0, 1]], ['death near study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1270, 20000, 20727, True]], 'method': 'actuarial'}, [365, 1]]], [['exact mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-1741, 20077, 20701, False], [-1769, 20197, 20455, False], [-2071, 19974, 20741, False], [-1918, 19823, 20436, False], [-2098, 20169, 20358, True]], 'method': 'exact'}, [1164, 0]], ['exact death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1954, 20112, 20568, False]], 'method': 'exact'}, [564, 0]], ['exact late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'exact'}, [50, 1]], ['exact death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'exact'}, [230, 0]], ['exact death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'exact'}, [0, 0]], ['actuarial mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-1887, 19974, 20561, False], [-2071, 20133, 20760, False], [-1820, 20134, 20483, False], [-1975, 20119, 20850, False], [-1795, 20071, 20207, True]], 'method': 'actuarial'}, [1273, 1]], ['actuarial death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-2147, 19920, 20609, False]], 'method': 'actuarial'}, [483, 0]], ['actuarial late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'actuarial'}, [215, 1]], ['actuarial death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'actuarial'}, [230, 0]], ['actuarial death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'actuarial'}, [0, 0]], ['exact survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-1894, 20110, 20820, False], [-1682, 19889, 20808, False], [-2155, 19896, 20593, False]], 'method': 'exact'}, [736, 0]], ['actuarial survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-2018, 19900, 20548, False], [-1644, 19900, 20877, False], [-2200, 19900, 20475, False]], 'method': 'actuarial'}, [677, 0]], ['death on first observed day', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20150, 20150, True]], 'method': 'exact'}, [0, 1]], ['death near study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1270, 20000, 20727, True]], 'method': 'actuarial'}, [365, 1]]], [['exact mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-1863, 20066, 20531, False], [-2075, 19963, 20495, False], [-1993, 19890, 20763, False], [-1827, 19962, 20674, False], [-2180, 20079, 20226, True]], 'method': 'exact'}, [1169, 0]], ['exact death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1679, 20195, 20683, False]], 'method': 'exact'}, [730, 0]], ['exact late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'exact'}, [50, 1]], ['exact death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'exact'}, [230, 0]], ['exact death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'exact'}, [0, 0]], ['actuarial mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-2025, 19978, 20453, False], [-2178, 19958, 20450, False], [-2000, 19923, 20448, False], [-2144, 19842, 20894, False], [-2062, 19838, 20339, True]], 'method': 'actuarial'}, [916, 0]], ['actuarial death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1658, 20133, 20633, False]], 'method': 'actuarial'}, [730, 0]], ['actuarial late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'actuarial'}, [215, 1]], ['actuarial death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'actuarial'}, [230, 0]], ['actuarial death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'actuarial'}, [0, 0]], ['exact survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-2119, 19951, 20507, False], [-1690, 20001, 20675, False], [-1814, 19802, 20650, False]], 'method': 'exact'}, [876, 0]], ['actuarial survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-1893, 19900, 20703, False], [-2022, 19900, 20661, False], [-1898, 19900, 20856, False]], 'method': 'actuarial'}, [973, 0]], ['death on first observed day', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20150, 20150, True]], 'method': 'exact'}, [0, 1]], ['death near study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1270, 20000, 20727, True]], 'method': 'actuarial'}, [365, 1]]], [['exact mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-1825, 20155, 20608, False], [-1632, 20145, 20432, False], [-1827, 20020, 20829, False], [-2080, 19871, 20894, False], [-2071, 20138, 20394, True]], 'method': 'exact'}, [1055, 0]], ['exact death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1652, 20173, 20716, False]], 'method': 'exact'}, [730, 0]], ['exact late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'exact'}, [50, 1]], ['exact death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'exact'}, [230, 0]], ['exact death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'exact'}, [0, 0]], ['actuarial mixed cohort', {'study': [20000, 20730], 'age': 60, 'records': [[-2038, 19972, 20521, False], [-1836, 19923, 20435, False], [-2081, 20049, 20457, False], [-1816, 19815, 20798, False], [-1964, 19855, 20159, True]], 'method': 'actuarial'}, [1393, 1]], ['actuarial death on next birthday', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20000, 20465, True], [-1744, 19944, 20873, False]], 'method': 'actuarial'}, [730, 0]], ['actuarial late entrant death', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20250, 20300, True]], 'method': 'actuarial'}, [215, 1]], ['actuarial death after study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1400, 20100, 20750, True]], 'method': 'actuarial'}, [230, 0]], ['actuarial death before age band', {'study': [20000, 20730], 'age': 60, 'records': [[-1600, 20000, 20200, True]], 'method': 'actuarial'}, [0, 0]], ['exact survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-1879, 19856, 20519, False], [-1807, 19835, 20774, False], [-2006, 19972, 20562, False]], 'method': 'exact'}, [989, 0]], ['actuarial survivors only', {'study': [20000, 20730], 'age': 60, 'records': [[-1878, 19900, 20430, False], [-2072, 19900, 20760, False], [-1895, 19900, 20822, False]], 'method': 'actuarial'}, [923, 0]], ['death on first observed day', {'study': [20000, 20730], 'age': 60, 'records': [[-1800, 20150, 20150, True]], 'method': 'exact'}, [0, 1]], ['death near study end', {'study': [20000, 20730], 'age': 60, 'records': [[-1270, 20000, 20727, True]], 'method': 'actuarial'}, [365, 1]]]]
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:
Deaths at younger ages inflate the age-band death count.

Input study [s, e) days, age a, method exact|actuarial, records [[birth, entry, exit, died]] with 365-day years. Age band [birth+365a, +365). Observation [max(s,entry,band start), min(e,exit,band end)); a death at exit counts if lo<=exit<min(e, band end). Actuarial exposure extends a counted death to the band end. Return [total exposure days, deaths].

split: open-access