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

N = 1
observations = []
def solve(x):
    m = x['age_months']
    bands = [(12, 100, 160, 30, 50), (48, 90, 150, 24, 40), (144, 70, 120, 18, 30), (10 ** 6, 60, 100, 12, 20)]
    for lim, hlo, hhi, rlo, rhi in bands:
        if m < lim:
            break
    dh = max(x['hr'] - hhi, 0)
    dr = max(rlo - x['rr'], x['rr'] - rhi, 0)
    crt = x['crt_s']
    card = 2 if dh > 20 or crt >= 4 else 1 if dh > 0 or crt == 3 else 0
    o2 = x['o2_lpm']
    resp = 2 if dr > 10 or o2 >= 4 else 1 if dr > 0 or o2 > 0 else 0
    beh = {'playing': 0, 'sleeping': 0, 'irritable': 1, 'lethargic': 3}[x['behavior']]
    total = card + resp + beh
    return {'score': total, 'escalate': total >= 5 or beh == 3}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('school-age control',
   {'age_months': 60, 'hr': 91, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 27, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 151, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 84, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 101, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 81, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 1, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 81, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 52, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 126, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 101, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})],
 [('school-age control',
   {'age_months': 60, 'hr': 92, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 28, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 152, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 83, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 102, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 82, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 0, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 82, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 53, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 127, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 102, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})],
 [('school-age control',
   {'age_months': 60, 'hr': 93, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 26, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 153, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 82, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 103, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 83, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 1, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 83, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 54, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 128, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 103, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})],
 [('school-age control',
   {'age_months': 60, 'hr': 94, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 27, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 154, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 81, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 104, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 84, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 0, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 84, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 55, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 129, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 104, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})],
 [('school-age control',
   {'age_months': 60, 'hr': 95, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 28, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 155, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 80, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 105, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 85, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 1, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 85, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 56, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 130, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 105, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})]]
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):
    m = x['age_months']
    bands = [(12, 100, 160, 30, 50), (48, 90, 150, 24, 40), (144, 70, 120, 18, 30), (10 ** 6, 60, 100, 12, 20)]
    for lim, hlo, hhi, rlo, rhi in bands:
        if m < lim:
            break
    dh = abs(x['hr'] - (hlo + hhi) // 2)
    dr = max(rlo - x['rr'], x['rr'] - rhi, 0)
    crt = x['crt_s']
    card = 2 if dh > 20 or crt >= 4 else 1 if dh > 0 or crt == 3 else 0
    o2 = x['o2_lpm']
    resp = 2 if dr > 10 or o2 >= 4 else 1 if dr > 0 or o2 > 0 else 0
    beh = {'playing': 0, 'sleeping': 0, 'irritable': 1, 'lethargic': 3}[x['behavior']]
    total = card + resp + beh
    return {'score': total, 'escalate': total >= 5 or beh == 3}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('school-age control',
   {'age_months': 60, 'hr': 91, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 27, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 151, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 84, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 101, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 81, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 1, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 81, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 52, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 126, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 101, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})],
 [('school-age control',
   {'age_months': 60, 'hr': 92, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 28, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 152, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 83, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 102, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 82, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 0, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 82, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 53, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 127, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 102, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})],
 [('school-age control',
   {'age_months': 60, 'hr': 93, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 26, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 153, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 82, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 103, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 83, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 1, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 83, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 54, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 128, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 103, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})],
 [('school-age control',
   {'age_months': 60, 'hr': 94, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 27, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 154, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 81, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 104, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 84, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 0, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 84, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 55, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 129, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 104, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})],
 [('school-age control',
   {'age_months': 60, 'hr': 95, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 28, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 155, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 80, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 105, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 85, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 1, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 85, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 56, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 130, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 105, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})]]
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:
Bradycardic infants score 0 for heart rate.

Input {age_months, hr, rr, behavior, crt_s, o2_lpm}. Toy normal ranges by age: < 12 months HR 100-160 RR 30-50; 12-47 HR 90-150 RR 24-40; 48-143 HR 70-120 RR 18-30; >= 144 HR 60-100 RR 12-20. Deviation = distance outside the range (0 inside). Cardiovascular: 2 if HR deviation > 20 or refill >= 4 s, 1 if any HR deviation or refill 3 s, else 0. Respiratory: 2 if RR deviation > 10 or oxygen >= 4 L/min, 1 if any RR deviation or any oxygen, else 0. Behaviour: playing/sleeping 0, irritable 1, lethargic 3. escalate when total >= 5 or behaviour scores 3. Return {score, escalate}.

split: open-access


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

N = 1
observations = []
def solve(x):
    m = x['age_months']
    bands = [(12, 100, 160, 30, 50), (48, 90, 150, 24, 40), (144, 70, 120, 18, 30), (10 ** 6, 60, 100, 12, 20)]
    for lim, hlo, hhi, rlo, rhi in bands:
        if m < lim:
            break
    dh = max(hlo - x['hr'], x['hr'] - hhi, 0)
    dr = max(rlo - x['rr'], x['rr'] - rhi, 0)
    crt = x['crt_s']
    card = 2 if dh > 20 or crt > 4 else 1 if dh > 0 or crt == 3 else 0
    o2 = x['o2_lpm']
    resp = 2 if dr > 10 or o2 >= 4 else 1 if dr > 0 or o2 > 0 else 0
    beh = {'playing': 0, 'sleeping': 0, 'irritable': 1, 'lethargic': 3}[x['behavior']]
    total = card + resp + beh
    return {'score': total, 'escalate': total >= 5 or beh == 3}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('school-age control',
   {'age_months': 60, 'hr': 91, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 27, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 151, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 84, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 101, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 81, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 1, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 81, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 52, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 126, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 101, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})],
 [('school-age control',
   {'age_months': 60, 'hr': 92, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 28, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 152, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 83, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 102, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 82, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 0, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 82, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 53, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 127, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 102, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})],
 [('school-age control',
   {'age_months': 60, 'hr': 93, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 26, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 153, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 82, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 103, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 83, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 1, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 83, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 54, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 128, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 103, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})],
 [('school-age control',
   {'age_months': 60, 'hr': 94, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 27, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 154, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 81, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 104, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 84, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 0, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 84, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 55, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 129, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 104, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})],
 [('school-age control',
   {'age_months': 60, 'hr': 95, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 28, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 155, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 80, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 105, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 85, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 1, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 85, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 56, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 130, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 105, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})]]
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):
    m = x['age_months']
    bands = [(12, 100, 160, 30, 50), (48, 90, 150, 24, 40), (144, 70, 120, 18, 30), (10 ** 6, 60, 100, 12, 20)]
    for lim, hlo, hhi, rlo, rhi in bands:
        if m < lim:
            break
    dh = max(hlo - x['hr'], x['hr'] - hhi, 0)
    dr = max(rlo - x['rr'], x['rr'] - rhi, 0)
    crt = x['crt_s']
    card = 2 if dh > 20 or crt >= 3 else 1 if dh > 0 or crt == 3 else 0
    o2 = x['o2_lpm']
    resp = 2 if dr > 10 or o2 >= 4 else 1 if dr > 0 or o2 > 0 else 0
    beh = {'playing': 0, 'sleeping': 0, 'irritable': 1, 'lethargic': 3}[x['behavior']]
    total = card + resp + beh
    return {'score': total, 'escalate': total >= 5 or beh == 3}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('school-age control',
   {'age_months': 60, 'hr': 91, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 27, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 151, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 84, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 101, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 81, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 1, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 81, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 52, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 126, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 101, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})],
 [('school-age control',
   {'age_months': 60, 'hr': 92, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 28, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 152, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 83, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 102, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 82, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 0, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 82, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 53, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 127, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 102, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})],
 [('school-age control',
   {'age_months': 60, 'hr': 93, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 26, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 153, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 82, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 103, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 83, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 1, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 83, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 54, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 128, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 103, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})],
 [('school-age control',
   {'age_months': 60, 'hr': 94, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 27, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 154, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 81, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 104, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 84, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 0, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 84, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 55, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 129, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 104, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})],
 [('school-age control',
   {'age_months': 60, 'hr': 95, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 28, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 155, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 80, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 105, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 85, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 1, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 85, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 56, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 130, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 105, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})]]
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 4-second capillary refill scores only 1.

Input {age_months, hr, rr, behavior, crt_s, o2_lpm}. Toy normal ranges by age: < 12 months HR 100-160 RR 30-50; 12-47 HR 90-150 RR 24-40; 48-143 HR 70-120 RR 18-30; >= 144 HR 60-100 RR 12-20. Deviation = distance outside the range (0 inside). Cardiovascular: 2 if HR deviation > 20 or refill >= 4 s, 1 if any HR deviation or refill 3 s, else 0. Respiratory: 2 if RR deviation > 10 or oxygen >= 4 L/min, 1 if any RR deviation or any oxygen, else 0. Behaviour: playing/sleeping 0, irritable 1, lethargic 3. escalate when total >= 5 or behaviour scores 3. Return {score, escalate}.

split: open-access


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

N = 1
observations = []
def solve(x):
    m = x['age_months']
    bands = [(12, 100, 160, 30, 50), (48, 90, 150, 24, 40), (144, 70, 120, 18, 30), (10 ** 6, 60, 100, 12, 20)]
    for lim, hlo, hhi, rlo, rhi in bands:
        if m < lim:
            break
    dh = max(hlo - x['hr'], x['hr'] - hhi, 0)
    dr = max(rlo - x['rr'], x['rr'] - rhi, 0)
    crt = x['crt_s']
    card = 2 if dh > 20 or crt >= 4 else 1 if dh > 0 or crt == 3 else 0
    o2 = x['o2_lpm']
    resp = 2 if dr > 10 or o2 >= 4 else 1 if dr > 0 or o2 > 0 else 0
    beh = {'playing': 0, 'sleeping': 0, 'irritable': 1, 'lethargic': 3}[x['behavior']]
    total = card + resp + beh
    return {'score': total, 'escalate': total >= 5}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('school-age control',
   {'age_months': 60, 'hr': 91, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 27, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 151, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 84, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 101, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 81, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 1, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 81, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 52, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 126, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 101, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})],
 [('school-age control',
   {'age_months': 60, 'hr': 92, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 28, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 152, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 83, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 102, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 82, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 0, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 82, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 53, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 127, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 102, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})],
 [('school-age control',
   {'age_months': 60, 'hr': 93, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 26, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 153, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 82, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 103, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 83, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 1, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 83, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 54, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 128, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 103, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})],
 [('school-age control',
   {'age_months': 60, 'hr': 94, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 27, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 154, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 81, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 104, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 84, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 0, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 84, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 55, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 129, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 104, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})],
 [('school-age control',
   {'age_months': 60, 'hr': 95, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 28, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 155, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 80, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 105, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 85, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 1, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 85, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 56, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 130, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 105, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})]]
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):
    m = x['age_months']
    bands = [(12, 100, 160, 30, 50), (48, 90, 150, 24, 40), (144, 70, 120, 18, 30), (10 ** 6, 60, 100, 12, 20)]
    for lim, hlo, hhi, rlo, rhi in bands:
        if m < lim:
            break
    dh = max(hlo - x['hr'], x['hr'] - hhi, 0)
    dr = max(rlo - x['rr'], x['rr'] - rhi, 0)
    crt = x['crt_s']
    card = 2 if dh > 20 or crt >= 4 else 1 if dh > 0 or crt == 3 else 0
    o2 = x['o2_lpm']
    resp = 2 if dr > 10 or o2 >= 4 else 1 if dr > 0 or o2 > 0 else 0
    beh = {'playing': 0, 'sleeping': 0, 'irritable': 1, 'lethargic': 3}[x['behavior']]
    total = card + resp + beh
    return {'score': total, 'escalate': total >= 5 or beh >= 1}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('school-age control',
   {'age_months': 60, 'hr': 91, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 27, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 151, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 84, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 101, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 81, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 1, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 81, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 52, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 126, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 101, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})],
 [('school-age control',
   {'age_months': 60, 'hr': 92, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 28, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 152, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 83, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 102, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 82, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 0, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 82, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 53, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 127, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 102, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})],
 [('school-age control',
   {'age_months': 60, 'hr': 93, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 26, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 153, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 82, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 103, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 83, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 1, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 83, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 54, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 128, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 103, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})],
 [('school-age control',
   {'age_months': 60, 'hr': 94, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 27, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 154, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 81, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 104, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 84, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 0, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 84, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 55, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 129, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 104, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})],
 [('school-age control',
   {'age_months': 60, 'hr': 95, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 28, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 155, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 80, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 105, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 85, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 1, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 85, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 56, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 130, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 105, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})]]
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 lethargic child with otherwise normal vitals is not escalated.

Input {age_months, hr, rr, behavior, crt_s, o2_lpm}. Toy normal ranges by age: < 12 months HR 100-160 RR 30-50; 12-47 HR 90-150 RR 24-40; 48-143 HR 70-120 RR 18-30; >= 144 HR 60-100 RR 12-20. Deviation = distance outside the range (0 inside). Cardiovascular: 2 if HR deviation > 20 or refill >= 4 s, 1 if any HR deviation or refill 3 s, else 0. Respiratory: 2 if RR deviation > 10 or oxygen >= 4 L/min, 1 if any RR deviation or any oxygen, else 0. Behaviour: playing/sleeping 0, irritable 1, lethargic 3. escalate when total >= 5 or behaviour scores 3. Return {score, escalate}.

split: open-access


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

N = 1
observations = []
def solve(x):
    m = x['age_months']
    bands = [(12, 100, 160, 30, 50), (48, 90, 150, 24, 40), (144, 70, 120, 18, 30), (10 ** 6, 60, 100, 12, 20)]
    for lim, hlo, hhi, rlo, rhi in bands:
        if m < lim:
            break
    dh = max(hlo - x['hr'], x['hr'] - hhi, 0)
    dr = max(rlo - x['rr'], x['rr'] - rhi, 0)
    crt = x['crt_s']
    card = 2 if dh > 20 or crt >= 4 else 1 if dh > 0 or crt == 3 else 0
    o2 = x['o2_lpm']
    resp = 2 if dr >= 10 or o2 >= 4 else 1 if dr > 0 or o2 > 0 else 0
    beh = {'playing': 0, 'sleeping': 0, 'irritable': 1, 'lethargic': 3}[x['behavior']]
    total = card + resp + beh
    return {'score': total, 'escalate': total >= 5 or beh == 3}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('school-age control',
   {'age_months': 60, 'hr': 91, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 27, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 151, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 84, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 101, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 81, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 1, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 81, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 52, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 126, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 101, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})],
 [('school-age control',
   {'age_months': 60, 'hr': 92, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 28, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 152, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 83, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 102, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 82, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 0, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 82, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 53, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 127, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 102, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})],
 [('school-age control',
   {'age_months': 60, 'hr': 93, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 26, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 153, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 82, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 103, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 83, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 1, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 83, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 54, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 128, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 103, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})],
 [('school-age control',
   {'age_months': 60, 'hr': 94, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 27, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 154, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 81, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 104, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 84, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 0, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 84, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 55, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 129, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 104, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})],
 [('school-age control',
   {'age_months': 60, 'hr': 95, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 28, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 155, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 80, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 105, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 85, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 1, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 85, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 56, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 130, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 105, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})]]
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):
    m = x['age_months']
    bands = [(12, 100, 160, 30, 50), (48, 90, 150, 24, 40), (144, 70, 120, 18, 30), (10 ** 6, 60, 100, 12, 20)]
    for lim, hlo, hhi, rlo, rhi in bands:
        if m < lim:
            break
    dh = max(hlo - x['hr'], x['hr'] - hhi, 0)
    dr = max(rlo - x['rr'], x['rr'] - rhi, 0)
    crt = x['crt_s']
    card = 2 if dh > 20 or crt >= 4 else 1 if dh > 0 or crt == 3 else 0
    o2 = x['o2_lpm']
    resp = 2 if x['rr'] > rhi + 10 or o2 >= 4 else 1 if dr > 0 or o2 > 0 else 0
    beh = {'playing': 0, 'sleeping': 0, 'irritable': 1, 'lethargic': 3}[x['behavior']]
    total = card + resp + beh
    return {'score': total, 'escalate': total >= 5 or beh == 3}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('school-age control',
   {'age_months': 60, 'hr': 91, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 27, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 151, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 84, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 101, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 81, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 1, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 81, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 52, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 126, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 101, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})],
 [('school-age control',
   {'age_months': 60, 'hr': 92, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 28, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 152, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 83, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 102, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 82, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 0, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 82, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 53, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 127, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 102, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})],
 [('school-age control',
   {'age_months': 60, 'hr': 93, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 26, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 153, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 82, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 103, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 83, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 1, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 83, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 54, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 128, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 103, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})],
 [('school-age control',
   {'age_months': 60, 'hr': 94, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 27, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 154, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 81, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 104, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 84, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 0, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 84, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 55, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 129, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 104, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})],
 [('school-age control',
   {'age_months': 60, 'hr': 95, 'rr': 24, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('first birthday uses toddler band',
   {'age_months': 12, 'hr': 95, 'rr': 28, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('newborn in infant band',
   {'age_months': 0, 'hr': 155, 'rr': 45, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 0, 'escalate': False}),
  ('bradycardic infant',
   {'age_months': 6, 'hr': 80, 'rr': 40, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('capillary refill 3 seconds',
   {'age_months': 60, 'hr': 105, 'rr': 24, 'behavior': 'playing', 'crt_s': 3, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('refill 4 seconds',
   {'age_months': 60, 'hr': 85, 'rr': 24, 'behavior': 'playing', 'crt_s': 4, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('slow breathing adolescent',
   {'age_months': 150, 'hr': 80, 'rr': 1, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('rate exactly 10 above range',
   {'age_months': 150, 'hr': 85, 'rr': 30, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 1, 'escalate': False}),
  ('fast breathing toddler',
   {'age_months': 30, 'hr': 120, 'rr': 56, 'behavior': 'playing', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 2, 'escalate': False}),
  ('irritable with oxygen',
   {'age_months': 60, 'hr': 130, 'rr': 24, 'behavior': 'irritable', 'crt_s': 2, 'o2_lpm': 2},
   {'score': 3, 'escalate': False}),
  ('lethargic alone escalates',
   {'age_months': 60, 'hr': 105, 'rr': 24, 'behavior': 'lethargic', 'crt_s': 2, 'o2_lpm': 0},
   {'score': 3, 'escalate': True})]]
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 respiratory rate exactly 10 above range scores 2.

Input {age_months, hr, rr, behavior, crt_s, o2_lpm}. Toy normal ranges by age: < 12 months HR 100-160 RR 30-50; 12-47 HR 90-150 RR 24-40; 48-143 HR 70-120 RR 18-30; >= 144 HR 60-100 RR 12-20. Deviation = distance outside the range (0 inside). Cardiovascular: 2 if HR deviation > 20 or refill >= 4 s, 1 if any HR deviation or refill 3 s, else 0. Respiratory: 2 if RR deviation > 10 or oxygen >= 4 L/min, 1 if any RR deviation or any oxygen, else 0. Behaviour: playing/sleeping 0, irritable 1, lethargic 3. escalate when total >= 5 or behaviour scores 3. Return {score, escalate}.

split: open-access