broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    T={'A':Fraction(1),'B':Fraction(115,100),'C':Fraction(130,100)}
    if x['territory'] not in T: return 'invalid territory'
    age=x['age']
    if age<16: return 'invalid age'
    if age<25: af=Fraction(150,100)
    elif age<65: af=Fraction(1)
    else: af=Fraction(120,100)
    sf=1+Fraction(5,100)*(x['symbol']-1)
    disc=Fraction(90,100) if x['cars']>=2 else Fraction(1)
    rated=x['base']*T[x['territory']]*af*sf
    rated=max(rated,30000)
    rated=rated*disc
    rated=int(rated+Fraction(1,2))
    return rated+x['fee']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['youthful band ends at 24', {'base': 54520, 'territory': 'B', 'age': 24, 'symbol': 10, 'cars': 1, 'fee': 0}, 136368], ['age 25 leaves youthful band', {'base': 48271, 'territory': 'A', 'age': 25, 'symbol': 2, 'cars': 1, 'fee': 1500}, 52185], ['senior boundary 65', {'base': 31490, 'territory': 'A', 'age': 65, 'symbol': 8, 'cars': 2, 'fee': 0}, 45912], ['two cars earn multi-car discount', {'base': 53546, 'territory': 'A', 'age': 55, 'symbol': 8, 'cars': 2, 'fee': 0}, 65058], ['single car control', {'base': 41604, 'territory': 'A', 'age': 56, 'symbol': 9, 'cars': 1, 'fee': 0}, 58246], ['discounted policy below minimum', {'base': 30977, 'territory': 'A', 'age': 39, 'symbol': 1, 'cars': 3, 'fee': 0}, 30000], ['unknown territory rejected', {'base': 78746, 'territory': 'Z', 'age': 40, 'symbol': 10, 'cars': 1, 'fee': 0}, 'invalid territory'], ['under-age applicant rejected', {'base': 84653, 'territory': 'C', 'age': 15, 'symbol': 2, 'cars': 1, 'fee': 2500}, 'invalid age'], ['random rating 0', {'base': 34126, 'territory': 'C', 'age': 33, 'symbol': 6, 'cars': 3, 'fee': 0}, 49909], ['random rating 1', {'base': 62350, 'territory': 'A', 'age': 16, 'symbol': 1, 'cars': 3, 'fee': 1500}, 85673], ['random rating 2', {'base': 95267, 'territory': 'A', 'age': 16, 'symbol': 6, 'cars': 2, 'fee': 2500}, 163263], ['random rating 3', {'base': 65141, 'territory': 'A', 'age': 16, 'symbol': 5, 'cars': 2, 'fee': 1500}, 107028], ['top symbol relativity', {'base': 50001, 'territory': 'B', 'age': 40, 'symbol': 10, 'cars': 1, 'fee': 2500}, 85877], ['half-cent rounds up', {'base': 60003, 'territory': 'B', 'age': 40, 'symbol': 1, 'cars': 1, 'fee': 2500}, 71503], ['sub-half cent rounds down', {'base': 40011, 'territory': 'B', 'age': 40, 'symbol': 1, 'cars': 1, 'fee': 2500}, 48513]], [['youthful band ends at 24', {'base': 65596, 'territory': 'B', 'age': 24, 'symbol': 4, 'cars': 1, 'fee': 1500}, 131626], ['age 25 leaves youthful band', {'base': 53332, 'territory': 'C', 'age': 25, 'symbol': 6, 'cars': 1, 'fee': 1500}, 88165], ['senior boundary 65', {'base': 72267, 'territory': 'B', 'age': 65, 'symbol': 9, 'cars': 2, 'fee': 0}, 125658], ['two cars earn multi-car discount', {'base': 46182, 'territory': 'A', 'age': 53, 'symbol': 1, 'cars': 2, 'fee': 2500}, 44064], ['single car control', {'base': 42325, 'territory': 'C', 'age': 57, 'symbol': 4, 'cars': 1, 'fee': 2500}, 65776], ['discounted policy below minimum', {'base': 31359, 'territory': 'A', 'age': 40, 'symbol': 1, 'cars': 3, 'fee': 1500}, 31500], ['unknown territory rejected', {'base': 70758, 'territory': 'Z', 'age': 40, 'symbol': 3, 'cars': 1, 'fee': 0}, 'invalid territory'], ['under-age applicant rejected', {'base': 74254, 'territory': 'B', 'age': 15, 'symbol': 2, 'cars': 1, 'fee': 0}, 'invalid age'], ['random rating 0', {'base': 35490, 'territory': 'C', 'age': 47, 'symbol': 10, 'cars': 1, 'fee': 0}, 66899], ['random rating 1', {'base': 93585, 'territory': 'B', 'age': 47, 'symbol': 2, 'cars': 1, 'fee': 0}, 113004], ['random rating 2', {'base': 54005, 'territory': 'C', 'age': 47, 'symbol': 8, 'cars': 1, 'fee': 0}, 94779], ['random rating 3', {'base': 35309, 'territory': 'C', 'age': 20, 'symbol': 6, 'cars': 2, 'fee': 1500}, 78959], ['top symbol relativity', {'base': 50002, 'territory': 'B', 'age': 40, 'symbol': 10, 'cars': 1, 'fee': 1500}, 84878], ['half-cent rounds up', {'base': 60007, 'territory': 'B', 'age': 40, 'symbol': 1, 'cars': 1, 'fee': 0}, 69008], ['sub-half cent rounds down', {'base': 40031, 'territory': 'B', 'age': 40, 'symbol': 1, 'cars': 1, 'fee': 0}, 46036]], [['youthful band ends at 24', {'base': 33706, 'territory': 'B', 'age': 24, 'symbol': 1, 'cars': 1, 'fee': 1500}, 59643], ['age 25 leaves youthful band', {'base': 47580, 'territory': 'C', 'age': 25, 'symbol': 4, 'cars': 1, 'fee': 1500}, 72632], ['senior boundary 65', {'base': 45782, 'territory': 'A', 'age': 65, 'symbol': 7, 'cars': 2, 'fee': 1500}, 65778], ['two cars earn multi-car discount', {'base': 69933, 'territory': 'C', 'age': 45, 'symbol': 3, 'cars': 2, 'fee': 2500}, 92504], ['single car control', {'base': 81532, 'territory': 'A', 'age': 57, 'symbol': 10, 'cars': 1, 'fee': 1500}, 119721], ['discounted policy below minimum', {'base': 31838, 'territory': 'A', 'age': 49, 'symbol': 1, 'cars': 3, 'fee': 1500}, 31500], ['unknown territory rejected', {'base': 23484, 'territory': 'Z', 'age': 40, 'symbol': 5, 'cars': 1, 'fee': 0}, 'invalid territory'], ['under-age applicant rejected', {'base': 20672, 'territory': 'A', 'age': 15, 'symbol': 8, 'cars': 1, 'fee': 1500}, 'invalid age'], ['random rating 0', {'base': 54283, 'territory': 'B', 'age': 16, 'symbol': 7, 'cars': 2, 'fee': 0}, 109557], ['random rating 1', {'base': 85283, 'territory': 'B', 'age': 33, 'symbol': 7, 'cars': 3, 'fee': 1500}, 116248], ['random rating 2', {'base': 97243, 'territory': 'A', 'age': 47, 'symbol': 10, 'cars': 2, 'fee': 1500}, 128402], ['random rating 3', {'base': 47342, 'territory': 'B', 'age': 70, 'symbol': 9, 'cars': 3, 'fee': 1500}, 83818], ['top symbol relativity', {'base': 50003, 'territory': 'B', 'age': 40, 'symbol': 10, 'cars': 1, 'fee': 2500}, 85880], ['half-cent rounds up', {'base': 60011, 'territory': 'B', 'age': 40, 'symbol': 1, 'cars': 1, 'fee': 0}, 69013], ['sub-half cent rounds down', {'base': 40051, 'territory': 'B', 'age': 40, 'symbol': 1, 'cars': 1, 'fee': 0}, 46059]], [['youthful band ends at 24', {'base': 49705, 'territory': 'B', 'age': 24, 'symbol': 10, 'cars': 1, 'fee': 0}, 124325], ['age 25 leaves youthful band', {'base': 77136, 'territory': 'B', 'age': 25, 'symbol': 9, 'cars': 1, 'fee': 2500}, 126689], ['senior boundary 65', {'base': 48566, 'territory': 'C', 'age': 65, 'symbol': 7, 'cars': 1, 'fee': 2500}, 100992], ['two cars earn multi-car discount', {'base': 86089, 'territory': 'C', 'age': 58, 'symbol': 4, 'cars': 2, 'fee': 2500}, 118333], ['single car control', {'base': 65782, 'territory': 'C', 'age': 60, 'symbol': 5, 'cars': 1, 'fee': 0}, 102620], ['discounted policy below minimum', {'base': 30193, 'territory': 'A', 'age': 34, 'symbol': 1, 'cars': 3, 'fee': 2500}, 32500], ['unknown territory rejected', {'base': 37853, 'territory': 'Z', 'age': 40, 'symbol': 5, 'cars': 1, 'fee': 2500}, 'invalid territory'], ['under-age applicant rejected', {'base': 85063, 'territory': 'C', 'age': 15, 'symbol': 9, 'cars': 1, 'fee': 1500}, 'invalid age'], ['random rating 0', {'base': 81605, 'territory': 'C', 'age': 70, 'symbol': 3, 'cars': 1, 'fee': 2500}, 142534], ['random rating 1', {'base': 50741, 'territory': 'C', 'age': 16, 'symbol': 9, 'cars': 1, 'fee': 0}, 138523], ['random rating 2', {'base': 88025, 'territory': 'B', 'age': 33, 'symbol': 5, 'cars': 1, 'fee': 0}, 121475], ['random rating 3', {'base': 60769, 'territory': 'C', 'age': 47, 'symbol': 8, 'cars': 3, 'fee': 1500}, 97485], ['top symbol relativity', {'base': 50004, 'territory': 'B', 'age': 40, 'symbol': 10, 'cars': 1, 'fee': 2500}, 85882], ['half-cent rounds up', {'base': 60015, 'territory': 'B', 'age': 40, 'symbol': 1, 'cars': 1, 'fee': 0}, 69017], ['sub-half cent rounds down', {'base': 40071, 'territory': 'B', 'age': 40, 'symbol': 1, 'cars': 1, 'fee': 2500}, 48582]], [['youthful band ends at 24', {'base': 83462, 'territory': 'C', 'age': 24, 'symbol': 4, 'cars': 1, 'fee': 0}, 187164], ['age 25 leaves youthful band', {'base': 23842, 'territory': 'A', 'age': 25, 'symbol': 10, 'cars': 1, 'fee': 2500}, 37071], ['senior boundary 65', {'base': 43695, 'territory': 'C', 'age': 65, 'symbol': 10, 'cars': 2, 'fee': 1500}, 90454], ['two cars earn multi-car discount', {'base': 87356, 'territory': 'A', 'age': 42, 'symbol': 8, 'cars': 2, 'fee': 2500}, 108638], ['single car control', {'base': 73244, 'territory': 'B', 'age': 41, 'symbol': 8, 'cars': 1, 'fee': 0}, 113711], ['discounted policy below minimum', {'base': 30044, 'territory': 'A', 'age': 31, 'symbol': 1, 'cars': 3, 'fee': 0}, 30000], ['unknown territory rejected', {'base': 50727, 'territory': 'Z', 'age': 40, 'symbol': 6, 'cars': 1, 'fee': 0}, 'invalid territory'], ['under-age applicant rejected', {'base': 35931, 'territory': 'A', 'age': 15, 'symbol': 3, 'cars': 1, 'fee': 1500}, 'invalid age'], ['random rating 0', {'base': 90411, 'territory': 'C', 'age': 70, 'symbol': 10, 'cars': 3, 'fee': 2500}, 186559], ['random rating 1', {'base': 60039, 'territory': 'C', 'age': 33, 'symbol': 10, 'cars': 2, 'fee': 2500}, 104356], ['random rating 2', {'base': 58926, 'territory': 'A', 'age': 47, 'symbol': 9, 'cars': 2, 'fee': 1500}, 75747], ['random rating 3', {'base': 56741, 'territory': 'B', 'age': 16, 'symbol': 6, 'cars': 1, 'fee': 2500}, 124848], ['top symbol relativity', {'base': 50005, 'territory': 'B', 'age': 40, 'symbol': 10, 'cars': 1, 'fee': 2500}, 85883], ['half-cent rounds up', {'base': 60019, 'territory': 'B', 'age': 40, 'symbol': 1, 'cars': 1, 'fee': 0}, 69022], ['sub-half cent rounds down', {'base': 40091, 'territory': 'B', 'age': 40, 'symbol': 1, 'cars': 1, 'fee': 2500}, 48605]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    T={'A':Fraction(1),'B':Fraction(115,100),'C':Fraction(130,100)}
    if x['territory'] not in T: return 'invalid territory'
    age=x['age']
    if age<16: return 'invalid age'
    if age<25: af=Fraction(150,100)
    elif age<65: af=Fraction(1)
    else: af=Fraction(120,100)
    sf=1+Fraction(5,100)*(x['symbol']-1)
    disc=Fraction(90,100) if x['cars']>=2 else Fraction(1)
    rated=x['base']*T[x['territory']]*af*sf
    rated=int(rated+Fraction(1,2))
    rated=max(rated,30000)
    rated=int(rated*disc)
    return rated+x['fee']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['youthful band ends at 24', {'base': 54520, 'territory': 'B', 'age': 24, 'symbol': 10, 'cars': 1, 'fee': 0}, 136368], ['age 25 leaves youthful band', {'base': 48271, 'territory': 'A', 'age': 25, 'symbol': 2, 'cars': 1, 'fee': 1500}, 52185], ['senior boundary 65', {'base': 31490, 'territory': 'A', 'age': 65, 'symbol': 8, 'cars': 2, 'fee': 0}, 45912], ['two cars earn multi-car discount', {'base': 53546, 'territory': 'A', 'age': 55, 'symbol': 8, 'cars': 2, 'fee': 0}, 65058], ['single car control', {'base': 41604, 'territory': 'A', 'age': 56, 'symbol': 9, 'cars': 1, 'fee': 0}, 58246], ['discounted policy below minimum', {'base': 30977, 'territory': 'A', 'age': 39, 'symbol': 1, 'cars': 3, 'fee': 0}, 30000], ['unknown territory rejected', {'base': 78746, 'territory': 'Z', 'age': 40, 'symbol': 10, 'cars': 1, 'fee': 0}, 'invalid territory'], ['under-age applicant rejected', {'base': 84653, 'territory': 'C', 'age': 15, 'symbol': 2, 'cars': 1, 'fee': 2500}, 'invalid age'], ['random rating 0', {'base': 34126, 'territory': 'C', 'age': 33, 'symbol': 6, 'cars': 3, 'fee': 0}, 49909], ['random rating 1', {'base': 62350, 'territory': 'A', 'age': 16, 'symbol': 1, 'cars': 3, 'fee': 1500}, 85673], ['random rating 2', {'base': 95267, 'territory': 'A', 'age': 16, 'symbol': 6, 'cars': 2, 'fee': 2500}, 163263], ['random rating 3', {'base': 65141, 'territory': 'A', 'age': 16, 'symbol': 5, 'cars': 2, 'fee': 1500}, 107028], ['top symbol relativity', {'base': 50001, 'territory': 'B', 'age': 40, 'symbol': 10, 'cars': 1, 'fee': 2500}, 85877], ['half-cent rounds up', {'base': 60003, 'territory': 'B', 'age': 40, 'symbol': 1, 'cars': 1, 'fee': 2500}, 71503], ['sub-half cent rounds down', {'base': 40011, 'territory': 'B', 'age': 40, 'symbol': 1, 'cars': 1, 'fee': 2500}, 48513]], [['youthful band ends at 24', {'base': 65596, 'territory': 'B', 'age': 24, 'symbol': 4, 'cars': 1, 'fee': 1500}, 131626], ['age 25 leaves youthful band', {'base': 53332, 'territory': 'C', 'age': 25, 'symbol': 6, 'cars': 1, 'fee': 1500}, 88165], ['senior boundary 65', {'base': 72267, 'territory': 'B', 'age': 65, 'symbol': 9, 'cars': 2, 'fee': 0}, 125658], ['two cars earn multi-car discount', {'base': 46182, 'territory': 'A', 'age': 53, 'symbol': 1, 'cars': 2, 'fee': 2500}, 44064], ['single car control', {'base': 42325, 'territory': 'C', 'age': 57, 'symbol': 4, 'cars': 1, 'fee': 2500}, 65776], ['discounted policy below minimum', {'base': 31359, 'territory': 'A', 'age': 40, 'symbol': 1, 'cars': 3, 'fee': 1500}, 31500], ['unknown territory rejected', {'base': 70758, 'territory': 'Z', 'age': 40, 'symbol': 3, 'cars': 1, 'fee': 0}, 'invalid territory'], ['under-age applicant rejected', {'base': 74254, 'territory': 'B', 'age': 15, 'symbol': 2, 'cars': 1, 'fee': 0}, 'invalid age'], ['random rating 0', {'base': 35490, 'territory': 'C', 'age': 47, 'symbol': 10, 'cars': 1, 'fee': 0}, 66899], ['random rating 1', {'base': 93585, 'territory': 'B', 'age': 47, 'symbol': 2, 'cars': 1, 'fee': 0}, 113004], ['random rating 2', {'base': 54005, 'territory': 'C', 'age': 47, 'symbol': 8, 'cars': 1, 'fee': 0}, 94779], ['random rating 3', {'base': 35309, 'territory': 'C', 'age': 20, 'symbol': 6, 'cars': 2, 'fee': 1500}, 78959], ['top symbol relativity', {'base': 50002, 'territory': 'B', 'age': 40, 'symbol': 10, 'cars': 1, 'fee': 1500}, 84878], ['half-cent rounds up', {'base': 60007, 'territory': 'B', 'age': 40, 'symbol': 1, 'cars': 1, 'fee': 0}, 69008], ['sub-half cent rounds down', {'base': 40031, 'territory': 'B', 'age': 40, 'symbol': 1, 'cars': 1, 'fee': 0}, 46036]], [['youthful band ends at 24', {'base': 33706, 'territory': 'B', 'age': 24, 'symbol': 1, 'cars': 1, 'fee': 1500}, 59643], ['age 25 leaves youthful band', {'base': 47580, 'territory': 'C', 'age': 25, 'symbol': 4, 'cars': 1, 'fee': 1500}, 72632], ['senior boundary 65', {'base': 45782, 'territory': 'A', 'age': 65, 'symbol': 7, 'cars': 2, 'fee': 1500}, 65778], ['two cars earn multi-car discount', {'base': 69933, 'territory': 'C', 'age': 45, 'symbol': 3, 'cars': 2, 'fee': 2500}, 92504], ['single car control', {'base': 81532, 'territory': 'A', 'age': 57, 'symbol': 10, 'cars': 1, 'fee': 1500}, 119721], ['discounted policy below minimum', {'base': 31838, 'territory': 'A', 'age': 49, 'symbol': 1, 'cars': 3, 'fee': 1500}, 31500], ['unknown territory rejected', {'base': 23484, 'territory': 'Z', 'age': 40, 'symbol': 5, 'cars': 1, 'fee': 0}, 'invalid territory'], ['under-age applicant rejected', {'base': 20672, 'territory': 'A', 'age': 15, 'symbol': 8, 'cars': 1, 'fee': 1500}, 'invalid age'], ['random rating 0', {'base': 54283, 'territory': 'B', 'age': 16, 'symbol': 7, 'cars': 2, 'fee': 0}, 109557], ['random rating 1', {'base': 85283, 'territory': 'B', 'age': 33, 'symbol': 7, 'cars': 3, 'fee': 1500}, 116248], ['random rating 2', {'base': 97243, 'territory': 'A', 'age': 47, 'symbol': 10, 'cars': 2, 'fee': 1500}, 128402], ['random rating 3', {'base': 47342, 'territory': 'B', 'age': 70, 'symbol': 9, 'cars': 3, 'fee': 1500}, 83818], ['top symbol relativity', {'base': 50003, 'territory': 'B', 'age': 40, 'symbol': 10, 'cars': 1, 'fee': 2500}, 85880], ['half-cent rounds up', {'base': 60011, 'territory': 'B', 'age': 40, 'symbol': 1, 'cars': 1, 'fee': 0}, 69013], ['sub-half cent rounds down', {'base': 40051, 'territory': 'B', 'age': 40, 'symbol': 1, 'cars': 1, 'fee': 0}, 46059]], [['youthful band ends at 24', {'base': 49705, 'territory': 'B', 'age': 24, 'symbol': 10, 'cars': 1, 'fee': 0}, 124325], ['age 25 leaves youthful band', {'base': 77136, 'territory': 'B', 'age': 25, 'symbol': 9, 'cars': 1, 'fee': 2500}, 126689], ['senior boundary 65', {'base': 48566, 'territory': 'C', 'age': 65, 'symbol': 7, 'cars': 1, 'fee': 2500}, 100992], ['two cars earn multi-car discount', {'base': 86089, 'territory': 'C', 'age': 58, 'symbol': 4, 'cars': 2, 'fee': 2500}, 118333], ['single car control', {'base': 65782, 'territory': 'C', 'age': 60, 'symbol': 5, 'cars': 1, 'fee': 0}, 102620], ['discounted policy below minimum', {'base': 30193, 'territory': 'A', 'age': 34, 'symbol': 1, 'cars': 3, 'fee': 2500}, 32500], ['unknown territory rejected', {'base': 37853, 'territory': 'Z', 'age': 40, 'symbol': 5, 'cars': 1, 'fee': 2500}, 'invalid territory'], ['under-age applicant rejected', {'base': 85063, 'territory': 'C', 'age': 15, 'symbol': 9, 'cars': 1, 'fee': 1500}, 'invalid age'], ['random rating 0', {'base': 81605, 'territory': 'C', 'age': 70, 'symbol': 3, 'cars': 1, 'fee': 2500}, 142534], ['random rating 1', {'base': 50741, 'territory': 'C', 'age': 16, 'symbol': 9, 'cars': 1, 'fee': 0}, 138523], ['random rating 2', {'base': 88025, 'territory': 'B', 'age': 33, 'symbol': 5, 'cars': 1, 'fee': 0}, 121475], ['random rating 3', {'base': 60769, 'territory': 'C', 'age': 47, 'symbol': 8, 'cars': 3, 'fee': 1500}, 97485], ['top symbol relativity', {'base': 50004, 'territory': 'B', 'age': 40, 'symbol': 10, 'cars': 1, 'fee': 2500}, 85882], ['half-cent rounds up', {'base': 60015, 'territory': 'B', 'age': 40, 'symbol': 1, 'cars': 1, 'fee': 0}, 69017], ['sub-half cent rounds down', {'base': 40071, 'territory': 'B', 'age': 40, 'symbol': 1, 'cars': 1, 'fee': 2500}, 48582]], [['youthful band ends at 24', {'base': 83462, 'territory': 'C', 'age': 24, 'symbol': 4, 'cars': 1, 'fee': 0}, 187164], ['age 25 leaves youthful band', {'base': 23842, 'territory': 'A', 'age': 25, 'symbol': 10, 'cars': 1, 'fee': 2500}, 37071], ['senior boundary 65', {'base': 43695, 'territory': 'C', 'age': 65, 'symbol': 10, 'cars': 2, 'fee': 1500}, 90454], ['two cars earn multi-car discount', {'base': 87356, 'territory': 'A', 'age': 42, 'symbol': 8, 'cars': 2, 'fee': 2500}, 108638], ['single car control', {'base': 73244, 'territory': 'B', 'age': 41, 'symbol': 8, 'cars': 1, 'fee': 0}, 113711], ['discounted policy below minimum', {'base': 30044, 'territory': 'A', 'age': 31, 'symbol': 1, 'cars': 3, 'fee': 0}, 30000], ['unknown territory rejected', {'base': 50727, 'territory': 'Z', 'age': 40, 'symbol': 6, 'cars': 1, 'fee': 0}, 'invalid territory'], ['under-age applicant rejected', {'base': 35931, 'territory': 'A', 'age': 15, 'symbol': 3, 'cars': 1, 'fee': 1500}, 'invalid age'], ['random rating 0', {'base': 90411, 'territory': 'C', 'age': 70, 'symbol': 10, 'cars': 3, 'fee': 2500}, 186559], ['random rating 1', {'base': 60039, 'territory': 'C', 'age': 33, 'symbol': 10, 'cars': 2, 'fee': 2500}, 104356], ['random rating 2', {'base': 58926, 'territory': 'A', 'age': 47, 'symbol': 9, 'cars': 2, 'fee': 1500}, 75747], ['random rating 3', {'base': 56741, 'territory': 'B', 'age': 16, 'symbol': 6, 'cars': 1, 'fee': 2500}, 124848], ['top symbol relativity', {'base': 50005, 'territory': 'B', 'age': 40, 'symbol': 10, 'cars': 1, 'fee': 2500}, 85883], ['half-cent rounds up', {'base': 60019, 'territory': 'B', 'age': 40, 'symbol': 1, 'cars': 1, 'fee': 0}, 69022], ['sub-half cent rounds down', {'base': 40091, 'territory': 'B', 'age': 40, 'symbol': 1, 'cars': 1, 'fee': 2500}, 48605]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A discounted small policy is charged less than the 30000-cent minimum premium.

Input dict base, territory (A/B/C factors 1.00/1.15/1.30, else 'invalid territory'), age (<16 'invalid age'; 16-24 factor 1.50; 25-64 1.00; 65+ 1.20), symbol s with factor 1+0.05*(s-1), cars (>=2 gives 10% discount), fee. Rated premium = base*factors*discount rounded half-up to a cent once, then a 30000-cent minimum, then the fee is added.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    E=x['expected']
    if E<=0: return 'invalid expected'
    S=x['split']; W=Fraction(x['weight'],1000)
    vals=[Fraction(amt)*Fraction(70,100) if kind=='med' else Fraction(amt) for amt,kind in x['claims']]
    ap=sum(min(v,S) for v in vals)
    ae=sum(vals)-ap
    ep=Fraction(E*x['primary_ratio'],1000); ee=E-ep
    B=x['ballast']
    mod=(ap+W*ae+(1-W)*ee+B)/(E+B)
    return int(mod*100+Fraction(1,2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['mixed claim history 0', {'expected': 311400, 'split': 17000, 'weight': 150, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[33740, 'ind'], [37448, 'ind'], [55230, 'ind'], [10817, 'med']]}, 78], ['mixed claim history 1', {'expected': 767200, 'split': 17000, 'weight': 150, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[42590, 'med'], [38435, 'med'], [27276, 'ind'], [26563, 'med'], [15138, 'ind'], [4744, 'ind'], [87257, 'ind'], [10244, 'med']]}, 75], ['mixed claim history 2', {'expected': 858400, 'split': 17000, 'weight': 150, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[54743, 'med'], [57687, 'ind'], [5771, 'med'], [32069, 'ind'], [9463, 'med']]}, 62], ['mixed claim history 3', {'expected': 677800, 'split': 17000, 'weight': 250, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[20283, 'ind'], [10778, 'ind'], [6643, 'med'], [45395, 'med'], [59048, 'ind'], [5648, 'med']]}, 64], ['mixed claim history 4', {'expected': 650900, 'split': 17000, 'weight': 200, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[37467, 'ind'], [13425, 'med'], [17798, 'ind'], [25433, 'ind'], [13608, 'med']]}, 63], ['mixed claim history 5', {'expected': 447400, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[41535, 'ind'], [48038, 'ind'], [32890, 'ind'], [5200, 'med']]}, 75], ['large medical-only claim', {'expected': 323600, 'split': 17000, 'weight': 250, 'primary_ratio': 350, 'ballast': 50000, 'claims': [[101990, 'med'], [5314, 'ind']]}, 62], ['claim free risk', {'expected': 867900, 'split': 17000, 'weight': 250, 'primary_ratio': 400, 'ballast': 50000, 'claims': []}, 48], ['invalid expected losses', {'expected': 0, 'split': 17000, 'weight': 150, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[1000, 'ind']]}, 'invalid expected'], ['mod rounding near half point', {'expected': 797000, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[11195, 'ind'], [36197, 'ind']]}, 63]], [['mixed claim history 0', {'expected': 316700, 'split': 17000, 'weight': 250, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[10286, 'med'], [40310, 'med'], [26393, 'ind'], [5424, 'med']]}, 65], ['mixed claim history 1', {'expected': 859500, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[23316, 'med'], [15025, 'ind'], [57735, 'ind'], [16008, 'ind'], [45146, 'ind'], [11487, 'med'], [60418, 'ind'], [6233, 'med']]}, 72], ['mixed claim history 2', {'expected': 896000, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 50000, 'claims': [[21038, 'ind'], [5062, 'ind'], [14527, 'med'], [1264, 'med'], [4935, 'med'], [56017, 'ind'], [59572, 'ind'], [6562, 'med']]}, 67], ['mixed claim history 3', {'expected': 779700, 'split': 17000, 'weight': 250, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[57322, 'ind'], [16107, 'med'], [20840, 'med'], [82520, 'ind'], [5448, 'med']]}, 59], ['mixed claim history 4', {'expected': 827000, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[31790, 'ind'], [13488, 'ind'], [71208, 'ind'], [13222, 'med']]}, 67], ['mixed claim history 5', {'expected': 464000, 'split': 17000, 'weight': 150, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[17834, 'ind'], [18093, 'med'], [30643, 'med'], [29993, 'med'], [55402, 'med'], [31809, 'ind'], [13749, 'med']]}, 80], ['large medical-only claim', {'expected': 469100, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 50000, 'claims': [[101036, 'med'], [5613, 'ind']]}, 65], ['claim free risk', {'expected': 687800, 'split': 17000, 'weight': 200, 'primary_ratio': 400, 'ballast': 80000, 'claims': []}, 53], ['invalid expected losses', {'expected': 0, 'split': 17000, 'weight': 200, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[1000, 'ind']]}, 'invalid expected'], ['mod rounding near half point', {'expected': 721000, 'split': 17000, 'weight': 250, 'primary_ratio': 350, 'ballast': 50000, 'claims': [[15423, 'ind'], [31956, 'ind']]}, 57]], [['mixed claim history 0', {'expected': 610400, 'split': 17000, 'weight': 150, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[53344, 'ind'], [48923, 'ind'], [52350, 'ind'], [50819, 'ind'], [10135, 'ind'], [12464, 'ind'], [67060, 'ind'], [12311, 'med']]}, 77], ['mixed claim history 1', {'expected': 402300, 'split': 17000, 'weight': 250, 'primary_ratio': 400, 'ballast': 50000, 'claims': [[17334, 'ind'], [22438, 'ind'], [22151, 'med'], [26026, 'ind'], [7894, 'med']]}, 65], ['mixed claim history 2', {'expected': 498400, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 50000, 'claims': [[48132, 'ind'], [8715, 'ind'], [59441, 'ind'], [20248, 'med'], [17905, 'ind'], [58937, 'med'], [80627, 'ind'], [7990, 'med']]}, 82], ['mixed claim history 3', {'expected': 464700, 'split': 17000, 'weight': 250, 'primary_ratio': 300, 'ballast': 50000, 'claims': [[13610, 'ind'], [3088, 'ind'], [43730, 'ind'], [8434, 'med']]}, 65], ['mixed claim history 4', {'expected': 879300, 'split': 17000, 'weight': 200, 'primary_ratio': 350, 'ballast': 50000, 'claims': [[13389, 'ind'], [32420, 'med'], [20542, 'ind'], [47517, 'ind'], [16287, 'ind'], [82017, 'ind'], [9410, 'med']]}, 67], ['mixed claim history 5', {'expected': 652900, 'split': 17000, 'weight': 200, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[22810, 'ind'], [40463, 'ind'], [74251, 'ind'], [9218, 'med']]}, 67], ['large medical-only claim', {'expected': 703800, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 50000, 'claims': [[84297, 'med'], [2962, 'ind']]}, 62], ['claim free risk', {'expected': 479000, 'split': 17000, 'weight': 250, 'primary_ratio': 300, 'ballast': 80000, 'claims': []}, 59], ['invalid expected losses', {'expected': 0, 'split': 17000, 'weight': 150, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[1000, 'ind']]}, 'invalid expected'], ['mod rounding near half point', {'expected': 447500, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 50000, 'claims': [[11462, 'ind'], [38751, 'ind']]}, 66]], [['mixed claim history 0', {'expected': 688800, 'split': 17000, 'weight': 200, 'primary_ratio': 400, 'ballast': 50000, 'claims': [[56711, 'ind'], [12536, 'med'], [30221, 'ind'], [51849, 'ind'], [13637, 'med']]}, 62], ['mixed claim history 1', {'expected': 402400, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[14109, 'med'], [42085, 'ind'], [59677, 'ind'], [55680, 'ind'], [6934, 'med']]}, 78], ['mixed claim history 2', {'expected': 773600, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[11209, 'med'], [26799, 'ind'], [10934, 'med'], [16129, 'ind'], [11873, 'ind'], [52155, 'ind'], [10727, 'med']]}, 70], ['mixed claim history 3', {'expected': 741200, 'split': 17000, 'weight': 250, 'primary_ratio': 300, 'ballast': 50000, 'claims': [[53124, 'ind'], [16325, 'ind'], [4833, 'ind'], [21033, 'ind'], [6837, 'ind'], [38580, 'ind'], [55554, 'ind'], [13784, 'med']]}, 71], ['mixed claim history 4', {'expected': 331500, 'split': 17000, 'weight': 250, 'primary_ratio': 300, 'ballast': 50000, 'claims': [[10786, 'ind'], [17213, 'med'], [39824, 'med'], [24282, 'ind'], [51513, 'ind'], [63075, 'ind'], [10156, 'med']]}, 86], ['mixed claim history 5', {'expected': 409600, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[54286, 'ind'], [35703, 'ind'], [30503, 'med'], [59058, 'ind'], [56149, 'med'], [41950, 'ind'], [41088, 'ind'], [8047, 'med']]}, 92], ['large medical-only claim', {'expected': 831400, 'split': 17000, 'weight': 200, 'primary_ratio': 400, 'ballast': 50000, 'claims': [[107249, 'med'], [3434, 'ind']]}, 54], ['claim free risk', {'expected': 597500, 'split': 17000, 'weight': 250, 'primary_ratio': 350, 'ballast': 80000, 'claims': []}, 55], ['invalid expected losses', {'expected': 0, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 50000, 'claims': [[1000, 'ind']]}, 'invalid expected'], ['mod rounding near half point', {'expected': 770300, 'split': 17000, 'weight': 200, 'primary_ratio': 400, 'ballast': 50000, 'claims': [[13951, 'ind'], [35547, 'ind']]}, 55]], [['mixed claim history 0', {'expected': 303600, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[20599, 'ind'], [56506, 'ind'], [28670, 'ind'], [70657, 'ind'], [13633, 'med']]}, 88], ['mixed claim history 1', {'expected': 729600, 'split': 17000, 'weight': 250, 'primary_ratio': 400, 'ballast': 50000, 'claims': [[14990, 'med'], [18865, 'ind'], [35152, 'ind'], [37220, 'med'], [45354, 'ind'], [6673, 'med']]}, 59], ['mixed claim history 2', {'expected': 697600, 'split': 17000, 'weight': 200, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[36216, 'ind'], [18993, 'ind'], [14909, 'ind'], [50234, 'med'], [88465, 'ind'], [7853, 'med']]}, 70], ['mixed claim history 3', {'expected': 334500, 'split': 17000, 'weight': 150, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[8211, 'ind'], [19267, 'med'], [4256, 'med'], [47071, 'ind'], [74176, 'ind'], [8958, 'med']]}, 83], ['mixed claim history 4', {'expected': 758400, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[24450, 'med'], [45271, 'ind'], [32248, 'med'], [53086, 'ind'], [11516, 'med']]}, 67], ['mixed claim history 5', {'expected': 883600, 'split': 17000, 'weight': 200, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[42495, 'ind'], [9679, 'ind'], [36464, 'ind'], [26823, 'ind'], [63484, 'ind'], [12267, 'med']]}, 63], ['large medical-only claim', {'expected': 318100, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 50000, 'claims': [[102133, 'med'], [5058, 'ind']]}, 68], ['claim free risk', {'expected': 634700, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 80000, 'claims': []}, 60], ['invalid expected losses', {'expected': 0, 'split': 17000, 'weight': 250, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[1000, 'ind']]}, 'invalid expected'], ['mod rounding near half point', {'expected': 457400, 'split': 17000, 'weight': 200, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[12750, 'ind'], [32633, 'ind']]}, 65]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    E=x['expected']
    if E<=0: return 'invalid expected'
    S=x['split']; W=Fraction(x['weight'],1000)
    vals=[Fraction(amt)*Fraction(30,100) if kind=='ind' else Fraction(amt) for amt,kind in x['claims']]
    ap=sum(min(v,S) for v in vals)
    ae=sum(vals)-ap
    ep=Fraction(E*x['primary_ratio'],1000); ee=E-ep
    B=x['ballast']
    mod=(ap+W*ae+(1-W)*ee+B)/(E+B)
    return int(mod*100+Fraction(1,2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['mixed claim history 0', {'expected': 311400, 'split': 17000, 'weight': 150, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[33740, 'ind'], [37448, 'ind'], [55230, 'ind'], [10817, 'med']]}, 78], ['mixed claim history 1', {'expected': 767200, 'split': 17000, 'weight': 150, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[42590, 'med'], [38435, 'med'], [27276, 'ind'], [26563, 'med'], [15138, 'ind'], [4744, 'ind'], [87257, 'ind'], [10244, 'med']]}, 75], ['mixed claim history 2', {'expected': 858400, 'split': 17000, 'weight': 150, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[54743, 'med'], [57687, 'ind'], [5771, 'med'], [32069, 'ind'], [9463, 'med']]}, 62], ['mixed claim history 3', {'expected': 677800, 'split': 17000, 'weight': 250, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[20283, 'ind'], [10778, 'ind'], [6643, 'med'], [45395, 'med'], [59048, 'ind'], [5648, 'med']]}, 64], ['mixed claim history 4', {'expected': 650900, 'split': 17000, 'weight': 200, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[37467, 'ind'], [13425, 'med'], [17798, 'ind'], [25433, 'ind'], [13608, 'med']]}, 63], ['mixed claim history 5', {'expected': 447400, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[41535, 'ind'], [48038, 'ind'], [32890, 'ind'], [5200, 'med']]}, 75], ['large medical-only claim', {'expected': 323600, 'split': 17000, 'weight': 250, 'primary_ratio': 350, 'ballast': 50000, 'claims': [[101990, 'med'], [5314, 'ind']]}, 62], ['claim free risk', {'expected': 867900, 'split': 17000, 'weight': 250, 'primary_ratio': 400, 'ballast': 50000, 'claims': []}, 48], ['invalid expected losses', {'expected': 0, 'split': 17000, 'weight': 150, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[1000, 'ind']]}, 'invalid expected'], ['mod rounding near half point', {'expected': 797000, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[11195, 'ind'], [36197, 'ind']]}, 63]], [['mixed claim history 0', {'expected': 316700, 'split': 17000, 'weight': 250, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[10286, 'med'], [40310, 'med'], [26393, 'ind'], [5424, 'med']]}, 65], ['mixed claim history 1', {'expected': 859500, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[23316, 'med'], [15025, 'ind'], [57735, 'ind'], [16008, 'ind'], [45146, 'ind'], [11487, 'med'], [60418, 'ind'], [6233, 'med']]}, 72], ['mixed claim history 2', {'expected': 896000, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 50000, 'claims': [[21038, 'ind'], [5062, 'ind'], [14527, 'med'], [1264, 'med'], [4935, 'med'], [56017, 'ind'], [59572, 'ind'], [6562, 'med']]}, 67], ['mixed claim history 3', {'expected': 779700, 'split': 17000, 'weight': 250, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[57322, 'ind'], [16107, 'med'], [20840, 'med'], [82520, 'ind'], [5448, 'med']]}, 59], ['mixed claim history 4', {'expected': 827000, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[31790, 'ind'], [13488, 'ind'], [71208, 'ind'], [13222, 'med']]}, 67], ['mixed claim history 5', {'expected': 464000, 'split': 17000, 'weight': 150, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[17834, 'ind'], [18093, 'med'], [30643, 'med'], [29993, 'med'], [55402, 'med'], [31809, 'ind'], [13749, 'med']]}, 80], ['large medical-only claim', {'expected': 469100, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 50000, 'claims': [[101036, 'med'], [5613, 'ind']]}, 65], ['claim free risk', {'expected': 687800, 'split': 17000, 'weight': 200, 'primary_ratio': 400, 'ballast': 80000, 'claims': []}, 53], ['invalid expected losses', {'expected': 0, 'split': 17000, 'weight': 200, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[1000, 'ind']]}, 'invalid expected'], ['mod rounding near half point', {'expected': 721000, 'split': 17000, 'weight': 250, 'primary_ratio': 350, 'ballast': 50000, 'claims': [[15423, 'ind'], [31956, 'ind']]}, 57]], [['mixed claim history 0', {'expected': 610400, 'split': 17000, 'weight': 150, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[53344, 'ind'], [48923, 'ind'], [52350, 'ind'], [50819, 'ind'], [10135, 'ind'], [12464, 'ind'], [67060, 'ind'], [12311, 'med']]}, 77], ['mixed claim history 1', {'expected': 402300, 'split': 17000, 'weight': 250, 'primary_ratio': 400, 'ballast': 50000, 'claims': [[17334, 'ind'], [22438, 'ind'], [22151, 'med'], [26026, 'ind'], [7894, 'med']]}, 65], ['mixed claim history 2', {'expected': 498400, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 50000, 'claims': [[48132, 'ind'], [8715, 'ind'], [59441, 'ind'], [20248, 'med'], [17905, 'ind'], [58937, 'med'], [80627, 'ind'], [7990, 'med']]}, 82], ['mixed claim history 3', {'expected': 464700, 'split': 17000, 'weight': 250, 'primary_ratio': 300, 'ballast': 50000, 'claims': [[13610, 'ind'], [3088, 'ind'], [43730, 'ind'], [8434, 'med']]}, 65], ['mixed claim history 4', {'expected': 879300, 'split': 17000, 'weight': 200, 'primary_ratio': 350, 'ballast': 50000, 'claims': [[13389, 'ind'], [32420, 'med'], [20542, 'ind'], [47517, 'ind'], [16287, 'ind'], [82017, 'ind'], [9410, 'med']]}, 67], ['mixed claim history 5', {'expected': 652900, 'split': 17000, 'weight': 200, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[22810, 'ind'], [40463, 'ind'], [74251, 'ind'], [9218, 'med']]}, 67], ['large medical-only claim', {'expected': 703800, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 50000, 'claims': [[84297, 'med'], [2962, 'ind']]}, 62], ['claim free risk', {'expected': 479000, 'split': 17000, 'weight': 250, 'primary_ratio': 300, 'ballast': 80000, 'claims': []}, 59], ['invalid expected losses', {'expected': 0, 'split': 17000, 'weight': 150, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[1000, 'ind']]}, 'invalid expected'], ['mod rounding near half point', {'expected': 447500, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 50000, 'claims': [[11462, 'ind'], [38751, 'ind']]}, 66]], [['mixed claim history 0', {'expected': 688800, 'split': 17000, 'weight': 200, 'primary_ratio': 400, 'ballast': 50000, 'claims': [[56711, 'ind'], [12536, 'med'], [30221, 'ind'], [51849, 'ind'], [13637, 'med']]}, 62], ['mixed claim history 1', {'expected': 402400, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[14109, 'med'], [42085, 'ind'], [59677, 'ind'], [55680, 'ind'], [6934, 'med']]}, 78], ['mixed claim history 2', {'expected': 773600, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[11209, 'med'], [26799, 'ind'], [10934, 'med'], [16129, 'ind'], [11873, 'ind'], [52155, 'ind'], [10727, 'med']]}, 70], ['mixed claim history 3', {'expected': 741200, 'split': 17000, 'weight': 250, 'primary_ratio': 300, 'ballast': 50000, 'claims': [[53124, 'ind'], [16325, 'ind'], [4833, 'ind'], [21033, 'ind'], [6837, 'ind'], [38580, 'ind'], [55554, 'ind'], [13784, 'med']]}, 71], ['mixed claim history 4', {'expected': 331500, 'split': 17000, 'weight': 250, 'primary_ratio': 300, 'ballast': 50000, 'claims': [[10786, 'ind'], [17213, 'med'], [39824, 'med'], [24282, 'ind'], [51513, 'ind'], [63075, 'ind'], [10156, 'med']]}, 86], ['mixed claim history 5', {'expected': 409600, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[54286, 'ind'], [35703, 'ind'], [30503, 'med'], [59058, 'ind'], [56149, 'med'], [41950, 'ind'], [41088, 'ind'], [8047, 'med']]}, 92], ['large medical-only claim', {'expected': 831400, 'split': 17000, 'weight': 200, 'primary_ratio': 400, 'ballast': 50000, 'claims': [[107249, 'med'], [3434, 'ind']]}, 54], ['claim free risk', {'expected': 597500, 'split': 17000, 'weight': 250, 'primary_ratio': 350, 'ballast': 80000, 'claims': []}, 55], ['invalid expected losses', {'expected': 0, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 50000, 'claims': [[1000, 'ind']]}, 'invalid expected'], ['mod rounding near half point', {'expected': 770300, 'split': 17000, 'weight': 200, 'primary_ratio': 400, 'ballast': 50000, 'claims': [[13951, 'ind'], [35547, 'ind']]}, 55]], [['mixed claim history 0', {'expected': 303600, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[20599, 'ind'], [56506, 'ind'], [28670, 'ind'], [70657, 'ind'], [13633, 'med']]}, 88], ['mixed claim history 1', {'expected': 729600, 'split': 17000, 'weight': 250, 'primary_ratio': 400, 'ballast': 50000, 'claims': [[14990, 'med'], [18865, 'ind'], [35152, 'ind'], [37220, 'med'], [45354, 'ind'], [6673, 'med']]}, 59], ['mixed claim history 2', {'expected': 697600, 'split': 17000, 'weight': 200, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[36216, 'ind'], [18993, 'ind'], [14909, 'ind'], [50234, 'med'], [88465, 'ind'], [7853, 'med']]}, 70], ['mixed claim history 3', {'expected': 334500, 'split': 17000, 'weight': 150, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[8211, 'ind'], [19267, 'med'], [4256, 'med'], [47071, 'ind'], [74176, 'ind'], [8958, 'med']]}, 83], ['mixed claim history 4', {'expected': 758400, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[24450, 'med'], [45271, 'ind'], [32248, 'med'], [53086, 'ind'], [11516, 'med']]}, 67], ['mixed claim history 5', {'expected': 883600, 'split': 17000, 'weight': 200, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[42495, 'ind'], [9679, 'ind'], [36464, 'ind'], [26823, 'ind'], [63484, 'ind'], [12267, 'med']]}, 63], ['large medical-only claim', {'expected': 318100, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 50000, 'claims': [[102133, 'med'], [5058, 'ind']]}, 68], ['claim free risk', {'expected': 634700, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 80000, 'claims': []}, 60], ['invalid expected losses', {'expected': 0, 'split': 17000, 'weight': 250, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[1000, 'ind']]}, 'invalid expected'], ['mod rounding near half point', {'expected': 457400, 'split': 17000, 'weight': 200, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[12750, 'ind'], [32633, 'ind']]}, 65]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Employers with medical-only claims receive a higher mod than the plan allows.

Input expected (cents, >0 else 'invalid expected'), split, weight W (per mille), primary_ratio (per mille of expected that is primary), ballast B, claims [[amount, 'ind'|'med']]. Medical-only claims count at 30%. Each claim splits into primary min(v,split) and excess. mod=(Ap+W*Ae+(1-W)*Ee+B)/(E+B), returned in hundredths rounded half-up.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    E=x['expected']
    if E<=0: return 'invalid expected'
    S=x['split']; W=Fraction(x['weight'],1000)
    vals=[Fraction(amt)*Fraction(30,100) if kind=='med' else Fraction(amt) for amt,kind in x['claims']]
    ap=min(sum(vals),S)
    ae=sum(vals)-ap
    ep=Fraction(E*x['primary_ratio'],1000); ee=E-ep
    B=x['ballast']
    mod=(ap+W*ae+(1-W)*ee+B)/(E+B)
    return int(mod*100+Fraction(1,2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['mixed claim history 0', {'expected': 311400, 'split': 17000, 'weight': 150, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[33740, 'ind'], [37448, 'ind'], [55230, 'ind'], [10817, 'med']]}, 78], ['mixed claim history 1', {'expected': 767200, 'split': 17000, 'weight': 150, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[42590, 'med'], [38435, 'med'], [27276, 'ind'], [26563, 'med'], [15138, 'ind'], [4744, 'ind'], [87257, 'ind'], [10244, 'med']]}, 75], ['mixed claim history 2', {'expected': 858400, 'split': 17000, 'weight': 150, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[54743, 'med'], [57687, 'ind'], [5771, 'med'], [32069, 'ind'], [9463, 'med']]}, 62], ['mixed claim history 3', {'expected': 677800, 'split': 17000, 'weight': 250, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[20283, 'ind'], [10778, 'ind'], [6643, 'med'], [45395, 'med'], [59048, 'ind'], [5648, 'med']]}, 64], ['mixed claim history 4', {'expected': 650900, 'split': 17000, 'weight': 200, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[37467, 'ind'], [13425, 'med'], [17798, 'ind'], [25433, 'ind'], [13608, 'med']]}, 63], ['mixed claim history 5', {'expected': 447400, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[41535, 'ind'], [48038, 'ind'], [32890, 'ind'], [5200, 'med']]}, 75], ['large medical-only claim', {'expected': 323600, 'split': 17000, 'weight': 250, 'primary_ratio': 350, 'ballast': 50000, 'claims': [[101990, 'med'], [5314, 'ind']]}, 62], ['claim free risk', {'expected': 867900, 'split': 17000, 'weight': 250, 'primary_ratio': 400, 'ballast': 50000, 'claims': []}, 48], ['invalid expected losses', {'expected': 0, 'split': 17000, 'weight': 150, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[1000, 'ind']]}, 'invalid expected'], ['mod rounding near half point', {'expected': 797000, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[11195, 'ind'], [36197, 'ind']]}, 63]], [['mixed claim history 0', {'expected': 316700, 'split': 17000, 'weight': 250, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[10286, 'med'], [40310, 'med'], [26393, 'ind'], [5424, 'med']]}, 65], ['mixed claim history 1', {'expected': 859500, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[23316, 'med'], [15025, 'ind'], [57735, 'ind'], [16008, 'ind'], [45146, 'ind'], [11487, 'med'], [60418, 'ind'], [6233, 'med']]}, 72], ['mixed claim history 2', {'expected': 896000, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 50000, 'claims': [[21038, 'ind'], [5062, 'ind'], [14527, 'med'], [1264, 'med'], [4935, 'med'], [56017, 'ind'], [59572, 'ind'], [6562, 'med']]}, 67], ['mixed claim history 3', {'expected': 779700, 'split': 17000, 'weight': 250, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[57322, 'ind'], [16107, 'med'], [20840, 'med'], [82520, 'ind'], [5448, 'med']]}, 59], ['mixed claim history 4', {'expected': 827000, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[31790, 'ind'], [13488, 'ind'], [71208, 'ind'], [13222, 'med']]}, 67], ['mixed claim history 5', {'expected': 464000, 'split': 17000, 'weight': 150, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[17834, 'ind'], [18093, 'med'], [30643, 'med'], [29993, 'med'], [55402, 'med'], [31809, 'ind'], [13749, 'med']]}, 80], ['large medical-only claim', {'expected': 469100, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 50000, 'claims': [[101036, 'med'], [5613, 'ind']]}, 65], ['claim free risk', {'expected': 687800, 'split': 17000, 'weight': 200, 'primary_ratio': 400, 'ballast': 80000, 'claims': []}, 53], ['invalid expected losses', {'expected': 0, 'split': 17000, 'weight': 200, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[1000, 'ind']]}, 'invalid expected'], ['mod rounding near half point', {'expected': 721000, 'split': 17000, 'weight': 250, 'primary_ratio': 350, 'ballast': 50000, 'claims': [[15423, 'ind'], [31956, 'ind']]}, 57]], [['mixed claim history 0', {'expected': 610400, 'split': 17000, 'weight': 150, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[53344, 'ind'], [48923, 'ind'], [52350, 'ind'], [50819, 'ind'], [10135, 'ind'], [12464, 'ind'], [67060, 'ind'], [12311, 'med']]}, 77], ['mixed claim history 1', {'expected': 402300, 'split': 17000, 'weight': 250, 'primary_ratio': 400, 'ballast': 50000, 'claims': [[17334, 'ind'], [22438, 'ind'], [22151, 'med'], [26026, 'ind'], [7894, 'med']]}, 65], ['mixed claim history 2', {'expected': 498400, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 50000, 'claims': [[48132, 'ind'], [8715, 'ind'], [59441, 'ind'], [20248, 'med'], [17905, 'ind'], [58937, 'med'], [80627, 'ind'], [7990, 'med']]}, 82], ['mixed claim history 3', {'expected': 464700, 'split': 17000, 'weight': 250, 'primary_ratio': 300, 'ballast': 50000, 'claims': [[13610, 'ind'], [3088, 'ind'], [43730, 'ind'], [8434, 'med']]}, 65], ['mixed claim history 4', {'expected': 879300, 'split': 17000, 'weight': 200, 'primary_ratio': 350, 'ballast': 50000, 'claims': [[13389, 'ind'], [32420, 'med'], [20542, 'ind'], [47517, 'ind'], [16287, 'ind'], [82017, 'ind'], [9410, 'med']]}, 67], ['mixed claim history 5', {'expected': 652900, 'split': 17000, 'weight': 200, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[22810, 'ind'], [40463, 'ind'], [74251, 'ind'], [9218, 'med']]}, 67], ['large medical-only claim', {'expected': 703800, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 50000, 'claims': [[84297, 'med'], [2962, 'ind']]}, 62], ['claim free risk', {'expected': 479000, 'split': 17000, 'weight': 250, 'primary_ratio': 300, 'ballast': 80000, 'claims': []}, 59], ['invalid expected losses', {'expected': 0, 'split': 17000, 'weight': 150, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[1000, 'ind']]}, 'invalid expected'], ['mod rounding near half point', {'expected': 447500, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 50000, 'claims': [[11462, 'ind'], [38751, 'ind']]}, 66]], [['mixed claim history 0', {'expected': 688800, 'split': 17000, 'weight': 200, 'primary_ratio': 400, 'ballast': 50000, 'claims': [[56711, 'ind'], [12536, 'med'], [30221, 'ind'], [51849, 'ind'], [13637, 'med']]}, 62], ['mixed claim history 1', {'expected': 402400, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[14109, 'med'], [42085, 'ind'], [59677, 'ind'], [55680, 'ind'], [6934, 'med']]}, 78], ['mixed claim history 2', {'expected': 773600, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[11209, 'med'], [26799, 'ind'], [10934, 'med'], [16129, 'ind'], [11873, 'ind'], [52155, 'ind'], [10727, 'med']]}, 70], ['mixed claim history 3', {'expected': 741200, 'split': 17000, 'weight': 250, 'primary_ratio': 300, 'ballast': 50000, 'claims': [[53124, 'ind'], [16325, 'ind'], [4833, 'ind'], [21033, 'ind'], [6837, 'ind'], [38580, 'ind'], [55554, 'ind'], [13784, 'med']]}, 71], ['mixed claim history 4', {'expected': 331500, 'split': 17000, 'weight': 250, 'primary_ratio': 300, 'ballast': 50000, 'claims': [[10786, 'ind'], [17213, 'med'], [39824, 'med'], [24282, 'ind'], [51513, 'ind'], [63075, 'ind'], [10156, 'med']]}, 86], ['mixed claim history 5', {'expected': 409600, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[54286, 'ind'], [35703, 'ind'], [30503, 'med'], [59058, 'ind'], [56149, 'med'], [41950, 'ind'], [41088, 'ind'], [8047, 'med']]}, 92], ['large medical-only claim', {'expected': 831400, 'split': 17000, 'weight': 200, 'primary_ratio': 400, 'ballast': 50000, 'claims': [[107249, 'med'], [3434, 'ind']]}, 54], ['claim free risk', {'expected': 597500, 'split': 17000, 'weight': 250, 'primary_ratio': 350, 'ballast': 80000, 'claims': []}, 55], ['invalid expected losses', {'expected': 0, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 50000, 'claims': [[1000, 'ind']]}, 'invalid expected'], ['mod rounding near half point', {'expected': 770300, 'split': 17000, 'weight': 200, 'primary_ratio': 400, 'ballast': 50000, 'claims': [[13951, 'ind'], [35547, 'ind']]}, 55]], [['mixed claim history 0', {'expected': 303600, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[20599, 'ind'], [56506, 'ind'], [28670, 'ind'], [70657, 'ind'], [13633, 'med']]}, 88], ['mixed claim history 1', {'expected': 729600, 'split': 17000, 'weight': 250, 'primary_ratio': 400, 'ballast': 50000, 'claims': [[14990, 'med'], [18865, 'ind'], [35152, 'ind'], [37220, 'med'], [45354, 'ind'], [6673, 'med']]}, 59], ['mixed claim history 2', {'expected': 697600, 'split': 17000, 'weight': 200, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[36216, 'ind'], [18993, 'ind'], [14909, 'ind'], [50234, 'med'], [88465, 'ind'], [7853, 'med']]}, 70], ['mixed claim history 3', {'expected': 334500, 'split': 17000, 'weight': 150, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[8211, 'ind'], [19267, 'med'], [4256, 'med'], [47071, 'ind'], [74176, 'ind'], [8958, 'med']]}, 83], ['mixed claim history 4', {'expected': 758400, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[24450, 'med'], [45271, 'ind'], [32248, 'med'], [53086, 'ind'], [11516, 'med']]}, 67], ['mixed claim history 5', {'expected': 883600, 'split': 17000, 'weight': 200, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[42495, 'ind'], [9679, 'ind'], [36464, 'ind'], [26823, 'ind'], [63484, 'ind'], [12267, 'med']]}, 63], ['large medical-only claim', {'expected': 318100, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 50000, 'claims': [[102133, 'med'], [5058, 'ind']]}, 68], ['claim free risk', {'expected': 634700, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 80000, 'claims': []}, 60], ['invalid expected losses', {'expected': 0, 'split': 17000, 'weight': 250, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[1000, 'ind']]}, 'invalid expected'], ['mod rounding near half point', {'expected': 457400, 'split': 17000, 'weight': 200, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[12750, 'ind'], [32633, 'ind']]}, 65]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    E=x['expected']
    if E<=0: return 'invalid expected'
    S=x['split']; W=Fraction(x['weight'],1000)
    vals=[Fraction(amt)*Fraction(30,100) if kind=='med' else Fraction(amt) for amt,kind in x['claims']]
    ap=min(sum(vals),S*len(vals))
    ae=sum(vals)-ap
    ep=Fraction(E*x['primary_ratio'],1000); ee=E-ep
    B=x['ballast']
    mod=(ap+W*ae+(1-W)*ee+B)/(E+B)
    return int(mod*100+Fraction(1,2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['mixed claim history 0', {'expected': 311400, 'split': 17000, 'weight': 150, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[33740, 'ind'], [37448, 'ind'], [55230, 'ind'], [10817, 'med']]}, 78], ['mixed claim history 1', {'expected': 767200, 'split': 17000, 'weight': 150, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[42590, 'med'], [38435, 'med'], [27276, 'ind'], [26563, 'med'], [15138, 'ind'], [4744, 'ind'], [87257, 'ind'], [10244, 'med']]}, 75], ['mixed claim history 2', {'expected': 858400, 'split': 17000, 'weight': 150, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[54743, 'med'], [57687, 'ind'], [5771, 'med'], [32069, 'ind'], [9463, 'med']]}, 62], ['mixed claim history 3', {'expected': 677800, 'split': 17000, 'weight': 250, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[20283, 'ind'], [10778, 'ind'], [6643, 'med'], [45395, 'med'], [59048, 'ind'], [5648, 'med']]}, 64], ['mixed claim history 4', {'expected': 650900, 'split': 17000, 'weight': 200, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[37467, 'ind'], [13425, 'med'], [17798, 'ind'], [25433, 'ind'], [13608, 'med']]}, 63], ['mixed claim history 5', {'expected': 447400, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[41535, 'ind'], [48038, 'ind'], [32890, 'ind'], [5200, 'med']]}, 75], ['large medical-only claim', {'expected': 323600, 'split': 17000, 'weight': 250, 'primary_ratio': 350, 'ballast': 50000, 'claims': [[101990, 'med'], [5314, 'ind']]}, 62], ['claim free risk', {'expected': 867900, 'split': 17000, 'weight': 250, 'primary_ratio': 400, 'ballast': 50000, 'claims': []}, 48], ['invalid expected losses', {'expected': 0, 'split': 17000, 'weight': 150, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[1000, 'ind']]}, 'invalid expected'], ['mod rounding near half point', {'expected': 797000, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[11195, 'ind'], [36197, 'ind']]}, 63]], [['mixed claim history 0', {'expected': 316700, 'split': 17000, 'weight': 250, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[10286, 'med'], [40310, 'med'], [26393, 'ind'], [5424, 'med']]}, 65], ['mixed claim history 1', {'expected': 859500, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[23316, 'med'], [15025, 'ind'], [57735, 'ind'], [16008, 'ind'], [45146, 'ind'], [11487, 'med'], [60418, 'ind'], [6233, 'med']]}, 72], ['mixed claim history 2', {'expected': 896000, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 50000, 'claims': [[21038, 'ind'], [5062, 'ind'], [14527, 'med'], [1264, 'med'], [4935, 'med'], [56017, 'ind'], [59572, 'ind'], [6562, 'med']]}, 67], ['mixed claim history 3', {'expected': 779700, 'split': 17000, 'weight': 250, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[57322, 'ind'], [16107, 'med'], [20840, 'med'], [82520, 'ind'], [5448, 'med']]}, 59], ['mixed claim history 4', {'expected': 827000, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[31790, 'ind'], [13488, 'ind'], [71208, 'ind'], [13222, 'med']]}, 67], ['mixed claim history 5', {'expected': 464000, 'split': 17000, 'weight': 150, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[17834, 'ind'], [18093, 'med'], [30643, 'med'], [29993, 'med'], [55402, 'med'], [31809, 'ind'], [13749, 'med']]}, 80], ['large medical-only claim', {'expected': 469100, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 50000, 'claims': [[101036, 'med'], [5613, 'ind']]}, 65], ['claim free risk', {'expected': 687800, 'split': 17000, 'weight': 200, 'primary_ratio': 400, 'ballast': 80000, 'claims': []}, 53], ['invalid expected losses', {'expected': 0, 'split': 17000, 'weight': 200, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[1000, 'ind']]}, 'invalid expected'], ['mod rounding near half point', {'expected': 721000, 'split': 17000, 'weight': 250, 'primary_ratio': 350, 'ballast': 50000, 'claims': [[15423, 'ind'], [31956, 'ind']]}, 57]], [['mixed claim history 0', {'expected': 610400, 'split': 17000, 'weight': 150, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[53344, 'ind'], [48923, 'ind'], [52350, 'ind'], [50819, 'ind'], [10135, 'ind'], [12464, 'ind'], [67060, 'ind'], [12311, 'med']]}, 77], ['mixed claim history 1', {'expected': 402300, 'split': 17000, 'weight': 250, 'primary_ratio': 400, 'ballast': 50000, 'claims': [[17334, 'ind'], [22438, 'ind'], [22151, 'med'], [26026, 'ind'], [7894, 'med']]}, 65], ['mixed claim history 2', {'expected': 498400, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 50000, 'claims': [[48132, 'ind'], [8715, 'ind'], [59441, 'ind'], [20248, 'med'], [17905, 'ind'], [58937, 'med'], [80627, 'ind'], [7990, 'med']]}, 82], ['mixed claim history 3', {'expected': 464700, 'split': 17000, 'weight': 250, 'primary_ratio': 300, 'ballast': 50000, 'claims': [[13610, 'ind'], [3088, 'ind'], [43730, 'ind'], [8434, 'med']]}, 65], ['mixed claim history 4', {'expected': 879300, 'split': 17000, 'weight': 200, 'primary_ratio': 350, 'ballast': 50000, 'claims': [[13389, 'ind'], [32420, 'med'], [20542, 'ind'], [47517, 'ind'], [16287, 'ind'], [82017, 'ind'], [9410, 'med']]}, 67], ['mixed claim history 5', {'expected': 652900, 'split': 17000, 'weight': 200, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[22810, 'ind'], [40463, 'ind'], [74251, 'ind'], [9218, 'med']]}, 67], ['large medical-only claim', {'expected': 703800, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 50000, 'claims': [[84297, 'med'], [2962, 'ind']]}, 62], ['claim free risk', {'expected': 479000, 'split': 17000, 'weight': 250, 'primary_ratio': 300, 'ballast': 80000, 'claims': []}, 59], ['invalid expected losses', {'expected': 0, 'split': 17000, 'weight': 150, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[1000, 'ind']]}, 'invalid expected'], ['mod rounding near half point', {'expected': 447500, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 50000, 'claims': [[11462, 'ind'], [38751, 'ind']]}, 66]], [['mixed claim history 0', {'expected': 688800, 'split': 17000, 'weight': 200, 'primary_ratio': 400, 'ballast': 50000, 'claims': [[56711, 'ind'], [12536, 'med'], [30221, 'ind'], [51849, 'ind'], [13637, 'med']]}, 62], ['mixed claim history 1', {'expected': 402400, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[14109, 'med'], [42085, 'ind'], [59677, 'ind'], [55680, 'ind'], [6934, 'med']]}, 78], ['mixed claim history 2', {'expected': 773600, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[11209, 'med'], [26799, 'ind'], [10934, 'med'], [16129, 'ind'], [11873, 'ind'], [52155, 'ind'], [10727, 'med']]}, 70], ['mixed claim history 3', {'expected': 741200, 'split': 17000, 'weight': 250, 'primary_ratio': 300, 'ballast': 50000, 'claims': [[53124, 'ind'], [16325, 'ind'], [4833, 'ind'], [21033, 'ind'], [6837, 'ind'], [38580, 'ind'], [55554, 'ind'], [13784, 'med']]}, 71], ['mixed claim history 4', {'expected': 331500, 'split': 17000, 'weight': 250, 'primary_ratio': 300, 'ballast': 50000, 'claims': [[10786, 'ind'], [17213, 'med'], [39824, 'med'], [24282, 'ind'], [51513, 'ind'], [63075, 'ind'], [10156, 'med']]}, 86], ['mixed claim history 5', {'expected': 409600, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[54286, 'ind'], [35703, 'ind'], [30503, 'med'], [59058, 'ind'], [56149, 'med'], [41950, 'ind'], [41088, 'ind'], [8047, 'med']]}, 92], ['large medical-only claim', {'expected': 831400, 'split': 17000, 'weight': 200, 'primary_ratio': 400, 'ballast': 50000, 'claims': [[107249, 'med'], [3434, 'ind']]}, 54], ['claim free risk', {'expected': 597500, 'split': 17000, 'weight': 250, 'primary_ratio': 350, 'ballast': 80000, 'claims': []}, 55], ['invalid expected losses', {'expected': 0, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 50000, 'claims': [[1000, 'ind']]}, 'invalid expected'], ['mod rounding near half point', {'expected': 770300, 'split': 17000, 'weight': 200, 'primary_ratio': 400, 'ballast': 50000, 'claims': [[13951, 'ind'], [35547, 'ind']]}, 55]], [['mixed claim history 0', {'expected': 303600, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[20599, 'ind'], [56506, 'ind'], [28670, 'ind'], [70657, 'ind'], [13633, 'med']]}, 88], ['mixed claim history 1', {'expected': 729600, 'split': 17000, 'weight': 250, 'primary_ratio': 400, 'ballast': 50000, 'claims': [[14990, 'med'], [18865, 'ind'], [35152, 'ind'], [37220, 'med'], [45354, 'ind'], [6673, 'med']]}, 59], ['mixed claim history 2', {'expected': 697600, 'split': 17000, 'weight': 200, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[36216, 'ind'], [18993, 'ind'], [14909, 'ind'], [50234, 'med'], [88465, 'ind'], [7853, 'med']]}, 70], ['mixed claim history 3', {'expected': 334500, 'split': 17000, 'weight': 150, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[8211, 'ind'], [19267, 'med'], [4256, 'med'], [47071, 'ind'], [74176, 'ind'], [8958, 'med']]}, 83], ['mixed claim history 4', {'expected': 758400, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[24450, 'med'], [45271, 'ind'], [32248, 'med'], [53086, 'ind'], [11516, 'med']]}, 67], ['mixed claim history 5', {'expected': 883600, 'split': 17000, 'weight': 200, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[42495, 'ind'], [9679, 'ind'], [36464, 'ind'], [26823, 'ind'], [63484, 'ind'], [12267, 'med']]}, 63], ['large medical-only claim', {'expected': 318100, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 50000, 'claims': [[102133, 'med'], [5058, 'ind']]}, 68], ['claim free risk', {'expected': 634700, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 80000, 'claims': []}, 60], ['invalid expected losses', {'expected': 0, 'split': 17000, 'weight': 250, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[1000, 'ind']]}, 'invalid expected'], ['mod rounding near half point', {'expected': 457400, 'split': 17000, 'weight': 200, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[12750, 'ind'], [32633, 'ind']]}, 65]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Several moderate claims are treated as mostly excess, understating the mod.

Input expected (cents, >0 else 'invalid expected'), split, weight W (per mille), primary_ratio (per mille of expected that is primary), ballast B, claims [[amount, 'ind'|'med']]. Medical-only claims count at 30%. Each claim splits into primary min(v,split) and excess. mod=(Ap+W*Ae+(1-W)*Ee+B)/(E+B), returned in hundredths rounded half-up.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    E=x['expected']
    if E<=0: return 'invalid expected'
    S=x['split']; W=Fraction(x['weight'],1000)
    vals=[Fraction(amt)*Fraction(30,100) if kind=='med' else Fraction(amt) for amt,kind in x['claims']]
    ap=sum(min(v,S) for v in vals)
    ae=sum(vals)-ap
    ep=Fraction(E*x['primary_ratio'],1000); ee=E-ep
    B=x['ballast']
    mod=(ap+(1-W)*ae+W*ee+B)/(E+B)
    return int(mod*100+Fraction(1,2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['mixed claim history 0', {'expected': 311400, 'split': 17000, 'weight': 150, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[33740, 'ind'], [37448, 'ind'], [55230, 'ind'], [10817, 'med']]}, 78], ['mixed claim history 1', {'expected': 767200, 'split': 17000, 'weight': 150, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[42590, 'med'], [38435, 'med'], [27276, 'ind'], [26563, 'med'], [15138, 'ind'], [4744, 'ind'], [87257, 'ind'], [10244, 'med']]}, 75], ['mixed claim history 2', {'expected': 858400, 'split': 17000, 'weight': 150, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[54743, 'med'], [57687, 'ind'], [5771, 'med'], [32069, 'ind'], [9463, 'med']]}, 62], ['mixed claim history 3', {'expected': 677800, 'split': 17000, 'weight': 250, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[20283, 'ind'], [10778, 'ind'], [6643, 'med'], [45395, 'med'], [59048, 'ind'], [5648, 'med']]}, 64], ['mixed claim history 4', {'expected': 650900, 'split': 17000, 'weight': 200, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[37467, 'ind'], [13425, 'med'], [17798, 'ind'], [25433, 'ind'], [13608, 'med']]}, 63], ['mixed claim history 5', {'expected': 447400, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[41535, 'ind'], [48038, 'ind'], [32890, 'ind'], [5200, 'med']]}, 75], ['large medical-only claim', {'expected': 323600, 'split': 17000, 'weight': 250, 'primary_ratio': 350, 'ballast': 50000, 'claims': [[101990, 'med'], [5314, 'ind']]}, 62], ['claim free risk', {'expected': 867900, 'split': 17000, 'weight': 250, 'primary_ratio': 400, 'ballast': 50000, 'claims': []}, 48], ['invalid expected losses', {'expected': 0, 'split': 17000, 'weight': 150, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[1000, 'ind']]}, 'invalid expected'], ['mod rounding near half point', {'expected': 797000, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[11195, 'ind'], [36197, 'ind']]}, 63]], [['mixed claim history 0', {'expected': 316700, 'split': 17000, 'weight': 250, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[10286, 'med'], [40310, 'med'], [26393, 'ind'], [5424, 'med']]}, 65], ['mixed claim history 1', {'expected': 859500, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[23316, 'med'], [15025, 'ind'], [57735, 'ind'], [16008, 'ind'], [45146, 'ind'], [11487, 'med'], [60418, 'ind'], [6233, 'med']]}, 72], ['mixed claim history 2', {'expected': 896000, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 50000, 'claims': [[21038, 'ind'], [5062, 'ind'], [14527, 'med'], [1264, 'med'], [4935, 'med'], [56017, 'ind'], [59572, 'ind'], [6562, 'med']]}, 67], ['mixed claim history 3', {'expected': 779700, 'split': 17000, 'weight': 250, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[57322, 'ind'], [16107, 'med'], [20840, 'med'], [82520, 'ind'], [5448, 'med']]}, 59], ['mixed claim history 4', {'expected': 827000, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[31790, 'ind'], [13488, 'ind'], [71208, 'ind'], [13222, 'med']]}, 67], ['mixed claim history 5', {'expected': 464000, 'split': 17000, 'weight': 150, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[17834, 'ind'], [18093, 'med'], [30643, 'med'], [29993, 'med'], [55402, 'med'], [31809, 'ind'], [13749, 'med']]}, 80], ['large medical-only claim', {'expected': 469100, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 50000, 'claims': [[101036, 'med'], [5613, 'ind']]}, 65], ['claim free risk', {'expected': 687800, 'split': 17000, 'weight': 200, 'primary_ratio': 400, 'ballast': 80000, 'claims': []}, 53], ['invalid expected losses', {'expected': 0, 'split': 17000, 'weight': 200, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[1000, 'ind']]}, 'invalid expected'], ['mod rounding near half point', {'expected': 721000, 'split': 17000, 'weight': 250, 'primary_ratio': 350, 'ballast': 50000, 'claims': [[15423, 'ind'], [31956, 'ind']]}, 57]], [['mixed claim history 0', {'expected': 610400, 'split': 17000, 'weight': 150, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[53344, 'ind'], [48923, 'ind'], [52350, 'ind'], [50819, 'ind'], [10135, 'ind'], [12464, 'ind'], [67060, 'ind'], [12311, 'med']]}, 77], ['mixed claim history 1', {'expected': 402300, 'split': 17000, 'weight': 250, 'primary_ratio': 400, 'ballast': 50000, 'claims': [[17334, 'ind'], [22438, 'ind'], [22151, 'med'], [26026, 'ind'], [7894, 'med']]}, 65], ['mixed claim history 2', {'expected': 498400, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 50000, 'claims': [[48132, 'ind'], [8715, 'ind'], [59441, 'ind'], [20248, 'med'], [17905, 'ind'], [58937, 'med'], [80627, 'ind'], [7990, 'med']]}, 82], ['mixed claim history 3', {'expected': 464700, 'split': 17000, 'weight': 250, 'primary_ratio': 300, 'ballast': 50000, 'claims': [[13610, 'ind'], [3088, 'ind'], [43730, 'ind'], [8434, 'med']]}, 65], ['mixed claim history 4', {'expected': 879300, 'split': 17000, 'weight': 200, 'primary_ratio': 350, 'ballast': 50000, 'claims': [[13389, 'ind'], [32420, 'med'], [20542, 'ind'], [47517, 'ind'], [16287, 'ind'], [82017, 'ind'], [9410, 'med']]}, 67], ['mixed claim history 5', {'expected': 652900, 'split': 17000, 'weight': 200, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[22810, 'ind'], [40463, 'ind'], [74251, 'ind'], [9218, 'med']]}, 67], ['large medical-only claim', {'expected': 703800, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 50000, 'claims': [[84297, 'med'], [2962, 'ind']]}, 62], ['claim free risk', {'expected': 479000, 'split': 17000, 'weight': 250, 'primary_ratio': 300, 'ballast': 80000, 'claims': []}, 59], ['invalid expected losses', {'expected': 0, 'split': 17000, 'weight': 150, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[1000, 'ind']]}, 'invalid expected'], ['mod rounding near half point', {'expected': 447500, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 50000, 'claims': [[11462, 'ind'], [38751, 'ind']]}, 66]], [['mixed claim history 0', {'expected': 688800, 'split': 17000, 'weight': 200, 'primary_ratio': 400, 'ballast': 50000, 'claims': [[56711, 'ind'], [12536, 'med'], [30221, 'ind'], [51849, 'ind'], [13637, 'med']]}, 62], ['mixed claim history 1', {'expected': 402400, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[14109, 'med'], [42085, 'ind'], [59677, 'ind'], [55680, 'ind'], [6934, 'med']]}, 78], ['mixed claim history 2', {'expected': 773600, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[11209, 'med'], [26799, 'ind'], [10934, 'med'], [16129, 'ind'], [11873, 'ind'], [52155, 'ind'], [10727, 'med']]}, 70], ['mixed claim history 3', {'expected': 741200, 'split': 17000, 'weight': 250, 'primary_ratio': 300, 'ballast': 50000, 'claims': [[53124, 'ind'], [16325, 'ind'], [4833, 'ind'], [21033, 'ind'], [6837, 'ind'], [38580, 'ind'], [55554, 'ind'], [13784, 'med']]}, 71], ['mixed claim history 4', {'expected': 331500, 'split': 17000, 'weight': 250, 'primary_ratio': 300, 'ballast': 50000, 'claims': [[10786, 'ind'], [17213, 'med'], [39824, 'med'], [24282, 'ind'], [51513, 'ind'], [63075, 'ind'], [10156, 'med']]}, 86], ['mixed claim history 5', {'expected': 409600, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[54286, 'ind'], [35703, 'ind'], [30503, 'med'], [59058, 'ind'], [56149, 'med'], [41950, 'ind'], [41088, 'ind'], [8047, 'med']]}, 92], ['large medical-only claim', {'expected': 831400, 'split': 17000, 'weight': 200, 'primary_ratio': 400, 'ballast': 50000, 'claims': [[107249, 'med'], [3434, 'ind']]}, 54], ['claim free risk', {'expected': 597500, 'split': 17000, 'weight': 250, 'primary_ratio': 350, 'ballast': 80000, 'claims': []}, 55], ['invalid expected losses', {'expected': 0, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 50000, 'claims': [[1000, 'ind']]}, 'invalid expected'], ['mod rounding near half point', {'expected': 770300, 'split': 17000, 'weight': 200, 'primary_ratio': 400, 'ballast': 50000, 'claims': [[13951, 'ind'], [35547, 'ind']]}, 55]], [['mixed claim history 0', {'expected': 303600, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[20599, 'ind'], [56506, 'ind'], [28670, 'ind'], [70657, 'ind'], [13633, 'med']]}, 88], ['mixed claim history 1', {'expected': 729600, 'split': 17000, 'weight': 250, 'primary_ratio': 400, 'ballast': 50000, 'claims': [[14990, 'med'], [18865, 'ind'], [35152, 'ind'], [37220, 'med'], [45354, 'ind'], [6673, 'med']]}, 59], ['mixed claim history 2', {'expected': 697600, 'split': 17000, 'weight': 200, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[36216, 'ind'], [18993, 'ind'], [14909, 'ind'], [50234, 'med'], [88465, 'ind'], [7853, 'med']]}, 70], ['mixed claim history 3', {'expected': 334500, 'split': 17000, 'weight': 150, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[8211, 'ind'], [19267, 'med'], [4256, 'med'], [47071, 'ind'], [74176, 'ind'], [8958, 'med']]}, 83], ['mixed claim history 4', {'expected': 758400, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[24450, 'med'], [45271, 'ind'], [32248, 'med'], [53086, 'ind'], [11516, 'med']]}, 67], ['mixed claim history 5', {'expected': 883600, 'split': 17000, 'weight': 200, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[42495, 'ind'], [9679, 'ind'], [36464, 'ind'], [26823, 'ind'], [63484, 'ind'], [12267, 'med']]}, 63], ['large medical-only claim', {'expected': 318100, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 50000, 'claims': [[102133, 'med'], [5058, 'ind']]}, 68], ['claim free risk', {'expected': 634700, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 80000, 'claims': []}, 60], ['invalid expected losses', {'expected': 0, 'split': 17000, 'weight': 250, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[1000, 'ind']]}, 'invalid expected'], ['mod rounding near half point', {'expected': 457400, 'split': 17000, 'weight': 200, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[12750, 'ind'], [32633, 'ind']]}, 65]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    E=x['expected']
    if E<=0: return 'invalid expected'
    S=x['split']; W=Fraction(x['weight'],1000)
    vals=[Fraction(amt)*Fraction(30,100) if kind=='med' else Fraction(amt) for amt,kind in x['claims']]
    ap=sum(min(v,S) for v in vals)
    ae=sum(vals)-ap
    ep=Fraction(E*x['primary_ratio'],1000); ee=E-ep
    B=x['ballast']
    mod=(ap+W*ae+ee+B)/(E+B)
    return int(mod*100+Fraction(1,2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['mixed claim history 0', {'expected': 311400, 'split': 17000, 'weight': 150, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[33740, 'ind'], [37448, 'ind'], [55230, 'ind'], [10817, 'med']]}, 78], ['mixed claim history 1', {'expected': 767200, 'split': 17000, 'weight': 150, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[42590, 'med'], [38435, 'med'], [27276, 'ind'], [26563, 'med'], [15138, 'ind'], [4744, 'ind'], [87257, 'ind'], [10244, 'med']]}, 75], ['mixed claim history 2', {'expected': 858400, 'split': 17000, 'weight': 150, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[54743, 'med'], [57687, 'ind'], [5771, 'med'], [32069, 'ind'], [9463, 'med']]}, 62], ['mixed claim history 3', {'expected': 677800, 'split': 17000, 'weight': 250, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[20283, 'ind'], [10778, 'ind'], [6643, 'med'], [45395, 'med'], [59048, 'ind'], [5648, 'med']]}, 64], ['mixed claim history 4', {'expected': 650900, 'split': 17000, 'weight': 200, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[37467, 'ind'], [13425, 'med'], [17798, 'ind'], [25433, 'ind'], [13608, 'med']]}, 63], ['mixed claim history 5', {'expected': 447400, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[41535, 'ind'], [48038, 'ind'], [32890, 'ind'], [5200, 'med']]}, 75], ['large medical-only claim', {'expected': 323600, 'split': 17000, 'weight': 250, 'primary_ratio': 350, 'ballast': 50000, 'claims': [[101990, 'med'], [5314, 'ind']]}, 62], ['claim free risk', {'expected': 867900, 'split': 17000, 'weight': 250, 'primary_ratio': 400, 'ballast': 50000, 'claims': []}, 48], ['invalid expected losses', {'expected': 0, 'split': 17000, 'weight': 150, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[1000, 'ind']]}, 'invalid expected'], ['mod rounding near half point', {'expected': 797000, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[11195, 'ind'], [36197, 'ind']]}, 63]], [['mixed claim history 0', {'expected': 316700, 'split': 17000, 'weight': 250, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[10286, 'med'], [40310, 'med'], [26393, 'ind'], [5424, 'med']]}, 65], ['mixed claim history 1', {'expected': 859500, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[23316, 'med'], [15025, 'ind'], [57735, 'ind'], [16008, 'ind'], [45146, 'ind'], [11487, 'med'], [60418, 'ind'], [6233, 'med']]}, 72], ['mixed claim history 2', {'expected': 896000, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 50000, 'claims': [[21038, 'ind'], [5062, 'ind'], [14527, 'med'], [1264, 'med'], [4935, 'med'], [56017, 'ind'], [59572, 'ind'], [6562, 'med']]}, 67], ['mixed claim history 3', {'expected': 779700, 'split': 17000, 'weight': 250, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[57322, 'ind'], [16107, 'med'], [20840, 'med'], [82520, 'ind'], [5448, 'med']]}, 59], ['mixed claim history 4', {'expected': 827000, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[31790, 'ind'], [13488, 'ind'], [71208, 'ind'], [13222, 'med']]}, 67], ['mixed claim history 5', {'expected': 464000, 'split': 17000, 'weight': 150, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[17834, 'ind'], [18093, 'med'], [30643, 'med'], [29993, 'med'], [55402, 'med'], [31809, 'ind'], [13749, 'med']]}, 80], ['large medical-only claim', {'expected': 469100, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 50000, 'claims': [[101036, 'med'], [5613, 'ind']]}, 65], ['claim free risk', {'expected': 687800, 'split': 17000, 'weight': 200, 'primary_ratio': 400, 'ballast': 80000, 'claims': []}, 53], ['invalid expected losses', {'expected': 0, 'split': 17000, 'weight': 200, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[1000, 'ind']]}, 'invalid expected'], ['mod rounding near half point', {'expected': 721000, 'split': 17000, 'weight': 250, 'primary_ratio': 350, 'ballast': 50000, 'claims': [[15423, 'ind'], [31956, 'ind']]}, 57]], [['mixed claim history 0', {'expected': 610400, 'split': 17000, 'weight': 150, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[53344, 'ind'], [48923, 'ind'], [52350, 'ind'], [50819, 'ind'], [10135, 'ind'], [12464, 'ind'], [67060, 'ind'], [12311, 'med']]}, 77], ['mixed claim history 1', {'expected': 402300, 'split': 17000, 'weight': 250, 'primary_ratio': 400, 'ballast': 50000, 'claims': [[17334, 'ind'], [22438, 'ind'], [22151, 'med'], [26026, 'ind'], [7894, 'med']]}, 65], ['mixed claim history 2', {'expected': 498400, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 50000, 'claims': [[48132, 'ind'], [8715, 'ind'], [59441, 'ind'], [20248, 'med'], [17905, 'ind'], [58937, 'med'], [80627, 'ind'], [7990, 'med']]}, 82], ['mixed claim history 3', {'expected': 464700, 'split': 17000, 'weight': 250, 'primary_ratio': 300, 'ballast': 50000, 'claims': [[13610, 'ind'], [3088, 'ind'], [43730, 'ind'], [8434, 'med']]}, 65], ['mixed claim history 4', {'expected': 879300, 'split': 17000, 'weight': 200, 'primary_ratio': 350, 'ballast': 50000, 'claims': [[13389, 'ind'], [32420, 'med'], [20542, 'ind'], [47517, 'ind'], [16287, 'ind'], [82017, 'ind'], [9410, 'med']]}, 67], ['mixed claim history 5', {'expected': 652900, 'split': 17000, 'weight': 200, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[22810, 'ind'], [40463, 'ind'], [74251, 'ind'], [9218, 'med']]}, 67], ['large medical-only claim', {'expected': 703800, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 50000, 'claims': [[84297, 'med'], [2962, 'ind']]}, 62], ['claim free risk', {'expected': 479000, 'split': 17000, 'weight': 250, 'primary_ratio': 300, 'ballast': 80000, 'claims': []}, 59], ['invalid expected losses', {'expected': 0, 'split': 17000, 'weight': 150, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[1000, 'ind']]}, 'invalid expected'], ['mod rounding near half point', {'expected': 447500, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 50000, 'claims': [[11462, 'ind'], [38751, 'ind']]}, 66]], [['mixed claim history 0', {'expected': 688800, 'split': 17000, 'weight': 200, 'primary_ratio': 400, 'ballast': 50000, 'claims': [[56711, 'ind'], [12536, 'med'], [30221, 'ind'], [51849, 'ind'], [13637, 'med']]}, 62], ['mixed claim history 1', {'expected': 402400, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[14109, 'med'], [42085, 'ind'], [59677, 'ind'], [55680, 'ind'], [6934, 'med']]}, 78], ['mixed claim history 2', {'expected': 773600, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[11209, 'med'], [26799, 'ind'], [10934, 'med'], [16129, 'ind'], [11873, 'ind'], [52155, 'ind'], [10727, 'med']]}, 70], ['mixed claim history 3', {'expected': 741200, 'split': 17000, 'weight': 250, 'primary_ratio': 300, 'ballast': 50000, 'claims': [[53124, 'ind'], [16325, 'ind'], [4833, 'ind'], [21033, 'ind'], [6837, 'ind'], [38580, 'ind'], [55554, 'ind'], [13784, 'med']]}, 71], ['mixed claim history 4', {'expected': 331500, 'split': 17000, 'weight': 250, 'primary_ratio': 300, 'ballast': 50000, 'claims': [[10786, 'ind'], [17213, 'med'], [39824, 'med'], [24282, 'ind'], [51513, 'ind'], [63075, 'ind'], [10156, 'med']]}, 86], ['mixed claim history 5', {'expected': 409600, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[54286, 'ind'], [35703, 'ind'], [30503, 'med'], [59058, 'ind'], [56149, 'med'], [41950, 'ind'], [41088, 'ind'], [8047, 'med']]}, 92], ['large medical-only claim', {'expected': 831400, 'split': 17000, 'weight': 200, 'primary_ratio': 400, 'ballast': 50000, 'claims': [[107249, 'med'], [3434, 'ind']]}, 54], ['claim free risk', {'expected': 597500, 'split': 17000, 'weight': 250, 'primary_ratio': 350, 'ballast': 80000, 'claims': []}, 55], ['invalid expected losses', {'expected': 0, 'split': 17000, 'weight': 200, 'primary_ratio': 300, 'ballast': 50000, 'claims': [[1000, 'ind']]}, 'invalid expected'], ['mod rounding near half point', {'expected': 770300, 'split': 17000, 'weight': 200, 'primary_ratio': 400, 'ballast': 50000, 'claims': [[13951, 'ind'], [35547, 'ind']]}, 55]], [['mixed claim history 0', {'expected': 303600, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[20599, 'ind'], [56506, 'ind'], [28670, 'ind'], [70657, 'ind'], [13633, 'med']]}, 88], ['mixed claim history 1', {'expected': 729600, 'split': 17000, 'weight': 250, 'primary_ratio': 400, 'ballast': 50000, 'claims': [[14990, 'med'], [18865, 'ind'], [35152, 'ind'], [37220, 'med'], [45354, 'ind'], [6673, 'med']]}, 59], ['mixed claim history 2', {'expected': 697600, 'split': 17000, 'weight': 200, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[36216, 'ind'], [18993, 'ind'], [14909, 'ind'], [50234, 'med'], [88465, 'ind'], [7853, 'med']]}, 70], ['mixed claim history 3', {'expected': 334500, 'split': 17000, 'weight': 150, 'primary_ratio': 300, 'ballast': 80000, 'claims': [[8211, 'ind'], [19267, 'med'], [4256, 'med'], [47071, 'ind'], [74176, 'ind'], [8958, 'med']]}, 83], ['mixed claim history 4', {'expected': 758400, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[24450, 'med'], [45271, 'ind'], [32248, 'med'], [53086, 'ind'], [11516, 'med']]}, 67], ['mixed claim history 5', {'expected': 883600, 'split': 17000, 'weight': 200, 'primary_ratio': 400, 'ballast': 80000, 'claims': [[42495, 'ind'], [9679, 'ind'], [36464, 'ind'], [26823, 'ind'], [63484, 'ind'], [12267, 'med']]}, 63], ['large medical-only claim', {'expected': 318100, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 50000, 'claims': [[102133, 'med'], [5058, 'ind']]}, 68], ['claim free risk', {'expected': 634700, 'split': 17000, 'weight': 150, 'primary_ratio': 350, 'ballast': 80000, 'claims': []}, 60], ['invalid expected losses', {'expected': 0, 'split': 17000, 'weight': 250, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[1000, 'ind']]}, 'invalid expected'], ['mod rounding near half point', {'expected': 457400, 'split': 17000, 'weight': 200, 'primary_ratio': 350, 'ballast': 80000, 'claims': [[12750, 'ind'], [32633, 'ind']]}, 65]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Mods overreact to excess losses and the expected-excess ballast is mostly discarded.

Input expected (cents, >0 else 'invalid expected'), split, weight W (per mille), primary_ratio (per mille of expected that is primary), ballast B, claims [[amount, 'ind'|'med']]. Medical-only claims count at 30%. Each claim splits into primary min(v,split) and excess. mod=(Ap+W*Ae+(1-W)*Ee+B)/(E+B), returned in hundredths rounded half-up.

split: open-access