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

N = 1
observations = []
def solve(x):
    tag = plate = 0
    periods = set()
    for day, base, method in x['trips']:
        if method == 'exempt':
            continue
        if method == 'tag':
            tag += base * (100 - x['tag_discount_pct']) // 100
        else:
            plate += base + -(-base * x['plate_surcharge_pct'] // 100)
            periods.add(day // x['cycle_days'])
    fees = len(periods) * x['invoice_fee']
    return {'tag': tag, 'plate': plate + fees, 'invoices': len(periods)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'trips': [[91, 175, 'tag'], [42, 250, 'tag'], [44, 333, 'exempt']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 10, 'invoice_fee': 150, 'cycle_days': 30}, {'tag': 383, 'plate': 0, 'invoices': 0}), ({'trips': [[3, 410, 'exempt'], [4, 410, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 369, 'plate': 0, 'invoices': 0}), ({'trips': [[76, 333, 'plate'], [50, 525, 'exempt']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 5, 'invoice_fee': 150, 'cycle_days': 31}, {'tag': 0, 'plate': 650, 'invoices': 1}), ({'trips': [[26, 333, 'tag'], [88, 175, 'tag'], [11, 525, 'exempt'], [80, 175, 'tag'], [18, 175, 'plate'], [51, 333, 'plate']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 15, 'invoice_fee': 400, 'cycle_days': 30}, {'tag': 582, 'plate': 1436, 'invoices': 2}), ({'trips': [[29, 250, 'plate'], [30, 250, 'plate'], [5, 333, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 284, 'plate': 1076, 'invoices': 2}), ({'trips': [[40, 250, 'plate']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 5, 'invoice_fee': 150, 'cycle_days': 30}, {'tag': 0, 'plate': 488, 'invoices': 1}), ({'trips': [[63, 525, 'plate']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 10, 'invoice_fee': 400, 'cycle_days': 31}, {'tag': 0, 'plate': 1109, 'invoices': 1}), ({'trips': [[61, 333, 'tag']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 15, 'invoice_fee': 150, 'cycle_days': 30}, {'tag': 284, 'plate': 0, 'invoices': 0})], [({'trips': [[3, 410, 'exempt'], [4, 410, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 369, 'plate': 0, 'invoices': 0}), ({'trips': [[27, 250, 'tag'], [39, 410, 'plate'], [68, 525, 'tag'], [60, 525, 'plate'], [21, 175, 'tag'], [32, 250, 'exempt'], [67, 410, 'exempt'], [95, 410, 'exempt']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 5, 'invoice_fee': 200, 'cycle_days': 31}, {'tag': 904, 'plate': 1370, 'invoices': 1}), ({'trips': [[29, 250, 'plate'], [30, 250, 'plate'], [5, 333, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 284, 'plate': 1076, 'invoices': 2}), ({'trips': [[91, 333, 'exempt'], [12, 525, 'tag'], [73, 175, 'plate']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 5, 'invoice_fee': 400, 'cycle_days': 31}, {'tag': 499, 'plate': 619, 'invoices': 1}), ({'trips': [[54, 525, 'plate']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 10, 'invoice_fee': 400, 'cycle_days': 31}, {'tag': 0, 'plate': 1109, 'invoices': 1}), ({'trips': [[48, 410, 'plate'], [33, 175, 'exempt'], [49, 175, 'plate']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 10, 'invoice_fee': 150, 'cycle_days': 31}, {'tag': 0, 'plate': 882, 'invoices': 1}), ({'trips': [[1, 333, 'plate'], [37, 250, 'plate'], [50, 175, 'plate']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 31}, {'tag': 0, 'plate': 1425, 'invoices': 2}), ({'trips': [[21, 525, 'tag'], [11, 525, 'tag'], [62, 410, 'exempt']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 10, 'invoice_fee': 400, 'cycle_days': 30}, {'tag': 946, 'plate': 0, 'invoices': 0})], [({'trips': [[10, 410, 'plate'], [15, 250, 'exempt'], [21, 525, 'plate'], [36, 250, 'plate'], [56, 175, 'plate'], [35, 250, 'tag'], [94, 525, 'plate']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 10, 'invoice_fee': 150, 'cycle_days': 31}, {'tag': 225, 'plate': 2809, 'invoices': 3}), ({'trips': [[25, 175, 'exempt'], [7, 175, 'exempt'], [95, 410, 'plate'], [12, 250, 'exempt'], [95, 175, 'plate']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 0, 'plate': 932, 'invoices': 1}), ({'trips': [[3, 410, 'exempt'], [4, 410, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 369, 'plate': 0, 'invoices': 0}), ({'trips': [[54, 410, 'tag'], [50, 250, 'plate'], [25, 333, 'tag'], [46, 333, 'plate'], [39, 333, 'plate'], [41, 175, 'plate'], [49, 175, 'plate']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 15, 'invoice_fee': 400, 'cycle_days': 31}, {'tag': 633, 'plate': 1985, 'invoices': 1}), ({'trips': [[29, 250, 'plate'], [30, 250, 'plate'], [5, 333, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 284, 'plate': 1076, 'invoices': 2}), ({'trips': [[81, 250, 'tag'], [14, 250, 'plate'], [37, 333, 'tag']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 10, 'invoice_fee': 400, 'cycle_days': 30}, {'tag': 525, 'plate': 713, 'invoices': 1}), ({'trips': [[31, 525, 'plate']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 0, 'plate': 909, 'invoices': 1}), ({'trips': [[46, 333, 'exempt'], [24, 250, 'tag'], [31, 175, 'plate'], [4, 250, 'exempt'], [28, 333, 'exempt'], [14, 250, 'tag'], [79, 410, 'plate'], [1, 525, 'plate']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 150, 'cycle_days': 31}, {'tag': 426, 'plate': 1950, 'invoices': 3})], [({'trips': [[20, 410, 'plate'], [72, 525, 'plate'], [58, 525, 'plate'], [6, 250, 'exempt']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 5, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 0, 'plate': 2791, 'invoices': 3}), ({'trips': [[74, 250, 'plate'], [2, 250, 'plate'], [8, 525, 'plate'], [44, 175, 'tag'], [92, 250, 'plate'], [31, 175, 'plate'], [50, 333, 'plate'], [74, 250, 'tag']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 15, 'invoice_fee': 400, 'cycle_days': 30}, {'tag': 362, 'plate': 3832, 'invoices': 4}), ({'trips': [[78, 250, 'tag'], [20, 250, 'plate'], [57, 175, 'exempt']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 400, 'cycle_days': 30}, {'tag': 225, 'plate': 775, 'invoices': 1}), ({'trips': [[15, 250, 'tag'], [8, 410, 'tag']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 5, 'invoice_fee': 150, 'cycle_days': 30}, {'tag': 628, 'plate': 0, 'invoices': 0}), ({'trips': [[29, 250, 'plate'], [30, 250, 'plate'], [5, 333, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 284, 'plate': 1076, 'invoices': 2}), ({'trips': [[8, 333, 'plate']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 31}, {'tag': 0, 'plate': 617, 'invoices': 1}), ({'trips': [[46, 410, 'exempt'], [86, 525, 'plate'], [35, 250, 'tag'], [77, 333, 'tag'], [63, 250, 'plate'], [34, 250, 'exempt'], [50, 525, 'plate']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 5, 'invoice_fee': 200, 'cycle_days': 31}, {'tag': 555, 'plate': 2351, 'invoices': 2}), ({'trips': [[3, 410, 'exempt'], [4, 410, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 369, 'plate': 0, 'invoices': 0})], [({'trips': [[22, 175, 'plate'], [60, 250, 'plate'], [21, 333, 'tag'], [66, 333, 'plate'], [60, 525, 'plate'], [14, 250, 'tag']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 5, 'invoice_fee': 400, 'cycle_days': 30}, {'tag': 555, 'plate': 2406, 'invoices': 2}), ({'trips': [[3, 410, 'exempt'], [4, 410, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 369, 'plate': 0, 'invoices': 0}), ({'trips': [[68, 410, 'tag'], [4, 410, 'plate'], [20, 250, 'plate'], [32, 525, 'exempt'], [72, 250, 'plate'], [75, 250, 'plate'], [93, 525, 'plate'], [84, 250, 'exempt']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 369, 'plate': 3128, 'invoices': 3}), ({'trips': [[18, 250, 'plate'], [23, 175, 'tag']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 5, 'invoice_fee': 400, 'cycle_days': 30}, {'tag': 167, 'plate': 713, 'invoices': 1}), ({'trips': [[27, 333, 'plate'], [18, 250, 'plate']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 0, 'plate': 1075, 'invoices': 1}), ({'trips': [[51, 250, 'plate'], [31, 333, 'plate']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 150, 'cycle_days': 30}, {'tag': 0, 'plate': 938, 'invoices': 1}), ({'trips': [[29, 250, 'plate'], [30, 250, 'plate'], [5, 333, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 284, 'plate': 1076, 'invoices': 2}), ({'trips': [[3, 410, 'exempt'], [13, 250, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 150, 'cycle_days': 31}, {'tag': 213, 'plate': 0, 'invoices': 0})]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('fee oracle' + ' %d' % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    tag = plate = 0
    periods = set()
    for day, base, method in x['trips']:
        if method == 'exempt':
            continue
        if method == 'tag':
            tag += base - -(-base * x['tag_discount_pct'] // 100)
        else:
            plate += base + -(-base * x['plate_surcharge_pct'] // 100)
            periods.add(day // x['cycle_days'])
    fees = len(periods) * x['invoice_fee']
    return {'tag': tag, 'plate': plate + fees, 'invoices': len(periods)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'trips': [[91, 175, 'tag'], [42, 250, 'tag'], [44, 333, 'exempt']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 10, 'invoice_fee': 150, 'cycle_days': 30}, {'tag': 383, 'plate': 0, 'invoices': 0}), ({'trips': [[3, 410, 'exempt'], [4, 410, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 369, 'plate': 0, 'invoices': 0}), ({'trips': [[76, 333, 'plate'], [50, 525, 'exempt']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 5, 'invoice_fee': 150, 'cycle_days': 31}, {'tag': 0, 'plate': 650, 'invoices': 1}), ({'trips': [[26, 333, 'tag'], [88, 175, 'tag'], [11, 525, 'exempt'], [80, 175, 'tag'], [18, 175, 'plate'], [51, 333, 'plate']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 15, 'invoice_fee': 400, 'cycle_days': 30}, {'tag': 582, 'plate': 1436, 'invoices': 2}), ({'trips': [[29, 250, 'plate'], [30, 250, 'plate'], [5, 333, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 284, 'plate': 1076, 'invoices': 2}), ({'trips': [[40, 250, 'plate']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 5, 'invoice_fee': 150, 'cycle_days': 30}, {'tag': 0, 'plate': 488, 'invoices': 1}), ({'trips': [[63, 525, 'plate']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 10, 'invoice_fee': 400, 'cycle_days': 31}, {'tag': 0, 'plate': 1109, 'invoices': 1}), ({'trips': [[61, 333, 'tag']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 15, 'invoice_fee': 150, 'cycle_days': 30}, {'tag': 284, 'plate': 0, 'invoices': 0})], [({'trips': [[3, 410, 'exempt'], [4, 410, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 369, 'plate': 0, 'invoices': 0}), ({'trips': [[27, 250, 'tag'], [39, 410, 'plate'], [68, 525, 'tag'], [60, 525, 'plate'], [21, 175, 'tag'], [32, 250, 'exempt'], [67, 410, 'exempt'], [95, 410, 'exempt']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 5, 'invoice_fee': 200, 'cycle_days': 31}, {'tag': 904, 'plate': 1370, 'invoices': 1}), ({'trips': [[29, 250, 'plate'], [30, 250, 'plate'], [5, 333, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 284, 'plate': 1076, 'invoices': 2}), ({'trips': [[91, 333, 'exempt'], [12, 525, 'tag'], [73, 175, 'plate']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 5, 'invoice_fee': 400, 'cycle_days': 31}, {'tag': 499, 'plate': 619, 'invoices': 1}), ({'trips': [[54, 525, 'plate']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 10, 'invoice_fee': 400, 'cycle_days': 31}, {'tag': 0, 'plate': 1109, 'invoices': 1}), ({'trips': [[48, 410, 'plate'], [33, 175, 'exempt'], [49, 175, 'plate']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 10, 'invoice_fee': 150, 'cycle_days': 31}, {'tag': 0, 'plate': 882, 'invoices': 1}), ({'trips': [[1, 333, 'plate'], [37, 250, 'plate'], [50, 175, 'plate']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 31}, {'tag': 0, 'plate': 1425, 'invoices': 2}), ({'trips': [[21, 525, 'tag'], [11, 525, 'tag'], [62, 410, 'exempt']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 10, 'invoice_fee': 400, 'cycle_days': 30}, {'tag': 946, 'plate': 0, 'invoices': 0})], [({'trips': [[10, 410, 'plate'], [15, 250, 'exempt'], [21, 525, 'plate'], [36, 250, 'plate'], [56, 175, 'plate'], [35, 250, 'tag'], [94, 525, 'plate']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 10, 'invoice_fee': 150, 'cycle_days': 31}, {'tag': 225, 'plate': 2809, 'invoices': 3}), ({'trips': [[25, 175, 'exempt'], [7, 175, 'exempt'], [95, 410, 'plate'], [12, 250, 'exempt'], [95, 175, 'plate']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 0, 'plate': 932, 'invoices': 1}), ({'trips': [[3, 410, 'exempt'], [4, 410, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 369, 'plate': 0, 'invoices': 0}), ({'trips': [[54, 410, 'tag'], [50, 250, 'plate'], [25, 333, 'tag'], [46, 333, 'plate'], [39, 333, 'plate'], [41, 175, 'plate'], [49, 175, 'plate']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 15, 'invoice_fee': 400, 'cycle_days': 31}, {'tag': 633, 'plate': 1985, 'invoices': 1}), ({'trips': [[29, 250, 'plate'], [30, 250, 'plate'], [5, 333, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 284, 'plate': 1076, 'invoices': 2}), ({'trips': [[81, 250, 'tag'], [14, 250, 'plate'], [37, 333, 'tag']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 10, 'invoice_fee': 400, 'cycle_days': 30}, {'tag': 525, 'plate': 713, 'invoices': 1}), ({'trips': [[31, 525, 'plate']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 0, 'plate': 909, 'invoices': 1}), ({'trips': [[46, 333, 'exempt'], [24, 250, 'tag'], [31, 175, 'plate'], [4, 250, 'exempt'], [28, 333, 'exempt'], [14, 250, 'tag'], [79, 410, 'plate'], [1, 525, 'plate']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 150, 'cycle_days': 31}, {'tag': 426, 'plate': 1950, 'invoices': 3})], [({'trips': [[20, 410, 'plate'], [72, 525, 'plate'], [58, 525, 'plate'], [6, 250, 'exempt']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 5, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 0, 'plate': 2791, 'invoices': 3}), ({'trips': [[74, 250, 'plate'], [2, 250, 'plate'], [8, 525, 'plate'], [44, 175, 'tag'], [92, 250, 'plate'], [31, 175, 'plate'], [50, 333, 'plate'], [74, 250, 'tag']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 15, 'invoice_fee': 400, 'cycle_days': 30}, {'tag': 362, 'plate': 3832, 'invoices': 4}), ({'trips': [[78, 250, 'tag'], [20, 250, 'plate'], [57, 175, 'exempt']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 400, 'cycle_days': 30}, {'tag': 225, 'plate': 775, 'invoices': 1}), ({'trips': [[15, 250, 'tag'], [8, 410, 'tag']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 5, 'invoice_fee': 150, 'cycle_days': 30}, {'tag': 628, 'plate': 0, 'invoices': 0}), ({'trips': [[29, 250, 'plate'], [30, 250, 'plate'], [5, 333, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 284, 'plate': 1076, 'invoices': 2}), ({'trips': [[8, 333, 'plate']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 31}, {'tag': 0, 'plate': 617, 'invoices': 1}), ({'trips': [[46, 410, 'exempt'], [86, 525, 'plate'], [35, 250, 'tag'], [77, 333, 'tag'], [63, 250, 'plate'], [34, 250, 'exempt'], [50, 525, 'plate']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 5, 'invoice_fee': 200, 'cycle_days': 31}, {'tag': 555, 'plate': 2351, 'invoices': 2}), ({'trips': [[3, 410, 'exempt'], [4, 410, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 369, 'plate': 0, 'invoices': 0})], [({'trips': [[22, 175, 'plate'], [60, 250, 'plate'], [21, 333, 'tag'], [66, 333, 'plate'], [60, 525, 'plate'], [14, 250, 'tag']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 5, 'invoice_fee': 400, 'cycle_days': 30}, {'tag': 555, 'plate': 2406, 'invoices': 2}), ({'trips': [[3, 410, 'exempt'], [4, 410, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 369, 'plate': 0, 'invoices': 0}), ({'trips': [[68, 410, 'tag'], [4, 410, 'plate'], [20, 250, 'plate'], [32, 525, 'exempt'], [72, 250, 'plate'], [75, 250, 'plate'], [93, 525, 'plate'], [84, 250, 'exempt']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 369, 'plate': 3128, 'invoices': 3}), ({'trips': [[18, 250, 'plate'], [23, 175, 'tag']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 5, 'invoice_fee': 400, 'cycle_days': 30}, {'tag': 167, 'plate': 713, 'invoices': 1}), ({'trips': [[27, 333, 'plate'], [18, 250, 'plate']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 0, 'plate': 1075, 'invoices': 1}), ({'trips': [[51, 250, 'plate'], [31, 333, 'plate']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 150, 'cycle_days': 30}, {'tag': 0, 'plate': 938, 'invoices': 1}), ({'trips': [[29, 250, 'plate'], [30, 250, 'plate'], [5, 333, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 284, 'plate': 1076, 'invoices': 2}), ({'trips': [[3, 410, 'exempt'], [13, 250, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 150, 'cycle_days': 31}, {'tag': 213, 'plate': 0, 'invoices': 0})]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('fee oracle' + ' %d' % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Pay-by-plate invoice and tag discount returns a wrong result when the discounted price is floored instead of the discount.

Input {trips: [[day (0-based), base cents, tag|plate|exempt]], plate_surcharge_pct, tag_discount_pct, invoice_fee, cycle_days}. Exempt trips are ignored. Tag trips pay base minus a discount floored to cents. Plate trips pay base plus a surcharge rounded up to cents and are grouped into invoices by billing period day // cycle_days; each invoice adds one invoice_fee to the plate total. Return {tag, plate, invoices}.

split: open-access


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

N = 1
observations = []
def solve(x):
    tag = plate = 0
    periods = set()
    for day, base, method in x['trips']:
        if method == 'exempt':
            continue
        if method == 'tag':
            tag += base - base * x['tag_discount_pct'] // 100
        else:
            plate += base + -(-base * x['plate_surcharge_pct'] // 100)
            periods.add(day // x['cycle_days'])
    fees = len(periods) * x['invoice_fee']
    return {'tag': tag, 'plate': plate, 'invoices': len(periods)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'trips': [[25, 175, 'exempt'], [34, 410, 'plate'], [15, 250, 'plate'], [87, 175, 'exempt'], [2, 175, 'tag'], [22, 250, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 5, 'invoice_fee': 200, 'cycle_days': 31}, {'tag': 405, 'plate': 1292, 'invoices': 2}), ({'trips': [[94, 250, 'exempt'], [10, 410, 'tag'], [27, 333, 'plate'], [90, 175, 'plate'], [20, 410, 'plate'], [82, 525, 'tag']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 31}, {'tag': 796, 'plate': 1549, 'invoices': 2}), ({'trips': [[93, 333, 'tag'], [94, 333, 'tag'], [77, 333, 'tag'], [35, 175, 'exempt'], [63, 333, 'exempt'], [46, 175, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 5, 'invoice_fee': 200, 'cycle_days': 31}, {'tag': 1118, 'plate': 0, 'invoices': 0}), ({'trips': [[14, 410, 'plate'], [57, 333, 'exempt'], [15, 175, 'plate']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 150, 'cycle_days': 31}, {'tag': 0, 'plate': 941, 'invoices': 1}), ({'trips': [[29, 250, 'plate'], [30, 250, 'plate'], [5, 333, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 284, 'plate': 1076, 'invoices': 2}), ({'trips': [[72, 175, 'plate'], [36, 333, 'tag'], [69, 525, 'tag'], [34, 525, 'tag'], [42, 525, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 15, 'invoice_fee': 400, 'cycle_days': 31}, {'tag': 1625, 'plate': 663, 'invoices': 1}), ({'trips': [[3, 410, 'exempt'], [4, 410, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 369, 'plate': 0, 'invoices': 0}), ({'trips': [[30, 175, 'tag'], [60, 525, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 596, 'plate': 0, 'invoices': 0})], [({'trips': [[67, 410, 'plate'], [33, 410, 'tag'], [41, 250, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 400, 'cycle_days': 31}, {'tag': 594, 'plate': 1015, 'invoices': 1}), ({'trips': [[60, 175, 'tag'], [33, 333, 'exempt'], [92, 410, 'plate'], [20, 333, 'tag'], [34, 525, 'tag'], [54, 250, 'tag'], [60, 525, 'exempt']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 5, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 1221, 'plate': 713, 'invoices': 1}), ({'trips': [[3, 525, 'tag'], [27, 525, 'tag'], [24, 333, 'exempt'], [25, 250, 'plate'], [17, 175, 'exempt'], [40, 175, 'plate'], [92, 410, 'exempt'], [0, 410, 'tag']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 1315, 'plate': 932, 'invoices': 2}), ({'trips': [[49, 410, 'exempt'], [6, 525, 'plate']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 15, 'invoice_fee': 400, 'cycle_days': 31}, {'tag': 0, 'plate': 1188, 'invoices': 1}), ({'trips': [[21, 410, 'plate'], [90, 250, 'plate'], [6, 250, 'tag'], [80, 525, 'tag']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 15, 'invoice_fee': 150, 'cycle_days': 30}, {'tag': 660, 'plate': 1126, 'invoices': 2}), ({'trips': [[3, 410, 'exempt'], [4, 410, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 369, 'plate': 0, 'invoices': 0}), ({'trips': [[69, 410, 'plate'], [79, 410, 'plate'], [50, 175, 'tag'], [1, 333, 'plate'], [78, 250, 'tag'], [95, 175, 'exempt'], [93, 175, 'tag'], [68, 175, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 5, 'invoice_fee': 200, 'cycle_days': 31}, {'tag': 739, 'plate': 2130, 'invoices': 2}), ({'trips': [[29, 250, 'plate'], [30, 250, 'plate'], [5, 333, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 284, 'plate': 1076, 'invoices': 2})], [({'trips': [[20, 333, 'tag'], [29, 175, 'plate'], [74, 410, 'plate'], [22, 250, 'plate'], [2, 525, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 5, 'invoice_fee': 150, 'cycle_days': 31}, {'tag': 816, 'plate': 1429, 'invoices': 2}), ({'trips': [[29, 250, 'plate'], [30, 250, 'plate'], [5, 333, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 284, 'plate': 1076, 'invoices': 2}), ({'trips': [[85, 175, 'tag'], [52, 410, 'plate']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 15, 'invoice_fee': 150, 'cycle_days': 31}, {'tag': 149, 'plate': 765, 'invoices': 1}), ({'trips': [[3, 410, 'exempt'], [4, 410, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 369, 'plate': 0, 'invoices': 0}), ({'trips': [[46, 250, 'plate'], [53, 175, 'exempt'], [25, 333, 'plate'], [61, 250, 'exempt'], [80, 333, 'exempt'], [54, 525, 'tag'], [88, 175, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 5, 'invoice_fee': 150, 'cycle_days': 31}, {'tag': 666, 'plate': 1088, 'invoices': 2}), ({'trips': [[40, 250, 'tag'], [88, 175, 'exempt'], [93, 410, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 5, 'invoice_fee': 150, 'cycle_days': 30}, {'tag': 628, 'plate': 0, 'invoices': 0}), ({'trips': [[2, 333, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 5, 'invoice_fee': 150, 'cycle_days': 30}, {'tag': 317, 'plate': 0, 'invoices': 0}), ({'trips': [[28, 333, 'exempt']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 10, 'invoice_fee': 400, 'cycle_days': 31}, {'tag': 0, 'plate': 0, 'invoices': 0})], [({'trips': [[3, 410, 'exempt'], [4, 410, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 369, 'plate': 0, 'invoices': 0}), ({'trips': [[29, 250, 'plate'], [30, 250, 'plate'], [5, 333, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 284, 'plate': 1076, 'invoices': 2}), ({'trips': [[50, 250, 'tag'], [32, 410, 'exempt'], [37, 525, 'plate'], [58, 333, 'plate'], [45, 250, 'plate'], [20, 525, 'exempt']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 5, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 238, 'plate': 1863, 'invoices': 1}), ({'trips': [[63, 525, 'plate'], [69, 250, 'exempt'], [43, 175, 'plate'], [45, 333, 'plate'], [25, 175, 'exempt'], [63, 333, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 300, 'plate': 1951, 'invoices': 2}), ({'trips': [[6, 333, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 5, 'invoice_fee': 150, 'cycle_days': 30}, {'tag': 317, 'plate': 0, 'invoices': 0}), ({'trips': [[42, 410, 'tag'], [26, 250, 'plate'], [17, 525, 'plate']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 369, 'plate': 1170, 'invoices': 1}), ({'trips': [[65, 410, 'exempt'], [81, 175, 'tag'], [49, 525, 'tag'], [41, 410, 'tag'], [37, 525, 'tag'], [51, 333, 'tag'], [1, 250, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 150, 'cycle_days': 31}, {'tag': 1889, 'plate': 0, 'invoices': 0}), ({'trips': [[40, 175, 'tag'], [49, 525, 'tag'], [43, 175, 'plate'], [3, 250, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 5, 'invoice_fee': 200, 'cycle_days': 31}, {'tag': 904, 'plate': 437, 'invoices': 1})], [({'trips': [[69, 175, 'exempt']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 5, 'invoice_fee': 400, 'cycle_days': 31}, {'tag': 0, 'plate': 0, 'invoices': 0}), ({'trips': [[3, 250, 'tag'], [58, 333, 'tag'], [42, 525, 'tag'], [72, 175, 'exempt'], [25, 175, 'tag'], [73, 410, 'plate']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 31}, {'tag': 1156, 'plate': 754, 'invoices': 1}), ({'trips': [[39, 250, 'exempt'], [93, 410, 'plate'], [0, 333, 'plate'], [7, 525, 'tag'], [48, 333, 'tag'], [53, 175, 'plate']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 10, 'invoice_fee': 150, 'cycle_days': 30}, {'tag': 773, 'plate': 1599, 'invoices': 3}), ({'trips': [[47, 175, 'tag'], [51, 525, 'exempt'], [26, 333, 'plate'], [37, 250, 'exempt'], [1, 250, 'exempt'], [61, 333, 'tag'], [11, 333, 'tag'], [69, 175, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 10, 'invoice_fee': 400, 'cycle_days': 31}, {'tag': 916, 'plate': 850, 'invoices': 1}), ({'trips': [[72, 525, 'tag'], [84, 175, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 15, 'invoice_fee': 400, 'cycle_days': 31}, {'tag': 596, 'plate': 0, 'invoices': 0}), ({'trips': [[81, 333, 'plate'], [52, 410, 'tag'], [43, 175, 'plate'], [72, 525, 'tag'], [45, 525, 'plate'], [20, 525, 'plate'], [43, 250, 'plate'], [28, 333, 'plate']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 5, 'invoice_fee': 200, 'cycle_days': 31}, {'tag': 889, 'plate': 3493, 'invoices': 3}), ({'trips': [[3, 410, 'exempt'], [4, 410, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 369, 'plate': 0, 'invoices': 0}), ({'trips': [[29, 250, 'plate'], [30, 250, 'plate'], [5, 333, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 284, 'plate': 1076, 'invoices': 2})]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('fee oracle' + ' %d' % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

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

N = 1
observations = []
def solve(x):
    tag = plate = 0
    periods = set()
    for day, base, method in x['trips']:
        if method == 'exempt':
            continue
        if method == 'tag':
            tag += base - base * x['tag_discount_pct'] // 100
        else:
            plate += base + -(-base * x['plate_surcharge_pct'] // 100)
            periods.add(day // x['cycle_days'])
    fees = len(periods) * x['invoice_fee']
    return {'tag': tag, 'plate': plate + x['invoice_fee'], 'invoices': len(periods)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'trips': [[25, 175, 'exempt'], [34, 410, 'plate'], [15, 250, 'plate'], [87, 175, 'exempt'], [2, 175, 'tag'], [22, 250, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 5, 'invoice_fee': 200, 'cycle_days': 31}, {'tag': 405, 'plate': 1292, 'invoices': 2}), ({'trips': [[94, 250, 'exempt'], [10, 410, 'tag'], [27, 333, 'plate'], [90, 175, 'plate'], [20, 410, 'plate'], [82, 525, 'tag']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 31}, {'tag': 796, 'plate': 1549, 'invoices': 2}), ({'trips': [[93, 333, 'tag'], [94, 333, 'tag'], [77, 333, 'tag'], [35, 175, 'exempt'], [63, 333, 'exempt'], [46, 175, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 5, 'invoice_fee': 200, 'cycle_days': 31}, {'tag': 1118, 'plate': 0, 'invoices': 0}), ({'trips': [[14, 410, 'plate'], [57, 333, 'exempt'], [15, 175, 'plate']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 150, 'cycle_days': 31}, {'tag': 0, 'plate': 941, 'invoices': 1}), ({'trips': [[29, 250, 'plate'], [30, 250, 'plate'], [5, 333, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 284, 'plate': 1076, 'invoices': 2}), ({'trips': [[72, 175, 'plate'], [36, 333, 'tag'], [69, 525, 'tag'], [34, 525, 'tag'], [42, 525, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 15, 'invoice_fee': 400, 'cycle_days': 31}, {'tag': 1625, 'plate': 663, 'invoices': 1}), ({'trips': [[3, 410, 'exempt'], [4, 410, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 369, 'plate': 0, 'invoices': 0}), ({'trips': [[30, 175, 'tag'], [60, 525, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 596, 'plate': 0, 'invoices': 0})], [({'trips': [[67, 410, 'plate'], [33, 410, 'tag'], [41, 250, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 400, 'cycle_days': 31}, {'tag': 594, 'plate': 1015, 'invoices': 1}), ({'trips': [[60, 175, 'tag'], [33, 333, 'exempt'], [92, 410, 'plate'], [20, 333, 'tag'], [34, 525, 'tag'], [54, 250, 'tag'], [60, 525, 'exempt']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 5, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 1221, 'plate': 713, 'invoices': 1}), ({'trips': [[3, 525, 'tag'], [27, 525, 'tag'], [24, 333, 'exempt'], [25, 250, 'plate'], [17, 175, 'exempt'], [40, 175, 'plate'], [92, 410, 'exempt'], [0, 410, 'tag']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 1315, 'plate': 932, 'invoices': 2}), ({'trips': [[49, 410, 'exempt'], [6, 525, 'plate']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 15, 'invoice_fee': 400, 'cycle_days': 31}, {'tag': 0, 'plate': 1188, 'invoices': 1}), ({'trips': [[21, 410, 'plate'], [90, 250, 'plate'], [6, 250, 'tag'], [80, 525, 'tag']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 15, 'invoice_fee': 150, 'cycle_days': 30}, {'tag': 660, 'plate': 1126, 'invoices': 2}), ({'trips': [[3, 410, 'exempt'], [4, 410, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 369, 'plate': 0, 'invoices': 0}), ({'trips': [[69, 410, 'plate'], [79, 410, 'plate'], [50, 175, 'tag'], [1, 333, 'plate'], [78, 250, 'tag'], [95, 175, 'exempt'], [93, 175, 'tag'], [68, 175, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 5, 'invoice_fee': 200, 'cycle_days': 31}, {'tag': 739, 'plate': 2130, 'invoices': 2}), ({'trips': [[29, 250, 'plate'], [30, 250, 'plate'], [5, 333, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 284, 'plate': 1076, 'invoices': 2})], [({'trips': [[20, 333, 'tag'], [29, 175, 'plate'], [74, 410, 'plate'], [22, 250, 'plate'], [2, 525, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 5, 'invoice_fee': 150, 'cycle_days': 31}, {'tag': 816, 'plate': 1429, 'invoices': 2}), ({'trips': [[29, 250, 'plate'], [30, 250, 'plate'], [5, 333, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 284, 'plate': 1076, 'invoices': 2}), ({'trips': [[85, 175, 'tag'], [52, 410, 'plate']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 15, 'invoice_fee': 150, 'cycle_days': 31}, {'tag': 149, 'plate': 765, 'invoices': 1}), ({'trips': [[3, 410, 'exempt'], [4, 410, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 369, 'plate': 0, 'invoices': 0}), ({'trips': [[46, 250, 'plate'], [53, 175, 'exempt'], [25, 333, 'plate'], [61, 250, 'exempt'], [80, 333, 'exempt'], [54, 525, 'tag'], [88, 175, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 5, 'invoice_fee': 150, 'cycle_days': 31}, {'tag': 666, 'plate': 1088, 'invoices': 2}), ({'trips': [[40, 250, 'tag'], [88, 175, 'exempt'], [93, 410, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 5, 'invoice_fee': 150, 'cycle_days': 30}, {'tag': 628, 'plate': 0, 'invoices': 0}), ({'trips': [[2, 333, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 5, 'invoice_fee': 150, 'cycle_days': 30}, {'tag': 317, 'plate': 0, 'invoices': 0}), ({'trips': [[28, 333, 'exempt']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 10, 'invoice_fee': 400, 'cycle_days': 31}, {'tag': 0, 'plate': 0, 'invoices': 0})], [({'trips': [[3, 410, 'exempt'], [4, 410, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 369, 'plate': 0, 'invoices': 0}), ({'trips': [[29, 250, 'plate'], [30, 250, 'plate'], [5, 333, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 284, 'plate': 1076, 'invoices': 2}), ({'trips': [[50, 250, 'tag'], [32, 410, 'exempt'], [37, 525, 'plate'], [58, 333, 'plate'], [45, 250, 'plate'], [20, 525, 'exempt']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 5, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 238, 'plate': 1863, 'invoices': 1}), ({'trips': [[63, 525, 'plate'], [69, 250, 'exempt'], [43, 175, 'plate'], [45, 333, 'plate'], [25, 175, 'exempt'], [63, 333, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 300, 'plate': 1951, 'invoices': 2}), ({'trips': [[6, 333, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 5, 'invoice_fee': 150, 'cycle_days': 30}, {'tag': 317, 'plate': 0, 'invoices': 0}), ({'trips': [[42, 410, 'tag'], [26, 250, 'plate'], [17, 525, 'plate']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 369, 'plate': 1170, 'invoices': 1}), ({'trips': [[65, 410, 'exempt'], [81, 175, 'tag'], [49, 525, 'tag'], [41, 410, 'tag'], [37, 525, 'tag'], [51, 333, 'tag'], [1, 250, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 150, 'cycle_days': 31}, {'tag': 1889, 'plate': 0, 'invoices': 0}), ({'trips': [[40, 175, 'tag'], [49, 525, 'tag'], [43, 175, 'plate'], [3, 250, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 5, 'invoice_fee': 200, 'cycle_days': 31}, {'tag': 904, 'plate': 437, 'invoices': 1})], [({'trips': [[69, 175, 'exempt']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 5, 'invoice_fee': 400, 'cycle_days': 31}, {'tag': 0, 'plate': 0, 'invoices': 0}), ({'trips': [[3, 250, 'tag'], [58, 333, 'tag'], [42, 525, 'tag'], [72, 175, 'exempt'], [25, 175, 'tag'], [73, 410, 'plate']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 31}, {'tag': 1156, 'plate': 754, 'invoices': 1}), ({'trips': [[39, 250, 'exempt'], [93, 410, 'plate'], [0, 333, 'plate'], [7, 525, 'tag'], [48, 333, 'tag'], [53, 175, 'plate']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 10, 'invoice_fee': 150, 'cycle_days': 30}, {'tag': 773, 'plate': 1599, 'invoices': 3}), ({'trips': [[47, 175, 'tag'], [51, 525, 'exempt'], [26, 333, 'plate'], [37, 250, 'exempt'], [1, 250, 'exempt'], [61, 333, 'tag'], [11, 333, 'tag'], [69, 175, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 10, 'invoice_fee': 400, 'cycle_days': 31}, {'tag': 916, 'plate': 850, 'invoices': 1}), ({'trips': [[72, 525, 'tag'], [84, 175, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 15, 'invoice_fee': 400, 'cycle_days': 31}, {'tag': 596, 'plate': 0, 'invoices': 0}), ({'trips': [[81, 333, 'plate'], [52, 410, 'tag'], [43, 175, 'plate'], [72, 525, 'tag'], [45, 525, 'plate'], [20, 525, 'plate'], [43, 250, 'plate'], [28, 333, 'plate']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 5, 'invoice_fee': 200, 'cycle_days': 31}, {'tag': 889, 'plate': 3493, 'invoices': 3}), ({'trips': [[3, 410, 'exempt'], [4, 410, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 369, 'plate': 0, 'invoices': 0}), ({'trips': [[29, 250, 'plate'], [30, 250, 'plate'], [5, 333, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 284, 'plate': 1076, 'invoices': 2})]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('fee oracle' + ' %d' % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Pay-by-plate invoice and tag discount returns a wrong result when a single invoice fee is added regardless of invoices.

Input {trips: [[day (0-based), base cents, tag|plate|exempt]], plate_surcharge_pct, tag_discount_pct, invoice_fee, cycle_days}. Exempt trips are ignored. Tag trips pay base minus a discount floored to cents. Plate trips pay base plus a surcharge rounded up to cents and are grouped into invoices by billing period day // cycle_days; each invoice adds one invoice_fee to the plate total. Return {tag, plate, invoices}.

split: open-access


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

N = 1
observations = []
def solve(x):
    tag = plate = 0
    periods = set()
    for day, base, method in x['trips']:
        if method == 'exempt':
            pass
        if method == 'tag':
            tag += base - base * x['tag_discount_pct'] // 100
        else:
            plate += base + -(-base * x['plate_surcharge_pct'] // 100)
            periods.add(day // x['cycle_days'])
    fees = len(periods) * x['invoice_fee']
    return {'tag': tag, 'plate': plate + fees, 'invoices': len(periods)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'trips': [[19, 525, 'tag']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 447, 'plate': 0, 'invoices': 0}), ({'trips': [[3, 410, 'exempt'], [4, 410, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 369, 'plate': 0, 'invoices': 0}), ({'trips': [[14, 175, 'tag'], [8, 333, 'plate'], [31, 333, 'tag'], [34, 333, 'tag'], [85, 525, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 5, 'invoice_fee': 150, 'cycle_days': 30}, {'tag': 1300, 'plate': 600, 'invoices': 1}), ({'trips': [[46, 250, 'plate'], [36, 175, 'tag'], [84, 250, 'plate']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 150, 'cycle_days': 31}, {'tag': 149, 'plate': 976, 'invoices': 2}), ({'trips': [[28, 410, 'exempt'], [41, 333, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 284, 'plate': 0, 'invoices': 0}), ({'trips': [[29, 250, 'plate'], [30, 250, 'plate'], [5, 333, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 284, 'plate': 1076, 'invoices': 2}), ({'trips': [[86, 525, 'exempt'], [43, 525, 'plate'], [12, 410, 'plate'], [69, 525, 'plate'], [35, 410, 'plate']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 31}, {'tag': 0, 'plate': 2940, 'invoices': 3}), ({'trips': [[46, 250, 'exempt'], [13, 410, 'tag'], [29, 333, 'plate'], [27, 525, 'exempt']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 369, 'plate': 650, 'invoices': 1})], [({'trips': [[34, 410, 'plate'], [42, 410, 'tag'], [69, 525, 'plate'], [4, 525, 'tag'], [11, 250, 'exempt'], [87, 525, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 10, 'invoice_fee': 400, 'cycle_days': 30}, {'tag': 1315, 'plate': 2063, 'invoices': 2}), ({'trips': [[77, 250, 'plate'], [50, 175, 'plate'], [14, 175, 'tag'], [81, 250, 'plate'], [89, 333, 'tag'], [61, 250, 'tag'], [19, 333, 'tag'], [9, 333, 'tag']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 5, 'invoice_fee': 150, 'cycle_days': 31}, {'tag': 1356, 'plate': 1145, 'invoices': 2}), ({'trips': [[33, 333, 'plate']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 31}, {'tag': 0, 'plate': 650, 'invoices': 1}), ({'trips': [[76, 250, 'tag'], [39, 175, 'plate'], [95, 175, 'plate'], [20, 333, 'plate'], [78, 410, 'exempt'], [59, 250, 'plate'], [88, 410, 'tag'], [5, 175, 'plate']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 5, 'invoice_fee': 150, 'cycle_days': 31}, {'tag': 628, 'plate': 1949, 'invoices': 3}), ({'trips': [[55, 410, 'exempt']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 5, 'invoice_fee': 200, 'cycle_days': 31}, {'tag': 0, 'plate': 0, 'invoices': 0}), ({'trips': [[3, 410, 'exempt'], [4, 410, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 369, 'plate': 0, 'invoices': 0}), ({'trips': [[19, 525, 'plate'], [51, 410, 'plate']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 15, 'invoice_fee': 400, 'cycle_days': 31}, {'tag': 0, 'plate': 1970, 'invoices': 2}), ({'trips': [[29, 250, 'plate'], [30, 250, 'plate'], [5, 333, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 284, 'plate': 1076, 'invoices': 2})], [({'trips': [[40, 410, 'tag'], [72, 250, 'exempt'], [22, 410, 'tag'], [1, 525, 'exempt'], [12, 410, 'plate'], [67, 525, 'plate'], [31, 410, 'tag']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 5, 'invoice_fee': 150, 'cycle_days': 31}, {'tag': 1170, 'plate': 1470, 'invoices': 2}), ({'trips': [[3, 410, 'exempt'], [4, 410, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 369, 'plate': 0, 'invoices': 0}), ({'trips': [[29, 250, 'plate'], [30, 250, 'plate'], [5, 333, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 284, 'plate': 1076, 'invoices': 2}), ({'trips': [[52, 175, 'plate'], [89, 525, 'tag'], [15, 333, 'plate'], [70, 333, 'plate'], [65, 333, 'tag'], [45, 250, 'tag'], [80, 175, 'tag'], [82, 410, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 150, 'cycle_days': 31}, {'tag': 1525, 'plate': 1713, 'invoices': 3}), ({'trips': [[12, 250, 'exempt'], [79, 175, 'plate'], [39, 175, 'plate'], [33, 175, 'plate'], [59, 525, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 15, 'invoice_fee': 400, 'cycle_days': 31}, {'tag': 447, 'plate': 1589, 'invoices': 2}), ({'trips': [[69, 525, 'tag'], [7, 525, 'plate'], [83, 410, 'plate'], [84, 333, 'tag'], [1, 175, 'plate'], [52, 175, 'plate'], [0, 525, 'plate'], [33, 410, 'plate']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 150, 'cycle_days': 30}, {'tag': 773, 'plate': 3782, 'invoices': 3}), ({'trips': [[1, 525, 'plate'], [80, 333, 'tag'], [16, 250, 'tag'], [26, 525, 'plate'], [81, 410, 'tag'], [16, 525, 'plate'], [22, 250, 'plate']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 5, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 945, 'plate': 2484, 'invoices': 1}), ({'trips': [[59, 410, 'plate']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 0, 'plate': 815, 'invoices': 1})], [({'trips': [[29, 250, 'plate'], [30, 250, 'plate'], [5, 333, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 284, 'plate': 1076, 'invoices': 2}), ({'trips': [[64, 410, 'tag'], [37, 250, 'plate'], [70, 410, 'exempt'], [69, 333, 'plate'], [15, 250, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 5, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 628, 'plate': 1188, 'invoices': 2}), ({'trips': [[39, 175, 'exempt'], [88, 250, 'exempt'], [26, 333, 'plate'], [38, 250, 'plate'], [87, 333, 'plate'], [91, 333, 'tag'], [95, 333, 'plate'], [21, 333, 'exempt']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 284, 'plate': 2675, 'invoices': 4}), ({'trips': [[89, 410, 'tag'], [63, 250, 'plate'], [89, 333, 'plate']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 150, 'cycle_days': 31}, {'tag': 369, 'plate': 1025, 'invoices': 1}), ({'trips': [[3, 410, 'exempt'], [4, 410, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 369, 'plate': 0, 'invoices': 0}), ({'trips': [[45, 175, 'plate']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 5, 'invoice_fee': 400, 'cycle_days': 31}, {'tag': 0, 'plate': 619, 'invoices': 1}), ({'trips': [[21, 333, 'tag'], [53, 175, 'tag']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 10, 'invoice_fee': 400, 'cycle_days': 31}, {'tag': 458, 'plate': 0, 'invoices': 0}), ({'trips': [[16, 410, 'tag'], [38, 333, 'plate'], [40, 175, 'plate'], [91, 250, 'exempt'], [67, 250, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 5, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 628, 'plate': 963, 'invoices': 1})], [({'trips': [[34, 175, 'plate'], [12, 175, 'plate'], [40, 250, 'plate'], [83, 525, 'tag'], [79, 250, 'plate']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 150, 'cycle_days': 30}, {'tag': 473, 'plate': 1726, 'invoices': 3}), ({'trips': [[23, 175, 'plate'], [66, 525, 'plate'], [52, 410, 'plate'], [73, 175, 'plate'], [39, 410, 'exempt'], [44, 250, 'tag'], [20, 333, 'tag'], [66, 410, 'exempt']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 5, 'invoice_fee': 400, 'cycle_days': 30}, {'tag': 555, 'plate': 3129, 'invoices': 3}), ({'trips': [[83, 175, 'exempt'], [80, 333, 'plate']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 400, 'cycle_days': 31}, {'tag': 0, 'plate': 900, 'invoices': 1}), ({'trips': [[3, 410, 'exempt'], [4, 410, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 369, 'plate': 0, 'invoices': 0}), ({'trips': [[29, 250, 'plate'], [30, 250, 'plate'], [5, 333, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 284, 'plate': 1076, 'invoices': 2}), ({'trips': [[67, 525, 'tag'], [87, 525, 'exempt'], [47, 525, 'tag'], [12, 250, 'tag'], [26, 250, 'exempt']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 5, 'invoice_fee': 400, 'cycle_days': 30}, {'tag': 1236, 'plate': 0, 'invoices': 0}), ({'trips': [[88, 175, 'tag']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 5, 'invoice_fee': 400, 'cycle_days': 30}, {'tag': 167, 'plate': 0, 'invoices': 0}), ({'trips': [[92, 525, 'tag'], [74, 333, 'tag'], [73, 333, 'plate']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 31}, {'tag': 773, 'plate': 700, 'invoices': 1})]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('fee oracle' + ' %d' % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    tag = plate = 0
    periods = set()
    for day, base, method in x['trips']:
        if method == 'exempt':
            base = 0
        if method == 'tag':
            tag += base - base * x['tag_discount_pct'] // 100
        else:
            plate += base + -(-base * x['plate_surcharge_pct'] // 100)
            periods.add(day // x['cycle_days'])
    fees = len(periods) * x['invoice_fee']
    return {'tag': tag, 'plate': plate + fees, 'invoices': len(periods)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'trips': [[19, 525, 'tag']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 447, 'plate': 0, 'invoices': 0}), ({'trips': [[3, 410, 'exempt'], [4, 410, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 369, 'plate': 0, 'invoices': 0}), ({'trips': [[14, 175, 'tag'], [8, 333, 'plate'], [31, 333, 'tag'], [34, 333, 'tag'], [85, 525, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 5, 'invoice_fee': 150, 'cycle_days': 30}, {'tag': 1300, 'plate': 600, 'invoices': 1}), ({'trips': [[46, 250, 'plate'], [36, 175, 'tag'], [84, 250, 'plate']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 150, 'cycle_days': 31}, {'tag': 149, 'plate': 976, 'invoices': 2}), ({'trips': [[28, 410, 'exempt'], [41, 333, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 284, 'plate': 0, 'invoices': 0}), ({'trips': [[29, 250, 'plate'], [30, 250, 'plate'], [5, 333, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 284, 'plate': 1076, 'invoices': 2}), ({'trips': [[86, 525, 'exempt'], [43, 525, 'plate'], [12, 410, 'plate'], [69, 525, 'plate'], [35, 410, 'plate']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 31}, {'tag': 0, 'plate': 2940, 'invoices': 3}), ({'trips': [[46, 250, 'exempt'], [13, 410, 'tag'], [29, 333, 'plate'], [27, 525, 'exempt']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 369, 'plate': 650, 'invoices': 1})], [({'trips': [[34, 410, 'plate'], [42, 410, 'tag'], [69, 525, 'plate'], [4, 525, 'tag'], [11, 250, 'exempt'], [87, 525, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 10, 'invoice_fee': 400, 'cycle_days': 30}, {'tag': 1315, 'plate': 2063, 'invoices': 2}), ({'trips': [[77, 250, 'plate'], [50, 175, 'plate'], [14, 175, 'tag'], [81, 250, 'plate'], [89, 333, 'tag'], [61, 250, 'tag'], [19, 333, 'tag'], [9, 333, 'tag']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 5, 'invoice_fee': 150, 'cycle_days': 31}, {'tag': 1356, 'plate': 1145, 'invoices': 2}), ({'trips': [[33, 333, 'plate']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 31}, {'tag': 0, 'plate': 650, 'invoices': 1}), ({'trips': [[76, 250, 'tag'], [39, 175, 'plate'], [95, 175, 'plate'], [20, 333, 'plate'], [78, 410, 'exempt'], [59, 250, 'plate'], [88, 410, 'tag'], [5, 175, 'plate']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 5, 'invoice_fee': 150, 'cycle_days': 31}, {'tag': 628, 'plate': 1949, 'invoices': 3}), ({'trips': [[55, 410, 'exempt']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 5, 'invoice_fee': 200, 'cycle_days': 31}, {'tag': 0, 'plate': 0, 'invoices': 0}), ({'trips': [[3, 410, 'exempt'], [4, 410, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 369, 'plate': 0, 'invoices': 0}), ({'trips': [[19, 525, 'plate'], [51, 410, 'plate']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 15, 'invoice_fee': 400, 'cycle_days': 31}, {'tag': 0, 'plate': 1970, 'invoices': 2}), ({'trips': [[29, 250, 'plate'], [30, 250, 'plate'], [5, 333, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 284, 'plate': 1076, 'invoices': 2})], [({'trips': [[40, 410, 'tag'], [72, 250, 'exempt'], [22, 410, 'tag'], [1, 525, 'exempt'], [12, 410, 'plate'], [67, 525, 'plate'], [31, 410, 'tag']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 5, 'invoice_fee': 150, 'cycle_days': 31}, {'tag': 1170, 'plate': 1470, 'invoices': 2}), ({'trips': [[3, 410, 'exempt'], [4, 410, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 369, 'plate': 0, 'invoices': 0}), ({'trips': [[29, 250, 'plate'], [30, 250, 'plate'], [5, 333, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 284, 'plate': 1076, 'invoices': 2}), ({'trips': [[52, 175, 'plate'], [89, 525, 'tag'], [15, 333, 'plate'], [70, 333, 'plate'], [65, 333, 'tag'], [45, 250, 'tag'], [80, 175, 'tag'], [82, 410, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 150, 'cycle_days': 31}, {'tag': 1525, 'plate': 1713, 'invoices': 3}), ({'trips': [[12, 250, 'exempt'], [79, 175, 'plate'], [39, 175, 'plate'], [33, 175, 'plate'], [59, 525, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 15, 'invoice_fee': 400, 'cycle_days': 31}, {'tag': 447, 'plate': 1589, 'invoices': 2}), ({'trips': [[69, 525, 'tag'], [7, 525, 'plate'], [83, 410, 'plate'], [84, 333, 'tag'], [1, 175, 'plate'], [52, 175, 'plate'], [0, 525, 'plate'], [33, 410, 'plate']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 150, 'cycle_days': 30}, {'tag': 773, 'plate': 3782, 'invoices': 3}), ({'trips': [[1, 525, 'plate'], [80, 333, 'tag'], [16, 250, 'tag'], [26, 525, 'plate'], [81, 410, 'tag'], [16, 525, 'plate'], [22, 250, 'plate']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 5, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 945, 'plate': 2484, 'invoices': 1}), ({'trips': [[59, 410, 'plate']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 0, 'plate': 815, 'invoices': 1})], [({'trips': [[29, 250, 'plate'], [30, 250, 'plate'], [5, 333, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 284, 'plate': 1076, 'invoices': 2}), ({'trips': [[64, 410, 'tag'], [37, 250, 'plate'], [70, 410, 'exempt'], [69, 333, 'plate'], [15, 250, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 5, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 628, 'plate': 1188, 'invoices': 2}), ({'trips': [[39, 175, 'exempt'], [88, 250, 'exempt'], [26, 333, 'plate'], [38, 250, 'plate'], [87, 333, 'plate'], [91, 333, 'tag'], [95, 333, 'plate'], [21, 333, 'exempt']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 284, 'plate': 2675, 'invoices': 4}), ({'trips': [[89, 410, 'tag'], [63, 250, 'plate'], [89, 333, 'plate']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 150, 'cycle_days': 31}, {'tag': 369, 'plate': 1025, 'invoices': 1}), ({'trips': [[3, 410, 'exempt'], [4, 410, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 369, 'plate': 0, 'invoices': 0}), ({'trips': [[45, 175, 'plate']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 5, 'invoice_fee': 400, 'cycle_days': 31}, {'tag': 0, 'plate': 619, 'invoices': 1}), ({'trips': [[21, 333, 'tag'], [53, 175, 'tag']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 10, 'invoice_fee': 400, 'cycle_days': 31}, {'tag': 458, 'plate': 0, 'invoices': 0}), ({'trips': [[16, 410, 'tag'], [38, 333, 'plate'], [40, 175, 'plate'], [91, 250, 'exempt'], [67, 250, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 5, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 628, 'plate': 963, 'invoices': 1})], [({'trips': [[34, 175, 'plate'], [12, 175, 'plate'], [40, 250, 'plate'], [83, 525, 'tag'], [79, 250, 'plate']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 150, 'cycle_days': 30}, {'tag': 473, 'plate': 1726, 'invoices': 3}), ({'trips': [[23, 175, 'plate'], [66, 525, 'plate'], [52, 410, 'plate'], [73, 175, 'plate'], [39, 410, 'exempt'], [44, 250, 'tag'], [20, 333, 'tag'], [66, 410, 'exempt']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 5, 'invoice_fee': 400, 'cycle_days': 30}, {'tag': 555, 'plate': 3129, 'invoices': 3}), ({'trips': [[83, 175, 'exempt'], [80, 333, 'plate']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 400, 'cycle_days': 31}, {'tag': 0, 'plate': 900, 'invoices': 1}), ({'trips': [[3, 410, 'exempt'], [4, 410, 'tag']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 369, 'plate': 0, 'invoices': 0}), ({'trips': [[29, 250, 'plate'], [30, 250, 'plate'], [5, 333, 'tag']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 15, 'invoice_fee': 200, 'cycle_days': 30}, {'tag': 284, 'plate': 1076, 'invoices': 2}), ({'trips': [[67, 525, 'tag'], [87, 525, 'exempt'], [47, 525, 'tag'], [12, 250, 'tag'], [26, 250, 'exempt']], 'plate_surcharge_pct': 35, 'tag_discount_pct': 5, 'invoice_fee': 400, 'cycle_days': 30}, {'tag': 1236, 'plate': 0, 'invoices': 0}), ({'trips': [[88, 175, 'tag']], 'plate_surcharge_pct': 25, 'tag_discount_pct': 5, 'invoice_fee': 400, 'cycle_days': 30}, {'tag': 167, 'plate': 0, 'invoices': 0}), ({'trips': [[92, 525, 'tag'], [74, 333, 'tag'], [73, 333, 'plate']], 'plate_surcharge_pct': 50, 'tag_discount_pct': 10, 'invoice_fee': 200, 'cycle_days': 31}, {'tag': 773, 'plate': 700, 'invoices': 1})]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('fee oracle' + ' %d' % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Pay-by-plate invoice and tag discount returns a wrong result when exempt trips fall through to plate billing.

Input {trips: [[day (0-based), base cents, tag|plate|exempt]], plate_surcharge_pct, tag_discount_pct, invoice_fee, cycle_days}. Exempt trips are ignored. Tag trips pay base minus a discount floored to cents. Plate trips pay base plus a surcharge rounded up to cents and are grouped into invoices by billing period day // cycle_days; each invoice adds one invoice_fee to the plate total. Return {tag, plate, invoices}.

split: open-access


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

N = 1
observations = []
def solve(x):
    bal = x['balance']
    n = 0
    first = None
    amt = max(x['min_replenish'], -(-x['usage_30d'] // 2000) * 500)
    for i, c in enumerate(x['charges']):
        bal -= c
        if bal <= x['threshold'] and x['card_ok']:
            bal += amt
            n += 1
        if bal < 0 and first is None:
            first = i
    return {'balance': bal, 'replenished': n, 'first_negative': first}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'balance': 2266, 'charges': [150, 1200, 3000, 400, 150, 650, 650], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 3563, 'card_ok': True}, {'balance': 1066, 'replenished': 2, 'first_negative': None}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': -441, 'charges': [150], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 1094, 'card_ok': True}, {'balance': 1409, 'replenished': 1, 'first_negative': None}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': 2855, 'charges': [650, 1200], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 5906, 'card_ok': True}, {'balance': 1005, 'replenished': 0, 'first_negative': None}), ({'balance': 400, 'charges': [400], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': 0, 'replenished': 0, 'first_negative': None}), ({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 2453, 'charges': [1200, 150, 650, 150, 150, 150, 275, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 18693, 'card_ok': False}, {'balance': -547, 'replenished': 0, 'first_negative': 6})], [({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 500, 'charges': [3000], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 12686, 'card_ok': True}, {'balance': 1000, 'replenished': 1, 'first_negative': None}), ({'balance': 3332, 'charges': [150, 400, 275, 1200, 150, 150, 275, 3000], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 4983, 'card_ok': True}, {'balance': -768, 'replenished': 1, 'first_negative': 7}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 2401, 'charges': [3000, 275, 150, 150, 275], 'threshold': 1000, 'min_replenish': 2500, 'usage_30d': 3761, 'card_ok': True}, {'balance': 1051, 'replenished': 1, 'first_negative': None}), ({'balance': 1390, 'charges': [150, 150, 1200, 150, 3000], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 10475, 'card_ok': True}, {'balance': 2740, 'replenished': 2, 'first_negative': None}), ({'balance': 3658, 'charges': [650, 150, 400, 275], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 12188, 'card_ok': True}, {'balance': 2183, 'replenished': 0, 'first_negative': None})], [({'balance': -192, 'charges': [650, 3000, 650, 3000], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 9701, 'card_ok': True}, {'balance': 8, 'replenished': 3, 'first_negative': None}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 1210, 'charges': [400], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 7111, 'card_ok': True}, {'balance': 2810, 'replenished': 1, 'first_negative': None}), ({'balance': 400, 'charges': [400], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': 0, 'replenished': 0, 'first_negative': None}), ({'balance': 252, 'charges': [400], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 7082, 'card_ok': True}, {'balance': 2352, 'replenished': 1, 'first_negative': None}), ({'balance': -78, 'charges': [650, 400], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 12782, 'card_ok': True}, {'balance': 2372, 'replenished': 1, 'first_negative': None}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': 2049, 'charges': [650, 275, 650, 3000, 650, 400, 275], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 12840, 'card_ok': True}, {'balance': 3149, 'replenished': 2, 'first_negative': None})], [({'balance': 2222, 'charges': [275, 650], 'threshold': 1500, 'min_replenish': 2500, 'usage_30d': 19460, 'card_ok': True}, {'balance': 6297, 'replenished': 1, 'first_negative': None}), ({'balance': 650, 'charges': [1200, 650, 150, 400, 650, 275, 150, 150], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 15662, 'card_ok': True}, {'balance': 1025, 'replenished': 1, 'first_negative': None}), ({'balance': 1372, 'charges': [400, 400, 3000, 650], 'threshold': 1500, 'min_replenish': 2500, 'usage_30d': 1021, 'card_ok': True}, {'balance': 1922, 'replenished': 2, 'first_negative': None}), ({'balance': 400, 'charges': [400], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': 0, 'replenished': 0, 'first_negative': None}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': -398, 'charges': [150, 400, 3000, 275, 150, 400, 1200, 1200], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 10518, 'card_ok': False}, {'balance': -7173, 'replenished': 0, 'first_negative': 0}), ({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None})], [({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 587, 'charges': [1200, 3000, 650, 1200, 1200, 150], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 12748, 'card_ok': True}, {'balance': 3687, 'replenished': 3, 'first_negative': None}), ({'balance': 1610, 'charges': [400, 1200, 150, 1200, 400, 650, 400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 4096, 'card_ok': True}, {'balance': 1710, 'replenished': 3, 'first_negative': None}), ({'balance': 400, 'charges': [400], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': 0, 'replenished': 0, 'first_negative': None}), ({'balance': 2876, 'charges': [3000, 400, 150, 275], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 2566, 'card_ok': True}, {'balance': 1051, 'replenished': 1, 'first_negative': None}), ({'balance': 2382, 'charges': [400, 1200, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 12535, 'card_ok': True}, {'balance': 507, 'replenished': 0, 'first_negative': None}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': 1299, 'charges': [3000, 3000, 650], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 8830, 'card_ok': True}, {'balance': 2149, 'replenished': 3, 'first_negative': None})]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('fee oracle' + ' %d' % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    bal = x['balance']
    n = 0
    first = None
    amt = max(x['min_replenish'], -(-x['usage_30d'] // 2000) * 500)
    for i, c in enumerate(x['charges']):
        bal -= c
        if bal - c < x['threshold'] and x['card_ok']:
            bal += amt
            n += 1
        if bal < 0 and first is None:
            first = i
    return {'balance': bal, 'replenished': n, 'first_negative': first}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'balance': 2266, 'charges': [150, 1200, 3000, 400, 150, 650, 650], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 3563, 'card_ok': True}, {'balance': 1066, 'replenished': 2, 'first_negative': None}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': -441, 'charges': [150], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 1094, 'card_ok': True}, {'balance': 1409, 'replenished': 1, 'first_negative': None}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': 2855, 'charges': [650, 1200], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 5906, 'card_ok': True}, {'balance': 1005, 'replenished': 0, 'first_negative': None}), ({'balance': 400, 'charges': [400], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': 0, 'replenished': 0, 'first_negative': None}), ({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 2453, 'charges': [1200, 150, 650, 150, 150, 150, 275, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 18693, 'card_ok': False}, {'balance': -547, 'replenished': 0, 'first_negative': 6})], [({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 500, 'charges': [3000], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 12686, 'card_ok': True}, {'balance': 1000, 'replenished': 1, 'first_negative': None}), ({'balance': 3332, 'charges': [150, 400, 275, 1200, 150, 150, 275, 3000], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 4983, 'card_ok': True}, {'balance': -768, 'replenished': 1, 'first_negative': 7}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 2401, 'charges': [3000, 275, 150, 150, 275], 'threshold': 1000, 'min_replenish': 2500, 'usage_30d': 3761, 'card_ok': True}, {'balance': 1051, 'replenished': 1, 'first_negative': None}), ({'balance': 1390, 'charges': [150, 150, 1200, 150, 3000], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 10475, 'card_ok': True}, {'balance': 2740, 'replenished': 2, 'first_negative': None}), ({'balance': 3658, 'charges': [650, 150, 400, 275], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 12188, 'card_ok': True}, {'balance': 2183, 'replenished': 0, 'first_negative': None})], [({'balance': -192, 'charges': [650, 3000, 650, 3000], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 9701, 'card_ok': True}, {'balance': 8, 'replenished': 3, 'first_negative': None}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 1210, 'charges': [400], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 7111, 'card_ok': True}, {'balance': 2810, 'replenished': 1, 'first_negative': None}), ({'balance': 400, 'charges': [400], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': 0, 'replenished': 0, 'first_negative': None}), ({'balance': 252, 'charges': [400], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 7082, 'card_ok': True}, {'balance': 2352, 'replenished': 1, 'first_negative': None}), ({'balance': -78, 'charges': [650, 400], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 12782, 'card_ok': True}, {'balance': 2372, 'replenished': 1, 'first_negative': None}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': 2049, 'charges': [650, 275, 650, 3000, 650, 400, 275], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 12840, 'card_ok': True}, {'balance': 3149, 'replenished': 2, 'first_negative': None})], [({'balance': 2222, 'charges': [275, 650], 'threshold': 1500, 'min_replenish': 2500, 'usage_30d': 19460, 'card_ok': True}, {'balance': 6297, 'replenished': 1, 'first_negative': None}), ({'balance': 650, 'charges': [1200, 650, 150, 400, 650, 275, 150, 150], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 15662, 'card_ok': True}, {'balance': 1025, 'replenished': 1, 'first_negative': None}), ({'balance': 1372, 'charges': [400, 400, 3000, 650], 'threshold': 1500, 'min_replenish': 2500, 'usage_30d': 1021, 'card_ok': True}, {'balance': 1922, 'replenished': 2, 'first_negative': None}), ({'balance': 400, 'charges': [400], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': 0, 'replenished': 0, 'first_negative': None}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': -398, 'charges': [150, 400, 3000, 275, 150, 400, 1200, 1200], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 10518, 'card_ok': False}, {'balance': -7173, 'replenished': 0, 'first_negative': 0}), ({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None})], [({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 587, 'charges': [1200, 3000, 650, 1200, 1200, 150], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 12748, 'card_ok': True}, {'balance': 3687, 'replenished': 3, 'first_negative': None}), ({'balance': 1610, 'charges': [400, 1200, 150, 1200, 400, 650, 400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 4096, 'card_ok': True}, {'balance': 1710, 'replenished': 3, 'first_negative': None}), ({'balance': 400, 'charges': [400], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': 0, 'replenished': 0, 'first_negative': None}), ({'balance': 2876, 'charges': [3000, 400, 150, 275], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 2566, 'card_ok': True}, {'balance': 1051, 'replenished': 1, 'first_negative': None}), ({'balance': 2382, 'charges': [400, 1200, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 12535, 'card_ok': True}, {'balance': 507, 'replenished': 0, 'first_negative': None}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': 1299, 'charges': [3000, 3000, 650], 'threshold': 500, 'min_replenish': 2000, 'usage_30d': 8830, 'card_ok': True}, {'balance': 2149, 'replenished': 3, 'first_negative': None})]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('fee oracle' + ' %d' % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Prepaid toll account auto-replenishment returns a wrong result when a balance equal to the threshold triggers replenishment.

Input {balance, charges, threshold, min_replenish, usage_30d, card_ok}. The replenish amount is max(min_replenish, ceil(usage_30d/4) rounded up to a multiple of 500). After each charge, if the balance is strictly below threshold and the card works, one replenishment is added. first_negative is the index of the first charge after which the balance is negative (or null). Return {balance, replenished, first_negative}.

split: open-access


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

N = 1
observations = []
def solve(x):
    bal = x['balance']
    n = 0
    first = None
    amt = max(x['min_replenish'], x['usage_30d'] // 2000 * 500)
    for i, c in enumerate(x['charges']):
        bal -= c
        if bal < x['threshold'] and x['card_ok']:
            bal += amt
            n += 1
        if bal < 0 and first is None:
            first = i
    return {'balance': bal, 'replenished': n, 'first_negative': first}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 2574, 'charges': [3000, 650, 650], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 11833, 'card_ok': True}, {'balance': 4274, 'replenished': 2, 'first_negative': None}), ({'balance': 930, 'charges': [3000, 150, 275, 3000, 275, 400, 1200, 650], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 7179, 'card_ok': True}, {'balance': 1980, 'replenished': 5, 'first_negative': 0}), ({'balance': 3406, 'charges': [3000, 650, 400, 400, 3000], 'threshold': 1500, 'min_replenish': 1000, 'usage_30d': 19012, 'card_ok': False}, {'balance': -4044, 'replenished': 0, 'first_negative': 1}), ({'balance': 288, 'charges': [3000], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 7617, 'card_ok': False}, {'balance': -2712, 'replenished': 0, 'first_negative': 0}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 324, 'charges': [275, 650, 1200, 1200, 400, 650, 1200, 3000], 'threshold': 1000, 'min_replenish': 2500, 'usage_30d': 11394, 'card_ok': True}, {'balance': 3749, 'replenished': 4, 'first_negative': None}), ({'balance': 400, 'charges': [400], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': 0, 'replenished': 0, 'first_negative': None})], [({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 2515, 'charges': [400], 'threshold': 1500, 'min_replenish': 2500, 'usage_30d': 3531, 'card_ok': True}, {'balance': 2115, 'replenished': 0, 'first_negative': None}), ({'balance': 400, 'charges': [400], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': 0, 'replenished': 0, 'first_negative': None}), ({'balance': 1219, 'charges': [150, 400, 275, 1200, 275, 275], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 15594, 'card_ok': False}, {'balance': -1356, 'replenished': 0, 'first_negative': 3}), ({'balance': 412, 'charges': [400, 3000, 650], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 13088, 'card_ok': True}, {'balance': 3362, 'replenished': 2, 'first_negative': None}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': 2633, 'charges': [650, 150, 275, 1200, 3000, 150, 400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 12112, 'card_ok': False}, {'balance': -3192, 'replenished': 0, 'first_negative': 4}), ({'balance': 1282, 'charges': [1200, 150, 1200, 150, 3000], 'threshold': 1500, 'min_replenish': 2500, 'usage_30d': 15237, 'card_ok': True}, {'balance': 3582, 'replenished': 2, 'first_negative': None})], [({'balance': 26, 'charges': [150, 1200, 3000, 400], 'threshold': 1000, 'min_replenish': 2500, 'usage_30d': 19243, 'card_ok': False}, {'balance': -4724, 'replenished': 0, 'first_negative': 0}), ({'balance': 2453, 'charges': [650, 275], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 7993, 'card_ok': True}, {'balance': 1528, 'replenished': 0, 'first_negative': None}), ({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 1341, 'charges': [400, 3000, 275], 'threshold': 1000, 'min_replenish': 2500, 'usage_30d': 15381, 'card_ok': True}, {'balance': 1666, 'replenished': 1, 'first_negative': None}), ({'balance': -329, 'charges': [3000, 150, 1200, 400], 'threshold': 1500, 'min_replenish': 2500, 'usage_30d': 7527, 'card_ok': True}, {'balance': 2421, 'replenished': 3, 'first_negative': 0}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 552, 'charges': [275, 1200], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 7045, 'card_ok': True}, {'balance': 1077, 'replenished': 1, 'first_negative': None}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None})], [({'balance': 2290, 'charges': [1200, 650, 150, 1200, 400, 1200], 'threshold': 1500, 'min_replenish': 2500, 'usage_30d': 6040, 'card_ok': True}, {'balance': 2490, 'replenished': 2, 'first_negative': None}), ({'balance': 2621, 'charges': [3000, 150, 1200, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 17666, 'card_ok': True}, {'balance': 2621, 'replenished': 1, 'first_negative': None}), ({'balance': 2757, 'charges': [1200, 3000, 150], 'threshold': 1500, 'min_replenish': 1000, 'usage_30d': 14481, 'card_ok': False}, {'balance': -1593, 'replenished': 0, 'first_negative': 1}), ({'balance': 777, 'charges': [650, 3000, 400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 17628, 'card_ok': True}, {'balance': 1227, 'replenished': 1, 'first_negative': None}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 1586, 'charges': [650, 650, 275, 1200], 'threshold': 1500, 'min_replenish': 1000, 'usage_30d': 6189, 'card_ok': True}, {'balance': 2811, 'replenished': 2, 'first_negative': None})], [({'balance': 1234, 'charges': [650, 3000, 650, 275], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 16752, 'card_ok': False}, {'balance': -3341, 'replenished': 0, 'first_negative': 1}), ({'balance': 400, 'charges': [400], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': 0, 'replenished': 0, 'first_negative': None}), ({'balance': 767, 'charges': [3000, 275, 275, 400, 3000, 3000, 275], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 18564, 'card_ok': True}, {'balance': 5542, 'replenished': 3, 'first_negative': None}), ({'balance': 3840, 'charges': [275, 275, 1200, 400, 150], 'threshold': 1000, 'min_replenish': 2500, 'usage_30d': 4963, 'card_ok': True}, {'balance': 1540, 'replenished': 0, 'first_negative': None}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 979, 'charges': [275, 275], 'threshold': 1000, 'min_replenish': 2500, 'usage_30d': 19904, 'card_ok': True}, {'balance': 5429, 'replenished': 1, 'first_negative': None}), ({'balance': 3921, 'charges': [275, 3000, 275], 'threshold': 1000, 'min_replenish': 2500, 'usage_30d': 12856, 'card_ok': True}, {'balance': 3871, 'replenished': 1, 'first_negative': None}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None})]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('fee oracle' + ' %d' % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    bal = x['balance']
    n = 0
    first = None
    amt = max(x['min_replenish'], -(-x['usage_30d'] // 4))
    for i, c in enumerate(x['charges']):
        bal -= c
        if bal < x['threshold'] and x['card_ok']:
            bal += amt
            n += 1
        if bal < 0 and first is None:
            first = i
    return {'balance': bal, 'replenished': n, 'first_negative': first}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 2574, 'charges': [3000, 650, 650], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 11833, 'card_ok': True}, {'balance': 4274, 'replenished': 2, 'first_negative': None}), ({'balance': 930, 'charges': [3000, 150, 275, 3000, 275, 400, 1200, 650], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 7179, 'card_ok': True}, {'balance': 1980, 'replenished': 5, 'first_negative': 0}), ({'balance': 3406, 'charges': [3000, 650, 400, 400, 3000], 'threshold': 1500, 'min_replenish': 1000, 'usage_30d': 19012, 'card_ok': False}, {'balance': -4044, 'replenished': 0, 'first_negative': 1}), ({'balance': 288, 'charges': [3000], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 7617, 'card_ok': False}, {'balance': -2712, 'replenished': 0, 'first_negative': 0}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 324, 'charges': [275, 650, 1200, 1200, 400, 650, 1200, 3000], 'threshold': 1000, 'min_replenish': 2500, 'usage_30d': 11394, 'card_ok': True}, {'balance': 3749, 'replenished': 4, 'first_negative': None}), ({'balance': 400, 'charges': [400], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': 0, 'replenished': 0, 'first_negative': None})], [({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 2515, 'charges': [400], 'threshold': 1500, 'min_replenish': 2500, 'usage_30d': 3531, 'card_ok': True}, {'balance': 2115, 'replenished': 0, 'first_negative': None}), ({'balance': 400, 'charges': [400], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': 0, 'replenished': 0, 'first_negative': None}), ({'balance': 1219, 'charges': [150, 400, 275, 1200, 275, 275], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 15594, 'card_ok': False}, {'balance': -1356, 'replenished': 0, 'first_negative': 3}), ({'balance': 412, 'charges': [400, 3000, 650], 'threshold': 500, 'min_replenish': 2500, 'usage_30d': 13088, 'card_ok': True}, {'balance': 3362, 'replenished': 2, 'first_negative': None}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': 2633, 'charges': [650, 150, 275, 1200, 3000, 150, 400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 12112, 'card_ok': False}, {'balance': -3192, 'replenished': 0, 'first_negative': 4}), ({'balance': 1282, 'charges': [1200, 150, 1200, 150, 3000], 'threshold': 1500, 'min_replenish': 2500, 'usage_30d': 15237, 'card_ok': True}, {'balance': 3582, 'replenished': 2, 'first_negative': None})], [({'balance': 26, 'charges': [150, 1200, 3000, 400], 'threshold': 1000, 'min_replenish': 2500, 'usage_30d': 19243, 'card_ok': False}, {'balance': -4724, 'replenished': 0, 'first_negative': 0}), ({'balance': 2453, 'charges': [650, 275], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 7993, 'card_ok': True}, {'balance': 1528, 'replenished': 0, 'first_negative': None}), ({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 1341, 'charges': [400, 3000, 275], 'threshold': 1000, 'min_replenish': 2500, 'usage_30d': 15381, 'card_ok': True}, {'balance': 1666, 'replenished': 1, 'first_negative': None}), ({'balance': -329, 'charges': [3000, 150, 1200, 400], 'threshold': 1500, 'min_replenish': 2500, 'usage_30d': 7527, 'card_ok': True}, {'balance': 2421, 'replenished': 3, 'first_negative': 0}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 552, 'charges': [275, 1200], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 7045, 'card_ok': True}, {'balance': 1077, 'replenished': 1, 'first_negative': None}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None})], [({'balance': 2290, 'charges': [1200, 650, 150, 1200, 400, 1200], 'threshold': 1500, 'min_replenish': 2500, 'usage_30d': 6040, 'card_ok': True}, {'balance': 2490, 'replenished': 2, 'first_negative': None}), ({'balance': 2621, 'charges': [3000, 150, 1200, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 17666, 'card_ok': True}, {'balance': 2621, 'replenished': 1, 'first_negative': None}), ({'balance': 2757, 'charges': [1200, 3000, 150], 'threshold': 1500, 'min_replenish': 1000, 'usage_30d': 14481, 'card_ok': False}, {'balance': -1593, 'replenished': 0, 'first_negative': 1}), ({'balance': 777, 'charges': [650, 3000, 400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 17628, 'card_ok': True}, {'balance': 1227, 'replenished': 1, 'first_negative': None}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None}), ({'balance': 1400, 'charges': [400, 150], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 3350, 'replenished': 1, 'first_negative': None}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 1586, 'charges': [650, 650, 275, 1200], 'threshold': 1500, 'min_replenish': 1000, 'usage_30d': 6189, 'card_ok': True}, {'balance': 2811, 'replenished': 2, 'first_negative': None})], [({'balance': 1234, 'charges': [650, 3000, 650, 275], 'threshold': 1000, 'min_replenish': 2000, 'usage_30d': 16752, 'card_ok': False}, {'balance': -3341, 'replenished': 0, 'first_negative': 1}), ({'balance': 400, 'charges': [400], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': 0, 'replenished': 0, 'first_negative': None}), ({'balance': 767, 'charges': [3000, 275, 275, 400, 3000, 3000, 275], 'threshold': 1500, 'min_replenish': 2000, 'usage_30d': 18564, 'card_ok': True}, {'balance': 5542, 'replenished': 3, 'first_negative': None}), ({'balance': 3840, 'charges': [275, 275, 1200, 400, 150], 'threshold': 1000, 'min_replenish': 2500, 'usage_30d': 4963, 'card_ok': True}, {'balance': 1540, 'replenished': 0, 'first_negative': None}), ({'balance': 300, 'charges': [400, 150, 275], 'threshold': 500, 'min_replenish': 1000, 'usage_30d': 0, 'card_ok': False}, {'balance': -525, 'replenished': 0, 'first_negative': 0}), ({'balance': 979, 'charges': [275, 275], 'threshold': 1000, 'min_replenish': 2500, 'usage_30d': 19904, 'card_ok': True}, {'balance': 5429, 'replenished': 1, 'first_negative': None}), ({'balance': 3921, 'charges': [275, 3000, 275], 'threshold': 1000, 'min_replenish': 2500, 'usage_30d': 12856, 'card_ok': True}, {'balance': 3871, 'replenished': 1, 'first_negative': None}), ({'balance': 1400, 'charges': [400], 'threshold': 1000, 'min_replenish': 1000, 'usage_30d': 9000, 'card_ok': True}, {'balance': 1000, 'replenished': 0, 'first_negative': None})]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('fee oracle' + ' %d' % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Prepaid toll account auto-replenishment returns a wrong result when the usage-based amount is floored to 500.

Input {balance, charges, threshold, min_replenish, usage_30d, card_ok}. The replenish amount is max(min_replenish, ceil(usage_30d/4) rounded up to a multiple of 500). After each charge, if the balance is strictly below threshold and the card works, one replenishment is added. first_negative is the index of the first charge after which the balance is negative (or null). Return {balance, replenished, first_negative}.

split: open-access