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

N = 1
observations = []
def solve(x):
    rates = x['rates']
    w = x['wage']
    def tax(st):
        return (w * rates.get(st, 0) + 5000) // 10000
    res, work = x['res'], x['work']
    if res == work:
        return {work: tax(work)}
    pair = sorted([res, work])
    if pair in x['reciprocal']:
        return {res: tax(res)}
    work_tax = tax(work)
    res_tax = tax(res) - work_tax if x['res_credit'] else tax(res)
    out = {work: work_tax}
    if res_tax:
        out[res] = res_tax
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'wage': 92630, 'res': 'PA', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 425, 'OH': 0, 'MI': 0, 'IN': 425, 'KY': 425, 'WV': 637}, 'res_credit': True}, {'WV': 5901}), ('regression', {'wage': 348021, 'res': 'MI', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 307, 'NJ': 355, 'OH': 0, 'MI': 254, 'IN': 425, 'KY': 350, 'WV': 425}, 'res_credit': True}, {'KY': 12181}), ('partial-repair probe', {'wage': 202229, 'res': 'KY', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 350, 'NJ': 637, 'OH': 350, 'MI': 425, 'IN': 0, 'KY': 0, 'WV': 500}, 'res_credit': True}, {'PA': 7078}), ('partial-repair probe', {'wage': 353313, 'res': 'OH', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY']], 'rates': {'PA': 500, 'NJ': 425, 'OH': 159, 'MI': 637, 'IN': 500, 'KY': 500, 'WV': 425}, 'res_credit': True}, {'IN': 17666}), ('normal control', {'wage': 379815, 'res': 'MI', 'work': 'OH', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 637, 'OH': 0, 'MI': 637, 'IN': 350, 'KY': 307, 'WV': 242}, 'res_credit': True}, {'MI': 24194}), ('normal control', {'wage': 333788, 'res': 'NJ', 'work': 'NJ', 'reciprocal': [['IN', 'KY']], 'rates': {'PA': 637, 'NJ': 425, 'OH': 446, 'MI': 500, 'IN': 122, 'KY': 312, 'WV': 0}, 'res_credit': True}, {'NJ': 14186}), ('normal control', {'wage': 108935, 'res': 'MI', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 307, 'OH': 350, 'MI': 0, 'IN': 425, 'KY': 0, 'WV': 350}, 'res_credit': False}, {'WV': 3813}), ('normal control', {'wage': 267886, 'res': 'PA', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 425, 'OH': 425, 'MI': 637, 'IN': 637, 'KY': 0, 'WV': 637}, 'res_credit': False}, {'IN': 17064, 'PA': 13394})], [('regression', {'wage': 348021, 'res': 'MI', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 307, 'NJ': 355, 'OH': 0, 'MI': 254, 'IN': 425, 'KY': 350, 'WV': 425}, 'res_credit': True}, {'KY': 12181}), ('regression', {'wage': 202229, 'res': 'KY', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 350, 'NJ': 637, 'OH': 350, 'MI': 425, 'IN': 0, 'KY': 0, 'WV': 500}, 'res_credit': True}, {'PA': 7078}), ('partial-repair probe', {'wage': 353313, 'res': 'OH', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY']], 'rates': {'PA': 500, 'NJ': 425, 'OH': 159, 'MI': 637, 'IN': 500, 'KY': 500, 'WV': 425}, 'res_credit': True}, {'IN': 17666}), ('partial-repair probe', {'wage': 104553, 'res': 'PA', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 307, 'NJ': 330, 'OH': 637, 'MI': 425, 'IN': 500, 'KY': 637, 'WV': 350}, 'res_credit': True}, {'WV': 3659}), ('normal control', {'wage': 243443, 'res': 'IN', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 350, 'NJ': 425, 'OH': 0, 'MI': 0, 'IN': 637, 'KY': 307, 'WV': 425}, 'res_credit': True}, {'IN': 15507}), ('normal control', {'wage': 133100, 'res': 'KY', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 307, 'NJ': 500, 'OH': 500, 'MI': 350, 'IN': 0, 'KY': 500, 'WV': 637}, 'res_credit': True}, {'PA': 4086, 'KY': 2569}), ('normal control', {'wage': 326976, 'res': 'OH', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 543, 'NJ': 500, 'OH': 500, 'MI': 0, 'IN': 350, 'KY': 500, 'WV': 350}, 'res_credit': True}, {'NJ': 16349}), ('normal control', {'wage': 373364, 'res': 'MI', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY']], 'rates': {'PA': 350, 'NJ': 611, 'OH': 307, 'MI': 637, 'IN': 0, 'KY': 500, 'WV': 637}, 'res_credit': False}, {'WV': 23783, 'MI': 23783})], [('regression', {'wage': 202229, 'res': 'KY', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 350, 'NJ': 637, 'OH': 350, 'MI': 425, 'IN': 0, 'KY': 0, 'WV': 500}, 'res_credit': True}, {'PA': 7078}), ('regression', {'wage': 353313, 'res': 'OH', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY']], 'rates': {'PA': 500, 'NJ': 425, 'OH': 159, 'MI': 637, 'IN': 500, 'KY': 500, 'WV': 425}, 'res_credit': True}, {'IN': 17666}), ('partial-repair probe', {'wage': 104553, 'res': 'PA', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 307, 'NJ': 330, 'OH': 637, 'MI': 425, 'IN': 500, 'KY': 637, 'WV': 350}, 'res_credit': True}, {'WV': 3659}), ('partial-repair probe', {'wage': 56393, 'res': 'KY', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 363, 'NJ': 350, 'OH': 500, 'MI': 500, 'IN': 350, 'KY': 307, 'WV': 307}, 'res_credit': True}, {'PA': 2047}), ('normal control', {'wage': 391289, 'res': 'WV', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 0, 'OH': 500, 'MI': 350, 'IN': 425, 'KY': 350, 'WV': 350}, 'res_credit': True}, {'KY': 13695}), ('normal control', {'wage': 214002, 'res': 'KY', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 239, 'NJ': 637, 'OH': 156, 'MI': 0, 'IN': 350, 'KY': 300, 'WV': 350}, 'res_credit': True}, {'PA': 5115, 'KY': 1305}), ('normal control', {'wage': 314004, 'res': 'IN', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 0, 'NJ': 350, 'OH': 307, 'MI': 637, 'IN': 307, 'KY': 180, 'WV': 425}, 'res_credit': True}, {'IN': 9640}), ('normal control', {'wage': 190832, 'res': 'KY', 'work': 'OH', 'reciprocal': [['MI', 'OH']], 'rates': {'PA': 637, 'NJ': 0, 'OH': 425, 'MI': 425, 'IN': 637, 'KY': 500, 'WV': 425}, 'res_credit': True}, {'OH': 8110, 'KY': 1432})], [('regression', {'wage': 353313, 'res': 'OH', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY']], 'rates': {'PA': 500, 'NJ': 425, 'OH': 159, 'MI': 637, 'IN': 500, 'KY': 500, 'WV': 425}, 'res_credit': True}, {'IN': 17666}), ('regression', {'wage': 104553, 'res': 'PA', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 307, 'NJ': 330, 'OH': 637, 'MI': 425, 'IN': 500, 'KY': 637, 'WV': 350}, 'res_credit': True}, {'WV': 3659}), ('partial-repair probe', {'wage': 290036, 'res': 'IN', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 318, 'NJ': 0, 'OH': 46, 'MI': 425, 'IN': 500, 'KY': 164, 'WV': 637}, 'res_credit': True}, {'WV': 18475}), ('partial-repair probe', {'wage': 2279, 'res': 'WV', 'work': 'PA', 'reciprocal': [['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 0, 'OH': 0, 'MI': 350, 'IN': 500, 'KY': 350, 'WV': 321}, 'res_credit': True}, {'PA': 114}), ('normal control', {'wage': 51460, 'res': 'KY', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 307, 'OH': 425, 'MI': 350, 'IN': 637, 'KY': 652, 'WV': 0}, 'res_credit': True}, {'NJ': 1580, 'KY': 1775}), ('normal control', {'wage': 236355, 'res': 'PA', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 425, 'NJ': 307, 'OH': 425, 'MI': 425, 'IN': 350, 'KY': 637, 'WV': 637}, 'res_credit': False}, {'WV': 15056, 'PA': 10045}), ('normal control', {'wage': 92712, 'res': 'MI', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 0, 'NJ': 425, 'OH': 425, 'MI': 250, 'IN': 350, 'KY': 637, 'WV': 350}, 'res_credit': False}, {'PA': 0, 'MI': 2318}), ('normal control', {'wage': 91863, 'res': 'NJ', 'work': 'OH', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 350, 'NJ': 307, 'OH': 350, 'MI': 549, 'IN': 307, 'KY': 637, 'WV': 590}, 'res_credit': False}, {'OH': 3215, 'NJ': 2820})], [('regression', {'wage': 104553, 'res': 'PA', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 307, 'NJ': 330, 'OH': 637, 'MI': 425, 'IN': 500, 'KY': 637, 'WV': 350}, 'res_credit': True}, {'WV': 3659}), ('regression', {'wage': 56393, 'res': 'KY', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 363, 'NJ': 350, 'OH': 500, 'MI': 500, 'IN': 350, 'KY': 307, 'WV': 307}, 'res_credit': True}, {'PA': 2047}), ('partial-repair probe', {'wage': 122807, 'res': 'KY', 'work': 'PA', 'reciprocal': [['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 307, 'NJ': 637, 'OH': 425, 'MI': 0, 'IN': 425, 'KY': 0, 'WV': 0}, 'res_credit': True}, {'PA': 3770}), ('partial-repair probe', {'wage': 321787, 'res': 'MI', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 500, 'NJ': 637, 'OH': 307, 'MI': 350, 'IN': 0, 'KY': 500, 'WV': 350}, 'res_credit': True}, {'PA': 16089}), ('normal control', {'wage': 208890, 'res': 'KY', 'work': 'MI', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 0, 'NJ': 0, 'OH': 307, 'MI': 0, 'IN': 577, 'KY': 307, 'WV': 350}, 'res_credit': True}, {'MI': 0, 'KY': 6413}), ('normal control', {'wage': 70654, 'res': 'NJ', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY']], 'rates': {'PA': 0, 'NJ': 637, 'OH': 458, 'MI': 637, 'IN': 425, 'KY': 307, 'WV': 71}, 'res_credit': False}, {'NJ': 4501}), ('normal control', {'wage': 369165, 'res': 'PA', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 307, 'NJ': 307, 'OH': 350, 'MI': 307, 'IN': 307, 'KY': 425, 'WV': 102}, 'res_credit': False}, {'WV': 3765, 'PA': 11333}), ('normal control', {'wage': 129954, 'res': 'PA', 'work': 'PA', 'reciprocal': [['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 350, 'NJ': 651, 'OH': 637, 'MI': 0, 'IN': 0, 'KY': 623, 'WV': 0}, 'res_credit': True}, {'PA': 4548})]]
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):
    rates = x['rates']
    w = x['wage']
    def tax(st):
        return (w * rates.get(st, 0) + 5000) // 10000
    res, work = x['res'], x['work']
    if res == work:
        return {work: tax(work)}
    pair = sorted([res, work])
    if pair in x['reciprocal']:
        return {res: tax(res)}
    work_tax = tax(work)
    res_tax = abs(tax(res) - work_tax) if x['res_credit'] else tax(res)
    out = {work: work_tax}
    if res_tax:
        out[res] = res_tax
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'wage': 92630, 'res': 'PA', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 425, 'OH': 0, 'MI': 0, 'IN': 425, 'KY': 425, 'WV': 637}, 'res_credit': True}, {'WV': 5901}), ('regression', {'wage': 348021, 'res': 'MI', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 307, 'NJ': 355, 'OH': 0, 'MI': 254, 'IN': 425, 'KY': 350, 'WV': 425}, 'res_credit': True}, {'KY': 12181}), ('partial-repair probe', {'wage': 202229, 'res': 'KY', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 350, 'NJ': 637, 'OH': 350, 'MI': 425, 'IN': 0, 'KY': 0, 'WV': 500}, 'res_credit': True}, {'PA': 7078}), ('partial-repair probe', {'wage': 353313, 'res': 'OH', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY']], 'rates': {'PA': 500, 'NJ': 425, 'OH': 159, 'MI': 637, 'IN': 500, 'KY': 500, 'WV': 425}, 'res_credit': True}, {'IN': 17666}), ('normal control', {'wage': 379815, 'res': 'MI', 'work': 'OH', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 637, 'OH': 0, 'MI': 637, 'IN': 350, 'KY': 307, 'WV': 242}, 'res_credit': True}, {'MI': 24194}), ('normal control', {'wage': 333788, 'res': 'NJ', 'work': 'NJ', 'reciprocal': [['IN', 'KY']], 'rates': {'PA': 637, 'NJ': 425, 'OH': 446, 'MI': 500, 'IN': 122, 'KY': 312, 'WV': 0}, 'res_credit': True}, {'NJ': 14186}), ('normal control', {'wage': 108935, 'res': 'MI', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 307, 'OH': 350, 'MI': 0, 'IN': 425, 'KY': 0, 'WV': 350}, 'res_credit': False}, {'WV': 3813}), ('normal control', {'wage': 267886, 'res': 'PA', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 425, 'OH': 425, 'MI': 637, 'IN': 637, 'KY': 0, 'WV': 637}, 'res_credit': False}, {'IN': 17064, 'PA': 13394})], [('regression', {'wage': 348021, 'res': 'MI', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 307, 'NJ': 355, 'OH': 0, 'MI': 254, 'IN': 425, 'KY': 350, 'WV': 425}, 'res_credit': True}, {'KY': 12181}), ('regression', {'wage': 202229, 'res': 'KY', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 350, 'NJ': 637, 'OH': 350, 'MI': 425, 'IN': 0, 'KY': 0, 'WV': 500}, 'res_credit': True}, {'PA': 7078}), ('partial-repair probe', {'wage': 353313, 'res': 'OH', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY']], 'rates': {'PA': 500, 'NJ': 425, 'OH': 159, 'MI': 637, 'IN': 500, 'KY': 500, 'WV': 425}, 'res_credit': True}, {'IN': 17666}), ('partial-repair probe', {'wage': 104553, 'res': 'PA', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 307, 'NJ': 330, 'OH': 637, 'MI': 425, 'IN': 500, 'KY': 637, 'WV': 350}, 'res_credit': True}, {'WV': 3659}), ('normal control', {'wage': 243443, 'res': 'IN', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 350, 'NJ': 425, 'OH': 0, 'MI': 0, 'IN': 637, 'KY': 307, 'WV': 425}, 'res_credit': True}, {'IN': 15507}), ('normal control', {'wage': 133100, 'res': 'KY', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 307, 'NJ': 500, 'OH': 500, 'MI': 350, 'IN': 0, 'KY': 500, 'WV': 637}, 'res_credit': True}, {'PA': 4086, 'KY': 2569}), ('normal control', {'wage': 326976, 'res': 'OH', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 543, 'NJ': 500, 'OH': 500, 'MI': 0, 'IN': 350, 'KY': 500, 'WV': 350}, 'res_credit': True}, {'NJ': 16349}), ('normal control', {'wage': 373364, 'res': 'MI', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY']], 'rates': {'PA': 350, 'NJ': 611, 'OH': 307, 'MI': 637, 'IN': 0, 'KY': 500, 'WV': 637}, 'res_credit': False}, {'WV': 23783, 'MI': 23783})], [('regression', {'wage': 202229, 'res': 'KY', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 350, 'NJ': 637, 'OH': 350, 'MI': 425, 'IN': 0, 'KY': 0, 'WV': 500}, 'res_credit': True}, {'PA': 7078}), ('regression', {'wage': 353313, 'res': 'OH', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY']], 'rates': {'PA': 500, 'NJ': 425, 'OH': 159, 'MI': 637, 'IN': 500, 'KY': 500, 'WV': 425}, 'res_credit': True}, {'IN': 17666}), ('partial-repair probe', {'wage': 104553, 'res': 'PA', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 307, 'NJ': 330, 'OH': 637, 'MI': 425, 'IN': 500, 'KY': 637, 'WV': 350}, 'res_credit': True}, {'WV': 3659}), ('partial-repair probe', {'wage': 56393, 'res': 'KY', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 363, 'NJ': 350, 'OH': 500, 'MI': 500, 'IN': 350, 'KY': 307, 'WV': 307}, 'res_credit': True}, {'PA': 2047}), ('normal control', {'wage': 391289, 'res': 'WV', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 0, 'OH': 500, 'MI': 350, 'IN': 425, 'KY': 350, 'WV': 350}, 'res_credit': True}, {'KY': 13695}), ('normal control', {'wage': 214002, 'res': 'KY', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 239, 'NJ': 637, 'OH': 156, 'MI': 0, 'IN': 350, 'KY': 300, 'WV': 350}, 'res_credit': True}, {'PA': 5115, 'KY': 1305}), ('normal control', {'wage': 314004, 'res': 'IN', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 0, 'NJ': 350, 'OH': 307, 'MI': 637, 'IN': 307, 'KY': 180, 'WV': 425}, 'res_credit': True}, {'IN': 9640}), ('normal control', {'wage': 190832, 'res': 'KY', 'work': 'OH', 'reciprocal': [['MI', 'OH']], 'rates': {'PA': 637, 'NJ': 0, 'OH': 425, 'MI': 425, 'IN': 637, 'KY': 500, 'WV': 425}, 'res_credit': True}, {'OH': 8110, 'KY': 1432})], [('regression', {'wage': 353313, 'res': 'OH', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY']], 'rates': {'PA': 500, 'NJ': 425, 'OH': 159, 'MI': 637, 'IN': 500, 'KY': 500, 'WV': 425}, 'res_credit': True}, {'IN': 17666}), ('regression', {'wage': 104553, 'res': 'PA', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 307, 'NJ': 330, 'OH': 637, 'MI': 425, 'IN': 500, 'KY': 637, 'WV': 350}, 'res_credit': True}, {'WV': 3659}), ('partial-repair probe', {'wage': 290036, 'res': 'IN', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 318, 'NJ': 0, 'OH': 46, 'MI': 425, 'IN': 500, 'KY': 164, 'WV': 637}, 'res_credit': True}, {'WV': 18475}), ('partial-repair probe', {'wage': 2279, 'res': 'WV', 'work': 'PA', 'reciprocal': [['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 0, 'OH': 0, 'MI': 350, 'IN': 500, 'KY': 350, 'WV': 321}, 'res_credit': True}, {'PA': 114}), ('normal control', {'wage': 51460, 'res': 'KY', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 307, 'OH': 425, 'MI': 350, 'IN': 637, 'KY': 652, 'WV': 0}, 'res_credit': True}, {'NJ': 1580, 'KY': 1775}), ('normal control', {'wage': 236355, 'res': 'PA', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 425, 'NJ': 307, 'OH': 425, 'MI': 425, 'IN': 350, 'KY': 637, 'WV': 637}, 'res_credit': False}, {'WV': 15056, 'PA': 10045}), ('normal control', {'wage': 92712, 'res': 'MI', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 0, 'NJ': 425, 'OH': 425, 'MI': 250, 'IN': 350, 'KY': 637, 'WV': 350}, 'res_credit': False}, {'PA': 0, 'MI': 2318}), ('normal control', {'wage': 91863, 'res': 'NJ', 'work': 'OH', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 350, 'NJ': 307, 'OH': 350, 'MI': 549, 'IN': 307, 'KY': 637, 'WV': 590}, 'res_credit': False}, {'OH': 3215, 'NJ': 2820})], [('regression', {'wage': 104553, 'res': 'PA', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 307, 'NJ': 330, 'OH': 637, 'MI': 425, 'IN': 500, 'KY': 637, 'WV': 350}, 'res_credit': True}, {'WV': 3659}), ('regression', {'wage': 56393, 'res': 'KY', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 363, 'NJ': 350, 'OH': 500, 'MI': 500, 'IN': 350, 'KY': 307, 'WV': 307}, 'res_credit': True}, {'PA': 2047}), ('partial-repair probe', {'wage': 122807, 'res': 'KY', 'work': 'PA', 'reciprocal': [['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 307, 'NJ': 637, 'OH': 425, 'MI': 0, 'IN': 425, 'KY': 0, 'WV': 0}, 'res_credit': True}, {'PA': 3770}), ('partial-repair probe', {'wage': 321787, 'res': 'MI', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 500, 'NJ': 637, 'OH': 307, 'MI': 350, 'IN': 0, 'KY': 500, 'WV': 350}, 'res_credit': True}, {'PA': 16089}), ('normal control', {'wage': 208890, 'res': 'KY', 'work': 'MI', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 0, 'NJ': 0, 'OH': 307, 'MI': 0, 'IN': 577, 'KY': 307, 'WV': 350}, 'res_credit': True}, {'MI': 0, 'KY': 6413}), ('normal control', {'wage': 70654, 'res': 'NJ', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY']], 'rates': {'PA': 0, 'NJ': 637, 'OH': 458, 'MI': 637, 'IN': 425, 'KY': 307, 'WV': 71}, 'res_credit': False}, {'NJ': 4501}), ('normal control', {'wage': 369165, 'res': 'PA', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 307, 'NJ': 307, 'OH': 350, 'MI': 307, 'IN': 307, 'KY': 425, 'WV': 102}, 'res_credit': False}, {'WV': 3765, 'PA': 11333}), ('normal control', {'wage': 129954, 'res': 'PA', 'work': 'PA', 'reciprocal': [['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 350, 'NJ': 651, 'OH': 637, 'MI': 0, 'IN': 0, 'KY': 623, 'WV': 0}, 'res_credit': True}, {'PA': 4548})]]
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 living in a lower-tax state get a negative resident withholding line.

Input {wage, res, work, reciprocal:[sorted state pairs], rates:{state: basis points}, res_credit}. Tax for a state = wage*rate/10000 half-up. Same state: withhold only there. Reciprocal pair: withhold only the resident state. Otherwise withhold the work state; the resident state gets max(0, resident - work) when res_credit else its full tax; omit zero resident lines. Return {state: cents}.

split: open-access


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

N = 1
observations = []
def solve(x):
    rates = x['rates']
    w = x['wage']
    def tax(st):
        return (w * rates.get(st, 0) + 5000) // 10000
    res, work = x['res'], x['work']
    if res == work:
        return {work: tax(work)}
    pair = sorted([res, work])
    if pair in x['reciprocal']:
        return {res: tax(res)}
    work_tax = tax(work)
    res_tax = max(0, tax(res) - work_tax) if x['res_credit'] else tax(res)
    out = {work: work_tax}
    if True:
        out[res] = res_tax
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'wage': 92630, 'res': 'PA', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 425, 'OH': 0, 'MI': 0, 'IN': 425, 'KY': 425, 'WV': 637}, 'res_credit': True}, {'WV': 5901}), ('regression', {'wage': 108935, 'res': 'MI', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 307, 'OH': 350, 'MI': 0, 'IN': 425, 'KY': 0, 'WV': 350}, 'res_credit': False}, {'WV': 3813}), ('partial-repair probe', {'wage': 348021, 'res': 'MI', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 307, 'NJ': 355, 'OH': 0, 'MI': 254, 'IN': 425, 'KY': 350, 'WV': 425}, 'res_credit': True}, {'KY': 12181}), ('partial-repair probe', {'wage': 202229, 'res': 'KY', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 350, 'NJ': 637, 'OH': 350, 'MI': 425, 'IN': 0, 'KY': 0, 'WV': 500}, 'res_credit': True}, {'PA': 7078}), ('normal control', {'wage': 379815, 'res': 'MI', 'work': 'OH', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 637, 'OH': 0, 'MI': 637, 'IN': 350, 'KY': 307, 'WV': 242}, 'res_credit': True}, {'MI': 24194}), ('normal control', {'wage': 333788, 'res': 'NJ', 'work': 'NJ', 'reciprocal': [['IN', 'KY']], 'rates': {'PA': 637, 'NJ': 425, 'OH': 446, 'MI': 500, 'IN': 122, 'KY': 312, 'WV': 0}, 'res_credit': True}, {'NJ': 14186}), ('normal control', {'wage': 267886, 'res': 'PA', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 425, 'OH': 425, 'MI': 637, 'IN': 637, 'KY': 0, 'WV': 637}, 'res_credit': False}, {'IN': 17064, 'PA': 13394}), ('normal control', {'wage': 243443, 'res': 'IN', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 350, 'NJ': 425, 'OH': 0, 'MI': 0, 'IN': 637, 'KY': 307, 'WV': 425}, 'res_credit': True}, {'IN': 15507})], [('regression', {'wage': 108935, 'res': 'MI', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 307, 'OH': 350, 'MI': 0, 'IN': 425, 'KY': 0, 'WV': 350}, 'res_credit': False}, {'WV': 3813}), ('regression', {'wage': 348021, 'res': 'MI', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 307, 'NJ': 355, 'OH': 0, 'MI': 254, 'IN': 425, 'KY': 350, 'WV': 425}, 'res_credit': True}, {'KY': 12181}), ('partial-repair probe', {'wage': 202229, 'res': 'KY', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 350, 'NJ': 637, 'OH': 350, 'MI': 425, 'IN': 0, 'KY': 0, 'WV': 500}, 'res_credit': True}, {'PA': 7078}), ('partial-repair probe', {'wage': 326976, 'res': 'OH', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 543, 'NJ': 500, 'OH': 500, 'MI': 0, 'IN': 350, 'KY': 500, 'WV': 350}, 'res_credit': True}, {'NJ': 16349}), ('normal control', {'wage': 133100, 'res': 'KY', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 307, 'NJ': 500, 'OH': 500, 'MI': 350, 'IN': 0, 'KY': 500, 'WV': 637}, 'res_credit': True}, {'PA': 4086, 'KY': 2569}), ('normal control', {'wage': 373364, 'res': 'MI', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY']], 'rates': {'PA': 350, 'NJ': 611, 'OH': 307, 'MI': 637, 'IN': 0, 'KY': 500, 'WV': 637}, 'res_credit': False}, {'WV': 23783, 'MI': 23783}), ('normal control', {'wage': 214002, 'res': 'KY', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 239, 'NJ': 637, 'OH': 156, 'MI': 0, 'IN': 350, 'KY': 300, 'WV': 350}, 'res_credit': True}, {'PA': 5115, 'KY': 1305}), ('normal control', {'wage': 314004, 'res': 'IN', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 0, 'NJ': 350, 'OH': 307, 'MI': 637, 'IN': 307, 'KY': 180, 'WV': 425}, 'res_credit': True}, {'IN': 9640})], [('regression', {'wage': 348021, 'res': 'MI', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 307, 'NJ': 355, 'OH': 0, 'MI': 254, 'IN': 425, 'KY': 350, 'WV': 425}, 'res_credit': True}, {'KY': 12181}), ('regression', {'wage': 202229, 'res': 'KY', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 350, 'NJ': 637, 'OH': 350, 'MI': 425, 'IN': 0, 'KY': 0, 'WV': 500}, 'res_credit': True}, {'PA': 7078}), ('partial-repair probe', {'wage': 326976, 'res': 'OH', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 543, 'NJ': 500, 'OH': 500, 'MI': 0, 'IN': 350, 'KY': 500, 'WV': 350}, 'res_credit': True}, {'NJ': 16349}), ('partial-repair probe', {'wage': 391289, 'res': 'WV', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 0, 'OH': 500, 'MI': 350, 'IN': 425, 'KY': 350, 'WV': 350}, 'res_credit': True}, {'KY': 13695}), ('normal control', {'wage': 190832, 'res': 'KY', 'work': 'OH', 'reciprocal': [['MI', 'OH']], 'rates': {'PA': 637, 'NJ': 0, 'OH': 425, 'MI': 425, 'IN': 637, 'KY': 500, 'WV': 425}, 'res_credit': True}, {'OH': 8110, 'KY': 1432}), ('normal control', {'wage': 51460, 'res': 'KY', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 307, 'OH': 425, 'MI': 350, 'IN': 637, 'KY': 652, 'WV': 0}, 'res_credit': True}, {'NJ': 1580, 'KY': 1775}), ('normal control', {'wage': 236355, 'res': 'PA', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 425, 'NJ': 307, 'OH': 425, 'MI': 425, 'IN': 350, 'KY': 637, 'WV': 637}, 'res_credit': False}, {'WV': 15056, 'PA': 10045}), ('normal control', {'wage': 91863, 'res': 'NJ', 'work': 'OH', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 350, 'NJ': 307, 'OH': 350, 'MI': 549, 'IN': 307, 'KY': 637, 'WV': 590}, 'res_credit': False}, {'OH': 3215, 'NJ': 2820})], [('regression', {'wage': 202229, 'res': 'KY', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 350, 'NJ': 637, 'OH': 350, 'MI': 425, 'IN': 0, 'KY': 0, 'WV': 500}, 'res_credit': True}, {'PA': 7078}), ('regression', {'wage': 326976, 'res': 'OH', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 543, 'NJ': 500, 'OH': 500, 'MI': 0, 'IN': 350, 'KY': 500, 'WV': 350}, 'res_credit': True}, {'NJ': 16349}), ('partial-repair probe', {'wage': 353313, 'res': 'OH', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY']], 'rates': {'PA': 500, 'NJ': 425, 'OH': 159, 'MI': 637, 'IN': 500, 'KY': 500, 'WV': 425}, 'res_credit': True}, {'IN': 17666}), ('partial-repair probe', {'wage': 92712, 'res': 'MI', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 0, 'NJ': 425, 'OH': 425, 'MI': 250, 'IN': 350, 'KY': 637, 'WV': 350}, 'res_credit': False}, {'PA': 0, 'MI': 2318}), ('normal control', {'wage': 70654, 'res': 'NJ', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY']], 'rates': {'PA': 0, 'NJ': 637, 'OH': 458, 'MI': 637, 'IN': 425, 'KY': 307, 'WV': 71}, 'res_credit': False}, {'NJ': 4501}), ('normal control', {'wage': 369165, 'res': 'PA', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 307, 'NJ': 307, 'OH': 350, 'MI': 307, 'IN': 307, 'KY': 425, 'WV': 102}, 'res_credit': False}, {'WV': 3765, 'PA': 11333}), ('normal control', {'wage': 129954, 'res': 'PA', 'work': 'PA', 'reciprocal': [['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 350, 'NJ': 651, 'OH': 637, 'MI': 0, 'IN': 0, 'KY': 623, 'WV': 0}, 'res_credit': True}, {'PA': 4548}), ('normal control', {'wage': 192147, 'res': 'OH', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 425, 'NJ': 126, 'OH': 425, 'MI': 637, 'IN': 0, 'KY': 307, 'WV': 350}, 'res_credit': False}, {'NJ': 2421, 'OH': 8166})], [('regression', {'wage': 326976, 'res': 'OH', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 543, 'NJ': 500, 'OH': 500, 'MI': 0, 'IN': 350, 'KY': 500, 'WV': 350}, 'res_credit': True}, {'NJ': 16349}), ('regression', {'wage': 391289, 'res': 'WV', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 0, 'OH': 500, 'MI': 350, 'IN': 425, 'KY': 350, 'WV': 350}, 'res_credit': True}, {'KY': 13695}), ('partial-repair probe', {'wage': 208890, 'res': 'KY', 'work': 'MI', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 0, 'NJ': 0, 'OH': 307, 'MI': 0, 'IN': 577, 'KY': 307, 'WV': 350}, 'res_credit': True}, {'MI': 0, 'KY': 6413}), ('partial-repair probe', {'wage': 104553, 'res': 'PA', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 307, 'NJ': 330, 'OH': 637, 'MI': 425, 'IN': 500, 'KY': 637, 'WV': 350}, 'res_credit': True}, {'WV': 3659}), ('normal control', {'wage': 161312, 'res': 'WV', 'work': 'OH', 'reciprocal': [['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 363, 'NJ': 90, 'OH': 307, 'MI': 670, 'IN': 307, 'KY': 500, 'WV': 500}, 'res_credit': False}, {'OH': 4952, 'WV': 8066}), ('normal control', {'wage': 377853, 'res': 'IN', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 637, 'OH': 502, 'MI': 637, 'IN': 500, 'KY': 307, 'WV': 425}, 'res_credit': True}, {'IN': 18893}), ('normal control', {'wage': 340787, 'res': 'OH', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY']], 'rates': {'PA': 0, 'NJ': 0, 'OH': 500, 'MI': 504, 'IN': 307, 'KY': 425, 'WV': 425}, 'res_credit': True}, {'KY': 14483, 'OH': 2556}), ('normal control', {'wage': 201266, 'res': 'OH', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 425, 'NJ': 425, 'OH': 500, 'MI': 500, 'IN': 637, 'KY': 307, 'WV': 350}, 'res_credit': True}, {'OH': 10063})]]
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):
    rates = x['rates']
    w = x['wage']
    def tax(st):
        return (w * rates.get(st, 0) + 5000) // 10000
    res, work = x['res'], x['work']
    if res == work:
        return {work: tax(work)}
    pair = sorted([res, work])
    if pair in x['reciprocal']:
        return {res: tax(res)}
    work_tax = tax(work)
    res_tax = max(0, tax(res) - work_tax) if x['res_credit'] else tax(res)
    out = {work: work_tax}
    if work_tax:
        out[res] = res_tax
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'wage': 92630, 'res': 'PA', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 425, 'OH': 0, 'MI': 0, 'IN': 425, 'KY': 425, 'WV': 637}, 'res_credit': True}, {'WV': 5901}), ('regression', {'wage': 108935, 'res': 'MI', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 307, 'OH': 350, 'MI': 0, 'IN': 425, 'KY': 0, 'WV': 350}, 'res_credit': False}, {'WV': 3813}), ('partial-repair probe', {'wage': 348021, 'res': 'MI', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 307, 'NJ': 355, 'OH': 0, 'MI': 254, 'IN': 425, 'KY': 350, 'WV': 425}, 'res_credit': True}, {'KY': 12181}), ('partial-repair probe', {'wage': 202229, 'res': 'KY', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 350, 'NJ': 637, 'OH': 350, 'MI': 425, 'IN': 0, 'KY': 0, 'WV': 500}, 'res_credit': True}, {'PA': 7078}), ('normal control', {'wage': 379815, 'res': 'MI', 'work': 'OH', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 637, 'OH': 0, 'MI': 637, 'IN': 350, 'KY': 307, 'WV': 242}, 'res_credit': True}, {'MI': 24194}), ('normal control', {'wage': 333788, 'res': 'NJ', 'work': 'NJ', 'reciprocal': [['IN', 'KY']], 'rates': {'PA': 637, 'NJ': 425, 'OH': 446, 'MI': 500, 'IN': 122, 'KY': 312, 'WV': 0}, 'res_credit': True}, {'NJ': 14186}), ('normal control', {'wage': 267886, 'res': 'PA', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 425, 'OH': 425, 'MI': 637, 'IN': 637, 'KY': 0, 'WV': 637}, 'res_credit': False}, {'IN': 17064, 'PA': 13394}), ('normal control', {'wage': 243443, 'res': 'IN', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 350, 'NJ': 425, 'OH': 0, 'MI': 0, 'IN': 637, 'KY': 307, 'WV': 425}, 'res_credit': True}, {'IN': 15507})], [('regression', {'wage': 108935, 'res': 'MI', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 307, 'OH': 350, 'MI': 0, 'IN': 425, 'KY': 0, 'WV': 350}, 'res_credit': False}, {'WV': 3813}), ('regression', {'wage': 348021, 'res': 'MI', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 307, 'NJ': 355, 'OH': 0, 'MI': 254, 'IN': 425, 'KY': 350, 'WV': 425}, 'res_credit': True}, {'KY': 12181}), ('partial-repair probe', {'wage': 202229, 'res': 'KY', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 350, 'NJ': 637, 'OH': 350, 'MI': 425, 'IN': 0, 'KY': 0, 'WV': 500}, 'res_credit': True}, {'PA': 7078}), ('partial-repair probe', {'wage': 326976, 'res': 'OH', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 543, 'NJ': 500, 'OH': 500, 'MI': 0, 'IN': 350, 'KY': 500, 'WV': 350}, 'res_credit': True}, {'NJ': 16349}), ('normal control', {'wage': 133100, 'res': 'KY', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 307, 'NJ': 500, 'OH': 500, 'MI': 350, 'IN': 0, 'KY': 500, 'WV': 637}, 'res_credit': True}, {'PA': 4086, 'KY': 2569}), ('normal control', {'wage': 373364, 'res': 'MI', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY']], 'rates': {'PA': 350, 'NJ': 611, 'OH': 307, 'MI': 637, 'IN': 0, 'KY': 500, 'WV': 637}, 'res_credit': False}, {'WV': 23783, 'MI': 23783}), ('normal control', {'wage': 214002, 'res': 'KY', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 239, 'NJ': 637, 'OH': 156, 'MI': 0, 'IN': 350, 'KY': 300, 'WV': 350}, 'res_credit': True}, {'PA': 5115, 'KY': 1305}), ('normal control', {'wage': 314004, 'res': 'IN', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 0, 'NJ': 350, 'OH': 307, 'MI': 637, 'IN': 307, 'KY': 180, 'WV': 425}, 'res_credit': True}, {'IN': 9640})], [('regression', {'wage': 348021, 'res': 'MI', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 307, 'NJ': 355, 'OH': 0, 'MI': 254, 'IN': 425, 'KY': 350, 'WV': 425}, 'res_credit': True}, {'KY': 12181}), ('regression', {'wage': 202229, 'res': 'KY', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 350, 'NJ': 637, 'OH': 350, 'MI': 425, 'IN': 0, 'KY': 0, 'WV': 500}, 'res_credit': True}, {'PA': 7078}), ('partial-repair probe', {'wage': 326976, 'res': 'OH', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 543, 'NJ': 500, 'OH': 500, 'MI': 0, 'IN': 350, 'KY': 500, 'WV': 350}, 'res_credit': True}, {'NJ': 16349}), ('partial-repair probe', {'wage': 391289, 'res': 'WV', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 0, 'OH': 500, 'MI': 350, 'IN': 425, 'KY': 350, 'WV': 350}, 'res_credit': True}, {'KY': 13695}), ('normal control', {'wage': 190832, 'res': 'KY', 'work': 'OH', 'reciprocal': [['MI', 'OH']], 'rates': {'PA': 637, 'NJ': 0, 'OH': 425, 'MI': 425, 'IN': 637, 'KY': 500, 'WV': 425}, 'res_credit': True}, {'OH': 8110, 'KY': 1432}), ('normal control', {'wage': 51460, 'res': 'KY', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 307, 'OH': 425, 'MI': 350, 'IN': 637, 'KY': 652, 'WV': 0}, 'res_credit': True}, {'NJ': 1580, 'KY': 1775}), ('normal control', {'wage': 236355, 'res': 'PA', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 425, 'NJ': 307, 'OH': 425, 'MI': 425, 'IN': 350, 'KY': 637, 'WV': 637}, 'res_credit': False}, {'WV': 15056, 'PA': 10045}), ('normal control', {'wage': 91863, 'res': 'NJ', 'work': 'OH', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 350, 'NJ': 307, 'OH': 350, 'MI': 549, 'IN': 307, 'KY': 637, 'WV': 590}, 'res_credit': False}, {'OH': 3215, 'NJ': 2820})], [('regression', {'wage': 202229, 'res': 'KY', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 350, 'NJ': 637, 'OH': 350, 'MI': 425, 'IN': 0, 'KY': 0, 'WV': 500}, 'res_credit': True}, {'PA': 7078}), ('regression', {'wage': 326976, 'res': 'OH', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 543, 'NJ': 500, 'OH': 500, 'MI': 0, 'IN': 350, 'KY': 500, 'WV': 350}, 'res_credit': True}, {'NJ': 16349}), ('partial-repair probe', {'wage': 353313, 'res': 'OH', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY']], 'rates': {'PA': 500, 'NJ': 425, 'OH': 159, 'MI': 637, 'IN': 500, 'KY': 500, 'WV': 425}, 'res_credit': True}, {'IN': 17666}), ('partial-repair probe', {'wage': 92712, 'res': 'MI', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 0, 'NJ': 425, 'OH': 425, 'MI': 250, 'IN': 350, 'KY': 637, 'WV': 350}, 'res_credit': False}, {'PA': 0, 'MI': 2318}), ('normal control', {'wage': 70654, 'res': 'NJ', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY']], 'rates': {'PA': 0, 'NJ': 637, 'OH': 458, 'MI': 637, 'IN': 425, 'KY': 307, 'WV': 71}, 'res_credit': False}, {'NJ': 4501}), ('normal control', {'wage': 369165, 'res': 'PA', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 307, 'NJ': 307, 'OH': 350, 'MI': 307, 'IN': 307, 'KY': 425, 'WV': 102}, 'res_credit': False}, {'WV': 3765, 'PA': 11333}), ('normal control', {'wage': 129954, 'res': 'PA', 'work': 'PA', 'reciprocal': [['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 350, 'NJ': 651, 'OH': 637, 'MI': 0, 'IN': 0, 'KY': 623, 'WV': 0}, 'res_credit': True}, {'PA': 4548}), ('normal control', {'wage': 192147, 'res': 'OH', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 425, 'NJ': 126, 'OH': 425, 'MI': 637, 'IN': 0, 'KY': 307, 'WV': 350}, 'res_credit': False}, {'NJ': 2421, 'OH': 8166})], [('regression', {'wage': 326976, 'res': 'OH', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 543, 'NJ': 500, 'OH': 500, 'MI': 0, 'IN': 350, 'KY': 500, 'WV': 350}, 'res_credit': True}, {'NJ': 16349}), ('regression', {'wage': 391289, 'res': 'WV', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 0, 'OH': 500, 'MI': 350, 'IN': 425, 'KY': 350, 'WV': 350}, 'res_credit': True}, {'KY': 13695}), ('partial-repair probe', {'wage': 208890, 'res': 'KY', 'work': 'MI', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 0, 'NJ': 0, 'OH': 307, 'MI': 0, 'IN': 577, 'KY': 307, 'WV': 350}, 'res_credit': True}, {'MI': 0, 'KY': 6413}), ('partial-repair probe', {'wage': 104553, 'res': 'PA', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 307, 'NJ': 330, 'OH': 637, 'MI': 425, 'IN': 500, 'KY': 637, 'WV': 350}, 'res_credit': True}, {'WV': 3659}), ('normal control', {'wage': 161312, 'res': 'WV', 'work': 'OH', 'reciprocal': [['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 363, 'NJ': 90, 'OH': 307, 'MI': 670, 'IN': 307, 'KY': 500, 'WV': 500}, 'res_credit': False}, {'OH': 4952, 'WV': 8066}), ('normal control', {'wage': 377853, 'res': 'IN', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 637, 'OH': 502, 'MI': 637, 'IN': 500, 'KY': 307, 'WV': 425}, 'res_credit': True}, {'IN': 18893}), ('normal control', {'wage': 340787, 'res': 'OH', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY']], 'rates': {'PA': 0, 'NJ': 0, 'OH': 500, 'MI': 504, 'IN': 307, 'KY': 425, 'WV': 425}, 'res_credit': True}, {'KY': 14483, 'OH': 2556}), ('normal control', {'wage': 201266, 'res': 'OH', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 425, 'NJ': 425, 'OH': 500, 'MI': 500, 'IN': 637, 'KY': 307, 'WV': 350}, 'res_credit': True}, {'OH': 10063})]]
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:
Pay stubs show a zero-cent resident state withholding line.

Input {wage, res, work, reciprocal:[sorted state pairs], rates:{state: basis points}, res_credit}. Tax for a state = wage*rate/10000 half-up. Same state: withhold only there. Reciprocal pair: withhold only the resident state. Otherwise withhold the work state; the resident state gets max(0, resident - work) when res_credit else its full tax; omit zero resident lines. Return {state: cents}.

split: open-access


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

N = 1
observations = []
def solve(x):
    rates = x['rates']
    w = x['wage']
    def tax(st):
        return (w * rates.get(st, 0) + 5000) // 10000
    res, work = x['res'], x['work']
    if res == work:
        return {work: tax(work)}
    pair = sorted([res, work])
    if pair in x['reciprocal']:
        return {res: tax(res)}
    work_tax = tax(work)
    res_tax = max(0, tax(res) - work_tax) if not x['res_credit'] else tax(res)
    out = {work: work_tax}
    if res_tax:
        out[res] = res_tax
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'wage': 267886, 'res': 'PA', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 425, 'OH': 425, 'MI': 637, 'IN': 637, 'KY': 0, 'WV': 637}, 'res_credit': False}, {'IN': 17064, 'PA': 13394}), ('regression', {'wage': 92630, 'res': 'PA', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 425, 'OH': 0, 'MI': 0, 'IN': 425, 'KY': 425, 'WV': 637}, 'res_credit': True}, {'WV': 5901}), ('partial-repair probe', {'wage': 373364, 'res': 'MI', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY']], 'rates': {'PA': 350, 'NJ': 611, 'OH': 307, 'MI': 637, 'IN': 0, 'KY': 500, 'WV': 637}, 'res_credit': False}, {'WV': 23783, 'MI': 23783}), ('partial-repair probe', {'wage': 236355, 'res': 'PA', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 425, 'NJ': 307, 'OH': 425, 'MI': 425, 'IN': 350, 'KY': 637, 'WV': 637}, 'res_credit': False}, {'WV': 15056, 'PA': 10045}), ('normal control', {'wage': 379815, 'res': 'MI', 'work': 'OH', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 637, 'OH': 0, 'MI': 637, 'IN': 350, 'KY': 307, 'WV': 242}, 'res_credit': True}, {'MI': 24194}), ('normal control', {'wage': 333788, 'res': 'NJ', 'work': 'NJ', 'reciprocal': [['IN', 'KY']], 'rates': {'PA': 637, 'NJ': 425, 'OH': 446, 'MI': 500, 'IN': 122, 'KY': 312, 'WV': 0}, 'res_credit': True}, {'NJ': 14186}), ('normal control', {'wage': 108935, 'res': 'MI', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 307, 'OH': 350, 'MI': 0, 'IN': 425, 'KY': 0, 'WV': 350}, 'res_credit': False}, {'WV': 3813}), ('normal control', {'wage': 243443, 'res': 'IN', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 350, 'NJ': 425, 'OH': 0, 'MI': 0, 'IN': 637, 'KY': 307, 'WV': 425}, 'res_credit': True}, {'IN': 15507})], [('regression', {'wage': 373364, 'res': 'MI', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY']], 'rates': {'PA': 350, 'NJ': 611, 'OH': 307, 'MI': 637, 'IN': 0, 'KY': 500, 'WV': 637}, 'res_credit': False}, {'WV': 23783, 'MI': 23783}), ('regression', {'wage': 267886, 'res': 'PA', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 425, 'OH': 425, 'MI': 637, 'IN': 637, 'KY': 0, 'WV': 637}, 'res_credit': False}, {'IN': 17064, 'PA': 13394}), ('partial-repair probe', {'wage': 236355, 'res': 'PA', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 425, 'NJ': 307, 'OH': 425, 'MI': 425, 'IN': 350, 'KY': 637, 'WV': 637}, 'res_credit': False}, {'WV': 15056, 'PA': 10045}), ('partial-repair probe', {'wage': 91863, 'res': 'NJ', 'work': 'OH', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 350, 'NJ': 307, 'OH': 350, 'MI': 549, 'IN': 307, 'KY': 637, 'WV': 590}, 'res_credit': False}, {'OH': 3215, 'NJ': 2820}), ('normal control', {'wage': 202229, 'res': 'KY', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 350, 'NJ': 637, 'OH': 350, 'MI': 425, 'IN': 0, 'KY': 0, 'WV': 500}, 'res_credit': True}, {'PA': 7078}), ('normal control', {'wage': 314004, 'res': 'IN', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 0, 'NJ': 350, 'OH': 307, 'MI': 637, 'IN': 307, 'KY': 180, 'WV': 425}, 'res_credit': True}, {'IN': 9640}), ('normal control', {'wage': 92712, 'res': 'MI', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 0, 'NJ': 425, 'OH': 425, 'MI': 250, 'IN': 350, 'KY': 637, 'WV': 350}, 'res_credit': False}, {'PA': 0, 'MI': 2318}), ('normal control', {'wage': 208890, 'res': 'KY', 'work': 'MI', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 0, 'NJ': 0, 'OH': 307, 'MI': 0, 'IN': 577, 'KY': 307, 'WV': 350}, 'res_credit': True}, {'MI': 0, 'KY': 6413})], [('regression', {'wage': 236355, 'res': 'PA', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 425, 'NJ': 307, 'OH': 425, 'MI': 425, 'IN': 350, 'KY': 637, 'WV': 637}, 'res_credit': False}, {'WV': 15056, 'PA': 10045}), ('regression', {'wage': 348021, 'res': 'MI', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 307, 'NJ': 355, 'OH': 0, 'MI': 254, 'IN': 425, 'KY': 350, 'WV': 425}, 'res_credit': True}, {'KY': 12181}), ('partial-repair probe', {'wage': 369165, 'res': 'PA', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 307, 'NJ': 307, 'OH': 350, 'MI': 307, 'IN': 307, 'KY': 425, 'WV': 102}, 'res_credit': False}, {'WV': 3765, 'PA': 11333}), ('partial-repair probe', {'wage': 192147, 'res': 'OH', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 425, 'NJ': 126, 'OH': 425, 'MI': 637, 'IN': 0, 'KY': 307, 'WV': 350}, 'res_credit': False}, {'NJ': 2421, 'OH': 8166}), ('normal control', {'wage': 70654, 'res': 'NJ', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY']], 'rates': {'PA': 0, 'NJ': 637, 'OH': 458, 'MI': 637, 'IN': 425, 'KY': 307, 'WV': 71}, 'res_credit': False}, {'NJ': 4501}), ('normal control', {'wage': 129954, 'res': 'PA', 'work': 'PA', 'reciprocal': [['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 350, 'NJ': 651, 'OH': 637, 'MI': 0, 'IN': 0, 'KY': 623, 'WV': 0}, 'res_credit': True}, {'PA': 4548}), ('normal control', {'wage': 231453, 'res': 'MI', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 0, 'NJ': 0, 'OH': 500, 'MI': 307, 'IN': 350, 'KY': 637, 'WV': 307}, 'res_credit': False}, {'PA': 0, 'MI': 7106}), ('normal control', {'wage': 377853, 'res': 'IN', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 637, 'OH': 502, 'MI': 637, 'IN': 500, 'KY': 307, 'WV': 425}, 'res_credit': True}, {'IN': 18893})], [('regression', {'wage': 91863, 'res': 'NJ', 'work': 'OH', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 350, 'NJ': 307, 'OH': 350, 'MI': 549, 'IN': 307, 'KY': 637, 'WV': 590}, 'res_credit': False}, {'OH': 3215, 'NJ': 2820}), ('regression', {'wage': 133100, 'res': 'KY', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 307, 'NJ': 500, 'OH': 500, 'MI': 350, 'IN': 0, 'KY': 500, 'WV': 637}, 'res_credit': True}, {'PA': 4086, 'KY': 2569}), ('partial-repair probe', {'wage': 161312, 'res': 'WV', 'work': 'OH', 'reciprocal': [['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 363, 'NJ': 90, 'OH': 307, 'MI': 670, 'IN': 307, 'KY': 500, 'WV': 500}, 'res_credit': False}, {'OH': 4952, 'WV': 8066}), ('partial-repair probe', {'wage': 388515, 'res': 'MI', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 350, 'OH': 205, 'MI': 350, 'IN': 250, 'KY': 0, 'WV': 307}, 'res_credit': False}, {'NJ': 13598, 'MI': 13598}), ('normal control', {'wage': 122807, 'res': 'KY', 'work': 'PA', 'reciprocal': [['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 307, 'NJ': 637, 'OH': 425, 'MI': 0, 'IN': 425, 'KY': 0, 'WV': 0}, 'res_credit': True}, {'PA': 3770}), ('normal control', {'wage': 201266, 'res': 'OH', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 425, 'NJ': 425, 'OH': 500, 'MI': 500, 'IN': 637, 'KY': 307, 'WV': 350}, 'res_credit': True}, {'OH': 10063}), ('normal control', {'wage': 238358, 'res': 'IN', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 0, 'NJ': 0, 'OH': 288, 'MI': 0, 'IN': 425, 'KY': 350, 'WV': 500}, 'res_credit': True}, {'NJ': 0, 'IN': 10130}), ('normal control', {'wage': 363240, 'res': 'PA', 'work': 'MI', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 0, 'NJ': 350, 'OH': 350, 'MI': 307, 'IN': 279, 'KY': 262, 'WV': 425}, 'res_credit': True}, {'MI': 11151})], [('regression', {'wage': 369165, 'res': 'PA', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 307, 'NJ': 307, 'OH': 350, 'MI': 307, 'IN': 307, 'KY': 425, 'WV': 102}, 'res_credit': False}, {'WV': 3765, 'PA': 11333}), ('regression', {'wage': 326976, 'res': 'OH', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 543, 'NJ': 500, 'OH': 500, 'MI': 0, 'IN': 350, 'KY': 500, 'WV': 350}, 'res_credit': True}, {'NJ': 16349}), ('partial-repair probe', {'wage': 321120, 'res': 'PA', 'work': 'OH', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 307, 'OH': 350, 'MI': 500, 'IN': 350, 'KY': 425, 'WV': 637}, 'res_credit': False}, {'OH': 11239, 'PA': 20455}), ('partial-repair probe', {'wage': 12418, 'res': 'KY', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 500, 'OH': 0, 'MI': 637, 'IN': 637, 'KY': 307, 'WV': 500}, 'res_credit': False}, {'NJ': 621, 'KY': 381}), ('normal control', {'wage': 19055, 'res': 'IN', 'work': 'OH', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY']], 'rates': {'PA': 637, 'NJ': 466, 'OH': 0, 'MI': 0, 'IN': 425, 'KY': 307, 'WV': 307}, 'res_credit': False}, {'OH': 0, 'IN': 810}), ('normal control', {'wage': 43218, 'res': 'NJ', 'work': 'MI', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY']], 'rates': {'PA': 641, 'NJ': 352, 'OH': 0, 'MI': 0, 'IN': 307, 'KY': 425, 'WV': 425}, 'res_credit': False}, {'MI': 0, 'NJ': 1521}), ('normal control', {'wage': 108017, 'res': 'PA', 'work': 'KY', 'reciprocal': [['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 637, 'OH': 307, 'MI': 500, 'IN': 500, 'KY': 0, 'WV': 425}, 'res_credit': True}, {'KY': 0, 'PA': 6881}), ('normal control', {'wage': 162145, 'res': 'IN', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 307, 'OH': 350, 'MI': 425, 'IN': 425, 'KY': 0, 'WV': 425}, 'res_credit': False}, {'IN': 6891})]]
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):
    rates = x['rates']
    w = x['wage']
    def tax(st):
        return (w * rates.get(st, 0) + 5000) // 10000
    res, work = x['res'], x['work']
    if res == work:
        return {work: tax(work)}
    pair = sorted([res, work])
    if pair in x['reciprocal']:
        return {res: tax(res)}
    work_tax = tax(work)
    res_tax = max(0, tax(res) - work_tax) if x['res_credit'] or work_tax > 0 else tax(res)
    out = {work: work_tax}
    if res_tax:
        out[res] = res_tax
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'wage': 267886, 'res': 'PA', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 425, 'OH': 425, 'MI': 637, 'IN': 637, 'KY': 0, 'WV': 637}, 'res_credit': False}, {'IN': 17064, 'PA': 13394}), ('regression', {'wage': 92630, 'res': 'PA', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 425, 'OH': 0, 'MI': 0, 'IN': 425, 'KY': 425, 'WV': 637}, 'res_credit': True}, {'WV': 5901}), ('partial-repair probe', {'wage': 373364, 'res': 'MI', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY']], 'rates': {'PA': 350, 'NJ': 611, 'OH': 307, 'MI': 637, 'IN': 0, 'KY': 500, 'WV': 637}, 'res_credit': False}, {'WV': 23783, 'MI': 23783}), ('partial-repair probe', {'wage': 236355, 'res': 'PA', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 425, 'NJ': 307, 'OH': 425, 'MI': 425, 'IN': 350, 'KY': 637, 'WV': 637}, 'res_credit': False}, {'WV': 15056, 'PA': 10045}), ('normal control', {'wage': 379815, 'res': 'MI', 'work': 'OH', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 637, 'OH': 0, 'MI': 637, 'IN': 350, 'KY': 307, 'WV': 242}, 'res_credit': True}, {'MI': 24194}), ('normal control', {'wage': 333788, 'res': 'NJ', 'work': 'NJ', 'reciprocal': [['IN', 'KY']], 'rates': {'PA': 637, 'NJ': 425, 'OH': 446, 'MI': 500, 'IN': 122, 'KY': 312, 'WV': 0}, 'res_credit': True}, {'NJ': 14186}), ('normal control', {'wage': 108935, 'res': 'MI', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 307, 'OH': 350, 'MI': 0, 'IN': 425, 'KY': 0, 'WV': 350}, 'res_credit': False}, {'WV': 3813}), ('normal control', {'wage': 243443, 'res': 'IN', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 350, 'NJ': 425, 'OH': 0, 'MI': 0, 'IN': 637, 'KY': 307, 'WV': 425}, 'res_credit': True}, {'IN': 15507})], [('regression', {'wage': 373364, 'res': 'MI', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY']], 'rates': {'PA': 350, 'NJ': 611, 'OH': 307, 'MI': 637, 'IN': 0, 'KY': 500, 'WV': 637}, 'res_credit': False}, {'WV': 23783, 'MI': 23783}), ('regression', {'wage': 267886, 'res': 'PA', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 425, 'OH': 425, 'MI': 637, 'IN': 637, 'KY': 0, 'WV': 637}, 'res_credit': False}, {'IN': 17064, 'PA': 13394}), ('partial-repair probe', {'wage': 236355, 'res': 'PA', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 425, 'NJ': 307, 'OH': 425, 'MI': 425, 'IN': 350, 'KY': 637, 'WV': 637}, 'res_credit': False}, {'WV': 15056, 'PA': 10045}), ('partial-repair probe', {'wage': 91863, 'res': 'NJ', 'work': 'OH', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 350, 'NJ': 307, 'OH': 350, 'MI': 549, 'IN': 307, 'KY': 637, 'WV': 590}, 'res_credit': False}, {'OH': 3215, 'NJ': 2820}), ('normal control', {'wage': 202229, 'res': 'KY', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 350, 'NJ': 637, 'OH': 350, 'MI': 425, 'IN': 0, 'KY': 0, 'WV': 500}, 'res_credit': True}, {'PA': 7078}), ('normal control', {'wage': 314004, 'res': 'IN', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 0, 'NJ': 350, 'OH': 307, 'MI': 637, 'IN': 307, 'KY': 180, 'WV': 425}, 'res_credit': True}, {'IN': 9640}), ('normal control', {'wage': 92712, 'res': 'MI', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 0, 'NJ': 425, 'OH': 425, 'MI': 250, 'IN': 350, 'KY': 637, 'WV': 350}, 'res_credit': False}, {'PA': 0, 'MI': 2318}), ('normal control', {'wage': 208890, 'res': 'KY', 'work': 'MI', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 0, 'NJ': 0, 'OH': 307, 'MI': 0, 'IN': 577, 'KY': 307, 'WV': 350}, 'res_credit': True}, {'MI': 0, 'KY': 6413})], [('regression', {'wage': 236355, 'res': 'PA', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 425, 'NJ': 307, 'OH': 425, 'MI': 425, 'IN': 350, 'KY': 637, 'WV': 637}, 'res_credit': False}, {'WV': 15056, 'PA': 10045}), ('regression', {'wage': 348021, 'res': 'MI', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 307, 'NJ': 355, 'OH': 0, 'MI': 254, 'IN': 425, 'KY': 350, 'WV': 425}, 'res_credit': True}, {'KY': 12181}), ('partial-repair probe', {'wage': 369165, 'res': 'PA', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 307, 'NJ': 307, 'OH': 350, 'MI': 307, 'IN': 307, 'KY': 425, 'WV': 102}, 'res_credit': False}, {'WV': 3765, 'PA': 11333}), ('partial-repair probe', {'wage': 192147, 'res': 'OH', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 425, 'NJ': 126, 'OH': 425, 'MI': 637, 'IN': 0, 'KY': 307, 'WV': 350}, 'res_credit': False}, {'NJ': 2421, 'OH': 8166}), ('normal control', {'wage': 70654, 'res': 'NJ', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY']], 'rates': {'PA': 0, 'NJ': 637, 'OH': 458, 'MI': 637, 'IN': 425, 'KY': 307, 'WV': 71}, 'res_credit': False}, {'NJ': 4501}), ('normal control', {'wage': 129954, 'res': 'PA', 'work': 'PA', 'reciprocal': [['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 350, 'NJ': 651, 'OH': 637, 'MI': 0, 'IN': 0, 'KY': 623, 'WV': 0}, 'res_credit': True}, {'PA': 4548}), ('normal control', {'wage': 231453, 'res': 'MI', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 0, 'NJ': 0, 'OH': 500, 'MI': 307, 'IN': 350, 'KY': 637, 'WV': 307}, 'res_credit': False}, {'PA': 0, 'MI': 7106}), ('normal control', {'wage': 377853, 'res': 'IN', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 637, 'OH': 502, 'MI': 637, 'IN': 500, 'KY': 307, 'WV': 425}, 'res_credit': True}, {'IN': 18893})], [('regression', {'wage': 91863, 'res': 'NJ', 'work': 'OH', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 350, 'NJ': 307, 'OH': 350, 'MI': 549, 'IN': 307, 'KY': 637, 'WV': 590}, 'res_credit': False}, {'OH': 3215, 'NJ': 2820}), ('regression', {'wage': 133100, 'res': 'KY', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 307, 'NJ': 500, 'OH': 500, 'MI': 350, 'IN': 0, 'KY': 500, 'WV': 637}, 'res_credit': True}, {'PA': 4086, 'KY': 2569}), ('partial-repair probe', {'wage': 161312, 'res': 'WV', 'work': 'OH', 'reciprocal': [['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 363, 'NJ': 90, 'OH': 307, 'MI': 670, 'IN': 307, 'KY': 500, 'WV': 500}, 'res_credit': False}, {'OH': 4952, 'WV': 8066}), ('partial-repair probe', {'wage': 388515, 'res': 'MI', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 350, 'OH': 205, 'MI': 350, 'IN': 250, 'KY': 0, 'WV': 307}, 'res_credit': False}, {'NJ': 13598, 'MI': 13598}), ('normal control', {'wage': 122807, 'res': 'KY', 'work': 'PA', 'reciprocal': [['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 307, 'NJ': 637, 'OH': 425, 'MI': 0, 'IN': 425, 'KY': 0, 'WV': 0}, 'res_credit': True}, {'PA': 3770}), ('normal control', {'wage': 201266, 'res': 'OH', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 425, 'NJ': 425, 'OH': 500, 'MI': 500, 'IN': 637, 'KY': 307, 'WV': 350}, 'res_credit': True}, {'OH': 10063}), ('normal control', {'wage': 238358, 'res': 'IN', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 0, 'NJ': 0, 'OH': 288, 'MI': 0, 'IN': 425, 'KY': 350, 'WV': 500}, 'res_credit': True}, {'NJ': 0, 'IN': 10130}), ('normal control', {'wage': 363240, 'res': 'PA', 'work': 'MI', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 0, 'NJ': 350, 'OH': 350, 'MI': 307, 'IN': 279, 'KY': 262, 'WV': 425}, 'res_credit': True}, {'MI': 11151})], [('regression', {'wage': 369165, 'res': 'PA', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 307, 'NJ': 307, 'OH': 350, 'MI': 307, 'IN': 307, 'KY': 425, 'WV': 102}, 'res_credit': False}, {'WV': 3765, 'PA': 11333}), ('regression', {'wage': 326976, 'res': 'OH', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 543, 'NJ': 500, 'OH': 500, 'MI': 0, 'IN': 350, 'KY': 500, 'WV': 350}, 'res_credit': True}, {'NJ': 16349}), ('partial-repair probe', {'wage': 321120, 'res': 'PA', 'work': 'OH', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 307, 'OH': 350, 'MI': 500, 'IN': 350, 'KY': 425, 'WV': 637}, 'res_credit': False}, {'OH': 11239, 'PA': 20455}), ('partial-repair probe', {'wage': 12418, 'res': 'KY', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 500, 'OH': 0, 'MI': 637, 'IN': 637, 'KY': 307, 'WV': 500}, 'res_credit': False}, {'NJ': 621, 'KY': 381}), ('normal control', {'wage': 19055, 'res': 'IN', 'work': 'OH', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY']], 'rates': {'PA': 637, 'NJ': 466, 'OH': 0, 'MI': 0, 'IN': 425, 'KY': 307, 'WV': 307}, 'res_credit': False}, {'OH': 0, 'IN': 810}), ('normal control', {'wage': 43218, 'res': 'NJ', 'work': 'MI', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY']], 'rates': {'PA': 641, 'NJ': 352, 'OH': 0, 'MI': 0, 'IN': 307, 'KY': 425, 'WV': 425}, 'res_credit': False}, {'MI': 0, 'NJ': 1521}), ('normal control', {'wage': 108017, 'res': 'PA', 'work': 'KY', 'reciprocal': [['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 637, 'OH': 307, 'MI': 500, 'IN': 500, 'KY': 0, 'WV': 425}, 'res_credit': True}, {'KY': 0, 'PA': 6881}), ('normal control', {'wage': 162145, 'res': 'IN', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 307, 'OH': 350, 'MI': 425, 'IN': 425, 'KY': 0, 'WV': 425}, 'res_credit': False}, {'IN': 6891})]]
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:
Resident states without a credit election receive the reduced amount, and vice versa.

Input {wage, res, work, reciprocal:[sorted state pairs], rates:{state: basis points}, res_credit}. Tax for a state = wage*rate/10000 half-up. Same state: withhold only there. Reciprocal pair: withhold only the resident state. Otherwise withhold the work state; the resident state gets max(0, resident - work) when res_credit else its full tax; omit zero resident lines. Return {state: cents}.

split: open-access


prompt:
Employees turning 50 this year are blocked from catch-up contributions.

Input {gross, pct, ytd, birth_year, year, net_available}. Requested deferral = gross*pct/100 half-up. Annual cap 23,000.00 plus 7,500.00 catch-up when the employee turns 50 or older during the year. Deferral = min(request, max(0, cap - ytd), net_available). Return [deferral, remaining room after it].

split: open-access


prompt:
Deferrals are smaller than the election because they are computed on net pay.

Input {gross, pct, ytd, birth_year, year, net_available}. Requested deferral = gross*pct/100 half-up. Annual cap 23,000.00 plus 7,500.00 catch-up when the employee turns 50 or older during the year. Deferral = min(request, max(0, cap - ytd), net_available). Return [deferral, remaining room after it].

split: open-access


prompt:
Paychecks with large taxes defer more than the cash available, driving net pay negative.

Input {gross, pct, ytd, birth_year, year, net_available}. Requested deferral = gross*pct/100 half-up. Annual cap 23,000.00 plus 7,500.00 catch-up when the employee turns 50 or older during the year. Deferral = min(request, max(0, cap - ytd), net_available). Return [deferral, remaining room after it].

split: open-access


prompt:
Reported remaining deferral room ignores year-to-date contributions.

Input {gross, pct, ytd, birth_year, year, net_available}. Requested deferral = gross*pct/100 half-up. Annual cap 23,000.00 plus 7,500.00 catch-up when the employee turns 50 or older during the year. Deferral = min(request, max(0, cap - ytd), net_available). Return [deferral, remaining room after it].

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[0] 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'] - 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, 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self'], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 456065, 'request': 36894}, [529600, 36894]), ('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, 'self', None, None, None, None, None], 'age': 55, 'employer_ytd': 115762, 'employee_ytd': 24574, 'request': 286981}, [44133, 0]), ('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': [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, None, 'self'], 'age': 56, 'employer_ytd': 0, 'employee_ytd': 524863, 'request': 386331}, [529600, 4737]), ('regression', {'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': ['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, None, None, None, None, None, None, 'self', 'self', 'self', 'self', 'self'], 'age': 25, 'employer_ytd': 28613, 'employee_ytd': 65322, 'request': 390696}, [429600, 335665]), ('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': ['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])], [('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, None, 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self'], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 456065, 'request': 36894}, [529600, 36894]), ('partial-repair probe', {'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]), ('partial-repair probe', {'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]), ('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]), ('normal control', {'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': ['family', None, None, None, 'family', None, 'self', 'family', 'self', 'family', None, 'family'], 'age': 56, 'employer_ytd': 0, 'employee_ytd': 555307, 'request': 67227}, [955000, 67227]), ('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])], [('regression', {'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]), ('regression', {'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': ['family', None, 'self', 'family', 'family', 'self', 'self', 'self', 'self', 'self', 'family', 'self'], 'age': 40, 'employer_ytd': 209919, 'employee_ytd': 194888, 'request': 252834}, [429600, 24793]), ('partial-repair probe', {'coverage': ['self', 'family', 'family', 'self', 'self', 'self', 'family', 'family', 'self', 'self', 'family', 'self'], 'age': 52, 'employer_ytd': 229253, 'employee_ytd': 485049, 'request': 147605}, [429600, 0]), ('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]), ('normal control', {'coverage': ['family', None, 'family', None, 'family', 'family', 'family', None, 'self', None, 'family', 'family'], 'age': 69, 'employer_ytd': 261888, 'employee_ytd': 315926, 'request': 316230}, [955000, 316230])], [('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, 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family'], 'age': 40, 'employer_ytd': 0, 'employee_ytd': 164388, 'request': 96773}, [855000, 96773]), ('partial-repair probe', {'coverage': [None, None, None, None, None, None, None, None, None, None, None, 'self'], 'age': 55, 'employer_ytd': 57484, 'employee_ytd': 55375, 'request': 233853}, [529600, 233853]), ('partial-repair probe', {'coverage': [None, None, None, None, None, 'self', 'self', 'self', 'self', 'self', 'self', 'self'], 'age': 55, 'employer_ytd': 280115, 'employee_ytd': 65179, 'request': 93980}, [529600, 93980]), ('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, 'self', 'self', None, 'family', None, None, None, 'self', 'family', 'family', None], 'age': 54, 'employer_ytd': 181950, 'employee_ytd': 107143, 'request': 54200}, [321150, 32057]), ('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])]]
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] == 'family':
        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'] - 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, 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self'], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 456065, 'request': 36894}, [529600, 36894]), ('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, 'self', None, None, None, None, None], 'age': 55, 'employer_ytd': 115762, 'employee_ytd': 24574, 'request': 286981}, [44133, 0]), ('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': [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, None, 'self'], 'age': 56, 'employer_ytd': 0, 'employee_ytd': 524863, 'request': 386331}, [529600, 4737]), ('regression', {'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': ['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, None, None, None, None, None, None, 'self', 'self', 'self', 'self', 'self'], 'age': 25, 'employer_ytd': 28613, 'employee_ytd': 65322, 'request': 390696}, [429600, 335665]), ('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': ['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])], [('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, None, 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self', 'self'], 'age': 55, 'employer_ytd': 0, 'employee_ytd': 456065, 'request': 36894}, [529600, 36894]), ('partial-repair probe', {'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]), ('partial-repair probe', {'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]), ('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]), ('normal control', {'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': ['family', None, None, None, 'family', None, 'self', 'family', 'self', 'family', None, 'family'], 'age': 56, 'employer_ytd': 0, 'employee_ytd': 555307, 'request': 67227}, [955000, 67227]), ('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])], [('regression', {'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]), ('regression', {'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': ['family', None, 'self', 'family', 'family', 'self', 'self', 'self', 'self', 'self', 'family', 'self'], 'age': 40, 'employer_ytd': 209919, 'employee_ytd': 194888, 'request': 252834}, [429600, 24793]), ('partial-repair probe', {'coverage': ['self', 'family', 'family', 'self', 'self', 'self', 'family', 'family', 'self', 'self', 'family', 'self'], 'age': 52, 'employer_ytd': 229253, 'employee_ytd': 485049, 'request': 147605}, [429600, 0]), ('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]), ('normal control', {'coverage': ['family', None, 'family', None, 'family', 'family', 'family', None, 'self', None, 'family', 'family'], 'age': 69, 'employer_ytd': 261888, 'employee_ytd': 315926, 'request': 316230}, [955000, 316230])], [('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, 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family', 'family'], 'age': 40, 'employer_ytd': 0, 'employee_ytd': 164388, 'request': 96773}, [855000, 96773]), ('partial-repair probe', {'coverage': [None, None, None, None, None, None, None, None, None, None, None, 'self'], 'age': 55, 'employer_ytd': 57484, 'employee_ytd': 55375, 'request': 233853}, [529600, 233853]), ('partial-repair probe', {'coverage': [None, None, None, None, None, 'self', 'self', 'self', 'self', 'self', 'self', 'self'], 'age': 55, 'employer_ytd': 280115, 'employee_ytd': 65179, 'request': 93980}, [529600, 93980]), ('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, 'self', 'self', None, 'family', None, None, None, 'self', 'family', 'family', None], 'age': 54, 'employer_ytd': 181950, 'employee_ytd': 107143, 'request': 54200}, [321150, 32057]), ('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])]]
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 enroll mid-year are limited to a partial-year amount despite December coverage.

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