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

N = 1
observations = []
def solve(x):
    acc = x['accounts']
    def total(kind):
        return sum(b for k, b in acc.values() if k == kind)
    rev = total('revenue')
    contra = total('contra_revenue')
    exp = total('expense')
    gain = total('gain')
    loss = total('loss')
    div = total('dividend')
    oci = total('oci')
    income_summary = rev - contra + gain - exp + loss
    retained = x['retained'] + income_summary - div
    aoci = x['aoci'] + oci
    temporary = ('revenue', 'contra_revenue', 'expense', 'gain', 'loss', 'dividend', 'oci')
    closed = sorted(n for n, (k, b) in acc.items() if k in temporary and b != 0)
    return {'net_income': income_summary, 'retained': retained, 'aoci': aoci, 'closed': closed}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: loss sign', {'accounts': {'oci_0': ['oci', 150], 'oci_1': ['oci', 400], 'expe_2': ['expense', 7500], 'loss_3': ['loss', 3000]}, 'retained': 1000, 'aoci': -100}, {'net_income': -10500, 'retained': -9500, 'aoci': 450, 'closed': ['expe_2', 'loss_3', 'oci_0', 'oci_1']}], ['control 1', {'accounts': {'reve_0': ['revenue', 3000], 'oci_1': ['oci', 1200], 'divi_2': ['dividend', 400], 'expe_3': ['expense', 150]}, 'retained': 0, 'aoci': -100}, {'net_income': 2850, 'retained': 2450, 'aoci': 1100, 'closed': ['divi_2', 'expe_3', 'oci_1', 'reve_0']}], ['control 2', {'accounts': {'asse_0': ['asset', 400], 'gain_1': ['gain', 150], 'reve_2': ['revenue', 7500], 'gain_3': ['gain', 7500], 'asse_4': ['asset', 3000], 'reve_5': ['revenue', 3000], 'expe_6': ['expense', 400], 'reve_7': ['revenue', 400], 'reve_8': ['revenue', 3000]}, 'retained': 25000, 'aoci': 300}, {'net_income': 21150, 'retained': 46150, 'aoci': 300, 'closed': ['expe_6', 'gain_1', 'gain_3', 'reve_2', 'reve_5', 'reve_7', 'reve_8']}], ['control 3', {'accounts': {'cont_0': ['contra_revenue', 7500], 'cont_1': ['contra_revenue', 7500], 'oci_2': ['oci', 1200], 'cont_3': ['contra_revenue', 1200], 'reve_4': ['revenue', 0], 'divi_5': ['dividend', -200], 'gain_6': ['gain', 150]}, 'retained': 25000, 'aoci': -100}, {'net_income': -16050, 'retained': 9150, 'aoci': 1100, 'closed': ['cont_0', 'cont_1', 'cont_3', 'divi_5', 'gain_6', 'oci_2']}], ['control 4', {'accounts': {'asse_0': ['asset', 150], 'reve_1': ['revenue', 7500], 'divi_2': ['dividend', 0], 'gain_3': ['gain', 0], 'reve_4': ['revenue', 3000], 'gain_5': ['gain', 3000], 'asse_6': ['asset', 400]}, 'retained': 25000, 'aoci': 0}, {'net_income': 13500, 'retained': 38500, 'aoci': 0, 'closed': ['gain_5', 'reve_1', 'reve_4']}], ['control 5', {'accounts': {'gain_0': ['gain', 0], 'reve_1': ['revenue', -200], 'oci_2': ['oci', 400], 'asse_3': ['asset', 3000]}, 'retained': 1000, 'aoci': 300}, {'net_income': -200, 'retained': 800, 'aoci': 700, 'closed': ['oci_2', 'reve_1']}], ['control 6', {'accounts': {'liab_0': ['liability', 150], 'gain_1': ['gain', 150], 'reve_2': ['revenue', 150], 'asse_3': ['asset', 7500], 'gain_4': ['gain', 0], 'expe_5': ['expense', 150], 'liab_6': ['liability', 0]}, 'retained': -500, 'aoci': 0}, {'net_income': 150, 'retained': -350, 'aoci': 0, 'closed': ['expe_5', 'gain_1', 'reve_2']}]], [['regression: loss sign', {'accounts': {'oci_0': ['oci', 150], 'gain_1': ['gain', 7500], 'loss_2': ['loss', 400], 'divi_3': ['dividend', 7500], 'cont_4': ['contra_revenue', 150], 'liab_5': ['liability', 7500], 'asse_6': ['asset', 150]}, 'retained': 1000, 'aoci': 0}, {'net_income': 6950, 'retained': 450, 'aoci': 150, 'closed': ['cont_4', 'divi_3', 'gain_1', 'loss_2', 'oci_0']}], ['control 1', {'accounts': {'reve_0': ['revenue', 1200], 'expe_1': ['expense', 7500], 'asse_2': ['asset', -200], 'cont_3': ['contra_revenue', 7500], 'cont_4': ['contra_revenue', 7500], 'divi_5': ['dividend', 7500], 'divi_6': ['dividend', 3000], 'cont_7': ['contra_revenue', 7500]}, 'retained': 0, 'aoci': -100}, {'net_income': -28800, 'retained': -39300, 'aoci': -100, 'closed': ['cont_3', 'cont_4', 'cont_7', 'divi_5', 'divi_6', 'expe_1', 'reve_0']}], ['control 2', {'accounts': {'asse_0': ['asset', 7500], 'expe_1': ['expense', 7500], 'gain_2': ['gain', 400], 'loss_3': ['loss', 0], 'liab_4': ['liability', 400], 'oci_5': ['oci', -200], 'cont_6': ['contra_revenue', 150], 'oci_7': ['oci', -200]}, 'retained': 25000, 'aoci': 300}, {'net_income': -7250, 'retained': 17750, 'aoci': -100, 'closed': ['cont_6', 'expe_1', 'gain_2', 'oci_5', 'oci_7']}], ['control 3', {'accounts': {'reve_0': ['revenue', 0], 'loss_1': ['loss', 0], 'reve_2': ['revenue', 7500], 'gain_3': ['gain', 0], 'divi_4': ['dividend', 150], 'divi_5': ['dividend', 1200]}, 'retained': 25000, 'aoci': -100}, {'net_income': 7500, 'retained': 31150, 'aoci': -100, 'closed': ['divi_4', 'divi_5', 'reve_2']}], ['control 4', {'accounts': {'reve_0': ['revenue', -200], 'gain_1': ['gain', 400], 'liab_2': ['liability', 400], 'expe_3': ['expense', 150], 'expe_4': ['expense', 0], 'reve_5': ['revenue', 400]}, 'retained': 0, 'aoci': 0}, {'net_income': 450, 'retained': 450, 'aoci': 0, 'closed': ['expe_3', 'gain_1', 'reve_0', 'reve_5']}], ['control 5', {'accounts': {'reve_0': ['revenue', 400], 'oci_1': ['oci', 3000], 'gain_2': ['gain', 7500], 'expe_3': ['expense', 150], 'loss_4': ['loss', 0], 'divi_5': ['dividend', -200]}, 'retained': 25000, 'aoci': 300}, {'net_income': 7750, 'retained': 32950, 'aoci': 3300, 'closed': ['divi_5', 'expe_3', 'gain_2', 'oci_1', 'reve_0']}], ['control 6', {'accounts': {'reve_0': ['revenue', 1200], 'liab_1': ['liability', 150], 'gain_2': ['gain', 3000], 'expe_3': ['expense', 400], 'cont_4': ['contra_revenue', 1200], 'asse_5': ['asset', 3000]}, 'retained': 1000, 'aoci': 0}, {'net_income': 2600, 'retained': 3600, 'aoci': 0, 'closed': ['cont_4', 'expe_3', 'gain_2', 'reve_0']}]], [['regression: loss sign', {'accounts': {'liab_0': ['liability', 1200], 'cont_1': ['contra_revenue', 400], 'expe_2': ['expense', 1200], 'loss_3': ['loss', 400], 'liab_4': ['liability', 1200], 'expe_5': ['expense', 400], 'asse_6': ['asset', 3000], 'oci_7': ['oci', 3000]}, 'retained': 0, 'aoci': 0}, {'net_income': -2400, 'retained': -2400, 'aoci': 3000, 'closed': ['cont_1', 'expe_2', 'expe_5', 'loss_3', 'oci_7']}], ['control 1', {'accounts': {'cont_0': ['contra_revenue', -200], 'expe_1': ['expense', -200], 'liab_2': ['liability', 0], 'asse_3': ['asset', 3000], 'gain_4': ['gain', 1200], 'gain_5': ['gain', 150], 'liab_6': ['liability', 1200], 'gain_7': ['gain', 400], 'liab_8': ['liability', 0]}, 'retained': 25000, 'aoci': -100}, {'net_income': 2150, 'retained': 27150, 'aoci': -100, 'closed': ['cont_0', 'expe_1', 'gain_4', 'gain_5', 'gain_7']}], ['control 2', {'accounts': {'reve_0': ['revenue', 400], 'gain_1': ['gain', 0], 'liab_2': ['liability', 400], 'gain_3': ['gain', -200], 'asse_4': ['asset', 0], 'divi_5': ['dividend', 400]}, 'retained': 0, 'aoci': 300}, {'net_income': 200, 'retained': -200, 'aoci': 300, 'closed': ['divi_5', 'gain_3', 'reve_0']}], ['control 3', {'accounts': {'oci_0': ['oci', 3000], 'oci_1': ['oci', -200], 'expe_2': ['expense', 400], 'gain_3': ['gain', 7500], 'cont_4': ['contra_revenue', 0]}, 'retained': -500, 'aoci': 0}, {'net_income': 7100, 'retained': 6600, 'aoci': 2800, 'closed': ['expe_2', 'gain_3', 'oci_0', 'oci_1']}], ['control 4', {'accounts': {'reve_0': ['revenue', 3000], 'liab_1': ['liability', -200], 'asse_2': ['asset', 7500], 'asse_3': ['asset', 0]}, 'retained': -500, 'aoci': -100}, {'net_income': 3000, 'retained': 2500, 'aoci': -100, 'closed': ['reve_0']}], ['control 5', {'accounts': {'liab_0': ['liability', 150], 'divi_1': ['dividend', 7500], 'reve_2': ['revenue', 400], 'liab_3': ['liability', 1200], 'expe_4': ['expense', -200], 'divi_5': ['dividend', 0], 'expe_6': ['expense', 0]}, 'retained': 0, 'aoci': 0}, {'net_income': 600, 'retained': -6900, 'aoci': 0, 'closed': ['divi_1', 'expe_4', 'reve_2']}], ['control 6', {'accounts': {'liab_0': ['liability', 150], 'oci_1': ['oci', 3000], 'expe_2': ['expense', -200], 'cont_3': ['contra_revenue', 400], 'asse_4': ['asset', 3000], 'liab_5': ['liability', 150], 'cont_6': ['contra_revenue', 0], 'cont_7': ['contra_revenue', -200], 'cont_8': ['contra_revenue', 400]}, 'retained': 1000, 'aoci': 300}, {'net_income': -400, 'retained': 600, 'aoci': 3300, 'closed': ['cont_3', 'cont_7', 'cont_8', 'expe_2', 'oci_1']}]], [['regression: loss sign', {'accounts': {'oci_0': ['oci', 1200], 'liab_1': ['liability', 3000], 'expe_2': ['expense', 1200], 'loss_3': ['loss', 3000], 'liab_4': ['liability', 1200], 'loss_5': ['loss', 150], 'asse_6': ['asset', -200]}, 'retained': -500, 'aoci': 300}, {'net_income': -4350, 'retained': -4850, 'aoci': 1500, 'closed': ['expe_2', 'loss_3', 'loss_5', 'oci_0']}], ['control 1', {'accounts': {'liab_0': ['liability', 0], 'expe_1': ['expense', 150], 'gain_2': ['gain', 0], 'liab_3': ['liability', 1200], 'gain_4': ['gain', -200], 'divi_5': ['dividend', 7500], 'divi_6': ['dividend', 1200], 'oci_7': ['oci', -200], 'asse_8': ['asset', -200]}, 'retained': 0, 'aoci': 300}, {'net_income': -350, 'retained': -9050, 'aoci': 100, 'closed': ['divi_5', 'divi_6', 'expe_1', 'gain_4', 'oci_7']}], ['control 2', {'accounts': {'oci_0': ['oci', 400], 'liab_1': ['liability', 1200], 'asse_2': ['asset', 7500], 'expe_3': ['expense', 3000], 'asse_4': ['asset', 400], 'liab_5': ['liability', 3000], 'liab_6': ['liability', 7500]}, 'retained': -500, 'aoci': -100}, {'net_income': -3000, 'retained': -3500, 'aoci': 300, 'closed': ['expe_3', 'oci_0']}], ['control 3', {'accounts': {'oci_0': ['oci', 1200], 'gain_1': ['gain', 7500], 'oci_2': ['oci', 150], 'divi_3': ['dividend', 3000], 'expe_4': ['expense', 150], 'loss_5': ['loss', 0], 'liab_6': ['liability', 1200], 'liab_7': ['liability', 150]}, 'retained': 1000, 'aoci': 0}, {'net_income': 7350, 'retained': 5350, 'aoci': 1350, 'closed': ['divi_3', 'expe_4', 'gain_1', 'oci_0', 'oci_2']}], ['control 4', {'accounts': {'divi_0': ['dividend', 150], 'divi_1': ['dividend', -200], 'asse_2': ['asset', 150], 'cont_3': ['contra_revenue', 400], 'gain_4': ['gain', 150]}, 'retained': 0, 'aoci': 300}, {'net_income': -250, 'retained': -200, 'aoci': 300, 'closed': ['cont_3', 'divi_0', 'divi_1', 'gain_4']}], ['control 5', {'accounts': {'gain_0': ['gain', 1200], 'asse_1': ['asset', 3000], 'cont_2': ['contra_revenue', 400], 'expe_3': ['expense', 3000], 'cont_4': ['contra_revenue', 7500], 'expe_5': ['expense', 0]}, 'retained': 0, 'aoci': 0}, {'net_income': -9700, 'retained': -9700, 'aoci': 0, 'closed': ['cont_2', 'cont_4', 'expe_3', 'gain_0']}], ['control 6', {'accounts': {'reve_0': ['revenue', 150], 'asse_1': ['asset', 7500], 'oci_2': ['oci', 1200], 'reve_3': ['revenue', 400], 'divi_4': ['dividend', 150], 'gain_5': ['gain', 1200], 'liab_6': ['liability', -200], 'asse_7': ['asset', 150], 'divi_8': ['dividend', 7500]}, 'retained': 1000, 'aoci': 300}, {'net_income': 1750, 'retained': -4900, 'aoci': 1500, 'closed': ['divi_4', 'divi_8', 'gain_5', 'oci_2', 'reve_0', 'reve_3']}]], [['regression: loss sign', {'accounts': {'oci_0': ['oci', 0], 'gain_1': ['gain', 0], 'oci_2': ['oci', 3000], 'expe_3': ['expense', 150], 'loss_4': ['loss', 150], 'divi_5': ['dividend', 150], 'cont_6': ['contra_revenue', 1200], 'expe_7': ['expense', 7500]}, 'retained': -500, 'aoci': 300}, {'net_income': -9000, 'retained': -9650, 'aoci': 3300, 'closed': ['cont_6', 'divi_5', 'expe_3', 'expe_7', 'loss_4', 'oci_2']}], ['control 1', {'accounts': {'gain_0': ['gain', 400], 'reve_1': ['revenue', 1200], 'reve_2': ['revenue', 400], 'expe_3': ['expense', 3000], 'oci_4': ['oci', -200], 'reve_5': ['revenue', -200], 'gain_6': ['gain', 3000], 'reve_7': ['revenue', -200]}, 'retained': 0, 'aoci': 300}, {'net_income': 1600, 'retained': 1600, 'aoci': 100, 'closed': ['expe_3', 'gain_0', 'gain_6', 'oci_4', 'reve_1', 'reve_2', 'reve_5', 'reve_7']}], ['control 2', {'accounts': {'liab_0': ['liability', 3000], 'gain_1': ['gain', -200], 'reve_2': ['revenue', -200], 'oci_3': ['oci', 150], 'oci_4': ['oci', 3000], 'oci_5': ['oci', 3000], 'cont_6': ['contra_revenue', 3000]}, 'retained': 1000, 'aoci': 300}, {'net_income': -3400, 'retained': -2400, 'aoci': 6450, 'closed': ['cont_6', 'gain_1', 'oci_3', 'oci_4', 'oci_5', 'reve_2']}], ['control 3', {'accounts': {'cont_0': ['contra_revenue', 3000], 'reve_1': ['revenue', 7500], 'asse_2': ['asset', 0], 'oci_3': ['oci', 150], 'liab_4': ['liability', 0], 'reve_5': ['revenue', 400], 'divi_6': ['dividend', 1200], 'reve_7': ['revenue', 1200]}, 'retained': 25000, 'aoci': 0}, {'net_income': 6100, 'retained': 29900, 'aoci': 150, 'closed': ['cont_0', 'divi_6', 'oci_3', 'reve_1', 'reve_5', 'reve_7']}], ['control 4', {'accounts': {'gain_0': ['gain', 3000], 'expe_1': ['expense', -200], 'asse_2': ['asset', 0], 'expe_3': ['expense', 150], 'asse_4': ['asset', 7500], 'gain_5': ['gain', 400], 'divi_6': ['dividend', 150], 'expe_7': ['expense', 3000], 'reve_8': ['revenue', 150]}, 'retained': -500, 'aoci': 0}, {'net_income': 600, 'retained': -50, 'aoci': 0, 'closed': ['divi_6', 'expe_1', 'expe_3', 'expe_7', 'gain_0', 'gain_5', 'reve_8']}], ['control 5', {'accounts': {'asse_0': ['asset', -200], 'expe_1': ['expense', 1200], 'liab_2': ['liability', 150], 'divi_3': ['dividend', 7500], 'asse_4': ['asset', -200], 'reve_5': ['revenue', 3000], 'divi_6': ['dividend', 400], 'reve_7': ['revenue', 1200]}, 'retained': -500, 'aoci': 0}, {'net_income': 3000, 'retained': -5400, 'aoci': 0, 'closed': ['divi_3', 'divi_6', 'expe_1', 'reve_5', 'reve_7']}], ['control 6', {'accounts': {'gain_0': ['gain', 7500], 'asse_1': ['asset', 400], 'oci_2': ['oci', 7500], 'liab_3': ['liability', 400], 'divi_4': ['dividend', 0], 'reve_5': ['revenue', 1200], 'gain_6': ['gain', 3000], 'oci_7': ['oci', 1200], 'oci_8': ['oci', 150]}, 'retained': -500, 'aoci': 0}, {'net_income': 11700, 'retained': 11200, 'aoci': 8850, 'closed': ['gain_0', 'gain_6', 'oci_2', 'oci_7', 'oci_8', 'reve_5']}]]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'raised ' + type(exc).__name__
    check(label, actual, expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    acc = x['accounts']
    def total(kind):
        return sum(b for k, b in acc.values() if k == kind)
    rev = total('revenue')
    contra = total('contra_revenue')
    exp = total('expense')
    gain = total('gain')
    loss = total('loss')
    div = total('dividend')
    oci = total('oci')
    income_summary = rev - contra + gain - exp
    retained = x['retained'] + income_summary - div
    aoci = x['aoci'] + oci
    temporary = ('revenue', 'contra_revenue', 'expense', 'gain', 'loss', 'dividend', 'oci')
    closed = sorted(n for n, (k, b) in acc.items() if k in temporary and b != 0)
    return {'net_income': income_summary, 'retained': retained, 'aoci': aoci, 'closed': closed}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: loss sign', {'accounts': {'oci_0': ['oci', 150], 'oci_1': ['oci', 400], 'expe_2': ['expense', 7500], 'loss_3': ['loss', 3000]}, 'retained': 1000, 'aoci': -100}, {'net_income': -10500, 'retained': -9500, 'aoci': 450, 'closed': ['expe_2', 'loss_3', 'oci_0', 'oci_1']}], ['control 1', {'accounts': {'reve_0': ['revenue', 3000], 'oci_1': ['oci', 1200], 'divi_2': ['dividend', 400], 'expe_3': ['expense', 150]}, 'retained': 0, 'aoci': -100}, {'net_income': 2850, 'retained': 2450, 'aoci': 1100, 'closed': ['divi_2', 'expe_3', 'oci_1', 'reve_0']}], ['control 2', {'accounts': {'asse_0': ['asset', 400], 'gain_1': ['gain', 150], 'reve_2': ['revenue', 7500], 'gain_3': ['gain', 7500], 'asse_4': ['asset', 3000], 'reve_5': ['revenue', 3000], 'expe_6': ['expense', 400], 'reve_7': ['revenue', 400], 'reve_8': ['revenue', 3000]}, 'retained': 25000, 'aoci': 300}, {'net_income': 21150, 'retained': 46150, 'aoci': 300, 'closed': ['expe_6', 'gain_1', 'gain_3', 'reve_2', 'reve_5', 'reve_7', 'reve_8']}], ['control 3', {'accounts': {'cont_0': ['contra_revenue', 7500], 'cont_1': ['contra_revenue', 7500], 'oci_2': ['oci', 1200], 'cont_3': ['contra_revenue', 1200], 'reve_4': ['revenue', 0], 'divi_5': ['dividend', -200], 'gain_6': ['gain', 150]}, 'retained': 25000, 'aoci': -100}, {'net_income': -16050, 'retained': 9150, 'aoci': 1100, 'closed': ['cont_0', 'cont_1', 'cont_3', 'divi_5', 'gain_6', 'oci_2']}], ['control 4', {'accounts': {'asse_0': ['asset', 150], 'reve_1': ['revenue', 7500], 'divi_2': ['dividend', 0], 'gain_3': ['gain', 0], 'reve_4': ['revenue', 3000], 'gain_5': ['gain', 3000], 'asse_6': ['asset', 400]}, 'retained': 25000, 'aoci': 0}, {'net_income': 13500, 'retained': 38500, 'aoci': 0, 'closed': ['gain_5', 'reve_1', 'reve_4']}], ['control 5', {'accounts': {'gain_0': ['gain', 0], 'reve_1': ['revenue', -200], 'oci_2': ['oci', 400], 'asse_3': ['asset', 3000]}, 'retained': 1000, 'aoci': 300}, {'net_income': -200, 'retained': 800, 'aoci': 700, 'closed': ['oci_2', 'reve_1']}], ['control 6', {'accounts': {'liab_0': ['liability', 150], 'gain_1': ['gain', 150], 'reve_2': ['revenue', 150], 'asse_3': ['asset', 7500], 'gain_4': ['gain', 0], 'expe_5': ['expense', 150], 'liab_6': ['liability', 0]}, 'retained': -500, 'aoci': 0}, {'net_income': 150, 'retained': -350, 'aoci': 0, 'closed': ['expe_5', 'gain_1', 'reve_2']}]], [['regression: loss sign', {'accounts': {'oci_0': ['oci', 150], 'gain_1': ['gain', 7500], 'loss_2': ['loss', 400], 'divi_3': ['dividend', 7500], 'cont_4': ['contra_revenue', 150], 'liab_5': ['liability', 7500], 'asse_6': ['asset', 150]}, 'retained': 1000, 'aoci': 0}, {'net_income': 6950, 'retained': 450, 'aoci': 150, 'closed': ['cont_4', 'divi_3', 'gain_1', 'loss_2', 'oci_0']}], ['control 1', {'accounts': {'reve_0': ['revenue', 1200], 'expe_1': ['expense', 7500], 'asse_2': ['asset', -200], 'cont_3': ['contra_revenue', 7500], 'cont_4': ['contra_revenue', 7500], 'divi_5': ['dividend', 7500], 'divi_6': ['dividend', 3000], 'cont_7': ['contra_revenue', 7500]}, 'retained': 0, 'aoci': -100}, {'net_income': -28800, 'retained': -39300, 'aoci': -100, 'closed': ['cont_3', 'cont_4', 'cont_7', 'divi_5', 'divi_6', 'expe_1', 'reve_0']}], ['control 2', {'accounts': {'asse_0': ['asset', 7500], 'expe_1': ['expense', 7500], 'gain_2': ['gain', 400], 'loss_3': ['loss', 0], 'liab_4': ['liability', 400], 'oci_5': ['oci', -200], 'cont_6': ['contra_revenue', 150], 'oci_7': ['oci', -200]}, 'retained': 25000, 'aoci': 300}, {'net_income': -7250, 'retained': 17750, 'aoci': -100, 'closed': ['cont_6', 'expe_1', 'gain_2', 'oci_5', 'oci_7']}], ['control 3', {'accounts': {'reve_0': ['revenue', 0], 'loss_1': ['loss', 0], 'reve_2': ['revenue', 7500], 'gain_3': ['gain', 0], 'divi_4': ['dividend', 150], 'divi_5': ['dividend', 1200]}, 'retained': 25000, 'aoci': -100}, {'net_income': 7500, 'retained': 31150, 'aoci': -100, 'closed': ['divi_4', 'divi_5', 'reve_2']}], ['control 4', {'accounts': {'reve_0': ['revenue', -200], 'gain_1': ['gain', 400], 'liab_2': ['liability', 400], 'expe_3': ['expense', 150], 'expe_4': ['expense', 0], 'reve_5': ['revenue', 400]}, 'retained': 0, 'aoci': 0}, {'net_income': 450, 'retained': 450, 'aoci': 0, 'closed': ['expe_3', 'gain_1', 'reve_0', 'reve_5']}], ['control 5', {'accounts': {'reve_0': ['revenue', 400], 'oci_1': ['oci', 3000], 'gain_2': ['gain', 7500], 'expe_3': ['expense', 150], 'loss_4': ['loss', 0], 'divi_5': ['dividend', -200]}, 'retained': 25000, 'aoci': 300}, {'net_income': 7750, 'retained': 32950, 'aoci': 3300, 'closed': ['divi_5', 'expe_3', 'gain_2', 'oci_1', 'reve_0']}], ['control 6', {'accounts': {'reve_0': ['revenue', 1200], 'liab_1': ['liability', 150], 'gain_2': ['gain', 3000], 'expe_3': ['expense', 400], 'cont_4': ['contra_revenue', 1200], 'asse_5': ['asset', 3000]}, 'retained': 1000, 'aoci': 0}, {'net_income': 2600, 'retained': 3600, 'aoci': 0, 'closed': ['cont_4', 'expe_3', 'gain_2', 'reve_0']}]], [['regression: loss sign', {'accounts': {'liab_0': ['liability', 1200], 'cont_1': ['contra_revenue', 400], 'expe_2': ['expense', 1200], 'loss_3': ['loss', 400], 'liab_4': ['liability', 1200], 'expe_5': ['expense', 400], 'asse_6': ['asset', 3000], 'oci_7': ['oci', 3000]}, 'retained': 0, 'aoci': 0}, {'net_income': -2400, 'retained': -2400, 'aoci': 3000, 'closed': ['cont_1', 'expe_2', 'expe_5', 'loss_3', 'oci_7']}], ['control 1', {'accounts': {'cont_0': ['contra_revenue', -200], 'expe_1': ['expense', -200], 'liab_2': ['liability', 0], 'asse_3': ['asset', 3000], 'gain_4': ['gain', 1200], 'gain_5': ['gain', 150], 'liab_6': ['liability', 1200], 'gain_7': ['gain', 400], 'liab_8': ['liability', 0]}, 'retained': 25000, 'aoci': -100}, {'net_income': 2150, 'retained': 27150, 'aoci': -100, 'closed': ['cont_0', 'expe_1', 'gain_4', 'gain_5', 'gain_7']}], ['control 2', {'accounts': {'reve_0': ['revenue', 400], 'gain_1': ['gain', 0], 'liab_2': ['liability', 400], 'gain_3': ['gain', -200], 'asse_4': ['asset', 0], 'divi_5': ['dividend', 400]}, 'retained': 0, 'aoci': 300}, {'net_income': 200, 'retained': -200, 'aoci': 300, 'closed': ['divi_5', 'gain_3', 'reve_0']}], ['control 3', {'accounts': {'oci_0': ['oci', 3000], 'oci_1': ['oci', -200], 'expe_2': ['expense', 400], 'gain_3': ['gain', 7500], 'cont_4': ['contra_revenue', 0]}, 'retained': -500, 'aoci': 0}, {'net_income': 7100, 'retained': 6600, 'aoci': 2800, 'closed': ['expe_2', 'gain_3', 'oci_0', 'oci_1']}], ['control 4', {'accounts': {'reve_0': ['revenue', 3000], 'liab_1': ['liability', -200], 'asse_2': ['asset', 7500], 'asse_3': ['asset', 0]}, 'retained': -500, 'aoci': -100}, {'net_income': 3000, 'retained': 2500, 'aoci': -100, 'closed': ['reve_0']}], ['control 5', {'accounts': {'liab_0': ['liability', 150], 'divi_1': ['dividend', 7500], 'reve_2': ['revenue', 400], 'liab_3': ['liability', 1200], 'expe_4': ['expense', -200], 'divi_5': ['dividend', 0], 'expe_6': ['expense', 0]}, 'retained': 0, 'aoci': 0}, {'net_income': 600, 'retained': -6900, 'aoci': 0, 'closed': ['divi_1', 'expe_4', 'reve_2']}], ['control 6', {'accounts': {'liab_0': ['liability', 150], 'oci_1': ['oci', 3000], 'expe_2': ['expense', -200], 'cont_3': ['contra_revenue', 400], 'asse_4': ['asset', 3000], 'liab_5': ['liability', 150], 'cont_6': ['contra_revenue', 0], 'cont_7': ['contra_revenue', -200], 'cont_8': ['contra_revenue', 400]}, 'retained': 1000, 'aoci': 300}, {'net_income': -400, 'retained': 600, 'aoci': 3300, 'closed': ['cont_3', 'cont_7', 'cont_8', 'expe_2', 'oci_1']}]], [['regression: loss sign', {'accounts': {'oci_0': ['oci', 1200], 'liab_1': ['liability', 3000], 'expe_2': ['expense', 1200], 'loss_3': ['loss', 3000], 'liab_4': ['liability', 1200], 'loss_5': ['loss', 150], 'asse_6': ['asset', -200]}, 'retained': -500, 'aoci': 300}, {'net_income': -4350, 'retained': -4850, 'aoci': 1500, 'closed': ['expe_2', 'loss_3', 'loss_5', 'oci_0']}], ['control 1', {'accounts': {'liab_0': ['liability', 0], 'expe_1': ['expense', 150], 'gain_2': ['gain', 0], 'liab_3': ['liability', 1200], 'gain_4': ['gain', -200], 'divi_5': ['dividend', 7500], 'divi_6': ['dividend', 1200], 'oci_7': ['oci', -200], 'asse_8': ['asset', -200]}, 'retained': 0, 'aoci': 300}, {'net_income': -350, 'retained': -9050, 'aoci': 100, 'closed': ['divi_5', 'divi_6', 'expe_1', 'gain_4', 'oci_7']}], ['control 2', {'accounts': {'oci_0': ['oci', 400], 'liab_1': ['liability', 1200], 'asse_2': ['asset', 7500], 'expe_3': ['expense', 3000], 'asse_4': ['asset', 400], 'liab_5': ['liability', 3000], 'liab_6': ['liability', 7500]}, 'retained': -500, 'aoci': -100}, {'net_income': -3000, 'retained': -3500, 'aoci': 300, 'closed': ['expe_3', 'oci_0']}], ['control 3', {'accounts': {'oci_0': ['oci', 1200], 'gain_1': ['gain', 7500], 'oci_2': ['oci', 150], 'divi_3': ['dividend', 3000], 'expe_4': ['expense', 150], 'loss_5': ['loss', 0], 'liab_6': ['liability', 1200], 'liab_7': ['liability', 150]}, 'retained': 1000, 'aoci': 0}, {'net_income': 7350, 'retained': 5350, 'aoci': 1350, 'closed': ['divi_3', 'expe_4', 'gain_1', 'oci_0', 'oci_2']}], ['control 4', {'accounts': {'divi_0': ['dividend', 150], 'divi_1': ['dividend', -200], 'asse_2': ['asset', 150], 'cont_3': ['contra_revenue', 400], 'gain_4': ['gain', 150]}, 'retained': 0, 'aoci': 300}, {'net_income': -250, 'retained': -200, 'aoci': 300, 'closed': ['cont_3', 'divi_0', 'divi_1', 'gain_4']}], ['control 5', {'accounts': {'gain_0': ['gain', 1200], 'asse_1': ['asset', 3000], 'cont_2': ['contra_revenue', 400], 'expe_3': ['expense', 3000], 'cont_4': ['contra_revenue', 7500], 'expe_5': ['expense', 0]}, 'retained': 0, 'aoci': 0}, {'net_income': -9700, 'retained': -9700, 'aoci': 0, 'closed': ['cont_2', 'cont_4', 'expe_3', 'gain_0']}], ['control 6', {'accounts': {'reve_0': ['revenue', 150], 'asse_1': ['asset', 7500], 'oci_2': ['oci', 1200], 'reve_3': ['revenue', 400], 'divi_4': ['dividend', 150], 'gain_5': ['gain', 1200], 'liab_6': ['liability', -200], 'asse_7': ['asset', 150], 'divi_8': ['dividend', 7500]}, 'retained': 1000, 'aoci': 300}, {'net_income': 1750, 'retained': -4900, 'aoci': 1500, 'closed': ['divi_4', 'divi_8', 'gain_5', 'oci_2', 'reve_0', 'reve_3']}]], [['regression: loss sign', {'accounts': {'oci_0': ['oci', 0], 'gain_1': ['gain', 0], 'oci_2': ['oci', 3000], 'expe_3': ['expense', 150], 'loss_4': ['loss', 150], 'divi_5': ['dividend', 150], 'cont_6': ['contra_revenue', 1200], 'expe_7': ['expense', 7500]}, 'retained': -500, 'aoci': 300}, {'net_income': -9000, 'retained': -9650, 'aoci': 3300, 'closed': ['cont_6', 'divi_5', 'expe_3', 'expe_7', 'loss_4', 'oci_2']}], ['control 1', {'accounts': {'gain_0': ['gain', 400], 'reve_1': ['revenue', 1200], 'reve_2': ['revenue', 400], 'expe_3': ['expense', 3000], 'oci_4': ['oci', -200], 'reve_5': ['revenue', -200], 'gain_6': ['gain', 3000], 'reve_7': ['revenue', -200]}, 'retained': 0, 'aoci': 300}, {'net_income': 1600, 'retained': 1600, 'aoci': 100, 'closed': ['expe_3', 'gain_0', 'gain_6', 'oci_4', 'reve_1', 'reve_2', 'reve_5', 'reve_7']}], ['control 2', {'accounts': {'liab_0': ['liability', 3000], 'gain_1': ['gain', -200], 'reve_2': ['revenue', -200], 'oci_3': ['oci', 150], 'oci_4': ['oci', 3000], 'oci_5': ['oci', 3000], 'cont_6': ['contra_revenue', 3000]}, 'retained': 1000, 'aoci': 300}, {'net_income': -3400, 'retained': -2400, 'aoci': 6450, 'closed': ['cont_6', 'gain_1', 'oci_3', 'oci_4', 'oci_5', 'reve_2']}], ['control 3', {'accounts': {'cont_0': ['contra_revenue', 3000], 'reve_1': ['revenue', 7500], 'asse_2': ['asset', 0], 'oci_3': ['oci', 150], 'liab_4': ['liability', 0], 'reve_5': ['revenue', 400], 'divi_6': ['dividend', 1200], 'reve_7': ['revenue', 1200]}, 'retained': 25000, 'aoci': 0}, {'net_income': 6100, 'retained': 29900, 'aoci': 150, 'closed': ['cont_0', 'divi_6', 'oci_3', 'reve_1', 'reve_5', 'reve_7']}], ['control 4', {'accounts': {'gain_0': ['gain', 3000], 'expe_1': ['expense', -200], 'asse_2': ['asset', 0], 'expe_3': ['expense', 150], 'asse_4': ['asset', 7500], 'gain_5': ['gain', 400], 'divi_6': ['dividend', 150], 'expe_7': ['expense', 3000], 'reve_8': ['revenue', 150]}, 'retained': -500, 'aoci': 0}, {'net_income': 600, 'retained': -50, 'aoci': 0, 'closed': ['divi_6', 'expe_1', 'expe_3', 'expe_7', 'gain_0', 'gain_5', 'reve_8']}], ['control 5', {'accounts': {'asse_0': ['asset', -200], 'expe_1': ['expense', 1200], 'liab_2': ['liability', 150], 'divi_3': ['dividend', 7500], 'asse_4': ['asset', -200], 'reve_5': ['revenue', 3000], 'divi_6': ['dividend', 400], 'reve_7': ['revenue', 1200]}, 'retained': -500, 'aoci': 0}, {'net_income': 3000, 'retained': -5400, 'aoci': 0, 'closed': ['divi_3', 'divi_6', 'expe_1', 'reve_5', 'reve_7']}], ['control 6', {'accounts': {'gain_0': ['gain', 7500], 'asse_1': ['asset', 400], 'oci_2': ['oci', 7500], 'liab_3': ['liability', 400], 'divi_4': ['dividend', 0], 'reve_5': ['revenue', 1200], 'gain_6': ['gain', 3000], 'oci_7': ['oci', 1200], 'oci_8': ['oci', 150]}, 'retained': -500, 'aoci': 0}, {'net_income': 11700, 'retained': 11200, 'aoci': 8850, 'closed': ['gain_0', 'gain_6', 'oci_2', 'oci_7', 'oci_8', 'reve_5']}]]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'raised ' + type(exc).__name__
    check(label, actual, expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A loss on disposal raises net income.

x = {'accounts': {name: [type, normal-signed balance]}, 'retained': opening retained earnings, 'aoci': opening accumulated OCI}. Temporary types are revenue, contra_revenue, expense, gain, loss, dividend and oci. Income summary = revenue - contra_revenue + gain - expense - loss and is net income. Retained earnings close = opening + net income - dividends. OCI closes to AOCI, never to income or retained earnings. 'closed' lists temporary accounts with a nonzero balance (including abnormal negative ones), sorted. Return {'net_income', 'retained', 'aoci', 'closed'}.

split: open-access


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

N = 1
observations = []
def solve(x):
    acc = x['accounts']
    def total(kind):
        return sum(b for k, b in acc.values() if k == kind)
    rev = total('revenue')
    contra = total('contra_revenue')
    exp = total('expense')
    gain = total('gain')
    loss = total('loss')
    div = total('dividend')
    oci = total('oci')
    income_summary = rev - contra + gain - exp - loss
    retained = x['retained'] + income_summary - div
    aoci = x['aoci'] + oci
    temporary = ('revenue', 'contra_revenue', 'expense', 'gain', 'loss', 'dividend', 'oci')
    closed = sorted(n for n, (k, b) in acc.items() if k in temporary and b != 0)
    return {'net_income': income_summary - div, 'retained': retained, 'aoci': aoci, 'closed': closed}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: dividends in net income', {'accounts': {'reve_0': ['revenue', 3000], 'oci_1': ['oci', 1200], 'divi_2': ['dividend', 400], 'expe_3': ['expense', 150]}, 'retained': 0, 'aoci': -100}, {'net_income': 2850, 'retained': 2450, 'aoci': 1100, 'closed': ['divi_2', 'expe_3', 'oci_1', 'reve_0']}], ['control 1', {'accounts': {'oci_0': ['oci', 150], 'oci_1': ['oci', 400], 'expe_2': ['expense', 7500], 'loss_3': ['loss', 3000]}, 'retained': 1000, 'aoci': -100}, {'net_income': -10500, 'retained': -9500, 'aoci': 450, 'closed': ['expe_2', 'loss_3', 'oci_0', 'oci_1']}], ['control 2', {'accounts': {'asse_0': ['asset', 400], 'gain_1': ['gain', 150], 'reve_2': ['revenue', 7500], 'gain_3': ['gain', 7500], 'asse_4': ['asset', 3000], 'reve_5': ['revenue', 3000], 'expe_6': ['expense', 400], 'reve_7': ['revenue', 400], 'reve_8': ['revenue', 3000]}, 'retained': 25000, 'aoci': 300}, {'net_income': 21150, 'retained': 46150, 'aoci': 300, 'closed': ['expe_6', 'gain_1', 'gain_3', 'reve_2', 'reve_5', 'reve_7', 'reve_8']}], ['control 3', {'accounts': {'asse_0': ['asset', 150], 'reve_1': ['revenue', 7500], 'divi_2': ['dividend', 0], 'gain_3': ['gain', 0], 'reve_4': ['revenue', 3000], 'gain_5': ['gain', 3000], 'asse_6': ['asset', 400]}, 'retained': 25000, 'aoci': 0}, {'net_income': 13500, 'retained': 38500, 'aoci': 0, 'closed': ['gain_5', 'reve_1', 'reve_4']}], ['control 4', {'accounts': {'gain_0': ['gain', 0], 'reve_1': ['revenue', -200], 'oci_2': ['oci', 400], 'asse_3': ['asset', 3000]}, 'retained': 1000, 'aoci': 300}, {'net_income': -200, 'retained': 800, 'aoci': 700, 'closed': ['oci_2', 'reve_1']}], ['control 5', {'accounts': {'reve_0': ['revenue', -200], 'reve_1': ['revenue', 0], 'expe_2': ['expense', 1200], 'loss_3': ['loss', 150]}, 'retained': 1000, 'aoci': 0}, {'net_income': -1550, 'retained': -550, 'aoci': 0, 'closed': ['expe_2', 'loss_3', 'reve_0']}], ['control 6', {'accounts': {'gain_0': ['gain', 3000], 'oci_1': ['oci', 150], 'gain_2': ['gain', 150], 'oci_3': ['oci', 0], 'loss_4': ['loss', 7500], 'cont_5': ['contra_revenue', 1200]}, 'retained': 0, 'aoci': 0}, {'net_income': -5550, 'retained': -5550, 'aoci': 150, 'closed': ['cont_5', 'gain_0', 'gain_2', 'loss_4', 'oci_1']}]], [['regression: dividends in net income', {'accounts': {'reve_0': ['revenue', 1200], 'expe_1': ['expense', 7500], 'asse_2': ['asset', -200], 'cont_3': ['contra_revenue', 7500], 'cont_4': ['contra_revenue', 7500], 'divi_5': ['dividend', 7500], 'divi_6': ['dividend', 3000], 'cont_7': ['contra_revenue', 7500]}, 'retained': 0, 'aoci': -100}, {'net_income': -28800, 'retained': -39300, 'aoci': -100, 'closed': ['cont_3', 'cont_4', 'cont_7', 'divi_5', 'divi_6', 'expe_1', 'reve_0']}], ['control 1', {'accounts': {'asse_0': ['asset', 7500], 'expe_1': ['expense', 7500], 'gain_2': ['gain', 400], 'loss_3': ['loss', 0], 'liab_4': ['liability', 400], 'oci_5': ['oci', -200], 'cont_6': ['contra_revenue', 150], 'oci_7': ['oci', -200]}, 'retained': 25000, 'aoci': 300}, {'net_income': -7250, 'retained': 17750, 'aoci': -100, 'closed': ['cont_6', 'expe_1', 'gain_2', 'oci_5', 'oci_7']}], ['control 2', {'accounts': {'cont_0': ['contra_revenue', 400], 'expe_1': ['expense', 400], 'loss_2': ['loss', 0], 'loss_3': ['loss', 150], 'cont_4': ['contra_revenue', 400], 'cont_5': ['contra_revenue', 3000]}, 'retained': 0, 'aoci': 300}, {'net_income': -4350, 'retained': -4350, 'aoci': 300, 'closed': ['cont_0', 'cont_4', 'cont_5', 'expe_1', 'loss_3']}], ['control 3', {'accounts': {'reve_0': ['revenue', -200], 'gain_1': ['gain', 400], 'liab_2': ['liability', 400], 'expe_3': ['expense', 150], 'expe_4': ['expense', 0], 'reve_5': ['revenue', 400]}, 'retained': 0, 'aoci': 0}, {'net_income': 450, 'retained': 450, 'aoci': 0, 'closed': ['expe_3', 'gain_1', 'reve_0', 'reve_5']}], ['control 4', {'accounts': {'oci_0': ['oci', -200], 'cont_1': ['contra_revenue', 0], 'asse_2': ['asset', 7500], 'loss_3': ['loss', 0], 'expe_4': ['expense', 150], 'asse_5': ['asset', 3000], 'loss_6': ['loss', 400]}, 'retained': 25000, 'aoci': 300}, {'net_income': -550, 'retained': 24450, 'aoci': 100, 'closed': ['expe_4', 'loss_6', 'oci_0']}], ['control 5', {'accounts': {'loss_0': ['loss', 7500], 'cont_1': ['contra_revenue', 400], 'reve_2': ['revenue', 0], 'loss_3': ['loss', 7500], 'expe_4': ['expense', 1200], 'reve_5': ['revenue', 150]}, 'retained': 0, 'aoci': -100}, {'net_income': -16450, 'retained': -16450, 'aoci': -100, 'closed': ['cont_1', 'expe_4', 'loss_0', 'loss_3', 'reve_5']}], ['control 6', {'accounts': {'loss_0': ['loss', 1200], 'cont_1': ['contra_revenue', 3000], 'reve_2': ['revenue', 1200], 'expe_3': ['expense', 7500], 'reve_4': ['revenue', 400], 'liab_5': ['liability', 400]}, 'retained': -500, 'aoci': 300}, {'net_income': -10100, 'retained': -10600, 'aoci': 300, 'closed': ['cont_1', 'expe_3', 'loss_0', 'reve_2', 'reve_4']}]], [['regression: dividends in net income', {'accounts': {'reve_0': ['revenue', 400], 'gain_1': ['gain', 0], 'liab_2': ['liability', 400], 'gain_3': ['gain', -200], 'asse_4': ['asset', 0], 'divi_5': ['dividend', 400]}, 'retained': 0, 'aoci': 300}, {'net_income': 200, 'retained': -200, 'aoci': 300, 'closed': ['divi_5', 'gain_3', 'reve_0']}], ['control 1', {'accounts': {'cont_0': ['contra_revenue', -200], 'expe_1': ['expense', -200], 'liab_2': ['liability', 0], 'asse_3': ['asset', 3000], 'gain_4': ['gain', 1200], 'gain_5': ['gain', 150], 'liab_6': ['liability', 1200], 'gain_7': ['gain', 400], 'liab_8': ['liability', 0]}, 'retained': 25000, 'aoci': -100}, {'net_income': 2150, 'retained': 27150, 'aoci': -100, 'closed': ['cont_0', 'expe_1', 'gain_4', 'gain_5', 'gain_7']}], ['control 2', {'accounts': {'liab_0': ['liability', 1200], 'cont_1': ['contra_revenue', 400], 'expe_2': ['expense', 1200], 'loss_3': ['loss', 400], 'liab_4': ['liability', 1200], 'expe_5': ['expense', 400], 'asse_6': ['asset', 3000], 'oci_7': ['oci', 3000]}, 'retained': 0, 'aoci': 0}, {'net_income': -2400, 'retained': -2400, 'aoci': 3000, 'closed': ['cont_1', 'expe_2', 'expe_5', 'loss_3', 'oci_7']}], ['control 3', {'accounts': {'oci_0': ['oci', 3000], 'oci_1': ['oci', -200], 'expe_2': ['expense', 400], 'gain_3': ['gain', 7500], 'cont_4': ['contra_revenue', 0]}, 'retained': -500, 'aoci': 0}, {'net_income': 7100, 'retained': 6600, 'aoci': 2800, 'closed': ['expe_2', 'gain_3', 'oci_0', 'oci_1']}], ['control 4', {'accounts': {'reve_0': ['revenue', 3000], 'liab_1': ['liability', -200], 'asse_2': ['asset', 7500], 'asse_3': ['asset', 0]}, 'retained': -500, 'aoci': -100}, {'net_income': 3000, 'retained': 2500, 'aoci': -100, 'closed': ['reve_0']}], ['control 5', {'accounts': {'expe_0': ['expense', -200], 'cont_1': ['contra_revenue', 1200], 'cont_2': ['contra_revenue', 1200], 'liab_3': ['liability', -200], 'cont_4': ['contra_revenue', 1200], 'oci_5': ['oci', 400], 'reve_6': ['revenue', -200], 'liab_7': ['liability', -200], 'loss_8': ['loss', 1200]}, 'retained': 1000, 'aoci': 0}, {'net_income': -4800, 'retained': -3800, 'aoci': 400, 'closed': ['cont_1', 'cont_2', 'cont_4', 'expe_0', 'loss_8', 'oci_5', 'reve_6']}], ['control 6', {'accounts': {'liab_0': ['liability', 150], 'oci_1': ['oci', 3000], 'expe_2': ['expense', -200], 'cont_3': ['contra_revenue', 400], 'asse_4': ['asset', 3000], 'liab_5': ['liability', 150], 'cont_6': ['contra_revenue', 0], 'cont_7': ['contra_revenue', -200], 'cont_8': ['contra_revenue', 400]}, 'retained': 1000, 'aoci': 300}, {'net_income': -400, 'retained': 600, 'aoci': 3300, 'closed': ['cont_3', 'cont_7', 'cont_8', 'expe_2', 'oci_1']}]], [['regression: dividends in net income', {'accounts': {'liab_0': ['liability', 0], 'expe_1': ['expense', 150], 'gain_2': ['gain', 0], 'liab_3': ['liability', 1200], 'gain_4': ['gain', -200], 'divi_5': ['dividend', 7500], 'divi_6': ['dividend', 1200], 'oci_7': ['oci', -200], 'asse_8': ['asset', -200]}, 'retained': 0, 'aoci': 300}, {'net_income': -350, 'retained': -9050, 'aoci': 100, 'closed': ['divi_5', 'divi_6', 'expe_1', 'gain_4', 'oci_7']}], ['control 1', {'accounts': {'oci_0': ['oci', 1200], 'liab_1': ['liability', 3000], 'expe_2': ['expense', 1200], 'loss_3': ['loss', 3000], 'liab_4': ['liability', 1200], 'loss_5': ['loss', 150], 'asse_6': ['asset', -200]}, 'retained': -500, 'aoci': 300}, {'net_income': -4350, 'retained': -4850, 'aoci': 1500, 'closed': ['expe_2', 'loss_3', 'loss_5', 'oci_0']}], ['control 2', {'accounts': {'oci_0': ['oci', 400], 'liab_1': ['liability', 1200], 'asse_2': ['asset', 7500], 'expe_3': ['expense', 3000], 'asse_4': ['asset', 400], 'liab_5': ['liability', 3000], 'liab_6': ['liability', 7500]}, 'retained': -500, 'aoci': -100}, {'net_income': -3000, 'retained': -3500, 'aoci': 300, 'closed': ['expe_3', 'oci_0']}], ['control 3', {'accounts': {'gain_0': ['gain', 1200], 'asse_1': ['asset', 3000], 'cont_2': ['contra_revenue', 400], 'expe_3': ['expense', 3000], 'cont_4': ['contra_revenue', 7500], 'expe_5': ['expense', 0]}, 'retained': 0, 'aoci': 0}, {'net_income': -9700, 'retained': -9700, 'aoci': 0, 'closed': ['cont_2', 'cont_4', 'expe_3', 'gain_0']}], ['control 4', {'accounts': {'cont_0': ['contra_revenue', 0], 'liab_1': ['liability', 3000], 'oci_2': ['oci', 3000], 'asse_3': ['asset', -200], 'reve_4': ['revenue', 7500]}, 'retained': 1000, 'aoci': 0}, {'net_income': 7500, 'retained': 8500, 'aoci': 3000, 'closed': ['oci_2', 'reve_4']}], ['control 5', {'accounts': {'gain_0': ['gain', 7500], 'loss_1': ['loss', 7500], 'oci_2': ['oci', -200], 'loss_3': ['loss', 1200], 'oci_4': ['oci', 1200], 'cont_5': ['contra_revenue', 0], 'oci_6': ['oci', -200]}, 'retained': -500, 'aoci': 0}, {'net_income': -1200, 'retained': -1700, 'aoci': 800, 'closed': ['gain_0', 'loss_1', 'loss_3', 'oci_2', 'oci_4', 'oci_6']}], ['control 6', {'accounts': {'liab_0': ['liability', -200], 'reve_1': ['revenue', 3000], 'asse_2': ['asset', 3000], 'reve_3': ['revenue', 3000], 'liab_4': ['liability', 3000], 'reve_5': ['revenue', 0], 'liab_6': ['liability', 150]}, 'retained': -500, 'aoci': 0}, {'net_income': 6000, 'retained': 5500, 'aoci': 0, 'closed': ['reve_1', 'reve_3']}]], [['regression: dividends in net income', {'accounts': {'oci_0': ['oci', 0], 'gain_1': ['gain', 0], 'oci_2': ['oci', 3000], 'expe_3': ['expense', 150], 'loss_4': ['loss', 150], 'divi_5': ['dividend', 150], 'cont_6': ['contra_revenue', 1200], 'expe_7': ['expense', 7500]}, 'retained': -500, 'aoci': 300}, {'net_income': -9000, 'retained': -9650, 'aoci': 3300, 'closed': ['cont_6', 'divi_5', 'expe_3', 'expe_7', 'loss_4', 'oci_2']}], ['control 1', {'accounts': {'gain_0': ['gain', 400], 'reve_1': ['revenue', 1200], 'reve_2': ['revenue', 400], 'expe_3': ['expense', 3000], 'oci_4': ['oci', -200], 'reve_5': ['revenue', -200], 'gain_6': ['gain', 3000], 'reve_7': ['revenue', -200]}, 'retained': 0, 'aoci': 300}, {'net_income': 1600, 'retained': 1600, 'aoci': 100, 'closed': ['expe_3', 'gain_0', 'gain_6', 'oci_4', 'reve_1', 'reve_2', 'reve_5', 'reve_7']}], ['control 2', {'accounts': {'liab_0': ['liability', 3000], 'gain_1': ['gain', -200], 'reve_2': ['revenue', -200], 'oci_3': ['oci', 150], 'oci_4': ['oci', 3000], 'oci_5': ['oci', 3000], 'cont_6': ['contra_revenue', 3000]}, 'retained': 1000, 'aoci': 300}, {'net_income': -3400, 'retained': -2400, 'aoci': 6450, 'closed': ['cont_6', 'gain_1', 'oci_3', 'oci_4', 'oci_5', 'reve_2']}], ['control 3', {'accounts': {'gain_0': ['gain', 7500], 'asse_1': ['asset', 400], 'oci_2': ['oci', 7500], 'liab_3': ['liability', 400], 'divi_4': ['dividend', 0], 'reve_5': ['revenue', 1200], 'gain_6': ['gain', 3000], 'oci_7': ['oci', 1200], 'oci_8': ['oci', 150]}, 'retained': -500, 'aoci': 0}, {'net_income': 11700, 'retained': 11200, 'aoci': 8850, 'closed': ['gain_0', 'gain_6', 'oci_2', 'oci_7', 'oci_8', 'reve_5']}], ['control 4', {'accounts': {'asse_0': ['asset', 400], 'expe_1': ['expense', 0], 'asse_2': ['asset', 150], 'loss_3': ['loss', 1200], 'asse_4': ['asset', 150], 'gain_5': ['gain', 7500], 'expe_6': ['expense', 150]}, 'retained': 0, 'aoci': -100}, {'net_income': 6150, 'retained': 6150, 'aoci': -100, 'closed': ['expe_6', 'gain_5', 'loss_3']}], ['control 5', {'accounts': {'oci_0': ['oci', 3000], 'liab_1': ['liability', 150], 'gain_2': ['gain', 0], 'loss_3': ['loss', 150], 'asse_4': ['asset', 3000], 'reve_5': ['revenue', -200], 'reve_6': ['revenue', 400]}, 'retained': -500, 'aoci': 300}, {'net_income': 50, 'retained': -450, 'aoci': 3300, 'closed': ['loss_3', 'oci_0', 'reve_5', 'reve_6']}], ['control 6', {'accounts': {'gain_0': ['gain', 0], 'cont_1': ['contra_revenue', 400], 'expe_2': ['expense', 150], 'loss_3': ['loss', 0], 'loss_4': ['loss', -200]}, 'retained': 1000, 'aoci': 300}, {'net_income': -350, 'retained': 650, 'aoci': 300, 'closed': ['cont_1', 'expe_2', 'loss_4']}]]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'raised ' + type(exc).__name__
    check(label, actual, expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

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

N = 1
observations = []
def solve(x):
    acc = x['accounts']
    def total(kind):
        return sum(b for k, b in acc.values() if k == kind)
    rev = total('revenue')
    contra = total('contra_revenue')
    exp = total('expense')
    gain = total('gain')
    loss = total('loss')
    div = total('dividend')
    oci = total('oci')
    income_summary = rev - contra + gain - exp - loss
    retained = x['retained'] + income_summary - div
    aoci = x['aoci'] + oci
    temporary = ('revenue', 'contra_revenue', 'expense', 'gain', 'loss', 'dividend', 'oci')
    closed = sorted(n for n, (k, b) in acc.items() if k in temporary and b != 0)
    return {'net_income': retained - x['retained'], 'retained': retained, 'aoci': aoci, 'closed': closed}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: dividends in net income', {'accounts': {'reve_0': ['revenue', 3000], 'oci_1': ['oci', 1200], 'divi_2': ['dividend', 400], 'expe_3': ['expense', 150]}, 'retained': 0, 'aoci': -100}, {'net_income': 2850, 'retained': 2450, 'aoci': 1100, 'closed': ['divi_2', 'expe_3', 'oci_1', 'reve_0']}], ['control 1', {'accounts': {'oci_0': ['oci', 150], 'oci_1': ['oci', 400], 'expe_2': ['expense', 7500], 'loss_3': ['loss', 3000]}, 'retained': 1000, 'aoci': -100}, {'net_income': -10500, 'retained': -9500, 'aoci': 450, 'closed': ['expe_2', 'loss_3', 'oci_0', 'oci_1']}], ['control 2', {'accounts': {'asse_0': ['asset', 400], 'gain_1': ['gain', 150], 'reve_2': ['revenue', 7500], 'gain_3': ['gain', 7500], 'asse_4': ['asset', 3000], 'reve_5': ['revenue', 3000], 'expe_6': ['expense', 400], 'reve_7': ['revenue', 400], 'reve_8': ['revenue', 3000]}, 'retained': 25000, 'aoci': 300}, {'net_income': 21150, 'retained': 46150, 'aoci': 300, 'closed': ['expe_6', 'gain_1', 'gain_3', 'reve_2', 'reve_5', 'reve_7', 'reve_8']}], ['control 3', {'accounts': {'asse_0': ['asset', 150], 'reve_1': ['revenue', 7500], 'divi_2': ['dividend', 0], 'gain_3': ['gain', 0], 'reve_4': ['revenue', 3000], 'gain_5': ['gain', 3000], 'asse_6': ['asset', 400]}, 'retained': 25000, 'aoci': 0}, {'net_income': 13500, 'retained': 38500, 'aoci': 0, 'closed': ['gain_5', 'reve_1', 'reve_4']}], ['control 4', {'accounts': {'gain_0': ['gain', 0], 'reve_1': ['revenue', -200], 'oci_2': ['oci', 400], 'asse_3': ['asset', 3000]}, 'retained': 1000, 'aoci': 300}, {'net_income': -200, 'retained': 800, 'aoci': 700, 'closed': ['oci_2', 'reve_1']}], ['control 5', {'accounts': {'reve_0': ['revenue', -200], 'reve_1': ['revenue', 0], 'expe_2': ['expense', 1200], 'loss_3': ['loss', 150]}, 'retained': 1000, 'aoci': 0}, {'net_income': -1550, 'retained': -550, 'aoci': 0, 'closed': ['expe_2', 'loss_3', 'reve_0']}], ['control 6', {'accounts': {'gain_0': ['gain', 3000], 'oci_1': ['oci', 150], 'gain_2': ['gain', 150], 'oci_3': ['oci', 0], 'loss_4': ['loss', 7500], 'cont_5': ['contra_revenue', 1200]}, 'retained': 0, 'aoci': 0}, {'net_income': -5550, 'retained': -5550, 'aoci': 150, 'closed': ['cont_5', 'gain_0', 'gain_2', 'loss_4', 'oci_1']}]], [['regression: dividends in net income', {'accounts': {'reve_0': ['revenue', 1200], 'expe_1': ['expense', 7500], 'asse_2': ['asset', -200], 'cont_3': ['contra_revenue', 7500], 'cont_4': ['contra_revenue', 7500], 'divi_5': ['dividend', 7500], 'divi_6': ['dividend', 3000], 'cont_7': ['contra_revenue', 7500]}, 'retained': 0, 'aoci': -100}, {'net_income': -28800, 'retained': -39300, 'aoci': -100, 'closed': ['cont_3', 'cont_4', 'cont_7', 'divi_5', 'divi_6', 'expe_1', 'reve_0']}], ['control 1', {'accounts': {'asse_0': ['asset', 7500], 'expe_1': ['expense', 7500], 'gain_2': ['gain', 400], 'loss_3': ['loss', 0], 'liab_4': ['liability', 400], 'oci_5': ['oci', -200], 'cont_6': ['contra_revenue', 150], 'oci_7': ['oci', -200]}, 'retained': 25000, 'aoci': 300}, {'net_income': -7250, 'retained': 17750, 'aoci': -100, 'closed': ['cont_6', 'expe_1', 'gain_2', 'oci_5', 'oci_7']}], ['control 2', {'accounts': {'cont_0': ['contra_revenue', 400], 'expe_1': ['expense', 400], 'loss_2': ['loss', 0], 'loss_3': ['loss', 150], 'cont_4': ['contra_revenue', 400], 'cont_5': ['contra_revenue', 3000]}, 'retained': 0, 'aoci': 300}, {'net_income': -4350, 'retained': -4350, 'aoci': 300, 'closed': ['cont_0', 'cont_4', 'cont_5', 'expe_1', 'loss_3']}], ['control 3', {'accounts': {'reve_0': ['revenue', -200], 'gain_1': ['gain', 400], 'liab_2': ['liability', 400], 'expe_3': ['expense', 150], 'expe_4': ['expense', 0], 'reve_5': ['revenue', 400]}, 'retained': 0, 'aoci': 0}, {'net_income': 450, 'retained': 450, 'aoci': 0, 'closed': ['expe_3', 'gain_1', 'reve_0', 'reve_5']}], ['control 4', {'accounts': {'oci_0': ['oci', -200], 'cont_1': ['contra_revenue', 0], 'asse_2': ['asset', 7500], 'loss_3': ['loss', 0], 'expe_4': ['expense', 150], 'asse_5': ['asset', 3000], 'loss_6': ['loss', 400]}, 'retained': 25000, 'aoci': 300}, {'net_income': -550, 'retained': 24450, 'aoci': 100, 'closed': ['expe_4', 'loss_6', 'oci_0']}], ['control 5', {'accounts': {'loss_0': ['loss', 7500], 'cont_1': ['contra_revenue', 400], 'reve_2': ['revenue', 0], 'loss_3': ['loss', 7500], 'expe_4': ['expense', 1200], 'reve_5': ['revenue', 150]}, 'retained': 0, 'aoci': -100}, {'net_income': -16450, 'retained': -16450, 'aoci': -100, 'closed': ['cont_1', 'expe_4', 'loss_0', 'loss_3', 'reve_5']}], ['control 6', {'accounts': {'loss_0': ['loss', 1200], 'cont_1': ['contra_revenue', 3000], 'reve_2': ['revenue', 1200], 'expe_3': ['expense', 7500], 'reve_4': ['revenue', 400], 'liab_5': ['liability', 400]}, 'retained': -500, 'aoci': 300}, {'net_income': -10100, 'retained': -10600, 'aoci': 300, 'closed': ['cont_1', 'expe_3', 'loss_0', 'reve_2', 'reve_4']}]], [['regression: dividends in net income', {'accounts': {'reve_0': ['revenue', 400], 'gain_1': ['gain', 0], 'liab_2': ['liability', 400], 'gain_3': ['gain', -200], 'asse_4': ['asset', 0], 'divi_5': ['dividend', 400]}, 'retained': 0, 'aoci': 300}, {'net_income': 200, 'retained': -200, 'aoci': 300, 'closed': ['divi_5', 'gain_3', 'reve_0']}], ['control 1', {'accounts': {'cont_0': ['contra_revenue', -200], 'expe_1': ['expense', -200], 'liab_2': ['liability', 0], 'asse_3': ['asset', 3000], 'gain_4': ['gain', 1200], 'gain_5': ['gain', 150], 'liab_6': ['liability', 1200], 'gain_7': ['gain', 400], 'liab_8': ['liability', 0]}, 'retained': 25000, 'aoci': -100}, {'net_income': 2150, 'retained': 27150, 'aoci': -100, 'closed': ['cont_0', 'expe_1', 'gain_4', 'gain_5', 'gain_7']}], ['control 2', {'accounts': {'liab_0': ['liability', 1200], 'cont_1': ['contra_revenue', 400], 'expe_2': ['expense', 1200], 'loss_3': ['loss', 400], 'liab_4': ['liability', 1200], 'expe_5': ['expense', 400], 'asse_6': ['asset', 3000], 'oci_7': ['oci', 3000]}, 'retained': 0, 'aoci': 0}, {'net_income': -2400, 'retained': -2400, 'aoci': 3000, 'closed': ['cont_1', 'expe_2', 'expe_5', 'loss_3', 'oci_7']}], ['control 3', {'accounts': {'oci_0': ['oci', 3000], 'oci_1': ['oci', -200], 'expe_2': ['expense', 400], 'gain_3': ['gain', 7500], 'cont_4': ['contra_revenue', 0]}, 'retained': -500, 'aoci': 0}, {'net_income': 7100, 'retained': 6600, 'aoci': 2800, 'closed': ['expe_2', 'gain_3', 'oci_0', 'oci_1']}], ['control 4', {'accounts': {'reve_0': ['revenue', 3000], 'liab_1': ['liability', -200], 'asse_2': ['asset', 7500], 'asse_3': ['asset', 0]}, 'retained': -500, 'aoci': -100}, {'net_income': 3000, 'retained': 2500, 'aoci': -100, 'closed': ['reve_0']}], ['control 5', {'accounts': {'expe_0': ['expense', -200], 'cont_1': ['contra_revenue', 1200], 'cont_2': ['contra_revenue', 1200], 'liab_3': ['liability', -200], 'cont_4': ['contra_revenue', 1200], 'oci_5': ['oci', 400], 'reve_6': ['revenue', -200], 'liab_7': ['liability', -200], 'loss_8': ['loss', 1200]}, 'retained': 1000, 'aoci': 0}, {'net_income': -4800, 'retained': -3800, 'aoci': 400, 'closed': ['cont_1', 'cont_2', 'cont_4', 'expe_0', 'loss_8', 'oci_5', 'reve_6']}], ['control 6', {'accounts': {'liab_0': ['liability', 150], 'oci_1': ['oci', 3000], 'expe_2': ['expense', -200], 'cont_3': ['contra_revenue', 400], 'asse_4': ['asset', 3000], 'liab_5': ['liability', 150], 'cont_6': ['contra_revenue', 0], 'cont_7': ['contra_revenue', -200], 'cont_8': ['contra_revenue', 400]}, 'retained': 1000, 'aoci': 300}, {'net_income': -400, 'retained': 600, 'aoci': 3300, 'closed': ['cont_3', 'cont_7', 'cont_8', 'expe_2', 'oci_1']}]], [['regression: dividends in net income', {'accounts': {'liab_0': ['liability', 0], 'expe_1': ['expense', 150], 'gain_2': ['gain', 0], 'liab_3': ['liability', 1200], 'gain_4': ['gain', -200], 'divi_5': ['dividend', 7500], 'divi_6': ['dividend', 1200], 'oci_7': ['oci', -200], 'asse_8': ['asset', -200]}, 'retained': 0, 'aoci': 300}, {'net_income': -350, 'retained': -9050, 'aoci': 100, 'closed': ['divi_5', 'divi_6', 'expe_1', 'gain_4', 'oci_7']}], ['control 1', {'accounts': {'oci_0': ['oci', 1200], 'liab_1': ['liability', 3000], 'expe_2': ['expense', 1200], 'loss_3': ['loss', 3000], 'liab_4': ['liability', 1200], 'loss_5': ['loss', 150], 'asse_6': ['asset', -200]}, 'retained': -500, 'aoci': 300}, {'net_income': -4350, 'retained': -4850, 'aoci': 1500, 'closed': ['expe_2', 'loss_3', 'loss_5', 'oci_0']}], ['control 2', {'accounts': {'oci_0': ['oci', 400], 'liab_1': ['liability', 1200], 'asse_2': ['asset', 7500], 'expe_3': ['expense', 3000], 'asse_4': ['asset', 400], 'liab_5': ['liability', 3000], 'liab_6': ['liability', 7500]}, 'retained': -500, 'aoci': -100}, {'net_income': -3000, 'retained': -3500, 'aoci': 300, 'closed': ['expe_3', 'oci_0']}], ['control 3', {'accounts': {'gain_0': ['gain', 1200], 'asse_1': ['asset', 3000], 'cont_2': ['contra_revenue', 400], 'expe_3': ['expense', 3000], 'cont_4': ['contra_revenue', 7500], 'expe_5': ['expense', 0]}, 'retained': 0, 'aoci': 0}, {'net_income': -9700, 'retained': -9700, 'aoci': 0, 'closed': ['cont_2', 'cont_4', 'expe_3', 'gain_0']}], ['control 4', {'accounts': {'cont_0': ['contra_revenue', 0], 'liab_1': ['liability', 3000], 'oci_2': ['oci', 3000], 'asse_3': ['asset', -200], 'reve_4': ['revenue', 7500]}, 'retained': 1000, 'aoci': 0}, {'net_income': 7500, 'retained': 8500, 'aoci': 3000, 'closed': ['oci_2', 'reve_4']}], ['control 5', {'accounts': {'gain_0': ['gain', 7500], 'loss_1': ['loss', 7500], 'oci_2': ['oci', -200], 'loss_3': ['loss', 1200], 'oci_4': ['oci', 1200], 'cont_5': ['contra_revenue', 0], 'oci_6': ['oci', -200]}, 'retained': -500, 'aoci': 0}, {'net_income': -1200, 'retained': -1700, 'aoci': 800, 'closed': ['gain_0', 'loss_1', 'loss_3', 'oci_2', 'oci_4', 'oci_6']}], ['control 6', {'accounts': {'liab_0': ['liability', -200], 'reve_1': ['revenue', 3000], 'asse_2': ['asset', 3000], 'reve_3': ['revenue', 3000], 'liab_4': ['liability', 3000], 'reve_5': ['revenue', 0], 'liab_6': ['liability', 150]}, 'retained': -500, 'aoci': 0}, {'net_income': 6000, 'retained': 5500, 'aoci': 0, 'closed': ['reve_1', 'reve_3']}]], [['regression: dividends in net income', {'accounts': {'oci_0': ['oci', 0], 'gain_1': ['gain', 0], 'oci_2': ['oci', 3000], 'expe_3': ['expense', 150], 'loss_4': ['loss', 150], 'divi_5': ['dividend', 150], 'cont_6': ['contra_revenue', 1200], 'expe_7': ['expense', 7500]}, 'retained': -500, 'aoci': 300}, {'net_income': -9000, 'retained': -9650, 'aoci': 3300, 'closed': ['cont_6', 'divi_5', 'expe_3', 'expe_7', 'loss_4', 'oci_2']}], ['control 1', {'accounts': {'gain_0': ['gain', 400], 'reve_1': ['revenue', 1200], 'reve_2': ['revenue', 400], 'expe_3': ['expense', 3000], 'oci_4': ['oci', -200], 'reve_5': ['revenue', -200], 'gain_6': ['gain', 3000], 'reve_7': ['revenue', -200]}, 'retained': 0, 'aoci': 300}, {'net_income': 1600, 'retained': 1600, 'aoci': 100, 'closed': ['expe_3', 'gain_0', 'gain_6', 'oci_4', 'reve_1', 'reve_2', 'reve_5', 'reve_7']}], ['control 2', {'accounts': {'liab_0': ['liability', 3000], 'gain_1': ['gain', -200], 'reve_2': ['revenue', -200], 'oci_3': ['oci', 150], 'oci_4': ['oci', 3000], 'oci_5': ['oci', 3000], 'cont_6': ['contra_revenue', 3000]}, 'retained': 1000, 'aoci': 300}, {'net_income': -3400, 'retained': -2400, 'aoci': 6450, 'closed': ['cont_6', 'gain_1', 'oci_3', 'oci_4', 'oci_5', 'reve_2']}], ['control 3', {'accounts': {'gain_0': ['gain', 7500], 'asse_1': ['asset', 400], 'oci_2': ['oci', 7500], 'liab_3': ['liability', 400], 'divi_4': ['dividend', 0], 'reve_5': ['revenue', 1200], 'gain_6': ['gain', 3000], 'oci_7': ['oci', 1200], 'oci_8': ['oci', 150]}, 'retained': -500, 'aoci': 0}, {'net_income': 11700, 'retained': 11200, 'aoci': 8850, 'closed': ['gain_0', 'gain_6', 'oci_2', 'oci_7', 'oci_8', 'reve_5']}], ['control 4', {'accounts': {'asse_0': ['asset', 400], 'expe_1': ['expense', 0], 'asse_2': ['asset', 150], 'loss_3': ['loss', 1200], 'asse_4': ['asset', 150], 'gain_5': ['gain', 7500], 'expe_6': ['expense', 150]}, 'retained': 0, 'aoci': -100}, {'net_income': 6150, 'retained': 6150, 'aoci': -100, 'closed': ['expe_6', 'gain_5', 'loss_3']}], ['control 5', {'accounts': {'oci_0': ['oci', 3000], 'liab_1': ['liability', 150], 'gain_2': ['gain', 0], 'loss_3': ['loss', 150], 'asse_4': ['asset', 3000], 'reve_5': ['revenue', -200], 'reve_6': ['revenue', 400]}, 'retained': -500, 'aoci': 300}, {'net_income': 50, 'retained': -450, 'aoci': 3300, 'closed': ['loss_3', 'oci_0', 'reve_5', 'reve_6']}], ['control 6', {'accounts': {'gain_0': ['gain', 0], 'cont_1': ['contra_revenue', 400], 'expe_2': ['expense', 150], 'loss_3': ['loss', 0], 'loss_4': ['loss', -200]}, 'retained': 1000, 'aoci': 300}, {'net_income': -350, 'retained': 650, 'aoci': 300, 'closed': ['cont_1', 'expe_2', 'loss_4']}]]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'raised ' + type(exc).__name__
    check(label, actual, expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Net income shrinks whenever dividends are declared.

x = {'accounts': {name: [type, normal-signed balance]}, 'retained': opening retained earnings, 'aoci': opening accumulated OCI}. Temporary types are revenue, contra_revenue, expense, gain, loss, dividend and oci. Income summary = revenue - contra_revenue + gain - expense - loss and is net income. Retained earnings close = opening + net income - dividends. OCI closes to AOCI, never to income or retained earnings. 'closed' lists temporary accounts with a nonzero balance (including abnormal negative ones), sorted. Return {'net_income', 'retained', 'aoci', 'closed'}.

split: open-access


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

N = 1
observations = []
def solve(x):
    acc = x['accounts']
    def total(kind):
        return sum(b for k, b in acc.values() if k == kind)
    rev = total('revenue')
    contra = total('contra_revenue')
    exp = total('expense')
    gain = total('gain')
    loss = total('loss')
    div = total('dividend')
    oci = total('oci')
    income_summary = rev - contra + gain - exp - loss
    retained = x['retained'] + income_summary - div
    aoci = x['aoci'] + oci
    temporary = ('revenue', 'contra_revenue', 'expense', 'gain', 'loss', 'oci')
    closed = sorted(n for n, (k, b) in acc.items() if k in temporary and b != 0)
    return {'net_income': income_summary, 'retained': retained, 'aoci': aoci, 'closed': closed}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: temporary account list', {'accounts': {'reve_0': ['revenue', 3000], 'oci_1': ['oci', 1200], 'divi_2': ['dividend', 400], 'expe_3': ['expense', 150]}, 'retained': 0, 'aoci': -100}, {'net_income': 2850, 'retained': 2450, 'aoci': 1100, 'closed': ['divi_2', 'expe_3', 'oci_1', 'reve_0']}], ['control 1', {'accounts': {'oci_0': ['oci', 150], 'oci_1': ['oci', 400], 'expe_2': ['expense', 7500], 'loss_3': ['loss', 3000]}, 'retained': 1000, 'aoci': -100}, {'net_income': -10500, 'retained': -9500, 'aoci': 450, 'closed': ['expe_2', 'loss_3', 'oci_0', 'oci_1']}], ['control 2', {'accounts': {'asse_0': ['asset', 400], 'gain_1': ['gain', 150], 'reve_2': ['revenue', 7500], 'gain_3': ['gain', 7500], 'asse_4': ['asset', 3000], 'reve_5': ['revenue', 3000], 'expe_6': ['expense', 400], 'reve_7': ['revenue', 400], 'reve_8': ['revenue', 3000]}, 'retained': 25000, 'aoci': 300}, {'net_income': 21150, 'retained': 46150, 'aoci': 300, 'closed': ['expe_6', 'gain_1', 'gain_3', 'reve_2', 'reve_5', 'reve_7', 'reve_8']}], ['control 3', {'accounts': {'asse_0': ['asset', 150], 'reve_1': ['revenue', 7500], 'divi_2': ['dividend', 0], 'gain_3': ['gain', 0], 'reve_4': ['revenue', 3000], 'gain_5': ['gain', 3000], 'asse_6': ['asset', 400]}, 'retained': 25000, 'aoci': 0}, {'net_income': 13500, 'retained': 38500, 'aoci': 0, 'closed': ['gain_5', 'reve_1', 'reve_4']}], ['control 4', {'accounts': {'gain_0': ['gain', 0], 'reve_1': ['revenue', -200], 'oci_2': ['oci', 400], 'asse_3': ['asset', 3000]}, 'retained': 1000, 'aoci': 300}, {'net_income': -200, 'retained': 800, 'aoci': 700, 'closed': ['oci_2', 'reve_1']}], ['control 5', {'accounts': {'reve_0': ['revenue', -200], 'reve_1': ['revenue', 0], 'expe_2': ['expense', 1200], 'loss_3': ['loss', 150]}, 'retained': 1000, 'aoci': 0}, {'net_income': -1550, 'retained': -550, 'aoci': 0, 'closed': ['expe_2', 'loss_3', 'reve_0']}], ['control 6', {'accounts': {'gain_0': ['gain', 3000], 'oci_1': ['oci', 150], 'gain_2': ['gain', 150], 'oci_3': ['oci', 0], 'loss_4': ['loss', 7500], 'cont_5': ['contra_revenue', 1200]}, 'retained': 0, 'aoci': 0}, {'net_income': -5550, 'retained': -5550, 'aoci': 150, 'closed': ['cont_5', 'gain_0', 'gain_2', 'loss_4', 'oci_1']}]], [['regression: temporary account list', {'accounts': {'reve_0': ['revenue', 1200], 'expe_1': ['expense', 7500], 'asse_2': ['asset', -200], 'cont_3': ['contra_revenue', 7500], 'cont_4': ['contra_revenue', 7500], 'divi_5': ['dividend', 7500], 'divi_6': ['dividend', 3000], 'cont_7': ['contra_revenue', 7500]}, 'retained': 0, 'aoci': -100}, {'net_income': -28800, 'retained': -39300, 'aoci': -100, 'closed': ['cont_3', 'cont_4', 'cont_7', 'divi_5', 'divi_6', 'expe_1', 'reve_0']}], ['regression: temporary account list, partial-repair probe', {'accounts': {'asse_0': ['asset', 7500], 'expe_1': ['expense', 7500], 'gain_2': ['gain', 400], 'loss_3': ['loss', 0], 'liab_4': ['liability', 400], 'oci_5': ['oci', -200], 'cont_6': ['contra_revenue', 150], 'oci_7': ['oci', -200]}, 'retained': 25000, 'aoci': 300}, {'net_income': -7250, 'retained': 17750, 'aoci': -100, 'closed': ['cont_6', 'expe_1', 'gain_2', 'oci_5', 'oci_7']}], ['control 1', {'accounts': {'cont_0': ['contra_revenue', 400], 'expe_1': ['expense', 400], 'loss_2': ['loss', 0], 'loss_3': ['loss', 150], 'cont_4': ['contra_revenue', 400], 'cont_5': ['contra_revenue', 3000]}, 'retained': 0, 'aoci': 300}, {'net_income': -4350, 'retained': -4350, 'aoci': 300, 'closed': ['cont_0', 'cont_4', 'cont_5', 'expe_1', 'loss_3']}], ['control 2', {'accounts': {'reve_0': ['revenue', -200], 'gain_1': ['gain', 400], 'liab_2': ['liability', 400], 'expe_3': ['expense', 150], 'expe_4': ['expense', 0], 'reve_5': ['revenue', 400]}, 'retained': 0, 'aoci': 0}, {'net_income': 450, 'retained': 450, 'aoci': 0, 'closed': ['expe_3', 'gain_1', 'reve_0', 'reve_5']}], ['control 3', {'accounts': {'oci_0': ['oci', -200], 'cont_1': ['contra_revenue', 0], 'asse_2': ['asset', 7500], 'loss_3': ['loss', 0], 'expe_4': ['expense', 150], 'asse_5': ['asset', 3000], 'loss_6': ['loss', 400]}, 'retained': 25000, 'aoci': 300}, {'net_income': -550, 'retained': 24450, 'aoci': 100, 'closed': ['expe_4', 'loss_6', 'oci_0']}], ['control 4', {'accounts': {'loss_0': ['loss', 7500], 'cont_1': ['contra_revenue', 400], 'reve_2': ['revenue', 0], 'loss_3': ['loss', 7500], 'expe_4': ['expense', 1200], 'reve_5': ['revenue', 150]}, 'retained': 0, 'aoci': -100}, {'net_income': -16450, 'retained': -16450, 'aoci': -100, 'closed': ['cont_1', 'expe_4', 'loss_0', 'loss_3', 'reve_5']}], ['control 5', {'accounts': {'loss_0': ['loss', 1200], 'cont_1': ['contra_revenue', 3000], 'reve_2': ['revenue', 1200], 'expe_3': ['expense', 7500], 'reve_4': ['revenue', 400], 'liab_5': ['liability', 400]}, 'retained': -500, 'aoci': 300}, {'net_income': -10100, 'retained': -10600, 'aoci': 300, 'closed': ['cont_1', 'expe_3', 'loss_0', 'reve_2', 'reve_4']}]], [['regression: temporary account list', {'accounts': {'reve_0': ['revenue', 400], 'gain_1': ['gain', 0], 'liab_2': ['liability', 400], 'gain_3': ['gain', -200], 'asse_4': ['asset', 0], 'divi_5': ['dividend', 400]}, 'retained': 0, 'aoci': 300}, {'net_income': 200, 'retained': -200, 'aoci': 300, 'closed': ['divi_5', 'gain_3', 'reve_0']}], ['regression: temporary account list, partial-repair probe', {'accounts': {'liab_0': ['liability', 1200], 'cont_1': ['contra_revenue', 400], 'expe_2': ['expense', 1200], 'loss_3': ['loss', 400], 'liab_4': ['liability', 1200], 'expe_5': ['expense', 400], 'asse_6': ['asset', 3000], 'oci_7': ['oci', 3000]}, 'retained': 0, 'aoci': 0}, {'net_income': -2400, 'retained': -2400, 'aoci': 3000, 'closed': ['cont_1', 'expe_2', 'expe_5', 'loss_3', 'oci_7']}], ['control 1', {'accounts': {'cont_0': ['contra_revenue', -200], 'expe_1': ['expense', -200], 'liab_2': ['liability', 0], 'asse_3': ['asset', 3000], 'gain_4': ['gain', 1200], 'gain_5': ['gain', 150], 'liab_6': ['liability', 1200], 'gain_7': ['gain', 400], 'liab_8': ['liability', 0]}, 'retained': 25000, 'aoci': -100}, {'net_income': 2150, 'retained': 27150, 'aoci': -100, 'closed': ['cont_0', 'expe_1', 'gain_4', 'gain_5', 'gain_7']}], ['control 2', {'accounts': {'oci_0': ['oci', 3000], 'oci_1': ['oci', -200], 'expe_2': ['expense', 400], 'gain_3': ['gain', 7500], 'cont_4': ['contra_revenue', 0]}, 'retained': -500, 'aoci': 0}, {'net_income': 7100, 'retained': 6600, 'aoci': 2800, 'closed': ['expe_2', 'gain_3', 'oci_0', 'oci_1']}], ['control 3', {'accounts': {'reve_0': ['revenue', 3000], 'liab_1': ['liability', -200], 'asse_2': ['asset', 7500], 'asse_3': ['asset', 0]}, 'retained': -500, 'aoci': -100}, {'net_income': 3000, 'retained': 2500, 'aoci': -100, 'closed': ['reve_0']}], ['control 4', {'accounts': {'expe_0': ['expense', -200], 'cont_1': ['contra_revenue', 1200], 'cont_2': ['contra_revenue', 1200], 'liab_3': ['liability', -200], 'cont_4': ['contra_revenue', 1200], 'oci_5': ['oci', 400], 'reve_6': ['revenue', -200], 'liab_7': ['liability', -200], 'loss_8': ['loss', 1200]}, 'retained': 1000, 'aoci': 0}, {'net_income': -4800, 'retained': -3800, 'aoci': 400, 'closed': ['cont_1', 'cont_2', 'cont_4', 'expe_0', 'loss_8', 'oci_5', 'reve_6']}], ['control 5', {'accounts': {'liab_0': ['liability', 150], 'oci_1': ['oci', 3000], 'expe_2': ['expense', -200], 'cont_3': ['contra_revenue', 400], 'asse_4': ['asset', 3000], 'liab_5': ['liability', 150], 'cont_6': ['contra_revenue', 0], 'cont_7': ['contra_revenue', -200], 'cont_8': ['contra_revenue', 400]}, 'retained': 1000, 'aoci': 300}, {'net_income': -400, 'retained': 600, 'aoci': 3300, 'closed': ['cont_3', 'cont_7', 'cont_8', 'expe_2', 'oci_1']}]], [['regression: temporary account list', {'accounts': {'liab_0': ['liability', 0], 'expe_1': ['expense', 150], 'gain_2': ['gain', 0], 'liab_3': ['liability', 1200], 'gain_4': ['gain', -200], 'divi_5': ['dividend', 7500], 'divi_6': ['dividend', 1200], 'oci_7': ['oci', -200], 'asse_8': ['asset', -200]}, 'retained': 0, 'aoci': 300}, {'net_income': -350, 'retained': -9050, 'aoci': 100, 'closed': ['divi_5', 'divi_6', 'expe_1', 'gain_4', 'oci_7']}], ['control 1', {'accounts': {'oci_0': ['oci', 1200], 'liab_1': ['liability', 3000], 'expe_2': ['expense', 1200], 'loss_3': ['loss', 3000], 'liab_4': ['liability', 1200], 'loss_5': ['loss', 150], 'asse_6': ['asset', -200]}, 'retained': -500, 'aoci': 300}, {'net_income': -4350, 'retained': -4850, 'aoci': 1500, 'closed': ['expe_2', 'loss_3', 'loss_5', 'oci_0']}], ['control 2', {'accounts': {'oci_0': ['oci', 400], 'liab_1': ['liability', 1200], 'asse_2': ['asset', 7500], 'expe_3': ['expense', 3000], 'asse_4': ['asset', 400], 'liab_5': ['liability', 3000], 'liab_6': ['liability', 7500]}, 'retained': -500, 'aoci': -100}, {'net_income': -3000, 'retained': -3500, 'aoci': 300, 'closed': ['expe_3', 'oci_0']}], ['control 3', {'accounts': {'gain_0': ['gain', 1200], 'asse_1': ['asset', 3000], 'cont_2': ['contra_revenue', 400], 'expe_3': ['expense', 3000], 'cont_4': ['contra_revenue', 7500], 'expe_5': ['expense', 0]}, 'retained': 0, 'aoci': 0}, {'net_income': -9700, 'retained': -9700, 'aoci': 0, 'closed': ['cont_2', 'cont_4', 'expe_3', 'gain_0']}], ['control 4', {'accounts': {'cont_0': ['contra_revenue', 0], 'liab_1': ['liability', 3000], 'oci_2': ['oci', 3000], 'asse_3': ['asset', -200], 'reve_4': ['revenue', 7500]}, 'retained': 1000, 'aoci': 0}, {'net_income': 7500, 'retained': 8500, 'aoci': 3000, 'closed': ['oci_2', 'reve_4']}], ['control 5', {'accounts': {'gain_0': ['gain', 7500], 'loss_1': ['loss', 7500], 'oci_2': ['oci', -200], 'loss_3': ['loss', 1200], 'oci_4': ['oci', 1200], 'cont_5': ['contra_revenue', 0], 'oci_6': ['oci', -200]}, 'retained': -500, 'aoci': 0}, {'net_income': -1200, 'retained': -1700, 'aoci': 800, 'closed': ['gain_0', 'loss_1', 'loss_3', 'oci_2', 'oci_4', 'oci_6']}], ['control 6', {'accounts': {'liab_0': ['liability', -200], 'reve_1': ['revenue', 3000], 'asse_2': ['asset', 3000], 'reve_3': ['revenue', 3000], 'liab_4': ['liability', 3000], 'reve_5': ['revenue', 0], 'liab_6': ['liability', 150]}, 'retained': -500, 'aoci': 0}, {'net_income': 6000, 'retained': 5500, 'aoci': 0, 'closed': ['reve_1', 'reve_3']}]], [['regression: temporary account list', {'accounts': {'oci_0': ['oci', 0], 'gain_1': ['gain', 0], 'oci_2': ['oci', 3000], 'expe_3': ['expense', 150], 'loss_4': ['loss', 150], 'divi_5': ['dividend', 150], 'cont_6': ['contra_revenue', 1200], 'expe_7': ['expense', 7500]}, 'retained': -500, 'aoci': 300}, {'net_income': -9000, 'retained': -9650, 'aoci': 3300, 'closed': ['cont_6', 'divi_5', 'expe_3', 'expe_7', 'loss_4', 'oci_2']}], ['control 1', {'accounts': {'gain_0': ['gain', 400], 'reve_1': ['revenue', 1200], 'reve_2': ['revenue', 400], 'expe_3': ['expense', 3000], 'oci_4': ['oci', -200], 'reve_5': ['revenue', -200], 'gain_6': ['gain', 3000], 'reve_7': ['revenue', -200]}, 'retained': 0, 'aoci': 300}, {'net_income': 1600, 'retained': 1600, 'aoci': 100, 'closed': ['expe_3', 'gain_0', 'gain_6', 'oci_4', 'reve_1', 'reve_2', 'reve_5', 'reve_7']}], ['control 2', {'accounts': {'liab_0': ['liability', 3000], 'gain_1': ['gain', -200], 'reve_2': ['revenue', -200], 'oci_3': ['oci', 150], 'oci_4': ['oci', 3000], 'oci_5': ['oci', 3000], 'cont_6': ['contra_revenue', 3000]}, 'retained': 1000, 'aoci': 300}, {'net_income': -3400, 'retained': -2400, 'aoci': 6450, 'closed': ['cont_6', 'gain_1', 'oci_3', 'oci_4', 'oci_5', 'reve_2']}], ['control 3', {'accounts': {'gain_0': ['gain', 7500], 'asse_1': ['asset', 400], 'oci_2': ['oci', 7500], 'liab_3': ['liability', 400], 'divi_4': ['dividend', 0], 'reve_5': ['revenue', 1200], 'gain_6': ['gain', 3000], 'oci_7': ['oci', 1200], 'oci_8': ['oci', 150]}, 'retained': -500, 'aoci': 0}, {'net_income': 11700, 'retained': 11200, 'aoci': 8850, 'closed': ['gain_0', 'gain_6', 'oci_2', 'oci_7', 'oci_8', 'reve_5']}], ['control 4', {'accounts': {'asse_0': ['asset', 400], 'expe_1': ['expense', 0], 'asse_2': ['asset', 150], 'loss_3': ['loss', 1200], 'asse_4': ['asset', 150], 'gain_5': ['gain', 7500], 'expe_6': ['expense', 150]}, 'retained': 0, 'aoci': -100}, {'net_income': 6150, 'retained': 6150, 'aoci': -100, 'closed': ['expe_6', 'gain_5', 'loss_3']}], ['control 5', {'accounts': {'oci_0': ['oci', 3000], 'liab_1': ['liability', 150], 'gain_2': ['gain', 0], 'loss_3': ['loss', 150], 'asse_4': ['asset', 3000], 'reve_5': ['revenue', -200], 'reve_6': ['revenue', 400]}, 'retained': -500, 'aoci': 300}, {'net_income': 50, 'retained': -450, 'aoci': 3300, 'closed': ['loss_3', 'oci_0', 'reve_5', 'reve_6']}], ['control 6', {'accounts': {'gain_0': ['gain', 0], 'cont_1': ['contra_revenue', 400], 'expe_2': ['expense', 150], 'loss_3': ['loss', 0], 'loss_4': ['loss', -200]}, 'retained': 1000, 'aoci': 300}, {'net_income': -350, 'retained': 650, 'aoci': 300, 'closed': ['cont_1', 'expe_2', 'loss_4']}]]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'raised ' + type(exc).__name__
    check(label, actual, expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    acc = x['accounts']
    def total(kind):
        return sum(b for k, b in acc.values() if k == kind)
    rev = total('revenue')
    contra = total('contra_revenue')
    exp = total('expense')
    gain = total('gain')
    loss = total('loss')
    div = total('dividend')
    oci = total('oci')
    income_summary = rev - contra + gain - exp - loss
    retained = x['retained'] + income_summary - div
    aoci = x['aoci'] + oci
    temporary = ('revenue', 'contra_revenue', 'expense', 'gain', 'loss', 'dividend')
    closed = sorted(n for n, (k, b) in acc.items() if k in temporary and b != 0)
    return {'net_income': income_summary, 'retained': retained, 'aoci': aoci, 'closed': closed}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: temporary account list', {'accounts': {'reve_0': ['revenue', 3000], 'oci_1': ['oci', 1200], 'divi_2': ['dividend', 400], 'expe_3': ['expense', 150]}, 'retained': 0, 'aoci': -100}, {'net_income': 2850, 'retained': 2450, 'aoci': 1100, 'closed': ['divi_2', 'expe_3', 'oci_1', 'reve_0']}], ['control 1', {'accounts': {'oci_0': ['oci', 150], 'oci_1': ['oci', 400], 'expe_2': ['expense', 7500], 'loss_3': ['loss', 3000]}, 'retained': 1000, 'aoci': -100}, {'net_income': -10500, 'retained': -9500, 'aoci': 450, 'closed': ['expe_2', 'loss_3', 'oci_0', 'oci_1']}], ['control 2', {'accounts': {'asse_0': ['asset', 400], 'gain_1': ['gain', 150], 'reve_2': ['revenue', 7500], 'gain_3': ['gain', 7500], 'asse_4': ['asset', 3000], 'reve_5': ['revenue', 3000], 'expe_6': ['expense', 400], 'reve_7': ['revenue', 400], 'reve_8': ['revenue', 3000]}, 'retained': 25000, 'aoci': 300}, {'net_income': 21150, 'retained': 46150, 'aoci': 300, 'closed': ['expe_6', 'gain_1', 'gain_3', 'reve_2', 'reve_5', 'reve_7', 'reve_8']}], ['control 3', {'accounts': {'asse_0': ['asset', 150], 'reve_1': ['revenue', 7500], 'divi_2': ['dividend', 0], 'gain_3': ['gain', 0], 'reve_4': ['revenue', 3000], 'gain_5': ['gain', 3000], 'asse_6': ['asset', 400]}, 'retained': 25000, 'aoci': 0}, {'net_income': 13500, 'retained': 38500, 'aoci': 0, 'closed': ['gain_5', 'reve_1', 'reve_4']}], ['control 4', {'accounts': {'gain_0': ['gain', 0], 'reve_1': ['revenue', -200], 'oci_2': ['oci', 400], 'asse_3': ['asset', 3000]}, 'retained': 1000, 'aoci': 300}, {'net_income': -200, 'retained': 800, 'aoci': 700, 'closed': ['oci_2', 'reve_1']}], ['control 5', {'accounts': {'reve_0': ['revenue', -200], 'reve_1': ['revenue', 0], 'expe_2': ['expense', 1200], 'loss_3': ['loss', 150]}, 'retained': 1000, 'aoci': 0}, {'net_income': -1550, 'retained': -550, 'aoci': 0, 'closed': ['expe_2', 'loss_3', 'reve_0']}], ['control 6', {'accounts': {'gain_0': ['gain', 3000], 'oci_1': ['oci', 150], 'gain_2': ['gain', 150], 'oci_3': ['oci', 0], 'loss_4': ['loss', 7500], 'cont_5': ['contra_revenue', 1200]}, 'retained': 0, 'aoci': 0}, {'net_income': -5550, 'retained': -5550, 'aoci': 150, 'closed': ['cont_5', 'gain_0', 'gain_2', 'loss_4', 'oci_1']}]], [['regression: temporary account list', {'accounts': {'reve_0': ['revenue', 1200], 'expe_1': ['expense', 7500], 'asse_2': ['asset', -200], 'cont_3': ['contra_revenue', 7500], 'cont_4': ['contra_revenue', 7500], 'divi_5': ['dividend', 7500], 'divi_6': ['dividend', 3000], 'cont_7': ['contra_revenue', 7500]}, 'retained': 0, 'aoci': -100}, {'net_income': -28800, 'retained': -39300, 'aoci': -100, 'closed': ['cont_3', 'cont_4', 'cont_7', 'divi_5', 'divi_6', 'expe_1', 'reve_0']}], ['regression: temporary account list, partial-repair probe', {'accounts': {'asse_0': ['asset', 7500], 'expe_1': ['expense', 7500], 'gain_2': ['gain', 400], 'loss_3': ['loss', 0], 'liab_4': ['liability', 400], 'oci_5': ['oci', -200], 'cont_6': ['contra_revenue', 150], 'oci_7': ['oci', -200]}, 'retained': 25000, 'aoci': 300}, {'net_income': -7250, 'retained': 17750, 'aoci': -100, 'closed': ['cont_6', 'expe_1', 'gain_2', 'oci_5', 'oci_7']}], ['control 1', {'accounts': {'cont_0': ['contra_revenue', 400], 'expe_1': ['expense', 400], 'loss_2': ['loss', 0], 'loss_3': ['loss', 150], 'cont_4': ['contra_revenue', 400], 'cont_5': ['contra_revenue', 3000]}, 'retained': 0, 'aoci': 300}, {'net_income': -4350, 'retained': -4350, 'aoci': 300, 'closed': ['cont_0', 'cont_4', 'cont_5', 'expe_1', 'loss_3']}], ['control 2', {'accounts': {'reve_0': ['revenue', -200], 'gain_1': ['gain', 400], 'liab_2': ['liability', 400], 'expe_3': ['expense', 150], 'expe_4': ['expense', 0], 'reve_5': ['revenue', 400]}, 'retained': 0, 'aoci': 0}, {'net_income': 450, 'retained': 450, 'aoci': 0, 'closed': ['expe_3', 'gain_1', 'reve_0', 'reve_5']}], ['control 3', {'accounts': {'oci_0': ['oci', -200], 'cont_1': ['contra_revenue', 0], 'asse_2': ['asset', 7500], 'loss_3': ['loss', 0], 'expe_4': ['expense', 150], 'asse_5': ['asset', 3000], 'loss_6': ['loss', 400]}, 'retained': 25000, 'aoci': 300}, {'net_income': -550, 'retained': 24450, 'aoci': 100, 'closed': ['expe_4', 'loss_6', 'oci_0']}], ['control 4', {'accounts': {'loss_0': ['loss', 7500], 'cont_1': ['contra_revenue', 400], 'reve_2': ['revenue', 0], 'loss_3': ['loss', 7500], 'expe_4': ['expense', 1200], 'reve_5': ['revenue', 150]}, 'retained': 0, 'aoci': -100}, {'net_income': -16450, 'retained': -16450, 'aoci': -100, 'closed': ['cont_1', 'expe_4', 'loss_0', 'loss_3', 'reve_5']}], ['control 5', {'accounts': {'loss_0': ['loss', 1200], 'cont_1': ['contra_revenue', 3000], 'reve_2': ['revenue', 1200], 'expe_3': ['expense', 7500], 'reve_4': ['revenue', 400], 'liab_5': ['liability', 400]}, 'retained': -500, 'aoci': 300}, {'net_income': -10100, 'retained': -10600, 'aoci': 300, 'closed': ['cont_1', 'expe_3', 'loss_0', 'reve_2', 'reve_4']}]], [['regression: temporary account list', {'accounts': {'reve_0': ['revenue', 400], 'gain_1': ['gain', 0], 'liab_2': ['liability', 400], 'gain_3': ['gain', -200], 'asse_4': ['asset', 0], 'divi_5': ['dividend', 400]}, 'retained': 0, 'aoci': 300}, {'net_income': 200, 'retained': -200, 'aoci': 300, 'closed': ['divi_5', 'gain_3', 'reve_0']}], ['regression: temporary account list, partial-repair probe', {'accounts': {'liab_0': ['liability', 1200], 'cont_1': ['contra_revenue', 400], 'expe_2': ['expense', 1200], 'loss_3': ['loss', 400], 'liab_4': ['liability', 1200], 'expe_5': ['expense', 400], 'asse_6': ['asset', 3000], 'oci_7': ['oci', 3000]}, 'retained': 0, 'aoci': 0}, {'net_income': -2400, 'retained': -2400, 'aoci': 3000, 'closed': ['cont_1', 'expe_2', 'expe_5', 'loss_3', 'oci_7']}], ['control 1', {'accounts': {'cont_0': ['contra_revenue', -200], 'expe_1': ['expense', -200], 'liab_2': ['liability', 0], 'asse_3': ['asset', 3000], 'gain_4': ['gain', 1200], 'gain_5': ['gain', 150], 'liab_6': ['liability', 1200], 'gain_7': ['gain', 400], 'liab_8': ['liability', 0]}, 'retained': 25000, 'aoci': -100}, {'net_income': 2150, 'retained': 27150, 'aoci': -100, 'closed': ['cont_0', 'expe_1', 'gain_4', 'gain_5', 'gain_7']}], ['control 2', {'accounts': {'oci_0': ['oci', 3000], 'oci_1': ['oci', -200], 'expe_2': ['expense', 400], 'gain_3': ['gain', 7500], 'cont_4': ['contra_revenue', 0]}, 'retained': -500, 'aoci': 0}, {'net_income': 7100, 'retained': 6600, 'aoci': 2800, 'closed': ['expe_2', 'gain_3', 'oci_0', 'oci_1']}], ['control 3', {'accounts': {'reve_0': ['revenue', 3000], 'liab_1': ['liability', -200], 'asse_2': ['asset', 7500], 'asse_3': ['asset', 0]}, 'retained': -500, 'aoci': -100}, {'net_income': 3000, 'retained': 2500, 'aoci': -100, 'closed': ['reve_0']}], ['control 4', {'accounts': {'expe_0': ['expense', -200], 'cont_1': ['contra_revenue', 1200], 'cont_2': ['contra_revenue', 1200], 'liab_3': ['liability', -200], 'cont_4': ['contra_revenue', 1200], 'oci_5': ['oci', 400], 'reve_6': ['revenue', -200], 'liab_7': ['liability', -200], 'loss_8': ['loss', 1200]}, 'retained': 1000, 'aoci': 0}, {'net_income': -4800, 'retained': -3800, 'aoci': 400, 'closed': ['cont_1', 'cont_2', 'cont_4', 'expe_0', 'loss_8', 'oci_5', 'reve_6']}], ['control 5', {'accounts': {'liab_0': ['liability', 150], 'oci_1': ['oci', 3000], 'expe_2': ['expense', -200], 'cont_3': ['contra_revenue', 400], 'asse_4': ['asset', 3000], 'liab_5': ['liability', 150], 'cont_6': ['contra_revenue', 0], 'cont_7': ['contra_revenue', -200], 'cont_8': ['contra_revenue', 400]}, 'retained': 1000, 'aoci': 300}, {'net_income': -400, 'retained': 600, 'aoci': 3300, 'closed': ['cont_3', 'cont_7', 'cont_8', 'expe_2', 'oci_1']}]], [['regression: temporary account list', {'accounts': {'liab_0': ['liability', 0], 'expe_1': ['expense', 150], 'gain_2': ['gain', 0], 'liab_3': ['liability', 1200], 'gain_4': ['gain', -200], 'divi_5': ['dividend', 7500], 'divi_6': ['dividend', 1200], 'oci_7': ['oci', -200], 'asse_8': ['asset', -200]}, 'retained': 0, 'aoci': 300}, {'net_income': -350, 'retained': -9050, 'aoci': 100, 'closed': ['divi_5', 'divi_6', 'expe_1', 'gain_4', 'oci_7']}], ['control 1', {'accounts': {'oci_0': ['oci', 1200], 'liab_1': ['liability', 3000], 'expe_2': ['expense', 1200], 'loss_3': ['loss', 3000], 'liab_4': ['liability', 1200], 'loss_5': ['loss', 150], 'asse_6': ['asset', -200]}, 'retained': -500, 'aoci': 300}, {'net_income': -4350, 'retained': -4850, 'aoci': 1500, 'closed': ['expe_2', 'loss_3', 'loss_5', 'oci_0']}], ['control 2', {'accounts': {'oci_0': ['oci', 400], 'liab_1': ['liability', 1200], 'asse_2': ['asset', 7500], 'expe_3': ['expense', 3000], 'asse_4': ['asset', 400], 'liab_5': ['liability', 3000], 'liab_6': ['liability', 7500]}, 'retained': -500, 'aoci': -100}, {'net_income': -3000, 'retained': -3500, 'aoci': 300, 'closed': ['expe_3', 'oci_0']}], ['control 3', {'accounts': {'gain_0': ['gain', 1200], 'asse_1': ['asset', 3000], 'cont_2': ['contra_revenue', 400], 'expe_3': ['expense', 3000], 'cont_4': ['contra_revenue', 7500], 'expe_5': ['expense', 0]}, 'retained': 0, 'aoci': 0}, {'net_income': -9700, 'retained': -9700, 'aoci': 0, 'closed': ['cont_2', 'cont_4', 'expe_3', 'gain_0']}], ['control 4', {'accounts': {'cont_0': ['contra_revenue', 0], 'liab_1': ['liability', 3000], 'oci_2': ['oci', 3000], 'asse_3': ['asset', -200], 'reve_4': ['revenue', 7500]}, 'retained': 1000, 'aoci': 0}, {'net_income': 7500, 'retained': 8500, 'aoci': 3000, 'closed': ['oci_2', 'reve_4']}], ['control 5', {'accounts': {'gain_0': ['gain', 7500], 'loss_1': ['loss', 7500], 'oci_2': ['oci', -200], 'loss_3': ['loss', 1200], 'oci_4': ['oci', 1200], 'cont_5': ['contra_revenue', 0], 'oci_6': ['oci', -200]}, 'retained': -500, 'aoci': 0}, {'net_income': -1200, 'retained': -1700, 'aoci': 800, 'closed': ['gain_0', 'loss_1', 'loss_3', 'oci_2', 'oci_4', 'oci_6']}], ['control 6', {'accounts': {'liab_0': ['liability', -200], 'reve_1': ['revenue', 3000], 'asse_2': ['asset', 3000], 'reve_3': ['revenue', 3000], 'liab_4': ['liability', 3000], 'reve_5': ['revenue', 0], 'liab_6': ['liability', 150]}, 'retained': -500, 'aoci': 0}, {'net_income': 6000, 'retained': 5500, 'aoci': 0, 'closed': ['reve_1', 'reve_3']}]], [['regression: temporary account list', {'accounts': {'oci_0': ['oci', 0], 'gain_1': ['gain', 0], 'oci_2': ['oci', 3000], 'expe_3': ['expense', 150], 'loss_4': ['loss', 150], 'divi_5': ['dividend', 150], 'cont_6': ['contra_revenue', 1200], 'expe_7': ['expense', 7500]}, 'retained': -500, 'aoci': 300}, {'net_income': -9000, 'retained': -9650, 'aoci': 3300, 'closed': ['cont_6', 'divi_5', 'expe_3', 'expe_7', 'loss_4', 'oci_2']}], ['control 1', {'accounts': {'gain_0': ['gain', 400], 'reve_1': ['revenue', 1200], 'reve_2': ['revenue', 400], 'expe_3': ['expense', 3000], 'oci_4': ['oci', -200], 'reve_5': ['revenue', -200], 'gain_6': ['gain', 3000], 'reve_7': ['revenue', -200]}, 'retained': 0, 'aoci': 300}, {'net_income': 1600, 'retained': 1600, 'aoci': 100, 'closed': ['expe_3', 'gain_0', 'gain_6', 'oci_4', 'reve_1', 'reve_2', 'reve_5', 'reve_7']}], ['control 2', {'accounts': {'liab_0': ['liability', 3000], 'gain_1': ['gain', -200], 'reve_2': ['revenue', -200], 'oci_3': ['oci', 150], 'oci_4': ['oci', 3000], 'oci_5': ['oci', 3000], 'cont_6': ['contra_revenue', 3000]}, 'retained': 1000, 'aoci': 300}, {'net_income': -3400, 'retained': -2400, 'aoci': 6450, 'closed': ['cont_6', 'gain_1', 'oci_3', 'oci_4', 'oci_5', 'reve_2']}], ['control 3', {'accounts': {'gain_0': ['gain', 7500], 'asse_1': ['asset', 400], 'oci_2': ['oci', 7500], 'liab_3': ['liability', 400], 'divi_4': ['dividend', 0], 'reve_5': ['revenue', 1200], 'gain_6': ['gain', 3000], 'oci_7': ['oci', 1200], 'oci_8': ['oci', 150]}, 'retained': -500, 'aoci': 0}, {'net_income': 11700, 'retained': 11200, 'aoci': 8850, 'closed': ['gain_0', 'gain_6', 'oci_2', 'oci_7', 'oci_8', 'reve_5']}], ['control 4', {'accounts': {'asse_0': ['asset', 400], 'expe_1': ['expense', 0], 'asse_2': ['asset', 150], 'loss_3': ['loss', 1200], 'asse_4': ['asset', 150], 'gain_5': ['gain', 7500], 'expe_6': ['expense', 150]}, 'retained': 0, 'aoci': -100}, {'net_income': 6150, 'retained': 6150, 'aoci': -100, 'closed': ['expe_6', 'gain_5', 'loss_3']}], ['control 5', {'accounts': {'oci_0': ['oci', 3000], 'liab_1': ['liability', 150], 'gain_2': ['gain', 0], 'loss_3': ['loss', 150], 'asse_4': ['asset', 3000], 'reve_5': ['revenue', -200], 'reve_6': ['revenue', 400]}, 'retained': -500, 'aoci': 300}, {'net_income': 50, 'retained': -450, 'aoci': 3300, 'closed': ['loss_3', 'oci_0', 'reve_5', 'reve_6']}], ['control 6', {'accounts': {'gain_0': ['gain', 0], 'cont_1': ['contra_revenue', 400], 'expe_2': ['expense', 150], 'loss_3': ['loss', 0], 'loss_4': ['loss', -200]}, 'retained': 1000, 'aoci': 300}, {'net_income': -350, 'retained': 650, 'aoci': 300, 'closed': ['cont_1', 'expe_2', 'loss_4']}]]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'raised ' + type(exc).__name__
    check(label, actual, expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The dividend account is left open after closing.

x = {'accounts': {name: [type, normal-signed balance]}, 'retained': opening retained earnings, 'aoci': opening accumulated OCI}. Temporary types are revenue, contra_revenue, expense, gain, loss, dividend and oci. Income summary = revenue - contra_revenue + gain - expense - loss and is net income. Retained earnings close = opening + net income - dividends. OCI closes to AOCI, never to income or retained earnings. 'closed' lists temporary accounts with a nonzero balance (including abnormal negative ones), sorted. Return {'net_income', 'retained', 'aoci', 'closed'}.

split: open-access