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)*x['tax'],1000))
    sur=r(Fraction((p+pf)*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+pf)*x['tax'],1000))
    sur=r(Fraction((p+tax)*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:
The surcharge is levied on fees.

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


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)*x['tax'],1000))
    sur=r(Fraction(p*x['surcharge'],1000))
    stamp=r(Fraction((p+pf+inf+tax)*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)

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):
    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)*x['tax'],1000))
    sur=r(Fraction(p*x['surcharge'],1000))
    stamp=r(Fraction((p+pf)*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:
Stamping fees are computed on a base that includes tax.

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


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)*x['tax'],1000))
    sur=r(Fraction(p*x['surcharge'],1000))
    stamp=r(Fraction((p+pf+inf)*x['stamping'],1000))
    return [tax,sur,stamp,r(p+pf+inf+Fraction((p+pf)*x['tax'],1000)+Fraction(p*x['surcharge'],1000)+Fraction((p+pf+inf)*x['stamping'],1000))]
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+pf)*x['tax'],1000))
    sur=r(Fraction(p*x['surcharge'],1000))
    stamp=r(Fraction((p+pf+inf)*x['stamping'],1000))
    return [tax,sur,stamp,r((p+pf+inf)*(1+Fraction(x['tax']+x['surcharge']+x['stamping'],1000)))]
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:
The invoice total does not equal the sum of its itemised lines.

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


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))
    tax=r(Fraction((p+pf)*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 round(v)
    tax=r(Fraction((p+pf)*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:
Refunded tax on a return premium is a cent short.

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


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    sp=x['standard']
    if x['max']<x['min']: return 'invalid bounds'
    lim=max(0,sum(min(c,x['loss_limit']) for c in x['claims']))
    basic=Fraction(sp*x['basic'],1000)
    retro=(basic+lim)*Fraction(x['lcf'],1000)*Fraction(x['tax'],1000)
    lo=Fraction(sp*x['min'],1000); hi=Fraction(sp*x['max'],1000)
    retro=max(lo,min(hi,retro))
    return [lim, math.floor(retro+Fraction(1,2))]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['moderate losses between bounds', {'standard': 1208187, 'basic': 250, 'lcf': 1100, 'tax': 1030, 'min': 400, 'max': 2000, 'loss_limit': 5000000, 'claims': [65251, 117766, 199866, 72604]}, [455487, 827175]], ['large claim limited', {'standard': 1536795, 'basic': 250, 'lcf': 1100, 'tax': 1050, 'min': 600, 'max': 3000, 'loss_limit': 5000000, 'claims': [7899385, 85219]}, [5085219, 4610385]], ['maximum binds', {'standard': 576969, 'basic': 250, 'lcf': 1100, 'tax': 1030, 'min': 500, 'max': 1200, 'loss_limit': 5000000, 'claims': [3887820, 3676391, 3519603, 3011895]}, [14095709, 692363]], ['no losses minimum binds', {'standard': 783317, 'basic': 200, 'lcf': 1150, 'tax': 1050, 'min': 500, 'max': 1400, 'loss_limit': 5000000, 'claims': []}, [0, 391659]], ['subrogation recovery offsets', {'standard': 1402360, 'basic': 200, 'lcf': 1200, 'tax': 1050, 'min': 300, 'max': 2500, 'loss_limit': 5000000, 'claims': [299401, -71949]}, [227452, 581085]], ['net recovery floors at zero', {'standard': 1970882, 'basic': 200, 'lcf': 1150, 'tax': 1030, 'min': 300, 'max': 2500, 'loss_limit': 5000000, 'claims': [-13900]}, [0, 591265]], ['inverted bounds rejected', {'standard': 857821, 'basic': 200, 'lcf': 1150, 'tax': 1030, 'min': 1300, 'max': 1200, 'loss_limit': 5000000, 'claims': [100000]}, 'invalid bounds'], ['flat plan with equal bounds', {'standard': 1032758, 'basic': 250, 'lcf': 1200, 'tax': 1030, 'min': 900, 'max': 900, 'loss_limit': 5000000, 'claims': [100000]}, [100000, 929482]], ['near-minimum losses', {'standard': 1037917, 'basic': 250, 'lcf': 1200, 'tax': 1030, 'min': 450, 'max': 1800, 'loss_limit': 5000000, 'claims': [196003]}, [196003, 509523]]], [['moderate losses between bounds', {'standard': 559811, 'basic': 250, 'lcf': 1150, 'tax': 1030, 'min': 400, 'max': 2000, 'loss_limit': 5000000, 'claims': [168808, 170340, 188681, 153930]}, [681759, 951695]], ['large claim limited', {'standard': 1398667, 'basic': 200, 'lcf': 1150, 'tax': 1030, 'min': 500, 'max': 3000, 'loss_limit': 5000000, 'claims': [8563900, 72244]}, [5072244, 4196001]], ['maximum binds', {'standard': 1860838, 'basic': 250, 'lcf': 1100, 'tax': 1050, 'min': 600, 'max': 1200, 'loss_limit': 5000000, 'claims': [3974702, 2021857, 3323996, 2741110]}, [12061665, 2233006]], ['no losses minimum binds', {'standard': 1054836, 'basic': 200, 'lcf': 1150, 'tax': 1050, 'min': 500, 'max': 1400, 'loss_limit': 5000000, 'claims': []}, [0, 527418]], ['subrogation recovery offsets', {'standard': 572933, 'basic': 250, 'lcf': 1150, 'tax': 1030, 'min': 300, 'max': 2500, 'loss_limit': 5000000, 'claims': [215865, -67794]}, [148071, 322920]], ['net recovery floors at zero', {'standard': 1415569, 'basic': 200, 'lcf': 1200, 'tax': 1030, 'min': 300, 'max': 2500, 'loss_limit': 5000000, 'claims': [-23951]}, [0, 424671]], ['inverted bounds rejected', {'standard': 1885857, 'basic': 200, 'lcf': 1200, 'tax': 1030, 'min': 1300, 'max': 1200, 'loss_limit': 5000000, 'claims': [100000]}, 'invalid bounds'], ['flat plan with equal bounds', {'standard': 1658903, 'basic': 200, 'lcf': 1200, 'tax': 1050, 'min': 900, 'max': 900, 'loss_limit': 5000000, 'claims': [100000]}, [100000, 1493013]], ['near-minimum losses', {'standard': 1831216, 'basic': 250, 'lcf': 1150, 'tax': 1030, 'min': 450, 'max': 1800, 'loss_limit': 5000000, 'claims': [255597]}, [255597, 824047]]], [['moderate losses between bounds', {'standard': 1953166, 'basic': 200, 'lcf': 1150, 'tax': 1050, 'min': 400, 'max': 2000, 'loss_limit': 5000000, 'claims': [130486, 146045, 106267, 80838]}, [463636, 970005]], ['large claim limited', {'standard': 1375996, 'basic': 200, 'lcf': 1150, 'tax': 1050, 'min': 600, 'max': 3000, 'loss_limit': 5000000, 'claims': [8850428, 26063]}, [5026063, 4127988]], ['maximum binds', {'standard': 1822101, 'basic': 200, 'lcf': 1200, 'tax': 1030, 'min': 600, 'max': 1200, 'loss_limit': 5000000, 'claims': [3010425, 2467545, 2177771, 3447891]}, [11103632, 2186521]], ['no losses minimum binds', {'standard': 1516833, 'basic': 200, 'lcf': 1100, 'tax': 1050, 'min': 500, 'max': 1400, 'loss_limit': 5000000, 'claims': []}, [0, 758417]], ['subrogation recovery offsets', {'standard': 714829, 'basic': 200, 'lcf': 1100, 'tax': 1050, 'min': 300, 'max': 2500, 'loss_limit': 5000000, 'claims': [292326, -101272]}, [191054, 370781]], ['net recovery floors at zero', {'standard': 1501098, 'basic': 200, 'lcf': 1100, 'tax': 1030, 'min': 300, 'max': 2500, 'loss_limit': 5000000, 'claims': [-22616]}, [0, 450329]], ['inverted bounds rejected', {'standard': 696781, 'basic': 200, 'lcf': 1200, 'tax': 1050, 'min': 1300, 'max': 1200, 'loss_limit': 5000000, 'claims': [100000]}, 'invalid bounds'], ['flat plan with equal bounds', {'standard': 802028, 'basic': 200, 'lcf': 1200, 'tax': 1030, 'min': 900, 'max': 900, 'loss_limit': 5000000, 'claims': [100000]}, [100000, 721825]], ['near-minimum losses', {'standard': 715359, 'basic': 200, 'lcf': 1200, 'tax': 1030, 'min': 450, 'max': 1800, 'loss_limit': 5000000, 'claims': [161153]}, [161153, 346549]]], [['moderate losses between bounds', {'standard': 714988, 'basic': 200, 'lcf': 1200, 'tax': 1050, 'min': 400, 'max': 2000, 'loss_limit': 5000000, 'claims': [147807, 50783, 101639, 147624]}, [447853, 714442]], ['large claim limited', {'standard': 1075364, 'basic': 200, 'lcf': 1100, 'tax': 1050, 'min': 600, 'max': 3000, 'loss_limit': 5000000, 'claims': [6621396, 51697]}, [5051697, 3226092]], ['maximum binds', {'standard': 636493, 'basic': 250, 'lcf': 1200, 'tax': 1050, 'min': 500, 'max': 1200, 'loss_limit': 5000000, 'claims': [3206066, 2811387, 2370852, 2596520]}, [10984825, 763792]], ['no losses minimum binds', {'standard': 1974481, 'basic': 200, 'lcf': 1200, 'tax': 1050, 'min': 500, 'max': 1600, 'loss_limit': 5000000, 'claims': []}, [0, 987241]], ['subrogation recovery offsets', {'standard': 1092045, 'basic': 200, 'lcf': 1200, 'tax': 1030, 'min': 300, 'max': 2500, 'loss_limit': 5000000, 'claims': [210597, -95806]}, [114791, 366843]], ['net recovery floors at zero', {'standard': 1088467, 'basic': 250, 'lcf': 1200, 'tax': 1030, 'min': 300, 'max': 2500, 'loss_limit': 5000000, 'claims': [-13789]}, [0, 326540]], ['inverted bounds rejected', {'standard': 1508678, 'basic': 200, 'lcf': 1150, 'tax': 1050, 'min': 1300, 'max': 1200, 'loss_limit': 5000000, 'claims': [100000]}, 'invalid bounds'], ['flat plan with equal bounds', {'standard': 811592, 'basic': 250, 'lcf': 1200, 'tax': 1050, 'min': 900, 'max': 900, 'loss_limit': 5000000, 'claims': [100000]}, [100000, 730433]], ['near-minimum losses', {'standard': 1513685, 'basic': 200, 'lcf': 1100, 'tax': 1050, 'min': 450, 'max': 1800, 'loss_limit': 5000000, 'claims': [237641]}, [237641, 681158]]], [['moderate losses between bounds', {'standard': 1863348, 'basic': 250, 'lcf': 1200, 'tax': 1050, 'min': 400, 'max': 2000, 'loss_limit': 5000000, 'claims': [182396, 119506, 129126, 64521]}, [495549, 1113521]], ['large claim limited', {'standard': 1794820, 'basic': 200, 'lcf': 1100, 'tax': 1030, 'min': 500, 'max': 3000, 'loss_limit': 5000000, 'claims': [6997029, 30223]}, [5030223, 5384460]], ['maximum binds', {'standard': 1446879, 'basic': 200, 'lcf': 1200, 'tax': 1030, 'min': 500, 'max': 1200, 'loss_limit': 5000000, 'claims': [3226070, 2149089, 2381869, 2566788]}, [10323816, 1736255]], ['no losses minimum binds', {'standard': 1111989, 'basic': 200, 'lcf': 1150, 'tax': 1050, 'min': 500, 'max': 1400, 'loss_limit': 5000000, 'claims': []}, [0, 555995]], ['subrogation recovery offsets', {'standard': 930668, 'basic': 250, 'lcf': 1150, 'tax': 1030, 'min': 300, 'max': 2500, 'loss_limit': 5000000, 'claims': [215001, -125166]}, [89835, 346057]], ['net recovery floors at zero', {'standard': 790663, 'basic': 200, 'lcf': 1100, 'tax': 1050, 'min': 300, 'max': 2500, 'loss_limit': 5000000, 'claims': [-24524]}, [0, 237199]], ['inverted bounds rejected', {'standard': 901935, 'basic': 200, 'lcf': 1150, 'tax': 1050, 'min': 1300, 'max': 1200, 'loss_limit': 5000000, 'claims': [100000]}, 'invalid bounds'], ['flat plan with equal bounds', {'standard': 802066, 'basic': 250, 'lcf': 1150, 'tax': 1050, 'min': 900, 'max': 900, 'loss_limit': 5000000, 'claims': [100000]}, [100000, 721859]], ['near-minimum losses', {'standard': 1352189, 'basic': 250, 'lcf': 1150, 'tax': 1050, 'min': 450, 'max': 1800, 'loss_limit': 5000000, 'claims': [178467]}, [178467, 608485]]]]
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):
    sp=x['standard']
    if x['max']<x['min']: return 'invalid bounds'
    lim=max(0,sum(min(c,x['loss_limit']) for c in x['claims']))
    basic=Fraction(sp*x['basic'],1000)
    retro=(basic+lim)*Fraction(x['tax'],1000)
    lo=Fraction(sp*x['min'],1000); hi=Fraction(sp*x['max'],1000)
    retro=max(lo,min(hi,retro))
    return [lim, math.floor(retro+Fraction(1,2))]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['moderate losses between bounds', {'standard': 1208187, 'basic': 250, 'lcf': 1100, 'tax': 1030, 'min': 400, 'max': 2000, 'loss_limit': 5000000, 'claims': [65251, 117766, 199866, 72604]}, [455487, 827175]], ['large claim limited', {'standard': 1536795, 'basic': 250, 'lcf': 1100, 'tax': 1050, 'min': 600, 'max': 3000, 'loss_limit': 5000000, 'claims': [7899385, 85219]}, [5085219, 4610385]], ['maximum binds', {'standard': 576969, 'basic': 250, 'lcf': 1100, 'tax': 1030, 'min': 500, 'max': 1200, 'loss_limit': 5000000, 'claims': [3887820, 3676391, 3519603, 3011895]}, [14095709, 692363]], ['no losses minimum binds', {'standard': 783317, 'basic': 200, 'lcf': 1150, 'tax': 1050, 'min': 500, 'max': 1400, 'loss_limit': 5000000, 'claims': []}, [0, 391659]], ['subrogation recovery offsets', {'standard': 1402360, 'basic': 200, 'lcf': 1200, 'tax': 1050, 'min': 300, 'max': 2500, 'loss_limit': 5000000, 'claims': [299401, -71949]}, [227452, 581085]], ['net recovery floors at zero', {'standard': 1970882, 'basic': 200, 'lcf': 1150, 'tax': 1030, 'min': 300, 'max': 2500, 'loss_limit': 5000000, 'claims': [-13900]}, [0, 591265]], ['inverted bounds rejected', {'standard': 857821, 'basic': 200, 'lcf': 1150, 'tax': 1030, 'min': 1300, 'max': 1200, 'loss_limit': 5000000, 'claims': [100000]}, 'invalid bounds'], ['flat plan with equal bounds', {'standard': 1032758, 'basic': 250, 'lcf': 1200, 'tax': 1030, 'min': 900, 'max': 900, 'loss_limit': 5000000, 'claims': [100000]}, [100000, 929482]], ['near-minimum losses', {'standard': 1037917, 'basic': 250, 'lcf': 1200, 'tax': 1030, 'min': 450, 'max': 1800, 'loss_limit': 5000000, 'claims': [196003]}, [196003, 509523]]], [['moderate losses between bounds', {'standard': 559811, 'basic': 250, 'lcf': 1150, 'tax': 1030, 'min': 400, 'max': 2000, 'loss_limit': 5000000, 'claims': [168808, 170340, 188681, 153930]}, [681759, 951695]], ['large claim limited', {'standard': 1398667, 'basic': 200, 'lcf': 1150, 'tax': 1030, 'min': 500, 'max': 3000, 'loss_limit': 5000000, 'claims': [8563900, 72244]}, [5072244, 4196001]], ['maximum binds', {'standard': 1860838, 'basic': 250, 'lcf': 1100, 'tax': 1050, 'min': 600, 'max': 1200, 'loss_limit': 5000000, 'claims': [3974702, 2021857, 3323996, 2741110]}, [12061665, 2233006]], ['no losses minimum binds', {'standard': 1054836, 'basic': 200, 'lcf': 1150, 'tax': 1050, 'min': 500, 'max': 1400, 'loss_limit': 5000000, 'claims': []}, [0, 527418]], ['subrogation recovery offsets', {'standard': 572933, 'basic': 250, 'lcf': 1150, 'tax': 1030, 'min': 300, 'max': 2500, 'loss_limit': 5000000, 'claims': [215865, -67794]}, [148071, 322920]], ['net recovery floors at zero', {'standard': 1415569, 'basic': 200, 'lcf': 1200, 'tax': 1030, 'min': 300, 'max': 2500, 'loss_limit': 5000000, 'claims': [-23951]}, [0, 424671]], ['inverted bounds rejected', {'standard': 1885857, 'basic': 200, 'lcf': 1200, 'tax': 1030, 'min': 1300, 'max': 1200, 'loss_limit': 5000000, 'claims': [100000]}, 'invalid bounds'], ['flat plan with equal bounds', {'standard': 1658903, 'basic': 200, 'lcf': 1200, 'tax': 1050, 'min': 900, 'max': 900, 'loss_limit': 5000000, 'claims': [100000]}, [100000, 1493013]], ['near-minimum losses', {'standard': 1831216, 'basic': 250, 'lcf': 1150, 'tax': 1030, 'min': 450, 'max': 1800, 'loss_limit': 5000000, 'claims': [255597]}, [255597, 824047]]], [['moderate losses between bounds', {'standard': 1953166, 'basic': 200, 'lcf': 1150, 'tax': 1050, 'min': 400, 'max': 2000, 'loss_limit': 5000000, 'claims': [130486, 146045, 106267, 80838]}, [463636, 970005]], ['large claim limited', {'standard': 1375996, 'basic': 200, 'lcf': 1150, 'tax': 1050, 'min': 600, 'max': 3000, 'loss_limit': 5000000, 'claims': [8850428, 26063]}, [5026063, 4127988]], ['maximum binds', {'standard': 1822101, 'basic': 200, 'lcf': 1200, 'tax': 1030, 'min': 600, 'max': 1200, 'loss_limit': 5000000, 'claims': [3010425, 2467545, 2177771, 3447891]}, [11103632, 2186521]], ['no losses minimum binds', {'standard': 1516833, 'basic': 200, 'lcf': 1100, 'tax': 1050, 'min': 500, 'max': 1400, 'loss_limit': 5000000, 'claims': []}, [0, 758417]], ['subrogation recovery offsets', {'standard': 714829, 'basic': 200, 'lcf': 1100, 'tax': 1050, 'min': 300, 'max': 2500, 'loss_limit': 5000000, 'claims': [292326, -101272]}, [191054, 370781]], ['net recovery floors at zero', {'standard': 1501098, 'basic': 200, 'lcf': 1100, 'tax': 1030, 'min': 300, 'max': 2500, 'loss_limit': 5000000, 'claims': [-22616]}, [0, 450329]], ['inverted bounds rejected', {'standard': 696781, 'basic': 200, 'lcf': 1200, 'tax': 1050, 'min': 1300, 'max': 1200, 'loss_limit': 5000000, 'claims': [100000]}, 'invalid bounds'], ['flat plan with equal bounds', {'standard': 802028, 'basic': 200, 'lcf': 1200, 'tax': 1030, 'min': 900, 'max': 900, 'loss_limit': 5000000, 'claims': [100000]}, [100000, 721825]], ['near-minimum losses', {'standard': 715359, 'basic': 200, 'lcf': 1200, 'tax': 1030, 'min': 450, 'max': 1800, 'loss_limit': 5000000, 'claims': [161153]}, [161153, 346549]]], [['moderate losses between bounds', {'standard': 714988, 'basic': 200, 'lcf': 1200, 'tax': 1050, 'min': 400, 'max': 2000, 'loss_limit': 5000000, 'claims': [147807, 50783, 101639, 147624]}, [447853, 714442]], ['large claim limited', {'standard': 1075364, 'basic': 200, 'lcf': 1100, 'tax': 1050, 'min': 600, 'max': 3000, 'loss_limit': 5000000, 'claims': [6621396, 51697]}, [5051697, 3226092]], ['maximum binds', {'standard': 636493, 'basic': 250, 'lcf': 1200, 'tax': 1050, 'min': 500, 'max': 1200, 'loss_limit': 5000000, 'claims': [3206066, 2811387, 2370852, 2596520]}, [10984825, 763792]], ['no losses minimum binds', {'standard': 1974481, 'basic': 200, 'lcf': 1200, 'tax': 1050, 'min': 500, 'max': 1600, 'loss_limit': 5000000, 'claims': []}, [0, 987241]], ['subrogation recovery offsets', {'standard': 1092045, 'basic': 200, 'lcf': 1200, 'tax': 1030, 'min': 300, 'max': 2500, 'loss_limit': 5000000, 'claims': [210597, -95806]}, [114791, 366843]], ['net recovery floors at zero', {'standard': 1088467, 'basic': 250, 'lcf': 1200, 'tax': 1030, 'min': 300, 'max': 2500, 'loss_limit': 5000000, 'claims': [-13789]}, [0, 326540]], ['inverted bounds rejected', {'standard': 1508678, 'basic': 200, 'lcf': 1150, 'tax': 1050, 'min': 1300, 'max': 1200, 'loss_limit': 5000000, 'claims': [100000]}, 'invalid bounds'], ['flat plan with equal bounds', {'standard': 811592, 'basic': 250, 'lcf': 1200, 'tax': 1050, 'min': 900, 'max': 900, 'loss_limit': 5000000, 'claims': [100000]}, [100000, 730433]], ['near-minimum losses', {'standard': 1513685, 'basic': 200, 'lcf': 1100, 'tax': 1050, 'min': 450, 'max': 1800, 'loss_limit': 5000000, 'claims': [237641]}, [237641, 681158]]], [['moderate losses between bounds', {'standard': 1863348, 'basic': 250, 'lcf': 1200, 'tax': 1050, 'min': 400, 'max': 2000, 'loss_limit': 5000000, 'claims': [182396, 119506, 129126, 64521]}, [495549, 1113521]], ['large claim limited', {'standard': 1794820, 'basic': 200, 'lcf': 1100, 'tax': 1030, 'min': 500, 'max': 3000, 'loss_limit': 5000000, 'claims': [6997029, 30223]}, [5030223, 5384460]], ['maximum binds', {'standard': 1446879, 'basic': 200, 'lcf': 1200, 'tax': 1030, 'min': 500, 'max': 1200, 'loss_limit': 5000000, 'claims': [3226070, 2149089, 2381869, 2566788]}, [10323816, 1736255]], ['no losses minimum binds', {'standard': 1111989, 'basic': 200, 'lcf': 1150, 'tax': 1050, 'min': 500, 'max': 1400, 'loss_limit': 5000000, 'claims': []}, [0, 555995]], ['subrogation recovery offsets', {'standard': 930668, 'basic': 250, 'lcf': 1150, 'tax': 1030, 'min': 300, 'max': 2500, 'loss_limit': 5000000, 'claims': [215001, -125166]}, [89835, 346057]], ['net recovery floors at zero', {'standard': 790663, 'basic': 200, 'lcf': 1100, 'tax': 1050, 'min': 300, 'max': 2500, 'loss_limit': 5000000, 'claims': [-24524]}, [0, 237199]], ['inverted bounds rejected', {'standard': 901935, 'basic': 200, 'lcf': 1150, 'tax': 1050, 'min': 1300, 'max': 1200, 'loss_limit': 5000000, 'claims': [100000]}, 'invalid bounds'], ['flat plan with equal bounds', {'standard': 802066, 'basic': 250, 'lcf': 1150, 'tax': 1050, 'min': 900, 'max': 900, 'loss_limit': 5000000, 'claims': [100000]}, [100000, 721859]], ['near-minimum losses', {'standard': 1352189, 'basic': 250, 'lcf': 1150, 'tax': 1050, 'min': 450, 'max': 1800, 'loss_limit': 5000000, 'claims': [178467]}, [178467, 608485]]]]
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:
Retro premiums are inflated because expense loading is converted like losses.

Input standard premium, basic, lcf, tax (x1000), min and max (per mille of standard), loss_limit, claims (negative = recovery). max<min -> 'invalid bounds'. Limited losses = max(0, sum(min(claim, limit))). Retro = (standard*basic + limited*lcf)*tax, bounded by [standard*min, standard*max] (bounds already include tax), rounded half-up. Return [limited, retro].

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):
    sp=x['standard']
    if x['max']<x['min']: return 'invalid bounds'
    lim=max(0,sum(min(c,x['loss_limit']) for c in x['claims']))
    basic=Fraction(sp*x['basic'],1000)
    retro=basic+Fraction(lim*x['lcf'],1000)
    lo=Fraction(sp*x['min'],1000); hi=Fraction(sp*x['max'],1000)
    retro=max(lo,min(hi,retro))*Fraction(x['tax'],1000)
    return [lim, math.floor(retro+Fraction(1,2))]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['moderate losses between bounds', {'standard': 1208187, 'basic': 250, 'lcf': 1100, 'tax': 1030, 'min': 400, 'max': 2000, 'loss_limit': 5000000, 'claims': [65251, 117766, 199866, 72604]}, [455487, 827175]], ['large claim limited', {'standard': 1536795, 'basic': 250, 'lcf': 1100, 'tax': 1050, 'min': 600, 'max': 3000, 'loss_limit': 5000000, 'claims': [7899385, 85219]}, [5085219, 4610385]], ['maximum binds', {'standard': 576969, 'basic': 250, 'lcf': 1100, 'tax': 1030, 'min': 500, 'max': 1200, 'loss_limit': 5000000, 'claims': [3887820, 3676391, 3519603, 3011895]}, [14095709, 692363]], ['no losses minimum binds', {'standard': 783317, 'basic': 200, 'lcf': 1150, 'tax': 1050, 'min': 500, 'max': 1400, 'loss_limit': 5000000, 'claims': []}, [0, 391659]], ['subrogation recovery offsets', {'standard': 1402360, 'basic': 200, 'lcf': 1200, 'tax': 1050, 'min': 300, 'max': 2500, 'loss_limit': 5000000, 'claims': [299401, -71949]}, [227452, 581085]], ['net recovery floors at zero', {'standard': 1970882, 'basic': 200, 'lcf': 1150, 'tax': 1030, 'min': 300, 'max': 2500, 'loss_limit': 5000000, 'claims': [-13900]}, [0, 591265]], ['inverted bounds rejected', {'standard': 857821, 'basic': 200, 'lcf': 1150, 'tax': 1030, 'min': 1300, 'max': 1200, 'loss_limit': 5000000, 'claims': [100000]}, 'invalid bounds'], ['flat plan with equal bounds', {'standard': 1032758, 'basic': 250, 'lcf': 1200, 'tax': 1030, 'min': 900, 'max': 900, 'loss_limit': 5000000, 'claims': [100000]}, [100000, 929482]], ['near-minimum losses', {'standard': 1037917, 'basic': 250, 'lcf': 1200, 'tax': 1030, 'min': 450, 'max': 1800, 'loss_limit': 5000000, 'claims': [196003]}, [196003, 509523]]], [['moderate losses between bounds', {'standard': 559811, 'basic': 250, 'lcf': 1150, 'tax': 1030, 'min': 400, 'max': 2000, 'loss_limit': 5000000, 'claims': [168808, 170340, 188681, 153930]}, [681759, 951695]], ['large claim limited', {'standard': 1398667, 'basic': 200, 'lcf': 1150, 'tax': 1030, 'min': 500, 'max': 3000, 'loss_limit': 5000000, 'claims': [8563900, 72244]}, [5072244, 4196001]], ['maximum binds', {'standard': 1860838, 'basic': 250, 'lcf': 1100, 'tax': 1050, 'min': 600, 'max': 1200, 'loss_limit': 5000000, 'claims': [3974702, 2021857, 3323996, 2741110]}, [12061665, 2233006]], ['no losses minimum binds', {'standard': 1054836, 'basic': 200, 'lcf': 1150, 'tax': 1050, 'min': 500, 'max': 1400, 'loss_limit': 5000000, 'claims': []}, [0, 527418]], ['subrogation recovery offsets', {'standard': 572933, 'basic': 250, 'lcf': 1150, 'tax': 1030, 'min': 300, 'max': 2500, 'loss_limit': 5000000, 'claims': [215865, -67794]}, [148071, 322920]], ['net recovery floors at zero', {'standard': 1415569, 'basic': 200, 'lcf': 1200, 'tax': 1030, 'min': 300, 'max': 2500, 'loss_limit': 5000000, 'claims': [-23951]}, [0, 424671]], ['inverted bounds rejected', {'standard': 1885857, 'basic': 200, 'lcf': 1200, 'tax': 1030, 'min': 1300, 'max': 1200, 'loss_limit': 5000000, 'claims': [100000]}, 'invalid bounds'], ['flat plan with equal bounds', {'standard': 1658903, 'basic': 200, 'lcf': 1200, 'tax': 1050, 'min': 900, 'max': 900, 'loss_limit': 5000000, 'claims': [100000]}, [100000, 1493013]], ['near-minimum losses', {'standard': 1831216, 'basic': 250, 'lcf': 1150, 'tax': 1030, 'min': 450, 'max': 1800, 'loss_limit': 5000000, 'claims': [255597]}, [255597, 824047]]], [['moderate losses between bounds', {'standard': 1953166, 'basic': 200, 'lcf': 1150, 'tax': 1050, 'min': 400, 'max': 2000, 'loss_limit': 5000000, 'claims': [130486, 146045, 106267, 80838]}, [463636, 970005]], ['large claim limited', {'standard': 1375996, 'basic': 200, 'lcf': 1150, 'tax': 1050, 'min': 600, 'max': 3000, 'loss_limit': 5000000, 'claims': [8850428, 26063]}, [5026063, 4127988]], ['maximum binds', {'standard': 1822101, 'basic': 200, 'lcf': 1200, 'tax': 1030, 'min': 600, 'max': 1200, 'loss_limit': 5000000, 'claims': [3010425, 2467545, 2177771, 3447891]}, [11103632, 2186521]], ['no losses minimum binds', {'standard': 1516833, 'basic': 200, 'lcf': 1100, 'tax': 1050, 'min': 500, 'max': 1400, 'loss_limit': 5000000, 'claims': []}, [0, 758417]], ['subrogation recovery offsets', {'standard': 714829, 'basic': 200, 'lcf': 1100, 'tax': 1050, 'min': 300, 'max': 2500, 'loss_limit': 5000000, 'claims': [292326, -101272]}, [191054, 370781]], ['net recovery floors at zero', {'standard': 1501098, 'basic': 200, 'lcf': 1100, 'tax': 1030, 'min': 300, 'max': 2500, 'loss_limit': 5000000, 'claims': [-22616]}, [0, 450329]], ['inverted bounds rejected', {'standard': 696781, 'basic': 200, 'lcf': 1200, 'tax': 1050, 'min': 1300, 'max': 1200, 'loss_limit': 5000000, 'claims': [100000]}, 'invalid bounds'], ['flat plan with equal bounds', {'standard': 802028, 'basic': 200, 'lcf': 1200, 'tax': 1030, 'min': 900, 'max': 900, 'loss_limit': 5000000, 'claims': [100000]}, [100000, 721825]], ['near-minimum losses', {'standard': 715359, 'basic': 200, 'lcf': 1200, 'tax': 1030, 'min': 450, 'max': 1800, 'loss_limit': 5000000, 'claims': [161153]}, [161153, 346549]]], [['moderate losses between bounds', {'standard': 714988, 'basic': 200, 'lcf': 1200, 'tax': 1050, 'min': 400, 'max': 2000, 'loss_limit': 5000000, 'claims': [147807, 50783, 101639, 147624]}, [447853, 714442]], ['large claim limited', {'standard': 1075364, 'basic': 200, 'lcf': 1100, 'tax': 1050, 'min': 600, 'max': 3000, 'loss_limit': 5000000, 'claims': [6621396, 51697]}, [5051697, 3226092]], ['maximum binds', {'standard': 636493, 'basic': 250, 'lcf': 1200, 'tax': 1050, 'min': 500, 'max': 1200, 'loss_limit': 5000000, 'claims': [3206066, 2811387, 2370852, 2596520]}, [10984825, 763792]], ['no losses minimum binds', {'standard': 1974481, 'basic': 200, 'lcf': 1200, 'tax': 1050, 'min': 500, 'max': 1600, 'loss_limit': 5000000, 'claims': []}, [0, 987241]], ['subrogation recovery offsets', {'standard': 1092045, 'basic': 200, 'lcf': 1200, 'tax': 1030, 'min': 300, 'max': 2500, 'loss_limit': 5000000, 'claims': [210597, -95806]}, [114791, 366843]], ['net recovery floors at zero', {'standard': 1088467, 'basic': 250, 'lcf': 1200, 'tax': 1030, 'min': 300, 'max': 2500, 'loss_limit': 5000000, 'claims': [-13789]}, [0, 326540]], ['inverted bounds rejected', {'standard': 1508678, 'basic': 200, 'lcf': 1150, 'tax': 1050, 'min': 1300, 'max': 1200, 'loss_limit': 5000000, 'claims': [100000]}, 'invalid bounds'], ['flat plan with equal bounds', {'standard': 811592, 'basic': 250, 'lcf': 1200, 'tax': 1050, 'min': 900, 'max': 900, 'loss_limit': 5000000, 'claims': [100000]}, [100000, 730433]], ['near-minimum losses', {'standard': 1513685, 'basic': 200, 'lcf': 1100, 'tax': 1050, 'min': 450, 'max': 1800, 'loss_limit': 5000000, 'claims': [237641]}, [237641, 681158]]], [['moderate losses between bounds', {'standard': 1863348, 'basic': 250, 'lcf': 1200, 'tax': 1050, 'min': 400, 'max': 2000, 'loss_limit': 5000000, 'claims': [182396, 119506, 129126, 64521]}, [495549, 1113521]], ['large claim limited', {'standard': 1794820, 'basic': 200, 'lcf': 1100, 'tax': 1030, 'min': 500, 'max': 3000, 'loss_limit': 5000000, 'claims': [6997029, 30223]}, [5030223, 5384460]], ['maximum binds', {'standard': 1446879, 'basic': 200, 'lcf': 1200, 'tax': 1030, 'min': 500, 'max': 1200, 'loss_limit': 5000000, 'claims': [3226070, 2149089, 2381869, 2566788]}, [10323816, 1736255]], ['no losses minimum binds', {'standard': 1111989, 'basic': 200, 'lcf': 1150, 'tax': 1050, 'min': 500, 'max': 1400, 'loss_limit': 5000000, 'claims': []}, [0, 555995]], ['subrogation recovery offsets', {'standard': 930668, 'basic': 250, 'lcf': 1150, 'tax': 1030, 'min': 300, 'max': 2500, 'loss_limit': 5000000, 'claims': [215001, -125166]}, [89835, 346057]], ['net recovery floors at zero', {'standard': 790663, 'basic': 200, 'lcf': 1100, 'tax': 1050, 'min': 300, 'max': 2500, 'loss_limit': 5000000, 'claims': [-24524]}, [0, 237199]], ['inverted bounds rejected', {'standard': 901935, 'basic': 200, 'lcf': 1150, 'tax': 1050, 'min': 1300, 'max': 1200, 'loss_limit': 5000000, 'claims': [100000]}, 'invalid bounds'], ['flat plan with equal bounds', {'standard': 802066, 'basic': 250, 'lcf': 1150, 'tax': 1050, 'min': 900, 'max': 900, 'loss_limit': 5000000, 'claims': [100000]}, [100000, 721859]], ['near-minimum losses', {'standard': 1352189, 'basic': 250, 'lcf': 1150, 'tax': 1050, 'min': 450, 'max': 1800, 'loss_limit': 5000000, 'claims': [178467]}, [178467, 608485]]]]
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):
    sp=x['standard']
    if x['max']<x['min']: return 'invalid bounds'
    lim=max(0,sum(min(c,x['loss_limit']) for c in x['claims']))
    basic=Fraction(sp*x['basic'],1000)
    retro=(basic+Fraction(lim*x['lcf'],1000))*Fraction(x['tax'],1000)
    lo=Fraction(sp*x['min'],1000)*Fraction(x['tax'],1000); hi=Fraction(sp*x['max'],1000)*Fraction(x['tax'],1000)
    retro=max(lo,min(hi,retro))
    return [lim, math.floor(retro+Fraction(1,2))]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['moderate losses between bounds', {'standard': 1208187, 'basic': 250, 'lcf': 1100, 'tax': 1030, 'min': 400, 'max': 2000, 'loss_limit': 5000000, 'claims': [65251, 117766, 199866, 72604]}, [455487, 827175]], ['large claim limited', {'standard': 1536795, 'basic': 250, 'lcf': 1100, 'tax': 1050, 'min': 600, 'max': 3000, 'loss_limit': 5000000, 'claims': [7899385, 85219]}, [5085219, 4610385]], ['maximum binds', {'standard': 576969, 'basic': 250, 'lcf': 1100, 'tax': 1030, 'min': 500, 'max': 1200, 'loss_limit': 5000000, 'claims': [3887820, 3676391, 3519603, 3011895]}, [14095709, 692363]], ['no losses minimum binds', {'standard': 783317, 'basic': 200, 'lcf': 1150, 'tax': 1050, 'min': 500, 'max': 1400, 'loss_limit': 5000000, 'claims': []}, [0, 391659]], ['subrogation recovery offsets', {'standard': 1402360, 'basic': 200, 'lcf': 1200, 'tax': 1050, 'min': 300, 'max': 2500, 'loss_limit': 5000000, 'claims': [299401, -71949]}, [227452, 581085]], ['net recovery floors at zero', {'standard': 1970882, 'basic': 200, 'lcf': 1150, 'tax': 1030, 'min': 300, 'max': 2500, 'loss_limit': 5000000, 'claims': [-13900]}, [0, 591265]], ['inverted bounds rejected', {'standard': 857821, 'basic': 200, 'lcf': 1150, 'tax': 1030, 'min': 1300, 'max': 1200, 'loss_limit': 5000000, 'claims': [100000]}, 'invalid bounds'], ['flat plan with equal bounds', {'standard': 1032758, 'basic': 250, 'lcf': 1200, 'tax': 1030, 'min': 900, 'max': 900, 'loss_limit': 5000000, 'claims': [100000]}, [100000, 929482]], ['near-minimum losses', {'standard': 1037917, 'basic': 250, 'lcf': 1200, 'tax': 1030, 'min': 450, 'max': 1800, 'loss_limit': 5000000, 'claims': [196003]}, [196003, 509523]]], [['moderate losses between bounds', {'standard': 559811, 'basic': 250, 'lcf': 1150, 'tax': 1030, 'min': 400, 'max': 2000, 'loss_limit': 5000000, 'claims': [168808, 170340, 188681, 153930]}, [681759, 951695]], ['large claim limited', {'standard': 1398667, 'basic': 200, 'lcf': 1150, 'tax': 1030, 'min': 500, 'max': 3000, 'loss_limit': 5000000, 'claims': [8563900, 72244]}, [5072244, 4196001]], ['maximum binds', {'standard': 1860838, 'basic': 250, 'lcf': 1100, 'tax': 1050, 'min': 600, 'max': 1200, 'loss_limit': 5000000, 'claims': [3974702, 2021857, 3323996, 2741110]}, [12061665, 2233006]], ['no losses minimum binds', {'standard': 1054836, 'basic': 200, 'lcf': 1150, 'tax': 1050, 'min': 500, 'max': 1400, 'loss_limit': 5000000, 'claims': []}, [0, 527418]], ['subrogation recovery offsets', {'standard': 572933, 'basic': 250, 'lcf': 1150, 'tax': 1030, 'min': 300, 'max': 2500, 'loss_limit': 5000000, 'claims': [215865, -67794]}, [148071, 322920]], ['net recovery floors at zero', {'standard': 1415569, 'basic': 200, 'lcf': 1200, 'tax': 1030, 'min': 300, 'max': 2500, 'loss_limit': 5000000, 'claims': [-23951]}, [0, 424671]], ['inverted bounds rejected', {'standard': 1885857, 'basic': 200, 'lcf': 1200, 'tax': 1030, 'min': 1300, 'max': 1200, 'loss_limit': 5000000, 'claims': [100000]}, 'invalid bounds'], ['flat plan with equal bounds', {'standard': 1658903, 'basic': 200, 'lcf': 1200, 'tax': 1050, 'min': 900, 'max': 900, 'loss_limit': 5000000, 'claims': [100000]}, [100000, 1493013]], ['near-minimum losses', {'standard': 1831216, 'basic': 250, 'lcf': 1150, 'tax': 1030, 'min': 450, 'max': 1800, 'loss_limit': 5000000, 'claims': [255597]}, [255597, 824047]]], [['moderate losses between bounds', {'standard': 1953166, 'basic': 200, 'lcf': 1150, 'tax': 1050, 'min': 400, 'max': 2000, 'loss_limit': 5000000, 'claims': [130486, 146045, 106267, 80838]}, [463636, 970005]], ['large claim limited', {'standard': 1375996, 'basic': 200, 'lcf': 1150, 'tax': 1050, 'min': 600, 'max': 3000, 'loss_limit': 5000000, 'claims': [8850428, 26063]}, [5026063, 4127988]], ['maximum binds', {'standard': 1822101, 'basic': 200, 'lcf': 1200, 'tax': 1030, 'min': 600, 'max': 1200, 'loss_limit': 5000000, 'claims': [3010425, 2467545, 2177771, 3447891]}, [11103632, 2186521]], ['no losses minimum binds', {'standard': 1516833, 'basic': 200, 'lcf': 1100, 'tax': 1050, 'min': 500, 'max': 1400, 'loss_limit': 5000000, 'claims': []}, [0, 758417]], ['subrogation recovery offsets', {'standard': 714829, 'basic': 200, 'lcf': 1100, 'tax': 1050, 'min': 300, 'max': 2500, 'loss_limit': 5000000, 'claims': [292326, -101272]}, [191054, 370781]], ['net recovery floors at zero', {'standard': 1501098, 'basic': 200, 'lcf': 1100, 'tax': 1030, 'min': 300, 'max': 2500, 'loss_limit': 5000000, 'claims': [-22616]}, [0, 450329]], ['inverted bounds rejected', {'standard': 696781, 'basic': 200, 'lcf': 1200, 'tax': 1050, 'min': 1300, 'max': 1200, 'loss_limit': 5000000, 'claims': [100000]}, 'invalid bounds'], ['flat plan with equal bounds', {'standard': 802028, 'basic': 200, 'lcf': 1200, 'tax': 1030, 'min': 900, 'max': 900, 'loss_limit': 5000000, 'claims': [100000]}, [100000, 721825]], ['near-minimum losses', {'standard': 715359, 'basic': 200, 'lcf': 1200, 'tax': 1030, 'min': 450, 'max': 1800, 'loss_limit': 5000000, 'claims': [161153]}, [161153, 346549]]], [['moderate losses between bounds', {'standard': 714988, 'basic': 200, 'lcf': 1200, 'tax': 1050, 'min': 400, 'max': 2000, 'loss_limit': 5000000, 'claims': [147807, 50783, 101639, 147624]}, [447853, 714442]], ['large claim limited', {'standard': 1075364, 'basic': 200, 'lcf': 1100, 'tax': 1050, 'min': 600, 'max': 3000, 'loss_limit': 5000000, 'claims': [6621396, 51697]}, [5051697, 3226092]], ['maximum binds', {'standard': 636493, 'basic': 250, 'lcf': 1200, 'tax': 1050, 'min': 500, 'max': 1200, 'loss_limit': 5000000, 'claims': [3206066, 2811387, 2370852, 2596520]}, [10984825, 763792]], ['no losses minimum binds', {'standard': 1974481, 'basic': 200, 'lcf': 1200, 'tax': 1050, 'min': 500, 'max': 1600, 'loss_limit': 5000000, 'claims': []}, [0, 987241]], ['subrogation recovery offsets', {'standard': 1092045, 'basic': 200, 'lcf': 1200, 'tax': 1030, 'min': 300, 'max': 2500, 'loss_limit': 5000000, 'claims': [210597, -95806]}, [114791, 366843]], ['net recovery floors at zero', {'standard': 1088467, 'basic': 250, 'lcf': 1200, 'tax': 1030, 'min': 300, 'max': 2500, 'loss_limit': 5000000, 'claims': [-13789]}, [0, 326540]], ['inverted bounds rejected', {'standard': 1508678, 'basic': 200, 'lcf': 1150, 'tax': 1050, 'min': 1300, 'max': 1200, 'loss_limit': 5000000, 'claims': [100000]}, 'invalid bounds'], ['flat plan with equal bounds', {'standard': 811592, 'basic': 250, 'lcf': 1200, 'tax': 1050, 'min': 900, 'max': 900, 'loss_limit': 5000000, 'claims': [100000]}, [100000, 730433]], ['near-minimum losses', {'standard': 1513685, 'basic': 200, 'lcf': 1100, 'tax': 1050, 'min': 450, 'max': 1800, 'loss_limit': 5000000, 'claims': [237641]}, [237641, 681158]]], [['moderate losses between bounds', {'standard': 1863348, 'basic': 250, 'lcf': 1200, 'tax': 1050, 'min': 400, 'max': 2000, 'loss_limit': 5000000, 'claims': [182396, 119506, 129126, 64521]}, [495549, 1113521]], ['large claim limited', {'standard': 1794820, 'basic': 200, 'lcf': 1100, 'tax': 1030, 'min': 500, 'max': 3000, 'loss_limit': 5000000, 'claims': [6997029, 30223]}, [5030223, 5384460]], ['maximum binds', {'standard': 1446879, 'basic': 200, 'lcf': 1200, 'tax': 1030, 'min': 500, 'max': 1200, 'loss_limit': 5000000, 'claims': [3226070, 2149089, 2381869, 2566788]}, [10323816, 1736255]], ['no losses minimum binds', {'standard': 1111989, 'basic': 200, 'lcf': 1150, 'tax': 1050, 'min': 500, 'max': 1400, 'loss_limit': 5000000, 'claims': []}, [0, 555995]], ['subrogation recovery offsets', {'standard': 930668, 'basic': 250, 'lcf': 1150, 'tax': 1030, 'min': 300, 'max': 2500, 'loss_limit': 5000000, 'claims': [215001, -125166]}, [89835, 346057]], ['net recovery floors at zero', {'standard': 790663, 'basic': 200, 'lcf': 1100, 'tax': 1050, 'min': 300, 'max': 2500, 'loss_limit': 5000000, 'claims': [-24524]}, [0, 237199]], ['inverted bounds rejected', {'standard': 901935, 'basic': 200, 'lcf': 1150, 'tax': 1050, 'min': 1300, 'max': 1200, 'loss_limit': 5000000, 'claims': [100000]}, 'invalid bounds'], ['flat plan with equal bounds', {'standard': 802066, 'basic': 250, 'lcf': 1150, 'tax': 1050, 'min': 900, 'max': 900, 'loss_limit': 5000000, 'claims': [100000]}, [100000, 721859]], ['near-minimum losses', {'standard': 1352189, 'basic': 250, 'lcf': 1150, 'tax': 1050, 'min': 450, 'max': 1800, 'loss_limit': 5000000, 'claims': [178467]}, [178467, 608485]]]]
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:
Capped or floored retro premiums exceed the plan bounds by the tax multiplier.

Input standard premium, basic, lcf, tax (x1000), min and max (per mille of standard), loss_limit, claims (negative = recovery). max<min -> 'invalid bounds'. Limited losses = max(0, sum(min(claim, limit))). Retro = (standard*basic + limited*lcf)*tax, bounded by [standard*min, standard*max] (bounds already include tax), rounded half-up. Return [limited, retro].

split: open-access