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

N = 1
observations = []
def solve(x):
    cov = x['coverage']
    monthly = {'self': 35800, 'family': 71250}
    if cov[11] is not None:
        months = [cov[11]] * 12
    else:
        months = cov
    limit = sum(monthly[m] for m in months if m is not None)
    covered = sum(1 for m in months if m is not None)
    if x['age'] >= 55:
        limit += 100000 * covered // 12
    room = max(0, limit - x['employee_ytd'])
    allowed = min(x['request'], room)
    return [limit, allowed]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'coverage': ['self', 'self', 'family', 'family', 'family', None, 'self', 'family', None, None, 'family', None], 'age': 41, 'employer_ytd': 182987, 'employee_ytd': 284378, 'request': 281989}, [463650, 0]), ('regression', {'coverage': [None, None, None, None, None, None, 'self', None, None, None, None, None], 'age': 55, 'employer_ytd': 115762, 'employee_ytd': 24574, 'request': 286981}, [44133, 0]), ('partial-repair probe', {'coverage': [None, 'self', 'family', 'self', 'self', None, 'family', None, 'self', 'family', 'family', None], 'age': 40, 'employer_ytd': 225872, 'employee_ytd': 144016, 'request': 380678}, [428200, 58312]), ('partial-repair probe', {'coverage': ['self', None, 'self', 'family', 'family', None, None, None, None, 'family', None, 'self'], 'age': 48, 'employer_ytd': 141642, 'employee_ytd': 558877, 'request': 321776}, [429600, 0]), ('normal control', {'coverage': [None, None, None, None, None, None, None, 'family', 'family', 'family', 'family', 'family'], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 238336, 'request': 135874}, [955000, 135874]), ('normal control', {'coverage': [None, None, 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self'], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 456065, 'request': 36894}, [529600, 36894]), ('normal control', {'coverage': [None, 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family'], 'age': 40, 'employer_ytd': 0, 'employee_ytd': 74724, 'request': 118780}, [855000, 118780]), ('normal control', {'coverage': [None, 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family'], 'age': 40, 'employer_ytd': 0, 'employee_ytd': 164388, 'request': 96773}, [855000, 96773])], [('regression', {'coverage': [None, 'self', 'family', 'self', 'self', None, 'family', None, 'self', 'family', 'family', None], 'age': 40, 'employer_ytd': 225872, 'employee_ytd': 144016, 'request': 380678}, [428200, 58312]), ('regression', {'coverage': ['self', 'self', 'family', 'family', 'family', None, 'self', 'family', None, None, 'family', None], 'age': 41, 'employer_ytd': 182987, 'employee_ytd': 284378, 'request': 281989}, [463650, 0]), ('partial-repair probe', {'coverage': ['self', None, 'self', 'family', 'family', None, None, None, None, 'family', None, 'self'], 'age': 48, 'employer_ytd': 141642, 'employee_ytd': 558877, 'request': 321776}, [429600, 0]), ('partial-repair probe', {'coverage': ['family', 'family', 'family', None, 'self', 'self', None, 'family', 'family', 'family', None, 'self'], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 380378, 'request': 301438}, [529600, 149222]), ('normal control', {'coverage': [None, None, None, None, None, None, None, 'family', 'family', 'family', 'family', 'family'], 'age': 56, 'employer_ytd': 0, 'employee_ytd': 506616, 'request': 122643}, [955000, 122643]), ('normal control', {'coverage': [None, 'family', None, None, None, None, 'family', None, 'self', 'self', None, 'family'], 'age': 36, 'employer_ytd': 0, 'employee_ytd': 317677, 'request': 360183}, [855000, 360183]), ('normal control', {'coverage': [None, None, None, None, None, None, None, None, None, None, None, 'family'], 'age': 56, 'employer_ytd': 72944, 'employee_ytd': 287033, 'request': 147965}, [955000, 147965]), ('normal control', {'coverage': ['self', 'family', None, None, 'family', 'family', 'family', 'family', None, None, 'self', 'family'], 'age': 56, 'employer_ytd': 0, 'employee_ytd': 12981, 'request': 364571}, [955000, 364571])], [('regression', {'coverage': [None, None, None, None, None, None, None, 'self', 'self', 'self', 'self', 'self'], 'age': 25, 'employer_ytd': 28613, 'employee_ytd': 65322, 'request': 390696}, [429600, 335665]), ('regression', {'coverage': [None, 'self', 'family', 'self', 'self', None, 'family', None, 'self', 'family', 'family', None], 'age': 40, 'employer_ytd': 225872, 'employee_ytd': 144016, 'request': 380678}, [428200, 58312]), ('partial-repair probe', {'coverage': [None, 'family', None, None, 'family', 'self', 'family', 'self', None, 'self', None, None], 'age': 40, 'employer_ytd': 0, 'employee_ytd': 423473, 'request': 127772}, [321150, 0]), ('partial-repair probe', {'coverage': ['self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self'], 'age': 54, 'employer_ytd': 0, 'employee_ytd': 551908, 'request': 166115}, [429600, 0]), ('normal control', {'coverage': [None, None, None, None, None, None, 'family', 'family', 'family', 'family', 'family', 'family'], 'age': 55, 'employer_ytd': 102233, 'employee_ytd': 513881, 'request': 171346}, [955000, 171346]), ('normal control', {'coverage': [None, None, None, None, None, None, None, None, 'family', 'family', 'family', 'family'], 'age': 30, 'employer_ytd': 0, 'employee_ytd': 594908, 'request': 135782}, [855000, 135782]), ('normal control', {'coverage': ['family', 'self', None, 'self', None, 'self', 'family', 'family', 'self', 'family', None, 'family'], 'age': 65, 'employer_ytd': 119262, 'employee_ytd': 404161, 'request': 137517}, [955000, 137517]), ('normal control', {'coverage': ['self', None, None, None, None, 'family', None, None, None, 'self', None, 'family'], 'age': 35, 'employer_ytd': 0, 'employee_ytd': 316436, 'request': 299379}, [855000, 299379])], [('regression', {'coverage': ['family', None, 'self', 'family', 'family', 'self', 'self', 'self', 'self', 'self', 'family', 'self'], 'age': 40, 'employer_ytd': 209919, 'employee_ytd': 194888, 'request': 252834}, [429600, 24793]), ('regression', {'coverage': [None, None, None, None, None, None, None, 'family', 'family', None, None, None], 'age': 37, 'employer_ytd': 208148, 'employee_ytd': 1425, 'request': 155636}, [142500, 0]), ('partial-repair probe', {'coverage': ['self', 'self', 'self', None, 'family', 'self', None, None, 'self', None, 'family', None], 'age': 55, 'employer_ytd': 286268, 'employee_ytd': 434159, 'request': 197484}, [379833, 0]), ('partial-repair probe', {'coverage': [None, None, None, None, None, None, None, None, None, 'self', 'self', None], 'age': 40, 'employer_ytd': 0, 'employee_ytd': 243944, 'request': 352402}, [71600, 0]), ('normal control', {'coverage': [None, None, None, None, None, None, None, None, 'family', 'family', 'family', 'family'], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 112368, 'request': 180107}, [955000, 180107]), ('normal control', {'coverage': [None, None, None, None, None, None, 'family', 'family', 'family', 'family', 'family', 'family'], 'age': 44, 'employer_ytd': 0, 'employee_ytd': 292931, 'request': 211494}, [855000, 211494]), ('normal control', {'coverage': [None, None, None, None, None, None, 'family', 'family', 'family', 'family', 'family', 'family'], 'age': 40, 'employer_ytd': 0, 'employee_ytd': 141822, 'request': 189175}, [855000, 189175]), ('normal control', {'coverage': [None, None, None, None, None, None, 'family', 'family', 'family', 'family', 'family', 'family'], 'age': 56, 'employer_ytd': 256678, 'employee_ytd': 281811, 'request': 361142}, [955000, 361142])], [('regression', {'coverage': [None, 'self', 'family', 'family', None, 'family', 'self', 'family', 'family', 'self', None, 'self'], 'age': 54, 'employer_ytd': 250670, 'employee_ytd': 128042, 'request': 333278}, [429600, 50888]), ('regression', {'coverage': [None, None, None, None, None, None, None, 'self', 'self', 'self', 'self', 'self'], 'age': 25, 'employer_ytd': 28613, 'employee_ytd': 65322, 'request': 390696}, [429600, 335665]), ('partial-repair probe', {'coverage': [None, None, None, None, None, None, None, None, None, None, None, 'self'], 'age': 56, 'employer_ytd': 0, 'employee_ytd': 524863, 'request': 386331}, [529600, 4737]), ('partial-repair probe', {'coverage': [None, None, 'self', 'self', 'family', None, 'family', None, None, 'family', None, None], 'age': 56, 'employer_ytd': 180971, 'employee_ytd': 345821, 'request': 207004}, [327016, 0]), ('normal control', {'coverage': [None, None, None, None, None, None, None, None, None, None, 'family', 'family'], 'age': 56, 'employer_ytd': 104769, 'employee_ytd': 270158, 'request': 236626}, [955000, 236626]), ('normal control', {'coverage': [None, 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self'], 'age': 56, 'employer_ytd': 0, 'employee_ytd': 81281, 'request': 140013}, [529600, 140013]), ('normal control', {'coverage': [None, None, None, None, None, None, None, None, None, None, None, 'family'], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 57407, 'request': 185458}, [955000, 185458]), ('normal control', {'coverage': [None, None, None, None, 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family'], 'age': 30, 'employer_ytd': 173842, 'employee_ytd': 330283, 'request': 54863}, [855000, 54863])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    cov = x['coverage']
    monthly = {'self': 35800, 'family': 71250}
    if cov[11] is not None:
        months = [cov[11]] * 12
    else:
        months = cov
    limit = sum(monthly[m] for m in months if m is not None)
    covered = sum(1 for m in months if m is not None)
    if x['age'] >= 55:
        limit += 100000 * covered // 12
    room = max(0, limit - x['employer_ytd'])
    allowed = min(x['request'], room)
    return [limit, allowed]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'coverage': ['self', 'self', 'family', 'family', 'family', None, 'self', 'family', None, None, 'family', None], 'age': 41, 'employer_ytd': 182987, 'employee_ytd': 284378, 'request': 281989}, [463650, 0]), ('regression', {'coverage': [None, None, None, None, None, None, 'self', None, None, None, None, None], 'age': 55, 'employer_ytd': 115762, 'employee_ytd': 24574, 'request': 286981}, [44133, 0]), ('partial-repair probe', {'coverage': [None, 'self', 'family', 'self', 'self', None, 'family', None, 'self', 'family', 'family', None], 'age': 40, 'employer_ytd': 225872, 'employee_ytd': 144016, 'request': 380678}, [428200, 58312]), ('partial-repair probe', {'coverage': ['self', None, 'self', 'family', 'family', None, None, None, None, 'family', None, 'self'], 'age': 48, 'employer_ytd': 141642, 'employee_ytd': 558877, 'request': 321776}, [429600, 0]), ('normal control', {'coverage': [None, None, None, None, None, None, None, 'family', 'family', 'family', 'family', 'family'], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 238336, 'request': 135874}, [955000, 135874]), ('normal control', {'coverage': [None, None, 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self'], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 456065, 'request': 36894}, [529600, 36894]), ('normal control', {'coverage': [None, 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family'], 'age': 40, 'employer_ytd': 0, 'employee_ytd': 74724, 'request': 118780}, [855000, 118780]), ('normal control', {'coverage': [None, 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family'], 'age': 40, 'employer_ytd': 0, 'employee_ytd': 164388, 'request': 96773}, [855000, 96773])], [('regression', {'coverage': [None, 'self', 'family', 'self', 'self', None, 'family', None, 'self', 'family', 'family', None], 'age': 40, 'employer_ytd': 225872, 'employee_ytd': 144016, 'request': 380678}, [428200, 58312]), ('regression', {'coverage': ['self', 'self', 'family', 'family', 'family', None, 'self', 'family', None, None, 'family', None], 'age': 41, 'employer_ytd': 182987, 'employee_ytd': 284378, 'request': 281989}, [463650, 0]), ('partial-repair probe', {'coverage': ['self', None, 'self', 'family', 'family', None, None, None, None, 'family', None, 'self'], 'age': 48, 'employer_ytd': 141642, 'employee_ytd': 558877, 'request': 321776}, [429600, 0]), ('partial-repair probe', {'coverage': ['family', 'family', 'family', None, 'self', 'self', None, 'family', 'family', 'family', None, 'self'], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 380378, 'request': 301438}, [529600, 149222]), ('normal control', {'coverage': [None, None, None, None, None, None, None, 'family', 'family', 'family', 'family', 'family'], 'age': 56, 'employer_ytd': 0, 'employee_ytd': 506616, 'request': 122643}, [955000, 122643]), ('normal control', {'coverage': [None, 'family', None, None, None, None, 'family', None, 'self', 'self', None, 'family'], 'age': 36, 'employer_ytd': 0, 'employee_ytd': 317677, 'request': 360183}, [855000, 360183]), ('normal control', {'coverage': [None, None, None, None, None, None, None, None, None, None, None, 'family'], 'age': 56, 'employer_ytd': 72944, 'employee_ytd': 287033, 'request': 147965}, [955000, 147965]), ('normal control', {'coverage': ['self', 'family', None, None, 'family', 'family', 'family', 'family', None, None, 'self', 'family'], 'age': 56, 'employer_ytd': 0, 'employee_ytd': 12981, 'request': 364571}, [955000, 364571])], [('regression', {'coverage': [None, None, None, None, None, None, None, 'self', 'self', 'self', 'self', 'self'], 'age': 25, 'employer_ytd': 28613, 'employee_ytd': 65322, 'request': 390696}, [429600, 335665]), ('regression', {'coverage': [None, 'self', 'family', 'self', 'self', None, 'family', None, 'self', 'family', 'family', None], 'age': 40, 'employer_ytd': 225872, 'employee_ytd': 144016, 'request': 380678}, [428200, 58312]), ('partial-repair probe', {'coverage': [None, 'family', None, None, 'family', 'self', 'family', 'self', None, 'self', None, None], 'age': 40, 'employer_ytd': 0, 'employee_ytd': 423473, 'request': 127772}, [321150, 0]), ('partial-repair probe', {'coverage': ['self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self'], 'age': 54, 'employer_ytd': 0, 'employee_ytd': 551908, 'request': 166115}, [429600, 0]), ('normal control', {'coverage': [None, None, None, None, None, None, 'family', 'family', 'family', 'family', 'family', 'family'], 'age': 55, 'employer_ytd': 102233, 'employee_ytd': 513881, 'request': 171346}, [955000, 171346]), ('normal control', {'coverage': [None, None, None, None, None, None, None, None, 'family', 'family', 'family', 'family'], 'age': 30, 'employer_ytd': 0, 'employee_ytd': 594908, 'request': 135782}, [855000, 135782]), ('normal control', {'coverage': ['family', 'self', None, 'self', None, 'self', 'family', 'family', 'self', 'family', None, 'family'], 'age': 65, 'employer_ytd': 119262, 'employee_ytd': 404161, 'request': 137517}, [955000, 137517]), ('normal control', {'coverage': ['self', None, None, None, None, 'family', None, None, None, 'self', None, 'family'], 'age': 35, 'employer_ytd': 0, 'employee_ytd': 316436, 'request': 299379}, [855000, 299379])], [('regression', {'coverage': ['family', None, 'self', 'family', 'family', 'self', 'self', 'self', 'self', 'self', 'family', 'self'], 'age': 40, 'employer_ytd': 209919, 'employee_ytd': 194888, 'request': 252834}, [429600, 24793]), ('regression', {'coverage': [None, None, None, None, None, None, None, 'family', 'family', None, None, None], 'age': 37, 'employer_ytd': 208148, 'employee_ytd': 1425, 'request': 155636}, [142500, 0]), ('partial-repair probe', {'coverage': ['self', 'self', 'self', None, 'family', 'self', None, None, 'self', None, 'family', None], 'age': 55, 'employer_ytd': 286268, 'employee_ytd': 434159, 'request': 197484}, [379833, 0]), ('partial-repair probe', {'coverage': [None, None, None, None, None, None, None, None, None, 'self', 'self', None], 'age': 40, 'employer_ytd': 0, 'employee_ytd': 243944, 'request': 352402}, [71600, 0]), ('normal control', {'coverage': [None, None, None, None, None, None, None, None, 'family', 'family', 'family', 'family'], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 112368, 'request': 180107}, [955000, 180107]), ('normal control', {'coverage': [None, None, None, None, None, None, 'family', 'family', 'family', 'family', 'family', 'family'], 'age': 44, 'employer_ytd': 0, 'employee_ytd': 292931, 'request': 211494}, [855000, 211494]), ('normal control', {'coverage': [None, None, None, None, None, None, 'family', 'family', 'family', 'family', 'family', 'family'], 'age': 40, 'employer_ytd': 0, 'employee_ytd': 141822, 'request': 189175}, [855000, 189175]), ('normal control', {'coverage': [None, None, None, None, None, None, 'family', 'family', 'family', 'family', 'family', 'family'], 'age': 56, 'employer_ytd': 256678, 'employee_ytd': 281811, 'request': 361142}, [955000, 361142])], [('regression', {'coverage': [None, 'self', 'family', 'family', None, 'family', 'self', 'family', 'family', 'self', None, 'self'], 'age': 54, 'employer_ytd': 250670, 'employee_ytd': 128042, 'request': 333278}, [429600, 50888]), ('regression', {'coverage': [None, None, None, None, None, None, None, 'self', 'self', 'self', 'self', 'self'], 'age': 25, 'employer_ytd': 28613, 'employee_ytd': 65322, 'request': 390696}, [429600, 335665]), ('partial-repair probe', {'coverage': [None, None, None, None, None, None, None, None, None, None, None, 'self'], 'age': 56, 'employer_ytd': 0, 'employee_ytd': 524863, 'request': 386331}, [529600, 4737]), ('partial-repair probe', {'coverage': [None, None, 'self', 'self', 'family', None, 'family', None, None, 'family', None, None], 'age': 56, 'employer_ytd': 180971, 'employee_ytd': 345821, 'request': 207004}, [327016, 0]), ('normal control', {'coverage': [None, None, None, None, None, None, None, None, None, None, 'family', 'family'], 'age': 56, 'employer_ytd': 104769, 'employee_ytd': 270158, 'request': 236626}, [955000, 236626]), ('normal control', {'coverage': [None, 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self'], 'age': 56, 'employer_ytd': 0, 'employee_ytd': 81281, 'request': 140013}, [529600, 140013]), ('normal control', {'coverage': [None, None, None, None, None, None, None, None, None, None, None, 'family'], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 57407, 'request': 185458}, [955000, 185458]), ('normal control', {'coverage': [None, None, None, None, 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family'], 'age': 30, 'employer_ytd': 173842, 'employee_ytd': 330283, 'request': 54863}, [855000, 54863])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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:
Employees whose employer also funds the HSA are allowed to exceed the combined limit.

Input {coverage: 12 monthly entries None|self|family, age, employer_ytd, employee_ytd, request}. If December is covered, every month is treated as having December's tier (last-month rule). Limit = sum of monthly limits (self 358.00, family 712.50). Age 55+ adds 1,000.00 * covered months // 12. Allowed payroll contribution = min(request, max(0, limit - employer_ytd - employee_ytd)). Return [limit, allowed].

split: open-access


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

N = 1
observations = []
def solve(x):
    cov = x['coverage']
    monthly = {'self': 35800, 'family': 71250}
    if cov[11] is not None:
        months = [cov[11]] * 12
    else:
        months = cov
    limit = sum(monthly[m] for m in months if m is not None)
    covered = sum(1 for m in months if m is not None)
    if x['age'] >= 55:
        limit += 100000
    room = max(0, limit - x['employer_ytd'] - x['employee_ytd'])
    allowed = min(x['request'], room)
    return [limit, allowed]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'coverage': [None, None, None, None, None, None, 'self', None, None, None, None, None], 'age': 55, 'employer_ytd': 115762, 'employee_ytd': 24574, 'request': 286981}, [44133, 0]), ('regression', {'coverage': ['self', 'self', 'self', None, 'family', 'self', None, None, 'self', None, 'family', None], 'age': 55, 'employer_ytd': 286268, 'employee_ytd': 434159, 'request': 197484}, [379833, 0]), ('partial-repair probe', {'coverage': [None, None, 'self', 'self', 'family', None, 'family', None, None, 'family', None, None], 'age': 56, 'employer_ytd': 180971, 'employee_ytd': 345821, 'request': 207004}, [327016, 0]), ('partial-repair probe', {'coverage': [None, None, None, None, None, None, None, None, None, None, 'self', None], 'age': 55, 'employer_ytd': 129076, 'employee_ytd': 256621, 'request': 34707}, [44133, 0]), ('normal control', {'coverage': ['self', 'self', 'family', 'family', 'family', None, 'self', 'family', None, None, 'family', None], 'age': 41, 'employer_ytd': 182987, 'employee_ytd': 284378, 'request': 281989}, [463650, 0]), ('normal control', {'coverage': [None, None, None, None, None, None, None, 'family', 'family', 'family', 'family', 'family'], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 238336, 'request': 135874}, [955000, 135874]), ('normal control', {'coverage': [None, None, 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self'], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 456065, 'request': 36894}, [529600, 36894]), ('normal control', {'coverage': [None, 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family'], 'age': 40, 'employer_ytd': 0, 'employee_ytd': 74724, 'request': 118780}, [855000, 118780])], [('regression', {'coverage': ['self', 'self', 'self', None, 'family', 'self', None, None, 'self', None, 'family', None], 'age': 55, 'employer_ytd': 286268, 'employee_ytd': 434159, 'request': 197484}, [379833, 0]), ('regression', {'coverage': [None, None, 'self', 'self', 'family', None, 'family', None, None, 'family', None, None], 'age': 56, 'employer_ytd': 180971, 'employee_ytd': 345821, 'request': 207004}, [327016, 0]), ('partial-repair probe', {'coverage': [None, None, None, None, None, None, None, None, None, None, 'self', None], 'age': 55, 'employer_ytd': 129076, 'employee_ytd': 256621, 'request': 34707}, [44133, 0]), ('partial-repair probe', {'coverage': [None, None, 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', None], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 227366, 'request': 100757}, [397200, 100757]), ('normal control', {'coverage': [None, 'self', 'family', 'self', 'self', None, 'family', None, 'self', 'family', 'family', None], 'age': 40, 'employer_ytd': 225872, 'employee_ytd': 144016, 'request': 380678}, [428200, 58312]), ('normal control', {'coverage': [None, None, None, None, None, None, None, 'family', 'family', None, None, None], 'age': 37, 'employer_ytd': 208148, 'employee_ytd': 1425, 'request': 155636}, [142500, 0]), ('normal control', {'coverage': ['self', None, 'self', 'family', 'family', None, None, None, None, 'family', None, 'self'], 'age': 48, 'employer_ytd': 141642, 'employee_ytd': 558877, 'request': 321776}, [429600, 0]), ('normal control', {'coverage': ['family', 'family', 'family', None, 'self', 'self', None, 'family', 'family', 'family', None, 'self'], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 380378, 'request': 301438}, [529600, 149222])], [('regression', {'coverage': [None, None, 'self', 'self', 'family', None, 'family', None, None, 'family', None, None], 'age': 56, 'employer_ytd': 180971, 'employee_ytd': 345821, 'request': 207004}, [327016, 0]), ('regression', {'coverage': [None, None, None, None, None, None, None, None, None, None, 'self', None], 'age': 55, 'employer_ytd': 129076, 'employee_ytd': 256621, 'request': 34707}, [44133, 0]), ('partial-repair probe', {'coverage': [None, None, 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', None], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 227366, 'request': 100757}, [397200, 100757]), ('partial-repair probe', {'coverage': ['family', 'self', 'self', 'self', None, 'self', None, 'self', 'self', 'family', 'self', None], 'age': 56, 'employer_ytd': 129254, 'employee_ytd': 314848, 'request': 257142}, [468100, 23998]), ('normal control', {'coverage': [None, 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family'], 'age': 40, 'employer_ytd': 0, 'employee_ytd': 164388, 'request': 96773}, [855000, 96773]), ('normal control', {'coverage': [None, None, None, None, None, None, None, 'family', 'family', 'family', 'family', 'family'], 'age': 56, 'employer_ytd': 0, 'employee_ytd': 506616, 'request': 122643}, [955000, 122643]), ('normal control', {'coverage': [None, 'family', None, None, None, None, 'family', None, 'self', 'self', None, 'family'], 'age': 36, 'employer_ytd': 0, 'employee_ytd': 317677, 'request': 360183}, [855000, 360183]), ('normal control', {'coverage': [None, 'family', None, None, 'family', 'self', 'family', 'self', None, 'self', None, None], 'age': 40, 'employer_ytd': 0, 'employee_ytd': 423473, 'request': 127772}, [321150, 0])], [('regression', {'coverage': [None, None, None, None, None, None, None, None, None, None, 'self', None], 'age': 55, 'employer_ytd': 129076, 'employee_ytd': 256621, 'request': 34707}, [44133, 0]), ('regression', {'coverage': [None, None, 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', None], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 227366, 'request': 100757}, [397200, 100757]), ('partial-repair probe', {'coverage': [None, None, None, 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', None], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 187011, 'request': 370324}, [636666, 370324]), ('partial-repair probe', {'coverage': [None, None, None, 'family', 'family', None, None, None, None, None, None, None], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 374275, 'request': 45667}, [159166, 0]), ('normal control', {'coverage': [None, None, None, None, None, None, None, None, None, None, None, 'family'], 'age': 56, 'employer_ytd': 72944, 'employee_ytd': 287033, 'request': 147965}, [955000, 147965]), ('normal control', {'coverage': ['self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self'], 'age': 54, 'employer_ytd': 0, 'employee_ytd': 551908, 'request': 166115}, [429600, 0]), ('normal control', {'coverage': ['self', 'family', None, None, 'family', 'family', 'family', 'family', None, None, 'self', 'family'], 'age': 56, 'employer_ytd': 0, 'employee_ytd': 12981, 'request': 364571}, [955000, 364571]), ('normal control', {'coverage': [None, None, None, None, None, None, 'family', 'family', 'family', 'family', 'family', 'family'], 'age': 55, 'employer_ytd': 102233, 'employee_ytd': 513881, 'request': 171346}, [955000, 171346])], [('regression', {'coverage': [None, None, 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', None], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 227366, 'request': 100757}, [397200, 100757]), ('regression', {'coverage': ['family', 'self', 'self', 'self', None, 'self', None, 'self', 'self', 'family', 'self', None], 'age': 56, 'employer_ytd': 129254, 'employee_ytd': 314848, 'request': 257142}, [468100, 23998]), ('partial-repair probe', {'coverage': [None, None, 'self', 'self', 'self', 'self', None, None, None, None, None, None], 'age': 69, 'employer_ytd': 0, 'employee_ytd': 286196, 'request': 258790}, [176533, 0]), ('partial-repair probe', {'coverage': [None, None, None, 'family', 'family', None, None, None, None, None, None, None], 'age': 55, 'employer_ytd': 26008, 'employee_ytd': 286427, 'request': 122717}, [159166, 0]), ('normal control', {'coverage': [None, None, None, None, None, None, None, None, 'family', 'family', 'family', 'family'], 'age': 30, 'employer_ytd': 0, 'employee_ytd': 594908, 'request': 135782}, [855000, 135782]), ('normal control', {'coverage': ['family', 'self', None, 'self', None, 'self', 'family', 'family', 'self', 'family', None, 'family'], 'age': 65, 'employer_ytd': 119262, 'employee_ytd': 404161, 'request': 137517}, [955000, 137517]), ('normal control', {'coverage': [None, None, None, None, None, None, None, None, None, 'self', 'self', None], 'age': 40, 'employer_ytd': 0, 'employee_ytd': 243944, 'request': 352402}, [71600, 0]), ('normal control', {'coverage': ['self', None, None, None, None, 'family', None, None, None, 'self', None, 'family'], 'age': 35, 'employer_ytd': 0, 'employee_ytd': 316436, 'request': 299379}, [855000, 299379])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

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

N = 1
observations = []
def solve(x):
    cov = x['coverage']
    monthly = {'self': 35800, 'family': 71250}
    if cov[11] is not None:
        months = [cov[11]] * 12
    else:
        months = cov
    limit = sum(monthly[m] for m in months if m is not None)
    covered = sum(1 for m in months if m is not None)
    if x['age'] >= 55:
        limit += 100000 * covered // 12 if covered == 12 else 0
    room = max(0, limit - x['employer_ytd'] - x['employee_ytd'])
    allowed = min(x['request'], room)
    return [limit, allowed]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'coverage': [None, None, None, None, None, None, 'self', None, None, None, None, None], 'age': 55, 'employer_ytd': 115762, 'employee_ytd': 24574, 'request': 286981}, [44133, 0]), ('regression', {'coverage': ['self', 'self', 'self', None, 'family', 'self', None, None, 'self', None, 'family', None], 'age': 55, 'employer_ytd': 286268, 'employee_ytd': 434159, 'request': 197484}, [379833, 0]), ('partial-repair probe', {'coverage': [None, None, 'self', 'self', 'family', None, 'family', None, None, 'family', None, None], 'age': 56, 'employer_ytd': 180971, 'employee_ytd': 345821, 'request': 207004}, [327016, 0]), ('partial-repair probe', {'coverage': [None, None, None, None, None, None, None, None, None, None, 'self', None], 'age': 55, 'employer_ytd': 129076, 'employee_ytd': 256621, 'request': 34707}, [44133, 0]), ('normal control', {'coverage': ['self', 'self', 'family', 'family', 'family', None, 'self', 'family', None, None, 'family', None], 'age': 41, 'employer_ytd': 182987, 'employee_ytd': 284378, 'request': 281989}, [463650, 0]), ('normal control', {'coverage': [None, None, None, None, None, None, None, 'family', 'family', 'family', 'family', 'family'], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 238336, 'request': 135874}, [955000, 135874]), ('normal control', {'coverage': [None, None, 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self'], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 456065, 'request': 36894}, [529600, 36894]), ('normal control', {'coverage': [None, 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family'], 'age': 40, 'employer_ytd': 0, 'employee_ytd': 74724, 'request': 118780}, [855000, 118780])], [('regression', {'coverage': ['self', 'self', 'self', None, 'family', 'self', None, None, 'self', None, 'family', None], 'age': 55, 'employer_ytd': 286268, 'employee_ytd': 434159, 'request': 197484}, [379833, 0]), ('regression', {'coverage': [None, None, 'self', 'self', 'family', None, 'family', None, None, 'family', None, None], 'age': 56, 'employer_ytd': 180971, 'employee_ytd': 345821, 'request': 207004}, [327016, 0]), ('partial-repair probe', {'coverage': [None, None, None, None, None, None, None, None, None, None, 'self', None], 'age': 55, 'employer_ytd': 129076, 'employee_ytd': 256621, 'request': 34707}, [44133, 0]), ('partial-repair probe', {'coverage': [None, None, 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', None], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 227366, 'request': 100757}, [397200, 100757]), ('normal control', {'coverage': [None, 'self', 'family', 'self', 'self', None, 'family', None, 'self', 'family', 'family', None], 'age': 40, 'employer_ytd': 225872, 'employee_ytd': 144016, 'request': 380678}, [428200, 58312]), ('normal control', {'coverage': [None, None, None, None, None, None, None, 'family', 'family', None, None, None], 'age': 37, 'employer_ytd': 208148, 'employee_ytd': 1425, 'request': 155636}, [142500, 0]), ('normal control', {'coverage': ['self', None, 'self', 'family', 'family', None, None, None, None, 'family', None, 'self'], 'age': 48, 'employer_ytd': 141642, 'employee_ytd': 558877, 'request': 321776}, [429600, 0]), ('normal control', {'coverage': ['family', 'family', 'family', None, 'self', 'self', None, 'family', 'family', 'family', None, 'self'], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 380378, 'request': 301438}, [529600, 149222])], [('regression', {'coverage': [None, None, 'self', 'self', 'family', None, 'family', None, None, 'family', None, None], 'age': 56, 'employer_ytd': 180971, 'employee_ytd': 345821, 'request': 207004}, [327016, 0]), ('regression', {'coverage': [None, None, None, None, None, None, None, None, None, None, 'self', None], 'age': 55, 'employer_ytd': 129076, 'employee_ytd': 256621, 'request': 34707}, [44133, 0]), ('partial-repair probe', {'coverage': [None, None, 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', None], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 227366, 'request': 100757}, [397200, 100757]), ('partial-repair probe', {'coverage': ['family', 'self', 'self', 'self', None, 'self', None, 'self', 'self', 'family', 'self', None], 'age': 56, 'employer_ytd': 129254, 'employee_ytd': 314848, 'request': 257142}, [468100, 23998]), ('normal control', {'coverage': [None, 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family'], 'age': 40, 'employer_ytd': 0, 'employee_ytd': 164388, 'request': 96773}, [855000, 96773]), ('normal control', {'coverage': [None, None, None, None, None, None, None, 'family', 'family', 'family', 'family', 'family'], 'age': 56, 'employer_ytd': 0, 'employee_ytd': 506616, 'request': 122643}, [955000, 122643]), ('normal control', {'coverage': [None, 'family', None, None, None, None, 'family', None, 'self', 'self', None, 'family'], 'age': 36, 'employer_ytd': 0, 'employee_ytd': 317677, 'request': 360183}, [855000, 360183]), ('normal control', {'coverage': [None, 'family', None, None, 'family', 'self', 'family', 'self', None, 'self', None, None], 'age': 40, 'employer_ytd': 0, 'employee_ytd': 423473, 'request': 127772}, [321150, 0])], [('regression', {'coverage': [None, None, None, None, None, None, None, None, None, None, 'self', None], 'age': 55, 'employer_ytd': 129076, 'employee_ytd': 256621, 'request': 34707}, [44133, 0]), ('regression', {'coverage': [None, None, 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', None], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 227366, 'request': 100757}, [397200, 100757]), ('partial-repair probe', {'coverage': [None, None, None, 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', None], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 187011, 'request': 370324}, [636666, 370324]), ('partial-repair probe', {'coverage': [None, None, None, 'family', 'family', None, None, None, None, None, None, None], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 374275, 'request': 45667}, [159166, 0]), ('normal control', {'coverage': [None, None, None, None, None, None, None, None, None, None, None, 'family'], 'age': 56, 'employer_ytd': 72944, 'employee_ytd': 287033, 'request': 147965}, [955000, 147965]), ('normal control', {'coverage': ['self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self'], 'age': 54, 'employer_ytd': 0, 'employee_ytd': 551908, 'request': 166115}, [429600, 0]), ('normal control', {'coverage': ['self', 'family', None, None, 'family', 'family', 'family', 'family', None, None, 'self', 'family'], 'age': 56, 'employer_ytd': 0, 'employee_ytd': 12981, 'request': 364571}, [955000, 364571]), ('normal control', {'coverage': [None, None, None, None, None, None, 'family', 'family', 'family', 'family', 'family', 'family'], 'age': 55, 'employer_ytd': 102233, 'employee_ytd': 513881, 'request': 171346}, [955000, 171346])], [('regression', {'coverage': [None, None, 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', None], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 227366, 'request': 100757}, [397200, 100757]), ('regression', {'coverage': ['family', 'self', 'self', 'self', None, 'self', None, 'self', 'self', 'family', 'self', None], 'age': 56, 'employer_ytd': 129254, 'employee_ytd': 314848, 'request': 257142}, [468100, 23998]), ('partial-repair probe', {'coverage': [None, None, 'self', 'self', 'self', 'self', None, None, None, None, None, None], 'age': 69, 'employer_ytd': 0, 'employee_ytd': 286196, 'request': 258790}, [176533, 0]), ('partial-repair probe', {'coverage': [None, None, None, 'family', 'family', None, None, None, None, None, None, None], 'age': 55, 'employer_ytd': 26008, 'employee_ytd': 286427, 'request': 122717}, [159166, 0]), ('normal control', {'coverage': [None, None, None, None, None, None, None, None, 'family', 'family', 'family', 'family'], 'age': 30, 'employer_ytd': 0, 'employee_ytd': 594908, 'request': 135782}, [855000, 135782]), ('normal control', {'coverage': ['family', 'self', None, 'self', None, 'self', 'family', 'family', 'self', 'family', None, 'family'], 'age': 65, 'employer_ytd': 119262, 'employee_ytd': 404161, 'request': 137517}, [955000, 137517]), ('normal control', {'coverage': [None, None, None, None, None, None, None, None, None, 'self', 'self', None], 'age': 40, 'employer_ytd': 0, 'employee_ytd': 243944, 'request': 352402}, [71600, 0]), ('normal control', {'coverage': ['self', None, None, None, None, 'family', None, None, None, 'self', None, 'family'], 'age': 35, 'employer_ytd': 0, 'employee_ytd': 316436, 'request': 299379}, [855000, 299379])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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:
Part-year participants aged 55 or older receive the full catch-up amount.

Input {coverage: 12 monthly entries None|self|family, age, employer_ytd, employee_ytd, request}. If December is covered, every month is treated as having December's tier (last-month rule). Limit = sum of monthly limits (self 358.00, family 712.50). Age 55+ adds 1,000.00 * covered months // 12. Allowed payroll contribution = min(request, max(0, limit - employer_ytd - employee_ytd)). Return [limit, allowed].

split: open-access


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

N = 1
observations = []
def solve(x):
    cov = x['coverage']
    monthly = {'self': 35800, 'family': 71250}
    if cov[11] is not None:
        months = [cov[11]] * 12
    else:
        months = cov
    limit = monthly['family' if 'family' in months else 'self'] * sum(1 for m in months if m is not None)
    covered = sum(1 for m in months if m is not None)
    if x['age'] >= 55:
        limit += 100000 * covered // 12
    room = max(0, limit - x['employer_ytd'] - x['employee_ytd'])
    allowed = min(x['request'], room)
    return [limit, allowed]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'coverage': ['self', 'self', 'family', 'family', 'family', None, 'self', 'family', None, None, 'family', None], 'age': 41, 'employer_ytd': 182987, 'employee_ytd': 284378, 'request': 281989}, [463650, 0]), ('regression', {'coverage': [None, 'self', 'family', 'self', 'self', None, 'family', None, 'self', 'family', 'family', None], 'age': 40, 'employer_ytd': 225872, 'employee_ytd': 144016, 'request': 380678}, [428200, 58312]), ('partial-repair probe', {'coverage': [None, None, None, None, None, None, None, 'family', 'family', 'family', 'family', 'family'], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 238336, 'request': 135874}, [955000, 135874]), ('partial-repair probe', {'coverage': [None, None, 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self'], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 456065, 'request': 36894}, [529600, 36894]), ('normal control', {'coverage': [None, None, None, None, None, None, 'self', None, None, None, None, None], 'age': 55, 'employer_ytd': 115762, 'employee_ytd': 24574, 'request': 286981}, [44133, 0]), ('normal control', {'coverage': [None, None, None, None, None, None, None, 'family', 'family', None, None, None], 'age': 37, 'employer_ytd': 208148, 'employee_ytd': 1425, 'request': 155636}, [142500, 0]), ('normal control', {'coverage': ['self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self'], 'age': 54, 'employer_ytd': 0, 'employee_ytd': 551908, 'request': 166115}, [429600, 0]), ('normal control', {'coverage': [None, None, None, None, None, None, None, None, None, 'self', 'self', None], 'age': 40, 'employer_ytd': 0, 'employee_ytd': 243944, 'request': 352402}, [71600, 0])], [('regression', {'coverage': [None, 'self', 'family', 'self', 'self', None, 'family', None, 'self', 'family', 'family', None], 'age': 40, 'employer_ytd': 225872, 'employee_ytd': 144016, 'request': 380678}, [428200, 58312]), ('regression', {'coverage': [None, 'family', None, None, 'family', 'self', 'family', 'self', None, 'self', None, None], 'age': 40, 'employer_ytd': 0, 'employee_ytd': 423473, 'request': 127772}, [321150, 0]), ('partial-repair probe', {'coverage': [None, 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family'], 'age': 40, 'employer_ytd': 0, 'employee_ytd': 74724, 'request': 118780}, [855000, 118780]), ('partial-repair probe', {'coverage': ['self', None, 'self', 'family', 'family', None, None, None, None, 'family', None, 'self'], 'age': 48, 'employer_ytd': 141642, 'employee_ytd': 558877, 'request': 321776}, [429600, 0]), ('normal control', {'coverage': ['family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family'], 'age': 56, 'employer_ytd': 190055, 'employee_ytd': 233251, 'request': 299705}, [955000, 299705]), ('normal control', {'coverage': [None, None, None, None, None, None, None, None, None, None, 'self', None], 'age': 55, 'employer_ytd': 129076, 'employee_ytd': 256621, 'request': 34707}, [44133, 0]), ('normal control', {'coverage': [None, None, 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', None], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 227366, 'request': 100757}, [397200, 100757]), ('normal control', {'coverage': [None, None, None, 'family', 'family', 'family', 'family', 'family', 'family', 'family', None, None], 'age': 40, 'employer_ytd': 0, 'employee_ytd': 575897, 'request': 101952}, [498750, 0])], [('regression', {'coverage': [None, 'family', None, None, 'family', 'self', 'family', 'self', None, 'self', None, None], 'age': 40, 'employer_ytd': 0, 'employee_ytd': 423473, 'request': 127772}, [321150, 0]), ('regression', {'coverage': ['self', 'self', 'self', None, 'family', 'self', None, None, 'self', None, 'family', None], 'age': 55, 'employer_ytd': 286268, 'employee_ytd': 434159, 'request': 197484}, [379833, 0]), ('partial-repair probe', {'coverage': ['family', 'family', 'family', None, 'self', 'self', None, 'family', 'family', 'family', None, 'self'], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 380378, 'request': 301438}, [529600, 149222]), ('partial-repair probe', {'coverage': [None, 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family'], 'age': 40, 'employer_ytd': 0, 'employee_ytd': 164388, 'request': 96773}, [855000, 96773]), ('normal control', {'coverage': ['family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family'], 'age': 40, 'employer_ytd': 0, 'employee_ytd': 220797, 'request': 153139}, [855000, 153139]), ('normal control', {'coverage': [None, None, None, 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', None], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 187011, 'request': 370324}, [636666, 370324]), ('normal control', {'coverage': [None, None, None, None, None, 'self', 'self', 'self', 'self', 'self', None, None], 'age': 54, 'employer_ytd': 0, 'employee_ytd': 567724, 'request': 14650}, [179000, 0]), ('normal control', {'coverage': [None, None, None, None, None, None, None, 'family', 'family', 'family', 'family', None], 'age': 40, 'employer_ytd': 73749, 'employee_ytd': 425782, 'request': 376733}, [285000, 0])], [('regression', {'coverage': ['self', 'self', 'self', None, 'family', 'self', None, None, 'self', None, 'family', None], 'age': 55, 'employer_ytd': 286268, 'employee_ytd': 434159, 'request': 197484}, [379833, 0]), ('regression', {'coverage': [None, None, 'self', 'self', 'family', None, 'family', None, None, 'family', None, None], 'age': 56, 'employer_ytd': 180971, 'employee_ytd': 345821, 'request': 207004}, [327016, 0]), ('partial-repair probe', {'coverage': [None, None, None, None, None, None, None, 'family', 'family', 'family', 'family', 'family'], 'age': 56, 'employer_ytd': 0, 'employee_ytd': 506616, 'request': 122643}, [955000, 122643]), ('partial-repair probe', {'coverage': [None, 'family', None, None, None, None, 'family', None, 'self', 'self', None, 'family'], 'age': 36, 'employer_ytd': 0, 'employee_ytd': 317677, 'request': 360183}, [855000, 360183]), ('normal control', {'coverage': [None, None, None, None, None, None, 'self', 'self', 'self', None, None, None], 'age': 53, 'employer_ytd': 17184, 'employee_ytd': 157674, 'request': 351205}, [107400, 0]), ('normal control', {'coverage': [None, None, None, 'family', 'family', None, None, None, None, None, None, None], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 374275, 'request': 45667}, [159166, 0]), ('normal control', {'coverage': [None, None, 'self', 'self', 'self', 'self', None, None, None, None, None, None], 'age': 69, 'employer_ytd': 0, 'employee_ytd': 286196, 'request': 258790}, [176533, 0]), ('normal control', {'coverage': [None, None, None, 'family', 'family', None, None, None, None, None, None, None], 'age': 55, 'employer_ytd': 26008, 'employee_ytd': 286427, 'request': 122717}, [159166, 0])], [('regression', {'coverage': [None, None, 'self', 'self', 'family', None, 'family', None, None, 'family', None, None], 'age': 56, 'employer_ytd': 180971, 'employee_ytd': 345821, 'request': 207004}, [327016, 0]), ('regression', {'coverage': ['self', 'family', 'family', None, None, 'family', 'self', None, None, 'self', None, None], 'age': 51, 'employer_ytd': 0, 'employee_ytd': 124613, 'request': 317861}, [321150, 196537]), ('partial-repair probe', {'coverage': [None, None, None, None, None, None, None, None, None, None, None, 'family'], 'age': 56, 'employer_ytd': 72944, 'employee_ytd': 287033, 'request': 147965}, [955000, 147965]), ('partial-repair probe', {'coverage': ['self', 'family', None, None, 'family', 'family', 'family', 'family', None, None, 'self', 'family'], 'age': 56, 'employer_ytd': 0, 'employee_ytd': 12981, 'request': 364571}, [955000, 364571]), ('normal control', {'coverage': [None, None, None, None, None, None, None, 'family', 'family', 'family', 'family', None], 'age': 54, 'employer_ytd': 95832, 'employee_ytd': 494479, 'request': 262097}, [285000, 0]), ('normal control', {'coverage': [None, None, 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', None], 'age': 64, 'employer_ytd': 0, 'employee_ytd': 122288, 'request': 375154}, [716250, 375154]), ('normal control', {'coverage': ['self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self'], 'age': 56, 'employer_ytd': 274826, 'employee_ytd': 205940, 'request': 252446}, [529600, 48834]), ('normal control', {'coverage': [None, 'self', 'self', 'self', 'self', None, None, None, None, None, None, None], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 149922, 'request': 313016}, [176533, 26611])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    cov = x['coverage']
    monthly = {'self': 35800, 'family': 71250}
    if cov[11] is not None:
        months = [cov[11]] * 12
    else:
        months = cov
    limit = sum(monthly[m] for m in cov if m is not None)
    covered = sum(1 for m in months if m is not None)
    if x['age'] >= 55:
        limit += 100000 * covered // 12
    room = max(0, limit - x['employer_ytd'] - x['employee_ytd'])
    allowed = min(x['request'], room)
    return [limit, allowed]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'coverage': ['self', 'self', 'family', 'family', 'family', None, 'self', 'family', None, None, 'family', None], 'age': 41, 'employer_ytd': 182987, 'employee_ytd': 284378, 'request': 281989}, [463650, 0]), ('regression', {'coverage': [None, 'self', 'family', 'self', 'self', None, 'family', None, 'self', 'family', 'family', None], 'age': 40, 'employer_ytd': 225872, 'employee_ytd': 144016, 'request': 380678}, [428200, 58312]), ('partial-repair probe', {'coverage': [None, None, None, None, None, None, None, 'family', 'family', 'family', 'family', 'family'], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 238336, 'request': 135874}, [955000, 135874]), ('partial-repair probe', {'coverage': [None, None, 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self'], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 456065, 'request': 36894}, [529600, 36894]), ('normal control', {'coverage': [None, None, None, None, None, None, 'self', None, None, None, None, None], 'age': 55, 'employer_ytd': 115762, 'employee_ytd': 24574, 'request': 286981}, [44133, 0]), ('normal control', {'coverage': [None, None, None, None, None, None, None, 'family', 'family', None, None, None], 'age': 37, 'employer_ytd': 208148, 'employee_ytd': 1425, 'request': 155636}, [142500, 0]), ('normal control', {'coverage': ['self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self'], 'age': 54, 'employer_ytd': 0, 'employee_ytd': 551908, 'request': 166115}, [429600, 0]), ('normal control', {'coverage': [None, None, None, None, None, None, None, None, None, 'self', 'self', None], 'age': 40, 'employer_ytd': 0, 'employee_ytd': 243944, 'request': 352402}, [71600, 0])], [('regression', {'coverage': [None, 'self', 'family', 'self', 'self', None, 'family', None, 'self', 'family', 'family', None], 'age': 40, 'employer_ytd': 225872, 'employee_ytd': 144016, 'request': 380678}, [428200, 58312]), ('regression', {'coverage': [None, 'family', None, None, 'family', 'self', 'family', 'self', None, 'self', None, None], 'age': 40, 'employer_ytd': 0, 'employee_ytd': 423473, 'request': 127772}, [321150, 0]), ('partial-repair probe', {'coverage': [None, 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family'], 'age': 40, 'employer_ytd': 0, 'employee_ytd': 74724, 'request': 118780}, [855000, 118780]), ('partial-repair probe', {'coverage': ['self', None, 'self', 'family', 'family', None, None, None, None, 'family', None, 'self'], 'age': 48, 'employer_ytd': 141642, 'employee_ytd': 558877, 'request': 321776}, [429600, 0]), ('normal control', {'coverage': ['family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family'], 'age': 56, 'employer_ytd': 190055, 'employee_ytd': 233251, 'request': 299705}, [955000, 299705]), ('normal control', {'coverage': [None, None, None, None, None, None, None, None, None, None, 'self', None], 'age': 55, 'employer_ytd': 129076, 'employee_ytd': 256621, 'request': 34707}, [44133, 0]), ('normal control', {'coverage': [None, None, 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', None], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 227366, 'request': 100757}, [397200, 100757]), ('normal control', {'coverage': [None, None, None, 'family', 'family', 'family', 'family', 'family', 'family', 'family', None, None], 'age': 40, 'employer_ytd': 0, 'employee_ytd': 575897, 'request': 101952}, [498750, 0])], [('regression', {'coverage': [None, 'family', None, None, 'family', 'self', 'family', 'self', None, 'self', None, None], 'age': 40, 'employer_ytd': 0, 'employee_ytd': 423473, 'request': 127772}, [321150, 0]), ('regression', {'coverage': ['self', 'self', 'self', None, 'family', 'self', None, None, 'self', None, 'family', None], 'age': 55, 'employer_ytd': 286268, 'employee_ytd': 434159, 'request': 197484}, [379833, 0]), ('partial-repair probe', {'coverage': ['family', 'family', 'family', None, 'self', 'self', None, 'family', 'family', 'family', None, 'self'], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 380378, 'request': 301438}, [529600, 149222]), ('partial-repair probe', {'coverage': [None, 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family'], 'age': 40, 'employer_ytd': 0, 'employee_ytd': 164388, 'request': 96773}, [855000, 96773]), ('normal control', {'coverage': ['family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family'], 'age': 40, 'employer_ytd': 0, 'employee_ytd': 220797, 'request': 153139}, [855000, 153139]), ('normal control', {'coverage': [None, None, None, 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', None], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 187011, 'request': 370324}, [636666, 370324]), ('normal control', {'coverage': [None, None, None, None, None, 'self', 'self', 'self', 'self', 'self', None, None], 'age': 54, 'employer_ytd': 0, 'employee_ytd': 567724, 'request': 14650}, [179000, 0]), ('normal control', {'coverage': [None, None, None, None, None, None, None, 'family', 'family', 'family', 'family', None], 'age': 40, 'employer_ytd': 73749, 'employee_ytd': 425782, 'request': 376733}, [285000, 0])], [('regression', {'coverage': ['self', 'self', 'self', None, 'family', 'self', None, None, 'self', None, 'family', None], 'age': 55, 'employer_ytd': 286268, 'employee_ytd': 434159, 'request': 197484}, [379833, 0]), ('regression', {'coverage': [None, None, 'self', 'self', 'family', None, 'family', None, None, 'family', None, None], 'age': 56, 'employer_ytd': 180971, 'employee_ytd': 345821, 'request': 207004}, [327016, 0]), ('partial-repair probe', {'coverage': [None, None, None, None, None, None, None, 'family', 'family', 'family', 'family', 'family'], 'age': 56, 'employer_ytd': 0, 'employee_ytd': 506616, 'request': 122643}, [955000, 122643]), ('partial-repair probe', {'coverage': [None, 'family', None, None, None, None, 'family', None, 'self', 'self', None, 'family'], 'age': 36, 'employer_ytd': 0, 'employee_ytd': 317677, 'request': 360183}, [855000, 360183]), ('normal control', {'coverage': [None, None, None, None, None, None, 'self', 'self', 'self', None, None, None], 'age': 53, 'employer_ytd': 17184, 'employee_ytd': 157674, 'request': 351205}, [107400, 0]), ('normal control', {'coverage': [None, None, None, 'family', 'family', None, None, None, None, None, None, None], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 374275, 'request': 45667}, [159166, 0]), ('normal control', {'coverage': [None, None, 'self', 'self', 'self', 'self', None, None, None, None, None, None], 'age': 69, 'employer_ytd': 0, 'employee_ytd': 286196, 'request': 258790}, [176533, 0]), ('normal control', {'coverage': [None, None, None, 'family', 'family', None, None, None, None, None, None, None], 'age': 55, 'employer_ytd': 26008, 'employee_ytd': 286427, 'request': 122717}, [159166, 0])], [('regression', {'coverage': [None, None, 'self', 'self', 'family', None, 'family', None, None, 'family', None, None], 'age': 56, 'employer_ytd': 180971, 'employee_ytd': 345821, 'request': 207004}, [327016, 0]), ('regression', {'coverage': ['self', 'family', 'family', None, None, 'family', 'self', None, None, 'self', None, None], 'age': 51, 'employer_ytd': 0, 'employee_ytd': 124613, 'request': 317861}, [321150, 196537]), ('partial-repair probe', {'coverage': [None, None, None, None, None, None, None, None, None, None, None, 'family'], 'age': 56, 'employer_ytd': 72944, 'employee_ytd': 287033, 'request': 147965}, [955000, 147965]), ('partial-repair probe', {'coverage': ['self', 'family', None, None, 'family', 'family', 'family', 'family', None, None, 'self', 'family'], 'age': 56, 'employer_ytd': 0, 'employee_ytd': 12981, 'request': 364571}, [955000, 364571]), ('normal control', {'coverage': [None, None, None, None, None, None, None, 'family', 'family', 'family', 'family', None], 'age': 54, 'employer_ytd': 95832, 'employee_ytd': 494479, 'request': 262097}, [285000, 0]), ('normal control', {'coverage': [None, None, 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', None], 'age': 64, 'employer_ytd': 0, 'employee_ytd': 122288, 'request': 375154}, [716250, 375154]), ('normal control', {'coverage': ['self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self'], 'age': 56, 'employer_ytd': 274826, 'employee_ytd': 205940, 'request': 252446}, [529600, 48834]), ('normal control', {'coverage': [None, 'self', 'self', 'self', 'self', None, None, None, None, None, None, None], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 149922, 'request': 313016}, [176533, 26611])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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:
Employees who switched from self to family coverage get the family limit for every covered month.

Input {coverage: 12 monthly entries None|self|family, age, employer_ytd, employee_ytd, request}. If December is covered, every month is treated as having December's tier (last-month rule). Limit = sum of monthly limits (self 358.00, family 712.50). Age 55+ adds 1,000.00 * covered months // 12. Allowed payroll contribution = min(request, max(0, limit - employer_ytd - employee_ytd)). Return [limit, allowed].

split: open-access


prompt:
Employers in credit-reduction states owe additional FUTA on wages above the 7,000 base.

Input {employees: [[ytd, wages, state]], credit_reduction: {state: basis points}, carry}. Per employee taxable = min(wages, max(0, 7,000.00 - ytd)). Each line costs taxable*(60 + reduction bp); lines are summed in cent-basis-point units and the quarter liability is rounded half-up once. A deposit is due when liability plus carried undeposited liability is more than 500.00. Return [taxable_total, liability, deposit_due].

split: open-access


prompt:
Quarterly FUTA liability differs by a few cents from the rate applied to total taxable wages.

Input {employees: [[ytd, wages, state]], credit_reduction: {state: basis points}, carry}. Per employee taxable = min(wages, max(0, 7,000.00 - ytd)). Each line costs taxable*(60 + reduction bp); lines are summed in cent-basis-point units and the quarter liability is rounded half-up once. A deposit is due when liability plus carried undeposited liability is more than 500.00. Return [taxable_total, liability, deposit_due].

split: open-access


prompt:
A deposit is demanded when accumulated liability is exactly 500.00.

Input {employees: [[ytd, wages, state]], credit_reduction: {state: basis points}, carry}. Per employee taxable = min(wages, max(0, 7,000.00 - ytd)). Each line costs taxable*(60 + reduction bp); lines are summed in cent-basis-point units and the quarter liability is rounded half-up once. A deposit is due when liability plus carried undeposited liability is more than 500.00. Return [taxable_total, liability, deposit_due].

split: open-access


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

N = 1
observations = []
def solve(x):
    avail = max(0, x['gross'] - x['taxes'])
    taken = {}
    arrears = {}
    for name, amt, pri, partial in sorted(x['deductions'], key=lambda d: -d[2]):
        due = amt + x['arrears'].get(name, 0)
        if due <= avail:
            take = due
        elif partial:
            take = avail
        else:
            take = 0
        avail -= take
        taken[name] = take
        if due - take > 0:
            arrears[name] = due - take
    return {'net': avail, 'taken': taken, 'arrears': arrears}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'gross': 63849, 'taxes': 6027, 'deductions': [['union', 18684, 2, True], ['charity', 28880, 1, True], ['loan', 38844, 2, True], ['support', 20513, 3, False]], 'arrears': {'union': 15372}}, {'net': 0, 'taken': {'charity': 28880, 'union': 28942, 'loan': 0, 'support': 0}, 'arrears': {'union': 5114, 'loan': 38844, 'support': 20513}}), ('regression', {'gross': 6593, 'taxes': 872, 'deductions': [['parking', 5312, 3, False], ['union', 4345, 3, False], ['medical', 14587, 3, False], ['loan', 24540, 2, True], ['support', 7319, 3, True]], 'arrears': {'parking': 388, 'medical': 17218}}, {'net': 0, 'taken': {'loan': 5721, 'parking': 0, 'union': 0, 'medical': 0, 'support': 0}, 'arrears': {'loan': 18819, 'parking': 5700, 'union': 4345, 'medical': 31805, 'support': 7319}}), ('partial-repair probe', {'gross': 45406, 'taxes': 3941, 'deductions': [['parking', 32509, 3, True], ['loan', 15062, 3, True], ['charity', 31648, 1, False]], 'arrears': {'parking': 1472, 'charity': 15167}}, {'net': 0, 'taken': {'charity': 0, 'parking': 33981, 'loan': 7484}, 'arrears': {'charity': 46815, 'loan': 7578}}), ('partial-repair probe', {'gross': 71403, 'taxes': 15182, 'deductions': [['support', 561, 2, True], ['charity', 7949, 1, True], ['parking', 31674, 1, False], ['medical', 37176, 1, False]], 'arrears': {'support': 13700}}, {'net': 2337, 'taken': {'charity': 7949, 'parking': 31674, 'medical': 0, 'support': 14261}, 'arrears': {'medical': 37176}}), ('normal control', {'gross': 134653, 'taxes': 27454, 'deductions': [['parking', 26770, 3, False], ['loan', 12315, 2, False], ['union', 3364, 1, False], ['support', 11662, 3, True]], 'arrears': {'parking': 10177, 'loan': 15972, 'support': 6216}}, {'net': 20723, 'taken': {'union': 3364, 'loan': 28287, 'parking': 36947, 'support': 17878}, 'arrears': {}}), ('normal control', {'gross': 138327, 'taxes': 24358, 'deductions': [['loan', 12004, 3, True], ['union', 4120, 2, True], ['medical', 35331, 3, False], ['parking', 697, 1, True], ['support', 15166, 2, True]], 'arrears': {'loan': 5341, 'union': 19151, 'support': 16971}}, {'net': 5188, 'taken': {'parking': 697, 'union': 23271, 'support': 32137, 'loan': 17345, 'medical': 35331}, 'arrears': {}}), ('normal control', {'gross': 102757, 'taxes': 16339, 'deductions': [['medical', 20312, 1, False]], 'arrears': {'medical': 12422}}, {'net': 53684, 'taken': {'medical': 32734}, 'arrears': {}}), ('normal control', {'gross': 106436, 'taxes': 29897, 'deductions': [['parking', 39254, 1, True]], 'arrears': {}}, {'net': 37285, 'taken': {'parking': 39254}, 'arrears': {}})], [('regression', {'gross': 60703, 'taxes': 11543, 'deductions': [['support', 14720, 2, False], ['loan', 10777, 3, False], ['medical', 34788, 2, True]], 'arrears': {}}, {'net': 0, 'taken': {'support': 14720, 'medical': 34440, 'loan': 0}, 'arrears': {'medical': 348, 'loan': 10777}}), ('regression', {'gross': 3515, 'taxes': 674, 'deductions': [['parking', 20962, 1, False], ['union', 18985, 3, True], ['loan', 33701, 1, True]], 'arrears': {}}, {'net': 0, 'taken': {'parking': 0, 'loan': 2841, 'union': 0}, 'arrears': {'parking': 20962, 'loan': 30860, 'union': 18985}}), ('partial-repair probe', {'gross': 63849, 'taxes': 6027, 'deductions': [['union', 18684, 2, True], ['charity', 28880, 1, True], ['loan', 38844, 2, True], ['support', 20513, 3, False]], 'arrears': {'union': 15372}}, {'net': 0, 'taken': {'charity': 28880, 'union': 28942, 'loan': 0, 'support': 0}, 'arrears': {'union': 5114, 'loan': 38844, 'support': 20513}}), ('partial-repair probe', {'gross': 37898, 'taxes': 10470, 'deductions': [['union', 18447, 3, False], ['parking', 30036, 3, True], ['support', 12641, 2, True], ['loan', 39343, 2, False], ['charity', 10333, 2, False]], 'arrears': {'parking': 13057, 'support': 19997}}, {'net': 0, 'taken': {'support': 27428, 'loan': 0, 'charity': 0, 'union': 0, 'parking': 0}, 'arrears': {'support': 5210, 'loan': 39343, 'charity': 10333, 'union': 18447, 'parking': 43093}}), ('normal control', {'gross': 132719, 'taxes': 9617, 'deductions': [['charity', 21694, 1, False], ['loan', 11829, 1, True], ['parking', 18178, 3, True], ['union', 1782, 3, True]], 'arrears': {'loan': 14963, 'parking': 3722, 'union': 3447}}, {'net': 47487, 'taken': {'charity': 21694, 'loan': 26792, 'parking': 21900, 'union': 5229}, 'arrears': {}}), ('normal control', {'gross': 13589, 'taxes': 714, 'deductions': [['charity', 299, 3, True]], 'arrears': {'charity': 4459}}, {'net': 8117, 'taken': {'charity': 4758}, 'arrears': {}}), ('normal control', {'gross': 33426, 'taxes': 5333, 'deductions': [['union', 35082, 2, False], ['loan', 36975, 1, True], ['support', 21693, 3, False], ['parking', 29816, 1, True]], 'arrears': {'union': 18802, 'support': 12060, 'parking': 10514}}, {'net': 0, 'taken': {'loan': 28093, 'parking': 0, 'union': 0, 'support': 0}, 'arrears': {'loan': 8882, 'parking': 40330, 'union': 53884, 'support': 33753}}), ('normal control', {'gross': 142935, 'taxes': 39131, 'deductions': [['parking', 22705, 2, False], ['charity', 7658, 1, True], ['union', 9456, 1, False]], 'arrears': {'charity': 15978}}, {'net': 48007, 'taken': {'charity': 23636, 'union': 9456, 'parking': 22705}, 'arrears': {}})], [('regression', {'gross': 37898, 'taxes': 10470, 'deductions': [['union', 18447, 3, False], ['parking', 30036, 3, True], ['support', 12641, 2, True], ['loan', 39343, 2, False], ['charity', 10333, 2, False]], 'arrears': {'parking': 13057, 'support': 19997}}, {'net': 0, 'taken': {'support': 27428, 'loan': 0, 'charity': 0, 'union': 0, 'parking': 0}, 'arrears': {'support': 5210, 'loan': 39343, 'charity': 10333, 'union': 18447, 'parking': 43093}}), ('regression', {'gross': 91681, 'taxes': 9563, 'deductions': [['union', 25760, 2, False], ['parking', 28566, 1, False], ['support', 8036, 1, False], ['medical', 15864, 1, False], ['charity', 5966, 2, True]], 'arrears': {'parking': 5836, 'support': 18944, 'charity': 5663}}, {'net': 0, 'taken': {'parking': 34402, 'support': 26980, 'medical': 15864, 'union': 0, 'charity': 4872}, 'arrears': {'union': 25760, 'charity': 6757}}), ('partial-repair probe', {'gross': 70795, 'taxes': 21939, 'deductions': [['charity', 32424, 2, True], ['union', 13741, 1, True], ['support', 37512, 1, True], ['loan', 10429, 3, False], ['parking', 8289, 3, False]], 'arrears': {'charity': 12305, 'union': 10397, 'support': 13769}}, {'net': 0, 'taken': {'union': 24138, 'support': 24718, 'charity': 0, 'loan': 0, 'parking': 0}, 'arrears': {'support': 26563, 'charity': 44729, 'loan': 10429, 'parking': 8289}}), ('partial-repair probe', {'gross': 75893, 'taxes': 4166, 'deductions': [['parking', 28979, 1, True], ['medical', 32307, 2, True], ['support', 39584, 3, True], ['loan', 36560, 1, True]], 'arrears': {'medical': 4976, 'loan': 12853}}, {'net': 0, 'taken': {'parking': 28979, 'loan': 42748, 'medical': 0, 'support': 0}, 'arrears': {'loan': 6665, 'medical': 37283, 'support': 39584}}), ('normal control', {'gross': 42097, 'taxes': 527, 'deductions': [['medical', 23283, 1, False], ['union', 33588, 1, False]], 'arrears': {}}, {'net': 18287, 'taken': {'medical': 23283, 'union': 0}, 'arrears': {'union': 33588}}), ('normal control', {'gross': 123929, 'taxes': 27738, 'deductions': [['parking', 24255, 3, False]], 'arrears': {}}, {'net': 71936, 'taken': {'parking': 24255}, 'arrears': {}}), ('normal control', {'gross': 18626, 'taxes': 5266, 'deductions': [['union', 19250, 2, False], ['medical', 18064, 1, False], ['parking', 36984, 1, False], ['charity', 38440, 1, True]], 'arrears': {'medical': 7698}}, {'net': 0, 'taken': {'medical': 0, 'parking': 0, 'charity': 13360, 'union': 0}, 'arrears': {'medical': 25762, 'parking': 36984, 'charity': 25080, 'union': 19250}}), ('normal control', {'gross': 121022, 'taxes': 14438, 'deductions': [['charity', 24183, 2, False], ['loan', 4420, 2, True]], 'arrears': {}}, {'net': 77981, 'taken': {'charity': 24183, 'loan': 4420}, 'arrears': {}})], [('regression', {'gross': 70795, 'taxes': 21939, 'deductions': [['charity', 32424, 2, True], ['union', 13741, 1, True], ['support', 37512, 1, True], ['loan', 10429, 3, False], ['parking', 8289, 3, False]], 'arrears': {'charity': 12305, 'union': 10397, 'support': 13769}}, {'net': 0, 'taken': {'union': 24138, 'support': 24718, 'charity': 0, 'loan': 0, 'parking': 0}, 'arrears': {'support': 26563, 'charity': 44729, 'loan': 10429, 'parking': 8289}}), ('regression', {'gross': 13592, 'taxes': 3481, 'deductions': [['union', 941, 2, False], ['medical', 37170, 2, False], ['charity', 11425, 3, True], ['support', 36894, 2, False], ['parking', 10277, 3, True]], 'arrears': {'medical': 2360}}, {'net': 0, 'taken': {'union': 941, 'medical': 0, 'support': 0, 'charity': 9170, 'parking': 0}, 'arrears': {'medical': 39530, 'support': 36894, 'charity': 2255, 'parking': 10277}}), ('partial-repair probe', {'gross': 75893, 'taxes': 4166, 'deductions': [['parking', 28979, 1, True], ['medical', 32307, 2, True], ['support', 39584, 3, True], ['loan', 36560, 1, True]], 'arrears': {'medical': 4976, 'loan': 12853}}, {'net': 0, 'taken': {'parking': 28979, 'loan': 42748, 'medical': 0, 'support': 0}, 'arrears': {'loan': 6665, 'medical': 37283, 'support': 39584}}), ('partial-repair probe', {'gross': 90353, 'taxes': 27655, 'deductions': [['charity', 13590, 1, False], ['support', 19892, 1, False], ['parking', 27727, 2, False], ['loan', 31849, 1, False]], 'arrears': {'support': 554, 'parking': 7070}}, {'net': 28662, 'taken': {'charity': 13590, 'support': 20446, 'loan': 0, 'parking': 0}, 'arrears': {'loan': 31849, 'parking': 34797}}), ('normal control', {'gross': 77237, 'taxes': 17252, 'deductions': [['medical', 39008, 2, True], ['charity', 8652, 1, False]], 'arrears': {'medical': 6588, 'charity': 5636}}, {'net': 101, 'taken': {'charity': 14288, 'medical': 45596}, 'arrears': {}}), ('normal control', {'gross': 131039, 'taxes': 2132, 'deductions': [['charity', 22460, 2, True], ['loan', 32332, 3, False]], 'arrears': {}}, {'net': 74115, 'taken': {'charity': 22460, 'loan': 32332}, 'arrears': {}}), ('normal control', {'gross': 35155, 'taxes': 4541, 'deductions': [['parking', 30989, 1, False], ['support', 32872, 1, False]], 'arrears': {'parking': 10286, 'support': 19476}}, {'net': 30614, 'taken': {'parking': 0, 'support': 0}, 'arrears': {'parking': 41275, 'support': 52348}}), ('normal control', {'gross': 93080, 'taxes': 11717, 'deductions': [['medical', 15825, 3, False]], 'arrears': {}}, {'net': 65538, 'taken': {'medical': 15825}, 'arrears': {}})], [('regression', {'gross': 75893, 'taxes': 4166, 'deductions': [['parking', 28979, 1, True], ['medical', 32307, 2, True], ['support', 39584, 3, True], ['loan', 36560, 1, True]], 'arrears': {'medical': 4976, 'loan': 12853}}, {'net': 0, 'taken': {'parking': 28979, 'loan': 42748, 'medical': 0, 'support': 0}, 'arrears': {'loan': 6665, 'medical': 37283, 'support': 39584}}), ('regression', {'gross': 32919, 'taxes': 7584, 'deductions': [['parking', 36420, 3, True], ['charity', 19693, 3, False], ['loan', 12305, 1, True], ['medical', 7400, 2, True], ['support', 39536, 2, True]], 'arrears': {}}, {'net': 0, 'taken': {'loan': 12305, 'medical': 7400, 'support': 5630, 'parking': 0, 'charity': 0}, 'arrears': {'support': 33906, 'parking': 36420, 'charity': 19693}}), ('partial-repair probe', {'gross': 75942, 'taxes': 7615, 'deductions': [['parking', 25077, 2, False], ['loan', 28426, 2, True], ['union', 34888, 3, True], ['support', 7824, 1, True], ['medical', 30567, 3, True]], 'arrears': {'union': 13295, 'medical': 8109}}, {'net': 0, 'taken': {'support': 7824, 'parking': 25077, 'loan': 28426, 'union': 7000, 'medical': 0}, 'arrears': {'union': 41183, 'medical': 38676}}), ('partial-repair probe', {'gross': 15439, 'taxes': 1016, 'deductions': [['support', 4501, 1, False], ['parking', 36906, 1, True]], 'arrears': {'support': 32}}, {'net': 0, 'taken': {'support': 4533, 'parking': 9890}, 'arrears': {'parking': 27016}}), ('normal control', {'gross': 46146, 'taxes': 9111, 'deductions': [['loan', 7074, 1, False]], 'arrears': {'loan': 552}}, {'net': 29409, 'taken': {'loan': 7626}, 'arrears': {}}), ('normal control', {'gross': 58263, 'taxes': 3517, 'deductions': [['loan', 34211, 3, False], ['support', 2445, 1, True], ['parking', 6724, 3, False]], 'arrears': {}}, {'net': 11366, 'taken': {'support': 2445, 'loan': 34211, 'parking': 6724}, 'arrears': {}}), ('normal control', {'gross': 133300, 'taxes': 877, 'deductions': [['loan', 8059, 1, False], ['support', 15673, 3, True], ['parking', 24069, 2, True], ['medical', 3549, 2, True], ['union', 35943, 1, False]], 'arrears': {'support': 13159, 'parking': 11492, 'medical': 4680}}, {'net': 15799, 'taken': {'loan': 8059, 'union': 35943, 'parking': 35561, 'medical': 8229, 'support': 28832}, 'arrears': {}}), ('normal control', {'gross': 77880, 'taxes': 19549, 'deductions': [['loan', 3379, 3, True]], 'arrears': {}}, {'net': 54952, 'taken': {'loan': 3379}, 'arrears': {}})]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    avail = max(0, x['gross'] - x['taxes'])
    taken = {}
    arrears = {}
    for name, amt, pri, partial in sorted(x['deductions'], key=lambda d: (d[2], d[0])):
        due = amt + x['arrears'].get(name, 0)
        if due <= avail:
            take = due
        elif partial:
            take = avail
        else:
            take = 0
        avail -= take
        taken[name] = take
        if due - take > 0:
            arrears[name] = due - take
    return {'net': avail, 'taken': taken, 'arrears': arrears}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'gross': 63849, 'taxes': 6027, 'deductions': [['union', 18684, 2, True], ['charity', 28880, 1, True], ['loan', 38844, 2, True], ['support', 20513, 3, False]], 'arrears': {'union': 15372}}, {'net': 0, 'taken': {'charity': 28880, 'union': 28942, 'loan': 0, 'support': 0}, 'arrears': {'union': 5114, 'loan': 38844, 'support': 20513}}), ('regression', {'gross': 6593, 'taxes': 872, 'deductions': [['parking', 5312, 3, False], ['union', 4345, 3, False], ['medical', 14587, 3, False], ['loan', 24540, 2, True], ['support', 7319, 3, True]], 'arrears': {'parking': 388, 'medical': 17218}}, {'net': 0, 'taken': {'loan': 5721, 'parking': 0, 'union': 0, 'medical': 0, 'support': 0}, 'arrears': {'loan': 18819, 'parking': 5700, 'union': 4345, 'medical': 31805, 'support': 7319}}), ('partial-repair probe', {'gross': 45406, 'taxes': 3941, 'deductions': [['parking', 32509, 3, True], ['loan', 15062, 3, True], ['charity', 31648, 1, False]], 'arrears': {'parking': 1472, 'charity': 15167}}, {'net': 0, 'taken': {'charity': 0, 'parking': 33981, 'loan': 7484}, 'arrears': {'charity': 46815, 'loan': 7578}}), ('partial-repair probe', {'gross': 71403, 'taxes': 15182, 'deductions': [['support', 561, 2, True], ['charity', 7949, 1, True], ['parking', 31674, 1, False], ['medical', 37176, 1, False]], 'arrears': {'support': 13700}}, {'net': 2337, 'taken': {'charity': 7949, 'parking': 31674, 'medical': 0, 'support': 14261}, 'arrears': {'medical': 37176}}), ('normal control', {'gross': 134653, 'taxes': 27454, 'deductions': [['parking', 26770, 3, False], ['loan', 12315, 2, False], ['union', 3364, 1, False], ['support', 11662, 3, True]], 'arrears': {'parking': 10177, 'loan': 15972, 'support': 6216}}, {'net': 20723, 'taken': {'union': 3364, 'loan': 28287, 'parking': 36947, 'support': 17878}, 'arrears': {}}), ('normal control', {'gross': 138327, 'taxes': 24358, 'deductions': [['loan', 12004, 3, True], ['union', 4120, 2, True], ['medical', 35331, 3, False], ['parking', 697, 1, True], ['support', 15166, 2, True]], 'arrears': {'loan': 5341, 'union': 19151, 'support': 16971}}, {'net': 5188, 'taken': {'parking': 697, 'union': 23271, 'support': 32137, 'loan': 17345, 'medical': 35331}, 'arrears': {}}), ('normal control', {'gross': 102757, 'taxes': 16339, 'deductions': [['medical', 20312, 1, False]], 'arrears': {'medical': 12422}}, {'net': 53684, 'taken': {'medical': 32734}, 'arrears': {}}), ('normal control', {'gross': 106436, 'taxes': 29897, 'deductions': [['parking', 39254, 1, True]], 'arrears': {}}, {'net': 37285, 'taken': {'parking': 39254}, 'arrears': {}})], [('regression', {'gross': 60703, 'taxes': 11543, 'deductions': [['support', 14720, 2, False], ['loan', 10777, 3, False], ['medical', 34788, 2, True]], 'arrears': {}}, {'net': 0, 'taken': {'support': 14720, 'medical': 34440, 'loan': 0}, 'arrears': {'medical': 348, 'loan': 10777}}), ('regression', {'gross': 3515, 'taxes': 674, 'deductions': [['parking', 20962, 1, False], ['union', 18985, 3, True], ['loan', 33701, 1, True]], 'arrears': {}}, {'net': 0, 'taken': {'parking': 0, 'loan': 2841, 'union': 0}, 'arrears': {'parking': 20962, 'loan': 30860, 'union': 18985}}), ('partial-repair probe', {'gross': 63849, 'taxes': 6027, 'deductions': [['union', 18684, 2, True], ['charity', 28880, 1, True], ['loan', 38844, 2, True], ['support', 20513, 3, False]], 'arrears': {'union': 15372}}, {'net': 0, 'taken': {'charity': 28880, 'union': 28942, 'loan': 0, 'support': 0}, 'arrears': {'union': 5114, 'loan': 38844, 'support': 20513}}), ('partial-repair probe', {'gross': 37898, 'taxes': 10470, 'deductions': [['union', 18447, 3, False], ['parking', 30036, 3, True], ['support', 12641, 2, True], ['loan', 39343, 2, False], ['charity', 10333, 2, False]], 'arrears': {'parking': 13057, 'support': 19997}}, {'net': 0, 'taken': {'support': 27428, 'loan': 0, 'charity': 0, 'union': 0, 'parking': 0}, 'arrears': {'support': 5210, 'loan': 39343, 'charity': 10333, 'union': 18447, 'parking': 43093}}), ('normal control', {'gross': 132719, 'taxes': 9617, 'deductions': [['charity', 21694, 1, False], ['loan', 11829, 1, True], ['parking', 18178, 3, True], ['union', 1782, 3, True]], 'arrears': {'loan': 14963, 'parking': 3722, 'union': 3447}}, {'net': 47487, 'taken': {'charity': 21694, 'loan': 26792, 'parking': 21900, 'union': 5229}, 'arrears': {}}), ('normal control', {'gross': 13589, 'taxes': 714, 'deductions': [['charity', 299, 3, True]], 'arrears': {'charity': 4459}}, {'net': 8117, 'taken': {'charity': 4758}, 'arrears': {}}), ('normal control', {'gross': 33426, 'taxes': 5333, 'deductions': [['union', 35082, 2, False], ['loan', 36975, 1, True], ['support', 21693, 3, False], ['parking', 29816, 1, True]], 'arrears': {'union': 18802, 'support': 12060, 'parking': 10514}}, {'net': 0, 'taken': {'loan': 28093, 'parking': 0, 'union': 0, 'support': 0}, 'arrears': {'loan': 8882, 'parking': 40330, 'union': 53884, 'support': 33753}}), ('normal control', {'gross': 142935, 'taxes': 39131, 'deductions': [['parking', 22705, 2, False], ['charity', 7658, 1, True], ['union', 9456, 1, False]], 'arrears': {'charity': 15978}}, {'net': 48007, 'taken': {'charity': 23636, 'union': 9456, 'parking': 22705}, 'arrears': {}})], [('regression', {'gross': 37898, 'taxes': 10470, 'deductions': [['union', 18447, 3, False], ['parking', 30036, 3, True], ['support', 12641, 2, True], ['loan', 39343, 2, False], ['charity', 10333, 2, False]], 'arrears': {'parking': 13057, 'support': 19997}}, {'net': 0, 'taken': {'support': 27428, 'loan': 0, 'charity': 0, 'union': 0, 'parking': 0}, 'arrears': {'support': 5210, 'loan': 39343, 'charity': 10333, 'union': 18447, 'parking': 43093}}), ('regression', {'gross': 91681, 'taxes': 9563, 'deductions': [['union', 25760, 2, False], ['parking', 28566, 1, False], ['support', 8036, 1, False], ['medical', 15864, 1, False], ['charity', 5966, 2, True]], 'arrears': {'parking': 5836, 'support': 18944, 'charity': 5663}}, {'net': 0, 'taken': {'parking': 34402, 'support': 26980, 'medical': 15864, 'union': 0, 'charity': 4872}, 'arrears': {'union': 25760, 'charity': 6757}}), ('partial-repair probe', {'gross': 70795, 'taxes': 21939, 'deductions': [['charity', 32424, 2, True], ['union', 13741, 1, True], ['support', 37512, 1, True], ['loan', 10429, 3, False], ['parking', 8289, 3, False]], 'arrears': {'charity': 12305, 'union': 10397, 'support': 13769}}, {'net': 0, 'taken': {'union': 24138, 'support': 24718, 'charity': 0, 'loan': 0, 'parking': 0}, 'arrears': {'support': 26563, 'charity': 44729, 'loan': 10429, 'parking': 8289}}), ('partial-repair probe', {'gross': 75893, 'taxes': 4166, 'deductions': [['parking', 28979, 1, True], ['medical', 32307, 2, True], ['support', 39584, 3, True], ['loan', 36560, 1, True]], 'arrears': {'medical': 4976, 'loan': 12853}}, {'net': 0, 'taken': {'parking': 28979, 'loan': 42748, 'medical': 0, 'support': 0}, 'arrears': {'loan': 6665, 'medical': 37283, 'support': 39584}}), ('normal control', {'gross': 42097, 'taxes': 527, 'deductions': [['medical', 23283, 1, False], ['union', 33588, 1, False]], 'arrears': {}}, {'net': 18287, 'taken': {'medical': 23283, 'union': 0}, 'arrears': {'union': 33588}}), ('normal control', {'gross': 123929, 'taxes': 27738, 'deductions': [['parking', 24255, 3, False]], 'arrears': {}}, {'net': 71936, 'taken': {'parking': 24255}, 'arrears': {}}), ('normal control', {'gross': 18626, 'taxes': 5266, 'deductions': [['union', 19250, 2, False], ['medical', 18064, 1, False], ['parking', 36984, 1, False], ['charity', 38440, 1, True]], 'arrears': {'medical': 7698}}, {'net': 0, 'taken': {'medical': 0, 'parking': 0, 'charity': 13360, 'union': 0}, 'arrears': {'medical': 25762, 'parking': 36984, 'charity': 25080, 'union': 19250}}), ('normal control', {'gross': 121022, 'taxes': 14438, 'deductions': [['charity', 24183, 2, False], ['loan', 4420, 2, True]], 'arrears': {}}, {'net': 77981, 'taken': {'charity': 24183, 'loan': 4420}, 'arrears': {}})], [('regression', {'gross': 70795, 'taxes': 21939, 'deductions': [['charity', 32424, 2, True], ['union', 13741, 1, True], ['support', 37512, 1, True], ['loan', 10429, 3, False], ['parking', 8289, 3, False]], 'arrears': {'charity': 12305, 'union': 10397, 'support': 13769}}, {'net': 0, 'taken': {'union': 24138, 'support': 24718, 'charity': 0, 'loan': 0, 'parking': 0}, 'arrears': {'support': 26563, 'charity': 44729, 'loan': 10429, 'parking': 8289}}), ('regression', {'gross': 13592, 'taxes': 3481, 'deductions': [['union', 941, 2, False], ['medical', 37170, 2, False], ['charity', 11425, 3, True], ['support', 36894, 2, False], ['parking', 10277, 3, True]], 'arrears': {'medical': 2360}}, {'net': 0, 'taken': {'union': 941, 'medical': 0, 'support': 0, 'charity': 9170, 'parking': 0}, 'arrears': {'medical': 39530, 'support': 36894, 'charity': 2255, 'parking': 10277}}), ('partial-repair probe', {'gross': 75893, 'taxes': 4166, 'deductions': [['parking', 28979, 1, True], ['medical', 32307, 2, True], ['support', 39584, 3, True], ['loan', 36560, 1, True]], 'arrears': {'medical': 4976, 'loan': 12853}}, {'net': 0, 'taken': {'parking': 28979, 'loan': 42748, 'medical': 0, 'support': 0}, 'arrears': {'loan': 6665, 'medical': 37283, 'support': 39584}}), ('partial-repair probe', {'gross': 90353, 'taxes': 27655, 'deductions': [['charity', 13590, 1, False], ['support', 19892, 1, False], ['parking', 27727, 2, False], ['loan', 31849, 1, False]], 'arrears': {'support': 554, 'parking': 7070}}, {'net': 28662, 'taken': {'charity': 13590, 'support': 20446, 'loan': 0, 'parking': 0}, 'arrears': {'loan': 31849, 'parking': 34797}}), ('normal control', {'gross': 77237, 'taxes': 17252, 'deductions': [['medical', 39008, 2, True], ['charity', 8652, 1, False]], 'arrears': {'medical': 6588, 'charity': 5636}}, {'net': 101, 'taken': {'charity': 14288, 'medical': 45596}, 'arrears': {}}), ('normal control', {'gross': 131039, 'taxes': 2132, 'deductions': [['charity', 22460, 2, True], ['loan', 32332, 3, False]], 'arrears': {}}, {'net': 74115, 'taken': {'charity': 22460, 'loan': 32332}, 'arrears': {}}), ('normal control', {'gross': 35155, 'taxes': 4541, 'deductions': [['parking', 30989, 1, False], ['support', 32872, 1, False]], 'arrears': {'parking': 10286, 'support': 19476}}, {'net': 30614, 'taken': {'parking': 0, 'support': 0}, 'arrears': {'parking': 41275, 'support': 52348}}), ('normal control', {'gross': 93080, 'taxes': 11717, 'deductions': [['medical', 15825, 3, False]], 'arrears': {}}, {'net': 65538, 'taken': {'medical': 15825}, 'arrears': {}})], [('regression', {'gross': 75893, 'taxes': 4166, 'deductions': [['parking', 28979, 1, True], ['medical', 32307, 2, True], ['support', 39584, 3, True], ['loan', 36560, 1, True]], 'arrears': {'medical': 4976, 'loan': 12853}}, {'net': 0, 'taken': {'parking': 28979, 'loan': 42748, 'medical': 0, 'support': 0}, 'arrears': {'loan': 6665, 'medical': 37283, 'support': 39584}}), ('regression', {'gross': 32919, 'taxes': 7584, 'deductions': [['parking', 36420, 3, True], ['charity', 19693, 3, False], ['loan', 12305, 1, True], ['medical', 7400, 2, True], ['support', 39536, 2, True]], 'arrears': {}}, {'net': 0, 'taken': {'loan': 12305, 'medical': 7400, 'support': 5630, 'parking': 0, 'charity': 0}, 'arrears': {'support': 33906, 'parking': 36420, 'charity': 19693}}), ('partial-repair probe', {'gross': 75942, 'taxes': 7615, 'deductions': [['parking', 25077, 2, False], ['loan', 28426, 2, True], ['union', 34888, 3, True], ['support', 7824, 1, True], ['medical', 30567, 3, True]], 'arrears': {'union': 13295, 'medical': 8109}}, {'net': 0, 'taken': {'support': 7824, 'parking': 25077, 'loan': 28426, 'union': 7000, 'medical': 0}, 'arrears': {'union': 41183, 'medical': 38676}}), ('partial-repair probe', {'gross': 15439, 'taxes': 1016, 'deductions': [['support', 4501, 1, False], ['parking', 36906, 1, True]], 'arrears': {'support': 32}}, {'net': 0, 'taken': {'support': 4533, 'parking': 9890}, 'arrears': {'parking': 27016}}), ('normal control', {'gross': 46146, 'taxes': 9111, 'deductions': [['loan', 7074, 1, False]], 'arrears': {'loan': 552}}, {'net': 29409, 'taken': {'loan': 7626}, 'arrears': {}}), ('normal control', {'gross': 58263, 'taxes': 3517, 'deductions': [['loan', 34211, 3, False], ['support', 2445, 1, True], ['parking', 6724, 3, False]], 'arrears': {}}, {'net': 11366, 'taken': {'support': 2445, 'loan': 34211, 'parking': 6724}, 'arrears': {}}), ('normal control', {'gross': 133300, 'taxes': 877, 'deductions': [['loan', 8059, 1, False], ['support', 15673, 3, True], ['parking', 24069, 2, True], ['medical', 3549, 2, True], ['union', 35943, 1, False]], 'arrears': {'support': 13159, 'parking': 11492, 'medical': 4680}}, {'net': 15799, 'taken': {'loan': 8059, 'union': 35943, 'parking': 35561, 'medical': 8229, 'support': 28832}, 'arrears': {}}), ('normal control', {'gross': 77880, 'taxes': 19549, 'deductions': [['loan', 3379, 3, True]], 'arrears': {}}, {'net': 54952, 'taken': {'loan': 3379}, 'arrears': {}})]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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:
Low-priority voluntary deductions consume net pay before mandatory ones.

Input {gross, taxes, deductions: [[name, amount, priority, allow_partial]], arrears: {name: cents}}. Available = max(0, gross - taxes). Deductions run by ascending priority, ties in input order. Each is due amount + prior arrears; if due fits it is taken in full, else partial deductions take what is left and all-or-nothing deductions take 0. Any unpaid due becomes new arrears (only positive entries). Return {net, taken, arrears}.

split: open-access