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

N = 1
observations = []
def solve(p):
    p = dict(p)
    widths = [max(1,(p["w"]+(1<<i)-1)//(1<<i)) for i in range(4)]
    heights = [max(1,(p["h"]+(1<<i)-1)//(1<<i)) for i in range(4)]
    row_pitches = [w*p["b"]+2 for w in widths]
    level_sizes = [row_pitches[i]*heights[i]+3 for i in range(4)]
    directory_size = 4
    level_offsets = [directory_size+sum(level_sizes[:i]) for i in range(4)]
    selected_size = level_sizes[p["level"]]
    level_origin = p["base"]+level_offsets[p["level"]]
    payload_origin = level_origin+3
    allocation_end = p["base"]+directory_size+sum(level_sizes)
    return {'widths': widths, 'heights': heights, 'row_pitches': row_pitches, 'level_sizes': level_sizes, 'directory_size': directory_size, 'level_offsets': level_offsets, 'selected_size': selected_size, 'level_origin': level_origin, 'payload_origin': payload_origin, 'allocation_end': allocation_end}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [({'w': 8, 'h': 5, 'b': 2, 'base': 9, 'level': 0, 'x': 0, 'y': 0}, {'widths': [8, 4, 2, 1], 'heights': [5, 3, 2, 1], 'row_pitches': [18, 10, 6, 4], 'level_sizes': [93, 33, 15, 7], 'directory_size': 8, 'level_offsets': [8, 101, 134, 149], 'selected_size': 93, 'level_origin': 17, 'payload_origin': 20, 'allocation_end': 165}), ({'w': 9, 'h': 6, 'b': 2, 'base': 9, 'level': 1, 'x': 0, 'y': 0}, {'widths': [9, 5, 3, 2], 'heights': [6, 3, 2, 1], 'row_pitches': [20, 12, 8, 6], 'level_sizes': [123, 39, 19, 9], 'directory_size': 8, 'level_offsets': [8, 131, 170, 189], 'selected_size': 39, 'level_origin': 140, 'payload_origin': 143, 'allocation_end': 207}), ({'w': 10, 'h': 7, 'b': 2, 'base': 9, 'level': 2, 'x': 0, 'y': 0}, {'widths': [10, 5, 3, 2], 'heights': [7, 4, 2, 1], 'row_pitches': [22, 12, 8, 6], 'level_sizes': [157, 51, 19, 9], 'directory_size': 8, 'level_offsets': [8, 165, 216, 235], 'selected_size': 19, 'level_origin': 225, 'payload_origin': 228, 'allocation_end': 253}), ({'w': 11, 'h': 8, 'b': 2, 'base': 9, 'level': 3, 'x': 0, 'y': 0}, {'widths': [11, 6, 3, 2], 'heights': [8, 4, 2, 1], 'row_pitches': [24, 14, 8, 6], 'level_sizes': [195, 59, 19, 9], 'directory_size': 8, 'level_offsets': [8, 203, 262, 281], 'selected_size': 9, 'level_origin': 290, 'payload_origin': 293, 'allocation_end': 299}), ({'w': 12, 'h': 9, 'b': 2, 'base': 9, 'level': 0, 'x': 0, 'y': 0}, {'widths': [12, 6, 3, 2], 'heights': [9, 5, 3, 2], 'row_pitches': [26, 14, 8, 6], 'level_sizes': [237, 73, 27, 15], 'directory_size': 8, 'level_offsets': [8, 245, 318, 345], 'selected_size': 237, 'level_origin': 17, 'payload_origin': 20, 'allocation_end': 369}), ({'w': 13, 'h': 10, 'b': 2, 'base': 9, 'level': 1, 'x': 0, 'y': 0}, {'widths': [13, 7, 4, 2], 'heights': [10, 5, 3, 2], 'row_pitches': [28, 16, 10, 6], 'level_sizes': [283, 83, 33, 15], 'directory_size': 8, 'level_offsets': [8, 291, 374, 407], 'selected_size': 83, 'level_origin': 300, 'payload_origin': 303, 'allocation_end': 431})], 2: [({'w': 9, 'h': 5, 'b': 3, 'base': 18, 'level': 0, 'x': 0, 'y': 0}, {'widths': [9, 5, 3, 2], 'heights': [5, 3, 2, 1], 'row_pitches': [29, 17, 11, 8], 'level_sizes': [148, 54, 25, 11], 'directory_size': 8, 'level_offsets': [8, 156, 210, 235], 'selected_size': 148, 'level_origin': 26, 'payload_origin': 29, 'allocation_end': 264}), ({'w': 10, 'h': 6, 'b': 3, 'base': 18, 'level': 1, 'x': 0, 'y': 0}, {'widths': [10, 5, 3, 2], 'heights': [6, 3, 2, 1], 'row_pitches': [32, 17, 11, 8], 'level_sizes': [195, 54, 25, 11], 'directory_size': 8, 'level_offsets': [8, 203, 257, 282], 'selected_size': 54, 'level_origin': 221, 'payload_origin': 224, 'allocation_end': 311}), ({'w': 11, 'h': 7, 'b': 3, 'base': 18, 'level': 2, 'x': 0, 'y': 0}, {'widths': [11, 6, 3, 2], 'heights': [7, 4, 2, 1], 'row_pitches': [35, 20, 11, 8], 'level_sizes': [248, 83, 25, 11], 'directory_size': 8, 'level_offsets': [8, 256, 339, 364], 'selected_size': 25, 'level_origin': 357, 'payload_origin': 360, 'allocation_end': 393}), ({'w': 12, 'h': 8, 'b': 3, 'base': 18, 'level': 3, 'x': 0, 'y': 0}, {'widths': [12, 6, 3, 2], 'heights': [8, 4, 2, 1], 'row_pitches': [38, 20, 11, 8], 'level_sizes': [307, 83, 25, 11], 'directory_size': 8, 'level_offsets': [8, 315, 398, 423], 'selected_size': 11, 'level_origin': 441, 'payload_origin': 444, 'allocation_end': 452}), ({'w': 13, 'h': 9, 'b': 3, 'base': 18, 'level': 0, 'x': 0, 'y': 0}, {'widths': [13, 7, 4, 2], 'heights': [9, 5, 3, 2], 'row_pitches': [41, 23, 14, 8], 'level_sizes': [372, 118, 45, 19], 'directory_size': 8, 'level_offsets': [8, 380, 498, 543], 'selected_size': 372, 'level_origin': 26, 'payload_origin': 29, 'allocation_end': 580}), ({'w': 14, 'h': 10, 'b': 3, 'base': 18, 'level': 1, 'x': 0, 'y': 0}, {'widths': [14, 7, 4, 2], 'heights': [10, 5, 3, 2], 'row_pitches': [44, 23, 14, 8], 'level_sizes': [443, 118, 45, 19], 'directory_size': 8, 'level_offsets': [8, 451, 569, 614], 'selected_size': 118, 'level_origin': 469, 'payload_origin': 472, 'allocation_end': 651})], 3: [({'w': 10, 'h': 5, 'b': 4, 'base': 27, 'level': 0, 'x': 0, 'y': 0}, {'widths': [10, 5, 3, 2], 'heights': [5, 3, 2, 1], 'row_pitches': [42, 22, 14, 10], 'level_sizes': [213, 69, 31, 13], 'directory_size': 8, 'level_offsets': [8, 221, 290, 321], 'selected_size': 213, 'level_origin': 35, 'payload_origin': 38, 'allocation_end': 361}), ({'w': 11, 'h': 6, 'b': 4, 'base': 27, 'level': 1, 'x': 0, 'y': 0}, {'widths': [11, 6, 3, 2], 'heights': [6, 3, 2, 1], 'row_pitches': [46, 26, 14, 10], 'level_sizes': [279, 81, 31, 13], 'directory_size': 8, 'level_offsets': [8, 287, 368, 399], 'selected_size': 81, 'level_origin': 314, 'payload_origin': 317, 'allocation_end': 439}), ({'w': 12, 'h': 7, 'b': 4, 'base': 27, 'level': 2, 'x': 0, 'y': 0}, {'widths': [12, 6, 3, 2], 'heights': [7, 4, 2, 1], 'row_pitches': [50, 26, 14, 10], 'level_sizes': [353, 107, 31, 13], 'directory_size': 8, 'level_offsets': [8, 361, 468, 499], 'selected_size': 31, 'level_origin': 495, 'payload_origin': 498, 'allocation_end': 539}), ({'w': 13, 'h': 8, 'b': 4, 'base': 27, 'level': 3, 'x': 0, 'y': 0}, {'widths': [13, 7, 4, 2], 'heights': [8, 4, 2, 1], 'row_pitches': [54, 30, 18, 10], 'level_sizes': [435, 123, 39, 13], 'directory_size': 8, 'level_offsets': [8, 443, 566, 605], 'selected_size': 13, 'level_origin': 632, 'payload_origin': 635, 'allocation_end': 645}), ({'w': 14, 'h': 9, 'b': 4, 'base': 27, 'level': 0, 'x': 0, 'y': 0}, {'widths': [14, 7, 4, 2], 'heights': [9, 5, 3, 2], 'row_pitches': [58, 30, 18, 10], 'level_sizes': [525, 153, 57, 23], 'directory_size': 8, 'level_offsets': [8, 533, 686, 743], 'selected_size': 525, 'level_origin': 35, 'payload_origin': 38, 'allocation_end': 793}), ({'w': 15, 'h': 10, 'b': 4, 'base': 27, 'level': 1, 'x': 0, 'y': 0}, {'widths': [15, 8, 4, 2], 'heights': [10, 5, 3, 2], 'row_pitches': [62, 34, 18, 10], 'level_sizes': [623, 173, 57, 23], 'directory_size': 8, 'level_offsets': [8, 631, 804, 861], 'selected_size': 173, 'level_origin': 658, 'payload_origin': 661, 'allocation_end': 911})], 4: [({'w': 11, 'h': 5, 'b': 5, 'base': 36, 'level': 0, 'x': 0, 'y': 0}, {'widths': [11, 6, 3, 2], 'heights': [5, 3, 2, 1], 'row_pitches': [57, 32, 17, 12], 'level_sizes': [288, 99, 37, 15], 'directory_size': 8, 'level_offsets': [8, 296, 395, 432], 'selected_size': 288, 'level_origin': 44, 'payload_origin': 47, 'allocation_end': 483}), ({'w': 12, 'h': 6, 'b': 5, 'base': 36, 'level': 1, 'x': 0, 'y': 0}, {'widths': [12, 6, 3, 2], 'heights': [6, 3, 2, 1], 'row_pitches': [62, 32, 17, 12], 'level_sizes': [375, 99, 37, 15], 'directory_size': 8, 'level_offsets': [8, 383, 482, 519], 'selected_size': 99, 'level_origin': 419, 'payload_origin': 422, 'allocation_end': 570}), ({'w': 13, 'h': 7, 'b': 5, 'base': 36, 'level': 2, 'x': 0, 'y': 0}, {'widths': [13, 7, 4, 2], 'heights': [7, 4, 2, 1], 'row_pitches': [67, 37, 22, 12], 'level_sizes': [472, 151, 47, 15], 'directory_size': 8, 'level_offsets': [8, 480, 631, 678], 'selected_size': 47, 'level_origin': 667, 'payload_origin': 670, 'allocation_end': 729}), ({'w': 14, 'h': 8, 'b': 5, 'base': 36, 'level': 3, 'x': 0, 'y': 0}, {'widths': [14, 7, 4, 2], 'heights': [8, 4, 2, 1], 'row_pitches': [72, 37, 22, 12], 'level_sizes': [579, 151, 47, 15], 'directory_size': 8, 'level_offsets': [8, 587, 738, 785], 'selected_size': 15, 'level_origin': 821, 'payload_origin': 824, 'allocation_end': 836}), ({'w': 15, 'h': 9, 'b': 5, 'base': 36, 'level': 0, 'x': 0, 'y': 0}, {'widths': [15, 8, 4, 2], 'heights': [9, 5, 3, 2], 'row_pitches': [77, 42, 22, 12], 'level_sizes': [696, 213, 69, 27], 'directory_size': 8, 'level_offsets': [8, 704, 917, 986], 'selected_size': 696, 'level_origin': 44, 'payload_origin': 47, 'allocation_end': 1049}), ({'w': 16, 'h': 10, 'b': 5, 'base': 36, 'level': 1, 'x': 0, 'y': 0}, {'widths': [16, 8, 4, 2], 'heights': [10, 5, 3, 2], 'row_pitches': [82, 42, 22, 12], 'level_sizes': [823, 213, 69, 27], 'directory_size': 8, 'level_offsets': [8, 831, 1044, 1113], 'selected_size': 213, 'level_origin': 867, 'payload_origin': 870, 'allocation_end': 1176})], 5: [({'w': 12, 'h': 5, 'b': 6, 'base': 45, 'level': 0, 'x': 0, 'y': 0}, {'widths': [12, 6, 3, 2], 'heights': [5, 3, 2, 1], 'row_pitches': [74, 38, 20, 14], 'level_sizes': [373, 117, 43, 17], 'directory_size': 8, 'level_offsets': [8, 381, 498, 541], 'selected_size': 373, 'level_origin': 53, 'payload_origin': 56, 'allocation_end': 603}), ({'w': 13, 'h': 6, 'b': 6, 'base': 45, 'level': 1, 'x': 0, 'y': 0}, {'widths': [13, 7, 4, 2], 'heights': [6, 3, 2, 1], 'row_pitches': [80, 44, 26, 14], 'level_sizes': [483, 135, 55, 17], 'directory_size': 8, 'level_offsets': [8, 491, 626, 681], 'selected_size': 135, 'level_origin': 536, 'payload_origin': 539, 'allocation_end': 743}), ({'w': 14, 'h': 7, 'b': 6, 'base': 45, 'level': 2, 'x': 0, 'y': 0}, {'widths': [14, 7, 4, 2], 'heights': [7, 4, 2, 1], 'row_pitches': [86, 44, 26, 14], 'level_sizes': [605, 179, 55, 17], 'directory_size': 8, 'level_offsets': [8, 613, 792, 847], 'selected_size': 55, 'level_origin': 837, 'payload_origin': 840, 'allocation_end': 909}), ({'w': 15, 'h': 8, 'b': 6, 'base': 45, 'level': 3, 'x': 0, 'y': 0}, {'widths': [15, 8, 4, 2], 'heights': [8, 4, 2, 1], 'row_pitches': [92, 50, 26, 14], 'level_sizes': [739, 203, 55, 17], 'directory_size': 8, 'level_offsets': [8, 747, 950, 1005], 'selected_size': 17, 'level_origin': 1050, 'payload_origin': 1053, 'allocation_end': 1067}), ({'w': 16, 'h': 9, 'b': 6, 'base': 45, 'level': 0, 'x': 0, 'y': 0}, {'widths': [16, 8, 4, 2], 'heights': [9, 5, 3, 2], 'row_pitches': [98, 50, 26, 14], 'level_sizes': [885, 253, 81, 31], 'directory_size': 8, 'level_offsets': [8, 893, 1146, 1227], 'selected_size': 885, 'level_origin': 53, 'payload_origin': 56, 'allocation_end': 1303}), ({'w': 17, 'h': 10, 'b': 6, 'base': 45, 'level': 1, 'x': 0, 'y': 0}, {'widths': [17, 9, 5, 3], 'heights': [10, 5, 3, 2], 'row_pitches': [104, 56, 32, 20], 'level_sizes': [1043, 283, 99, 43], 'directory_size': 8, 'level_offsets': [8, 1051, 1334, 1433], 'selected_size': 283, 'level_origin': 1096, 'payload_origin': 1099, 'allocation_end': 1521})]}
for i, (p, expected) in enumerate(cases[N]):
    check("layout fixture " + str(i + 1), solve(p), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(p):
    p = dict(p)
    widths = [max(1,(p["w"]+(1<<i)-1)//(1<<i)) for i in range(4)]
    heights = [max(1,(p["h"]+(1<<i)-1)//(1<<i)) for i in range(4)]
    row_pitches = [w*p["b"]+2 for w in widths]
    level_sizes = [row_pitches[i]*heights[i]+3 for i in range(4)]
    directory_size = sum(widths)
    level_offsets = [directory_size+sum(level_sizes[:i]) for i in range(4)]
    selected_size = level_sizes[p["level"]]
    level_origin = p["base"]+level_offsets[p["level"]]
    payload_origin = level_origin+3
    allocation_end = p["base"]+directory_size+sum(level_sizes)
    return {'widths': widths, 'heights': heights, 'row_pitches': row_pitches, 'level_sizes': level_sizes, 'directory_size': directory_size, 'level_offsets': level_offsets, 'selected_size': selected_size, 'level_origin': level_origin, 'payload_origin': payload_origin, 'allocation_end': allocation_end}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [({'w': 8, 'h': 5, 'b': 2, 'base': 9, 'level': 0, 'x': 0, 'y': 0}, {'widths': [8, 4, 2, 1], 'heights': [5, 3, 2, 1], 'row_pitches': [18, 10, 6, 4], 'level_sizes': [93, 33, 15, 7], 'directory_size': 8, 'level_offsets': [8, 101, 134, 149], 'selected_size': 93, 'level_origin': 17, 'payload_origin': 20, 'allocation_end': 165}), ({'w': 9, 'h': 6, 'b': 2, 'base': 9, 'level': 1, 'x': 0, 'y': 0}, {'widths': [9, 5, 3, 2], 'heights': [6, 3, 2, 1], 'row_pitches': [20, 12, 8, 6], 'level_sizes': [123, 39, 19, 9], 'directory_size': 8, 'level_offsets': [8, 131, 170, 189], 'selected_size': 39, 'level_origin': 140, 'payload_origin': 143, 'allocation_end': 207}), ({'w': 10, 'h': 7, 'b': 2, 'base': 9, 'level': 2, 'x': 0, 'y': 0}, {'widths': [10, 5, 3, 2], 'heights': [7, 4, 2, 1], 'row_pitches': [22, 12, 8, 6], 'level_sizes': [157, 51, 19, 9], 'directory_size': 8, 'level_offsets': [8, 165, 216, 235], 'selected_size': 19, 'level_origin': 225, 'payload_origin': 228, 'allocation_end': 253}), ({'w': 11, 'h': 8, 'b': 2, 'base': 9, 'level': 3, 'x': 0, 'y': 0}, {'widths': [11, 6, 3, 2], 'heights': [8, 4, 2, 1], 'row_pitches': [24, 14, 8, 6], 'level_sizes': [195, 59, 19, 9], 'directory_size': 8, 'level_offsets': [8, 203, 262, 281], 'selected_size': 9, 'level_origin': 290, 'payload_origin': 293, 'allocation_end': 299}), ({'w': 12, 'h': 9, 'b': 2, 'base': 9, 'level': 0, 'x': 0, 'y': 0}, {'widths': [12, 6, 3, 2], 'heights': [9, 5, 3, 2], 'row_pitches': [26, 14, 8, 6], 'level_sizes': [237, 73, 27, 15], 'directory_size': 8, 'level_offsets': [8, 245, 318, 345], 'selected_size': 237, 'level_origin': 17, 'payload_origin': 20, 'allocation_end': 369}), ({'w': 13, 'h': 10, 'b': 2, 'base': 9, 'level': 1, 'x': 0, 'y': 0}, {'widths': [13, 7, 4, 2], 'heights': [10, 5, 3, 2], 'row_pitches': [28, 16, 10, 6], 'level_sizes': [283, 83, 33, 15], 'directory_size': 8, 'level_offsets': [8, 291, 374, 407], 'selected_size': 83, 'level_origin': 300, 'payload_origin': 303, 'allocation_end': 431})], 2: [({'w': 9, 'h': 5, 'b': 3, 'base': 18, 'level': 0, 'x': 0, 'y': 0}, {'widths': [9, 5, 3, 2], 'heights': [5, 3, 2, 1], 'row_pitches': [29, 17, 11, 8], 'level_sizes': [148, 54, 25, 11], 'directory_size': 8, 'level_offsets': [8, 156, 210, 235], 'selected_size': 148, 'level_origin': 26, 'payload_origin': 29, 'allocation_end': 264}), ({'w': 10, 'h': 6, 'b': 3, 'base': 18, 'level': 1, 'x': 0, 'y': 0}, {'widths': [10, 5, 3, 2], 'heights': [6, 3, 2, 1], 'row_pitches': [32, 17, 11, 8], 'level_sizes': [195, 54, 25, 11], 'directory_size': 8, 'level_offsets': [8, 203, 257, 282], 'selected_size': 54, 'level_origin': 221, 'payload_origin': 224, 'allocation_end': 311}), ({'w': 11, 'h': 7, 'b': 3, 'base': 18, 'level': 2, 'x': 0, 'y': 0}, {'widths': [11, 6, 3, 2], 'heights': [7, 4, 2, 1], 'row_pitches': [35, 20, 11, 8], 'level_sizes': [248, 83, 25, 11], 'directory_size': 8, 'level_offsets': [8, 256, 339, 364], 'selected_size': 25, 'level_origin': 357, 'payload_origin': 360, 'allocation_end': 393}), ({'w': 12, 'h': 8, 'b': 3, 'base': 18, 'level': 3, 'x': 0, 'y': 0}, {'widths': [12, 6, 3, 2], 'heights': [8, 4, 2, 1], 'row_pitches': [38, 20, 11, 8], 'level_sizes': [307, 83, 25, 11], 'directory_size': 8, 'level_offsets': [8, 315, 398, 423], 'selected_size': 11, 'level_origin': 441, 'payload_origin': 444, 'allocation_end': 452}), ({'w': 13, 'h': 9, 'b': 3, 'base': 18, 'level': 0, 'x': 0, 'y': 0}, {'widths': [13, 7, 4, 2], 'heights': [9, 5, 3, 2], 'row_pitches': [41, 23, 14, 8], 'level_sizes': [372, 118, 45, 19], 'directory_size': 8, 'level_offsets': [8, 380, 498, 543], 'selected_size': 372, 'level_origin': 26, 'payload_origin': 29, 'allocation_end': 580}), ({'w': 14, 'h': 10, 'b': 3, 'base': 18, 'level': 1, 'x': 0, 'y': 0}, {'widths': [14, 7, 4, 2], 'heights': [10, 5, 3, 2], 'row_pitches': [44, 23, 14, 8], 'level_sizes': [443, 118, 45, 19], 'directory_size': 8, 'level_offsets': [8, 451, 569, 614], 'selected_size': 118, 'level_origin': 469, 'payload_origin': 472, 'allocation_end': 651})], 3: [({'w': 10, 'h': 5, 'b': 4, 'base': 27, 'level': 0, 'x': 0, 'y': 0}, {'widths': [10, 5, 3, 2], 'heights': [5, 3, 2, 1], 'row_pitches': [42, 22, 14, 10], 'level_sizes': [213, 69, 31, 13], 'directory_size': 8, 'level_offsets': [8, 221, 290, 321], 'selected_size': 213, 'level_origin': 35, 'payload_origin': 38, 'allocation_end': 361}), ({'w': 11, 'h': 6, 'b': 4, 'base': 27, 'level': 1, 'x': 0, 'y': 0}, {'widths': [11, 6, 3, 2], 'heights': [6, 3, 2, 1], 'row_pitches': [46, 26, 14, 10], 'level_sizes': [279, 81, 31, 13], 'directory_size': 8, 'level_offsets': [8, 287, 368, 399], 'selected_size': 81, 'level_origin': 314, 'payload_origin': 317, 'allocation_end': 439}), ({'w': 12, 'h': 7, 'b': 4, 'base': 27, 'level': 2, 'x': 0, 'y': 0}, {'widths': [12, 6, 3, 2], 'heights': [7, 4, 2, 1], 'row_pitches': [50, 26, 14, 10], 'level_sizes': [353, 107, 31, 13], 'directory_size': 8, 'level_offsets': [8, 361, 468, 499], 'selected_size': 31, 'level_origin': 495, 'payload_origin': 498, 'allocation_end': 539}), ({'w': 13, 'h': 8, 'b': 4, 'base': 27, 'level': 3, 'x': 0, 'y': 0}, {'widths': [13, 7, 4, 2], 'heights': [8, 4, 2, 1], 'row_pitches': [54, 30, 18, 10], 'level_sizes': [435, 123, 39, 13], 'directory_size': 8, 'level_offsets': [8, 443, 566, 605], 'selected_size': 13, 'level_origin': 632, 'payload_origin': 635, 'allocation_end': 645}), ({'w': 14, 'h': 9, 'b': 4, 'base': 27, 'level': 0, 'x': 0, 'y': 0}, {'widths': [14, 7, 4, 2], 'heights': [9, 5, 3, 2], 'row_pitches': [58, 30, 18, 10], 'level_sizes': [525, 153, 57, 23], 'directory_size': 8, 'level_offsets': [8, 533, 686, 743], 'selected_size': 525, 'level_origin': 35, 'payload_origin': 38, 'allocation_end': 793}), ({'w': 15, 'h': 10, 'b': 4, 'base': 27, 'level': 1, 'x': 0, 'y': 0}, {'widths': [15, 8, 4, 2], 'heights': [10, 5, 3, 2], 'row_pitches': [62, 34, 18, 10], 'level_sizes': [623, 173, 57, 23], 'directory_size': 8, 'level_offsets': [8, 631, 804, 861], 'selected_size': 173, 'level_origin': 658, 'payload_origin': 661, 'allocation_end': 911})], 4: [({'w': 11, 'h': 5, 'b': 5, 'base': 36, 'level': 0, 'x': 0, 'y': 0}, {'widths': [11, 6, 3, 2], 'heights': [5, 3, 2, 1], 'row_pitches': [57, 32, 17, 12], 'level_sizes': [288, 99, 37, 15], 'directory_size': 8, 'level_offsets': [8, 296, 395, 432], 'selected_size': 288, 'level_origin': 44, 'payload_origin': 47, 'allocation_end': 483}), ({'w': 12, 'h': 6, 'b': 5, 'base': 36, 'level': 1, 'x': 0, 'y': 0}, {'widths': [12, 6, 3, 2], 'heights': [6, 3, 2, 1], 'row_pitches': [62, 32, 17, 12], 'level_sizes': [375, 99, 37, 15], 'directory_size': 8, 'level_offsets': [8, 383, 482, 519], 'selected_size': 99, 'level_origin': 419, 'payload_origin': 422, 'allocation_end': 570}), ({'w': 13, 'h': 7, 'b': 5, 'base': 36, 'level': 2, 'x': 0, 'y': 0}, {'widths': [13, 7, 4, 2], 'heights': [7, 4, 2, 1], 'row_pitches': [67, 37, 22, 12], 'level_sizes': [472, 151, 47, 15], 'directory_size': 8, 'level_offsets': [8, 480, 631, 678], 'selected_size': 47, 'level_origin': 667, 'payload_origin': 670, 'allocation_end': 729}), ({'w': 14, 'h': 8, 'b': 5, 'base': 36, 'level': 3, 'x': 0, 'y': 0}, {'widths': [14, 7, 4, 2], 'heights': [8, 4, 2, 1], 'row_pitches': [72, 37, 22, 12], 'level_sizes': [579, 151, 47, 15], 'directory_size': 8, 'level_offsets': [8, 587, 738, 785], 'selected_size': 15, 'level_origin': 821, 'payload_origin': 824, 'allocation_end': 836}), ({'w': 15, 'h': 9, 'b': 5, 'base': 36, 'level': 0, 'x': 0, 'y': 0}, {'widths': [15, 8, 4, 2], 'heights': [9, 5, 3, 2], 'row_pitches': [77, 42, 22, 12], 'level_sizes': [696, 213, 69, 27], 'directory_size': 8, 'level_offsets': [8, 704, 917, 986], 'selected_size': 696, 'level_origin': 44, 'payload_origin': 47, 'allocation_end': 1049}), ({'w': 16, 'h': 10, 'b': 5, 'base': 36, 'level': 1, 'x': 0, 'y': 0}, {'widths': [16, 8, 4, 2], 'heights': [10, 5, 3, 2], 'row_pitches': [82, 42, 22, 12], 'level_sizes': [823, 213, 69, 27], 'directory_size': 8, 'level_offsets': [8, 831, 1044, 1113], 'selected_size': 213, 'level_origin': 867, 'payload_origin': 870, 'allocation_end': 1176})], 5: [({'w': 12, 'h': 5, 'b': 6, 'base': 45, 'level': 0, 'x': 0, 'y': 0}, {'widths': [12, 6, 3, 2], 'heights': [5, 3, 2, 1], 'row_pitches': [74, 38, 20, 14], 'level_sizes': [373, 117, 43, 17], 'directory_size': 8, 'level_offsets': [8, 381, 498, 541], 'selected_size': 373, 'level_origin': 53, 'payload_origin': 56, 'allocation_end': 603}), ({'w': 13, 'h': 6, 'b': 6, 'base': 45, 'level': 1, 'x': 0, 'y': 0}, {'widths': [13, 7, 4, 2], 'heights': [6, 3, 2, 1], 'row_pitches': [80, 44, 26, 14], 'level_sizes': [483, 135, 55, 17], 'directory_size': 8, 'level_offsets': [8, 491, 626, 681], 'selected_size': 135, 'level_origin': 536, 'payload_origin': 539, 'allocation_end': 743}), ({'w': 14, 'h': 7, 'b': 6, 'base': 45, 'level': 2, 'x': 0, 'y': 0}, {'widths': [14, 7, 4, 2], 'heights': [7, 4, 2, 1], 'row_pitches': [86, 44, 26, 14], 'level_sizes': [605, 179, 55, 17], 'directory_size': 8, 'level_offsets': [8, 613, 792, 847], 'selected_size': 55, 'level_origin': 837, 'payload_origin': 840, 'allocation_end': 909}), ({'w': 15, 'h': 8, 'b': 6, 'base': 45, 'level': 3, 'x': 0, 'y': 0}, {'widths': [15, 8, 4, 2], 'heights': [8, 4, 2, 1], 'row_pitches': [92, 50, 26, 14], 'level_sizes': [739, 203, 55, 17], 'directory_size': 8, 'level_offsets': [8, 747, 950, 1005], 'selected_size': 17, 'level_origin': 1050, 'payload_origin': 1053, 'allocation_end': 1067}), ({'w': 16, 'h': 9, 'b': 6, 'base': 45, 'level': 0, 'x': 0, 'y': 0}, {'widths': [16, 8, 4, 2], 'heights': [9, 5, 3, 2], 'row_pitches': [98, 50, 26, 14], 'level_sizes': [885, 253, 81, 31], 'directory_size': 8, 'level_offsets': [8, 893, 1146, 1227], 'selected_size': 885, 'level_origin': 53, 'payload_origin': 56, 'allocation_end': 1303}), ({'w': 17, 'h': 10, 'b': 6, 'base': 45, 'level': 1, 'x': 0, 'y': 0}, {'widths': [17, 9, 5, 3], 'heights': [10, 5, 3, 2], 'row_pitches': [104, 56, 32, 20], 'level_sizes': [1043, 283, 99, 43], 'directory_size': 8, 'level_offsets': [8, 1051, 1334, 1433], 'selected_size': 283, 'level_origin': 1096, 'payload_origin': 1099, 'allocation_end': 1521})]}
for i, (p, expected) in enumerate(cases[N]):
    check("layout fixture " + str(i + 1), solve(p), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The returned physical layout descriptor disagrees with the declared buffer mapping at directory_size.

Store four mip levels consecutively. Each level uses ceil-halving, keeps dimensions at least one, has a two-byte row guard and a three-byte level header. A four-entry directory of two-byte offsets precedes all levels. Return the named intermediate layout descriptor and final address fields; all quantities are integer byte offsets unless explicitly stated.

split: open-access


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

N = 1
observations = []
def solve(p):
    p = dict(p)
    widths = [max(1,(p["w"]+(1<<i)-1)//(1<<i)) for i in range(4)]
    heights = [max(1,(p["h"]+(1<<i)-1)//(1<<i)) for i in range(4)]
    row_pitches = [w*p["b"]+2 for w in widths]
    level_sizes = [row_pitches[i]*heights[i]+3 for i in range(4)]
    directory_size = 4*2
    level_offsets = [directory_size+sum(level_sizes[:i+1]) for i in range(4)]
    selected_size = level_sizes[p["level"]]
    level_origin = p["base"]+level_offsets[p["level"]]
    payload_origin = level_origin+3
    allocation_end = p["base"]+directory_size+sum(level_sizes)
    return {'widths': widths, 'heights': heights, 'row_pitches': row_pitches, 'level_sizes': level_sizes, 'directory_size': directory_size, 'level_offsets': level_offsets, 'selected_size': selected_size, 'level_origin': level_origin, 'payload_origin': payload_origin, 'allocation_end': allocation_end}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [({'w': 8, 'h': 5, 'b': 2, 'base': 9, 'level': 0, 'x': 0, 'y': 0}, {'widths': [8, 4, 2, 1], 'heights': [5, 3, 2, 1], 'row_pitches': [18, 10, 6, 4], 'level_sizes': [93, 33, 15, 7], 'directory_size': 8, 'level_offsets': [8, 101, 134, 149], 'selected_size': 93, 'level_origin': 17, 'payload_origin': 20, 'allocation_end': 165}), ({'w': 9, 'h': 6, 'b': 2, 'base': 9, 'level': 1, 'x': 0, 'y': 0}, {'widths': [9, 5, 3, 2], 'heights': [6, 3, 2, 1], 'row_pitches': [20, 12, 8, 6], 'level_sizes': [123, 39, 19, 9], 'directory_size': 8, 'level_offsets': [8, 131, 170, 189], 'selected_size': 39, 'level_origin': 140, 'payload_origin': 143, 'allocation_end': 207}), ({'w': 10, 'h': 7, 'b': 2, 'base': 9, 'level': 2, 'x': 0, 'y': 0}, {'widths': [10, 5, 3, 2], 'heights': [7, 4, 2, 1], 'row_pitches': [22, 12, 8, 6], 'level_sizes': [157, 51, 19, 9], 'directory_size': 8, 'level_offsets': [8, 165, 216, 235], 'selected_size': 19, 'level_origin': 225, 'payload_origin': 228, 'allocation_end': 253}), ({'w': 11, 'h': 8, 'b': 2, 'base': 9, 'level': 3, 'x': 0, 'y': 0}, {'widths': [11, 6, 3, 2], 'heights': [8, 4, 2, 1], 'row_pitches': [24, 14, 8, 6], 'level_sizes': [195, 59, 19, 9], 'directory_size': 8, 'level_offsets': [8, 203, 262, 281], 'selected_size': 9, 'level_origin': 290, 'payload_origin': 293, 'allocation_end': 299}), ({'w': 12, 'h': 9, 'b': 2, 'base': 9, 'level': 0, 'x': 0, 'y': 0}, {'widths': [12, 6, 3, 2], 'heights': [9, 5, 3, 2], 'row_pitches': [26, 14, 8, 6], 'level_sizes': [237, 73, 27, 15], 'directory_size': 8, 'level_offsets': [8, 245, 318, 345], 'selected_size': 237, 'level_origin': 17, 'payload_origin': 20, 'allocation_end': 369}), ({'w': 13, 'h': 10, 'b': 2, 'base': 9, 'level': 1, 'x': 0, 'y': 0}, {'widths': [13, 7, 4, 2], 'heights': [10, 5, 3, 2], 'row_pitches': [28, 16, 10, 6], 'level_sizes': [283, 83, 33, 15], 'directory_size': 8, 'level_offsets': [8, 291, 374, 407], 'selected_size': 83, 'level_origin': 300, 'payload_origin': 303, 'allocation_end': 431})], 2: [({'w': 9, 'h': 5, 'b': 3, 'base': 18, 'level': 0, 'x': 0, 'y': 0}, {'widths': [9, 5, 3, 2], 'heights': [5, 3, 2, 1], 'row_pitches': [29, 17, 11, 8], 'level_sizes': [148, 54, 25, 11], 'directory_size': 8, 'level_offsets': [8, 156, 210, 235], 'selected_size': 148, 'level_origin': 26, 'payload_origin': 29, 'allocation_end': 264}), ({'w': 10, 'h': 6, 'b': 3, 'base': 18, 'level': 1, 'x': 0, 'y': 0}, {'widths': [10, 5, 3, 2], 'heights': [6, 3, 2, 1], 'row_pitches': [32, 17, 11, 8], 'level_sizes': [195, 54, 25, 11], 'directory_size': 8, 'level_offsets': [8, 203, 257, 282], 'selected_size': 54, 'level_origin': 221, 'payload_origin': 224, 'allocation_end': 311}), ({'w': 11, 'h': 7, 'b': 3, 'base': 18, 'level': 2, 'x': 0, 'y': 0}, {'widths': [11, 6, 3, 2], 'heights': [7, 4, 2, 1], 'row_pitches': [35, 20, 11, 8], 'level_sizes': [248, 83, 25, 11], 'directory_size': 8, 'level_offsets': [8, 256, 339, 364], 'selected_size': 25, 'level_origin': 357, 'payload_origin': 360, 'allocation_end': 393}), ({'w': 12, 'h': 8, 'b': 3, 'base': 18, 'level': 3, 'x': 0, 'y': 0}, {'widths': [12, 6, 3, 2], 'heights': [8, 4, 2, 1], 'row_pitches': [38, 20, 11, 8], 'level_sizes': [307, 83, 25, 11], 'directory_size': 8, 'level_offsets': [8, 315, 398, 423], 'selected_size': 11, 'level_origin': 441, 'payload_origin': 444, 'allocation_end': 452}), ({'w': 13, 'h': 9, 'b': 3, 'base': 18, 'level': 0, 'x': 0, 'y': 0}, {'widths': [13, 7, 4, 2], 'heights': [9, 5, 3, 2], 'row_pitches': [41, 23, 14, 8], 'level_sizes': [372, 118, 45, 19], 'directory_size': 8, 'level_offsets': [8, 380, 498, 543], 'selected_size': 372, 'level_origin': 26, 'payload_origin': 29, 'allocation_end': 580}), ({'w': 14, 'h': 10, 'b': 3, 'base': 18, 'level': 1, 'x': 0, 'y': 0}, {'widths': [14, 7, 4, 2], 'heights': [10, 5, 3, 2], 'row_pitches': [44, 23, 14, 8], 'level_sizes': [443, 118, 45, 19], 'directory_size': 8, 'level_offsets': [8, 451, 569, 614], 'selected_size': 118, 'level_origin': 469, 'payload_origin': 472, 'allocation_end': 651})], 3: [({'w': 10, 'h': 5, 'b': 4, 'base': 27, 'level': 0, 'x': 0, 'y': 0}, {'widths': [10, 5, 3, 2], 'heights': [5, 3, 2, 1], 'row_pitches': [42, 22, 14, 10], 'level_sizes': [213, 69, 31, 13], 'directory_size': 8, 'level_offsets': [8, 221, 290, 321], 'selected_size': 213, 'level_origin': 35, 'payload_origin': 38, 'allocation_end': 361}), ({'w': 11, 'h': 6, 'b': 4, 'base': 27, 'level': 1, 'x': 0, 'y': 0}, {'widths': [11, 6, 3, 2], 'heights': [6, 3, 2, 1], 'row_pitches': [46, 26, 14, 10], 'level_sizes': [279, 81, 31, 13], 'directory_size': 8, 'level_offsets': [8, 287, 368, 399], 'selected_size': 81, 'level_origin': 314, 'payload_origin': 317, 'allocation_end': 439}), ({'w': 12, 'h': 7, 'b': 4, 'base': 27, 'level': 2, 'x': 0, 'y': 0}, {'widths': [12, 6, 3, 2], 'heights': [7, 4, 2, 1], 'row_pitches': [50, 26, 14, 10], 'level_sizes': [353, 107, 31, 13], 'directory_size': 8, 'level_offsets': [8, 361, 468, 499], 'selected_size': 31, 'level_origin': 495, 'payload_origin': 498, 'allocation_end': 539}), ({'w': 13, 'h': 8, 'b': 4, 'base': 27, 'level': 3, 'x': 0, 'y': 0}, {'widths': [13, 7, 4, 2], 'heights': [8, 4, 2, 1], 'row_pitches': [54, 30, 18, 10], 'level_sizes': [435, 123, 39, 13], 'directory_size': 8, 'level_offsets': [8, 443, 566, 605], 'selected_size': 13, 'level_origin': 632, 'payload_origin': 635, 'allocation_end': 645}), ({'w': 14, 'h': 9, 'b': 4, 'base': 27, 'level': 0, 'x': 0, 'y': 0}, {'widths': [14, 7, 4, 2], 'heights': [9, 5, 3, 2], 'row_pitches': [58, 30, 18, 10], 'level_sizes': [525, 153, 57, 23], 'directory_size': 8, 'level_offsets': [8, 533, 686, 743], 'selected_size': 525, 'level_origin': 35, 'payload_origin': 38, 'allocation_end': 793}), ({'w': 15, 'h': 10, 'b': 4, 'base': 27, 'level': 1, 'x': 0, 'y': 0}, {'widths': [15, 8, 4, 2], 'heights': [10, 5, 3, 2], 'row_pitches': [62, 34, 18, 10], 'level_sizes': [623, 173, 57, 23], 'directory_size': 8, 'level_offsets': [8, 631, 804, 861], 'selected_size': 173, 'level_origin': 658, 'payload_origin': 661, 'allocation_end': 911})], 4: [({'w': 11, 'h': 5, 'b': 5, 'base': 36, 'level': 0, 'x': 0, 'y': 0}, {'widths': [11, 6, 3, 2], 'heights': [5, 3, 2, 1], 'row_pitches': [57, 32, 17, 12], 'level_sizes': [288, 99, 37, 15], 'directory_size': 8, 'level_offsets': [8, 296, 395, 432], 'selected_size': 288, 'level_origin': 44, 'payload_origin': 47, 'allocation_end': 483}), ({'w': 12, 'h': 6, 'b': 5, 'base': 36, 'level': 1, 'x': 0, 'y': 0}, {'widths': [12, 6, 3, 2], 'heights': [6, 3, 2, 1], 'row_pitches': [62, 32, 17, 12], 'level_sizes': [375, 99, 37, 15], 'directory_size': 8, 'level_offsets': [8, 383, 482, 519], 'selected_size': 99, 'level_origin': 419, 'payload_origin': 422, 'allocation_end': 570}), ({'w': 13, 'h': 7, 'b': 5, 'base': 36, 'level': 2, 'x': 0, 'y': 0}, {'widths': [13, 7, 4, 2], 'heights': [7, 4, 2, 1], 'row_pitches': [67, 37, 22, 12], 'level_sizes': [472, 151, 47, 15], 'directory_size': 8, 'level_offsets': [8, 480, 631, 678], 'selected_size': 47, 'level_origin': 667, 'payload_origin': 670, 'allocation_end': 729}), ({'w': 14, 'h': 8, 'b': 5, 'base': 36, 'level': 3, 'x': 0, 'y': 0}, {'widths': [14, 7, 4, 2], 'heights': [8, 4, 2, 1], 'row_pitches': [72, 37, 22, 12], 'level_sizes': [579, 151, 47, 15], 'directory_size': 8, 'level_offsets': [8, 587, 738, 785], 'selected_size': 15, 'level_origin': 821, 'payload_origin': 824, 'allocation_end': 836}), ({'w': 15, 'h': 9, 'b': 5, 'base': 36, 'level': 0, 'x': 0, 'y': 0}, {'widths': [15, 8, 4, 2], 'heights': [9, 5, 3, 2], 'row_pitches': [77, 42, 22, 12], 'level_sizes': [696, 213, 69, 27], 'directory_size': 8, 'level_offsets': [8, 704, 917, 986], 'selected_size': 696, 'level_origin': 44, 'payload_origin': 47, 'allocation_end': 1049}), ({'w': 16, 'h': 10, 'b': 5, 'base': 36, 'level': 1, 'x': 0, 'y': 0}, {'widths': [16, 8, 4, 2], 'heights': [10, 5, 3, 2], 'row_pitches': [82, 42, 22, 12], 'level_sizes': [823, 213, 69, 27], 'directory_size': 8, 'level_offsets': [8, 831, 1044, 1113], 'selected_size': 213, 'level_origin': 867, 'payload_origin': 870, 'allocation_end': 1176})], 5: [({'w': 12, 'h': 5, 'b': 6, 'base': 45, 'level': 0, 'x': 0, 'y': 0}, {'widths': [12, 6, 3, 2], 'heights': [5, 3, 2, 1], 'row_pitches': [74, 38, 20, 14], 'level_sizes': [373, 117, 43, 17], 'directory_size': 8, 'level_offsets': [8, 381, 498, 541], 'selected_size': 373, 'level_origin': 53, 'payload_origin': 56, 'allocation_end': 603}), ({'w': 13, 'h': 6, 'b': 6, 'base': 45, 'level': 1, 'x': 0, 'y': 0}, {'widths': [13, 7, 4, 2], 'heights': [6, 3, 2, 1], 'row_pitches': [80, 44, 26, 14], 'level_sizes': [483, 135, 55, 17], 'directory_size': 8, 'level_offsets': [8, 491, 626, 681], 'selected_size': 135, 'level_origin': 536, 'payload_origin': 539, 'allocation_end': 743}), ({'w': 14, 'h': 7, 'b': 6, 'base': 45, 'level': 2, 'x': 0, 'y': 0}, {'widths': [14, 7, 4, 2], 'heights': [7, 4, 2, 1], 'row_pitches': [86, 44, 26, 14], 'level_sizes': [605, 179, 55, 17], 'directory_size': 8, 'level_offsets': [8, 613, 792, 847], 'selected_size': 55, 'level_origin': 837, 'payload_origin': 840, 'allocation_end': 909}), ({'w': 15, 'h': 8, 'b': 6, 'base': 45, 'level': 3, 'x': 0, 'y': 0}, {'widths': [15, 8, 4, 2], 'heights': [8, 4, 2, 1], 'row_pitches': [92, 50, 26, 14], 'level_sizes': [739, 203, 55, 17], 'directory_size': 8, 'level_offsets': [8, 747, 950, 1005], 'selected_size': 17, 'level_origin': 1050, 'payload_origin': 1053, 'allocation_end': 1067}), ({'w': 16, 'h': 9, 'b': 6, 'base': 45, 'level': 0, 'x': 0, 'y': 0}, {'widths': [16, 8, 4, 2], 'heights': [9, 5, 3, 2], 'row_pitches': [98, 50, 26, 14], 'level_sizes': [885, 253, 81, 31], 'directory_size': 8, 'level_offsets': [8, 893, 1146, 1227], 'selected_size': 885, 'level_origin': 53, 'payload_origin': 56, 'allocation_end': 1303}), ({'w': 17, 'h': 10, 'b': 6, 'base': 45, 'level': 1, 'x': 0, 'y': 0}, {'widths': [17, 9, 5, 3], 'heights': [10, 5, 3, 2], 'row_pitches': [104, 56, 32, 20], 'level_sizes': [1043, 283, 99, 43], 'directory_size': 8, 'level_offsets': [8, 1051, 1334, 1433], 'selected_size': 283, 'level_origin': 1096, 'payload_origin': 1099, 'allocation_end': 1521})]}
for i, (p, expected) in enumerate(cases[N]):
    check("layout fixture " + str(i + 1), solve(p), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

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

N = 1
observations = []
def solve(p):
    p = dict(p)
    widths = [max(1,(p["w"]+(1<<i)-1)//(1<<i)) for i in range(4)]
    heights = [max(1,(p["h"]+(1<<i)-1)//(1<<i)) for i in range(4)]
    row_pitches = [w*p["b"]+2 for w in widths]
    level_sizes = [row_pitches[i]*heights[i]+3 for i in range(4)]
    directory_size = 4*2
    level_offsets = [directory_size+i*level_sizes[0] for i in range(4)]
    selected_size = level_sizes[p["level"]]
    level_origin = p["base"]+level_offsets[p["level"]]
    payload_origin = level_origin+3
    allocation_end = p["base"]+directory_size+sum(level_sizes)
    return {'widths': widths, 'heights': heights, 'row_pitches': row_pitches, 'level_sizes': level_sizes, 'directory_size': directory_size, 'level_offsets': level_offsets, 'selected_size': selected_size, 'level_origin': level_origin, 'payload_origin': payload_origin, 'allocation_end': allocation_end}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [({'w': 8, 'h': 5, 'b': 2, 'base': 9, 'level': 0, 'x': 0, 'y': 0}, {'widths': [8, 4, 2, 1], 'heights': [5, 3, 2, 1], 'row_pitches': [18, 10, 6, 4], 'level_sizes': [93, 33, 15, 7], 'directory_size': 8, 'level_offsets': [8, 101, 134, 149], 'selected_size': 93, 'level_origin': 17, 'payload_origin': 20, 'allocation_end': 165}), ({'w': 9, 'h': 6, 'b': 2, 'base': 9, 'level': 1, 'x': 0, 'y': 0}, {'widths': [9, 5, 3, 2], 'heights': [6, 3, 2, 1], 'row_pitches': [20, 12, 8, 6], 'level_sizes': [123, 39, 19, 9], 'directory_size': 8, 'level_offsets': [8, 131, 170, 189], 'selected_size': 39, 'level_origin': 140, 'payload_origin': 143, 'allocation_end': 207}), ({'w': 10, 'h': 7, 'b': 2, 'base': 9, 'level': 2, 'x': 0, 'y': 0}, {'widths': [10, 5, 3, 2], 'heights': [7, 4, 2, 1], 'row_pitches': [22, 12, 8, 6], 'level_sizes': [157, 51, 19, 9], 'directory_size': 8, 'level_offsets': [8, 165, 216, 235], 'selected_size': 19, 'level_origin': 225, 'payload_origin': 228, 'allocation_end': 253}), ({'w': 11, 'h': 8, 'b': 2, 'base': 9, 'level': 3, 'x': 0, 'y': 0}, {'widths': [11, 6, 3, 2], 'heights': [8, 4, 2, 1], 'row_pitches': [24, 14, 8, 6], 'level_sizes': [195, 59, 19, 9], 'directory_size': 8, 'level_offsets': [8, 203, 262, 281], 'selected_size': 9, 'level_origin': 290, 'payload_origin': 293, 'allocation_end': 299}), ({'w': 12, 'h': 9, 'b': 2, 'base': 9, 'level': 0, 'x': 0, 'y': 0}, {'widths': [12, 6, 3, 2], 'heights': [9, 5, 3, 2], 'row_pitches': [26, 14, 8, 6], 'level_sizes': [237, 73, 27, 15], 'directory_size': 8, 'level_offsets': [8, 245, 318, 345], 'selected_size': 237, 'level_origin': 17, 'payload_origin': 20, 'allocation_end': 369}), ({'w': 13, 'h': 10, 'b': 2, 'base': 9, 'level': 1, 'x': 0, 'y': 0}, {'widths': [13, 7, 4, 2], 'heights': [10, 5, 3, 2], 'row_pitches': [28, 16, 10, 6], 'level_sizes': [283, 83, 33, 15], 'directory_size': 8, 'level_offsets': [8, 291, 374, 407], 'selected_size': 83, 'level_origin': 300, 'payload_origin': 303, 'allocation_end': 431})], 2: [({'w': 9, 'h': 5, 'b': 3, 'base': 18, 'level': 0, 'x': 0, 'y': 0}, {'widths': [9, 5, 3, 2], 'heights': [5, 3, 2, 1], 'row_pitches': [29, 17, 11, 8], 'level_sizes': [148, 54, 25, 11], 'directory_size': 8, 'level_offsets': [8, 156, 210, 235], 'selected_size': 148, 'level_origin': 26, 'payload_origin': 29, 'allocation_end': 264}), ({'w': 10, 'h': 6, 'b': 3, 'base': 18, 'level': 1, 'x': 0, 'y': 0}, {'widths': [10, 5, 3, 2], 'heights': [6, 3, 2, 1], 'row_pitches': [32, 17, 11, 8], 'level_sizes': [195, 54, 25, 11], 'directory_size': 8, 'level_offsets': [8, 203, 257, 282], 'selected_size': 54, 'level_origin': 221, 'payload_origin': 224, 'allocation_end': 311}), ({'w': 11, 'h': 7, 'b': 3, 'base': 18, 'level': 2, 'x': 0, 'y': 0}, {'widths': [11, 6, 3, 2], 'heights': [7, 4, 2, 1], 'row_pitches': [35, 20, 11, 8], 'level_sizes': [248, 83, 25, 11], 'directory_size': 8, 'level_offsets': [8, 256, 339, 364], 'selected_size': 25, 'level_origin': 357, 'payload_origin': 360, 'allocation_end': 393}), ({'w': 12, 'h': 8, 'b': 3, 'base': 18, 'level': 3, 'x': 0, 'y': 0}, {'widths': [12, 6, 3, 2], 'heights': [8, 4, 2, 1], 'row_pitches': [38, 20, 11, 8], 'level_sizes': [307, 83, 25, 11], 'directory_size': 8, 'level_offsets': [8, 315, 398, 423], 'selected_size': 11, 'level_origin': 441, 'payload_origin': 444, 'allocation_end': 452}), ({'w': 13, 'h': 9, 'b': 3, 'base': 18, 'level': 0, 'x': 0, 'y': 0}, {'widths': [13, 7, 4, 2], 'heights': [9, 5, 3, 2], 'row_pitches': [41, 23, 14, 8], 'level_sizes': [372, 118, 45, 19], 'directory_size': 8, 'level_offsets': [8, 380, 498, 543], 'selected_size': 372, 'level_origin': 26, 'payload_origin': 29, 'allocation_end': 580}), ({'w': 14, 'h': 10, 'b': 3, 'base': 18, 'level': 1, 'x': 0, 'y': 0}, {'widths': [14, 7, 4, 2], 'heights': [10, 5, 3, 2], 'row_pitches': [44, 23, 14, 8], 'level_sizes': [443, 118, 45, 19], 'directory_size': 8, 'level_offsets': [8, 451, 569, 614], 'selected_size': 118, 'level_origin': 469, 'payload_origin': 472, 'allocation_end': 651})], 3: [({'w': 10, 'h': 5, 'b': 4, 'base': 27, 'level': 0, 'x': 0, 'y': 0}, {'widths': [10, 5, 3, 2], 'heights': [5, 3, 2, 1], 'row_pitches': [42, 22, 14, 10], 'level_sizes': [213, 69, 31, 13], 'directory_size': 8, 'level_offsets': [8, 221, 290, 321], 'selected_size': 213, 'level_origin': 35, 'payload_origin': 38, 'allocation_end': 361}), ({'w': 11, 'h': 6, 'b': 4, 'base': 27, 'level': 1, 'x': 0, 'y': 0}, {'widths': [11, 6, 3, 2], 'heights': [6, 3, 2, 1], 'row_pitches': [46, 26, 14, 10], 'level_sizes': [279, 81, 31, 13], 'directory_size': 8, 'level_offsets': [8, 287, 368, 399], 'selected_size': 81, 'level_origin': 314, 'payload_origin': 317, 'allocation_end': 439}), ({'w': 12, 'h': 7, 'b': 4, 'base': 27, 'level': 2, 'x': 0, 'y': 0}, {'widths': [12, 6, 3, 2], 'heights': [7, 4, 2, 1], 'row_pitches': [50, 26, 14, 10], 'level_sizes': [353, 107, 31, 13], 'directory_size': 8, 'level_offsets': [8, 361, 468, 499], 'selected_size': 31, 'level_origin': 495, 'payload_origin': 498, 'allocation_end': 539}), ({'w': 13, 'h': 8, 'b': 4, 'base': 27, 'level': 3, 'x': 0, 'y': 0}, {'widths': [13, 7, 4, 2], 'heights': [8, 4, 2, 1], 'row_pitches': [54, 30, 18, 10], 'level_sizes': [435, 123, 39, 13], 'directory_size': 8, 'level_offsets': [8, 443, 566, 605], 'selected_size': 13, 'level_origin': 632, 'payload_origin': 635, 'allocation_end': 645}), ({'w': 14, 'h': 9, 'b': 4, 'base': 27, 'level': 0, 'x': 0, 'y': 0}, {'widths': [14, 7, 4, 2], 'heights': [9, 5, 3, 2], 'row_pitches': [58, 30, 18, 10], 'level_sizes': [525, 153, 57, 23], 'directory_size': 8, 'level_offsets': [8, 533, 686, 743], 'selected_size': 525, 'level_origin': 35, 'payload_origin': 38, 'allocation_end': 793}), ({'w': 15, 'h': 10, 'b': 4, 'base': 27, 'level': 1, 'x': 0, 'y': 0}, {'widths': [15, 8, 4, 2], 'heights': [10, 5, 3, 2], 'row_pitches': [62, 34, 18, 10], 'level_sizes': [623, 173, 57, 23], 'directory_size': 8, 'level_offsets': [8, 631, 804, 861], 'selected_size': 173, 'level_origin': 658, 'payload_origin': 661, 'allocation_end': 911})], 4: [({'w': 11, 'h': 5, 'b': 5, 'base': 36, 'level': 0, 'x': 0, 'y': 0}, {'widths': [11, 6, 3, 2], 'heights': [5, 3, 2, 1], 'row_pitches': [57, 32, 17, 12], 'level_sizes': [288, 99, 37, 15], 'directory_size': 8, 'level_offsets': [8, 296, 395, 432], 'selected_size': 288, 'level_origin': 44, 'payload_origin': 47, 'allocation_end': 483}), ({'w': 12, 'h': 6, 'b': 5, 'base': 36, 'level': 1, 'x': 0, 'y': 0}, {'widths': [12, 6, 3, 2], 'heights': [6, 3, 2, 1], 'row_pitches': [62, 32, 17, 12], 'level_sizes': [375, 99, 37, 15], 'directory_size': 8, 'level_offsets': [8, 383, 482, 519], 'selected_size': 99, 'level_origin': 419, 'payload_origin': 422, 'allocation_end': 570}), ({'w': 13, 'h': 7, 'b': 5, 'base': 36, 'level': 2, 'x': 0, 'y': 0}, {'widths': [13, 7, 4, 2], 'heights': [7, 4, 2, 1], 'row_pitches': [67, 37, 22, 12], 'level_sizes': [472, 151, 47, 15], 'directory_size': 8, 'level_offsets': [8, 480, 631, 678], 'selected_size': 47, 'level_origin': 667, 'payload_origin': 670, 'allocation_end': 729}), ({'w': 14, 'h': 8, 'b': 5, 'base': 36, 'level': 3, 'x': 0, 'y': 0}, {'widths': [14, 7, 4, 2], 'heights': [8, 4, 2, 1], 'row_pitches': [72, 37, 22, 12], 'level_sizes': [579, 151, 47, 15], 'directory_size': 8, 'level_offsets': [8, 587, 738, 785], 'selected_size': 15, 'level_origin': 821, 'payload_origin': 824, 'allocation_end': 836}), ({'w': 15, 'h': 9, 'b': 5, 'base': 36, 'level': 0, 'x': 0, 'y': 0}, {'widths': [15, 8, 4, 2], 'heights': [9, 5, 3, 2], 'row_pitches': [77, 42, 22, 12], 'level_sizes': [696, 213, 69, 27], 'directory_size': 8, 'level_offsets': [8, 704, 917, 986], 'selected_size': 696, 'level_origin': 44, 'payload_origin': 47, 'allocation_end': 1049}), ({'w': 16, 'h': 10, 'b': 5, 'base': 36, 'level': 1, 'x': 0, 'y': 0}, {'widths': [16, 8, 4, 2], 'heights': [10, 5, 3, 2], 'row_pitches': [82, 42, 22, 12], 'level_sizes': [823, 213, 69, 27], 'directory_size': 8, 'level_offsets': [8, 831, 1044, 1113], 'selected_size': 213, 'level_origin': 867, 'payload_origin': 870, 'allocation_end': 1176})], 5: [({'w': 12, 'h': 5, 'b': 6, 'base': 45, 'level': 0, 'x': 0, 'y': 0}, {'widths': [12, 6, 3, 2], 'heights': [5, 3, 2, 1], 'row_pitches': [74, 38, 20, 14], 'level_sizes': [373, 117, 43, 17], 'directory_size': 8, 'level_offsets': [8, 381, 498, 541], 'selected_size': 373, 'level_origin': 53, 'payload_origin': 56, 'allocation_end': 603}), ({'w': 13, 'h': 6, 'b': 6, 'base': 45, 'level': 1, 'x': 0, 'y': 0}, {'widths': [13, 7, 4, 2], 'heights': [6, 3, 2, 1], 'row_pitches': [80, 44, 26, 14], 'level_sizes': [483, 135, 55, 17], 'directory_size': 8, 'level_offsets': [8, 491, 626, 681], 'selected_size': 135, 'level_origin': 536, 'payload_origin': 539, 'allocation_end': 743}), ({'w': 14, 'h': 7, 'b': 6, 'base': 45, 'level': 2, 'x': 0, 'y': 0}, {'widths': [14, 7, 4, 2], 'heights': [7, 4, 2, 1], 'row_pitches': [86, 44, 26, 14], 'level_sizes': [605, 179, 55, 17], 'directory_size': 8, 'level_offsets': [8, 613, 792, 847], 'selected_size': 55, 'level_origin': 837, 'payload_origin': 840, 'allocation_end': 909}), ({'w': 15, 'h': 8, 'b': 6, 'base': 45, 'level': 3, 'x': 0, 'y': 0}, {'widths': [15, 8, 4, 2], 'heights': [8, 4, 2, 1], 'row_pitches': [92, 50, 26, 14], 'level_sizes': [739, 203, 55, 17], 'directory_size': 8, 'level_offsets': [8, 747, 950, 1005], 'selected_size': 17, 'level_origin': 1050, 'payload_origin': 1053, 'allocation_end': 1067}), ({'w': 16, 'h': 9, 'b': 6, 'base': 45, 'level': 0, 'x': 0, 'y': 0}, {'widths': [16, 8, 4, 2], 'heights': [9, 5, 3, 2], 'row_pitches': [98, 50, 26, 14], 'level_sizes': [885, 253, 81, 31], 'directory_size': 8, 'level_offsets': [8, 893, 1146, 1227], 'selected_size': 885, 'level_origin': 53, 'payload_origin': 56, 'allocation_end': 1303}), ({'w': 17, 'h': 10, 'b': 6, 'base': 45, 'level': 1, 'x': 0, 'y': 0}, {'widths': [17, 9, 5, 3], 'heights': [10, 5, 3, 2], 'row_pitches': [104, 56, 32, 20], 'level_sizes': [1043, 283, 99, 43], 'directory_size': 8, 'level_offsets': [8, 1051, 1334, 1433], 'selected_size': 283, 'level_origin': 1096, 'payload_origin': 1099, 'allocation_end': 1521})]}
for i, (p, expected) in enumerate(cases[N]):
    check("layout fixture " + str(i + 1), solve(p), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The returned physical layout descriptor disagrees with the declared buffer mapping at level_offsets.

Store four mip levels consecutively. Each level uses ceil-halving, keeps dimensions at least one, has a two-byte row guard and a three-byte level header. A four-entry directory of two-byte offsets precedes all levels. Return the named intermediate layout descriptor and final address fields; all quantities are integer byte offsets unless explicitly stated.

split: open-access


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

N = 1
observations = []
def solve(p):
    p = dict(p)
    widths = [max(1,(p["w"]+(1<<i)-1)//(1<<i)) for i in range(4)]
    heights = [max(1,(p["h"]+(1<<i)-1)//(1<<i)) for i in range(4)]
    row_pitches = [w*p["b"]+2 for w in widths]
    level_sizes = [row_pitches[i]*heights[i]+3 for i in range(4)]
    directory_size = 4*2
    level_offsets = [directory_size+sum(level_sizes[:i]) for i in range(4)]
    selected_size = level_sizes[0]
    level_origin = p["base"]+level_offsets[p["level"]]
    payload_origin = level_origin+3
    allocation_end = p["base"]+directory_size+sum(level_sizes)
    return {'widths': widths, 'heights': heights, 'row_pitches': row_pitches, 'level_sizes': level_sizes, 'directory_size': directory_size, 'level_offsets': level_offsets, 'selected_size': selected_size, 'level_origin': level_origin, 'payload_origin': payload_origin, 'allocation_end': allocation_end}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [({'w': 8, 'h': 5, 'b': 2, 'base': 9, 'level': 0, 'x': 0, 'y': 0}, {'widths': [8, 4, 2, 1], 'heights': [5, 3, 2, 1], 'row_pitches': [18, 10, 6, 4], 'level_sizes': [93, 33, 15, 7], 'directory_size': 8, 'level_offsets': [8, 101, 134, 149], 'selected_size': 93, 'level_origin': 17, 'payload_origin': 20, 'allocation_end': 165}), ({'w': 9, 'h': 6, 'b': 2, 'base': 9, 'level': 1, 'x': 0, 'y': 0}, {'widths': [9, 5, 3, 2], 'heights': [6, 3, 2, 1], 'row_pitches': [20, 12, 8, 6], 'level_sizes': [123, 39, 19, 9], 'directory_size': 8, 'level_offsets': [8, 131, 170, 189], 'selected_size': 39, 'level_origin': 140, 'payload_origin': 143, 'allocation_end': 207}), ({'w': 10, 'h': 7, 'b': 2, 'base': 9, 'level': 2, 'x': 0, 'y': 0}, {'widths': [10, 5, 3, 2], 'heights': [7, 4, 2, 1], 'row_pitches': [22, 12, 8, 6], 'level_sizes': [157, 51, 19, 9], 'directory_size': 8, 'level_offsets': [8, 165, 216, 235], 'selected_size': 19, 'level_origin': 225, 'payload_origin': 228, 'allocation_end': 253}), ({'w': 11, 'h': 8, 'b': 2, 'base': 9, 'level': 3, 'x': 0, 'y': 0}, {'widths': [11, 6, 3, 2], 'heights': [8, 4, 2, 1], 'row_pitches': [24, 14, 8, 6], 'level_sizes': [195, 59, 19, 9], 'directory_size': 8, 'level_offsets': [8, 203, 262, 281], 'selected_size': 9, 'level_origin': 290, 'payload_origin': 293, 'allocation_end': 299}), ({'w': 12, 'h': 9, 'b': 2, 'base': 9, 'level': 0, 'x': 0, 'y': 0}, {'widths': [12, 6, 3, 2], 'heights': [9, 5, 3, 2], 'row_pitches': [26, 14, 8, 6], 'level_sizes': [237, 73, 27, 15], 'directory_size': 8, 'level_offsets': [8, 245, 318, 345], 'selected_size': 237, 'level_origin': 17, 'payload_origin': 20, 'allocation_end': 369}), ({'w': 13, 'h': 10, 'b': 2, 'base': 9, 'level': 1, 'x': 0, 'y': 0}, {'widths': [13, 7, 4, 2], 'heights': [10, 5, 3, 2], 'row_pitches': [28, 16, 10, 6], 'level_sizes': [283, 83, 33, 15], 'directory_size': 8, 'level_offsets': [8, 291, 374, 407], 'selected_size': 83, 'level_origin': 300, 'payload_origin': 303, 'allocation_end': 431})], 2: [({'w': 9, 'h': 5, 'b': 3, 'base': 18, 'level': 0, 'x': 0, 'y': 0}, {'widths': [9, 5, 3, 2], 'heights': [5, 3, 2, 1], 'row_pitches': [29, 17, 11, 8], 'level_sizes': [148, 54, 25, 11], 'directory_size': 8, 'level_offsets': [8, 156, 210, 235], 'selected_size': 148, 'level_origin': 26, 'payload_origin': 29, 'allocation_end': 264}), ({'w': 10, 'h': 6, 'b': 3, 'base': 18, 'level': 1, 'x': 0, 'y': 0}, {'widths': [10, 5, 3, 2], 'heights': [6, 3, 2, 1], 'row_pitches': [32, 17, 11, 8], 'level_sizes': [195, 54, 25, 11], 'directory_size': 8, 'level_offsets': [8, 203, 257, 282], 'selected_size': 54, 'level_origin': 221, 'payload_origin': 224, 'allocation_end': 311}), ({'w': 11, 'h': 7, 'b': 3, 'base': 18, 'level': 2, 'x': 0, 'y': 0}, {'widths': [11, 6, 3, 2], 'heights': [7, 4, 2, 1], 'row_pitches': [35, 20, 11, 8], 'level_sizes': [248, 83, 25, 11], 'directory_size': 8, 'level_offsets': [8, 256, 339, 364], 'selected_size': 25, 'level_origin': 357, 'payload_origin': 360, 'allocation_end': 393}), ({'w': 12, 'h': 8, 'b': 3, 'base': 18, 'level': 3, 'x': 0, 'y': 0}, {'widths': [12, 6, 3, 2], 'heights': [8, 4, 2, 1], 'row_pitches': [38, 20, 11, 8], 'level_sizes': [307, 83, 25, 11], 'directory_size': 8, 'level_offsets': [8, 315, 398, 423], 'selected_size': 11, 'level_origin': 441, 'payload_origin': 444, 'allocation_end': 452}), ({'w': 13, 'h': 9, 'b': 3, 'base': 18, 'level': 0, 'x': 0, 'y': 0}, {'widths': [13, 7, 4, 2], 'heights': [9, 5, 3, 2], 'row_pitches': [41, 23, 14, 8], 'level_sizes': [372, 118, 45, 19], 'directory_size': 8, 'level_offsets': [8, 380, 498, 543], 'selected_size': 372, 'level_origin': 26, 'payload_origin': 29, 'allocation_end': 580}), ({'w': 14, 'h': 10, 'b': 3, 'base': 18, 'level': 1, 'x': 0, 'y': 0}, {'widths': [14, 7, 4, 2], 'heights': [10, 5, 3, 2], 'row_pitches': [44, 23, 14, 8], 'level_sizes': [443, 118, 45, 19], 'directory_size': 8, 'level_offsets': [8, 451, 569, 614], 'selected_size': 118, 'level_origin': 469, 'payload_origin': 472, 'allocation_end': 651})], 3: [({'w': 10, 'h': 5, 'b': 4, 'base': 27, 'level': 0, 'x': 0, 'y': 0}, {'widths': [10, 5, 3, 2], 'heights': [5, 3, 2, 1], 'row_pitches': [42, 22, 14, 10], 'level_sizes': [213, 69, 31, 13], 'directory_size': 8, 'level_offsets': [8, 221, 290, 321], 'selected_size': 213, 'level_origin': 35, 'payload_origin': 38, 'allocation_end': 361}), ({'w': 11, 'h': 6, 'b': 4, 'base': 27, 'level': 1, 'x': 0, 'y': 0}, {'widths': [11, 6, 3, 2], 'heights': [6, 3, 2, 1], 'row_pitches': [46, 26, 14, 10], 'level_sizes': [279, 81, 31, 13], 'directory_size': 8, 'level_offsets': [8, 287, 368, 399], 'selected_size': 81, 'level_origin': 314, 'payload_origin': 317, 'allocation_end': 439}), ({'w': 12, 'h': 7, 'b': 4, 'base': 27, 'level': 2, 'x': 0, 'y': 0}, {'widths': [12, 6, 3, 2], 'heights': [7, 4, 2, 1], 'row_pitches': [50, 26, 14, 10], 'level_sizes': [353, 107, 31, 13], 'directory_size': 8, 'level_offsets': [8, 361, 468, 499], 'selected_size': 31, 'level_origin': 495, 'payload_origin': 498, 'allocation_end': 539}), ({'w': 13, 'h': 8, 'b': 4, 'base': 27, 'level': 3, 'x': 0, 'y': 0}, {'widths': [13, 7, 4, 2], 'heights': [8, 4, 2, 1], 'row_pitches': [54, 30, 18, 10], 'level_sizes': [435, 123, 39, 13], 'directory_size': 8, 'level_offsets': [8, 443, 566, 605], 'selected_size': 13, 'level_origin': 632, 'payload_origin': 635, 'allocation_end': 645}), ({'w': 14, 'h': 9, 'b': 4, 'base': 27, 'level': 0, 'x': 0, 'y': 0}, {'widths': [14, 7, 4, 2], 'heights': [9, 5, 3, 2], 'row_pitches': [58, 30, 18, 10], 'level_sizes': [525, 153, 57, 23], 'directory_size': 8, 'level_offsets': [8, 533, 686, 743], 'selected_size': 525, 'level_origin': 35, 'payload_origin': 38, 'allocation_end': 793}), ({'w': 15, 'h': 10, 'b': 4, 'base': 27, 'level': 1, 'x': 0, 'y': 0}, {'widths': [15, 8, 4, 2], 'heights': [10, 5, 3, 2], 'row_pitches': [62, 34, 18, 10], 'level_sizes': [623, 173, 57, 23], 'directory_size': 8, 'level_offsets': [8, 631, 804, 861], 'selected_size': 173, 'level_origin': 658, 'payload_origin': 661, 'allocation_end': 911})], 4: [({'w': 11, 'h': 5, 'b': 5, 'base': 36, 'level': 0, 'x': 0, 'y': 0}, {'widths': [11, 6, 3, 2], 'heights': [5, 3, 2, 1], 'row_pitches': [57, 32, 17, 12], 'level_sizes': [288, 99, 37, 15], 'directory_size': 8, 'level_offsets': [8, 296, 395, 432], 'selected_size': 288, 'level_origin': 44, 'payload_origin': 47, 'allocation_end': 483}), ({'w': 12, 'h': 6, 'b': 5, 'base': 36, 'level': 1, 'x': 0, 'y': 0}, {'widths': [12, 6, 3, 2], 'heights': [6, 3, 2, 1], 'row_pitches': [62, 32, 17, 12], 'level_sizes': [375, 99, 37, 15], 'directory_size': 8, 'level_offsets': [8, 383, 482, 519], 'selected_size': 99, 'level_origin': 419, 'payload_origin': 422, 'allocation_end': 570}), ({'w': 13, 'h': 7, 'b': 5, 'base': 36, 'level': 2, 'x': 0, 'y': 0}, {'widths': [13, 7, 4, 2], 'heights': [7, 4, 2, 1], 'row_pitches': [67, 37, 22, 12], 'level_sizes': [472, 151, 47, 15], 'directory_size': 8, 'level_offsets': [8, 480, 631, 678], 'selected_size': 47, 'level_origin': 667, 'payload_origin': 670, 'allocation_end': 729}), ({'w': 14, 'h': 8, 'b': 5, 'base': 36, 'level': 3, 'x': 0, 'y': 0}, {'widths': [14, 7, 4, 2], 'heights': [8, 4, 2, 1], 'row_pitches': [72, 37, 22, 12], 'level_sizes': [579, 151, 47, 15], 'directory_size': 8, 'level_offsets': [8, 587, 738, 785], 'selected_size': 15, 'level_origin': 821, 'payload_origin': 824, 'allocation_end': 836}), ({'w': 15, 'h': 9, 'b': 5, 'base': 36, 'level': 0, 'x': 0, 'y': 0}, {'widths': [15, 8, 4, 2], 'heights': [9, 5, 3, 2], 'row_pitches': [77, 42, 22, 12], 'level_sizes': [696, 213, 69, 27], 'directory_size': 8, 'level_offsets': [8, 704, 917, 986], 'selected_size': 696, 'level_origin': 44, 'payload_origin': 47, 'allocation_end': 1049}), ({'w': 16, 'h': 10, 'b': 5, 'base': 36, 'level': 1, 'x': 0, 'y': 0}, {'widths': [16, 8, 4, 2], 'heights': [10, 5, 3, 2], 'row_pitches': [82, 42, 22, 12], 'level_sizes': [823, 213, 69, 27], 'directory_size': 8, 'level_offsets': [8, 831, 1044, 1113], 'selected_size': 213, 'level_origin': 867, 'payload_origin': 870, 'allocation_end': 1176})], 5: [({'w': 12, 'h': 5, 'b': 6, 'base': 45, 'level': 0, 'x': 0, 'y': 0}, {'widths': [12, 6, 3, 2], 'heights': [5, 3, 2, 1], 'row_pitches': [74, 38, 20, 14], 'level_sizes': [373, 117, 43, 17], 'directory_size': 8, 'level_offsets': [8, 381, 498, 541], 'selected_size': 373, 'level_origin': 53, 'payload_origin': 56, 'allocation_end': 603}), ({'w': 13, 'h': 6, 'b': 6, 'base': 45, 'level': 1, 'x': 0, 'y': 0}, {'widths': [13, 7, 4, 2], 'heights': [6, 3, 2, 1], 'row_pitches': [80, 44, 26, 14], 'level_sizes': [483, 135, 55, 17], 'directory_size': 8, 'level_offsets': [8, 491, 626, 681], 'selected_size': 135, 'level_origin': 536, 'payload_origin': 539, 'allocation_end': 743}), ({'w': 14, 'h': 7, 'b': 6, 'base': 45, 'level': 2, 'x': 0, 'y': 0}, {'widths': [14, 7, 4, 2], 'heights': [7, 4, 2, 1], 'row_pitches': [86, 44, 26, 14], 'level_sizes': [605, 179, 55, 17], 'directory_size': 8, 'level_offsets': [8, 613, 792, 847], 'selected_size': 55, 'level_origin': 837, 'payload_origin': 840, 'allocation_end': 909}), ({'w': 15, 'h': 8, 'b': 6, 'base': 45, 'level': 3, 'x': 0, 'y': 0}, {'widths': [15, 8, 4, 2], 'heights': [8, 4, 2, 1], 'row_pitches': [92, 50, 26, 14], 'level_sizes': [739, 203, 55, 17], 'directory_size': 8, 'level_offsets': [8, 747, 950, 1005], 'selected_size': 17, 'level_origin': 1050, 'payload_origin': 1053, 'allocation_end': 1067}), ({'w': 16, 'h': 9, 'b': 6, 'base': 45, 'level': 0, 'x': 0, 'y': 0}, {'widths': [16, 8, 4, 2], 'heights': [9, 5, 3, 2], 'row_pitches': [98, 50, 26, 14], 'level_sizes': [885, 253, 81, 31], 'directory_size': 8, 'level_offsets': [8, 893, 1146, 1227], 'selected_size': 885, 'level_origin': 53, 'payload_origin': 56, 'allocation_end': 1303}), ({'w': 17, 'h': 10, 'b': 6, 'base': 45, 'level': 1, 'x': 0, 'y': 0}, {'widths': [17, 9, 5, 3], 'heights': [10, 5, 3, 2], 'row_pitches': [104, 56, 32, 20], 'level_sizes': [1043, 283, 99, 43], 'directory_size': 8, 'level_offsets': [8, 1051, 1334, 1433], 'selected_size': 283, 'level_origin': 1096, 'payload_origin': 1099, 'allocation_end': 1521})]}
for i, (p, expected) in enumerate(cases[N]):
    check("layout fixture " + str(i + 1), solve(p), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(p):
    p = dict(p)
    widths = [max(1,(p["w"]+(1<<i)-1)//(1<<i)) for i in range(4)]
    heights = [max(1,(p["h"]+(1<<i)-1)//(1<<i)) for i in range(4)]
    row_pitches = [w*p["b"]+2 for w in widths]
    level_sizes = [row_pitches[i]*heights[i]+3 for i in range(4)]
    directory_size = 4*2
    level_offsets = [directory_size+sum(level_sizes[:i]) for i in range(4)]
    selected_size = level_sizes[-1]
    level_origin = p["base"]+level_offsets[p["level"]]
    payload_origin = level_origin+3
    allocation_end = p["base"]+directory_size+sum(level_sizes)
    return {'widths': widths, 'heights': heights, 'row_pitches': row_pitches, 'level_sizes': level_sizes, 'directory_size': directory_size, 'level_offsets': level_offsets, 'selected_size': selected_size, 'level_origin': level_origin, 'payload_origin': payload_origin, 'allocation_end': allocation_end}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [({'w': 8, 'h': 5, 'b': 2, 'base': 9, 'level': 0, 'x': 0, 'y': 0}, {'widths': [8, 4, 2, 1], 'heights': [5, 3, 2, 1], 'row_pitches': [18, 10, 6, 4], 'level_sizes': [93, 33, 15, 7], 'directory_size': 8, 'level_offsets': [8, 101, 134, 149], 'selected_size': 93, 'level_origin': 17, 'payload_origin': 20, 'allocation_end': 165}), ({'w': 9, 'h': 6, 'b': 2, 'base': 9, 'level': 1, 'x': 0, 'y': 0}, {'widths': [9, 5, 3, 2], 'heights': [6, 3, 2, 1], 'row_pitches': [20, 12, 8, 6], 'level_sizes': [123, 39, 19, 9], 'directory_size': 8, 'level_offsets': [8, 131, 170, 189], 'selected_size': 39, 'level_origin': 140, 'payload_origin': 143, 'allocation_end': 207}), ({'w': 10, 'h': 7, 'b': 2, 'base': 9, 'level': 2, 'x': 0, 'y': 0}, {'widths': [10, 5, 3, 2], 'heights': [7, 4, 2, 1], 'row_pitches': [22, 12, 8, 6], 'level_sizes': [157, 51, 19, 9], 'directory_size': 8, 'level_offsets': [8, 165, 216, 235], 'selected_size': 19, 'level_origin': 225, 'payload_origin': 228, 'allocation_end': 253}), ({'w': 11, 'h': 8, 'b': 2, 'base': 9, 'level': 3, 'x': 0, 'y': 0}, {'widths': [11, 6, 3, 2], 'heights': [8, 4, 2, 1], 'row_pitches': [24, 14, 8, 6], 'level_sizes': [195, 59, 19, 9], 'directory_size': 8, 'level_offsets': [8, 203, 262, 281], 'selected_size': 9, 'level_origin': 290, 'payload_origin': 293, 'allocation_end': 299}), ({'w': 12, 'h': 9, 'b': 2, 'base': 9, 'level': 0, 'x': 0, 'y': 0}, {'widths': [12, 6, 3, 2], 'heights': [9, 5, 3, 2], 'row_pitches': [26, 14, 8, 6], 'level_sizes': [237, 73, 27, 15], 'directory_size': 8, 'level_offsets': [8, 245, 318, 345], 'selected_size': 237, 'level_origin': 17, 'payload_origin': 20, 'allocation_end': 369}), ({'w': 13, 'h': 10, 'b': 2, 'base': 9, 'level': 1, 'x': 0, 'y': 0}, {'widths': [13, 7, 4, 2], 'heights': [10, 5, 3, 2], 'row_pitches': [28, 16, 10, 6], 'level_sizes': [283, 83, 33, 15], 'directory_size': 8, 'level_offsets': [8, 291, 374, 407], 'selected_size': 83, 'level_origin': 300, 'payload_origin': 303, 'allocation_end': 431})], 2: [({'w': 9, 'h': 5, 'b': 3, 'base': 18, 'level': 0, 'x': 0, 'y': 0}, {'widths': [9, 5, 3, 2], 'heights': [5, 3, 2, 1], 'row_pitches': [29, 17, 11, 8], 'level_sizes': [148, 54, 25, 11], 'directory_size': 8, 'level_offsets': [8, 156, 210, 235], 'selected_size': 148, 'level_origin': 26, 'payload_origin': 29, 'allocation_end': 264}), ({'w': 10, 'h': 6, 'b': 3, 'base': 18, 'level': 1, 'x': 0, 'y': 0}, {'widths': [10, 5, 3, 2], 'heights': [6, 3, 2, 1], 'row_pitches': [32, 17, 11, 8], 'level_sizes': [195, 54, 25, 11], 'directory_size': 8, 'level_offsets': [8, 203, 257, 282], 'selected_size': 54, 'level_origin': 221, 'payload_origin': 224, 'allocation_end': 311}), ({'w': 11, 'h': 7, 'b': 3, 'base': 18, 'level': 2, 'x': 0, 'y': 0}, {'widths': [11, 6, 3, 2], 'heights': [7, 4, 2, 1], 'row_pitches': [35, 20, 11, 8], 'level_sizes': [248, 83, 25, 11], 'directory_size': 8, 'level_offsets': [8, 256, 339, 364], 'selected_size': 25, 'level_origin': 357, 'payload_origin': 360, 'allocation_end': 393}), ({'w': 12, 'h': 8, 'b': 3, 'base': 18, 'level': 3, 'x': 0, 'y': 0}, {'widths': [12, 6, 3, 2], 'heights': [8, 4, 2, 1], 'row_pitches': [38, 20, 11, 8], 'level_sizes': [307, 83, 25, 11], 'directory_size': 8, 'level_offsets': [8, 315, 398, 423], 'selected_size': 11, 'level_origin': 441, 'payload_origin': 444, 'allocation_end': 452}), ({'w': 13, 'h': 9, 'b': 3, 'base': 18, 'level': 0, 'x': 0, 'y': 0}, {'widths': [13, 7, 4, 2], 'heights': [9, 5, 3, 2], 'row_pitches': [41, 23, 14, 8], 'level_sizes': [372, 118, 45, 19], 'directory_size': 8, 'level_offsets': [8, 380, 498, 543], 'selected_size': 372, 'level_origin': 26, 'payload_origin': 29, 'allocation_end': 580}), ({'w': 14, 'h': 10, 'b': 3, 'base': 18, 'level': 1, 'x': 0, 'y': 0}, {'widths': [14, 7, 4, 2], 'heights': [10, 5, 3, 2], 'row_pitches': [44, 23, 14, 8], 'level_sizes': [443, 118, 45, 19], 'directory_size': 8, 'level_offsets': [8, 451, 569, 614], 'selected_size': 118, 'level_origin': 469, 'payload_origin': 472, 'allocation_end': 651})], 3: [({'w': 10, 'h': 5, 'b': 4, 'base': 27, 'level': 0, 'x': 0, 'y': 0}, {'widths': [10, 5, 3, 2], 'heights': [5, 3, 2, 1], 'row_pitches': [42, 22, 14, 10], 'level_sizes': [213, 69, 31, 13], 'directory_size': 8, 'level_offsets': [8, 221, 290, 321], 'selected_size': 213, 'level_origin': 35, 'payload_origin': 38, 'allocation_end': 361}), ({'w': 11, 'h': 6, 'b': 4, 'base': 27, 'level': 1, 'x': 0, 'y': 0}, {'widths': [11, 6, 3, 2], 'heights': [6, 3, 2, 1], 'row_pitches': [46, 26, 14, 10], 'level_sizes': [279, 81, 31, 13], 'directory_size': 8, 'level_offsets': [8, 287, 368, 399], 'selected_size': 81, 'level_origin': 314, 'payload_origin': 317, 'allocation_end': 439}), ({'w': 12, 'h': 7, 'b': 4, 'base': 27, 'level': 2, 'x': 0, 'y': 0}, {'widths': [12, 6, 3, 2], 'heights': [7, 4, 2, 1], 'row_pitches': [50, 26, 14, 10], 'level_sizes': [353, 107, 31, 13], 'directory_size': 8, 'level_offsets': [8, 361, 468, 499], 'selected_size': 31, 'level_origin': 495, 'payload_origin': 498, 'allocation_end': 539}), ({'w': 13, 'h': 8, 'b': 4, 'base': 27, 'level': 3, 'x': 0, 'y': 0}, {'widths': [13, 7, 4, 2], 'heights': [8, 4, 2, 1], 'row_pitches': [54, 30, 18, 10], 'level_sizes': [435, 123, 39, 13], 'directory_size': 8, 'level_offsets': [8, 443, 566, 605], 'selected_size': 13, 'level_origin': 632, 'payload_origin': 635, 'allocation_end': 645}), ({'w': 14, 'h': 9, 'b': 4, 'base': 27, 'level': 0, 'x': 0, 'y': 0}, {'widths': [14, 7, 4, 2], 'heights': [9, 5, 3, 2], 'row_pitches': [58, 30, 18, 10], 'level_sizes': [525, 153, 57, 23], 'directory_size': 8, 'level_offsets': [8, 533, 686, 743], 'selected_size': 525, 'level_origin': 35, 'payload_origin': 38, 'allocation_end': 793}), ({'w': 15, 'h': 10, 'b': 4, 'base': 27, 'level': 1, 'x': 0, 'y': 0}, {'widths': [15, 8, 4, 2], 'heights': [10, 5, 3, 2], 'row_pitches': [62, 34, 18, 10], 'level_sizes': [623, 173, 57, 23], 'directory_size': 8, 'level_offsets': [8, 631, 804, 861], 'selected_size': 173, 'level_origin': 658, 'payload_origin': 661, 'allocation_end': 911})], 4: [({'w': 11, 'h': 5, 'b': 5, 'base': 36, 'level': 0, 'x': 0, 'y': 0}, {'widths': [11, 6, 3, 2], 'heights': [5, 3, 2, 1], 'row_pitches': [57, 32, 17, 12], 'level_sizes': [288, 99, 37, 15], 'directory_size': 8, 'level_offsets': [8, 296, 395, 432], 'selected_size': 288, 'level_origin': 44, 'payload_origin': 47, 'allocation_end': 483}), ({'w': 12, 'h': 6, 'b': 5, 'base': 36, 'level': 1, 'x': 0, 'y': 0}, {'widths': [12, 6, 3, 2], 'heights': [6, 3, 2, 1], 'row_pitches': [62, 32, 17, 12], 'level_sizes': [375, 99, 37, 15], 'directory_size': 8, 'level_offsets': [8, 383, 482, 519], 'selected_size': 99, 'level_origin': 419, 'payload_origin': 422, 'allocation_end': 570}), ({'w': 13, 'h': 7, 'b': 5, 'base': 36, 'level': 2, 'x': 0, 'y': 0}, {'widths': [13, 7, 4, 2], 'heights': [7, 4, 2, 1], 'row_pitches': [67, 37, 22, 12], 'level_sizes': [472, 151, 47, 15], 'directory_size': 8, 'level_offsets': [8, 480, 631, 678], 'selected_size': 47, 'level_origin': 667, 'payload_origin': 670, 'allocation_end': 729}), ({'w': 14, 'h': 8, 'b': 5, 'base': 36, 'level': 3, 'x': 0, 'y': 0}, {'widths': [14, 7, 4, 2], 'heights': [8, 4, 2, 1], 'row_pitches': [72, 37, 22, 12], 'level_sizes': [579, 151, 47, 15], 'directory_size': 8, 'level_offsets': [8, 587, 738, 785], 'selected_size': 15, 'level_origin': 821, 'payload_origin': 824, 'allocation_end': 836}), ({'w': 15, 'h': 9, 'b': 5, 'base': 36, 'level': 0, 'x': 0, 'y': 0}, {'widths': [15, 8, 4, 2], 'heights': [9, 5, 3, 2], 'row_pitches': [77, 42, 22, 12], 'level_sizes': [696, 213, 69, 27], 'directory_size': 8, 'level_offsets': [8, 704, 917, 986], 'selected_size': 696, 'level_origin': 44, 'payload_origin': 47, 'allocation_end': 1049}), ({'w': 16, 'h': 10, 'b': 5, 'base': 36, 'level': 1, 'x': 0, 'y': 0}, {'widths': [16, 8, 4, 2], 'heights': [10, 5, 3, 2], 'row_pitches': [82, 42, 22, 12], 'level_sizes': [823, 213, 69, 27], 'directory_size': 8, 'level_offsets': [8, 831, 1044, 1113], 'selected_size': 213, 'level_origin': 867, 'payload_origin': 870, 'allocation_end': 1176})], 5: [({'w': 12, 'h': 5, 'b': 6, 'base': 45, 'level': 0, 'x': 0, 'y': 0}, {'widths': [12, 6, 3, 2], 'heights': [5, 3, 2, 1], 'row_pitches': [74, 38, 20, 14], 'level_sizes': [373, 117, 43, 17], 'directory_size': 8, 'level_offsets': [8, 381, 498, 541], 'selected_size': 373, 'level_origin': 53, 'payload_origin': 56, 'allocation_end': 603}), ({'w': 13, 'h': 6, 'b': 6, 'base': 45, 'level': 1, 'x': 0, 'y': 0}, {'widths': [13, 7, 4, 2], 'heights': [6, 3, 2, 1], 'row_pitches': [80, 44, 26, 14], 'level_sizes': [483, 135, 55, 17], 'directory_size': 8, 'level_offsets': [8, 491, 626, 681], 'selected_size': 135, 'level_origin': 536, 'payload_origin': 539, 'allocation_end': 743}), ({'w': 14, 'h': 7, 'b': 6, 'base': 45, 'level': 2, 'x': 0, 'y': 0}, {'widths': [14, 7, 4, 2], 'heights': [7, 4, 2, 1], 'row_pitches': [86, 44, 26, 14], 'level_sizes': [605, 179, 55, 17], 'directory_size': 8, 'level_offsets': [8, 613, 792, 847], 'selected_size': 55, 'level_origin': 837, 'payload_origin': 840, 'allocation_end': 909}), ({'w': 15, 'h': 8, 'b': 6, 'base': 45, 'level': 3, 'x': 0, 'y': 0}, {'widths': [15, 8, 4, 2], 'heights': [8, 4, 2, 1], 'row_pitches': [92, 50, 26, 14], 'level_sizes': [739, 203, 55, 17], 'directory_size': 8, 'level_offsets': [8, 747, 950, 1005], 'selected_size': 17, 'level_origin': 1050, 'payload_origin': 1053, 'allocation_end': 1067}), ({'w': 16, 'h': 9, 'b': 6, 'base': 45, 'level': 0, 'x': 0, 'y': 0}, {'widths': [16, 8, 4, 2], 'heights': [9, 5, 3, 2], 'row_pitches': [98, 50, 26, 14], 'level_sizes': [885, 253, 81, 31], 'directory_size': 8, 'level_offsets': [8, 893, 1146, 1227], 'selected_size': 885, 'level_origin': 53, 'payload_origin': 56, 'allocation_end': 1303}), ({'w': 17, 'h': 10, 'b': 6, 'base': 45, 'level': 1, 'x': 0, 'y': 0}, {'widths': [17, 9, 5, 3], 'heights': [10, 5, 3, 2], 'row_pitches': [104, 56, 32, 20], 'level_sizes': [1043, 283, 99, 43], 'directory_size': 8, 'level_offsets': [8, 1051, 1334, 1433], 'selected_size': 283, 'level_origin': 1096, 'payload_origin': 1099, 'allocation_end': 1521})]}
for i, (p, expected) in enumerate(cases[N]):
    check("layout fixture " + str(i + 1), solve(p), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The returned physical layout descriptor disagrees with the declared buffer mapping at selected_size.

Store four mip levels consecutively. Each level uses ceil-halving, keeps dimensions at least one, has a two-byte row guard and a three-byte level header. A four-entry directory of two-byte offsets precedes all levels. Return the named intermediate layout descriptor and final address fields; all quantities are integer byte offsets unless explicitly stated.

split: open-access


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

N = 1
observations = []
def solve(p):
    p = dict(p)
    widths = [max(1,(p["w"]+(1<<i)-1)//(1<<i)) for i in range(4)]
    heights = [max(1,(p["h"]+(1<<i)-1)//(1<<i)) for i in range(4)]
    row_pitches = [w*p["b"]+2 for w in widths]
    level_sizes = [row_pitches[i]*heights[i]+3 for i in range(4)]
    directory_size = 4*2
    level_offsets = [directory_size+sum(level_sizes[:i]) for i in range(4)]
    selected_size = level_sizes[p["level"]]
    level_origin = p["base"]+level_offsets[0]
    payload_origin = level_origin+3
    allocation_end = p["base"]+directory_size+sum(level_sizes)
    return {'widths': widths, 'heights': heights, 'row_pitches': row_pitches, 'level_sizes': level_sizes, 'directory_size': directory_size, 'level_offsets': level_offsets, 'selected_size': selected_size, 'level_origin': level_origin, 'payload_origin': payload_origin, 'allocation_end': allocation_end}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [({'w': 8, 'h': 5, 'b': 2, 'base': 9, 'level': 0, 'x': 0, 'y': 0}, {'widths': [8, 4, 2, 1], 'heights': [5, 3, 2, 1], 'row_pitches': [18, 10, 6, 4], 'level_sizes': [93, 33, 15, 7], 'directory_size': 8, 'level_offsets': [8, 101, 134, 149], 'selected_size': 93, 'level_origin': 17, 'payload_origin': 20, 'allocation_end': 165}), ({'w': 9, 'h': 6, 'b': 2, 'base': 9, 'level': 1, 'x': 0, 'y': 0}, {'widths': [9, 5, 3, 2], 'heights': [6, 3, 2, 1], 'row_pitches': [20, 12, 8, 6], 'level_sizes': [123, 39, 19, 9], 'directory_size': 8, 'level_offsets': [8, 131, 170, 189], 'selected_size': 39, 'level_origin': 140, 'payload_origin': 143, 'allocation_end': 207}), ({'w': 10, 'h': 7, 'b': 2, 'base': 9, 'level': 2, 'x': 0, 'y': 0}, {'widths': [10, 5, 3, 2], 'heights': [7, 4, 2, 1], 'row_pitches': [22, 12, 8, 6], 'level_sizes': [157, 51, 19, 9], 'directory_size': 8, 'level_offsets': [8, 165, 216, 235], 'selected_size': 19, 'level_origin': 225, 'payload_origin': 228, 'allocation_end': 253}), ({'w': 11, 'h': 8, 'b': 2, 'base': 9, 'level': 3, 'x': 0, 'y': 0}, {'widths': [11, 6, 3, 2], 'heights': [8, 4, 2, 1], 'row_pitches': [24, 14, 8, 6], 'level_sizes': [195, 59, 19, 9], 'directory_size': 8, 'level_offsets': [8, 203, 262, 281], 'selected_size': 9, 'level_origin': 290, 'payload_origin': 293, 'allocation_end': 299}), ({'w': 12, 'h': 9, 'b': 2, 'base': 9, 'level': 0, 'x': 0, 'y': 0}, {'widths': [12, 6, 3, 2], 'heights': [9, 5, 3, 2], 'row_pitches': [26, 14, 8, 6], 'level_sizes': [237, 73, 27, 15], 'directory_size': 8, 'level_offsets': [8, 245, 318, 345], 'selected_size': 237, 'level_origin': 17, 'payload_origin': 20, 'allocation_end': 369}), ({'w': 13, 'h': 10, 'b': 2, 'base': 9, 'level': 1, 'x': 0, 'y': 0}, {'widths': [13, 7, 4, 2], 'heights': [10, 5, 3, 2], 'row_pitches': [28, 16, 10, 6], 'level_sizes': [283, 83, 33, 15], 'directory_size': 8, 'level_offsets': [8, 291, 374, 407], 'selected_size': 83, 'level_origin': 300, 'payload_origin': 303, 'allocation_end': 431})], 2: [({'w': 9, 'h': 5, 'b': 3, 'base': 18, 'level': 0, 'x': 0, 'y': 0}, {'widths': [9, 5, 3, 2], 'heights': [5, 3, 2, 1], 'row_pitches': [29, 17, 11, 8], 'level_sizes': [148, 54, 25, 11], 'directory_size': 8, 'level_offsets': [8, 156, 210, 235], 'selected_size': 148, 'level_origin': 26, 'payload_origin': 29, 'allocation_end': 264}), ({'w': 10, 'h': 6, 'b': 3, 'base': 18, 'level': 1, 'x': 0, 'y': 0}, {'widths': [10, 5, 3, 2], 'heights': [6, 3, 2, 1], 'row_pitches': [32, 17, 11, 8], 'level_sizes': [195, 54, 25, 11], 'directory_size': 8, 'level_offsets': [8, 203, 257, 282], 'selected_size': 54, 'level_origin': 221, 'payload_origin': 224, 'allocation_end': 311}), ({'w': 11, 'h': 7, 'b': 3, 'base': 18, 'level': 2, 'x': 0, 'y': 0}, {'widths': [11, 6, 3, 2], 'heights': [7, 4, 2, 1], 'row_pitches': [35, 20, 11, 8], 'level_sizes': [248, 83, 25, 11], 'directory_size': 8, 'level_offsets': [8, 256, 339, 364], 'selected_size': 25, 'level_origin': 357, 'payload_origin': 360, 'allocation_end': 393}), ({'w': 12, 'h': 8, 'b': 3, 'base': 18, 'level': 3, 'x': 0, 'y': 0}, {'widths': [12, 6, 3, 2], 'heights': [8, 4, 2, 1], 'row_pitches': [38, 20, 11, 8], 'level_sizes': [307, 83, 25, 11], 'directory_size': 8, 'level_offsets': [8, 315, 398, 423], 'selected_size': 11, 'level_origin': 441, 'payload_origin': 444, 'allocation_end': 452}), ({'w': 13, 'h': 9, 'b': 3, 'base': 18, 'level': 0, 'x': 0, 'y': 0}, {'widths': [13, 7, 4, 2], 'heights': [9, 5, 3, 2], 'row_pitches': [41, 23, 14, 8], 'level_sizes': [372, 118, 45, 19], 'directory_size': 8, 'level_offsets': [8, 380, 498, 543], 'selected_size': 372, 'level_origin': 26, 'payload_origin': 29, 'allocation_end': 580}), ({'w': 14, 'h': 10, 'b': 3, 'base': 18, 'level': 1, 'x': 0, 'y': 0}, {'widths': [14, 7, 4, 2], 'heights': [10, 5, 3, 2], 'row_pitches': [44, 23, 14, 8], 'level_sizes': [443, 118, 45, 19], 'directory_size': 8, 'level_offsets': [8, 451, 569, 614], 'selected_size': 118, 'level_origin': 469, 'payload_origin': 472, 'allocation_end': 651})], 3: [({'w': 10, 'h': 5, 'b': 4, 'base': 27, 'level': 0, 'x': 0, 'y': 0}, {'widths': [10, 5, 3, 2], 'heights': [5, 3, 2, 1], 'row_pitches': [42, 22, 14, 10], 'level_sizes': [213, 69, 31, 13], 'directory_size': 8, 'level_offsets': [8, 221, 290, 321], 'selected_size': 213, 'level_origin': 35, 'payload_origin': 38, 'allocation_end': 361}), ({'w': 11, 'h': 6, 'b': 4, 'base': 27, 'level': 1, 'x': 0, 'y': 0}, {'widths': [11, 6, 3, 2], 'heights': [6, 3, 2, 1], 'row_pitches': [46, 26, 14, 10], 'level_sizes': [279, 81, 31, 13], 'directory_size': 8, 'level_offsets': [8, 287, 368, 399], 'selected_size': 81, 'level_origin': 314, 'payload_origin': 317, 'allocation_end': 439}), ({'w': 12, 'h': 7, 'b': 4, 'base': 27, 'level': 2, 'x': 0, 'y': 0}, {'widths': [12, 6, 3, 2], 'heights': [7, 4, 2, 1], 'row_pitches': [50, 26, 14, 10], 'level_sizes': [353, 107, 31, 13], 'directory_size': 8, 'level_offsets': [8, 361, 468, 499], 'selected_size': 31, 'level_origin': 495, 'payload_origin': 498, 'allocation_end': 539}), ({'w': 13, 'h': 8, 'b': 4, 'base': 27, 'level': 3, 'x': 0, 'y': 0}, {'widths': [13, 7, 4, 2], 'heights': [8, 4, 2, 1], 'row_pitches': [54, 30, 18, 10], 'level_sizes': [435, 123, 39, 13], 'directory_size': 8, 'level_offsets': [8, 443, 566, 605], 'selected_size': 13, 'level_origin': 632, 'payload_origin': 635, 'allocation_end': 645}), ({'w': 14, 'h': 9, 'b': 4, 'base': 27, 'level': 0, 'x': 0, 'y': 0}, {'widths': [14, 7, 4, 2], 'heights': [9, 5, 3, 2], 'row_pitches': [58, 30, 18, 10], 'level_sizes': [525, 153, 57, 23], 'directory_size': 8, 'level_offsets': [8, 533, 686, 743], 'selected_size': 525, 'level_origin': 35, 'payload_origin': 38, 'allocation_end': 793}), ({'w': 15, 'h': 10, 'b': 4, 'base': 27, 'level': 1, 'x': 0, 'y': 0}, {'widths': [15, 8, 4, 2], 'heights': [10, 5, 3, 2], 'row_pitches': [62, 34, 18, 10], 'level_sizes': [623, 173, 57, 23], 'directory_size': 8, 'level_offsets': [8, 631, 804, 861], 'selected_size': 173, 'level_origin': 658, 'payload_origin': 661, 'allocation_end': 911})], 4: [({'w': 11, 'h': 5, 'b': 5, 'base': 36, 'level': 0, 'x': 0, 'y': 0}, {'widths': [11, 6, 3, 2], 'heights': [5, 3, 2, 1], 'row_pitches': [57, 32, 17, 12], 'level_sizes': [288, 99, 37, 15], 'directory_size': 8, 'level_offsets': [8, 296, 395, 432], 'selected_size': 288, 'level_origin': 44, 'payload_origin': 47, 'allocation_end': 483}), ({'w': 12, 'h': 6, 'b': 5, 'base': 36, 'level': 1, 'x': 0, 'y': 0}, {'widths': [12, 6, 3, 2], 'heights': [6, 3, 2, 1], 'row_pitches': [62, 32, 17, 12], 'level_sizes': [375, 99, 37, 15], 'directory_size': 8, 'level_offsets': [8, 383, 482, 519], 'selected_size': 99, 'level_origin': 419, 'payload_origin': 422, 'allocation_end': 570}), ({'w': 13, 'h': 7, 'b': 5, 'base': 36, 'level': 2, 'x': 0, 'y': 0}, {'widths': [13, 7, 4, 2], 'heights': [7, 4, 2, 1], 'row_pitches': [67, 37, 22, 12], 'level_sizes': [472, 151, 47, 15], 'directory_size': 8, 'level_offsets': [8, 480, 631, 678], 'selected_size': 47, 'level_origin': 667, 'payload_origin': 670, 'allocation_end': 729}), ({'w': 14, 'h': 8, 'b': 5, 'base': 36, 'level': 3, 'x': 0, 'y': 0}, {'widths': [14, 7, 4, 2], 'heights': [8, 4, 2, 1], 'row_pitches': [72, 37, 22, 12], 'level_sizes': [579, 151, 47, 15], 'directory_size': 8, 'level_offsets': [8, 587, 738, 785], 'selected_size': 15, 'level_origin': 821, 'payload_origin': 824, 'allocation_end': 836}), ({'w': 15, 'h': 9, 'b': 5, 'base': 36, 'level': 0, 'x': 0, 'y': 0}, {'widths': [15, 8, 4, 2], 'heights': [9, 5, 3, 2], 'row_pitches': [77, 42, 22, 12], 'level_sizes': [696, 213, 69, 27], 'directory_size': 8, 'level_offsets': [8, 704, 917, 986], 'selected_size': 696, 'level_origin': 44, 'payload_origin': 47, 'allocation_end': 1049}), ({'w': 16, 'h': 10, 'b': 5, 'base': 36, 'level': 1, 'x': 0, 'y': 0}, {'widths': [16, 8, 4, 2], 'heights': [10, 5, 3, 2], 'row_pitches': [82, 42, 22, 12], 'level_sizes': [823, 213, 69, 27], 'directory_size': 8, 'level_offsets': [8, 831, 1044, 1113], 'selected_size': 213, 'level_origin': 867, 'payload_origin': 870, 'allocation_end': 1176})], 5: [({'w': 12, 'h': 5, 'b': 6, 'base': 45, 'level': 0, 'x': 0, 'y': 0}, {'widths': [12, 6, 3, 2], 'heights': [5, 3, 2, 1], 'row_pitches': [74, 38, 20, 14], 'level_sizes': [373, 117, 43, 17], 'directory_size': 8, 'level_offsets': [8, 381, 498, 541], 'selected_size': 373, 'level_origin': 53, 'payload_origin': 56, 'allocation_end': 603}), ({'w': 13, 'h': 6, 'b': 6, 'base': 45, 'level': 1, 'x': 0, 'y': 0}, {'widths': [13, 7, 4, 2], 'heights': [6, 3, 2, 1], 'row_pitches': [80, 44, 26, 14], 'level_sizes': [483, 135, 55, 17], 'directory_size': 8, 'level_offsets': [8, 491, 626, 681], 'selected_size': 135, 'level_origin': 536, 'payload_origin': 539, 'allocation_end': 743}), ({'w': 14, 'h': 7, 'b': 6, 'base': 45, 'level': 2, 'x': 0, 'y': 0}, {'widths': [14, 7, 4, 2], 'heights': [7, 4, 2, 1], 'row_pitches': [86, 44, 26, 14], 'level_sizes': [605, 179, 55, 17], 'directory_size': 8, 'level_offsets': [8, 613, 792, 847], 'selected_size': 55, 'level_origin': 837, 'payload_origin': 840, 'allocation_end': 909}), ({'w': 15, 'h': 8, 'b': 6, 'base': 45, 'level': 3, 'x': 0, 'y': 0}, {'widths': [15, 8, 4, 2], 'heights': [8, 4, 2, 1], 'row_pitches': [92, 50, 26, 14], 'level_sizes': [739, 203, 55, 17], 'directory_size': 8, 'level_offsets': [8, 747, 950, 1005], 'selected_size': 17, 'level_origin': 1050, 'payload_origin': 1053, 'allocation_end': 1067}), ({'w': 16, 'h': 9, 'b': 6, 'base': 45, 'level': 0, 'x': 0, 'y': 0}, {'widths': [16, 8, 4, 2], 'heights': [9, 5, 3, 2], 'row_pitches': [98, 50, 26, 14], 'level_sizes': [885, 253, 81, 31], 'directory_size': 8, 'level_offsets': [8, 893, 1146, 1227], 'selected_size': 885, 'level_origin': 53, 'payload_origin': 56, 'allocation_end': 1303}), ({'w': 17, 'h': 10, 'b': 6, 'base': 45, 'level': 1, 'x': 0, 'y': 0}, {'widths': [17, 9, 5, 3], 'heights': [10, 5, 3, 2], 'row_pitches': [104, 56, 32, 20], 'level_sizes': [1043, 283, 99, 43], 'directory_size': 8, 'level_offsets': [8, 1051, 1334, 1433], 'selected_size': 283, 'level_origin': 1096, 'payload_origin': 1099, 'allocation_end': 1521})]}
for i, (p, expected) in enumerate(cases[N]):
    check("layout fixture " + str(i + 1), solve(p), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(p):
    p = dict(p)
    widths = [max(1,(p["w"]+(1<<i)-1)//(1<<i)) for i in range(4)]
    heights = [max(1,(p["h"]+(1<<i)-1)//(1<<i)) for i in range(4)]
    row_pitches = [w*p["b"]+2 for w in widths]
    level_sizes = [row_pitches[i]*heights[i]+3 for i in range(4)]
    directory_size = 4*2
    level_offsets = [directory_size+sum(level_sizes[:i]) for i in range(4)]
    selected_size = level_sizes[p["level"]]
    level_origin = level_offsets[p["level"]]
    payload_origin = level_origin+3
    allocation_end = p["base"]+directory_size+sum(level_sizes)
    return {'widths': widths, 'heights': heights, 'row_pitches': row_pitches, 'level_sizes': level_sizes, 'directory_size': directory_size, 'level_offsets': level_offsets, 'selected_size': selected_size, 'level_origin': level_origin, 'payload_origin': payload_origin, 'allocation_end': allocation_end}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [({'w': 8, 'h': 5, 'b': 2, 'base': 9, 'level': 0, 'x': 0, 'y': 0}, {'widths': [8, 4, 2, 1], 'heights': [5, 3, 2, 1], 'row_pitches': [18, 10, 6, 4], 'level_sizes': [93, 33, 15, 7], 'directory_size': 8, 'level_offsets': [8, 101, 134, 149], 'selected_size': 93, 'level_origin': 17, 'payload_origin': 20, 'allocation_end': 165}), ({'w': 9, 'h': 6, 'b': 2, 'base': 9, 'level': 1, 'x': 0, 'y': 0}, {'widths': [9, 5, 3, 2], 'heights': [6, 3, 2, 1], 'row_pitches': [20, 12, 8, 6], 'level_sizes': [123, 39, 19, 9], 'directory_size': 8, 'level_offsets': [8, 131, 170, 189], 'selected_size': 39, 'level_origin': 140, 'payload_origin': 143, 'allocation_end': 207}), ({'w': 10, 'h': 7, 'b': 2, 'base': 9, 'level': 2, 'x': 0, 'y': 0}, {'widths': [10, 5, 3, 2], 'heights': [7, 4, 2, 1], 'row_pitches': [22, 12, 8, 6], 'level_sizes': [157, 51, 19, 9], 'directory_size': 8, 'level_offsets': [8, 165, 216, 235], 'selected_size': 19, 'level_origin': 225, 'payload_origin': 228, 'allocation_end': 253}), ({'w': 11, 'h': 8, 'b': 2, 'base': 9, 'level': 3, 'x': 0, 'y': 0}, {'widths': [11, 6, 3, 2], 'heights': [8, 4, 2, 1], 'row_pitches': [24, 14, 8, 6], 'level_sizes': [195, 59, 19, 9], 'directory_size': 8, 'level_offsets': [8, 203, 262, 281], 'selected_size': 9, 'level_origin': 290, 'payload_origin': 293, 'allocation_end': 299}), ({'w': 12, 'h': 9, 'b': 2, 'base': 9, 'level': 0, 'x': 0, 'y': 0}, {'widths': [12, 6, 3, 2], 'heights': [9, 5, 3, 2], 'row_pitches': [26, 14, 8, 6], 'level_sizes': [237, 73, 27, 15], 'directory_size': 8, 'level_offsets': [8, 245, 318, 345], 'selected_size': 237, 'level_origin': 17, 'payload_origin': 20, 'allocation_end': 369}), ({'w': 13, 'h': 10, 'b': 2, 'base': 9, 'level': 1, 'x': 0, 'y': 0}, {'widths': [13, 7, 4, 2], 'heights': [10, 5, 3, 2], 'row_pitches': [28, 16, 10, 6], 'level_sizes': [283, 83, 33, 15], 'directory_size': 8, 'level_offsets': [8, 291, 374, 407], 'selected_size': 83, 'level_origin': 300, 'payload_origin': 303, 'allocation_end': 431})], 2: [({'w': 9, 'h': 5, 'b': 3, 'base': 18, 'level': 0, 'x': 0, 'y': 0}, {'widths': [9, 5, 3, 2], 'heights': [5, 3, 2, 1], 'row_pitches': [29, 17, 11, 8], 'level_sizes': [148, 54, 25, 11], 'directory_size': 8, 'level_offsets': [8, 156, 210, 235], 'selected_size': 148, 'level_origin': 26, 'payload_origin': 29, 'allocation_end': 264}), ({'w': 10, 'h': 6, 'b': 3, 'base': 18, 'level': 1, 'x': 0, 'y': 0}, {'widths': [10, 5, 3, 2], 'heights': [6, 3, 2, 1], 'row_pitches': [32, 17, 11, 8], 'level_sizes': [195, 54, 25, 11], 'directory_size': 8, 'level_offsets': [8, 203, 257, 282], 'selected_size': 54, 'level_origin': 221, 'payload_origin': 224, 'allocation_end': 311}), ({'w': 11, 'h': 7, 'b': 3, 'base': 18, 'level': 2, 'x': 0, 'y': 0}, {'widths': [11, 6, 3, 2], 'heights': [7, 4, 2, 1], 'row_pitches': [35, 20, 11, 8], 'level_sizes': [248, 83, 25, 11], 'directory_size': 8, 'level_offsets': [8, 256, 339, 364], 'selected_size': 25, 'level_origin': 357, 'payload_origin': 360, 'allocation_end': 393}), ({'w': 12, 'h': 8, 'b': 3, 'base': 18, 'level': 3, 'x': 0, 'y': 0}, {'widths': [12, 6, 3, 2], 'heights': [8, 4, 2, 1], 'row_pitches': [38, 20, 11, 8], 'level_sizes': [307, 83, 25, 11], 'directory_size': 8, 'level_offsets': [8, 315, 398, 423], 'selected_size': 11, 'level_origin': 441, 'payload_origin': 444, 'allocation_end': 452}), ({'w': 13, 'h': 9, 'b': 3, 'base': 18, 'level': 0, 'x': 0, 'y': 0}, {'widths': [13, 7, 4, 2], 'heights': [9, 5, 3, 2], 'row_pitches': [41, 23, 14, 8], 'level_sizes': [372, 118, 45, 19], 'directory_size': 8, 'level_offsets': [8, 380, 498, 543], 'selected_size': 372, 'level_origin': 26, 'payload_origin': 29, 'allocation_end': 580}), ({'w': 14, 'h': 10, 'b': 3, 'base': 18, 'level': 1, 'x': 0, 'y': 0}, {'widths': [14, 7, 4, 2], 'heights': [10, 5, 3, 2], 'row_pitches': [44, 23, 14, 8], 'level_sizes': [443, 118, 45, 19], 'directory_size': 8, 'level_offsets': [8, 451, 569, 614], 'selected_size': 118, 'level_origin': 469, 'payload_origin': 472, 'allocation_end': 651})], 3: [({'w': 10, 'h': 5, 'b': 4, 'base': 27, 'level': 0, 'x': 0, 'y': 0}, {'widths': [10, 5, 3, 2], 'heights': [5, 3, 2, 1], 'row_pitches': [42, 22, 14, 10], 'level_sizes': [213, 69, 31, 13], 'directory_size': 8, 'level_offsets': [8, 221, 290, 321], 'selected_size': 213, 'level_origin': 35, 'payload_origin': 38, 'allocation_end': 361}), ({'w': 11, 'h': 6, 'b': 4, 'base': 27, 'level': 1, 'x': 0, 'y': 0}, {'widths': [11, 6, 3, 2], 'heights': [6, 3, 2, 1], 'row_pitches': [46, 26, 14, 10], 'level_sizes': [279, 81, 31, 13], 'directory_size': 8, 'level_offsets': [8, 287, 368, 399], 'selected_size': 81, 'level_origin': 314, 'payload_origin': 317, 'allocation_end': 439}), ({'w': 12, 'h': 7, 'b': 4, 'base': 27, 'level': 2, 'x': 0, 'y': 0}, {'widths': [12, 6, 3, 2], 'heights': [7, 4, 2, 1], 'row_pitches': [50, 26, 14, 10], 'level_sizes': [353, 107, 31, 13], 'directory_size': 8, 'level_offsets': [8, 361, 468, 499], 'selected_size': 31, 'level_origin': 495, 'payload_origin': 498, 'allocation_end': 539}), ({'w': 13, 'h': 8, 'b': 4, 'base': 27, 'level': 3, 'x': 0, 'y': 0}, {'widths': [13, 7, 4, 2], 'heights': [8, 4, 2, 1], 'row_pitches': [54, 30, 18, 10], 'level_sizes': [435, 123, 39, 13], 'directory_size': 8, 'level_offsets': [8, 443, 566, 605], 'selected_size': 13, 'level_origin': 632, 'payload_origin': 635, 'allocation_end': 645}), ({'w': 14, 'h': 9, 'b': 4, 'base': 27, 'level': 0, 'x': 0, 'y': 0}, {'widths': [14, 7, 4, 2], 'heights': [9, 5, 3, 2], 'row_pitches': [58, 30, 18, 10], 'level_sizes': [525, 153, 57, 23], 'directory_size': 8, 'level_offsets': [8, 533, 686, 743], 'selected_size': 525, 'level_origin': 35, 'payload_origin': 38, 'allocation_end': 793}), ({'w': 15, 'h': 10, 'b': 4, 'base': 27, 'level': 1, 'x': 0, 'y': 0}, {'widths': [15, 8, 4, 2], 'heights': [10, 5, 3, 2], 'row_pitches': [62, 34, 18, 10], 'level_sizes': [623, 173, 57, 23], 'directory_size': 8, 'level_offsets': [8, 631, 804, 861], 'selected_size': 173, 'level_origin': 658, 'payload_origin': 661, 'allocation_end': 911})], 4: [({'w': 11, 'h': 5, 'b': 5, 'base': 36, 'level': 0, 'x': 0, 'y': 0}, {'widths': [11, 6, 3, 2], 'heights': [5, 3, 2, 1], 'row_pitches': [57, 32, 17, 12], 'level_sizes': [288, 99, 37, 15], 'directory_size': 8, 'level_offsets': [8, 296, 395, 432], 'selected_size': 288, 'level_origin': 44, 'payload_origin': 47, 'allocation_end': 483}), ({'w': 12, 'h': 6, 'b': 5, 'base': 36, 'level': 1, 'x': 0, 'y': 0}, {'widths': [12, 6, 3, 2], 'heights': [6, 3, 2, 1], 'row_pitches': [62, 32, 17, 12], 'level_sizes': [375, 99, 37, 15], 'directory_size': 8, 'level_offsets': [8, 383, 482, 519], 'selected_size': 99, 'level_origin': 419, 'payload_origin': 422, 'allocation_end': 570}), ({'w': 13, 'h': 7, 'b': 5, 'base': 36, 'level': 2, 'x': 0, 'y': 0}, {'widths': [13, 7, 4, 2], 'heights': [7, 4, 2, 1], 'row_pitches': [67, 37, 22, 12], 'level_sizes': [472, 151, 47, 15], 'directory_size': 8, 'level_offsets': [8, 480, 631, 678], 'selected_size': 47, 'level_origin': 667, 'payload_origin': 670, 'allocation_end': 729}), ({'w': 14, 'h': 8, 'b': 5, 'base': 36, 'level': 3, 'x': 0, 'y': 0}, {'widths': [14, 7, 4, 2], 'heights': [8, 4, 2, 1], 'row_pitches': [72, 37, 22, 12], 'level_sizes': [579, 151, 47, 15], 'directory_size': 8, 'level_offsets': [8, 587, 738, 785], 'selected_size': 15, 'level_origin': 821, 'payload_origin': 824, 'allocation_end': 836}), ({'w': 15, 'h': 9, 'b': 5, 'base': 36, 'level': 0, 'x': 0, 'y': 0}, {'widths': [15, 8, 4, 2], 'heights': [9, 5, 3, 2], 'row_pitches': [77, 42, 22, 12], 'level_sizes': [696, 213, 69, 27], 'directory_size': 8, 'level_offsets': [8, 704, 917, 986], 'selected_size': 696, 'level_origin': 44, 'payload_origin': 47, 'allocation_end': 1049}), ({'w': 16, 'h': 10, 'b': 5, 'base': 36, 'level': 1, 'x': 0, 'y': 0}, {'widths': [16, 8, 4, 2], 'heights': [10, 5, 3, 2], 'row_pitches': [82, 42, 22, 12], 'level_sizes': [823, 213, 69, 27], 'directory_size': 8, 'level_offsets': [8, 831, 1044, 1113], 'selected_size': 213, 'level_origin': 867, 'payload_origin': 870, 'allocation_end': 1176})], 5: [({'w': 12, 'h': 5, 'b': 6, 'base': 45, 'level': 0, 'x': 0, 'y': 0}, {'widths': [12, 6, 3, 2], 'heights': [5, 3, 2, 1], 'row_pitches': [74, 38, 20, 14], 'level_sizes': [373, 117, 43, 17], 'directory_size': 8, 'level_offsets': [8, 381, 498, 541], 'selected_size': 373, 'level_origin': 53, 'payload_origin': 56, 'allocation_end': 603}), ({'w': 13, 'h': 6, 'b': 6, 'base': 45, 'level': 1, 'x': 0, 'y': 0}, {'widths': [13, 7, 4, 2], 'heights': [6, 3, 2, 1], 'row_pitches': [80, 44, 26, 14], 'level_sizes': [483, 135, 55, 17], 'directory_size': 8, 'level_offsets': [8, 491, 626, 681], 'selected_size': 135, 'level_origin': 536, 'payload_origin': 539, 'allocation_end': 743}), ({'w': 14, 'h': 7, 'b': 6, 'base': 45, 'level': 2, 'x': 0, 'y': 0}, {'widths': [14, 7, 4, 2], 'heights': [7, 4, 2, 1], 'row_pitches': [86, 44, 26, 14], 'level_sizes': [605, 179, 55, 17], 'directory_size': 8, 'level_offsets': [8, 613, 792, 847], 'selected_size': 55, 'level_origin': 837, 'payload_origin': 840, 'allocation_end': 909}), ({'w': 15, 'h': 8, 'b': 6, 'base': 45, 'level': 3, 'x': 0, 'y': 0}, {'widths': [15, 8, 4, 2], 'heights': [8, 4, 2, 1], 'row_pitches': [92, 50, 26, 14], 'level_sizes': [739, 203, 55, 17], 'directory_size': 8, 'level_offsets': [8, 747, 950, 1005], 'selected_size': 17, 'level_origin': 1050, 'payload_origin': 1053, 'allocation_end': 1067}), ({'w': 16, 'h': 9, 'b': 6, 'base': 45, 'level': 0, 'x': 0, 'y': 0}, {'widths': [16, 8, 4, 2], 'heights': [9, 5, 3, 2], 'row_pitches': [98, 50, 26, 14], 'level_sizes': [885, 253, 81, 31], 'directory_size': 8, 'level_offsets': [8, 893, 1146, 1227], 'selected_size': 885, 'level_origin': 53, 'payload_origin': 56, 'allocation_end': 1303}), ({'w': 17, 'h': 10, 'b': 6, 'base': 45, 'level': 1, 'x': 0, 'y': 0}, {'widths': [17, 9, 5, 3], 'heights': [10, 5, 3, 2], 'row_pitches': [104, 56, 32, 20], 'level_sizes': [1043, 283, 99, 43], 'directory_size': 8, 'level_offsets': [8, 1051, 1334, 1433], 'selected_size': 283, 'level_origin': 1096, 'payload_origin': 1099, 'allocation_end': 1521})]}
for i, (p, expected) in enumerate(cases[N]):
    check("layout fixture " + str(i + 1), solve(p), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The returned physical layout descriptor disagrees with the declared buffer mapping at level_origin.

Store four mip levels consecutively. Each level uses ceil-halving, keeps dimensions at least one, has a two-byte row guard and a three-byte level header. A four-entry directory of two-byte offsets precedes all levels. Return the named intermediate layout descriptor and final address fields; all quantities are integer byte offsets unless explicitly stated.

split: open-access