prompt:
Level installments exceed the balance share and the last installment is reduced.

Input premium, n total payments including the down payment (n<1 -> 'invalid'; n==1 -> [premium], no fee), down (per mille), fee per installment. Down = premium*down/1000 rounded half-up; the rest splits over n-1 installments by floor division with the remainder added to the last installment; each installment after the down payment carries the fee.

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):
    groups={}
    for g,code,v in x['discounts']:
        groups.setdefault(g,{})
        groups[g][code]=groups[g].get(code,0)+v
    f=Fraction(1)
    for g in sorted(groups):
        f*=1-Fraction(sum(groups[g].values()),1000)
    d=min(Fraction(x['cap'],1000),1-f)
    net=math.floor(x['premium']*(1-d)+Fraction(1,2))
    return max(net,x['min_premium'])
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['two groups multiply', {'premium': 179834, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 51], ['driver', 'student', 40]], 'cap': 350, 'min_premium': 20000}, 147122], ['duplicate discount code', {'premium': 83536, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 350, 'min_premium': 20000}, 72676], ['duplicate code rising value', {'premium': 216432, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 300, 'min_premium': 20000}, 199377], ['cap binds', {'premium': 295817, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 221863], ['single group', {'premium': 83079, 'discounts': [['vehicle', 'abs', 45], ['vehicle', 'alarm', 25]], 'cap': 350, 'min_premium': 20000}, 77263], ['minimum premium binds', {'premium': 22100, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 300, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 114606, 'discounts': [], 'cap': 350, 'min_premium': 20000}, 114606]], [['two groups multiply', {'premium': 259533, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 52], ['driver', 'student', 40]], 'cap': 300, 'min_premium': 20000}, 212090], ['duplicate discount code', {'premium': 222796, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 350, 'min_premium': 20000}, 193833], ['duplicate code rising value', {'premium': 264635, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 300, 'min_premium': 20000}, 243782], ['cap binds', {'premium': 274466, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 205850], ['single group', {'premium': 122187, 'discounts': [['vehicle', 'abs', 48], ['vehicle', 'alarm', 51]], 'cap': 350, 'min_premium': 20000}, 110090], ['minimum premium binds', {'premium': 22200, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 300, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 67195, 'discounts': [], 'cap': 300, 'min_premium': 20000}, 67195]], [['two groups multiply', {'premium': 246480, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 53], ['driver', 'student', 40]], 'cap': 300, 'min_premium': 20000}, 201202], ['duplicate discount code', {'premium': 212077, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 350, 'min_premium': 20000}, 184507], ['duplicate code rising value', {'premium': 239143, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 300, 'min_premium': 20000}, 220299], ['cap binds', {'premium': 260788, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 195591], ['single group', {'premium': 76428, 'discounts': [['vehicle', 'abs', 25], ['vehicle', 'alarm', 25]], 'cap': 350, 'min_premium': 20000}, 72607], ['minimum premium binds', {'premium': 22300, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 350, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 231596, 'discounts': [], 'cap': 300, 'min_premium': 20000}, 231596]], [['two groups multiply', {'premium': 234855, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 54], ['driver', 'student', 40]], 'cap': 300, 'min_premium': 20000}, 191501], ['duplicate discount code', {'premium': 62000, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 300, 'min_premium': 20000}, 53940], ['duplicate code rising value', {'premium': 164924, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 350, 'min_premium': 20000}, 151928], ['cap binds', {'premium': 160428, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 120321], ['single group', {'premium': 150010, 'discounts': [['vehicle', 'abs', 53], ['vehicle', 'alarm', 34]], 'cap': 350, 'min_premium': 20000}, 136959], ['minimum premium binds', {'premium': 22400, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 350, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 64059, 'discounts': [], 'cap': 350, 'min_premium': 20000}, 64059]], [['two groups multiply', {'premium': 70322, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 55], ['driver', 'student', 40]], 'cap': 350, 'min_premium': 20000}, 57277], ['duplicate discount code', {'premium': 120452, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 300, 'min_premium': 20000}, 104793], ['duplicate code rising value', {'premium': 89846, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 350, 'min_premium': 20000}, 82766], ['cap binds', {'premium': 116342, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 87257], ['single group', {'premium': 214086, 'discounts': [['vehicle', 'abs', 20], ['vehicle', 'alarm', 44]], 'cap': 300, 'min_premium': 20000}, 200384], ['minimum premium binds', {'premium': 22500, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 350, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 211453, 'discounts': [], 'cap': 300, 'min_premium': 20000}, 211453]]]
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):
    groups={}
    for g,code,v in x['discounts']:
        groups.setdefault(g,{})
        groups[g][code]=v
    f=Fraction(1)
    for g in sorted(groups):
        f*=1-Fraction(sum(groups[g].values()),1000)
    d=min(Fraction(x['cap'],1000),1-f)
    net=math.floor(x['premium']*(1-d)+Fraction(1,2))
    return max(net,x['min_premium'])
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['two groups multiply', {'premium': 179834, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 51], ['driver', 'student', 40]], 'cap': 350, 'min_premium': 20000}, 147122], ['duplicate discount code', {'premium': 83536, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 350, 'min_premium': 20000}, 72676], ['duplicate code rising value', {'premium': 216432, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 300, 'min_premium': 20000}, 199377], ['cap binds', {'premium': 295817, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 221863], ['single group', {'premium': 83079, 'discounts': [['vehicle', 'abs', 45], ['vehicle', 'alarm', 25]], 'cap': 350, 'min_premium': 20000}, 77263], ['minimum premium binds', {'premium': 22100, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 300, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 114606, 'discounts': [], 'cap': 350, 'min_premium': 20000}, 114606]], [['two groups multiply', {'premium': 259533, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 52], ['driver', 'student', 40]], 'cap': 300, 'min_premium': 20000}, 212090], ['duplicate discount code', {'premium': 222796, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 350, 'min_premium': 20000}, 193833], ['duplicate code rising value', {'premium': 264635, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 300, 'min_premium': 20000}, 243782], ['cap binds', {'premium': 274466, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 205850], ['single group', {'premium': 122187, 'discounts': [['vehicle', 'abs', 48], ['vehicle', 'alarm', 51]], 'cap': 350, 'min_premium': 20000}, 110090], ['minimum premium binds', {'premium': 22200, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 300, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 67195, 'discounts': [], 'cap': 300, 'min_premium': 20000}, 67195]], [['two groups multiply', {'premium': 246480, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 53], ['driver', 'student', 40]], 'cap': 300, 'min_premium': 20000}, 201202], ['duplicate discount code', {'premium': 212077, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 350, 'min_premium': 20000}, 184507], ['duplicate code rising value', {'premium': 239143, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 300, 'min_premium': 20000}, 220299], ['cap binds', {'premium': 260788, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 195591], ['single group', {'premium': 76428, 'discounts': [['vehicle', 'abs', 25], ['vehicle', 'alarm', 25]], 'cap': 350, 'min_premium': 20000}, 72607], ['minimum premium binds', {'premium': 22300, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 350, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 231596, 'discounts': [], 'cap': 300, 'min_premium': 20000}, 231596]], [['two groups multiply', {'premium': 234855, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 54], ['driver', 'student', 40]], 'cap': 300, 'min_premium': 20000}, 191501], ['duplicate discount code', {'premium': 62000, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 300, 'min_premium': 20000}, 53940], ['duplicate code rising value', {'premium': 164924, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 350, 'min_premium': 20000}, 151928], ['cap binds', {'premium': 160428, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 120321], ['single group', {'premium': 150010, 'discounts': [['vehicle', 'abs', 53], ['vehicle', 'alarm', 34]], 'cap': 350, 'min_premium': 20000}, 136959], ['minimum premium binds', {'premium': 22400, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 350, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 64059, 'discounts': [], 'cap': 350, 'min_premium': 20000}, 64059]], [['two groups multiply', {'premium': 70322, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 55], ['driver', 'student', 40]], 'cap': 350, 'min_premium': 20000}, 57277], ['duplicate discount code', {'premium': 120452, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 300, 'min_premium': 20000}, 104793], ['duplicate code rising value', {'premium': 89846, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 350, 'min_premium': 20000}, 82766], ['cap binds', {'premium': 116342, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 87257], ['single group', {'premium': 214086, 'discounts': [['vehicle', 'abs', 20], ['vehicle', 'alarm', 44]], 'cap': 300, 'min_premium': 20000}, 200384], ['minimum premium binds', {'premium': 22500, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 350, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 211453, 'discounts': [], 'cap': 300, 'min_premium': 20000}, 211453]]]
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 discount reported twice is granted twice.

Input premium, discounts [[group, code, per mille]], cap per mille, min_premium. A code repeated within a group counts once at its largest value; codes within a group add; groups combine multiplicatively; the total discount 1-product is capped; net = premium*(1-d) rounded half-up, then floored at min_premium.

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):
    groups={}
    for g,code,v in x['discounts']:
        groups.setdefault(g,{})
        groups[g][code]=max(groups[g].get(code,0),v)
    f=Fraction(1)
    for g in sorted(groups):
        for v in groups[g].values(): f*=1-Fraction(v,1000)
    d=min(Fraction(x['cap'],1000),1-f)
    net=math.floor(x['premium']*(1-d)+Fraction(1,2))
    return max(net,x['min_premium'])
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['two groups multiply', {'premium': 179834, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 51], ['driver', 'student', 40]], 'cap': 350, 'min_premium': 20000}, 147122], ['duplicate discount code', {'premium': 83536, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 350, 'min_premium': 20000}, 72676], ['duplicate code rising value', {'premium': 216432, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 300, 'min_premium': 20000}, 199377], ['cap binds', {'premium': 295817, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 221863], ['single group', {'premium': 83079, 'discounts': [['vehicle', 'abs', 45], ['vehicle', 'alarm', 25]], 'cap': 350, 'min_premium': 20000}, 77263], ['minimum premium binds', {'premium': 22100, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 300, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 114606, 'discounts': [], 'cap': 350, 'min_premium': 20000}, 114606]], [['two groups multiply', {'premium': 259533, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 52], ['driver', 'student', 40]], 'cap': 300, 'min_premium': 20000}, 212090], ['duplicate discount code', {'premium': 222796, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 350, 'min_premium': 20000}, 193833], ['duplicate code rising value', {'premium': 264635, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 300, 'min_premium': 20000}, 243782], ['cap binds', {'premium': 274466, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 205850], ['single group', {'premium': 122187, 'discounts': [['vehicle', 'abs', 48], ['vehicle', 'alarm', 51]], 'cap': 350, 'min_premium': 20000}, 110090], ['minimum premium binds', {'premium': 22200, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 300, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 67195, 'discounts': [], 'cap': 300, 'min_premium': 20000}, 67195]], [['two groups multiply', {'premium': 246480, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 53], ['driver', 'student', 40]], 'cap': 300, 'min_premium': 20000}, 201202], ['duplicate discount code', {'premium': 212077, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 350, 'min_premium': 20000}, 184507], ['duplicate code rising value', {'premium': 239143, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 300, 'min_premium': 20000}, 220299], ['cap binds', {'premium': 260788, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 195591], ['single group', {'premium': 76428, 'discounts': [['vehicle', 'abs', 25], ['vehicle', 'alarm', 25]], 'cap': 350, 'min_premium': 20000}, 72607], ['minimum premium binds', {'premium': 22300, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 350, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 231596, 'discounts': [], 'cap': 300, 'min_premium': 20000}, 231596]], [['two groups multiply', {'premium': 234855, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 54], ['driver', 'student', 40]], 'cap': 300, 'min_premium': 20000}, 191501], ['duplicate discount code', {'premium': 62000, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 300, 'min_premium': 20000}, 53940], ['duplicate code rising value', {'premium': 164924, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 350, 'min_premium': 20000}, 151928], ['cap binds', {'premium': 160428, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 120321], ['single group', {'premium': 150010, 'discounts': [['vehicle', 'abs', 53], ['vehicle', 'alarm', 34]], 'cap': 350, 'min_premium': 20000}, 136959], ['minimum premium binds', {'premium': 22400, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 350, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 64059, 'discounts': [], 'cap': 350, 'min_premium': 20000}, 64059]], [['two groups multiply', {'premium': 70322, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 55], ['driver', 'student', 40]], 'cap': 350, 'min_premium': 20000}, 57277], ['duplicate discount code', {'premium': 120452, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 300, 'min_premium': 20000}, 104793], ['duplicate code rising value', {'premium': 89846, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 350, 'min_premium': 20000}, 82766], ['cap binds', {'premium': 116342, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 87257], ['single group', {'premium': 214086, 'discounts': [['vehicle', 'abs', 20], ['vehicle', 'alarm', 44]], 'cap': 300, 'min_premium': 20000}, 200384], ['minimum premium binds', {'premium': 22500, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 350, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 211453, 'discounts': [], 'cap': 300, 'min_premium': 20000}, 211453]]]
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):
    groups={}
    for g,code,v in x['discounts']:
        groups.setdefault(g,{})
        groups[g][code]=max(groups[g].get(code,0),v)
    f=Fraction(1)
    for g in sorted(groups):
        f*=1-Fraction(max(groups[g].values()),1000)
    d=min(Fraction(x['cap'],1000),1-f)
    net=math.floor(x['premium']*(1-d)+Fraction(1,2))
    return max(net,x['min_premium'])
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['two groups multiply', {'premium': 179834, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 51], ['driver', 'student', 40]], 'cap': 350, 'min_premium': 20000}, 147122], ['duplicate discount code', {'premium': 83536, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 350, 'min_premium': 20000}, 72676], ['duplicate code rising value', {'premium': 216432, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 300, 'min_premium': 20000}, 199377], ['cap binds', {'premium': 295817, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 221863], ['single group', {'premium': 83079, 'discounts': [['vehicle', 'abs', 45], ['vehicle', 'alarm', 25]], 'cap': 350, 'min_premium': 20000}, 77263], ['minimum premium binds', {'premium': 22100, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 300, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 114606, 'discounts': [], 'cap': 350, 'min_premium': 20000}, 114606]], [['two groups multiply', {'premium': 259533, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 52], ['driver', 'student', 40]], 'cap': 300, 'min_premium': 20000}, 212090], ['duplicate discount code', {'premium': 222796, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 350, 'min_premium': 20000}, 193833], ['duplicate code rising value', {'premium': 264635, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 300, 'min_premium': 20000}, 243782], ['cap binds', {'premium': 274466, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 205850], ['single group', {'premium': 122187, 'discounts': [['vehicle', 'abs', 48], ['vehicle', 'alarm', 51]], 'cap': 350, 'min_premium': 20000}, 110090], ['minimum premium binds', {'premium': 22200, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 300, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 67195, 'discounts': [], 'cap': 300, 'min_premium': 20000}, 67195]], [['two groups multiply', {'premium': 246480, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 53], ['driver', 'student', 40]], 'cap': 300, 'min_premium': 20000}, 201202], ['duplicate discount code', {'premium': 212077, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 350, 'min_premium': 20000}, 184507], ['duplicate code rising value', {'premium': 239143, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 300, 'min_premium': 20000}, 220299], ['cap binds', {'premium': 260788, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 195591], ['single group', {'premium': 76428, 'discounts': [['vehicle', 'abs', 25], ['vehicle', 'alarm', 25]], 'cap': 350, 'min_premium': 20000}, 72607], ['minimum premium binds', {'premium': 22300, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 350, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 231596, 'discounts': [], 'cap': 300, 'min_premium': 20000}, 231596]], [['two groups multiply', {'premium': 234855, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 54], ['driver', 'student', 40]], 'cap': 300, 'min_premium': 20000}, 191501], ['duplicate discount code', {'premium': 62000, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 300, 'min_premium': 20000}, 53940], ['duplicate code rising value', {'premium': 164924, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 350, 'min_premium': 20000}, 151928], ['cap binds', {'premium': 160428, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 120321], ['single group', {'premium': 150010, 'discounts': [['vehicle', 'abs', 53], ['vehicle', 'alarm', 34]], 'cap': 350, 'min_premium': 20000}, 136959], ['minimum premium binds', {'premium': 22400, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 350, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 64059, 'discounts': [], 'cap': 350, 'min_premium': 20000}, 64059]], [['two groups multiply', {'premium': 70322, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 55], ['driver', 'student', 40]], 'cap': 350, 'min_premium': 20000}, 57277], ['duplicate discount code', {'premium': 120452, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 300, 'min_premium': 20000}, 104793], ['duplicate code rising value', {'premium': 89846, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 350, 'min_premium': 20000}, 82766], ['cap binds', {'premium': 116342, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 87257], ['single group', {'premium': 214086, 'discounts': [['vehicle', 'abs', 20], ['vehicle', 'alarm', 44]], 'cap': 300, 'min_premium': 20000}, 200384], ['minimum premium binds', {'premium': 22500, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 350, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 211453, 'discounts': [], 'cap': 300, 'min_premium': 20000}, 211453]]]
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:
Same-group discounts are worth less than the filed additive total.

Input premium, discounts [[group, code, per mille]], cap per mille, min_premium. A code repeated within a group counts once at its largest value; codes within a group add; groups combine multiplicatively; the total discount 1-product is capped; net = premium*(1-d) rounded half-up, then floored at min_premium.

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):
    groups={}
    for g,code,v in x['discounts']:
        groups.setdefault(g,{})
        groups[g][code]=max(groups[g].get(code,0),v)
    f=Fraction(1)
    for g in sorted(groups):
        f-=Fraction(sum(groups[g].values()),1000)
    d=min(Fraction(x['cap'],1000),1-f)
    net=math.floor(x['premium']*(1-d)+Fraction(1,2))
    return max(net,x['min_premium'])
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['two groups multiply', {'premium': 179834, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 51], ['driver', 'student', 40]], 'cap': 350, 'min_premium': 20000}, 147122], ['duplicate discount code', {'premium': 83536, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 350, 'min_premium': 20000}, 72676], ['duplicate code rising value', {'premium': 216432, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 300, 'min_premium': 20000}, 199377], ['cap binds', {'premium': 295817, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 221863], ['single group', {'premium': 83079, 'discounts': [['vehicle', 'abs', 45], ['vehicle', 'alarm', 25]], 'cap': 350, 'min_premium': 20000}, 77263], ['minimum premium binds', {'premium': 22100, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 300, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 114606, 'discounts': [], 'cap': 350, 'min_premium': 20000}, 114606]], [['two groups multiply', {'premium': 259533, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 52], ['driver', 'student', 40]], 'cap': 300, 'min_premium': 20000}, 212090], ['duplicate discount code', {'premium': 222796, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 350, 'min_premium': 20000}, 193833], ['duplicate code rising value', {'premium': 264635, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 300, 'min_premium': 20000}, 243782], ['cap binds', {'premium': 274466, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 205850], ['single group', {'premium': 122187, 'discounts': [['vehicle', 'abs', 48], ['vehicle', 'alarm', 51]], 'cap': 350, 'min_premium': 20000}, 110090], ['minimum premium binds', {'premium': 22200, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 300, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 67195, 'discounts': [], 'cap': 300, 'min_premium': 20000}, 67195]], [['two groups multiply', {'premium': 246480, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 53], ['driver', 'student', 40]], 'cap': 300, 'min_premium': 20000}, 201202], ['duplicate discount code', {'premium': 212077, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 350, 'min_premium': 20000}, 184507], ['duplicate code rising value', {'premium': 239143, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 300, 'min_premium': 20000}, 220299], ['cap binds', {'premium': 260788, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 195591], ['single group', {'premium': 76428, 'discounts': [['vehicle', 'abs', 25], ['vehicle', 'alarm', 25]], 'cap': 350, 'min_premium': 20000}, 72607], ['minimum premium binds', {'premium': 22300, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 350, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 231596, 'discounts': [], 'cap': 300, 'min_premium': 20000}, 231596]], [['two groups multiply', {'premium': 234855, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 54], ['driver', 'student', 40]], 'cap': 300, 'min_premium': 20000}, 191501], ['duplicate discount code', {'premium': 62000, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 300, 'min_premium': 20000}, 53940], ['duplicate code rising value', {'premium': 164924, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 350, 'min_premium': 20000}, 151928], ['cap binds', {'premium': 160428, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 120321], ['single group', {'premium': 150010, 'discounts': [['vehicle', 'abs', 53], ['vehicle', 'alarm', 34]], 'cap': 350, 'min_premium': 20000}, 136959], ['minimum premium binds', {'premium': 22400, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 350, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 64059, 'discounts': [], 'cap': 350, 'min_premium': 20000}, 64059]], [['two groups multiply', {'premium': 70322, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 55], ['driver', 'student', 40]], 'cap': 350, 'min_premium': 20000}, 57277], ['duplicate discount code', {'premium': 120452, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 300, 'min_premium': 20000}, 104793], ['duplicate code rising value', {'premium': 89846, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 350, 'min_premium': 20000}, 82766], ['cap binds', {'premium': 116342, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 87257], ['single group', {'premium': 214086, 'discounts': [['vehicle', 'abs', 20], ['vehicle', 'alarm', 44]], 'cap': 300, 'min_premium': 20000}, 200384], ['minimum premium binds', {'premium': 22500, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 350, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 211453, 'discounts': [], 'cap': 300, 'min_premium': 20000}, 211453]]]
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):
    groups={}
    for g,code,v in x['discounts']:
        groups.setdefault(g,{})
        groups[g][code]=max(groups[g].get(code,0),v)
    f=Fraction(1)
    for g in sorted(groups):
        f=min(f,1-Fraction(sum(groups[g].values()),1000))
    d=min(Fraction(x['cap'],1000),1-f)
    net=math.floor(x['premium']*(1-d)+Fraction(1,2))
    return max(net,x['min_premium'])
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['two groups multiply', {'premium': 179834, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 51], ['driver', 'student', 40]], 'cap': 350, 'min_premium': 20000}, 147122], ['duplicate discount code', {'premium': 83536, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 350, 'min_premium': 20000}, 72676], ['duplicate code rising value', {'premium': 216432, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 300, 'min_premium': 20000}, 199377], ['cap binds', {'premium': 295817, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 221863], ['single group', {'premium': 83079, 'discounts': [['vehicle', 'abs', 45], ['vehicle', 'alarm', 25]], 'cap': 350, 'min_premium': 20000}, 77263], ['minimum premium binds', {'premium': 22100, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 300, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 114606, 'discounts': [], 'cap': 350, 'min_premium': 20000}, 114606]], [['two groups multiply', {'premium': 259533, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 52], ['driver', 'student', 40]], 'cap': 300, 'min_premium': 20000}, 212090], ['duplicate discount code', {'premium': 222796, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 350, 'min_premium': 20000}, 193833], ['duplicate code rising value', {'premium': 264635, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 300, 'min_premium': 20000}, 243782], ['cap binds', {'premium': 274466, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 205850], ['single group', {'premium': 122187, 'discounts': [['vehicle', 'abs', 48], ['vehicle', 'alarm', 51]], 'cap': 350, 'min_premium': 20000}, 110090], ['minimum premium binds', {'premium': 22200, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 300, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 67195, 'discounts': [], 'cap': 300, 'min_premium': 20000}, 67195]], [['two groups multiply', {'premium': 246480, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 53], ['driver', 'student', 40]], 'cap': 300, 'min_premium': 20000}, 201202], ['duplicate discount code', {'premium': 212077, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 350, 'min_premium': 20000}, 184507], ['duplicate code rising value', {'premium': 239143, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 300, 'min_premium': 20000}, 220299], ['cap binds', {'premium': 260788, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 195591], ['single group', {'premium': 76428, 'discounts': [['vehicle', 'abs', 25], ['vehicle', 'alarm', 25]], 'cap': 350, 'min_premium': 20000}, 72607], ['minimum premium binds', {'premium': 22300, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 350, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 231596, 'discounts': [], 'cap': 300, 'min_premium': 20000}, 231596]], [['two groups multiply', {'premium': 234855, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 54], ['driver', 'student', 40]], 'cap': 300, 'min_premium': 20000}, 191501], ['duplicate discount code', {'premium': 62000, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 300, 'min_premium': 20000}, 53940], ['duplicate code rising value', {'premium': 164924, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 350, 'min_premium': 20000}, 151928], ['cap binds', {'premium': 160428, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 120321], ['single group', {'premium': 150010, 'discounts': [['vehicle', 'abs', 53], ['vehicle', 'alarm', 34]], 'cap': 350, 'min_premium': 20000}, 136959], ['minimum premium binds', {'premium': 22400, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 350, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 64059, 'discounts': [], 'cap': 350, 'min_premium': 20000}, 64059]], [['two groups multiply', {'premium': 70322, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 55], ['driver', 'student', 40]], 'cap': 350, 'min_premium': 20000}, 57277], ['duplicate discount code', {'premium': 120452, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 300, 'min_premium': 20000}, 104793], ['duplicate code rising value', {'premium': 89846, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 350, 'min_premium': 20000}, 82766], ['cap binds', {'premium': 116342, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 87257], ['single group', {'premium': 214086, 'discounts': [['vehicle', 'abs', 20], ['vehicle', 'alarm', 44]], 'cap': 300, 'min_premium': 20000}, 200384], ['minimum premium binds', {'premium': 22500, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 350, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 211453, 'discounts': [], 'cap': 300, 'min_premium': 20000}, 211453]]]
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:
Policies with several discount groups receive too large a discount.

Input premium, discounts [[group, code, per mille]], cap per mille, min_premium. A code repeated within a group counts once at its largest value; codes within a group add; groups combine multiplicatively; the total discount 1-product is capped; net = premium*(1-d) rounded half-up, then floored at min_premium.

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):
    groups={}
    for g,code,v in x['discounts']:
        groups.setdefault(g,{})
        groups[g][code]=max(groups[g].get(code,0),v)
    f=Fraction(1)
    for g in sorted(groups):
        f*=1-Fraction(sum(groups[g].values()),1000)
    d=1-f
    net=math.floor(x['premium']*(1-d)+Fraction(1,2))
    return max(net,x['min_premium'])
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['two groups multiply', {'premium': 179834, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 51], ['driver', 'student', 40]], 'cap': 350, 'min_premium': 20000}, 147122], ['duplicate discount code', {'premium': 83536, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 350, 'min_premium': 20000}, 72676], ['duplicate code rising value', {'premium': 216432, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 300, 'min_premium': 20000}, 199377], ['cap binds', {'premium': 295817, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 221863], ['single group', {'premium': 83079, 'discounts': [['vehicle', 'abs', 45], ['vehicle', 'alarm', 25]], 'cap': 350, 'min_premium': 20000}, 77263], ['minimum premium binds', {'premium': 22100, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 300, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 114606, 'discounts': [], 'cap': 350, 'min_premium': 20000}, 114606]], [['two groups multiply', {'premium': 259533, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 52], ['driver', 'student', 40]], 'cap': 300, 'min_premium': 20000}, 212090], ['duplicate discount code', {'premium': 222796, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 350, 'min_premium': 20000}, 193833], ['duplicate code rising value', {'premium': 264635, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 300, 'min_premium': 20000}, 243782], ['cap binds', {'premium': 274466, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 205850], ['single group', {'premium': 122187, 'discounts': [['vehicle', 'abs', 48], ['vehicle', 'alarm', 51]], 'cap': 350, 'min_premium': 20000}, 110090], ['minimum premium binds', {'premium': 22200, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 300, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 67195, 'discounts': [], 'cap': 300, 'min_premium': 20000}, 67195]], [['two groups multiply', {'premium': 246480, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 53], ['driver', 'student', 40]], 'cap': 300, 'min_premium': 20000}, 201202], ['duplicate discount code', {'premium': 212077, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 350, 'min_premium': 20000}, 184507], ['duplicate code rising value', {'premium': 239143, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 300, 'min_premium': 20000}, 220299], ['cap binds', {'premium': 260788, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 195591], ['single group', {'premium': 76428, 'discounts': [['vehicle', 'abs', 25], ['vehicle', 'alarm', 25]], 'cap': 350, 'min_premium': 20000}, 72607], ['minimum premium binds', {'premium': 22300, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 350, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 231596, 'discounts': [], 'cap': 300, 'min_premium': 20000}, 231596]], [['two groups multiply', {'premium': 234855, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 54], ['driver', 'student', 40]], 'cap': 300, 'min_premium': 20000}, 191501], ['duplicate discount code', {'premium': 62000, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 300, 'min_premium': 20000}, 53940], ['duplicate code rising value', {'premium': 164924, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 350, 'min_premium': 20000}, 151928], ['cap binds', {'premium': 160428, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 120321], ['single group', {'premium': 150010, 'discounts': [['vehicle', 'abs', 53], ['vehicle', 'alarm', 34]], 'cap': 350, 'min_premium': 20000}, 136959], ['minimum premium binds', {'premium': 22400, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 350, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 64059, 'discounts': [], 'cap': 350, 'min_premium': 20000}, 64059]], [['two groups multiply', {'premium': 70322, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 55], ['driver', 'student', 40]], 'cap': 350, 'min_premium': 20000}, 57277], ['duplicate discount code', {'premium': 120452, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 300, 'min_premium': 20000}, 104793], ['duplicate code rising value', {'premium': 89846, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 350, 'min_premium': 20000}, 82766], ['cap binds', {'premium': 116342, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 87257], ['single group', {'premium': 214086, 'discounts': [['vehicle', 'abs', 20], ['vehicle', 'alarm', 44]], 'cap': 300, 'min_premium': 20000}, 200384], ['minimum premium binds', {'premium': 22500, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 350, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 211453, 'discounts': [], 'cap': 300, 'min_premium': 20000}, 211453]]]
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):
    groups={}
    for g,code,v in x['discounts']:
        groups.setdefault(g,{})
        groups[g][code]=max(groups[g].get(code,0),v)
    f=Fraction(1)
    for g in sorted(groups):
        f*=1-Fraction(sum(groups[g].values()),1000)
    d=min(Fraction(x['cap'],100),1-f)
    net=math.floor(x['premium']*(1-d)+Fraction(1,2))
    return max(net,x['min_premium'])
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['two groups multiply', {'premium': 179834, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 51], ['driver', 'student', 40]], 'cap': 350, 'min_premium': 20000}, 147122], ['duplicate discount code', {'premium': 83536, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 350, 'min_premium': 20000}, 72676], ['duplicate code rising value', {'premium': 216432, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 300, 'min_premium': 20000}, 199377], ['cap binds', {'premium': 295817, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 221863], ['single group', {'premium': 83079, 'discounts': [['vehicle', 'abs', 45], ['vehicle', 'alarm', 25]], 'cap': 350, 'min_premium': 20000}, 77263], ['minimum premium binds', {'premium': 22100, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 300, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 114606, 'discounts': [], 'cap': 350, 'min_premium': 20000}, 114606]], [['two groups multiply', {'premium': 259533, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 52], ['driver', 'student', 40]], 'cap': 300, 'min_premium': 20000}, 212090], ['duplicate discount code', {'premium': 222796, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 350, 'min_premium': 20000}, 193833], ['duplicate code rising value', {'premium': 264635, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 300, 'min_premium': 20000}, 243782], ['cap binds', {'premium': 274466, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 205850], ['single group', {'premium': 122187, 'discounts': [['vehicle', 'abs', 48], ['vehicle', 'alarm', 51]], 'cap': 350, 'min_premium': 20000}, 110090], ['minimum premium binds', {'premium': 22200, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 300, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 67195, 'discounts': [], 'cap': 300, 'min_premium': 20000}, 67195]], [['two groups multiply', {'premium': 246480, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 53], ['driver', 'student', 40]], 'cap': 300, 'min_premium': 20000}, 201202], ['duplicate discount code', {'premium': 212077, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 350, 'min_premium': 20000}, 184507], ['duplicate code rising value', {'premium': 239143, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 300, 'min_premium': 20000}, 220299], ['cap binds', {'premium': 260788, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 195591], ['single group', {'premium': 76428, 'discounts': [['vehicle', 'abs', 25], ['vehicle', 'alarm', 25]], 'cap': 350, 'min_premium': 20000}, 72607], ['minimum premium binds', {'premium': 22300, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 350, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 231596, 'discounts': [], 'cap': 300, 'min_premium': 20000}, 231596]], [['two groups multiply', {'premium': 234855, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 54], ['driver', 'student', 40]], 'cap': 300, 'min_premium': 20000}, 191501], ['duplicate discount code', {'premium': 62000, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 300, 'min_premium': 20000}, 53940], ['duplicate code rising value', {'premium': 164924, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 350, 'min_premium': 20000}, 151928], ['cap binds', {'premium': 160428, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 120321], ['single group', {'premium': 150010, 'discounts': [['vehicle', 'abs', 53], ['vehicle', 'alarm', 34]], 'cap': 350, 'min_premium': 20000}, 136959], ['minimum premium binds', {'premium': 22400, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 350, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 64059, 'discounts': [], 'cap': 350, 'min_premium': 20000}, 64059]], [['two groups multiply', {'premium': 70322, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 55], ['driver', 'student', 40]], 'cap': 350, 'min_premium': 20000}, 57277], ['duplicate discount code', {'premium': 120452, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 300, 'min_premium': 20000}, 104793], ['duplicate code rising value', {'premium': 89846, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 350, 'min_premium': 20000}, 82766], ['cap binds', {'premium': 116342, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 87257], ['single group', {'premium': 214086, 'discounts': [['vehicle', 'abs', 20], ['vehicle', 'alarm', 44]], 'cap': 300, 'min_premium': 20000}, 200384], ['minimum premium binds', {'premium': 22500, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 350, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 211453, 'discounts': [], 'cap': 300, 'min_premium': 20000}, 211453]]]
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:
Stacked discounts exceed the maximum allowed discount.

Input premium, discounts [[group, code, per mille]], cap per mille, min_premium. A code repeated within a group counts once at its largest value; codes within a group add; groups combine multiplicatively; the total discount 1-product is capped; net = premium*(1-d) rounded half-up, then floored at min_premium.

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):
    groups={}
    for g,code,v in x['discounts']:
        groups.setdefault(g,{})
        groups[g][code]=max(groups[g].get(code,0),v)
    f=Fraction(1)
    for g in sorted(groups):
        f*=1-Fraction(sum(groups[g].values()),1000)
    d=min(Fraction(x['cap'],1000),1-f)
    net=math.floor(x['premium']*(1-d)+Fraction(1,2))
    return net
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['two groups multiply', {'premium': 179834, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 51], ['driver', 'student', 40]], 'cap': 350, 'min_premium': 20000}, 147122], ['duplicate discount code', {'premium': 83536, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 350, 'min_premium': 20000}, 72676], ['duplicate code rising value', {'premium': 216432, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 300, 'min_premium': 20000}, 199377], ['cap binds', {'premium': 295817, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 221863], ['single group', {'premium': 83079, 'discounts': [['vehicle', 'abs', 45], ['vehicle', 'alarm', 25]], 'cap': 350, 'min_premium': 20000}, 77263], ['minimum premium binds', {'premium': 22100, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 300, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 114606, 'discounts': [], 'cap': 350, 'min_premium': 20000}, 114606]], [['two groups multiply', {'premium': 259533, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 52], ['driver', 'student', 40]], 'cap': 300, 'min_premium': 20000}, 212090], ['duplicate discount code', {'premium': 222796, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 350, 'min_premium': 20000}, 193833], ['duplicate code rising value', {'premium': 264635, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 300, 'min_premium': 20000}, 243782], ['cap binds', {'premium': 274466, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 205850], ['single group', {'premium': 122187, 'discounts': [['vehicle', 'abs', 48], ['vehicle', 'alarm', 51]], 'cap': 350, 'min_premium': 20000}, 110090], ['minimum premium binds', {'premium': 22200, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 300, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 67195, 'discounts': [], 'cap': 300, 'min_premium': 20000}, 67195]], [['two groups multiply', {'premium': 246480, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 53], ['driver', 'student', 40]], 'cap': 300, 'min_premium': 20000}, 201202], ['duplicate discount code', {'premium': 212077, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 350, 'min_premium': 20000}, 184507], ['duplicate code rising value', {'premium': 239143, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 300, 'min_premium': 20000}, 220299], ['cap binds', {'premium': 260788, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 195591], ['single group', {'premium': 76428, 'discounts': [['vehicle', 'abs', 25], ['vehicle', 'alarm', 25]], 'cap': 350, 'min_premium': 20000}, 72607], ['minimum premium binds', {'premium': 22300, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 350, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 231596, 'discounts': [], 'cap': 300, 'min_premium': 20000}, 231596]], [['two groups multiply', {'premium': 234855, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 54], ['driver', 'student', 40]], 'cap': 300, 'min_premium': 20000}, 191501], ['duplicate discount code', {'premium': 62000, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 300, 'min_premium': 20000}, 53940], ['duplicate code rising value', {'premium': 164924, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 350, 'min_premium': 20000}, 151928], ['cap binds', {'premium': 160428, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 120321], ['single group', {'premium': 150010, 'discounts': [['vehicle', 'abs', 53], ['vehicle', 'alarm', 34]], 'cap': 350, 'min_premium': 20000}, 136959], ['minimum premium binds', {'premium': 22400, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 350, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 64059, 'discounts': [], 'cap': 350, 'min_premium': 20000}, 64059]], [['two groups multiply', {'premium': 70322, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 55], ['driver', 'student', 40]], 'cap': 350, 'min_premium': 20000}, 57277], ['duplicate discount code', {'premium': 120452, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 300, 'min_premium': 20000}, 104793], ['duplicate code rising value', {'premium': 89846, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 350, 'min_premium': 20000}, 82766], ['cap binds', {'premium': 116342, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 87257], ['single group', {'premium': 214086, 'discounts': [['vehicle', 'abs', 20], ['vehicle', 'alarm', 44]], 'cap': 300, 'min_premium': 20000}, 200384], ['minimum premium binds', {'premium': 22500, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 350, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 211453, 'discounts': [], 'cap': 300, 'min_premium': 20000}, 211453]]]
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):
    groups={}
    for g,code,v in x['discounts']:
        groups.setdefault(g,{})
        groups[g][code]=max(groups[g].get(code,0),v)
    f=Fraction(1)
    for g in sorted(groups):
        f*=1-Fraction(sum(groups[g].values()),1000)
    d=min(Fraction(x['cap'],1000),1-f)
    net=math.floor(x['premium']*(1-d)+Fraction(1,2))
    return max(net,x['min_premium']) if d<Fraction(x['cap'],1000) else net
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['two groups multiply', {'premium': 179834, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 51], ['driver', 'student', 40]], 'cap': 350, 'min_premium': 20000}, 147122], ['duplicate discount code', {'premium': 83536, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 350, 'min_premium': 20000}, 72676], ['duplicate code rising value', {'premium': 216432, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 300, 'min_premium': 20000}, 199377], ['cap binds', {'premium': 295817, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 221863], ['single group', {'premium': 83079, 'discounts': [['vehicle', 'abs', 45], ['vehicle', 'alarm', 25]], 'cap': 350, 'min_premium': 20000}, 77263], ['minimum premium binds', {'premium': 22100, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 300, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 114606, 'discounts': [], 'cap': 350, 'min_premium': 20000}, 114606]], [['two groups multiply', {'premium': 259533, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 52], ['driver', 'student', 40]], 'cap': 300, 'min_premium': 20000}, 212090], ['duplicate discount code', {'premium': 222796, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 350, 'min_premium': 20000}, 193833], ['duplicate code rising value', {'premium': 264635, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 300, 'min_premium': 20000}, 243782], ['cap binds', {'premium': 274466, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 205850], ['single group', {'premium': 122187, 'discounts': [['vehicle', 'abs', 48], ['vehicle', 'alarm', 51]], 'cap': 350, 'min_premium': 20000}, 110090], ['minimum premium binds', {'premium': 22200, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 300, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 67195, 'discounts': [], 'cap': 300, 'min_premium': 20000}, 67195]], [['two groups multiply', {'premium': 246480, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 53], ['driver', 'student', 40]], 'cap': 300, 'min_premium': 20000}, 201202], ['duplicate discount code', {'premium': 212077, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 350, 'min_premium': 20000}, 184507], ['duplicate code rising value', {'premium': 239143, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 300, 'min_premium': 20000}, 220299], ['cap binds', {'premium': 260788, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 195591], ['single group', {'premium': 76428, 'discounts': [['vehicle', 'abs', 25], ['vehicle', 'alarm', 25]], 'cap': 350, 'min_premium': 20000}, 72607], ['minimum premium binds', {'premium': 22300, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 350, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 231596, 'discounts': [], 'cap': 300, 'min_premium': 20000}, 231596]], [['two groups multiply', {'premium': 234855, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 54], ['driver', 'student', 40]], 'cap': 300, 'min_premium': 20000}, 191501], ['duplicate discount code', {'premium': 62000, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 300, 'min_premium': 20000}, 53940], ['duplicate code rising value', {'premium': 164924, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 350, 'min_premium': 20000}, 151928], ['cap binds', {'premium': 160428, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 120321], ['single group', {'premium': 150010, 'discounts': [['vehicle', 'abs', 53], ['vehicle', 'alarm', 34]], 'cap': 350, 'min_premium': 20000}, 136959], ['minimum premium binds', {'premium': 22400, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 350, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 64059, 'discounts': [], 'cap': 350, 'min_premium': 20000}, 64059]], [['two groups multiply', {'premium': 70322, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 55], ['driver', 'student', 40]], 'cap': 350, 'min_premium': 20000}, 57277], ['duplicate discount code', {'premium': 120452, 'discounts': [['policy', 'home', 100], ['policy', 'home', 80], ['policy', 'life', 30]], 'cap': 300, 'min_premium': 20000}, 104793], ['duplicate code rising value', {'premium': 89846, 'discounts': [['driver', 'safe', 40], ['driver', 'safe', 60], ['vehicle', 'abs', 20]], 'cap': 350, 'min_premium': 20000}, 82766], ['cap binds', {'premium': 116342, 'discounts': [['policy', 'home', 150], ['driver', 'safe', 150], ['vehicle', 'abs', 100], ['vehicle', 'alarm', 50]], 'cap': 250, 'min_premium': 20000}, 87257], ['single group', {'premium': 214086, 'discounts': [['vehicle', 'abs', 20], ['vehicle', 'alarm', 44]], 'cap': 300, 'min_premium': 20000}, 200384], ['minimum premium binds', {'premium': 22500, 'discounts': [['policy', 'home', 100], ['driver', 'safe', 80]], 'cap': 350, 'min_premium': 20000}, 20000], ['capped policy at minimum', {'premium': 28000, 'discounts': [['policy', 'home', 200], ['driver', 'safe', 200]], 'cap': 300, 'min_premium': 20000}, 20000], ['no discounts', {'premium': 211453, 'discounts': [], 'cap': 300, 'min_premium': 20000}, 211453]]]
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:
Heavily discounted small policies are billed below the minimum premium.

Input premium, discounts [[group, code, per mille]], cap per mille, min_premium. A code repeated within a group counts once at its largest value; codes within a group add; groups combine multiplicatively; the total discount 1-product is capped; net = premium*(1-d) rounded half-up, then floored at min_premium.

split: open-access


prompt:
Premium is understated for classes that work overtime.

Input rates {class: cents per $100 of payroll}, employees [[class, payroll cents incl. overtime, overtime cents, officer]], officer_min, officer_max. Unknown class -> 'unknown class <code>'. Remove the overtime premium portion (one third of overtime pay), then clamp officer payroll to [officer_min, officer_max]. Sum payroll by class; class premium = payroll*rate/10000 rounded half-up per class; return the total.

split: open-access


prompt:
Officers near the cap lose their overtime exclusion.

Input rates {class: cents per $100 of payroll}, employees [[class, payroll cents incl. overtime, overtime cents, officer]], officer_min, officer_max. Unknown class -> 'unknown class <code>'. Remove the overtime premium portion (one third of overtime pay), then clamp officer payroll to [officer_min, officer_max]. Sum payroll by class; class premium = payroll*rate/10000 rounded half-up per class; return the total.

split: open-access


prompt:
Part-time officers are rated below the statutory minimum payroll.

Input rates {class: cents per $100 of payroll}, employees [[class, payroll cents incl. overtime, overtime cents, officer]], officer_min, officer_max. Unknown class -> 'unknown class <code>'. Remove the overtime premium portion (one third of overtime pay), then clamp officer payroll to [officer_min, officer_max]. Sum payroll by class; class premium = payroll*rate/10000 rounded half-up per class; return the total.

split: open-access


prompt:
Audits with many employees drift by cents from the class-level premium.

Input rates {class: cents per $100 of payroll}, employees [[class, payroll cents incl. overtime, overtime cents, officer]], officer_min, officer_max. Unknown class -> 'unknown class <code>'. Remove the overtime premium portion (one third of overtime pay), then clamp officer payroll to [officer_min, officer_max]. Sum payroll by class; class premium = payroll*rate/10000 rounded half-up per class; return the total.

split: open-access


prompt:
Payroll reported under an unfiled class code disappears from the audit.

Input rates {class: cents per $100 of payroll}, employees [[class, payroll cents incl. overtime, overtime cents, officer]], officer_min, officer_max. Unknown class -> 'unknown class <code>'. Remove the overtime premium portion (one third of overtime pay), then clamp officer payroll to [officer_min, officer_max]. Sum payroll by class; class premium = payroll*rate/10000 rounded half-up per class; return the total.

split: open-access


prompt:
Policies written before the period are credited with earnings from before it began.

Input period [start, end) in days and policies [[written day, term days (>0 else 'invalid term'), premium]]. Earned = premium*overlap/term where overlap = max(0, min(end, w+term) - max(start, w)). Unearned at end counts policies written before end and still in force after it. Sum exactly; round each total half-up once.

split: open-access


prompt:
Policies that expired before the period reduce earned premium.

Input period [start, end) in days and policies [[written day, term days (>0 else 'invalid term'), premium]]. Earned = premium*overlap/term where overlap = max(0, min(end, w+term) - max(start, w)). Unearned at end counts policies written before end and still in force after it. Sum exactly; round each total half-up once.

split: open-access


prompt:
The unearned reserve includes premium for policies written after the valuation date.

Input period [start, end) in days and policies [[written day, term days (>0 else 'invalid term'), premium]]. Earned = premium*overlap/term where overlap = max(0, min(end, w+term) - max(start, w)). Unearned at end counts policies written before end and still in force after it. Sum exactly; round each total half-up once.

split: open-access


prompt:
Portfolio earned premium differs by cents from the exact total.

Input period [start, end) in days and policies [[written day, term days (>0 else 'invalid term'), premium]]. Earned = premium*overlap/term where overlap = max(0, min(end, w+term) - max(start, w)). Unearned at end counts policies written before end and still in force after it. Sum exactly; round each total half-up once.

split: open-access


prompt:
The unearned reserve is overstated by the earned portion.

Input period [start, end) in days and policies [[written day, term days (>0 else 'invalid term'), premium]]. Earned = premium*overlap/term where overlap = max(0, min(end, w+term) - max(start, w)). Unearned at end counts policies written before end and still in force after it. Sum exactly; round each total 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']; pf=x['policy_fee']; inf=x['inspection_fee']
    def r(v): return math.floor(v+Fraction(1,2)) if v>=0 else -math.floor(-v+Fraction(1,2))
    tax=r(Fraction((p+pf+inf)*x['tax'],1000))
    sur=r(Fraction(p*x['surcharge'],1000))
    stamp=r(Fraction((p+pf+inf)*x['stamping'],1000))
    return [tax,sur,stamp,p+pf+inf+tax+sur+stamp]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['new business 0', {'premium': 412845, 'policy_fee': 2500, 'inspection_fee': 7500, 'tax': 50, 'surcharge': 3, 'stamping': 2}, [20767, 1239, 846, 445697]], ['new business 1', {'premium': 206492, 'policy_fee': 2500, 'inspection_fee': 15000, 'tax': 36, 'surcharge': 7, 'stamping': 2}, [7524, 1445, 448, 233409]], ['new business 2', {'premium': 248678, 'policy_fee': 5000, 'inspection_fee': 15000, 'tax': 50, 'surcharge': 3, 'stamping': 1}, [12684, 746, 269, 282377]], ['new business 3', {'premium': 180805, 'policy_fee': 2500, 'inspection_fee': 7500, 'tax': 50, 'surcharge': 3, 'stamping': 2}, [9165, 542, 382, 200894]], ['new business 4', {'premium': 81321, 'policy_fee': 2500, 'inspection_fee': 15000, 'tax': 36, 'surcharge': 7, 'stamping': 2}, [3018, 569, 198, 102606]], ['return premium tie', {'premium': -12500, 'policy_fee': 0, 'inspection_fee': 0, 'tax': 5, 'surcharge': 3, 'stamping': 1}, [-63, -38, -13, -12614]], ['return premium odd tie', {'premium': -112500, 'policy_fee': 0, 'inspection_fee': 0, 'tax': 1, 'surcharge': 1, 'stamping': 1}, [-113, -113, -113, -112839]], ['no fees', {'premium': 296266, 'policy_fee': 0, 'inspection_fee': 0, 'tax': 36, 'surcharge': 3, 'stamping': 1}, [10666, 889, 296, 308117]]], [['new business 0', {'premium': 63014, 'policy_fee': 5000, 'inspection_fee': 7500, 'tax': 36, 'surcharge': 7, 'stamping': 2}, [2449, 441, 151, 78555]], ['new business 1', {'premium': 135696, 'policy_fee': 2500, 'inspection_fee': 15000, 'tax': 50, 'surcharge': 7, 'stamping': 1}, [6910, 950, 153, 161209]], ['new business 2', {'premium': 152271, 'policy_fee': 2500, 'inspection_fee': 7500, 'tax': 49, 'surcharge': 7, 'stamping': 1}, [7584, 1066, 162, 171083]], ['new business 3', {'premium': 393593, 'policy_fee': 5000, 'inspection_fee': 7500, 'tax': 49, 'surcharge': 7, 'stamping': 2}, [19531, 2755, 812, 429191]], ['new business 4', {'premium': 347134, 'policy_fee': 5000, 'inspection_fee': 15000, 'tax': 36, 'surcharge': 3, 'stamping': 1}, [12677, 1041, 367, 381219]], ['return premium tie', {'premium': -37500, 'policy_fee': 0, 'inspection_fee': 0, 'tax': 5, 'surcharge': 3, 'stamping': 1}, [-188, -113, -38, -37839]], ['return premium odd tie', {'premium': -137500, 'policy_fee': 0, 'inspection_fee': 0, 'tax': 1, 'surcharge': 1, 'stamping': 1}, [-138, -138, -138, -137914]], ['no fees', {'premium': 313133, 'policy_fee': 0, 'inspection_fee': 0, 'tax': 50, 'surcharge': 3, 'stamping': 2}, [15657, 939, 626, 330355]]], [['new business 0', {'premium': 464734, 'policy_fee': 5000, 'inspection_fee': 15000, 'tax': 36, 'surcharge': 3, 'stamping': 1}, [16910, 1394, 485, 503523]], ['new business 1', {'premium': 379927, 'policy_fee': 2500, 'inspection_fee': 7500, 'tax': 49, 'surcharge': 7, 'stamping': 2}, [18739, 2659, 780, 412105]], ['new business 2', {'premium': 142805, 'policy_fee': 2500, 'inspection_fee': 7500, 'tax': 36, 'surcharge': 7, 'stamping': 1}, [5231, 1000, 153, 159189]], ['new business 3', {'premium': 172357, 'policy_fee': 2500, 'inspection_fee': 7500, 'tax': 36, 'surcharge': 7, 'stamping': 2}, [6295, 1206, 365, 190223]], ['new business 4', {'premium': 145157, 'policy_fee': 2500, 'inspection_fee': 15000, 'tax': 49, 'surcharge': 7, 'stamping': 2}, [7235, 1016, 325, 171233]], ['return premium tie', {'premium': -62500, 'policy_fee': 0, 'inspection_fee': 0, 'tax': 5, 'surcharge': 3, 'stamping': 1}, [-313, -188, -63, -63064]], ['return premium odd tie', {'premium': -162500, 'policy_fee': 0, 'inspection_fee': 0, 'tax': 1, 'surcharge': 1, 'stamping': 1}, [-163, -163, -163, -162989]], ['no fees', {'premium': 383065, 'policy_fee': 0, 'inspection_fee': 0, 'tax': 36, 'surcharge': 7, 'stamping': 1}, [13790, 2681, 383, 399919]]], [['new business 0', {'premium': 410101, 'policy_fee': 5000, 'inspection_fee': 15000, 'tax': 50, 'surcharge': 7, 'stamping': 1}, [20755, 2871, 430, 454157]], ['new business 1', {'premium': 268176, 'policy_fee': 2500, 'inspection_fee': 15000, 'tax': 50, 'surcharge': 7, 'stamping': 1}, [13534, 1877, 286, 301373]], ['new business 2', {'premium': 321115, 'policy_fee': 2500, 'inspection_fee': 15000, 'tax': 50, 'surcharge': 7, 'stamping': 1}, [16181, 2248, 339, 357383]], ['new business 3', {'premium': 50665, 'policy_fee': 2500, 'inspection_fee': 7500, 'tax': 36, 'surcharge': 7, 'stamping': 1}, [1914, 355, 61, 62995]], ['new business 4', {'premium': 490929, 'policy_fee': 5000, 'inspection_fee': 7500, 'tax': 49, 'surcharge': 3, 'stamping': 1}, [24301, 1473, 503, 529706]], ['return premium tie', {'premium': -87500, 'policy_fee': 0, 'inspection_fee': 0, 'tax': 5, 'surcharge': 3, 'stamping': 1}, [-438, -263, -88, -88289]], ['return premium odd tie', {'premium': -187500, 'policy_fee': 0, 'inspection_fee': 0, 'tax': 1, 'surcharge': 1, 'stamping': 1}, [-188, -188, -188, -188064]], ['no fees', {'premium': 176432, 'policy_fee': 0, 'inspection_fee': 0, 'tax': 50, 'surcharge': 7, 'stamping': 1}, [8822, 1235, 176, 186665]]], [['new business 0', {'premium': 318606, 'policy_fee': 2500, 'inspection_fee': 15000, 'tax': 49, 'surcharge': 7, 'stamping': 2}, [15734, 2230, 672, 354742]], ['new business 1', {'premium': 169116, 'policy_fee': 2500, 'inspection_fee': 15000, 'tax': 50, 'surcharge': 3, 'stamping': 1}, [8581, 507, 187, 195891]], ['new business 2', {'premium': 235982, 'policy_fee': 2500, 'inspection_fee': 7500, 'tax': 50, 'surcharge': 7, 'stamping': 2}, [11924, 1652, 492, 260050]], ['new business 3', {'premium': 143193, 'policy_fee': 2500, 'inspection_fee': 7500, 'tax': 49, 'surcharge': 3, 'stamping': 2}, [7139, 430, 306, 161068]], ['new business 4', {'premium': 241775, 'policy_fee': 2500, 'inspection_fee': 15000, 'tax': 50, 'surcharge': 7, 'stamping': 1}, [12214, 1692, 259, 273440]], ['return premium tie', {'premium': -112500, 'policy_fee': 0, 'inspection_fee': 0, 'tax': 5, 'surcharge': 3, 'stamping': 1}, [-563, -338, -113, -113514]], ['return premium odd tie', {'premium': -212500, 'policy_fee': 0, 'inspection_fee': 0, 'tax': 1, 'surcharge': 1, 'stamping': 1}, [-213, -213, -213, -213139]], ['no fees', {'premium': 300225, 'policy_fee': 0, 'inspection_fee': 0, 'tax': 49, 'surcharge': 7, 'stamping': 1}, [14711, 2102, 300, 317338]]]]
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']; pf=x['policy_fee']; inf=x['inspection_fee']
    def r(v): return math.floor(v+Fraction(1,2)) if v>=0 else -math.floor(-v+Fraction(1,2))
    tax=r(Fraction(p*x['tax'],1000))
    sur=r(Fraction(p*x['surcharge'],1000))
    stamp=r(Fraction((p+pf+inf)*x['stamping'],1000))
    return [tax,sur,stamp,p+pf+inf+tax+sur+stamp]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['new business 0', {'premium': 412845, 'policy_fee': 2500, 'inspection_fee': 7500, 'tax': 50, 'surcharge': 3, 'stamping': 2}, [20767, 1239, 846, 445697]], ['new business 1', {'premium': 206492, 'policy_fee': 2500, 'inspection_fee': 15000, 'tax': 36, 'surcharge': 7, 'stamping': 2}, [7524, 1445, 448, 233409]], ['new business 2', {'premium': 248678, 'policy_fee': 5000, 'inspection_fee': 15000, 'tax': 50, 'surcharge': 3, 'stamping': 1}, [12684, 746, 269, 282377]], ['new business 3', {'premium': 180805, 'policy_fee': 2500, 'inspection_fee': 7500, 'tax': 50, 'surcharge': 3, 'stamping': 2}, [9165, 542, 382, 200894]], ['new business 4', {'premium': 81321, 'policy_fee': 2500, 'inspection_fee': 15000, 'tax': 36, 'surcharge': 7, 'stamping': 2}, [3018, 569, 198, 102606]], ['return premium tie', {'premium': -12500, 'policy_fee': 0, 'inspection_fee': 0, 'tax': 5, 'surcharge': 3, 'stamping': 1}, [-63, -38, -13, -12614]], ['return premium odd tie', {'premium': -112500, 'policy_fee': 0, 'inspection_fee': 0, 'tax': 1, 'surcharge': 1, 'stamping': 1}, [-113, -113, -113, -112839]], ['no fees', {'premium': 296266, 'policy_fee': 0, 'inspection_fee': 0, 'tax': 36, 'surcharge': 3, 'stamping': 1}, [10666, 889, 296, 308117]]], [['new business 0', {'premium': 63014, 'policy_fee': 5000, 'inspection_fee': 7500, 'tax': 36, 'surcharge': 7, 'stamping': 2}, [2449, 441, 151, 78555]], ['new business 1', {'premium': 135696, 'policy_fee': 2500, 'inspection_fee': 15000, 'tax': 50, 'surcharge': 7, 'stamping': 1}, [6910, 950, 153, 161209]], ['new business 2', {'premium': 152271, 'policy_fee': 2500, 'inspection_fee': 7500, 'tax': 49, 'surcharge': 7, 'stamping': 1}, [7584, 1066, 162, 171083]], ['new business 3', {'premium': 393593, 'policy_fee': 5000, 'inspection_fee': 7500, 'tax': 49, 'surcharge': 7, 'stamping': 2}, [19531, 2755, 812, 429191]], ['new business 4', {'premium': 347134, 'policy_fee': 5000, 'inspection_fee': 15000, 'tax': 36, 'surcharge': 3, 'stamping': 1}, [12677, 1041, 367, 381219]], ['return premium tie', {'premium': -37500, 'policy_fee': 0, 'inspection_fee': 0, 'tax': 5, 'surcharge': 3, 'stamping': 1}, [-188, -113, -38, -37839]], ['return premium odd tie', {'premium': -137500, 'policy_fee': 0, 'inspection_fee': 0, 'tax': 1, 'surcharge': 1, 'stamping': 1}, [-138, -138, -138, -137914]], ['no fees', {'premium': 313133, 'policy_fee': 0, 'inspection_fee': 0, 'tax': 50, 'surcharge': 3, 'stamping': 2}, [15657, 939, 626, 330355]]], [['new business 0', {'premium': 464734, 'policy_fee': 5000, 'inspection_fee': 15000, 'tax': 36, 'surcharge': 3, 'stamping': 1}, [16910, 1394, 485, 503523]], ['new business 1', {'premium': 379927, 'policy_fee': 2500, 'inspection_fee': 7500, 'tax': 49, 'surcharge': 7, 'stamping': 2}, [18739, 2659, 780, 412105]], ['new business 2', {'premium': 142805, 'policy_fee': 2500, 'inspection_fee': 7500, 'tax': 36, 'surcharge': 7, 'stamping': 1}, [5231, 1000, 153, 159189]], ['new business 3', {'premium': 172357, 'policy_fee': 2500, 'inspection_fee': 7500, 'tax': 36, 'surcharge': 7, 'stamping': 2}, [6295, 1206, 365, 190223]], ['new business 4', {'premium': 145157, 'policy_fee': 2500, 'inspection_fee': 15000, 'tax': 49, 'surcharge': 7, 'stamping': 2}, [7235, 1016, 325, 171233]], ['return premium tie', {'premium': -62500, 'policy_fee': 0, 'inspection_fee': 0, 'tax': 5, 'surcharge': 3, 'stamping': 1}, [-313, -188, -63, -63064]], ['return premium odd tie', {'premium': -162500, 'policy_fee': 0, 'inspection_fee': 0, 'tax': 1, 'surcharge': 1, 'stamping': 1}, [-163, -163, -163, -162989]], ['no fees', {'premium': 383065, 'policy_fee': 0, 'inspection_fee': 0, 'tax': 36, 'surcharge': 7, 'stamping': 1}, [13790, 2681, 383, 399919]]], [['new business 0', {'premium': 410101, 'policy_fee': 5000, 'inspection_fee': 15000, 'tax': 50, 'surcharge': 7, 'stamping': 1}, [20755, 2871, 430, 454157]], ['new business 1', {'premium': 268176, 'policy_fee': 2500, 'inspection_fee': 15000, 'tax': 50, 'surcharge': 7, 'stamping': 1}, [13534, 1877, 286, 301373]], ['new business 2', {'premium': 321115, 'policy_fee': 2500, 'inspection_fee': 15000, 'tax': 50, 'surcharge': 7, 'stamping': 1}, [16181, 2248, 339, 357383]], ['new business 3', {'premium': 50665, 'policy_fee': 2500, 'inspection_fee': 7500, 'tax': 36, 'surcharge': 7, 'stamping': 1}, [1914, 355, 61, 62995]], ['new business 4', {'premium': 490929, 'policy_fee': 5000, 'inspection_fee': 7500, 'tax': 49, 'surcharge': 3, 'stamping': 1}, [24301, 1473, 503, 529706]], ['return premium tie', {'premium': -87500, 'policy_fee': 0, 'inspection_fee': 0, 'tax': 5, 'surcharge': 3, 'stamping': 1}, [-438, -263, -88, -88289]], ['return premium odd tie', {'premium': -187500, 'policy_fee': 0, 'inspection_fee': 0, 'tax': 1, 'surcharge': 1, 'stamping': 1}, [-188, -188, -188, -188064]], ['no fees', {'premium': 176432, 'policy_fee': 0, 'inspection_fee': 0, 'tax': 50, 'surcharge': 7, 'stamping': 1}, [8822, 1235, 176, 186665]]], [['new business 0', {'premium': 318606, 'policy_fee': 2500, 'inspection_fee': 15000, 'tax': 49, 'surcharge': 7, 'stamping': 2}, [15734, 2230, 672, 354742]], ['new business 1', {'premium': 169116, 'policy_fee': 2500, 'inspection_fee': 15000, 'tax': 50, 'surcharge': 3, 'stamping': 1}, [8581, 507, 187, 195891]], ['new business 2', {'premium': 235982, 'policy_fee': 2500, 'inspection_fee': 7500, 'tax': 50, 'surcharge': 7, 'stamping': 2}, [11924, 1652, 492, 260050]], ['new business 3', {'premium': 143193, 'policy_fee': 2500, 'inspection_fee': 7500, 'tax': 49, 'surcharge': 3, 'stamping': 2}, [7139, 430, 306, 161068]], ['new business 4', {'premium': 241775, 'policy_fee': 2500, 'inspection_fee': 15000, 'tax': 50, 'surcharge': 7, 'stamping': 1}, [12214, 1692, 259, 273440]], ['return premium tie', {'premium': -112500, 'policy_fee': 0, 'inspection_fee': 0, 'tax': 5, 'surcharge': 3, 'stamping': 1}, [-563, -338, -113, -113514]], ['return premium odd tie', {'premium': -212500, 'policy_fee': 0, 'inspection_fee': 0, 'tax': 1, 'surcharge': 1, 'stamping': 1}, [-213, -213, -213, -213139]], ['no fees', {'premium': 300225, 'policy_fee': 0, 'inspection_fee': 0, 'tax': 49, 'surcharge': 7, 'stamping': 1}, [14711, 2102, 300, 317338]]]]
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:
Premium tax is overstated on inspected policies.

Input premium (may be negative for return premium), policy_fee, inspection_fee, tax, surcharge, stamping (per mille). Tax applies to premium+policy fee; surcharge to premium only; stamping to premium+both fees. Each item is rounded half away from zero separately; return [tax, surcharge, stamping, total billed].

split: open-access