broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    pc=x['pc']; con=x['construction']
    if x['station_miles']>5: pc='10'
    elif x['hydrant_feet']>1000 and pc not in ('8B','9','10'): pc='9'
    key=x['pc']+'-'+con
    if key in x['matrix']: f=Fraction(x['matrix'][key],1000)
    elif con=='masonry' and pc+'-frame' in x['matrix']: f=Fraction(x['matrix'][pc+'-frame'],1000)*Fraction(95,100)
    else: return 'unrated '+key
    return math.floor(x['base']*f+Fraction(1,2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['protected frame', {'base': 120317, 'pc': '2', 'construction': 'frame', 'station_miles': 2, 'hydrant_feet': 300, 'matrix': {'1-frame': 801, '1-masonry': 760, '2-frame': 861, '2-masonry': 815, '3-frame': 921, '3-masonry': 870, '4-frame': 981, '4-masonry': 925, '5-frame': 1041, '5-masonry': 980, '6-frame': 1101, '6-masonry': 1035, '7-frame': 1161, '7-masonry': 1090, '8-frame': 1221, '8-masonry': 1145, '8B-frame': 1281, '8B-masonry': 1200, '9-frame': 1341, '10-frame': 1401}}, 103593], ['station exactly five miles', {'base': 247853, 'pc': '4', 'construction': 'masonry', 'station_miles': 5, 'hydrant_feet': 400, 'matrix': {'1-frame': 801, '1-masonry': 760, '2-frame': 861, '2-masonry': 815, '3-frame': 921, '3-masonry': 870, '4-frame': 981, '4-masonry': 925, '5-frame': 1041, '5-masonry': 980, '6-frame': 1101, '6-masonry': 1035, '7-frame': 1161, '7-masonry': 1090, '8-frame': 1221, '8-masonry': 1145, '8B-frame': 1281, '8B-masonry': 1200, '9-frame': 1341, '10-frame': 1401}}, 229264], ['beyond five miles', {'base': 235309, 'pc': '3', 'construction': 'frame', 'station_miles': 5.5, 'hydrant_feet': 200, 'matrix': {'1-frame': 801, '1-masonry': 760, '2-frame': 861, '2-masonry': 815, '3-frame': 921, '3-masonry': 870, '4-frame': 981, '4-masonry': 925, '5-frame': 1041, '5-masonry': 980, '6-frame': 1101, '6-masonry': 1035, '7-frame': 1161, '7-masonry': 1090, '8-frame': 1221, '8-masonry': 1145, '8B-frame': 1281, '8B-masonry': 1200, '9-frame': 1341, '10-frame': 1401}}, 329668], ['distant hydrant downgrades', {'base': 90594, 'pc': '5', 'construction': 'frame', 'station_miles': 3, 'hydrant_feet': 1030, 'matrix': {'1-frame': 801, '1-masonry': 760, '2-frame': 861, '2-masonry': 815, '3-frame': 921, '3-masonry': 870, '4-frame': 981, '4-masonry': 925, '5-frame': 1041, '5-masonry': 980, '6-frame': 1101, '6-masonry': 1035, '7-frame': 1161, '7-masonry': 1090, '8-frame': 1221, '8-masonry': 1145, '8B-frame': 1281, '8B-masonry': 1200, '9-frame': 1341, '10-frame': 1401}}, 121487], ['hydrant exactly 1000 feet', {'base': 178365, 'pc': '6', 'construction': 'frame', 'station_miles': 3, 'hydrant_feet': 1000, 'matrix': {'1-frame': 801, '1-masonry': 760, '2-frame': 861, '2-masonry': 815, '3-frame': 921, '3-masonry': 870, '4-frame': 981, '4-masonry': 925, '5-frame': 1041, '5-masonry': 980, '6-frame': 1101, '6-masonry': 1035, '7-frame': 1161, '7-masonry': 1090, '8-frame': 1221, '8-masonry': 1145, '8B-frame': 1281, '8B-masonry': 1200, '9-frame': 1341, '10-frame': 1401}}, 196380], ['split class keeps 8B', {'base': 197429, 'pc': '8B', 'construction': 'frame', 'station_miles': 4, 'hydrant_feet': 1500, 'matrix': {'1-frame': 801, '1-masonry': 760, '2-frame': 861, '2-masonry': 815, '3-frame': 921, '3-masonry': 870, '4-frame': 981, '4-masonry': 925, '5-frame': 1041, '5-masonry': 980, '6-frame': 1101, '6-masonry': 1035, '7-frame': 1161, '7-masonry': 1090, '8-frame': 1221, '8-masonry': 1145, '8B-frame': 1281, '8B-masonry': 1200, '9-frame': 1341, '10-frame': 1401}}, 252907], ['masonry downgraded uses frame fallback', {'base': 201148, 'pc': '7', 'construction': 'masonry', 'station_miles': 2, 'hydrant_feet': 1400, 'matrix': {'1-frame': 801, '1-masonry': 760, '2-frame': 861, '2-masonry': 815, '3-frame': 921, '3-masonry': 870, '4-frame': 981, '4-masonry': 925, '5-frame': 1041, '5-masonry': 980, '6-frame': 1101, '6-masonry': 1035, '7-frame': 1161, '7-masonry': 1090, '8-frame': 1221, '8-masonry': 1145, '8B-frame': 1281, '8B-masonry': 1200, '9-frame': 1341, '10-frame': 1401}}, 256252], ['masonry class 10 fallback', {'base': 217127, 'pc': '3', 'construction': 'masonry', 'station_miles': 7, 'hydrant_feet': 100, 'matrix': {'1-frame': 801, '1-masonry': 760, '2-frame': 861, '2-masonry': 815, '3-frame': 921, '3-masonry': 870, '4-frame': 981, '4-masonry': 925, '5-frame': 1041, '5-masonry': 980, '6-frame': 1101, '6-masonry': 1035, '7-frame': 1161, '7-masonry': 1090, '8-frame': 1221, '8-masonry': 1145, '8B-frame': 1281, '8B-masonry': 1200, '9-frame': 1341, '10-frame': 1401}}, 288985], ['fire resistive unrated', {'base': 212313, 'pc': '9', 'construction': 'fire-resistive', 'station_miles': 1, 'hydrant_feet': 100, 'matrix': {'1-frame': 801, '1-masonry': 760, '2-frame': 861, '2-masonry': 815, '3-frame': 921, '3-masonry': 870, '4-frame': 981, '4-masonry': 925, '5-frame': 1041, '5-masonry': 980, '6-frame': 1101, '6-masonry': 1035, '7-frame': 1161, '7-masonry': 1090, '8-frame': 1221, '8-masonry': 1145, '8B-frame': 1281, '8B-masonry': 1200, '9-frame': 1341, '10-frame': 1401}}, 'unrated 9-fire-resistive'], ['masonry protected', {'base': 186678, 'pc': '8', 'construction': 'masonry', 'station_miles': 1, 'hydrant_feet': 200, 'matrix': {'1-frame': 801, '1-masonry': 760, '2-frame': 861, '2-masonry': 815, '3-frame': 921, '3-masonry': 870, '4-frame': 981, '4-masonry': 925, '5-frame': 1041, '5-masonry': 980, '6-frame': 1101, '6-masonry': 1035, '7-frame': 1161, '7-masonry': 1090, '8-frame': 1221, '8-masonry': 1145, '8B-frame': 1281, '8B-masonry': 1200, '9-frame': 1341, '10-frame': 1401}}, 213746]], [['protected frame', {'base': 184759, 'pc': '2', 'construction': 'frame', 'station_miles': 2, 'hydrant_feet': 300, 'matrix': {'1-frame': 802, '1-masonry': 760, '2-frame': 862, '2-masonry': 815, '3-frame': 922, '3-masonry': 870, '4-frame': 982, '4-masonry': 925, '5-frame': 1042, '5-masonry': 980, '6-frame': 1102, '6-masonry': 1035, '7-frame': 1162, '7-masonry': 1090, '8-frame': 1222, '8-masonry': 1145, '8B-frame': 1282, '8B-masonry': 1200, '9-frame': 1342, '10-frame': 1402}}, 159262], ['station exactly five miles', {'base': 141915, 'pc': '4', 'construction': 'masonry', 'station_miles': 5, 'hydrant_feet': 400, 'matrix': {'1-frame': 802, '1-masonry': 760, '2-frame': 862, '2-masonry': 815, '3-frame': 922, '3-masonry': 870, '4-frame': 982, '4-masonry': 925, '5-frame': 1042, '5-masonry': 980, '6-frame': 1102, '6-masonry': 1035, '7-frame': 1162, '7-masonry': 1090, '8-frame': 1222, '8-masonry': 1145, '8B-frame': 1282, '8B-masonry': 1200, '9-frame': 1342, '10-frame': 1402}}, 131271], ['beyond five miles', {'base': 198782, 'pc': '3', 'construction': 'frame', 'station_miles': 5.5, 'hydrant_feet': 200, 'matrix': {'1-frame': 802, '1-masonry': 760, '2-frame': 862, '2-masonry': 815, '3-frame': 922, '3-masonry': 870, '4-frame': 982, '4-masonry': 925, '5-frame': 1042, '5-masonry': 980, '6-frame': 1102, '6-masonry': 1035, '7-frame': 1162, '7-masonry': 1090, '8-frame': 1222, '8-masonry': 1145, '8B-frame': 1282, '8B-masonry': 1200, '9-frame': 1342, '10-frame': 1402}}, 278692], ['distant hydrant downgrades', {'base': 97374, 'pc': '5', 'construction': 'frame', 'station_miles': 3, 'hydrant_feet': 1030, 'matrix': {'1-frame': 802, '1-masonry': 760, '2-frame': 862, '2-masonry': 815, '3-frame': 922, '3-masonry': 870, '4-frame': 982, '4-masonry': 925, '5-frame': 1042, '5-masonry': 980, '6-frame': 1102, '6-masonry': 1035, '7-frame': 1162, '7-masonry': 1090, '8-frame': 1222, '8-masonry': 1145, '8B-frame': 1282, '8B-masonry': 1200, '9-frame': 1342, '10-frame': 1402}}, 130676], ['hydrant exactly 1000 feet', {'base': 119429, 'pc': '6', 'construction': 'frame', 'station_miles': 3, 'hydrant_feet': 1000, 'matrix': {'1-frame': 802, '1-masonry': 760, '2-frame': 862, '2-masonry': 815, '3-frame': 922, '3-masonry': 870, '4-frame': 982, '4-masonry': 925, '5-frame': 1042, '5-masonry': 980, '6-frame': 1102, '6-masonry': 1035, '7-frame': 1162, '7-masonry': 1090, '8-frame': 1222, '8-masonry': 1145, '8B-frame': 1282, '8B-masonry': 1200, '9-frame': 1342, '10-frame': 1402}}, 131611], ['split class keeps 8B', {'base': 152686, 'pc': '8B', 'construction': 'frame', 'station_miles': 4, 'hydrant_feet': 1500, 'matrix': {'1-frame': 802, '1-masonry': 760, '2-frame': 862, '2-masonry': 815, '3-frame': 922, '3-masonry': 870, '4-frame': 982, '4-masonry': 925, '5-frame': 1042, '5-masonry': 980, '6-frame': 1102, '6-masonry': 1035, '7-frame': 1162, '7-masonry': 1090, '8-frame': 1222, '8-masonry': 1145, '8B-frame': 1282, '8B-masonry': 1200, '9-frame': 1342, '10-frame': 1402}}, 195743], ['masonry downgraded uses frame fallback', {'base': 105761, 'pc': '7', 'construction': 'masonry', 'station_miles': 2, 'hydrant_feet': 1400, 'matrix': {'1-frame': 802, '1-masonry': 760, '2-frame': 862, '2-masonry': 815, '3-frame': 922, '3-masonry': 870, '4-frame': 982, '4-masonry': 925, '5-frame': 1042, '5-masonry': 980, '6-frame': 1102, '6-masonry': 1035, '7-frame': 1162, '7-masonry': 1090, '8-frame': 1222, '8-masonry': 1145, '8B-frame': 1282, '8B-masonry': 1200, '9-frame': 1342, '10-frame': 1402}}, 134835], ['masonry class 10 fallback', {'base': 112632, 'pc': '3', 'construction': 'masonry', 'station_miles': 7, 'hydrant_feet': 100, 'matrix': {'1-frame': 802, '1-masonry': 760, '2-frame': 862, '2-masonry': 815, '3-frame': 922, '3-masonry': 870, '4-frame': 982, '4-masonry': 925, '5-frame': 1042, '5-masonry': 980, '6-frame': 1102, '6-masonry': 1035, '7-frame': 1162, '7-masonry': 1090, '8-frame': 1222, '8-masonry': 1145, '8B-frame': 1282, '8B-masonry': 1200, '9-frame': 1342, '10-frame': 1402}}, 150015], ['fire resistive unrated', {'base': 169686, 'pc': '9', 'construction': 'fire-resistive', 'station_miles': 1, 'hydrant_feet': 100, 'matrix': {'1-frame': 802, '1-masonry': 760, '2-frame': 862, '2-masonry': 815, '3-frame': 922, '3-masonry': 870, '4-frame': 982, '4-masonry': 925, '5-frame': 1042, '5-masonry': 980, '6-frame': 1102, '6-masonry': 1035, '7-frame': 1162, '7-masonry': 1090, '8-frame': 1222, '8-masonry': 1145, '8B-frame': 1282, '8B-masonry': 1200, '9-frame': 1342, '10-frame': 1402}}, 'unrated 9-fire-resistive'], ['masonry protected', {'base': 202626, 'pc': '8', 'construction': 'masonry', 'station_miles': 1, 'hydrant_feet': 200, 'matrix': {'1-frame': 802, '1-masonry': 760, '2-frame': 862, '2-masonry': 815, '3-frame': 922, '3-masonry': 870, '4-frame': 982, '4-masonry': 925, '5-frame': 1042, '5-masonry': 980, '6-frame': 1102, '6-masonry': 1035, '7-frame': 1162, '7-masonry': 1090, '8-frame': 1222, '8-masonry': 1145, '8B-frame': 1282, '8B-masonry': 1200, '9-frame': 1342, '10-frame': 1402}}, 232007]], [['protected frame', {'base': 204115, 'pc': '4', 'construction': 'frame', 'station_miles': 2, 'hydrant_feet': 300, 'matrix': {'1-frame': 803, '1-masonry': 760, '2-frame': 863, '2-masonry': 815, '3-frame': 923, '3-masonry': 870, '4-frame': 983, '4-masonry': 925, '5-frame': 1043, '5-masonry': 980, '6-frame': 1103, '6-masonry': 1035, '7-frame': 1163, '7-masonry': 1090, '8-frame': 1223, '8-masonry': 1145, '8B-frame': 1283, '8B-masonry': 1200, '9-frame': 1343, '10-frame': 1403}}, 200645], ['station exactly five miles', {'base': 156901, 'pc': '4', 'construction': 'frame', 'station_miles': 5, 'hydrant_feet': 400, 'matrix': {'1-frame': 803, '1-masonry': 760, '2-frame': 863, '2-masonry': 815, '3-frame': 923, '3-masonry': 870, '4-frame': 983, '4-masonry': 925, '5-frame': 1043, '5-masonry': 980, '6-frame': 1103, '6-masonry': 1035, '7-frame': 1163, '7-masonry': 1090, '8-frame': 1223, '8-masonry': 1145, '8B-frame': 1283, '8B-masonry': 1200, '9-frame': 1343, '10-frame': 1403}}, 154234], ['beyond five miles', {'base': 115311, 'pc': '3', 'construction': 'frame', 'station_miles': 5.5, 'hydrant_feet': 200, 'matrix': {'1-frame': 803, '1-masonry': 760, '2-frame': 863, '2-masonry': 815, '3-frame': 923, '3-masonry': 870, '4-frame': 983, '4-masonry': 925, '5-frame': 1043, '5-masonry': 980, '6-frame': 1103, '6-masonry': 1035, '7-frame': 1163, '7-masonry': 1090, '8-frame': 1223, '8-masonry': 1145, '8B-frame': 1283, '8B-masonry': 1200, '9-frame': 1343, '10-frame': 1403}}, 161781], ['distant hydrant downgrades', {'base': 150626, 'pc': '5', 'construction': 'frame', 'station_miles': 3, 'hydrant_feet': 1030, 'matrix': {'1-frame': 803, '1-masonry': 760, '2-frame': 863, '2-masonry': 815, '3-frame': 923, '3-masonry': 870, '4-frame': 983, '4-masonry': 925, '5-frame': 1043, '5-masonry': 980, '6-frame': 1103, '6-masonry': 1035, '7-frame': 1163, '7-masonry': 1090, '8-frame': 1223, '8-masonry': 1145, '8B-frame': 1283, '8B-masonry': 1200, '9-frame': 1343, '10-frame': 1403}}, 202291], ['hydrant exactly 1000 feet', {'base': 122970, 'pc': '6', 'construction': 'frame', 'station_miles': 3, 'hydrant_feet': 1000, 'matrix': {'1-frame': 803, '1-masonry': 760, '2-frame': 863, '2-masonry': 815, '3-frame': 923, '3-masonry': 870, '4-frame': 983, '4-masonry': 925, '5-frame': 1043, '5-masonry': 980, '6-frame': 1103, '6-masonry': 1035, '7-frame': 1163, '7-masonry': 1090, '8-frame': 1223, '8-masonry': 1145, '8B-frame': 1283, '8B-masonry': 1200, '9-frame': 1343, '10-frame': 1403}}, 135636], ['split class keeps 8B', {'base': 163526, 'pc': '8B', 'construction': 'frame', 'station_miles': 4, 'hydrant_feet': 1500, 'matrix': {'1-frame': 803, '1-masonry': 760, '2-frame': 863, '2-masonry': 815, '3-frame': 923, '3-masonry': 870, '4-frame': 983, '4-masonry': 925, '5-frame': 1043, '5-masonry': 980, '6-frame': 1103, '6-masonry': 1035, '7-frame': 1163, '7-masonry': 1090, '8-frame': 1223, '8-masonry': 1145, '8B-frame': 1283, '8B-masonry': 1200, '9-frame': 1343, '10-frame': 1403}}, 209804], ['masonry downgraded uses frame fallback', {'base': 154344, 'pc': '7', 'construction': 'masonry', 'station_miles': 2, 'hydrant_feet': 1400, 'matrix': {'1-frame': 803, '1-masonry': 760, '2-frame': 863, '2-masonry': 815, '3-frame': 923, '3-masonry': 870, '4-frame': 983, '4-masonry': 925, '5-frame': 1043, '5-masonry': 980, '6-frame': 1103, '6-masonry': 1035, '7-frame': 1163, '7-masonry': 1090, '8-frame': 1223, '8-masonry': 1145, '8B-frame': 1283, '8B-masonry': 1200, '9-frame': 1343, '10-frame': 1403}}, 196920], ['masonry class 10 fallback', {'base': 127756, 'pc': '3', 'construction': 'masonry', 'station_miles': 7, 'hydrant_feet': 100, 'matrix': {'1-frame': 803, '1-masonry': 760, '2-frame': 863, '2-masonry': 815, '3-frame': 923, '3-masonry': 870, '4-frame': 983, '4-masonry': 925, '5-frame': 1043, '5-masonry': 980, '6-frame': 1103, '6-masonry': 1035, '7-frame': 1163, '7-masonry': 1090, '8-frame': 1223, '8-masonry': 1145, '8B-frame': 1283, '8B-masonry': 1200, '9-frame': 1343, '10-frame': 1403}}, 170280], ['fire resistive unrated', {'base': 229613, 'pc': '9', 'construction': 'fire-resistive', 'station_miles': 1, 'hydrant_feet': 100, 'matrix': {'1-frame': 803, '1-masonry': 760, '2-frame': 863, '2-masonry': 815, '3-frame': 923, '3-masonry': 870, '4-frame': 983, '4-masonry': 925, '5-frame': 1043, '5-masonry': 980, '6-frame': 1103, '6-masonry': 1035, '7-frame': 1163, '7-masonry': 1090, '8-frame': 1223, '8-masonry': 1145, '8B-frame': 1283, '8B-masonry': 1200, '9-frame': 1343, '10-frame': 1403}}, 'unrated 9-fire-resistive'], ['masonry protected', {'base': 92691, 'pc': '8', 'construction': 'masonry', 'station_miles': 1, 'hydrant_feet': 200, 'matrix': {'1-frame': 803, '1-masonry': 760, '2-frame': 863, '2-masonry': 815, '3-frame': 923, '3-masonry': 870, '4-frame': 983, '4-masonry': 925, '5-frame': 1043, '5-masonry': 980, '6-frame': 1103, '6-masonry': 1035, '7-frame': 1163, '7-masonry': 1090, '8-frame': 1223, '8-masonry': 1145, '8B-frame': 1283, '8B-masonry': 1200, '9-frame': 1343, '10-frame': 1403}}, 106131]], [['protected frame', {'base': 247005, 'pc': '2', 'construction': 'frame', 'station_miles': 2, 'hydrant_feet': 300, 'matrix': {'1-frame': 804, '1-masonry': 760, '2-frame': 864, '2-masonry': 815, '3-frame': 924, '3-masonry': 870, '4-frame': 984, '4-masonry': 925, '5-frame': 1044, '5-masonry': 980, '6-frame': 1104, '6-masonry': 1035, '7-frame': 1164, '7-masonry': 1090, '8-frame': 1224, '8-masonry': 1145, '8B-frame': 1284, '8B-masonry': 1200, '9-frame': 1344, '10-frame': 1404}}, 213412], ['station exactly five miles', {'base': 224534, 'pc': '4', 'construction': 'masonry', 'station_miles': 5, 'hydrant_feet': 400, 'matrix': {'1-frame': 804, '1-masonry': 760, '2-frame': 864, '2-masonry': 815, '3-frame': 924, '3-masonry': 870, '4-frame': 984, '4-masonry': 925, '5-frame': 1044, '5-masonry': 980, '6-frame': 1104, '6-masonry': 1035, '7-frame': 1164, '7-masonry': 1090, '8-frame': 1224, '8-masonry': 1145, '8B-frame': 1284, '8B-masonry': 1200, '9-frame': 1344, '10-frame': 1404}}, 207694], ['beyond five miles', {'base': 241571, 'pc': '3', 'construction': 'frame', 'station_miles': 5.5, 'hydrant_feet': 200, 'matrix': {'1-frame': 804, '1-masonry': 760, '2-frame': 864, '2-masonry': 815, '3-frame': 924, '3-masonry': 870, '4-frame': 984, '4-masonry': 925, '5-frame': 1044, '5-masonry': 980, '6-frame': 1104, '6-masonry': 1035, '7-frame': 1164, '7-masonry': 1090, '8-frame': 1224, '8-masonry': 1145, '8B-frame': 1284, '8B-masonry': 1200, '9-frame': 1344, '10-frame': 1404}}, 339166], ['distant hydrant downgrades', {'base': 161859, 'pc': '5', 'construction': 'frame', 'station_miles': 3, 'hydrant_feet': 1030, 'matrix': {'1-frame': 804, '1-masonry': 760, '2-frame': 864, '2-masonry': 815, '3-frame': 924, '3-masonry': 870, '4-frame': 984, '4-masonry': 925, '5-frame': 1044, '5-masonry': 980, '6-frame': 1104, '6-masonry': 1035, '7-frame': 1164, '7-masonry': 1090, '8-frame': 1224, '8-masonry': 1145, '8B-frame': 1284, '8B-masonry': 1200, '9-frame': 1344, '10-frame': 1404}}, 217538], ['hydrant exactly 1000 feet', {'base': 142348, 'pc': '6', 'construction': 'frame', 'station_miles': 3, 'hydrant_feet': 1000, 'matrix': {'1-frame': 804, '1-masonry': 760, '2-frame': 864, '2-masonry': 815, '3-frame': 924, '3-masonry': 870, '4-frame': 984, '4-masonry': 925, '5-frame': 1044, '5-masonry': 980, '6-frame': 1104, '6-masonry': 1035, '7-frame': 1164, '7-masonry': 1090, '8-frame': 1224, '8-masonry': 1145, '8B-frame': 1284, '8B-masonry': 1200, '9-frame': 1344, '10-frame': 1404}}, 157152], ['split class keeps 8B', {'base': 76654, 'pc': '8B', 'construction': 'frame', 'station_miles': 4, 'hydrant_feet': 1500, 'matrix': {'1-frame': 804, '1-masonry': 760, '2-frame': 864, '2-masonry': 815, '3-frame': 924, '3-masonry': 870, '4-frame': 984, '4-masonry': 925, '5-frame': 1044, '5-masonry': 980, '6-frame': 1104, '6-masonry': 1035, '7-frame': 1164, '7-masonry': 1090, '8-frame': 1224, '8-masonry': 1145, '8B-frame': 1284, '8B-masonry': 1200, '9-frame': 1344, '10-frame': 1404}}, 98424], ['masonry downgraded uses frame fallback', {'base': 150835, 'pc': '7', 'construction': 'masonry', 'station_miles': 2, 'hydrant_feet': 1400, 'matrix': {'1-frame': 804, '1-masonry': 760, '2-frame': 864, '2-masonry': 815, '3-frame': 924, '3-masonry': 870, '4-frame': 984, '4-masonry': 925, '5-frame': 1044, '5-masonry': 980, '6-frame': 1104, '6-masonry': 1035, '7-frame': 1164, '7-masonry': 1090, '8-frame': 1224, '8-masonry': 1145, '8B-frame': 1284, '8B-masonry': 1200, '9-frame': 1344, '10-frame': 1404}}, 192586], ['masonry class 10 fallback', {'base': 175432, 'pc': '3', 'construction': 'masonry', 'station_miles': 7, 'hydrant_feet': 100, 'matrix': {'1-frame': 804, '1-masonry': 760, '2-frame': 864, '2-masonry': 815, '3-frame': 924, '3-masonry': 870, '4-frame': 984, '4-masonry': 925, '5-frame': 1044, '5-masonry': 980, '6-frame': 1104, '6-masonry': 1035, '7-frame': 1164, '7-masonry': 1090, '8-frame': 1224, '8-masonry': 1145, '8B-frame': 1284, '8B-masonry': 1200, '9-frame': 1344, '10-frame': 1404}}, 233991], ['fire resistive unrated', {'base': 103540, 'pc': '9', 'construction': 'fire-resistive', 'station_miles': 1, 'hydrant_feet': 100, 'matrix': {'1-frame': 804, '1-masonry': 760, '2-frame': 864, '2-masonry': 815, '3-frame': 924, '3-masonry': 870, '4-frame': 984, '4-masonry': 925, '5-frame': 1044, '5-masonry': 980, '6-frame': 1104, '6-masonry': 1035, '7-frame': 1164, '7-masonry': 1090, '8-frame': 1224, '8-masonry': 1145, '8B-frame': 1284, '8B-masonry': 1200, '9-frame': 1344, '10-frame': 1404}}, 'unrated 9-fire-resistive'], ['masonry protected', {'base': 83396, 'pc': '8', 'construction': 'masonry', 'station_miles': 1, 'hydrant_feet': 200, 'matrix': {'1-frame': 804, '1-masonry': 760, '2-frame': 864, '2-masonry': 815, '3-frame': 924, '3-masonry': 870, '4-frame': 984, '4-masonry': 925, '5-frame': 1044, '5-masonry': 980, '6-frame': 1104, '6-masonry': 1035, '7-frame': 1164, '7-masonry': 1090, '8-frame': 1224, '8-masonry': 1145, '8B-frame': 1284, '8B-masonry': 1200, '9-frame': 1344, '10-frame': 1404}}, 95488]], [['protected frame', {'base': 182973, 'pc': '2', 'construction': 'frame', 'station_miles': 2, 'hydrant_feet': 300, 'matrix': {'1-frame': 805, '1-masonry': 760, '2-frame': 865, '2-masonry': 815, '3-frame': 925, '3-masonry': 870, '4-frame': 985, '4-masonry': 925, '5-frame': 1045, '5-masonry': 980, '6-frame': 1105, '6-masonry': 1035, '7-frame': 1165, '7-masonry': 1090, '8-frame': 1225, '8-masonry': 1145, '8B-frame': 1285, '8B-masonry': 1200, '9-frame': 1345, '10-frame': 1405}}, 158272], ['station exactly five miles', {'base': 226119, 'pc': '4', 'construction': 'frame', 'station_miles': 5, 'hydrant_feet': 400, 'matrix': {'1-frame': 805, '1-masonry': 760, '2-frame': 865, '2-masonry': 815, '3-frame': 925, '3-masonry': 870, '4-frame': 985, '4-masonry': 925, '5-frame': 1045, '5-masonry': 980, '6-frame': 1105, '6-masonry': 1035, '7-frame': 1165, '7-masonry': 1090, '8-frame': 1225, '8-masonry': 1145, '8B-frame': 1285, '8B-masonry': 1200, '9-frame': 1345, '10-frame': 1405}}, 222727], ['beyond five miles', {'base': 98376, 'pc': '3', 'construction': 'frame', 'station_miles': 5.5, 'hydrant_feet': 200, 'matrix': {'1-frame': 805, '1-masonry': 760, '2-frame': 865, '2-masonry': 815, '3-frame': 925, '3-masonry': 870, '4-frame': 985, '4-masonry': 925, '5-frame': 1045, '5-masonry': 980, '6-frame': 1105, '6-masonry': 1035, '7-frame': 1165, '7-masonry': 1090, '8-frame': 1225, '8-masonry': 1145, '8B-frame': 1285, '8B-masonry': 1200, '9-frame': 1345, '10-frame': 1405}}, 138218], ['distant hydrant downgrades', {'base': 168912, 'pc': '5', 'construction': 'frame', 'station_miles': 3, 'hydrant_feet': 1030, 'matrix': {'1-frame': 805, '1-masonry': 760, '2-frame': 865, '2-masonry': 815, '3-frame': 925, '3-masonry': 870, '4-frame': 985, '4-masonry': 925, '5-frame': 1045, '5-masonry': 980, '6-frame': 1105, '6-masonry': 1035, '7-frame': 1165, '7-masonry': 1090, '8-frame': 1225, '8-masonry': 1145, '8B-frame': 1285, '8B-masonry': 1200, '9-frame': 1345, '10-frame': 1405}}, 227187], ['hydrant exactly 1000 feet', {'base': 213720, 'pc': '6', 'construction': 'frame', 'station_miles': 3, 'hydrant_feet': 1000, 'matrix': {'1-frame': 805, '1-masonry': 760, '2-frame': 865, '2-masonry': 815, '3-frame': 925, '3-masonry': 870, '4-frame': 985, '4-masonry': 925, '5-frame': 1045, '5-masonry': 980, '6-frame': 1105, '6-masonry': 1035, '7-frame': 1165, '7-masonry': 1090, '8-frame': 1225, '8-masonry': 1145, '8B-frame': 1285, '8B-masonry': 1200, '9-frame': 1345, '10-frame': 1405}}, 236161], ['split class keeps 8B', {'base': 61162, 'pc': '8B', 'construction': 'frame', 'station_miles': 4, 'hydrant_feet': 1500, 'matrix': {'1-frame': 805, '1-masonry': 760, '2-frame': 865, '2-masonry': 815, '3-frame': 925, '3-masonry': 870, '4-frame': 985, '4-masonry': 925, '5-frame': 1045, '5-masonry': 980, '6-frame': 1105, '6-masonry': 1035, '7-frame': 1165, '7-masonry': 1090, '8-frame': 1225, '8-masonry': 1145, '8B-frame': 1285, '8B-masonry': 1200, '9-frame': 1345, '10-frame': 1405}}, 78593], ['masonry downgraded uses frame fallback', {'base': 109402, 'pc': '7', 'construction': 'masonry', 'station_miles': 2, 'hydrant_feet': 1400, 'matrix': {'1-frame': 805, '1-masonry': 760, '2-frame': 865, '2-masonry': 815, '3-frame': 925, '3-masonry': 870, '4-frame': 985, '4-masonry': 925, '5-frame': 1045, '5-masonry': 980, '6-frame': 1105, '6-masonry': 1035, '7-frame': 1165, '7-masonry': 1090, '8-frame': 1225, '8-masonry': 1145, '8B-frame': 1285, '8B-masonry': 1200, '9-frame': 1345, '10-frame': 1405}}, 139788], ['masonry class 10 fallback', {'base': 131356, 'pc': '3', 'construction': 'masonry', 'station_miles': 7, 'hydrant_feet': 100, 'matrix': {'1-frame': 805, '1-masonry': 760, '2-frame': 865, '2-masonry': 815, '3-frame': 925, '3-masonry': 870, '4-frame': 985, '4-masonry': 925, '5-frame': 1045, '5-masonry': 980, '6-frame': 1105, '6-masonry': 1035, '7-frame': 1165, '7-masonry': 1090, '8-frame': 1225, '8-masonry': 1145, '8B-frame': 1285, '8B-masonry': 1200, '9-frame': 1345, '10-frame': 1405}}, 175327], ['fire resistive unrated', {'base': 230152, 'pc': '9', 'construction': 'fire-resistive', 'station_miles': 1, 'hydrant_feet': 100, 'matrix': {'1-frame': 805, '1-masonry': 760, '2-frame': 865, '2-masonry': 815, '3-frame': 925, '3-masonry': 870, '4-frame': 985, '4-masonry': 925, '5-frame': 1045, '5-masonry': 980, '6-frame': 1105, '6-masonry': 1035, '7-frame': 1165, '7-masonry': 1090, '8-frame': 1225, '8-masonry': 1145, '8B-frame': 1285, '8B-masonry': 1200, '9-frame': 1345, '10-frame': 1405}}, 'unrated 9-fire-resistive'], ['masonry protected', {'base': 90689, 'pc': '8', 'construction': 'masonry', 'station_miles': 1, 'hydrant_feet': 200, 'matrix': {'1-frame': 805, '1-masonry': 760, '2-frame': 865, '2-masonry': 815, '3-frame': 925, '3-masonry': 870, '4-frame': 985, '4-masonry': 925, '5-frame': 1045, '5-masonry': 980, '6-frame': 1105, '6-masonry': 1035, '7-frame': 1165, '7-masonry': 1090, '8-frame': 1225, '8-masonry': 1145, '8B-frame': 1285, '8B-masonry': 1200, '9-frame': 1345, '10-frame': 1405}}, 103839]]]
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):
    pc=x['pc']; con=x['construction']
    if x['station_miles']>5: pc='10'
    elif x['hydrant_feet']>1000 and pc not in ('8B','9','10'): pc='9'
    key=(pc if x['station_miles']>5 else x['pc'])+'-'+con
    if key in x['matrix']: f=Fraction(x['matrix'][key],1000)
    elif con=='masonry' and pc+'-frame' in x['matrix']: f=Fraction(x['matrix'][pc+'-frame'],1000)*Fraction(95,100)
    else: return 'unrated '+key
    return math.floor(x['base']*f+Fraction(1,2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['protected frame', {'base': 120317, 'pc': '2', 'construction': 'frame', 'station_miles': 2, 'hydrant_feet': 300, 'matrix': {'1-frame': 801, '1-masonry': 760, '2-frame': 861, '2-masonry': 815, '3-frame': 921, '3-masonry': 870, '4-frame': 981, '4-masonry': 925, '5-frame': 1041, '5-masonry': 980, '6-frame': 1101, '6-masonry': 1035, '7-frame': 1161, '7-masonry': 1090, '8-frame': 1221, '8-masonry': 1145, '8B-frame': 1281, '8B-masonry': 1200, '9-frame': 1341, '10-frame': 1401}}, 103593], ['station exactly five miles', {'base': 247853, 'pc': '4', 'construction': 'masonry', 'station_miles': 5, 'hydrant_feet': 400, 'matrix': {'1-frame': 801, '1-masonry': 760, '2-frame': 861, '2-masonry': 815, '3-frame': 921, '3-masonry': 870, '4-frame': 981, '4-masonry': 925, '5-frame': 1041, '5-masonry': 980, '6-frame': 1101, '6-masonry': 1035, '7-frame': 1161, '7-masonry': 1090, '8-frame': 1221, '8-masonry': 1145, '8B-frame': 1281, '8B-masonry': 1200, '9-frame': 1341, '10-frame': 1401}}, 229264], ['beyond five miles', {'base': 235309, 'pc': '3', 'construction': 'frame', 'station_miles': 5.5, 'hydrant_feet': 200, 'matrix': {'1-frame': 801, '1-masonry': 760, '2-frame': 861, '2-masonry': 815, '3-frame': 921, '3-masonry': 870, '4-frame': 981, '4-masonry': 925, '5-frame': 1041, '5-masonry': 980, '6-frame': 1101, '6-masonry': 1035, '7-frame': 1161, '7-masonry': 1090, '8-frame': 1221, '8-masonry': 1145, '8B-frame': 1281, '8B-masonry': 1200, '9-frame': 1341, '10-frame': 1401}}, 329668], ['distant hydrant downgrades', {'base': 90594, 'pc': '5', 'construction': 'frame', 'station_miles': 3, 'hydrant_feet': 1030, 'matrix': {'1-frame': 801, '1-masonry': 760, '2-frame': 861, '2-masonry': 815, '3-frame': 921, '3-masonry': 870, '4-frame': 981, '4-masonry': 925, '5-frame': 1041, '5-masonry': 980, '6-frame': 1101, '6-masonry': 1035, '7-frame': 1161, '7-masonry': 1090, '8-frame': 1221, '8-masonry': 1145, '8B-frame': 1281, '8B-masonry': 1200, '9-frame': 1341, '10-frame': 1401}}, 121487], ['hydrant exactly 1000 feet', {'base': 178365, 'pc': '6', 'construction': 'frame', 'station_miles': 3, 'hydrant_feet': 1000, 'matrix': {'1-frame': 801, '1-masonry': 760, '2-frame': 861, '2-masonry': 815, '3-frame': 921, '3-masonry': 870, '4-frame': 981, '4-masonry': 925, '5-frame': 1041, '5-masonry': 980, '6-frame': 1101, '6-masonry': 1035, '7-frame': 1161, '7-masonry': 1090, '8-frame': 1221, '8-masonry': 1145, '8B-frame': 1281, '8B-masonry': 1200, '9-frame': 1341, '10-frame': 1401}}, 196380], ['split class keeps 8B', {'base': 197429, 'pc': '8B', 'construction': 'frame', 'station_miles': 4, 'hydrant_feet': 1500, 'matrix': {'1-frame': 801, '1-masonry': 760, '2-frame': 861, '2-masonry': 815, '3-frame': 921, '3-masonry': 870, '4-frame': 981, '4-masonry': 925, '5-frame': 1041, '5-masonry': 980, '6-frame': 1101, '6-masonry': 1035, '7-frame': 1161, '7-masonry': 1090, '8-frame': 1221, '8-masonry': 1145, '8B-frame': 1281, '8B-masonry': 1200, '9-frame': 1341, '10-frame': 1401}}, 252907], ['masonry downgraded uses frame fallback', {'base': 201148, 'pc': '7', 'construction': 'masonry', 'station_miles': 2, 'hydrant_feet': 1400, 'matrix': {'1-frame': 801, '1-masonry': 760, '2-frame': 861, '2-masonry': 815, '3-frame': 921, '3-masonry': 870, '4-frame': 981, '4-masonry': 925, '5-frame': 1041, '5-masonry': 980, '6-frame': 1101, '6-masonry': 1035, '7-frame': 1161, '7-masonry': 1090, '8-frame': 1221, '8-masonry': 1145, '8B-frame': 1281, '8B-masonry': 1200, '9-frame': 1341, '10-frame': 1401}}, 256252], ['masonry class 10 fallback', {'base': 217127, 'pc': '3', 'construction': 'masonry', 'station_miles': 7, 'hydrant_feet': 100, 'matrix': {'1-frame': 801, '1-masonry': 760, '2-frame': 861, '2-masonry': 815, '3-frame': 921, '3-masonry': 870, '4-frame': 981, '4-masonry': 925, '5-frame': 1041, '5-masonry': 980, '6-frame': 1101, '6-masonry': 1035, '7-frame': 1161, '7-masonry': 1090, '8-frame': 1221, '8-masonry': 1145, '8B-frame': 1281, '8B-masonry': 1200, '9-frame': 1341, '10-frame': 1401}}, 288985], ['fire resistive unrated', {'base': 212313, 'pc': '9', 'construction': 'fire-resistive', 'station_miles': 1, 'hydrant_feet': 100, 'matrix': {'1-frame': 801, '1-masonry': 760, '2-frame': 861, '2-masonry': 815, '3-frame': 921, '3-masonry': 870, '4-frame': 981, '4-masonry': 925, '5-frame': 1041, '5-masonry': 980, '6-frame': 1101, '6-masonry': 1035, '7-frame': 1161, '7-masonry': 1090, '8-frame': 1221, '8-masonry': 1145, '8B-frame': 1281, '8B-masonry': 1200, '9-frame': 1341, '10-frame': 1401}}, 'unrated 9-fire-resistive'], ['masonry protected', {'base': 186678, 'pc': '8', 'construction': 'masonry', 'station_miles': 1, 'hydrant_feet': 200, 'matrix': {'1-frame': 801, '1-masonry': 760, '2-frame': 861, '2-masonry': 815, '3-frame': 921, '3-masonry': 870, '4-frame': 981, '4-masonry': 925, '5-frame': 1041, '5-masonry': 980, '6-frame': 1101, '6-masonry': 1035, '7-frame': 1161, '7-masonry': 1090, '8-frame': 1221, '8-masonry': 1145, '8B-frame': 1281, '8B-masonry': 1200, '9-frame': 1341, '10-frame': 1401}}, 213746]], [['protected frame', {'base': 184759, 'pc': '2', 'construction': 'frame', 'station_miles': 2, 'hydrant_feet': 300, 'matrix': {'1-frame': 802, '1-masonry': 760, '2-frame': 862, '2-masonry': 815, '3-frame': 922, '3-masonry': 870, '4-frame': 982, '4-masonry': 925, '5-frame': 1042, '5-masonry': 980, '6-frame': 1102, '6-masonry': 1035, '7-frame': 1162, '7-masonry': 1090, '8-frame': 1222, '8-masonry': 1145, '8B-frame': 1282, '8B-masonry': 1200, '9-frame': 1342, '10-frame': 1402}}, 159262], ['station exactly five miles', {'base': 141915, 'pc': '4', 'construction': 'masonry', 'station_miles': 5, 'hydrant_feet': 400, 'matrix': {'1-frame': 802, '1-masonry': 760, '2-frame': 862, '2-masonry': 815, '3-frame': 922, '3-masonry': 870, '4-frame': 982, '4-masonry': 925, '5-frame': 1042, '5-masonry': 980, '6-frame': 1102, '6-masonry': 1035, '7-frame': 1162, '7-masonry': 1090, '8-frame': 1222, '8-masonry': 1145, '8B-frame': 1282, '8B-masonry': 1200, '9-frame': 1342, '10-frame': 1402}}, 131271], ['beyond five miles', {'base': 198782, 'pc': '3', 'construction': 'frame', 'station_miles': 5.5, 'hydrant_feet': 200, 'matrix': {'1-frame': 802, '1-masonry': 760, '2-frame': 862, '2-masonry': 815, '3-frame': 922, '3-masonry': 870, '4-frame': 982, '4-masonry': 925, '5-frame': 1042, '5-masonry': 980, '6-frame': 1102, '6-masonry': 1035, '7-frame': 1162, '7-masonry': 1090, '8-frame': 1222, '8-masonry': 1145, '8B-frame': 1282, '8B-masonry': 1200, '9-frame': 1342, '10-frame': 1402}}, 278692], ['distant hydrant downgrades', {'base': 97374, 'pc': '5', 'construction': 'frame', 'station_miles': 3, 'hydrant_feet': 1030, 'matrix': {'1-frame': 802, '1-masonry': 760, '2-frame': 862, '2-masonry': 815, '3-frame': 922, '3-masonry': 870, '4-frame': 982, '4-masonry': 925, '5-frame': 1042, '5-masonry': 980, '6-frame': 1102, '6-masonry': 1035, '7-frame': 1162, '7-masonry': 1090, '8-frame': 1222, '8-masonry': 1145, '8B-frame': 1282, '8B-masonry': 1200, '9-frame': 1342, '10-frame': 1402}}, 130676], ['hydrant exactly 1000 feet', {'base': 119429, 'pc': '6', 'construction': 'frame', 'station_miles': 3, 'hydrant_feet': 1000, 'matrix': {'1-frame': 802, '1-masonry': 760, '2-frame': 862, '2-masonry': 815, '3-frame': 922, '3-masonry': 870, '4-frame': 982, '4-masonry': 925, '5-frame': 1042, '5-masonry': 980, '6-frame': 1102, '6-masonry': 1035, '7-frame': 1162, '7-masonry': 1090, '8-frame': 1222, '8-masonry': 1145, '8B-frame': 1282, '8B-masonry': 1200, '9-frame': 1342, '10-frame': 1402}}, 131611], ['split class keeps 8B', {'base': 152686, 'pc': '8B', 'construction': 'frame', 'station_miles': 4, 'hydrant_feet': 1500, 'matrix': {'1-frame': 802, '1-masonry': 760, '2-frame': 862, '2-masonry': 815, '3-frame': 922, '3-masonry': 870, '4-frame': 982, '4-masonry': 925, '5-frame': 1042, '5-masonry': 980, '6-frame': 1102, '6-masonry': 1035, '7-frame': 1162, '7-masonry': 1090, '8-frame': 1222, '8-masonry': 1145, '8B-frame': 1282, '8B-masonry': 1200, '9-frame': 1342, '10-frame': 1402}}, 195743], ['masonry downgraded uses frame fallback', {'base': 105761, 'pc': '7', 'construction': 'masonry', 'station_miles': 2, 'hydrant_feet': 1400, 'matrix': {'1-frame': 802, '1-masonry': 760, '2-frame': 862, '2-masonry': 815, '3-frame': 922, '3-masonry': 870, '4-frame': 982, '4-masonry': 925, '5-frame': 1042, '5-masonry': 980, '6-frame': 1102, '6-masonry': 1035, '7-frame': 1162, '7-masonry': 1090, '8-frame': 1222, '8-masonry': 1145, '8B-frame': 1282, '8B-masonry': 1200, '9-frame': 1342, '10-frame': 1402}}, 134835], ['masonry class 10 fallback', {'base': 112632, 'pc': '3', 'construction': 'masonry', 'station_miles': 7, 'hydrant_feet': 100, 'matrix': {'1-frame': 802, '1-masonry': 760, '2-frame': 862, '2-masonry': 815, '3-frame': 922, '3-masonry': 870, '4-frame': 982, '4-masonry': 925, '5-frame': 1042, '5-masonry': 980, '6-frame': 1102, '6-masonry': 1035, '7-frame': 1162, '7-masonry': 1090, '8-frame': 1222, '8-masonry': 1145, '8B-frame': 1282, '8B-masonry': 1200, '9-frame': 1342, '10-frame': 1402}}, 150015], ['fire resistive unrated', {'base': 169686, 'pc': '9', 'construction': 'fire-resistive', 'station_miles': 1, 'hydrant_feet': 100, 'matrix': {'1-frame': 802, '1-masonry': 760, '2-frame': 862, '2-masonry': 815, '3-frame': 922, '3-masonry': 870, '4-frame': 982, '4-masonry': 925, '5-frame': 1042, '5-masonry': 980, '6-frame': 1102, '6-masonry': 1035, '7-frame': 1162, '7-masonry': 1090, '8-frame': 1222, '8-masonry': 1145, '8B-frame': 1282, '8B-masonry': 1200, '9-frame': 1342, '10-frame': 1402}}, 'unrated 9-fire-resistive'], ['masonry protected', {'base': 202626, 'pc': '8', 'construction': 'masonry', 'station_miles': 1, 'hydrant_feet': 200, 'matrix': {'1-frame': 802, '1-masonry': 760, '2-frame': 862, '2-masonry': 815, '3-frame': 922, '3-masonry': 870, '4-frame': 982, '4-masonry': 925, '5-frame': 1042, '5-masonry': 980, '6-frame': 1102, '6-masonry': 1035, '7-frame': 1162, '7-masonry': 1090, '8-frame': 1222, '8-masonry': 1145, '8B-frame': 1282, '8B-masonry': 1200, '9-frame': 1342, '10-frame': 1402}}, 232007]], [['protected frame', {'base': 204115, 'pc': '4', 'construction': 'frame', 'station_miles': 2, 'hydrant_feet': 300, 'matrix': {'1-frame': 803, '1-masonry': 760, '2-frame': 863, '2-masonry': 815, '3-frame': 923, '3-masonry': 870, '4-frame': 983, '4-masonry': 925, '5-frame': 1043, '5-masonry': 980, '6-frame': 1103, '6-masonry': 1035, '7-frame': 1163, '7-masonry': 1090, '8-frame': 1223, '8-masonry': 1145, '8B-frame': 1283, '8B-masonry': 1200, '9-frame': 1343, '10-frame': 1403}}, 200645], ['station exactly five miles', {'base': 156901, 'pc': '4', 'construction': 'frame', 'station_miles': 5, 'hydrant_feet': 400, 'matrix': {'1-frame': 803, '1-masonry': 760, '2-frame': 863, '2-masonry': 815, '3-frame': 923, '3-masonry': 870, '4-frame': 983, '4-masonry': 925, '5-frame': 1043, '5-masonry': 980, '6-frame': 1103, '6-masonry': 1035, '7-frame': 1163, '7-masonry': 1090, '8-frame': 1223, '8-masonry': 1145, '8B-frame': 1283, '8B-masonry': 1200, '9-frame': 1343, '10-frame': 1403}}, 154234], ['beyond five miles', {'base': 115311, 'pc': '3', 'construction': 'frame', 'station_miles': 5.5, 'hydrant_feet': 200, 'matrix': {'1-frame': 803, '1-masonry': 760, '2-frame': 863, '2-masonry': 815, '3-frame': 923, '3-masonry': 870, '4-frame': 983, '4-masonry': 925, '5-frame': 1043, '5-masonry': 980, '6-frame': 1103, '6-masonry': 1035, '7-frame': 1163, '7-masonry': 1090, '8-frame': 1223, '8-masonry': 1145, '8B-frame': 1283, '8B-masonry': 1200, '9-frame': 1343, '10-frame': 1403}}, 161781], ['distant hydrant downgrades', {'base': 150626, 'pc': '5', 'construction': 'frame', 'station_miles': 3, 'hydrant_feet': 1030, 'matrix': {'1-frame': 803, '1-masonry': 760, '2-frame': 863, '2-masonry': 815, '3-frame': 923, '3-masonry': 870, '4-frame': 983, '4-masonry': 925, '5-frame': 1043, '5-masonry': 980, '6-frame': 1103, '6-masonry': 1035, '7-frame': 1163, '7-masonry': 1090, '8-frame': 1223, '8-masonry': 1145, '8B-frame': 1283, '8B-masonry': 1200, '9-frame': 1343, '10-frame': 1403}}, 202291], ['hydrant exactly 1000 feet', {'base': 122970, 'pc': '6', 'construction': 'frame', 'station_miles': 3, 'hydrant_feet': 1000, 'matrix': {'1-frame': 803, '1-masonry': 760, '2-frame': 863, '2-masonry': 815, '3-frame': 923, '3-masonry': 870, '4-frame': 983, '4-masonry': 925, '5-frame': 1043, '5-masonry': 980, '6-frame': 1103, '6-masonry': 1035, '7-frame': 1163, '7-masonry': 1090, '8-frame': 1223, '8-masonry': 1145, '8B-frame': 1283, '8B-masonry': 1200, '9-frame': 1343, '10-frame': 1403}}, 135636], ['split class keeps 8B', {'base': 163526, 'pc': '8B', 'construction': 'frame', 'station_miles': 4, 'hydrant_feet': 1500, 'matrix': {'1-frame': 803, '1-masonry': 760, '2-frame': 863, '2-masonry': 815, '3-frame': 923, '3-masonry': 870, '4-frame': 983, '4-masonry': 925, '5-frame': 1043, '5-masonry': 980, '6-frame': 1103, '6-masonry': 1035, '7-frame': 1163, '7-masonry': 1090, '8-frame': 1223, '8-masonry': 1145, '8B-frame': 1283, '8B-masonry': 1200, '9-frame': 1343, '10-frame': 1403}}, 209804], ['masonry downgraded uses frame fallback', {'base': 154344, 'pc': '7', 'construction': 'masonry', 'station_miles': 2, 'hydrant_feet': 1400, 'matrix': {'1-frame': 803, '1-masonry': 760, '2-frame': 863, '2-masonry': 815, '3-frame': 923, '3-masonry': 870, '4-frame': 983, '4-masonry': 925, '5-frame': 1043, '5-masonry': 980, '6-frame': 1103, '6-masonry': 1035, '7-frame': 1163, '7-masonry': 1090, '8-frame': 1223, '8-masonry': 1145, '8B-frame': 1283, '8B-masonry': 1200, '9-frame': 1343, '10-frame': 1403}}, 196920], ['masonry class 10 fallback', {'base': 127756, 'pc': '3', 'construction': 'masonry', 'station_miles': 7, 'hydrant_feet': 100, 'matrix': {'1-frame': 803, '1-masonry': 760, '2-frame': 863, '2-masonry': 815, '3-frame': 923, '3-masonry': 870, '4-frame': 983, '4-masonry': 925, '5-frame': 1043, '5-masonry': 980, '6-frame': 1103, '6-masonry': 1035, '7-frame': 1163, '7-masonry': 1090, '8-frame': 1223, '8-masonry': 1145, '8B-frame': 1283, '8B-masonry': 1200, '9-frame': 1343, '10-frame': 1403}}, 170280], ['fire resistive unrated', {'base': 229613, 'pc': '9', 'construction': 'fire-resistive', 'station_miles': 1, 'hydrant_feet': 100, 'matrix': {'1-frame': 803, '1-masonry': 760, '2-frame': 863, '2-masonry': 815, '3-frame': 923, '3-masonry': 870, '4-frame': 983, '4-masonry': 925, '5-frame': 1043, '5-masonry': 980, '6-frame': 1103, '6-masonry': 1035, '7-frame': 1163, '7-masonry': 1090, '8-frame': 1223, '8-masonry': 1145, '8B-frame': 1283, '8B-masonry': 1200, '9-frame': 1343, '10-frame': 1403}}, 'unrated 9-fire-resistive'], ['masonry protected', {'base': 92691, 'pc': '8', 'construction': 'masonry', 'station_miles': 1, 'hydrant_feet': 200, 'matrix': {'1-frame': 803, '1-masonry': 760, '2-frame': 863, '2-masonry': 815, '3-frame': 923, '3-masonry': 870, '4-frame': 983, '4-masonry': 925, '5-frame': 1043, '5-masonry': 980, '6-frame': 1103, '6-masonry': 1035, '7-frame': 1163, '7-masonry': 1090, '8-frame': 1223, '8-masonry': 1145, '8B-frame': 1283, '8B-masonry': 1200, '9-frame': 1343, '10-frame': 1403}}, 106131]], [['protected frame', {'base': 247005, 'pc': '2', 'construction': 'frame', 'station_miles': 2, 'hydrant_feet': 300, 'matrix': {'1-frame': 804, '1-masonry': 760, '2-frame': 864, '2-masonry': 815, '3-frame': 924, '3-masonry': 870, '4-frame': 984, '4-masonry': 925, '5-frame': 1044, '5-masonry': 980, '6-frame': 1104, '6-masonry': 1035, '7-frame': 1164, '7-masonry': 1090, '8-frame': 1224, '8-masonry': 1145, '8B-frame': 1284, '8B-masonry': 1200, '9-frame': 1344, '10-frame': 1404}}, 213412], ['station exactly five miles', {'base': 224534, 'pc': '4', 'construction': 'masonry', 'station_miles': 5, 'hydrant_feet': 400, 'matrix': {'1-frame': 804, '1-masonry': 760, '2-frame': 864, '2-masonry': 815, '3-frame': 924, '3-masonry': 870, '4-frame': 984, '4-masonry': 925, '5-frame': 1044, '5-masonry': 980, '6-frame': 1104, '6-masonry': 1035, '7-frame': 1164, '7-masonry': 1090, '8-frame': 1224, '8-masonry': 1145, '8B-frame': 1284, '8B-masonry': 1200, '9-frame': 1344, '10-frame': 1404}}, 207694], ['beyond five miles', {'base': 241571, 'pc': '3', 'construction': 'frame', 'station_miles': 5.5, 'hydrant_feet': 200, 'matrix': {'1-frame': 804, '1-masonry': 760, '2-frame': 864, '2-masonry': 815, '3-frame': 924, '3-masonry': 870, '4-frame': 984, '4-masonry': 925, '5-frame': 1044, '5-masonry': 980, '6-frame': 1104, '6-masonry': 1035, '7-frame': 1164, '7-masonry': 1090, '8-frame': 1224, '8-masonry': 1145, '8B-frame': 1284, '8B-masonry': 1200, '9-frame': 1344, '10-frame': 1404}}, 339166], ['distant hydrant downgrades', {'base': 161859, 'pc': '5', 'construction': 'frame', 'station_miles': 3, 'hydrant_feet': 1030, 'matrix': {'1-frame': 804, '1-masonry': 760, '2-frame': 864, '2-masonry': 815, '3-frame': 924, '3-masonry': 870, '4-frame': 984, '4-masonry': 925, '5-frame': 1044, '5-masonry': 980, '6-frame': 1104, '6-masonry': 1035, '7-frame': 1164, '7-masonry': 1090, '8-frame': 1224, '8-masonry': 1145, '8B-frame': 1284, '8B-masonry': 1200, '9-frame': 1344, '10-frame': 1404}}, 217538], ['hydrant exactly 1000 feet', {'base': 142348, 'pc': '6', 'construction': 'frame', 'station_miles': 3, 'hydrant_feet': 1000, 'matrix': {'1-frame': 804, '1-masonry': 760, '2-frame': 864, '2-masonry': 815, '3-frame': 924, '3-masonry': 870, '4-frame': 984, '4-masonry': 925, '5-frame': 1044, '5-masonry': 980, '6-frame': 1104, '6-masonry': 1035, '7-frame': 1164, '7-masonry': 1090, '8-frame': 1224, '8-masonry': 1145, '8B-frame': 1284, '8B-masonry': 1200, '9-frame': 1344, '10-frame': 1404}}, 157152], ['split class keeps 8B', {'base': 76654, 'pc': '8B', 'construction': 'frame', 'station_miles': 4, 'hydrant_feet': 1500, 'matrix': {'1-frame': 804, '1-masonry': 760, '2-frame': 864, '2-masonry': 815, '3-frame': 924, '3-masonry': 870, '4-frame': 984, '4-masonry': 925, '5-frame': 1044, '5-masonry': 980, '6-frame': 1104, '6-masonry': 1035, '7-frame': 1164, '7-masonry': 1090, '8-frame': 1224, '8-masonry': 1145, '8B-frame': 1284, '8B-masonry': 1200, '9-frame': 1344, '10-frame': 1404}}, 98424], ['masonry downgraded uses frame fallback', {'base': 150835, 'pc': '7', 'construction': 'masonry', 'station_miles': 2, 'hydrant_feet': 1400, 'matrix': {'1-frame': 804, '1-masonry': 760, '2-frame': 864, '2-masonry': 815, '3-frame': 924, '3-masonry': 870, '4-frame': 984, '4-masonry': 925, '5-frame': 1044, '5-masonry': 980, '6-frame': 1104, '6-masonry': 1035, '7-frame': 1164, '7-masonry': 1090, '8-frame': 1224, '8-masonry': 1145, '8B-frame': 1284, '8B-masonry': 1200, '9-frame': 1344, '10-frame': 1404}}, 192586], ['masonry class 10 fallback', {'base': 175432, 'pc': '3', 'construction': 'masonry', 'station_miles': 7, 'hydrant_feet': 100, 'matrix': {'1-frame': 804, '1-masonry': 760, '2-frame': 864, '2-masonry': 815, '3-frame': 924, '3-masonry': 870, '4-frame': 984, '4-masonry': 925, '5-frame': 1044, '5-masonry': 980, '6-frame': 1104, '6-masonry': 1035, '7-frame': 1164, '7-masonry': 1090, '8-frame': 1224, '8-masonry': 1145, '8B-frame': 1284, '8B-masonry': 1200, '9-frame': 1344, '10-frame': 1404}}, 233991], ['fire resistive unrated', {'base': 103540, 'pc': '9', 'construction': 'fire-resistive', 'station_miles': 1, 'hydrant_feet': 100, 'matrix': {'1-frame': 804, '1-masonry': 760, '2-frame': 864, '2-masonry': 815, '3-frame': 924, '3-masonry': 870, '4-frame': 984, '4-masonry': 925, '5-frame': 1044, '5-masonry': 980, '6-frame': 1104, '6-masonry': 1035, '7-frame': 1164, '7-masonry': 1090, '8-frame': 1224, '8-masonry': 1145, '8B-frame': 1284, '8B-masonry': 1200, '9-frame': 1344, '10-frame': 1404}}, 'unrated 9-fire-resistive'], ['masonry protected', {'base': 83396, 'pc': '8', 'construction': 'masonry', 'station_miles': 1, 'hydrant_feet': 200, 'matrix': {'1-frame': 804, '1-masonry': 760, '2-frame': 864, '2-masonry': 815, '3-frame': 924, '3-masonry': 870, '4-frame': 984, '4-masonry': 925, '5-frame': 1044, '5-masonry': 980, '6-frame': 1104, '6-masonry': 1035, '7-frame': 1164, '7-masonry': 1090, '8-frame': 1224, '8-masonry': 1145, '8B-frame': 1284, '8B-masonry': 1200, '9-frame': 1344, '10-frame': 1404}}, 95488]], [['protected frame', {'base': 182973, 'pc': '2', 'construction': 'frame', 'station_miles': 2, 'hydrant_feet': 300, 'matrix': {'1-frame': 805, '1-masonry': 760, '2-frame': 865, '2-masonry': 815, '3-frame': 925, '3-masonry': 870, '4-frame': 985, '4-masonry': 925, '5-frame': 1045, '5-masonry': 980, '6-frame': 1105, '6-masonry': 1035, '7-frame': 1165, '7-masonry': 1090, '8-frame': 1225, '8-masonry': 1145, '8B-frame': 1285, '8B-masonry': 1200, '9-frame': 1345, '10-frame': 1405}}, 158272], ['station exactly five miles', {'base': 226119, 'pc': '4', 'construction': 'frame', 'station_miles': 5, 'hydrant_feet': 400, 'matrix': {'1-frame': 805, '1-masonry': 760, '2-frame': 865, '2-masonry': 815, '3-frame': 925, '3-masonry': 870, '4-frame': 985, '4-masonry': 925, '5-frame': 1045, '5-masonry': 980, '6-frame': 1105, '6-masonry': 1035, '7-frame': 1165, '7-masonry': 1090, '8-frame': 1225, '8-masonry': 1145, '8B-frame': 1285, '8B-masonry': 1200, '9-frame': 1345, '10-frame': 1405}}, 222727], ['beyond five miles', {'base': 98376, 'pc': '3', 'construction': 'frame', 'station_miles': 5.5, 'hydrant_feet': 200, 'matrix': {'1-frame': 805, '1-masonry': 760, '2-frame': 865, '2-masonry': 815, '3-frame': 925, '3-masonry': 870, '4-frame': 985, '4-masonry': 925, '5-frame': 1045, '5-masonry': 980, '6-frame': 1105, '6-masonry': 1035, '7-frame': 1165, '7-masonry': 1090, '8-frame': 1225, '8-masonry': 1145, '8B-frame': 1285, '8B-masonry': 1200, '9-frame': 1345, '10-frame': 1405}}, 138218], ['distant hydrant downgrades', {'base': 168912, 'pc': '5', 'construction': 'frame', 'station_miles': 3, 'hydrant_feet': 1030, 'matrix': {'1-frame': 805, '1-masonry': 760, '2-frame': 865, '2-masonry': 815, '3-frame': 925, '3-masonry': 870, '4-frame': 985, '4-masonry': 925, '5-frame': 1045, '5-masonry': 980, '6-frame': 1105, '6-masonry': 1035, '7-frame': 1165, '7-masonry': 1090, '8-frame': 1225, '8-masonry': 1145, '8B-frame': 1285, '8B-masonry': 1200, '9-frame': 1345, '10-frame': 1405}}, 227187], ['hydrant exactly 1000 feet', {'base': 213720, 'pc': '6', 'construction': 'frame', 'station_miles': 3, 'hydrant_feet': 1000, 'matrix': {'1-frame': 805, '1-masonry': 760, '2-frame': 865, '2-masonry': 815, '3-frame': 925, '3-masonry': 870, '4-frame': 985, '4-masonry': 925, '5-frame': 1045, '5-masonry': 980, '6-frame': 1105, '6-masonry': 1035, '7-frame': 1165, '7-masonry': 1090, '8-frame': 1225, '8-masonry': 1145, '8B-frame': 1285, '8B-masonry': 1200, '9-frame': 1345, '10-frame': 1405}}, 236161], ['split class keeps 8B', {'base': 61162, 'pc': '8B', 'construction': 'frame', 'station_miles': 4, 'hydrant_feet': 1500, 'matrix': {'1-frame': 805, '1-masonry': 760, '2-frame': 865, '2-masonry': 815, '3-frame': 925, '3-masonry': 870, '4-frame': 985, '4-masonry': 925, '5-frame': 1045, '5-masonry': 980, '6-frame': 1105, '6-masonry': 1035, '7-frame': 1165, '7-masonry': 1090, '8-frame': 1225, '8-masonry': 1145, '8B-frame': 1285, '8B-masonry': 1200, '9-frame': 1345, '10-frame': 1405}}, 78593], ['masonry downgraded uses frame fallback', {'base': 109402, 'pc': '7', 'construction': 'masonry', 'station_miles': 2, 'hydrant_feet': 1400, 'matrix': {'1-frame': 805, '1-masonry': 760, '2-frame': 865, '2-masonry': 815, '3-frame': 925, '3-masonry': 870, '4-frame': 985, '4-masonry': 925, '5-frame': 1045, '5-masonry': 980, '6-frame': 1105, '6-masonry': 1035, '7-frame': 1165, '7-masonry': 1090, '8-frame': 1225, '8-masonry': 1145, '8B-frame': 1285, '8B-masonry': 1200, '9-frame': 1345, '10-frame': 1405}}, 139788], ['masonry class 10 fallback', {'base': 131356, 'pc': '3', 'construction': 'masonry', 'station_miles': 7, 'hydrant_feet': 100, 'matrix': {'1-frame': 805, '1-masonry': 760, '2-frame': 865, '2-masonry': 815, '3-frame': 925, '3-masonry': 870, '4-frame': 985, '4-masonry': 925, '5-frame': 1045, '5-masonry': 980, '6-frame': 1105, '6-masonry': 1035, '7-frame': 1165, '7-masonry': 1090, '8-frame': 1225, '8-masonry': 1145, '8B-frame': 1285, '8B-masonry': 1200, '9-frame': 1345, '10-frame': 1405}}, 175327], ['fire resistive unrated', {'base': 230152, 'pc': '9', 'construction': 'fire-resistive', 'station_miles': 1, 'hydrant_feet': 100, 'matrix': {'1-frame': 805, '1-masonry': 760, '2-frame': 865, '2-masonry': 815, '3-frame': 925, '3-masonry': 870, '4-frame': 985, '4-masonry': 925, '5-frame': 1045, '5-masonry': 980, '6-frame': 1105, '6-masonry': 1035, '7-frame': 1165, '7-masonry': 1090, '8-frame': 1225, '8-masonry': 1145, '8B-frame': 1285, '8B-masonry': 1200, '9-frame': 1345, '10-frame': 1405}}, 'unrated 9-fire-resistive'], ['masonry protected', {'base': 90689, 'pc': '8', 'construction': 'masonry', 'station_miles': 1, 'hydrant_feet': 200, 'matrix': {'1-frame': 805, '1-masonry': 760, '2-frame': 865, '2-masonry': 815, '3-frame': 925, '3-masonry': 870, '4-frame': 985, '4-masonry': 925, '5-frame': 1045, '5-masonry': 980, '6-frame': 1105, '6-masonry': 1035, '7-frame': 1165, '7-masonry': 1090, '8-frame': 1225, '8-masonry': 1145, '8B-frame': 1285, '8B-masonry': 1200, '9-frame': 1345, '10-frame': 1405}}, 103839]]]
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:
Downgraded homes are still rated at their reported class.

Input base, pc ('1'..'10' or split class '8B'), construction, station_miles, hydrant_feet, matrix {'pc-construction': factor*1000}. More than 5 miles from a station -> class 10; else hydrant over 1000 ft downgrades classes other than 8B/9/10 to 9. Missing masonry factors fall back to 95% of the frame factor; any other missing cell -> 'unrated <key>'.

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):
    s=x['start']; e=x['end']; T=e-s
    def r(v): return math.floor(v+Fraction(1,2)) if v>=0 else -math.floor(-v+Fraction(1,2))
    cur=x['annual']; out=[]; last=s
    for d,new in x['endorsements']:
        if d<s or d>=e or d<last: return 'invalid endorsement date'
        out.append(r(Fraction((new-cur)*(e-d),T)))
        last=d
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['single increase', {'start': 2912, 'end': 3277, 'annual': 228520, 'endorsements': [[3043, 390228]]}, [103670]], ['increase then decrease', {'start': 477, 'end': 842, 'annual': 136883, 'endorsements': [[562, 340860], [681, 77377]]}, [156476, -116221]], ['decrease then partial restore', {'start': 2037, 'end': 2402, 'annual': 100000, 'endorsements': [[2109, 40001], [2277, 63890]]}, [-48164, 8181]], ['leap-year term', {'start': 2320, 'end': 2686, 'annual': 138690, 'endorsements': [[2497, 161560]]}, [11810]], ['six-month term', {'start': 2269, 'end': 2451, 'annual': 114166, 'endorsements': [[2418, 400299], [2439, 379739]]}, [51881, -1356]], ['endorsement on expiry rejected', {'start': 286, 'end': 651, 'annual': 174243, 'endorsements': [[651, 200000]]}, 'invalid endorsement date'], ['endorsement before inception rejected', {'start': 962, 'end': 1327, 'annual': 166624, 'endorsements': [[961, 200000]]}, 'invalid endorsement date'], ['out of order rejected', {'start': 251, 'end': 616, 'annual': 164047, 'endorsements': [[451, 200000], [351, 250000]]}, 'invalid endorsement date'], ['inception-day endorsement', {'start': 579, 'end': 944, 'annual': 88017, 'endorsements': [[579, 316996]]}, [228979]], ['same-day endorsements', {'start': 17, 'end': 382, 'annual': 194026, 'endorsements': [[137, 250000], [137, 260000]]}, [37572, 6712]], ['last day endorsement', {'start': 2889, 'end': 3254, 'annual': 100000, 'endorsements': [[3253, 255567]]}, [426]]], [['single increase', {'start': 2490, 'end': 2855, 'annual': 104092, 'endorsements': [[2682, 358418]]}, [120544]], ['increase then decrease', {'start': 1761, 'end': 2126, 'annual': 95155, 'endorsements': [[1839, 390602], [1949, 60898]]}, [232310, -159884]], ['decrease then partial restore', {'start': 2809, 'end': 3174, 'annual': 100000, 'endorsements': [[2849, 40002], [3041, 65761]]}, [-53423, 9386]], ['leap-year term', {'start': 2789, 'end': 3155, 'annual': 136600, 'endorsements': [[3052, 310248]]}, [48868]], ['six-month term', {'start': 1197, 'end': 1379, 'annual': 163268, 'endorsements': [[1271, 255330], [1367, 168424]]}, [54630, -5730]], ['endorsement on expiry rejected', {'start': 48, 'end': 413, 'annual': 192511, 'endorsements': [[413, 200000]]}, 'invalid endorsement date'], ['endorsement before inception rejected', {'start': 1771, 'end': 2136, 'annual': 162702, 'endorsements': [[1770, 200000]]}, 'invalid endorsement date'], ['out of order rejected', {'start': 2865, 'end': 3230, 'annual': 261177, 'endorsements': [[3065, 200000], [2965, 250000]]}, 'invalid endorsement date'], ['inception-day endorsement', {'start': 1467, 'end': 1832, 'annual': 116027, 'endorsements': [[1467, 190089]]}, [74062]], ['same-day endorsements', {'start': 847, 'end': 1212, 'annual': 109565, 'endorsements': [[967, 250000], [967, 260000]]}, [94265, 6712]], ['last day endorsement', {'start': 2776, 'end': 3141, 'annual': 100000, 'endorsements': [[3140, 396043]]}, [811]]], [['single increase', {'start': 1206, 'end': 1571, 'annual': 166000, 'endorsements': [[1276, 393494]]}, [183865]], ['increase then decrease', {'start': 749, 'end': 1114, 'annual': 280762, 'endorsements': [[848, 343990], [953, 67369]]}, [46078, -122016]], ['decrease then partial restore', {'start': 766, 'end': 1131, 'annual': 100000, 'endorsements': [[803, 40003], [1051, 69438]]}, [-53915, 6452]], ['leap-year term', {'start': 2028, 'end': 2394, 'annual': 148609, 'endorsements': [[2319, 100348]]}, [-9890]], ['six-month term', {'start': 1944, 'end': 2126, 'annual': 124458, 'endorsements': [[2010, 171861], [2114, 388840]]}, [30213, 14306]], ['endorsement on expiry rejected', {'start': 1174, 'end': 1539, 'annual': 115160, 'endorsements': [[1539, 200000]]}, 'invalid endorsement date'], ['endorsement before inception rejected', {'start': 2665, 'end': 3030, 'annual': 152976, 'endorsements': [[2664, 200000]]}, 'invalid endorsement date'], ['out of order rejected', {'start': 1602, 'end': 1967, 'annual': 240101, 'endorsements': [[1802, 200000], [1702, 250000]]}, 'invalid endorsement date'], ['inception-day endorsement', {'start': 908, 'end': 1273, 'annual': 148941, 'endorsements': [[908, 436896]]}, [287955]], ['same-day endorsements', {'start': 1319, 'end': 1684, 'annual': 113258, 'endorsements': [[1439, 250000], [1439, 260000]]}, [91786, 6712]], ['last day endorsement', {'start': 2821, 'end': 3186, 'annual': 100000, 'endorsements': [[3185, 367523]]}, [733]]], [['single increase', {'start': 2447, 'end': 2812, 'annual': 190688, 'endorsements': [[2655, 312597]]}, [52438]], ['increase then decrease', {'start': 1314, 'end': 1679, 'annual': 268062, 'endorsements': [[1335, 344123], [1518, 58352]]}, [71685, -126052]], ['decrease then partial restore', {'start': 1117, 'end': 1482, 'annual': 100000, 'endorsements': [[1159, 40004], [1334, 61238]]}, [-53092, 8610]], ['leap-year term', {'start': 1273, 'end': 1639, 'annual': 241312, 'endorsements': [[1536, 193555]]}, [-13440]], ['six-month term', {'start': 49, 'end': 231, 'annual': 80756, 'endorsements': [[79, 411368], [219, 276361]]}, [276116, -8902]], ['endorsement on expiry rejected', {'start': 2167, 'end': 2532, 'annual': 216523, 'endorsements': [[2532, 200000]]}, 'invalid endorsement date'], ['endorsement before inception rejected', {'start': 1680, 'end': 2045, 'annual': 258325, 'endorsements': [[1679, 200000]]}, 'invalid endorsement date'], ['out of order rejected', {'start': 2653, 'end': 3018, 'annual': 115795, 'endorsements': [[2853, 200000], [2753, 250000]]}, 'invalid endorsement date'], ['inception-day endorsement', {'start': 2438, 'end': 2803, 'annual': 251511, 'endorsements': [[2438, 112887]]}, [-138624]], ['same-day endorsements', {'start': 1751, 'end': 2116, 'annual': 210625, 'endorsements': [[1871, 250000], [1871, 260000]]}, [26430, 6712]], ['last day endorsement', {'start': 1049, 'end': 1414, 'annual': 100000, 'endorsements': [[1413, 290691]]}, [522]]], [['single increase', {'start': 567, 'end': 932, 'annual': 242069, 'endorsements': [[864, 340392]]}, [18318]], ['increase then decrease', {'start': 2519, 'end': 2884, 'annual': 179314, 'endorsements': [[2537, 319903], [2726, 81013]]}, [133656, -103410]], ['decrease then partial restore', {'start': 1092, 'end': 1457, 'annual': 100000, 'endorsements': [[1105, 40005], [1285, 62765]]}, [-57858, 10725]], ['leap-year term', {'start': 820, 'end': 1186, 'annual': 204385, 'endorsements': [[905, 292674]]}, [67785]], ['six-month term', {'start': 1400, 'end': 1582, 'annual': 108639, 'endorsements': [[1481, 441832], [1570, 418671]]}, [184904, -1527]], ['endorsement on expiry rejected', {'start': 936, 'end': 1301, 'annual': 206524, 'endorsements': [[1301, 200000]]}, 'invalid endorsement date'], ['endorsement before inception rejected', {'start': 983, 'end': 1348, 'annual': 294557, 'endorsements': [[982, 200000]]}, 'invalid endorsement date'], ['out of order rejected', {'start': 1953, 'end': 2318, 'annual': 262141, 'endorsements': [[2153, 200000], [2053, 250000]]}, 'invalid endorsement date'], ['inception-day endorsement', {'start': 2741, 'end': 3106, 'annual': 192566, 'endorsements': [[2741, 174344]]}, [-18222]], ['same-day endorsements', {'start': 114, 'end': 479, 'annual': 252584, 'endorsements': [[234, 250000], [234, 260000]]}, [-1734, 6712]], ['last day endorsement', {'start': 1695, 'end': 2060, 'annual': 100000, 'endorsements': [[2059, 111498]]}, [32]]]]
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):
    s=x['start']; e=x['end']; T=e-s
    def r(v): return math.floor(v+Fraction(1,2)) if v>=0 else -math.floor(-v+Fraction(1,2))
    cur=x['annual']; out=[]; last=s
    for d,new in x['endorsements']:
        if d<s or d>=e or d<last: return 'invalid endorsement date'
        out.append(r(Fraction((new-cur)*(e-d),T)))
        cur=new if new>cur else cur; last=d
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['single increase', {'start': 2912, 'end': 3277, 'annual': 228520, 'endorsements': [[3043, 390228]]}, [103670]], ['increase then decrease', {'start': 477, 'end': 842, 'annual': 136883, 'endorsements': [[562, 340860], [681, 77377]]}, [156476, -116221]], ['decrease then partial restore', {'start': 2037, 'end': 2402, 'annual': 100000, 'endorsements': [[2109, 40001], [2277, 63890]]}, [-48164, 8181]], ['leap-year term', {'start': 2320, 'end': 2686, 'annual': 138690, 'endorsements': [[2497, 161560]]}, [11810]], ['six-month term', {'start': 2269, 'end': 2451, 'annual': 114166, 'endorsements': [[2418, 400299], [2439, 379739]]}, [51881, -1356]], ['endorsement on expiry rejected', {'start': 286, 'end': 651, 'annual': 174243, 'endorsements': [[651, 200000]]}, 'invalid endorsement date'], ['endorsement before inception rejected', {'start': 962, 'end': 1327, 'annual': 166624, 'endorsements': [[961, 200000]]}, 'invalid endorsement date'], ['out of order rejected', {'start': 251, 'end': 616, 'annual': 164047, 'endorsements': [[451, 200000], [351, 250000]]}, 'invalid endorsement date'], ['inception-day endorsement', {'start': 579, 'end': 944, 'annual': 88017, 'endorsements': [[579, 316996]]}, [228979]], ['same-day endorsements', {'start': 17, 'end': 382, 'annual': 194026, 'endorsements': [[137, 250000], [137, 260000]]}, [37572, 6712]], ['last day endorsement', {'start': 2889, 'end': 3254, 'annual': 100000, 'endorsements': [[3253, 255567]]}, [426]]], [['single increase', {'start': 2490, 'end': 2855, 'annual': 104092, 'endorsements': [[2682, 358418]]}, [120544]], ['increase then decrease', {'start': 1761, 'end': 2126, 'annual': 95155, 'endorsements': [[1839, 390602], [1949, 60898]]}, [232310, -159884]], ['decrease then partial restore', {'start': 2809, 'end': 3174, 'annual': 100000, 'endorsements': [[2849, 40002], [3041, 65761]]}, [-53423, 9386]], ['leap-year term', {'start': 2789, 'end': 3155, 'annual': 136600, 'endorsements': [[3052, 310248]]}, [48868]], ['six-month term', {'start': 1197, 'end': 1379, 'annual': 163268, 'endorsements': [[1271, 255330], [1367, 168424]]}, [54630, -5730]], ['endorsement on expiry rejected', {'start': 48, 'end': 413, 'annual': 192511, 'endorsements': [[413, 200000]]}, 'invalid endorsement date'], ['endorsement before inception rejected', {'start': 1771, 'end': 2136, 'annual': 162702, 'endorsements': [[1770, 200000]]}, 'invalid endorsement date'], ['out of order rejected', {'start': 2865, 'end': 3230, 'annual': 261177, 'endorsements': [[3065, 200000], [2965, 250000]]}, 'invalid endorsement date'], ['inception-day endorsement', {'start': 1467, 'end': 1832, 'annual': 116027, 'endorsements': [[1467, 190089]]}, [74062]], ['same-day endorsements', {'start': 847, 'end': 1212, 'annual': 109565, 'endorsements': [[967, 250000], [967, 260000]]}, [94265, 6712]], ['last day endorsement', {'start': 2776, 'end': 3141, 'annual': 100000, 'endorsements': [[3140, 396043]]}, [811]]], [['single increase', {'start': 1206, 'end': 1571, 'annual': 166000, 'endorsements': [[1276, 393494]]}, [183865]], ['increase then decrease', {'start': 749, 'end': 1114, 'annual': 280762, 'endorsements': [[848, 343990], [953, 67369]]}, [46078, -122016]], ['decrease then partial restore', {'start': 766, 'end': 1131, 'annual': 100000, 'endorsements': [[803, 40003], [1051, 69438]]}, [-53915, 6452]], ['leap-year term', {'start': 2028, 'end': 2394, 'annual': 148609, 'endorsements': [[2319, 100348]]}, [-9890]], ['six-month term', {'start': 1944, 'end': 2126, 'annual': 124458, 'endorsements': [[2010, 171861], [2114, 388840]]}, [30213, 14306]], ['endorsement on expiry rejected', {'start': 1174, 'end': 1539, 'annual': 115160, 'endorsements': [[1539, 200000]]}, 'invalid endorsement date'], ['endorsement before inception rejected', {'start': 2665, 'end': 3030, 'annual': 152976, 'endorsements': [[2664, 200000]]}, 'invalid endorsement date'], ['out of order rejected', {'start': 1602, 'end': 1967, 'annual': 240101, 'endorsements': [[1802, 200000], [1702, 250000]]}, 'invalid endorsement date'], ['inception-day endorsement', {'start': 908, 'end': 1273, 'annual': 148941, 'endorsements': [[908, 436896]]}, [287955]], ['same-day endorsements', {'start': 1319, 'end': 1684, 'annual': 113258, 'endorsements': [[1439, 250000], [1439, 260000]]}, [91786, 6712]], ['last day endorsement', {'start': 2821, 'end': 3186, 'annual': 100000, 'endorsements': [[3185, 367523]]}, [733]]], [['single increase', {'start': 2447, 'end': 2812, 'annual': 190688, 'endorsements': [[2655, 312597]]}, [52438]], ['increase then decrease', {'start': 1314, 'end': 1679, 'annual': 268062, 'endorsements': [[1335, 344123], [1518, 58352]]}, [71685, -126052]], ['decrease then partial restore', {'start': 1117, 'end': 1482, 'annual': 100000, 'endorsements': [[1159, 40004], [1334, 61238]]}, [-53092, 8610]], ['leap-year term', {'start': 1273, 'end': 1639, 'annual': 241312, 'endorsements': [[1536, 193555]]}, [-13440]], ['six-month term', {'start': 49, 'end': 231, 'annual': 80756, 'endorsements': [[79, 411368], [219, 276361]]}, [276116, -8902]], ['endorsement on expiry rejected', {'start': 2167, 'end': 2532, 'annual': 216523, 'endorsements': [[2532, 200000]]}, 'invalid endorsement date'], ['endorsement before inception rejected', {'start': 1680, 'end': 2045, 'annual': 258325, 'endorsements': [[1679, 200000]]}, 'invalid endorsement date'], ['out of order rejected', {'start': 2653, 'end': 3018, 'annual': 115795, 'endorsements': [[2853, 200000], [2753, 250000]]}, 'invalid endorsement date'], ['inception-day endorsement', {'start': 2438, 'end': 2803, 'annual': 251511, 'endorsements': [[2438, 112887]]}, [-138624]], ['same-day endorsements', {'start': 1751, 'end': 2116, 'annual': 210625, 'endorsements': [[1871, 250000], [1871, 260000]]}, [26430, 6712]], ['last day endorsement', {'start': 1049, 'end': 1414, 'annual': 100000, 'endorsements': [[1413, 290691]]}, [522]]], [['single increase', {'start': 567, 'end': 932, 'annual': 242069, 'endorsements': [[864, 340392]]}, [18318]], ['increase then decrease', {'start': 2519, 'end': 2884, 'annual': 179314, 'endorsements': [[2537, 319903], [2726, 81013]]}, [133656, -103410]], ['decrease then partial restore', {'start': 1092, 'end': 1457, 'annual': 100000, 'endorsements': [[1105, 40005], [1285, 62765]]}, [-57858, 10725]], ['leap-year term', {'start': 820, 'end': 1186, 'annual': 204385, 'endorsements': [[905, 292674]]}, [67785]], ['six-month term', {'start': 1400, 'end': 1582, 'annual': 108639, 'endorsements': [[1481, 441832], [1570, 418671]]}, [184904, -1527]], ['endorsement on expiry rejected', {'start': 936, 'end': 1301, 'annual': 206524, 'endorsements': [[1301, 200000]]}, 'invalid endorsement date'], ['endorsement before inception rejected', {'start': 983, 'end': 1348, 'annual': 294557, 'endorsements': [[982, 200000]]}, 'invalid endorsement date'], ['out of order rejected', {'start': 1953, 'end': 2318, 'annual': 262141, 'endorsements': [[2153, 200000], [2053, 250000]]}, 'invalid endorsement date'], ['inception-day endorsement', {'start': 2741, 'end': 3106, 'annual': 192566, 'endorsements': [[2741, 174344]]}, [-18222]], ['same-day endorsements', {'start': 114, 'end': 479, 'annual': 252584, 'endorsements': [[234, 250000], [234, 260000]]}, [-1734, 6712]], ['last day endorsement', {'start': 1695, 'end': 2060, 'annual': 100000, 'endorsements': [[2059, 111498]]}, [32]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A second endorsement double-charges the first change.

Input start, end (days), annual premium, endorsements [[effective day, new annual premium]]. Dates must satisfy start<=d<end and be non-decreasing, else 'invalid endorsement date'. Each endorsement charges (new-current)*(end-d)/(end-start) rounded half away from zero, and the new premium becomes current.

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):
    s=x['start']; e=x['end']; T=e-s
    def r(v): return math.floor(v+Fraction(1,2)) if v>=0 else -math.floor(-v+Fraction(1,2))
    cur=x['annual']; out=[]; last=s
    for d,new in x['endorsements']:
        if d<s or d>=e or d<last: return 'invalid endorsement date'
        out.append(r(Fraction((new-cur)*(e-d+1),T)))
        cur=new; last=d
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['single increase', {'start': 2912, 'end': 3277, 'annual': 228520, 'endorsements': [[3043, 390228]]}, [103670]], ['increase then decrease', {'start': 477, 'end': 842, 'annual': 136883, 'endorsements': [[562, 340860], [681, 77377]]}, [156476, -116221]], ['decrease then partial restore', {'start': 2037, 'end': 2402, 'annual': 100000, 'endorsements': [[2109, 40001], [2277, 63890]]}, [-48164, 8181]], ['leap-year term', {'start': 2320, 'end': 2686, 'annual': 138690, 'endorsements': [[2497, 161560]]}, [11810]], ['six-month term', {'start': 2269, 'end': 2451, 'annual': 114166, 'endorsements': [[2418, 400299], [2439, 379739]]}, [51881, -1356]], ['endorsement on expiry rejected', {'start': 286, 'end': 651, 'annual': 174243, 'endorsements': [[651, 200000]]}, 'invalid endorsement date'], ['endorsement before inception rejected', {'start': 962, 'end': 1327, 'annual': 166624, 'endorsements': [[961, 200000]]}, 'invalid endorsement date'], ['out of order rejected', {'start': 251, 'end': 616, 'annual': 164047, 'endorsements': [[451, 200000], [351, 250000]]}, 'invalid endorsement date'], ['inception-day endorsement', {'start': 579, 'end': 944, 'annual': 88017, 'endorsements': [[579, 316996]]}, [228979]], ['same-day endorsements', {'start': 17, 'end': 382, 'annual': 194026, 'endorsements': [[137, 250000], [137, 260000]]}, [37572, 6712]], ['last day endorsement', {'start': 2889, 'end': 3254, 'annual': 100000, 'endorsements': [[3253, 255567]]}, [426]]], [['single increase', {'start': 2490, 'end': 2855, 'annual': 104092, 'endorsements': [[2682, 358418]]}, [120544]], ['increase then decrease', {'start': 1761, 'end': 2126, 'annual': 95155, 'endorsements': [[1839, 390602], [1949, 60898]]}, [232310, -159884]], ['decrease then partial restore', {'start': 2809, 'end': 3174, 'annual': 100000, 'endorsements': [[2849, 40002], [3041, 65761]]}, [-53423, 9386]], ['leap-year term', {'start': 2789, 'end': 3155, 'annual': 136600, 'endorsements': [[3052, 310248]]}, [48868]], ['six-month term', {'start': 1197, 'end': 1379, 'annual': 163268, 'endorsements': [[1271, 255330], [1367, 168424]]}, [54630, -5730]], ['endorsement on expiry rejected', {'start': 48, 'end': 413, 'annual': 192511, 'endorsements': [[413, 200000]]}, 'invalid endorsement date'], ['endorsement before inception rejected', {'start': 1771, 'end': 2136, 'annual': 162702, 'endorsements': [[1770, 200000]]}, 'invalid endorsement date'], ['out of order rejected', {'start': 2865, 'end': 3230, 'annual': 261177, 'endorsements': [[3065, 200000], [2965, 250000]]}, 'invalid endorsement date'], ['inception-day endorsement', {'start': 1467, 'end': 1832, 'annual': 116027, 'endorsements': [[1467, 190089]]}, [74062]], ['same-day endorsements', {'start': 847, 'end': 1212, 'annual': 109565, 'endorsements': [[967, 250000], [967, 260000]]}, [94265, 6712]], ['last day endorsement', {'start': 2776, 'end': 3141, 'annual': 100000, 'endorsements': [[3140, 396043]]}, [811]]], [['single increase', {'start': 1206, 'end': 1571, 'annual': 166000, 'endorsements': [[1276, 393494]]}, [183865]], ['increase then decrease', {'start': 749, 'end': 1114, 'annual': 280762, 'endorsements': [[848, 343990], [953, 67369]]}, [46078, -122016]], ['decrease then partial restore', {'start': 766, 'end': 1131, 'annual': 100000, 'endorsements': [[803, 40003], [1051, 69438]]}, [-53915, 6452]], ['leap-year term', {'start': 2028, 'end': 2394, 'annual': 148609, 'endorsements': [[2319, 100348]]}, [-9890]], ['six-month term', {'start': 1944, 'end': 2126, 'annual': 124458, 'endorsements': [[2010, 171861], [2114, 388840]]}, [30213, 14306]], ['endorsement on expiry rejected', {'start': 1174, 'end': 1539, 'annual': 115160, 'endorsements': [[1539, 200000]]}, 'invalid endorsement date'], ['endorsement before inception rejected', {'start': 2665, 'end': 3030, 'annual': 152976, 'endorsements': [[2664, 200000]]}, 'invalid endorsement date'], ['out of order rejected', {'start': 1602, 'end': 1967, 'annual': 240101, 'endorsements': [[1802, 200000], [1702, 250000]]}, 'invalid endorsement date'], ['inception-day endorsement', {'start': 908, 'end': 1273, 'annual': 148941, 'endorsements': [[908, 436896]]}, [287955]], ['same-day endorsements', {'start': 1319, 'end': 1684, 'annual': 113258, 'endorsements': [[1439, 250000], [1439, 260000]]}, [91786, 6712]], ['last day endorsement', {'start': 2821, 'end': 3186, 'annual': 100000, 'endorsements': [[3185, 367523]]}, [733]]], [['single increase', {'start': 2447, 'end': 2812, 'annual': 190688, 'endorsements': [[2655, 312597]]}, [52438]], ['increase then decrease', {'start': 1314, 'end': 1679, 'annual': 268062, 'endorsements': [[1335, 344123], [1518, 58352]]}, [71685, -126052]], ['decrease then partial restore', {'start': 1117, 'end': 1482, 'annual': 100000, 'endorsements': [[1159, 40004], [1334, 61238]]}, [-53092, 8610]], ['leap-year term', {'start': 1273, 'end': 1639, 'annual': 241312, 'endorsements': [[1536, 193555]]}, [-13440]], ['six-month term', {'start': 49, 'end': 231, 'annual': 80756, 'endorsements': [[79, 411368], [219, 276361]]}, [276116, -8902]], ['endorsement on expiry rejected', {'start': 2167, 'end': 2532, 'annual': 216523, 'endorsements': [[2532, 200000]]}, 'invalid endorsement date'], ['endorsement before inception rejected', {'start': 1680, 'end': 2045, 'annual': 258325, 'endorsements': [[1679, 200000]]}, 'invalid endorsement date'], ['out of order rejected', {'start': 2653, 'end': 3018, 'annual': 115795, 'endorsements': [[2853, 200000], [2753, 250000]]}, 'invalid endorsement date'], ['inception-day endorsement', {'start': 2438, 'end': 2803, 'annual': 251511, 'endorsements': [[2438, 112887]]}, [-138624]], ['same-day endorsements', {'start': 1751, 'end': 2116, 'annual': 210625, 'endorsements': [[1871, 250000], [1871, 260000]]}, [26430, 6712]], ['last day endorsement', {'start': 1049, 'end': 1414, 'annual': 100000, 'endorsements': [[1413, 290691]]}, [522]]], [['single increase', {'start': 567, 'end': 932, 'annual': 242069, 'endorsements': [[864, 340392]]}, [18318]], ['increase then decrease', {'start': 2519, 'end': 2884, 'annual': 179314, 'endorsements': [[2537, 319903], [2726, 81013]]}, [133656, -103410]], ['decrease then partial restore', {'start': 1092, 'end': 1457, 'annual': 100000, 'endorsements': [[1105, 40005], [1285, 62765]]}, [-57858, 10725]], ['leap-year term', {'start': 820, 'end': 1186, 'annual': 204385, 'endorsements': [[905, 292674]]}, [67785]], ['six-month term', {'start': 1400, 'end': 1582, 'annual': 108639, 'endorsements': [[1481, 441832], [1570, 418671]]}, [184904, -1527]], ['endorsement on expiry rejected', {'start': 936, 'end': 1301, 'annual': 206524, 'endorsements': [[1301, 200000]]}, 'invalid endorsement date'], ['endorsement before inception rejected', {'start': 983, 'end': 1348, 'annual': 294557, 'endorsements': [[982, 200000]]}, 'invalid endorsement date'], ['out of order rejected', {'start': 1953, 'end': 2318, 'annual': 262141, 'endorsements': [[2153, 200000], [2053, 250000]]}, 'invalid endorsement date'], ['inception-day endorsement', {'start': 2741, 'end': 3106, 'annual': 192566, 'endorsements': [[2741, 174344]]}, [-18222]], ['same-day endorsements', {'start': 114, 'end': 479, 'annual': 252584, 'endorsements': [[234, 250000], [234, 260000]]}, [-1734, 6712]], ['last day endorsement', {'start': 1695, 'end': 2060, 'annual': 100000, 'endorsements': [[2059, 111498]]}, [32]]]]
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):
    s=x['start']; e=x['end']; T=e-s
    def r(v): return math.floor(v+Fraction(1,2)) if v>=0 else -math.floor(-v+Fraction(1,2))
    cur=x['annual']; out=[]; last=s
    for d,new in x['endorsements']:
        if d<s or d>=e or d<last: return 'invalid endorsement date'
        out.append(r(Fraction((new-cur)*(e-last),T)))
        cur=new; last=d
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['single increase', {'start': 2912, 'end': 3277, 'annual': 228520, 'endorsements': [[3043, 390228]]}, [103670]], ['increase then decrease', {'start': 477, 'end': 842, 'annual': 136883, 'endorsements': [[562, 340860], [681, 77377]]}, [156476, -116221]], ['decrease then partial restore', {'start': 2037, 'end': 2402, 'annual': 100000, 'endorsements': [[2109, 40001], [2277, 63890]]}, [-48164, 8181]], ['leap-year term', {'start': 2320, 'end': 2686, 'annual': 138690, 'endorsements': [[2497, 161560]]}, [11810]], ['six-month term', {'start': 2269, 'end': 2451, 'annual': 114166, 'endorsements': [[2418, 400299], [2439, 379739]]}, [51881, -1356]], ['endorsement on expiry rejected', {'start': 286, 'end': 651, 'annual': 174243, 'endorsements': [[651, 200000]]}, 'invalid endorsement date'], ['endorsement before inception rejected', {'start': 962, 'end': 1327, 'annual': 166624, 'endorsements': [[961, 200000]]}, 'invalid endorsement date'], ['out of order rejected', {'start': 251, 'end': 616, 'annual': 164047, 'endorsements': [[451, 200000], [351, 250000]]}, 'invalid endorsement date'], ['inception-day endorsement', {'start': 579, 'end': 944, 'annual': 88017, 'endorsements': [[579, 316996]]}, [228979]], ['same-day endorsements', {'start': 17, 'end': 382, 'annual': 194026, 'endorsements': [[137, 250000], [137, 260000]]}, [37572, 6712]], ['last day endorsement', {'start': 2889, 'end': 3254, 'annual': 100000, 'endorsements': [[3253, 255567]]}, [426]]], [['single increase', {'start': 2490, 'end': 2855, 'annual': 104092, 'endorsements': [[2682, 358418]]}, [120544]], ['increase then decrease', {'start': 1761, 'end': 2126, 'annual': 95155, 'endorsements': [[1839, 390602], [1949, 60898]]}, [232310, -159884]], ['decrease then partial restore', {'start': 2809, 'end': 3174, 'annual': 100000, 'endorsements': [[2849, 40002], [3041, 65761]]}, [-53423, 9386]], ['leap-year term', {'start': 2789, 'end': 3155, 'annual': 136600, 'endorsements': [[3052, 310248]]}, [48868]], ['six-month term', {'start': 1197, 'end': 1379, 'annual': 163268, 'endorsements': [[1271, 255330], [1367, 168424]]}, [54630, -5730]], ['endorsement on expiry rejected', {'start': 48, 'end': 413, 'annual': 192511, 'endorsements': [[413, 200000]]}, 'invalid endorsement date'], ['endorsement before inception rejected', {'start': 1771, 'end': 2136, 'annual': 162702, 'endorsements': [[1770, 200000]]}, 'invalid endorsement date'], ['out of order rejected', {'start': 2865, 'end': 3230, 'annual': 261177, 'endorsements': [[3065, 200000], [2965, 250000]]}, 'invalid endorsement date'], ['inception-day endorsement', {'start': 1467, 'end': 1832, 'annual': 116027, 'endorsements': [[1467, 190089]]}, [74062]], ['same-day endorsements', {'start': 847, 'end': 1212, 'annual': 109565, 'endorsements': [[967, 250000], [967, 260000]]}, [94265, 6712]], ['last day endorsement', {'start': 2776, 'end': 3141, 'annual': 100000, 'endorsements': [[3140, 396043]]}, [811]]], [['single increase', {'start': 1206, 'end': 1571, 'annual': 166000, 'endorsements': [[1276, 393494]]}, [183865]], ['increase then decrease', {'start': 749, 'end': 1114, 'annual': 280762, 'endorsements': [[848, 343990], [953, 67369]]}, [46078, -122016]], ['decrease then partial restore', {'start': 766, 'end': 1131, 'annual': 100000, 'endorsements': [[803, 40003], [1051, 69438]]}, [-53915, 6452]], ['leap-year term', {'start': 2028, 'end': 2394, 'annual': 148609, 'endorsements': [[2319, 100348]]}, [-9890]], ['six-month term', {'start': 1944, 'end': 2126, 'annual': 124458, 'endorsements': [[2010, 171861], [2114, 388840]]}, [30213, 14306]], ['endorsement on expiry rejected', {'start': 1174, 'end': 1539, 'annual': 115160, 'endorsements': [[1539, 200000]]}, 'invalid endorsement date'], ['endorsement before inception rejected', {'start': 2665, 'end': 3030, 'annual': 152976, 'endorsements': [[2664, 200000]]}, 'invalid endorsement date'], ['out of order rejected', {'start': 1602, 'end': 1967, 'annual': 240101, 'endorsements': [[1802, 200000], [1702, 250000]]}, 'invalid endorsement date'], ['inception-day endorsement', {'start': 908, 'end': 1273, 'annual': 148941, 'endorsements': [[908, 436896]]}, [287955]], ['same-day endorsements', {'start': 1319, 'end': 1684, 'annual': 113258, 'endorsements': [[1439, 250000], [1439, 260000]]}, [91786, 6712]], ['last day endorsement', {'start': 2821, 'end': 3186, 'annual': 100000, 'endorsements': [[3185, 367523]]}, [733]]], [['single increase', {'start': 2447, 'end': 2812, 'annual': 190688, 'endorsements': [[2655, 312597]]}, [52438]], ['increase then decrease', {'start': 1314, 'end': 1679, 'annual': 268062, 'endorsements': [[1335, 344123], [1518, 58352]]}, [71685, -126052]], ['decrease then partial restore', {'start': 1117, 'end': 1482, 'annual': 100000, 'endorsements': [[1159, 40004], [1334, 61238]]}, [-53092, 8610]], ['leap-year term', {'start': 1273, 'end': 1639, 'annual': 241312, 'endorsements': [[1536, 193555]]}, [-13440]], ['six-month term', {'start': 49, 'end': 231, 'annual': 80756, 'endorsements': [[79, 411368], [219, 276361]]}, [276116, -8902]], ['endorsement on expiry rejected', {'start': 2167, 'end': 2532, 'annual': 216523, 'endorsements': [[2532, 200000]]}, 'invalid endorsement date'], ['endorsement before inception rejected', {'start': 1680, 'end': 2045, 'annual': 258325, 'endorsements': [[1679, 200000]]}, 'invalid endorsement date'], ['out of order rejected', {'start': 2653, 'end': 3018, 'annual': 115795, 'endorsements': [[2853, 200000], [2753, 250000]]}, 'invalid endorsement date'], ['inception-day endorsement', {'start': 2438, 'end': 2803, 'annual': 251511, 'endorsements': [[2438, 112887]]}, [-138624]], ['same-day endorsements', {'start': 1751, 'end': 2116, 'annual': 210625, 'endorsements': [[1871, 250000], [1871, 260000]]}, [26430, 6712]], ['last day endorsement', {'start': 1049, 'end': 1414, 'annual': 100000, 'endorsements': [[1413, 290691]]}, [522]]], [['single increase', {'start': 567, 'end': 932, 'annual': 242069, 'endorsements': [[864, 340392]]}, [18318]], ['increase then decrease', {'start': 2519, 'end': 2884, 'annual': 179314, 'endorsements': [[2537, 319903], [2726, 81013]]}, [133656, -103410]], ['decrease then partial restore', {'start': 1092, 'end': 1457, 'annual': 100000, 'endorsements': [[1105, 40005], [1285, 62765]]}, [-57858, 10725]], ['leap-year term', {'start': 820, 'end': 1186, 'annual': 204385, 'endorsements': [[905, 292674]]}, [67785]], ['six-month term', {'start': 1400, 'end': 1582, 'annual': 108639, 'endorsements': [[1481, 441832], [1570, 418671]]}, [184904, -1527]], ['endorsement on expiry rejected', {'start': 936, 'end': 1301, 'annual': 206524, 'endorsements': [[1301, 200000]]}, 'invalid endorsement date'], ['endorsement before inception rejected', {'start': 983, 'end': 1348, 'annual': 294557, 'endorsements': [[982, 200000]]}, 'invalid endorsement date'], ['out of order rejected', {'start': 1953, 'end': 2318, 'annual': 262141, 'endorsements': [[2153, 200000], [2053, 250000]]}, 'invalid endorsement date'], ['inception-day endorsement', {'start': 2741, 'end': 3106, 'annual': 192566, 'endorsements': [[2741, 174344]]}, [-18222]], ['same-day endorsements', {'start': 114, 'end': 479, 'annual': 252584, 'endorsements': [[234, 250000], [234, 260000]]}, [-1734, 6712]], ['last day endorsement', {'start': 1695, 'end': 2060, 'annual': 100000, 'endorsements': [[2059, 111498]]}, [32]]]]
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:
Additional premiums are one day too large.

Input start, end (days), annual premium, endorsements [[effective day, new annual premium]]. Dates must satisfy start<=d<end and be non-decreasing, else 'invalid endorsement date'. Each endorsement charges (new-current)*(end-d)/(end-start) rounded half away from zero, and the new premium becomes current.

split: open-access