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

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

prompt:
Every mid-term return is one day of premium too large.

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

split: open-access


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

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

prompt:
An insured who cancels before inception is charged a short-rate penalty.

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

split: open-access


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

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

prompt:
Insured cancellations refund more than the premium minus the minimum earned amount.

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

split: open-access


prompt:
Excess layers are priced as if they ended at the layer width.

Input basic (premium at basic limit), ilf table [[limit, factor*1000]] ascending, attachment, layer_limit. ILF(0)=0 and ILF is linear between tabulated points (including from 0 to the basic limit); limits above the table are unrated. Layer premium = floor(basic*(ILF(att+lim)-ILF(att))/1000+1/2). layer_limit<=0 or attachment<0 -> 'invalid'.

split: open-access


prompt:
Ground-up and sub-basic layers come back unrated.

Input basic (premium at basic limit), ilf table [[limit, factor*1000]] ascending, attachment, layer_limit. ILF(0)=0 and ILF is linear between tabulated points (including from 0 to the basic limit); limits above the table are unrated. Layer premium = floor(basic*(ILF(att+lim)-ILF(att))/1000+1/2). layer_limit<=0 or attachment<0 -> 'invalid'.

split: open-access


prompt:
A layer that exhausts exactly at the maximum limit is unrated.

Input basic (premium at basic limit), ilf table [[limit, factor*1000]] ascending, attachment, layer_limit. ILF(0)=0 and ILF is linear between tabulated points (including from 0 to the basic limit); limits above the table are unrated. Layer premium = floor(basic*(ILF(att+lim)-ILF(att))/1000+1/2). layer_limit<=0 or attachment<0 -> 'invalid'.

split: open-access


prompt:
Excess layers are charged the full ground-up premium.

Input basic (premium at basic limit), ilf table [[limit, factor*1000]] ascending, attachment, layer_limit. ILF(0)=0 and ILF is linear between tabulated points (including from 0 to the basic limit); limits above the table are unrated. Layer premium = floor(basic*(ILF(att+lim)-ILF(att))/1000+1/2). layer_limit<=0 or attachment<0 -> 'invalid'.

split: open-access


prompt:
A zero-limit layer returns a premium of 0 instead of invalid.

Input basic (premium at basic limit), ilf table [[limit, factor*1000]] ascending, attachment, layer_limit. ILF(0)=0 and ILF is linear between tabulated points (including from 0 to the basic limit); limits above the table are unrated. Layer premium = floor(basic*(ILF(att+lim)-ILF(att))/1000+1/2). layer_limit<=0 or attachment<0 -> 'invalid'.

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, n*1000//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)

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)

prompt:
Partially credible books get far less weight on their own experience.

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=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)

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(100, 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:
Large books overshoot their own experience and give the complement negative weight.

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)
    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)

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']+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:
Thin books are pulled toward no change instead of toward 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