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

N = 1
observations = []
def solve(leaves, hidden, pins):
    v = [x for x in leaves if x['id'] not in hidden]
    runs=[]
    for x in v:
        pane=pins.get(x['id'], 'center')
        key=(x.get('group'),pane)
        if runs and runs[-1]['key']==key:
            runs[-1]['leaves'].append(x['id'])
            runs[-1]['width']+=x['width']
        else: runs.append({'key':key,'leaves':[x['id']],'width':x['width']})
    return [{'group':r['key'][0], 'pane':r['key'][1], 'span':len(r['leaves']), 'width':r['width'], 'first':r['leaves'][0], 'last':r['leaves'][-1], 'leaf_ids':r['leaves'], 'blank':r['key'][0] is None, 'resizable':True} for r in runs]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('contiguous group', solve([{'id':'a','group':'G','width':2*1},{'id':'b','group':'G','width':3},{'id':'c','group':'H','width':4}], [], {}), [{'group': 'G', 'pane': 'center', 'span': 2, 'width': 5, 'first': 'a', 'last': 'b', 'leaf_ids': ['a', 'b'], 'blank': False, 'resizable': True}, {'group': 'H', 'pane': 'center', 'span': 1, 'width': 4, 'first': 'c', 'last': 'c', 'leaf_ids': ['c'], 'blank': False, 'resizable': False}])
    check('pin splits group', solve([{'id':'a','group':'G','width':2},{'id':'b','group':'G','width':3},{'id':'c','group':'G','width':4}], [], {'a':'left'}), [{'group': 'G', 'pane': 'left', 'span': 1, 'width': 2, 'first': 'a', 'last': 'a', 'leaf_ids': ['a'], 'blank': False, 'resizable': False}, {'group': 'G', 'pane': 'center', 'span': 2, 'width': 7, 'first': 'b', 'last': 'c', 'leaf_ids': ['b', 'c'], 'blank': False, 'resizable': True}])
    check('hidden leaves', solve([{'id':'a','group':'G','width':2},{'id':'b','group':'G','width':3},{'id':'c','group':'G','width':4}], ['a','b'], {}), [{'group': 'G', 'pane': 'center', 'span': 1, 'width': 4, 'first': 'c', 'last': 'c', 'leaf_ids': ['c'], 'blank': False, 'resizable': False}])
    check('blank versus empty', solve([{'id':'a','width':2},{'id':'b','group':'','width':3}], [], {}), [{'group': None, 'pane': 'center', 'span': 1, 'width': 2, 'first': 'a', 'last': 'a', 'leaf_ids': ['a'], 'blank': True, 'resizable': False}, {'group': '', 'pane': 'center', 'span': 1, 'width': 3, 'first': 'b', 'last': 'b', 'leaf_ids': ['b'], 'blank': False, 'resizable': False}])
    check('separated groups', solve([{'id':'a','group':'G','width':2},{'id':'b','group':'H','width':3},{'id':'c','group':'G','width':4}], [], {}), [{'group': 'G', 'pane': 'center', 'span': 1, 'width': 2, 'first': 'a', 'last': 'a', 'leaf_ids': ['a'], 'blank': False, 'resizable': False}, {'group': 'H', 'pane': 'center', 'span': 1, 'width': 3, 'first': 'b', 'last': 'b', 'leaf_ids': ['b'], 'blank': False, 'resizable': False}, {'group': 'G', 'pane': 'center', 'span': 1, 'width': 4, 'first': 'c', 'last': 'c', 'leaf_ids': ['c'], 'blank': False, 'resizable': False}])
    check('empty header', solve([], [], {}), [])

if N == 2:
    check('contiguous group', solve([{'id':'a','group':'G','width':2*2},{'id':'b','group':'G','width':3},{'id':'c','group':'H','width':4}], [], {}), [{'group': 'G', 'pane': 'center', 'span': 2, 'width': 7, 'first': 'a', 'last': 'b', 'leaf_ids': ['a', 'b'], 'blank': False, 'resizable': True}, {'group': 'H', 'pane': 'center', 'span': 1, 'width': 4, 'first': 'c', 'last': 'c', 'leaf_ids': ['c'], 'blank': False, 'resizable': False}])
    check('pin splits group', solve([{'id':'a','group':'G','width':2},{'id':'b','group':'G','width':3},{'id':'c','group':'G','width':4}], [], {'a':'left'}), [{'group': 'G', 'pane': 'left', 'span': 1, 'width': 2, 'first': 'a', 'last': 'a', 'leaf_ids': ['a'], 'blank': False, 'resizable': False}, {'group': 'G', 'pane': 'center', 'span': 2, 'width': 7, 'first': 'b', 'last': 'c', 'leaf_ids': ['b', 'c'], 'blank': False, 'resizable': True}])
    check('hidden leaves', solve([{'id':'a','group':'G','width':2},{'id':'b','group':'G','width':3},{'id':'c','group':'G','width':4}], ['a','b'], {}), [{'group': 'G', 'pane': 'center', 'span': 1, 'width': 4, 'first': 'c', 'last': 'c', 'leaf_ids': ['c'], 'blank': False, 'resizable': False}])
    check('blank versus empty', solve([{'id':'a','width':2},{'id':'b','group':'','width':3}], [], {}), [{'group': None, 'pane': 'center', 'span': 1, 'width': 2, 'first': 'a', 'last': 'a', 'leaf_ids': ['a'], 'blank': True, 'resizable': False}, {'group': '', 'pane': 'center', 'span': 1, 'width': 3, 'first': 'b', 'last': 'b', 'leaf_ids': ['b'], 'blank': False, 'resizable': False}])
    check('separated groups', solve([{'id':'a','group':'G','width':2},{'id':'b','group':'H','width':3},{'id':'c','group':'G','width':4}], [], {}), [{'group': 'G', 'pane': 'center', 'span': 1, 'width': 2, 'first': 'a', 'last': 'a', 'leaf_ids': ['a'], 'blank': False, 'resizable': False}, {'group': 'H', 'pane': 'center', 'span': 1, 'width': 3, 'first': 'b', 'last': 'b', 'leaf_ids': ['b'], 'blank': False, 'resizable': False}, {'group': 'G', 'pane': 'center', 'span': 1, 'width': 4, 'first': 'c', 'last': 'c', 'leaf_ids': ['c'], 'blank': False, 'resizable': False}])
    check('empty header', solve([], [], {}), [])

if N == 3:
    check('contiguous group', solve([{'id':'a','group':'G','width':2*3},{'id':'b','group':'G','width':3},{'id':'c','group':'H','width':4}], [], {}), [{'group': 'G', 'pane': 'center', 'span': 2, 'width': 9, 'first': 'a', 'last': 'b', 'leaf_ids': ['a', 'b'], 'blank': False, 'resizable': True}, {'group': 'H', 'pane': 'center', 'span': 1, 'width': 4, 'first': 'c', 'last': 'c', 'leaf_ids': ['c'], 'blank': False, 'resizable': False}])
    check('pin splits group', solve([{'id':'a','group':'G','width':2},{'id':'b','group':'G','width':3},{'id':'c','group':'G','width':4}], [], {'a':'left'}), [{'group': 'G', 'pane': 'left', 'span': 1, 'width': 2, 'first': 'a', 'last': 'a', 'leaf_ids': ['a'], 'blank': False, 'resizable': False}, {'group': 'G', 'pane': 'center', 'span': 2, 'width': 7, 'first': 'b', 'last': 'c', 'leaf_ids': ['b', 'c'], 'blank': False, 'resizable': True}])
    check('hidden leaves', solve([{'id':'a','group':'G','width':2},{'id':'b','group':'G','width':3},{'id':'c','group':'G','width':4}], ['a','b'], {}), [{'group': 'G', 'pane': 'center', 'span': 1, 'width': 4, 'first': 'c', 'last': 'c', 'leaf_ids': ['c'], 'blank': False, 'resizable': False}])
    check('blank versus empty', solve([{'id':'a','width':2},{'id':'b','group':'','width':3}], [], {}), [{'group': None, 'pane': 'center', 'span': 1, 'width': 2, 'first': 'a', 'last': 'a', 'leaf_ids': ['a'], 'blank': True, 'resizable': False}, {'group': '', 'pane': 'center', 'span': 1, 'width': 3, 'first': 'b', 'last': 'b', 'leaf_ids': ['b'], 'blank': False, 'resizable': False}])
    check('separated groups', solve([{'id':'a','group':'G','width':2},{'id':'b','group':'H','width':3},{'id':'c','group':'G','width':4}], [], {}), [{'group': 'G', 'pane': 'center', 'span': 1, 'width': 2, 'first': 'a', 'last': 'a', 'leaf_ids': ['a'], 'blank': False, 'resizable': False}, {'group': 'H', 'pane': 'center', 'span': 1, 'width': 3, 'first': 'b', 'last': 'b', 'leaf_ids': ['b'], 'blank': False, 'resizable': False}, {'group': 'G', 'pane': 'center', 'span': 1, 'width': 4, 'first': 'c', 'last': 'c', 'leaf_ids': ['c'], 'blank': False, 'resizable': False}])
    check('empty header', solve([], [], {}), [])

if N == 4:
    check('contiguous group', solve([{'id':'a','group':'G','width':2*4},{'id':'b','group':'G','width':3},{'id':'c','group':'H','width':4}], [], {}), [{'group': 'G', 'pane': 'center', 'span': 2, 'width': 11, 'first': 'a', 'last': 'b', 'leaf_ids': ['a', 'b'], 'blank': False, 'resizable': True}, {'group': 'H', 'pane': 'center', 'span': 1, 'width': 4, 'first': 'c', 'last': 'c', 'leaf_ids': ['c'], 'blank': False, 'resizable': False}])
    check('pin splits group', solve([{'id':'a','group':'G','width':2},{'id':'b','group':'G','width':3},{'id':'c','group':'G','width':4}], [], {'a':'left'}), [{'group': 'G', 'pane': 'left', 'span': 1, 'width': 2, 'first': 'a', 'last': 'a', 'leaf_ids': ['a'], 'blank': False, 'resizable': False}, {'group': 'G', 'pane': 'center', 'span': 2, 'width': 7, 'first': 'b', 'last': 'c', 'leaf_ids': ['b', 'c'], 'blank': False, 'resizable': True}])
    check('hidden leaves', solve([{'id':'a','group':'G','width':2},{'id':'b','group':'G','width':3},{'id':'c','group':'G','width':4}], ['a','b'], {}), [{'group': 'G', 'pane': 'center', 'span': 1, 'width': 4, 'first': 'c', 'last': 'c', 'leaf_ids': ['c'], 'blank': False, 'resizable': False}])
    check('blank versus empty', solve([{'id':'a','width':2},{'id':'b','group':'','width':3}], [], {}), [{'group': None, 'pane': 'center', 'span': 1, 'width': 2, 'first': 'a', 'last': 'a', 'leaf_ids': ['a'], 'blank': True, 'resizable': False}, {'group': '', 'pane': 'center', 'span': 1, 'width': 3, 'first': 'b', 'last': 'b', 'leaf_ids': ['b'], 'blank': False, 'resizable': False}])
    check('separated groups', solve([{'id':'a','group':'G','width':2},{'id':'b','group':'H','width':3},{'id':'c','group':'G','width':4}], [], {}), [{'group': 'G', 'pane': 'center', 'span': 1, 'width': 2, 'first': 'a', 'last': 'a', 'leaf_ids': ['a'], 'blank': False, 'resizable': False}, {'group': 'H', 'pane': 'center', 'span': 1, 'width': 3, 'first': 'b', 'last': 'b', 'leaf_ids': ['b'], 'blank': False, 'resizable': False}, {'group': 'G', 'pane': 'center', 'span': 1, 'width': 4, 'first': 'c', 'last': 'c', 'leaf_ids': ['c'], 'blank': False, 'resizable': False}])
    check('empty header', solve([], [], {}), [])

if N == 5:
    check('contiguous group', solve([{'id':'a','group':'G','width':2*5},{'id':'b','group':'G','width':3},{'id':'c','group':'H','width':4}], [], {}), [{'group': 'G', 'pane': 'center', 'span': 2, 'width': 13, 'first': 'a', 'last': 'b', 'leaf_ids': ['a', 'b'], 'blank': False, 'resizable': True}, {'group': 'H', 'pane': 'center', 'span': 1, 'width': 4, 'first': 'c', 'last': 'c', 'leaf_ids': ['c'], 'blank': False, 'resizable': False}])
    check('pin splits group', solve([{'id':'a','group':'G','width':2},{'id':'b','group':'G','width':3},{'id':'c','group':'G','width':4}], [], {'a':'left'}), [{'group': 'G', 'pane': 'left', 'span': 1, 'width': 2, 'first': 'a', 'last': 'a', 'leaf_ids': ['a'], 'blank': False, 'resizable': False}, {'group': 'G', 'pane': 'center', 'span': 2, 'width': 7, 'first': 'b', 'last': 'c', 'leaf_ids': ['b', 'c'], 'blank': False, 'resizable': True}])
    check('hidden leaves', solve([{'id':'a','group':'G','width':2},{'id':'b','group':'G','width':3},{'id':'c','group':'G','width':4}], ['a','b'], {}), [{'group': 'G', 'pane': 'center', 'span': 1, 'width': 4, 'first': 'c', 'last': 'c', 'leaf_ids': ['c'], 'blank': False, 'resizable': False}])
    check('blank versus empty', solve([{'id':'a','width':2},{'id':'b','group':'','width':3}], [], {}), [{'group': None, 'pane': 'center', 'span': 1, 'width': 2, 'first': 'a', 'last': 'a', 'leaf_ids': ['a'], 'blank': True, 'resizable': False}, {'group': '', 'pane': 'center', 'span': 1, 'width': 3, 'first': 'b', 'last': 'b', 'leaf_ids': ['b'], 'blank': False, 'resizable': False}])
    check('separated groups', solve([{'id':'a','group':'G','width':2},{'id':'b','group':'H','width':3},{'id':'c','group':'G','width':4}], [], {}), [{'group': 'G', 'pane': 'center', 'span': 1, 'width': 2, 'first': 'a', 'last': 'a', 'leaf_ids': ['a'], 'blank': False, 'resizable': False}, {'group': 'H', 'pane': 'center', 'span': 1, 'width': 3, 'first': 'b', 'last': 'b', 'leaf_ids': ['b'], 'blank': False, 'resizable': False}, {'group': 'G', 'pane': 'center', 'span': 1, 'width': 4, 'first': 'c', 'last': 'c', 'leaf_ids': ['c'], 'blank': False, 'resizable': False}])
    check('empty header', solve([], [], {}), [])

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(leaves, hidden, pins):
    v = [x for x in leaves if x['id'] not in hidden]
    runs=[]
    for x in v:
        pane=pins.get(x['id'], 'center')
        key=(x.get('group'),pane)
        if runs and runs[-1]['key']==key:
            runs[-1]['leaves'].append(x['id'])
            runs[-1]['width']+=x['width']
        else: runs.append({'key':key,'leaves':[x['id']],'width':x['width']})
    return [{'group':r['key'][0], 'pane':r['key'][1], 'span':len(r['leaves']), 'width':r['width'], 'first':r['leaves'][0], 'last':r['leaves'][-1], 'leaf_ids':r['leaves'], 'blank':r['key'][0] is None, 'resizable':len(r['leaves'])>2} for r in runs]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('contiguous group', solve([{'id':'a','group':'G','width':2*1},{'id':'b','group':'G','width':3},{'id':'c','group':'H','width':4}], [], {}), [{'group': 'G', 'pane': 'center', 'span': 2, 'width': 5, 'first': 'a', 'last': 'b', 'leaf_ids': ['a', 'b'], 'blank': False, 'resizable': True}, {'group': 'H', 'pane': 'center', 'span': 1, 'width': 4, 'first': 'c', 'last': 'c', 'leaf_ids': ['c'], 'blank': False, 'resizable': False}])
    check('pin splits group', solve([{'id':'a','group':'G','width':2},{'id':'b','group':'G','width':3},{'id':'c','group':'G','width':4}], [], {'a':'left'}), [{'group': 'G', 'pane': 'left', 'span': 1, 'width': 2, 'first': 'a', 'last': 'a', 'leaf_ids': ['a'], 'blank': False, 'resizable': False}, {'group': 'G', 'pane': 'center', 'span': 2, 'width': 7, 'first': 'b', 'last': 'c', 'leaf_ids': ['b', 'c'], 'blank': False, 'resizable': True}])
    check('hidden leaves', solve([{'id':'a','group':'G','width':2},{'id':'b','group':'G','width':3},{'id':'c','group':'G','width':4}], ['a','b'], {}), [{'group': 'G', 'pane': 'center', 'span': 1, 'width': 4, 'first': 'c', 'last': 'c', 'leaf_ids': ['c'], 'blank': False, 'resizable': False}])
    check('blank versus empty', solve([{'id':'a','width':2},{'id':'b','group':'','width':3}], [], {}), [{'group': None, 'pane': 'center', 'span': 1, 'width': 2, 'first': 'a', 'last': 'a', 'leaf_ids': ['a'], 'blank': True, 'resizable': False}, {'group': '', 'pane': 'center', 'span': 1, 'width': 3, 'first': 'b', 'last': 'b', 'leaf_ids': ['b'], 'blank': False, 'resizable': False}])
    check('separated groups', solve([{'id':'a','group':'G','width':2},{'id':'b','group':'H','width':3},{'id':'c','group':'G','width':4}], [], {}), [{'group': 'G', 'pane': 'center', 'span': 1, 'width': 2, 'first': 'a', 'last': 'a', 'leaf_ids': ['a'], 'blank': False, 'resizable': False}, {'group': 'H', 'pane': 'center', 'span': 1, 'width': 3, 'first': 'b', 'last': 'b', 'leaf_ids': ['b'], 'blank': False, 'resizable': False}, {'group': 'G', 'pane': 'center', 'span': 1, 'width': 4, 'first': 'c', 'last': 'c', 'leaf_ids': ['c'], 'blank': False, 'resizable': False}])
    check('empty header', solve([], [], {}), [])

if N == 2:
    check('contiguous group', solve([{'id':'a','group':'G','width':2*2},{'id':'b','group':'G','width':3},{'id':'c','group':'H','width':4}], [], {}), [{'group': 'G', 'pane': 'center', 'span': 2, 'width': 7, 'first': 'a', 'last': 'b', 'leaf_ids': ['a', 'b'], 'blank': False, 'resizable': True}, {'group': 'H', 'pane': 'center', 'span': 1, 'width': 4, 'first': 'c', 'last': 'c', 'leaf_ids': ['c'], 'blank': False, 'resizable': False}])
    check('pin splits group', solve([{'id':'a','group':'G','width':2},{'id':'b','group':'G','width':3},{'id':'c','group':'G','width':4}], [], {'a':'left'}), [{'group': 'G', 'pane': 'left', 'span': 1, 'width': 2, 'first': 'a', 'last': 'a', 'leaf_ids': ['a'], 'blank': False, 'resizable': False}, {'group': 'G', 'pane': 'center', 'span': 2, 'width': 7, 'first': 'b', 'last': 'c', 'leaf_ids': ['b', 'c'], 'blank': False, 'resizable': True}])
    check('hidden leaves', solve([{'id':'a','group':'G','width':2},{'id':'b','group':'G','width':3},{'id':'c','group':'G','width':4}], ['a','b'], {}), [{'group': 'G', 'pane': 'center', 'span': 1, 'width': 4, 'first': 'c', 'last': 'c', 'leaf_ids': ['c'], 'blank': False, 'resizable': False}])
    check('blank versus empty', solve([{'id':'a','width':2},{'id':'b','group':'','width':3}], [], {}), [{'group': None, 'pane': 'center', 'span': 1, 'width': 2, 'first': 'a', 'last': 'a', 'leaf_ids': ['a'], 'blank': True, 'resizable': False}, {'group': '', 'pane': 'center', 'span': 1, 'width': 3, 'first': 'b', 'last': 'b', 'leaf_ids': ['b'], 'blank': False, 'resizable': False}])
    check('separated groups', solve([{'id':'a','group':'G','width':2},{'id':'b','group':'H','width':3},{'id':'c','group':'G','width':4}], [], {}), [{'group': 'G', 'pane': 'center', 'span': 1, 'width': 2, 'first': 'a', 'last': 'a', 'leaf_ids': ['a'], 'blank': False, 'resizable': False}, {'group': 'H', 'pane': 'center', 'span': 1, 'width': 3, 'first': 'b', 'last': 'b', 'leaf_ids': ['b'], 'blank': False, 'resizable': False}, {'group': 'G', 'pane': 'center', 'span': 1, 'width': 4, 'first': 'c', 'last': 'c', 'leaf_ids': ['c'], 'blank': False, 'resizable': False}])
    check('empty header', solve([], [], {}), [])

if N == 3:
    check('contiguous group', solve([{'id':'a','group':'G','width':2*3},{'id':'b','group':'G','width':3},{'id':'c','group':'H','width':4}], [], {}), [{'group': 'G', 'pane': 'center', 'span': 2, 'width': 9, 'first': 'a', 'last': 'b', 'leaf_ids': ['a', 'b'], 'blank': False, 'resizable': True}, {'group': 'H', 'pane': 'center', 'span': 1, 'width': 4, 'first': 'c', 'last': 'c', 'leaf_ids': ['c'], 'blank': False, 'resizable': False}])
    check('pin splits group', solve([{'id':'a','group':'G','width':2},{'id':'b','group':'G','width':3},{'id':'c','group':'G','width':4}], [], {'a':'left'}), [{'group': 'G', 'pane': 'left', 'span': 1, 'width': 2, 'first': 'a', 'last': 'a', 'leaf_ids': ['a'], 'blank': False, 'resizable': False}, {'group': 'G', 'pane': 'center', 'span': 2, 'width': 7, 'first': 'b', 'last': 'c', 'leaf_ids': ['b', 'c'], 'blank': False, 'resizable': True}])
    check('hidden leaves', solve([{'id':'a','group':'G','width':2},{'id':'b','group':'G','width':3},{'id':'c','group':'G','width':4}], ['a','b'], {}), [{'group': 'G', 'pane': 'center', 'span': 1, 'width': 4, 'first': 'c', 'last': 'c', 'leaf_ids': ['c'], 'blank': False, 'resizable': False}])
    check('blank versus empty', solve([{'id':'a','width':2},{'id':'b','group':'','width':3}], [], {}), [{'group': None, 'pane': 'center', 'span': 1, 'width': 2, 'first': 'a', 'last': 'a', 'leaf_ids': ['a'], 'blank': True, 'resizable': False}, {'group': '', 'pane': 'center', 'span': 1, 'width': 3, 'first': 'b', 'last': 'b', 'leaf_ids': ['b'], 'blank': False, 'resizable': False}])
    check('separated groups', solve([{'id':'a','group':'G','width':2},{'id':'b','group':'H','width':3},{'id':'c','group':'G','width':4}], [], {}), [{'group': 'G', 'pane': 'center', 'span': 1, 'width': 2, 'first': 'a', 'last': 'a', 'leaf_ids': ['a'], 'blank': False, 'resizable': False}, {'group': 'H', 'pane': 'center', 'span': 1, 'width': 3, 'first': 'b', 'last': 'b', 'leaf_ids': ['b'], 'blank': False, 'resizable': False}, {'group': 'G', 'pane': 'center', 'span': 1, 'width': 4, 'first': 'c', 'last': 'c', 'leaf_ids': ['c'], 'blank': False, 'resizable': False}])
    check('empty header', solve([], [], {}), [])

if N == 4:
    check('contiguous group', solve([{'id':'a','group':'G','width':2*4},{'id':'b','group':'G','width':3},{'id':'c','group':'H','width':4}], [], {}), [{'group': 'G', 'pane': 'center', 'span': 2, 'width': 11, 'first': 'a', 'last': 'b', 'leaf_ids': ['a', 'b'], 'blank': False, 'resizable': True}, {'group': 'H', 'pane': 'center', 'span': 1, 'width': 4, 'first': 'c', 'last': 'c', 'leaf_ids': ['c'], 'blank': False, 'resizable': False}])
    check('pin splits group', solve([{'id':'a','group':'G','width':2},{'id':'b','group':'G','width':3},{'id':'c','group':'G','width':4}], [], {'a':'left'}), [{'group': 'G', 'pane': 'left', 'span': 1, 'width': 2, 'first': 'a', 'last': 'a', 'leaf_ids': ['a'], 'blank': False, 'resizable': False}, {'group': 'G', 'pane': 'center', 'span': 2, 'width': 7, 'first': 'b', 'last': 'c', 'leaf_ids': ['b', 'c'], 'blank': False, 'resizable': True}])
    check('hidden leaves', solve([{'id':'a','group':'G','width':2},{'id':'b','group':'G','width':3},{'id':'c','group':'G','width':4}], ['a','b'], {}), [{'group': 'G', 'pane': 'center', 'span': 1, 'width': 4, 'first': 'c', 'last': 'c', 'leaf_ids': ['c'], 'blank': False, 'resizable': False}])
    check('blank versus empty', solve([{'id':'a','width':2},{'id':'b','group':'','width':3}], [], {}), [{'group': None, 'pane': 'center', 'span': 1, 'width': 2, 'first': 'a', 'last': 'a', 'leaf_ids': ['a'], 'blank': True, 'resizable': False}, {'group': '', 'pane': 'center', 'span': 1, 'width': 3, 'first': 'b', 'last': 'b', 'leaf_ids': ['b'], 'blank': False, 'resizable': False}])
    check('separated groups', solve([{'id':'a','group':'G','width':2},{'id':'b','group':'H','width':3},{'id':'c','group':'G','width':4}], [], {}), [{'group': 'G', 'pane': 'center', 'span': 1, 'width': 2, 'first': 'a', 'last': 'a', 'leaf_ids': ['a'], 'blank': False, 'resizable': False}, {'group': 'H', 'pane': 'center', 'span': 1, 'width': 3, 'first': 'b', 'last': 'b', 'leaf_ids': ['b'], 'blank': False, 'resizable': False}, {'group': 'G', 'pane': 'center', 'span': 1, 'width': 4, 'first': 'c', 'last': 'c', 'leaf_ids': ['c'], 'blank': False, 'resizable': False}])
    check('empty header', solve([], [], {}), [])

if N == 5:
    check('contiguous group', solve([{'id':'a','group':'G','width':2*5},{'id':'b','group':'G','width':3},{'id':'c','group':'H','width':4}], [], {}), [{'group': 'G', 'pane': 'center', 'span': 2, 'width': 13, 'first': 'a', 'last': 'b', 'leaf_ids': ['a', 'b'], 'blank': False, 'resizable': True}, {'group': 'H', 'pane': 'center', 'span': 1, 'width': 4, 'first': 'c', 'last': 'c', 'leaf_ids': ['c'], 'blank': False, 'resizable': False}])
    check('pin splits group', solve([{'id':'a','group':'G','width':2},{'id':'b','group':'G','width':3},{'id':'c','group':'G','width':4}], [], {'a':'left'}), [{'group': 'G', 'pane': 'left', 'span': 1, 'width': 2, 'first': 'a', 'last': 'a', 'leaf_ids': ['a'], 'blank': False, 'resizable': False}, {'group': 'G', 'pane': 'center', 'span': 2, 'width': 7, 'first': 'b', 'last': 'c', 'leaf_ids': ['b', 'c'], 'blank': False, 'resizable': True}])
    check('hidden leaves', solve([{'id':'a','group':'G','width':2},{'id':'b','group':'G','width':3},{'id':'c','group':'G','width':4}], ['a','b'], {}), [{'group': 'G', 'pane': 'center', 'span': 1, 'width': 4, 'first': 'c', 'last': 'c', 'leaf_ids': ['c'], 'blank': False, 'resizable': False}])
    check('blank versus empty', solve([{'id':'a','width':2},{'id':'b','group':'','width':3}], [], {}), [{'group': None, 'pane': 'center', 'span': 1, 'width': 2, 'first': 'a', 'last': 'a', 'leaf_ids': ['a'], 'blank': True, 'resizable': False}, {'group': '', 'pane': 'center', 'span': 1, 'width': 3, 'first': 'b', 'last': 'b', 'leaf_ids': ['b'], 'blank': False, 'resizable': False}])
    check('separated groups', solve([{'id':'a','group':'G','width':2},{'id':'b','group':'H','width':3},{'id':'c','group':'G','width':4}], [], {}), [{'group': 'G', 'pane': 'center', 'span': 1, 'width': 2, 'first': 'a', 'last': 'a', 'leaf_ids': ['a'], 'blank': False, 'resizable': False}, {'group': 'H', 'pane': 'center', 'span': 1, 'width': 3, 'first': 'b', 'last': 'b', 'leaf_ids': ['b'], 'blank': False, 'resizable': False}, {'group': 'G', 'pane': 'center', 'span': 1, 'width': 4, 'first': 'c', 'last': 'c', 'leaf_ids': ['c'], 'blank': False, 'resizable': False}])
    check('empty header', solve([], [], {}), [])

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 group resize handle result violates the stipulated grouped table header runs contract.

Construct contiguous visible leaf runs keyed by exact group and pane, retaining leaf order and width sums. A missing group is a blank placeholder; an empty group string is an actual named group. Group resize handles require at least two visible leaves.

split: open-access


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

N = 1
observations = []
def solve(rows, cols, anchors, hidden_rows, hidden_cols):
    vr=[r for r in rows if True]
    vc=[c for c in cols if c not in hidden_cols]
    result=[]
    covered=set()
    for a in anchors:
        rr=[r for r in rows[a['r']:a['r']+a['rs']] if r in vr]
        cc=[c for c in cols[a['c']:a['c']+a['cs']] if c in vc]
        if not rr or not cc: continue
        cells={(r,c) for r in rr for c in cc}
        if cells & covered: continue
        covered |= cells
        result.append({'anchor':[rr[0],cc[0]],'rowspan':len(rr),'colspan':len(cc),'value':a['value'],'covered':sorted(cells-{(rr[0],cc[0])})})
    return {'merges':result,'plain':[(r,c) for r in vr for c in vc if (r,c) not in covered]}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('nonzero origin', solve(['r0','r1','r2','r3'], ['a','b','c','d'], [{'r':1,'c':1,'rs':2,'cs':2,'value':1}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 2, 'colspan': 2, 'value': 1, 'covered': [('r1', 'c'), ('r2', 'b'), ('r2', 'c')]}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r0', 'c'), ('r0', 'd'), ('r1', 'a'), ('r1', 'd'), ('r2', 'a'), ('r2', 'd'), ('r3', 'a'), ('r3', 'b'), ('r3', 'c'), ('r3', 'd')]})
    check('hidden anchor', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':3,'cs':3,'value':'x'}], ['r0','r1'], ['a','b']), {'merges': [{'anchor': ['r2', 'c'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': []})
    check('partial overlap', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':2,'cs':2,'value':'x'},{'r':1,'c':1,'rs':2,'cs':2,'value':'y'}], [], []), {'merges': [{'anchor': ['r0', 'a'], 'rowspan': 2, 'colspan': 2, 'value': 'x', 'covered': [('r0', 'b'), ('r1', 'a'), ('r1', 'b')]}], 'plain': [('r0', 'c'), ('r1', 'c'), ('r2', 'a'), ('r2', 'b'), ('r2', 'c')]})
    check('hidden merge', solve(['r0'], ['a'], [{'r':0,'c':0,'rs':1,'cs':1,'value':'x'}], ['r0'], []), {'merges': [], 'plain': []})
    check('clamped span', solve(['r0','r1'], ['a','b'], [{'r':1,'c':1,'rs':4,'cs':4,'value':'x'}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a')]})
    check('unmerged grid', solve(['r0','r1'], ['a','b'], [], [], []), {'merges': [], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a'), ('r1', 'b')]})

if N == 2:
    check('nonzero origin', solve(['r0','r1','r2','r3'], ['a','b','c','d'], [{'r':1,'c':1,'rs':2,'cs':2,'value':2}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 2, 'colspan': 2, 'value': 2, 'covered': [('r1', 'c'), ('r2', 'b'), ('r2', 'c')]}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r0', 'c'), ('r0', 'd'), ('r1', 'a'), ('r1', 'd'), ('r2', 'a'), ('r2', 'd'), ('r3', 'a'), ('r3', 'b'), ('r3', 'c'), ('r3', 'd')]})
    check('hidden anchor', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':3,'cs':3,'value':'x'}], ['r0','r1'], ['a','b']), {'merges': [{'anchor': ['r2', 'c'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': []})
    check('partial overlap', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':2,'cs':2,'value':'x'},{'r':1,'c':1,'rs':2,'cs':2,'value':'y'}], [], []), {'merges': [{'anchor': ['r0', 'a'], 'rowspan': 2, 'colspan': 2, 'value': 'x', 'covered': [('r0', 'b'), ('r1', 'a'), ('r1', 'b')]}], 'plain': [('r0', 'c'), ('r1', 'c'), ('r2', 'a'), ('r2', 'b'), ('r2', 'c')]})
    check('hidden merge', solve(['r0'], ['a'], [{'r':0,'c':0,'rs':1,'cs':1,'value':'x'}], ['r0'], []), {'merges': [], 'plain': []})
    check('clamped span', solve(['r0','r1'], ['a','b'], [{'r':1,'c':1,'rs':4,'cs':4,'value':'x'}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a')]})
    check('unmerged grid', solve(['r0','r1'], ['a','b'], [], [], []), {'merges': [], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a'), ('r1', 'b')]})

if N == 3:
    check('nonzero origin', solve(['r0','r1','r2','r3'], ['a','b','c','d'], [{'r':1,'c':1,'rs':2,'cs':2,'value':3}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 2, 'colspan': 2, 'value': 3, 'covered': [('r1', 'c'), ('r2', 'b'), ('r2', 'c')]}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r0', 'c'), ('r0', 'd'), ('r1', 'a'), ('r1', 'd'), ('r2', 'a'), ('r2', 'd'), ('r3', 'a'), ('r3', 'b'), ('r3', 'c'), ('r3', 'd')]})
    check('hidden anchor', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':3,'cs':3,'value':'x'}], ['r0','r1'], ['a','b']), {'merges': [{'anchor': ['r2', 'c'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': []})
    check('partial overlap', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':2,'cs':2,'value':'x'},{'r':1,'c':1,'rs':2,'cs':2,'value':'y'}], [], []), {'merges': [{'anchor': ['r0', 'a'], 'rowspan': 2, 'colspan': 2, 'value': 'x', 'covered': [('r0', 'b'), ('r1', 'a'), ('r1', 'b')]}], 'plain': [('r0', 'c'), ('r1', 'c'), ('r2', 'a'), ('r2', 'b'), ('r2', 'c')]})
    check('hidden merge', solve(['r0'], ['a'], [{'r':0,'c':0,'rs':1,'cs':1,'value':'x'}], ['r0'], []), {'merges': [], 'plain': []})
    check('clamped span', solve(['r0','r1'], ['a','b'], [{'r':1,'c':1,'rs':4,'cs':4,'value':'x'}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a')]})
    check('unmerged grid', solve(['r0','r1'], ['a','b'], [], [], []), {'merges': [], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a'), ('r1', 'b')]})

if N == 4:
    check('nonzero origin', solve(['r0','r1','r2','r3'], ['a','b','c','d'], [{'r':1,'c':1,'rs':2,'cs':2,'value':4}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 2, 'colspan': 2, 'value': 4, 'covered': [('r1', 'c'), ('r2', 'b'), ('r2', 'c')]}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r0', 'c'), ('r0', 'd'), ('r1', 'a'), ('r1', 'd'), ('r2', 'a'), ('r2', 'd'), ('r3', 'a'), ('r3', 'b'), ('r3', 'c'), ('r3', 'd')]})
    check('hidden anchor', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':3,'cs':3,'value':'x'}], ['r0','r1'], ['a','b']), {'merges': [{'anchor': ['r2', 'c'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': []})
    check('partial overlap', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':2,'cs':2,'value':'x'},{'r':1,'c':1,'rs':2,'cs':2,'value':'y'}], [], []), {'merges': [{'anchor': ['r0', 'a'], 'rowspan': 2, 'colspan': 2, 'value': 'x', 'covered': [('r0', 'b'), ('r1', 'a'), ('r1', 'b')]}], 'plain': [('r0', 'c'), ('r1', 'c'), ('r2', 'a'), ('r2', 'b'), ('r2', 'c')]})
    check('hidden merge', solve(['r0'], ['a'], [{'r':0,'c':0,'rs':1,'cs':1,'value':'x'}], ['r0'], []), {'merges': [], 'plain': []})
    check('clamped span', solve(['r0','r1'], ['a','b'], [{'r':1,'c':1,'rs':4,'cs':4,'value':'x'}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a')]})
    check('unmerged grid', solve(['r0','r1'], ['a','b'], [], [], []), {'merges': [], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a'), ('r1', 'b')]})

if N == 5:
    check('nonzero origin', solve(['r0','r1','r2','r3'], ['a','b','c','d'], [{'r':1,'c':1,'rs':2,'cs':2,'value':5}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 2, 'colspan': 2, 'value': 5, 'covered': [('r1', 'c'), ('r2', 'b'), ('r2', 'c')]}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r0', 'c'), ('r0', 'd'), ('r1', 'a'), ('r1', 'd'), ('r2', 'a'), ('r2', 'd'), ('r3', 'a'), ('r3', 'b'), ('r3', 'c'), ('r3', 'd')]})
    check('hidden anchor', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':3,'cs':3,'value':'x'}], ['r0','r1'], ['a','b']), {'merges': [{'anchor': ['r2', 'c'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': []})
    check('partial overlap', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':2,'cs':2,'value':'x'},{'r':1,'c':1,'rs':2,'cs':2,'value':'y'}], [], []), {'merges': [{'anchor': ['r0', 'a'], 'rowspan': 2, 'colspan': 2, 'value': 'x', 'covered': [('r0', 'b'), ('r1', 'a'), ('r1', 'b')]}], 'plain': [('r0', 'c'), ('r1', 'c'), ('r2', 'a'), ('r2', 'b'), ('r2', 'c')]})
    check('hidden merge', solve(['r0'], ['a'], [{'r':0,'c':0,'rs':1,'cs':1,'value':'x'}], ['r0'], []), {'merges': [], 'plain': []})
    check('clamped span', solve(['r0','r1'], ['a','b'], [{'r':1,'c':1,'rs':4,'cs':4,'value':'x'}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a')]})
    check('unmerged grid', solve(['r0','r1'], ['a','b'], [], [], []), {'merges': [], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a'), ('r1', 'b')]})

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(rows, cols, anchors, hidden_rows, hidden_cols):
    vr=[r for r in rows if r not in hidden_rows[:1]]
    vc=[c for c in cols if c not in hidden_cols]
    result=[]
    covered=set()
    for a in anchors:
        rr=[r for r in rows[a['r']:a['r']+a['rs']] if r in vr]
        cc=[c for c in cols[a['c']:a['c']+a['cs']] if c in vc]
        if not rr or not cc: continue
        cells={(r,c) for r in rr for c in cc}
        if cells & covered: continue
        covered |= cells
        result.append({'anchor':[rr[0],cc[0]],'rowspan':len(rr),'colspan':len(cc),'value':a['value'],'covered':sorted(cells-{(rr[0],cc[0])})})
    return {'merges':result,'plain':[(r,c) for r in vr for c in vc if (r,c) not in covered]}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('nonzero origin', solve(['r0','r1','r2','r3'], ['a','b','c','d'], [{'r':1,'c':1,'rs':2,'cs':2,'value':1}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 2, 'colspan': 2, 'value': 1, 'covered': [('r1', 'c'), ('r2', 'b'), ('r2', 'c')]}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r0', 'c'), ('r0', 'd'), ('r1', 'a'), ('r1', 'd'), ('r2', 'a'), ('r2', 'd'), ('r3', 'a'), ('r3', 'b'), ('r3', 'c'), ('r3', 'd')]})
    check('hidden anchor', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':3,'cs':3,'value':'x'}], ['r0','r1'], ['a','b']), {'merges': [{'anchor': ['r2', 'c'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': []})
    check('partial overlap', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':2,'cs':2,'value':'x'},{'r':1,'c':1,'rs':2,'cs':2,'value':'y'}], [], []), {'merges': [{'anchor': ['r0', 'a'], 'rowspan': 2, 'colspan': 2, 'value': 'x', 'covered': [('r0', 'b'), ('r1', 'a'), ('r1', 'b')]}], 'plain': [('r0', 'c'), ('r1', 'c'), ('r2', 'a'), ('r2', 'b'), ('r2', 'c')]})
    check('hidden merge', solve(['r0'], ['a'], [{'r':0,'c':0,'rs':1,'cs':1,'value':'x'}], ['r0'], []), {'merges': [], 'plain': []})
    check('clamped span', solve(['r0','r1'], ['a','b'], [{'r':1,'c':1,'rs':4,'cs':4,'value':'x'}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a')]})
    check('unmerged grid', solve(['r0','r1'], ['a','b'], [], [], []), {'merges': [], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a'), ('r1', 'b')]})

if N == 2:
    check('nonzero origin', solve(['r0','r1','r2','r3'], ['a','b','c','d'], [{'r':1,'c':1,'rs':2,'cs':2,'value':2}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 2, 'colspan': 2, 'value': 2, 'covered': [('r1', 'c'), ('r2', 'b'), ('r2', 'c')]}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r0', 'c'), ('r0', 'd'), ('r1', 'a'), ('r1', 'd'), ('r2', 'a'), ('r2', 'd'), ('r3', 'a'), ('r3', 'b'), ('r3', 'c'), ('r3', 'd')]})
    check('hidden anchor', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':3,'cs':3,'value':'x'}], ['r0','r1'], ['a','b']), {'merges': [{'anchor': ['r2', 'c'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': []})
    check('partial overlap', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':2,'cs':2,'value':'x'},{'r':1,'c':1,'rs':2,'cs':2,'value':'y'}], [], []), {'merges': [{'anchor': ['r0', 'a'], 'rowspan': 2, 'colspan': 2, 'value': 'x', 'covered': [('r0', 'b'), ('r1', 'a'), ('r1', 'b')]}], 'plain': [('r0', 'c'), ('r1', 'c'), ('r2', 'a'), ('r2', 'b'), ('r2', 'c')]})
    check('hidden merge', solve(['r0'], ['a'], [{'r':0,'c':0,'rs':1,'cs':1,'value':'x'}], ['r0'], []), {'merges': [], 'plain': []})
    check('clamped span', solve(['r0','r1'], ['a','b'], [{'r':1,'c':1,'rs':4,'cs':4,'value':'x'}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a')]})
    check('unmerged grid', solve(['r0','r1'], ['a','b'], [], [], []), {'merges': [], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a'), ('r1', 'b')]})

if N == 3:
    check('nonzero origin', solve(['r0','r1','r2','r3'], ['a','b','c','d'], [{'r':1,'c':1,'rs':2,'cs':2,'value':3}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 2, 'colspan': 2, 'value': 3, 'covered': [('r1', 'c'), ('r2', 'b'), ('r2', 'c')]}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r0', 'c'), ('r0', 'd'), ('r1', 'a'), ('r1', 'd'), ('r2', 'a'), ('r2', 'd'), ('r3', 'a'), ('r3', 'b'), ('r3', 'c'), ('r3', 'd')]})
    check('hidden anchor', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':3,'cs':3,'value':'x'}], ['r0','r1'], ['a','b']), {'merges': [{'anchor': ['r2', 'c'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': []})
    check('partial overlap', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':2,'cs':2,'value':'x'},{'r':1,'c':1,'rs':2,'cs':2,'value':'y'}], [], []), {'merges': [{'anchor': ['r0', 'a'], 'rowspan': 2, 'colspan': 2, 'value': 'x', 'covered': [('r0', 'b'), ('r1', 'a'), ('r1', 'b')]}], 'plain': [('r0', 'c'), ('r1', 'c'), ('r2', 'a'), ('r2', 'b'), ('r2', 'c')]})
    check('hidden merge', solve(['r0'], ['a'], [{'r':0,'c':0,'rs':1,'cs':1,'value':'x'}], ['r0'], []), {'merges': [], 'plain': []})
    check('clamped span', solve(['r0','r1'], ['a','b'], [{'r':1,'c':1,'rs':4,'cs':4,'value':'x'}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a')]})
    check('unmerged grid', solve(['r0','r1'], ['a','b'], [], [], []), {'merges': [], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a'), ('r1', 'b')]})

if N == 4:
    check('nonzero origin', solve(['r0','r1','r2','r3'], ['a','b','c','d'], [{'r':1,'c':1,'rs':2,'cs':2,'value':4}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 2, 'colspan': 2, 'value': 4, 'covered': [('r1', 'c'), ('r2', 'b'), ('r2', 'c')]}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r0', 'c'), ('r0', 'd'), ('r1', 'a'), ('r1', 'd'), ('r2', 'a'), ('r2', 'd'), ('r3', 'a'), ('r3', 'b'), ('r3', 'c'), ('r3', 'd')]})
    check('hidden anchor', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':3,'cs':3,'value':'x'}], ['r0','r1'], ['a','b']), {'merges': [{'anchor': ['r2', 'c'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': []})
    check('partial overlap', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':2,'cs':2,'value':'x'},{'r':1,'c':1,'rs':2,'cs':2,'value':'y'}], [], []), {'merges': [{'anchor': ['r0', 'a'], 'rowspan': 2, 'colspan': 2, 'value': 'x', 'covered': [('r0', 'b'), ('r1', 'a'), ('r1', 'b')]}], 'plain': [('r0', 'c'), ('r1', 'c'), ('r2', 'a'), ('r2', 'b'), ('r2', 'c')]})
    check('hidden merge', solve(['r0'], ['a'], [{'r':0,'c':0,'rs':1,'cs':1,'value':'x'}], ['r0'], []), {'merges': [], 'plain': []})
    check('clamped span', solve(['r0','r1'], ['a','b'], [{'r':1,'c':1,'rs':4,'cs':4,'value':'x'}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a')]})
    check('unmerged grid', solve(['r0','r1'], ['a','b'], [], [], []), {'merges': [], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a'), ('r1', 'b')]})

if N == 5:
    check('nonzero origin', solve(['r0','r1','r2','r3'], ['a','b','c','d'], [{'r':1,'c':1,'rs':2,'cs':2,'value':5}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 2, 'colspan': 2, 'value': 5, 'covered': [('r1', 'c'), ('r2', 'b'), ('r2', 'c')]}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r0', 'c'), ('r0', 'd'), ('r1', 'a'), ('r1', 'd'), ('r2', 'a'), ('r2', 'd'), ('r3', 'a'), ('r3', 'b'), ('r3', 'c'), ('r3', 'd')]})
    check('hidden anchor', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':3,'cs':3,'value':'x'}], ['r0','r1'], ['a','b']), {'merges': [{'anchor': ['r2', 'c'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': []})
    check('partial overlap', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':2,'cs':2,'value':'x'},{'r':1,'c':1,'rs':2,'cs':2,'value':'y'}], [], []), {'merges': [{'anchor': ['r0', 'a'], 'rowspan': 2, 'colspan': 2, 'value': 'x', 'covered': [('r0', 'b'), ('r1', 'a'), ('r1', 'b')]}], 'plain': [('r0', 'c'), ('r1', 'c'), ('r2', 'a'), ('r2', 'b'), ('r2', 'c')]})
    check('hidden merge', solve(['r0'], ['a'], [{'r':0,'c':0,'rs':1,'cs':1,'value':'x'}], ['r0'], []), {'merges': [], 'plain': []})
    check('clamped span', solve(['r0','r1'], ['a','b'], [{'r':1,'c':1,'rs':4,'cs':4,'value':'x'}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a')]})
    check('unmerged grid', solve(['r0','r1'], ['a','b'], [], [], []), {'merges': [], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a'), ('r1', 'b')]})

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 row visibility result violates the stipulated merged cell rendering contract.

Merged rectangles are expressed in source coordinates, clipped to source bounds and visible rows/columns, rebased to the first visible cell, and accepted in declaration order only if disjoint; plain cells omit every accepted merged cell.

split: open-access


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

N = 1
observations = []
def solve(rows, cols, anchors, hidden_rows, hidden_cols):
    vr=[r for r in rows if r not in hidden_rows]
    vc=[c for c in cols if True]
    result=[]
    covered=set()
    for a in anchors:
        rr=[r for r in rows[a['r']:a['r']+a['rs']] if r in vr]
        cc=[c for c in cols[a['c']:a['c']+a['cs']] if c in vc]
        if not rr or not cc: continue
        cells={(r,c) for r in rr for c in cc}
        if cells & covered: continue
        covered |= cells
        result.append({'anchor':[rr[0],cc[0]],'rowspan':len(rr),'colspan':len(cc),'value':a['value'],'covered':sorted(cells-{(rr[0],cc[0])})})
    return {'merges':result,'plain':[(r,c) for r in vr for c in vc if (r,c) not in covered]}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('nonzero origin', solve(['r0','r1','r2','r3'], ['a','b','c','d'], [{'r':1,'c':1,'rs':2,'cs':2,'value':1}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 2, 'colspan': 2, 'value': 1, 'covered': [('r1', 'c'), ('r2', 'b'), ('r2', 'c')]}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r0', 'c'), ('r0', 'd'), ('r1', 'a'), ('r1', 'd'), ('r2', 'a'), ('r2', 'd'), ('r3', 'a'), ('r3', 'b'), ('r3', 'c'), ('r3', 'd')]})
    check('hidden anchor', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':3,'cs':3,'value':'x'}], ['r0','r1'], ['a','b']), {'merges': [{'anchor': ['r2', 'c'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': []})
    check('partial overlap', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':2,'cs':2,'value':'x'},{'r':1,'c':1,'rs':2,'cs':2,'value':'y'}], [], []), {'merges': [{'anchor': ['r0', 'a'], 'rowspan': 2, 'colspan': 2, 'value': 'x', 'covered': [('r0', 'b'), ('r1', 'a'), ('r1', 'b')]}], 'plain': [('r0', 'c'), ('r1', 'c'), ('r2', 'a'), ('r2', 'b'), ('r2', 'c')]})
    check('hidden merge', solve(['r0'], ['a'], [{'r':0,'c':0,'rs':1,'cs':1,'value':'x'}], ['r0'], []), {'merges': [], 'plain': []})
    check('clamped span', solve(['r0','r1'], ['a','b'], [{'r':1,'c':1,'rs':4,'cs':4,'value':'x'}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a')]})
    check('unmerged grid', solve(['r0','r1'], ['a','b'], [], [], []), {'merges': [], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a'), ('r1', 'b')]})

if N == 2:
    check('nonzero origin', solve(['r0','r1','r2','r3'], ['a','b','c','d'], [{'r':1,'c':1,'rs':2,'cs':2,'value':2}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 2, 'colspan': 2, 'value': 2, 'covered': [('r1', 'c'), ('r2', 'b'), ('r2', 'c')]}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r0', 'c'), ('r0', 'd'), ('r1', 'a'), ('r1', 'd'), ('r2', 'a'), ('r2', 'd'), ('r3', 'a'), ('r3', 'b'), ('r3', 'c'), ('r3', 'd')]})
    check('hidden anchor', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':3,'cs':3,'value':'x'}], ['r0','r1'], ['a','b']), {'merges': [{'anchor': ['r2', 'c'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': []})
    check('partial overlap', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':2,'cs':2,'value':'x'},{'r':1,'c':1,'rs':2,'cs':2,'value':'y'}], [], []), {'merges': [{'anchor': ['r0', 'a'], 'rowspan': 2, 'colspan': 2, 'value': 'x', 'covered': [('r0', 'b'), ('r1', 'a'), ('r1', 'b')]}], 'plain': [('r0', 'c'), ('r1', 'c'), ('r2', 'a'), ('r2', 'b'), ('r2', 'c')]})
    check('hidden merge', solve(['r0'], ['a'], [{'r':0,'c':0,'rs':1,'cs':1,'value':'x'}], ['r0'], []), {'merges': [], 'plain': []})
    check('clamped span', solve(['r0','r1'], ['a','b'], [{'r':1,'c':1,'rs':4,'cs':4,'value':'x'}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a')]})
    check('unmerged grid', solve(['r0','r1'], ['a','b'], [], [], []), {'merges': [], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a'), ('r1', 'b')]})

if N == 3:
    check('nonzero origin', solve(['r0','r1','r2','r3'], ['a','b','c','d'], [{'r':1,'c':1,'rs':2,'cs':2,'value':3}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 2, 'colspan': 2, 'value': 3, 'covered': [('r1', 'c'), ('r2', 'b'), ('r2', 'c')]}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r0', 'c'), ('r0', 'd'), ('r1', 'a'), ('r1', 'd'), ('r2', 'a'), ('r2', 'd'), ('r3', 'a'), ('r3', 'b'), ('r3', 'c'), ('r3', 'd')]})
    check('hidden anchor', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':3,'cs':3,'value':'x'}], ['r0','r1'], ['a','b']), {'merges': [{'anchor': ['r2', 'c'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': []})
    check('partial overlap', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':2,'cs':2,'value':'x'},{'r':1,'c':1,'rs':2,'cs':2,'value':'y'}], [], []), {'merges': [{'anchor': ['r0', 'a'], 'rowspan': 2, 'colspan': 2, 'value': 'x', 'covered': [('r0', 'b'), ('r1', 'a'), ('r1', 'b')]}], 'plain': [('r0', 'c'), ('r1', 'c'), ('r2', 'a'), ('r2', 'b'), ('r2', 'c')]})
    check('hidden merge', solve(['r0'], ['a'], [{'r':0,'c':0,'rs':1,'cs':1,'value':'x'}], ['r0'], []), {'merges': [], 'plain': []})
    check('clamped span', solve(['r0','r1'], ['a','b'], [{'r':1,'c':1,'rs':4,'cs':4,'value':'x'}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a')]})
    check('unmerged grid', solve(['r0','r1'], ['a','b'], [], [], []), {'merges': [], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a'), ('r1', 'b')]})

if N == 4:
    check('nonzero origin', solve(['r0','r1','r2','r3'], ['a','b','c','d'], [{'r':1,'c':1,'rs':2,'cs':2,'value':4}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 2, 'colspan': 2, 'value': 4, 'covered': [('r1', 'c'), ('r2', 'b'), ('r2', 'c')]}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r0', 'c'), ('r0', 'd'), ('r1', 'a'), ('r1', 'd'), ('r2', 'a'), ('r2', 'd'), ('r3', 'a'), ('r3', 'b'), ('r3', 'c'), ('r3', 'd')]})
    check('hidden anchor', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':3,'cs':3,'value':'x'}], ['r0','r1'], ['a','b']), {'merges': [{'anchor': ['r2', 'c'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': []})
    check('partial overlap', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':2,'cs':2,'value':'x'},{'r':1,'c':1,'rs':2,'cs':2,'value':'y'}], [], []), {'merges': [{'anchor': ['r0', 'a'], 'rowspan': 2, 'colspan': 2, 'value': 'x', 'covered': [('r0', 'b'), ('r1', 'a'), ('r1', 'b')]}], 'plain': [('r0', 'c'), ('r1', 'c'), ('r2', 'a'), ('r2', 'b'), ('r2', 'c')]})
    check('hidden merge', solve(['r0'], ['a'], [{'r':0,'c':0,'rs':1,'cs':1,'value':'x'}], ['r0'], []), {'merges': [], 'plain': []})
    check('clamped span', solve(['r0','r1'], ['a','b'], [{'r':1,'c':1,'rs':4,'cs':4,'value':'x'}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a')]})
    check('unmerged grid', solve(['r0','r1'], ['a','b'], [], [], []), {'merges': [], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a'), ('r1', 'b')]})

if N == 5:
    check('nonzero origin', solve(['r0','r1','r2','r3'], ['a','b','c','d'], [{'r':1,'c':1,'rs':2,'cs':2,'value':5}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 2, 'colspan': 2, 'value': 5, 'covered': [('r1', 'c'), ('r2', 'b'), ('r2', 'c')]}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r0', 'c'), ('r0', 'd'), ('r1', 'a'), ('r1', 'd'), ('r2', 'a'), ('r2', 'd'), ('r3', 'a'), ('r3', 'b'), ('r3', 'c'), ('r3', 'd')]})
    check('hidden anchor', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':3,'cs':3,'value':'x'}], ['r0','r1'], ['a','b']), {'merges': [{'anchor': ['r2', 'c'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': []})
    check('partial overlap', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':2,'cs':2,'value':'x'},{'r':1,'c':1,'rs':2,'cs':2,'value':'y'}], [], []), {'merges': [{'anchor': ['r0', 'a'], 'rowspan': 2, 'colspan': 2, 'value': 'x', 'covered': [('r0', 'b'), ('r1', 'a'), ('r1', 'b')]}], 'plain': [('r0', 'c'), ('r1', 'c'), ('r2', 'a'), ('r2', 'b'), ('r2', 'c')]})
    check('hidden merge', solve(['r0'], ['a'], [{'r':0,'c':0,'rs':1,'cs':1,'value':'x'}], ['r0'], []), {'merges': [], 'plain': []})
    check('clamped span', solve(['r0','r1'], ['a','b'], [{'r':1,'c':1,'rs':4,'cs':4,'value':'x'}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a')]})
    check('unmerged grid', solve(['r0','r1'], ['a','b'], [], [], []), {'merges': [], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a'), ('r1', 'b')]})

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, cols, anchors, hidden_rows, hidden_cols):
    vr=[r for r in rows if r not in hidden_rows]
    vc=[c for c in cols if c not in hidden_cols[:1]]
    result=[]
    covered=set()
    for a in anchors:
        rr=[r for r in rows[a['r']:a['r']+a['rs']] if r in vr]
        cc=[c for c in cols[a['c']:a['c']+a['cs']] if c in vc]
        if not rr or not cc: continue
        cells={(r,c) for r in rr for c in cc}
        if cells & covered: continue
        covered |= cells
        result.append({'anchor':[rr[0],cc[0]],'rowspan':len(rr),'colspan':len(cc),'value':a['value'],'covered':sorted(cells-{(rr[0],cc[0])})})
    return {'merges':result,'plain':[(r,c) for r in vr for c in vc if (r,c) not in covered]}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('nonzero origin', solve(['r0','r1','r2','r3'], ['a','b','c','d'], [{'r':1,'c':1,'rs':2,'cs':2,'value':1}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 2, 'colspan': 2, 'value': 1, 'covered': [('r1', 'c'), ('r2', 'b'), ('r2', 'c')]}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r0', 'c'), ('r0', 'd'), ('r1', 'a'), ('r1', 'd'), ('r2', 'a'), ('r2', 'd'), ('r3', 'a'), ('r3', 'b'), ('r3', 'c'), ('r3', 'd')]})
    check('hidden anchor', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':3,'cs':3,'value':'x'}], ['r0','r1'], ['a','b']), {'merges': [{'anchor': ['r2', 'c'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': []})
    check('partial overlap', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':2,'cs':2,'value':'x'},{'r':1,'c':1,'rs':2,'cs':2,'value':'y'}], [], []), {'merges': [{'anchor': ['r0', 'a'], 'rowspan': 2, 'colspan': 2, 'value': 'x', 'covered': [('r0', 'b'), ('r1', 'a'), ('r1', 'b')]}], 'plain': [('r0', 'c'), ('r1', 'c'), ('r2', 'a'), ('r2', 'b'), ('r2', 'c')]})
    check('hidden merge', solve(['r0'], ['a'], [{'r':0,'c':0,'rs':1,'cs':1,'value':'x'}], ['r0'], []), {'merges': [], 'plain': []})
    check('clamped span', solve(['r0','r1'], ['a','b'], [{'r':1,'c':1,'rs':4,'cs':4,'value':'x'}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a')]})
    check('unmerged grid', solve(['r0','r1'], ['a','b'], [], [], []), {'merges': [], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a'), ('r1', 'b')]})

if N == 2:
    check('nonzero origin', solve(['r0','r1','r2','r3'], ['a','b','c','d'], [{'r':1,'c':1,'rs':2,'cs':2,'value':2}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 2, 'colspan': 2, 'value': 2, 'covered': [('r1', 'c'), ('r2', 'b'), ('r2', 'c')]}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r0', 'c'), ('r0', 'd'), ('r1', 'a'), ('r1', 'd'), ('r2', 'a'), ('r2', 'd'), ('r3', 'a'), ('r3', 'b'), ('r3', 'c'), ('r3', 'd')]})
    check('hidden anchor', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':3,'cs':3,'value':'x'}], ['r0','r1'], ['a','b']), {'merges': [{'anchor': ['r2', 'c'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': []})
    check('partial overlap', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':2,'cs':2,'value':'x'},{'r':1,'c':1,'rs':2,'cs':2,'value':'y'}], [], []), {'merges': [{'anchor': ['r0', 'a'], 'rowspan': 2, 'colspan': 2, 'value': 'x', 'covered': [('r0', 'b'), ('r1', 'a'), ('r1', 'b')]}], 'plain': [('r0', 'c'), ('r1', 'c'), ('r2', 'a'), ('r2', 'b'), ('r2', 'c')]})
    check('hidden merge', solve(['r0'], ['a'], [{'r':0,'c':0,'rs':1,'cs':1,'value':'x'}], ['r0'], []), {'merges': [], 'plain': []})
    check('clamped span', solve(['r0','r1'], ['a','b'], [{'r':1,'c':1,'rs':4,'cs':4,'value':'x'}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a')]})
    check('unmerged grid', solve(['r0','r1'], ['a','b'], [], [], []), {'merges': [], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a'), ('r1', 'b')]})

if N == 3:
    check('nonzero origin', solve(['r0','r1','r2','r3'], ['a','b','c','d'], [{'r':1,'c':1,'rs':2,'cs':2,'value':3}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 2, 'colspan': 2, 'value': 3, 'covered': [('r1', 'c'), ('r2', 'b'), ('r2', 'c')]}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r0', 'c'), ('r0', 'd'), ('r1', 'a'), ('r1', 'd'), ('r2', 'a'), ('r2', 'd'), ('r3', 'a'), ('r3', 'b'), ('r3', 'c'), ('r3', 'd')]})
    check('hidden anchor', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':3,'cs':3,'value':'x'}], ['r0','r1'], ['a','b']), {'merges': [{'anchor': ['r2', 'c'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': []})
    check('partial overlap', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':2,'cs':2,'value':'x'},{'r':1,'c':1,'rs':2,'cs':2,'value':'y'}], [], []), {'merges': [{'anchor': ['r0', 'a'], 'rowspan': 2, 'colspan': 2, 'value': 'x', 'covered': [('r0', 'b'), ('r1', 'a'), ('r1', 'b')]}], 'plain': [('r0', 'c'), ('r1', 'c'), ('r2', 'a'), ('r2', 'b'), ('r2', 'c')]})
    check('hidden merge', solve(['r0'], ['a'], [{'r':0,'c':0,'rs':1,'cs':1,'value':'x'}], ['r0'], []), {'merges': [], 'plain': []})
    check('clamped span', solve(['r0','r1'], ['a','b'], [{'r':1,'c':1,'rs':4,'cs':4,'value':'x'}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a')]})
    check('unmerged grid', solve(['r0','r1'], ['a','b'], [], [], []), {'merges': [], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a'), ('r1', 'b')]})

if N == 4:
    check('nonzero origin', solve(['r0','r1','r2','r3'], ['a','b','c','d'], [{'r':1,'c':1,'rs':2,'cs':2,'value':4}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 2, 'colspan': 2, 'value': 4, 'covered': [('r1', 'c'), ('r2', 'b'), ('r2', 'c')]}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r0', 'c'), ('r0', 'd'), ('r1', 'a'), ('r1', 'd'), ('r2', 'a'), ('r2', 'd'), ('r3', 'a'), ('r3', 'b'), ('r3', 'c'), ('r3', 'd')]})
    check('hidden anchor', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':3,'cs':3,'value':'x'}], ['r0','r1'], ['a','b']), {'merges': [{'anchor': ['r2', 'c'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': []})
    check('partial overlap', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':2,'cs':2,'value':'x'},{'r':1,'c':1,'rs':2,'cs':2,'value':'y'}], [], []), {'merges': [{'anchor': ['r0', 'a'], 'rowspan': 2, 'colspan': 2, 'value': 'x', 'covered': [('r0', 'b'), ('r1', 'a'), ('r1', 'b')]}], 'plain': [('r0', 'c'), ('r1', 'c'), ('r2', 'a'), ('r2', 'b'), ('r2', 'c')]})
    check('hidden merge', solve(['r0'], ['a'], [{'r':0,'c':0,'rs':1,'cs':1,'value':'x'}], ['r0'], []), {'merges': [], 'plain': []})
    check('clamped span', solve(['r0','r1'], ['a','b'], [{'r':1,'c':1,'rs':4,'cs':4,'value':'x'}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a')]})
    check('unmerged grid', solve(['r0','r1'], ['a','b'], [], [], []), {'merges': [], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a'), ('r1', 'b')]})

if N == 5:
    check('nonzero origin', solve(['r0','r1','r2','r3'], ['a','b','c','d'], [{'r':1,'c':1,'rs':2,'cs':2,'value':5}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 2, 'colspan': 2, 'value': 5, 'covered': [('r1', 'c'), ('r2', 'b'), ('r2', 'c')]}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r0', 'c'), ('r0', 'd'), ('r1', 'a'), ('r1', 'd'), ('r2', 'a'), ('r2', 'd'), ('r3', 'a'), ('r3', 'b'), ('r3', 'c'), ('r3', 'd')]})
    check('hidden anchor', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':3,'cs':3,'value':'x'}], ['r0','r1'], ['a','b']), {'merges': [{'anchor': ['r2', 'c'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': []})
    check('partial overlap', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':2,'cs':2,'value':'x'},{'r':1,'c':1,'rs':2,'cs':2,'value':'y'}], [], []), {'merges': [{'anchor': ['r0', 'a'], 'rowspan': 2, 'colspan': 2, 'value': 'x', 'covered': [('r0', 'b'), ('r1', 'a'), ('r1', 'b')]}], 'plain': [('r0', 'c'), ('r1', 'c'), ('r2', 'a'), ('r2', 'b'), ('r2', 'c')]})
    check('hidden merge', solve(['r0'], ['a'], [{'r':0,'c':0,'rs':1,'cs':1,'value':'x'}], ['r0'], []), {'merges': [], 'plain': []})
    check('clamped span', solve(['r0','r1'], ['a','b'], [{'r':1,'c':1,'rs':4,'cs':4,'value':'x'}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a')]})
    check('unmerged grid', solve(['r0','r1'], ['a','b'], [], [], []), {'merges': [], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a'), ('r1', 'b')]})

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 column visibility result violates the stipulated merged cell rendering contract.

Merged rectangles are expressed in source coordinates, clipped to source bounds and visible rows/columns, rebased to the first visible cell, and accepted in declaration order only if disjoint; plain cells omit every accepted merged cell.

split: open-access


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

N = 1
observations = []
def solve(rows, cols, anchors, hidden_rows, hidden_cols):
    vr=[r for r in rows if r not in hidden_rows]
    vc=[c for c in cols if c not in hidden_cols]
    result=[]
    covered=set()
    for a in anchors:
        rr=[r for r in rows[a['r']:a['rs']] if r in vr]
        cc=[c for c in cols[a['c']:a['c']+a['cs']] if c in vc]
        if not rr or not cc: continue
        cells={(r,c) for r in rr for c in cc}
        if cells & covered: continue
        covered |= cells
        result.append({'anchor':[rr[0],cc[0]],'rowspan':len(rr),'colspan':len(cc),'value':a['value'],'covered':sorted(cells-{(rr[0],cc[0])})})
    return {'merges':result,'plain':[(r,c) for r in vr for c in vc if (r,c) not in covered]}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('nonzero origin', solve(['r0','r1','r2','r3'], ['a','b','c','d'], [{'r':1,'c':1,'rs':2,'cs':2,'value':1}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 2, 'colspan': 2, 'value': 1, 'covered': [('r1', 'c'), ('r2', 'b'), ('r2', 'c')]}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r0', 'c'), ('r0', 'd'), ('r1', 'a'), ('r1', 'd'), ('r2', 'a'), ('r2', 'd'), ('r3', 'a'), ('r3', 'b'), ('r3', 'c'), ('r3', 'd')]})
    check('hidden anchor', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':3,'cs':3,'value':'x'}], ['r0','r1'], ['a','b']), {'merges': [{'anchor': ['r2', 'c'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': []})
    check('partial overlap', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':2,'cs':2,'value':'x'},{'r':1,'c':1,'rs':2,'cs':2,'value':'y'}], [], []), {'merges': [{'anchor': ['r0', 'a'], 'rowspan': 2, 'colspan': 2, 'value': 'x', 'covered': [('r0', 'b'), ('r1', 'a'), ('r1', 'b')]}], 'plain': [('r0', 'c'), ('r1', 'c'), ('r2', 'a'), ('r2', 'b'), ('r2', 'c')]})
    check('hidden merge', solve(['r0'], ['a'], [{'r':0,'c':0,'rs':1,'cs':1,'value':'x'}], ['r0'], []), {'merges': [], 'plain': []})
    check('clamped span', solve(['r0','r1'], ['a','b'], [{'r':1,'c':1,'rs':4,'cs':4,'value':'x'}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a')]})
    check('unmerged grid', solve(['r0','r1'], ['a','b'], [], [], []), {'merges': [], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a'), ('r1', 'b')]})

if N == 2:
    check('nonzero origin', solve(['r0','r1','r2','r3'], ['a','b','c','d'], [{'r':1,'c':1,'rs':2,'cs':2,'value':2}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 2, 'colspan': 2, 'value': 2, 'covered': [('r1', 'c'), ('r2', 'b'), ('r2', 'c')]}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r0', 'c'), ('r0', 'd'), ('r1', 'a'), ('r1', 'd'), ('r2', 'a'), ('r2', 'd'), ('r3', 'a'), ('r3', 'b'), ('r3', 'c'), ('r3', 'd')]})
    check('hidden anchor', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':3,'cs':3,'value':'x'}], ['r0','r1'], ['a','b']), {'merges': [{'anchor': ['r2', 'c'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': []})
    check('partial overlap', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':2,'cs':2,'value':'x'},{'r':1,'c':1,'rs':2,'cs':2,'value':'y'}], [], []), {'merges': [{'anchor': ['r0', 'a'], 'rowspan': 2, 'colspan': 2, 'value': 'x', 'covered': [('r0', 'b'), ('r1', 'a'), ('r1', 'b')]}], 'plain': [('r0', 'c'), ('r1', 'c'), ('r2', 'a'), ('r2', 'b'), ('r2', 'c')]})
    check('hidden merge', solve(['r0'], ['a'], [{'r':0,'c':0,'rs':1,'cs':1,'value':'x'}], ['r0'], []), {'merges': [], 'plain': []})
    check('clamped span', solve(['r0','r1'], ['a','b'], [{'r':1,'c':1,'rs':4,'cs':4,'value':'x'}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a')]})
    check('unmerged grid', solve(['r0','r1'], ['a','b'], [], [], []), {'merges': [], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a'), ('r1', 'b')]})

if N == 3:
    check('nonzero origin', solve(['r0','r1','r2','r3'], ['a','b','c','d'], [{'r':1,'c':1,'rs':2,'cs':2,'value':3}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 2, 'colspan': 2, 'value': 3, 'covered': [('r1', 'c'), ('r2', 'b'), ('r2', 'c')]}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r0', 'c'), ('r0', 'd'), ('r1', 'a'), ('r1', 'd'), ('r2', 'a'), ('r2', 'd'), ('r3', 'a'), ('r3', 'b'), ('r3', 'c'), ('r3', 'd')]})
    check('hidden anchor', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':3,'cs':3,'value':'x'}], ['r0','r1'], ['a','b']), {'merges': [{'anchor': ['r2', 'c'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': []})
    check('partial overlap', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':2,'cs':2,'value':'x'},{'r':1,'c':1,'rs':2,'cs':2,'value':'y'}], [], []), {'merges': [{'anchor': ['r0', 'a'], 'rowspan': 2, 'colspan': 2, 'value': 'x', 'covered': [('r0', 'b'), ('r1', 'a'), ('r1', 'b')]}], 'plain': [('r0', 'c'), ('r1', 'c'), ('r2', 'a'), ('r2', 'b'), ('r2', 'c')]})
    check('hidden merge', solve(['r0'], ['a'], [{'r':0,'c':0,'rs':1,'cs':1,'value':'x'}], ['r0'], []), {'merges': [], 'plain': []})
    check('clamped span', solve(['r0','r1'], ['a','b'], [{'r':1,'c':1,'rs':4,'cs':4,'value':'x'}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a')]})
    check('unmerged grid', solve(['r0','r1'], ['a','b'], [], [], []), {'merges': [], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a'), ('r1', 'b')]})

if N == 4:
    check('nonzero origin', solve(['r0','r1','r2','r3'], ['a','b','c','d'], [{'r':1,'c':1,'rs':2,'cs':2,'value':4}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 2, 'colspan': 2, 'value': 4, 'covered': [('r1', 'c'), ('r2', 'b'), ('r2', 'c')]}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r0', 'c'), ('r0', 'd'), ('r1', 'a'), ('r1', 'd'), ('r2', 'a'), ('r2', 'd'), ('r3', 'a'), ('r3', 'b'), ('r3', 'c'), ('r3', 'd')]})
    check('hidden anchor', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':3,'cs':3,'value':'x'}], ['r0','r1'], ['a','b']), {'merges': [{'anchor': ['r2', 'c'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': []})
    check('partial overlap', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':2,'cs':2,'value':'x'},{'r':1,'c':1,'rs':2,'cs':2,'value':'y'}], [], []), {'merges': [{'anchor': ['r0', 'a'], 'rowspan': 2, 'colspan': 2, 'value': 'x', 'covered': [('r0', 'b'), ('r1', 'a'), ('r1', 'b')]}], 'plain': [('r0', 'c'), ('r1', 'c'), ('r2', 'a'), ('r2', 'b'), ('r2', 'c')]})
    check('hidden merge', solve(['r0'], ['a'], [{'r':0,'c':0,'rs':1,'cs':1,'value':'x'}], ['r0'], []), {'merges': [], 'plain': []})
    check('clamped span', solve(['r0','r1'], ['a','b'], [{'r':1,'c':1,'rs':4,'cs':4,'value':'x'}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a')]})
    check('unmerged grid', solve(['r0','r1'], ['a','b'], [], [], []), {'merges': [], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a'), ('r1', 'b')]})

if N == 5:
    check('nonzero origin', solve(['r0','r1','r2','r3'], ['a','b','c','d'], [{'r':1,'c':1,'rs':2,'cs':2,'value':5}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 2, 'colspan': 2, 'value': 5, 'covered': [('r1', 'c'), ('r2', 'b'), ('r2', 'c')]}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r0', 'c'), ('r0', 'd'), ('r1', 'a'), ('r1', 'd'), ('r2', 'a'), ('r2', 'd'), ('r3', 'a'), ('r3', 'b'), ('r3', 'c'), ('r3', 'd')]})
    check('hidden anchor', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':3,'cs':3,'value':'x'}], ['r0','r1'], ['a','b']), {'merges': [{'anchor': ['r2', 'c'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': []})
    check('partial overlap', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':2,'cs':2,'value':'x'},{'r':1,'c':1,'rs':2,'cs':2,'value':'y'}], [], []), {'merges': [{'anchor': ['r0', 'a'], 'rowspan': 2, 'colspan': 2, 'value': 'x', 'covered': [('r0', 'b'), ('r1', 'a'), ('r1', 'b')]}], 'plain': [('r0', 'c'), ('r1', 'c'), ('r2', 'a'), ('r2', 'b'), ('r2', 'c')]})
    check('hidden merge', solve(['r0'], ['a'], [{'r':0,'c':0,'rs':1,'cs':1,'value':'x'}], ['r0'], []), {'merges': [], 'plain': []})
    check('clamped span', solve(['r0','r1'], ['a','b'], [{'r':1,'c':1,'rs':4,'cs':4,'value':'x'}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a')]})
    check('unmerged grid', solve(['r0','r1'], ['a','b'], [], [], []), {'merges': [], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a'), ('r1', 'b')]})

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, cols, anchors, hidden_rows, hidden_cols):
    vr=[r for r in rows if r not in hidden_rows]
    vc=[c for c in cols if c not in hidden_cols]
    result=[]
    covered=set()
    for a in anchors:
        rr=[r for r in rows[a['r']:a['r']+a['rs']+1] if r in vr]
        cc=[c for c in cols[a['c']:a['c']+a['cs']] if c in vc]
        if not rr or not cc: continue
        cells={(r,c) for r in rr for c in cc}
        if cells & covered: continue
        covered |= cells
        result.append({'anchor':[rr[0],cc[0]],'rowspan':len(rr),'colspan':len(cc),'value':a['value'],'covered':sorted(cells-{(rr[0],cc[0])})})
    return {'merges':result,'plain':[(r,c) for r in vr for c in vc if (r,c) not in covered]}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('nonzero origin', solve(['r0','r1','r2','r3'], ['a','b','c','d'], [{'r':1,'c':1,'rs':2,'cs':2,'value':1}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 2, 'colspan': 2, 'value': 1, 'covered': [('r1', 'c'), ('r2', 'b'), ('r2', 'c')]}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r0', 'c'), ('r0', 'd'), ('r1', 'a'), ('r1', 'd'), ('r2', 'a'), ('r2', 'd'), ('r3', 'a'), ('r3', 'b'), ('r3', 'c'), ('r3', 'd')]})
    check('hidden anchor', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':3,'cs':3,'value':'x'}], ['r0','r1'], ['a','b']), {'merges': [{'anchor': ['r2', 'c'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': []})
    check('partial overlap', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':2,'cs':2,'value':'x'},{'r':1,'c':1,'rs':2,'cs':2,'value':'y'}], [], []), {'merges': [{'anchor': ['r0', 'a'], 'rowspan': 2, 'colspan': 2, 'value': 'x', 'covered': [('r0', 'b'), ('r1', 'a'), ('r1', 'b')]}], 'plain': [('r0', 'c'), ('r1', 'c'), ('r2', 'a'), ('r2', 'b'), ('r2', 'c')]})
    check('hidden merge', solve(['r0'], ['a'], [{'r':0,'c':0,'rs':1,'cs':1,'value':'x'}], ['r0'], []), {'merges': [], 'plain': []})
    check('clamped span', solve(['r0','r1'], ['a','b'], [{'r':1,'c':1,'rs':4,'cs':4,'value':'x'}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a')]})
    check('unmerged grid', solve(['r0','r1'], ['a','b'], [], [], []), {'merges': [], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a'), ('r1', 'b')]})

if N == 2:
    check('nonzero origin', solve(['r0','r1','r2','r3'], ['a','b','c','d'], [{'r':1,'c':1,'rs':2,'cs':2,'value':2}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 2, 'colspan': 2, 'value': 2, 'covered': [('r1', 'c'), ('r2', 'b'), ('r2', 'c')]}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r0', 'c'), ('r0', 'd'), ('r1', 'a'), ('r1', 'd'), ('r2', 'a'), ('r2', 'd'), ('r3', 'a'), ('r3', 'b'), ('r3', 'c'), ('r3', 'd')]})
    check('hidden anchor', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':3,'cs':3,'value':'x'}], ['r0','r1'], ['a','b']), {'merges': [{'anchor': ['r2', 'c'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': []})
    check('partial overlap', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':2,'cs':2,'value':'x'},{'r':1,'c':1,'rs':2,'cs':2,'value':'y'}], [], []), {'merges': [{'anchor': ['r0', 'a'], 'rowspan': 2, 'colspan': 2, 'value': 'x', 'covered': [('r0', 'b'), ('r1', 'a'), ('r1', 'b')]}], 'plain': [('r0', 'c'), ('r1', 'c'), ('r2', 'a'), ('r2', 'b'), ('r2', 'c')]})
    check('hidden merge', solve(['r0'], ['a'], [{'r':0,'c':0,'rs':1,'cs':1,'value':'x'}], ['r0'], []), {'merges': [], 'plain': []})
    check('clamped span', solve(['r0','r1'], ['a','b'], [{'r':1,'c':1,'rs':4,'cs':4,'value':'x'}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a')]})
    check('unmerged grid', solve(['r0','r1'], ['a','b'], [], [], []), {'merges': [], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a'), ('r1', 'b')]})

if N == 3:
    check('nonzero origin', solve(['r0','r1','r2','r3'], ['a','b','c','d'], [{'r':1,'c':1,'rs':2,'cs':2,'value':3}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 2, 'colspan': 2, 'value': 3, 'covered': [('r1', 'c'), ('r2', 'b'), ('r2', 'c')]}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r0', 'c'), ('r0', 'd'), ('r1', 'a'), ('r1', 'd'), ('r2', 'a'), ('r2', 'd'), ('r3', 'a'), ('r3', 'b'), ('r3', 'c'), ('r3', 'd')]})
    check('hidden anchor', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':3,'cs':3,'value':'x'}], ['r0','r1'], ['a','b']), {'merges': [{'anchor': ['r2', 'c'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': []})
    check('partial overlap', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':2,'cs':2,'value':'x'},{'r':1,'c':1,'rs':2,'cs':2,'value':'y'}], [], []), {'merges': [{'anchor': ['r0', 'a'], 'rowspan': 2, 'colspan': 2, 'value': 'x', 'covered': [('r0', 'b'), ('r1', 'a'), ('r1', 'b')]}], 'plain': [('r0', 'c'), ('r1', 'c'), ('r2', 'a'), ('r2', 'b'), ('r2', 'c')]})
    check('hidden merge', solve(['r0'], ['a'], [{'r':0,'c':0,'rs':1,'cs':1,'value':'x'}], ['r0'], []), {'merges': [], 'plain': []})
    check('clamped span', solve(['r0','r1'], ['a','b'], [{'r':1,'c':1,'rs':4,'cs':4,'value':'x'}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a')]})
    check('unmerged grid', solve(['r0','r1'], ['a','b'], [], [], []), {'merges': [], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a'), ('r1', 'b')]})

if N == 4:
    check('nonzero origin', solve(['r0','r1','r2','r3'], ['a','b','c','d'], [{'r':1,'c':1,'rs':2,'cs':2,'value':4}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 2, 'colspan': 2, 'value': 4, 'covered': [('r1', 'c'), ('r2', 'b'), ('r2', 'c')]}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r0', 'c'), ('r0', 'd'), ('r1', 'a'), ('r1', 'd'), ('r2', 'a'), ('r2', 'd'), ('r3', 'a'), ('r3', 'b'), ('r3', 'c'), ('r3', 'd')]})
    check('hidden anchor', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':3,'cs':3,'value':'x'}], ['r0','r1'], ['a','b']), {'merges': [{'anchor': ['r2', 'c'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': []})
    check('partial overlap', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':2,'cs':2,'value':'x'},{'r':1,'c':1,'rs':2,'cs':2,'value':'y'}], [], []), {'merges': [{'anchor': ['r0', 'a'], 'rowspan': 2, 'colspan': 2, 'value': 'x', 'covered': [('r0', 'b'), ('r1', 'a'), ('r1', 'b')]}], 'plain': [('r0', 'c'), ('r1', 'c'), ('r2', 'a'), ('r2', 'b'), ('r2', 'c')]})
    check('hidden merge', solve(['r0'], ['a'], [{'r':0,'c':0,'rs':1,'cs':1,'value':'x'}], ['r0'], []), {'merges': [], 'plain': []})
    check('clamped span', solve(['r0','r1'], ['a','b'], [{'r':1,'c':1,'rs':4,'cs':4,'value':'x'}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a')]})
    check('unmerged grid', solve(['r0','r1'], ['a','b'], [], [], []), {'merges': [], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a'), ('r1', 'b')]})

if N == 5:
    check('nonzero origin', solve(['r0','r1','r2','r3'], ['a','b','c','d'], [{'r':1,'c':1,'rs':2,'cs':2,'value':5}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 2, 'colspan': 2, 'value': 5, 'covered': [('r1', 'c'), ('r2', 'b'), ('r2', 'c')]}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r0', 'c'), ('r0', 'd'), ('r1', 'a'), ('r1', 'd'), ('r2', 'a'), ('r2', 'd'), ('r3', 'a'), ('r3', 'b'), ('r3', 'c'), ('r3', 'd')]})
    check('hidden anchor', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':3,'cs':3,'value':'x'}], ['r0','r1'], ['a','b']), {'merges': [{'anchor': ['r2', 'c'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': []})
    check('partial overlap', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':2,'cs':2,'value':'x'},{'r':1,'c':1,'rs':2,'cs':2,'value':'y'}], [], []), {'merges': [{'anchor': ['r0', 'a'], 'rowspan': 2, 'colspan': 2, 'value': 'x', 'covered': [('r0', 'b'), ('r1', 'a'), ('r1', 'b')]}], 'plain': [('r0', 'c'), ('r1', 'c'), ('r2', 'a'), ('r2', 'b'), ('r2', 'c')]})
    check('hidden merge', solve(['r0'], ['a'], [{'r':0,'c':0,'rs':1,'cs':1,'value':'x'}], ['r0'], []), {'merges': [], 'plain': []})
    check('clamped span', solve(['r0','r1'], ['a','b'], [{'r':1,'c':1,'rs':4,'cs':4,'value':'x'}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a')]})
    check('unmerged grid', solve(['r0','r1'], ['a','b'], [], [], []), {'merges': [], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a'), ('r1', 'b')]})

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 row span end result violates the stipulated merged cell rendering contract.

Merged rectangles are expressed in source coordinates, clipped to source bounds and visible rows/columns, rebased to the first visible cell, and accepted in declaration order only if disjoint; plain cells omit every accepted merged cell.

split: open-access


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

N = 1
observations = []
def solve(rows, cols, anchors, hidden_rows, hidden_cols):
    vr=[r for r in rows if r not in hidden_rows]
    vc=[c for c in cols if c not in hidden_cols]
    result=[]
    covered=set()
    for a in anchors:
        rr=[r for r in rows[a['r']:a['r']+a['rs']] if r in vr]
        cc=[c for c in cols[a['c']:a['cs']] if c in vc]
        if not rr or not cc: continue
        cells={(r,c) for r in rr for c in cc}
        if cells & covered: continue
        covered |= cells
        result.append({'anchor':[rr[0],cc[0]],'rowspan':len(rr),'colspan':len(cc),'value':a['value'],'covered':sorted(cells-{(rr[0],cc[0])})})
    return {'merges':result,'plain':[(r,c) for r in vr for c in vc if (r,c) not in covered]}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('nonzero origin', solve(['r0','r1','r2','r3'], ['a','b','c','d'], [{'r':1,'c':1,'rs':2,'cs':2,'value':1}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 2, 'colspan': 2, 'value': 1, 'covered': [('r1', 'c'), ('r2', 'b'), ('r2', 'c')]}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r0', 'c'), ('r0', 'd'), ('r1', 'a'), ('r1', 'd'), ('r2', 'a'), ('r2', 'd'), ('r3', 'a'), ('r3', 'b'), ('r3', 'c'), ('r3', 'd')]})
    check('hidden anchor', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':3,'cs':3,'value':'x'}], ['r0','r1'], ['a','b']), {'merges': [{'anchor': ['r2', 'c'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': []})
    check('partial overlap', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':2,'cs':2,'value':'x'},{'r':1,'c':1,'rs':2,'cs':2,'value':'y'}], [], []), {'merges': [{'anchor': ['r0', 'a'], 'rowspan': 2, 'colspan': 2, 'value': 'x', 'covered': [('r0', 'b'), ('r1', 'a'), ('r1', 'b')]}], 'plain': [('r0', 'c'), ('r1', 'c'), ('r2', 'a'), ('r2', 'b'), ('r2', 'c')]})
    check('hidden merge', solve(['r0'], ['a'], [{'r':0,'c':0,'rs':1,'cs':1,'value':'x'}], ['r0'], []), {'merges': [], 'plain': []})
    check('clamped span', solve(['r0','r1'], ['a','b'], [{'r':1,'c':1,'rs':4,'cs':4,'value':'x'}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a')]})
    check('unmerged grid', solve(['r0','r1'], ['a','b'], [], [], []), {'merges': [], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a'), ('r1', 'b')]})

if N == 2:
    check('nonzero origin', solve(['r0','r1','r2','r3'], ['a','b','c','d'], [{'r':1,'c':1,'rs':2,'cs':2,'value':2}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 2, 'colspan': 2, 'value': 2, 'covered': [('r1', 'c'), ('r2', 'b'), ('r2', 'c')]}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r0', 'c'), ('r0', 'd'), ('r1', 'a'), ('r1', 'd'), ('r2', 'a'), ('r2', 'd'), ('r3', 'a'), ('r3', 'b'), ('r3', 'c'), ('r3', 'd')]})
    check('hidden anchor', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':3,'cs':3,'value':'x'}], ['r0','r1'], ['a','b']), {'merges': [{'anchor': ['r2', 'c'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': []})
    check('partial overlap', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':2,'cs':2,'value':'x'},{'r':1,'c':1,'rs':2,'cs':2,'value':'y'}], [], []), {'merges': [{'anchor': ['r0', 'a'], 'rowspan': 2, 'colspan': 2, 'value': 'x', 'covered': [('r0', 'b'), ('r1', 'a'), ('r1', 'b')]}], 'plain': [('r0', 'c'), ('r1', 'c'), ('r2', 'a'), ('r2', 'b'), ('r2', 'c')]})
    check('hidden merge', solve(['r0'], ['a'], [{'r':0,'c':0,'rs':1,'cs':1,'value':'x'}], ['r0'], []), {'merges': [], 'plain': []})
    check('clamped span', solve(['r0','r1'], ['a','b'], [{'r':1,'c':1,'rs':4,'cs':4,'value':'x'}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a')]})
    check('unmerged grid', solve(['r0','r1'], ['a','b'], [], [], []), {'merges': [], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a'), ('r1', 'b')]})

if N == 3:
    check('nonzero origin', solve(['r0','r1','r2','r3'], ['a','b','c','d'], [{'r':1,'c':1,'rs':2,'cs':2,'value':3}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 2, 'colspan': 2, 'value': 3, 'covered': [('r1', 'c'), ('r2', 'b'), ('r2', 'c')]}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r0', 'c'), ('r0', 'd'), ('r1', 'a'), ('r1', 'd'), ('r2', 'a'), ('r2', 'd'), ('r3', 'a'), ('r3', 'b'), ('r3', 'c'), ('r3', 'd')]})
    check('hidden anchor', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':3,'cs':3,'value':'x'}], ['r0','r1'], ['a','b']), {'merges': [{'anchor': ['r2', 'c'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': []})
    check('partial overlap', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':2,'cs':2,'value':'x'},{'r':1,'c':1,'rs':2,'cs':2,'value':'y'}], [], []), {'merges': [{'anchor': ['r0', 'a'], 'rowspan': 2, 'colspan': 2, 'value': 'x', 'covered': [('r0', 'b'), ('r1', 'a'), ('r1', 'b')]}], 'plain': [('r0', 'c'), ('r1', 'c'), ('r2', 'a'), ('r2', 'b'), ('r2', 'c')]})
    check('hidden merge', solve(['r0'], ['a'], [{'r':0,'c':0,'rs':1,'cs':1,'value':'x'}], ['r0'], []), {'merges': [], 'plain': []})
    check('clamped span', solve(['r0','r1'], ['a','b'], [{'r':1,'c':1,'rs':4,'cs':4,'value':'x'}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a')]})
    check('unmerged grid', solve(['r0','r1'], ['a','b'], [], [], []), {'merges': [], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a'), ('r1', 'b')]})

if N == 4:
    check('nonzero origin', solve(['r0','r1','r2','r3'], ['a','b','c','d'], [{'r':1,'c':1,'rs':2,'cs':2,'value':4}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 2, 'colspan': 2, 'value': 4, 'covered': [('r1', 'c'), ('r2', 'b'), ('r2', 'c')]}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r0', 'c'), ('r0', 'd'), ('r1', 'a'), ('r1', 'd'), ('r2', 'a'), ('r2', 'd'), ('r3', 'a'), ('r3', 'b'), ('r3', 'c'), ('r3', 'd')]})
    check('hidden anchor', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':3,'cs':3,'value':'x'}], ['r0','r1'], ['a','b']), {'merges': [{'anchor': ['r2', 'c'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': []})
    check('partial overlap', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':2,'cs':2,'value':'x'},{'r':1,'c':1,'rs':2,'cs':2,'value':'y'}], [], []), {'merges': [{'anchor': ['r0', 'a'], 'rowspan': 2, 'colspan': 2, 'value': 'x', 'covered': [('r0', 'b'), ('r1', 'a'), ('r1', 'b')]}], 'plain': [('r0', 'c'), ('r1', 'c'), ('r2', 'a'), ('r2', 'b'), ('r2', 'c')]})
    check('hidden merge', solve(['r0'], ['a'], [{'r':0,'c':0,'rs':1,'cs':1,'value':'x'}], ['r0'], []), {'merges': [], 'plain': []})
    check('clamped span', solve(['r0','r1'], ['a','b'], [{'r':1,'c':1,'rs':4,'cs':4,'value':'x'}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a')]})
    check('unmerged grid', solve(['r0','r1'], ['a','b'], [], [], []), {'merges': [], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a'), ('r1', 'b')]})

if N == 5:
    check('nonzero origin', solve(['r0','r1','r2','r3'], ['a','b','c','d'], [{'r':1,'c':1,'rs':2,'cs':2,'value':5}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 2, 'colspan': 2, 'value': 5, 'covered': [('r1', 'c'), ('r2', 'b'), ('r2', 'c')]}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r0', 'c'), ('r0', 'd'), ('r1', 'a'), ('r1', 'd'), ('r2', 'a'), ('r2', 'd'), ('r3', 'a'), ('r3', 'b'), ('r3', 'c'), ('r3', 'd')]})
    check('hidden anchor', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':3,'cs':3,'value':'x'}], ['r0','r1'], ['a','b']), {'merges': [{'anchor': ['r2', 'c'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': []})
    check('partial overlap', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':2,'cs':2,'value':'x'},{'r':1,'c':1,'rs':2,'cs':2,'value':'y'}], [], []), {'merges': [{'anchor': ['r0', 'a'], 'rowspan': 2, 'colspan': 2, 'value': 'x', 'covered': [('r0', 'b'), ('r1', 'a'), ('r1', 'b')]}], 'plain': [('r0', 'c'), ('r1', 'c'), ('r2', 'a'), ('r2', 'b'), ('r2', 'c')]})
    check('hidden merge', solve(['r0'], ['a'], [{'r':0,'c':0,'rs':1,'cs':1,'value':'x'}], ['r0'], []), {'merges': [], 'plain': []})
    check('clamped span', solve(['r0','r1'], ['a','b'], [{'r':1,'c':1,'rs':4,'cs':4,'value':'x'}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a')]})
    check('unmerged grid', solve(['r0','r1'], ['a','b'], [], [], []), {'merges': [], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a'), ('r1', 'b')]})

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, cols, anchors, hidden_rows, hidden_cols):
    vr=[r for r in rows if r not in hidden_rows]
    vc=[c for c in cols if c not in hidden_cols]
    result=[]
    covered=set()
    for a in anchors:
        rr=[r for r in rows[a['r']:a['r']+a['rs']] if r in vr]
        cc=[c for c in cols[a['c']:a['c']+a['cs']+1] if c in vc]
        if not rr or not cc: continue
        cells={(r,c) for r in rr for c in cc}
        if cells & covered: continue
        covered |= cells
        result.append({'anchor':[rr[0],cc[0]],'rowspan':len(rr),'colspan':len(cc),'value':a['value'],'covered':sorted(cells-{(rr[0],cc[0])})})
    return {'merges':result,'plain':[(r,c) for r in vr for c in vc if (r,c) not in covered]}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('nonzero origin', solve(['r0','r1','r2','r3'], ['a','b','c','d'], [{'r':1,'c':1,'rs':2,'cs':2,'value':1}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 2, 'colspan': 2, 'value': 1, 'covered': [('r1', 'c'), ('r2', 'b'), ('r2', 'c')]}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r0', 'c'), ('r0', 'd'), ('r1', 'a'), ('r1', 'd'), ('r2', 'a'), ('r2', 'd'), ('r3', 'a'), ('r3', 'b'), ('r3', 'c'), ('r3', 'd')]})
    check('hidden anchor', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':3,'cs':3,'value':'x'}], ['r0','r1'], ['a','b']), {'merges': [{'anchor': ['r2', 'c'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': []})
    check('partial overlap', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':2,'cs':2,'value':'x'},{'r':1,'c':1,'rs':2,'cs':2,'value':'y'}], [], []), {'merges': [{'anchor': ['r0', 'a'], 'rowspan': 2, 'colspan': 2, 'value': 'x', 'covered': [('r0', 'b'), ('r1', 'a'), ('r1', 'b')]}], 'plain': [('r0', 'c'), ('r1', 'c'), ('r2', 'a'), ('r2', 'b'), ('r2', 'c')]})
    check('hidden merge', solve(['r0'], ['a'], [{'r':0,'c':0,'rs':1,'cs':1,'value':'x'}], ['r0'], []), {'merges': [], 'plain': []})
    check('clamped span', solve(['r0','r1'], ['a','b'], [{'r':1,'c':1,'rs':4,'cs':4,'value':'x'}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a')]})
    check('unmerged grid', solve(['r0','r1'], ['a','b'], [], [], []), {'merges': [], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a'), ('r1', 'b')]})

if N == 2:
    check('nonzero origin', solve(['r0','r1','r2','r3'], ['a','b','c','d'], [{'r':1,'c':1,'rs':2,'cs':2,'value':2}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 2, 'colspan': 2, 'value': 2, 'covered': [('r1', 'c'), ('r2', 'b'), ('r2', 'c')]}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r0', 'c'), ('r0', 'd'), ('r1', 'a'), ('r1', 'd'), ('r2', 'a'), ('r2', 'd'), ('r3', 'a'), ('r3', 'b'), ('r3', 'c'), ('r3', 'd')]})
    check('hidden anchor', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':3,'cs':3,'value':'x'}], ['r0','r1'], ['a','b']), {'merges': [{'anchor': ['r2', 'c'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': []})
    check('partial overlap', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':2,'cs':2,'value':'x'},{'r':1,'c':1,'rs':2,'cs':2,'value':'y'}], [], []), {'merges': [{'anchor': ['r0', 'a'], 'rowspan': 2, 'colspan': 2, 'value': 'x', 'covered': [('r0', 'b'), ('r1', 'a'), ('r1', 'b')]}], 'plain': [('r0', 'c'), ('r1', 'c'), ('r2', 'a'), ('r2', 'b'), ('r2', 'c')]})
    check('hidden merge', solve(['r0'], ['a'], [{'r':0,'c':0,'rs':1,'cs':1,'value':'x'}], ['r0'], []), {'merges': [], 'plain': []})
    check('clamped span', solve(['r0','r1'], ['a','b'], [{'r':1,'c':1,'rs':4,'cs':4,'value':'x'}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a')]})
    check('unmerged grid', solve(['r0','r1'], ['a','b'], [], [], []), {'merges': [], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a'), ('r1', 'b')]})

if N == 3:
    check('nonzero origin', solve(['r0','r1','r2','r3'], ['a','b','c','d'], [{'r':1,'c':1,'rs':2,'cs':2,'value':3}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 2, 'colspan': 2, 'value': 3, 'covered': [('r1', 'c'), ('r2', 'b'), ('r2', 'c')]}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r0', 'c'), ('r0', 'd'), ('r1', 'a'), ('r1', 'd'), ('r2', 'a'), ('r2', 'd'), ('r3', 'a'), ('r3', 'b'), ('r3', 'c'), ('r3', 'd')]})
    check('hidden anchor', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':3,'cs':3,'value':'x'}], ['r0','r1'], ['a','b']), {'merges': [{'anchor': ['r2', 'c'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': []})
    check('partial overlap', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':2,'cs':2,'value':'x'},{'r':1,'c':1,'rs':2,'cs':2,'value':'y'}], [], []), {'merges': [{'anchor': ['r0', 'a'], 'rowspan': 2, 'colspan': 2, 'value': 'x', 'covered': [('r0', 'b'), ('r1', 'a'), ('r1', 'b')]}], 'plain': [('r0', 'c'), ('r1', 'c'), ('r2', 'a'), ('r2', 'b'), ('r2', 'c')]})
    check('hidden merge', solve(['r0'], ['a'], [{'r':0,'c':0,'rs':1,'cs':1,'value':'x'}], ['r0'], []), {'merges': [], 'plain': []})
    check('clamped span', solve(['r0','r1'], ['a','b'], [{'r':1,'c':1,'rs':4,'cs':4,'value':'x'}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a')]})
    check('unmerged grid', solve(['r0','r1'], ['a','b'], [], [], []), {'merges': [], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a'), ('r1', 'b')]})

if N == 4:
    check('nonzero origin', solve(['r0','r1','r2','r3'], ['a','b','c','d'], [{'r':1,'c':1,'rs':2,'cs':2,'value':4}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 2, 'colspan': 2, 'value': 4, 'covered': [('r1', 'c'), ('r2', 'b'), ('r2', 'c')]}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r0', 'c'), ('r0', 'd'), ('r1', 'a'), ('r1', 'd'), ('r2', 'a'), ('r2', 'd'), ('r3', 'a'), ('r3', 'b'), ('r3', 'c'), ('r3', 'd')]})
    check('hidden anchor', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':3,'cs':3,'value':'x'}], ['r0','r1'], ['a','b']), {'merges': [{'anchor': ['r2', 'c'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': []})
    check('partial overlap', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':2,'cs':2,'value':'x'},{'r':1,'c':1,'rs':2,'cs':2,'value':'y'}], [], []), {'merges': [{'anchor': ['r0', 'a'], 'rowspan': 2, 'colspan': 2, 'value': 'x', 'covered': [('r0', 'b'), ('r1', 'a'), ('r1', 'b')]}], 'plain': [('r0', 'c'), ('r1', 'c'), ('r2', 'a'), ('r2', 'b'), ('r2', 'c')]})
    check('hidden merge', solve(['r0'], ['a'], [{'r':0,'c':0,'rs':1,'cs':1,'value':'x'}], ['r0'], []), {'merges': [], 'plain': []})
    check('clamped span', solve(['r0','r1'], ['a','b'], [{'r':1,'c':1,'rs':4,'cs':4,'value':'x'}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a')]})
    check('unmerged grid', solve(['r0','r1'], ['a','b'], [], [], []), {'merges': [], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a'), ('r1', 'b')]})

if N == 5:
    check('nonzero origin', solve(['r0','r1','r2','r3'], ['a','b','c','d'], [{'r':1,'c':1,'rs':2,'cs':2,'value':5}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 2, 'colspan': 2, 'value': 5, 'covered': [('r1', 'c'), ('r2', 'b'), ('r2', 'c')]}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r0', 'c'), ('r0', 'd'), ('r1', 'a'), ('r1', 'd'), ('r2', 'a'), ('r2', 'd'), ('r3', 'a'), ('r3', 'b'), ('r3', 'c'), ('r3', 'd')]})
    check('hidden anchor', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':3,'cs':3,'value':'x'}], ['r0','r1'], ['a','b']), {'merges': [{'anchor': ['r2', 'c'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': []})
    check('partial overlap', solve(['r0','r1','r2'], ['a','b','c'], [{'r':0,'c':0,'rs':2,'cs':2,'value':'x'},{'r':1,'c':1,'rs':2,'cs':2,'value':'y'}], [], []), {'merges': [{'anchor': ['r0', 'a'], 'rowspan': 2, 'colspan': 2, 'value': 'x', 'covered': [('r0', 'b'), ('r1', 'a'), ('r1', 'b')]}], 'plain': [('r0', 'c'), ('r1', 'c'), ('r2', 'a'), ('r2', 'b'), ('r2', 'c')]})
    check('hidden merge', solve(['r0'], ['a'], [{'r':0,'c':0,'rs':1,'cs':1,'value':'x'}], ['r0'], []), {'merges': [], 'plain': []})
    check('clamped span', solve(['r0','r1'], ['a','b'], [{'r':1,'c':1,'rs':4,'cs':4,'value':'x'}], [], []), {'merges': [{'anchor': ['r1', 'b'], 'rowspan': 1, 'colspan': 1, 'value': 'x', 'covered': []}], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a')]})
    check('unmerged grid', solve(['r0','r1'], ['a','b'], [], [], []), {'merges': [], 'plain': [('r0', 'a'), ('r0', 'b'), ('r1', 'a'), ('r1', 'b')]})

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 column span end result violates the stipulated merged cell rendering contract.

Merged rectangles are expressed in source coordinates, clipped to source bounds and visible rows/columns, rebased to the first visible cell, and accepted in declaration order only if disjoint; plain cells omit every accepted merged cell.

split: open-access