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

N = 1
observations = []
def solve(schema, saved, version, defaults):
    ids=[c['id'] for c in schema]
    if saved.get('version')!=version: return defaults
    order=[]
    for c in saved.get('order',[]):
        if c in ids and c not in order: order.append(c)
    order += [c for c in ids if c not in order]
    hidden=[c for c in order if c in saved.get('hidden',[]) and not next((x for x in schema if x['id']==c),{}).get('required')]
    widths={c:max(1,w) for c,w in saved.get('widths',{}).items() if c in ids and isinstance(w,int) and not isinstance(w,bool)}
    pins={c:p for c,p in saved.get('pins',{}).items() if c in ids and p in ('left','right')}
    return {'order':order,'hidden':hidden,'widths':widths,'pins':pins,'density':saved.get('density') if True else defaults['density'],'page_size':saved.get('page_size') if saved.get('page_size') in (10,25,50) else defaults['page_size']}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('schema evolution', solve([{'id':'a','required':True},{'id':'b'},{'id':'c'}], {'version':2,'order':['b','gone','b'],'hidden':['a','b'],'widths':{'a':1+2,'b':0,'gone':8},'pins':{'a':'right','b':'middle'},'density':'comfortable','page_size':25}, 2, {'density':'normal','page_size':10}), {'order': ['b', 'a', 'c'], 'hidden': ['b'], 'widths': {'a': 3, 'b': 1}, 'pins': {'a': 'right'}, 'density': 'comfortable', 'page_size': 25})
    check('old version', solve([{'id':'a'}], {'version':1}, 2, {'density':'normal','page_size':10}), {'density': 'normal', 'page_size': 10})
    check('missing version', solve([{'id':'a'}], {}, 2, {'density':'normal','page_size':10}), {'density': 'normal', 'page_size': 10})
    check('invalid values', solve([{'id':'a'},{'id':'b'}], {'version':2,'widths':{'a':True,'b':2.5},'density':'wild','page_size':13}, 2, {'density':'normal','page_size':10}), {'order': ['a', 'b'], 'hidden': [], 'widths': {}, 'pins': {}, 'density': 'normal', 'page_size': 10})
    check('negative width', solve([{'id':'a'}], {'version':2,'widths':{'a':-4},'pins':{'a':'left'},'density':'normal','page_size':50}, 2, {'density':'compact','page_size':10}), {'order': ['a'], 'hidden': [], 'widths': {'a': 1}, 'pins': {'a': 'left'}, 'density': 'normal', 'page_size': 50})
    check('empty schema', solve([], {'version':2,'order':['gone'],'hidden':['gone'],'widths':{},'pins':{'gone':'left'},'density':'compact','page_size':10}, 2, {'density':'normal','page_size':25}), {'order': [], 'hidden': [], 'widths': {}, 'pins': {}, 'density': 'compact', 'page_size': 10})

if N == 2:
    check('schema evolution', solve([{'id':'a','required':True},{'id':'b'},{'id':'c'}], {'version':2,'order':['b','gone','b'],'hidden':['a','b'],'widths':{'a':2+2,'b':0,'gone':8},'pins':{'a':'right','b':'middle'},'density':'comfortable','page_size':25}, 2, {'density':'normal','page_size':10}), {'order': ['b', 'a', 'c'], 'hidden': ['b'], 'widths': {'a': 4, 'b': 1}, 'pins': {'a': 'right'}, 'density': 'comfortable', 'page_size': 25})
    check('old version', solve([{'id':'a'}], {'version':1}, 2, {'density':'normal','page_size':10}), {'density': 'normal', 'page_size': 10})
    check('missing version', solve([{'id':'a'}], {}, 2, {'density':'normal','page_size':10}), {'density': 'normal', 'page_size': 10})
    check('invalid values', solve([{'id':'a'},{'id':'b'}], {'version':2,'widths':{'a':True,'b':2.5},'density':'wild','page_size':13}, 2, {'density':'normal','page_size':10}), {'order': ['a', 'b'], 'hidden': [], 'widths': {}, 'pins': {}, 'density': 'normal', 'page_size': 10})
    check('negative width', solve([{'id':'a'}], {'version':2,'widths':{'a':-4},'pins':{'a':'left'},'density':'normal','page_size':50}, 2, {'density':'compact','page_size':10}), {'order': ['a'], 'hidden': [], 'widths': {'a': 1}, 'pins': {'a': 'left'}, 'density': 'normal', 'page_size': 50})
    check('empty schema', solve([], {'version':2,'order':['gone'],'hidden':['gone'],'widths':{},'pins':{'gone':'left'},'density':'compact','page_size':10}, 2, {'density':'normal','page_size':25}), {'order': [], 'hidden': [], 'widths': {}, 'pins': {}, 'density': 'compact', 'page_size': 10})

if N == 3:
    check('schema evolution', solve([{'id':'a','required':True},{'id':'b'},{'id':'c'}], {'version':2,'order':['b','gone','b'],'hidden':['a','b'],'widths':{'a':3+2,'b':0,'gone':8},'pins':{'a':'right','b':'middle'},'density':'comfortable','page_size':25}, 2, {'density':'normal','page_size':10}), {'order': ['b', 'a', 'c'], 'hidden': ['b'], 'widths': {'a': 5, 'b': 1}, 'pins': {'a': 'right'}, 'density': 'comfortable', 'page_size': 25})
    check('old version', solve([{'id':'a'}], {'version':1}, 2, {'density':'normal','page_size':10}), {'density': 'normal', 'page_size': 10})
    check('missing version', solve([{'id':'a'}], {}, 2, {'density':'normal','page_size':10}), {'density': 'normal', 'page_size': 10})
    check('invalid values', solve([{'id':'a'},{'id':'b'}], {'version':2,'widths':{'a':True,'b':2.5},'density':'wild','page_size':13}, 2, {'density':'normal','page_size':10}), {'order': ['a', 'b'], 'hidden': [], 'widths': {}, 'pins': {}, 'density': 'normal', 'page_size': 10})
    check('negative width', solve([{'id':'a'}], {'version':2,'widths':{'a':-4},'pins':{'a':'left'},'density':'normal','page_size':50}, 2, {'density':'compact','page_size':10}), {'order': ['a'], 'hidden': [], 'widths': {'a': 1}, 'pins': {'a': 'left'}, 'density': 'normal', 'page_size': 50})
    check('empty schema', solve([], {'version':2,'order':['gone'],'hidden':['gone'],'widths':{},'pins':{'gone':'left'},'density':'compact','page_size':10}, 2, {'density':'normal','page_size':25}), {'order': [], 'hidden': [], 'widths': {}, 'pins': {}, 'density': 'compact', 'page_size': 10})

if N == 4:
    check('schema evolution', solve([{'id':'a','required':True},{'id':'b'},{'id':'c'}], {'version':2,'order':['b','gone','b'],'hidden':['a','b'],'widths':{'a':4+2,'b':0,'gone':8},'pins':{'a':'right','b':'middle'},'density':'comfortable','page_size':25}, 2, {'density':'normal','page_size':10}), {'order': ['b', 'a', 'c'], 'hidden': ['b'], 'widths': {'a': 6, 'b': 1}, 'pins': {'a': 'right'}, 'density': 'comfortable', 'page_size': 25})
    check('old version', solve([{'id':'a'}], {'version':1}, 2, {'density':'normal','page_size':10}), {'density': 'normal', 'page_size': 10})
    check('missing version', solve([{'id':'a'}], {}, 2, {'density':'normal','page_size':10}), {'density': 'normal', 'page_size': 10})
    check('invalid values', solve([{'id':'a'},{'id':'b'}], {'version':2,'widths':{'a':True,'b':2.5},'density':'wild','page_size':13}, 2, {'density':'normal','page_size':10}), {'order': ['a', 'b'], 'hidden': [], 'widths': {}, 'pins': {}, 'density': 'normal', 'page_size': 10})
    check('negative width', solve([{'id':'a'}], {'version':2,'widths':{'a':-4},'pins':{'a':'left'},'density':'normal','page_size':50}, 2, {'density':'compact','page_size':10}), {'order': ['a'], 'hidden': [], 'widths': {'a': 1}, 'pins': {'a': 'left'}, 'density': 'normal', 'page_size': 50})
    check('empty schema', solve([], {'version':2,'order':['gone'],'hidden':['gone'],'widths':{},'pins':{'gone':'left'},'density':'compact','page_size':10}, 2, {'density':'normal','page_size':25}), {'order': [], 'hidden': [], 'widths': {}, 'pins': {}, 'density': 'compact', 'page_size': 10})

if N == 5:
    check('schema evolution', solve([{'id':'a','required':True},{'id':'b'},{'id':'c'}], {'version':2,'order':['b','gone','b'],'hidden':['a','b'],'widths':{'a':5+2,'b':0,'gone':8},'pins':{'a':'right','b':'middle'},'density':'comfortable','page_size':25}, 2, {'density':'normal','page_size':10}), {'order': ['b', 'a', 'c'], 'hidden': ['b'], 'widths': {'a': 7, 'b': 1}, 'pins': {'a': 'right'}, 'density': 'comfortable', 'page_size': 25})
    check('old version', solve([{'id':'a'}], {'version':1}, 2, {'density':'normal','page_size':10}), {'density': 'normal', 'page_size': 10})
    check('missing version', solve([{'id':'a'}], {}, 2, {'density':'normal','page_size':10}), {'density': 'normal', 'page_size': 10})
    check('invalid values', solve([{'id':'a'},{'id':'b'}], {'version':2,'widths':{'a':True,'b':2.5},'density':'wild','page_size':13}, 2, {'density':'normal','page_size':10}), {'order': ['a', 'b'], 'hidden': [], 'widths': {}, 'pins': {}, 'density': 'normal', 'page_size': 10})
    check('negative width', solve([{'id':'a'}], {'version':2,'widths':{'a':-4},'pins':{'a':'left'},'density':'normal','page_size':50}, 2, {'density':'compact','page_size':10}), {'order': ['a'], 'hidden': [], 'widths': {'a': 1}, 'pins': {'a': 'left'}, 'density': 'normal', 'page_size': 50})
    check('empty schema', solve([], {'version':2,'order':['gone'],'hidden':['gone'],'widths':{},'pins':{'gone':'left'},'density':'compact','page_size':10}, 2, {'density':'normal','page_size':25}), {'order': [], 'hidden': [], 'widths': {}, 'pins': {}, 'density': 'compact', 'page_size': 10})

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(schema, saved, version, defaults):
    ids=[c['id'] for c in schema]
    if saved.get('version')!=version: return defaults
    order=[]
    for c in saved.get('order',[]):
        if c in ids and c not in order: order.append(c)
    order += [c for c in ids if c not in order]
    hidden=[c for c in order if c in saved.get('hidden',[]) and not next((x for x in schema if x['id']==c),{}).get('required')]
    widths={c:max(1,w) for c,w in saved.get('widths',{}).items() if c in ids and isinstance(w,int) and not isinstance(w,bool)}
    pins={c:p for c,p in saved.get('pins',{}).items() if c in ids and p in ('left','right')}
    return {'order':order,'hidden':hidden,'widths':widths,'pins':pins,'density':saved.get('density') if saved.get('density')=='compact' else defaults['density'],'page_size':saved.get('page_size') if saved.get('page_size') in (10,25,50) else defaults['page_size']}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('schema evolution', solve([{'id':'a','required':True},{'id':'b'},{'id':'c'}], {'version':2,'order':['b','gone','b'],'hidden':['a','b'],'widths':{'a':1+2,'b':0,'gone':8},'pins':{'a':'right','b':'middle'},'density':'comfortable','page_size':25}, 2, {'density':'normal','page_size':10}), {'order': ['b', 'a', 'c'], 'hidden': ['b'], 'widths': {'a': 3, 'b': 1}, 'pins': {'a': 'right'}, 'density': 'comfortable', 'page_size': 25})
    check('old version', solve([{'id':'a'}], {'version':1}, 2, {'density':'normal','page_size':10}), {'density': 'normal', 'page_size': 10})
    check('missing version', solve([{'id':'a'}], {}, 2, {'density':'normal','page_size':10}), {'density': 'normal', 'page_size': 10})
    check('invalid values', solve([{'id':'a'},{'id':'b'}], {'version':2,'widths':{'a':True,'b':2.5},'density':'wild','page_size':13}, 2, {'density':'normal','page_size':10}), {'order': ['a', 'b'], 'hidden': [], 'widths': {}, 'pins': {}, 'density': 'normal', 'page_size': 10})
    check('negative width', solve([{'id':'a'}], {'version':2,'widths':{'a':-4},'pins':{'a':'left'},'density':'normal','page_size':50}, 2, {'density':'compact','page_size':10}), {'order': ['a'], 'hidden': [], 'widths': {'a': 1}, 'pins': {'a': 'left'}, 'density': 'normal', 'page_size': 50})
    check('empty schema', solve([], {'version':2,'order':['gone'],'hidden':['gone'],'widths':{},'pins':{'gone':'left'},'density':'compact','page_size':10}, 2, {'density':'normal','page_size':25}), {'order': [], 'hidden': [], 'widths': {}, 'pins': {}, 'density': 'compact', 'page_size': 10})

if N == 2:
    check('schema evolution', solve([{'id':'a','required':True},{'id':'b'},{'id':'c'}], {'version':2,'order':['b','gone','b'],'hidden':['a','b'],'widths':{'a':2+2,'b':0,'gone':8},'pins':{'a':'right','b':'middle'},'density':'comfortable','page_size':25}, 2, {'density':'normal','page_size':10}), {'order': ['b', 'a', 'c'], 'hidden': ['b'], 'widths': {'a': 4, 'b': 1}, 'pins': {'a': 'right'}, 'density': 'comfortable', 'page_size': 25})
    check('old version', solve([{'id':'a'}], {'version':1}, 2, {'density':'normal','page_size':10}), {'density': 'normal', 'page_size': 10})
    check('missing version', solve([{'id':'a'}], {}, 2, {'density':'normal','page_size':10}), {'density': 'normal', 'page_size': 10})
    check('invalid values', solve([{'id':'a'},{'id':'b'}], {'version':2,'widths':{'a':True,'b':2.5},'density':'wild','page_size':13}, 2, {'density':'normal','page_size':10}), {'order': ['a', 'b'], 'hidden': [], 'widths': {}, 'pins': {}, 'density': 'normal', 'page_size': 10})
    check('negative width', solve([{'id':'a'}], {'version':2,'widths':{'a':-4},'pins':{'a':'left'},'density':'normal','page_size':50}, 2, {'density':'compact','page_size':10}), {'order': ['a'], 'hidden': [], 'widths': {'a': 1}, 'pins': {'a': 'left'}, 'density': 'normal', 'page_size': 50})
    check('empty schema', solve([], {'version':2,'order':['gone'],'hidden':['gone'],'widths':{},'pins':{'gone':'left'},'density':'compact','page_size':10}, 2, {'density':'normal','page_size':25}), {'order': [], 'hidden': [], 'widths': {}, 'pins': {}, 'density': 'compact', 'page_size': 10})

if N == 3:
    check('schema evolution', solve([{'id':'a','required':True},{'id':'b'},{'id':'c'}], {'version':2,'order':['b','gone','b'],'hidden':['a','b'],'widths':{'a':3+2,'b':0,'gone':8},'pins':{'a':'right','b':'middle'},'density':'comfortable','page_size':25}, 2, {'density':'normal','page_size':10}), {'order': ['b', 'a', 'c'], 'hidden': ['b'], 'widths': {'a': 5, 'b': 1}, 'pins': {'a': 'right'}, 'density': 'comfortable', 'page_size': 25})
    check('old version', solve([{'id':'a'}], {'version':1}, 2, {'density':'normal','page_size':10}), {'density': 'normal', 'page_size': 10})
    check('missing version', solve([{'id':'a'}], {}, 2, {'density':'normal','page_size':10}), {'density': 'normal', 'page_size': 10})
    check('invalid values', solve([{'id':'a'},{'id':'b'}], {'version':2,'widths':{'a':True,'b':2.5},'density':'wild','page_size':13}, 2, {'density':'normal','page_size':10}), {'order': ['a', 'b'], 'hidden': [], 'widths': {}, 'pins': {}, 'density': 'normal', 'page_size': 10})
    check('negative width', solve([{'id':'a'}], {'version':2,'widths':{'a':-4},'pins':{'a':'left'},'density':'normal','page_size':50}, 2, {'density':'compact','page_size':10}), {'order': ['a'], 'hidden': [], 'widths': {'a': 1}, 'pins': {'a': 'left'}, 'density': 'normal', 'page_size': 50})
    check('empty schema', solve([], {'version':2,'order':['gone'],'hidden':['gone'],'widths':{},'pins':{'gone':'left'},'density':'compact','page_size':10}, 2, {'density':'normal','page_size':25}), {'order': [], 'hidden': [], 'widths': {}, 'pins': {}, 'density': 'compact', 'page_size': 10})

if N == 4:
    check('schema evolution', solve([{'id':'a','required':True},{'id':'b'},{'id':'c'}], {'version':2,'order':['b','gone','b'],'hidden':['a','b'],'widths':{'a':4+2,'b':0,'gone':8},'pins':{'a':'right','b':'middle'},'density':'comfortable','page_size':25}, 2, {'density':'normal','page_size':10}), {'order': ['b', 'a', 'c'], 'hidden': ['b'], 'widths': {'a': 6, 'b': 1}, 'pins': {'a': 'right'}, 'density': 'comfortable', 'page_size': 25})
    check('old version', solve([{'id':'a'}], {'version':1}, 2, {'density':'normal','page_size':10}), {'density': 'normal', 'page_size': 10})
    check('missing version', solve([{'id':'a'}], {}, 2, {'density':'normal','page_size':10}), {'density': 'normal', 'page_size': 10})
    check('invalid values', solve([{'id':'a'},{'id':'b'}], {'version':2,'widths':{'a':True,'b':2.5},'density':'wild','page_size':13}, 2, {'density':'normal','page_size':10}), {'order': ['a', 'b'], 'hidden': [], 'widths': {}, 'pins': {}, 'density': 'normal', 'page_size': 10})
    check('negative width', solve([{'id':'a'}], {'version':2,'widths':{'a':-4},'pins':{'a':'left'},'density':'normal','page_size':50}, 2, {'density':'compact','page_size':10}), {'order': ['a'], 'hidden': [], 'widths': {'a': 1}, 'pins': {'a': 'left'}, 'density': 'normal', 'page_size': 50})
    check('empty schema', solve([], {'version':2,'order':['gone'],'hidden':['gone'],'widths':{},'pins':{'gone':'left'},'density':'compact','page_size':10}, 2, {'density':'normal','page_size':25}), {'order': [], 'hidden': [], 'widths': {}, 'pins': {}, 'density': 'compact', 'page_size': 10})

if N == 5:
    check('schema evolution', solve([{'id':'a','required':True},{'id':'b'},{'id':'c'}], {'version':2,'order':['b','gone','b'],'hidden':['a','b'],'widths':{'a':5+2,'b':0,'gone':8},'pins':{'a':'right','b':'middle'},'density':'comfortable','page_size':25}, 2, {'density':'normal','page_size':10}), {'order': ['b', 'a', 'c'], 'hidden': ['b'], 'widths': {'a': 7, 'b': 1}, 'pins': {'a': 'right'}, 'density': 'comfortable', 'page_size': 25})
    check('old version', solve([{'id':'a'}], {'version':1}, 2, {'density':'normal','page_size':10}), {'density': 'normal', 'page_size': 10})
    check('missing version', solve([{'id':'a'}], {}, 2, {'density':'normal','page_size':10}), {'density': 'normal', 'page_size': 10})
    check('invalid values', solve([{'id':'a'},{'id':'b'}], {'version':2,'widths':{'a':True,'b':2.5},'density':'wild','page_size':13}, 2, {'density':'normal','page_size':10}), {'order': ['a', 'b'], 'hidden': [], 'widths': {}, 'pins': {}, 'density': 'normal', 'page_size': 10})
    check('negative width', solve([{'id':'a'}], {'version':2,'widths':{'a':-4},'pins':{'a':'left'},'density':'normal','page_size':50}, 2, {'density':'compact','page_size':10}), {'order': ['a'], 'hidden': [], 'widths': {'a': 1}, 'pins': {'a': 'left'}, 'density': 'normal', 'page_size': 50})
    check('empty schema', solve([], {'version':2,'order':['gone'],'hidden':['gone'],'widths':{},'pins':{'gone':'left'},'density':'compact','page_size':10}, 2, {'density':'normal','page_size':25}), {'order': [], 'hidden': [], 'widths': {}, 'pins': {}, 'density': 'compact', 'page_size': 10})

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:
The table density enum result violates the stipulated saved table view restoration contract.

Restore a table view only at matching schema version; deduplicate known order, append new schema columns, keep required columns visible, accept positive-clamped integer nonboolean widths, validate pin sides/density/page-size enums, and ignore removed columns.

split: open-access


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

N = 1
observations = []
def solve(schema, saved, version, defaults):
    ids=[c['id'] for c in schema]
    if saved.get('version')!=version: return defaults
    order=[]
    for c in saved.get('order',[]):
        if c in ids and c not in order: order.append(c)
    order += [c for c in ids if c not in order]
    hidden=[c for c in order if c in saved.get('hidden',[]) and not next((x for x in schema if x['id']==c),{}).get('required')]
    widths={c:max(1,w) for c,w in saved.get('widths',{}).items() if c in ids and isinstance(w,int) and not isinstance(w,bool)}
    pins={c:p for c,p in saved.get('pins',{}).items() if c in ids and p in ('left','right')}
    return {'order':order,'hidden':hidden,'widths':widths,'pins':pins,'density':saved.get('density') if saved.get('density') in ('compact','normal','comfortable') else defaults['density'],'page_size':saved.get('page_size') if True else defaults['page_size']}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('schema evolution', solve([{'id':'a','required':True},{'id':'b'},{'id':'c'}], {'version':2,'order':['b','gone','b'],'hidden':['a','b'],'widths':{'a':1+2,'b':0,'gone':8},'pins':{'a':'right','b':'middle'},'density':'comfortable','page_size':25}, 2, {'density':'normal','page_size':10}), {'order': ['b', 'a', 'c'], 'hidden': ['b'], 'widths': {'a': 3, 'b': 1}, 'pins': {'a': 'right'}, 'density': 'comfortable', 'page_size': 25})
    check('old version', solve([{'id':'a'}], {'version':1}, 2, {'density':'normal','page_size':10}), {'density': 'normal', 'page_size': 10})
    check('missing version', solve([{'id':'a'}], {}, 2, {'density':'normal','page_size':10}), {'density': 'normal', 'page_size': 10})
    check('invalid values', solve([{'id':'a'},{'id':'b'}], {'version':2,'widths':{'a':True,'b':2.5},'density':'wild','page_size':13}, 2, {'density':'normal','page_size':10}), {'order': ['a', 'b'], 'hidden': [], 'widths': {}, 'pins': {}, 'density': 'normal', 'page_size': 10})
    check('negative width', solve([{'id':'a'}], {'version':2,'widths':{'a':-4},'pins':{'a':'left'},'density':'normal','page_size':50}, 2, {'density':'compact','page_size':10}), {'order': ['a'], 'hidden': [], 'widths': {'a': 1}, 'pins': {'a': 'left'}, 'density': 'normal', 'page_size': 50})
    check('empty schema', solve([], {'version':2,'order':['gone'],'hidden':['gone'],'widths':{},'pins':{'gone':'left'},'density':'compact','page_size':10}, 2, {'density':'normal','page_size':25}), {'order': [], 'hidden': [], 'widths': {}, 'pins': {}, 'density': 'compact', 'page_size': 10})

if N == 2:
    check('schema evolution', solve([{'id':'a','required':True},{'id':'b'},{'id':'c'}], {'version':2,'order':['b','gone','b'],'hidden':['a','b'],'widths':{'a':2+2,'b':0,'gone':8},'pins':{'a':'right','b':'middle'},'density':'comfortable','page_size':25}, 2, {'density':'normal','page_size':10}), {'order': ['b', 'a', 'c'], 'hidden': ['b'], 'widths': {'a': 4, 'b': 1}, 'pins': {'a': 'right'}, 'density': 'comfortable', 'page_size': 25})
    check('old version', solve([{'id':'a'}], {'version':1}, 2, {'density':'normal','page_size':10}), {'density': 'normal', 'page_size': 10})
    check('missing version', solve([{'id':'a'}], {}, 2, {'density':'normal','page_size':10}), {'density': 'normal', 'page_size': 10})
    check('invalid values', solve([{'id':'a'},{'id':'b'}], {'version':2,'widths':{'a':True,'b':2.5},'density':'wild','page_size':13}, 2, {'density':'normal','page_size':10}), {'order': ['a', 'b'], 'hidden': [], 'widths': {}, 'pins': {}, 'density': 'normal', 'page_size': 10})
    check('negative width', solve([{'id':'a'}], {'version':2,'widths':{'a':-4},'pins':{'a':'left'},'density':'normal','page_size':50}, 2, {'density':'compact','page_size':10}), {'order': ['a'], 'hidden': [], 'widths': {'a': 1}, 'pins': {'a': 'left'}, 'density': 'normal', 'page_size': 50})
    check('empty schema', solve([], {'version':2,'order':['gone'],'hidden':['gone'],'widths':{},'pins':{'gone':'left'},'density':'compact','page_size':10}, 2, {'density':'normal','page_size':25}), {'order': [], 'hidden': [], 'widths': {}, 'pins': {}, 'density': 'compact', 'page_size': 10})

if N == 3:
    check('schema evolution', solve([{'id':'a','required':True},{'id':'b'},{'id':'c'}], {'version':2,'order':['b','gone','b'],'hidden':['a','b'],'widths':{'a':3+2,'b':0,'gone':8},'pins':{'a':'right','b':'middle'},'density':'comfortable','page_size':25}, 2, {'density':'normal','page_size':10}), {'order': ['b', 'a', 'c'], 'hidden': ['b'], 'widths': {'a': 5, 'b': 1}, 'pins': {'a': 'right'}, 'density': 'comfortable', 'page_size': 25})
    check('old version', solve([{'id':'a'}], {'version':1}, 2, {'density':'normal','page_size':10}), {'density': 'normal', 'page_size': 10})
    check('missing version', solve([{'id':'a'}], {}, 2, {'density':'normal','page_size':10}), {'density': 'normal', 'page_size': 10})
    check('invalid values', solve([{'id':'a'},{'id':'b'}], {'version':2,'widths':{'a':True,'b':2.5},'density':'wild','page_size':13}, 2, {'density':'normal','page_size':10}), {'order': ['a', 'b'], 'hidden': [], 'widths': {}, 'pins': {}, 'density': 'normal', 'page_size': 10})
    check('negative width', solve([{'id':'a'}], {'version':2,'widths':{'a':-4},'pins':{'a':'left'},'density':'normal','page_size':50}, 2, {'density':'compact','page_size':10}), {'order': ['a'], 'hidden': [], 'widths': {'a': 1}, 'pins': {'a': 'left'}, 'density': 'normal', 'page_size': 50})
    check('empty schema', solve([], {'version':2,'order':['gone'],'hidden':['gone'],'widths':{},'pins':{'gone':'left'},'density':'compact','page_size':10}, 2, {'density':'normal','page_size':25}), {'order': [], 'hidden': [], 'widths': {}, 'pins': {}, 'density': 'compact', 'page_size': 10})

if N == 4:
    check('schema evolution', solve([{'id':'a','required':True},{'id':'b'},{'id':'c'}], {'version':2,'order':['b','gone','b'],'hidden':['a','b'],'widths':{'a':4+2,'b':0,'gone':8},'pins':{'a':'right','b':'middle'},'density':'comfortable','page_size':25}, 2, {'density':'normal','page_size':10}), {'order': ['b', 'a', 'c'], 'hidden': ['b'], 'widths': {'a': 6, 'b': 1}, 'pins': {'a': 'right'}, 'density': 'comfortable', 'page_size': 25})
    check('old version', solve([{'id':'a'}], {'version':1}, 2, {'density':'normal','page_size':10}), {'density': 'normal', 'page_size': 10})
    check('missing version', solve([{'id':'a'}], {}, 2, {'density':'normal','page_size':10}), {'density': 'normal', 'page_size': 10})
    check('invalid values', solve([{'id':'a'},{'id':'b'}], {'version':2,'widths':{'a':True,'b':2.5},'density':'wild','page_size':13}, 2, {'density':'normal','page_size':10}), {'order': ['a', 'b'], 'hidden': [], 'widths': {}, 'pins': {}, 'density': 'normal', 'page_size': 10})
    check('negative width', solve([{'id':'a'}], {'version':2,'widths':{'a':-4},'pins':{'a':'left'},'density':'normal','page_size':50}, 2, {'density':'compact','page_size':10}), {'order': ['a'], 'hidden': [], 'widths': {'a': 1}, 'pins': {'a': 'left'}, 'density': 'normal', 'page_size': 50})
    check('empty schema', solve([], {'version':2,'order':['gone'],'hidden':['gone'],'widths':{},'pins':{'gone':'left'},'density':'compact','page_size':10}, 2, {'density':'normal','page_size':25}), {'order': [], 'hidden': [], 'widths': {}, 'pins': {}, 'density': 'compact', 'page_size': 10})

if N == 5:
    check('schema evolution', solve([{'id':'a','required':True},{'id':'b'},{'id':'c'}], {'version':2,'order':['b','gone','b'],'hidden':['a','b'],'widths':{'a':5+2,'b':0,'gone':8},'pins':{'a':'right','b':'middle'},'density':'comfortable','page_size':25}, 2, {'density':'normal','page_size':10}), {'order': ['b', 'a', 'c'], 'hidden': ['b'], 'widths': {'a': 7, 'b': 1}, 'pins': {'a': 'right'}, 'density': 'comfortable', 'page_size': 25})
    check('old version', solve([{'id':'a'}], {'version':1}, 2, {'density':'normal','page_size':10}), {'density': 'normal', 'page_size': 10})
    check('missing version', solve([{'id':'a'}], {}, 2, {'density':'normal','page_size':10}), {'density': 'normal', 'page_size': 10})
    check('invalid values', solve([{'id':'a'},{'id':'b'}], {'version':2,'widths':{'a':True,'b':2.5},'density':'wild','page_size':13}, 2, {'density':'normal','page_size':10}), {'order': ['a', 'b'], 'hidden': [], 'widths': {}, 'pins': {}, 'density': 'normal', 'page_size': 10})
    check('negative width', solve([{'id':'a'}], {'version':2,'widths':{'a':-4},'pins':{'a':'left'},'density':'normal','page_size':50}, 2, {'density':'compact','page_size':10}), {'order': ['a'], 'hidden': [], 'widths': {'a': 1}, 'pins': {'a': 'left'}, 'density': 'normal', 'page_size': 50})
    check('empty schema', solve([], {'version':2,'order':['gone'],'hidden':['gone'],'widths':{},'pins':{'gone':'left'},'density':'compact','page_size':10}, 2, {'density':'normal','page_size':25}), {'order': [], 'hidden': [], 'widths': {}, 'pins': {}, 'density': 'compact', 'page_size': 10})

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(schema, saved, version, defaults):
    ids=[c['id'] for c in schema]
    if saved.get('version')!=version: return defaults
    order=[]
    for c in saved.get('order',[]):
        if c in ids and c not in order: order.append(c)
    order += [c for c in ids if c not in order]
    hidden=[c for c in order if c in saved.get('hidden',[]) and not next((x for x in schema if x['id']==c),{}).get('required')]
    widths={c:max(1,w) for c,w in saved.get('widths',{}).items() if c in ids and isinstance(w,int) and not isinstance(w,bool)}
    pins={c:p for c,p in saved.get('pins',{}).items() if c in ids and p in ('left','right')}
    return {'order':order,'hidden':hidden,'widths':widths,'pins':pins,'density':saved.get('density') if saved.get('density') in ('compact','normal','comfortable') else defaults['density'],'page_size':saved.get('page_size') if saved.get('page_size')==10 else defaults['page_size']}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('schema evolution', solve([{'id':'a','required':True},{'id':'b'},{'id':'c'}], {'version':2,'order':['b','gone','b'],'hidden':['a','b'],'widths':{'a':1+2,'b':0,'gone':8},'pins':{'a':'right','b':'middle'},'density':'comfortable','page_size':25}, 2, {'density':'normal','page_size':10}), {'order': ['b', 'a', 'c'], 'hidden': ['b'], 'widths': {'a': 3, 'b': 1}, 'pins': {'a': 'right'}, 'density': 'comfortable', 'page_size': 25})
    check('old version', solve([{'id':'a'}], {'version':1}, 2, {'density':'normal','page_size':10}), {'density': 'normal', 'page_size': 10})
    check('missing version', solve([{'id':'a'}], {}, 2, {'density':'normal','page_size':10}), {'density': 'normal', 'page_size': 10})
    check('invalid values', solve([{'id':'a'},{'id':'b'}], {'version':2,'widths':{'a':True,'b':2.5},'density':'wild','page_size':13}, 2, {'density':'normal','page_size':10}), {'order': ['a', 'b'], 'hidden': [], 'widths': {}, 'pins': {}, 'density': 'normal', 'page_size': 10})
    check('negative width', solve([{'id':'a'}], {'version':2,'widths':{'a':-4},'pins':{'a':'left'},'density':'normal','page_size':50}, 2, {'density':'compact','page_size':10}), {'order': ['a'], 'hidden': [], 'widths': {'a': 1}, 'pins': {'a': 'left'}, 'density': 'normal', 'page_size': 50})
    check('empty schema', solve([], {'version':2,'order':['gone'],'hidden':['gone'],'widths':{},'pins':{'gone':'left'},'density':'compact','page_size':10}, 2, {'density':'normal','page_size':25}), {'order': [], 'hidden': [], 'widths': {}, 'pins': {}, 'density': 'compact', 'page_size': 10})

if N == 2:
    check('schema evolution', solve([{'id':'a','required':True},{'id':'b'},{'id':'c'}], {'version':2,'order':['b','gone','b'],'hidden':['a','b'],'widths':{'a':2+2,'b':0,'gone':8},'pins':{'a':'right','b':'middle'},'density':'comfortable','page_size':25}, 2, {'density':'normal','page_size':10}), {'order': ['b', 'a', 'c'], 'hidden': ['b'], 'widths': {'a': 4, 'b': 1}, 'pins': {'a': 'right'}, 'density': 'comfortable', 'page_size': 25})
    check('old version', solve([{'id':'a'}], {'version':1}, 2, {'density':'normal','page_size':10}), {'density': 'normal', 'page_size': 10})
    check('missing version', solve([{'id':'a'}], {}, 2, {'density':'normal','page_size':10}), {'density': 'normal', 'page_size': 10})
    check('invalid values', solve([{'id':'a'},{'id':'b'}], {'version':2,'widths':{'a':True,'b':2.5},'density':'wild','page_size':13}, 2, {'density':'normal','page_size':10}), {'order': ['a', 'b'], 'hidden': [], 'widths': {}, 'pins': {}, 'density': 'normal', 'page_size': 10})
    check('negative width', solve([{'id':'a'}], {'version':2,'widths':{'a':-4},'pins':{'a':'left'},'density':'normal','page_size':50}, 2, {'density':'compact','page_size':10}), {'order': ['a'], 'hidden': [], 'widths': {'a': 1}, 'pins': {'a': 'left'}, 'density': 'normal', 'page_size': 50})
    check('empty schema', solve([], {'version':2,'order':['gone'],'hidden':['gone'],'widths':{},'pins':{'gone':'left'},'density':'compact','page_size':10}, 2, {'density':'normal','page_size':25}), {'order': [], 'hidden': [], 'widths': {}, 'pins': {}, 'density': 'compact', 'page_size': 10})

if N == 3:
    check('schema evolution', solve([{'id':'a','required':True},{'id':'b'},{'id':'c'}], {'version':2,'order':['b','gone','b'],'hidden':['a','b'],'widths':{'a':3+2,'b':0,'gone':8},'pins':{'a':'right','b':'middle'},'density':'comfortable','page_size':25}, 2, {'density':'normal','page_size':10}), {'order': ['b', 'a', 'c'], 'hidden': ['b'], 'widths': {'a': 5, 'b': 1}, 'pins': {'a': 'right'}, 'density': 'comfortable', 'page_size': 25})
    check('old version', solve([{'id':'a'}], {'version':1}, 2, {'density':'normal','page_size':10}), {'density': 'normal', 'page_size': 10})
    check('missing version', solve([{'id':'a'}], {}, 2, {'density':'normal','page_size':10}), {'density': 'normal', 'page_size': 10})
    check('invalid values', solve([{'id':'a'},{'id':'b'}], {'version':2,'widths':{'a':True,'b':2.5},'density':'wild','page_size':13}, 2, {'density':'normal','page_size':10}), {'order': ['a', 'b'], 'hidden': [], 'widths': {}, 'pins': {}, 'density': 'normal', 'page_size': 10})
    check('negative width', solve([{'id':'a'}], {'version':2,'widths':{'a':-4},'pins':{'a':'left'},'density':'normal','page_size':50}, 2, {'density':'compact','page_size':10}), {'order': ['a'], 'hidden': [], 'widths': {'a': 1}, 'pins': {'a': 'left'}, 'density': 'normal', 'page_size': 50})
    check('empty schema', solve([], {'version':2,'order':['gone'],'hidden':['gone'],'widths':{},'pins':{'gone':'left'},'density':'compact','page_size':10}, 2, {'density':'normal','page_size':25}), {'order': [], 'hidden': [], 'widths': {}, 'pins': {}, 'density': 'compact', 'page_size': 10})

if N == 4:
    check('schema evolution', solve([{'id':'a','required':True},{'id':'b'},{'id':'c'}], {'version':2,'order':['b','gone','b'],'hidden':['a','b'],'widths':{'a':4+2,'b':0,'gone':8},'pins':{'a':'right','b':'middle'},'density':'comfortable','page_size':25}, 2, {'density':'normal','page_size':10}), {'order': ['b', 'a', 'c'], 'hidden': ['b'], 'widths': {'a': 6, 'b': 1}, 'pins': {'a': 'right'}, 'density': 'comfortable', 'page_size': 25})
    check('old version', solve([{'id':'a'}], {'version':1}, 2, {'density':'normal','page_size':10}), {'density': 'normal', 'page_size': 10})
    check('missing version', solve([{'id':'a'}], {}, 2, {'density':'normal','page_size':10}), {'density': 'normal', 'page_size': 10})
    check('invalid values', solve([{'id':'a'},{'id':'b'}], {'version':2,'widths':{'a':True,'b':2.5},'density':'wild','page_size':13}, 2, {'density':'normal','page_size':10}), {'order': ['a', 'b'], 'hidden': [], 'widths': {}, 'pins': {}, 'density': 'normal', 'page_size': 10})
    check('negative width', solve([{'id':'a'}], {'version':2,'widths':{'a':-4},'pins':{'a':'left'},'density':'normal','page_size':50}, 2, {'density':'compact','page_size':10}), {'order': ['a'], 'hidden': [], 'widths': {'a': 1}, 'pins': {'a': 'left'}, 'density': 'normal', 'page_size': 50})
    check('empty schema', solve([], {'version':2,'order':['gone'],'hidden':['gone'],'widths':{},'pins':{'gone':'left'},'density':'compact','page_size':10}, 2, {'density':'normal','page_size':25}), {'order': [], 'hidden': [], 'widths': {}, 'pins': {}, 'density': 'compact', 'page_size': 10})

if N == 5:
    check('schema evolution', solve([{'id':'a','required':True},{'id':'b'},{'id':'c'}], {'version':2,'order':['b','gone','b'],'hidden':['a','b'],'widths':{'a':5+2,'b':0,'gone':8},'pins':{'a':'right','b':'middle'},'density':'comfortable','page_size':25}, 2, {'density':'normal','page_size':10}), {'order': ['b', 'a', 'c'], 'hidden': ['b'], 'widths': {'a': 7, 'b': 1}, 'pins': {'a': 'right'}, 'density': 'comfortable', 'page_size': 25})
    check('old version', solve([{'id':'a'}], {'version':1}, 2, {'density':'normal','page_size':10}), {'density': 'normal', 'page_size': 10})
    check('missing version', solve([{'id':'a'}], {}, 2, {'density':'normal','page_size':10}), {'density': 'normal', 'page_size': 10})
    check('invalid values', solve([{'id':'a'},{'id':'b'}], {'version':2,'widths':{'a':True,'b':2.5},'density':'wild','page_size':13}, 2, {'density':'normal','page_size':10}), {'order': ['a', 'b'], 'hidden': [], 'widths': {}, 'pins': {}, 'density': 'normal', 'page_size': 10})
    check('negative width', solve([{'id':'a'}], {'version':2,'widths':{'a':-4},'pins':{'a':'left'},'density':'normal','page_size':50}, 2, {'density':'compact','page_size':10}), {'order': ['a'], 'hidden': [], 'widths': {'a': 1}, 'pins': {'a': 'left'}, 'density': 'normal', 'page_size': 50})
    check('empty schema', solve([], {'version':2,'order':['gone'],'hidden':['gone'],'widths':{},'pins':{'gone':'left'},'density':'compact','page_size':10}, 2, {'density':'normal','page_size':25}), {'order': [], 'hidden': [], 'widths': {}, 'pins': {}, 'density': 'compact', 'page_size': 10})

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:
The table page size enum result violates the stipulated saved table view restoration contract.

Restore a table view only at matching schema version; deduplicate known order, append new schema columns, keep required columns visible, accept positive-clamped integer nonboolean widths, validate pin sides/density/page-size enums, and ignore removed columns.

split: open-access


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

N = 1
observations = []
def solve(rows, header, footer, page_height, repeat, keep_detail):
    capacity=page_height-header
    if capacity<=0: return {'error':'no-body-space','pages':[]}
    pages=[]; page=[]; used=0
    for row in rows:
        h=row['height']+(row.get('detail_height',0) if keep_detail else 0)
        if page and used+h>capacity:
            pages.append(page); page=[]; used=0
        page.append({'id':row['id'],'height':h,'overflow':h>capacity})
        used+=h
    if page: pages.append(page)
    return {'error':None,'pages':[{'number':i+1,'header':repeat or i==0,'footer':True,'rows':p,'used':sum(r['height'] for r in p),'body_limit':capacity} for i,p in enumerate(pages)]}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('exactly filled body', solve([{'id':'a','height':3},{'id':'b','height':4},{'id':'c','height':1+1},{'id':'d','height':2}], 2, 1, 10, False, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 3, 'overflow': False}, {'id': 'b', 'height': 4, 'overflow': False}], 'used': 7, 'body_limit': 7}, {'number': 2, 'header': False, 'footer': True, 'rows': [{'id': 'c', 'height': 2, 'overflow': False}, {'id': 'd', 'height': 2, 'overflow': False}], 'used': 4, 'body_limit': 7}]})
    check('oversized row', solve([{'id':'a','height':11},{'id':'b','height':2}], 2, 1, 10, True, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 11, 'overflow': True}], 'used': 11, 'body_limit': 7}, {'number': 2, 'header': True, 'footer': True, 'rows': [{'id': 'b', 'height': 2, 'overflow': False}], 'used': 2, 'body_limit': 7}]})
    check('detail blocks', solve([{'id':'a','height':3,'detail_height':4},{'id':'b','height':3,'detail_height':4}], 2, 1, 10, True, True), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 7, 'overflow': False}], 'used': 7, 'body_limit': 7}, {'number': 2, 'header': True, 'footer': True, 'rows': [{'id': 'b', 'height': 7, 'overflow': False}], 'used': 7, 'body_limit': 7}]})
    check('detail excluded', solve([{'id':'a','height':3,'detail_height':4},{'id':'b','height':3,'detail_height':4}], 2, 1, 10, True, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 3, 'overflow': False}, {'id': 'b', 'height': 3, 'overflow': False}], 'used': 6, 'body_limit': 7}]})
    check('zero body', solve([{'id':'a','height':1}], 2, 1, 3, True, False), {'error': 'no-body-space', 'pages': []})
    check('negative body', solve([], 2, 2, 3, False, False), {'error': 'no-body-space', 'pages': []})
    check('nonexact overflow', solve([{'id':'a','height':4},{'id':'b','height':4},{'id':'c','height':3}], 2, 1, 10, False, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 4, 'overflow': False}], 'used': 4, 'body_limit': 7}, {'number': 2, 'header': False, 'footer': True, 'rows': [{'id': 'b', 'height': 4, 'overflow': False}, {'id': 'c', 'height': 3, 'overflow': False}], 'used': 7, 'body_limit': 7}]})
    check('reset capacity', solve([{'id':'a','height':3},{'id':'b','height':5},{'id':'c','height':2}], 2, 1, 10, False, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 3, 'overflow': False}], 'used': 3, 'body_limit': 7}, {'number': 2, 'header': False, 'footer': True, 'rows': [{'id': 'b', 'height': 5, 'overflow': False}, {'id': 'c', 'height': 2, 'overflow': False}], 'used': 7, 'body_limit': 7}]})
    check('empty print', solve([], 2, 1, 10, False, False), {'error': None, 'pages': []})

if N == 2:
    check('exactly filled body', solve([{'id':'a','height':3},{'id':'b','height':4},{'id':'c','height':2+1},{'id':'d','height':2}], 2, 1, 10, False, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 3, 'overflow': False}, {'id': 'b', 'height': 4, 'overflow': False}], 'used': 7, 'body_limit': 7}, {'number': 2, 'header': False, 'footer': True, 'rows': [{'id': 'c', 'height': 3, 'overflow': False}, {'id': 'd', 'height': 2, 'overflow': False}], 'used': 5, 'body_limit': 7}]})
    check('oversized row', solve([{'id':'a','height':11},{'id':'b','height':2}], 2, 1, 10, True, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 11, 'overflow': True}], 'used': 11, 'body_limit': 7}, {'number': 2, 'header': True, 'footer': True, 'rows': [{'id': 'b', 'height': 2, 'overflow': False}], 'used': 2, 'body_limit': 7}]})
    check('detail blocks', solve([{'id':'a','height':3,'detail_height':4},{'id':'b','height':3,'detail_height':4}], 2, 1, 10, True, True), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 7, 'overflow': False}], 'used': 7, 'body_limit': 7}, {'number': 2, 'header': True, 'footer': True, 'rows': [{'id': 'b', 'height': 7, 'overflow': False}], 'used': 7, 'body_limit': 7}]})
    check('detail excluded', solve([{'id':'a','height':3,'detail_height':4},{'id':'b','height':3,'detail_height':4}], 2, 1, 10, True, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 3, 'overflow': False}, {'id': 'b', 'height': 3, 'overflow': False}], 'used': 6, 'body_limit': 7}]})
    check('zero body', solve([{'id':'a','height':1}], 2, 1, 3, True, False), {'error': 'no-body-space', 'pages': []})
    check('negative body', solve([], 2, 2, 3, False, False), {'error': 'no-body-space', 'pages': []})
    check('nonexact overflow', solve([{'id':'a','height':4},{'id':'b','height':4},{'id':'c','height':3}], 2, 1, 10, False, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 4, 'overflow': False}], 'used': 4, 'body_limit': 7}, {'number': 2, 'header': False, 'footer': True, 'rows': [{'id': 'b', 'height': 4, 'overflow': False}, {'id': 'c', 'height': 3, 'overflow': False}], 'used': 7, 'body_limit': 7}]})
    check('reset capacity', solve([{'id':'a','height':3},{'id':'b','height':5},{'id':'c','height':2}], 2, 1, 10, False, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 3, 'overflow': False}], 'used': 3, 'body_limit': 7}, {'number': 2, 'header': False, 'footer': True, 'rows': [{'id': 'b', 'height': 5, 'overflow': False}, {'id': 'c', 'height': 2, 'overflow': False}], 'used': 7, 'body_limit': 7}]})
    check('empty print', solve([], 2, 1, 10, False, False), {'error': None, 'pages': []})

if N == 3:
    check('exactly filled body', solve([{'id':'a','height':3},{'id':'b','height':4},{'id':'c','height':3+1},{'id':'d','height':2}], 2, 1, 10, False, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 3, 'overflow': False}, {'id': 'b', 'height': 4, 'overflow': False}], 'used': 7, 'body_limit': 7}, {'number': 2, 'header': False, 'footer': True, 'rows': [{'id': 'c', 'height': 4, 'overflow': False}, {'id': 'd', 'height': 2, 'overflow': False}], 'used': 6, 'body_limit': 7}]})
    check('oversized row', solve([{'id':'a','height':11},{'id':'b','height':2}], 2, 1, 10, True, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 11, 'overflow': True}], 'used': 11, 'body_limit': 7}, {'number': 2, 'header': True, 'footer': True, 'rows': [{'id': 'b', 'height': 2, 'overflow': False}], 'used': 2, 'body_limit': 7}]})
    check('detail blocks', solve([{'id':'a','height':3,'detail_height':4},{'id':'b','height':3,'detail_height':4}], 2, 1, 10, True, True), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 7, 'overflow': False}], 'used': 7, 'body_limit': 7}, {'number': 2, 'header': True, 'footer': True, 'rows': [{'id': 'b', 'height': 7, 'overflow': False}], 'used': 7, 'body_limit': 7}]})
    check('detail excluded', solve([{'id':'a','height':3,'detail_height':4},{'id':'b','height':3,'detail_height':4}], 2, 1, 10, True, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 3, 'overflow': False}, {'id': 'b', 'height': 3, 'overflow': False}], 'used': 6, 'body_limit': 7}]})
    check('zero body', solve([{'id':'a','height':1}], 2, 1, 3, True, False), {'error': 'no-body-space', 'pages': []})
    check('negative body', solve([], 2, 2, 3, False, False), {'error': 'no-body-space', 'pages': []})
    check('nonexact overflow', solve([{'id':'a','height':4},{'id':'b','height':4},{'id':'c','height':3}], 2, 1, 10, False, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 4, 'overflow': False}], 'used': 4, 'body_limit': 7}, {'number': 2, 'header': False, 'footer': True, 'rows': [{'id': 'b', 'height': 4, 'overflow': False}, {'id': 'c', 'height': 3, 'overflow': False}], 'used': 7, 'body_limit': 7}]})
    check('reset capacity', solve([{'id':'a','height':3},{'id':'b','height':5},{'id':'c','height':2}], 2, 1, 10, False, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 3, 'overflow': False}], 'used': 3, 'body_limit': 7}, {'number': 2, 'header': False, 'footer': True, 'rows': [{'id': 'b', 'height': 5, 'overflow': False}, {'id': 'c', 'height': 2, 'overflow': False}], 'used': 7, 'body_limit': 7}]})
    check('empty print', solve([], 2, 1, 10, False, False), {'error': None, 'pages': []})

if N == 4:
    check('exactly filled body', solve([{'id':'a','height':3},{'id':'b','height':4},{'id':'c','height':4+1},{'id':'d','height':2}], 2, 1, 10, False, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 3, 'overflow': False}, {'id': 'b', 'height': 4, 'overflow': False}], 'used': 7, 'body_limit': 7}, {'number': 2, 'header': False, 'footer': True, 'rows': [{'id': 'c', 'height': 5, 'overflow': False}, {'id': 'd', 'height': 2, 'overflow': False}], 'used': 7, 'body_limit': 7}]})
    check('oversized row', solve([{'id':'a','height':11},{'id':'b','height':2}], 2, 1, 10, True, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 11, 'overflow': True}], 'used': 11, 'body_limit': 7}, {'number': 2, 'header': True, 'footer': True, 'rows': [{'id': 'b', 'height': 2, 'overflow': False}], 'used': 2, 'body_limit': 7}]})
    check('detail blocks', solve([{'id':'a','height':3,'detail_height':4},{'id':'b','height':3,'detail_height':4}], 2, 1, 10, True, True), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 7, 'overflow': False}], 'used': 7, 'body_limit': 7}, {'number': 2, 'header': True, 'footer': True, 'rows': [{'id': 'b', 'height': 7, 'overflow': False}], 'used': 7, 'body_limit': 7}]})
    check('detail excluded', solve([{'id':'a','height':3,'detail_height':4},{'id':'b','height':3,'detail_height':4}], 2, 1, 10, True, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 3, 'overflow': False}, {'id': 'b', 'height': 3, 'overflow': False}], 'used': 6, 'body_limit': 7}]})
    check('zero body', solve([{'id':'a','height':1}], 2, 1, 3, True, False), {'error': 'no-body-space', 'pages': []})
    check('negative body', solve([], 2, 2, 3, False, False), {'error': 'no-body-space', 'pages': []})
    check('nonexact overflow', solve([{'id':'a','height':4},{'id':'b','height':4},{'id':'c','height':3}], 2, 1, 10, False, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 4, 'overflow': False}], 'used': 4, 'body_limit': 7}, {'number': 2, 'header': False, 'footer': True, 'rows': [{'id': 'b', 'height': 4, 'overflow': False}, {'id': 'c', 'height': 3, 'overflow': False}], 'used': 7, 'body_limit': 7}]})
    check('reset capacity', solve([{'id':'a','height':3},{'id':'b','height':5},{'id':'c','height':2}], 2, 1, 10, False, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 3, 'overflow': False}], 'used': 3, 'body_limit': 7}, {'number': 2, 'header': False, 'footer': True, 'rows': [{'id': 'b', 'height': 5, 'overflow': False}, {'id': 'c', 'height': 2, 'overflow': False}], 'used': 7, 'body_limit': 7}]})
    check('empty print', solve([], 2, 1, 10, False, False), {'error': None, 'pages': []})

if N == 5:
    check('exactly filled body', solve([{'id':'a','height':3},{'id':'b','height':4},{'id':'c','height':5+1},{'id':'d','height':2}], 2, 1, 10, False, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 3, 'overflow': False}, {'id': 'b', 'height': 4, 'overflow': False}], 'used': 7, 'body_limit': 7}, {'number': 2, 'header': False, 'footer': True, 'rows': [{'id': 'c', 'height': 6, 'overflow': False}], 'used': 6, 'body_limit': 7}, {'number': 3, 'header': False, 'footer': True, 'rows': [{'id': 'd', 'height': 2, 'overflow': False}], 'used': 2, 'body_limit': 7}]})
    check('oversized row', solve([{'id':'a','height':11},{'id':'b','height':2}], 2, 1, 10, True, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 11, 'overflow': True}], 'used': 11, 'body_limit': 7}, {'number': 2, 'header': True, 'footer': True, 'rows': [{'id': 'b', 'height': 2, 'overflow': False}], 'used': 2, 'body_limit': 7}]})
    check('detail blocks', solve([{'id':'a','height':3,'detail_height':4},{'id':'b','height':3,'detail_height':4}], 2, 1, 10, True, True), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 7, 'overflow': False}], 'used': 7, 'body_limit': 7}, {'number': 2, 'header': True, 'footer': True, 'rows': [{'id': 'b', 'height': 7, 'overflow': False}], 'used': 7, 'body_limit': 7}]})
    check('detail excluded', solve([{'id':'a','height':3,'detail_height':4},{'id':'b','height':3,'detail_height':4}], 2, 1, 10, True, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 3, 'overflow': False}, {'id': 'b', 'height': 3, 'overflow': False}], 'used': 6, 'body_limit': 7}]})
    check('zero body', solve([{'id':'a','height':1}], 2, 1, 3, True, False), {'error': 'no-body-space', 'pages': []})
    check('negative body', solve([], 2, 2, 3, False, False), {'error': 'no-body-space', 'pages': []})
    check('nonexact overflow', solve([{'id':'a','height':4},{'id':'b','height':4},{'id':'c','height':3}], 2, 1, 10, False, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 4, 'overflow': False}], 'used': 4, 'body_limit': 7}, {'number': 2, 'header': False, 'footer': True, 'rows': [{'id': 'b', 'height': 4, 'overflow': False}, {'id': 'c', 'height': 3, 'overflow': False}], 'used': 7, 'body_limit': 7}]})
    check('reset capacity', solve([{'id':'a','height':3},{'id':'b','height':5},{'id':'c','height':2}], 2, 1, 10, False, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 3, 'overflow': False}], 'used': 3, 'body_limit': 7}, {'number': 2, 'header': False, 'footer': True, 'rows': [{'id': 'b', 'height': 5, 'overflow': False}, {'id': 'c', 'height': 2, 'overflow': False}], 'used': 7, 'body_limit': 7}]})
    check('empty print', solve([], 2, 1, 10, False, False), {'error': None, 'pages': []})

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(rows, header, footer, page_height, repeat, keep_detail):
    capacity=page_height-footer
    if capacity<=0: return {'error':'no-body-space','pages':[]}
    pages=[]; page=[]; used=0
    for row in rows:
        h=row['height']+(row.get('detail_height',0) if keep_detail else 0)
        if page and used+h>capacity:
            pages.append(page); page=[]; used=0
        page.append({'id':row['id'],'height':h,'overflow':h>capacity})
        used+=h
    if page: pages.append(page)
    return {'error':None,'pages':[{'number':i+1,'header':repeat or i==0,'footer':True,'rows':p,'used':sum(r['height'] for r in p),'body_limit':capacity} for i,p in enumerate(pages)]}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('exactly filled body', solve([{'id':'a','height':3},{'id':'b','height':4},{'id':'c','height':1+1},{'id':'d','height':2}], 2, 1, 10, False, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 3, 'overflow': False}, {'id': 'b', 'height': 4, 'overflow': False}], 'used': 7, 'body_limit': 7}, {'number': 2, 'header': False, 'footer': True, 'rows': [{'id': 'c', 'height': 2, 'overflow': False}, {'id': 'd', 'height': 2, 'overflow': False}], 'used': 4, 'body_limit': 7}]})
    check('oversized row', solve([{'id':'a','height':11},{'id':'b','height':2}], 2, 1, 10, True, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 11, 'overflow': True}], 'used': 11, 'body_limit': 7}, {'number': 2, 'header': True, 'footer': True, 'rows': [{'id': 'b', 'height': 2, 'overflow': False}], 'used': 2, 'body_limit': 7}]})
    check('detail blocks', solve([{'id':'a','height':3,'detail_height':4},{'id':'b','height':3,'detail_height':4}], 2, 1, 10, True, True), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 7, 'overflow': False}], 'used': 7, 'body_limit': 7}, {'number': 2, 'header': True, 'footer': True, 'rows': [{'id': 'b', 'height': 7, 'overflow': False}], 'used': 7, 'body_limit': 7}]})
    check('detail excluded', solve([{'id':'a','height':3,'detail_height':4},{'id':'b','height':3,'detail_height':4}], 2, 1, 10, True, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 3, 'overflow': False}, {'id': 'b', 'height': 3, 'overflow': False}], 'used': 6, 'body_limit': 7}]})
    check('zero body', solve([{'id':'a','height':1}], 2, 1, 3, True, False), {'error': 'no-body-space', 'pages': []})
    check('negative body', solve([], 2, 2, 3, False, False), {'error': 'no-body-space', 'pages': []})
    check('nonexact overflow', solve([{'id':'a','height':4},{'id':'b','height':4},{'id':'c','height':3}], 2, 1, 10, False, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 4, 'overflow': False}], 'used': 4, 'body_limit': 7}, {'number': 2, 'header': False, 'footer': True, 'rows': [{'id': 'b', 'height': 4, 'overflow': False}, {'id': 'c', 'height': 3, 'overflow': False}], 'used': 7, 'body_limit': 7}]})
    check('reset capacity', solve([{'id':'a','height':3},{'id':'b','height':5},{'id':'c','height':2}], 2, 1, 10, False, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 3, 'overflow': False}], 'used': 3, 'body_limit': 7}, {'number': 2, 'header': False, 'footer': True, 'rows': [{'id': 'b', 'height': 5, 'overflow': False}, {'id': 'c', 'height': 2, 'overflow': False}], 'used': 7, 'body_limit': 7}]})
    check('empty print', solve([], 2, 1, 10, False, False), {'error': None, 'pages': []})

if N == 2:
    check('exactly filled body', solve([{'id':'a','height':3},{'id':'b','height':4},{'id':'c','height':2+1},{'id':'d','height':2}], 2, 1, 10, False, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 3, 'overflow': False}, {'id': 'b', 'height': 4, 'overflow': False}], 'used': 7, 'body_limit': 7}, {'number': 2, 'header': False, 'footer': True, 'rows': [{'id': 'c', 'height': 3, 'overflow': False}, {'id': 'd', 'height': 2, 'overflow': False}], 'used': 5, 'body_limit': 7}]})
    check('oversized row', solve([{'id':'a','height':11},{'id':'b','height':2}], 2, 1, 10, True, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 11, 'overflow': True}], 'used': 11, 'body_limit': 7}, {'number': 2, 'header': True, 'footer': True, 'rows': [{'id': 'b', 'height': 2, 'overflow': False}], 'used': 2, 'body_limit': 7}]})
    check('detail blocks', solve([{'id':'a','height':3,'detail_height':4},{'id':'b','height':3,'detail_height':4}], 2, 1, 10, True, True), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 7, 'overflow': False}], 'used': 7, 'body_limit': 7}, {'number': 2, 'header': True, 'footer': True, 'rows': [{'id': 'b', 'height': 7, 'overflow': False}], 'used': 7, 'body_limit': 7}]})
    check('detail excluded', solve([{'id':'a','height':3,'detail_height':4},{'id':'b','height':3,'detail_height':4}], 2, 1, 10, True, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 3, 'overflow': False}, {'id': 'b', 'height': 3, 'overflow': False}], 'used': 6, 'body_limit': 7}]})
    check('zero body', solve([{'id':'a','height':1}], 2, 1, 3, True, False), {'error': 'no-body-space', 'pages': []})
    check('negative body', solve([], 2, 2, 3, False, False), {'error': 'no-body-space', 'pages': []})
    check('nonexact overflow', solve([{'id':'a','height':4},{'id':'b','height':4},{'id':'c','height':3}], 2, 1, 10, False, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 4, 'overflow': False}], 'used': 4, 'body_limit': 7}, {'number': 2, 'header': False, 'footer': True, 'rows': [{'id': 'b', 'height': 4, 'overflow': False}, {'id': 'c', 'height': 3, 'overflow': False}], 'used': 7, 'body_limit': 7}]})
    check('reset capacity', solve([{'id':'a','height':3},{'id':'b','height':5},{'id':'c','height':2}], 2, 1, 10, False, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 3, 'overflow': False}], 'used': 3, 'body_limit': 7}, {'number': 2, 'header': False, 'footer': True, 'rows': [{'id': 'b', 'height': 5, 'overflow': False}, {'id': 'c', 'height': 2, 'overflow': False}], 'used': 7, 'body_limit': 7}]})
    check('empty print', solve([], 2, 1, 10, False, False), {'error': None, 'pages': []})

if N == 3:
    check('exactly filled body', solve([{'id':'a','height':3},{'id':'b','height':4},{'id':'c','height':3+1},{'id':'d','height':2}], 2, 1, 10, False, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 3, 'overflow': False}, {'id': 'b', 'height': 4, 'overflow': False}], 'used': 7, 'body_limit': 7}, {'number': 2, 'header': False, 'footer': True, 'rows': [{'id': 'c', 'height': 4, 'overflow': False}, {'id': 'd', 'height': 2, 'overflow': False}], 'used': 6, 'body_limit': 7}]})
    check('oversized row', solve([{'id':'a','height':11},{'id':'b','height':2}], 2, 1, 10, True, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 11, 'overflow': True}], 'used': 11, 'body_limit': 7}, {'number': 2, 'header': True, 'footer': True, 'rows': [{'id': 'b', 'height': 2, 'overflow': False}], 'used': 2, 'body_limit': 7}]})
    check('detail blocks', solve([{'id':'a','height':3,'detail_height':4},{'id':'b','height':3,'detail_height':4}], 2, 1, 10, True, True), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 7, 'overflow': False}], 'used': 7, 'body_limit': 7}, {'number': 2, 'header': True, 'footer': True, 'rows': [{'id': 'b', 'height': 7, 'overflow': False}], 'used': 7, 'body_limit': 7}]})
    check('detail excluded', solve([{'id':'a','height':3,'detail_height':4},{'id':'b','height':3,'detail_height':4}], 2, 1, 10, True, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 3, 'overflow': False}, {'id': 'b', 'height': 3, 'overflow': False}], 'used': 6, 'body_limit': 7}]})
    check('zero body', solve([{'id':'a','height':1}], 2, 1, 3, True, False), {'error': 'no-body-space', 'pages': []})
    check('negative body', solve([], 2, 2, 3, False, False), {'error': 'no-body-space', 'pages': []})
    check('nonexact overflow', solve([{'id':'a','height':4},{'id':'b','height':4},{'id':'c','height':3}], 2, 1, 10, False, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 4, 'overflow': False}], 'used': 4, 'body_limit': 7}, {'number': 2, 'header': False, 'footer': True, 'rows': [{'id': 'b', 'height': 4, 'overflow': False}, {'id': 'c', 'height': 3, 'overflow': False}], 'used': 7, 'body_limit': 7}]})
    check('reset capacity', solve([{'id':'a','height':3},{'id':'b','height':5},{'id':'c','height':2}], 2, 1, 10, False, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 3, 'overflow': False}], 'used': 3, 'body_limit': 7}, {'number': 2, 'header': False, 'footer': True, 'rows': [{'id': 'b', 'height': 5, 'overflow': False}, {'id': 'c', 'height': 2, 'overflow': False}], 'used': 7, 'body_limit': 7}]})
    check('empty print', solve([], 2, 1, 10, False, False), {'error': None, 'pages': []})

if N == 4:
    check('exactly filled body', solve([{'id':'a','height':3},{'id':'b','height':4},{'id':'c','height':4+1},{'id':'d','height':2}], 2, 1, 10, False, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 3, 'overflow': False}, {'id': 'b', 'height': 4, 'overflow': False}], 'used': 7, 'body_limit': 7}, {'number': 2, 'header': False, 'footer': True, 'rows': [{'id': 'c', 'height': 5, 'overflow': False}, {'id': 'd', 'height': 2, 'overflow': False}], 'used': 7, 'body_limit': 7}]})
    check('oversized row', solve([{'id':'a','height':11},{'id':'b','height':2}], 2, 1, 10, True, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 11, 'overflow': True}], 'used': 11, 'body_limit': 7}, {'number': 2, 'header': True, 'footer': True, 'rows': [{'id': 'b', 'height': 2, 'overflow': False}], 'used': 2, 'body_limit': 7}]})
    check('detail blocks', solve([{'id':'a','height':3,'detail_height':4},{'id':'b','height':3,'detail_height':4}], 2, 1, 10, True, True), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 7, 'overflow': False}], 'used': 7, 'body_limit': 7}, {'number': 2, 'header': True, 'footer': True, 'rows': [{'id': 'b', 'height': 7, 'overflow': False}], 'used': 7, 'body_limit': 7}]})
    check('detail excluded', solve([{'id':'a','height':3,'detail_height':4},{'id':'b','height':3,'detail_height':4}], 2, 1, 10, True, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 3, 'overflow': False}, {'id': 'b', 'height': 3, 'overflow': False}], 'used': 6, 'body_limit': 7}]})
    check('zero body', solve([{'id':'a','height':1}], 2, 1, 3, True, False), {'error': 'no-body-space', 'pages': []})
    check('negative body', solve([], 2, 2, 3, False, False), {'error': 'no-body-space', 'pages': []})
    check('nonexact overflow', solve([{'id':'a','height':4},{'id':'b','height':4},{'id':'c','height':3}], 2, 1, 10, False, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 4, 'overflow': False}], 'used': 4, 'body_limit': 7}, {'number': 2, 'header': False, 'footer': True, 'rows': [{'id': 'b', 'height': 4, 'overflow': False}, {'id': 'c', 'height': 3, 'overflow': False}], 'used': 7, 'body_limit': 7}]})
    check('reset capacity', solve([{'id':'a','height':3},{'id':'b','height':5},{'id':'c','height':2}], 2, 1, 10, False, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 3, 'overflow': False}], 'used': 3, 'body_limit': 7}, {'number': 2, 'header': False, 'footer': True, 'rows': [{'id': 'b', 'height': 5, 'overflow': False}, {'id': 'c', 'height': 2, 'overflow': False}], 'used': 7, 'body_limit': 7}]})
    check('empty print', solve([], 2, 1, 10, False, False), {'error': None, 'pages': []})

if N == 5:
    check('exactly filled body', solve([{'id':'a','height':3},{'id':'b','height':4},{'id':'c','height':5+1},{'id':'d','height':2}], 2, 1, 10, False, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 3, 'overflow': False}, {'id': 'b', 'height': 4, 'overflow': False}], 'used': 7, 'body_limit': 7}, {'number': 2, 'header': False, 'footer': True, 'rows': [{'id': 'c', 'height': 6, 'overflow': False}], 'used': 6, 'body_limit': 7}, {'number': 3, 'header': False, 'footer': True, 'rows': [{'id': 'd', 'height': 2, 'overflow': False}], 'used': 2, 'body_limit': 7}]})
    check('oversized row', solve([{'id':'a','height':11},{'id':'b','height':2}], 2, 1, 10, True, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 11, 'overflow': True}], 'used': 11, 'body_limit': 7}, {'number': 2, 'header': True, 'footer': True, 'rows': [{'id': 'b', 'height': 2, 'overflow': False}], 'used': 2, 'body_limit': 7}]})
    check('detail blocks', solve([{'id':'a','height':3,'detail_height':4},{'id':'b','height':3,'detail_height':4}], 2, 1, 10, True, True), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 7, 'overflow': False}], 'used': 7, 'body_limit': 7}, {'number': 2, 'header': True, 'footer': True, 'rows': [{'id': 'b', 'height': 7, 'overflow': False}], 'used': 7, 'body_limit': 7}]})
    check('detail excluded', solve([{'id':'a','height':3,'detail_height':4},{'id':'b','height':3,'detail_height':4}], 2, 1, 10, True, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 3, 'overflow': False}, {'id': 'b', 'height': 3, 'overflow': False}], 'used': 6, 'body_limit': 7}]})
    check('zero body', solve([{'id':'a','height':1}], 2, 1, 3, True, False), {'error': 'no-body-space', 'pages': []})
    check('negative body', solve([], 2, 2, 3, False, False), {'error': 'no-body-space', 'pages': []})
    check('nonexact overflow', solve([{'id':'a','height':4},{'id':'b','height':4},{'id':'c','height':3}], 2, 1, 10, False, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 4, 'overflow': False}], 'used': 4, 'body_limit': 7}, {'number': 2, 'header': False, 'footer': True, 'rows': [{'id': 'b', 'height': 4, 'overflow': False}, {'id': 'c', 'height': 3, 'overflow': False}], 'used': 7, 'body_limit': 7}]})
    check('reset capacity', solve([{'id':'a','height':3},{'id':'b','height':5},{'id':'c','height':2}], 2, 1, 10, False, False), {'error': None, 'pages': [{'number': 1, 'header': True, 'footer': True, 'rows': [{'id': 'a', 'height': 3, 'overflow': False}], 'used': 3, 'body_limit': 7}, {'number': 2, 'header': False, 'footer': True, 'rows': [{'id': 'b', 'height': 5, 'overflow': False}, {'id': 'c', 'height': 2, 'overflow': False}], 'used': 7, 'body_limit': 7}]})
    check('empty print', solve([], 2, 1, 10, False, False), {'error': None, 'pages': []})

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:
The table footer space reservation result violates the stipulated printed table page partition contract.

Print pages reserve header/footer height, pack whole row/detail blocks in order, allow exact fits, place oversized rows alone with an overflow marker, never generate empty pages, number from one, and repeat headers only when requested.

split: open-access