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

N = 1
observations = []
def solve(booked_price, metered, driver_no_show, reservation_fee):
    if driver_no_show:
        return {'charge': 0, 'refund_fee': True}
    return {'charge': min(booked_price, metered + reservation_fee), 'refund_fee': False}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: reservation fee placement', [3200, 3200, False, 300], {'charge': 3500, 'refund_fee': False}),
  ('partial repair probe: reservation fee placement', [4100, 4100, False, 300],
   {'charge': 4400, 'refund_fee': False}),
  ('second regression', [3200, 3199, False, 200], {'charge': 3399, 'refund_fee': False}),
  ('normal control 1', [2500, 1800, True, 300], {'charge': 0, 'refund_fee': True}),
  ('normal control 2', [4100, 3400, True, 300], {'charge': 0, 'refund_fee': True}),
  ('normal control 3', [3200, 3201, True, 200], {'charge': 0, 'refund_fee': True}),
  ('normal control 4', [2500, 2501, True, 300], {'charge': 0, 'refund_fee': True})],
 [('regression: reservation fee placement', [3200, 3200, False, 200], {'charge': 3400, 'refund_fee': False}),
  ('partial repair probe: reservation fee placement', [2500, 2500, False, 300],
   {'charge': 2800, 'refund_fee': False}),
  ('second regression', [2500, 2500, False, 200], {'charge': 2700, 'refund_fee': False}),
  ('normal control 1', [2500, 2501, True, 200], {'charge': 0, 'refund_fee': True}),
  ('normal control 2', [3200, 4100, True, 300], {'charge': 0, 'refund_fee': True}),
  ('normal control 3', [3200, 4100, True, 200], {'charge': 0, 'refund_fee': True}),
  ('normal control 4', [2500, 2500, True, 300], {'charge': 0, 'refund_fee': True})],
 [('regression: reservation fee placement', [3200, 3199, False, 200], {'charge': 3399, 'refund_fee': False}),
  ('partial repair probe: reservation fee placement', [2500, 1800, False, 200],
   {'charge': 2000, 'refund_fee': False}),
  ('second regression', [2500, 2499, False, 300], {'charge': 2799, 'refund_fee': False}),
  ('normal control 1', [3200, 3200, True, 200], {'charge': 0, 'refund_fee': True}),
  ('normal control 2', [3200, 3201, True, 300], {'charge': 0, 'refund_fee': True}),
  ('normal control 3', [3200, 2500, True, 200], {'charge': 0, 'refund_fee': True}),
  ('normal control 4', [2500, 2500, True, 200], {'charge': 0, 'refund_fee': True})],
 [('regression: reservation fee placement', [4100, 4101, False, 300], {'charge': 4400, 'refund_fee': False}),
  ('partial repair probe: reservation fee placement', [3200, 3199, False, 200],
   {'charge': 3399, 'refund_fee': False}),
  ('second regression', [4100, 4101, False, 200], {'charge': 4300, 'refund_fee': False}),
  ('normal control 1', [2500, 2501, True, 200], {'charge': 0, 'refund_fee': True}),
  ('normal control 2', [2500, 2501, True, 300], {'charge': 0, 'refund_fee': True}),
  ('normal control 3', [3200, 3200, True, 200], {'charge': 0, 'refund_fee': True}),
  ('normal control 4', [3200, 3199, True, 300], {'charge': 0, 'refund_fee': True})],
 [('regression: reservation fee placement', [4100, 4099, False, 200], {'charge': 4299, 'refund_fee': False}),
  ('partial repair probe: reservation fee placement', [4100, 3400, False, 300],
   {'charge': 3700, 'refund_fee': False}),
  ('second regression', [4100, 4101, False, 300], {'charge': 4400, 'refund_fee': False}),
  ('normal control 1', [2500, 2500, True, 200], {'charge': 0, 'refund_fee': True}),
  ('normal control 2', [4100, 4099, True, 300], {'charge': 0, 'refund_fee': True}),
  ('normal control 3', [3200, 3201, True, 300], {'charge': 0, 'refund_fee': True}),
  ('normal control 4', [3200, 3199, True, 200], {'charge': 0, 'refund_fee': 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(booked_price, metered, driver_no_show, reservation_fee):
    if driver_no_show:
        return {'charge': 0, 'refund_fee': True}
    return {'charge': min(booked_price + reservation_fee, metered), 'refund_fee': False}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: reservation fee placement', [3200, 3200, False, 300], {'charge': 3500, 'refund_fee': False}),
  ('partial repair probe: reservation fee placement', [4100, 4100, False, 300],
   {'charge': 4400, 'refund_fee': False}),
  ('second regression', [3200, 3199, False, 200], {'charge': 3399, 'refund_fee': False}),
  ('normal control 1', [2500, 1800, True, 300], {'charge': 0, 'refund_fee': True}),
  ('normal control 2', [4100, 3400, True, 300], {'charge': 0, 'refund_fee': True}),
  ('normal control 3', [3200, 3201, True, 200], {'charge': 0, 'refund_fee': True}),
  ('normal control 4', [2500, 2501, True, 300], {'charge': 0, 'refund_fee': True})],
 [('regression: reservation fee placement', [3200, 3200, False, 200], {'charge': 3400, 'refund_fee': False}),
  ('partial repair probe: reservation fee placement', [2500, 2500, False, 300],
   {'charge': 2800, 'refund_fee': False}),
  ('second regression', [2500, 2500, False, 200], {'charge': 2700, 'refund_fee': False}),
  ('normal control 1', [2500, 2501, True, 200], {'charge': 0, 'refund_fee': True}),
  ('normal control 2', [3200, 4100, True, 300], {'charge': 0, 'refund_fee': True}),
  ('normal control 3', [3200, 4100, True, 200], {'charge': 0, 'refund_fee': True}),
  ('normal control 4', [2500, 2500, True, 300], {'charge': 0, 'refund_fee': True})],
 [('regression: reservation fee placement', [3200, 3199, False, 200], {'charge': 3399, 'refund_fee': False}),
  ('partial repair probe: reservation fee placement', [2500, 1800, False, 200],
   {'charge': 2000, 'refund_fee': False}),
  ('second regression', [2500, 2499, False, 300], {'charge': 2799, 'refund_fee': False}),
  ('normal control 1', [3200, 3200, True, 200], {'charge': 0, 'refund_fee': True}),
  ('normal control 2', [3200, 3201, True, 300], {'charge': 0, 'refund_fee': True}),
  ('normal control 3', [3200, 2500, True, 200], {'charge': 0, 'refund_fee': True}),
  ('normal control 4', [2500, 2500, True, 200], {'charge': 0, 'refund_fee': True})],
 [('regression: reservation fee placement', [4100, 4101, False, 300], {'charge': 4400, 'refund_fee': False}),
  ('partial repair probe: reservation fee placement', [3200, 3199, False, 200],
   {'charge': 3399, 'refund_fee': False}),
  ('second regression', [4100, 4101, False, 200], {'charge': 4300, 'refund_fee': False}),
  ('normal control 1', [2500, 2501, True, 200], {'charge': 0, 'refund_fee': True}),
  ('normal control 2', [2500, 2501, True, 300], {'charge': 0, 'refund_fee': True}),
  ('normal control 3', [3200, 3200, True, 200], {'charge': 0, 'refund_fee': True}),
  ('normal control 4', [3200, 3199, True, 300], {'charge': 0, 'refund_fee': True})],
 [('regression: reservation fee placement', [4100, 4099, False, 200], {'charge': 4299, 'refund_fee': False}),
  ('partial repair probe: reservation fee placement', [4100, 3400, False, 300],
   {'charge': 3700, 'refund_fee': False}),
  ('second regression', [4100, 4101, False, 300], {'charge': 4400, 'refund_fee': False}),
  ('normal control 1', [2500, 2500, True, 200], {'charge': 0, 'refund_fee': True}),
  ('normal control 2', [4100, 4099, True, 300], {'charge': 0, 'refund_fee': True}),
  ('normal control 3', [3200, 3201, True, 300], {'charge': 0, 'refund_fee': True}),
  ('normal control 4', [3200, 3199, True, 200], {'charge': 0, 'refund_fee': 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:
Riders with a metered fare above booked pay no reservation fee.

Scheduled rides guarantee the booked price: the rider pays the lower of booked and metered fare plus the reservation fee. If the driver never shows, nothing is charged and the reservation fee is refunded. Return charge cents and whether the fee is refunded.

split: open-access


meaning: Fixture-count band, not measured model difficulty

deps: stdlib

prompt:
A tip added at the last second of the window is refused.

Tips can be added from trip end through 72 hours later inclusive (259200 s). Total tips per trip are capped at the larger of twice the fare or 50.00; a new tip is truncated to the remaining room, and rejected with "cap" when no room is left. Return [accepted cents, reason].

split: open-access


prompt:
Riders on a 12.00 trip cannot tip more than 24.00.

Tips can be added from trip end through 72 hours later inclusive (259200 s). Total tips per trip are capped at the larger of twice the fare or 50.00; a new tip is truncated to the remaining room, and rejected with "cap" when no room is left. Return [accepted cents, reason].

split: open-access


prompt:
Repeated tips on one trip exceed the cap.

Tips can be added from trip end through 72 hours later inclusive (259200 s). Total tips per trip are capped at the larger of twice the fare or 50.00; a new tip is truncated to the remaining room, and rejected with "cap" when no room is left. Return [accepted cents, reason].

split: open-access


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

N = 1
observations = []
def solve(recipe, inventory, requested, skill):
    if requested <= 0:
        crafts = 0
    else:
        crafts = requested
        for mat, qty in recipe['inputs'].items():
            crafts = min(crafts, inventory.get(mat, 0))
    bonus = crafts // 5 if skill >= 50 else 0
    made = crafts * recipe['yield'] + bonus
    cap = recipe['stack']
    stacks = [cap] * (made // cap)
    if made % cap:
        stacks.append(made % cap)
    left = dict(inventory)
    for mat, qty in recipe['inputs'].items():
        left[mat] = left.get(mat, 0) - crafts * qty
    return {'crafts': crafts, 'made': made, 'stacks': stacks, 'left': dict(sorted(left.items()))}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('exact material multiple #1',
   [{'inputs': {'ore': 3}, 'output': 'bar', 'yield': 1, 'stack': 5}, {'ore': 15}, 10, 50],
   {'crafts': 5, 'made': 6, 'stacks': [5, 1], 'left': {'ore': 0}}),
  ('one short of a batch #1',
   [{'inputs': {'ore': 3, 'wood': 2}, 'output': 'axe', 'yield': 2, 'stack': 4},
    {'ore': 14, 'wood': 9, 'herb': 2},
    9,
    10],
   {'crafts': 4, 'made': 8, 'stacks': [4, 4], 'left': {'herb': 2, 'ore': 2, 'wood': 1}}),
  ('regression material availability #1',
   [{'inputs': {'ore': 4}, 'output': 'blade', 'yield': 3, 'stack': 10}, {'ore': 6}, 2, 51],
   {'crafts': 1, 'made': 3, 'stacks': [3], 'left': {'ore': 2}}),
  ('regression material availability #2',
   [{'inputs': {'wood': 2, 'hide': 3, 'gem': 3}, 'output': 'blade', 'yield': 3, 'stack': 7},
    {'wood': 12, 'hide': 23, 'gem': 11},
    4,
    51],
   {'crafts': 3, 'made': 9, 'stacks': [7, 2], 'left': {'gem': 2, 'hide': 14, 'wood': 6}}),
  ('regression material availability #3',
   [{'inputs': {'ore': 2, 'wood': 4, 'hide': 2}, 'output': 'blade', 'yield': 3, 'stack': 6},
    {'ore': 20, 'wood': 13, 'hide': 16, 'herb': 2},
    9,
    120],
   {'crafts': 3, 'made': 9, 'stacks': [6, 3], 'left': {'herb': 2, 'hide': 10, 'ore': 14, 'wood': 1}}),
  ('regression material availability #4',
   [{'inputs': {'gem': 4, 'ore': 2}, 'output': 'blade', 'yield': 1, 'stack': 9},
    {'gem': 15, 'ore': 20, 'herb': 6},
    12,
    120],
   {'crafts': 3, 'made': 3, 'stacks': [3], 'left': {'gem': 3, 'herb': 6, 'ore': 14}}),
  ('zero request #1',
   [{'inputs': {'hide': 2}, 'output': 'belt', 'yield': 1, 'stack': 3}, {'hide': 8}, 0, 80],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'hide': 8}}),
  ('control #1',
   [{'inputs': {'hide': 3, 'ore': 1}, 'output': 'blade', 'yield': 1, 'stack': 5},
    {'hide': 21, 'ore': 5},
    3,
    99],
   {'crafts': 3, 'made': 3, 'stacks': [3], 'left': {'hide': 12, 'ore': 2}})],
 [('one short of a batch #1',
   [{'inputs': {'ore': 3, 'wood': 2}, 'output': 'axe', 'yield': 2, 'stack': 4},
    {'ore': 14, 'wood': 9, 'herb': 2},
    9,
    10],
   {'crafts': 4, 'made': 8, 'stacks': [4, 4], 'left': {'herb': 2, 'ore': 2, 'wood': 1}}),
  ('regression material availability #1',
   [{'inputs': {'ore': 4}, 'output': 'blade', 'yield': 3, 'stack': 10}, {'ore': 6}, 2, 51],
   {'crafts': 1, 'made': 3, 'stacks': [3], 'left': {'ore': 2}}),
  ('regression material availability #2',
   [{'inputs': {'wood': 2, 'hide': 3, 'gem': 3}, 'output': 'blade', 'yield': 3, 'stack': 7},
    {'wood': 12, 'hide': 23, 'gem': 11},
    4,
    51],
   {'crafts': 3, 'made': 9, 'stacks': [7, 2], 'left': {'gem': 2, 'hide': 14, 'wood': 6}}),
  ('regression material availability #3',
   [{'inputs': {'ore': 2, 'wood': 4, 'hide': 2}, 'output': 'blade', 'yield': 3, 'stack': 6},
    {'ore': 20, 'wood': 13, 'hide': 16, 'herb': 2},
    9,
    120],
   {'crafts': 3, 'made': 9, 'stacks': [6, 3], 'left': {'herb': 2, 'hide': 10, 'ore': 14, 'wood': 1}}),
  ('regression material availability #4',
   [{'inputs': {'gem': 4, 'ore': 2}, 'output': 'blade', 'yield': 1, 'stack': 9},
    {'gem': 15, 'ore': 20, 'herb': 6},
    12,
    120],
   {'crafts': 3, 'made': 3, 'stacks': [3], 'left': {'gem': 3, 'herb': 6, 'ore': 14}}),
  ('zero request #1',
   [{'inputs': {'hide': 2}, 'output': 'belt', 'yield': 1, 'stack': 3}, {'hide': 8}, 0, 80],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'hide': 8}}),
  ('control #1',
   [{'inputs': {'ore': 4, 'gem': 4, 'hide': 4}, 'output': 'blade', 'yield': 2, 'stack': 7},
    {'ore': 13, 'gem': 22, 'hide': 22, 'herb': 6},
    2,
    120],
   {'crafts': 2, 'made': 4, 'stacks': [4], 'left': {'gem': 14, 'herb': 6, 'hide': 14, 'ore': 5}}),
  ('control #2',
   [{'inputs': {'gem': 2}, 'output': 'blade', 'yield': 3, 'stack': 9}, {'gem': 19}, 0, 120],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'gem': 19}})],
 [('exact material multiple #1',
   [{'inputs': {'ore': 3}, 'output': 'bar', 'yield': 1, 'stack': 5}, {'ore': 15}, 10, 50],
   {'crafts': 5, 'made': 6, 'stacks': [5, 1], 'left': {'ore': 0}}),
  ('one short of a batch #1',
   [{'inputs': {'ore': 3, 'wood': 2}, 'output': 'axe', 'yield': 2, 'stack': 4},
    {'ore': 14, 'wood': 9, 'herb': 2},
    9,
    10],
   {'crafts': 4, 'made': 8, 'stacks': [4, 4], 'left': {'herb': 2, 'ore': 2, 'wood': 1}}),
  ('regression material availability #1',
   [{'inputs': {'ore': 2, 'wood': 4, 'hide': 2}, 'output': 'blade', 'yield': 3, 'stack': 6},
    {'ore': 20, 'wood': 13, 'hide': 16, 'herb': 2},
    9,
    120],
   {'crafts': 3, 'made': 9, 'stacks': [6, 3], 'left': {'herb': 2, 'hide': 10, 'ore': 14, 'wood': 1}}),
  ('regression material availability #2',
   [{'inputs': {'gem': 4, 'ore': 2}, 'output': 'blade', 'yield': 1, 'stack': 9},
    {'gem': 15, 'ore': 20, 'herb': 6},
    12,
    120],
   {'crafts': 3, 'made': 3, 'stacks': [3], 'left': {'gem': 3, 'herb': 6, 'ore': 14}}),
  ('regression material availability #3',
   [{'inputs': {'gem': 1, 'hide': 3}, 'output': 'blade', 'yield': 1, 'stack': 4},
    {'gem': 2, 'hide': 5, 'herb': 8},
    12,
    99],
   {'crafts': 1, 'made': 1, 'stacks': [1], 'left': {'gem': 1, 'herb': 8, 'hide': 2}}),
  ('regression material availability #4',
   [{'inputs': {'hide': 4}, 'output': 'blade', 'yield': 3, 'stack': 7}, {'hide': 15}, 7, 120],
   {'crafts': 3, 'made': 9, 'stacks': [7, 2], 'left': {'hide': 3}}),
  ('zero request #1',
   [{'inputs': {'hide': 2}, 'output': 'belt', 'yield': 1, 'stack': 3}, {'hide': 8}, 0, 80],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'hide': 8}}),
  ('control #1',
   [{'inputs': {'ore': 4, 'gem': 4, 'hide': 4}, 'output': 'blade', 'yield': 2, 'stack': 7},
    {'ore': 13, 'gem': 22, 'hide': 22, 'herb': 6},
    2,
    120],
   {'crafts': 2, 'made': 4, 'stacks': [4], 'left': {'gem': 14, 'herb': 6, 'hide': 14, 'ore': 5}})],
 [('one short of a batch #1',
   [{'inputs': {'ore': 3, 'wood': 2}, 'output': 'axe', 'yield': 2, 'stack': 4},
    {'ore': 14, 'wood': 9, 'herb': 2},
    9,
    10],
   {'crafts': 4, 'made': 8, 'stacks': [4, 4], 'left': {'herb': 2, 'ore': 2, 'wood': 1}}),
  ('regression material availability #1',
   [{'inputs': {'gem': 1, 'hide': 3}, 'output': 'blade', 'yield': 1, 'stack': 4},
    {'gem': 2, 'hide': 5, 'herb': 8},
    12,
    99],
   {'crafts': 1, 'made': 1, 'stacks': [1], 'left': {'gem': 1, 'herb': 8, 'hide': 2}}),
  ('fault site material availability #1',
   [{'inputs': {'hide': 1, 'gem': 2, 'wood': 1}, 'output': 'blade', 'yield': 3, 'stack': 10},
    {'hide': 28, 'gem': 10, 'wood': 23, 'herb': 6},
    8,
    120],
   {'crafts': 5, 'made': 16, 'stacks': [10, 6], 'left': {'gem': 0, 'herb': 6, 'hide': 23, 'wood': 18}}),
  ('regression material availability #2',
   [{'inputs': {'hide': 4}, 'output': 'blade', 'yield': 3, 'stack': 7}, {'hide': 15}, 7, 120],
   {'crafts': 3, 'made': 9, 'stacks': [7, 2], 'left': {'hide': 3}}),
  ('regression material availability #3',
   [{'inputs': {'ore': 2}, 'output': 'blade', 'yield': 3, 'stack': 8}, {'ore': 23, 'herb': 5}, 12, 99],
   {'crafts': 11, 'made': 35, 'stacks': [8, 8, 8, 8, 3], 'left': {'herb': 5, 'ore': 1}}),
  ('zero request #1',
   [{'inputs': {'hide': 2}, 'output': 'belt', 'yield': 1, 'stack': 3}, {'hide': 8}, 0, 80],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'hide': 8}}),
  ('control #1',
   [{'inputs': {'wood': 1, 'ore': 3, 'gem': 1}, 'output': 'blade', 'yield': 3, 'stack': 9},
    {'wood': 2, 'ore': 29, 'gem': 5, 'herb': 7},
    11,
    0],
   {'crafts': 2, 'made': 6, 'stacks': [6], 'left': {'gem': 3, 'herb': 7, 'ore': 23, 'wood': 0}}),
  ('control #2',
   [{'inputs': {'gem': 3, 'hide': 4}, 'output': 'blade', 'yield': 3, 'stack': 6},
    {'gem': 16, 'hide': 29},
    0,
    100],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'gem': 16, 'hide': 29}})],
 [('exact material multiple #1',
   [{'inputs': {'ore': 3}, 'output': 'bar', 'yield': 1, 'stack': 5}, {'ore': 15}, 10, 50],
   {'crafts': 5, 'made': 6, 'stacks': [5, 1], 'left': {'ore': 0}}),
  ('one short of a batch #1',
   [{'inputs': {'ore': 3, 'wood': 2}, 'output': 'axe', 'yield': 2, 'stack': 4},
    {'ore': 14, 'wood': 9, 'herb': 2},
    9,
    10],
   {'crafts': 4, 'made': 8, 'stacks': [4, 4], 'left': {'herb': 2, 'ore': 2, 'wood': 1}}),
  ('fault site material availability #1',
   [{'inputs': {'hide': 1, 'gem': 3, 'ore': 2}, 'output': 'blade', 'yield': 2, 'stack': 3},
    {'hide': 4, 'gem': 10, 'ore': 4, 'herb': 8},
    8,
    120],
   {'crafts': 2, 'made': 4, 'stacks': [3, 1], 'left': {'gem': 4, 'herb': 8, 'hide': 2, 'ore': 0}}),
  ('regression material availability #1',
   [{'inputs': {'hide': 4}, 'output': 'blade', 'yield': 3, 'stack': 7}, {'hide': 15}, 7, 120],
   {'crafts': 3, 'made': 9, 'stacks': [7, 2], 'left': {'hide': 3}}),
  ('regression material availability #2',
   [{'inputs': {'ore': 2, 'hide': 4, 'wood': 1}, 'output': 'blade', 'yield': 1, 'stack': 9},
    {'ore': 3, 'hide': 11, 'wood': 24, 'herb': 7},
    9,
    99],
   {'crafts': 1, 'made': 1, 'stacks': [1], 'left': {'herb': 7, 'hide': 7, 'ore': 1, 'wood': 23}}),
  ('regression material availability #3',
   [{'inputs': {'gem': 4, 'wood': 3, 'hide': 3}, 'output': 'blade', 'yield': 2, 'stack': 3},
    {'gem': 11, 'wood': 22, 'hide': 5, 'herb': 1},
    11,
    50],
   {'crafts': 1, 'made': 2, 'stacks': [2], 'left': {'gem': 7, 'herb': 1, 'hide': 2, 'wood': 19}}),
  ('zero request #1',
   [{'inputs': {'hide': 2}, 'output': 'belt', 'yield': 1, 'stack': 3}, {'hide': 8}, 0, 80],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'hide': 8}}),
  ('control #1',
   [{'inputs': {'gem': 1, 'hide': 3, 'ore': 4}, 'output': 'blade', 'yield': 1, 'stack': 6},
    {'gem': 15, 'hide': 15, 'ore': 26},
    2,
    49],
   {'crafts': 2, 'made': 2, 'stacks': [2], 'left': {'gem': 13, 'hide': 9, 'ore': 18}})]]
for label, args, expected in cases[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(recipe, inventory, requested, skill):
    if requested <= 0:
        crafts = 0
    else:
        crafts = requested
        for mat, qty in recipe['inputs'].items():
            crafts = min(crafts, (inventory.get(mat, 0) + qty - 1) // qty)
    bonus = crafts // 5 if skill >= 50 else 0
    made = crafts * recipe['yield'] + bonus
    cap = recipe['stack']
    stacks = [cap] * (made // cap)
    if made % cap:
        stacks.append(made % cap)
    left = dict(inventory)
    for mat, qty in recipe['inputs'].items():
        left[mat] = left.get(mat, 0) - crafts * qty
    return {'crafts': crafts, 'made': made, 'stacks': stacks, 'left': dict(sorted(left.items()))}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('exact material multiple #1',
   [{'inputs': {'ore': 3}, 'output': 'bar', 'yield': 1, 'stack': 5}, {'ore': 15}, 10, 50],
   {'crafts': 5, 'made': 6, 'stacks': [5, 1], 'left': {'ore': 0}}),
  ('one short of a batch #1',
   [{'inputs': {'ore': 3, 'wood': 2}, 'output': 'axe', 'yield': 2, 'stack': 4},
    {'ore': 14, 'wood': 9, 'herb': 2},
    9,
    10],
   {'crafts': 4, 'made': 8, 'stacks': [4, 4], 'left': {'herb': 2, 'ore': 2, 'wood': 1}}),
  ('regression material availability #1',
   [{'inputs': {'ore': 4}, 'output': 'blade', 'yield': 3, 'stack': 10}, {'ore': 6}, 2, 51],
   {'crafts': 1, 'made': 3, 'stacks': [3], 'left': {'ore': 2}}),
  ('regression material availability #2',
   [{'inputs': {'wood': 2, 'hide': 3, 'gem': 3}, 'output': 'blade', 'yield': 3, 'stack': 7},
    {'wood': 12, 'hide': 23, 'gem': 11},
    4,
    51],
   {'crafts': 3, 'made': 9, 'stacks': [7, 2], 'left': {'gem': 2, 'hide': 14, 'wood': 6}}),
  ('regression material availability #3',
   [{'inputs': {'ore': 2, 'wood': 4, 'hide': 2}, 'output': 'blade', 'yield': 3, 'stack': 6},
    {'ore': 20, 'wood': 13, 'hide': 16, 'herb': 2},
    9,
    120],
   {'crafts': 3, 'made': 9, 'stacks': [6, 3], 'left': {'herb': 2, 'hide': 10, 'ore': 14, 'wood': 1}}),
  ('regression material availability #4',
   [{'inputs': {'gem': 4, 'ore': 2}, 'output': 'blade', 'yield': 1, 'stack': 9},
    {'gem': 15, 'ore': 20, 'herb': 6},
    12,
    120],
   {'crafts': 3, 'made': 3, 'stacks': [3], 'left': {'gem': 3, 'herb': 6, 'ore': 14}}),
  ('zero request #1',
   [{'inputs': {'hide': 2}, 'output': 'belt', 'yield': 1, 'stack': 3}, {'hide': 8}, 0, 80],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'hide': 8}}),
  ('control #1',
   [{'inputs': {'hide': 3, 'ore': 1}, 'output': 'blade', 'yield': 1, 'stack': 5},
    {'hide': 21, 'ore': 5},
    3,
    99],
   {'crafts': 3, 'made': 3, 'stacks': [3], 'left': {'hide': 12, 'ore': 2}})],
 [('one short of a batch #1',
   [{'inputs': {'ore': 3, 'wood': 2}, 'output': 'axe', 'yield': 2, 'stack': 4},
    {'ore': 14, 'wood': 9, 'herb': 2},
    9,
    10],
   {'crafts': 4, 'made': 8, 'stacks': [4, 4], 'left': {'herb': 2, 'ore': 2, 'wood': 1}}),
  ('regression material availability #1',
   [{'inputs': {'ore': 4}, 'output': 'blade', 'yield': 3, 'stack': 10}, {'ore': 6}, 2, 51],
   {'crafts': 1, 'made': 3, 'stacks': [3], 'left': {'ore': 2}}),
  ('regression material availability #2',
   [{'inputs': {'wood': 2, 'hide': 3, 'gem': 3}, 'output': 'blade', 'yield': 3, 'stack': 7},
    {'wood': 12, 'hide': 23, 'gem': 11},
    4,
    51],
   {'crafts': 3, 'made': 9, 'stacks': [7, 2], 'left': {'gem': 2, 'hide': 14, 'wood': 6}}),
  ('regression material availability #3',
   [{'inputs': {'ore': 2, 'wood': 4, 'hide': 2}, 'output': 'blade', 'yield': 3, 'stack': 6},
    {'ore': 20, 'wood': 13, 'hide': 16, 'herb': 2},
    9,
    120],
   {'crafts': 3, 'made': 9, 'stacks': [6, 3], 'left': {'herb': 2, 'hide': 10, 'ore': 14, 'wood': 1}}),
  ('regression material availability #4',
   [{'inputs': {'gem': 4, 'ore': 2}, 'output': 'blade', 'yield': 1, 'stack': 9},
    {'gem': 15, 'ore': 20, 'herb': 6},
    12,
    120],
   {'crafts': 3, 'made': 3, 'stacks': [3], 'left': {'gem': 3, 'herb': 6, 'ore': 14}}),
  ('zero request #1',
   [{'inputs': {'hide': 2}, 'output': 'belt', 'yield': 1, 'stack': 3}, {'hide': 8}, 0, 80],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'hide': 8}}),
  ('control #1',
   [{'inputs': {'ore': 4, 'gem': 4, 'hide': 4}, 'output': 'blade', 'yield': 2, 'stack': 7},
    {'ore': 13, 'gem': 22, 'hide': 22, 'herb': 6},
    2,
    120],
   {'crafts': 2, 'made': 4, 'stacks': [4], 'left': {'gem': 14, 'herb': 6, 'hide': 14, 'ore': 5}}),
  ('control #2',
   [{'inputs': {'gem': 2}, 'output': 'blade', 'yield': 3, 'stack': 9}, {'gem': 19}, 0, 120],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'gem': 19}})],
 [('exact material multiple #1',
   [{'inputs': {'ore': 3}, 'output': 'bar', 'yield': 1, 'stack': 5}, {'ore': 15}, 10, 50],
   {'crafts': 5, 'made': 6, 'stacks': [5, 1], 'left': {'ore': 0}}),
  ('one short of a batch #1',
   [{'inputs': {'ore': 3, 'wood': 2}, 'output': 'axe', 'yield': 2, 'stack': 4},
    {'ore': 14, 'wood': 9, 'herb': 2},
    9,
    10],
   {'crafts': 4, 'made': 8, 'stacks': [4, 4], 'left': {'herb': 2, 'ore': 2, 'wood': 1}}),
  ('regression material availability #1',
   [{'inputs': {'ore': 2, 'wood': 4, 'hide': 2}, 'output': 'blade', 'yield': 3, 'stack': 6},
    {'ore': 20, 'wood': 13, 'hide': 16, 'herb': 2},
    9,
    120],
   {'crafts': 3, 'made': 9, 'stacks': [6, 3], 'left': {'herb': 2, 'hide': 10, 'ore': 14, 'wood': 1}}),
  ('regression material availability #2',
   [{'inputs': {'gem': 4, 'ore': 2}, 'output': 'blade', 'yield': 1, 'stack': 9},
    {'gem': 15, 'ore': 20, 'herb': 6},
    12,
    120],
   {'crafts': 3, 'made': 3, 'stacks': [3], 'left': {'gem': 3, 'herb': 6, 'ore': 14}}),
  ('regression material availability #3',
   [{'inputs': {'gem': 1, 'hide': 3}, 'output': 'blade', 'yield': 1, 'stack': 4},
    {'gem': 2, 'hide': 5, 'herb': 8},
    12,
    99],
   {'crafts': 1, 'made': 1, 'stacks': [1], 'left': {'gem': 1, 'herb': 8, 'hide': 2}}),
  ('regression material availability #4',
   [{'inputs': {'hide': 4}, 'output': 'blade', 'yield': 3, 'stack': 7}, {'hide': 15}, 7, 120],
   {'crafts': 3, 'made': 9, 'stacks': [7, 2], 'left': {'hide': 3}}),
  ('zero request #1',
   [{'inputs': {'hide': 2}, 'output': 'belt', 'yield': 1, 'stack': 3}, {'hide': 8}, 0, 80],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'hide': 8}}),
  ('control #1',
   [{'inputs': {'ore': 4, 'gem': 4, 'hide': 4}, 'output': 'blade', 'yield': 2, 'stack': 7},
    {'ore': 13, 'gem': 22, 'hide': 22, 'herb': 6},
    2,
    120],
   {'crafts': 2, 'made': 4, 'stacks': [4], 'left': {'gem': 14, 'herb': 6, 'hide': 14, 'ore': 5}})],
 [('one short of a batch #1',
   [{'inputs': {'ore': 3, 'wood': 2}, 'output': 'axe', 'yield': 2, 'stack': 4},
    {'ore': 14, 'wood': 9, 'herb': 2},
    9,
    10],
   {'crafts': 4, 'made': 8, 'stacks': [4, 4], 'left': {'herb': 2, 'ore': 2, 'wood': 1}}),
  ('regression material availability #1',
   [{'inputs': {'gem': 1, 'hide': 3}, 'output': 'blade', 'yield': 1, 'stack': 4},
    {'gem': 2, 'hide': 5, 'herb': 8},
    12,
    99],
   {'crafts': 1, 'made': 1, 'stacks': [1], 'left': {'gem': 1, 'herb': 8, 'hide': 2}}),
  ('fault site material availability #1',
   [{'inputs': {'hide': 1, 'gem': 2, 'wood': 1}, 'output': 'blade', 'yield': 3, 'stack': 10},
    {'hide': 28, 'gem': 10, 'wood': 23, 'herb': 6},
    8,
    120],
   {'crafts': 5, 'made': 16, 'stacks': [10, 6], 'left': {'gem': 0, 'herb': 6, 'hide': 23, 'wood': 18}}),
  ('regression material availability #2',
   [{'inputs': {'hide': 4}, 'output': 'blade', 'yield': 3, 'stack': 7}, {'hide': 15}, 7, 120],
   {'crafts': 3, 'made': 9, 'stacks': [7, 2], 'left': {'hide': 3}}),
  ('regression material availability #3',
   [{'inputs': {'ore': 2}, 'output': 'blade', 'yield': 3, 'stack': 8}, {'ore': 23, 'herb': 5}, 12, 99],
   {'crafts': 11, 'made': 35, 'stacks': [8, 8, 8, 8, 3], 'left': {'herb': 5, 'ore': 1}}),
  ('zero request #1',
   [{'inputs': {'hide': 2}, 'output': 'belt', 'yield': 1, 'stack': 3}, {'hide': 8}, 0, 80],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'hide': 8}}),
  ('control #1',
   [{'inputs': {'wood': 1, 'ore': 3, 'gem': 1}, 'output': 'blade', 'yield': 3, 'stack': 9},
    {'wood': 2, 'ore': 29, 'gem': 5, 'herb': 7},
    11,
    0],
   {'crafts': 2, 'made': 6, 'stacks': [6], 'left': {'gem': 3, 'herb': 7, 'ore': 23, 'wood': 0}}),
  ('control #2',
   [{'inputs': {'gem': 3, 'hide': 4}, 'output': 'blade', 'yield': 3, 'stack': 6},
    {'gem': 16, 'hide': 29},
    0,
    100],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'gem': 16, 'hide': 29}})],
 [('exact material multiple #1',
   [{'inputs': {'ore': 3}, 'output': 'bar', 'yield': 1, 'stack': 5}, {'ore': 15}, 10, 50],
   {'crafts': 5, 'made': 6, 'stacks': [5, 1], 'left': {'ore': 0}}),
  ('one short of a batch #1',
   [{'inputs': {'ore': 3, 'wood': 2}, 'output': 'axe', 'yield': 2, 'stack': 4},
    {'ore': 14, 'wood': 9, 'herb': 2},
    9,
    10],
   {'crafts': 4, 'made': 8, 'stacks': [4, 4], 'left': {'herb': 2, 'ore': 2, 'wood': 1}}),
  ('fault site material availability #1',
   [{'inputs': {'hide': 1, 'gem': 3, 'ore': 2}, 'output': 'blade', 'yield': 2, 'stack': 3},
    {'hide': 4, 'gem': 10, 'ore': 4, 'herb': 8},
    8,
    120],
   {'crafts': 2, 'made': 4, 'stacks': [3, 1], 'left': {'gem': 4, 'herb': 8, 'hide': 2, 'ore': 0}}),
  ('regression material availability #1',
   [{'inputs': {'hide': 4}, 'output': 'blade', 'yield': 3, 'stack': 7}, {'hide': 15}, 7, 120],
   {'crafts': 3, 'made': 9, 'stacks': [7, 2], 'left': {'hide': 3}}),
  ('regression material availability #2',
   [{'inputs': {'ore': 2, 'hide': 4, 'wood': 1}, 'output': 'blade', 'yield': 1, 'stack': 9},
    {'ore': 3, 'hide': 11, 'wood': 24, 'herb': 7},
    9,
    99],
   {'crafts': 1, 'made': 1, 'stacks': [1], 'left': {'herb': 7, 'hide': 7, 'ore': 1, 'wood': 23}}),
  ('regression material availability #3',
   [{'inputs': {'gem': 4, 'wood': 3, 'hide': 3}, 'output': 'blade', 'yield': 2, 'stack': 3},
    {'gem': 11, 'wood': 22, 'hide': 5, 'herb': 1},
    11,
    50],
   {'crafts': 1, 'made': 2, 'stacks': [2], 'left': {'gem': 7, 'herb': 1, 'hide': 2, 'wood': 19}}),
  ('zero request #1',
   [{'inputs': {'hide': 2}, 'output': 'belt', 'yield': 1, 'stack': 3}, {'hide': 8}, 0, 80],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'hide': 8}}),
  ('control #1',
   [{'inputs': {'gem': 1, 'hide': 3, 'ore': 4}, 'output': 'blade', 'yield': 1, 'stack': 6},
    {'gem': 15, 'hide': 15, 'ore': 26},
    2,
    49],
   {'crafts': 2, 'made': 2, 'stacks': [2], 'left': {'gem': 13, 'hide': 9, 'ore': 18}})]]
for label, args, expected in cases[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:
More crafts are performed than the stockpile can pay for and inventories go negative.

recipe = {inputs:{material:qty}, output, yield, stack}. Crafts = min(requested, floor(have/qty) per input), 0 when requested <= 0. With skill in [50, inf) every 5th craft adds one bonus item (bonus = crafts//5). made = crafts*yield + bonus, split into full stacks of size stack plus one partial stack. left = whole inventory (all materials) after consuming crafts*qty of each input, sorted by name.

split: open-access


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

N = 1
observations = []
def solve(recipe, inventory, requested, skill):
    if requested <= 0:
        crafts = 0
    else:
        crafts = requested
        for mat, qty in recipe['inputs'].items():
            crafts = min(crafts, inventory.get(mat, 0) // qty)
    bonus = crafts // 5 if skill > 50 else 0
    made = crafts * recipe['yield'] + bonus
    cap = recipe['stack']
    stacks = [cap] * (made // cap)
    if made % cap:
        stacks.append(made % cap)
    left = dict(inventory)
    for mat, qty in recipe['inputs'].items():
        left[mat] = left.get(mat, 0) - crafts * qty
    return {'crafts': crafts, 'made': made, 'stacks': stacks, 'left': dict(sorted(left.items()))}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('exact material multiple #1',
   [{'inputs': {'ore': 3}, 'output': 'bar', 'yield': 1, 'stack': 5}, {'ore': 15}, 10, 50],
   {'crafts': 5, 'made': 6, 'stacks': [5, 1], 'left': {'ore': 0}}),
  ('fault site bonus skill gate #1',
   [{'inputs': {'hide': 2}, 'output': 'blade', 'yield': 3, 'stack': 8}, {'hide': 23}, 9, 50],
   {'crafts': 9, 'made': 28, 'stacks': [8, 8, 8, 4], 'left': {'hide': 5}}),
  ('fault site bonus skill gate #2',
   [{'inputs': {'gem': 2, 'ore': 3}, 'output': 'blade', 'yield': 2, 'stack': 9},
    {'gem': 19, 'ore': 25},
    9,
    50],
   {'crafts': 8, 'made': 17, 'stacks': [9, 8], 'left': {'gem': 3, 'ore': 1}}),
  ('partial repair boundary #1',
   [{'inputs': {'hide': 1, 'gem': 2, 'wood': 1}, 'output': 'blade', 'yield': 3, 'stack': 10},
    {'hide': 28, 'gem': 10, 'wood': 23, 'herb': 6},
    8,
    120],
   {'crafts': 5, 'made': 16, 'stacks': [10, 6], 'left': {'gem': 0, 'herb': 6, 'hide': 23, 'wood': 18}}),
  ('partial repair boundary #2',
   [{'inputs': {'gem': 1}, 'output': 'blade', 'yield': 3, 'stack': 6}, {'gem': 27, 'herb': 8}, 7, 101],
   {'crafts': 7, 'made': 22, 'stacks': [6, 6, 6, 4], 'left': {'gem': 20, 'herb': 8}}),
  ('one short of a batch #1',
   [{'inputs': {'ore': 3, 'wood': 2}, 'output': 'axe', 'yield': 2, 'stack': 4},
    {'ore': 14, 'wood': 9, 'herb': 2},
    9,
    10],
   {'crafts': 4, 'made': 8, 'stacks': [4, 4], 'left': {'herb': 2, 'ore': 2, 'wood': 1}}),
  ('zero request #1',
   [{'inputs': {'hide': 2}, 'output': 'belt', 'yield': 1, 'stack': 3}, {'hide': 8}, 0, 80],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'hide': 8}}),
  ('control #1',
   [{'inputs': {'ore': 4}, 'output': 'blade', 'yield': 3, 'stack': 10}, {'ore': 6}, 2, 51],
   {'crafts': 1, 'made': 3, 'stacks': [3], 'left': {'ore': 2}})],
 [('exact material multiple #1',
   [{'inputs': {'ore': 3}, 'output': 'bar', 'yield': 1, 'stack': 5}, {'ore': 15}, 10, 50],
   {'crafts': 5, 'made': 6, 'stacks': [5, 1], 'left': {'ore': 0}}),
  ('fault site bonus skill gate #1',
   [{'inputs': {'gem': 2, 'ore': 3}, 'output': 'blade', 'yield': 2, 'stack': 9},
    {'gem': 19, 'ore': 25},
    9,
    50],
   {'crafts': 8, 'made': 17, 'stacks': [9, 8], 'left': {'gem': 3, 'ore': 1}}),
  ('fault site bonus skill gate #2',
   [{'inputs': {'hide': 2}, 'output': 'blade', 'yield': 3, 'stack': 8}, {'hide': 23}, 9, 50],
   {'crafts': 9, 'made': 28, 'stacks': [8, 8, 8, 4], 'left': {'hide': 5}}),
  ('partial repair boundary #1',
   [{'inputs': {'ore': 2}, 'output': 'blade', 'yield': 2, 'stack': 8}, {'ore': 28}, 5, 100],
   {'crafts': 5, 'made': 11, 'stacks': [8, 3], 'left': {'ore': 18}}),
  ('partial repair boundary #2',
   [{'inputs': {'wood': 1}, 'output': 'blade', 'yield': 3, 'stack': 7}, {'wood': 7}, 12, 120],
   {'crafts': 7, 'made': 22, 'stacks': [7, 7, 7, 1], 'left': {'wood': 0}}),
  ('one short of a batch #1',
   [{'inputs': {'ore': 3, 'wood': 2}, 'output': 'axe', 'yield': 2, 'stack': 4},
    {'ore': 14, 'wood': 9, 'herb': 2},
    9,
    10],
   {'crafts': 4, 'made': 8, 'stacks': [4, 4], 'left': {'herb': 2, 'ore': 2, 'wood': 1}}),
  ('zero request #1',
   [{'inputs': {'hide': 2}, 'output': 'belt', 'yield': 1, 'stack': 3}, {'hide': 8}, 0, 80],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'hide': 8}}),
  ('control #1',
   [{'inputs': {'ore': 4}, 'output': 'blade', 'yield': 3, 'stack': 10}, {'ore': 6}, 2, 51],
   {'crafts': 1, 'made': 3, 'stacks': [3], 'left': {'ore': 2}})],
 [('exact material multiple #1',
   [{'inputs': {'ore': 3}, 'output': 'bar', 'yield': 1, 'stack': 5}, {'ore': 15}, 10, 50],
   {'crafts': 5, 'made': 6, 'stacks': [5, 1], 'left': {'ore': 0}}),
  ('fault site bonus skill gate #1',
   [{'inputs': {'hide': 2}, 'output': 'blade', 'yield': 3, 'stack': 8}, {'hide': 23}, 9, 50],
   {'crafts': 9, 'made': 28, 'stacks': [8, 8, 8, 4], 'left': {'hide': 5}}),
  ('fault site bonus skill gate #2',
   [{'inputs': {'gem': 2, 'ore': 3}, 'output': 'blade', 'yield': 2, 'stack': 9},
    {'gem': 19, 'ore': 25},
    9,
    50],
   {'crafts': 8, 'made': 17, 'stacks': [9, 8], 'left': {'gem': 3, 'ore': 1}}),
  ('partial repair boundary #1',
   [{'inputs': {'hide': 3}, 'output': 'blade', 'yield': 1, 'stack': 6}, {'hide': 22}, 8, 100],
   {'crafts': 7, 'made': 8, 'stacks': [6, 2], 'left': {'hide': 1}}),
  ('partial repair boundary #2',
   [{'inputs': {'gem': 4, 'hide': 1, 'ore': 1}, 'output': 'blade', 'yield': 2, 'stack': 9},
    {'gem': 29, 'hide': 25, 'ore': 26},
    8,
    120],
   {'crafts': 7, 'made': 15, 'stacks': [9, 6], 'left': {'gem': 1, 'hide': 18, 'ore': 19}}),
  ('one short of a batch #1',
   [{'inputs': {'ore': 3, 'wood': 2}, 'output': 'axe', 'yield': 2, 'stack': 4},
    {'ore': 14, 'wood': 9, 'herb': 2},
    9,
    10],
   {'crafts': 4, 'made': 8, 'stacks': [4, 4], 'left': {'herb': 2, 'ore': 2, 'wood': 1}}),
  ('zero request #1',
   [{'inputs': {'hide': 2}, 'output': 'belt', 'yield': 1, 'stack': 3}, {'hide': 8}, 0, 80],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'hide': 8}}),
  ('control #1',
   [{'inputs': {'ore': 4}, 'output': 'blade', 'yield': 3, 'stack': 10}, {'ore': 6}, 2, 51],
   {'crafts': 1, 'made': 3, 'stacks': [3], 'left': {'ore': 2}})],
 [('exact material multiple #1',
   [{'inputs': {'ore': 3}, 'output': 'bar', 'yield': 1, 'stack': 5}, {'ore': 15}, 10, 50],
   {'crafts': 5, 'made': 6, 'stacks': [5, 1], 'left': {'ore': 0}}),
  ('fault site bonus skill gate #1',
   [{'inputs': {'hide': 2}, 'output': 'blade', 'yield': 3, 'stack': 8}, {'hide': 23}, 9, 50],
   {'crafts': 9, 'made': 28, 'stacks': [8, 8, 8, 4], 'left': {'hide': 5}}),
  ('fault site bonus skill gate #2',
   [{'inputs': {'gem': 2, 'ore': 3}, 'output': 'blade', 'yield': 2, 'stack': 9},
    {'gem': 19, 'ore': 25},
    9,
    50],
   {'crafts': 8, 'made': 17, 'stacks': [9, 8], 'left': {'gem': 3, 'ore': 1}}),
  ('partial repair boundary #1',
   [{'inputs': {'hide': 3, 'wood': 2}, 'output': 'blade', 'yield': 2, 'stack': 10},
    {'hide': 29, 'wood': 21, 'herb': 6},
    7,
    101],
   {'crafts': 7, 'made': 15, 'stacks': [10, 5], 'left': {'herb': 6, 'hide': 8, 'wood': 7}}),
  ('partial repair boundary #2',
   [{'inputs': {'gem': 2, 'wood': 3}, 'output': 'blade', 'yield': 1, 'stack': 3},
    {'gem': 30, 'wood': 19},
    10,
    101],
   {'crafts': 6, 'made': 7, 'stacks': [3, 3, 1], 'left': {'gem': 18, 'wood': 1}}),
  ('one short of a batch #1',
   [{'inputs': {'ore': 3, 'wood': 2}, 'output': 'axe', 'yield': 2, 'stack': 4},
    {'ore': 14, 'wood': 9, 'herb': 2},
    9,
    10],
   {'crafts': 4, 'made': 8, 'stacks': [4, 4], 'left': {'herb': 2, 'ore': 2, 'wood': 1}}),
  ('zero request #1',
   [{'inputs': {'hide': 2}, 'output': 'belt', 'yield': 1, 'stack': 3}, {'hide': 8}, 0, 80],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'hide': 8}}),
  ('control #1',
   [{'inputs': {'hide': 3, 'ore': 1}, 'output': 'blade', 'yield': 1, 'stack': 5},
    {'hide': 21, 'ore': 5},
    3,
    99],
   {'crafts': 3, 'made': 3, 'stacks': [3], 'left': {'hide': 12, 'ore': 2}})],
 [('exact material multiple #1',
   [{'inputs': {'ore': 3}, 'output': 'bar', 'yield': 1, 'stack': 5}, {'ore': 15}, 10, 50],
   {'crafts': 5, 'made': 6, 'stacks': [5, 1], 'left': {'ore': 0}}),
  ('fault site bonus skill gate #1',
   [{'inputs': {'gem': 2, 'ore': 3}, 'output': 'blade', 'yield': 2, 'stack': 9},
    {'gem': 19, 'ore': 25},
    9,
    50],
   {'crafts': 8, 'made': 17, 'stacks': [9, 8], 'left': {'gem': 3, 'ore': 1}}),
  ('fault site bonus skill gate #2',
   [{'inputs': {'hide': 2}, 'output': 'blade', 'yield': 3, 'stack': 8}, {'hide': 23}, 9, 50],
   {'crafts': 9, 'made': 28, 'stacks': [8, 8, 8, 4], 'left': {'hide': 5}}),
  ('partial repair boundary #1',
   [{'inputs': {'hide': 3}, 'output': 'blade', 'yield': 3, 'stack': 6}, {'hide': 25}, 12, 100],
   {'crafts': 8, 'made': 25, 'stacks': [6, 6, 6, 6, 1], 'left': {'hide': 1}}),
  ('partial repair boundary #2',
   [{'inputs': {'hide': 2, 'ore': 1, 'gem': 3}, 'output': 'blade', 'yield': 2, 'stack': 7},
    {'hide': 23, 'ore': 8, 'gem': 26, 'herb': 2},
    8,
    120],
   {'crafts': 8, 'made': 17, 'stacks': [7, 7, 3], 'left': {'gem': 2, 'herb': 2, 'hide': 7, 'ore': 0}}),
  ('one short of a batch #1',
   [{'inputs': {'ore': 3, 'wood': 2}, 'output': 'axe', 'yield': 2, 'stack': 4},
    {'ore': 14, 'wood': 9, 'herb': 2},
    9,
    10],
   {'crafts': 4, 'made': 8, 'stacks': [4, 4], 'left': {'herb': 2, 'ore': 2, 'wood': 1}}),
  ('zero request #1',
   [{'inputs': {'hide': 2}, 'output': 'belt', 'yield': 1, 'stack': 3}, {'hide': 8}, 0, 80],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'hide': 8}}),
  ('control #1',
   [{'inputs': {'wood': 2, 'hide': 3, 'gem': 3}, 'output': 'blade', 'yield': 3, 'stack': 7},
    {'wood': 12, 'hide': 23, 'gem': 11},
    4,
    51],
   {'crafts': 3, 'made': 9, 'stacks': [7, 2], 'left': {'gem': 2, 'hide': 14, 'wood': 6}})]]
for label, args, expected in cases[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(recipe, inventory, requested, skill):
    if requested <= 0:
        crafts = 0
    else:
        crafts = requested
        for mat, qty in recipe['inputs'].items():
            crafts = min(crafts, inventory.get(mat, 0) // qty)
    bonus = crafts // 5 if skill > 49 and skill < 100 else 0
    made = crafts * recipe['yield'] + bonus
    cap = recipe['stack']
    stacks = [cap] * (made // cap)
    if made % cap:
        stacks.append(made % cap)
    left = dict(inventory)
    for mat, qty in recipe['inputs'].items():
        left[mat] = left.get(mat, 0) - crafts * qty
    return {'crafts': crafts, 'made': made, 'stacks': stacks, 'left': dict(sorted(left.items()))}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('exact material multiple #1',
   [{'inputs': {'ore': 3}, 'output': 'bar', 'yield': 1, 'stack': 5}, {'ore': 15}, 10, 50],
   {'crafts': 5, 'made': 6, 'stacks': [5, 1], 'left': {'ore': 0}}),
  ('fault site bonus skill gate #1',
   [{'inputs': {'hide': 2}, 'output': 'blade', 'yield': 3, 'stack': 8}, {'hide': 23}, 9, 50],
   {'crafts': 9, 'made': 28, 'stacks': [8, 8, 8, 4], 'left': {'hide': 5}}),
  ('fault site bonus skill gate #2',
   [{'inputs': {'gem': 2, 'ore': 3}, 'output': 'blade', 'yield': 2, 'stack': 9},
    {'gem': 19, 'ore': 25},
    9,
    50],
   {'crafts': 8, 'made': 17, 'stacks': [9, 8], 'left': {'gem': 3, 'ore': 1}}),
  ('partial repair boundary #1',
   [{'inputs': {'hide': 1, 'gem': 2, 'wood': 1}, 'output': 'blade', 'yield': 3, 'stack': 10},
    {'hide': 28, 'gem': 10, 'wood': 23, 'herb': 6},
    8,
    120],
   {'crafts': 5, 'made': 16, 'stacks': [10, 6], 'left': {'gem': 0, 'herb': 6, 'hide': 23, 'wood': 18}}),
  ('partial repair boundary #2',
   [{'inputs': {'gem': 1}, 'output': 'blade', 'yield': 3, 'stack': 6}, {'gem': 27, 'herb': 8}, 7, 101],
   {'crafts': 7, 'made': 22, 'stacks': [6, 6, 6, 4], 'left': {'gem': 20, 'herb': 8}}),
  ('one short of a batch #1',
   [{'inputs': {'ore': 3, 'wood': 2}, 'output': 'axe', 'yield': 2, 'stack': 4},
    {'ore': 14, 'wood': 9, 'herb': 2},
    9,
    10],
   {'crafts': 4, 'made': 8, 'stacks': [4, 4], 'left': {'herb': 2, 'ore': 2, 'wood': 1}}),
  ('zero request #1',
   [{'inputs': {'hide': 2}, 'output': 'belt', 'yield': 1, 'stack': 3}, {'hide': 8}, 0, 80],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'hide': 8}}),
  ('control #1',
   [{'inputs': {'ore': 4}, 'output': 'blade', 'yield': 3, 'stack': 10}, {'ore': 6}, 2, 51],
   {'crafts': 1, 'made': 3, 'stacks': [3], 'left': {'ore': 2}})],
 [('exact material multiple #1',
   [{'inputs': {'ore': 3}, 'output': 'bar', 'yield': 1, 'stack': 5}, {'ore': 15}, 10, 50],
   {'crafts': 5, 'made': 6, 'stacks': [5, 1], 'left': {'ore': 0}}),
  ('fault site bonus skill gate #1',
   [{'inputs': {'gem': 2, 'ore': 3}, 'output': 'blade', 'yield': 2, 'stack': 9},
    {'gem': 19, 'ore': 25},
    9,
    50],
   {'crafts': 8, 'made': 17, 'stacks': [9, 8], 'left': {'gem': 3, 'ore': 1}}),
  ('fault site bonus skill gate #2',
   [{'inputs': {'hide': 2}, 'output': 'blade', 'yield': 3, 'stack': 8}, {'hide': 23}, 9, 50],
   {'crafts': 9, 'made': 28, 'stacks': [8, 8, 8, 4], 'left': {'hide': 5}}),
  ('partial repair boundary #1',
   [{'inputs': {'ore': 2}, 'output': 'blade', 'yield': 2, 'stack': 8}, {'ore': 28}, 5, 100],
   {'crafts': 5, 'made': 11, 'stacks': [8, 3], 'left': {'ore': 18}}),
  ('partial repair boundary #2',
   [{'inputs': {'wood': 1}, 'output': 'blade', 'yield': 3, 'stack': 7}, {'wood': 7}, 12, 120],
   {'crafts': 7, 'made': 22, 'stacks': [7, 7, 7, 1], 'left': {'wood': 0}}),
  ('one short of a batch #1',
   [{'inputs': {'ore': 3, 'wood': 2}, 'output': 'axe', 'yield': 2, 'stack': 4},
    {'ore': 14, 'wood': 9, 'herb': 2},
    9,
    10],
   {'crafts': 4, 'made': 8, 'stacks': [4, 4], 'left': {'herb': 2, 'ore': 2, 'wood': 1}}),
  ('zero request #1',
   [{'inputs': {'hide': 2}, 'output': 'belt', 'yield': 1, 'stack': 3}, {'hide': 8}, 0, 80],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'hide': 8}}),
  ('control #1',
   [{'inputs': {'ore': 4}, 'output': 'blade', 'yield': 3, 'stack': 10}, {'ore': 6}, 2, 51],
   {'crafts': 1, 'made': 3, 'stacks': [3], 'left': {'ore': 2}})],
 [('exact material multiple #1',
   [{'inputs': {'ore': 3}, 'output': 'bar', 'yield': 1, 'stack': 5}, {'ore': 15}, 10, 50],
   {'crafts': 5, 'made': 6, 'stacks': [5, 1], 'left': {'ore': 0}}),
  ('fault site bonus skill gate #1',
   [{'inputs': {'hide': 2}, 'output': 'blade', 'yield': 3, 'stack': 8}, {'hide': 23}, 9, 50],
   {'crafts': 9, 'made': 28, 'stacks': [8, 8, 8, 4], 'left': {'hide': 5}}),
  ('fault site bonus skill gate #2',
   [{'inputs': {'gem': 2, 'ore': 3}, 'output': 'blade', 'yield': 2, 'stack': 9},
    {'gem': 19, 'ore': 25},
    9,
    50],
   {'crafts': 8, 'made': 17, 'stacks': [9, 8], 'left': {'gem': 3, 'ore': 1}}),
  ('partial repair boundary #1',
   [{'inputs': {'hide': 3}, 'output': 'blade', 'yield': 1, 'stack': 6}, {'hide': 22}, 8, 100],
   {'crafts': 7, 'made': 8, 'stacks': [6, 2], 'left': {'hide': 1}}),
  ('partial repair boundary #2',
   [{'inputs': {'gem': 4, 'hide': 1, 'ore': 1}, 'output': 'blade', 'yield': 2, 'stack': 9},
    {'gem': 29, 'hide': 25, 'ore': 26},
    8,
    120],
   {'crafts': 7, 'made': 15, 'stacks': [9, 6], 'left': {'gem': 1, 'hide': 18, 'ore': 19}}),
  ('one short of a batch #1',
   [{'inputs': {'ore': 3, 'wood': 2}, 'output': 'axe', 'yield': 2, 'stack': 4},
    {'ore': 14, 'wood': 9, 'herb': 2},
    9,
    10],
   {'crafts': 4, 'made': 8, 'stacks': [4, 4], 'left': {'herb': 2, 'ore': 2, 'wood': 1}}),
  ('zero request #1',
   [{'inputs': {'hide': 2}, 'output': 'belt', 'yield': 1, 'stack': 3}, {'hide': 8}, 0, 80],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'hide': 8}}),
  ('control #1',
   [{'inputs': {'ore': 4}, 'output': 'blade', 'yield': 3, 'stack': 10}, {'ore': 6}, 2, 51],
   {'crafts': 1, 'made': 3, 'stacks': [3], 'left': {'ore': 2}})],
 [('exact material multiple #1',
   [{'inputs': {'ore': 3}, 'output': 'bar', 'yield': 1, 'stack': 5}, {'ore': 15}, 10, 50],
   {'crafts': 5, 'made': 6, 'stacks': [5, 1], 'left': {'ore': 0}}),
  ('fault site bonus skill gate #1',
   [{'inputs': {'hide': 2}, 'output': 'blade', 'yield': 3, 'stack': 8}, {'hide': 23}, 9, 50],
   {'crafts': 9, 'made': 28, 'stacks': [8, 8, 8, 4], 'left': {'hide': 5}}),
  ('fault site bonus skill gate #2',
   [{'inputs': {'gem': 2, 'ore': 3}, 'output': 'blade', 'yield': 2, 'stack': 9},
    {'gem': 19, 'ore': 25},
    9,
    50],
   {'crafts': 8, 'made': 17, 'stacks': [9, 8], 'left': {'gem': 3, 'ore': 1}}),
  ('partial repair boundary #1',
   [{'inputs': {'hide': 3, 'wood': 2}, 'output': 'blade', 'yield': 2, 'stack': 10},
    {'hide': 29, 'wood': 21, 'herb': 6},
    7,
    101],
   {'crafts': 7, 'made': 15, 'stacks': [10, 5], 'left': {'herb': 6, 'hide': 8, 'wood': 7}}),
  ('partial repair boundary #2',
   [{'inputs': {'gem': 2, 'wood': 3}, 'output': 'blade', 'yield': 1, 'stack': 3},
    {'gem': 30, 'wood': 19},
    10,
    101],
   {'crafts': 6, 'made': 7, 'stacks': [3, 3, 1], 'left': {'gem': 18, 'wood': 1}}),
  ('one short of a batch #1',
   [{'inputs': {'ore': 3, 'wood': 2}, 'output': 'axe', 'yield': 2, 'stack': 4},
    {'ore': 14, 'wood': 9, 'herb': 2},
    9,
    10],
   {'crafts': 4, 'made': 8, 'stacks': [4, 4], 'left': {'herb': 2, 'ore': 2, 'wood': 1}}),
  ('zero request #1',
   [{'inputs': {'hide': 2}, 'output': 'belt', 'yield': 1, 'stack': 3}, {'hide': 8}, 0, 80],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'hide': 8}}),
  ('control #1',
   [{'inputs': {'hide': 3, 'ore': 1}, 'output': 'blade', 'yield': 1, 'stack': 5},
    {'hide': 21, 'ore': 5},
    3,
    99],
   {'crafts': 3, 'made': 3, 'stacks': [3], 'left': {'hide': 12, 'ore': 2}})],
 [('exact material multiple #1',
   [{'inputs': {'ore': 3}, 'output': 'bar', 'yield': 1, 'stack': 5}, {'ore': 15}, 10, 50],
   {'crafts': 5, 'made': 6, 'stacks': [5, 1], 'left': {'ore': 0}}),
  ('fault site bonus skill gate #1',
   [{'inputs': {'gem': 2, 'ore': 3}, 'output': 'blade', 'yield': 2, 'stack': 9},
    {'gem': 19, 'ore': 25},
    9,
    50],
   {'crafts': 8, 'made': 17, 'stacks': [9, 8], 'left': {'gem': 3, 'ore': 1}}),
  ('fault site bonus skill gate #2',
   [{'inputs': {'hide': 2}, 'output': 'blade', 'yield': 3, 'stack': 8}, {'hide': 23}, 9, 50],
   {'crafts': 9, 'made': 28, 'stacks': [8, 8, 8, 4], 'left': {'hide': 5}}),
  ('partial repair boundary #1',
   [{'inputs': {'hide': 3}, 'output': 'blade', 'yield': 3, 'stack': 6}, {'hide': 25}, 12, 100],
   {'crafts': 8, 'made': 25, 'stacks': [6, 6, 6, 6, 1], 'left': {'hide': 1}}),
  ('partial repair boundary #2',
   [{'inputs': {'hide': 2, 'ore': 1, 'gem': 3}, 'output': 'blade', 'yield': 2, 'stack': 7},
    {'hide': 23, 'ore': 8, 'gem': 26, 'herb': 2},
    8,
    120],
   {'crafts': 8, 'made': 17, 'stacks': [7, 7, 3], 'left': {'gem': 2, 'herb': 2, 'hide': 7, 'ore': 0}}),
  ('one short of a batch #1',
   [{'inputs': {'ore': 3, 'wood': 2}, 'output': 'axe', 'yield': 2, 'stack': 4},
    {'ore': 14, 'wood': 9, 'herb': 2},
    9,
    10],
   {'crafts': 4, 'made': 8, 'stacks': [4, 4], 'left': {'herb': 2, 'ore': 2, 'wood': 1}}),
  ('zero request #1',
   [{'inputs': {'hide': 2}, 'output': 'belt', 'yield': 1, 'stack': 3}, {'hide': 8}, 0, 80],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'hide': 8}}),
  ('control #1',
   [{'inputs': {'wood': 2, 'hide': 3, 'gem': 3}, 'output': 'blade', 'yield': 3, 'stack': 7},
    {'wood': 12, 'hide': 23, 'gem': 11},
    4,
    51],
   {'crafts': 3, 'made': 9, 'stacks': [7, 2], 'left': {'gem': 2, 'hide': 14, 'wood': 6}})]]
for label, args, expected in cases[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 crafter at exactly the bonus skill receives no bonus items.

recipe = {inputs:{material:qty}, output, yield, stack}. Crafts = min(requested, floor(have/qty) per input), 0 when requested <= 0. With skill in [50, inf) every 5th craft adds one bonus item (bonus = crafts//5). made = crafts*yield + bonus, split into full stacks of size stack plus one partial stack. left = whole inventory (all materials) after consuming crafts*qty of each input, sorted by name.

split: open-access


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

N = 1
observations = []
def solve(recipe, inventory, requested, skill):
    if requested <= 0:
        crafts = 0
    else:
        crafts = requested
        for mat, qty in recipe['inputs'].items():
            crafts = min(crafts, inventory.get(mat, 0) // qty)
    bonus = crafts // 5 * recipe['yield'] if skill >= 50 else 0
    made = crafts * recipe['yield'] + bonus
    cap = recipe['stack']
    stacks = [cap] * (made // cap)
    if made % cap:
        stacks.append(made % cap)
    left = dict(inventory)
    for mat, qty in recipe['inputs'].items():
        left[mat] = left.get(mat, 0) - crafts * qty
    return {'crafts': crafts, 'made': made, 'stacks': stacks, 'left': dict(sorted(left.items()))}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('fault site bonus cadence #1',
   [{'inputs': {'hide': 1, 'gem': 2, 'wood': 1}, 'output': 'blade', 'yield': 3, 'stack': 10},
    {'hide': 28, 'gem': 10, 'wood': 23, 'herb': 6},
    8,
    120],
   {'crafts': 5, 'made': 16, 'stacks': [10, 6], 'left': {'gem': 0, 'herb': 6, 'hide': 23, 'wood': 18}}),
  ('regression bonus cadence #1',
   [{'inputs': {'gem': 1}, 'output': 'blade', 'yield': 3, 'stack': 6}, {'gem': 27, 'herb': 8}, 7, 101],
   {'crafts': 7, 'made': 22, 'stacks': [6, 6, 6, 4], 'left': {'gem': 20, 'herb': 8}}),
  ('partial repair boundary #1',
   [{'inputs': {'ore': 4}, 'output': 'blade', 'yield': 3, 'stack': 10}, {'ore': 6}, 2, 51],
   {'crafts': 1, 'made': 3, 'stacks': [3], 'left': {'ore': 2}}),
  ('partial repair boundary #2',
   [{'inputs': {'hide': 3, 'ore': 1}, 'output': 'blade', 'yield': 1, 'stack': 5},
    {'hide': 21, 'ore': 5},
    3,
    99],
   {'crafts': 3, 'made': 3, 'stacks': [3], 'left': {'hide': 12, 'ore': 2}}),
  ('exact material multiple #1',
   [{'inputs': {'ore': 3}, 'output': 'bar', 'yield': 1, 'stack': 5}, {'ore': 15}, 10, 50],
   {'crafts': 5, 'made': 6, 'stacks': [5, 1], 'left': {'ore': 0}}),
  ('one short of a batch #1',
   [{'inputs': {'ore': 3, 'wood': 2}, 'output': 'axe', 'yield': 2, 'stack': 4},
    {'ore': 14, 'wood': 9, 'herb': 2},
    9,
    10],
   {'crafts': 4, 'made': 8, 'stacks': [4, 4], 'left': {'herb': 2, 'ore': 2, 'wood': 1}}),
  ('zero request #1',
   [{'inputs': {'hide': 2}, 'output': 'belt', 'yield': 1, 'stack': 3}, {'hide': 8}, 0, 80],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'hide': 8}}),
  ('control #1',
   [{'inputs': {'gem': 2}, 'output': 'blade', 'yield': 3, 'stack': 9}, {'gem': 19}, 0, 120],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'gem': 19}})],
 [('regression bonus cadence #1',
   [{'inputs': {'ore': 2}, 'output': 'blade', 'yield': 3, 'stack': 8}, {'ore': 23, 'herb': 5}, 12, 99],
   {'crafts': 11, 'made': 35, 'stacks': [8, 8, 8, 8, 3], 'left': {'herb': 5, 'ore': 1}}),
  ('regression bonus cadence #2',
   [{'inputs': {'gem': 2, 'hide': 3}, 'output': 'blade', 'yield': 2, 'stack': 10},
    {'gem': 19, 'hide': 18, 'herb': 2},
    8,
    51],
   {'crafts': 6, 'made': 13, 'stacks': [10, 3], 'left': {'gem': 7, 'herb': 2, 'hide': 0}}),
  ('partial repair boundary #1',
   [{'inputs': {'wood': 2, 'hide': 3, 'gem': 3}, 'output': 'blade', 'yield': 3, 'stack': 7},
    {'wood': 12, 'hide': 23, 'gem': 11},
    4,
    51],
   {'crafts': 3, 'made': 9, 'stacks': [7, 2], 'left': {'gem': 2, 'hide': 14, 'wood': 6}}),
  ('partial repair boundary #2',
   [{'inputs': {'ore': 2, 'wood': 4, 'hide': 2}, 'output': 'blade', 'yield': 3, 'stack': 6},
    {'ore': 20, 'wood': 13, 'hide': 16, 'herb': 2},
    9,
    120],
   {'crafts': 3, 'made': 9, 'stacks': [6, 3], 'left': {'herb': 2, 'hide': 10, 'ore': 14, 'wood': 1}}),
  ('zero request #1',
   [{'inputs': {'hide': 2}, 'output': 'belt', 'yield': 1, 'stack': 3}, {'hide': 8}, 0, 80],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'hide': 8}}),
  ('exact material multiple #1',
   [{'inputs': {'ore': 3}, 'output': 'bar', 'yield': 1, 'stack': 5}, {'ore': 15}, 10, 50],
   {'crafts': 5, 'made': 6, 'stacks': [5, 1], 'left': {'ore': 0}}),
  ('control #1',
   [{'inputs': {'gem': 2}, 'output': 'blade', 'yield': 3, 'stack': 9}, {'gem': 19}, 0, 120],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'gem': 19}}),
  ('control #2',
   [{'inputs': {'gem': 1, 'hide': 3, 'ore': 4}, 'output': 'blade', 'yield': 1, 'stack': 6},
    {'gem': 15, 'hide': 15, 'ore': 26},
    2,
    49],
   {'crafts': 2, 'made': 2, 'stacks': [2], 'left': {'gem': 13, 'hide': 9, 'ore': 18}})],
 [('regression bonus cadence #1',
   [{'inputs': {'hide': 2, 'wood': 2}, 'output': 'blade', 'yield': 3, 'stack': 6},
    {'hide': 18, 'wood': 27, 'herb': 4},
    9,
    51],
   {'crafts': 9, 'made': 28, 'stacks': [6, 6, 6, 6, 4], 'left': {'herb': 4, 'hide': 0, 'wood': 9}}),
  ('fault site bonus cadence #1',
   [{'inputs': {'ore': 2}, 'output': 'blade', 'yield': 2, 'stack': 8}, {'ore': 28}, 5, 100],
   {'crafts': 5, 'made': 11, 'stacks': [8, 3], 'left': {'ore': 18}}),
  ('partial repair boundary #1',
   [{'inputs': {'gem': 4, 'ore': 2}, 'output': 'blade', 'yield': 1, 'stack': 9},
    {'gem': 15, 'ore': 20, 'herb': 6},
    12,
    120],
   {'crafts': 3, 'made': 3, 'stacks': [3], 'left': {'gem': 3, 'herb': 6, 'ore': 14}}),
  ('partial repair boundary #2',
   [{'inputs': {'ore': 4, 'gem': 4, 'hide': 4}, 'output': 'blade', 'yield': 2, 'stack': 7},
    {'ore': 13, 'gem': 22, 'hide': 22, 'herb': 6},
    2,
    120],
   {'crafts': 2, 'made': 4, 'stacks': [4], 'left': {'gem': 14, 'herb': 6, 'hide': 14, 'ore': 5}}),
  ('one short of a batch #1',
   [{'inputs': {'ore': 3, 'wood': 2}, 'output': 'axe', 'yield': 2, 'stack': 4},
    {'ore': 14, 'wood': 9, 'herb': 2},
    9,
    10],
   {'crafts': 4, 'made': 8, 'stacks': [4, 4], 'left': {'herb': 2, 'ore': 2, 'wood': 1}}),
  ('zero request #1',
   [{'inputs': {'hide': 2}, 'output': 'belt', 'yield': 1, 'stack': 3}, {'hide': 8}, 0, 80],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'hide': 8}}),
  ('control #1',
   [{'inputs': {'gem': 1, 'hide': 3, 'ore': 4}, 'output': 'blade', 'yield': 1, 'stack': 6},
    {'gem': 15, 'hide': 15, 'ore': 26},
    2,
    49],
   {'crafts': 2, 'made': 2, 'stacks': [2], 'left': {'gem': 13, 'hide': 9, 'ore': 18}}),
  ('control #2',
   [{'inputs': {'hide': 1, 'wood': 1}, 'output': 'blade', 'yield': 1, 'stack': 6},
    {'wood': 23, 'herb': 9},
    4,
    49],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'herb': 9, 'hide': 0, 'wood': 23}})],
 [('regression bonus cadence #1',
   [{'inputs': {'wood': 1}, 'output': 'blade', 'yield': 3, 'stack': 7}, {'wood': 7}, 12, 120],
   {'crafts': 7, 'made': 22, 'stacks': [7, 7, 7, 1], 'left': {'wood': 0}}),
  ('regression bonus cadence #2',
   [{'inputs': {'gem': 4, 'hide': 1, 'ore': 1}, 'output': 'blade', 'yield': 2, 'stack': 9},
    {'gem': 29, 'hide': 25, 'ore': 26},
    8,
    120],
   {'crafts': 7, 'made': 15, 'stacks': [9, 6], 'left': {'gem': 1, 'hide': 18, 'ore': 19}}),
  ('partial repair boundary #1',
   [{'inputs': {'gem': 1, 'hide': 3}, 'output': 'blade', 'yield': 1, 'stack': 4},
    {'gem': 2, 'hide': 5, 'herb': 8},
    12,
    99],
   {'crafts': 1, 'made': 1, 'stacks': [1], 'left': {'gem': 1, 'herb': 8, 'hide': 2}}),
  ('partial repair boundary #2',
   [{'inputs': {'hide': 1, 'gem': 3, 'ore': 2}, 'output': 'blade', 'yield': 2, 'stack': 3},
    {'hide': 4, 'gem': 10, 'ore': 4, 'herb': 8},
    8,
    120],
   {'crafts': 2, 'made': 4, 'stacks': [3, 1], 'left': {'gem': 4, 'herb': 8, 'hide': 2, 'ore': 0}}),
  ('exact material multiple #1',
   [{'inputs': {'ore': 3}, 'output': 'bar', 'yield': 1, 'stack': 5}, {'ore': 15}, 10, 50],
   {'crafts': 5, 'made': 6, 'stacks': [5, 1], 'left': {'ore': 0}}),
  ('one short of a batch #1',
   [{'inputs': {'ore': 3, 'wood': 2}, 'output': 'axe', 'yield': 2, 'stack': 4},
    {'ore': 14, 'wood': 9, 'herb': 2},
    9,
    10],
   {'crafts': 4, 'made': 8, 'stacks': [4, 4], 'left': {'herb': 2, 'ore': 2, 'wood': 1}}),
  ('control #1',
   [{'inputs': {'wood': 1, 'ore': 3, 'gem': 1}, 'output': 'blade', 'yield': 3, 'stack': 9},
    {'wood': 2, 'ore': 29, 'gem': 5, 'herb': 7},
    11,
    0],
   {'crafts': 2, 'made': 6, 'stacks': [6], 'left': {'gem': 3, 'herb': 7, 'ore': 23, 'wood': 0}}),
  ('control #2',
   [{'inputs': {'gem': 3, 'hide': 4}, 'output': 'blade', 'yield': 3, 'stack': 6},
    {'gem': 16, 'hide': 29},
    0,
    100],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'gem': 16, 'hide': 29}})],
 [('fault site bonus cadence #1',
   [{'inputs': {'hide': 2}, 'output': 'blade', 'yield': 2, 'stack': 4}, {'hide': 30, 'herb': 9}, 10, 63],
   {'crafts': 10, 'made': 22, 'stacks': [4, 4, 4, 4, 4, 2], 'left': {'herb': 9, 'hide': 10}}),
  ('regression bonus cadence #1',
   [{'inputs': {'hide': 3, 'wood': 2}, 'output': 'blade', 'yield': 2, 'stack': 10},
    {'hide': 29, 'wood': 21, 'herb': 6},
    7,
    101],
   {'crafts': 7, 'made': 15, 'stacks': [10, 5], 'left': {'herb': 6, 'hide': 8, 'wood': 7}}),
  ('partial repair boundary #1',
   [{'inputs': {'hide': 4}, 'output': 'blade', 'yield': 3, 'stack': 7}, {'hide': 15}, 7, 120],
   {'crafts': 3, 'made': 9, 'stacks': [7, 2], 'left': {'hide': 3}}),
  ('partial repair boundary #2',
   [{'inputs': {'hide': 4, 'gem': 3, 'ore': 3}, 'output': 'blade', 'yield': 1, 'stack': 3},
    {'hide': 19, 'gem': 21, 'ore': 16},
    2,
    50],
   {'crafts': 2, 'made': 2, 'stacks': [2], 'left': {'gem': 15, 'hide': 11, 'ore': 10}}),
  ('zero request #1',
   [{'inputs': {'hide': 2}, 'output': 'belt', 'yield': 1, 'stack': 3}, {'hide': 8}, 0, 80],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'hide': 8}}),
  ('exact material multiple #1',
   [{'inputs': {'ore': 3}, 'output': 'bar', 'yield': 1, 'stack': 5}, {'ore': 15}, 10, 50],
   {'crafts': 5, 'made': 6, 'stacks': [5, 1], 'left': {'ore': 0}}),
  ('control #1',
   [{'inputs': {'wood': 4, 'ore': 3}, 'output': 'blade', 'yield': 3, 'stack': 7},
    {'wood': 13, 'ore': 6, 'herb': 6},
    5,
    0],
   {'crafts': 2, 'made': 6, 'stacks': [6], 'left': {'herb': 6, 'ore': 0, 'wood': 5}}),
  ('control #2',
   [{'inputs': {'wood': 1, 'ore': 2, 'hide': 4}, 'output': 'blade', 'yield': 2, 'stack': 6},
    {'wood': 3, 'ore': 26, 'hide': 6},
    5,
    17],
   {'crafts': 1, 'made': 2, 'stacks': [2], 'left': {'hide': 2, 'ore': 24, 'wood': 2}})]]
for label, args, expected in cases[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(recipe, inventory, requested, skill):
    if requested <= 0:
        crafts = 0
    else:
        crafts = requested
        for mat, qty in recipe['inputs'].items():
            crafts = min(crafts, inventory.get(mat, 0) // qty)
    bonus = (crafts + 4) // 5 if skill >= 50 else 0
    made = crafts * recipe['yield'] + bonus
    cap = recipe['stack']
    stacks = [cap] * (made // cap)
    if made % cap:
        stacks.append(made % cap)
    left = dict(inventory)
    for mat, qty in recipe['inputs'].items():
        left[mat] = left.get(mat, 0) - crafts * qty
    return {'crafts': crafts, 'made': made, 'stacks': stacks, 'left': dict(sorted(left.items()))}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('fault site bonus cadence #1',
   [{'inputs': {'hide': 1, 'gem': 2, 'wood': 1}, 'output': 'blade', 'yield': 3, 'stack': 10},
    {'hide': 28, 'gem': 10, 'wood': 23, 'herb': 6},
    8,
    120],
   {'crafts': 5, 'made': 16, 'stacks': [10, 6], 'left': {'gem': 0, 'herb': 6, 'hide': 23, 'wood': 18}}),
  ('regression bonus cadence #1',
   [{'inputs': {'gem': 1}, 'output': 'blade', 'yield': 3, 'stack': 6}, {'gem': 27, 'herb': 8}, 7, 101],
   {'crafts': 7, 'made': 22, 'stacks': [6, 6, 6, 4], 'left': {'gem': 20, 'herb': 8}}),
  ('partial repair boundary #1',
   [{'inputs': {'ore': 4}, 'output': 'blade', 'yield': 3, 'stack': 10}, {'ore': 6}, 2, 51],
   {'crafts': 1, 'made': 3, 'stacks': [3], 'left': {'ore': 2}}),
  ('partial repair boundary #2',
   [{'inputs': {'hide': 3, 'ore': 1}, 'output': 'blade', 'yield': 1, 'stack': 5},
    {'hide': 21, 'ore': 5},
    3,
    99],
   {'crafts': 3, 'made': 3, 'stacks': [3], 'left': {'hide': 12, 'ore': 2}}),
  ('exact material multiple #1',
   [{'inputs': {'ore': 3}, 'output': 'bar', 'yield': 1, 'stack': 5}, {'ore': 15}, 10, 50],
   {'crafts': 5, 'made': 6, 'stacks': [5, 1], 'left': {'ore': 0}}),
  ('one short of a batch #1',
   [{'inputs': {'ore': 3, 'wood': 2}, 'output': 'axe', 'yield': 2, 'stack': 4},
    {'ore': 14, 'wood': 9, 'herb': 2},
    9,
    10],
   {'crafts': 4, 'made': 8, 'stacks': [4, 4], 'left': {'herb': 2, 'ore': 2, 'wood': 1}}),
  ('zero request #1',
   [{'inputs': {'hide': 2}, 'output': 'belt', 'yield': 1, 'stack': 3}, {'hide': 8}, 0, 80],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'hide': 8}}),
  ('control #1',
   [{'inputs': {'gem': 2}, 'output': 'blade', 'yield': 3, 'stack': 9}, {'gem': 19}, 0, 120],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'gem': 19}})],
 [('regression bonus cadence #1',
   [{'inputs': {'ore': 2}, 'output': 'blade', 'yield': 3, 'stack': 8}, {'ore': 23, 'herb': 5}, 12, 99],
   {'crafts': 11, 'made': 35, 'stacks': [8, 8, 8, 8, 3], 'left': {'herb': 5, 'ore': 1}}),
  ('regression bonus cadence #2',
   [{'inputs': {'gem': 2, 'hide': 3}, 'output': 'blade', 'yield': 2, 'stack': 10},
    {'gem': 19, 'hide': 18, 'herb': 2},
    8,
    51],
   {'crafts': 6, 'made': 13, 'stacks': [10, 3], 'left': {'gem': 7, 'herb': 2, 'hide': 0}}),
  ('partial repair boundary #1',
   [{'inputs': {'wood': 2, 'hide': 3, 'gem': 3}, 'output': 'blade', 'yield': 3, 'stack': 7},
    {'wood': 12, 'hide': 23, 'gem': 11},
    4,
    51],
   {'crafts': 3, 'made': 9, 'stacks': [7, 2], 'left': {'gem': 2, 'hide': 14, 'wood': 6}}),
  ('partial repair boundary #2',
   [{'inputs': {'ore': 2, 'wood': 4, 'hide': 2}, 'output': 'blade', 'yield': 3, 'stack': 6},
    {'ore': 20, 'wood': 13, 'hide': 16, 'herb': 2},
    9,
    120],
   {'crafts': 3, 'made': 9, 'stacks': [6, 3], 'left': {'herb': 2, 'hide': 10, 'ore': 14, 'wood': 1}}),
  ('zero request #1',
   [{'inputs': {'hide': 2}, 'output': 'belt', 'yield': 1, 'stack': 3}, {'hide': 8}, 0, 80],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'hide': 8}}),
  ('exact material multiple #1',
   [{'inputs': {'ore': 3}, 'output': 'bar', 'yield': 1, 'stack': 5}, {'ore': 15}, 10, 50],
   {'crafts': 5, 'made': 6, 'stacks': [5, 1], 'left': {'ore': 0}}),
  ('control #1',
   [{'inputs': {'gem': 2}, 'output': 'blade', 'yield': 3, 'stack': 9}, {'gem': 19}, 0, 120],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'gem': 19}}),
  ('control #2',
   [{'inputs': {'gem': 1, 'hide': 3, 'ore': 4}, 'output': 'blade', 'yield': 1, 'stack': 6},
    {'gem': 15, 'hide': 15, 'ore': 26},
    2,
    49],
   {'crafts': 2, 'made': 2, 'stacks': [2], 'left': {'gem': 13, 'hide': 9, 'ore': 18}})],
 [('regression bonus cadence #1',
   [{'inputs': {'hide': 2, 'wood': 2}, 'output': 'blade', 'yield': 3, 'stack': 6},
    {'hide': 18, 'wood': 27, 'herb': 4},
    9,
    51],
   {'crafts': 9, 'made': 28, 'stacks': [6, 6, 6, 6, 4], 'left': {'herb': 4, 'hide': 0, 'wood': 9}}),
  ('fault site bonus cadence #1',
   [{'inputs': {'ore': 2}, 'output': 'blade', 'yield': 2, 'stack': 8}, {'ore': 28}, 5, 100],
   {'crafts': 5, 'made': 11, 'stacks': [8, 3], 'left': {'ore': 18}}),
  ('partial repair boundary #1',
   [{'inputs': {'gem': 4, 'ore': 2}, 'output': 'blade', 'yield': 1, 'stack': 9},
    {'gem': 15, 'ore': 20, 'herb': 6},
    12,
    120],
   {'crafts': 3, 'made': 3, 'stacks': [3], 'left': {'gem': 3, 'herb': 6, 'ore': 14}}),
  ('partial repair boundary #2',
   [{'inputs': {'ore': 4, 'gem': 4, 'hide': 4}, 'output': 'blade', 'yield': 2, 'stack': 7},
    {'ore': 13, 'gem': 22, 'hide': 22, 'herb': 6},
    2,
    120],
   {'crafts': 2, 'made': 4, 'stacks': [4], 'left': {'gem': 14, 'herb': 6, 'hide': 14, 'ore': 5}}),
  ('one short of a batch #1',
   [{'inputs': {'ore': 3, 'wood': 2}, 'output': 'axe', 'yield': 2, 'stack': 4},
    {'ore': 14, 'wood': 9, 'herb': 2},
    9,
    10],
   {'crafts': 4, 'made': 8, 'stacks': [4, 4], 'left': {'herb': 2, 'ore': 2, 'wood': 1}}),
  ('zero request #1',
   [{'inputs': {'hide': 2}, 'output': 'belt', 'yield': 1, 'stack': 3}, {'hide': 8}, 0, 80],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'hide': 8}}),
  ('control #1',
   [{'inputs': {'gem': 1, 'hide': 3, 'ore': 4}, 'output': 'blade', 'yield': 1, 'stack': 6},
    {'gem': 15, 'hide': 15, 'ore': 26},
    2,
    49],
   {'crafts': 2, 'made': 2, 'stacks': [2], 'left': {'gem': 13, 'hide': 9, 'ore': 18}}),
  ('control #2',
   [{'inputs': {'hide': 1, 'wood': 1}, 'output': 'blade', 'yield': 1, 'stack': 6},
    {'wood': 23, 'herb': 9},
    4,
    49],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'herb': 9, 'hide': 0, 'wood': 23}})],
 [('regression bonus cadence #1',
   [{'inputs': {'wood': 1}, 'output': 'blade', 'yield': 3, 'stack': 7}, {'wood': 7}, 12, 120],
   {'crafts': 7, 'made': 22, 'stacks': [7, 7, 7, 1], 'left': {'wood': 0}}),
  ('regression bonus cadence #2',
   [{'inputs': {'gem': 4, 'hide': 1, 'ore': 1}, 'output': 'blade', 'yield': 2, 'stack': 9},
    {'gem': 29, 'hide': 25, 'ore': 26},
    8,
    120],
   {'crafts': 7, 'made': 15, 'stacks': [9, 6], 'left': {'gem': 1, 'hide': 18, 'ore': 19}}),
  ('partial repair boundary #1',
   [{'inputs': {'gem': 1, 'hide': 3}, 'output': 'blade', 'yield': 1, 'stack': 4},
    {'gem': 2, 'hide': 5, 'herb': 8},
    12,
    99],
   {'crafts': 1, 'made': 1, 'stacks': [1], 'left': {'gem': 1, 'herb': 8, 'hide': 2}}),
  ('partial repair boundary #2',
   [{'inputs': {'hide': 1, 'gem': 3, 'ore': 2}, 'output': 'blade', 'yield': 2, 'stack': 3},
    {'hide': 4, 'gem': 10, 'ore': 4, 'herb': 8},
    8,
    120],
   {'crafts': 2, 'made': 4, 'stacks': [3, 1], 'left': {'gem': 4, 'herb': 8, 'hide': 2, 'ore': 0}}),
  ('exact material multiple #1',
   [{'inputs': {'ore': 3}, 'output': 'bar', 'yield': 1, 'stack': 5}, {'ore': 15}, 10, 50],
   {'crafts': 5, 'made': 6, 'stacks': [5, 1], 'left': {'ore': 0}}),
  ('one short of a batch #1',
   [{'inputs': {'ore': 3, 'wood': 2}, 'output': 'axe', 'yield': 2, 'stack': 4},
    {'ore': 14, 'wood': 9, 'herb': 2},
    9,
    10],
   {'crafts': 4, 'made': 8, 'stacks': [4, 4], 'left': {'herb': 2, 'ore': 2, 'wood': 1}}),
  ('control #1',
   [{'inputs': {'wood': 1, 'ore': 3, 'gem': 1}, 'output': 'blade', 'yield': 3, 'stack': 9},
    {'wood': 2, 'ore': 29, 'gem': 5, 'herb': 7},
    11,
    0],
   {'crafts': 2, 'made': 6, 'stacks': [6], 'left': {'gem': 3, 'herb': 7, 'ore': 23, 'wood': 0}}),
  ('control #2',
   [{'inputs': {'gem': 3, 'hide': 4}, 'output': 'blade', 'yield': 3, 'stack': 6},
    {'gem': 16, 'hide': 29},
    0,
    100],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'gem': 16, 'hide': 29}})],
 [('fault site bonus cadence #1',
   [{'inputs': {'hide': 2}, 'output': 'blade', 'yield': 2, 'stack': 4}, {'hide': 30, 'herb': 9}, 10, 63],
   {'crafts': 10, 'made': 22, 'stacks': [4, 4, 4, 4, 4, 2], 'left': {'herb': 9, 'hide': 10}}),
  ('regression bonus cadence #1',
   [{'inputs': {'hide': 3, 'wood': 2}, 'output': 'blade', 'yield': 2, 'stack': 10},
    {'hide': 29, 'wood': 21, 'herb': 6},
    7,
    101],
   {'crafts': 7, 'made': 15, 'stacks': [10, 5], 'left': {'herb': 6, 'hide': 8, 'wood': 7}}),
  ('partial repair boundary #1',
   [{'inputs': {'hide': 4}, 'output': 'blade', 'yield': 3, 'stack': 7}, {'hide': 15}, 7, 120],
   {'crafts': 3, 'made': 9, 'stacks': [7, 2], 'left': {'hide': 3}}),
  ('partial repair boundary #2',
   [{'inputs': {'hide': 4, 'gem': 3, 'ore': 3}, 'output': 'blade', 'yield': 1, 'stack': 3},
    {'hide': 19, 'gem': 21, 'ore': 16},
    2,
    50],
   {'crafts': 2, 'made': 2, 'stacks': [2], 'left': {'gem': 15, 'hide': 11, 'ore': 10}}),
  ('zero request #1',
   [{'inputs': {'hide': 2}, 'output': 'belt', 'yield': 1, 'stack': 3}, {'hide': 8}, 0, 80],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'hide': 8}}),
  ('exact material multiple #1',
   [{'inputs': {'ore': 3}, 'output': 'bar', 'yield': 1, 'stack': 5}, {'ore': 15}, 10, 50],
   {'crafts': 5, 'made': 6, 'stacks': [5, 1], 'left': {'ore': 0}}),
  ('control #1',
   [{'inputs': {'wood': 4, 'ore': 3}, 'output': 'blade', 'yield': 3, 'stack': 7},
    {'wood': 13, 'ore': 6, 'herb': 6},
    5,
    0],
   {'crafts': 2, 'made': 6, 'stacks': [6], 'left': {'herb': 6, 'ore': 0, 'wood': 5}}),
  ('control #2',
   [{'inputs': {'wood': 1, 'ore': 2, 'hide': 4}, 'output': 'blade', 'yield': 2, 'stack': 6},
    {'wood': 3, 'ore': 26, 'hide': 6},
    5,
    17],
   {'crafts': 1, 'made': 2, 'stacks': [2], 'left': {'hide': 2, 'ore': 24, 'wood': 2}})]]
for label, args, expected in cases[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:
Multi-yield recipes receive several bonus items per fifth craft.

recipe = {inputs:{material:qty}, output, yield, stack}. Crafts = min(requested, floor(have/qty) per input), 0 when requested <= 0. With skill in [50, inf) every 5th craft adds one bonus item (bonus = crafts//5). made = crafts*yield + bonus, split into full stacks of size stack plus one partial stack. left = whole inventory (all materials) after consuming crafts*qty of each input, sorted by name.

split: open-access


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

N = 1
observations = []
def solve(recipe, inventory, requested, skill):
    if requested <= 0:
        crafts = 0
    else:
        crafts = requested
        for mat, qty in recipe['inputs'].items():
            crafts = min(crafts, inventory.get(mat, 0) // qty)
    bonus = crafts // 5 if skill >= 50 else 0
    made = crafts * recipe['yield'] + bonus
    cap = recipe['stack']
    stacks = [cap] * (made // cap)
    stacks.append(made % cap)
    left = dict(inventory)
    for mat, qty in recipe['inputs'].items():
        left[mat] = left.get(mat, 0) - crafts * qty
    return {'crafts': crafts, 'made': made, 'stacks': stacks, 'left': dict(sorted(left.items()))}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('one short of a batch #1',
   [{'inputs': {'ore': 3, 'wood': 2}, 'output': 'axe', 'yield': 2, 'stack': 4},
    {'ore': 14, 'wood': 9, 'herb': 2},
    9,
    10],
   {'crafts': 4, 'made': 8, 'stacks': [4, 4], 'left': {'herb': 2, 'ore': 2, 'wood': 1}}),
  ('exact material multiple #1',
   [{'inputs': {'ore': 3}, 'output': 'bar', 'yield': 1, 'stack': 5}, {'ore': 15}, 10, 50],
   {'crafts': 5, 'made': 6, 'stacks': [5, 1], 'left': {'ore': 0}}),
  ('zero request #1',
   [{'inputs': {'hide': 2}, 'output': 'belt', 'yield': 1, 'stack': 3}, {'hide': 8}, 0, 80],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'hide': 8}}),
  ('fault site partial stack emission #1',
   [{'inputs': {'gem': 2}, 'output': 'blade', 'yield': 3, 'stack': 9}, {'gem': 19}, 0, 120],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'gem': 19}}),
  ('partial repair boundary #1',
   [{'inputs': {'gem': 1, 'hide': 3}, 'output': 'blade', 'yield': 1, 'stack': 4},
    {'gem': 2, 'hide': 5, 'herb': 8},
    12,
    99],
   {'crafts': 1, 'made': 1, 'stacks': [1], 'left': {'gem': 1, 'herb': 8, 'hide': 2}}),
  ('partial repair boundary #2',
   [{'inputs': {'hide': 1, 'gem': 3, 'ore': 2}, 'output': 'blade', 'yield': 2, 'stack': 3},
    {'hide': 4, 'gem': 10, 'ore': 4, 'herb': 8},
    8,
    120],
   {'crafts': 2, 'made': 4, 'stacks': [3, 1], 'left': {'gem': 4, 'herb': 8, 'hide': 2, 'ore': 0}}),
  ('control #1',
   [{'inputs': {'ore': 4}, 'output': 'blade', 'yield': 3, 'stack': 10}, {'ore': 6}, 2, 51],
   {'crafts': 1, 'made': 3, 'stacks': [3], 'left': {'ore': 2}}),
  ('control #2',
   [{'inputs': {'hide': 3, 'ore': 1}, 'output': 'blade', 'yield': 1, 'stack': 5},
    {'hide': 21, 'ore': 5},
    3,
    99],
   {'crafts': 3, 'made': 3, 'stacks': [3], 'left': {'hide': 12, 'ore': 2}})],
 [('zero request #1',
   [{'inputs': {'hide': 2}, 'output': 'belt', 'yield': 1, 'stack': 3}, {'hide': 8}, 0, 80],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'hide': 8}}),
  ('exact material multiple #1',
   [{'inputs': {'ore': 3}, 'output': 'bar', 'yield': 1, 'stack': 5}, {'ore': 15}, 10, 50],
   {'crafts': 5, 'made': 6, 'stacks': [5, 1], 'left': {'ore': 0}}),
  ('fault site partial stack emission #1',
   [{'inputs': {'gem': 2}, 'output': 'blade', 'yield': 3, 'stack': 9}, {'gem': 19}, 0, 120],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'gem': 19}}),
  ('fault site partial stack emission #2',
   [{'inputs': {'hide': 1, 'wood': 1}, 'output': 'blade', 'yield': 1, 'stack': 6},
    {'wood': 23, 'herb': 9},
    4,
    49],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'herb': 9, 'hide': 0, 'wood': 23}}),
  ('partial repair boundary #1',
   [{'inputs': {'hide': 1, 'gem': 3, 'ore': 2}, 'output': 'blade', 'yield': 2, 'stack': 3},
    {'hide': 4, 'gem': 10, 'ore': 4, 'herb': 8},
    8,
    120],
   {'crafts': 2, 'made': 4, 'stacks': [3, 1], 'left': {'gem': 4, 'herb': 8, 'hide': 2, 'ore': 0}}),
  ('partial repair boundary #2',
   [{'inputs': {'ore': 2, 'hide': 4, 'wood': 1}, 'output': 'blade', 'yield': 1, 'stack': 9},
    {'ore': 3, 'hide': 11, 'wood': 24, 'herb': 7},
    9,
    99],
   {'crafts': 1, 'made': 1, 'stacks': [1], 'left': {'herb': 7, 'hide': 7, 'ore': 1, 'wood': 23}}),
  ('control #1',
   [{'inputs': {'wood': 2, 'hide': 3, 'gem': 3}, 'output': 'blade', 'yield': 3, 'stack': 7},
    {'wood': 12, 'hide': 23, 'gem': 11},
    4,
    51],
   {'crafts': 3, 'made': 9, 'stacks': [7, 2], 'left': {'gem': 2, 'hide': 14, 'wood': 6}}),
  ('control #2',
   [{'inputs': {'ore': 2, 'wood': 4, 'hide': 2}, 'output': 'blade', 'yield': 3, 'stack': 6},
    {'ore': 20, 'wood': 13, 'hide': 16, 'herb': 2},
    9,
    120],
   {'crafts': 3, 'made': 9, 'stacks': [6, 3], 'left': {'herb': 2, 'hide': 10, 'ore': 14, 'wood': 1}})],
 [('one short of a batch #1',
   [{'inputs': {'ore': 3, 'wood': 2}, 'output': 'axe', 'yield': 2, 'stack': 4},
    {'ore': 14, 'wood': 9, 'herb': 2},
    9,
    10],
   {'crafts': 4, 'made': 8, 'stacks': [4, 4], 'left': {'herb': 2, 'ore': 2, 'wood': 1}}),
  ('exact material multiple #1',
   [{'inputs': {'ore': 3}, 'output': 'bar', 'yield': 1, 'stack': 5}, {'ore': 15}, 10, 50],
   {'crafts': 5, 'made': 6, 'stacks': [5, 1], 'left': {'ore': 0}}),
  ('fault site partial stack emission #1',
   [{'inputs': {'gem': 3, 'hide': 4}, 'output': 'blade', 'yield': 3, 'stack': 6},
    {'gem': 16, 'hide': 29},
    0,
    100],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'gem': 16, 'hide': 29}}),
  ('fault site partial stack emission #2',
   [{'inputs': {'hide': 3, 'ore': 2, 'gem': 3}, 'output': 'blade', 'yield': 2, 'stack': 7},
    {'ore': 21, 'gem': 0, 'herb': 6},
    7,
    49],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'gem': 0, 'herb': 6, 'hide': 0, 'ore': 21}}),
  ('partial repair boundary #1',
   [{'inputs': {'hide': 2, 'gem': 4}, 'output': 'blade', 'yield': 1, 'stack': 6},
    {'hide': 17, 'gem': 28, 'herb': 9},
    1,
    96],
   {'crafts': 1, 'made': 1, 'stacks': [1], 'left': {'gem': 24, 'herb': 9, 'hide': 15}}),
  ('partial repair boundary #2',
   [{'inputs': {'wood': 1, 'ore': 4}, 'output': 'blade', 'yield': 1, 'stack': 4},
    {'wood': 10, 'ore': 6},
    12,
    120],
   {'crafts': 1, 'made': 1, 'stacks': [1], 'left': {'ore': 2, 'wood': 9}}),
  ('control #1',
   [{'inputs': {'gem': 4, 'ore': 2}, 'output': 'blade', 'yield': 1, 'stack': 9},
    {'gem': 15, 'ore': 20, 'herb': 6},
    12,
    120],
   {'crafts': 3, 'made': 3, 'stacks': [3], 'left': {'gem': 3, 'herb': 6, 'ore': 14}}),
  ('control #2',
   [{'inputs': {'ore': 4, 'gem': 4, 'hide': 4}, 'output': 'blade', 'yield': 2, 'stack': 7},
    {'ore': 13, 'gem': 22, 'hide': 22, 'herb': 6},
    2,
    120],
   {'crafts': 2, 'made': 4, 'stacks': [4], 'left': {'gem': 14, 'herb': 6, 'hide': 14, 'ore': 5}})],
 [('zero request #1',
   [{'inputs': {'hide': 2}, 'output': 'belt', 'yield': 1, 'stack': 3}, {'hide': 8}, 0, 80],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'hide': 8}}),
  ('exact material multiple #1',
   [{'inputs': {'ore': 3}, 'output': 'bar', 'yield': 1, 'stack': 5}, {'ore': 15}, 10, 50],
   {'crafts': 5, 'made': 6, 'stacks': [5, 1], 'left': {'ore': 0}}),
  ('fault site partial stack emission #1',
   [{'inputs': {'gem': 1}, 'output': 'blade', 'yield': 3, 'stack': 4}, {'gem': 26, 'herb': 7}, 4, 49],
   {'crafts': 4, 'made': 12, 'stacks': [4, 4, 4], 'left': {'gem': 22, 'herb': 7}}),
  ('fault site partial stack emission #2',
   [{'inputs': {'ore': 3, 'wood': 2, 'gem': 4}, 'output': 'blade', 'yield': 3, 'stack': 3},
    {'ore': 25, 'wood': 22, 'gem': 19},
    2,
    99],
   {'crafts': 2, 'made': 6, 'stacks': [3, 3], 'left': {'gem': 11, 'ore': 19, 'wood': 18}}),
  ('partial repair boundary #1',
   [{'inputs': {'gem': 4, 'ore': 2}, 'output': 'blade', 'yield': 2, 'stack': 3},
    {'gem': 22, 'ore': 14},
    6,
    0],
   {'crafts': 5, 'made': 10, 'stacks': [3, 3, 3, 1], 'left': {'gem': 2, 'ore': 4}}),
  ('partial repair boundary #2',
   [{'inputs': {'ore': 1, 'hide': 4, 'wood': 4}, 'output': 'blade', 'yield': 1, 'stack': 3},
    {'ore': 11, 'hide': 13, 'wood': 6, 'herb': 9},
    2,
    100],
   {'crafts': 1, 'made': 1, 'stacks': [1], 'left': {'herb': 9, 'hide': 9, 'ore': 10, 'wood': 2}}),
  ('control #1',
   [{'inputs': {'gem': 1, 'hide': 3, 'ore': 4}, 'output': 'blade', 'yield': 1, 'stack': 6},
    {'gem': 15, 'hide': 15, 'ore': 26},
    2,
    49],
   {'crafts': 2, 'made': 2, 'stacks': [2], 'left': {'gem': 13, 'hide': 9, 'ore': 18}}),
  ('control #2',
   [{'inputs': {'wood': 1, 'ore': 3, 'gem': 1}, 'output': 'blade', 'yield': 3, 'stack': 9},
    {'wood': 2, 'ore': 29, 'gem': 5, 'herb': 7},
    11,
    0],
   {'crafts': 2, 'made': 6, 'stacks': [6], 'left': {'gem': 3, 'herb': 7, 'ore': 23, 'wood': 0}})],
 [('one short of a batch #1',
   [{'inputs': {'ore': 3, 'wood': 2}, 'output': 'axe', 'yield': 2, 'stack': 4},
    {'ore': 14, 'wood': 9, 'herb': 2},
    9,
    10],
   {'crafts': 4, 'made': 8, 'stacks': [4, 4], 'left': {'herb': 2, 'ore': 2, 'wood': 1}}),
  ('exact material multiple #1',
   [{'inputs': {'ore': 3}, 'output': 'bar', 'yield': 1, 'stack': 5}, {'ore': 15}, 10, 50],
   {'crafts': 5, 'made': 6, 'stacks': [5, 1], 'left': {'ore': 0}}),
  ('fault site partial stack emission #1',
   [{'inputs': {'hide': 2, 'gem': 4}, 'output': 'blade', 'yield': 3, 'stack': 10},
    {'gem': 11, 'herb': 6},
    11,
    99],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'gem': 11, 'herb': 6, 'hide': 0}}),
  ('fault site partial stack emission #2',
   [{'inputs': {'gem': 2}, 'output': 'blade', 'yield': 1, 'stack': 7}, {'gem': 0}, 6, 0],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'gem': 0}}),
  ('partial repair boundary #1',
   [{'inputs': {'gem': 3}, 'output': 'blade', 'yield': 1, 'stack': 10}, {'gem': 3}, 2, 119],
   {'crafts': 1, 'made': 1, 'stacks': [1], 'left': {'gem': 0}}),
  ('partial repair boundary #2',
   [{'inputs': {'wood': 3, 'ore': 2}, 'output': 'blade', 'yield': 1, 'stack': 7},
    {'wood': 27, 'ore': 16, 'herb': 7},
    12,
    49],
   {'crafts': 8, 'made': 8, 'stacks': [7, 1], 'left': {'herb': 7, 'ore': 0, 'wood': 3}}),
  ('control #1',
   [{'inputs': {'hide': 1, 'gem': 2, 'wood': 1}, 'output': 'blade', 'yield': 3, 'stack': 10},
    {'hide': 28, 'gem': 10, 'wood': 23, 'herb': 6},
    8,
    120],
   {'crafts': 5, 'made': 16, 'stacks': [10, 6], 'left': {'gem': 0, 'herb': 6, 'hide': 23, 'wood': 18}}),
  ('control #2',
   [{'inputs': {'hide': 4}, 'output': 'blade', 'yield': 3, 'stack': 7}, {'hide': 15}, 7, 120],
   {'crafts': 3, 'made': 9, 'stacks': [7, 2], 'left': {'hide': 3}})]]
for label, args, expected in cases[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(recipe, inventory, requested, skill):
    if requested <= 0:
        crafts = 0
    else:
        crafts = requested
        for mat, qty in recipe['inputs'].items():
            crafts = min(crafts, inventory.get(mat, 0) // qty)
    bonus = crafts // 5 if skill >= 50 else 0
    made = crafts * recipe['yield'] + bonus
    cap = recipe['stack']
    stacks = [cap] * (made // cap)
    if made % cap > 1:
        stacks.append(made % cap)
    left = dict(inventory)
    for mat, qty in recipe['inputs'].items():
        left[mat] = left.get(mat, 0) - crafts * qty
    return {'crafts': crafts, 'made': made, 'stacks': stacks, 'left': dict(sorted(left.items()))}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('one short of a batch #1',
   [{'inputs': {'ore': 3, 'wood': 2}, 'output': 'axe', 'yield': 2, 'stack': 4},
    {'ore': 14, 'wood': 9, 'herb': 2},
    9,
    10],
   {'crafts': 4, 'made': 8, 'stacks': [4, 4], 'left': {'herb': 2, 'ore': 2, 'wood': 1}}),
  ('exact material multiple #1',
   [{'inputs': {'ore': 3}, 'output': 'bar', 'yield': 1, 'stack': 5}, {'ore': 15}, 10, 50],
   {'crafts': 5, 'made': 6, 'stacks': [5, 1], 'left': {'ore': 0}}),
  ('zero request #1',
   [{'inputs': {'hide': 2}, 'output': 'belt', 'yield': 1, 'stack': 3}, {'hide': 8}, 0, 80],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'hide': 8}}),
  ('fault site partial stack emission #1',
   [{'inputs': {'gem': 2}, 'output': 'blade', 'yield': 3, 'stack': 9}, {'gem': 19}, 0, 120],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'gem': 19}}),
  ('partial repair boundary #1',
   [{'inputs': {'gem': 1, 'hide': 3}, 'output': 'blade', 'yield': 1, 'stack': 4},
    {'gem': 2, 'hide': 5, 'herb': 8},
    12,
    99],
   {'crafts': 1, 'made': 1, 'stacks': [1], 'left': {'gem': 1, 'herb': 8, 'hide': 2}}),
  ('partial repair boundary #2',
   [{'inputs': {'hide': 1, 'gem': 3, 'ore': 2}, 'output': 'blade', 'yield': 2, 'stack': 3},
    {'hide': 4, 'gem': 10, 'ore': 4, 'herb': 8},
    8,
    120],
   {'crafts': 2, 'made': 4, 'stacks': [3, 1], 'left': {'gem': 4, 'herb': 8, 'hide': 2, 'ore': 0}}),
  ('control #1',
   [{'inputs': {'ore': 4}, 'output': 'blade', 'yield': 3, 'stack': 10}, {'ore': 6}, 2, 51],
   {'crafts': 1, 'made': 3, 'stacks': [3], 'left': {'ore': 2}}),
  ('control #2',
   [{'inputs': {'hide': 3, 'ore': 1}, 'output': 'blade', 'yield': 1, 'stack': 5},
    {'hide': 21, 'ore': 5},
    3,
    99],
   {'crafts': 3, 'made': 3, 'stacks': [3], 'left': {'hide': 12, 'ore': 2}})],
 [('zero request #1',
   [{'inputs': {'hide': 2}, 'output': 'belt', 'yield': 1, 'stack': 3}, {'hide': 8}, 0, 80],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'hide': 8}}),
  ('exact material multiple #1',
   [{'inputs': {'ore': 3}, 'output': 'bar', 'yield': 1, 'stack': 5}, {'ore': 15}, 10, 50],
   {'crafts': 5, 'made': 6, 'stacks': [5, 1], 'left': {'ore': 0}}),
  ('fault site partial stack emission #1',
   [{'inputs': {'gem': 2}, 'output': 'blade', 'yield': 3, 'stack': 9}, {'gem': 19}, 0, 120],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'gem': 19}}),
  ('fault site partial stack emission #2',
   [{'inputs': {'hide': 1, 'wood': 1}, 'output': 'blade', 'yield': 1, 'stack': 6},
    {'wood': 23, 'herb': 9},
    4,
    49],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'herb': 9, 'hide': 0, 'wood': 23}}),
  ('partial repair boundary #1',
   [{'inputs': {'hide': 1, 'gem': 3, 'ore': 2}, 'output': 'blade', 'yield': 2, 'stack': 3},
    {'hide': 4, 'gem': 10, 'ore': 4, 'herb': 8},
    8,
    120],
   {'crafts': 2, 'made': 4, 'stacks': [3, 1], 'left': {'gem': 4, 'herb': 8, 'hide': 2, 'ore': 0}}),
  ('partial repair boundary #2',
   [{'inputs': {'ore': 2, 'hide': 4, 'wood': 1}, 'output': 'blade', 'yield': 1, 'stack': 9},
    {'ore': 3, 'hide': 11, 'wood': 24, 'herb': 7},
    9,
    99],
   {'crafts': 1, 'made': 1, 'stacks': [1], 'left': {'herb': 7, 'hide': 7, 'ore': 1, 'wood': 23}}),
  ('control #1',
   [{'inputs': {'wood': 2, 'hide': 3, 'gem': 3}, 'output': 'blade', 'yield': 3, 'stack': 7},
    {'wood': 12, 'hide': 23, 'gem': 11},
    4,
    51],
   {'crafts': 3, 'made': 9, 'stacks': [7, 2], 'left': {'gem': 2, 'hide': 14, 'wood': 6}}),
  ('control #2',
   [{'inputs': {'ore': 2, 'wood': 4, 'hide': 2}, 'output': 'blade', 'yield': 3, 'stack': 6},
    {'ore': 20, 'wood': 13, 'hide': 16, 'herb': 2},
    9,
    120],
   {'crafts': 3, 'made': 9, 'stacks': [6, 3], 'left': {'herb': 2, 'hide': 10, 'ore': 14, 'wood': 1}})],
 [('one short of a batch #1',
   [{'inputs': {'ore': 3, 'wood': 2}, 'output': 'axe', 'yield': 2, 'stack': 4},
    {'ore': 14, 'wood': 9, 'herb': 2},
    9,
    10],
   {'crafts': 4, 'made': 8, 'stacks': [4, 4], 'left': {'herb': 2, 'ore': 2, 'wood': 1}}),
  ('exact material multiple #1',
   [{'inputs': {'ore': 3}, 'output': 'bar', 'yield': 1, 'stack': 5}, {'ore': 15}, 10, 50],
   {'crafts': 5, 'made': 6, 'stacks': [5, 1], 'left': {'ore': 0}}),
  ('fault site partial stack emission #1',
   [{'inputs': {'gem': 3, 'hide': 4}, 'output': 'blade', 'yield': 3, 'stack': 6},
    {'gem': 16, 'hide': 29},
    0,
    100],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'gem': 16, 'hide': 29}}),
  ('fault site partial stack emission #2',
   [{'inputs': {'hide': 3, 'ore': 2, 'gem': 3}, 'output': 'blade', 'yield': 2, 'stack': 7},
    {'ore': 21, 'gem': 0, 'herb': 6},
    7,
    49],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'gem': 0, 'herb': 6, 'hide': 0, 'ore': 21}}),
  ('partial repair boundary #1',
   [{'inputs': {'hide': 2, 'gem': 4}, 'output': 'blade', 'yield': 1, 'stack': 6},
    {'hide': 17, 'gem': 28, 'herb': 9},
    1,
    96],
   {'crafts': 1, 'made': 1, 'stacks': [1], 'left': {'gem': 24, 'herb': 9, 'hide': 15}}),
  ('partial repair boundary #2',
   [{'inputs': {'wood': 1, 'ore': 4}, 'output': 'blade', 'yield': 1, 'stack': 4},
    {'wood': 10, 'ore': 6},
    12,
    120],
   {'crafts': 1, 'made': 1, 'stacks': [1], 'left': {'ore': 2, 'wood': 9}}),
  ('control #1',
   [{'inputs': {'gem': 4, 'ore': 2}, 'output': 'blade', 'yield': 1, 'stack': 9},
    {'gem': 15, 'ore': 20, 'herb': 6},
    12,
    120],
   {'crafts': 3, 'made': 3, 'stacks': [3], 'left': {'gem': 3, 'herb': 6, 'ore': 14}}),
  ('control #2',
   [{'inputs': {'ore': 4, 'gem': 4, 'hide': 4}, 'output': 'blade', 'yield': 2, 'stack': 7},
    {'ore': 13, 'gem': 22, 'hide': 22, 'herb': 6},
    2,
    120],
   {'crafts': 2, 'made': 4, 'stacks': [4], 'left': {'gem': 14, 'herb': 6, 'hide': 14, 'ore': 5}})],
 [('zero request #1',
   [{'inputs': {'hide': 2}, 'output': 'belt', 'yield': 1, 'stack': 3}, {'hide': 8}, 0, 80],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'hide': 8}}),
  ('exact material multiple #1',
   [{'inputs': {'ore': 3}, 'output': 'bar', 'yield': 1, 'stack': 5}, {'ore': 15}, 10, 50],
   {'crafts': 5, 'made': 6, 'stacks': [5, 1], 'left': {'ore': 0}}),
  ('fault site partial stack emission #1',
   [{'inputs': {'gem': 1}, 'output': 'blade', 'yield': 3, 'stack': 4}, {'gem': 26, 'herb': 7}, 4, 49],
   {'crafts': 4, 'made': 12, 'stacks': [4, 4, 4], 'left': {'gem': 22, 'herb': 7}}),
  ('fault site partial stack emission #2',
   [{'inputs': {'ore': 3, 'wood': 2, 'gem': 4}, 'output': 'blade', 'yield': 3, 'stack': 3},
    {'ore': 25, 'wood': 22, 'gem': 19},
    2,
    99],
   {'crafts': 2, 'made': 6, 'stacks': [3, 3], 'left': {'gem': 11, 'ore': 19, 'wood': 18}}),
  ('partial repair boundary #1',
   [{'inputs': {'gem': 4, 'ore': 2}, 'output': 'blade', 'yield': 2, 'stack': 3},
    {'gem': 22, 'ore': 14},
    6,
    0],
   {'crafts': 5, 'made': 10, 'stacks': [3, 3, 3, 1], 'left': {'gem': 2, 'ore': 4}}),
  ('partial repair boundary #2',
   [{'inputs': {'ore': 1, 'hide': 4, 'wood': 4}, 'output': 'blade', 'yield': 1, 'stack': 3},
    {'ore': 11, 'hide': 13, 'wood': 6, 'herb': 9},
    2,
    100],
   {'crafts': 1, 'made': 1, 'stacks': [1], 'left': {'herb': 9, 'hide': 9, 'ore': 10, 'wood': 2}}),
  ('control #1',
   [{'inputs': {'gem': 1, 'hide': 3, 'ore': 4}, 'output': 'blade', 'yield': 1, 'stack': 6},
    {'gem': 15, 'hide': 15, 'ore': 26},
    2,
    49],
   {'crafts': 2, 'made': 2, 'stacks': [2], 'left': {'gem': 13, 'hide': 9, 'ore': 18}}),
  ('control #2',
   [{'inputs': {'wood': 1, 'ore': 3, 'gem': 1}, 'output': 'blade', 'yield': 3, 'stack': 9},
    {'wood': 2, 'ore': 29, 'gem': 5, 'herb': 7},
    11,
    0],
   {'crafts': 2, 'made': 6, 'stacks': [6], 'left': {'gem': 3, 'herb': 7, 'ore': 23, 'wood': 0}})],
 [('one short of a batch #1',
   [{'inputs': {'ore': 3, 'wood': 2}, 'output': 'axe', 'yield': 2, 'stack': 4},
    {'ore': 14, 'wood': 9, 'herb': 2},
    9,
    10],
   {'crafts': 4, 'made': 8, 'stacks': [4, 4], 'left': {'herb': 2, 'ore': 2, 'wood': 1}}),
  ('exact material multiple #1',
   [{'inputs': {'ore': 3}, 'output': 'bar', 'yield': 1, 'stack': 5}, {'ore': 15}, 10, 50],
   {'crafts': 5, 'made': 6, 'stacks': [5, 1], 'left': {'ore': 0}}),
  ('fault site partial stack emission #1',
   [{'inputs': {'hide': 2, 'gem': 4}, 'output': 'blade', 'yield': 3, 'stack': 10},
    {'gem': 11, 'herb': 6},
    11,
    99],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'gem': 11, 'herb': 6, 'hide': 0}}),
  ('fault site partial stack emission #2',
   [{'inputs': {'gem': 2}, 'output': 'blade', 'yield': 1, 'stack': 7}, {'gem': 0}, 6, 0],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'gem': 0}}),
  ('partial repair boundary #1',
   [{'inputs': {'gem': 3}, 'output': 'blade', 'yield': 1, 'stack': 10}, {'gem': 3}, 2, 119],
   {'crafts': 1, 'made': 1, 'stacks': [1], 'left': {'gem': 0}}),
  ('partial repair boundary #2',
   [{'inputs': {'wood': 3, 'ore': 2}, 'output': 'blade', 'yield': 1, 'stack': 7},
    {'wood': 27, 'ore': 16, 'herb': 7},
    12,
    49],
   {'crafts': 8, 'made': 8, 'stacks': [7, 1], 'left': {'herb': 7, 'ore': 0, 'wood': 3}}),
  ('control #1',
   [{'inputs': {'hide': 1, 'gem': 2, 'wood': 1}, 'output': 'blade', 'yield': 3, 'stack': 10},
    {'hide': 28, 'gem': 10, 'wood': 23, 'herb': 6},
    8,
    120],
   {'crafts': 5, 'made': 16, 'stacks': [10, 6], 'left': {'gem': 0, 'herb': 6, 'hide': 23, 'wood': 18}}),
  ('control #2',
   [{'inputs': {'hide': 4}, 'output': 'blade', 'yield': 3, 'stack': 7}, {'hide': 15}, 7, 120],
   {'crafts': 3, 'made': 9, 'stacks': [7, 2], 'left': {'hide': 3}})]]
for label, args, expected in cases[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
An empty zero-count stack occupies an inventory slot after an exact multiple.

recipe = {inputs:{material:qty}, output, yield, stack}. Crafts = min(requested, floor(have/qty) per input), 0 when requested <= 0. With skill in [50, inf) every 5th craft adds one bonus item (bonus = crafts//5). made = crafts*yield + bonus, split into full stacks of size stack plus one partial stack. left = whole inventory (all materials) after consuming crafts*qty of each input, sorted by name.

split: open-access