{"abstract":"An allowance carrying a debit balance is under-adjusted.","category":"Double-entry ledger accounting","checks":7,"contract":"x = {'as_of': day, 'invoices': [[id, due_day, open cents]], 'rates': [[max_days_past_due or None, basis points]] ascending, 'allowance': existing credit balance (negative = debit balance), 'writeoffs': ids}. Written-off invoices leave receivables and reduce the allowance by their amount. Days past due = max(0, as_of - due); an invoice goes in the first bucket whose limit is None or >= days. Required allowance = sum over buckets of bucket total * bp / 10000 rounded half-up per bucket. Return {'buckets', 'required', 'adjustment': required - allowance after write-offs, 'net_ar'}.","evaluation_group":"w2-double-entry-ledger-accounting-aging-allowance","failed_approach":"Adding the balance breaks the ordinary credit-balance case.","family":"w2-double-entry-ledger-accounting-aging-allowance-adjustment-against-debit-balance","id":"FA-58141","implementations":{"attempt":{"sha256":"16155b800c218f9687d8a655cc15d07fc1005b4a0701f4f175102fbccbedc9f5","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\n\nN = 1\nobservations = []\ndef solve(x):\n    wo = set(x['writeoffs'])\n    allowance = x['allowance']\n    buckets = [0] * len(x['rates'])\n    for iid, due, amt in x['invoices']:\n        if iid in wo:\n            allowance -= amt\n            continue\n        past = max(0, x['as_of'] - due)\n        for k, (limit, bp) in enumerate(x['rates']):\n            if limit is None or past <= limit:\n                buckets[k] += amt\n                break\n    required = 0\n    for total, (limit, bp) in zip(buckets, x['rates']):\n        q, r = divmod(total * bp, 10000)\n        required += q + (1 if 2 * r >= 10000 else 0)\n    ar = sum(buckets)\n    return {'buckets': buckets, 'required': required, 'adjustment': required + allowance, 'net_ar': ar - required}\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\nfixtures = [[['regression: adjustment against debit balance', {'as_of': 100, 'invoices': [['I0', -100, 5], ['I1', 39, 333], ['I2', 9, 2500], ['I3', -100, 4000], ['I4', 69, 150], ['I5', 70, 2500], ['I6', 55, 4000]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 0, 'writeoffs': ['I5', 'I6']}, {'buckets': [0, 0, 150, 333, 6505], 'required': 5035, 'adjustment': 11535, 'net_ar': 1953}], ['control 1', {'as_of': 100, 'invoices': [['I0', 10, 4000], ['I1', 110, 150], ['I2', 100, 4000], ['I3', 40, 4000]], 'rates': [[0, 200], [45, 1250], [None, 5000]], 'allowance': 0, 'writeoffs': []}, {'buckets': [4150, 0, 8000], 'required': 4083, 'adjustment': 4083, 'net_ar': 8067}], ['control 2', {'as_of': 100, 'invoices': [['I0', 100, 333], ['I1', 70, 2500], ['I2', 55, 5], ['I3', 39, 2500]], 'rates': [[0, 200], [45, 1250], [None, 5000]], 'allowance': 200, 'writeoffs': []}, {'buckets': [333, 2505, 2500], 'required': 1570, 'adjustment': 1370, 'net_ar': 3768}], ['control 3', {'as_of': 100, 'invoices': [['I0', 40, 333], ['I1', 70, 150], ['I2', 99, 150], ['I3', 9, 333], ['I4', 100, 333]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 500, 'writeoffs': []}, {'buckets': [333, 300, 333, 0, 333], 'required': 318, 'adjustment': -182, 'net_ar': 981}], ['control 4', {'as_of': 100, 'invoices': [['I0', 40, 2500], ['I1', 99, 4000], ['I2', 9, 1000]], 'rates': [[0, 200], [45, 1250], [None, 5000]], 'allowance': 0, 'writeoffs': []}, {'buckets': [0, 4000, 3500], 'required': 2250, 'adjustment': 2250, 'net_ar': 5250}], ['control 5', {'as_of': 100, 'invoices': [['I0', 70, 333], ['I1', 70, 150], ['I2', 54, 5], ['I3', 100, 2500], ['I4', 100, 1000], ['I5', 70, 5], ['I6', 54, 1000]], 'rates': [[0, 200], [45, 1250], [None, 5000]], 'allowance': 0, 'writeoffs': []}, {'buckets': [3500, 488, 1005], 'required': 634, 'adjustment': 634, 'net_ar': 4359}], ['control 6', {'as_of': 100, 'invoices': [['I0', 69, 150], ['I1', 54, 150], ['I2', 54, 4000], ['I3', 70, 4000], ['I4', 40, 333], ['I5', 69, 2500]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 200, 'writeoffs': []}, {'buckets': [0, 4000, 7133, 0, 0], 'required': 1270, 'adjustment': 1070, 'net_ar': 9863}]], [['regression: adjustment against debit balance', {'as_of': 100, 'invoices': [['I0', 99, 2500], ['I1', 69, 1000], ['I2', 55, 333], ['I3', 39, 1000], ['I4', 39, 333], ['I5', 40, 4000]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 200, 'writeoffs': ['I1', 'I4', 'I5']}, {'buckets': [0, 2500, 333, 1000, 0], 'required': 575, 'adjustment': 5708, 'net_ar': 3258}], ['control 1', {'as_of': 100, 'invoices': [['I0', 70, 5], ['I1', 69, 5], ['I2', 71, 333], ['I3', -100, 5], ['I4', 54, 333], ['I5', 100, 150], ['I6', 71, 150]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 200, 'writeoffs': ['I0', 'I5']}, {'buckets': [0, 483, 338, 0, 5], 'required': 79, 'adjustment': 34, 'net_ar': 747}], ['control 2', {'as_of': 100, 'invoices': [['I0', 54, 1000], ['I1', 69, 333], ['I2', 55, 150], ['I3', 70, 150]], 'rates': [[0, 200], [45, 1250], [None, 5000]], 'allowance': 200, 'writeoffs': []}, {'buckets': [0, 633, 1000], 'required': 579, 'adjustment': 379, 'net_ar': 1054}], ['control 3', {'as_of': 100, 'invoices': [['I0', 39, 333], ['I1', 100, 1000], ['I2', 54, 2500], ['I3', -100, 2500], ['I4', 71, 150], ['I5', 70, 4000], ['I6', -100, 1000]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 500, 'writeoffs': []}, {'buckets': [1000, 4150, 2500, 333, 3500], 'required': 3351, 'adjustment': 2851, 'net_ar': 8132}], ['control 4', {'as_of': 100, 'invoices': [['I0', 70, 4000], ['I1', -100, 2500], ['I2', 55, 5], ['I3', 39, 5], ['I4', 99, 4000], ['I5', 69, 2500], ['I6', 40, 4000]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 500, 'writeoffs': ['I3']}, {'buckets': [0, 8000, 6505, 0, 2500], 'required': 3251, 'adjustment': 2756, 'net_ar': 13754}], ['control 5', {'as_of': 100, 'invoices': [['I0', 100, 5], ['I1', 69, 2500], ['I2', 9, 4000], ['I3', 39, 4000], ['I4', 99, 4000], ['I5', 39, 1000], ['I6', 100, 5]], 'rates': [[0, 200], [45, 1250], [None, 5000]], 'allowance': 0, 'writeoffs': []}, {'buckets': [10, 6500, 9000], 'required': 5313, 'adjustment': 5313, 'net_ar': 10197}], ['control 6', {'as_of': 100, 'invoices': [['I0', 70, 150], ['I1', 55, 150], ['I2', -100, 5]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 200, 'writeoffs': ['I2']}, {'buckets': [0, 150, 150, 0, 0], 'required': 31, 'adjustment': -164, 'net_ar': 269}]], [['regression: adjustment against debit balance', {'as_of': 100, 'invoices': [['I0', 69, 4000], ['I1', 110, 4000], ['I2', 55, 1000], ['I3', 100, 4000]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 0, 'writeoffs': ['I1']}, {'buckets': [4000, 0, 5000, 0, 0], 'required': 790, 'adjustment': 4790, 'net_ar': 8210}], ['control 1', {'as_of': 100, 'invoices': [['I0', 54, 150], ['I1', 71, 4000], ['I2', 70, 2500], ['I3', 110, 150], ['I4', 99, 5]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 500, 'writeoffs': ['I3']}, {'buckets': [0, 6505, 150, 0, 0], 'required': 348, 'adjustment': -2, 'net_ar': 6307}], ['control 2', {'as_of': 100, 'invoices': [['I0', 100, 4000], ['I1', 69, 1000], ['I2', 55, 4000]], 'rates': [[0, 200], [45, 1250], [None, 5000]], 'allowance': 200, 'writeoffs': []}, {'buckets': [4000, 5000, 0], 'required': 705, 'adjustment': 505, 'net_ar': 8295}], ['control 3', {'as_of': 100, 'invoices': [['I0', 100, 1000], ['I1', 54, 333], ['I2', 69, 1000], ['I3', 40, 150]], 'rates': [[0, 200], [45, 1250], [None, 5000]], 'allowance': 200, 'writeoffs': []}, {'buckets': [1000, 1000, 483], 'required': 387, 'adjustment': 187, 'net_ar': 2096}], ['control 4', {'as_of': 100, 'invoices': [['I0', 39, 2500], ['I1', 69, 150], ['I2', 55, 333]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 200, 'writeoffs': ['I1']}, {'buckets': [0, 0, 333, 2500, 0], 'required': 1050, 'adjustment': 1000, 'net_ar': 1783}], ['control 5', {'as_of': 100, 'invoices': [['I0', 70, 4000], ['I1', 54, 1000], ['I2', 70, 5]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 200, 'writeoffs': []}, {'buckets': [0, 4005, 1000, 0, 0], 'required': 350, 'adjustment': 150, 'net_ar': 4655}], ['control 6', {'as_of': 100, 'invoices': [['I0', 9, 2500], ['I1', 10, 2500], ['I2', 55, 333], ['I3', 69, 5]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 0, 'writeoffs': []}, {'buckets': [0, 0, 338, 2500, 2500], 'required': 2926, 'adjustment': 2926, 'net_ar': 2412}]], [['regression: adjustment against debit balance', {'as_of': 100, 'invoices': [['I0', 110, 150], ['I1', 10, 1000], ['I2', 70, 150], ['I3', 99, 1000], ['I4', 100, 2500], ['I5', 55, 333], ['I6', 54, 150]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 0, 'writeoffs': ['I5', 'I6']}, {'buckets': [2650, 1150, 0, 1000, 0], 'required': 485, 'adjustment': 968, 'net_ar': 4315}], ['control 1', {'as_of': 100, 'invoices': [['I0', 69, 150], ['I1', 71, 150], ['I2', 70, 150]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 500, 'writeoffs': ['I2']}, {'buckets': [0, 150, 150, 0, 0], 'required': 31, 'adjustment': -319, 'net_ar': 269}], ['control 2', {'as_of': 100, 'invoices': [['I0', 54, 1000], ['I1', 100, 5], ['I2', 70, 150], ['I3', 110, 150], ['I4', 100, 2500], ['I5', -100, 333], ['I6', 100, 150]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 0, 'writeoffs': []}, {'buckets': [2805, 150, 1000, 0, 333], 'required': 436, 'adjustment': 436, 'net_ar': 3852}], ['control 3', {'as_of': 100, 'invoices': [['I0', 71, 333], ['I1', 39, 150], ['I2', 71, 4000]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 0, 'writeoffs': []}, {'buckets': [0, 4333, 0, 150, 0], 'required': 277, 'adjustment': 277, 'net_ar': 4206}], ['control 4', {'as_of': 100, 'invoices': [['I0', 110, 2500], ['I1', 69, 150], ['I2', 54, 2500], ['I3', 10, 333]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 200, 'writeoffs': ['I1']}, {'buckets': [2500, 0, 2500, 333, 0], 'required': 533, 'adjustment': 483, 'net_ar': 4800}], ['control 5', {'as_of': 100, 'invoices': [['I0', 69, 2500], ['I1', 69, 150], ['I2', 55, 5], ['I3', 71, 1000], ['I4', 55, 4000], ['I5', -100, 2500], ['I6', 69, 4000]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 500, 'writeoffs': []}, {'buckets': [0, 1000, 10655, 0, 2500], 'required': 3523, 'adjustment': 3023, 'net_ar': 10632}], ['control 6', {'as_of': 100, 'invoices': [['I0', 71, 150], ['I1', 10, 5], ['I2', 54, 4000], ['I3', 54, 2500], ['I4', 55, 1000], ['I5', 99, 4000]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 0, 'writeoffs': []}, {'buckets': [0, 4150, 7500, 5, 0], 'required': 1335, 'adjustment': 1335, 'net_ar': 10320}]], [['regression: adjustment against debit balance', {'as_of': 100, 'invoices': [['I0', 70, 4000], ['I1', 70, 2500], ['I2', 100, 4000], ['I3', 71, 5]], 'rates': [[0, 200], [45, 1250], [None, 5000]], 'allowance': 0, 'writeoffs': ['I1']}, {'buckets': [4000, 4005, 0], 'required': 581, 'adjustment': 3081, 'net_ar': 7424}], ['control 1', {'as_of': 100, 'invoices': [['I0', 70, 2500], ['I1', 110, 4000], ['I2', -100, 150]], 'rates': [[0, 200], [45, 1250], [None, 5000]], 'allowance': 500, 'writeoffs': ['I2']}, {'buckets': [4000, 2500, 0], 'required': 393, 'adjustment': 43, 'net_ar': 6107}], ['control 2', {'as_of': 100, 'invoices': [['I0', 40, 4000], ['I1', 39, 1000], ['I2', -100, 5], ['I3', 99, 5], ['I4', -100, 333], ['I5', 10, 4000]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 500, 'writeoffs': ['I3']}, {'buckets': [0, 0, 4000, 5000, 338], 'required': 2854, 'adjustment': 2359, 'net_ar': 6484}], ['control 3', {'as_of': 100, 'invoices': [['I0', 54, 5], ['I1', 40, 5], ['I2', 99, 333], ['I3', 71, 150], ['I4', 54, 4000]], 'rates': [[0, 200], [45, 1250], [None, 5000]], 'allowance': 0, 'writeoffs': []}, {'buckets': [0, 483, 4010], 'required': 2065, 'adjustment': 2065, 'net_ar': 2428}], ['control 4', {'as_of': 100, 'invoices': [['I0', 39, 2500], ['I1', 39, 150], ['I2', 10, 4000], ['I3', 9, 2500]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 200, 'writeoffs': []}, {'buckets': [0, 0, 0, 6650, 2500], 'required': 4535, 'adjustment': 4335, 'net_ar': 4615}], ['control 5', {'as_of': 100, 'invoices': [['I0', 71, 2500], ['I1', 54, 4000], ['I2', 40, 333], ['I3', 54, 4000], ['I4', 100, 5]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 200, 'writeoffs': []}, {'buckets': [5, 2500, 8333, 0, 0], 'required': 1375, 'adjustment': 1175, 'net_ar': 9463}], ['control 6', {'as_of': 100, 'invoices': [['I0', 70, 150], ['I1', 9, 4000], ['I2', -100, 2500], ['I3', 110, 333], ['I4', 9, 1000], ['I5', 69, 5]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 500, 'writeoffs': []}, {'buckets': [333, 150, 5, 0, 7500], 'required': 5637, 'adjustment': 5137, 'net_ar': 2351}]]]\nfor label, args, expected in fixtures[N-1]:\n    try:\n        actual = solve(args)\n    except Exception as exc:\n        actual = 'raised ' + type(exc).__name__\n    check(label, actual, expected)\nprint(json.dumps({\"observations\": observations, \"passed\": all(x[\"passed\"] for x in observations)}, ensure_ascii=False))\nraise SystemExit(0 if all(x[\"passed\"] for x in observations) else 1)\n"},"broken":{"sha256":"e8c89045289523e81a5c2d2e1eda0b36600980f245288ff245ac58169b95a3d3","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\n\nN = 1\nobservations = []\ndef solve(x):\n    wo = set(x['writeoffs'])\n    allowance = x['allowance']\n    buckets = [0] * len(x['rates'])\n    for iid, due, amt in x['invoices']:\n        if iid in wo:\n            allowance -= amt\n            continue\n        past = max(0, x['as_of'] - due)\n        for k, (limit, bp) in enumerate(x['rates']):\n            if limit is None or past <= limit:\n                buckets[k] += amt\n                break\n    required = 0\n    for total, (limit, bp) in zip(buckets, x['rates']):\n        q, r = divmod(total * bp, 10000)\n        required += q + (1 if 2 * r >= 10000 else 0)\n    ar = sum(buckets)\n    return {'buckets': buckets, 'required': required, 'adjustment': required - abs(allowance), 'net_ar': ar - required}\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\nfixtures = [[['regression: adjustment against debit balance', {'as_of': 100, 'invoices': [['I0', -100, 5], ['I1', 39, 333], ['I2', 9, 2500], ['I3', -100, 4000], ['I4', 69, 150], ['I5', 70, 2500], ['I6', 55, 4000]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 0, 'writeoffs': ['I5', 'I6']}, {'buckets': [0, 0, 150, 333, 6505], 'required': 5035, 'adjustment': 11535, 'net_ar': 1953}], ['control 1', {'as_of': 100, 'invoices': [['I0', 10, 4000], ['I1', 110, 150], ['I2', 100, 4000], ['I3', 40, 4000]], 'rates': [[0, 200], [45, 1250], [None, 5000]], 'allowance': 0, 'writeoffs': []}, {'buckets': [4150, 0, 8000], 'required': 4083, 'adjustment': 4083, 'net_ar': 8067}], ['control 2', {'as_of': 100, 'invoices': [['I0', 100, 333], ['I1', 70, 2500], ['I2', 55, 5], ['I3', 39, 2500]], 'rates': [[0, 200], [45, 1250], [None, 5000]], 'allowance': 200, 'writeoffs': []}, {'buckets': [333, 2505, 2500], 'required': 1570, 'adjustment': 1370, 'net_ar': 3768}], ['control 3', {'as_of': 100, 'invoices': [['I0', 40, 333], ['I1', 70, 150], ['I2', 99, 150], ['I3', 9, 333], ['I4', 100, 333]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 500, 'writeoffs': []}, {'buckets': [333, 300, 333, 0, 333], 'required': 318, 'adjustment': -182, 'net_ar': 981}], ['control 4', {'as_of': 100, 'invoices': [['I0', 40, 2500], ['I1', 99, 4000], ['I2', 9, 1000]], 'rates': [[0, 200], [45, 1250], [None, 5000]], 'allowance': 0, 'writeoffs': []}, {'buckets': [0, 4000, 3500], 'required': 2250, 'adjustment': 2250, 'net_ar': 5250}], ['control 5', {'as_of': 100, 'invoices': [['I0', 70, 333], ['I1', 70, 150], ['I2', 54, 5], ['I3', 100, 2500], ['I4', 100, 1000], ['I5', 70, 5], ['I6', 54, 1000]], 'rates': [[0, 200], [45, 1250], [None, 5000]], 'allowance': 0, 'writeoffs': []}, {'buckets': [3500, 488, 1005], 'required': 634, 'adjustment': 634, 'net_ar': 4359}], ['control 6', {'as_of': 100, 'invoices': [['I0', 69, 150], ['I1', 54, 150], ['I2', 54, 4000], ['I3', 70, 4000], ['I4', 40, 333], ['I5', 69, 2500]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 200, 'writeoffs': []}, {'buckets': [0, 4000, 7133, 0, 0], 'required': 1270, 'adjustment': 1070, 'net_ar': 9863}]], [['regression: adjustment against debit balance', {'as_of': 100, 'invoices': [['I0', 99, 2500], ['I1', 69, 1000], ['I2', 55, 333], ['I3', 39, 1000], ['I4', 39, 333], ['I5', 40, 4000]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 200, 'writeoffs': ['I1', 'I4', 'I5']}, {'buckets': [0, 2500, 333, 1000, 0], 'required': 575, 'adjustment': 5708, 'net_ar': 3258}], ['control 1', {'as_of': 100, 'invoices': [['I0', 70, 5], ['I1', 69, 5], ['I2', 71, 333], ['I3', -100, 5], ['I4', 54, 333], ['I5', 100, 150], ['I6', 71, 150]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 200, 'writeoffs': ['I0', 'I5']}, {'buckets': [0, 483, 338, 0, 5], 'required': 79, 'adjustment': 34, 'net_ar': 747}], ['control 2', {'as_of': 100, 'invoices': [['I0', 54, 1000], ['I1', 69, 333], ['I2', 55, 150], ['I3', 70, 150]], 'rates': [[0, 200], [45, 1250], [None, 5000]], 'allowance': 200, 'writeoffs': []}, {'buckets': [0, 633, 1000], 'required': 579, 'adjustment': 379, 'net_ar': 1054}], ['control 3', {'as_of': 100, 'invoices': [['I0', 39, 333], ['I1', 100, 1000], ['I2', 54, 2500], ['I3', -100, 2500], ['I4', 71, 150], ['I5', 70, 4000], ['I6', -100, 1000]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 500, 'writeoffs': []}, {'buckets': [1000, 4150, 2500, 333, 3500], 'required': 3351, 'adjustment': 2851, 'net_ar': 8132}], ['control 4', {'as_of': 100, 'invoices': [['I0', 70, 4000], ['I1', -100, 2500], ['I2', 55, 5], ['I3', 39, 5], ['I4', 99, 4000], ['I5', 69, 2500], ['I6', 40, 4000]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 500, 'writeoffs': ['I3']}, {'buckets': [0, 8000, 6505, 0, 2500], 'required': 3251, 'adjustment': 2756, 'net_ar': 13754}], ['control 5', {'as_of': 100, 'invoices': [['I0', 100, 5], ['I1', 69, 2500], ['I2', 9, 4000], ['I3', 39, 4000], ['I4', 99, 4000], ['I5', 39, 1000], ['I6', 100, 5]], 'rates': [[0, 200], [45, 1250], [None, 5000]], 'allowance': 0, 'writeoffs': []}, {'buckets': [10, 6500, 9000], 'required': 5313, 'adjustment': 5313, 'net_ar': 10197}], ['control 6', {'as_of': 100, 'invoices': [['I0', 70, 150], ['I1', 55, 150], ['I2', -100, 5]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 200, 'writeoffs': ['I2']}, {'buckets': [0, 150, 150, 0, 0], 'required': 31, 'adjustment': -164, 'net_ar': 269}]], [['regression: adjustment against debit balance', {'as_of': 100, 'invoices': [['I0', 69, 4000], ['I1', 110, 4000], ['I2', 55, 1000], ['I3', 100, 4000]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 0, 'writeoffs': ['I1']}, {'buckets': [4000, 0, 5000, 0, 0], 'required': 790, 'adjustment': 4790, 'net_ar': 8210}], ['control 1', {'as_of': 100, 'invoices': [['I0', 54, 150], ['I1', 71, 4000], ['I2', 70, 2500], ['I3', 110, 150], ['I4', 99, 5]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 500, 'writeoffs': ['I3']}, {'buckets': [0, 6505, 150, 0, 0], 'required': 348, 'adjustment': -2, 'net_ar': 6307}], ['control 2', {'as_of': 100, 'invoices': [['I0', 100, 4000], ['I1', 69, 1000], ['I2', 55, 4000]], 'rates': [[0, 200], [45, 1250], [None, 5000]], 'allowance': 200, 'writeoffs': []}, {'buckets': [4000, 5000, 0], 'required': 705, 'adjustment': 505, 'net_ar': 8295}], ['control 3', {'as_of': 100, 'invoices': [['I0', 100, 1000], ['I1', 54, 333], ['I2', 69, 1000], ['I3', 40, 150]], 'rates': [[0, 200], [45, 1250], [None, 5000]], 'allowance': 200, 'writeoffs': []}, {'buckets': [1000, 1000, 483], 'required': 387, 'adjustment': 187, 'net_ar': 2096}], ['control 4', {'as_of': 100, 'invoices': [['I0', 39, 2500], ['I1', 69, 150], ['I2', 55, 333]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 200, 'writeoffs': ['I1']}, {'buckets': [0, 0, 333, 2500, 0], 'required': 1050, 'adjustment': 1000, 'net_ar': 1783}], ['control 5', {'as_of': 100, 'invoices': [['I0', 70, 4000], ['I1', 54, 1000], ['I2', 70, 5]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 200, 'writeoffs': []}, {'buckets': [0, 4005, 1000, 0, 0], 'required': 350, 'adjustment': 150, 'net_ar': 4655}], ['control 6', {'as_of': 100, 'invoices': [['I0', 9, 2500], ['I1', 10, 2500], ['I2', 55, 333], ['I3', 69, 5]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 0, 'writeoffs': []}, {'buckets': [0, 0, 338, 2500, 2500], 'required': 2926, 'adjustment': 2926, 'net_ar': 2412}]], [['regression: adjustment against debit balance', {'as_of': 100, 'invoices': [['I0', 110, 150], ['I1', 10, 1000], ['I2', 70, 150], ['I3', 99, 1000], ['I4', 100, 2500], ['I5', 55, 333], ['I6', 54, 150]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 0, 'writeoffs': ['I5', 'I6']}, {'buckets': [2650, 1150, 0, 1000, 0], 'required': 485, 'adjustment': 968, 'net_ar': 4315}], ['control 1', {'as_of': 100, 'invoices': [['I0', 69, 150], ['I1', 71, 150], ['I2', 70, 150]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 500, 'writeoffs': ['I2']}, {'buckets': [0, 150, 150, 0, 0], 'required': 31, 'adjustment': -319, 'net_ar': 269}], ['control 2', {'as_of': 100, 'invoices': [['I0', 54, 1000], ['I1', 100, 5], ['I2', 70, 150], ['I3', 110, 150], ['I4', 100, 2500], ['I5', -100, 333], ['I6', 100, 150]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 0, 'writeoffs': []}, {'buckets': [2805, 150, 1000, 0, 333], 'required': 436, 'adjustment': 436, 'net_ar': 3852}], ['control 3', {'as_of': 100, 'invoices': [['I0', 71, 333], ['I1', 39, 150], ['I2', 71, 4000]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 0, 'writeoffs': []}, {'buckets': [0, 4333, 0, 150, 0], 'required': 277, 'adjustment': 277, 'net_ar': 4206}], ['control 4', {'as_of': 100, 'invoices': [['I0', 110, 2500], ['I1', 69, 150], ['I2', 54, 2500], ['I3', 10, 333]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 200, 'writeoffs': ['I1']}, {'buckets': [2500, 0, 2500, 333, 0], 'required': 533, 'adjustment': 483, 'net_ar': 4800}], ['control 5', {'as_of': 100, 'invoices': [['I0', 69, 2500], ['I1', 69, 150], ['I2', 55, 5], ['I3', 71, 1000], ['I4', 55, 4000], ['I5', -100, 2500], ['I6', 69, 4000]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 500, 'writeoffs': []}, {'buckets': [0, 1000, 10655, 0, 2500], 'required': 3523, 'adjustment': 3023, 'net_ar': 10632}], ['control 6', {'as_of': 100, 'invoices': [['I0', 71, 150], ['I1', 10, 5], ['I2', 54, 4000], ['I3', 54, 2500], ['I4', 55, 1000], ['I5', 99, 4000]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 0, 'writeoffs': []}, {'buckets': [0, 4150, 7500, 5, 0], 'required': 1335, 'adjustment': 1335, 'net_ar': 10320}]], [['regression: adjustment against debit balance', {'as_of': 100, 'invoices': [['I0', 70, 4000], ['I1', 70, 2500], ['I2', 100, 4000], ['I3', 71, 5]], 'rates': [[0, 200], [45, 1250], [None, 5000]], 'allowance': 0, 'writeoffs': ['I1']}, {'buckets': [4000, 4005, 0], 'required': 581, 'adjustment': 3081, 'net_ar': 7424}], ['control 1', {'as_of': 100, 'invoices': [['I0', 70, 2500], ['I1', 110, 4000], ['I2', -100, 150]], 'rates': [[0, 200], [45, 1250], [None, 5000]], 'allowance': 500, 'writeoffs': ['I2']}, {'buckets': [4000, 2500, 0], 'required': 393, 'adjustment': 43, 'net_ar': 6107}], ['control 2', {'as_of': 100, 'invoices': [['I0', 40, 4000], ['I1', 39, 1000], ['I2', -100, 5], ['I3', 99, 5], ['I4', -100, 333], ['I5', 10, 4000]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 500, 'writeoffs': ['I3']}, {'buckets': [0, 0, 4000, 5000, 338], 'required': 2854, 'adjustment': 2359, 'net_ar': 6484}], ['control 3', {'as_of': 100, 'invoices': [['I0', 54, 5], ['I1', 40, 5], ['I2', 99, 333], ['I3', 71, 150], ['I4', 54, 4000]], 'rates': [[0, 200], [45, 1250], [None, 5000]], 'allowance': 0, 'writeoffs': []}, {'buckets': [0, 483, 4010], 'required': 2065, 'adjustment': 2065, 'net_ar': 2428}], ['control 4', {'as_of': 100, 'invoices': [['I0', 39, 2500], ['I1', 39, 150], ['I2', 10, 4000], ['I3', 9, 2500]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 200, 'writeoffs': []}, {'buckets': [0, 0, 0, 6650, 2500], 'required': 4535, 'adjustment': 4335, 'net_ar': 4615}], ['control 5', {'as_of': 100, 'invoices': [['I0', 71, 2500], ['I1', 54, 4000], ['I2', 40, 333], ['I3', 54, 4000], ['I4', 100, 5]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 200, 'writeoffs': []}, {'buckets': [5, 2500, 8333, 0, 0], 'required': 1375, 'adjustment': 1175, 'net_ar': 9463}], ['control 6', {'as_of': 100, 'invoices': [['I0', 70, 150], ['I1', 9, 4000], ['I2', -100, 2500], ['I3', 110, 333], ['I4', 9, 1000], ['I5', 69, 5]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 500, 'writeoffs': []}, {'buckets': [333, 150, 5, 0, 7500], 'required': 5637, 'adjustment': 5137, 'net_ar': 2351}]]]\nfor label, args, expected in fixtures[N-1]:\n    try:\n        actual = solve(args)\n    except Exception as exc:\n        actual = 'raised ' + type(exc).__name__\n    check(label, actual, expected)\nprint(json.dumps({\"observations\": observations, \"passed\": all(x[\"passed\"] for x in observations)}, ensure_ascii=False))\nraise SystemExit(0 if all(x[\"passed\"] for x in observations) else 1)\n"},"fixed":{"sha256":"781343eed3cd92e697936b46ebb2d868af8331dbef68f598e111674045a29cd2","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\n\nN = 1\nobservations = []\ndef solve(x):\n    wo = set(x['writeoffs'])\n    allowance = x['allowance']\n    buckets = [0] * len(x['rates'])\n    for iid, due, amt in x['invoices']:\n        if iid in wo:\n            allowance -= amt\n            continue\n        past = max(0, x['as_of'] - due)\n        for k, (limit, bp) in enumerate(x['rates']):\n            if limit is None or past <= limit:\n                buckets[k] += amt\n                break\n    required = 0\n    for total, (limit, bp) in zip(buckets, x['rates']):\n        q, r = divmod(total * bp, 10000)\n        required += q + (1 if 2 * r >= 10000 else 0)\n    ar = sum(buckets)\n    return {'buckets': buckets, 'required': required, 'adjustment': required - allowance, 'net_ar': ar - required}\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\nfixtures = [[['regression: adjustment against debit balance', {'as_of': 100, 'invoices': [['I0', -100, 5], ['I1', 39, 333], ['I2', 9, 2500], ['I3', -100, 4000], ['I4', 69, 150], ['I5', 70, 2500], ['I6', 55, 4000]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 0, 'writeoffs': ['I5', 'I6']}, {'buckets': [0, 0, 150, 333, 6505], 'required': 5035, 'adjustment': 11535, 'net_ar': 1953}], ['control 1', {'as_of': 100, 'invoices': [['I0', 10, 4000], ['I1', 110, 150], ['I2', 100, 4000], ['I3', 40, 4000]], 'rates': [[0, 200], [45, 1250], [None, 5000]], 'allowance': 0, 'writeoffs': []}, {'buckets': [4150, 0, 8000], 'required': 4083, 'adjustment': 4083, 'net_ar': 8067}], ['control 2', {'as_of': 100, 'invoices': [['I0', 100, 333], ['I1', 70, 2500], ['I2', 55, 5], ['I3', 39, 2500]], 'rates': [[0, 200], [45, 1250], [None, 5000]], 'allowance': 200, 'writeoffs': []}, {'buckets': [333, 2505, 2500], 'required': 1570, 'adjustment': 1370, 'net_ar': 3768}], ['control 3', {'as_of': 100, 'invoices': [['I0', 40, 333], ['I1', 70, 150], ['I2', 99, 150], ['I3', 9, 333], ['I4', 100, 333]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 500, 'writeoffs': []}, {'buckets': [333, 300, 333, 0, 333], 'required': 318, 'adjustment': -182, 'net_ar': 981}], ['control 4', {'as_of': 100, 'invoices': [['I0', 40, 2500], ['I1', 99, 4000], ['I2', 9, 1000]], 'rates': [[0, 200], [45, 1250], [None, 5000]], 'allowance': 0, 'writeoffs': []}, {'buckets': [0, 4000, 3500], 'required': 2250, 'adjustment': 2250, 'net_ar': 5250}], ['control 5', {'as_of': 100, 'invoices': [['I0', 70, 333], ['I1', 70, 150], ['I2', 54, 5], ['I3', 100, 2500], ['I4', 100, 1000], ['I5', 70, 5], ['I6', 54, 1000]], 'rates': [[0, 200], [45, 1250], [None, 5000]], 'allowance': 0, 'writeoffs': []}, {'buckets': [3500, 488, 1005], 'required': 634, 'adjustment': 634, 'net_ar': 4359}], ['control 6', {'as_of': 100, 'invoices': [['I0', 69, 150], ['I1', 54, 150], ['I2', 54, 4000], ['I3', 70, 4000], ['I4', 40, 333], ['I5', 69, 2500]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 200, 'writeoffs': []}, {'buckets': [0, 4000, 7133, 0, 0], 'required': 1270, 'adjustment': 1070, 'net_ar': 9863}]], [['regression: adjustment against debit balance', {'as_of': 100, 'invoices': [['I0', 99, 2500], ['I1', 69, 1000], ['I2', 55, 333], ['I3', 39, 1000], ['I4', 39, 333], ['I5', 40, 4000]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 200, 'writeoffs': ['I1', 'I4', 'I5']}, {'buckets': [0, 2500, 333, 1000, 0], 'required': 575, 'adjustment': 5708, 'net_ar': 3258}], ['control 1', {'as_of': 100, 'invoices': [['I0', 70, 5], ['I1', 69, 5], ['I2', 71, 333], ['I3', -100, 5], ['I4', 54, 333], ['I5', 100, 150], ['I6', 71, 150]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 200, 'writeoffs': ['I0', 'I5']}, {'buckets': [0, 483, 338, 0, 5], 'required': 79, 'adjustment': 34, 'net_ar': 747}], ['control 2', {'as_of': 100, 'invoices': [['I0', 54, 1000], ['I1', 69, 333], ['I2', 55, 150], ['I3', 70, 150]], 'rates': [[0, 200], [45, 1250], [None, 5000]], 'allowance': 200, 'writeoffs': []}, {'buckets': [0, 633, 1000], 'required': 579, 'adjustment': 379, 'net_ar': 1054}], ['control 3', {'as_of': 100, 'invoices': [['I0', 39, 333], ['I1', 100, 1000], ['I2', 54, 2500], ['I3', -100, 2500], ['I4', 71, 150], ['I5', 70, 4000], ['I6', -100, 1000]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 500, 'writeoffs': []}, {'buckets': [1000, 4150, 2500, 333, 3500], 'required': 3351, 'adjustment': 2851, 'net_ar': 8132}], ['control 4', {'as_of': 100, 'invoices': [['I0', 70, 4000], ['I1', -100, 2500], ['I2', 55, 5], ['I3', 39, 5], ['I4', 99, 4000], ['I5', 69, 2500], ['I6', 40, 4000]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 500, 'writeoffs': ['I3']}, {'buckets': [0, 8000, 6505, 0, 2500], 'required': 3251, 'adjustment': 2756, 'net_ar': 13754}], ['control 5', {'as_of': 100, 'invoices': [['I0', 100, 5], ['I1', 69, 2500], ['I2', 9, 4000], ['I3', 39, 4000], ['I4', 99, 4000], ['I5', 39, 1000], ['I6', 100, 5]], 'rates': [[0, 200], [45, 1250], [None, 5000]], 'allowance': 0, 'writeoffs': []}, {'buckets': [10, 6500, 9000], 'required': 5313, 'adjustment': 5313, 'net_ar': 10197}], ['control 6', {'as_of': 100, 'invoices': [['I0', 70, 150], ['I1', 55, 150], ['I2', -100, 5]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 200, 'writeoffs': ['I2']}, {'buckets': [0, 150, 150, 0, 0], 'required': 31, 'adjustment': -164, 'net_ar': 269}]], [['regression: adjustment against debit balance', {'as_of': 100, 'invoices': [['I0', 69, 4000], ['I1', 110, 4000], ['I2', 55, 1000], ['I3', 100, 4000]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 0, 'writeoffs': ['I1']}, {'buckets': [4000, 0, 5000, 0, 0], 'required': 790, 'adjustment': 4790, 'net_ar': 8210}], ['control 1', {'as_of': 100, 'invoices': [['I0', 54, 150], ['I1', 71, 4000], ['I2', 70, 2500], ['I3', 110, 150], ['I4', 99, 5]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 500, 'writeoffs': ['I3']}, {'buckets': [0, 6505, 150, 0, 0], 'required': 348, 'adjustment': -2, 'net_ar': 6307}], ['control 2', {'as_of': 100, 'invoices': [['I0', 100, 4000], ['I1', 69, 1000], ['I2', 55, 4000]], 'rates': [[0, 200], [45, 1250], [None, 5000]], 'allowance': 200, 'writeoffs': []}, {'buckets': [4000, 5000, 0], 'required': 705, 'adjustment': 505, 'net_ar': 8295}], ['control 3', {'as_of': 100, 'invoices': [['I0', 100, 1000], ['I1', 54, 333], ['I2', 69, 1000], ['I3', 40, 150]], 'rates': [[0, 200], [45, 1250], [None, 5000]], 'allowance': 200, 'writeoffs': []}, {'buckets': [1000, 1000, 483], 'required': 387, 'adjustment': 187, 'net_ar': 2096}], ['control 4', {'as_of': 100, 'invoices': [['I0', 39, 2500], ['I1', 69, 150], ['I2', 55, 333]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 200, 'writeoffs': ['I1']}, {'buckets': [0, 0, 333, 2500, 0], 'required': 1050, 'adjustment': 1000, 'net_ar': 1783}], ['control 5', {'as_of': 100, 'invoices': [['I0', 70, 4000], ['I1', 54, 1000], ['I2', 70, 5]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 200, 'writeoffs': []}, {'buckets': [0, 4005, 1000, 0, 0], 'required': 350, 'adjustment': 150, 'net_ar': 4655}], ['control 6', {'as_of': 100, 'invoices': [['I0', 9, 2500], ['I1', 10, 2500], ['I2', 55, 333], ['I3', 69, 5]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 0, 'writeoffs': []}, {'buckets': [0, 0, 338, 2500, 2500], 'required': 2926, 'adjustment': 2926, 'net_ar': 2412}]], [['regression: adjustment against debit balance', {'as_of': 100, 'invoices': [['I0', 110, 150], ['I1', 10, 1000], ['I2', 70, 150], ['I3', 99, 1000], ['I4', 100, 2500], ['I5', 55, 333], ['I6', 54, 150]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 0, 'writeoffs': ['I5', 'I6']}, {'buckets': [2650, 1150, 0, 1000, 0], 'required': 485, 'adjustment': 968, 'net_ar': 4315}], ['control 1', {'as_of': 100, 'invoices': [['I0', 69, 150], ['I1', 71, 150], ['I2', 70, 150]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 500, 'writeoffs': ['I2']}, {'buckets': [0, 150, 150, 0, 0], 'required': 31, 'adjustment': -319, 'net_ar': 269}], ['control 2', {'as_of': 100, 'invoices': [['I0', 54, 1000], ['I1', 100, 5], ['I2', 70, 150], ['I3', 110, 150], ['I4', 100, 2500], ['I5', -100, 333], ['I6', 100, 150]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 0, 'writeoffs': []}, {'buckets': [2805, 150, 1000, 0, 333], 'required': 436, 'adjustment': 436, 'net_ar': 3852}], ['control 3', {'as_of': 100, 'invoices': [['I0', 71, 333], ['I1', 39, 150], ['I2', 71, 4000]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 0, 'writeoffs': []}, {'buckets': [0, 4333, 0, 150, 0], 'required': 277, 'adjustment': 277, 'net_ar': 4206}], ['control 4', {'as_of': 100, 'invoices': [['I0', 110, 2500], ['I1', 69, 150], ['I2', 54, 2500], ['I3', 10, 333]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 200, 'writeoffs': ['I1']}, {'buckets': [2500, 0, 2500, 333, 0], 'required': 533, 'adjustment': 483, 'net_ar': 4800}], ['control 5', {'as_of': 100, 'invoices': [['I0', 69, 2500], ['I1', 69, 150], ['I2', 55, 5], ['I3', 71, 1000], ['I4', 55, 4000], ['I5', -100, 2500], ['I6', 69, 4000]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 500, 'writeoffs': []}, {'buckets': [0, 1000, 10655, 0, 2500], 'required': 3523, 'adjustment': 3023, 'net_ar': 10632}], ['control 6', {'as_of': 100, 'invoices': [['I0', 71, 150], ['I1', 10, 5], ['I2', 54, 4000], ['I3', 54, 2500], ['I4', 55, 1000], ['I5', 99, 4000]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 0, 'writeoffs': []}, {'buckets': [0, 4150, 7500, 5, 0], 'required': 1335, 'adjustment': 1335, 'net_ar': 10320}]], [['regression: adjustment against debit balance', {'as_of': 100, 'invoices': [['I0', 70, 4000], ['I1', 70, 2500], ['I2', 100, 4000], ['I3', 71, 5]], 'rates': [[0, 200], [45, 1250], [None, 5000]], 'allowance': 0, 'writeoffs': ['I1']}, {'buckets': [4000, 4005, 0], 'required': 581, 'adjustment': 3081, 'net_ar': 7424}], ['control 1', {'as_of': 100, 'invoices': [['I0', 70, 2500], ['I1', 110, 4000], ['I2', -100, 150]], 'rates': [[0, 200], [45, 1250], [None, 5000]], 'allowance': 500, 'writeoffs': ['I2']}, {'buckets': [4000, 2500, 0], 'required': 393, 'adjustment': 43, 'net_ar': 6107}], ['control 2', {'as_of': 100, 'invoices': [['I0', 40, 4000], ['I1', 39, 1000], ['I2', -100, 5], ['I3', 99, 5], ['I4', -100, 333], ['I5', 10, 4000]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 500, 'writeoffs': ['I3']}, {'buckets': [0, 0, 4000, 5000, 338], 'required': 2854, 'adjustment': 2359, 'net_ar': 6484}], ['control 3', {'as_of': 100, 'invoices': [['I0', 54, 5], ['I1', 40, 5], ['I2', 99, 333], ['I3', 71, 150], ['I4', 54, 4000]], 'rates': [[0, 200], [45, 1250], [None, 5000]], 'allowance': 0, 'writeoffs': []}, {'buckets': [0, 483, 4010], 'required': 2065, 'adjustment': 2065, 'net_ar': 2428}], ['control 4', {'as_of': 100, 'invoices': [['I0', 39, 2500], ['I1', 39, 150], ['I2', 10, 4000], ['I3', 9, 2500]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 200, 'writeoffs': []}, {'buckets': [0, 0, 0, 6650, 2500], 'required': 4535, 'adjustment': 4335, 'net_ar': 4615}], ['control 5', {'as_of': 100, 'invoices': [['I0', 71, 2500], ['I1', 54, 4000], ['I2', 40, 333], ['I3', 54, 4000], ['I4', 100, 5]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 200, 'writeoffs': []}, {'buckets': [5, 2500, 8333, 0, 0], 'required': 1375, 'adjustment': 1175, 'net_ar': 9463}], ['control 6', {'as_of': 100, 'invoices': [['I0', 70, 150], ['I1', 9, 4000], ['I2', -100, 2500], ['I3', 110, 333], ['I4', 9, 1000], ['I5', 69, 5]], 'rates': [[0, 100], [30, 500], [60, 1500], [90, 4000], [None, 7500]], 'allowance': 500, 'writeoffs': []}, {'buckets': [333, 150, 5, 0, 7500], 'required': 5637, 'adjustment': 5137, 'net_ar': 2351}]]]\nfor label, args, expected in fixtures[N-1]:\n    try:\n        actual = solve(args)\n    except Exception as exc:\n        actual = 'raised ' + type(exc).__name__\n    check(label, actual, expected)\nprint(json.dumps({\"observations\": observations, \"passed\": all(x[\"passed\"] for x in observations)}, ensure_ascii=False))\nraise SystemExit(0 if all(x[\"passed\"] for x in observations) else 1)\n"}},"limitations":"A deterministic bounded teaching model with stipulated toy bookkeeping rules stated in the contract; amounts are integer cents; it makes no claim of conformance to any accounting standard or product. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.","method":"Deterministic executable model with adversarial boundary fixtures.","provenance":{"created_by":"Failure Map","dependencies":"Python standard library","family":"w2-double-entry-ledger-accounting-aging-allowance-adjustment-against-debit-balance","generated_at":"2026-09-29T14:46:23.851845+00:00","license":"CC0-1.0","python":"3.12.14","seed":1,"split":"open-access"},"relevance":"Ledger software must keep debits equal to credits and apply normal-balance, period and cutoff rules exactly; small sign or boundary slips silently misstate financial statements.","repair":"Subtract the signed allowance balance from the requirement.","root_cause":"The existing allowance is taken as an absolute value, treating a debit balance as a credit.","sha256":"94908a5d9ec9906b1ea63d476446f6bb3eba33cbdfb59c88f72457432cd15c9c","title":"Aging-based allowance adjustment: adjustment against debit balance · case 01","variant":1,"variant_policy":"Five numbered records share a model and may reuse boundary fixtures.","verification":{"attempt":{"elapsed_ms":43.093,"exit_code":1,"observations":[{"actual":{"adjustment":-1465,"buckets":[0,0,150,333,6505],"net_ar":1953,"required":5035},"check":"regression: adjustment against debit balance","expected":{"adjustment":11535,"buckets":[0,0,150,333,6505],"net_ar":1953,"required":5035},"passed":false},{"actual":{"adjustment":4083,"buckets":[4150,0,8000],"net_ar":8067,"required":4083},"check":"control 1","expected":{"adjustment":4083,"buckets":[4150,0,8000],"net_ar":8067,"required":4083},"passed":true},{"actual":{"adjustment":1770,"buckets":[333,2505,2500],"net_ar":3768,"required":1570},"check":"control 2","expected":{"adjustment":1370,"buckets":[333,2505,2500],"net_ar":3768,"required":1570},"passed":false},{"actual":{"adjustment":818,"buckets":[333,300,333,0,333],"net_ar":981,"required":318},"check":"control 3","expected":{"adjustment":-182,"buckets":[333,300,333,0,333],"net_ar":981,"required":318},"passed":false},{"actual":{"adjustment":2250,"buckets":[0,4000,3500],"net_ar":5250,"required":2250},"check":"control 4","expected":{"adjustment":2250,"buckets":[0,4000,3500],"net_ar":5250,"required":2250},"passed":true},{"actual":{"adjustment":634,"buckets":[3500,488,1005],"net_ar":4359,"required":634},"check":"control 5","expected":{"adjustment":634,"buckets":[3500,488,1005],"net_ar":4359,"required":634},"passed":true},{"actual":{"adjustment":1470,"buckets":[0,4000,7133,0,0],"net_ar":9863,"required":1270},"check":"control 6","expected":{"adjustment":1070,"buckets":[0,4000,7133,0,0],"net_ar":9863,"required":1270},"passed":false}],"passed":false,"stderr":"","stdout":"{\"observations\": [{\"check\": \"regression: adjustment against debit balance\", \"actual\": {\"buckets\": [0, 0, 150, 333, 6505], \"required\": 5035, \"adjustment\": -1465, \"net_ar\": 1953}, \"expected\": {\"buckets\": [0, 0, 150, 333, 6505], \"required\": 5035, \"adjustment\": 11535, \"net_ar\": 1953}, \"passed\": false}, {\"check\": \"control 1\", \"actual\": {\"buckets\": [4150, 0, 8000], \"required\": 4083, \"adjustment\": 4083, \"net_ar\": 8067}, \"expected\": {\"buckets\": [4150, 0, 8000], \"required\": 4083, \"adjustment\": 4083, \"net_ar\": 8067}, \"passed\": true}, {\"check\": \"control 2\", \"actual\": {\"buckets\": [333, 2505, 2500], \"required\": 1570, \"adjustment\": 1770, \"net_ar\": 3768}, \"expected\": {\"buckets\": [333, 2505, 2500], \"required\": 1570, \"adjustment\": 1370, \"net_ar\": 3768}, \"passed\": false}, {\"check\": \"control 3\", \"actual\": {\"buckets\": [333, 300, 333, 0, 333], \"required\": 318, \"adjustment\": 818, \"net_ar\": 981}, \"expected\": {\"buckets\": [333, 300, 333, 0, 333], \"required\": 318, \"adjustment\": -182, \"net_ar\": 981}, \"passed\": false}, {\"check\": \"control 4\", \"actual\": {\"buckets\": [0, 4000, 3500], \"required\": 2250, \"adjustment\": 2250, \"net_ar\": 5250}, \"expected\": {\"buckets\": [0, 4000, 3500], \"required\": 2250, \"adjustment\": 2250, \"net_ar\": 5250}, \"passed\": true}, {\"check\": \"control 5\", \"actual\": {\"buckets\": [3500, 488, 1005], \"required\": 634, \"adjustment\": 634, \"net_ar\": 4359}, \"expected\": {\"buckets\": [3500, 488, 1005], \"required\": 634, \"adjustment\": 634, \"net_ar\": 4359}, \"passed\": true}, {\"check\": \"control 6\", \"actual\": {\"buckets\": [0, 4000, 7133, 0, 0], \"required\": 1270, \"adjustment\": 1470, \"net_ar\": 9863}, \"expected\": {\"buckets\": [0, 4000, 7133, 0, 0], \"required\": 1270, \"adjustment\": 1070, \"net_ar\": 9863}, \"passed\": false}], \"passed\": false}\n"},"broken":{"elapsed_ms":42.94,"exit_code":1,"observations":[{"actual":{"adjustment":-1465,"buckets":[0,0,150,333,6505],"net_ar":1953,"required":5035},"check":"regression: adjustment against debit balance","expected":{"adjustment":11535,"buckets":[0,0,150,333,6505],"net_ar":1953,"required":5035},"passed":false},{"actual":{"adjustment":4083,"buckets":[4150,0,8000],"net_ar":8067,"required":4083},"check":"control 1","expected":{"adjustment":4083,"buckets":[4150,0,8000],"net_ar":8067,"required":4083},"passed":true},{"actual":{"adjustment":1370,"buckets":[333,2505,2500],"net_ar":3768,"required":1570},"check":"control 2","expected":{"adjustment":1370,"buckets":[333,2505,2500],"net_ar":3768,"required":1570},"passed":true},{"actual":{"adjustment":-182,"buckets":[333,300,333,0,333],"net_ar":981,"required":318},"check":"control 3","expected":{"adjustment":-182,"buckets":[333,300,333,0,333],"net_ar":981,"required":318},"passed":true},{"actual":{"adjustment":2250,"buckets":[0,4000,3500],"net_ar":5250,"required":2250},"check":"control 4","expected":{"adjustment":2250,"buckets":[0,4000,3500],"net_ar":5250,"required":2250},"passed":true},{"actual":{"adjustment":634,"buckets":[3500,488,1005],"net_ar":4359,"required":634},"check":"control 5","expected":{"adjustment":634,"buckets":[3500,488,1005],"net_ar":4359,"required":634},"passed":true},{"actual":{"adjustment":1070,"buckets":[0,4000,7133,0,0],"net_ar":9863,"required":1270},"check":"control 6","expected":{"adjustment":1070,"buckets":[0,4000,7133,0,0],"net_ar":9863,"required":1270},"passed":true}],"passed":false,"stderr":"","stdout":"{\"observations\": [{\"check\": \"regression: adjustment against debit balance\", \"actual\": {\"buckets\": [0, 0, 150, 333, 6505], \"required\": 5035, \"adjustment\": -1465, \"net_ar\": 1953}, \"expected\": {\"buckets\": [0, 0, 150, 333, 6505], \"required\": 5035, \"adjustment\": 11535, \"net_ar\": 1953}, \"passed\": false}, {\"check\": \"control 1\", \"actual\": {\"buckets\": [4150, 0, 8000], \"required\": 4083, \"adjustment\": 4083, \"net_ar\": 8067}, \"expected\": {\"buckets\": [4150, 0, 8000], \"required\": 4083, \"adjustment\": 4083, \"net_ar\": 8067}, \"passed\": true}, {\"check\": \"control 2\", \"actual\": {\"buckets\": [333, 2505, 2500], \"required\": 1570, \"adjustment\": 1370, \"net_ar\": 3768}, \"expected\": {\"buckets\": [333, 2505, 2500], \"required\": 1570, \"adjustment\": 1370, \"net_ar\": 3768}, \"passed\": true}, {\"check\": \"control 3\", \"actual\": {\"buckets\": [333, 300, 333, 0, 333], \"required\": 318, \"adjustment\": -182, \"net_ar\": 981}, \"expected\": {\"buckets\": [333, 300, 333, 0, 333], \"required\": 318, \"adjustment\": -182, \"net_ar\": 981}, \"passed\": true}, {\"check\": \"control 4\", \"actual\": {\"buckets\": [0, 4000, 3500], \"required\": 2250, \"adjustment\": 2250, \"net_ar\": 5250}, \"expected\": {\"buckets\": [0, 4000, 3500], \"required\": 2250, \"adjustment\": 2250, \"net_ar\": 5250}, \"passed\": true}, {\"check\": \"control 5\", \"actual\": {\"buckets\": [3500, 488, 1005], \"required\": 634, \"adjustment\": 634, \"net_ar\": 4359}, \"expected\": {\"buckets\": [3500, 488, 1005], \"required\": 634, \"adjustment\": 634, \"net_ar\": 4359}, \"passed\": true}, {\"check\": \"control 6\", \"actual\": {\"buckets\": [0, 4000, 7133, 0, 0], \"required\": 1270, \"adjustment\": 1070, \"net_ar\": 9863}, \"expected\": {\"buckets\": [0, 4000, 7133, 0, 0], \"required\": 1270, \"adjustment\": 1070, \"net_ar\": 9863}, \"passed\": true}], \"passed\": false}\n"},"fixed":{"elapsed_ms":40.14,"exit_code":0,"observations":[{"actual":{"adjustment":11535,"buckets":[0,0,150,333,6505],"net_ar":1953,"required":5035},"check":"regression: adjustment against debit balance","expected":{"adjustment":11535,"buckets":[0,0,150,333,6505],"net_ar":1953,"required":5035},"passed":true},{"actual":{"adjustment":4083,"buckets":[4150,0,8000],"net_ar":8067,"required":4083},"check":"control 1","expected":{"adjustment":4083,"buckets":[4150,0,8000],"net_ar":8067,"required":4083},"passed":true},{"actual":{"adjustment":1370,"buckets":[333,2505,2500],"net_ar":3768,"required":1570},"check":"control 2","expected":{"adjustment":1370,"buckets":[333,2505,2500],"net_ar":3768,"required":1570},"passed":true},{"actual":{"adjustment":-182,"buckets":[333,300,333,0,333],"net_ar":981,"required":318},"check":"control 3","expected":{"adjustment":-182,"buckets":[333,300,333,0,333],"net_ar":981,"required":318},"passed":true},{"actual":{"adjustment":2250,"buckets":[0,4000,3500],"net_ar":5250,"required":2250},"check":"control 4","expected":{"adjustment":2250,"buckets":[0,4000,3500],"net_ar":5250,"required":2250},"passed":true},{"actual":{"adjustment":634,"buckets":[3500,488,1005],"net_ar":4359,"required":634},"check":"control 5","expected":{"adjustment":634,"buckets":[3500,488,1005],"net_ar":4359,"required":634},"passed":true},{"actual":{"adjustment":1070,"buckets":[0,4000,7133,0,0],"net_ar":9863,"required":1270},"check":"control 6","expected":{"adjustment":1070,"buckets":[0,4000,7133,0,0],"net_ar":9863,"required":1270},"passed":true}],"passed":true,"stderr":"","stdout":"{\"observations\": [{\"check\": \"regression: adjustment against debit balance\", \"actual\": {\"buckets\": [0, 0, 150, 333, 6505], \"required\": 5035, \"adjustment\": 11535, \"net_ar\": 1953}, \"expected\": {\"buckets\": [0, 0, 150, 333, 6505], \"required\": 5035, \"adjustment\": 11535, \"net_ar\": 1953}, \"passed\": true}, {\"check\": \"control 1\", \"actual\": {\"buckets\": [4150, 0, 8000], \"required\": 4083, \"adjustment\": 4083, \"net_ar\": 8067}, \"expected\": {\"buckets\": [4150, 0, 8000], \"required\": 4083, \"adjustment\": 4083, \"net_ar\": 8067}, \"passed\": true}, {\"check\": \"control 2\", \"actual\": {\"buckets\": [333, 2505, 2500], \"required\": 1570, \"adjustment\": 1370, \"net_ar\": 3768}, \"expected\": {\"buckets\": [333, 2505, 2500], \"required\": 1570, \"adjustment\": 1370, \"net_ar\": 3768}, \"passed\": true}, {\"check\": \"control 3\", \"actual\": {\"buckets\": [333, 300, 333, 0, 333], \"required\": 318, \"adjustment\": -182, \"net_ar\": 981}, \"expected\": {\"buckets\": [333, 300, 333, 0, 333], \"required\": 318, \"adjustment\": -182, \"net_ar\": 981}, \"passed\": true}, {\"check\": \"control 4\", \"actual\": {\"buckets\": [0, 4000, 3500], \"required\": 2250, \"adjustment\": 2250, \"net_ar\": 5250}, \"expected\": {\"buckets\": [0, 4000, 3500], \"required\": 2250, \"adjustment\": 2250, \"net_ar\": 5250}, \"passed\": true}, {\"check\": \"control 5\", \"actual\": {\"buckets\": [3500, 488, 1005], \"required\": 634, \"adjustment\": 634, \"net_ar\": 4359}, \"expected\": {\"buckets\": [3500, 488, 1005], \"required\": 634, \"adjustment\": 634, \"net_ar\": 4359}, \"passed\": true}, {\"check\": \"control 6\", \"actual\": {\"buckets\": [0, 4000, 7133, 0, 0], \"required\": 1270, \"adjustment\": 1070, \"net_ar\": 9863}, \"expected\": {\"buckets\": [0, 4000, 7133, 0, 0], \"required\": 1270, \"adjustment\": 1070, \"net_ar\": 9863}, \"passed\": true}], \"passed\": true}\n"}},"verified":true,"visibility":"public"}