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+W*ae+(1-W)*ee+B)/E
    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+(1-W)*ee+B)/(ep+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 are systematically inflated because ballast is added only to the numerator.

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+W*ae+(1-W)*ee+B)/(E+B)
    return int(mod*100)
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=='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*1000+Fraction(1,2))//10
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:
The published mod is one point low whenever the third decimal would round it up.

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


prompt:
Very large deductibles receive credits beyond the largest filed credit.

Input premium, deductible and table [[deductible, credit per mille]] ascending (credits may be negative surcharges). Deductibles at or below the first row take its credit, at or above the last row take the last credit (no extrapolation), otherwise interpolate linearly. Credit cents = floor(prem*c/1000+1/2). Negative deductible or empty table -> 'invalid'. Return [credit, premium-credit].

split: open-access


prompt:
Deductibles between tabulated rows get credits that do not lie on the segment.

Input premium, deductible and table [[deductible, credit per mille]] ascending (credits may be negative surcharges). Deductibles at or below the first row take its credit, at or above the last row take the last credit (no extrapolation), otherwise interpolate linearly. Credit cents = floor(prem*c/1000+1/2). Negative deductible or empty table -> 'invalid'. Return [credit, premium-credit].

split: open-access


prompt:
Low deductibles escape the surcharge in the first table row.

Input premium, deductible and table [[deductible, credit per mille]] ascending (credits may be negative surcharges). Deductibles at or below the first row take its credit, at or above the last row take the last credit (no extrapolation), otherwise interpolate linearly. Credit cents = floor(prem*c/1000+1/2). Negative deductible or empty table -> 'invalid'. Return [credit, premium-credit].

split: open-access


prompt:
A full-coverage zero-deductible quote returns invalid.

Input premium, deductible and table [[deductible, credit per mille]] ascending (credits may be negative surcharges). Deductibles at or below the first row take its credit, at or above the last row take the last credit (no extrapolation), otherwise interpolate linearly. Credit cents = floor(prem*c/1000+1/2). Negative deductible or empty table -> 'invalid'. Return [credit, premium-credit].

split: open-access


prompt:
Surcharge amounts are off by a cent in the insured's favour.

Input premium, deductible and table [[deductible, credit per mille]] ascending (credits may be negative surcharges). Deductibles at or below the first row take its credit, at or above the last row take the last credit (no extrapolation), otherwise interpolate linearly. Credit cents = floor(prem*c/1000+1/2). Negative deductible or empty table -> 'invalid'. Return [credit, premium-credit].

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):
    p=x['premium']; t=x['term_days']; d=x['days_in_force']
    if d<0 or t<=0: return 'invalid'
    if d>=t: return 0
    if d==0: return p
    unearned=Fraction(p*(t-d),t)
    if x['initiator']=='insured':
        ret=unearned-Fraction(p,10)
        ret=min(ret,p-Fraction(p*x['min_earned_permille'],1000))
    else:
        ret=unearned
    return math.floor(ret+Fraction(1,2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['insured cancels mid-term', {'premium': 167157, 'term_days': 365, 'days_in_force': 113, 'initiator': 'insured', 'min_earned_permille': 100}, 103866], ['insurer cancels mid-term', {'premium': 107827, 'term_days': 365, 'days_in_force': 285, 'initiator': 'insurer', 'min_earned_permille': 250}, 23633], ['insurer cancel early with minimum on file', {'premium': 135423, 'term_days': 365, 'days_in_force': 32, 'initiator': 'insurer', 'min_earned_permille': 400}, 123550], ['insured minimum earned binds', {'premium': 102264, 'term_days': 365, 'days_in_force': 24, 'initiator': 'insured', 'min_earned_permille': 300}, 71585], ['flat cancel by insured', {'premium': 246750, 'term_days': 365, 'days_in_force': 0, 'initiator': 'insured', 'min_earned_permille': 250}, 246750], ['flat cancel by insurer', {'premium': 77604, 'term_days': 365, 'days_in_force': 0, 'initiator': 'insurer', 'min_earned_permille': 100}, 77604], ['one day in force', {'premium': 285647, 'term_days': 180, 'days_in_force': 1, 'initiator': 'insurer', 'min_earned_permille': 100}, 284060], ['expiry day', {'premium': 163861, 'term_days': 365, 'days_in_force': 365, 'initiator': 'insured', 'min_earned_permille': 100}, 0], ['negative days rejected', {'premium': 253298, 'term_days': 365, 'days_in_force': -1, 'initiator': 'insured', 'min_earned_permille': 250}, 'invalid'], ['six month policy insured cancel', {'premium': 169415, 'term_days': 182, 'days_in_force': 105, 'initiator': 'insured', 'min_earned_permille': 100}, 64508]], [['insured cancels mid-term', {'premium': 136580, 'term_days': 365, 'days_in_force': 120, 'initiator': 'insured', 'min_earned_permille': 100}, 82509], ['insurer cancels mid-term', {'premium': 142197, 'term_days': 365, 'days_in_force': 42, 'initiator': 'insurer', 'min_earned_permille': 100}, 125835], ['insurer cancel early with minimum on file', {'premium': 130516, 'term_days': 365, 'days_in_force': 22, 'initiator': 'insurer', 'min_earned_permille': 400}, 122649], ['insured minimum earned binds', {'premium': 155356, 'term_days': 365, 'days_in_force': 30, 'initiator': 'insured', 'min_earned_permille': 300}, 108749], ['flat cancel by insured', {'premium': 128340, 'term_days': 365, 'days_in_force': 0, 'initiator': 'insured', 'min_earned_permille': 250}, 128340], ['flat cancel by insurer', {'premium': 205493, 'term_days': 365, 'days_in_force': 0, 'initiator': 'insurer', 'min_earned_permille': 250}, 205493], ['one day in force', {'premium': 125332, 'term_days': 180, 'days_in_force': 1, 'initiator': 'insurer', 'min_earned_permille': 100}, 124636], ['expiry day', {'premium': 149858, 'term_days': 365, 'days_in_force': 365, 'initiator': 'insured', 'min_earned_permille': 100}, 0], ['negative days rejected', {'premium': 143435, 'term_days': 365, 'days_in_force': -1, 'initiator': 'insured', 'min_earned_permille': 250}, 'invalid'], ['six month policy insured cancel', {'premium': 219606, 'term_days': 182, 'days_in_force': 115, 'initiator': 'insured', 'min_earned_permille': 100}, 72760]], [['insured cancels mid-term', {'premium': 236883, 'term_days': 365, 'days_in_force': 198, 'initiator': 'insured', 'min_earned_permille': 100}, 97544], ['insurer cancels mid-term', {'premium': 224272, 'term_days': 365, 'days_in_force': 89, 'initiator': 'insurer', 'min_earned_permille': 100}, 169586], ['insurer cancel early with minimum on file', {'premium': 271417, 'term_days': 365, 'days_in_force': 21, 'initiator': 'insurer', 'min_earned_permille': 400}, 255801], ['insured minimum earned binds', {'premium': 236806, 'term_days': 365, 'days_in_force': 27, 'initiator': 'insured', 'min_earned_permille': 300}, 165764], ['flat cancel by insured', {'premium': 50665, 'term_days': 365, 'days_in_force': 0, 'initiator': 'insured', 'min_earned_permille': 100}, 50665], ['flat cancel by insurer', {'premium': 266999, 'term_days': 365, 'days_in_force': 0, 'initiator': 'insurer', 'min_earned_permille': 250}, 266999], ['one day in force', {'premium': 51282, 'term_days': 180, 'days_in_force': 1, 'initiator': 'insurer', 'min_earned_permille': 250}, 50997], ['expiry day', {'premium': 202320, 'term_days': 365, 'days_in_force': 365, 'initiator': 'insured', 'min_earned_permille': 100}, 0], ['negative days rejected', {'premium': 67184, 'term_days': 365, 'days_in_force': -1, 'initiator': 'insured', 'min_earned_permille': 100}, 'invalid'], ['six month policy insured cancel', {'premium': 241675, 'term_days': 182, 'days_in_force': 118, 'initiator': 'insured', 'min_earned_permille': 100}, 76486]], [['insured cancels mid-term', {'premium': 82503, 'term_days': 365, 'days_in_force': 154, 'initiator': 'insured', 'min_earned_permille': 100}, 42924], ['insurer cancels mid-term', {'premium': 137193, 'term_days': 365, 'days_in_force': 295, 'initiator': 'insurer', 'min_earned_permille': 100}, 26311], ['insurer cancel early with minimum on file', {'premium': 157674, 'term_days': 365, 'days_in_force': 15, 'initiator': 'insurer', 'min_earned_permille': 400}, 151194], ['insured minimum earned binds', {'premium': 283617, 'term_days': 365, 'days_in_force': 21, 'initiator': 'insured', 'min_earned_permille': 300}, 198532], ['flat cancel by insured', {'premium': 97666, 'term_days': 365, 'days_in_force': 0, 'initiator': 'insured', 'min_earned_permille': 100}, 97666], ['flat cancel by insurer', {'premium': 137018, 'term_days': 365, 'days_in_force': 0, 'initiator': 'insurer', 'min_earned_permille': 100}, 137018], ['one day in force', {'premium': 261346, 'term_days': 180, 'days_in_force': 1, 'initiator': 'insurer', 'min_earned_permille': 100}, 259894], ['expiry day', {'premium': 135749, 'term_days': 365, 'days_in_force': 365, 'initiator': 'insured', 'min_earned_permille': 100}, 0], ['negative days rejected', {'premium': 260111, 'term_days': 365, 'days_in_force': -1, 'initiator': 'insured', 'min_earned_permille': 100}, 'invalid'], ['six month policy insured cancel', {'premium': 289415, 'term_days': 182, 'days_in_force': 81, 'initiator': 'insured', 'min_earned_permille': 100}, 144548]], [['insured cancels mid-term', {'premium': 59284, 'term_days': 365, 'days_in_force': 188, 'initiator': 'insured', 'min_earned_permille': 100}, 25874], ['insurer cancels mid-term', {'premium': 88844, 'term_days': 365, 'days_in_force': 105, 'initiator': 'insurer', 'min_earned_permille': 100}, 63286], ['insurer cancel early with minimum on file', {'premium': 70835, 'term_days': 365, 'days_in_force': 24, 'initiator': 'insurer', 'min_earned_permille': 400}, 66177], ['insured minimum earned binds', {'premium': 148105, 'term_days': 365, 'days_in_force': 29, 'initiator': 'insured', 'min_earned_permille': 300}, 103674], ['flat cancel by insured', {'premium': 267217, 'term_days': 365, 'days_in_force': 0, 'initiator': 'insured', 'min_earned_permille': 100}, 267217], ['flat cancel by insurer', {'premium': 201088, 'term_days': 365, 'days_in_force': 0, 'initiator': 'insurer', 'min_earned_permille': 100}, 201088], ['one day in force', {'premium': 293778, 'term_days': 180, 'days_in_force': 1, 'initiator': 'insurer', 'min_earned_permille': 250}, 292146], ['expiry day', {'premium': 81772, 'term_days': 365, 'days_in_force': 365, 'initiator': 'insured', 'min_earned_permille': 100}, 0], ['negative days rejected', {'premium': 193452, 'term_days': 365, 'days_in_force': -1, 'initiator': 'insured', 'min_earned_permille': 100}, 'invalid'], ['six month policy insured cancel', {'premium': 273407, 'term_days': 182, 'days_in_force': 107, 'initiator': 'insured', 'min_earned_permille': 100}, 101401]]]
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):
    p=x['premium']; t=x['term_days']; d=x['days_in_force']
    if d<0 or t<=0: return 'invalid'
    if d>=t: return 0
    if d==0: return p
    unearned=Fraction(p*(t-d),t)
    if x['initiator']=='insured':
        ret=max(unearned-Fraction(p,10),0)
        ret=min(ret,p-Fraction(p*x['min_earned_permille'],1000))
    else:
        ret=unearned
    return math.floor(ret+Fraction(1,2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['insured cancels mid-term', {'premium': 167157, 'term_days': 365, 'days_in_force': 113, 'initiator': 'insured', 'min_earned_permille': 100}, 103866], ['insurer cancels mid-term', {'premium': 107827, 'term_days': 365, 'days_in_force': 285, 'initiator': 'insurer', 'min_earned_permille': 250}, 23633], ['insurer cancel early with minimum on file', {'premium': 135423, 'term_days': 365, 'days_in_force': 32, 'initiator': 'insurer', 'min_earned_permille': 400}, 123550], ['insured minimum earned binds', {'premium': 102264, 'term_days': 365, 'days_in_force': 24, 'initiator': 'insured', 'min_earned_permille': 300}, 71585], ['flat cancel by insured', {'premium': 246750, 'term_days': 365, 'days_in_force': 0, 'initiator': 'insured', 'min_earned_permille': 250}, 246750], ['flat cancel by insurer', {'premium': 77604, 'term_days': 365, 'days_in_force': 0, 'initiator': 'insurer', 'min_earned_permille': 100}, 77604], ['one day in force', {'premium': 285647, 'term_days': 180, 'days_in_force': 1, 'initiator': 'insurer', 'min_earned_permille': 100}, 284060], ['expiry day', {'premium': 163861, 'term_days': 365, 'days_in_force': 365, 'initiator': 'insured', 'min_earned_permille': 100}, 0], ['negative days rejected', {'premium': 253298, 'term_days': 365, 'days_in_force': -1, 'initiator': 'insured', 'min_earned_permille': 250}, 'invalid'], ['six month policy insured cancel', {'premium': 169415, 'term_days': 182, 'days_in_force': 105, 'initiator': 'insured', 'min_earned_permille': 100}, 64508]], [['insured cancels mid-term', {'premium': 136580, 'term_days': 365, 'days_in_force': 120, 'initiator': 'insured', 'min_earned_permille': 100}, 82509], ['insurer cancels mid-term', {'premium': 142197, 'term_days': 365, 'days_in_force': 42, 'initiator': 'insurer', 'min_earned_permille': 100}, 125835], ['insurer cancel early with minimum on file', {'premium': 130516, 'term_days': 365, 'days_in_force': 22, 'initiator': 'insurer', 'min_earned_permille': 400}, 122649], ['insured minimum earned binds', {'premium': 155356, 'term_days': 365, 'days_in_force': 30, 'initiator': 'insured', 'min_earned_permille': 300}, 108749], ['flat cancel by insured', {'premium': 128340, 'term_days': 365, 'days_in_force': 0, 'initiator': 'insured', 'min_earned_permille': 250}, 128340], ['flat cancel by insurer', {'premium': 205493, 'term_days': 365, 'days_in_force': 0, 'initiator': 'insurer', 'min_earned_permille': 250}, 205493], ['one day in force', {'premium': 125332, 'term_days': 180, 'days_in_force': 1, 'initiator': 'insurer', 'min_earned_permille': 100}, 124636], ['expiry day', {'premium': 149858, 'term_days': 365, 'days_in_force': 365, 'initiator': 'insured', 'min_earned_permille': 100}, 0], ['negative days rejected', {'premium': 143435, 'term_days': 365, 'days_in_force': -1, 'initiator': 'insured', 'min_earned_permille': 250}, 'invalid'], ['six month policy insured cancel', {'premium': 219606, 'term_days': 182, 'days_in_force': 115, 'initiator': 'insured', 'min_earned_permille': 100}, 72760]], [['insured cancels mid-term', {'premium': 236883, 'term_days': 365, 'days_in_force': 198, 'initiator': 'insured', 'min_earned_permille': 100}, 97544], ['insurer cancels mid-term', {'premium': 224272, 'term_days': 365, 'days_in_force': 89, 'initiator': 'insurer', 'min_earned_permille': 100}, 169586], ['insurer cancel early with minimum on file', {'premium': 271417, 'term_days': 365, 'days_in_force': 21, 'initiator': 'insurer', 'min_earned_permille': 400}, 255801], ['insured minimum earned binds', {'premium': 236806, 'term_days': 365, 'days_in_force': 27, 'initiator': 'insured', 'min_earned_permille': 300}, 165764], ['flat cancel by insured', {'premium': 50665, 'term_days': 365, 'days_in_force': 0, 'initiator': 'insured', 'min_earned_permille': 100}, 50665], ['flat cancel by insurer', {'premium': 266999, 'term_days': 365, 'days_in_force': 0, 'initiator': 'insurer', 'min_earned_permille': 250}, 266999], ['one day in force', {'premium': 51282, 'term_days': 180, 'days_in_force': 1, 'initiator': 'insurer', 'min_earned_permille': 250}, 50997], ['expiry day', {'premium': 202320, 'term_days': 365, 'days_in_force': 365, 'initiator': 'insured', 'min_earned_permille': 100}, 0], ['negative days rejected', {'premium': 67184, 'term_days': 365, 'days_in_force': -1, 'initiator': 'insured', 'min_earned_permille': 100}, 'invalid'], ['six month policy insured cancel', {'premium': 241675, 'term_days': 182, 'days_in_force': 118, 'initiator': 'insured', 'min_earned_permille': 100}, 76486]], [['insured cancels mid-term', {'premium': 82503, 'term_days': 365, 'days_in_force': 154, 'initiator': 'insured', 'min_earned_permille': 100}, 42924], ['insurer cancels mid-term', {'premium': 137193, 'term_days': 365, 'days_in_force': 295, 'initiator': 'insurer', 'min_earned_permille': 100}, 26311], ['insurer cancel early with minimum on file', {'premium': 157674, 'term_days': 365, 'days_in_force': 15, 'initiator': 'insurer', 'min_earned_permille': 400}, 151194], ['insured minimum earned binds', {'premium': 283617, 'term_days': 365, 'days_in_force': 21, 'initiator': 'insured', 'min_earned_permille': 300}, 198532], ['flat cancel by insured', {'premium': 97666, 'term_days': 365, 'days_in_force': 0, 'initiator': 'insured', 'min_earned_permille': 100}, 97666], ['flat cancel by insurer', {'premium': 137018, 'term_days': 365, 'days_in_force': 0, 'initiator': 'insurer', 'min_earned_permille': 100}, 137018], ['one day in force', {'premium': 261346, 'term_days': 180, 'days_in_force': 1, 'initiator': 'insurer', 'min_earned_permille': 100}, 259894], ['expiry day', {'premium': 135749, 'term_days': 365, 'days_in_force': 365, 'initiator': 'insured', 'min_earned_permille': 100}, 0], ['negative days rejected', {'premium': 260111, 'term_days': 365, 'days_in_force': -1, 'initiator': 'insured', 'min_earned_permille': 100}, 'invalid'], ['six month policy insured cancel', {'premium': 289415, 'term_days': 182, 'days_in_force': 81, 'initiator': 'insured', 'min_earned_permille': 100}, 144548]], [['insured cancels mid-term', {'premium': 59284, 'term_days': 365, 'days_in_force': 188, 'initiator': 'insured', 'min_earned_permille': 100}, 25874], ['insurer cancels mid-term', {'premium': 88844, 'term_days': 365, 'days_in_force': 105, 'initiator': 'insurer', 'min_earned_permille': 100}, 63286], ['insurer cancel early with minimum on file', {'premium': 70835, 'term_days': 365, 'days_in_force': 24, 'initiator': 'insurer', 'min_earned_permille': 400}, 66177], ['insured minimum earned binds', {'premium': 148105, 'term_days': 365, 'days_in_force': 29, 'initiator': 'insured', 'min_earned_permille': 300}, 103674], ['flat cancel by insured', {'premium': 267217, 'term_days': 365, 'days_in_force': 0, 'initiator': 'insured', 'min_earned_permille': 100}, 267217], ['flat cancel by insurer', {'premium': 201088, 'term_days': 365, 'days_in_force': 0, 'initiator': 'insurer', 'min_earned_permille': 100}, 201088], ['one day in force', {'premium': 293778, 'term_days': 180, 'days_in_force': 1, 'initiator': 'insurer', 'min_earned_permille': 250}, 292146], ['expiry day', {'premium': 81772, 'term_days': 365, 'days_in_force': 365, 'initiator': 'insured', 'min_earned_permille': 100}, 0], ['negative days rejected', {'premium': 193452, 'term_days': 365, 'days_in_force': -1, 'initiator': 'insured', 'min_earned_permille': 100}, 'invalid'], ['six month policy insured cancel', {'premium': 273407, 'term_days': 182, 'days_in_force': 107, 'initiator': 'insured', 'min_earned_permille': 100}, 101401]]]
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:
Insured cancellations refund much less than 90% of unearned premium.

Input premium, term_days, days_in_force d, initiator, min_earned_permille. d<0 or term<=0 -> 'invalid'; d>=term -> 0; d==0 (flat cancel) returns the full premium. Otherwise unearned = premium*(term-d)/term; the insurer returns it in full; an insured cancellation returns 90% of unearned but never more than premium minus the minimum earned premium. Round half-up once.

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):
    p=x['premium']; t=x['term_days']; d=x['days_in_force']
    if d<0 or t<=0: return 'invalid'
    if d>=t: return 0
    if d==0: return p
    unearned=Fraction(p*(t-d),t)
    if x['initiator']=='insured':
        ret=unearned*Fraction(90,100)
    else:
        ret=unearned
    ret=min(ret,p-Fraction(p*x['min_earned_permille'],1000))
    return math.floor(ret+Fraction(1,2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['insured cancels mid-term', {'premium': 167157, 'term_days': 365, 'days_in_force': 113, 'initiator': 'insured', 'min_earned_permille': 100}, 103866], ['insurer cancels mid-term', {'premium': 107827, 'term_days': 365, 'days_in_force': 285, 'initiator': 'insurer', 'min_earned_permille': 250}, 23633], ['insurer cancel early with minimum on file', {'premium': 135423, 'term_days': 365, 'days_in_force': 32, 'initiator': 'insurer', 'min_earned_permille': 400}, 123550], ['insured minimum earned binds', {'premium': 102264, 'term_days': 365, 'days_in_force': 24, 'initiator': 'insured', 'min_earned_permille': 300}, 71585], ['flat cancel by insured', {'premium': 246750, 'term_days': 365, 'days_in_force': 0, 'initiator': 'insured', 'min_earned_permille': 250}, 246750], ['flat cancel by insurer', {'premium': 77604, 'term_days': 365, 'days_in_force': 0, 'initiator': 'insurer', 'min_earned_permille': 100}, 77604], ['one day in force', {'premium': 285647, 'term_days': 180, 'days_in_force': 1, 'initiator': 'insurer', 'min_earned_permille': 100}, 284060], ['expiry day', {'premium': 163861, 'term_days': 365, 'days_in_force': 365, 'initiator': 'insured', 'min_earned_permille': 100}, 0], ['negative days rejected', {'premium': 253298, 'term_days': 365, 'days_in_force': -1, 'initiator': 'insured', 'min_earned_permille': 250}, 'invalid'], ['six month policy insured cancel', {'premium': 169415, 'term_days': 182, 'days_in_force': 105, 'initiator': 'insured', 'min_earned_permille': 100}, 64508]], [['insured cancels mid-term', {'premium': 136580, 'term_days': 365, 'days_in_force': 120, 'initiator': 'insured', 'min_earned_permille': 100}, 82509], ['insurer cancels mid-term', {'premium': 142197, 'term_days': 365, 'days_in_force': 42, 'initiator': 'insurer', 'min_earned_permille': 100}, 125835], ['insurer cancel early with minimum on file', {'premium': 130516, 'term_days': 365, 'days_in_force': 22, 'initiator': 'insurer', 'min_earned_permille': 400}, 122649], ['insured minimum earned binds', {'premium': 155356, 'term_days': 365, 'days_in_force': 30, 'initiator': 'insured', 'min_earned_permille': 300}, 108749], ['flat cancel by insured', {'premium': 128340, 'term_days': 365, 'days_in_force': 0, 'initiator': 'insured', 'min_earned_permille': 250}, 128340], ['flat cancel by insurer', {'premium': 205493, 'term_days': 365, 'days_in_force': 0, 'initiator': 'insurer', 'min_earned_permille': 250}, 205493], ['one day in force', {'premium': 125332, 'term_days': 180, 'days_in_force': 1, 'initiator': 'insurer', 'min_earned_permille': 100}, 124636], ['expiry day', {'premium': 149858, 'term_days': 365, 'days_in_force': 365, 'initiator': 'insured', 'min_earned_permille': 100}, 0], ['negative days rejected', {'premium': 143435, 'term_days': 365, 'days_in_force': -1, 'initiator': 'insured', 'min_earned_permille': 250}, 'invalid'], ['six month policy insured cancel', {'premium': 219606, 'term_days': 182, 'days_in_force': 115, 'initiator': 'insured', 'min_earned_permille': 100}, 72760]], [['insured cancels mid-term', {'premium': 236883, 'term_days': 365, 'days_in_force': 198, 'initiator': 'insured', 'min_earned_permille': 100}, 97544], ['insurer cancels mid-term', {'premium': 224272, 'term_days': 365, 'days_in_force': 89, 'initiator': 'insurer', 'min_earned_permille': 100}, 169586], ['insurer cancel early with minimum on file', {'premium': 271417, 'term_days': 365, 'days_in_force': 21, 'initiator': 'insurer', 'min_earned_permille': 400}, 255801], ['insured minimum earned binds', {'premium': 236806, 'term_days': 365, 'days_in_force': 27, 'initiator': 'insured', 'min_earned_permille': 300}, 165764], ['flat cancel by insured', {'premium': 50665, 'term_days': 365, 'days_in_force': 0, 'initiator': 'insured', 'min_earned_permille': 100}, 50665], ['flat cancel by insurer', {'premium': 266999, 'term_days': 365, 'days_in_force': 0, 'initiator': 'insurer', 'min_earned_permille': 250}, 266999], ['one day in force', {'premium': 51282, 'term_days': 180, 'days_in_force': 1, 'initiator': 'insurer', 'min_earned_permille': 250}, 50997], ['expiry day', {'premium': 202320, 'term_days': 365, 'days_in_force': 365, 'initiator': 'insured', 'min_earned_permille': 100}, 0], ['negative days rejected', {'premium': 67184, 'term_days': 365, 'days_in_force': -1, 'initiator': 'insured', 'min_earned_permille': 100}, 'invalid'], ['six month policy insured cancel', {'premium': 241675, 'term_days': 182, 'days_in_force': 118, 'initiator': 'insured', 'min_earned_permille': 100}, 76486]], [['insured cancels mid-term', {'premium': 82503, 'term_days': 365, 'days_in_force': 154, 'initiator': 'insured', 'min_earned_permille': 100}, 42924], ['insurer cancels mid-term', {'premium': 137193, 'term_days': 365, 'days_in_force': 295, 'initiator': 'insurer', 'min_earned_permille': 100}, 26311], ['insurer cancel early with minimum on file', {'premium': 157674, 'term_days': 365, 'days_in_force': 15, 'initiator': 'insurer', 'min_earned_permille': 400}, 151194], ['insured minimum earned binds', {'premium': 283617, 'term_days': 365, 'days_in_force': 21, 'initiator': 'insured', 'min_earned_permille': 300}, 198532], ['flat cancel by insured', {'premium': 97666, 'term_days': 365, 'days_in_force': 0, 'initiator': 'insured', 'min_earned_permille': 100}, 97666], ['flat cancel by insurer', {'premium': 137018, 'term_days': 365, 'days_in_force': 0, 'initiator': 'insurer', 'min_earned_permille': 100}, 137018], ['one day in force', {'premium': 261346, 'term_days': 180, 'days_in_force': 1, 'initiator': 'insurer', 'min_earned_permille': 100}, 259894], ['expiry day', {'premium': 135749, 'term_days': 365, 'days_in_force': 365, 'initiator': 'insured', 'min_earned_permille': 100}, 0], ['negative days rejected', {'premium': 260111, 'term_days': 365, 'days_in_force': -1, 'initiator': 'insured', 'min_earned_permille': 100}, 'invalid'], ['six month policy insured cancel', {'premium': 289415, 'term_days': 182, 'days_in_force': 81, 'initiator': 'insured', 'min_earned_permille': 100}, 144548]], [['insured cancels mid-term', {'premium': 59284, 'term_days': 365, 'days_in_force': 188, 'initiator': 'insured', 'min_earned_permille': 100}, 25874], ['insurer cancels mid-term', {'premium': 88844, 'term_days': 365, 'days_in_force': 105, 'initiator': 'insurer', 'min_earned_permille': 100}, 63286], ['insurer cancel early with minimum on file', {'premium': 70835, 'term_days': 365, 'days_in_force': 24, 'initiator': 'insurer', 'min_earned_permille': 400}, 66177], ['insured minimum earned binds', {'premium': 148105, 'term_days': 365, 'days_in_force': 29, 'initiator': 'insured', 'min_earned_permille': 300}, 103674], ['flat cancel by insured', {'premium': 267217, 'term_days': 365, 'days_in_force': 0, 'initiator': 'insured', 'min_earned_permille': 100}, 267217], ['flat cancel by insurer', {'premium': 201088, 'term_days': 365, 'days_in_force': 0, 'initiator': 'insurer', 'min_earned_permille': 100}, 201088], ['one day in force', {'premium': 293778, 'term_days': 180, 'days_in_force': 1, 'initiator': 'insurer', 'min_earned_permille': 250}, 292146], ['expiry day', {'premium': 81772, 'term_days': 365, 'days_in_force': 365, 'initiator': 'insured', 'min_earned_permille': 100}, 0], ['negative days rejected', {'premium': 193452, 'term_days': 365, 'days_in_force': -1, 'initiator': 'insured', 'min_earned_permille': 100}, 'invalid'], ['six month policy insured cancel', {'premium': 273407, 'term_days': 182, 'days_in_force': 107, 'initiator': 'insured', 'min_earned_permille': 100}, 101401]]]
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):
    p=x['premium']; t=x['term_days']; d=x['days_in_force']
    if d<0 or t<=0: return 'invalid'
    if d>=t: return 0
    if d==0: return p
    unearned=Fraction(p*(t-d),t)
    if x['initiator']=='insured':
        ret=unearned*Fraction(90,100)
        ret=min(ret,p-Fraction(p*x['min_earned_permille'],1000))
    else:
        ret=min(unearned,p-Fraction(p*x['min_earned_permille'],2000))
    return math.floor(ret+Fraction(1,2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['insured cancels mid-term', {'premium': 167157, 'term_days': 365, 'days_in_force': 113, 'initiator': 'insured', 'min_earned_permille': 100}, 103866], ['insurer cancels mid-term', {'premium': 107827, 'term_days': 365, 'days_in_force': 285, 'initiator': 'insurer', 'min_earned_permille': 250}, 23633], ['insurer cancel early with minimum on file', {'premium': 135423, 'term_days': 365, 'days_in_force': 32, 'initiator': 'insurer', 'min_earned_permille': 400}, 123550], ['insured minimum earned binds', {'premium': 102264, 'term_days': 365, 'days_in_force': 24, 'initiator': 'insured', 'min_earned_permille': 300}, 71585], ['flat cancel by insured', {'premium': 246750, 'term_days': 365, 'days_in_force': 0, 'initiator': 'insured', 'min_earned_permille': 250}, 246750], ['flat cancel by insurer', {'premium': 77604, 'term_days': 365, 'days_in_force': 0, 'initiator': 'insurer', 'min_earned_permille': 100}, 77604], ['one day in force', {'premium': 285647, 'term_days': 180, 'days_in_force': 1, 'initiator': 'insurer', 'min_earned_permille': 100}, 284060], ['expiry day', {'premium': 163861, 'term_days': 365, 'days_in_force': 365, 'initiator': 'insured', 'min_earned_permille': 100}, 0], ['negative days rejected', {'premium': 253298, 'term_days': 365, 'days_in_force': -1, 'initiator': 'insured', 'min_earned_permille': 250}, 'invalid'], ['six month policy insured cancel', {'premium': 169415, 'term_days': 182, 'days_in_force': 105, 'initiator': 'insured', 'min_earned_permille': 100}, 64508]], [['insured cancels mid-term', {'premium': 136580, 'term_days': 365, 'days_in_force': 120, 'initiator': 'insured', 'min_earned_permille': 100}, 82509], ['insurer cancels mid-term', {'premium': 142197, 'term_days': 365, 'days_in_force': 42, 'initiator': 'insurer', 'min_earned_permille': 100}, 125835], ['insurer cancel early with minimum on file', {'premium': 130516, 'term_days': 365, 'days_in_force': 22, 'initiator': 'insurer', 'min_earned_permille': 400}, 122649], ['insured minimum earned binds', {'premium': 155356, 'term_days': 365, 'days_in_force': 30, 'initiator': 'insured', 'min_earned_permille': 300}, 108749], ['flat cancel by insured', {'premium': 128340, 'term_days': 365, 'days_in_force': 0, 'initiator': 'insured', 'min_earned_permille': 250}, 128340], ['flat cancel by insurer', {'premium': 205493, 'term_days': 365, 'days_in_force': 0, 'initiator': 'insurer', 'min_earned_permille': 250}, 205493], ['one day in force', {'premium': 125332, 'term_days': 180, 'days_in_force': 1, 'initiator': 'insurer', 'min_earned_permille': 100}, 124636], ['expiry day', {'premium': 149858, 'term_days': 365, 'days_in_force': 365, 'initiator': 'insured', 'min_earned_permille': 100}, 0], ['negative days rejected', {'premium': 143435, 'term_days': 365, 'days_in_force': -1, 'initiator': 'insured', 'min_earned_permille': 250}, 'invalid'], ['six month policy insured cancel', {'premium': 219606, 'term_days': 182, 'days_in_force': 115, 'initiator': 'insured', 'min_earned_permille': 100}, 72760]], [['insured cancels mid-term', {'premium': 236883, 'term_days': 365, 'days_in_force': 198, 'initiator': 'insured', 'min_earned_permille': 100}, 97544], ['insurer cancels mid-term', {'premium': 224272, 'term_days': 365, 'days_in_force': 89, 'initiator': 'insurer', 'min_earned_permille': 100}, 169586], ['insurer cancel early with minimum on file', {'premium': 271417, 'term_days': 365, 'days_in_force': 21, 'initiator': 'insurer', 'min_earned_permille': 400}, 255801], ['insured minimum earned binds', {'premium': 236806, 'term_days': 365, 'days_in_force': 27, 'initiator': 'insured', 'min_earned_permille': 300}, 165764], ['flat cancel by insured', {'premium': 50665, 'term_days': 365, 'days_in_force': 0, 'initiator': 'insured', 'min_earned_permille': 100}, 50665], ['flat cancel by insurer', {'premium': 266999, 'term_days': 365, 'days_in_force': 0, 'initiator': 'insurer', 'min_earned_permille': 250}, 266999], ['one day in force', {'premium': 51282, 'term_days': 180, 'days_in_force': 1, 'initiator': 'insurer', 'min_earned_permille': 250}, 50997], ['expiry day', {'premium': 202320, 'term_days': 365, 'days_in_force': 365, 'initiator': 'insured', 'min_earned_permille': 100}, 0], ['negative days rejected', {'premium': 67184, 'term_days': 365, 'days_in_force': -1, 'initiator': 'insured', 'min_earned_permille': 100}, 'invalid'], ['six month policy insured cancel', {'premium': 241675, 'term_days': 182, 'days_in_force': 118, 'initiator': 'insured', 'min_earned_permille': 100}, 76486]], [['insured cancels mid-term', {'premium': 82503, 'term_days': 365, 'days_in_force': 154, 'initiator': 'insured', 'min_earned_permille': 100}, 42924], ['insurer cancels mid-term', {'premium': 137193, 'term_days': 365, 'days_in_force': 295, 'initiator': 'insurer', 'min_earned_permille': 100}, 26311], ['insurer cancel early with minimum on file', {'premium': 157674, 'term_days': 365, 'days_in_force': 15, 'initiator': 'insurer', 'min_earned_permille': 400}, 151194], ['insured minimum earned binds', {'premium': 283617, 'term_days': 365, 'days_in_force': 21, 'initiator': 'insured', 'min_earned_permille': 300}, 198532], ['flat cancel by insured', {'premium': 97666, 'term_days': 365, 'days_in_force': 0, 'initiator': 'insured', 'min_earned_permille': 100}, 97666], ['flat cancel by insurer', {'premium': 137018, 'term_days': 365, 'days_in_force': 0, 'initiator': 'insurer', 'min_earned_permille': 100}, 137018], ['one day in force', {'premium': 261346, 'term_days': 180, 'days_in_force': 1, 'initiator': 'insurer', 'min_earned_permille': 100}, 259894], ['expiry day', {'premium': 135749, 'term_days': 365, 'days_in_force': 365, 'initiator': 'insured', 'min_earned_permille': 100}, 0], ['negative days rejected', {'premium': 260111, 'term_days': 365, 'days_in_force': -1, 'initiator': 'insured', 'min_earned_permille': 100}, 'invalid'], ['six month policy insured cancel', {'premium': 289415, 'term_days': 182, 'days_in_force': 81, 'initiator': 'insured', 'min_earned_permille': 100}, 144548]], [['insured cancels mid-term', {'premium': 59284, 'term_days': 365, 'days_in_force': 188, 'initiator': 'insured', 'min_earned_permille': 100}, 25874], ['insurer cancels mid-term', {'premium': 88844, 'term_days': 365, 'days_in_force': 105, 'initiator': 'insurer', 'min_earned_permille': 100}, 63286], ['insurer cancel early with minimum on file', {'premium': 70835, 'term_days': 365, 'days_in_force': 24, 'initiator': 'insurer', 'min_earned_permille': 400}, 66177], ['insured minimum earned binds', {'premium': 148105, 'term_days': 365, 'days_in_force': 29, 'initiator': 'insured', 'min_earned_permille': 300}, 103674], ['flat cancel by insured', {'premium': 267217, 'term_days': 365, 'days_in_force': 0, 'initiator': 'insured', 'min_earned_permille': 100}, 267217], ['flat cancel by insurer', {'premium': 201088, 'term_days': 365, 'days_in_force': 0, 'initiator': 'insurer', 'min_earned_permille': 100}, 201088], ['one day in force', {'premium': 293778, 'term_days': 180, 'days_in_force': 1, 'initiator': 'insurer', 'min_earned_permille': 250}, 292146], ['expiry day', {'premium': 81772, 'term_days': 365, 'days_in_force': 365, 'initiator': 'insured', 'min_earned_permille': 100}, 0], ['negative days rejected', {'premium': 193452, 'term_days': 365, 'days_in_force': -1, 'initiator': 'insured', 'min_earned_permille': 100}, 'invalid'], ['six month policy insured cancel', {'premium': 273407, 'term_days': 182, 'days_in_force': 107, 'initiator': 'insured', 'min_earned_permille': 100}, 101401]]]
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:
Early insurer-initiated cancellations retain a minimum earned premium.

Input premium, term_days, days_in_force d, initiator, min_earned_permille. d<0 or term<=0 -> 'invalid'; d>=term -> 0; d==0 (flat cancel) returns the full premium. Otherwise unearned = premium*(term-d)/term; the insurer returns it in full; an insured cancellation returns 90% of unearned but never more than premium minus the minimum earned premium. Round half-up once.

split: open-access