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

N = 1
observations = []
def solve(x):
    bal = dict(x['members'])
    sent = dict(x['sent_ytd'])
    out = []
    for f, t, p in x['transfers']:
        if f == t or f not in bal or t not in bal:
            out.append('invalid')
            continue
        if p < x['min_transfer']:
            out.append('below minimum')
            continue
        if sent.get(f, 0) + p > x['annual_cap']:
            out.append('cap')
            continue
        fee = p * x['fee_bp'] // 10000
        if bal[f] < p + fee:
            out.append('insufficient')
            continue
        bal[f] -= p + fee
        bal[t] += p
        sent[f] = sent.get(f, 0) + p
        out.append(fee)
    return {'results': out, 'balances': [[k, bal[k]] for k in sorted(bal)]}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2000]], 'sent_ytd': {}}, {'results': [50], 'balances': [['a', 2950], ['b', 2100]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1001]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1013], ['b', 1001]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14999}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5001]], 'sent_ytd': {'a': 14999}}, {'results': [126], 'balances': [['a', 84873], ['b', 5001]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1004], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48962], ['b', 1011]]}], ['fees do not use cap', {'fee_bp': 501, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [501, 501], 'balances': [['a', 68998], ['c', 20000]]}]], [['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2001]], 'sent_ytd': {}}, {'results': [51], 'balances': [['a', 2948], ['b', 2101]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1002]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1012], ['b', 1002]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14998}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5002]], 'sent_ytd': {'a': 14998}}, {'results': [126], 'balances': [['a', 84872], ['b', 5002]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1007], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48959], ['b', 1014]]}], ['fees do not use cap', {'fee_bp': 502, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [502, 502], 'balances': [['a', 68996], ['c', 20000]]}]], [['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2002]], 'sent_ytd': {}}, {'results': [51], 'balances': [['a', 2947], ['b', 2102]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1003]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1011], ['b', 1003]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14997}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5003]], 'sent_ytd': {'a': 14997}}, {'results': [126], 'balances': [['a', 84871], ['b', 5003]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1010], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48956], ['b', 1017]]}], ['fees do not use cap', {'fee_bp': 503, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [503, 503], 'balances': [['a', 68994], ['c', 20000]]}]], [['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2003]], 'sent_ytd': {}}, {'results': [51], 'balances': [['a', 2946], ['b', 2103]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1004]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1010], ['b', 1004]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14996}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5004]], 'sent_ytd': {'a': 14996}}, {'results': [126], 'balances': [['a', 84870], ['b', 5004]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1013], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48953], ['b', 1020]]}], ['fees do not use cap', {'fee_bp': 504, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [504, 504], 'balances': [['a', 68992], ['c', 20000]]}]], [['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2004]], 'sent_ytd': {}}, {'results': [51], 'balances': [['a', 2945], ['b', 2104]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1005]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1009], ['b', 1005]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14995}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5005]], 'sent_ytd': {'a': 14995}}, {'results': [126], 'balances': [['a', 84869], ['b', 5005]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1016], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48950], ['b', 1023]]}], ['fees do not use cap', {'fee_bp': 505, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [505, 505], 'balances': [['a', 68990], ['c', 20000]]}]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    bal = dict(x['members'])
    sent = dict(x['sent_ytd'])
    out = []
    for f, t, p in x['transfers']:
        if f == t or f not in bal or t not in bal:
            out.append('invalid')
            continue
        if p < x['min_transfer']:
            out.append('below minimum')
            continue
        if sent.get(f, 0) + p > x['annual_cap']:
            out.append('cap')
            continue
        fee = (p * x['fee_bp'] + 5000) // 10000
        if bal[f] < p + fee:
            out.append('insufficient')
            continue
        bal[f] -= p + fee
        bal[t] += p
        sent[f] = sent.get(f, 0) + p
        out.append(fee)
    return {'results': out, 'balances': [[k, bal[k]] for k in sorted(bal)]}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2000]], 'sent_ytd': {}}, {'results': [50], 'balances': [['a', 2950], ['b', 2100]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1001]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1013], ['b', 1001]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14999}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5001]], 'sent_ytd': {'a': 14999}}, {'results': [126], 'balances': [['a', 84873], ['b', 5001]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1004], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48962], ['b', 1011]]}], ['fees do not use cap', {'fee_bp': 501, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [501, 501], 'balances': [['a', 68998], ['c', 20000]]}]], [['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2001]], 'sent_ytd': {}}, {'results': [51], 'balances': [['a', 2948], ['b', 2101]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1002]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1012], ['b', 1002]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14998}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5002]], 'sent_ytd': {'a': 14998}}, {'results': [126], 'balances': [['a', 84872], ['b', 5002]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1007], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48959], ['b', 1014]]}], ['fees do not use cap', {'fee_bp': 502, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [502, 502], 'balances': [['a', 68996], ['c', 20000]]}]], [['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2002]], 'sent_ytd': {}}, {'results': [51], 'balances': [['a', 2947], ['b', 2102]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1003]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1011], ['b', 1003]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14997}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5003]], 'sent_ytd': {'a': 14997}}, {'results': [126], 'balances': [['a', 84871], ['b', 5003]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1010], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48956], ['b', 1017]]}], ['fees do not use cap', {'fee_bp': 503, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [503, 503], 'balances': [['a', 68994], ['c', 20000]]}]], [['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2003]], 'sent_ytd': {}}, {'results': [51], 'balances': [['a', 2946], ['b', 2103]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1004]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1010], ['b', 1004]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14996}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5004]], 'sent_ytd': {'a': 14996}}, {'results': [126], 'balances': [['a', 84870], ['b', 5004]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1013], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48953], ['b', 1020]]}], ['fees do not use cap', {'fee_bp': 504, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [504, 504], 'balances': [['a', 68992], ['c', 20000]]}]], [['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2004]], 'sent_ytd': {}}, {'results': [51], 'balances': [['a', 2945], ['b', 2104]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1005]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1009], ['b', 1005]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14995}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5005]], 'sent_ytd': {'a': 14995}}, {'results': [126], 'balances': [['a', 84869], ['b', 5005]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1016], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48950], ['b', 1023]]}], ['fees do not use cap', {'fee_bp': 505, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [505, 505], 'balances': [['a', 68990], ['c', 20000]]}]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Transfer fees come out a point short on amounts that do not divide evenly.

Input {members:{id:balance}, transfers:[[from,to,pts]], fee_bp, min_transfer, annual_cap, sent_ytd}. Self transfers or unknown members are "invalid"; pts below the minimum are "below minimum"; sent_ytd + pts above annual_cap is "cap" (fees do not count toward the cap). The fee is ceil(pts*fee_bp/10000) points charged to the sender, who must hold pts + fee ("insufficient" otherwise). The recipient receives pts. Return {results (fee or reason), balances:[[id,bal]] sorted}.

split: open-access


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

N = 1
observations = []
def solve(x):
    bal = dict(x['members'])
    sent = dict(x['sent_ytd'])
    out = []
    for f, t, p in x['transfers']:
        if f == t or f not in bal or t not in bal:
            out.append('invalid')
            continue
        if p < x['min_transfer']:
            out.append('below minimum')
            continue
        if sent.get(f, 0) + p > x['annual_cap']:
            out.append('cap')
            continue
        fee = (p * x['fee_bp'] + 9999) // 10000
        if bal[f] < p + fee:
            out.append('insufficient')
            continue
        bal[f] -= p
        bal[t] += p - fee
        sent[f] = sent.get(f, 0) + p
        out.append(fee)
    return {'results': out, 'balances': [[k, bal[k]] for k in sorted(bal)]}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2000]], 'sent_ytd': {}}, {'results': [50], 'balances': [['a', 2950], ['b', 2100]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1001]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1013], ['b', 1001]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14999}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5001]], 'sent_ytd': {'a': 14999}}, {'results': [126], 'balances': [['a', 84873], ['b', 5001]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1004], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48962], ['b', 1011]]}], ['fees do not use cap', {'fee_bp': 501, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [501, 501], 'balances': [['a', 68998], ['c', 20000]]}]], [['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2001]], 'sent_ytd': {}}, {'results': [51], 'balances': [['a', 2948], ['b', 2101]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1002]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1012], ['b', 1002]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14998}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5002]], 'sent_ytd': {'a': 14998}}, {'results': [126], 'balances': [['a', 84872], ['b', 5002]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1007], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48959], ['b', 1014]]}], ['fees do not use cap', {'fee_bp': 502, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [502, 502], 'balances': [['a', 68996], ['c', 20000]]}]], [['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2002]], 'sent_ytd': {}}, {'results': [51], 'balances': [['a', 2947], ['b', 2102]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1003]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1011], ['b', 1003]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14997}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5003]], 'sent_ytd': {'a': 14997}}, {'results': [126], 'balances': [['a', 84871], ['b', 5003]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1010], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48956], ['b', 1017]]}], ['fees do not use cap', {'fee_bp': 503, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [503, 503], 'balances': [['a', 68994], ['c', 20000]]}]], [['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2003]], 'sent_ytd': {}}, {'results': [51], 'balances': [['a', 2946], ['b', 2103]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1004]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1010], ['b', 1004]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14996}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5004]], 'sent_ytd': {'a': 14996}}, {'results': [126], 'balances': [['a', 84870], ['b', 5004]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1013], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48953], ['b', 1020]]}], ['fees do not use cap', {'fee_bp': 504, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [504, 504], 'balances': [['a', 68992], ['c', 20000]]}]], [['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2004]], 'sent_ytd': {}}, {'results': [51], 'balances': [['a', 2945], ['b', 2104]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1005]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1009], ['b', 1005]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14995}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5005]], 'sent_ytd': {'a': 14995}}, {'results': [126], 'balances': [['a', 84869], ['b', 5005]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1016], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48950], ['b', 1023]]}], ['fees do not use cap', {'fee_bp': 505, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [505, 505], 'balances': [['a', 68990], ['c', 20000]]}]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

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

N = 1
observations = []
def solve(x):
    bal = dict(x['members'])
    sent = dict(x['sent_ytd'])
    out = []
    for f, t, p in x['transfers']:
        if f == t or f not in bal or t not in bal:
            out.append('invalid')
            continue
        if p < x['min_transfer']:
            out.append('below minimum')
            continue
        if sent.get(f, 0) + p > x['annual_cap']:
            out.append('cap')
            continue
        fee = (p * x['fee_bp'] + 9999) // 10000
        if bal[f] < p + fee:
            out.append('insufficient')
            continue
        bal[f] -= p + fee
        bal[t] += p - fee
        sent[f] = sent.get(f, 0) + p
        out.append(fee)
    return {'results': out, 'balances': [[k, bal[k]] for k in sorted(bal)]}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2000]], 'sent_ytd': {}}, {'results': [50], 'balances': [['a', 2950], ['b', 2100]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1001]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1013], ['b', 1001]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14999}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5001]], 'sent_ytd': {'a': 14999}}, {'results': [126], 'balances': [['a', 84873], ['b', 5001]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1004], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48962], ['b', 1011]]}], ['fees do not use cap', {'fee_bp': 501, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [501, 501], 'balances': [['a', 68998], ['c', 20000]]}]], [['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2001]], 'sent_ytd': {}}, {'results': [51], 'balances': [['a', 2948], ['b', 2101]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1002]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1012], ['b', 1002]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14998}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5002]], 'sent_ytd': {'a': 14998}}, {'results': [126], 'balances': [['a', 84872], ['b', 5002]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1007], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48959], ['b', 1014]]}], ['fees do not use cap', {'fee_bp': 502, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [502, 502], 'balances': [['a', 68996], ['c', 20000]]}]], [['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2002]], 'sent_ytd': {}}, {'results': [51], 'balances': [['a', 2947], ['b', 2102]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1003]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1011], ['b', 1003]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14997}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5003]], 'sent_ytd': {'a': 14997}}, {'results': [126], 'balances': [['a', 84871], ['b', 5003]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1010], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48956], ['b', 1017]]}], ['fees do not use cap', {'fee_bp': 503, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [503, 503], 'balances': [['a', 68994], ['c', 20000]]}]], [['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2003]], 'sent_ytd': {}}, {'results': [51], 'balances': [['a', 2946], ['b', 2103]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1004]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1010], ['b', 1004]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14996}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5004]], 'sent_ytd': {'a': 14996}}, {'results': [126], 'balances': [['a', 84870], ['b', 5004]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1013], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48953], ['b', 1020]]}], ['fees do not use cap', {'fee_bp': 504, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [504, 504], 'balances': [['a', 68992], ['c', 20000]]}]], [['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2004]], 'sent_ytd': {}}, {'results': [51], 'balances': [['a', 2945], ['b', 2104]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1005]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1009], ['b', 1005]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14995}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5005]], 'sent_ytd': {'a': 14995}}, {'results': [126], 'balances': [['a', 84869], ['b', 5005]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1016], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48950], ['b', 1023]]}], ['fees do not use cap', {'fee_bp': 505, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [505, 505], 'balances': [['a', 68990], ['c', 20000]]}]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The recipient receives fewer points than were sent while the sender pays only the principal.

Input {members:{id:balance}, transfers:[[from,to,pts]], fee_bp, min_transfer, annual_cap, sent_ytd}. Self transfers or unknown members are "invalid"; pts below the minimum are "below minimum"; sent_ytd + pts above annual_cap is "cap" (fees do not count toward the cap). The fee is ceil(pts*fee_bp/10000) points charged to the sender, who must hold pts + fee ("insufficient" otherwise). The recipient receives pts. Return {results (fee or reason), balances:[[id,bal]] sorted}.

split: open-access


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

N = 1
observations = []
def solve(x):
    bal = dict(x['members'])
    sent = dict(x['sent_ytd'])
    out = []
    for f, t, p in x['transfers']:
        if f == t or f not in bal or t not in bal:
            out.append('invalid')
            continue
        if p < x['min_transfer']:
            out.append('below minimum')
            continue
        if sent.get(f, 0) + p > x['annual_cap']:
            out.append('cap')
            continue
        fee = (p * x['fee_bp'] + 9999) // 10000
        if bal[f] < p:
            out.append('insufficient')
            continue
        bal[f] -= p + fee
        bal[t] += p
        sent[f] = sent.get(f, 0) + p
        out.append(fee)
    return {'results': out, 'balances': [[k, bal[k]] for k in sorted(bal)]}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2000]], 'sent_ytd': {}}, {'results': [50], 'balances': [['a', 2950], ['b', 2100]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1001]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1013], ['b', 1001]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14999}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5001]], 'sent_ytd': {'a': 14999}}, {'results': [126], 'balances': [['a', 84873], ['b', 5001]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1004], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48962], ['b', 1011]]}], ['fees do not use cap', {'fee_bp': 501, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [501, 501], 'balances': [['a', 68998], ['c', 20000]]}]], [['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2001]], 'sent_ytd': {}}, {'results': [51], 'balances': [['a', 2948], ['b', 2101]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1002]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1012], ['b', 1002]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14998}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5002]], 'sent_ytd': {'a': 14998}}, {'results': [126], 'balances': [['a', 84872], ['b', 5002]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1007], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48959], ['b', 1014]]}], ['fees do not use cap', {'fee_bp': 502, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [502, 502], 'balances': [['a', 68996], ['c', 20000]]}]], [['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2002]], 'sent_ytd': {}}, {'results': [51], 'balances': [['a', 2947], ['b', 2102]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1003]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1011], ['b', 1003]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14997}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5003]], 'sent_ytd': {'a': 14997}}, {'results': [126], 'balances': [['a', 84871], ['b', 5003]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1010], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48956], ['b', 1017]]}], ['fees do not use cap', {'fee_bp': 503, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [503, 503], 'balances': [['a', 68994], ['c', 20000]]}]], [['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2003]], 'sent_ytd': {}}, {'results': [51], 'balances': [['a', 2946], ['b', 2103]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1004]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1010], ['b', 1004]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14996}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5004]], 'sent_ytd': {'a': 14996}}, {'results': [126], 'balances': [['a', 84870], ['b', 5004]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1013], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48953], ['b', 1020]]}], ['fees do not use cap', {'fee_bp': 504, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [504, 504], 'balances': [['a', 68992], ['c', 20000]]}]], [['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2004]], 'sent_ytd': {}}, {'results': [51], 'balances': [['a', 2945], ['b', 2104]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1005]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1009], ['b', 1005]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14995}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5005]], 'sent_ytd': {'a': 14995}}, {'results': [126], 'balances': [['a', 84869], ['b', 5005]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1016], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48950], ['b', 1023]]}], ['fees do not use cap', {'fee_bp': 505, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [505, 505], 'balances': [['a', 68990], ['c', 20000]]}]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    bal = dict(x['members'])
    sent = dict(x['sent_ytd'])
    out = []
    for f, t, p in x['transfers']:
        if f == t or f not in bal or t not in bal:
            out.append('invalid')
            continue
        if p < x['min_transfer']:
            out.append('below minimum')
            continue
        if sent.get(f, 0) + p > x['annual_cap']:
            out.append('cap')
            continue
        fee = (p * x['fee_bp'] + 9999) // 10000
        if bal[f] < p + x['fee_bp'] // 100:
            out.append('insufficient')
            continue
        bal[f] -= p + fee
        bal[t] += p
        sent[f] = sent.get(f, 0) + p
        out.append(fee)
    return {'results': out, 'balances': [[k, bal[k]] for k in sorted(bal)]}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2000]], 'sent_ytd': {}}, {'results': [50], 'balances': [['a', 2950], ['b', 2100]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1001]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1013], ['b', 1001]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14999}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5001]], 'sent_ytd': {'a': 14999}}, {'results': [126], 'balances': [['a', 84873], ['b', 5001]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1004], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48962], ['b', 1011]]}], ['fees do not use cap', {'fee_bp': 501, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [501, 501], 'balances': [['a', 68998], ['c', 20000]]}]], [['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2001]], 'sent_ytd': {}}, {'results': [51], 'balances': [['a', 2948], ['b', 2101]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1002]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1012], ['b', 1002]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14998}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5002]], 'sent_ytd': {'a': 14998}}, {'results': [126], 'balances': [['a', 84872], ['b', 5002]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1007], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48959], ['b', 1014]]}], ['fees do not use cap', {'fee_bp': 502, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [502, 502], 'balances': [['a', 68996], ['c', 20000]]}]], [['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2002]], 'sent_ytd': {}}, {'results': [51], 'balances': [['a', 2947], ['b', 2102]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1003]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1011], ['b', 1003]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14997}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5003]], 'sent_ytd': {'a': 14997}}, {'results': [126], 'balances': [['a', 84871], ['b', 5003]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1010], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48956], ['b', 1017]]}], ['fees do not use cap', {'fee_bp': 503, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [503, 503], 'balances': [['a', 68994], ['c', 20000]]}]], [['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2003]], 'sent_ytd': {}}, {'results': [51], 'balances': [['a', 2946], ['b', 2103]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1004]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1010], ['b', 1004]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14996}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5004]], 'sent_ytd': {'a': 14996}}, {'results': [126], 'balances': [['a', 84870], ['b', 5004]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1013], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48953], ['b', 1020]]}], ['fees do not use cap', {'fee_bp': 504, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [504, 504], 'balances': [['a', 68992], ['c', 20000]]}]], [['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2004]], 'sent_ytd': {}}, {'results': [51], 'balances': [['a', 2945], ['b', 2104]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1005]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1009], ['b', 1005]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14995}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5005]], 'sent_ytd': {'a': 14995}}, {'results': [126], 'balances': [['a', 84869], ['b', 5005]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1016], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48950], ['b', 1023]]}], ['fees do not use cap', {'fee_bp': 505, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [505, 505], 'balances': [['a', 68990], ['c', 20000]]}]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Senders end with negative balances after transferring their whole balance.

Input {members:{id:balance}, transfers:[[from,to,pts]], fee_bp, min_transfer, annual_cap, sent_ytd}. Self transfers or unknown members are "invalid"; pts below the minimum are "below minimum"; sent_ytd + pts above annual_cap is "cap" (fees do not count toward the cap). The fee is ceil(pts*fee_bp/10000) points charged to the sender, who must hold pts + fee ("insufficient" otherwise). The recipient receives pts. Return {results (fee or reason), balances:[[id,bal]] sorted}.

split: open-access


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

N = 1
observations = []
def solve(x):
    bal = dict(x['members'])
    sent = dict(x['sent_ytd'])
    out = []
    for f, t, p in x['transfers']:
        if f == t or f not in bal or t not in bal:
            out.append('invalid')
            continue
        if p < x['min_transfer']:
            out.append('below minimum')
            continue
        if sent.get(f, 0) + p > x['annual_cap']:
            out.append('cap')
            continue
        fee = (p * x['fee_bp'] + 9999) // 10000
        if bal[f] < p + fee:
            out.append('insufficient')
            continue
        bal[f] -= p + fee
        bal[t] += p
        sent[f] = sent.get(f, 0) + p + fee
        out.append(fee)
    return {'results': out, 'balances': [[k, bal[k]] for k in sorted(bal)]}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2000]], 'sent_ytd': {}}, {'results': [50], 'balances': [['a', 2950], ['b', 2100]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1001]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1013], ['b', 1001]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14999}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5001]], 'sent_ytd': {'a': 14999}}, {'results': [126], 'balances': [['a', 84873], ['b', 5001]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1004], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48962], ['b', 1011]]}], ['fees do not use cap', {'fee_bp': 501, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [501, 501], 'balances': [['a', 68998], ['c', 20000]]}]], [['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2001]], 'sent_ytd': {}}, {'results': [51], 'balances': [['a', 2948], ['b', 2101]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1002]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1012], ['b', 1002]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14998}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5002]], 'sent_ytd': {'a': 14998}}, {'results': [126], 'balances': [['a', 84872], ['b', 5002]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1007], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48959], ['b', 1014]]}], ['fees do not use cap', {'fee_bp': 502, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [502, 502], 'balances': [['a', 68996], ['c', 20000]]}]], [['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2002]], 'sent_ytd': {}}, {'results': [51], 'balances': [['a', 2947], ['b', 2102]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1003]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1011], ['b', 1003]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14997}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5003]], 'sent_ytd': {'a': 14997}}, {'results': [126], 'balances': [['a', 84871], ['b', 5003]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1010], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48956], ['b', 1017]]}], ['fees do not use cap', {'fee_bp': 503, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [503, 503], 'balances': [['a', 68994], ['c', 20000]]}]], [['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2003]], 'sent_ytd': {}}, {'results': [51], 'balances': [['a', 2946], ['b', 2103]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1004]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1010], ['b', 1004]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14996}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5004]], 'sent_ytd': {'a': 14996}}, {'results': [126], 'balances': [['a', 84870], ['b', 5004]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1013], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48953], ['b', 1020]]}], ['fees do not use cap', {'fee_bp': 504, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [504, 504], 'balances': [['a', 68992], ['c', 20000]]}]], [['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2004]], 'sent_ytd': {}}, {'results': [51], 'balances': [['a', 2945], ['b', 2104]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1005]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1009], ['b', 1005]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14995}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5005]], 'sent_ytd': {'a': 14995}}, {'results': [126], 'balances': [['a', 84869], ['b', 5005]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1016], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48950], ['b', 1023]]}], ['fees do not use cap', {'fee_bp': 505, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [505, 505], 'balances': [['a', 68990], ['c', 20000]]}]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    bal = dict(x['members'])
    sent = dict(x['sent_ytd'])
    out = []
    for f, t, p in x['transfers']:
        if f == t or f not in bal or t not in bal:
            out.append('invalid')
            continue
        if p < x['min_transfer']:
            out.append('below minimum')
            continue
        if sent.get(f, 0) + p + (p * x['fee_bp'] + 9999) // 10000 > x['annual_cap']:
            out.append('cap')
            continue
        fee = (p * x['fee_bp'] + 9999) // 10000
        if bal[f] < p + fee:
            out.append('insufficient')
            continue
        bal[f] -= p + fee
        bal[t] += p
        sent[f] = sent.get(f, 0) + p
        out.append(fee)
    return {'results': out, 'balances': [[k, bal[k]] for k in sorted(bal)]}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2000]], 'sent_ytd': {}}, {'results': [50], 'balances': [['a', 2950], ['b', 2100]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1001]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1013], ['b', 1001]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14999}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5001]], 'sent_ytd': {'a': 14999}}, {'results': [126], 'balances': [['a', 84873], ['b', 5001]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1004], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48962], ['b', 1011]]}], ['fees do not use cap', {'fee_bp': 501, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [501, 501], 'balances': [['a', 68998], ['c', 20000]]}]], [['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2001]], 'sent_ytd': {}}, {'results': [51], 'balances': [['a', 2948], ['b', 2101]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1002]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1012], ['b', 1002]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14998}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5002]], 'sent_ytd': {'a': 14998}}, {'results': [126], 'balances': [['a', 84872], ['b', 5002]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1007], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48959], ['b', 1014]]}], ['fees do not use cap', {'fee_bp': 502, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [502, 502], 'balances': [['a', 68996], ['c', 20000]]}]], [['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2002]], 'sent_ytd': {}}, {'results': [51], 'balances': [['a', 2947], ['b', 2102]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1003]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1011], ['b', 1003]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14997}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5003]], 'sent_ytd': {'a': 14997}}, {'results': [126], 'balances': [['a', 84871], ['b', 5003]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1010], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48956], ['b', 1017]]}], ['fees do not use cap', {'fee_bp': 503, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [503, 503], 'balances': [['a', 68994], ['c', 20000]]}]], [['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2003]], 'sent_ytd': {}}, {'results': [51], 'balances': [['a', 2946], ['b', 2103]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1004]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1010], ['b', 1004]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14996}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5004]], 'sent_ytd': {'a': 14996}}, {'results': [126], 'balances': [['a', 84870], ['b', 5004]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1013], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48953], ['b', 1020]]}], ['fees do not use cap', {'fee_bp': 504, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [504, 504], 'balances': [['a', 68992], ['c', 20000]]}]], [['normal transfer', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 100}, 'transfers': [['a', 'b', 2004]], 'sent_ytd': {}}, {'results': [51], 'balances': [['a', 2945], ['b', 2104]]}], ['fee needs balance', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 2040, 'b': 0}, 'transfers': [['a', 'b', 2000], ['a', 'b', 1005]], 'sent_ytd': {}}, {'results': ['insufficient', 26], 'balances': [['a', 1009], ['b', 1005]]}], ['cap edge', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5000]], 'sent_ytd': {'a': 14995}}, {'results': [125], 'balances': [['a', 84875], ['b', 5000]]}], ['cap exact', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'b': 0}, 'transfers': [['a', 'b', 5005]], 'sent_ytd': {'a': 14995}}, {'results': [126], 'balances': [['a', 84869], ['b', 5005]]}], ['invalid parties', {'fee_bp': 250, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 5000, 'b': 0}, 'transfers': [['a', 'a', 1000], ['a', 'z', 1000], ['a', 'b', 999]], 'sent_ytd': {}}, {'results': ['invalid', 'invalid', 'below minimum'], 'balances': [['a', 5000], ['b', 0]]}], ['fee rounding', {'fee_bp': 333, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 50000, 'b': 7}, 'transfers': [['a', 'b', 1016], ['b', 'a', 1000]], 'sent_ytd': {}}, {'results': [34, 'insufficient'], 'balances': [['a', 48950], ['b', 1023]]}], ['fees do not use cap', {'fee_bp': 505, 'min_transfer': 1000, 'annual_cap': 20000, 'members': {'a': 90000, 'c': 0}, 'transfers': [['a', 'c', 10000], ['a', 'c', 10000]], 'sent_ytd': {'a': 0}}, {'results': [505, 505], 'balances': [['a', 68990], ['c', 20000]]}]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Members hit the annual transfer cap early because fees are counted as transferred points.

Input {members:{id:balance}, transfers:[[from,to,pts]], fee_bp, min_transfer, annual_cap, sent_ytd}. Self transfers or unknown members are "invalid"; pts below the minimum are "below minimum"; sent_ytd + pts above annual_cap is "cap" (fees do not count toward the cap). The fee is ceil(pts*fee_bp/10000) points charged to the sender, who must hold pts + fee ("insufficient" otherwise). The recipient receives pts. Return {results (fee or reason), balances:[[id,bal]] sorted}.

split: open-access