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) - 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}}),
  ('zero request #1',
   [{'inputs': {'hide': 2}, 'output': 'belt', 'yield': 1, 'stack': 3}, {'hide': 8}, 0, 80],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'hide': 8}}),
  ('regression material consumption #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}}),
  ('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}}),
  ('regression material consumption #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}}),
  ('control #1',
   [{'inputs': {'hide': 3}, 'output': 'blade', 'yield': 3, 'stack': 4}, {'hide': 7, 'herb': 4}, 1, 90],
   {'crafts': 1, 'made': 3, 'stacks': [3], 'left': {'herb': 4, 'hide': 4}}),
  ('control #2',
   [{'inputs': {'hide': 1}, 'output': 'blade', 'yield': 1, 'stack': 3}, {'hide': 30, 'herb': 8}, 1, 120],
   {'crafts': 1, 'made': 1, 'stacks': [1], 'left': {'herb': 8, 'hide': 29}})],
 [('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}}),
  ('regression material consumption #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}}),
  ('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}}),
  ('regression material consumption #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}}),
  ('control #1',
   [{'inputs': {'wood': 2}, 'output': 'blade', 'yield': 2, 'stack': 8}, {'wood': 3}, 11, 9],
   {'crafts': 1, 'made': 2, 'stacks': [2], 'left': {'wood': 1}}),
  ('control #2',
   [{'inputs': {'wood': 2, 'gem': 2, 'ore': 2}, 'output': 'blade', 'yield': 2, 'stack': 10},
    {'wood': 25, 'gem': 16, 'ore': 19, 'herb': 2},
    1,
    25],
   {'crafts': 1, 'made': 2, 'stacks': [2], 'left': {'gem': 14, 'herb': 2, 'ore': 17, 'wood': 23}})],
 [('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}}),
  ('regression material consumption #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}}),
  ('regression material consumption #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}}),
  ('regression material consumption #3',
   [{'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 consumption #4',
   [{'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 #1',
   [{'inputs': {'gem': 1}, 'output': 'blade', 'yield': 1, 'stack': 9}, {'gem': 29}, 1, 30],
   {'crafts': 1, 'made': 1, 'stacks': [1], 'left': {'gem': 28}}),
  ('control #2',
   [{'inputs': {'ore': 1}, 'output': 'blade', 'yield': 1, 'stack': 10}, {'ore': 1, 'herb': 5}, 2, 34],
   {'crafts': 1, 'made': 1, 'stacks': [1], 'left': {'herb': 5, '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}}),
  ('regression material consumption #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}}),
  ('regression material consumption #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}}),
  ('regression material consumption #3',
   [{'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 material consumption #4',
   [{'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 #1',
   [{'inputs': {'hide': 1}, 'output': 'blade', 'yield': 1, 'stack': 5}, {'hide': 11}, 1, 50],
   {'crafts': 1, 'made': 1, 'stacks': [1], 'left': {'hide': 10}}),
  ('control #2',
   [{'inputs': {'gem': 3}, 'output': 'blade', 'yield': 3, 'stack': 4}, {'gem': 5}, 8, 50],
   {'crafts': 1, 'made': 3, 'stacks': [3], 'left': {'gem': 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}}),
  ('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 material consumption #1',
   [{'inputs': {'gem': 2}, 'output': 'blade', 'yield': 3, 'stack': 9}, {'gem': 19}, 0, 120],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'gem': 19}}),
  ('regression material consumption #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}}),
  ('regression material consumption #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}}),
  ('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}}),
  ('control #1',
   [{'inputs': {'hide': 3}, 'output': 'blade', 'yield': 3, 'stack': 3}, {'hide': 17, 'herb': 6}, 1, 50],
   {'crafts': 1, 'made': 3, 'stacks': [3], 'left': {'herb': 6, 'hide': 14}}),
  ('control #2',
   [{'inputs': {'hide': 3}, 'output': 'blade', 'yield': 3, 'stack': 4}, {'hide': 7, 'herb': 4}, 1, 90],
   {'crafts': 1, 'made': 3, 'stacks': [3], 'left': {'herb': 4, 'hide': 4}})]]
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:
        stacks.append(made % cap)
    left = dict(inventory)
    for mat, qty in recipe['inputs'].items():
        left[mat] = left.get(mat, 0) - crafts * recipe['yield']
    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}}),
  ('zero request #1',
   [{'inputs': {'hide': 2}, 'output': 'belt', 'yield': 1, 'stack': 3}, {'hide': 8}, 0, 80],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'hide': 8}}),
  ('regression material consumption #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}}),
  ('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}}),
  ('regression material consumption #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}}),
  ('control #1',
   [{'inputs': {'hide': 3}, 'output': 'blade', 'yield': 3, 'stack': 4}, {'hide': 7, 'herb': 4}, 1, 90],
   {'crafts': 1, 'made': 3, 'stacks': [3], 'left': {'herb': 4, 'hide': 4}}),
  ('control #2',
   [{'inputs': {'hide': 1}, 'output': 'blade', 'yield': 1, 'stack': 3}, {'hide': 30, 'herb': 8}, 1, 120],
   {'crafts': 1, 'made': 1, 'stacks': [1], 'left': {'herb': 8, 'hide': 29}})],
 [('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}}),
  ('regression material consumption #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}}),
  ('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}}),
  ('regression material consumption #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}}),
  ('control #1',
   [{'inputs': {'wood': 2}, 'output': 'blade', 'yield': 2, 'stack': 8}, {'wood': 3}, 11, 9],
   {'crafts': 1, 'made': 2, 'stacks': [2], 'left': {'wood': 1}}),
  ('control #2',
   [{'inputs': {'wood': 2, 'gem': 2, 'ore': 2}, 'output': 'blade', 'yield': 2, 'stack': 10},
    {'wood': 25, 'gem': 16, 'ore': 19, 'herb': 2},
    1,
    25],
   {'crafts': 1, 'made': 2, 'stacks': [2], 'left': {'gem': 14, 'herb': 2, 'ore': 17, 'wood': 23}})],
 [('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}}),
  ('regression material consumption #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}}),
  ('regression material consumption #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}}),
  ('regression material consumption #3',
   [{'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 consumption #4',
   [{'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 #1',
   [{'inputs': {'gem': 1}, 'output': 'blade', 'yield': 1, 'stack': 9}, {'gem': 29}, 1, 30],
   {'crafts': 1, 'made': 1, 'stacks': [1], 'left': {'gem': 28}}),
  ('control #2',
   [{'inputs': {'ore': 1}, 'output': 'blade', 'yield': 1, 'stack': 10}, {'ore': 1, 'herb': 5}, 2, 34],
   {'crafts': 1, 'made': 1, 'stacks': [1], 'left': {'herb': 5, '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}}),
  ('regression material consumption #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}}),
  ('regression material consumption #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}}),
  ('regression material consumption #3',
   [{'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 material consumption #4',
   [{'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 #1',
   [{'inputs': {'hide': 1}, 'output': 'blade', 'yield': 1, 'stack': 5}, {'hide': 11}, 1, 50],
   {'crafts': 1, 'made': 1, 'stacks': [1], 'left': {'hide': 10}}),
  ('control #2',
   [{'inputs': {'gem': 3}, 'output': 'blade', 'yield': 3, 'stack': 4}, {'gem': 5}, 8, 50],
   {'crafts': 1, 'made': 3, 'stacks': [3], 'left': {'gem': 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}}),
  ('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 material consumption #1',
   [{'inputs': {'gem': 2}, 'output': 'blade', 'yield': 3, 'stack': 9}, {'gem': 19}, 0, 120],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'gem': 19}}),
  ('regression material consumption #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}}),
  ('regression material consumption #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}}),
  ('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}}),
  ('control #1',
   [{'inputs': {'hide': 3}, 'output': 'blade', 'yield': 3, 'stack': 3}, {'hide': 17, 'herb': 6}, 1, 50],
   {'crafts': 1, 'made': 3, 'stacks': [3], 'left': {'herb': 6, 'hide': 14}}),
  ('control #2',
   [{'inputs': {'hide': 3}, 'output': 'blade', 'yield': 3, 'stack': 4}, {'hide': 7, 'herb': 4}, 1, 90],
   {'crafts': 1, 'made': 3, 'stacks': [3], 'left': {'herb': 4, 'hide': 4}})]]
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:
Long batches only charge materials for a single craft and duplicate resources.

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 = {}
    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}}),
  ('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 inventory carry-over #1',
   [{'inputs': {'ore': 4}, 'output': 'blade', 'yield': 3, 'stack': 10}, {'ore': 6}, 2, 51],
   {'crafts': 1, 'made': 3, 'stacks': [3], 'left': {'ore': 2}}),
  ('regression inventory carry-over #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 inventory carry-over #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}}),
  ('control #1',
   [{'inputs': {'gem': 2}, 'output': 'blade', 'yield': 1, 'stack': 7}, {'gem': 0}, 6, 0],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'gem': 0}}),
  ('control #2',
   [{'inputs': {'gem': 4}, 'output': 'blade', 'yield': 3, 'stack': 7}, {'gem': 0}, 12, 120],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'gem': 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}}),
  ('fault site inventory carry-over #1',
   [{'inputs': {'ore': 4}, 'output': 'blade', 'yield': 3, 'stack': 10}, {'ore': 6}, 2, 51],
   {'crafts': 1, 'made': 3, 'stacks': [3], 'left': {'ore': 2}}),
  ('regression inventory carry-over #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}}),
  ('regression inventory carry-over #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}}),
  ('control #1',
   [{'inputs': {'wood': 1, 'ore': 3}, 'output': 'blade', 'yield': 1, 'stack': 10}, {}, 8, 51],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'ore': 0, 'wood': 0}}),
  ('control #2',
   [{'inputs': {'ore': 4}, 'output': 'blade', 'yield': 3, 'stack': 10}, {}, 5, 100],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'ore': 0}}),
  ('control #3',
   [{'inputs': {'gem': 2}, 'output': 'blade', 'yield': 2, 'stack': 7}, {}, 5, 49],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'gem': 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}}),
  ('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 inventory carry-over #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}}),
  ('fault site inventory carry-over #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 inventory carry-over #1',
   [{'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 inventory carry-over #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}}),
  ('control #1',
   [{'inputs': {'ore': 4}, 'output': 'blade', 'yield': 3, 'stack': 10}, {}, 5, 100],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'ore': 0}}),
  ('control #2',
   [{'inputs': {'gem': 2}, 'output': 'blade', 'yield': 2, 'stack': 7}, {}, 5, 49],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'gem': 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}}),
  ('regression inventory carry-over #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 inventory carry-over #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 inventory carry-over #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 inventory carry-over #4',
   [{'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 #1',
   [{'inputs': {'wood': 2}, 'output': 'blade', 'yield': 2, 'stack': 5}, {}, 10, 79],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'wood': 0}}),
  ('control #2',
   [{'inputs': {'wood': 3}, 'output': 'blade', 'yield': 3, 'stack': 6}, {}, 6, 50],
   {'crafts': 0, 'made': 0, 'stacks': [], '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}}),
  ('regression inventory carry-over #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}}),
  ('fault site inventory carry-over #1',
   [{'inputs': {'gem': 2}, 'output': 'blade', 'yield': 3, 'stack': 9}, {'gem': 19}, 0, 120],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'gem': 19}}),
  ('regression inventory carry-over #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}}),
  ('regression inventory carry-over #3',
   [{'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}}),
  ('control #1',
   [{'inputs': {'gem': 4}, 'output': 'blade', 'yield': 3, 'stack': 7}, {'gem': 0}, 12, 120],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'gem': 0}}),
  ('control #2',
   [{'inputs': {'hide': 4}, 'output': 'blade', 'yield': 1, 'stack': 5}, {}, 0, 50],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'hide': 0}}),
  ('control #3',
   [{'inputs': {'wood': 1, 'ore': 3}, 'output': 'blade', 'yield': 1, 'stack': 10}, {}, 8, 51],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'ore': 0, 'wood': 0}})]]
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)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

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

N = 1
observations = []
def solve(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 = {m: inventory[m] for m in recipe['inputs'] if m in 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}}),
  ('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 inventory carry-over #1',
   [{'inputs': {'ore': 4}, 'output': 'blade', 'yield': 3, 'stack': 10}, {'ore': 6}, 2, 51],
   {'crafts': 1, 'made': 3, 'stacks': [3], 'left': {'ore': 2}}),
  ('regression inventory carry-over #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 inventory carry-over #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}}),
  ('control #1',
   [{'inputs': {'gem': 2}, 'output': 'blade', 'yield': 1, 'stack': 7}, {'gem': 0}, 6, 0],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'gem': 0}}),
  ('control #2',
   [{'inputs': {'gem': 4}, 'output': 'blade', 'yield': 3, 'stack': 7}, {'gem': 0}, 12, 120],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'gem': 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}}),
  ('fault site inventory carry-over #1',
   [{'inputs': {'ore': 4}, 'output': 'blade', 'yield': 3, 'stack': 10}, {'ore': 6}, 2, 51],
   {'crafts': 1, 'made': 3, 'stacks': [3], 'left': {'ore': 2}}),
  ('regression inventory carry-over #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}}),
  ('regression inventory carry-over #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}}),
  ('control #1',
   [{'inputs': {'wood': 1, 'ore': 3}, 'output': 'blade', 'yield': 1, 'stack': 10}, {}, 8, 51],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'ore': 0, 'wood': 0}}),
  ('control #2',
   [{'inputs': {'ore': 4}, 'output': 'blade', 'yield': 3, 'stack': 10}, {}, 5, 100],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'ore': 0}}),
  ('control #3',
   [{'inputs': {'gem': 2}, 'output': 'blade', 'yield': 2, 'stack': 7}, {}, 5, 49],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'gem': 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}}),
  ('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 inventory carry-over #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}}),
  ('fault site inventory carry-over #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 inventory carry-over #1',
   [{'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 inventory carry-over #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}}),
  ('control #1',
   [{'inputs': {'ore': 4}, 'output': 'blade', 'yield': 3, 'stack': 10}, {}, 5, 100],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'ore': 0}}),
  ('control #2',
   [{'inputs': {'gem': 2}, 'output': 'blade', 'yield': 2, 'stack': 7}, {}, 5, 49],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'gem': 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}}),
  ('regression inventory carry-over #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 inventory carry-over #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 inventory carry-over #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 inventory carry-over #4',
   [{'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 #1',
   [{'inputs': {'wood': 2}, 'output': 'blade', 'yield': 2, 'stack': 5}, {}, 10, 79],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'wood': 0}}),
  ('control #2',
   [{'inputs': {'wood': 3}, 'output': 'blade', 'yield': 3, 'stack': 6}, {}, 6, 50],
   {'crafts': 0, 'made': 0, 'stacks': [], '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}}),
  ('regression inventory carry-over #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}}),
  ('fault site inventory carry-over #1',
   [{'inputs': {'gem': 2}, 'output': 'blade', 'yield': 3, 'stack': 9}, {'gem': 19}, 0, 120],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'gem': 19}}),
  ('regression inventory carry-over #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}}),
  ('regression inventory carry-over #3',
   [{'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}}),
  ('control #1',
   [{'inputs': {'gem': 4}, 'output': 'blade', 'yield': 3, 'stack': 7}, {'gem': 0}, 12, 120],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'gem': 0}}),
  ('control #2',
   [{'inputs': {'hide': 4}, 'output': 'blade', 'yield': 1, 'stack': 5}, {}, 0, 50],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'hide': 0}}),
  ('control #3',
   [{'inputs': {'wood': 1, 'ore': 3}, 'output': 'blade', 'yield': 1, 'stack': 10}, {}, 8, 51],
   {'crafts': 0, 'made': 0, 'stacks': [], 'left': {'ore': 0, 'wood': 0}})]]
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:
Materials not used by the recipe are wiped from the returned inventory.

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 + bonus) * recipe['yield']
    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}}),
  ('regression yield composition #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 yield composition #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}}),
  ('regression yield composition #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}}),
  ('regression yield composition #4',
   [{'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}}),
  ('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}}),
  ('regression yield composition #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 yield composition #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}}),
  ('regression yield composition #3',
   [{'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}}),
  ('regression yield composition #4',
   [{'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}}),
  ('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}}),
  ('regression yield composition #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}}),
  ('regression yield composition #2',
   [{'inputs': {'ore': 2}, 'output': 'blade', 'yield': 2, 'stack': 8}, {'ore': 28}, 5, 100],
   {'crafts': 5, 'made': 11, 'stacks': [8, 3], 'left': {'ore': 18}}),
  ('regression yield composition #3',
   [{'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}}),
  ('regression yield composition #4',
   [{'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}}),
  ('regression yield composition #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 yield composition #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}}),
  ('regression yield composition #3',
   [{'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': {'hide': 3}, 'output': 'blade', 'yield': 1, 'stack': 6}, {'hide': 22}, 8, 100],
   {'crafts': 7, 'made': 8, 'stacks': [6, 2], 'left': {'hide': 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}}),
  ('regression yield composition #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 yield composition #2',
   [{'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': 3}, 'output': 'blade', 'yield': 1, 'stack': 6}, {'hide': 22}, 8, 100],
   {'crafts': 7, 'made': 8, 'stacks': [6, 2], 'left': {'hide': 1}}),
  ('regression yield composition #3',
   [{'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': {'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 >= 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}}),
  ('regression yield composition #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 yield composition #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}}),
  ('regression yield composition #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}}),
  ('regression yield composition #4',
   [{'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}}),
  ('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}}),
  ('regression yield composition #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 yield composition #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}}),
  ('regression yield composition #3',
   [{'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}}),
  ('regression yield composition #4',
   [{'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}}),
  ('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}}),
  ('regression yield composition #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}}),
  ('regression yield composition #2',
   [{'inputs': {'ore': 2}, 'output': 'blade', 'yield': 2, 'stack': 8}, {'ore': 28}, 5, 100],
   {'crafts': 5, 'made': 11, 'stacks': [8, 3], 'left': {'ore': 18}}),
  ('regression yield composition #3',
   [{'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}}),
  ('regression yield composition #4',
   [{'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}}),
  ('regression yield composition #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 yield composition #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}}),
  ('regression yield composition #3',
   [{'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': {'hide': 3}, 'output': 'blade', 'yield': 1, 'stack': 6}, {'hide': 22}, 8, 100],
   {'crafts': 7, 'made': 8, 'stacks': [6, 2], 'left': {'hide': 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}}),
  ('regression yield composition #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 yield composition #2',
   [{'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': 3}, 'output': 'blade', 'yield': 1, 'stack': 6}, {'hide': 22}, 8, 100],
   {'crafts': 7, 'made': 8, 'stacks': [6, 2], 'left': {'hide': 1}}),
  ('regression yield composition #3',
   [{'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': {'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:
High-skill multi-yield crafting mints extra items per bonus.

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(item, components):
    pct = {'common': 50, 'rare': 70, 'epic': 90}[item['rarity']]
    mx = item['max_durability']
    if mx == 0:
        d, mx = 1, 1
    else:
        d = min(item['durability'], mx)
    if d <= 0:
        return {'scrap': 1}
    out = {}
    for name, count in components.items():
        amt = count * pct // 100 * d // mx
        if item['rarity'] != 'common' and amt < 1:
            amt = 1
        if amt:
            out[name] = amt
    return dict(sorted(out.items()))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('over-repaired common #1',
   [{'rarity': 'common', 'durability': 30, 'max_durability': 20}, {'ingot': 4, 'cloth': 3}],
   {'cloth': 1, 'ingot': 2}),
  ('regression return rounding stage #1',
   [{'rarity': 'epic', 'durability': 67, 'max_durability': 100}, {'cloth': 6, 'ingot': 2, 'shard': 5}],
   {'cloth': 3, 'ingot': 1, 'shard': 3}),
  ('fault site return rounding stage #1',
   [{'rarity': 'epic', 'durability': 4, 'max_durability': 7}, {'shard': 4, 'ingot': 4, 'cloth': 6}],
   {'cloth': 3, 'ingot': 2, 'shard': 2}),
  ('partial repair boundary #1',
   [{'rarity': 'common', 'durability': 3, 'max_durability': 10}, {'thread': 4, 'cloth': 5}],
   {}),
  ('partial repair boundary #2',
   [{'rarity': 'rare', 'durability': 1, 'max_durability': 0}, {'cloth': 5, 'ingot': 4, 'shard': 1}],
   {'cloth': 3, 'ingot': 2, 'shard': 1}),
  ('indestructible relic #1',
   [{'rarity': 'epic', 'durability': 0, 'max_durability': 0}, {'shard': 5}],
   {'shard': 4}),
  ('broken rare #1',
   [{'rarity': 'rare', 'durability': 0, 'max_durability': 40}, {'thread': 2}],
   {'scrap': 1}),
  ('control #1', [{'rarity': 'rare', 'durability': 0, 'max_durability': 100}, {'shard': 5}], {'scrap': 1})],
 [('over-repaired common #1',
   [{'rarity': 'common', 'durability': 30, 'max_durability': 20}, {'ingot': 4, 'cloth': 3}],
   {'cloth': 1, 'ingot': 2}),
  ('regression return rounding stage #1',
   [{'rarity': 'common', 'durability': 70, 'max_durability': 100}, {'cloth': 3, 'shard': 2}],
   {'cloth': 1}),
  ('regression return rounding stage #2',
   [{'rarity': 'epic', 'durability': 8, 'max_durability': 10}, {'ingot': 3, 'cloth': 5}],
   {'cloth': 3, 'ingot': 2}),
  ('partial repair boundary #1',
   [{'rarity': 'rare', 'durability': 1, 'max_durability': 0}, {'cloth': 5, 'ingot': 4, 'shard': 1}],
   {'cloth': 3, 'ingot': 2, 'shard': 1}),
  ('partial repair boundary #2',
   [{'rarity': 'epic', 'durability': 4, 'max_durability': 7}, {'cloth': 5}],
   {'cloth': 2}),
  ('indestructible relic #1',
   [{'rarity': 'epic', 'durability': 0, 'max_durability': 0}, {'shard': 5}],
   {'shard': 4}),
  ('broken rare #1',
   [{'rarity': 'rare', 'durability': 0, 'max_durability': 40}, {'thread': 2}],
   {'scrap': 1}),
  ('control #1', [{'rarity': 'rare', 'durability': 0, 'max_durability': 100}, {'shard': 5}], {'scrap': 1})],
 [('over-repaired common #1',
   [{'rarity': 'common', 'durability': 30, 'max_durability': 20}, {'ingot': 4, 'cloth': 3}],
   {'cloth': 1, 'ingot': 2}),
  ('fault site return rounding stage #1',
   [{'rarity': 'epic', 'durability': 9, 'max_durability': 10}, {'cloth': 3, 'shard': 4, 'thread': 1}],
   {'cloth': 2, 'shard': 3, 'thread': 1}),
  ('fault site return rounding stage #2',
   [{'rarity': 'rare', 'durability': 37, 'max_durability': 50}, {'ingot': 4, 'shard': 6, 'cloth': 2}],
   {'cloth': 1, 'ingot': 2, 'shard': 3}),
  ('partial repair boundary #1',
   [{'rarity': 'epic', 'durability': 7, 'max_durability': 7}, {'thread': 2, 'ingot': 1, 'cloth': 1}],
   {'cloth': 1, 'ingot': 1, 'thread': 1}),
  ('partial repair boundary #2',
   [{'rarity': 'rare', 'durability': 50, 'max_durability': 50}, {'thread': 4, 'shard': 2, 'ingot': 4}],
   {'ingot': 2, 'shard': 1, 'thread': 2}),
  ('indestructible relic #1',
   [{'rarity': 'epic', 'durability': 0, 'max_durability': 0}, {'shard': 5}],
   {'shard': 4}),
  ('broken rare #1',
   [{'rarity': 'rare', 'durability': 0, 'max_durability': 40}, {'thread': 2}],
   {'scrap': 1}),
  ('control #1', [{'rarity': 'rare', 'durability': 0, 'max_durability': 100}, {'shard': 5}], {'scrap': 1})],
 [('over-repaired common #1',
   [{'rarity': 'common', 'durability': 30, 'max_durability': 20}, {'ingot': 4, 'cloth': 3}],
   {'cloth': 1, 'ingot': 2}),
  ('regression return rounding stage #1',
   [{'rarity': 'epic', 'durability': 5, 'max_durability': 7}, {'shard': 4, 'thread': 5, 'ingot': 5}],
   {'ingot': 3, 'shard': 2, 'thread': 3}),
  ('regression return rounding stage #2',
   [{'rarity': 'epic', 'durability': 67, 'max_durability': 100}, {'cloth': 6, 'ingot': 2, 'shard': 5}],
   {'cloth': 3, 'ingot': 1, 'shard': 3}),
  ('partial repair boundary #1',
   [{'rarity': 'rare', 'durability': 20, 'max_durability': 20}, {'shard': 2, 'cloth': 5, 'thread': 6}],
   {'cloth': 3, 'shard': 1, 'thread': 4}),
  ('partial repair boundary #2',
   [{'rarity': 'epic', 'durability': 12, 'max_durability': 7}, {'thread': 4, 'ingot': 5}],
   {'ingot': 4, 'thread': 3}),
  ('indestructible relic #1',
   [{'rarity': 'epic', 'durability': 0, 'max_durability': 0}, {'shard': 5}],
   {'shard': 4}),
  ('broken rare #1',
   [{'rarity': 'rare', 'durability': 0, 'max_durability': 40}, {'thread': 2}],
   {'scrap': 1}),
  ('control #1',
   [{'rarity': 'common', 'durability': 0, 'max_durability': 100}, {'cloth': 6, 'thread': 1}],
   {'scrap': 1})],
 [('over-repaired common #1',
   [{'rarity': 'common', 'durability': 30, 'max_durability': 20}, {'ingot': 4, 'cloth': 3}],
   {'cloth': 1, 'ingot': 2}),
  ('fault site return rounding stage #1',
   [{'rarity': 'epic', 'durability': 4, 'max_durability': 7}, {'shard': 4, 'ingot': 4, 'cloth': 6}],
   {'cloth': 3, 'ingot': 2, 'shard': 2}),
  ('regression return rounding stage #1',
   [{'rarity': 'common', 'durability': 70, 'max_durability': 100}, {'cloth': 3, 'shard': 2}],
   {'cloth': 1}),
  ('partial repair boundary #1',
   [{'rarity': 'common', 'durability': 100, 'max_durability': 100}, {'thread': 3}],
   {'thread': 1}),
  ('partial repair boundary #2',
   [{'rarity': 'epic', 'durability': 31, 'max_durability': 100}, {'thread': 1, 'cloth': 4, 'shard': 6}],
   {'cloth': 1, 'shard': 1, 'thread': 1}),
  ('indestructible relic #1',
   [{'rarity': 'epic', 'durability': 0, 'max_durability': 0}, {'shard': 5}],
   {'shard': 4}),
  ('broken rare #1',
   [{'rarity': 'rare', 'durability': 0, 'max_durability': 40}, {'thread': 2}],
   {'scrap': 1}),
  ('control #1',
   [{'rarity': 'common', 'durability': 1, 'max_durability': 0}, {'shard': 2, 'ingot': 2, 'thread': 6}],
   {'ingot': 1, 'shard': 1, 'thread': 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(item, components):
    pct = {'common': 50, 'rare': 70, 'epic': 90}[item['rarity']]
    mx = item['max_durability']
    if mx == 0:
        d, mx = 1, 1
    else:
        d = min(item['durability'], mx)
    if d <= 0:
        return {'scrap': 1}
    out = {}
    for name, count in components.items():
        amt = round(count * pct * d / (100 * mx))
        if item['rarity'] != 'common' and amt < 1:
            amt = 1
        if amt:
            out[name] = amt
    return dict(sorted(out.items()))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('over-repaired common #1',
   [{'rarity': 'common', 'durability': 30, 'max_durability': 20}, {'ingot': 4, 'cloth': 3}],
   {'cloth': 1, 'ingot': 2}),
  ('regression return rounding stage #1',
   [{'rarity': 'epic', 'durability': 67, 'max_durability': 100}, {'cloth': 6, 'ingot': 2, 'shard': 5}],
   {'cloth': 3, 'ingot': 1, 'shard': 3}),
  ('fault site return rounding stage #1',
   [{'rarity': 'epic', 'durability': 4, 'max_durability': 7}, {'shard': 4, 'ingot': 4, 'cloth': 6}],
   {'cloth': 3, 'ingot': 2, 'shard': 2}),
  ('partial repair boundary #1',
   [{'rarity': 'common', 'durability': 3, 'max_durability': 10}, {'thread': 4, 'cloth': 5}],
   {}),
  ('partial repair boundary #2',
   [{'rarity': 'rare', 'durability': 1, 'max_durability': 0}, {'cloth': 5, 'ingot': 4, 'shard': 1}],
   {'cloth': 3, 'ingot': 2, 'shard': 1}),
  ('indestructible relic #1',
   [{'rarity': 'epic', 'durability': 0, 'max_durability': 0}, {'shard': 5}],
   {'shard': 4}),
  ('broken rare #1',
   [{'rarity': 'rare', 'durability': 0, 'max_durability': 40}, {'thread': 2}],
   {'scrap': 1}),
  ('control #1', [{'rarity': 'rare', 'durability': 0, 'max_durability': 100}, {'shard': 5}], {'scrap': 1})],
 [('over-repaired common #1',
   [{'rarity': 'common', 'durability': 30, 'max_durability': 20}, {'ingot': 4, 'cloth': 3}],
   {'cloth': 1, 'ingot': 2}),
  ('regression return rounding stage #1',
   [{'rarity': 'common', 'durability': 70, 'max_durability': 100}, {'cloth': 3, 'shard': 2}],
   {'cloth': 1}),
  ('regression return rounding stage #2',
   [{'rarity': 'epic', 'durability': 8, 'max_durability': 10}, {'ingot': 3, 'cloth': 5}],
   {'cloth': 3, 'ingot': 2}),
  ('partial repair boundary #1',
   [{'rarity': 'rare', 'durability': 1, 'max_durability': 0}, {'cloth': 5, 'ingot': 4, 'shard': 1}],
   {'cloth': 3, 'ingot': 2, 'shard': 1}),
  ('partial repair boundary #2',
   [{'rarity': 'epic', 'durability': 4, 'max_durability': 7}, {'cloth': 5}],
   {'cloth': 2}),
  ('indestructible relic #1',
   [{'rarity': 'epic', 'durability': 0, 'max_durability': 0}, {'shard': 5}],
   {'shard': 4}),
  ('broken rare #1',
   [{'rarity': 'rare', 'durability': 0, 'max_durability': 40}, {'thread': 2}],
   {'scrap': 1}),
  ('control #1', [{'rarity': 'rare', 'durability': 0, 'max_durability': 100}, {'shard': 5}], {'scrap': 1})],
 [('over-repaired common #1',
   [{'rarity': 'common', 'durability': 30, 'max_durability': 20}, {'ingot': 4, 'cloth': 3}],
   {'cloth': 1, 'ingot': 2}),
  ('fault site return rounding stage #1',
   [{'rarity': 'epic', 'durability': 9, 'max_durability': 10}, {'cloth': 3, 'shard': 4, 'thread': 1}],
   {'cloth': 2, 'shard': 3, 'thread': 1}),
  ('fault site return rounding stage #2',
   [{'rarity': 'rare', 'durability': 37, 'max_durability': 50}, {'ingot': 4, 'shard': 6, 'cloth': 2}],
   {'cloth': 1, 'ingot': 2, 'shard': 3}),
  ('partial repair boundary #1',
   [{'rarity': 'epic', 'durability': 7, 'max_durability': 7}, {'thread': 2, 'ingot': 1, 'cloth': 1}],
   {'cloth': 1, 'ingot': 1, 'thread': 1}),
  ('partial repair boundary #2',
   [{'rarity': 'rare', 'durability': 50, 'max_durability': 50}, {'thread': 4, 'shard': 2, 'ingot': 4}],
   {'ingot': 2, 'shard': 1, 'thread': 2}),
  ('indestructible relic #1',
   [{'rarity': 'epic', 'durability': 0, 'max_durability': 0}, {'shard': 5}],
   {'shard': 4}),
  ('broken rare #1',
   [{'rarity': 'rare', 'durability': 0, 'max_durability': 40}, {'thread': 2}],
   {'scrap': 1}),
  ('control #1', [{'rarity': 'rare', 'durability': 0, 'max_durability': 100}, {'shard': 5}], {'scrap': 1})],
 [('over-repaired common #1',
   [{'rarity': 'common', 'durability': 30, 'max_durability': 20}, {'ingot': 4, 'cloth': 3}],
   {'cloth': 1, 'ingot': 2}),
  ('regression return rounding stage #1',
   [{'rarity': 'epic', 'durability': 5, 'max_durability': 7}, {'shard': 4, 'thread': 5, 'ingot': 5}],
   {'ingot': 3, 'shard': 2, 'thread': 3}),
  ('regression return rounding stage #2',
   [{'rarity': 'epic', 'durability': 67, 'max_durability': 100}, {'cloth': 6, 'ingot': 2, 'shard': 5}],
   {'cloth': 3, 'ingot': 1, 'shard': 3}),
  ('partial repair boundary #1',
   [{'rarity': 'rare', 'durability': 20, 'max_durability': 20}, {'shard': 2, 'cloth': 5, 'thread': 6}],
   {'cloth': 3, 'shard': 1, 'thread': 4}),
  ('partial repair boundary #2',
   [{'rarity': 'epic', 'durability': 12, 'max_durability': 7}, {'thread': 4, 'ingot': 5}],
   {'ingot': 4, 'thread': 3}),
  ('indestructible relic #1',
   [{'rarity': 'epic', 'durability': 0, 'max_durability': 0}, {'shard': 5}],
   {'shard': 4}),
  ('broken rare #1',
   [{'rarity': 'rare', 'durability': 0, 'max_durability': 40}, {'thread': 2}],
   {'scrap': 1}),
  ('control #1',
   [{'rarity': 'common', 'durability': 0, 'max_durability': 100}, {'cloth': 6, 'thread': 1}],
   {'scrap': 1})],
 [('over-repaired common #1',
   [{'rarity': 'common', 'durability': 30, 'max_durability': 20}, {'ingot': 4, 'cloth': 3}],
   {'cloth': 1, 'ingot': 2}),
  ('fault site return rounding stage #1',
   [{'rarity': 'epic', 'durability': 4, 'max_durability': 7}, {'shard': 4, 'ingot': 4, 'cloth': 6}],
   {'cloth': 3, 'ingot': 2, 'shard': 2}),
  ('regression return rounding stage #1',
   [{'rarity': 'common', 'durability': 70, 'max_durability': 100}, {'cloth': 3, 'shard': 2}],
   {'cloth': 1}),
  ('partial repair boundary #1',
   [{'rarity': 'common', 'durability': 100, 'max_durability': 100}, {'thread': 3}],
   {'thread': 1}),
  ('partial repair boundary #2',
   [{'rarity': 'epic', 'durability': 31, 'max_durability': 100}, {'thread': 1, 'cloth': 4, 'shard': 6}],
   {'cloth': 1, 'shard': 1, 'thread': 1}),
  ('indestructible relic #1',
   [{'rarity': 'epic', 'durability': 0, 'max_durability': 0}, {'shard': 5}],
   {'shard': 4}),
  ('broken rare #1',
   [{'rarity': 'rare', 'durability': 0, 'max_durability': 40}, {'thread': 2}],
   {'scrap': 1}),
  ('control #1',
   [{'rarity': 'common', 'durability': 1, 'max_durability': 0}, {'shard': 2, 'ingot': 2, 'thread': 6}],
   {'ingot': 1, 'shard': 1, 'thread': 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:
Damaged items return fewer components than the single-floor rule allows.

Return rate: common 50%, rare 70%, epic 90%. Condition d/mx with d clamped to mx; max_durability 0 means indestructible (full condition). Durability <= 0 yields {"scrap": 1}. Each component amount = floor(count*pct*d/(100*mx)) computed once; rare and epic items return at least 1 of each component; zero amounts are omitted.

split: open-access


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

N = 1
observations = []
def solve(item, components):
    pct = {'common': 50, 'rare': 70, 'epic': 90}[item['rarity']]
    mx = item['max_durability']
    if mx == 0:
        d, mx = 1, 1
    else:
        d = min(item['durability'], mx)
    if d <= 0:
        return {'scrap': 1}
    out = {}
    for name, count in components.items():
        amt = count * pct // 100
        if item['rarity'] != 'common' and amt < 1:
            amt = 1
        if amt:
            out[name] = amt
    return dict(sorted(out.items()))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('indestructible relic #1',
   [{'rarity': 'epic', 'durability': 0, 'max_durability': 0}, {'shard': 5}],
   {'shard': 4}),
  ('fault site condition scaling #1',
   [{'rarity': 'common', 'durability': 3, 'max_durability': 10}, {'thread': 4, 'cloth': 5}],
   {}),
  ('fault site condition scaling #2',
   [{'rarity': 'rare', 'durability': 1, 'max_durability': 50}, {'ingot': 4, 'shard': 3}],
   {'ingot': 1, 'shard': 1}),
  ('over-repaired common #1',
   [{'rarity': 'common', 'durability': 30, 'max_durability': 20}, {'ingot': 4, 'cloth': 3}],
   {'cloth': 1, 'ingot': 2}),
  ('partial repair boundary #1',
   [{'rarity': 'rare', 'durability': 1, 'max_durability': 0}, {'cloth': 5, 'ingot': 4, 'shard': 1}],
   {'cloth': 3, 'ingot': 2, 'shard': 1}),
  ('broken rare #1',
   [{'rarity': 'rare', 'durability': 0, 'max_durability': 40}, {'thread': 2}],
   {'scrap': 1}),
  ('control #1', [{'rarity': 'rare', 'durability': 0, 'max_durability': 100}, {'shard': 5}], {'scrap': 1}),
  ('control #2',
   [{'rarity': 'common', 'durability': 0, 'max_durability': 100}, {'cloth': 6, 'thread': 1}],
   {'scrap': 1})],
 [('over-repaired common #1',
   [{'rarity': 'common', 'durability': 30, 'max_durability': 20}, {'ingot': 4, 'cloth': 3}],
   {'cloth': 1, 'ingot': 2}),
  ('fault site condition scaling #1',
   [{'rarity': 'rare', 'durability': 1, 'max_durability': 20}, {'ingot': 3, 'shard': 3, 'thread': 5}],
   {'ingot': 1, 'shard': 1, 'thread': 1}),
  ('fault site condition scaling #2',
   [{'rarity': 'rare', 'durability': 1, 'max_durability': 100}, {'cloth': 4}],
   {'cloth': 1}),
  ('partial repair boundary #1',
   [{'rarity': 'rare', 'durability': 1, 'max_durability': 0}, {'cloth': 5, 'ingot': 4, 'shard': 1}],
   {'cloth': 3, 'ingot': 2, 'shard': 1}),
  ('partial repair boundary #2',
   [{'rarity': 'common', 'durability': 1, 'max_durability': 0}, {'shard': 2, 'ingot': 2, 'thread': 6}],
   {'ingot': 1, 'shard': 1, 'thread': 3}),
  ('broken rare #1',
   [{'rarity': 'rare', 'durability': 0, 'max_durability': 40}, {'thread': 2}],
   {'scrap': 1}),
  ('control #1',
   [{'rarity': 'common', 'durability': 0, 'max_durability': 100}, {'cloth': 6, 'thread': 1}],
   {'scrap': 1}),
  ('control #2', [{'rarity': 'epic', 'durability': 1, 'max_durability': 50}, {'cloth': 1}], {'cloth': 1})],
 [('indestructible relic #1',
   [{'rarity': 'epic', 'durability': 0, 'max_durability': 0}, {'shard': 5}],
   {'shard': 4}),
  ('fault site condition scaling #1',
   [{'rarity': 'common', 'durability': 4, 'max_durability': 20}, {'thread': 4, 'shard': 3}],
   {}),
  ('fault site condition scaling #2',
   [{'rarity': 'epic', 'durability': 1, 'max_durability': 100}, {'cloth': 6, 'ingot': 1, 'thread': 3}],
   {'cloth': 1, 'ingot': 1, 'thread': 1}),
  ('partial repair boundary #1',
   [{'rarity': 'epic', 'durability': 12, 'max_durability': 7}, {'ingot': 5}],
   {'ingot': 4}),
  ('partial repair boundary #2',
   [{'rarity': 'rare', 'durability': 12, 'max_durability': 7}, {'cloth': 3}],
   {'cloth': 2}),
  ('broken rare #1',
   [{'rarity': 'rare', 'durability': 0, 'max_durability': 40}, {'thread': 2}],
   {'scrap': 1}),
  ('control #1',
   [{'rarity': 'common', 'durability': 50, 'max_durability': 50}, {'thread': 1, 'ingot': 1}],
   {}),
  ('control #2', [{'rarity': 'common', 'durability': 0, 'max_durability': 10}, {'thread': 3}], {'scrap': 1})],
 [('over-repaired common #1',
   [{'rarity': 'common', 'durability': 30, 'max_durability': 20}, {'ingot': 4, 'cloth': 3}],
   {'cloth': 1, 'ingot': 2}),
  ('fault site condition scaling #1',
   [{'rarity': 'rare', 'durability': 2, 'max_durability': 7}, {'shard': 2, 'thread': 4, 'cloth': 2}],
   {'cloth': 1, 'shard': 1, 'thread': 1}),
  ('regression condition scaling #1',
   [{'rarity': 'epic', 'durability': 4, 'max_durability': 7}, {'cloth': 5}],
   {'cloth': 2}),
  ('partial repair boundary #1',
   [{'rarity': 'rare', 'durability': 7, 'max_durability': 7}, {'shard': 6}],
   {'shard': 4}),
  ('partial repair boundary #2',
   [{'rarity': 'common', 'durability': 1, 'max_durability': 0}, {'cloth': 6, 'ingot': 2}],
   {'cloth': 3, 'ingot': 1}),
  ('broken rare #1',
   [{'rarity': 'rare', 'durability': 0, 'max_durability': 40}, {'thread': 2}],
   {'scrap': 1}),
  ('control #1', [{'rarity': 'common', 'durability': 7, 'max_durability': 7}, {'thread': 1}], {}),
  ('control #2', [{'rarity': 'rare', 'durability': 0, 'max_durability': 10}, {'cloth': 6}], {'scrap': 1})],
 [('indestructible relic #1',
   [{'rarity': 'epic', 'durability': 0, 'max_durability': 0}, {'shard': 5}],
   {'shard': 4}),
  ('fault site condition scaling #1',
   [{'rarity': 'epic', 'durability': 1, 'max_durability': 20}, {'cloth': 2, 'thread': 4, 'ingot': 3}],
   {'cloth': 1, 'ingot': 1, 'thread': 1}),
  ('fault site condition scaling #2',
   [{'rarity': 'epic', 'durability': 3, 'max_durability': 100}, {'shard': 4, 'cloth': 4, 'ingot': 3}],
   {'cloth': 1, 'ingot': 1, 'shard': 1}),
  ('partial repair boundary #1',
   [{'rarity': 'common', 'durability': 20, 'max_durability': 20}, {'shard': 4, 'thread': 2}],
   {'shard': 2, 'thread': 1}),
  ('regression condition scaling #1',
   [{'rarity': 'epic', 'durability': 4, 'max_durability': 7}, {'cloth': 5}],
   {'cloth': 2}),
  ('broken rare #1',
   [{'rarity': 'rare', 'durability': 0, 'max_durability': 40}, {'thread': 2}],
   {'scrap': 1}),
  ('control #1',
   [{'rarity': 'rare', 'durability': 0, 'max_durability': 10}, {'ingot': 5, 'thread': 3}],
   {'scrap': 1}),
  ('control #2', [{'rarity': 'epic', 'durability': 1, 'max_durability': 50}, {'thread': 2}], {'thread': 1})]]
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(item, components):
    pct = {'common': 50, 'rare': 70, 'epic': 90}[item['rarity']]
    mx = item['max_durability']
    if mx == 0:
        d, mx = 1, 1
    else:
        d = min(item['durability'], mx)
    if d <= 0:
        return {'scrap': 1}
    out = {}
    for name, count in components.items():
        amt = count * pct * d // (100 * 100)
        if item['rarity'] != 'common' and amt < 1:
            amt = 1
        if amt:
            out[name] = amt
    return dict(sorted(out.items()))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('indestructible relic #1',
   [{'rarity': 'epic', 'durability': 0, 'max_durability': 0}, {'shard': 5}],
   {'shard': 4}),
  ('fault site condition scaling #1',
   [{'rarity': 'common', 'durability': 3, 'max_durability': 10}, {'thread': 4, 'cloth': 5}],
   {}),
  ('fault site condition scaling #2',
   [{'rarity': 'rare', 'durability': 1, 'max_durability': 50}, {'ingot': 4, 'shard': 3}],
   {'ingot': 1, 'shard': 1}),
  ('over-repaired common #1',
   [{'rarity': 'common', 'durability': 30, 'max_durability': 20}, {'ingot': 4, 'cloth': 3}],
   {'cloth': 1, 'ingot': 2}),
  ('partial repair boundary #1',
   [{'rarity': 'rare', 'durability': 1, 'max_durability': 0}, {'cloth': 5, 'ingot': 4, 'shard': 1}],
   {'cloth': 3, 'ingot': 2, 'shard': 1}),
  ('broken rare #1',
   [{'rarity': 'rare', 'durability': 0, 'max_durability': 40}, {'thread': 2}],
   {'scrap': 1}),
  ('control #1', [{'rarity': 'rare', 'durability': 0, 'max_durability': 100}, {'shard': 5}], {'scrap': 1}),
  ('control #2',
   [{'rarity': 'common', 'durability': 0, 'max_durability': 100}, {'cloth': 6, 'thread': 1}],
   {'scrap': 1})],
 [('over-repaired common #1',
   [{'rarity': 'common', 'durability': 30, 'max_durability': 20}, {'ingot': 4, 'cloth': 3}],
   {'cloth': 1, 'ingot': 2}),
  ('fault site condition scaling #1',
   [{'rarity': 'rare', 'durability': 1, 'max_durability': 20}, {'ingot': 3, 'shard': 3, 'thread': 5}],
   {'ingot': 1, 'shard': 1, 'thread': 1}),
  ('fault site condition scaling #2',
   [{'rarity': 'rare', 'durability': 1, 'max_durability': 100}, {'cloth': 4}],
   {'cloth': 1}),
  ('partial repair boundary #1',
   [{'rarity': 'rare', 'durability': 1, 'max_durability': 0}, {'cloth': 5, 'ingot': 4, 'shard': 1}],
   {'cloth': 3, 'ingot': 2, 'shard': 1}),
  ('partial repair boundary #2',
   [{'rarity': 'common', 'durability': 1, 'max_durability': 0}, {'shard': 2, 'ingot': 2, 'thread': 6}],
   {'ingot': 1, 'shard': 1, 'thread': 3}),
  ('broken rare #1',
   [{'rarity': 'rare', 'durability': 0, 'max_durability': 40}, {'thread': 2}],
   {'scrap': 1}),
  ('control #1',
   [{'rarity': 'common', 'durability': 0, 'max_durability': 100}, {'cloth': 6, 'thread': 1}],
   {'scrap': 1}),
  ('control #2', [{'rarity': 'epic', 'durability': 1, 'max_durability': 50}, {'cloth': 1}], {'cloth': 1})],
 [('indestructible relic #1',
   [{'rarity': 'epic', 'durability': 0, 'max_durability': 0}, {'shard': 5}],
   {'shard': 4}),
  ('fault site condition scaling #1',
   [{'rarity': 'common', 'durability': 4, 'max_durability': 20}, {'thread': 4, 'shard': 3}],
   {}),
  ('fault site condition scaling #2',
   [{'rarity': 'epic', 'durability': 1, 'max_durability': 100}, {'cloth': 6, 'ingot': 1, 'thread': 3}],
   {'cloth': 1, 'ingot': 1, 'thread': 1}),
  ('partial repair boundary #1',
   [{'rarity': 'epic', 'durability': 12, 'max_durability': 7}, {'ingot': 5}],
   {'ingot': 4}),
  ('partial repair boundary #2',
   [{'rarity': 'rare', 'durability': 12, 'max_durability': 7}, {'cloth': 3}],
   {'cloth': 2}),
  ('broken rare #1',
   [{'rarity': 'rare', 'durability': 0, 'max_durability': 40}, {'thread': 2}],
   {'scrap': 1}),
  ('control #1',
   [{'rarity': 'common', 'durability': 50, 'max_durability': 50}, {'thread': 1, 'ingot': 1}],
   {}),
  ('control #2', [{'rarity': 'common', 'durability': 0, 'max_durability': 10}, {'thread': 3}], {'scrap': 1})],
 [('over-repaired common #1',
   [{'rarity': 'common', 'durability': 30, 'max_durability': 20}, {'ingot': 4, 'cloth': 3}],
   {'cloth': 1, 'ingot': 2}),
  ('fault site condition scaling #1',
   [{'rarity': 'rare', 'durability': 2, 'max_durability': 7}, {'shard': 2, 'thread': 4, 'cloth': 2}],
   {'cloth': 1, 'shard': 1, 'thread': 1}),
  ('regression condition scaling #1',
   [{'rarity': 'epic', 'durability': 4, 'max_durability': 7}, {'cloth': 5}],
   {'cloth': 2}),
  ('partial repair boundary #1',
   [{'rarity': 'rare', 'durability': 7, 'max_durability': 7}, {'shard': 6}],
   {'shard': 4}),
  ('partial repair boundary #2',
   [{'rarity': 'common', 'durability': 1, 'max_durability': 0}, {'cloth': 6, 'ingot': 2}],
   {'cloth': 3, 'ingot': 1}),
  ('broken rare #1',
   [{'rarity': 'rare', 'durability': 0, 'max_durability': 40}, {'thread': 2}],
   {'scrap': 1}),
  ('control #1', [{'rarity': 'common', 'durability': 7, 'max_durability': 7}, {'thread': 1}], {}),
  ('control #2', [{'rarity': 'rare', 'durability': 0, 'max_durability': 10}, {'cloth': 6}], {'scrap': 1})],
 [('indestructible relic #1',
   [{'rarity': 'epic', 'durability': 0, 'max_durability': 0}, {'shard': 5}],
   {'shard': 4}),
  ('fault site condition scaling #1',
   [{'rarity': 'epic', 'durability': 1, 'max_durability': 20}, {'cloth': 2, 'thread': 4, 'ingot': 3}],
   {'cloth': 1, 'ingot': 1, 'thread': 1}),
  ('fault site condition scaling #2',
   [{'rarity': 'epic', 'durability': 3, 'max_durability': 100}, {'shard': 4, 'cloth': 4, 'ingot': 3}],
   {'cloth': 1, 'ingot': 1, 'shard': 1}),
  ('partial repair boundary #1',
   [{'rarity': 'common', 'durability': 20, 'max_durability': 20}, {'shard': 4, 'thread': 2}],
   {'shard': 2, 'thread': 1}),
  ('regression condition scaling #1',
   [{'rarity': 'epic', 'durability': 4, 'max_durability': 7}, {'cloth': 5}],
   {'cloth': 2}),
  ('broken rare #1',
   [{'rarity': 'rare', 'durability': 0, 'max_durability': 40}, {'thread': 2}],
   {'scrap': 1}),
  ('control #1',
   [{'rarity': 'rare', 'durability': 0, 'max_durability': 10}, {'ingot': 5, 'thread': 3}],
   {'scrap': 1}),
  ('control #2', [{'rarity': 'epic', 'durability': 1, 'max_durability': 50}, {'thread': 2}], {'thread': 1})]]
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:
Nearly broken gear salvages as if pristine.

Return rate: common 50%, rare 70%, epic 90%. Condition d/mx with d clamped to mx; max_durability 0 means indestructible (full condition). Durability <= 0 yields {"scrap": 1}. Each component amount = floor(count*pct*d/(100*mx)) computed once; rare and epic items return at least 1 of each component; zero amounts are omitted.

split: open-access