broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    n=x['claims']; full=x['full_standard']
    if n<0 or full<=0: return 'invalid'
    z=min(1000, math.isqrt(n*1000000//full))
    ind=Fraction(z*x['observed']+(1000-z)*x['complement'],1000)
    ind=math.floor(ind+Fraction(1,2))
    cap=x['cap']
    ind=min(cap,ind)
    return [z,ind]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['partial credibility', {'claims': 468, 'full_standard': 1082, 'observed': 177, 'complement': 60, 'cap': 150}, [657, 137]], ['small volume', {'claims': 43, 'full_standard': 1082, 'observed': 77, 'complement': 53, 'cap': 150}, [199, 58]], ['above full standard', {'claims': 1951, 'full_standard': 1082, 'observed': -79, 'complement': 43, 'cap': 150}, [1000, -79]], ['exactly full standard', {'claims': 1082, 'full_standard': 1082, 'observed': 28, 'complement': 29, 'cap': 150}, [1000, 28]], ['zero claims uses complement', {'claims': 0, 'full_standard': 1082, 'observed': -82, 'complement': -23, 'cap': 150}, [0, -23]], ['capped increase', {'claims': 898, 'full_standard': 1082, 'observed': 400, 'complement': 50, 'cap': 150}, [911, 150]], ['capped decrease', {'claims': 774, 'full_standard': 1082, 'observed': -400, 'complement': -20, 'cap': 150}, [845, -150]], ['negative claims rejected', {'claims': -3, 'full_standard': 1082, 'observed': -107, 'complement': -1, 'cap': 150}, 'invalid'], ['moderate volume', {'claims': 673, 'full_standard': 1082, 'observed': 49, 'complement': -23, 'cap': 150}, [788, 34]]], [['partial credibility', {'claims': 239, 'full_standard': 1082, 'observed': -28, 'complement': -25, 'cap': 150}, [469, -26]], ['small volume', {'claims': 23, 'full_standard': 1082, 'observed': -82, 'complement': 40, 'cap': 150}, [145, 22]], ['above full standard', {'claims': 1972, 'full_standard': 1082, 'observed': 21, 'complement': 2, 'cap': 150}, [1000, 21]], ['exactly full standard', {'claims': 1082, 'full_standard': 1082, 'observed': -116, 'complement': 58, 'cap': 150}, [1000, -116]], ['zero claims uses complement', {'claims': 0, 'full_standard': 1082, 'observed': 137, 'complement': -12, 'cap': 150}, [0, -12]], ['capped increase', {'claims': 802, 'full_standard': 1082, 'observed': 400, 'complement': 50, 'cap': 150}, [860, 150]], ['capped decrease', {'claims': 894, 'full_standard': 1082, 'observed': -400, 'complement': -20, 'cap': 150}, [908, -150]], ['negative claims rejected', {'claims': -3, 'full_standard': 1082, 'observed': -45, 'complement': 36, 'cap': 150}, 'invalid'], ['moderate volume', {'claims': 317, 'full_standard': 1082, 'observed': 154, 'complement': 46, 'cap': 150}, [541, 104]]], [['partial credibility', {'claims': 431, 'full_standard': 1082, 'observed': 31, 'complement': 31, 'cap': 150}, [631, 31]], ['small volume', {'claims': 7, 'full_standard': 1082, 'observed': 142, 'complement': 9, 'cap': 150}, [80, 20]], ['above full standard', {'claims': 1564, 'full_standard': 1082, 'observed': 48, 'complement': 19, 'cap': 150}, [1000, 48]], ['exactly full standard', {'claims': 1082, 'full_standard': 1082, 'observed': -29, 'complement': -12, 'cap': 150}, [1000, -29]], ['zero claims uses complement', {'claims': 0, 'full_standard': 1082, 'observed': 136, 'complement': 56, 'cap': 150}, [0, 56]], ['capped increase', {'claims': 914, 'full_standard': 1082, 'observed': 400, 'complement': 50, 'cap': 150}, [919, 150]], ['capped decrease', {'claims': 737, 'full_standard': 1082, 'observed': -400, 'complement': -20, 'cap': 150}, [825, -150]], ['negative claims rejected', {'claims': -3, 'full_standard': 1082, 'observed': -49, 'complement': 60, 'cap': 150}, 'invalid'], ['moderate volume', {'claims': 343, 'full_standard': 1082, 'observed': -32, 'complement': 32, 'cap': 150}, [563, -4]]], [['partial credibility', {'claims': 220, 'full_standard': 1082, 'observed': 10, 'complement': 36, 'cap': 150}, [450, 24]], ['small volume', {'claims': 46, 'full_standard': 1082, 'observed': 76, 'complement': -15, 'cap': 150}, [206, 4]], ['above full standard', {'claims': 1760, 'full_standard': 1082, 'observed': -79, 'complement': -7, 'cap': 150}, [1000, -79]], ['exactly full standard', {'claims': 1082, 'full_standard': 1082, 'observed': 138, 'complement': -10, 'cap': 150}, [1000, 138]], ['zero claims uses complement', {'claims': 0, 'full_standard': 1082, 'observed': 173, 'complement': 37, 'cap': 150}, [0, 37]], ['capped increase', {'claims': 760, 'full_standard': 1082, 'observed': 400, 'complement': 50, 'cap': 150}, [838, 150]], ['capped decrease', {'claims': 990, 'full_standard': 1082, 'observed': -400, 'complement': -20, 'cap': 150}, [956, -150]], ['negative claims rejected', {'claims': -3, 'full_standard': 1082, 'observed': 78, 'complement': 46, 'cap': 150}, 'invalid'], ['moderate volume', {'claims': 268, 'full_standard': 1082, 'observed': 127, 'complement': 57, 'cap': 150}, [497, 92]]], [['partial credibility', {'claims': 185, 'full_standard': 1082, 'observed': 50, 'complement': -6, 'cap': 150}, [413, 17]], ['small volume', {'claims': 26, 'full_standard': 1082, 'observed': 115, 'complement': 36, 'cap': 150}, [155, 48]], ['above full standard', {'claims': 1435, 'full_standard': 1082, 'observed': 127, 'complement': 35, 'cap': 150}, [1000, 127]], ['exactly full standard', {'claims': 1082, 'full_standard': 1082, 'observed': -88, 'complement': 21, 'cap': 150}, [1000, -88]], ['zero claims uses complement', {'claims': 0, 'full_standard': 1082, 'observed': -119, 'complement': 7, 'cap': 150}, [0, 7]], ['capped increase', {'claims': 843, 'full_standard': 1082, 'observed': 400, 'complement': 50, 'cap': 150}, [882, 150]], ['capped decrease', {'claims': 747, 'full_standard': 1082, 'observed': -400, 'complement': -20, 'cap': 150}, [830, -150]], ['negative claims rejected', {'claims': -3, 'full_standard': 1082, 'observed': -70, 'complement': 10, 'cap': 150}, 'invalid'], ['moderate volume', {'claims': 721, 'full_standard': 1082, 'observed': -26, 'complement': 48, 'cap': 150}, [816, -12]]]]
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):
    n=x['claims']; full=x['full_standard']
    if n<0 or full<=0: return 'invalid'
    z=min(1000, math.isqrt(n*1000000//full))
    ind=Fraction(z*x['observed']+(1000-z)*x['complement'],1000)
    ind=math.floor(ind+Fraction(1,2))
    cap=x['cap']
    ind=max(0,min(cap,ind))
    return [z,ind]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['partial credibility', {'claims': 468, 'full_standard': 1082, 'observed': 177, 'complement': 60, 'cap': 150}, [657, 137]], ['small volume', {'claims': 43, 'full_standard': 1082, 'observed': 77, 'complement': 53, 'cap': 150}, [199, 58]], ['above full standard', {'claims': 1951, 'full_standard': 1082, 'observed': -79, 'complement': 43, 'cap': 150}, [1000, -79]], ['exactly full standard', {'claims': 1082, 'full_standard': 1082, 'observed': 28, 'complement': 29, 'cap': 150}, [1000, 28]], ['zero claims uses complement', {'claims': 0, 'full_standard': 1082, 'observed': -82, 'complement': -23, 'cap': 150}, [0, -23]], ['capped increase', {'claims': 898, 'full_standard': 1082, 'observed': 400, 'complement': 50, 'cap': 150}, [911, 150]], ['capped decrease', {'claims': 774, 'full_standard': 1082, 'observed': -400, 'complement': -20, 'cap': 150}, [845, -150]], ['negative claims rejected', {'claims': -3, 'full_standard': 1082, 'observed': -107, 'complement': -1, 'cap': 150}, 'invalid'], ['moderate volume', {'claims': 673, 'full_standard': 1082, 'observed': 49, 'complement': -23, 'cap': 150}, [788, 34]]], [['partial credibility', {'claims': 239, 'full_standard': 1082, 'observed': -28, 'complement': -25, 'cap': 150}, [469, -26]], ['small volume', {'claims': 23, 'full_standard': 1082, 'observed': -82, 'complement': 40, 'cap': 150}, [145, 22]], ['above full standard', {'claims': 1972, 'full_standard': 1082, 'observed': 21, 'complement': 2, 'cap': 150}, [1000, 21]], ['exactly full standard', {'claims': 1082, 'full_standard': 1082, 'observed': -116, 'complement': 58, 'cap': 150}, [1000, -116]], ['zero claims uses complement', {'claims': 0, 'full_standard': 1082, 'observed': 137, 'complement': -12, 'cap': 150}, [0, -12]], ['capped increase', {'claims': 802, 'full_standard': 1082, 'observed': 400, 'complement': 50, 'cap': 150}, [860, 150]], ['capped decrease', {'claims': 894, 'full_standard': 1082, 'observed': -400, 'complement': -20, 'cap': 150}, [908, -150]], ['negative claims rejected', {'claims': -3, 'full_standard': 1082, 'observed': -45, 'complement': 36, 'cap': 150}, 'invalid'], ['moderate volume', {'claims': 317, 'full_standard': 1082, 'observed': 154, 'complement': 46, 'cap': 150}, [541, 104]]], [['partial credibility', {'claims': 431, 'full_standard': 1082, 'observed': 31, 'complement': 31, 'cap': 150}, [631, 31]], ['small volume', {'claims': 7, 'full_standard': 1082, 'observed': 142, 'complement': 9, 'cap': 150}, [80, 20]], ['above full standard', {'claims': 1564, 'full_standard': 1082, 'observed': 48, 'complement': 19, 'cap': 150}, [1000, 48]], ['exactly full standard', {'claims': 1082, 'full_standard': 1082, 'observed': -29, 'complement': -12, 'cap': 150}, [1000, -29]], ['zero claims uses complement', {'claims': 0, 'full_standard': 1082, 'observed': 136, 'complement': 56, 'cap': 150}, [0, 56]], ['capped increase', {'claims': 914, 'full_standard': 1082, 'observed': 400, 'complement': 50, 'cap': 150}, [919, 150]], ['capped decrease', {'claims': 737, 'full_standard': 1082, 'observed': -400, 'complement': -20, 'cap': 150}, [825, -150]], ['negative claims rejected', {'claims': -3, 'full_standard': 1082, 'observed': -49, 'complement': 60, 'cap': 150}, 'invalid'], ['moderate volume', {'claims': 343, 'full_standard': 1082, 'observed': -32, 'complement': 32, 'cap': 150}, [563, -4]]], [['partial credibility', {'claims': 220, 'full_standard': 1082, 'observed': 10, 'complement': 36, 'cap': 150}, [450, 24]], ['small volume', {'claims': 46, 'full_standard': 1082, 'observed': 76, 'complement': -15, 'cap': 150}, [206, 4]], ['above full standard', {'claims': 1760, 'full_standard': 1082, 'observed': -79, 'complement': -7, 'cap': 150}, [1000, -79]], ['exactly full standard', {'claims': 1082, 'full_standard': 1082, 'observed': 138, 'complement': -10, 'cap': 150}, [1000, 138]], ['zero claims uses complement', {'claims': 0, 'full_standard': 1082, 'observed': 173, 'complement': 37, 'cap': 150}, [0, 37]], ['capped increase', {'claims': 760, 'full_standard': 1082, 'observed': 400, 'complement': 50, 'cap': 150}, [838, 150]], ['capped decrease', {'claims': 990, 'full_standard': 1082, 'observed': -400, 'complement': -20, 'cap': 150}, [956, -150]], ['negative claims rejected', {'claims': -3, 'full_standard': 1082, 'observed': 78, 'complement': 46, 'cap': 150}, 'invalid'], ['moderate volume', {'claims': 268, 'full_standard': 1082, 'observed': 127, 'complement': 57, 'cap': 150}, [497, 92]]], [['partial credibility', {'claims': 185, 'full_standard': 1082, 'observed': 50, 'complement': -6, 'cap': 150}, [413, 17]], ['small volume', {'claims': 26, 'full_standard': 1082, 'observed': 115, 'complement': 36, 'cap': 150}, [155, 48]], ['above full standard', {'claims': 1435, 'full_standard': 1082, 'observed': 127, 'complement': 35, 'cap': 150}, [1000, 127]], ['exactly full standard', {'claims': 1082, 'full_standard': 1082, 'observed': -88, 'complement': 21, 'cap': 150}, [1000, -88]], ['zero claims uses complement', {'claims': 0, 'full_standard': 1082, 'observed': -119, 'complement': 7, 'cap': 150}, [0, 7]], ['capped increase', {'claims': 843, 'full_standard': 1082, 'observed': 400, 'complement': 50, 'cap': 150}, [882, 150]], ['capped decrease', {'claims': 747, 'full_standard': 1082, 'observed': -400, 'complement': -20, 'cap': 150}, [830, -150]], ['negative claims rejected', {'claims': -3, 'full_standard': 1082, 'observed': -70, 'complement': 10, 'cap': 150}, 'invalid'], ['moderate volume', {'claims': 721, 'full_standard': 1082, 'observed': -26, 'complement': 48, 'cap': 150}, [816, -12]]]]
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:
Large indicated decreases pass through uncapped.

Input claims n, full_standard, observed and complement changes (per mille), cap. n<0 or full<=0 -> 'invalid'. Z (per mille) = min(1000, isqrt(n*10^6 // full)). Indication = floor((Z*obs+(1000-Z)*comp)/1000+1/2), then clamped to [-cap, cap]. Return [Z, indication].

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):
    n=x['claims']; full=x['full_standard']
    if n<=0 or full<=0: return 'invalid'
    z=min(1000, math.isqrt(n*1000000//full))
    ind=Fraction(z*x['observed']+(1000-z)*x['complement'],1000)
    ind=math.floor(ind+Fraction(1,2))
    cap=x['cap']
    ind=max(-cap,min(cap,ind))
    return [z,ind]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['partial credibility', {'claims': 468, 'full_standard': 1082, 'observed': 177, 'complement': 60, 'cap': 150}, [657, 137]], ['small volume', {'claims': 43, 'full_standard': 1082, 'observed': 77, 'complement': 53, 'cap': 150}, [199, 58]], ['above full standard', {'claims': 1951, 'full_standard': 1082, 'observed': -79, 'complement': 43, 'cap': 150}, [1000, -79]], ['exactly full standard', {'claims': 1082, 'full_standard': 1082, 'observed': 28, 'complement': 29, 'cap': 150}, [1000, 28]], ['zero claims uses complement', {'claims': 0, 'full_standard': 1082, 'observed': -82, 'complement': -23, 'cap': 150}, [0, -23]], ['capped increase', {'claims': 898, 'full_standard': 1082, 'observed': 400, 'complement': 50, 'cap': 150}, [911, 150]], ['capped decrease', {'claims': 774, 'full_standard': 1082, 'observed': -400, 'complement': -20, 'cap': 150}, [845, -150]], ['negative claims rejected', {'claims': -3, 'full_standard': 1082, 'observed': -107, 'complement': -1, 'cap': 150}, 'invalid'], ['moderate volume', {'claims': 673, 'full_standard': 1082, 'observed': 49, 'complement': -23, 'cap': 150}, [788, 34]]], [['partial credibility', {'claims': 239, 'full_standard': 1082, 'observed': -28, 'complement': -25, 'cap': 150}, [469, -26]], ['small volume', {'claims': 23, 'full_standard': 1082, 'observed': -82, 'complement': 40, 'cap': 150}, [145, 22]], ['above full standard', {'claims': 1972, 'full_standard': 1082, 'observed': 21, 'complement': 2, 'cap': 150}, [1000, 21]], ['exactly full standard', {'claims': 1082, 'full_standard': 1082, 'observed': -116, 'complement': 58, 'cap': 150}, [1000, -116]], ['zero claims uses complement', {'claims': 0, 'full_standard': 1082, 'observed': 137, 'complement': -12, 'cap': 150}, [0, -12]], ['capped increase', {'claims': 802, 'full_standard': 1082, 'observed': 400, 'complement': 50, 'cap': 150}, [860, 150]], ['capped decrease', {'claims': 894, 'full_standard': 1082, 'observed': -400, 'complement': -20, 'cap': 150}, [908, -150]], ['negative claims rejected', {'claims': -3, 'full_standard': 1082, 'observed': -45, 'complement': 36, 'cap': 150}, 'invalid'], ['moderate volume', {'claims': 317, 'full_standard': 1082, 'observed': 154, 'complement': 46, 'cap': 150}, [541, 104]]], [['partial credibility', {'claims': 431, 'full_standard': 1082, 'observed': 31, 'complement': 31, 'cap': 150}, [631, 31]], ['small volume', {'claims': 7, 'full_standard': 1082, 'observed': 142, 'complement': 9, 'cap': 150}, [80, 20]], ['above full standard', {'claims': 1564, 'full_standard': 1082, 'observed': 48, 'complement': 19, 'cap': 150}, [1000, 48]], ['exactly full standard', {'claims': 1082, 'full_standard': 1082, 'observed': -29, 'complement': -12, 'cap': 150}, [1000, -29]], ['zero claims uses complement', {'claims': 0, 'full_standard': 1082, 'observed': 136, 'complement': 56, 'cap': 150}, [0, 56]], ['capped increase', {'claims': 914, 'full_standard': 1082, 'observed': 400, 'complement': 50, 'cap': 150}, [919, 150]], ['capped decrease', {'claims': 737, 'full_standard': 1082, 'observed': -400, 'complement': -20, 'cap': 150}, [825, -150]], ['negative claims rejected', {'claims': -3, 'full_standard': 1082, 'observed': -49, 'complement': 60, 'cap': 150}, 'invalid'], ['moderate volume', {'claims': 343, 'full_standard': 1082, 'observed': -32, 'complement': 32, 'cap': 150}, [563, -4]]], [['partial credibility', {'claims': 220, 'full_standard': 1082, 'observed': 10, 'complement': 36, 'cap': 150}, [450, 24]], ['small volume', {'claims': 46, 'full_standard': 1082, 'observed': 76, 'complement': -15, 'cap': 150}, [206, 4]], ['above full standard', {'claims': 1760, 'full_standard': 1082, 'observed': -79, 'complement': -7, 'cap': 150}, [1000, -79]], ['exactly full standard', {'claims': 1082, 'full_standard': 1082, 'observed': 138, 'complement': -10, 'cap': 150}, [1000, 138]], ['zero claims uses complement', {'claims': 0, 'full_standard': 1082, 'observed': 173, 'complement': 37, 'cap': 150}, [0, 37]], ['capped increase', {'claims': 760, 'full_standard': 1082, 'observed': 400, 'complement': 50, 'cap': 150}, [838, 150]], ['capped decrease', {'claims': 990, 'full_standard': 1082, 'observed': -400, 'complement': -20, 'cap': 150}, [956, -150]], ['negative claims rejected', {'claims': -3, 'full_standard': 1082, 'observed': 78, 'complement': 46, 'cap': 150}, 'invalid'], ['moderate volume', {'claims': 268, 'full_standard': 1082, 'observed': 127, 'complement': 57, 'cap': 150}, [497, 92]]], [['partial credibility', {'claims': 185, 'full_standard': 1082, 'observed': 50, 'complement': -6, 'cap': 150}, [413, 17]], ['small volume', {'claims': 26, 'full_standard': 1082, 'observed': 115, 'complement': 36, 'cap': 150}, [155, 48]], ['above full standard', {'claims': 1435, 'full_standard': 1082, 'observed': 127, 'complement': 35, 'cap': 150}, [1000, 127]], ['exactly full standard', {'claims': 1082, 'full_standard': 1082, 'observed': -88, 'complement': 21, 'cap': 150}, [1000, -88]], ['zero claims uses complement', {'claims': 0, 'full_standard': 1082, 'observed': -119, 'complement': 7, 'cap': 150}, [0, 7]], ['capped increase', {'claims': 843, 'full_standard': 1082, 'observed': 400, 'complement': 50, 'cap': 150}, [882, 150]], ['capped decrease', {'claims': 747, 'full_standard': 1082, 'observed': -400, 'complement': -20, 'cap': 150}, [830, -150]], ['negative claims rejected', {'claims': -3, 'full_standard': 1082, 'observed': -70, 'complement': 10, 'cap': 150}, 'invalid'], ['moderate volume', {'claims': 721, 'full_standard': 1082, 'observed': -26, 'complement': 48, 'cap': 150}, [816, -12]]]]
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):
    n=x['claims']; full=x['full_standard']
    if n<0 or full<=0 or n>full: return 'invalid'
    z=min(1000, math.isqrt(n*1000000//full))
    ind=Fraction(z*x['observed']+(1000-z)*x['complement'],1000)
    ind=math.floor(ind+Fraction(1,2))
    cap=x['cap']
    ind=max(-cap,min(cap,ind))
    return [z,ind]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['partial credibility', {'claims': 468, 'full_standard': 1082, 'observed': 177, 'complement': 60, 'cap': 150}, [657, 137]], ['small volume', {'claims': 43, 'full_standard': 1082, 'observed': 77, 'complement': 53, 'cap': 150}, [199, 58]], ['above full standard', {'claims': 1951, 'full_standard': 1082, 'observed': -79, 'complement': 43, 'cap': 150}, [1000, -79]], ['exactly full standard', {'claims': 1082, 'full_standard': 1082, 'observed': 28, 'complement': 29, 'cap': 150}, [1000, 28]], ['zero claims uses complement', {'claims': 0, 'full_standard': 1082, 'observed': -82, 'complement': -23, 'cap': 150}, [0, -23]], ['capped increase', {'claims': 898, 'full_standard': 1082, 'observed': 400, 'complement': 50, 'cap': 150}, [911, 150]], ['capped decrease', {'claims': 774, 'full_standard': 1082, 'observed': -400, 'complement': -20, 'cap': 150}, [845, -150]], ['negative claims rejected', {'claims': -3, 'full_standard': 1082, 'observed': -107, 'complement': -1, 'cap': 150}, 'invalid'], ['moderate volume', {'claims': 673, 'full_standard': 1082, 'observed': 49, 'complement': -23, 'cap': 150}, [788, 34]]], [['partial credibility', {'claims': 239, 'full_standard': 1082, 'observed': -28, 'complement': -25, 'cap': 150}, [469, -26]], ['small volume', {'claims': 23, 'full_standard': 1082, 'observed': -82, 'complement': 40, 'cap': 150}, [145, 22]], ['above full standard', {'claims': 1972, 'full_standard': 1082, 'observed': 21, 'complement': 2, 'cap': 150}, [1000, 21]], ['exactly full standard', {'claims': 1082, 'full_standard': 1082, 'observed': -116, 'complement': 58, 'cap': 150}, [1000, -116]], ['zero claims uses complement', {'claims': 0, 'full_standard': 1082, 'observed': 137, 'complement': -12, 'cap': 150}, [0, -12]], ['capped increase', {'claims': 802, 'full_standard': 1082, 'observed': 400, 'complement': 50, 'cap': 150}, [860, 150]], ['capped decrease', {'claims': 894, 'full_standard': 1082, 'observed': -400, 'complement': -20, 'cap': 150}, [908, -150]], ['negative claims rejected', {'claims': -3, 'full_standard': 1082, 'observed': -45, 'complement': 36, 'cap': 150}, 'invalid'], ['moderate volume', {'claims': 317, 'full_standard': 1082, 'observed': 154, 'complement': 46, 'cap': 150}, [541, 104]]], [['partial credibility', {'claims': 431, 'full_standard': 1082, 'observed': 31, 'complement': 31, 'cap': 150}, [631, 31]], ['small volume', {'claims': 7, 'full_standard': 1082, 'observed': 142, 'complement': 9, 'cap': 150}, [80, 20]], ['above full standard', {'claims': 1564, 'full_standard': 1082, 'observed': 48, 'complement': 19, 'cap': 150}, [1000, 48]], ['exactly full standard', {'claims': 1082, 'full_standard': 1082, 'observed': -29, 'complement': -12, 'cap': 150}, [1000, -29]], ['zero claims uses complement', {'claims': 0, 'full_standard': 1082, 'observed': 136, 'complement': 56, 'cap': 150}, [0, 56]], ['capped increase', {'claims': 914, 'full_standard': 1082, 'observed': 400, 'complement': 50, 'cap': 150}, [919, 150]], ['capped decrease', {'claims': 737, 'full_standard': 1082, 'observed': -400, 'complement': -20, 'cap': 150}, [825, -150]], ['negative claims rejected', {'claims': -3, 'full_standard': 1082, 'observed': -49, 'complement': 60, 'cap': 150}, 'invalid'], ['moderate volume', {'claims': 343, 'full_standard': 1082, 'observed': -32, 'complement': 32, 'cap': 150}, [563, -4]]], [['partial credibility', {'claims': 220, 'full_standard': 1082, 'observed': 10, 'complement': 36, 'cap': 150}, [450, 24]], ['small volume', {'claims': 46, 'full_standard': 1082, 'observed': 76, 'complement': -15, 'cap': 150}, [206, 4]], ['above full standard', {'claims': 1760, 'full_standard': 1082, 'observed': -79, 'complement': -7, 'cap': 150}, [1000, -79]], ['exactly full standard', {'claims': 1082, 'full_standard': 1082, 'observed': 138, 'complement': -10, 'cap': 150}, [1000, 138]], ['zero claims uses complement', {'claims': 0, 'full_standard': 1082, 'observed': 173, 'complement': 37, 'cap': 150}, [0, 37]], ['capped increase', {'claims': 760, 'full_standard': 1082, 'observed': 400, 'complement': 50, 'cap': 150}, [838, 150]], ['capped decrease', {'claims': 990, 'full_standard': 1082, 'observed': -400, 'complement': -20, 'cap': 150}, [956, -150]], ['negative claims rejected', {'claims': -3, 'full_standard': 1082, 'observed': 78, 'complement': 46, 'cap': 150}, 'invalid'], ['moderate volume', {'claims': 268, 'full_standard': 1082, 'observed': 127, 'complement': 57, 'cap': 150}, [497, 92]]], [['partial credibility', {'claims': 185, 'full_standard': 1082, 'observed': 50, 'complement': -6, 'cap': 150}, [413, 17]], ['small volume', {'claims': 26, 'full_standard': 1082, 'observed': 115, 'complement': 36, 'cap': 150}, [155, 48]], ['above full standard', {'claims': 1435, 'full_standard': 1082, 'observed': 127, 'complement': 35, 'cap': 150}, [1000, 127]], ['exactly full standard', {'claims': 1082, 'full_standard': 1082, 'observed': -88, 'complement': 21, 'cap': 150}, [1000, -88]], ['zero claims uses complement', {'claims': 0, 'full_standard': 1082, 'observed': -119, 'complement': 7, 'cap': 150}, [0, 7]], ['capped increase', {'claims': 843, 'full_standard': 1082, 'observed': 400, 'complement': 50, 'cap': 150}, [882, 150]], ['capped decrease', {'claims': 747, 'full_standard': 1082, 'observed': -400, 'complement': -20, 'cap': 150}, [830, -150]], ['negative claims rejected', {'claims': -3, 'full_standard': 1082, 'observed': -70, 'complement': 10, 'cap': 150}, 'invalid'], ['moderate volume', {'claims': 721, 'full_standard': 1082, 'observed': -26, 'complement': 48, 'cap': 150}, [816, -12]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A book with no claims returns invalid instead of the complement.

Input claims n, full_standard, observed and complement changes (per mille), cap. n<0 or full<=0 -> 'invalid'. Z (per mille) = min(1000, isqrt(n*10^6 // full)). Indication = floor((Z*obs+(1000-Z)*comp)/1000+1/2), then clamped to [-cap, cap]. Return [Z, indication].

split: open-access


prompt:
Losses are under-developed by one link factor.

Input losses, age (months, positive multiple of 12 else 'invalid'), ldfs (age-to-age *1000, first is 12-24), tail *1000, trend (annual per mille), exp_start and pol_start (months). CDF = tail * product of ldfs from index age/12-1. Trend span = (pol_start+12) - (exp_start+6) months; factor = (1+t)^years * (1+t*rem/12). Return floor(losses*CDF*factor+1/2).

split: open-access


prompt:
Ultimate losses omit development beyond the last factor.

Input losses, age (months, positive multiple of 12 else 'invalid'), ldfs (age-to-age *1000, first is 12-24), tail *1000, trend (annual per mille), exp_start and pol_start (months). CDF = tail * product of ldfs from index age/12-1. Trend span = (pol_start+12) - (exp_start+6) months; factor = (1+t)^years * (1+t*rem/12). Return floor(losses*CDF*factor+1/2).

split: open-access


prompt:
Trend is six months short for annual policies.

Input losses, age (months, positive multiple of 12 else 'invalid'), ldfs (age-to-age *1000, first is 12-24), tail *1000, trend (annual per mille), exp_start and pol_start (months). CDF = tail * product of ldfs from index age/12-1. Trend span = (pol_start+12) - (exp_start+6) months; factor = (1+t)^years * (1+t*rem/12). Return floor(losses*CDF*factor+1/2).

split: open-access


prompt:
Trend factors explode when the span is not a whole number of years.

Input losses, age (months, positive multiple of 12 else 'invalid'), ldfs (age-to-age *1000, first is 12-24), tail *1000, trend (annual per mille), exp_start and pol_start (months). CDF = tail * product of ldfs from index age/12-1. Trend span = (pol_start+12) - (exp_start+6) months; factor = (1+t)^years * (1+t*rem/12). Return floor(losses*CDF*factor+1/2).

split: open-access


prompt:
An 18-month evaluation is developed with annual factors.

Input losses, age (months, positive multiple of 12 else 'invalid'), ldfs (age-to-age *1000, first is 12-24), tail *1000, trend (annual per mille), exp_start and pol_start (months). CDF = tail * product of ldfs from index age/12-1. Trend span = (pol_start+12) - (exp_start+6) months; factor = (1+t)^years * (1+t*rem/12). Return floor(losses*CDF*factor+1/2).

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):
    def after(m):
        d=Fraction(m,12)
        if d>=1: return Fraction(0)
        if d<=-1: return Fraction(1)
        if d>=0: return (1-d)
        return 1-(1+d)**2/2
    level=Fraction(1); levels=[level]
    for m,c in x['changes']:
        level*=1+Fraction(c,1000); levels.append(level)
    avg=Fraction(0)
    prev=Fraction(1)
    for i,(m,c) in enumerate(x['changes']):
        a=after(m)
        avg+=levels[i]*(prev-a)
        prev=a
    avg+=levels[-1]*prev
    return math.floor(levels[-1]/avg*1000+Fraction(1,2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['single mid-year change', {'changes': [[3, 100]]}, 1070], ['change in prior year', {'changes': [[-7, 45]]}, 1004], ['two changes straddling', {'changes': [[-8, 45], [2, -50]]}, 969], ['three changes', {'changes': [[-9, 30], [3, 100], [8, -50]]}, 1020], ['change at year start', {'changes': [[0, 45]]}, 1022], ['change long before period', {'changes': [[-14, -50], [3, 100]]}, 1070], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[10, -80]]}, 921]], [['single mid-year change', {'changes': [[5, 60]]}, 1049], ['change in prior year', {'changes': [[-8, 30]]}, 1002], ['two changes straddling', {'changes': [[-6, 80], [6, 60]]}, 1062], ['three changes', {'changes': [[-6, 30], [4, 30], [7, 100]]}, 1120], ['change at year start', {'changes': [[0, 80]]}, 1038], ['change long before period', {'changes': [[-14, 100], [4, -50]]}, 961], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[6, -80]]}, 929]], [['single mid-year change', {'changes': [[8, 60]]}, 1056], ['change in prior year', {'changes': [[-3, -50]]}, 985], ['two changes straddling', {'changes': [[-7, 100], [2, 100]]}, 1071], ['three changes', {'changes': [[-11, -50], [0, -50], [10, 100]]}, 1070], ['change at year start', {'changes': [[0, 100]]}, 1048], ['change long before period', {'changes': [[-14, -50], [4, 30]]}, 1023], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[4, -80]]}, 937]], [['single mid-year change', {'changes': [[4, 80]]}, 1061], ['change in prior year', {'changes': [[-9, 60]]}, 1002], ['two changes straddling', {'changes': [[-4, 80], [8, 100]]}, 1112], ['three changes', {'changes': [[-2, 30], [2, 60], [8, 60]]}, 1108], ['change at year start', {'changes': [[0, 45]]}, 1022], ['change long before period', {'changes': [[-14, 30], [4, 60]]}, 1046], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[2, -80]]}, 946]], [['single mid-year change', {'changes': [[9, -50]]}, 951], ['change in prior year', {'changes': [[-5, -50]]}, 991], ['two changes straddling', {'changes': [[-8, 80], [5, -50]]}, 962], ['three changes', {'changes': [[-3, 80], [5, 30], [7, 60]]}, 1103], ['change at year start', {'changes': [[0, 100]]}, 1048], ['change long before period', {'changes': [[-14, 45], [4, 60]]}, 1046], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[4, -80]]}, 937]]]
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):
    def after(m):
        d=Fraction(m,12)
        if d>=1: return Fraction(0)
        if d<=-1: return Fraction(1)
        if d>=0: return (1-d)**2
        return 1-(1+d)**2/2
    level=Fraction(1); levels=[level]
    for m,c in x['changes']:
        level*=1+Fraction(c,1000); levels.append(level)
    avg=Fraction(0)
    prev=Fraction(1)
    for i,(m,c) in enumerate(x['changes']):
        a=after(m)
        avg+=levels[i]*(prev-a)
        prev=a
    avg+=levels[-1]*prev
    return math.floor(levels[-1]/avg*1000+Fraction(1,2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['single mid-year change', {'changes': [[3, 100]]}, 1070], ['change in prior year', {'changes': [[-7, 45]]}, 1004], ['two changes straddling', {'changes': [[-8, 45], [2, -50]]}, 969], ['three changes', {'changes': [[-9, 30], [3, 100], [8, -50]]}, 1020], ['change at year start', {'changes': [[0, 45]]}, 1022], ['change long before period', {'changes': [[-14, -50], [3, 100]]}, 1070], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[10, -80]]}, 921]], [['single mid-year change', {'changes': [[5, 60]]}, 1049], ['change in prior year', {'changes': [[-8, 30]]}, 1002], ['two changes straddling', {'changes': [[-6, 80], [6, 60]]}, 1062], ['three changes', {'changes': [[-6, 30], [4, 30], [7, 100]]}, 1120], ['change at year start', {'changes': [[0, 80]]}, 1038], ['change long before period', {'changes': [[-14, 100], [4, -50]]}, 961], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[6, -80]]}, 929]], [['single mid-year change', {'changes': [[8, 60]]}, 1056], ['change in prior year', {'changes': [[-3, -50]]}, 985], ['two changes straddling', {'changes': [[-7, 100], [2, 100]]}, 1071], ['three changes', {'changes': [[-11, -50], [0, -50], [10, 100]]}, 1070], ['change at year start', {'changes': [[0, 100]]}, 1048], ['change long before period', {'changes': [[-14, -50], [4, 30]]}, 1023], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[4, -80]]}, 937]], [['single mid-year change', {'changes': [[4, 80]]}, 1061], ['change in prior year', {'changes': [[-9, 60]]}, 1002], ['two changes straddling', {'changes': [[-4, 80], [8, 100]]}, 1112], ['three changes', {'changes': [[-2, 30], [2, 60], [8, 60]]}, 1108], ['change at year start', {'changes': [[0, 45]]}, 1022], ['change long before period', {'changes': [[-14, 30], [4, 60]]}, 1046], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[2, -80]]}, 946]], [['single mid-year change', {'changes': [[9, -50]]}, 951], ['change in prior year', {'changes': [[-5, -50]]}, 991], ['two changes straddling', {'changes': [[-8, 80], [5, -50]]}, 962], ['three changes', {'changes': [[-3, 80], [5, 30], [7, 60]]}, 1103], ['change at year start', {'changes': [[0, 100]]}, 1048], ['change long before period', {'changes': [[-14, 45], [4, 60]]}, 1046], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[4, -80]]}, 937]]]
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:
Changes within the calendar year are credited with too much earned exposure.

Input changes [[month offset from calendar-year start, change per mille]] in order. Annual policies written uniformly; the share of calendar-year earned exposure written after offset d=m/12 is (1-d)^2/2 for 0<=d<1, 1-(1+d)^2/2 for -1<d<0, 0 for d>=1 and 1 for d<=-1. Levels are cumulative products. OLF = current level / earned-weighted average level, returned *1000 rounded half-up.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    def after(m):
        d=Fraction(m,12)
        if d>=1: return Fraction(0)
        if d<=-1: return Fraction(1)
        if d>=0: return (1-d)**2/2
        return (1+d)**2/2
    level=Fraction(1); levels=[level]
    for m,c in x['changes']:
        level*=1+Fraction(c,1000); levels.append(level)
    avg=Fraction(0)
    prev=Fraction(1)
    for i,(m,c) in enumerate(x['changes']):
        a=after(m)
        avg+=levels[i]*(prev-a)
        prev=a
    avg+=levels[-1]*prev
    return math.floor(levels[-1]/avg*1000+Fraction(1,2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['single mid-year change', {'changes': [[3, 100]]}, 1070], ['change in prior year', {'changes': [[-7, 45]]}, 1004], ['two changes straddling', {'changes': [[-8, 45], [2, -50]]}, 969], ['three changes', {'changes': [[-9, 30], [3, 100], [8, -50]]}, 1020], ['change at year start', {'changes': [[0, 45]]}, 1022], ['change long before period', {'changes': [[-14, -50], [3, 100]]}, 1070], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[10, -80]]}, 921]], [['single mid-year change', {'changes': [[5, 60]]}, 1049], ['change in prior year', {'changes': [[-8, 30]]}, 1002], ['two changes straddling', {'changes': [[-6, 80], [6, 60]]}, 1062], ['three changes', {'changes': [[-6, 30], [4, 30], [7, 100]]}, 1120], ['change at year start', {'changes': [[0, 80]]}, 1038], ['change long before period', {'changes': [[-14, 100], [4, -50]]}, 961], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[6, -80]]}, 929]], [['single mid-year change', {'changes': [[8, 60]]}, 1056], ['change in prior year', {'changes': [[-3, -50]]}, 985], ['two changes straddling', {'changes': [[-7, 100], [2, 100]]}, 1071], ['three changes', {'changes': [[-11, -50], [0, -50], [10, 100]]}, 1070], ['change at year start', {'changes': [[0, 100]]}, 1048], ['change long before period', {'changes': [[-14, -50], [4, 30]]}, 1023], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[4, -80]]}, 937]], [['single mid-year change', {'changes': [[4, 80]]}, 1061], ['change in prior year', {'changes': [[-9, 60]]}, 1002], ['two changes straddling', {'changes': [[-4, 80], [8, 100]]}, 1112], ['three changes', {'changes': [[-2, 30], [2, 60], [8, 60]]}, 1108], ['change at year start', {'changes': [[0, 45]]}, 1022], ['change long before period', {'changes': [[-14, 30], [4, 60]]}, 1046], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[2, -80]]}, 946]], [['single mid-year change', {'changes': [[9, -50]]}, 951], ['change in prior year', {'changes': [[-5, -50]]}, 991], ['two changes straddling', {'changes': [[-8, 80], [5, -50]]}, 962], ['three changes', {'changes': [[-3, 80], [5, 30], [7, 60]]}, 1103], ['change at year start', {'changes': [[0, 100]]}, 1048], ['change long before period', {'changes': [[-14, 45], [4, 60]]}, 1046], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[4, -80]]}, 937]]]
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):
    def after(m):
        d=Fraction(m,12)
        if d>=1: return Fraction(0)
        if d<=-1: return Fraction(1)
        if d>=0: return (1-d)**2/2
        return 1-(1+d)/2
    level=Fraction(1); levels=[level]
    for m,c in x['changes']:
        level*=1+Fraction(c,1000); levels.append(level)
    avg=Fraction(0)
    prev=Fraction(1)
    for i,(m,c) in enumerate(x['changes']):
        a=after(m)
        avg+=levels[i]*(prev-a)
        prev=a
    avg+=levels[-1]*prev
    return math.floor(levels[-1]/avg*1000+Fraction(1,2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['single mid-year change', {'changes': [[3, 100]]}, 1070], ['change in prior year', {'changes': [[-7, 45]]}, 1004], ['two changes straddling', {'changes': [[-8, 45], [2, -50]]}, 969], ['three changes', {'changes': [[-9, 30], [3, 100], [8, -50]]}, 1020], ['change at year start', {'changes': [[0, 45]]}, 1022], ['change long before period', {'changes': [[-14, -50], [3, 100]]}, 1070], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[10, -80]]}, 921]], [['single mid-year change', {'changes': [[5, 60]]}, 1049], ['change in prior year', {'changes': [[-8, 30]]}, 1002], ['two changes straddling', {'changes': [[-6, 80], [6, 60]]}, 1062], ['three changes', {'changes': [[-6, 30], [4, 30], [7, 100]]}, 1120], ['change at year start', {'changes': [[0, 80]]}, 1038], ['change long before period', {'changes': [[-14, 100], [4, -50]]}, 961], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[6, -80]]}, 929]], [['single mid-year change', {'changes': [[8, 60]]}, 1056], ['change in prior year', {'changes': [[-3, -50]]}, 985], ['two changes straddling', {'changes': [[-7, 100], [2, 100]]}, 1071], ['three changes', {'changes': [[-11, -50], [0, -50], [10, 100]]}, 1070], ['change at year start', {'changes': [[0, 100]]}, 1048], ['change long before period', {'changes': [[-14, -50], [4, 30]]}, 1023], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[4, -80]]}, 937]], [['single mid-year change', {'changes': [[4, 80]]}, 1061], ['change in prior year', {'changes': [[-9, 60]]}, 1002], ['two changes straddling', {'changes': [[-4, 80], [8, 100]]}, 1112], ['three changes', {'changes': [[-2, 30], [2, 60], [8, 60]]}, 1108], ['change at year start', {'changes': [[0, 45]]}, 1022], ['change long before period', {'changes': [[-14, 30], [4, 60]]}, 1046], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[2, -80]]}, 946]], [['single mid-year change', {'changes': [[9, -50]]}, 951], ['change in prior year', {'changes': [[-5, -50]]}, 991], ['two changes straddling', {'changes': [[-8, 80], [5, -50]]}, 962], ['three changes', {'changes': [[-3, 80], [5, 30], [7, 60]]}, 1103], ['change at year start', {'changes': [[0, 100]]}, 1048], ['change long before period', {'changes': [[-14, 45], [4, 60]]}, 1046], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[4, -80]]}, 937]]]
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:
Changes effective late in the prior year are treated as barely earned.

Input changes [[month offset from calendar-year start, change per mille]] in order. Annual policies written uniformly; the share of calendar-year earned exposure written after offset d=m/12 is (1-d)^2/2 for 0<=d<1, 1-(1+d)^2/2 for -1<d<0, 0 for d>=1 and 1 for d<=-1. Levels are cumulative products. OLF = current level / earned-weighted average level, returned *1000 rounded half-up.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    def after(m):
        d=Fraction(m,12)
        if d>=1: return Fraction(0)
        if d<=-1: return Fraction(1)
        if d>=0: return (1-d)**2/2
        return 1-(1+d)**2/2
    level=Fraction(1); levels=[level]
    for m,c in x['changes']:
        level+=Fraction(c,1000); levels.append(level)
    avg=Fraction(0)
    prev=Fraction(1)
    for i,(m,c) in enumerate(x['changes']):
        a=after(m)
        avg+=levels[i]*(prev-a)
        prev=a
    avg+=levels[-1]*prev
    return math.floor(levels[-1]/avg*1000+Fraction(1,2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['single mid-year change', {'changes': [[3, 100]]}, 1070], ['change in prior year', {'changes': [[-7, 45]]}, 1004], ['two changes straddling', {'changes': [[-8, 45], [2, -50]]}, 969], ['three changes', {'changes': [[-9, 30], [3, 100], [8, -50]]}, 1020], ['change at year start', {'changes': [[0, 45]]}, 1022], ['change long before period', {'changes': [[-14, -50], [3, 100]]}, 1070], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[10, -80]]}, 921]], [['single mid-year change', {'changes': [[5, 60]]}, 1049], ['change in prior year', {'changes': [[-8, 30]]}, 1002], ['two changes straddling', {'changes': [[-6, 80], [6, 60]]}, 1062], ['three changes', {'changes': [[-6, 30], [4, 30], [7, 100]]}, 1120], ['change at year start', {'changes': [[0, 80]]}, 1038], ['change long before period', {'changes': [[-14, 100], [4, -50]]}, 961], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[6, -80]]}, 929]], [['single mid-year change', {'changes': [[8, 60]]}, 1056], ['change in prior year', {'changes': [[-3, -50]]}, 985], ['two changes straddling', {'changes': [[-7, 100], [2, 100]]}, 1071], ['three changes', {'changes': [[-11, -50], [0, -50], [10, 100]]}, 1070], ['change at year start', {'changes': [[0, 100]]}, 1048], ['change long before period', {'changes': [[-14, -50], [4, 30]]}, 1023], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[4, -80]]}, 937]], [['single mid-year change', {'changes': [[4, 80]]}, 1061], ['change in prior year', {'changes': [[-9, 60]]}, 1002], ['two changes straddling', {'changes': [[-4, 80], [8, 100]]}, 1112], ['three changes', {'changes': [[-2, 30], [2, 60], [8, 60]]}, 1108], ['change at year start', {'changes': [[0, 45]]}, 1022], ['change long before period', {'changes': [[-14, 30], [4, 60]]}, 1046], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[2, -80]]}, 946]], [['single mid-year change', {'changes': [[9, -50]]}, 951], ['change in prior year', {'changes': [[-5, -50]]}, 991], ['two changes straddling', {'changes': [[-8, 80], [5, -50]]}, 962], ['three changes', {'changes': [[-3, 80], [5, 30], [7, 60]]}, 1103], ['change at year start', {'changes': [[0, 100]]}, 1048], ['change long before period', {'changes': [[-14, 45], [4, 60]]}, 1046], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[4, -80]]}, 937]]]
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):
    def after(m):
        d=Fraction(m,12)
        if d>=1: return Fraction(0)
        if d<=-1: return Fraction(1)
        if d>=0: return (1-d)**2/2
        return 1-(1+d)**2/2
    level=Fraction(1); levels=[level]
    for m,c in x['changes']:
        level=1+Fraction(c,1000); levels.append(level)
    avg=Fraction(0)
    prev=Fraction(1)
    for i,(m,c) in enumerate(x['changes']):
        a=after(m)
        avg+=levels[i]*(prev-a)
        prev=a
    avg+=levels[-1]*prev
    return math.floor(levels[-1]/avg*1000+Fraction(1,2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['single mid-year change', {'changes': [[3, 100]]}, 1070], ['change in prior year', {'changes': [[-7, 45]]}, 1004], ['two changes straddling', {'changes': [[-8, 45], [2, -50]]}, 969], ['three changes', {'changes': [[-9, 30], [3, 100], [8, -50]]}, 1020], ['change at year start', {'changes': [[0, 45]]}, 1022], ['change long before period', {'changes': [[-14, -50], [3, 100]]}, 1070], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[10, -80]]}, 921]], [['single mid-year change', {'changes': [[5, 60]]}, 1049], ['change in prior year', {'changes': [[-8, 30]]}, 1002], ['two changes straddling', {'changes': [[-6, 80], [6, 60]]}, 1062], ['three changes', {'changes': [[-6, 30], [4, 30], [7, 100]]}, 1120], ['change at year start', {'changes': [[0, 80]]}, 1038], ['change long before period', {'changes': [[-14, 100], [4, -50]]}, 961], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[6, -80]]}, 929]], [['single mid-year change', {'changes': [[8, 60]]}, 1056], ['change in prior year', {'changes': [[-3, -50]]}, 985], ['two changes straddling', {'changes': [[-7, 100], [2, 100]]}, 1071], ['three changes', {'changes': [[-11, -50], [0, -50], [10, 100]]}, 1070], ['change at year start', {'changes': [[0, 100]]}, 1048], ['change long before period', {'changes': [[-14, -50], [4, 30]]}, 1023], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[4, -80]]}, 937]], [['single mid-year change', {'changes': [[4, 80]]}, 1061], ['change in prior year', {'changes': [[-9, 60]]}, 1002], ['two changes straddling', {'changes': [[-4, 80], [8, 100]]}, 1112], ['three changes', {'changes': [[-2, 30], [2, 60], [8, 60]]}, 1108], ['change at year start', {'changes': [[0, 45]]}, 1022], ['change long before period', {'changes': [[-14, 30], [4, 60]]}, 1046], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[2, -80]]}, 946]], [['single mid-year change', {'changes': [[9, -50]]}, 951], ['change in prior year', {'changes': [[-5, -50]]}, 991], ['two changes straddling', {'changes': [[-8, 80], [5, -50]]}, 962], ['three changes', {'changes': [[-3, 80], [5, 30], [7, 60]]}, 1103], ['change at year start', {'changes': [[0, 100]]}, 1048], ['change long before period', {'changes': [[-14, 45], [4, 60]]}, 1046], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[4, -80]]}, 937]]]
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:
Sequences of rate changes produce the wrong current level.

Input changes [[month offset from calendar-year start, change per mille]] in order. Annual policies written uniformly; the share of calendar-year earned exposure written after offset d=m/12 is (1-d)^2/2 for 0<=d<1, 1-(1+d)^2/2 for -1<d<0, 0 for d>=1 and 1 for d<=-1. Levels are cumulative products. OLF = current level / earned-weighted average level, returned *1000 rounded half-up.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    def after(m):
        d=Fraction(m,12)
        if d>=1: return Fraction(0)
        if d<=-1: return Fraction(1)
        if d>=0: return (1-d)**2/2
        return 1-(1+d)**2/2
    level=Fraction(1); levels=[level]
    for m,c in x['changes']:
        level*=1+Fraction(c,1000); levels.append(level)
    avg=Fraction(0)
    prev=Fraction(1)
    for i,(m,c) in enumerate(x['changes']):
        a=after(m)
        avg+=levels[i+1]*(prev-a)
        prev=a
    avg+=levels[-1]*prev
    return math.floor(levels[-1]/avg*1000+Fraction(1,2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['single mid-year change', {'changes': [[3, 100]]}, 1070], ['change in prior year', {'changes': [[-7, 45]]}, 1004], ['two changes straddling', {'changes': [[-8, 45], [2, -50]]}, 969], ['three changes', {'changes': [[-9, 30], [3, 100], [8, -50]]}, 1020], ['change at year start', {'changes': [[0, 45]]}, 1022], ['change long before period', {'changes': [[-14, -50], [3, 100]]}, 1070], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[10, -80]]}, 921]], [['single mid-year change', {'changes': [[5, 60]]}, 1049], ['change in prior year', {'changes': [[-8, 30]]}, 1002], ['two changes straddling', {'changes': [[-6, 80], [6, 60]]}, 1062], ['three changes', {'changes': [[-6, 30], [4, 30], [7, 100]]}, 1120], ['change at year start', {'changes': [[0, 80]]}, 1038], ['change long before period', {'changes': [[-14, 100], [4, -50]]}, 961], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[6, -80]]}, 929]], [['single mid-year change', {'changes': [[8, 60]]}, 1056], ['change in prior year', {'changes': [[-3, -50]]}, 985], ['two changes straddling', {'changes': [[-7, 100], [2, 100]]}, 1071], ['three changes', {'changes': [[-11, -50], [0, -50], [10, 100]]}, 1070], ['change at year start', {'changes': [[0, 100]]}, 1048], ['change long before period', {'changes': [[-14, -50], [4, 30]]}, 1023], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[4, -80]]}, 937]], [['single mid-year change', {'changes': [[4, 80]]}, 1061], ['change in prior year', {'changes': [[-9, 60]]}, 1002], ['two changes straddling', {'changes': [[-4, 80], [8, 100]]}, 1112], ['three changes', {'changes': [[-2, 30], [2, 60], [8, 60]]}, 1108], ['change at year start', {'changes': [[0, 45]]}, 1022], ['change long before period', {'changes': [[-14, 30], [4, 60]]}, 1046], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[2, -80]]}, 946]], [['single mid-year change', {'changes': [[9, -50]]}, 951], ['change in prior year', {'changes': [[-5, -50]]}, 991], ['two changes straddling', {'changes': [[-8, 80], [5, -50]]}, 962], ['three changes', {'changes': [[-3, 80], [5, 30], [7, 60]]}, 1103], ['change at year start', {'changes': [[0, 100]]}, 1048], ['change long before period', {'changes': [[-14, 45], [4, 60]]}, 1046], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[4, -80]]}, 937]]]
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):
    def after(m):
        d=Fraction(m,12)
        if d>=1: return Fraction(0)
        if d<=-1: return Fraction(1)
        if d>=0: return (1-d)**2/2
        return 1-(1+d)**2/2
    level=Fraction(1); levels=[level]
    for m,c in x['changes']:
        level*=1+Fraction(c,1000); levels.append(level)
    avg=Fraction(0)
    prev=Fraction(1)
    for i,(m,c) in enumerate(x['changes']):
        a=after(m)
        avg+=levels[i]*a
        prev=a
    avg+=levels[-1]*prev
    return math.floor(levels[-1]/avg*1000+Fraction(1,2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['single mid-year change', {'changes': [[3, 100]]}, 1070], ['change in prior year', {'changes': [[-7, 45]]}, 1004], ['two changes straddling', {'changes': [[-8, 45], [2, -50]]}, 969], ['three changes', {'changes': [[-9, 30], [3, 100], [8, -50]]}, 1020], ['change at year start', {'changes': [[0, 45]]}, 1022], ['change long before period', {'changes': [[-14, -50], [3, 100]]}, 1070], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[10, -80]]}, 921]], [['single mid-year change', {'changes': [[5, 60]]}, 1049], ['change in prior year', {'changes': [[-8, 30]]}, 1002], ['two changes straddling', {'changes': [[-6, 80], [6, 60]]}, 1062], ['three changes', {'changes': [[-6, 30], [4, 30], [7, 100]]}, 1120], ['change at year start', {'changes': [[0, 80]]}, 1038], ['change long before period', {'changes': [[-14, 100], [4, -50]]}, 961], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[6, -80]]}, 929]], [['single mid-year change', {'changes': [[8, 60]]}, 1056], ['change in prior year', {'changes': [[-3, -50]]}, 985], ['two changes straddling', {'changes': [[-7, 100], [2, 100]]}, 1071], ['three changes', {'changes': [[-11, -50], [0, -50], [10, 100]]}, 1070], ['change at year start', {'changes': [[0, 100]]}, 1048], ['change long before period', {'changes': [[-14, -50], [4, 30]]}, 1023], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[4, -80]]}, 937]], [['single mid-year change', {'changes': [[4, 80]]}, 1061], ['change in prior year', {'changes': [[-9, 60]]}, 1002], ['two changes straddling', {'changes': [[-4, 80], [8, 100]]}, 1112], ['three changes', {'changes': [[-2, 30], [2, 60], [8, 60]]}, 1108], ['change at year start', {'changes': [[0, 45]]}, 1022], ['change long before period', {'changes': [[-14, 30], [4, 60]]}, 1046], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[2, -80]]}, 946]], [['single mid-year change', {'changes': [[9, -50]]}, 951], ['change in prior year', {'changes': [[-5, -50]]}, 991], ['two changes straddling', {'changes': [[-8, 80], [5, -50]]}, 962], ['three changes', {'changes': [[-3, 80], [5, 30], [7, 60]]}, 1103], ['change at year start', {'changes': [[0, 100]]}, 1048], ['change long before period', {'changes': [[-14, 45], [4, 60]]}, 1046], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[4, -80]]}, 937]]]
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:
Average earned level is overstated so the on-level factor is too small.

Input changes [[month offset from calendar-year start, change per mille]] in order. Annual policies written uniformly; the share of calendar-year earned exposure written after offset d=m/12 is (1-d)^2/2 for 0<=d<1, 1-(1+d)^2/2 for -1<d<0, 0 for d>=1 and 1 for d<=-1. Levels are cumulative products. OLF = current level / earned-weighted average level, returned *1000 rounded half-up.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    def after(m):
        d=Fraction(m,12)
        if d>=1: return Fraction(0)
        if d<=-1: return Fraction(1)
        if d>=0: return (1-d)**2/2
        return 1-(1+d)**2/2
    level=Fraction(1); levels=[level]
    for m,c in x['changes']:
        level*=1+Fraction(c,1000); levels.append(level)
    avg=Fraction(0)
    prev=Fraction(1)
    for i,(m,c) in enumerate(x['changes']):
        a=after(m)
        avg+=levels[i]*(prev-a)
        prev=a
    avg+=levels[-1]*prev
    return math.floor(avg/levels[-1]*1000+Fraction(1,2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['single mid-year change', {'changes': [[3, 100]]}, 1070], ['change in prior year', {'changes': [[-7, 45]]}, 1004], ['two changes straddling', {'changes': [[-8, 45], [2, -50]]}, 969], ['three changes', {'changes': [[-9, 30], [3, 100], [8, -50]]}, 1020], ['change at year start', {'changes': [[0, 45]]}, 1022], ['change long before period', {'changes': [[-14, -50], [3, 100]]}, 1070], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[10, -80]]}, 921]], [['single mid-year change', {'changes': [[5, 60]]}, 1049], ['change in prior year', {'changes': [[-8, 30]]}, 1002], ['two changes straddling', {'changes': [[-6, 80], [6, 60]]}, 1062], ['three changes', {'changes': [[-6, 30], [4, 30], [7, 100]]}, 1120], ['change at year start', {'changes': [[0, 80]]}, 1038], ['change long before period', {'changes': [[-14, 100], [4, -50]]}, 961], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[6, -80]]}, 929]], [['single mid-year change', {'changes': [[8, 60]]}, 1056], ['change in prior year', {'changes': [[-3, -50]]}, 985], ['two changes straddling', {'changes': [[-7, 100], [2, 100]]}, 1071], ['three changes', {'changes': [[-11, -50], [0, -50], [10, 100]]}, 1070], ['change at year start', {'changes': [[0, 100]]}, 1048], ['change long before period', {'changes': [[-14, -50], [4, 30]]}, 1023], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[4, -80]]}, 937]], [['single mid-year change', {'changes': [[4, 80]]}, 1061], ['change in prior year', {'changes': [[-9, 60]]}, 1002], ['two changes straddling', {'changes': [[-4, 80], [8, 100]]}, 1112], ['three changes', {'changes': [[-2, 30], [2, 60], [8, 60]]}, 1108], ['change at year start', {'changes': [[0, 45]]}, 1022], ['change long before period', {'changes': [[-14, 30], [4, 60]]}, 1046], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[2, -80]]}, 946]], [['single mid-year change', {'changes': [[9, -50]]}, 951], ['change in prior year', {'changes': [[-5, -50]]}, 991], ['two changes straddling', {'changes': [[-8, 80], [5, -50]]}, 962], ['three changes', {'changes': [[-3, 80], [5, 30], [7, 60]]}, 1103], ['change at year start', {'changes': [[0, 100]]}, 1048], ['change long before period', {'changes': [[-14, 45], [4, 60]]}, 1046], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[4, -80]]}, 937]]]
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):
    def after(m):
        d=Fraction(m,12)
        if d>=1: return Fraction(0)
        if d<=-1: return Fraction(1)
        if d>=0: return (1-d)**2/2
        return 1-(1+d)**2/2
    level=Fraction(1); levels=[level]
    for m,c in x['changes']:
        level*=1+Fraction(c,1000); levels.append(level)
    avg=Fraction(0)
    prev=Fraction(1)
    for i,(m,c) in enumerate(x['changes']):
        a=after(m)
        avg+=levels[i]*(prev-a)
        prev=a
    avg+=levels[-1]*prev
    return math.floor((levels[-1]-avg+1)*1000+Fraction(1,2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['single mid-year change', {'changes': [[3, 100]]}, 1070], ['change in prior year', {'changes': [[-7, 45]]}, 1004], ['two changes straddling', {'changes': [[-8, 45], [2, -50]]}, 969], ['three changes', {'changes': [[-9, 30], [3, 100], [8, -50]]}, 1020], ['change at year start', {'changes': [[0, 45]]}, 1022], ['change long before period', {'changes': [[-14, -50], [3, 100]]}, 1070], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[10, -80]]}, 921]], [['single mid-year change', {'changes': [[5, 60]]}, 1049], ['change in prior year', {'changes': [[-8, 30]]}, 1002], ['two changes straddling', {'changes': [[-6, 80], [6, 60]]}, 1062], ['three changes', {'changes': [[-6, 30], [4, 30], [7, 100]]}, 1120], ['change at year start', {'changes': [[0, 80]]}, 1038], ['change long before period', {'changes': [[-14, 100], [4, -50]]}, 961], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[6, -80]]}, 929]], [['single mid-year change', {'changes': [[8, 60]]}, 1056], ['change in prior year', {'changes': [[-3, -50]]}, 985], ['two changes straddling', {'changes': [[-7, 100], [2, 100]]}, 1071], ['three changes', {'changes': [[-11, -50], [0, -50], [10, 100]]}, 1070], ['change at year start', {'changes': [[0, 100]]}, 1048], ['change long before period', {'changes': [[-14, -50], [4, 30]]}, 1023], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[4, -80]]}, 937]], [['single mid-year change', {'changes': [[4, 80]]}, 1061], ['change in prior year', {'changes': [[-9, 60]]}, 1002], ['two changes straddling', {'changes': [[-4, 80], [8, 100]]}, 1112], ['three changes', {'changes': [[-2, 30], [2, 60], [8, 60]]}, 1108], ['change at year start', {'changes': [[0, 45]]}, 1022], ['change long before period', {'changes': [[-14, 30], [4, 60]]}, 1046], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[2, -80]]}, 946]], [['single mid-year change', {'changes': [[9, -50]]}, 951], ['change in prior year', {'changes': [[-5, -50]]}, 991], ['two changes straddling', {'changes': [[-8, 80], [5, -50]]}, 962], ['three changes', {'changes': [[-3, 80], [5, 30], [7, 60]]}, 1103], ['change at year start', {'changes': [[0, 100]]}, 1048], ['change long before period', {'changes': [[-14, 45], [4, 60]]}, 1046], ['no changes', {'changes': []}, 1000], ['rate decrease', {'changes': [[4, -80]]}, 937]]]
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:
Historical premium is deflated when rates have risen.

Input changes [[month offset from calendar-year start, change per mille]] in order. Annual policies written uniformly; the share of calendar-year earned exposure written after offset d=m/12 is (1-d)^2/2 for 0<=d<1, 1-(1+d)^2/2 for -1<d<0, 0 for d>=1 and 1 for d<=-1. Levels are cumulative products. OLF = current level / earned-weighted average level, returned *1000 rounded half-up.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    per={}
    for cat,v in x['items']:
        if cat not in x['caps']: return 'unknown category '+cat
        per[cat]=per.get(cat,0)+v
    tot=0
    for cat,v in sorted(per.items()):
        c=x['caps'][cat]
        tot+=v
    tot=max(-x['max_credit'],min(x['max_debit'],tot))
    return [tot, math.floor(x['premium']*Fraction(1000+tot,1000)+Fraction(1,2))]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['split credits in one category', {'premium': 589010, 'items': [['management', -50], ['management', -45], ['premises', 20]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [-60, 553669]], ['category cap binds on debit', {'premium': 872720, 'items': [['equipment', 30], ['equipment', 26], ['employees', -10]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [30, 898902]], ['overall credit cap binds', {'premium': 194515, 'items': [['premises', -50], ['employees', -60], ['management', -80], ['equipment', -40], ['premises', -5]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 200, 'max_debit': 150}, [-200, 155612]], ['overall debit cap binds', {'premium': 730552, 'items': [['premises', 50], ['employees', 60], ['management', 60]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 120}, [120, 818218]], ['unknown credit category', {'premium': 820316, 'items': [['weather', -20], ['premises', 10]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, 'unknown category weather'], ['unknown debit category', {'premium': 179351, 'items': [['weather', 20]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, 'unknown category weather'], ['mixed small items', {'premium': 275874, 'items': [['premises', -7], ['employees', -2], ['management', -17]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [-26, 268701]], ['no items', {'premium': 289888, 'items': [], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [0, 289888]], ['credit within caps', {'premium': 802858, 'items': [['management', -31], ['employees', -7]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [-38, 772349]]], [['split credits in one category', {'premium': 366527, 'items': [['management', -50], ['management', -45], ['premises', 20]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [-60, 344535]], ['category cap binds on debit', {'premium': 688814, 'items': [['equipment', 30], ['equipment', 27], ['employees', -10]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [30, 709478]], ['overall credit cap binds', {'premium': 391467, 'items': [['premises', -50], ['employees', -60], ['management', -80], ['equipment', -40], ['premises', -5]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 200, 'max_debit': 150}, [-200, 313174]], ['overall debit cap binds', {'premium': 605730, 'items': [['premises', 50], ['employees', 60], ['management', 60]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 120}, [120, 678418]], ['unknown credit category', {'premium': 554487, 'items': [['weather', -20], ['premises', 10]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, 'unknown category weather'], ['unknown debit category', {'premium': 377083, 'items': [['weather', 20]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, 'unknown category weather'], ['mixed small items', {'premium': 645018, 'items': [['premises', 12], ['employees', -6], ['management', 11]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [17, 655983]], ['no items', {'premium': 197679, 'items': [], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [0, 197679]], ['credit within caps', {'premium': 746783, 'items': [['management', -30], ['employees', -7]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [-37, 719152]]], [['split credits in one category', {'premium': 149318, 'items': [['management', -50], ['management', -45], ['premises', 20]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [-60, 140359]], ['category cap binds on debit', {'premium': 776580, 'items': [['equipment', 30], ['equipment', 28], ['employees', -10]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [30, 799877]], ['overall credit cap binds', {'premium': 205836, 'items': [['premises', -50], ['employees', -60], ['management', -80], ['equipment', -40], ['premises', -5]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 200, 'max_debit': 150}, [-200, 164669]], ['overall debit cap binds', {'premium': 685528, 'items': [['premises', 50], ['employees', 60], ['management', 60]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 120}, [120, 767791]], ['unknown credit category', {'premium': 672687, 'items': [['weather', -20], ['premises', 10]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, 'unknown category weather'], ['unknown debit category', {'premium': 231208, 'items': [['weather', 20]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, 'unknown category weather'], ['mixed small items', {'premium': 466715, 'items': [['premises', -26], ['employees', 7], ['management', 25]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [6, 469515]], ['no items', {'premium': 280573, 'items': [], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [0, 280573]], ['credit within caps', {'premium': 847372, 'items': [['management', -15], ['employees', -5]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [-20, 830425]]], [['split credits in one category', {'premium': 259668, 'items': [['management', -50], ['management', -45], ['premises', 20]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [-60, 244088]], ['category cap binds on debit', {'premium': 544757, 'items': [['equipment', 30], ['equipment', 29], ['employees', -10]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [30, 561100]], ['overall credit cap binds', {'premium': 105294, 'items': [['premises', -50], ['employees', -60], ['management', -80], ['equipment', -40], ['premises', -5]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 200, 'max_debit': 150}, [-200, 84235]], ['overall debit cap binds', {'premium': 228463, 'items': [['premises', 50], ['employees', 60], ['management', 60]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 120}, [120, 255879]], ['unknown credit category', {'premium': 336609, 'items': [['weather', -20], ['premises', 10]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, 'unknown category weather'], ['unknown debit category', {'premium': 528562, 'items': [['weather', 20]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, 'unknown category weather'], ['mixed small items', {'premium': 111054, 'items': [['premises', -5], ['employees', -3], ['management', -26]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [-34, 107278]], ['no items', {'premium': 432026, 'items': [], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [0, 432026]], ['credit within caps', {'premium': 578818, 'items': [['management', -23], ['employees', -10]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [-33, 559717]]], [['split credits in one category', {'premium': 838683, 'items': [['management', -50], ['management', -45], ['premises', 20]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [-60, 788362]], ['category cap binds on debit', {'premium': 190937, 'items': [['equipment', 30], ['equipment', 30], ['employees', -10]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [30, 196665]], ['overall credit cap binds', {'premium': 878341, 'items': [['premises', -50], ['employees', -60], ['management', -80], ['equipment', -40], ['premises', -5]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 200, 'max_debit': 150}, [-200, 702673]], ['overall debit cap binds', {'premium': 467322, 'items': [['premises', 50], ['employees', 60], ['management', 60]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 120}, [120, 523401]], ['unknown credit category', {'premium': 352112, 'items': [['weather', -20], ['premises', 10]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, 'unknown category weather'], ['unknown debit category', {'premium': 280978, 'items': [['weather', 20]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, 'unknown category weather'], ['mixed small items', {'premium': 150014, 'items': [['premises', 12], ['employees', -23], ['management', 12]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [1, 150164]], ['no items', {'premium': 788931, 'items': [], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [0, 788931]], ['credit within caps', {'premium': 263345, 'items': [['management', -19], ['employees', -17]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [-36, 253865]]]]
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):
    per={}
    for cat,v in x['items']:
        if cat not in x['caps']: return 'unknown category '+cat
        per[cat]=per.get(cat,0)+v
    tot=0
    for cat,v in sorted(per.items()):
        c=x['caps'][cat]
        tot+=min(c,v)
    tot=max(-x['max_credit'],min(x['max_debit'],tot))
    return [tot, math.floor(x['premium']*Fraction(1000+tot,1000)+Fraction(1,2))]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['split credits in one category', {'premium': 589010, 'items': [['management', -50], ['management', -45], ['premises', 20]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [-60, 553669]], ['category cap binds on debit', {'premium': 872720, 'items': [['equipment', 30], ['equipment', 26], ['employees', -10]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [30, 898902]], ['overall credit cap binds', {'premium': 194515, 'items': [['premises', -50], ['employees', -60], ['management', -80], ['equipment', -40], ['premises', -5]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 200, 'max_debit': 150}, [-200, 155612]], ['overall debit cap binds', {'premium': 730552, 'items': [['premises', 50], ['employees', 60], ['management', 60]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 120}, [120, 818218]], ['unknown credit category', {'premium': 820316, 'items': [['weather', -20], ['premises', 10]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, 'unknown category weather'], ['unknown debit category', {'premium': 179351, 'items': [['weather', 20]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, 'unknown category weather'], ['mixed small items', {'premium': 275874, 'items': [['premises', -7], ['employees', -2], ['management', -17]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [-26, 268701]], ['no items', {'premium': 289888, 'items': [], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [0, 289888]], ['credit within caps', {'premium': 802858, 'items': [['management', -31], ['employees', -7]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [-38, 772349]]], [['split credits in one category', {'premium': 366527, 'items': [['management', -50], ['management', -45], ['premises', 20]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [-60, 344535]], ['category cap binds on debit', {'premium': 688814, 'items': [['equipment', 30], ['equipment', 27], ['employees', -10]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [30, 709478]], ['overall credit cap binds', {'premium': 391467, 'items': [['premises', -50], ['employees', -60], ['management', -80], ['equipment', -40], ['premises', -5]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 200, 'max_debit': 150}, [-200, 313174]], ['overall debit cap binds', {'premium': 605730, 'items': [['premises', 50], ['employees', 60], ['management', 60]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 120}, [120, 678418]], ['unknown credit category', {'premium': 554487, 'items': [['weather', -20], ['premises', 10]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, 'unknown category weather'], ['unknown debit category', {'premium': 377083, 'items': [['weather', 20]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, 'unknown category weather'], ['mixed small items', {'premium': 645018, 'items': [['premises', 12], ['employees', -6], ['management', 11]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [17, 655983]], ['no items', {'premium': 197679, 'items': [], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [0, 197679]], ['credit within caps', {'premium': 746783, 'items': [['management', -30], ['employees', -7]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [-37, 719152]]], [['split credits in one category', {'premium': 149318, 'items': [['management', -50], ['management', -45], ['premises', 20]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [-60, 140359]], ['category cap binds on debit', {'premium': 776580, 'items': [['equipment', 30], ['equipment', 28], ['employees', -10]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [30, 799877]], ['overall credit cap binds', {'premium': 205836, 'items': [['premises', -50], ['employees', -60], ['management', -80], ['equipment', -40], ['premises', -5]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 200, 'max_debit': 150}, [-200, 164669]], ['overall debit cap binds', {'premium': 685528, 'items': [['premises', 50], ['employees', 60], ['management', 60]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 120}, [120, 767791]], ['unknown credit category', {'premium': 672687, 'items': [['weather', -20], ['premises', 10]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, 'unknown category weather'], ['unknown debit category', {'premium': 231208, 'items': [['weather', 20]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, 'unknown category weather'], ['mixed small items', {'premium': 466715, 'items': [['premises', -26], ['employees', 7], ['management', 25]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [6, 469515]], ['no items', {'premium': 280573, 'items': [], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [0, 280573]], ['credit within caps', {'premium': 847372, 'items': [['management', -15], ['employees', -5]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [-20, 830425]]], [['split credits in one category', {'premium': 259668, 'items': [['management', -50], ['management', -45], ['premises', 20]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [-60, 244088]], ['category cap binds on debit', {'premium': 544757, 'items': [['equipment', 30], ['equipment', 29], ['employees', -10]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [30, 561100]], ['overall credit cap binds', {'premium': 105294, 'items': [['premises', -50], ['employees', -60], ['management', -80], ['equipment', -40], ['premises', -5]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 200, 'max_debit': 150}, [-200, 84235]], ['overall debit cap binds', {'premium': 228463, 'items': [['premises', 50], ['employees', 60], ['management', 60]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 120}, [120, 255879]], ['unknown credit category', {'premium': 336609, 'items': [['weather', -20], ['premises', 10]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, 'unknown category weather'], ['unknown debit category', {'premium': 528562, 'items': [['weather', 20]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, 'unknown category weather'], ['mixed small items', {'premium': 111054, 'items': [['premises', -5], ['employees', -3], ['management', -26]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [-34, 107278]], ['no items', {'premium': 432026, 'items': [], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [0, 432026]], ['credit within caps', {'premium': 578818, 'items': [['management', -23], ['employees', -10]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [-33, 559717]]], [['split credits in one category', {'premium': 838683, 'items': [['management', -50], ['management', -45], ['premises', 20]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [-60, 788362]], ['category cap binds on debit', {'premium': 190937, 'items': [['equipment', 30], ['equipment', 30], ['employees', -10]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [30, 196665]], ['overall credit cap binds', {'premium': 878341, 'items': [['premises', -50], ['employees', -60], ['management', -80], ['equipment', -40], ['premises', -5]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 200, 'max_debit': 150}, [-200, 702673]], ['overall debit cap binds', {'premium': 467322, 'items': [['premises', 50], ['employees', 60], ['management', 60]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 120}, [120, 523401]], ['unknown credit category', {'premium': 352112, 'items': [['weather', -20], ['premises', 10]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, 'unknown category weather'], ['unknown debit category', {'premium': 280978, 'items': [['weather', 20]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, 'unknown category weather'], ['mixed small items', {'premium': 150014, 'items': [['premises', 12], ['employees', -23], ['management', 12]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [1, 150164]], ['no items', {'premium': 788931, 'items': [], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [0, 788931]], ['credit within caps', {'premium': 263345, 'items': [['management', -19], ['employees', -17]], 'caps': {'premises': 50, 'employees': 60, 'management': 80, 'equipment': 40}, 'max_credit': 250, 'max_debit': 150}, [-36, 253865]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Stacked items in one category exceed that category's maximum.

Input premium, items [[category, per mille; negative is a credit]], caps {category: max abs per mille}, max_credit, max_debit. Unknown category -> 'unknown category <name>'. Items are summed per category, each category clamped to its cap, the total clamped to [-max_credit, max_debit], and premium*(1000+total)/1000 rounded half-up. Return [total, premium].

split: open-access