broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    gross = 0
    dw = 0
    di = 0.0
    for kind, wt, idx in x['changes']:
        s = 1 if kind == 'add' else -1
        gross += wt
        dw += s * wt
        di += s * idx
    if abs(dw) > x['max_lmc_weight'] or abs(di) > x['max_lmc_index']: return 'NEW_LOADSHEET'
    tow = x['tow'] + dw
    ti = x['index'] + di
    lo, hi = x['index_limits']
    if tow > x['mtow'] or ti < lo or ti > hi: return 'NEW_LOADSHEET'
    return ['LMC', tow, round(ti, 1)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['two late passengers', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 171, 1.5], ['add', 85, 0.8]]}, ['LMC', 68256, 54.3]], ['swap cancels net', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 300, 2.0], ['remove', 291, 1.9]]}, 'NEW_LOADSHEET'], ['exactly at weight tolerance', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 250, 1.0], ['add', 250, 1.0]]}, ['LMC', 68500, 54.0]], ['offload moves index', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 200, 3.1]]}, ['LMC', 67800, 48.9]], ['change pushes over MTOW', {'tow': 69900, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 151, 0.5]]}, 'NEW_LOADSHEET'], ['change pushes index out', {'tow': 68000, 'mtow': 70000, 'index': 68.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 100, 2.1]]}, 'NEW_LOADSHEET'], ['already heavy then offload', {'tow': 70200, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 150, 0.5]]}, 'NEW_LOADSHEET'], ['sampled case 1', {'tow': 64100, 'mtow': 70000, 'index': 45.9, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 3.0, 'changes': [['remove', 180, 3.4], ['remove', 155, -2.5], ['add', 35, -3.5], ['add', 345, 3.7]]}, 'NEW_LOADSHEET'], ['sampled case 2', {'tow': 68550, 'mtow': 70000, 'index': 33.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 400, 'max_lmc_index': 3.0, 'changes': [['add', 340, -1.0], ['remove', 260, 1.2]]}, 'NEW_LOADSHEET'], ['sampled case 3', {'tow': 61300, 'mtow': 70000, 'index': 42.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 400, 'max_lmc_index': 3.0, 'changes': [['add', 350, -3.5], ['remove', 30, -2.6], ['add', 230, 1.5]]}, 'NEW_LOADSHEET']], [['two late passengers', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 172, 1.5], ['add', 85, 0.8]]}, ['LMC', 68257, 54.3]], ['swap cancels net', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 300, 2.0], ['remove', 292, 1.9]]}, 'NEW_LOADSHEET'], ['exactly at weight tolerance', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 250, 1.0], ['add', 250, 1.0]]}, ['LMC', 68500, 54.0]], ['offload moves index', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 200, 3.2]]}, ['LMC', 67800, 48.8]], ['change pushes over MTOW', {'tow': 69900, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 152, 0.5]]}, 'NEW_LOADSHEET'], ['change pushes index out', {'tow': 68000, 'mtow': 70000, 'index': 68.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 100, 2.2]]}, 'NEW_LOADSHEET'], ['already heavy then offload', {'tow': 70200, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 150, 1.0]]}, 'NEW_LOADSHEET'], ['sampled case 1', {'tow': 68750, 'mtow': 70000, 'index': 62.6, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 3.0, 'changes': [['add', 275, -2.1], ['add', 25, -1.8]]}, 'NEW_LOADSHEET'], ['sampled case 2', {'tow': 64950, 'mtow': 70000, 'index': 44.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 600, 'max_lmc_index': 3.0, 'changes': [['add', 385, 2.3]]}, ['LMC', 65335, 46.8]], ['sampled case 3', {'tow': 65950, 'mtow': 70000, 'index': 59.8, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 3.0, 'changes': [['remove', 170, 1.7]]}, ['LMC', 65780, 58.1]]], [['two late passengers', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 173, 1.5], ['add', 85, 0.8]]}, ['LMC', 68258, 54.3]], ['swap cancels net', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 300, 2.0], ['remove', 293, 1.9]]}, 'NEW_LOADSHEET'], ['exactly at weight tolerance', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 250, 1.0], ['add', 250, 1.0]]}, ['LMC', 68500, 54.0]], ['offload moves index', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 200, 3.3]]}, ['LMC', 67800, 48.7]], ['change pushes over MTOW', {'tow': 69900, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 153, 0.5]]}, 'NEW_LOADSHEET'], ['change pushes index out', {'tow': 68000, 'mtow': 70000, 'index': 68.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 100, 2.3]]}, 'NEW_LOADSHEET'], ['already heavy then offload', {'tow': 70200, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 150, 1.5]]}, 'NEW_LOADSHEET'], ['sampled case 1', {'tow': 64750, 'mtow': 70000, 'index': 33.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 3.0, 'changes': [['remove', 20, 2.4], ['remove', 125, -3.9], ['remove', 190, 3.9], ['remove', 270, 3.3]]}, 'NEW_LOADSHEET'], ['sampled case 2', {'tow': 63200, 'mtow': 70000, 'index': 47.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 400, 'max_lmc_index': 5.0, 'changes': [['remove', 335, -0.9], ['add', 105, 3.3]]}, 'NEW_LOADSHEET'], ['sampled case 3', {'tow': 66200, 'mtow': 70000, 'index': 38.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 400, 'max_lmc_index': 3.0, 'changes': [['add', 150, -0.8], ['add', 95, 1.5], ['add', 140, -2.4], ['add', 150, -0.8]]}, 'NEW_LOADSHEET']], [['two late passengers', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 174, 1.5], ['add', 85, 0.8]]}, ['LMC', 68259, 54.3]], ['swap cancels net', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 300, 2.0], ['remove', 294, 1.9]]}, 'NEW_LOADSHEET'], ['exactly at weight tolerance', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 250, 1.0], ['add', 250, 1.0]]}, ['LMC', 68500, 54.0]], ['offload moves index', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 200, 3.4]]}, ['LMC', 67800, 48.6]], ['change pushes over MTOW', {'tow': 69900, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 154, 0.5]]}, 'NEW_LOADSHEET'], ['change pushes index out', {'tow': 68000, 'mtow': 70000, 'index': 68.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 100, 2.4]]}, 'NEW_LOADSHEET'], ['already heavy then offload', {'tow': 70200, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 150, 2.0]]}, 'NEW_LOADSHEET'], ['sampled case 1', {'tow': 66150, 'mtow': 70000, 'index': 46.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 400, 'max_lmc_index': 3.0, 'changes': [['add', 390, 0.4], ['remove', 40, 2.1], ['add', 300, 3.5]]}, 'NEW_LOADSHEET'], ['sampled case 2', {'tow': 64000, 'mtow': 70000, 'index': 30.4, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 3.0, 'changes': [['remove', 350, 3.5], ['remove', 60, 0.9]]}, 'NEW_LOADSHEET'], ['sampled case 3', {'tow': 60650, 'mtow': 70000, 'index': 63.7, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 295, -2.6]]}, ['LMC', 60945, 61.1]]], [['two late passengers', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 175, 1.5], ['add', 85, 0.8]]}, ['LMC', 68260, 54.3]], ['swap cancels net', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 300, 2.0], ['remove', 295, 1.9]]}, 'NEW_LOADSHEET'], ['exactly at weight tolerance', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 250, 1.0], ['add', 250, 1.0]]}, ['LMC', 68500, 54.0]], ['offload moves index', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 200, 3.5]]}, ['LMC', 67800, 48.5]], ['change pushes over MTOW', {'tow': 69900, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 155, 0.5]]}, 'NEW_LOADSHEET'], ['change pushes index out', {'tow': 68000, 'mtow': 70000, 'index': 68.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 100, 2.5]]}, 'NEW_LOADSHEET'], ['already heavy then offload', {'tow': 70200, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 150, 2.5]]}, 'NEW_LOADSHEET'], ['sampled case 1', {'tow': 69850, 'mtow': 70000, 'index': 46.3, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 600, 'max_lmc_index': 5.0, 'changes': [['add', 195, -0.8], ['add', 240, -1.5]]}, 'NEW_LOADSHEET'], ['sampled case 2', {'tow': 69600, 'mtow': 70000, 'index': 31.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 600, 'max_lmc_index': 3.0, 'changes': [['add', 180, 3.5], ['remove', 165, 3.5]]}, ['LMC', 69615, 31.5]], ['sampled case 3', {'tow': 61550, 'mtow': 70000, 'index': 46.4, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 600, 'max_lmc_index': 5.0, 'changes': [['remove', 340, 1.9], ['remove', 260, -0.5]]}, ['LMC', 60950, 45.0]]]]
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

N = 1
observations = []
def solve(x):
    gross = 0
    dw = 0
    di = 0.0
    for kind, wt, idx in x['changes']:
        s = 1 if kind == 'add' else -1
        gross += wt if s > 0 else 0
        dw += s * wt
        di += s * idx
    if gross > x['max_lmc_weight'] or abs(di) > x['max_lmc_index']: return 'NEW_LOADSHEET'
    tow = x['tow'] + dw
    ti = x['index'] + di
    lo, hi = x['index_limits']
    if tow > x['mtow'] or ti < lo or ti > hi: return 'NEW_LOADSHEET'
    return ['LMC', tow, round(ti, 1)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['two late passengers', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 171, 1.5], ['add', 85, 0.8]]}, ['LMC', 68256, 54.3]], ['swap cancels net', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 300, 2.0], ['remove', 291, 1.9]]}, 'NEW_LOADSHEET'], ['exactly at weight tolerance', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 250, 1.0], ['add', 250, 1.0]]}, ['LMC', 68500, 54.0]], ['offload moves index', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 200, 3.1]]}, ['LMC', 67800, 48.9]], ['change pushes over MTOW', {'tow': 69900, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 151, 0.5]]}, 'NEW_LOADSHEET'], ['change pushes index out', {'tow': 68000, 'mtow': 70000, 'index': 68.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 100, 2.1]]}, 'NEW_LOADSHEET'], ['already heavy then offload', {'tow': 70200, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 150, 0.5]]}, 'NEW_LOADSHEET'], ['sampled case 1', {'tow': 64100, 'mtow': 70000, 'index': 45.9, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 3.0, 'changes': [['remove', 180, 3.4], ['remove', 155, -2.5], ['add', 35, -3.5], ['add', 345, 3.7]]}, 'NEW_LOADSHEET'], ['sampled case 2', {'tow': 68550, 'mtow': 70000, 'index': 33.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 400, 'max_lmc_index': 3.0, 'changes': [['add', 340, -1.0], ['remove', 260, 1.2]]}, 'NEW_LOADSHEET'], ['sampled case 3', {'tow': 61300, 'mtow': 70000, 'index': 42.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 400, 'max_lmc_index': 3.0, 'changes': [['add', 350, -3.5], ['remove', 30, -2.6], ['add', 230, 1.5]]}, 'NEW_LOADSHEET']], [['two late passengers', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 172, 1.5], ['add', 85, 0.8]]}, ['LMC', 68257, 54.3]], ['swap cancels net', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 300, 2.0], ['remove', 292, 1.9]]}, 'NEW_LOADSHEET'], ['exactly at weight tolerance', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 250, 1.0], ['add', 250, 1.0]]}, ['LMC', 68500, 54.0]], ['offload moves index', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 200, 3.2]]}, ['LMC', 67800, 48.8]], ['change pushes over MTOW', {'tow': 69900, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 152, 0.5]]}, 'NEW_LOADSHEET'], ['change pushes index out', {'tow': 68000, 'mtow': 70000, 'index': 68.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 100, 2.2]]}, 'NEW_LOADSHEET'], ['already heavy then offload', {'tow': 70200, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 150, 1.0]]}, 'NEW_LOADSHEET'], ['sampled case 1', {'tow': 68750, 'mtow': 70000, 'index': 62.6, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 3.0, 'changes': [['add', 275, -2.1], ['add', 25, -1.8]]}, 'NEW_LOADSHEET'], ['sampled case 2', {'tow': 64950, 'mtow': 70000, 'index': 44.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 600, 'max_lmc_index': 3.0, 'changes': [['add', 385, 2.3]]}, ['LMC', 65335, 46.8]], ['sampled case 3', {'tow': 65950, 'mtow': 70000, 'index': 59.8, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 3.0, 'changes': [['remove', 170, 1.7]]}, ['LMC', 65780, 58.1]]], [['two late passengers', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 173, 1.5], ['add', 85, 0.8]]}, ['LMC', 68258, 54.3]], ['swap cancels net', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 300, 2.0], ['remove', 293, 1.9]]}, 'NEW_LOADSHEET'], ['exactly at weight tolerance', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 250, 1.0], ['add', 250, 1.0]]}, ['LMC', 68500, 54.0]], ['offload moves index', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 200, 3.3]]}, ['LMC', 67800, 48.7]], ['change pushes over MTOW', {'tow': 69900, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 153, 0.5]]}, 'NEW_LOADSHEET'], ['change pushes index out', {'tow': 68000, 'mtow': 70000, 'index': 68.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 100, 2.3]]}, 'NEW_LOADSHEET'], ['already heavy then offload', {'tow': 70200, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 150, 1.5]]}, 'NEW_LOADSHEET'], ['sampled case 1', {'tow': 64750, 'mtow': 70000, 'index': 33.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 3.0, 'changes': [['remove', 20, 2.4], ['remove', 125, -3.9], ['remove', 190, 3.9], ['remove', 270, 3.3]]}, 'NEW_LOADSHEET'], ['sampled case 2', {'tow': 63200, 'mtow': 70000, 'index': 47.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 400, 'max_lmc_index': 5.0, 'changes': [['remove', 335, -0.9], ['add', 105, 3.3]]}, 'NEW_LOADSHEET'], ['sampled case 3', {'tow': 66200, 'mtow': 70000, 'index': 38.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 400, 'max_lmc_index': 3.0, 'changes': [['add', 150, -0.8], ['add', 95, 1.5], ['add', 140, -2.4], ['add', 150, -0.8]]}, 'NEW_LOADSHEET']], [['two late passengers', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 174, 1.5], ['add', 85, 0.8]]}, ['LMC', 68259, 54.3]], ['swap cancels net', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 300, 2.0], ['remove', 294, 1.9]]}, 'NEW_LOADSHEET'], ['exactly at weight tolerance', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 250, 1.0], ['add', 250, 1.0]]}, ['LMC', 68500, 54.0]], ['offload moves index', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 200, 3.4]]}, ['LMC', 67800, 48.6]], ['change pushes over MTOW', {'tow': 69900, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 154, 0.5]]}, 'NEW_LOADSHEET'], ['change pushes index out', {'tow': 68000, 'mtow': 70000, 'index': 68.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 100, 2.4]]}, 'NEW_LOADSHEET'], ['already heavy then offload', {'tow': 70200, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 150, 2.0]]}, 'NEW_LOADSHEET'], ['sampled case 1', {'tow': 66150, 'mtow': 70000, 'index': 46.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 400, 'max_lmc_index': 3.0, 'changes': [['add', 390, 0.4], ['remove', 40, 2.1], ['add', 300, 3.5]]}, 'NEW_LOADSHEET'], ['sampled case 2', {'tow': 64000, 'mtow': 70000, 'index': 30.4, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 3.0, 'changes': [['remove', 350, 3.5], ['remove', 60, 0.9]]}, 'NEW_LOADSHEET'], ['sampled case 3', {'tow': 60650, 'mtow': 70000, 'index': 63.7, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 295, -2.6]]}, ['LMC', 60945, 61.1]]], [['two late passengers', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 175, 1.5], ['add', 85, 0.8]]}, ['LMC', 68260, 54.3]], ['swap cancels net', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 300, 2.0], ['remove', 295, 1.9]]}, 'NEW_LOADSHEET'], ['exactly at weight tolerance', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 250, 1.0], ['add', 250, 1.0]]}, ['LMC', 68500, 54.0]], ['offload moves index', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 200, 3.5]]}, ['LMC', 67800, 48.5]], ['change pushes over MTOW', {'tow': 69900, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 155, 0.5]]}, 'NEW_LOADSHEET'], ['change pushes index out', {'tow': 68000, 'mtow': 70000, 'index': 68.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 100, 2.5]]}, 'NEW_LOADSHEET'], ['already heavy then offload', {'tow': 70200, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 150, 2.5]]}, 'NEW_LOADSHEET'], ['sampled case 1', {'tow': 69850, 'mtow': 70000, 'index': 46.3, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 600, 'max_lmc_index': 5.0, 'changes': [['add', 195, -0.8], ['add', 240, -1.5]]}, 'NEW_LOADSHEET'], ['sampled case 2', {'tow': 69600, 'mtow': 70000, 'index': 31.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 600, 'max_lmc_index': 3.0, 'changes': [['add', 180, 3.5], ['remove', 165, 3.5]]}, ['LMC', 69615, 31.5]], ['sampled case 3', {'tow': 61550, 'mtow': 70000, 'index': 46.4, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 600, 'max_lmc_index': 5.0, 'changes': [['remove', 340, 1.9], ['remove', 260, -0.5]]}, ['LMC', 60950, 45.0]]]]
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:
Swapping 300 kg of cargo for 290 kg is annotated as an LMC instead of requiring a new loadsheet.

Input {'tow','mtow','index','index_limits','max_lmc_weight','max_lmc_index','changes':[['add'|'remove', kg, index effect of adding]]}. The weight tolerance applies to the gross sum of all changed weights (<= limit allowed); removals negate weight and index; |net index| <= limit. Then new TOW <= MTOW and new index within inclusive limits, else 'NEW_LOADSHEET'. Return ['LMC', new TOW, new index r1].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    gross = 0
    dw = 0
    di = 0.0
    for kind, wt, idx in x['changes']:
        s = 1 if kind == 'add' else -1
        gross += wt
        dw += s * wt
        di += idx
    if gross > x['max_lmc_weight'] or abs(di) > x['max_lmc_index']: return 'NEW_LOADSHEET'
    tow = x['tow'] + dw
    ti = x['index'] + di
    lo, hi = x['index_limits']
    if tow > x['mtow'] or ti < lo or ti > hi: return 'NEW_LOADSHEET'
    return ['LMC', tow, round(ti, 1)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['two late passengers', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 171, 1.5], ['add', 85, 0.8]]}, ['LMC', 68256, 54.3]], ['swap cancels net', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 300, 2.0], ['remove', 291, 1.9]]}, 'NEW_LOADSHEET'], ['exactly at weight tolerance', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 250, 1.0], ['add', 250, 1.0]]}, ['LMC', 68500, 54.0]], ['offload moves index', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 200, 3.1]]}, ['LMC', 67800, 48.9]], ['change pushes over MTOW', {'tow': 69900, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 151, 0.5]]}, 'NEW_LOADSHEET'], ['change pushes index out', {'tow': 68000, 'mtow': 70000, 'index': 68.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 100, 2.1]]}, 'NEW_LOADSHEET'], ['already heavy then offload', {'tow': 70200, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 150, 0.5]]}, 'NEW_LOADSHEET'], ['sampled case 1', {'tow': 64100, 'mtow': 70000, 'index': 45.9, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 3.0, 'changes': [['remove', 180, 3.4], ['remove', 155, -2.5], ['add', 35, -3.5], ['add', 345, 3.7]]}, 'NEW_LOADSHEET'], ['sampled case 2', {'tow': 68550, 'mtow': 70000, 'index': 33.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 400, 'max_lmc_index': 3.0, 'changes': [['add', 340, -1.0], ['remove', 260, 1.2]]}, 'NEW_LOADSHEET'], ['sampled case 3', {'tow': 61300, 'mtow': 70000, 'index': 42.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 400, 'max_lmc_index': 3.0, 'changes': [['add', 350, -3.5], ['remove', 30, -2.6], ['add', 230, 1.5]]}, 'NEW_LOADSHEET']], [['two late passengers', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 172, 1.5], ['add', 85, 0.8]]}, ['LMC', 68257, 54.3]], ['swap cancels net', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 300, 2.0], ['remove', 292, 1.9]]}, 'NEW_LOADSHEET'], ['exactly at weight tolerance', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 250, 1.0], ['add', 250, 1.0]]}, ['LMC', 68500, 54.0]], ['offload moves index', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 200, 3.2]]}, ['LMC', 67800, 48.8]], ['change pushes over MTOW', {'tow': 69900, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 152, 0.5]]}, 'NEW_LOADSHEET'], ['change pushes index out', {'tow': 68000, 'mtow': 70000, 'index': 68.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 100, 2.2]]}, 'NEW_LOADSHEET'], ['already heavy then offload', {'tow': 70200, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 150, 1.0]]}, 'NEW_LOADSHEET'], ['sampled case 1', {'tow': 68750, 'mtow': 70000, 'index': 62.6, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 3.0, 'changes': [['add', 275, -2.1], ['add', 25, -1.8]]}, 'NEW_LOADSHEET'], ['sampled case 2', {'tow': 64950, 'mtow': 70000, 'index': 44.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 600, 'max_lmc_index': 3.0, 'changes': [['add', 385, 2.3]]}, ['LMC', 65335, 46.8]], ['sampled case 3', {'tow': 65950, 'mtow': 70000, 'index': 59.8, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 3.0, 'changes': [['remove', 170, 1.7]]}, ['LMC', 65780, 58.1]]], [['two late passengers', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 173, 1.5], ['add', 85, 0.8]]}, ['LMC', 68258, 54.3]], ['swap cancels net', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 300, 2.0], ['remove', 293, 1.9]]}, 'NEW_LOADSHEET'], ['exactly at weight tolerance', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 250, 1.0], ['add', 250, 1.0]]}, ['LMC', 68500, 54.0]], ['offload moves index', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 200, 3.3]]}, ['LMC', 67800, 48.7]], ['change pushes over MTOW', {'tow': 69900, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 153, 0.5]]}, 'NEW_LOADSHEET'], ['change pushes index out', {'tow': 68000, 'mtow': 70000, 'index': 68.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 100, 2.3]]}, 'NEW_LOADSHEET'], ['already heavy then offload', {'tow': 70200, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 150, 1.5]]}, 'NEW_LOADSHEET'], ['sampled case 1', {'tow': 64750, 'mtow': 70000, 'index': 33.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 3.0, 'changes': [['remove', 20, 2.4], ['remove', 125, -3.9], ['remove', 190, 3.9], ['remove', 270, 3.3]]}, 'NEW_LOADSHEET'], ['sampled case 2', {'tow': 63200, 'mtow': 70000, 'index': 47.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 400, 'max_lmc_index': 5.0, 'changes': [['remove', 335, -0.9], ['add', 105, 3.3]]}, 'NEW_LOADSHEET'], ['sampled case 3', {'tow': 66200, 'mtow': 70000, 'index': 38.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 400, 'max_lmc_index': 3.0, 'changes': [['add', 150, -0.8], ['add', 95, 1.5], ['add', 140, -2.4], ['add', 150, -0.8]]}, 'NEW_LOADSHEET']], [['two late passengers', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 174, 1.5], ['add', 85, 0.8]]}, ['LMC', 68259, 54.3]], ['swap cancels net', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 300, 2.0], ['remove', 294, 1.9]]}, 'NEW_LOADSHEET'], ['exactly at weight tolerance', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 250, 1.0], ['add', 250, 1.0]]}, ['LMC', 68500, 54.0]], ['offload moves index', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 200, 3.4]]}, ['LMC', 67800, 48.6]], ['change pushes over MTOW', {'tow': 69900, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 154, 0.5]]}, 'NEW_LOADSHEET'], ['change pushes index out', {'tow': 68000, 'mtow': 70000, 'index': 68.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 100, 2.4]]}, 'NEW_LOADSHEET'], ['already heavy then offload', {'tow': 70200, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 150, 2.0]]}, 'NEW_LOADSHEET'], ['sampled case 1', {'tow': 66150, 'mtow': 70000, 'index': 46.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 400, 'max_lmc_index': 3.0, 'changes': [['add', 390, 0.4], ['remove', 40, 2.1], ['add', 300, 3.5]]}, 'NEW_LOADSHEET'], ['sampled case 2', {'tow': 64000, 'mtow': 70000, 'index': 30.4, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 3.0, 'changes': [['remove', 350, 3.5], ['remove', 60, 0.9]]}, 'NEW_LOADSHEET'], ['sampled case 3', {'tow': 60650, 'mtow': 70000, 'index': 63.7, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 295, -2.6]]}, ['LMC', 60945, 61.1]]], [['two late passengers', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 175, 1.5], ['add', 85, 0.8]]}, ['LMC', 68260, 54.3]], ['swap cancels net', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 300, 2.0], ['remove', 295, 1.9]]}, 'NEW_LOADSHEET'], ['exactly at weight tolerance', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 250, 1.0], ['add', 250, 1.0]]}, ['LMC', 68500, 54.0]], ['offload moves index', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 200, 3.5]]}, ['LMC', 67800, 48.5]], ['change pushes over MTOW', {'tow': 69900, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 155, 0.5]]}, 'NEW_LOADSHEET'], ['change pushes index out', {'tow': 68000, 'mtow': 70000, 'index': 68.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 100, 2.5]]}, 'NEW_LOADSHEET'], ['already heavy then offload', {'tow': 70200, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 150, 2.5]]}, 'NEW_LOADSHEET'], ['sampled case 1', {'tow': 69850, 'mtow': 70000, 'index': 46.3, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 600, 'max_lmc_index': 5.0, 'changes': [['add', 195, -0.8], ['add', 240, -1.5]]}, 'NEW_LOADSHEET'], ['sampled case 2', {'tow': 69600, 'mtow': 70000, 'index': 31.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 600, 'max_lmc_index': 3.0, 'changes': [['add', 180, 3.5], ['remove', 165, 3.5]]}, ['LMC', 69615, 31.5]], ['sampled case 3', {'tow': 61550, 'mtow': 70000, 'index': 46.4, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 600, 'max_lmc_index': 5.0, 'changes': [['remove', 340, 1.9], ['remove', 260, -0.5]]}, ['LMC', 60950, 45.0]]]]
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

N = 1
observations = []
def solve(x):
    gross = 0
    dw = 0
    di = 0.0
    for kind, wt, idx in x['changes']:
        s = 1 if kind == 'add' else -1
        gross += wt
        dw += s * wt
        di -= s * idx
    if gross > x['max_lmc_weight'] or abs(di) > x['max_lmc_index']: return 'NEW_LOADSHEET'
    tow = x['tow'] + dw
    ti = x['index'] + di
    lo, hi = x['index_limits']
    if tow > x['mtow'] or ti < lo or ti > hi: return 'NEW_LOADSHEET'
    return ['LMC', tow, round(ti, 1)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['two late passengers', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 171, 1.5], ['add', 85, 0.8]]}, ['LMC', 68256, 54.3]], ['swap cancels net', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 300, 2.0], ['remove', 291, 1.9]]}, 'NEW_LOADSHEET'], ['exactly at weight tolerance', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 250, 1.0], ['add', 250, 1.0]]}, ['LMC', 68500, 54.0]], ['offload moves index', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 200, 3.1]]}, ['LMC', 67800, 48.9]], ['change pushes over MTOW', {'tow': 69900, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 151, 0.5]]}, 'NEW_LOADSHEET'], ['change pushes index out', {'tow': 68000, 'mtow': 70000, 'index': 68.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 100, 2.1]]}, 'NEW_LOADSHEET'], ['already heavy then offload', {'tow': 70200, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 150, 0.5]]}, 'NEW_LOADSHEET'], ['sampled case 1', {'tow': 64100, 'mtow': 70000, 'index': 45.9, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 3.0, 'changes': [['remove', 180, 3.4], ['remove', 155, -2.5], ['add', 35, -3.5], ['add', 345, 3.7]]}, 'NEW_LOADSHEET'], ['sampled case 2', {'tow': 68550, 'mtow': 70000, 'index': 33.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 400, 'max_lmc_index': 3.0, 'changes': [['add', 340, -1.0], ['remove', 260, 1.2]]}, 'NEW_LOADSHEET'], ['sampled case 3', {'tow': 61300, 'mtow': 70000, 'index': 42.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 400, 'max_lmc_index': 3.0, 'changes': [['add', 350, -3.5], ['remove', 30, -2.6], ['add', 230, 1.5]]}, 'NEW_LOADSHEET']], [['two late passengers', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 172, 1.5], ['add', 85, 0.8]]}, ['LMC', 68257, 54.3]], ['swap cancels net', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 300, 2.0], ['remove', 292, 1.9]]}, 'NEW_LOADSHEET'], ['exactly at weight tolerance', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 250, 1.0], ['add', 250, 1.0]]}, ['LMC', 68500, 54.0]], ['offload moves index', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 200, 3.2]]}, ['LMC', 67800, 48.8]], ['change pushes over MTOW', {'tow': 69900, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 152, 0.5]]}, 'NEW_LOADSHEET'], ['change pushes index out', {'tow': 68000, 'mtow': 70000, 'index': 68.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 100, 2.2]]}, 'NEW_LOADSHEET'], ['already heavy then offload', {'tow': 70200, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 150, 1.0]]}, 'NEW_LOADSHEET'], ['sampled case 1', {'tow': 68750, 'mtow': 70000, 'index': 62.6, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 3.0, 'changes': [['add', 275, -2.1], ['add', 25, -1.8]]}, 'NEW_LOADSHEET'], ['sampled case 2', {'tow': 64950, 'mtow': 70000, 'index': 44.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 600, 'max_lmc_index': 3.0, 'changes': [['add', 385, 2.3]]}, ['LMC', 65335, 46.8]], ['sampled case 3', {'tow': 65950, 'mtow': 70000, 'index': 59.8, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 3.0, 'changes': [['remove', 170, 1.7]]}, ['LMC', 65780, 58.1]]], [['two late passengers', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 173, 1.5], ['add', 85, 0.8]]}, ['LMC', 68258, 54.3]], ['swap cancels net', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 300, 2.0], ['remove', 293, 1.9]]}, 'NEW_LOADSHEET'], ['exactly at weight tolerance', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 250, 1.0], ['add', 250, 1.0]]}, ['LMC', 68500, 54.0]], ['offload moves index', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 200, 3.3]]}, ['LMC', 67800, 48.7]], ['change pushes over MTOW', {'tow': 69900, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 153, 0.5]]}, 'NEW_LOADSHEET'], ['change pushes index out', {'tow': 68000, 'mtow': 70000, 'index': 68.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 100, 2.3]]}, 'NEW_LOADSHEET'], ['already heavy then offload', {'tow': 70200, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 150, 1.5]]}, 'NEW_LOADSHEET'], ['sampled case 1', {'tow': 64750, 'mtow': 70000, 'index': 33.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 3.0, 'changes': [['remove', 20, 2.4], ['remove', 125, -3.9], ['remove', 190, 3.9], ['remove', 270, 3.3]]}, 'NEW_LOADSHEET'], ['sampled case 2', {'tow': 63200, 'mtow': 70000, 'index': 47.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 400, 'max_lmc_index': 5.0, 'changes': [['remove', 335, -0.9], ['add', 105, 3.3]]}, 'NEW_LOADSHEET'], ['sampled case 3', {'tow': 66200, 'mtow': 70000, 'index': 38.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 400, 'max_lmc_index': 3.0, 'changes': [['add', 150, -0.8], ['add', 95, 1.5], ['add', 140, -2.4], ['add', 150, -0.8]]}, 'NEW_LOADSHEET']], [['two late passengers', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 174, 1.5], ['add', 85, 0.8]]}, ['LMC', 68259, 54.3]], ['swap cancels net', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 300, 2.0], ['remove', 294, 1.9]]}, 'NEW_LOADSHEET'], ['exactly at weight tolerance', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 250, 1.0], ['add', 250, 1.0]]}, ['LMC', 68500, 54.0]], ['offload moves index', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 200, 3.4]]}, ['LMC', 67800, 48.6]], ['change pushes over MTOW', {'tow': 69900, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 154, 0.5]]}, 'NEW_LOADSHEET'], ['change pushes index out', {'tow': 68000, 'mtow': 70000, 'index': 68.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 100, 2.4]]}, 'NEW_LOADSHEET'], ['already heavy then offload', {'tow': 70200, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 150, 2.0]]}, 'NEW_LOADSHEET'], ['sampled case 1', {'tow': 66150, 'mtow': 70000, 'index': 46.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 400, 'max_lmc_index': 3.0, 'changes': [['add', 390, 0.4], ['remove', 40, 2.1], ['add', 300, 3.5]]}, 'NEW_LOADSHEET'], ['sampled case 2', {'tow': 64000, 'mtow': 70000, 'index': 30.4, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 3.0, 'changes': [['remove', 350, 3.5], ['remove', 60, 0.9]]}, 'NEW_LOADSHEET'], ['sampled case 3', {'tow': 60650, 'mtow': 70000, 'index': 63.7, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 295, -2.6]]}, ['LMC', 60945, 61.1]]], [['two late passengers', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 175, 1.5], ['add', 85, 0.8]]}, ['LMC', 68260, 54.3]], ['swap cancels net', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 300, 2.0], ['remove', 295, 1.9]]}, 'NEW_LOADSHEET'], ['exactly at weight tolerance', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 250, 1.0], ['add', 250, 1.0]]}, ['LMC', 68500, 54.0]], ['offload moves index', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 200, 3.5]]}, ['LMC', 67800, 48.5]], ['change pushes over MTOW', {'tow': 69900, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 155, 0.5]]}, 'NEW_LOADSHEET'], ['change pushes index out', {'tow': 68000, 'mtow': 70000, 'index': 68.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 100, 2.5]]}, 'NEW_LOADSHEET'], ['already heavy then offload', {'tow': 70200, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 150, 2.5]]}, 'NEW_LOADSHEET'], ['sampled case 1', {'tow': 69850, 'mtow': 70000, 'index': 46.3, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 600, 'max_lmc_index': 5.0, 'changes': [['add', 195, -0.8], ['add', 240, -1.5]]}, 'NEW_LOADSHEET'], ['sampled case 2', {'tow': 69600, 'mtow': 70000, 'index': 31.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 600, 'max_lmc_index': 3.0, 'changes': [['add', 180, 3.5], ['remove', 165, 3.5]]}, ['LMC', 69615, 31.5]], ['sampled case 3', {'tow': 61550, 'mtow': 70000, 'index': 46.4, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 600, 'max_lmc_index': 5.0, 'changes': [['remove', 340, 1.9], ['remove', 260, -0.5]]}, ['LMC', 60950, 45.0]]]]
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:
Offloading a forward bag moves the index the same way as loading it.

Input {'tow','mtow','index','index_limits','max_lmc_weight','max_lmc_index','changes':[['add'|'remove', kg, index effect of adding]]}. The weight tolerance applies to the gross sum of all changed weights (<= limit allowed); removals negate weight and index; |net index| <= limit. Then new TOW <= MTOW and new index within inclusive limits, else 'NEW_LOADSHEET'. Return ['LMC', new TOW, new index r1].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    gross = 0
    dw = 0
    di = 0.0
    for kind, wt, idx in x['changes']:
        s = 1 if kind == 'add' else -1
        gross += wt
        dw += s * wt
        di += s * idx
    if gross >= x['max_lmc_weight'] or abs(di) > x['max_lmc_index']: return 'NEW_LOADSHEET'
    tow = x['tow'] + dw
    ti = x['index'] + di
    lo, hi = x['index_limits']
    if tow > x['mtow'] or ti < lo or ti > hi: return 'NEW_LOADSHEET'
    return ['LMC', tow, round(ti, 1)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['two late passengers', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 171, 1.5], ['add', 85, 0.8]]}, ['LMC', 68256, 54.3]], ['swap cancels net', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 300, 2.0], ['remove', 291, 1.9]]}, 'NEW_LOADSHEET'], ['exactly at weight tolerance', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 250, 1.0], ['add', 250, 1.0]]}, ['LMC', 68500, 54.0]], ['offload moves index', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 200, 3.1]]}, ['LMC', 67800, 48.9]], ['change pushes over MTOW', {'tow': 69900, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 151, 0.5]]}, 'NEW_LOADSHEET'], ['change pushes index out', {'tow': 68000, 'mtow': 70000, 'index': 68.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 100, 2.1]]}, 'NEW_LOADSHEET'], ['already heavy then offload', {'tow': 70200, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 150, 0.5]]}, 'NEW_LOADSHEET'], ['sampled case 1', {'tow': 64100, 'mtow': 70000, 'index': 45.9, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 3.0, 'changes': [['remove', 180, 3.4], ['remove', 155, -2.5], ['add', 35, -3.5], ['add', 345, 3.7]]}, 'NEW_LOADSHEET'], ['sampled case 2', {'tow': 68550, 'mtow': 70000, 'index': 33.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 400, 'max_lmc_index': 3.0, 'changes': [['add', 340, -1.0], ['remove', 260, 1.2]]}, 'NEW_LOADSHEET'], ['sampled case 3', {'tow': 61300, 'mtow': 70000, 'index': 42.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 400, 'max_lmc_index': 3.0, 'changes': [['add', 350, -3.5], ['remove', 30, -2.6], ['add', 230, 1.5]]}, 'NEW_LOADSHEET'], ['regression: weight tolerance boundary', {'tow': 62750, 'mtow': 70000, 'index': 35.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 600, 'max_lmc_index': 5.0, 'changes': [['remove', 185, -0.9], ['remove', 65, 3.5], ['remove', 300, 2.4]]}, ['LMC', 62200, 30.1]]], [['two late passengers', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 172, 1.5], ['add', 85, 0.8]]}, ['LMC', 68257, 54.3]], ['swap cancels net', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 300, 2.0], ['remove', 292, 1.9]]}, 'NEW_LOADSHEET'], ['exactly at weight tolerance', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 250, 1.0], ['add', 250, 1.0]]}, ['LMC', 68500, 54.0]], ['offload moves index', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 200, 3.2]]}, ['LMC', 67800, 48.8]], ['change pushes over MTOW', {'tow': 69900, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 152, 0.5]]}, 'NEW_LOADSHEET'], ['change pushes index out', {'tow': 68000, 'mtow': 70000, 'index': 68.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 100, 2.2]]}, 'NEW_LOADSHEET'], ['already heavy then offload', {'tow': 70200, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 150, 1.0]]}, 'NEW_LOADSHEET'], ['sampled case 1', {'tow': 68750, 'mtow': 70000, 'index': 62.6, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 3.0, 'changes': [['add', 275, -2.1], ['add', 25, -1.8]]}, 'NEW_LOADSHEET'], ['sampled case 2', {'tow': 64950, 'mtow': 70000, 'index': 44.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 600, 'max_lmc_index': 3.0, 'changes': [['add', 385, 2.3]]}, ['LMC', 65335, 46.8]], ['sampled case 3', {'tow': 65950, 'mtow': 70000, 'index': 59.8, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 3.0, 'changes': [['remove', 170, 1.7]]}, ['LMC', 65780, 58.1]], ['regression: weight tolerance boundary', {'tow': 69650, 'mtow': 70000, 'index': 48.8, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 3.0, 'changes': [['add', 115, 2.4], ['add', 245, -2.5], ['remove', 50, -3.1]]}, ['LMC', 69960, 51.8]]], [['two late passengers', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 173, 1.5], ['add', 85, 0.8]]}, ['LMC', 68258, 54.3]], ['swap cancels net', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 300, 2.0], ['remove', 293, 1.9]]}, 'NEW_LOADSHEET'], ['exactly at weight tolerance', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 250, 1.0], ['add', 250, 1.0]]}, ['LMC', 68500, 54.0]], ['offload moves index', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 200, 3.3]]}, ['LMC', 67800, 48.7]], ['change pushes over MTOW', {'tow': 69900, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 153, 0.5]]}, 'NEW_LOADSHEET'], ['change pushes index out', {'tow': 68000, 'mtow': 70000, 'index': 68.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 100, 2.3]]}, 'NEW_LOADSHEET'], ['already heavy then offload', {'tow': 70200, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 150, 1.5]]}, 'NEW_LOADSHEET'], ['sampled case 1', {'tow': 64750, 'mtow': 70000, 'index': 33.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 3.0, 'changes': [['remove', 20, 2.4], ['remove', 125, -3.9], ['remove', 190, 3.9], ['remove', 270, 3.3]]}, 'NEW_LOADSHEET'], ['sampled case 2', {'tow': 63200, 'mtow': 70000, 'index': 47.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 400, 'max_lmc_index': 5.0, 'changes': [['remove', 335, -0.9], ['add', 105, 3.3]]}, 'NEW_LOADSHEET'], ['sampled case 3', {'tow': 66200, 'mtow': 70000, 'index': 38.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 400, 'max_lmc_index': 3.0, 'changes': [['add', 150, -0.8], ['add', 95, 1.5], ['add', 140, -2.4], ['add', 150, -0.8]]}, 'NEW_LOADSHEET'], ['regression: weight tolerance boundary', {'tow': 66400, 'mtow': 70000, 'index': 50.8, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 600, 'max_lmc_index': 3.0, 'changes': [['add', 210, -3.0]]}, ['LMC', 66610, 47.8]]], [['two late passengers', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 174, 1.5], ['add', 85, 0.8]]}, ['LMC', 68259, 54.3]], ['swap cancels net', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 300, 2.0], ['remove', 294, 1.9]]}, 'NEW_LOADSHEET'], ['exactly at weight tolerance', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 250, 1.0], ['add', 250, 1.0]]}, ['LMC', 68500, 54.0]], ['offload moves index', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 200, 3.4]]}, ['LMC', 67800, 48.6]], ['change pushes over MTOW', {'tow': 69900, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 154, 0.5]]}, 'NEW_LOADSHEET'], ['change pushes index out', {'tow': 68000, 'mtow': 70000, 'index': 68.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 100, 2.4]]}, 'NEW_LOADSHEET'], ['already heavy then offload', {'tow': 70200, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 150, 2.0]]}, 'NEW_LOADSHEET'], ['sampled case 1', {'tow': 66150, 'mtow': 70000, 'index': 46.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 400, 'max_lmc_index': 3.0, 'changes': [['add', 390, 0.4], ['remove', 40, 2.1], ['add', 300, 3.5]]}, 'NEW_LOADSHEET'], ['sampled case 2', {'tow': 64000, 'mtow': 70000, 'index': 30.4, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 3.0, 'changes': [['remove', 350, 3.5], ['remove', 60, 0.9]]}, 'NEW_LOADSHEET'], ['sampled case 3', {'tow': 60650, 'mtow': 70000, 'index': 63.7, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 295, -2.6]]}, ['LMC', 60945, 61.1]], ['regression: weight tolerance boundary', {'tow': 67100, 'mtow': 70000, 'index': 51.9, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 400, 'max_lmc_index': 3.0, 'changes': [['add', 200, 3.0]]}, ['LMC', 67300, 54.9]]], [['two late passengers', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 175, 1.5], ['add', 85, 0.8]]}, ['LMC', 68260, 54.3]], ['swap cancels net', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 300, 2.0], ['remove', 295, 1.9]]}, 'NEW_LOADSHEET'], ['exactly at weight tolerance', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 250, 1.0], ['add', 250, 1.0]]}, ['LMC', 68500, 54.0]], ['offload moves index', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 200, 3.5]]}, ['LMC', 67800, 48.5]], ['change pushes over MTOW', {'tow': 69900, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 155, 0.5]]}, 'NEW_LOADSHEET'], ['change pushes index out', {'tow': 68000, 'mtow': 70000, 'index': 68.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 100, 2.5]]}, 'NEW_LOADSHEET'], ['already heavy then offload', {'tow': 70200, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 150, 2.5]]}, 'NEW_LOADSHEET'], ['sampled case 1', {'tow': 69850, 'mtow': 70000, 'index': 46.3, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 600, 'max_lmc_index': 5.0, 'changes': [['add', 195, -0.8], ['add', 240, -1.5]]}, 'NEW_LOADSHEET'], ['sampled case 2', {'tow': 69600, 'mtow': 70000, 'index': 31.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 600, 'max_lmc_index': 3.0, 'changes': [['add', 180, 3.5], ['remove', 165, 3.5]]}, ['LMC', 69615, 31.5]], ['sampled case 3', {'tow': 61550, 'mtow': 70000, 'index': 46.4, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 600, 'max_lmc_index': 5.0, 'changes': [['remove', 340, 1.9], ['remove', 260, -0.5]]}, ['LMC', 60950, 45.0]], ['regression: weight tolerance boundary', {'tow': 67100, 'mtow': 70000, 'index': 50.3, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 600, 'max_lmc_index': 5.0, 'changes': [['remove', 230, 0.1], ['add', 135, 0.2], ['add', 20, 4.0], ['remove', 105, -0.9]]}, ['LMC', 66920, 55.3]]]]
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

N = 1
observations = []
def solve(x):
    gross = 0
    dw = 0
    di = 0.0
    for kind, wt, idx in x['changes']:
        s = 1 if kind == 'add' else -1
        gross += wt
        dw += s * wt
        di += s * idx
    if gross > x['max_lmc_weight'] or abs(di) >= x['max_lmc_index']: return 'NEW_LOADSHEET'
    tow = x['tow'] + dw
    ti = x['index'] + di
    lo, hi = x['index_limits']
    if tow > x['mtow'] or ti < lo or ti > hi: return 'NEW_LOADSHEET'
    return ['LMC', tow, round(ti, 1)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['two late passengers', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 171, 1.5], ['add', 85, 0.8]]}, ['LMC', 68256, 54.3]], ['swap cancels net', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 300, 2.0], ['remove', 291, 1.9]]}, 'NEW_LOADSHEET'], ['exactly at weight tolerance', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 250, 1.0], ['add', 250, 1.0]]}, ['LMC', 68500, 54.0]], ['offload moves index', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 200, 3.1]]}, ['LMC', 67800, 48.9]], ['change pushes over MTOW', {'tow': 69900, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 151, 0.5]]}, 'NEW_LOADSHEET'], ['change pushes index out', {'tow': 68000, 'mtow': 70000, 'index': 68.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 100, 2.1]]}, 'NEW_LOADSHEET'], ['already heavy then offload', {'tow': 70200, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 150, 0.5]]}, 'NEW_LOADSHEET'], ['sampled case 1', {'tow': 64100, 'mtow': 70000, 'index': 45.9, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 3.0, 'changes': [['remove', 180, 3.4], ['remove', 155, -2.5], ['add', 35, -3.5], ['add', 345, 3.7]]}, 'NEW_LOADSHEET'], ['sampled case 2', {'tow': 68550, 'mtow': 70000, 'index': 33.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 400, 'max_lmc_index': 3.0, 'changes': [['add', 340, -1.0], ['remove', 260, 1.2]]}, 'NEW_LOADSHEET'], ['sampled case 3', {'tow': 61300, 'mtow': 70000, 'index': 42.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 400, 'max_lmc_index': 3.0, 'changes': [['add', 350, -3.5], ['remove', 30, -2.6], ['add', 230, 1.5]]}, 'NEW_LOADSHEET'], ['regression: weight tolerance boundary', {'tow': 62750, 'mtow': 70000, 'index': 35.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 600, 'max_lmc_index': 5.0, 'changes': [['remove', 185, -0.9], ['remove', 65, 3.5], ['remove', 300, 2.4]]}, ['LMC', 62200, 30.1]]], [['two late passengers', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 172, 1.5], ['add', 85, 0.8]]}, ['LMC', 68257, 54.3]], ['swap cancels net', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 300, 2.0], ['remove', 292, 1.9]]}, 'NEW_LOADSHEET'], ['exactly at weight tolerance', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 250, 1.0], ['add', 250, 1.0]]}, ['LMC', 68500, 54.0]], ['offload moves index', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 200, 3.2]]}, ['LMC', 67800, 48.8]], ['change pushes over MTOW', {'tow': 69900, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 152, 0.5]]}, 'NEW_LOADSHEET'], ['change pushes index out', {'tow': 68000, 'mtow': 70000, 'index': 68.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 100, 2.2]]}, 'NEW_LOADSHEET'], ['already heavy then offload', {'tow': 70200, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 150, 1.0]]}, 'NEW_LOADSHEET'], ['sampled case 1', {'tow': 68750, 'mtow': 70000, 'index': 62.6, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 3.0, 'changes': [['add', 275, -2.1], ['add', 25, -1.8]]}, 'NEW_LOADSHEET'], ['sampled case 2', {'tow': 64950, 'mtow': 70000, 'index': 44.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 600, 'max_lmc_index': 3.0, 'changes': [['add', 385, 2.3]]}, ['LMC', 65335, 46.8]], ['sampled case 3', {'tow': 65950, 'mtow': 70000, 'index': 59.8, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 3.0, 'changes': [['remove', 170, 1.7]]}, ['LMC', 65780, 58.1]], ['regression: weight tolerance boundary', {'tow': 69650, 'mtow': 70000, 'index': 48.8, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 3.0, 'changes': [['add', 115, 2.4], ['add', 245, -2.5], ['remove', 50, -3.1]]}, ['LMC', 69960, 51.8]]], [['two late passengers', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 173, 1.5], ['add', 85, 0.8]]}, ['LMC', 68258, 54.3]], ['swap cancels net', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 300, 2.0], ['remove', 293, 1.9]]}, 'NEW_LOADSHEET'], ['exactly at weight tolerance', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 250, 1.0], ['add', 250, 1.0]]}, ['LMC', 68500, 54.0]], ['offload moves index', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 200, 3.3]]}, ['LMC', 67800, 48.7]], ['change pushes over MTOW', {'tow': 69900, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 153, 0.5]]}, 'NEW_LOADSHEET'], ['change pushes index out', {'tow': 68000, 'mtow': 70000, 'index': 68.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 100, 2.3]]}, 'NEW_LOADSHEET'], ['already heavy then offload', {'tow': 70200, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 150, 1.5]]}, 'NEW_LOADSHEET'], ['sampled case 1', {'tow': 64750, 'mtow': 70000, 'index': 33.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 3.0, 'changes': [['remove', 20, 2.4], ['remove', 125, -3.9], ['remove', 190, 3.9], ['remove', 270, 3.3]]}, 'NEW_LOADSHEET'], ['sampled case 2', {'tow': 63200, 'mtow': 70000, 'index': 47.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 400, 'max_lmc_index': 5.0, 'changes': [['remove', 335, -0.9], ['add', 105, 3.3]]}, 'NEW_LOADSHEET'], ['sampled case 3', {'tow': 66200, 'mtow': 70000, 'index': 38.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 400, 'max_lmc_index': 3.0, 'changes': [['add', 150, -0.8], ['add', 95, 1.5], ['add', 140, -2.4], ['add', 150, -0.8]]}, 'NEW_LOADSHEET'], ['regression: weight tolerance boundary', {'tow': 66400, 'mtow': 70000, 'index': 50.8, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 600, 'max_lmc_index': 3.0, 'changes': [['add', 210, -3.0]]}, ['LMC', 66610, 47.8]]], [['two late passengers', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 174, 1.5], ['add', 85, 0.8]]}, ['LMC', 68259, 54.3]], ['swap cancels net', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 300, 2.0], ['remove', 294, 1.9]]}, 'NEW_LOADSHEET'], ['exactly at weight tolerance', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 250, 1.0], ['add', 250, 1.0]]}, ['LMC', 68500, 54.0]], ['offload moves index', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 200, 3.4]]}, ['LMC', 67800, 48.6]], ['change pushes over MTOW', {'tow': 69900, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 154, 0.5]]}, 'NEW_LOADSHEET'], ['change pushes index out', {'tow': 68000, 'mtow': 70000, 'index': 68.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 100, 2.4]]}, 'NEW_LOADSHEET'], ['already heavy then offload', {'tow': 70200, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 150, 2.0]]}, 'NEW_LOADSHEET'], ['sampled case 1', {'tow': 66150, 'mtow': 70000, 'index': 46.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 400, 'max_lmc_index': 3.0, 'changes': [['add', 390, 0.4], ['remove', 40, 2.1], ['add', 300, 3.5]]}, 'NEW_LOADSHEET'], ['sampled case 2', {'tow': 64000, 'mtow': 70000, 'index': 30.4, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 3.0, 'changes': [['remove', 350, 3.5], ['remove', 60, 0.9]]}, 'NEW_LOADSHEET'], ['sampled case 3', {'tow': 60650, 'mtow': 70000, 'index': 63.7, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 295, -2.6]]}, ['LMC', 60945, 61.1]], ['regression: weight tolerance boundary', {'tow': 67100, 'mtow': 70000, 'index': 51.9, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 400, 'max_lmc_index': 3.0, 'changes': [['add', 200, 3.0]]}, ['LMC', 67300, 54.9]]], [['two late passengers', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 175, 1.5], ['add', 85, 0.8]]}, ['LMC', 68260, 54.3]], ['swap cancels net', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 300, 2.0], ['remove', 295, 1.9]]}, 'NEW_LOADSHEET'], ['exactly at weight tolerance', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 250, 1.0], ['add', 250, 1.0]]}, ['LMC', 68500, 54.0]], ['offload moves index', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 200, 3.5]]}, ['LMC', 67800, 48.5]], ['change pushes over MTOW', {'tow': 69900, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 155, 0.5]]}, 'NEW_LOADSHEET'], ['change pushes index out', {'tow': 68000, 'mtow': 70000, 'index': 68.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 100, 2.5]]}, 'NEW_LOADSHEET'], ['already heavy then offload', {'tow': 70200, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 150, 2.5]]}, 'NEW_LOADSHEET'], ['sampled case 1', {'tow': 69850, 'mtow': 70000, 'index': 46.3, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 600, 'max_lmc_index': 5.0, 'changes': [['add', 195, -0.8], ['add', 240, -1.5]]}, 'NEW_LOADSHEET'], ['sampled case 2', {'tow': 69600, 'mtow': 70000, 'index': 31.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 600, 'max_lmc_index': 3.0, 'changes': [['add', 180, 3.5], ['remove', 165, 3.5]]}, ['LMC', 69615, 31.5]], ['sampled case 3', {'tow': 61550, 'mtow': 70000, 'index': 46.4, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 600, 'max_lmc_index': 5.0, 'changes': [['remove', 340, 1.9], ['remove', 260, -0.5]]}, ['LMC', 60950, 45.0]], ['regression: weight tolerance boundary', {'tow': 67100, 'mtow': 70000, 'index': 50.3, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 600, 'max_lmc_index': 5.0, 'changes': [['remove', 230, 0.1], ['add', 135, 0.2], ['add', 20, 4.0], ['remove', 105, -0.9]]}, ['LMC', 66920, 55.3]]]]
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:
Two changes totalling exactly the tolerance are rejected.

Input {'tow','mtow','index','index_limits','max_lmc_weight','max_lmc_index','changes':[['add'|'remove', kg, index effect of adding]]}. The weight tolerance applies to the gross sum of all changed weights (<= limit allowed); removals negate weight and index; |net index| <= limit. Then new TOW <= MTOW and new index within inclusive limits, else 'NEW_LOADSHEET'. Return ['LMC', new TOW, new index r1].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    gross = 0
    dw = 0
    di = 0.0
    for kind, wt, idx in x['changes']:
        s = 1 if kind == 'add' else -1
        gross += wt
        dw += s * wt
        di += s * idx
    if gross > x['max_lmc_weight'] or abs(di) > x['max_lmc_index']: return 'NEW_LOADSHEET'
    tow = x['tow'] + dw
    ti = x['index'] + di
    lo, hi = x['index_limits']
    if x['tow'] > x['mtow'] or ti < lo or ti > hi: return 'NEW_LOADSHEET'
    return ['LMC', tow, round(ti, 1)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['two late passengers', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 171, 1.5], ['add', 85, 0.8]]}, ['LMC', 68256, 54.3]], ['swap cancels net', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 300, 2.0], ['remove', 291, 1.9]]}, 'NEW_LOADSHEET'], ['exactly at weight tolerance', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 250, 1.0], ['add', 250, 1.0]]}, ['LMC', 68500, 54.0]], ['offload moves index', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 200, 3.1]]}, ['LMC', 67800, 48.9]], ['change pushes over MTOW', {'tow': 69900, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 151, 0.5]]}, 'NEW_LOADSHEET'], ['change pushes index out', {'tow': 68000, 'mtow': 70000, 'index': 68.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 100, 2.1]]}, 'NEW_LOADSHEET'], ['already heavy then offload', {'tow': 70200, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 150, 0.5]]}, 'NEW_LOADSHEET'], ['sampled case 1', {'tow': 64100, 'mtow': 70000, 'index': 45.9, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 3.0, 'changes': [['remove', 180, 3.4], ['remove', 155, -2.5], ['add', 35, -3.5], ['add', 345, 3.7]]}, 'NEW_LOADSHEET'], ['sampled case 2', {'tow': 68550, 'mtow': 70000, 'index': 33.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 400, 'max_lmc_index': 3.0, 'changes': [['add', 340, -1.0], ['remove', 260, 1.2]]}, 'NEW_LOADSHEET'], ['sampled case 3', {'tow': 61300, 'mtow': 70000, 'index': 42.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 400, 'max_lmc_index': 3.0, 'changes': [['add', 350, -3.5], ['remove', 30, -2.6], ['add', 230, 1.5]]}, 'NEW_LOADSHEET']], [['two late passengers', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 172, 1.5], ['add', 85, 0.8]]}, ['LMC', 68257, 54.3]], ['swap cancels net', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 300, 2.0], ['remove', 292, 1.9]]}, 'NEW_LOADSHEET'], ['exactly at weight tolerance', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 250, 1.0], ['add', 250, 1.0]]}, ['LMC', 68500, 54.0]], ['offload moves index', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 200, 3.2]]}, ['LMC', 67800, 48.8]], ['change pushes over MTOW', {'tow': 69900, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 152, 0.5]]}, 'NEW_LOADSHEET'], ['change pushes index out', {'tow': 68000, 'mtow': 70000, 'index': 68.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 100, 2.2]]}, 'NEW_LOADSHEET'], ['already heavy then offload', {'tow': 70200, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 150, 1.0]]}, 'NEW_LOADSHEET'], ['sampled case 1', {'tow': 68750, 'mtow': 70000, 'index': 62.6, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 3.0, 'changes': [['add', 275, -2.1], ['add', 25, -1.8]]}, 'NEW_LOADSHEET'], ['sampled case 2', {'tow': 64950, 'mtow': 70000, 'index': 44.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 600, 'max_lmc_index': 3.0, 'changes': [['add', 385, 2.3]]}, ['LMC', 65335, 46.8]], ['sampled case 3', {'tow': 65950, 'mtow': 70000, 'index': 59.8, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 3.0, 'changes': [['remove', 170, 1.7]]}, ['LMC', 65780, 58.1]]], [['two late passengers', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 173, 1.5], ['add', 85, 0.8]]}, ['LMC', 68258, 54.3]], ['swap cancels net', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 300, 2.0], ['remove', 293, 1.9]]}, 'NEW_LOADSHEET'], ['exactly at weight tolerance', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 250, 1.0], ['add', 250, 1.0]]}, ['LMC', 68500, 54.0]], ['offload moves index', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 200, 3.3]]}, ['LMC', 67800, 48.7]], ['change pushes over MTOW', {'tow': 69900, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 153, 0.5]]}, 'NEW_LOADSHEET'], ['change pushes index out', {'tow': 68000, 'mtow': 70000, 'index': 68.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 100, 2.3]]}, 'NEW_LOADSHEET'], ['already heavy then offload', {'tow': 70200, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 150, 1.5]]}, 'NEW_LOADSHEET'], ['sampled case 1', {'tow': 64750, 'mtow': 70000, 'index': 33.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 3.0, 'changes': [['remove', 20, 2.4], ['remove', 125, -3.9], ['remove', 190, 3.9], ['remove', 270, 3.3]]}, 'NEW_LOADSHEET'], ['sampled case 2', {'tow': 63200, 'mtow': 70000, 'index': 47.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 400, 'max_lmc_index': 5.0, 'changes': [['remove', 335, -0.9], ['add', 105, 3.3]]}, 'NEW_LOADSHEET'], ['sampled case 3', {'tow': 66200, 'mtow': 70000, 'index': 38.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 400, 'max_lmc_index': 3.0, 'changes': [['add', 150, -0.8], ['add', 95, 1.5], ['add', 140, -2.4], ['add', 150, -0.8]]}, 'NEW_LOADSHEET']], [['two late passengers', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 174, 1.5], ['add', 85, 0.8]]}, ['LMC', 68259, 54.3]], ['swap cancels net', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 300, 2.0], ['remove', 294, 1.9]]}, 'NEW_LOADSHEET'], ['exactly at weight tolerance', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 250, 1.0], ['add', 250, 1.0]]}, ['LMC', 68500, 54.0]], ['offload moves index', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 200, 3.4]]}, ['LMC', 67800, 48.6]], ['change pushes over MTOW', {'tow': 69900, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 154, 0.5]]}, 'NEW_LOADSHEET'], ['change pushes index out', {'tow': 68000, 'mtow': 70000, 'index': 68.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 100, 2.4]]}, 'NEW_LOADSHEET'], ['already heavy then offload', {'tow': 70200, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 150, 2.0]]}, 'NEW_LOADSHEET'], ['sampled case 1', {'tow': 66150, 'mtow': 70000, 'index': 46.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 400, 'max_lmc_index': 3.0, 'changes': [['add', 390, 0.4], ['remove', 40, 2.1], ['add', 300, 3.5]]}, 'NEW_LOADSHEET'], ['sampled case 2', {'tow': 64000, 'mtow': 70000, 'index': 30.4, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 3.0, 'changes': [['remove', 350, 3.5], ['remove', 60, 0.9]]}, 'NEW_LOADSHEET'], ['sampled case 3', {'tow': 60650, 'mtow': 70000, 'index': 63.7, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 295, -2.6]]}, ['LMC', 60945, 61.1]]], [['two late passengers', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 175, 1.5], ['add', 85, 0.8]]}, ['LMC', 68260, 54.3]], ['swap cancels net', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 300, 2.0], ['remove', 295, 1.9]]}, 'NEW_LOADSHEET'], ['exactly at weight tolerance', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 250, 1.0], ['add', 250, 1.0]]}, ['LMC', 68500, 54.0]], ['offload moves index', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 200, 3.5]]}, ['LMC', 67800, 48.5]], ['change pushes over MTOW', {'tow': 69900, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 155, 0.5]]}, 'NEW_LOADSHEET'], ['change pushes index out', {'tow': 68000, 'mtow': 70000, 'index': 68.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 100, 2.5]]}, 'NEW_LOADSHEET'], ['already heavy then offload', {'tow': 70200, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 150, 2.5]]}, 'NEW_LOADSHEET'], ['sampled case 1', {'tow': 69850, 'mtow': 70000, 'index': 46.3, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 600, 'max_lmc_index': 5.0, 'changes': [['add', 195, -0.8], ['add', 240, -1.5]]}, 'NEW_LOADSHEET'], ['sampled case 2', {'tow': 69600, 'mtow': 70000, 'index': 31.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 600, 'max_lmc_index': 3.0, 'changes': [['add', 180, 3.5], ['remove', 165, 3.5]]}, ['LMC', 69615, 31.5]], ['sampled case 3', {'tow': 61550, 'mtow': 70000, 'index': 46.4, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 600, 'max_lmc_index': 5.0, 'changes': [['remove', 340, 1.9], ['remove', 260, -0.5]]}, ['LMC', 60950, 45.0]]]]
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

N = 1
observations = []
def solve(x):
    gross = 0
    dw = 0
    di = 0.0
    for kind, wt, idx in x['changes']:
        s = 1 if kind == 'add' else -1
        gross += wt
        dw += s * wt
        di += s * idx
    if gross > x['max_lmc_weight'] or abs(di) > x['max_lmc_index']: return 'NEW_LOADSHEET'
    tow = x['tow'] + dw
    ti = x['index'] + di
    lo, hi = x['index_limits']
    if tow > x['mtow'] and dw > 0 or ti < lo or ti > hi: return 'NEW_LOADSHEET'
    return ['LMC', tow, round(ti, 1)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['two late passengers', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 171, 1.5], ['add', 85, 0.8]]}, ['LMC', 68256, 54.3]], ['swap cancels net', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 300, 2.0], ['remove', 291, 1.9]]}, 'NEW_LOADSHEET'], ['exactly at weight tolerance', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 250, 1.0], ['add', 250, 1.0]]}, ['LMC', 68500, 54.0]], ['offload moves index', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 200, 3.1]]}, ['LMC', 67800, 48.9]], ['change pushes over MTOW', {'tow': 69900, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 151, 0.5]]}, 'NEW_LOADSHEET'], ['change pushes index out', {'tow': 68000, 'mtow': 70000, 'index': 68.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 100, 2.1]]}, 'NEW_LOADSHEET'], ['already heavy then offload', {'tow': 70200, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 150, 0.5]]}, 'NEW_LOADSHEET'], ['sampled case 1', {'tow': 64100, 'mtow': 70000, 'index': 45.9, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 3.0, 'changes': [['remove', 180, 3.4], ['remove', 155, -2.5], ['add', 35, -3.5], ['add', 345, 3.7]]}, 'NEW_LOADSHEET'], ['sampled case 2', {'tow': 68550, 'mtow': 70000, 'index': 33.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 400, 'max_lmc_index': 3.0, 'changes': [['add', 340, -1.0], ['remove', 260, 1.2]]}, 'NEW_LOADSHEET'], ['sampled case 3', {'tow': 61300, 'mtow': 70000, 'index': 42.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 400, 'max_lmc_index': 3.0, 'changes': [['add', 350, -3.5], ['remove', 30, -2.6], ['add', 230, 1.5]]}, 'NEW_LOADSHEET']], [['two late passengers', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 172, 1.5], ['add', 85, 0.8]]}, ['LMC', 68257, 54.3]], ['swap cancels net', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 300, 2.0], ['remove', 292, 1.9]]}, 'NEW_LOADSHEET'], ['exactly at weight tolerance', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 250, 1.0], ['add', 250, 1.0]]}, ['LMC', 68500, 54.0]], ['offload moves index', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 200, 3.2]]}, ['LMC', 67800, 48.8]], ['change pushes over MTOW', {'tow': 69900, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 152, 0.5]]}, 'NEW_LOADSHEET'], ['change pushes index out', {'tow': 68000, 'mtow': 70000, 'index': 68.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 100, 2.2]]}, 'NEW_LOADSHEET'], ['already heavy then offload', {'tow': 70200, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 150, 1.0]]}, 'NEW_LOADSHEET'], ['sampled case 1', {'tow': 68750, 'mtow': 70000, 'index': 62.6, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 3.0, 'changes': [['add', 275, -2.1], ['add', 25, -1.8]]}, 'NEW_LOADSHEET'], ['sampled case 2', {'tow': 64950, 'mtow': 70000, 'index': 44.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 600, 'max_lmc_index': 3.0, 'changes': [['add', 385, 2.3]]}, ['LMC', 65335, 46.8]], ['sampled case 3', {'tow': 65950, 'mtow': 70000, 'index': 59.8, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 3.0, 'changes': [['remove', 170, 1.7]]}, ['LMC', 65780, 58.1]]], [['two late passengers', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 173, 1.5], ['add', 85, 0.8]]}, ['LMC', 68258, 54.3]], ['swap cancels net', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 300, 2.0], ['remove', 293, 1.9]]}, 'NEW_LOADSHEET'], ['exactly at weight tolerance', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 250, 1.0], ['add', 250, 1.0]]}, ['LMC', 68500, 54.0]], ['offload moves index', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 200, 3.3]]}, ['LMC', 67800, 48.7]], ['change pushes over MTOW', {'tow': 69900, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 153, 0.5]]}, 'NEW_LOADSHEET'], ['change pushes index out', {'tow': 68000, 'mtow': 70000, 'index': 68.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 100, 2.3]]}, 'NEW_LOADSHEET'], ['already heavy then offload', {'tow': 70200, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 150, 1.5]]}, 'NEW_LOADSHEET'], ['sampled case 1', {'tow': 64750, 'mtow': 70000, 'index': 33.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 3.0, 'changes': [['remove', 20, 2.4], ['remove', 125, -3.9], ['remove', 190, 3.9], ['remove', 270, 3.3]]}, 'NEW_LOADSHEET'], ['sampled case 2', {'tow': 63200, 'mtow': 70000, 'index': 47.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 400, 'max_lmc_index': 5.0, 'changes': [['remove', 335, -0.9], ['add', 105, 3.3]]}, 'NEW_LOADSHEET'], ['sampled case 3', {'tow': 66200, 'mtow': 70000, 'index': 38.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 400, 'max_lmc_index': 3.0, 'changes': [['add', 150, -0.8], ['add', 95, 1.5], ['add', 140, -2.4], ['add', 150, -0.8]]}, 'NEW_LOADSHEET']], [['two late passengers', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 174, 1.5], ['add', 85, 0.8]]}, ['LMC', 68259, 54.3]], ['swap cancels net', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 300, 2.0], ['remove', 294, 1.9]]}, 'NEW_LOADSHEET'], ['exactly at weight tolerance', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 250, 1.0], ['add', 250, 1.0]]}, ['LMC', 68500, 54.0]], ['offload moves index', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 200, 3.4]]}, ['LMC', 67800, 48.6]], ['change pushes over MTOW', {'tow': 69900, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 154, 0.5]]}, 'NEW_LOADSHEET'], ['change pushes index out', {'tow': 68000, 'mtow': 70000, 'index': 68.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 100, 2.4]]}, 'NEW_LOADSHEET'], ['already heavy then offload', {'tow': 70200, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 150, 2.0]]}, 'NEW_LOADSHEET'], ['sampled case 1', {'tow': 66150, 'mtow': 70000, 'index': 46.1, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 400, 'max_lmc_index': 3.0, 'changes': [['add', 390, 0.4], ['remove', 40, 2.1], ['add', 300, 3.5]]}, 'NEW_LOADSHEET'], ['sampled case 2', {'tow': 64000, 'mtow': 70000, 'index': 30.4, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 3.0, 'changes': [['remove', 350, 3.5], ['remove', 60, 0.9]]}, 'NEW_LOADSHEET'], ['sampled case 3', {'tow': 60650, 'mtow': 70000, 'index': 63.7, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 295, -2.6]]}, ['LMC', 60945, 61.1]]], [['two late passengers', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 175, 1.5], ['add', 85, 0.8]]}, ['LMC', 68260, 54.3]], ['swap cancels net', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 300, 2.0], ['remove', 295, 1.9]]}, 'NEW_LOADSHEET'], ['exactly at weight tolerance', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 250, 1.0], ['add', 250, 1.0]]}, ['LMC', 68500, 54.0]], ['offload moves index', {'tow': 68000, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 200, 3.5]]}, ['LMC', 67800, 48.5]], ['change pushes over MTOW', {'tow': 69900, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 155, 0.5]]}, 'NEW_LOADSHEET'], ['change pushes index out', {'tow': 68000, 'mtow': 70000, 'index': 68.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['add', 100, 2.5]]}, 'NEW_LOADSHEET'], ['already heavy then offload', {'tow': 70200, 'mtow': 70000, 'index': 52.0, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 500, 'max_lmc_index': 5.0, 'changes': [['remove', 150, 2.5]]}, 'NEW_LOADSHEET'], ['sampled case 1', {'tow': 69850, 'mtow': 70000, 'index': 46.3, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 600, 'max_lmc_index': 5.0, 'changes': [['add', 195, -0.8], ['add', 240, -1.5]]}, 'NEW_LOADSHEET'], ['sampled case 2', {'tow': 69600, 'mtow': 70000, 'index': 31.5, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 600, 'max_lmc_index': 3.0, 'changes': [['add', 180, 3.5], ['remove', 165, 3.5]]}, ['LMC', 69615, 31.5]], ['sampled case 3', {'tow': 61550, 'mtow': 70000, 'index': 46.4, 'index_limits': [30.0, 70.0], 'max_lmc_weight': 600, 'max_lmc_index': 5.0, 'changes': [['remove', 340, 1.9], ['remove', 260, -0.5]]}, ['LMC', 60950, 45.0]]]]
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 late passenger that takes the aircraft over MTOW is accepted as an LMC.

Input {'tow','mtow','index','index_limits','max_lmc_weight','max_lmc_index','changes':[['add'|'remove', kg, index effect of adding]]}. The weight tolerance applies to the gross sum of all changed weights (<= limit allowed); removals negate weight and index; |net index| <= limit. Then new TOW <= MTOW and new index within inclusive limits, else 'NEW_LOADSHEET'. Return ['LMC', new TOW, new index r1].

split: open-access