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

N = 1
observations = []
def solve(x):
    def rnd(n, d):
        q, r = divmod(n, d)
        return q + (1 if 2 * r >= d else 0)
    ytd = dict(x['ytd'])
    wage = tax_exp = cash = withholding = benefits = 0
    for emp, g in x['gross']:
        ben = x['benefit'].get(emp, 0)
        social = min(g, max(0, x['wage_base'] - ytd.get(emp, 0)))
        ytd[emp] = ytd.get(emp, 0) + g
        ss = rnd(social * x['ss_bp'], 10000)
        med = rnd(g * x['med_bp'], 10000)
        itax = rnd((g - ben) * x['itax_bp'], 10000)
        employer = ss + med
        wage += g
        tax_exp += employer
        cash += g - ss - med - itax - ben
        withholding += ss + med + itax
        benefits += ben
    return {'wage_expense': wage, 'tax_expense': tax_exp, 'cash': cash, 'withholding': withholding, 'benefits': benefits}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: withholding liability', {'gross': [['di', 1234], ['cy', 50000], ['bob', 50000], ['di', 80000]], 'ytd': {'di': 15000000, 'cy': 16800000, 'bob': 16800000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'di': 12345, 'cy': 0, 'bob': 5000}}, {'wage_expense': 181234, 'tax_expense': 13865, 'cash': 104339, 'withholding': 61070, 'benefits': 29690}], ['sample 1', {'gross': [['bob', 100000]], 'ytd': {'bob': 16800000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1200, 'benefit': {'bob': 5000}}, {'wage_expense': 100000, 'tax_expense': 5170, 'cash': 78430, 'withholding': 21740, 'benefits': 5000}], ['sample 2', {'gross': [['bob', 100000], ['ann', 250000], ['bob', 80000]], 'ytd': {'bob': 0, 'ann': 15000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'bob': 5000, 'ann': 0}}, {'wage_expense': 430000, 'tax_expense': 32895, 'cash': 294705, 'withholding': 158190, 'benefits': 10000}], ['sample 3', {'gross': [['di', 50000], ['ann', 50000], ['cy', 1234]], 'ytd': {'di': 16800000, 'ann': 16800000, 'cy': 0}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'di': 12345, 'ann': 0, 'cy': 5000}}, {'wage_expense': 101234, 'tax_expense': 7745, 'cash': 67755, 'withholding': 23879, 'benefits': 17345}], ['sample 4', {'gross': [['ann', 333333], ['di', 100000], ['bob', 1234]], 'ytd': {'ann': 0, 'di': 17000000, 'bob': 16800000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'ann': 12345, 'di': 5000, 'bob': 5000}}, {'wage_expense': 434567, 'tax_expense': 27045, 'cash': 343955, 'withholding': 95312, 'benefits': 22345}], ['sample 5', {'gross': [['ann', 50000], ['cy', 1234], ['di', 1234], ['ann', 200000]], 'ytd': {'ann': 0, 'cy': 17000000, 'di': 16800000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'ann': 0, 'cy': 5000, 'di': 5000}}, {'wage_expense': 252468, 'tax_expense': 19238, 'cash': 198984, 'withholding': 62722, 'benefits': 10000}], ['sample 6', {'gross': [['bob', 1234], ['cy', 333333], ['bob', 80000]], 'ytd': {'bob': 0, 'cy': 15000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'bob': 12345, 'cy': 0}}, {'wage_expense': 414567, 'tax_expense': 31715, 'cash': 319174, 'withholding': 102418, 'benefits': 24690}]], [['regression: withholding liability', {'gross': [['ann', 1234], ['bob', 100000], ['di', 50000], ['ann', 80000]], 'ytd': {'ann': 15000000, 'bob': 0, 'di': 17000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'ann': 0, 'bob': 12345, 'di': 12345}}, {'wage_expense': 231234, 'tax_expense': 14590, 'cash': 146515, 'withholding': 74619, 'benefits': 24690}], ['sample 1', {'gross': [['cy', 50000], ['ann', 50000], ['di', 333333]], 'ytd': {'cy': 16700000, 'ann': 15000000, 'di': 0}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'cy': 0, 'ann': 12345, 'di': 12345}}, {'wage_expense': 433333, 'tax_expense': 33150, 'cash': 334628, 'withholding': 107165, 'benefits': 24690}], ['sample 2', {'gross': [['bob', 100000], ['ann', 250000]], 'ytd': {'bob': 15000000, 'ann': 15000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'bob': 12345, 'ann': 5000}}, {'wage_expense': 350000, 'tax_expense': 26775, 'cash': 272614, 'withholding': 86816, 'benefits': 17345}], ['sample 3', {'gross': [['di', 100000], ['cy', 50000]], 'ytd': {'di': 16800000, 'cy': 16800000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'di': 12345, 'cy': 5000}}, {'wage_expense': 150000, 'tax_expense': 8995, 'cash': 94476, 'withholding': 47174, 'benefits': 17345}], ['sample 4', {'gross': [['ann', 1234], ['bob', 1234], ['cy', 1234], ['ann', 80000]], 'ytd': {'ann': 0, 'bob': 16800000, 'cy': 17000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1200, 'benefit': {'ann': 12345, 'bob': 0, 'cy': 5000}}, {'wage_expense': 83702, 'tax_expense': 6328, 'cash': 41202, 'withholding': 19138, 'benefits': 29690}], ['sample 5', {'gross': [['cy', 333333], ['ann', 333333]], 'ytd': {'cy': 0, 'ann': 16700000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'cy': 12345, 'ann': 5000}}, {'wage_expense': 666666, 'tax_expense': 40253, 'cash': 466218, 'withholding': 223356, 'benefits': 17345}], ['sample 6', {'gross': [['bob', 50000], ['bob', 80000]], 'ytd': {'bob': 15000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'bob': 0}}, {'wage_expense': 130000, 'tax_expense': 9945, 'cash': 91455, 'withholding': 48490, 'benefits': 0}]], [['regression: withholding liability', {'gross': [['ann', 250000], ['di', 333333], ['ann', 200000]], 'ytd': {'ann': 17000000, 'di': 15000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'ann': 5000, 'di': 12345}}, {'wage_expense': 783333, 'tax_expense': 32025, 'cash': 652864, 'withholding': 140149, 'benefits': 22345}], ['sample 1', {'gross': [['ann', 50000], ['cy', 50000], ['bob', 100000]], 'ytd': {'ann': 0, 'cy': 0, 'bob': 0}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1200, 'benefit': {'ann': 5000, 'cy': 5000, 'bob': 5000}}, {'wage_expense': 200000, 'tax_expense': 15300, 'cash': 147500, 'withholding': 52800, 'benefits': 15000}], ['sample 2', {'gross': [['ann', 333333]], 'ytd': {'ann': 17000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'ann': 12345}}, {'wage_expense': 333333, 'tax_expense': 4833, 'cash': 284056, 'withholding': 41765, 'benefits': 12345}], ['sample 3', {'gross': [['di', 250000], ['ann', 250000], ['di', 200000]], 'ytd': {'di': 16800000, 'ann': 0}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1200, 'benefit': {'di': 12345, 'ann': 5000}}, {'wage_expense': 700000, 'tax_expense': 29370, 'cash': 560502, 'withholding': 139178, 'benefits': 29690}], ['sample 4', {'gross': [['di', 50000], ['cy', 50000]], 'ytd': {'di': 16800000, 'cy': 0}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1200, 'benefit': {'di': 5000, 'cy': 5000}}, {'wage_expense': 100000, 'tax_expense': 7650, 'cash': 71550, 'withholding': 26100, 'benefits': 10000}], ['sample 5', {'gross': [['di', 250000], ['bob', 100000], ['cy', 1234], ['di', 200000]], 'ytd': {'di': 17000000, 'bob': 15000000, 'cy': 0}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'di': 0, 'bob': 12345, 'cy': 5000}}, {'wage_expense': 551234, 'tax_expense': 14270, 'cash': 402164, 'withholding': 145995, 'benefits': 17345}], ['sample 6', {'gross': [['cy', 250000]], 'ytd': {'cy': 0}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1200, 'benefit': {'cy': 0}}, {'wage_expense': 250000, 'tax_expense': 19125, 'cash': 200875, 'withholding': 68250, 'benefits': 0}]], [['regression: withholding liability', {'gross': [['bob', 100000]], 'ytd': {'bob': 15000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'bob': 5000}}, {'wage_expense': 100000, 'tax_expense': 7650, 'cash': 77850, 'withholding': 24800, 'benefits': 5000}], ['sample 1', {'gross': [['ann', 100000], ['bob', 100000], ['cy', 250000]], 'ytd': {'ann': 16700000, 'bob': 17000000, 'cy': 16700000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'ann': 12345, 'bob': 5000, 'cy': 0}}, {'wage_expense': 450000, 'tax_expense': 22645, 'cash': 314826, 'withholding': 140474, 'benefits': 17345}], ['sample 2', {'gross': [['bob', 1234], ['cy', 100000], ['ann', 100000], ['bob', 80000]], 'ytd': {'bob': 16800000, 'cy': 0, 'ann': 17000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1200, 'benefit': {'bob': 0, 'cy': 12345, 'ann': 5000}}, {'wage_expense': 281234, 'tax_expense': 13998, 'cash': 218224, 'withholding': 59663, 'benefits': 17345}], ['sample 3', {'gross': [['cy', 100000]], 'ytd': {'cy': 0}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'cy': 5000}}, {'wage_expense': 100000, 'tax_expense': 7650, 'cash': 77850, 'withholding': 24800, 'benefits': 5000}], ['sample 4', {'gross': [['di', 100000], ['bob', 333333]], 'ytd': {'di': 0, 'bob': 16700000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'di': 0, 'bob': 12345}}, {'wage_expense': 433333, 'tax_expense': 22403, 'cash': 356486, 'withholding': 86905, 'benefits': 12345}], ['sample 5', {'gross': [['bob', 333333], ['di', 250000], ['ann', 50000], ['bob', 80000]], 'ytd': {'bob': 0, 'di': 16700000, 'ann': 16700000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'bob': 12345, 'di': 0, 'ann': 5000}}, {'wage_expense': 713333, 'tax_expense': 48990, 'cash': 566288, 'withholding': 166345, 'benefits': 29690}], ['sample 6', {'gross': [['bob', 333333]], 'ytd': {'bob': 16700000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'bob': 5000}}, {'wage_expense': 333333, 'tax_expense': 14753, 'cash': 241347, 'withholding': 101739, 'benefits': 5000}]], [['regression: withholding liability', {'gross': [['ann', 333333], ['bob', 250000], ['cy', 1234]], 'ytd': {'ann': 0, 'bob': 16700000, 'cy': 16800000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'ann': 5000, 'bob': 12345, 'cy': 0}}, {'wage_expense': 584567, 'tax_expense': 39140, 'cash': 403294, 'withholding': 203068, 'benefits': 17345}], ['sample 1', {'gross': [['di', 1234], ['bob', 333333], ['di', 80000]], 'ytd': {'di': 15000000, 'bob': 0}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'di': 0, 'bob': 0}}, {'wage_expense': 414567, 'tax_expense': 31715, 'cash': 291648, 'withholding': 154634, 'benefits': 0}], ['sample 2', {'gross': [['di', 250000], ['di', 80000]], 'ytd': {'di': 0}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1200, 'benefit': {'di': 5000}}, {'wage_expense': 330000, 'tax_expense': 25245, 'cash': 256355, 'withholding': 88890, 'benefits': 10000}], ['sample 3', {'gross': [['di', 333333], ['bob', 100000], ['ann', 250000], ['di', 200000]], 'ytd': {'di': 17000000, 'bob': 17000000, 'ann': 16700000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'di': 5000, 'bob': 12345, 'ann': 12345}}, {'wage_expense': 883333, 'tax_expense': 22728, 'cash': 741050, 'withholding': 130321, 'benefits': 34690}], ['sample 4', {'gross': [['bob', 50000], ['bob', 200000]], 'ytd': {'bob': 16800000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'bob': 5000}}, {'wage_expense': 250000, 'tax_expense': 7345, 'cash': 208655, 'withholding': 38690, 'benefits': 10000}], ['sample 5', {'gross': [['bob', 100000], ['cy', 50000], ['ann', 100000]], 'ytd': {'bob': 15000000, 'cy': 16700000, 'ann': 16800000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'bob': 0, 'cy': 5000, 'ann': 12345}}, {'wage_expense': 250000, 'tax_expense': 16645, 'cash': 192744, 'withholding': 56556, 'benefits': 17345}], ['sample 6', {'gross': [['di', 1234]], 'ytd': {'di': 0}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1200, 'benefit': {'di': 5000}}, {'wage_expense': 1234, 'tax_expense': 95, 'cash': -3409, 'withholding': -262, 'benefits': 5000}]]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'raised ' + type(exc).__name__
    check(label, actual, 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):
    def rnd(n, d):
        q, r = divmod(n, d)
        return q + (1 if 2 * r >= d else 0)
    ytd = dict(x['ytd'])
    wage = tax_exp = cash = withholding = benefits = 0
    for emp, g in x['gross']:
        ben = x['benefit'].get(emp, 0)
        social = min(g, max(0, x['wage_base'] - ytd.get(emp, 0)))
        ytd[emp] = ytd.get(emp, 0) + g
        ss = rnd(social * x['ss_bp'], 10000)
        med = rnd(g * x['med_bp'], 10000)
        itax = rnd((g - ben) * x['itax_bp'], 10000)
        employer = ss + med
        wage += g
        tax_exp += employer
        cash += g - ss - med - itax - ben
        withholding += 2 * (ss + med + itax)
        benefits += ben
    return {'wage_expense': wage, 'tax_expense': tax_exp, 'cash': cash, 'withholding': withholding, 'benefits': benefits}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: withholding liability', {'gross': [['di', 1234], ['cy', 50000], ['bob', 50000], ['di', 80000]], 'ytd': {'di': 15000000, 'cy': 16800000, 'bob': 16800000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'di': 12345, 'cy': 0, 'bob': 5000}}, {'wage_expense': 181234, 'tax_expense': 13865, 'cash': 104339, 'withholding': 61070, 'benefits': 29690}], ['sample 1', {'gross': [['bob', 100000]], 'ytd': {'bob': 16800000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1200, 'benefit': {'bob': 5000}}, {'wage_expense': 100000, 'tax_expense': 5170, 'cash': 78430, 'withholding': 21740, 'benefits': 5000}], ['sample 2', {'gross': [['bob', 100000], ['ann', 250000], ['bob', 80000]], 'ytd': {'bob': 0, 'ann': 15000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'bob': 5000, 'ann': 0}}, {'wage_expense': 430000, 'tax_expense': 32895, 'cash': 294705, 'withholding': 158190, 'benefits': 10000}], ['sample 3', {'gross': [['di', 50000], ['ann', 50000], ['cy', 1234]], 'ytd': {'di': 16800000, 'ann': 16800000, 'cy': 0}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'di': 12345, 'ann': 0, 'cy': 5000}}, {'wage_expense': 101234, 'tax_expense': 7745, 'cash': 67755, 'withholding': 23879, 'benefits': 17345}], ['sample 4', {'gross': [['ann', 333333], ['di', 100000], ['bob', 1234]], 'ytd': {'ann': 0, 'di': 17000000, 'bob': 16800000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'ann': 12345, 'di': 5000, 'bob': 5000}}, {'wage_expense': 434567, 'tax_expense': 27045, 'cash': 343955, 'withholding': 95312, 'benefits': 22345}], ['sample 5', {'gross': [['ann', 50000], ['cy', 1234], ['di', 1234], ['ann', 200000]], 'ytd': {'ann': 0, 'cy': 17000000, 'di': 16800000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'ann': 0, 'cy': 5000, 'di': 5000}}, {'wage_expense': 252468, 'tax_expense': 19238, 'cash': 198984, 'withholding': 62722, 'benefits': 10000}], ['sample 6', {'gross': [['bob', 1234], ['cy', 333333], ['bob', 80000]], 'ytd': {'bob': 0, 'cy': 15000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'bob': 12345, 'cy': 0}}, {'wage_expense': 414567, 'tax_expense': 31715, 'cash': 319174, 'withholding': 102418, 'benefits': 24690}]], [['regression: withholding liability', {'gross': [['ann', 1234], ['bob', 100000], ['di', 50000], ['ann', 80000]], 'ytd': {'ann': 15000000, 'bob': 0, 'di': 17000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'ann': 0, 'bob': 12345, 'di': 12345}}, {'wage_expense': 231234, 'tax_expense': 14590, 'cash': 146515, 'withholding': 74619, 'benefits': 24690}], ['sample 1', {'gross': [['cy', 50000], ['ann', 50000], ['di', 333333]], 'ytd': {'cy': 16700000, 'ann': 15000000, 'di': 0}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'cy': 0, 'ann': 12345, 'di': 12345}}, {'wage_expense': 433333, 'tax_expense': 33150, 'cash': 334628, 'withholding': 107165, 'benefits': 24690}], ['sample 2', {'gross': [['bob', 100000], ['ann', 250000]], 'ytd': {'bob': 15000000, 'ann': 15000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'bob': 12345, 'ann': 5000}}, {'wage_expense': 350000, 'tax_expense': 26775, 'cash': 272614, 'withholding': 86816, 'benefits': 17345}], ['sample 3', {'gross': [['di', 100000], ['cy', 50000]], 'ytd': {'di': 16800000, 'cy': 16800000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'di': 12345, 'cy': 5000}}, {'wage_expense': 150000, 'tax_expense': 8995, 'cash': 94476, 'withholding': 47174, 'benefits': 17345}], ['sample 4', {'gross': [['ann', 1234], ['bob', 1234], ['cy', 1234], ['ann', 80000]], 'ytd': {'ann': 0, 'bob': 16800000, 'cy': 17000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1200, 'benefit': {'ann': 12345, 'bob': 0, 'cy': 5000}}, {'wage_expense': 83702, 'tax_expense': 6328, 'cash': 41202, 'withholding': 19138, 'benefits': 29690}], ['sample 5', {'gross': [['cy', 333333], ['ann', 333333]], 'ytd': {'cy': 0, 'ann': 16700000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'cy': 12345, 'ann': 5000}}, {'wage_expense': 666666, 'tax_expense': 40253, 'cash': 466218, 'withholding': 223356, 'benefits': 17345}], ['sample 6', {'gross': [['bob', 50000], ['bob', 80000]], 'ytd': {'bob': 15000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'bob': 0}}, {'wage_expense': 130000, 'tax_expense': 9945, 'cash': 91455, 'withholding': 48490, 'benefits': 0}]], [['regression: withholding liability', {'gross': [['ann', 250000], ['di', 333333], ['ann', 200000]], 'ytd': {'ann': 17000000, 'di': 15000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'ann': 5000, 'di': 12345}}, {'wage_expense': 783333, 'tax_expense': 32025, 'cash': 652864, 'withholding': 140149, 'benefits': 22345}], ['sample 1', {'gross': [['ann', 50000], ['cy', 50000], ['bob', 100000]], 'ytd': {'ann': 0, 'cy': 0, 'bob': 0}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1200, 'benefit': {'ann': 5000, 'cy': 5000, 'bob': 5000}}, {'wage_expense': 200000, 'tax_expense': 15300, 'cash': 147500, 'withholding': 52800, 'benefits': 15000}], ['sample 2', {'gross': [['ann', 333333]], 'ytd': {'ann': 17000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'ann': 12345}}, {'wage_expense': 333333, 'tax_expense': 4833, 'cash': 284056, 'withholding': 41765, 'benefits': 12345}], ['sample 3', {'gross': [['di', 250000], ['ann', 250000], ['di', 200000]], 'ytd': {'di': 16800000, 'ann': 0}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1200, 'benefit': {'di': 12345, 'ann': 5000}}, {'wage_expense': 700000, 'tax_expense': 29370, 'cash': 560502, 'withholding': 139178, 'benefits': 29690}], ['sample 4', {'gross': [['di', 50000], ['cy', 50000]], 'ytd': {'di': 16800000, 'cy': 0}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1200, 'benefit': {'di': 5000, 'cy': 5000}}, {'wage_expense': 100000, 'tax_expense': 7650, 'cash': 71550, 'withholding': 26100, 'benefits': 10000}], ['sample 5', {'gross': [['di', 250000], ['bob', 100000], ['cy', 1234], ['di', 200000]], 'ytd': {'di': 17000000, 'bob': 15000000, 'cy': 0}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'di': 0, 'bob': 12345, 'cy': 5000}}, {'wage_expense': 551234, 'tax_expense': 14270, 'cash': 402164, 'withholding': 145995, 'benefits': 17345}], ['sample 6', {'gross': [['cy', 250000]], 'ytd': {'cy': 0}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1200, 'benefit': {'cy': 0}}, {'wage_expense': 250000, 'tax_expense': 19125, 'cash': 200875, 'withholding': 68250, 'benefits': 0}]], [['regression: withholding liability', {'gross': [['bob', 100000]], 'ytd': {'bob': 15000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'bob': 5000}}, {'wage_expense': 100000, 'tax_expense': 7650, 'cash': 77850, 'withholding': 24800, 'benefits': 5000}], ['sample 1', {'gross': [['ann', 100000], ['bob', 100000], ['cy', 250000]], 'ytd': {'ann': 16700000, 'bob': 17000000, 'cy': 16700000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'ann': 12345, 'bob': 5000, 'cy': 0}}, {'wage_expense': 450000, 'tax_expense': 22645, 'cash': 314826, 'withholding': 140474, 'benefits': 17345}], ['sample 2', {'gross': [['bob', 1234], ['cy', 100000], ['ann', 100000], ['bob', 80000]], 'ytd': {'bob': 16800000, 'cy': 0, 'ann': 17000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1200, 'benefit': {'bob': 0, 'cy': 12345, 'ann': 5000}}, {'wage_expense': 281234, 'tax_expense': 13998, 'cash': 218224, 'withholding': 59663, 'benefits': 17345}], ['sample 3', {'gross': [['cy', 100000]], 'ytd': {'cy': 0}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'cy': 5000}}, {'wage_expense': 100000, 'tax_expense': 7650, 'cash': 77850, 'withholding': 24800, 'benefits': 5000}], ['sample 4', {'gross': [['di', 100000], ['bob', 333333]], 'ytd': {'di': 0, 'bob': 16700000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'di': 0, 'bob': 12345}}, {'wage_expense': 433333, 'tax_expense': 22403, 'cash': 356486, 'withholding': 86905, 'benefits': 12345}], ['sample 5', {'gross': [['bob', 333333], ['di', 250000], ['ann', 50000], ['bob', 80000]], 'ytd': {'bob': 0, 'di': 16700000, 'ann': 16700000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'bob': 12345, 'di': 0, 'ann': 5000}}, {'wage_expense': 713333, 'tax_expense': 48990, 'cash': 566288, 'withholding': 166345, 'benefits': 29690}], ['sample 6', {'gross': [['bob', 333333]], 'ytd': {'bob': 16700000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'bob': 5000}}, {'wage_expense': 333333, 'tax_expense': 14753, 'cash': 241347, 'withholding': 101739, 'benefits': 5000}]], [['regression: withholding liability', {'gross': [['ann', 333333], ['bob', 250000], ['cy', 1234]], 'ytd': {'ann': 0, 'bob': 16700000, 'cy': 16800000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'ann': 5000, 'bob': 12345, 'cy': 0}}, {'wage_expense': 584567, 'tax_expense': 39140, 'cash': 403294, 'withholding': 203068, 'benefits': 17345}], ['sample 1', {'gross': [['di', 1234], ['bob', 333333], ['di', 80000]], 'ytd': {'di': 15000000, 'bob': 0}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'di': 0, 'bob': 0}}, {'wage_expense': 414567, 'tax_expense': 31715, 'cash': 291648, 'withholding': 154634, 'benefits': 0}], ['sample 2', {'gross': [['di', 250000], ['di', 80000]], 'ytd': {'di': 0}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1200, 'benefit': {'di': 5000}}, {'wage_expense': 330000, 'tax_expense': 25245, 'cash': 256355, 'withholding': 88890, 'benefits': 10000}], ['sample 3', {'gross': [['di', 333333], ['bob', 100000], ['ann', 250000], ['di', 200000]], 'ytd': {'di': 17000000, 'bob': 17000000, 'ann': 16700000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'di': 5000, 'bob': 12345, 'ann': 12345}}, {'wage_expense': 883333, 'tax_expense': 22728, 'cash': 741050, 'withholding': 130321, 'benefits': 34690}], ['sample 4', {'gross': [['bob', 50000], ['bob', 200000]], 'ytd': {'bob': 16800000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'bob': 5000}}, {'wage_expense': 250000, 'tax_expense': 7345, 'cash': 208655, 'withholding': 38690, 'benefits': 10000}], ['sample 5', {'gross': [['bob', 100000], ['cy', 50000], ['ann', 100000]], 'ytd': {'bob': 15000000, 'cy': 16700000, 'ann': 16800000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'bob': 0, 'cy': 5000, 'ann': 12345}}, {'wage_expense': 250000, 'tax_expense': 16645, 'cash': 192744, 'withholding': 56556, 'benefits': 17345}], ['sample 6', {'gross': [['di', 1234]], 'ytd': {'di': 0}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1200, 'benefit': {'di': 5000}}, {'wage_expense': 1234, 'tax_expense': 95, 'cash': -3409, 'withholding': -262, 'benefits': 5000}]]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'raised ' + type(exc).__name__
    check(label, actual, expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The payroll entry does not balance; employer taxes have no liability.

x = {'gross': [[employee, cents]] (an employee may appear twice), 'ytd': prior year-to-date gross, 'wage_base', 'ss_bp', 'med_bp', 'itax_bp', 'benefit': {employee: pre-tax deduction per paycheck}}. Per paycheck: social wages = min(gross, max(0, wage_base - ytd)), ytd then increases by gross; social tax = round(social wages * ss_bp / 10000), medicare = round(gross * med_bp / 10000) (no cap), income tax = round((gross - benefit) * itax_bp / 10000), all half-up; net = gross - social - medicare - income tax - benefit. The employer matches social and medicare. Return {'wage_expense', 'tax_expense', 'cash', 'withholding', 'benefits'} where withholding holds employee and employer taxes.

split: open-access


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

N = 1
observations = []
def solve(x):
    def rnd(n, d):
        q, r = divmod(n, d)
        return q + (1 if 2 * r >= d else 0)
    ytd = dict(x['ytd'])
    wage = tax_exp = cash = withholding = benefits = 0
    for emp, g in x['gross']:
        ben = x['benefit'].get(emp, 0)
        social = min(g, max(0, x['wage_base'] - ytd.get(emp, 0)))
        ytd[emp] = ytd.get(emp, 0) + g
        ss = rnd(social * x['ss_bp'], 10000)
        med = rnd(g * x['med_bp'], 10000)
        itax = rnd(g * x['itax_bp'], 10000)
        employer = ss + med
        wage += g
        tax_exp += employer
        cash += g - ss - med - itax - ben
        withholding += ss + med + itax + employer
        benefits += ben
    return {'wage_expense': wage, 'tax_expense': tax_exp, 'cash': cash, 'withholding': withholding, 'benefits': benefits}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: pre-tax deduction scope', {'gross': [['di', 1234], ['cy', 50000], ['bob', 50000], ['di', 80000]], 'ytd': {'di': 15000000, 'cy': 16800000, 'bob': 16800000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'di': 12345, 'cy': 0, 'bob': 5000}}, {'wage_expense': 181234, 'tax_expense': 13865, 'cash': 104339, 'withholding': 61070, 'benefits': 29690}], ['control 1', {'gross': [['ann', 333333], ['ann', 200000]], 'ytd': {'ann': 17000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1200, 'benefit': {'ann': 0}}, {'wage_expense': 533333, 'tax_expense': 7733, 'cash': 461600, 'withholding': 79466, 'benefits': 0}], ['control 2', {'gross': [['ann', 250000]], 'ytd': {'ann': 17000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'ann': 0}}, {'wage_expense': 250000, 'tax_expense': 3625, 'cash': 191375, 'withholding': 62250, 'benefits': 0}], ['control 3', {'gross': [['cy', 100000], ['bob', 1234]], 'ytd': {'cy': 17000000, 'bob': 16800000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'cy': 0, 'bob': 0}}, {'wage_expense': 101234, 'tax_expense': 1545, 'cash': 89566, 'withholding': 13213, 'benefits': 0}], ['control 4', {'gross': [['bob', 333333]], 'ytd': {'bob': 16800000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1200, 'benefit': {'bob': 0}}, {'wage_expense': 333333, 'tax_expense': 8553, 'cash': 284780, 'withholding': 57106, 'benefits': 0}], ['control 5', {'gross': [['cy', 333333], ['ann', 50000], ['bob', 100000]], 'ytd': {'cy': 15000000, 'ann': 16800000, 'bob': 15000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'cy': 0, 'ann': 0, 'bob': 0}}, {'wage_expense': 483333, 'tax_expense': 36975, 'cash': 340025, 'withholding': 180283, 'benefits': 0}], ['control 6', {'gross': [['cy', 250000], ['cy', 80000]], 'ytd': {'cy': 16700000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'cy': 0}}, {'wage_expense': 330000, 'tax_expense': 14705, 'cash': 242695, 'withholding': 102010, 'benefits': 0}]], [['regression: pre-tax deduction scope', {'gross': [['ann', 1234], ['bob', 100000], ['di', 50000], ['ann', 80000]], 'ytd': {'ann': 15000000, 'bob': 0, 'di': 17000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'ann': 0, 'bob': 12345, 'di': 12345}}, {'wage_expense': 231234, 'tax_expense': 14590, 'cash': 146515, 'withholding': 74619, 'benefits': 24690}], ['control 1', {'gross': [['bob', 50000], ['bob', 80000]], 'ytd': {'bob': 15000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'bob': 0}}, {'wage_expense': 130000, 'tax_expense': 9945, 'cash': 91455, 'withholding': 48490, 'benefits': 0}], ['control 2', {'gross': [['cy', 50000], ['cy', 80000]], 'ytd': {'cy': 15000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'cy': 0}}, {'wage_expense': 130000, 'tax_expense': 9945, 'cash': 91455, 'withholding': 48490, 'benefits': 0}], ['control 3', {'gross': [['cy', 250000], ['bob', 333333]], 'ytd': {'cy': 16800000, 'bob': 16800000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1200, 'benefit': {'cy': 0, 'bob': 0}}, {'wage_expense': 583333, 'tax_expense': 15898, 'cash': 497435, 'withholding': 101796, 'benefits': 0}], ['control 4', {'gross': [['ann', 1234], ['di', 333333], ['bob', 50000], ['ann', 80000]], 'ytd': {'ann': 16800000, 'di': 15000000, 'bob': 0}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'ann': 0, 'di': 0, 'bob': 0}}, {'wage_expense': 464567, 'tax_expense': 34223, 'cash': 383888, 'withholding': 114902, 'benefits': 0}], ['control 5', {'gross': [['cy', 50000]], 'ytd': {'cy': 16700000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'cy': 0}}, {'wage_expense': 50000, 'tax_expense': 3825, 'cash': 35175, 'withholding': 18650, 'benefits': 0}], ['control 6', {'gross': [['di', 333333], ['di', 80000]], 'ytd': {'di': 15000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'di': 0}}, {'wage_expense': 413333, 'tax_expense': 31620, 'cash': 290780, 'withholding': 154173, 'benefits': 0}]], [['regression: pre-tax deduction scope', {'gross': [['ann', 250000], ['di', 333333], ['ann', 200000]], 'ytd': {'ann': 17000000, 'di': 15000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'ann': 5000, 'di': 12345}}, {'wage_expense': 783333, 'tax_expense': 32025, 'cash': 652864, 'withholding': 140149, 'benefits': 22345}], ['control 1', {'gross': [['cy', 250000]], 'ytd': {'cy': 0}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1200, 'benefit': {'cy': 0}}, {'wage_expense': 250000, 'tax_expense': 19125, 'cash': 200875, 'withholding': 68250, 'benefits': 0}], ['control 2', {'gross': [['cy', 250000], ['cy', 200000]], 'ytd': {'cy': 16800000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'cy': 0}}, {'wage_expense': 450000, 'tax_expense': 10245, 'cash': 340755, 'withholding': 119490, 'benefits': 0}], ['control 3', {'gross': [['ann', 250000], ['ann', 200000]], 'ytd': {'ann': 16700000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'ann': 0}}, {'wage_expense': 450000, 'tax_expense': 16445, 'cash': 388555, 'withholding': 77890, 'benefits': 0}], ['control 4', {'gross': [['ann', 50000], ['ann', 80000]], 'ytd': {'ann': 0}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'ann': 0}}, {'wage_expense': 130000, 'tax_expense': 9945, 'cash': 107055, 'withholding': 32890, 'benefits': 0}], ['control 5', {'gross': [['bob', 333333], ['di', 1234]], 'ytd': {'bob': 15000000, 'di': 17000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'bob': 0, 'di': 0}}, {'wage_expense': 334567, 'tax_expense': 25518, 'cash': 275593, 'withholding': 84492, 'benefits': 0}], ['control 6', {'gross': [['bob', 100000]], 'ytd': {'bob': 15000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1200, 'benefit': {'bob': 0}}, {'wage_expense': 100000, 'tax_expense': 7650, 'cash': 80350, 'withholding': 27300, 'benefits': 0}]], [['regression: pre-tax deduction scope', {'gross': [['bob', 100000]], 'ytd': {'bob': 15000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'bob': 5000}}, {'wage_expense': 100000, 'tax_expense': 7650, 'cash': 77850, 'withholding': 24800, 'benefits': 5000}], ['control 1', {'gross': [['ann', 100000]], 'ytd': {'ann': 16800000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1200, 'benefit': {'ann': 0}}, {'wage_expense': 100000, 'tax_expense': 5170, 'cash': 82830, 'withholding': 22340, 'benefits': 0}], ['control 2', {'gross': [['bob', 250000], ['bob', 80000]], 'ytd': {'bob': 16800000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'bob': 0}}, {'wage_expense': 330000, 'tax_expense': 8505, 'cash': 248895, 'withholding': 89610, 'benefits': 0}], ['control 3', {'gross': [['di', 333333], ['di', 80000]], 'ytd': {'di': 16700000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'di': 0}}, {'wage_expense': 413333, 'tax_expense': 15913, 'cash': 306487, 'withholding': 122759, 'benefits': 0}], ['control 4', {'gross': [['cy', 100000]], 'ytd': {'cy': 16800000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'cy': 0}}, {'wage_expense': 100000, 'tax_expense': 5170, 'cash': 72830, 'withholding': 32340, 'benefits': 0}], ['control 5', {'gross': [['di', 1234]], 'ytd': {'di': 0}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'di': 0}}, {'wage_expense': 1234, 'tax_expense': 95, 'cash': 1016, 'withholding': 313, 'benefits': 0}], ['control 6', {'gross': [['ann', 1234], ['ann', 80000]], 'ytd': {'ann': 17000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'ann': 0}}, {'wage_expense': 81234, 'tax_expense': 1178, 'cash': 71933, 'withholding': 10479, 'benefits': 0}]], [['regression: pre-tax deduction scope', {'gross': [['ann', 333333], ['bob', 250000], ['cy', 1234]], 'ytd': {'ann': 0, 'bob': 16700000, 'cy': 16800000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'ann': 5000, 'bob': 12345, 'cy': 0}}, {'wage_expense': 584567, 'tax_expense': 39140, 'cash': 403294, 'withholding': 203068, 'benefits': 17345}], ['control 1', {'gross': [['di', 1234], ['bob', 333333], ['di', 80000]], 'ytd': {'di': 15000000, 'bob': 0}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'di': 0, 'bob': 0}}, {'wage_expense': 414567, 'tax_expense': 31715, 'cash': 291648, 'withholding': 154634, 'benefits': 0}], ['control 2', {'gross': [['bob', 333333], ['bob', 200000]], 'ytd': {'bob': 0}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'bob': 0}}, {'wage_expense': 533333, 'tax_expense': 40800, 'cash': 439200, 'withholding': 134933, 'benefits': 0}], ['control 3', {'gross': [['bob', 100000], ['ann', 100000], ['bob', 200000]], 'ytd': {'bob': 16800000, 'ann': 16700000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'bob': 0, 'ann': 0}}, {'wage_expense': 400000, 'tax_expense': 15720, 'cash': 296280, 'withholding': 119440, 'benefits': 0}], ['control 4', {'gross': [['di', 1234], ['di', 80000]], 'ytd': {'di': 0}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1200, 'benefit': {'di': 0}}, {'wage_expense': 81234, 'tax_expense': 6215, 'cash': 65271, 'withholding': 22178, 'benefits': 0}], ['control 5', {'gross': [['cy', 100000], ['di', 50000], ['bob', 250000]], 'ytd': {'cy': 16800000, 'di': 16800000, 'bob': 0}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'cy': 0, 'di': 0, 'bob': 0}}, {'wage_expense': 400000, 'tax_expense': 28120, 'cash': 283880, 'withholding': 144240, 'benefits': 0}], ['control 6', {'gross': [['di', 250000]], 'ytd': {'di': 17000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'di': 0}}, {'wage_expense': 250000, 'tax_expense': 3625, 'cash': 191375, 'withholding': 62250, 'benefits': 0}]]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'raised ' + type(exc).__name__
    check(label, actual, 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):
    def rnd(n, d):
        q, r = divmod(n, d)
        return q + (1 if 2 * r >= d else 0)
    ytd = dict(x['ytd'])
    wage = tax_exp = cash = withholding = benefits = 0
    for emp, g in x['gross']:
        ben = x['benefit'].get(emp, 0)
        social = min(g - ben, max(0, x['wage_base'] - ytd.get(emp, 0)))
        ytd[emp] = ytd.get(emp, 0) + g
        ss = rnd(social * x['ss_bp'], 10000)
        med = rnd(g * x['med_bp'], 10000)
        itax = rnd(g * x['itax_bp'], 10000)
        employer = ss + med
        wage += g
        tax_exp += employer
        cash += g - ss - med - itax - ben
        withholding += ss + med + itax + employer
        benefits += ben
    return {'wage_expense': wage, 'tax_expense': tax_exp, 'cash': cash, 'withholding': withholding, 'benefits': benefits}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: pre-tax deduction scope', {'gross': [['di', 1234], ['cy', 50000], ['bob', 50000], ['di', 80000]], 'ytd': {'di': 15000000, 'cy': 16800000, 'bob': 16800000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'di': 12345, 'cy': 0, 'bob': 5000}}, {'wage_expense': 181234, 'tax_expense': 13865, 'cash': 104339, 'withholding': 61070, 'benefits': 29690}], ['control 1', {'gross': [['ann', 333333], ['ann', 200000]], 'ytd': {'ann': 17000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1200, 'benefit': {'ann': 0}}, {'wage_expense': 533333, 'tax_expense': 7733, 'cash': 461600, 'withholding': 79466, 'benefits': 0}], ['control 2', {'gross': [['ann', 250000]], 'ytd': {'ann': 17000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'ann': 0}}, {'wage_expense': 250000, 'tax_expense': 3625, 'cash': 191375, 'withholding': 62250, 'benefits': 0}], ['control 3', {'gross': [['cy', 100000], ['bob', 1234]], 'ytd': {'cy': 17000000, 'bob': 16800000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'cy': 0, 'bob': 0}}, {'wage_expense': 101234, 'tax_expense': 1545, 'cash': 89566, 'withholding': 13213, 'benefits': 0}], ['control 4', {'gross': [['bob', 333333]], 'ytd': {'bob': 16800000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1200, 'benefit': {'bob': 0}}, {'wage_expense': 333333, 'tax_expense': 8553, 'cash': 284780, 'withholding': 57106, 'benefits': 0}], ['control 5', {'gross': [['cy', 333333], ['ann', 50000], ['bob', 100000]], 'ytd': {'cy': 15000000, 'ann': 16800000, 'bob': 15000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'cy': 0, 'ann': 0, 'bob': 0}}, {'wage_expense': 483333, 'tax_expense': 36975, 'cash': 340025, 'withholding': 180283, 'benefits': 0}], ['control 6', {'gross': [['cy', 250000], ['cy', 80000]], 'ytd': {'cy': 16700000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'cy': 0}}, {'wage_expense': 330000, 'tax_expense': 14705, 'cash': 242695, 'withholding': 102010, 'benefits': 0}]], [['regression: pre-tax deduction scope', {'gross': [['ann', 1234], ['bob', 100000], ['di', 50000], ['ann', 80000]], 'ytd': {'ann': 15000000, 'bob': 0, 'di': 17000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'ann': 0, 'bob': 12345, 'di': 12345}}, {'wage_expense': 231234, 'tax_expense': 14590, 'cash': 146515, 'withholding': 74619, 'benefits': 24690}], ['control 1', {'gross': [['bob', 50000], ['bob', 80000]], 'ytd': {'bob': 15000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'bob': 0}}, {'wage_expense': 130000, 'tax_expense': 9945, 'cash': 91455, 'withholding': 48490, 'benefits': 0}], ['control 2', {'gross': [['cy', 50000], ['cy', 80000]], 'ytd': {'cy': 15000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'cy': 0}}, {'wage_expense': 130000, 'tax_expense': 9945, 'cash': 91455, 'withholding': 48490, 'benefits': 0}], ['control 3', {'gross': [['cy', 250000], ['bob', 333333]], 'ytd': {'cy': 16800000, 'bob': 16800000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1200, 'benefit': {'cy': 0, 'bob': 0}}, {'wage_expense': 583333, 'tax_expense': 15898, 'cash': 497435, 'withholding': 101796, 'benefits': 0}], ['control 4', {'gross': [['ann', 1234], ['di', 333333], ['bob', 50000], ['ann', 80000]], 'ytd': {'ann': 16800000, 'di': 15000000, 'bob': 0}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'ann': 0, 'di': 0, 'bob': 0}}, {'wage_expense': 464567, 'tax_expense': 34223, 'cash': 383888, 'withholding': 114902, 'benefits': 0}], ['control 5', {'gross': [['cy', 50000]], 'ytd': {'cy': 16700000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'cy': 0}}, {'wage_expense': 50000, 'tax_expense': 3825, 'cash': 35175, 'withholding': 18650, 'benefits': 0}], ['control 6', {'gross': [['di', 333333], ['di', 80000]], 'ytd': {'di': 15000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'di': 0}}, {'wage_expense': 413333, 'tax_expense': 31620, 'cash': 290780, 'withholding': 154173, 'benefits': 0}]], [['regression: pre-tax deduction scope', {'gross': [['ann', 250000], ['di', 333333], ['ann', 200000]], 'ytd': {'ann': 17000000, 'di': 15000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'ann': 5000, 'di': 12345}}, {'wage_expense': 783333, 'tax_expense': 32025, 'cash': 652864, 'withholding': 140149, 'benefits': 22345}], ['control 1', {'gross': [['cy', 250000]], 'ytd': {'cy': 0}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1200, 'benefit': {'cy': 0}}, {'wage_expense': 250000, 'tax_expense': 19125, 'cash': 200875, 'withholding': 68250, 'benefits': 0}], ['control 2', {'gross': [['cy', 250000], ['cy', 200000]], 'ytd': {'cy': 16800000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'cy': 0}}, {'wage_expense': 450000, 'tax_expense': 10245, 'cash': 340755, 'withholding': 119490, 'benefits': 0}], ['control 3', {'gross': [['ann', 250000], ['ann', 200000]], 'ytd': {'ann': 16700000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'ann': 0}}, {'wage_expense': 450000, 'tax_expense': 16445, 'cash': 388555, 'withholding': 77890, 'benefits': 0}], ['control 4', {'gross': [['ann', 50000], ['ann', 80000]], 'ytd': {'ann': 0}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'ann': 0}}, {'wage_expense': 130000, 'tax_expense': 9945, 'cash': 107055, 'withholding': 32890, 'benefits': 0}], ['control 5', {'gross': [['bob', 333333], ['di', 1234]], 'ytd': {'bob': 15000000, 'di': 17000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'bob': 0, 'di': 0}}, {'wage_expense': 334567, 'tax_expense': 25518, 'cash': 275593, 'withholding': 84492, 'benefits': 0}], ['control 6', {'gross': [['bob', 100000]], 'ytd': {'bob': 15000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1200, 'benefit': {'bob': 0}}, {'wage_expense': 100000, 'tax_expense': 7650, 'cash': 80350, 'withholding': 27300, 'benefits': 0}]], [['regression: pre-tax deduction scope', {'gross': [['bob', 100000]], 'ytd': {'bob': 15000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'bob': 5000}}, {'wage_expense': 100000, 'tax_expense': 7650, 'cash': 77850, 'withholding': 24800, 'benefits': 5000}], ['control 1', {'gross': [['ann', 100000]], 'ytd': {'ann': 16800000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1200, 'benefit': {'ann': 0}}, {'wage_expense': 100000, 'tax_expense': 5170, 'cash': 82830, 'withholding': 22340, 'benefits': 0}], ['control 2', {'gross': [['bob', 250000], ['bob', 80000]], 'ytd': {'bob': 16800000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'bob': 0}}, {'wage_expense': 330000, 'tax_expense': 8505, 'cash': 248895, 'withholding': 89610, 'benefits': 0}], ['control 3', {'gross': [['di', 333333], ['di', 80000]], 'ytd': {'di': 16700000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'di': 0}}, {'wage_expense': 413333, 'tax_expense': 15913, 'cash': 306487, 'withholding': 122759, 'benefits': 0}], ['control 4', {'gross': [['cy', 100000]], 'ytd': {'cy': 16800000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'cy': 0}}, {'wage_expense': 100000, 'tax_expense': 5170, 'cash': 72830, 'withholding': 32340, 'benefits': 0}], ['control 5', {'gross': [['di', 1234]], 'ytd': {'di': 0}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'di': 0}}, {'wage_expense': 1234, 'tax_expense': 95, 'cash': 1016, 'withholding': 313, 'benefits': 0}], ['control 6', {'gross': [['ann', 1234], ['ann', 80000]], 'ytd': {'ann': 17000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'ann': 0}}, {'wage_expense': 81234, 'tax_expense': 1178, 'cash': 71933, 'withholding': 10479, 'benefits': 0}]], [['regression: pre-tax deduction scope', {'gross': [['ann', 333333], ['bob', 250000], ['cy', 1234]], 'ytd': {'ann': 0, 'bob': 16700000, 'cy': 16800000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'ann': 5000, 'bob': 12345, 'cy': 0}}, {'wage_expense': 584567, 'tax_expense': 39140, 'cash': 403294, 'withholding': 203068, 'benefits': 17345}], ['control 1', {'gross': [['di', 1234], ['bob', 333333], ['di', 80000]], 'ytd': {'di': 15000000, 'bob': 0}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'di': 0, 'bob': 0}}, {'wage_expense': 414567, 'tax_expense': 31715, 'cash': 291648, 'withholding': 154634, 'benefits': 0}], ['control 2', {'gross': [['bob', 333333], ['bob', 200000]], 'ytd': {'bob': 0}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1000, 'benefit': {'bob': 0}}, {'wage_expense': 533333, 'tax_expense': 40800, 'cash': 439200, 'withholding': 134933, 'benefits': 0}], ['control 3', {'gross': [['bob', 100000], ['ann', 100000], ['bob', 200000]], 'ytd': {'bob': 16800000, 'ann': 16700000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'bob': 0, 'ann': 0}}, {'wage_expense': 400000, 'tax_expense': 15720, 'cash': 296280, 'withholding': 119440, 'benefits': 0}], ['control 4', {'gross': [['di', 1234], ['di', 80000]], 'ytd': {'di': 0}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 1200, 'benefit': {'di': 0}}, {'wage_expense': 81234, 'tax_expense': 6215, 'cash': 65271, 'withholding': 22178, 'benefits': 0}], ['control 5', {'gross': [['cy', 100000], ['di', 50000], ['bob', 250000]], 'ytd': {'cy': 16800000, 'di': 16800000, 'bob': 0}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'cy': 0, 'di': 0, 'bob': 0}}, {'wage_expense': 400000, 'tax_expense': 28120, 'cash': 283880, 'withholding': 144240, 'benefits': 0}], ['control 6', {'gross': [['di', 250000]], 'ytd': {'di': 17000000}, 'wage_base': 16860000, 'ss_bp': 620, 'med_bp': 145, 'itax_bp': 2200, 'benefit': {'di': 0}}, {'wage_expense': 250000, 'tax_expense': 3625, 'cash': 191375, 'withholding': 62250, 'benefits': 0}]]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'raised ' + type(exc).__name__
    check(label, actual, 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:
Income tax is withheld on benefit contributions that are pre-tax.

x = {'gross': [[employee, cents]] (an employee may appear twice), 'ytd': prior year-to-date gross, 'wage_base', 'ss_bp', 'med_bp', 'itax_bp', 'benefit': {employee: pre-tax deduction per paycheck}}. Per paycheck: social wages = min(gross, max(0, wage_base - ytd)), ytd then increases by gross; social tax = round(social wages * ss_bp / 10000), medicare = round(gross * med_bp / 10000) (no cap), income tax = round((gross - benefit) * itax_bp / 10000), all half-up; net = gross - social - medicare - income tax - benefit. The employer matches social and medicare. Return {'wage_expense', 'tax_expense', 'cash', 'withholding', 'benefits'} where withholding holds employee and employer taxes.

split: open-access


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

N = 1
observations = []
def solve(x):
    def rnd(n, d):
        q, r = divmod(n, d)
        return q + (1 if 2 * r >= d else 0)
    base = x['cost'] - x['salvage']
    life = x['life_months']
    conv = x['convention']
    first = x['start_month'] + (1 if conv != 'full_month' else 0)
    acc = 0
    rows = []
    month = first
    while month <= x['through'] and acc < base:
        j = month - first + 1
        if conv == 'mid_month':
            target = rnd(base * (2 * j - 1), 2 * life)
        else:
            target = rnd(base * j, life)
        target = min(target, base)
        rows.append([month, target - acc])
        acc = target
        month += 1
    return {'schedule': rows, 'accumulated': acc, 'book_value': x['cost'] - acc}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: first charge month', {'cost': 5000, 'salvage': 0, 'life_months': 12, 'start_month': 1, 'convention': 'mid_month', 'through': 80}, {'schedule': [[1, 208], [2, 417], [3, 417], [4, 416], [5, 417], [6, 417], [7, 416], [8, 417], [9, 417], [10, 416], [11, 417], [12, 417], [13, 208]], 'accumulated': 5000, 'book_value': 0}], ['control 1', {'cost': 5000, 'salvage': 12000, 'life_months': 12, 'start_month': 10, 'convention': 'next_month', 'through': 1}, {'schedule': [], 'accumulated': 0, 'book_value': 5000}], ['control 2', {'cost': 120000, 'salvage': 7, 'life_months': 7, 'start_month': 10, 'convention': 'full_month', 'through': 80}, {'schedule': [[10, 17142], [11, 17142], [12, 17142], [13, 17141], [14, 17142], [15, 17142], [16, 17142]], 'accumulated': 119993, 'book_value': 7}], ['control 3', {'cost': 36000, 'salvage': 0, 'life_months': 12, 'start_month': 3, 'convention': 'full_month', 'through': 3}, {'schedule': [[3, 3000]], 'accumulated': 3000, 'book_value': 33000}], ['control 4', {'cost': 120000, 'salvage': 1000, 'life_months': 36, 'start_month': 3, 'convention': 'full_month', 'through': 40}, {'schedule': [[3, 3306], [4, 3305], [5, 3306], [6, 3305], [7, 3306], [8, 3305], [9, 3306], [10, 3305], [11, 3306], [12, 3306], [13, 3305], [14, 3306], [15, 3305], [16, 3306], [17, 3305], [18, 3306], [19, 3305], [20, 3306], [21, 3306], [22, 3305], [23, 3306], [24, 3305], [25, 3306], [26, 3305], [27, 3306], [28, 3305], [29, 3306], [30, 3306], [31, 3305], [32, 3306], [33, 3305], [34, 3306], [35, 3305], [36, 3306], [37, 3305], [38, 3306]], 'accumulated': 119000, 'book_value': 1000}], ['control 5', {'cost': 36000, 'salvage': 12000, 'life_months': 36, 'start_month': 1, 'convention': 'next_month', 'through': 1}, {'schedule': [], 'accumulated': 0, 'book_value': 36000}], ['control 6', {'cost': 99999, 'salvage': 7, 'life_months': 12, 'start_month': 1, 'convention': 'next_month', 'through': 40}, {'schedule': [[2, 8333], [3, 8332], [4, 8333], [5, 8333], [6, 8332], [7, 8333], [8, 8333], [9, 8332], [10, 8333], [11, 8333], [12, 8332], [13, 8333]], 'accumulated': 99992, 'book_value': 7}]], [['regression: first charge month', {'cost': 99999, 'salvage': 12000, 'life_months': 12, 'start_month': 10, 'convention': 'mid_month', 'through': 40}, {'schedule': [[10, 3667], [11, 7333], [12, 7333], [13, 7333], [14, 7334], [15, 7333], [16, 7333], [17, 7333], [18, 7334], [19, 7333], [20, 7333], [21, 7333], [22, 3667]], 'accumulated': 87999, 'book_value': 12000}], ['control 1', {'cost': 99999, 'salvage': 1000, 'life_months': 60, 'start_month': 3, 'convention': 'next_month', 'through': 40}, {'schedule': [[4, 1650], [5, 1650], [6, 1650], [7, 1650], [8, 1650], [9, 1650], [10, 1650], [11, 1650], [12, 1650], [13, 1650], [14, 1650], [15, 1650], [16, 1650], [17, 1650], [18, 1650], [19, 1650], [20, 1650], [21, 1650], [22, 1650], [23, 1650], [24, 1650], [25, 1650], [26, 1650], [27, 1650], [28, 1650], [29, 1650], [30, 1650], [31, 1650], [32, 1650], [33, 1650], [34, 1649], [35, 1650], [36, 1650], [37, 1650], [38, 1650], [39, 1650], [40, 1650]], 'accumulated': 61049, 'book_value': 38950}], ['control 2', {'cost': 36000, 'salvage': 12000, 'life_months': 12, 'start_month': 10, 'convention': 'next_month', 'through': 40}, {'schedule': [[11, 2000], [12, 2000], [13, 2000], [14, 2000], [15, 2000], [16, 2000], [17, 2000], [18, 2000], [19, 2000], [20, 2000], [21, 2000], [22, 2000]], 'accumulated': 24000, 'book_value': 12000}], ['control 3', {'cost': 120000, 'salvage': 1000, 'life_months': 60, 'start_month': 10, 'convention': 'next_month', 'through': 1}, {'schedule': [], 'accumulated': 0, 'book_value': 120000}], ['control 4', {'cost': 36000, 'salvage': 0, 'life_months': 60, 'start_month': 10, 'convention': 'next_month', 'through': 80}, {'schedule': [[11, 600], [12, 600], [13, 600], [14, 600], [15, 600], [16, 600], [17, 600], [18, 600], [19, 600], [20, 600], [21, 600], [22, 600], [23, 600], [24, 600], [25, 600], [26, 600], [27, 600], [28, 600], [29, 600], [30, 600], [31, 600], [32, 600], [33, 600], [34, 600], [35, 600], [36, 600], [37, 600], [38, 600], [39, 600], [40, 600], [41, 600], [42, 600], [43, 600], [44, 600], [45, 600], [46, 600], [47, 600], [48, 600], [49, 600], [50, 600], [51, 600], [52, 600], [53, 600], [54, 600], [55, 600], [56, 600], [57, 600], [58, 600], [59, 600], [60, 600], [61, 600], [62, 600], [63, 600], [64, 600], [65, 600], [66, 600], [67, 600], [68, 600], [69, 600], [70, 600]], 'accumulated': 36000, 'book_value': 0}], ['control 5', {'cost': 100000, 'salvage': 7, 'life_months': 60, 'start_month': 1, 'convention': 'next_month', 'through': 1}, {'schedule': [], 'accumulated': 0, 'book_value': 100000}], ['control 6', {'cost': 36000, 'salvage': 7, 'life_months': 36, 'start_month': 3, 'convention': 'full_month', 'through': 3}, {'schedule': [[3, 1000]], 'accumulated': 1000, 'book_value': 35000}]], [['regression: first charge month', {'cost': 120000, 'salvage': 0, 'life_months': 36, 'start_month': 3, 'convention': 'mid_month', 'through': 40}, {'schedule': [[3, 1667], [4, 3333], [5, 3333], [6, 3334], [7, 3333], [8, 3333], [9, 3334], [10, 3333], [11, 3333], [12, 3334], [13, 3333], [14, 3333], [15, 3334], [16, 3333], [17, 3333], [18, 3334], [19, 3333], [20, 3333], [21, 3334], [22, 3333], [23, 3333], [24, 3334], [25, 3333], [26, 3333], [27, 3334], [28, 3333], [29, 3333], [30, 3334], [31, 3333], [32, 3333], [33, 3334], [34, 3333], [35, 3333], [36, 3334], [37, 3333], [38, 3333], [39, 1667]], 'accumulated': 120000, 'book_value': 0}], ['control 1', {'cost': 36000, 'salvage': 0, 'life_months': 7, 'start_month': 3, 'convention': 'mid_month', 'through': 1}, {'schedule': [], 'accumulated': 0, 'book_value': 36000}], ['control 2', {'cost': 100000, 'salvage': 12000, 'life_months': 7, 'start_month': 1, 'convention': 'next_month', 'through': 12}, {'schedule': [[2, 12571], [3, 12572], [4, 12571], [5, 12572], [6, 12571], [7, 12572], [8, 12571]], 'accumulated': 88000, 'book_value': 12000}], ['control 3', {'cost': 100000, 'salvage': 0, 'life_months': 12, 'start_month': 3, 'convention': 'next_month', 'through': 12}, {'schedule': [[4, 8333], [5, 8334], [6, 8333], [7, 8333], [8, 8334], [9, 8333], [10, 8333], [11, 8334], [12, 8333]], 'accumulated': 75000, 'book_value': 25000}], ['control 4', {'cost': 36000, 'salvage': 0, 'life_months': 60, 'start_month': 1, 'convention': 'next_month', 'through': 80}, {'schedule': [[2, 600], [3, 600], [4, 600], [5, 600], [6, 600], [7, 600], [8, 600], [9, 600], [10, 600], [11, 600], [12, 600], [13, 600], [14, 600], [15, 600], [16, 600], [17, 600], [18, 600], [19, 600], [20, 600], [21, 600], [22, 600], [23, 600], [24, 600], [25, 600], [26, 600], [27, 600], [28, 600], [29, 600], [30, 600], [31, 600], [32, 600], [33, 600], [34, 600], [35, 600], [36, 600], [37, 600], [38, 600], [39, 600], [40, 600], [41, 600], [42, 600], [43, 600], [44, 600], [45, 600], [46, 600], [47, 600], [48, 600], [49, 600], [50, 600], [51, 600], [52, 600], [53, 600], [54, 600], [55, 600], [56, 600], [57, 600], [58, 600], [59, 600], [60, 600], [61, 600]], 'accumulated': 36000, 'book_value': 0}], ['control 5', {'cost': 36000, 'salvage': 1000, 'life_months': 7, 'start_month': 3, 'convention': 'full_month', 'through': 40}, {'schedule': [[3, 5000], [4, 5000], [5, 5000], [6, 5000], [7, 5000], [8, 5000], [9, 5000]], 'accumulated': 35000, 'book_value': 1000}], ['control 6', {'cost': 99999, 'salvage': 7, 'life_months': 12, 'start_month': 3, 'convention': 'next_month', 'through': 1}, {'schedule': [], 'accumulated': 0, 'book_value': 99999}]], [['regression: first charge month', {'cost': 36000, 'salvage': 7, 'life_months': 36, 'start_month': 1, 'convention': 'mid_month', 'through': 3}, {'schedule': [[1, 500], [2, 1000], [3, 1000]], 'accumulated': 2500, 'book_value': 33500}], ['control 1', {'cost': 120000, 'salvage': 12000, 'life_months': 36, 'start_month': 3, 'convention': 'next_month', 'through': 1}, {'schedule': [], 'accumulated': 0, 'book_value': 120000}], ['control 2', {'cost': 36000, 'salvage': 0, 'life_months': 7, 'start_month': 1, 'convention': 'next_month', 'through': 80}, {'schedule': [[2, 5143], [3, 5143], [4, 5143], [5, 5142], [6, 5143], [7, 5143], [8, 5143]], 'accumulated': 36000, 'book_value': 0}], ['control 3', {'cost': 100000, 'salvage': 7, 'life_months': 60, 'start_month': 3, 'convention': 'mid_month', 'through': 1}, {'schedule': [], 'accumulated': 0, 'book_value': 100000}], ['control 4', {'cost': 36000, 'salvage': 12000, 'life_months': 60, 'start_month': 10, 'convention': 'full_month', 'through': 12}, {'schedule': [[10, 400], [11, 400], [12, 400]], 'accumulated': 1200, 'book_value': 34800}], ['control 5', {'cost': 120000, 'salvage': 7, 'life_months': 60, 'start_month': 10, 'convention': 'next_month', 'through': 80}, {'schedule': [[11, 2000], [12, 2000], [13, 2000], [14, 2000], [15, 1999], [16, 2000], [17, 2000], [18, 2000], [19, 2000], [20, 2000], [21, 2000], [22, 2000], [23, 1999], [24, 2000], [25, 2000], [26, 2000], [27, 2000], [28, 2000], [29, 2000], [30, 2000], [31, 2000], [32, 1999], [33, 2000], [34, 2000], [35, 2000], [36, 2000], [37, 2000], [38, 2000], [39, 2000], [40, 2000], [41, 1999], [42, 2000], [43, 2000], [44, 2000], [45, 2000], [46, 2000], [47, 2000], [48, 2000], [49, 1999], [50, 2000], [51, 2000], [52, 2000], [53, 2000], [54, 2000], [55, 2000], [56, 2000], [57, 2000], [58, 1999], [59, 2000], [60, 2000], [61, 2000], [62, 2000], [63, 2000], [64, 2000], [65, 2000], [66, 1999], [67, 2000], [68, 2000], [69, 2000], [70, 2000]], 'accumulated': 119993, 'book_value': 7}], ['control 6', {'cost': 100000, 'salvage': 1000, 'life_months': 36, 'start_month': 3, 'convention': 'full_month', 'through': 80}, {'schedule': [[3, 2750], [4, 2750], [5, 2750], [6, 2750], [7, 2750], [8, 2750], [9, 2750], [10, 2750], [11, 2750], [12, 2750], [13, 2750], [14, 2750], [15, 2750], [16, 2750], [17, 2750], [18, 2750], [19, 2750], [20, 2750], [21, 2750], [22, 2750], [23, 2750], [24, 2750], [25, 2750], [26, 2750], [27, 2750], [28, 2750], [29, 2750], [30, 2750], [31, 2750], [32, 2750], [33, 2750], [34, 2750], [35, 2750], [36, 2750], [37, 2750], [38, 2750]], 'accumulated': 99000, 'book_value': 1000}]], [['regression: first charge month', {'cost': 100000, 'salvage': 12000, 'life_months': 12, 'start_month': 10, 'convention': 'mid_month', 'through': 80}, {'schedule': [[10, 3667], [11, 7333], [12, 7333], [13, 7334], [14, 7333], [15, 7333], [16, 7334], [17, 7333], [18, 7333], [19, 7334], [20, 7333], [21, 7333], [22, 3667]], 'accumulated': 88000, 'book_value': 12000}], ['control 1', {'cost': 120000, 'salvage': 12000, 'life_months': 60, 'start_month': 10, 'convention': 'mid_month', 'through': 3}, {'schedule': [], 'accumulated': 0, 'book_value': 120000}], ['control 2', {'cost': 5000, 'salvage': 0, 'life_months': 36, 'start_month': 3, 'convention': 'next_month', 'through': 12}, {'schedule': [[4, 139], [5, 139], [6, 139], [7, 139], [8, 138], [9, 139], [10, 139], [11, 139], [12, 139]], 'accumulated': 1250, 'book_value': 3750}], ['control 3', {'cost': 120000, 'salvage': 1000, 'life_months': 36, 'start_month': 1, 'convention': 'full_month', 'through': 40}, {'schedule': [[1, 3306], [2, 3305], [3, 3306], [4, 3305], [5, 3306], [6, 3305], [7, 3306], [8, 3305], [9, 3306], [10, 3306], [11, 3305], [12, 3306], [13, 3305], [14, 3306], [15, 3305], [16, 3306], [17, 3305], [18, 3306], [19, 3306], [20, 3305], [21, 3306], [22, 3305], [23, 3306], [24, 3305], [25, 3306], [26, 3305], [27, 3306], [28, 3306], [29, 3305], [30, 3306], [31, 3305], [32, 3306], [33, 3305], [34, 3306], [35, 3305], [36, 3306]], 'accumulated': 119000, 'book_value': 1000}], ['control 4', {'cost': 100000, 'salvage': 1000, 'life_months': 7, 'start_month': 3, 'convention': 'full_month', 'through': 3}, {'schedule': [[3, 14143]], 'accumulated': 14143, 'book_value': 85857}], ['control 5', {'cost': 99999, 'salvage': 0, 'life_months': 60, 'start_month': 3, 'convention': 'full_month', 'through': 40}, {'schedule': [[3, 1667], [4, 1666], [5, 1667], [6, 1667], [7, 1666], [8, 1667], [9, 1667], [10, 1666], [11, 1667], [12, 1667], [13, 1666], [14, 1667], [15, 1666], [16, 1667], [17, 1667], [18, 1666], [19, 1667], [20, 1667], [21, 1666], [22, 1667], [23, 1667], [24, 1666], [25, 1667], [26, 1667], [27, 1666], [28, 1667], [29, 1667], [30, 1666], [31, 1667], [32, 1667], [33, 1666], [34, 1667], [35, 1666], [36, 1667], [37, 1667], [38, 1666], [39, 1667], [40, 1667]], 'accumulated': 63333, 'book_value': 36666}], ['control 6', {'cost': 100000, 'salvage': 0, 'life_months': 60, 'start_month': 10, 'convention': 'next_month', 'through': 1}, {'schedule': [], 'accumulated': 0, 'book_value': 100000}]]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'raised ' + type(exc).__name__
    check(label, actual, 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):
    def rnd(n, d):
        q, r = divmod(n, d)
        return q + (1 if 2 * r >= d else 0)
    base = x['cost'] - x['salvage']
    life = x['life_months']
    conv = x['convention']
    first = x['start_month'] + (1 if conv == 'mid_month' else 0)
    acc = 0
    rows = []
    month = first
    while month <= x['through'] and acc < base:
        j = month - first + 1
        if conv == 'mid_month':
            target = rnd(base * (2 * j - 1), 2 * life)
        else:
            target = rnd(base * j, life)
        target = min(target, base)
        rows.append([month, target - acc])
        acc = target
        month += 1
    return {'schedule': rows, 'accumulated': acc, 'book_value': x['cost'] - acc}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: first charge month', {'cost': 5000, 'salvage': 0, 'life_months': 12, 'start_month': 1, 'convention': 'mid_month', 'through': 80}, {'schedule': [[1, 208], [2, 417], [3, 417], [4, 416], [5, 417], [6, 417], [7, 416], [8, 417], [9, 417], [10, 416], [11, 417], [12, 417], [13, 208]], 'accumulated': 5000, 'book_value': 0}], ['control 1', {'cost': 5000, 'salvage': 12000, 'life_months': 12, 'start_month': 10, 'convention': 'next_month', 'through': 1}, {'schedule': [], 'accumulated': 0, 'book_value': 5000}], ['control 2', {'cost': 120000, 'salvage': 7, 'life_months': 7, 'start_month': 10, 'convention': 'full_month', 'through': 80}, {'schedule': [[10, 17142], [11, 17142], [12, 17142], [13, 17141], [14, 17142], [15, 17142], [16, 17142]], 'accumulated': 119993, 'book_value': 7}], ['control 3', {'cost': 36000, 'salvage': 0, 'life_months': 12, 'start_month': 3, 'convention': 'full_month', 'through': 3}, {'schedule': [[3, 3000]], 'accumulated': 3000, 'book_value': 33000}], ['control 4', {'cost': 120000, 'salvage': 1000, 'life_months': 36, 'start_month': 3, 'convention': 'full_month', 'through': 40}, {'schedule': [[3, 3306], [4, 3305], [5, 3306], [6, 3305], [7, 3306], [8, 3305], [9, 3306], [10, 3305], [11, 3306], [12, 3306], [13, 3305], [14, 3306], [15, 3305], [16, 3306], [17, 3305], [18, 3306], [19, 3305], [20, 3306], [21, 3306], [22, 3305], [23, 3306], [24, 3305], [25, 3306], [26, 3305], [27, 3306], [28, 3305], [29, 3306], [30, 3306], [31, 3305], [32, 3306], [33, 3305], [34, 3306], [35, 3305], [36, 3306], [37, 3305], [38, 3306]], 'accumulated': 119000, 'book_value': 1000}], ['control 5', {'cost': 36000, 'salvage': 12000, 'life_months': 36, 'start_month': 1, 'convention': 'next_month', 'through': 1}, {'schedule': [], 'accumulated': 0, 'book_value': 36000}], ['control 6', {'cost': 99999, 'salvage': 7, 'life_months': 12, 'start_month': 1, 'convention': 'next_month', 'through': 40}, {'schedule': [[2, 8333], [3, 8332], [4, 8333], [5, 8333], [6, 8332], [7, 8333], [8, 8333], [9, 8332], [10, 8333], [11, 8333], [12, 8332], [13, 8333]], 'accumulated': 99992, 'book_value': 7}]], [['regression: first charge month', {'cost': 99999, 'salvage': 12000, 'life_months': 12, 'start_month': 10, 'convention': 'mid_month', 'through': 40}, {'schedule': [[10, 3667], [11, 7333], [12, 7333], [13, 7333], [14, 7334], [15, 7333], [16, 7333], [17, 7333], [18, 7334], [19, 7333], [20, 7333], [21, 7333], [22, 3667]], 'accumulated': 87999, 'book_value': 12000}], ['control 1', {'cost': 99999, 'salvage': 1000, 'life_months': 60, 'start_month': 3, 'convention': 'next_month', 'through': 40}, {'schedule': [[4, 1650], [5, 1650], [6, 1650], [7, 1650], [8, 1650], [9, 1650], [10, 1650], [11, 1650], [12, 1650], [13, 1650], [14, 1650], [15, 1650], [16, 1650], [17, 1650], [18, 1650], [19, 1650], [20, 1650], [21, 1650], [22, 1650], [23, 1650], [24, 1650], [25, 1650], [26, 1650], [27, 1650], [28, 1650], [29, 1650], [30, 1650], [31, 1650], [32, 1650], [33, 1650], [34, 1649], [35, 1650], [36, 1650], [37, 1650], [38, 1650], [39, 1650], [40, 1650]], 'accumulated': 61049, 'book_value': 38950}], ['control 2', {'cost': 36000, 'salvage': 12000, 'life_months': 12, 'start_month': 10, 'convention': 'next_month', 'through': 40}, {'schedule': [[11, 2000], [12, 2000], [13, 2000], [14, 2000], [15, 2000], [16, 2000], [17, 2000], [18, 2000], [19, 2000], [20, 2000], [21, 2000], [22, 2000]], 'accumulated': 24000, 'book_value': 12000}], ['control 3', {'cost': 120000, 'salvage': 1000, 'life_months': 60, 'start_month': 10, 'convention': 'next_month', 'through': 1}, {'schedule': [], 'accumulated': 0, 'book_value': 120000}], ['control 4', {'cost': 36000, 'salvage': 0, 'life_months': 60, 'start_month': 10, 'convention': 'next_month', 'through': 80}, {'schedule': [[11, 600], [12, 600], [13, 600], [14, 600], [15, 600], [16, 600], [17, 600], [18, 600], [19, 600], [20, 600], [21, 600], [22, 600], [23, 600], [24, 600], [25, 600], [26, 600], [27, 600], [28, 600], [29, 600], [30, 600], [31, 600], [32, 600], [33, 600], [34, 600], [35, 600], [36, 600], [37, 600], [38, 600], [39, 600], [40, 600], [41, 600], [42, 600], [43, 600], [44, 600], [45, 600], [46, 600], [47, 600], [48, 600], [49, 600], [50, 600], [51, 600], [52, 600], [53, 600], [54, 600], [55, 600], [56, 600], [57, 600], [58, 600], [59, 600], [60, 600], [61, 600], [62, 600], [63, 600], [64, 600], [65, 600], [66, 600], [67, 600], [68, 600], [69, 600], [70, 600]], 'accumulated': 36000, 'book_value': 0}], ['control 5', {'cost': 100000, 'salvage': 7, 'life_months': 60, 'start_month': 1, 'convention': 'next_month', 'through': 1}, {'schedule': [], 'accumulated': 0, 'book_value': 100000}], ['control 6', {'cost': 36000, 'salvage': 7, 'life_months': 36, 'start_month': 3, 'convention': 'full_month', 'through': 3}, {'schedule': [[3, 1000]], 'accumulated': 1000, 'book_value': 35000}]], [['regression: first charge month', {'cost': 120000, 'salvage': 0, 'life_months': 36, 'start_month': 3, 'convention': 'mid_month', 'through': 40}, {'schedule': [[3, 1667], [4, 3333], [5, 3333], [6, 3334], [7, 3333], [8, 3333], [9, 3334], [10, 3333], [11, 3333], [12, 3334], [13, 3333], [14, 3333], [15, 3334], [16, 3333], [17, 3333], [18, 3334], [19, 3333], [20, 3333], [21, 3334], [22, 3333], [23, 3333], [24, 3334], [25, 3333], [26, 3333], [27, 3334], [28, 3333], [29, 3333], [30, 3334], [31, 3333], [32, 3333], [33, 3334], [34, 3333], [35, 3333], [36, 3334], [37, 3333], [38, 3333], [39, 1667]], 'accumulated': 120000, 'book_value': 0}], ['control 1', {'cost': 36000, 'salvage': 0, 'life_months': 7, 'start_month': 3, 'convention': 'mid_month', 'through': 1}, {'schedule': [], 'accumulated': 0, 'book_value': 36000}], ['control 2', {'cost': 100000, 'salvage': 12000, 'life_months': 7, 'start_month': 1, 'convention': 'next_month', 'through': 12}, {'schedule': [[2, 12571], [3, 12572], [4, 12571], [5, 12572], [6, 12571], [7, 12572], [8, 12571]], 'accumulated': 88000, 'book_value': 12000}], ['control 3', {'cost': 100000, 'salvage': 0, 'life_months': 12, 'start_month': 3, 'convention': 'next_month', 'through': 12}, {'schedule': [[4, 8333], [5, 8334], [6, 8333], [7, 8333], [8, 8334], [9, 8333], [10, 8333], [11, 8334], [12, 8333]], 'accumulated': 75000, 'book_value': 25000}], ['control 4', {'cost': 36000, 'salvage': 0, 'life_months': 60, 'start_month': 1, 'convention': 'next_month', 'through': 80}, {'schedule': [[2, 600], [3, 600], [4, 600], [5, 600], [6, 600], [7, 600], [8, 600], [9, 600], [10, 600], [11, 600], [12, 600], [13, 600], [14, 600], [15, 600], [16, 600], [17, 600], [18, 600], [19, 600], [20, 600], [21, 600], [22, 600], [23, 600], [24, 600], [25, 600], [26, 600], [27, 600], [28, 600], [29, 600], [30, 600], [31, 600], [32, 600], [33, 600], [34, 600], [35, 600], [36, 600], [37, 600], [38, 600], [39, 600], [40, 600], [41, 600], [42, 600], [43, 600], [44, 600], [45, 600], [46, 600], [47, 600], [48, 600], [49, 600], [50, 600], [51, 600], [52, 600], [53, 600], [54, 600], [55, 600], [56, 600], [57, 600], [58, 600], [59, 600], [60, 600], [61, 600]], 'accumulated': 36000, 'book_value': 0}], ['control 5', {'cost': 36000, 'salvage': 1000, 'life_months': 7, 'start_month': 3, 'convention': 'full_month', 'through': 40}, {'schedule': [[3, 5000], [4, 5000], [5, 5000], [6, 5000], [7, 5000], [8, 5000], [9, 5000]], 'accumulated': 35000, 'book_value': 1000}], ['control 6', {'cost': 99999, 'salvage': 7, 'life_months': 12, 'start_month': 3, 'convention': 'next_month', 'through': 1}, {'schedule': [], 'accumulated': 0, 'book_value': 99999}]], [['regression: first charge month', {'cost': 36000, 'salvage': 7, 'life_months': 36, 'start_month': 1, 'convention': 'mid_month', 'through': 3}, {'schedule': [[1, 500], [2, 1000], [3, 1000]], 'accumulated': 2500, 'book_value': 33500}], ['control 1', {'cost': 120000, 'salvage': 12000, 'life_months': 36, 'start_month': 3, 'convention': 'next_month', 'through': 1}, {'schedule': [], 'accumulated': 0, 'book_value': 120000}], ['control 2', {'cost': 36000, 'salvage': 0, 'life_months': 7, 'start_month': 1, 'convention': 'next_month', 'through': 80}, {'schedule': [[2, 5143], [3, 5143], [4, 5143], [5, 5142], [6, 5143], [7, 5143], [8, 5143]], 'accumulated': 36000, 'book_value': 0}], ['control 3', {'cost': 100000, 'salvage': 7, 'life_months': 60, 'start_month': 3, 'convention': 'mid_month', 'through': 1}, {'schedule': [], 'accumulated': 0, 'book_value': 100000}], ['control 4', {'cost': 36000, 'salvage': 12000, 'life_months': 60, 'start_month': 10, 'convention': 'full_month', 'through': 12}, {'schedule': [[10, 400], [11, 400], [12, 400]], 'accumulated': 1200, 'book_value': 34800}], ['control 5', {'cost': 120000, 'salvage': 7, 'life_months': 60, 'start_month': 10, 'convention': 'next_month', 'through': 80}, {'schedule': [[11, 2000], [12, 2000], [13, 2000], [14, 2000], [15, 1999], [16, 2000], [17, 2000], [18, 2000], [19, 2000], [20, 2000], [21, 2000], [22, 2000], [23, 1999], [24, 2000], [25, 2000], [26, 2000], [27, 2000], [28, 2000], [29, 2000], [30, 2000], [31, 2000], [32, 1999], [33, 2000], [34, 2000], [35, 2000], [36, 2000], [37, 2000], [38, 2000], [39, 2000], [40, 2000], [41, 1999], [42, 2000], [43, 2000], [44, 2000], [45, 2000], [46, 2000], [47, 2000], [48, 2000], [49, 1999], [50, 2000], [51, 2000], [52, 2000], [53, 2000], [54, 2000], [55, 2000], [56, 2000], [57, 2000], [58, 1999], [59, 2000], [60, 2000], [61, 2000], [62, 2000], [63, 2000], [64, 2000], [65, 2000], [66, 1999], [67, 2000], [68, 2000], [69, 2000], [70, 2000]], 'accumulated': 119993, 'book_value': 7}], ['control 6', {'cost': 100000, 'salvage': 1000, 'life_months': 36, 'start_month': 3, 'convention': 'full_month', 'through': 80}, {'schedule': [[3, 2750], [4, 2750], [5, 2750], [6, 2750], [7, 2750], [8, 2750], [9, 2750], [10, 2750], [11, 2750], [12, 2750], [13, 2750], [14, 2750], [15, 2750], [16, 2750], [17, 2750], [18, 2750], [19, 2750], [20, 2750], [21, 2750], [22, 2750], [23, 2750], [24, 2750], [25, 2750], [26, 2750], [27, 2750], [28, 2750], [29, 2750], [30, 2750], [31, 2750], [32, 2750], [33, 2750], [34, 2750], [35, 2750], [36, 2750], [37, 2750], [38, 2750]], 'accumulated': 99000, 'book_value': 1000}]], [['regression: first charge month', {'cost': 100000, 'salvage': 12000, 'life_months': 12, 'start_month': 10, 'convention': 'mid_month', 'through': 80}, {'schedule': [[10, 3667], [11, 7333], [12, 7333], [13, 7334], [14, 7333], [15, 7333], [16, 7334], [17, 7333], [18, 7333], [19, 7334], [20, 7333], [21, 7333], [22, 3667]], 'accumulated': 88000, 'book_value': 12000}], ['control 1', {'cost': 120000, 'salvage': 12000, 'life_months': 60, 'start_month': 10, 'convention': 'mid_month', 'through': 3}, {'schedule': [], 'accumulated': 0, 'book_value': 120000}], ['control 2', {'cost': 5000, 'salvage': 0, 'life_months': 36, 'start_month': 3, 'convention': 'next_month', 'through': 12}, {'schedule': [[4, 139], [5, 139], [6, 139], [7, 139], [8, 138], [9, 139], [10, 139], [11, 139], [12, 139]], 'accumulated': 1250, 'book_value': 3750}], ['control 3', {'cost': 120000, 'salvage': 1000, 'life_months': 36, 'start_month': 1, 'convention': 'full_month', 'through': 40}, {'schedule': [[1, 3306], [2, 3305], [3, 3306], [4, 3305], [5, 3306], [6, 3305], [7, 3306], [8, 3305], [9, 3306], [10, 3306], [11, 3305], [12, 3306], [13, 3305], [14, 3306], [15, 3305], [16, 3306], [17, 3305], [18, 3306], [19, 3306], [20, 3305], [21, 3306], [22, 3305], [23, 3306], [24, 3305], [25, 3306], [26, 3305], [27, 3306], [28, 3306], [29, 3305], [30, 3306], [31, 3305], [32, 3306], [33, 3305], [34, 3306], [35, 3305], [36, 3306]], 'accumulated': 119000, 'book_value': 1000}], ['control 4', {'cost': 100000, 'salvage': 1000, 'life_months': 7, 'start_month': 3, 'convention': 'full_month', 'through': 3}, {'schedule': [[3, 14143]], 'accumulated': 14143, 'book_value': 85857}], ['control 5', {'cost': 99999, 'salvage': 0, 'life_months': 60, 'start_month': 3, 'convention': 'full_month', 'through': 40}, {'schedule': [[3, 1667], [4, 1666], [5, 1667], [6, 1667], [7, 1666], [8, 1667], [9, 1667], [10, 1666], [11, 1667], [12, 1667], [13, 1666], [14, 1667], [15, 1666], [16, 1667], [17, 1667], [18, 1666], [19, 1667], [20, 1667], [21, 1666], [22, 1667], [23, 1667], [24, 1666], [25, 1667], [26, 1667], [27, 1666], [28, 1667], [29, 1667], [30, 1666], [31, 1667], [32, 1667], [33, 1666], [34, 1667], [35, 1666], [36, 1667], [37, 1667], [38, 1666], [39, 1667], [40, 1667]], 'accumulated': 63333, 'book_value': 36666}], ['control 6', {'cost': 100000, 'salvage': 0, 'life_months': 60, 'start_month': 10, 'convention': 'next_month', 'through': 1}, {'schedule': [], 'accumulated': 0, 'book_value': 100000}]]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'raised ' + type(exc).__name__
    check(label, actual, 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:
Mid-month assets start depreciating a month late.

x = {'cost', 'salvage', 'life_months', 'start_month', 'convention': 'full_month'|'mid_month'|'next_month', 'through': last month to post}. Depreciable base = cost - salvage. The first charge month is start_month (start_month + 1 for next_month). Charges use cumulative rounding: target accumulated after the j-th charge month is round(base*j/life) or, for mid_month, round(base*(2j-1)/(2*life)), half-up and capped at base; each month posts target - accumulated. Posting stops after 'through' or once accumulated reaches base. Return {'schedule': [[month, amount]], 'accumulated', 'book_value': cost - accumulated}.

split: open-access