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

N = 1
observations = []
def solve(x):
    classes, para, max_depth = x
    stack = [(para, None)]
    overflow = 0
    levels = []
    types = []
    for c in classes:
        if c in ('RLE', 'LRE', 'RLO', 'LRO'):
            cur = stack[-1][0]
            if c in ('RLE', 'RLO'):
                new = cur + 1 if cur % 2 == 0 else cur + 2
            else:
                new = cur + 2 if cur % 2 == 0 else cur + 1
            if new <= max_depth and overflow == 0:
                ovr = None if c in ('RLE', 'LRE') else ('R' if c == 'RLO' else 'L')
                stack.append((new, ovr))
            else:
                overflow += 1
            levels.append('x')
            types.append('BN')
        elif c == 'PDF':
            if len(stack) > 1:
                stack.pop()
            elif overflow > 0:
                overflow -= 1
            levels.append('x')
            types.append('BN')
        else:
            lv, ovr = stack[-1]
            levels.append(lv)
            types.append(ovr if ovr else c)
    return [levels, types]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: PDF overflow priority', [['RLO', 'EN', 'R', 'ON', 'EN', 'L', 'ON', 'R', 'RLO', 'RLE', 'LRE', 'PDF', 'EN', 'LRE'], 1, 3], [['x', 3, 3, 3, 3, 3, 3, 3, 'x', 'x', 'x', 'x', 3, 'x'], ['BN', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'BN', 'BN', 'BN', 'BN', 'R', 'BN']]), ('regression: PDF overflow priority', [['PDF', 'RLO', 'RLE', 'LRE', 'LRO', 'PDF', 'PDF', 'EN', 'PDF', 'R', 'L', 'EN', 'L'], 1, 5], [['x', 'x', 'x', 'x', 'x', 'x', 'x', 5, 'x', 3, 3, 3, 3], ['BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'EN', 'BN', 'R', 'R', 'R', 'R']]), ('regression: PDF overflow priority', [['LRE', 'R', 'R', 'LRE', 'LRE', 'LRE', 'EN', 'PDF', 'RLO', 'PDF', 'L'], 0, 3], [['x', 2, 2, 'x', 'x', 'x', 2, 'x', 'x', 'x', 2], ['BN', 'R', 'R', 'BN', 'BN', 'BN', 'EN', 'BN', 'BN', 'BN', 'L']]), ('regression: PDF overflow priority', [['LRE', 'R', 'RLO', 'L', 'R', 'PDF', 'WS', 'LRE', 'RLE', 'PDF', 'L'], 0, 4], [['x', 2, 'x', 3, 3, 'x', 2, 'x', 'x', 'x', 4], ['BN', 'R', 'BN', 'R', 'R', 'BN', 'WS', 'BN', 'BN', 'BN', 'L']]), ('RLE from odd level', [['RLE', 'RLE', 'L'], 0, 6], [['x', 'x', 3], ['BN', 'BN', 'L']]), ('depth limit exactly reached', [['RLE', 'LRE', 'L', 'PDF', 'L'], 0, 2], [['x', 'x', 2, 'x', 1], ['BN', 'BN', 'L', 'BN', 'L']]), ('control layout', [['RLE', 'PDF', 'L', 'L', 'R'], 1, 6], [['x', 'x', 1, 1, 1], ['BN', 'BN', 'L', 'L', 'R']]), ('control layout', [['ON', 'L', 'PDF', 'RLO', 'R'], 1, 4], [[1, 1, 'x', 'x', 3], ['ON', 'L', 'BN', 'BN', 'R']])], [('regression: PDF overflow priority', [['RLE', 'L', 'LRE', 'EN', 'RLE', 'PDF', 'L'], 0, 2], [['x', 1, 'x', 2, 'x', 'x', 2], ['BN', 'L', 'BN', 'EN', 'BN', 'BN', 'L']]), ('regression: PDF overflow priority', [['L', 'L', 'L', 'R', 'RLE', 'LRE', 'PDF', 'LRE', 'PDF', 'L', 'R', 'PDF', 'LRE', 'R'], 1, 3], [[1, 1, 1, 1, 'x', 'x', 'x', 'x', 'x', 3, 3, 'x', 'x', 2], ['L', 'L', 'L', 'R', 'BN', 'BN', 'BN', 'BN', 'BN', 'L', 'R', 'BN', 'BN', 'R']]), ('regression: PDF overflow priority', [['ON', 'ON', 'RLE', 'RLE', 'EN', 'L', 'LRO', 'RLE', 'EN', 'PDF', 'R'], 0, 4], [[0, 0, 'x', 'x', 3, 3, 'x', 'x', 4, 'x', 4], ['ON', 'ON', 'BN', 'BN', 'EN', 'L', 'BN', 'BN', 'L', 'BN', 'L']]), ('regression: PDF overflow priority', [['L', 'PDF', 'EN', 'LRE', 'R', 'LRE', 'RLE', 'PDF', 'WS', 'RLO', 'ON', 'L', 'R', 'R'], 1, 3], [[1, 'x', 1, 'x', 2, 'x', 'x', 'x', 2, 'x', 2, 2, 2, 2], ['L', 'BN', 'EN', 'BN', 'R', 'BN', 'BN', 'BN', 'WS', 'BN', 'ON', 'L', 'R', 'R']]), ('override on neutrals', [['RLO', 'ON', 'L', 'WS'], 0, 6], [['x', 1, 1, 1], ['BN', 'R', 'R', 'R']]), ('depth limit exactly reached', [['RLE', 'LRE', 'L', 'PDF', 'L'], 0, 2], [['x', 'x', 2, 'x', 1], ['BN', 'BN', 'L', 'BN', 'L']]), ('control layout', [['PDF', 'RLE', 'L', 'L', 'RLE', 'PDF', 'PDF', 'L', 'R', 'L', 'PDF', 'EN', 'WS'], 0, 4], [['x', 'x', 1, 1, 'x', 'x', 'x', 0, 0, 0, 'x', 0, 0], ['BN', 'BN', 'L', 'L', 'BN', 'BN', 'BN', 'L', 'R', 'L', 'BN', 'EN', 'WS']]), ('control layout', [['R', 'L', 'RLE', 'WS', 'R', 'LRE', 'ON', 'PDF', 'RLE'], 0, 4], [[0, 0, 'x', 1, 1, 'x', 2, 'x', 'x'], ['R', 'L', 'BN', 'WS', 'R', 'BN', 'ON', 'BN', 'BN']])], [('regression: PDF overflow priority', [['LRE', 'R', 'R', 'LRE', 'LRE', 'LRE', 'EN', 'PDF', 'RLO', 'PDF', 'L'], 0, 3], [['x', 2, 2, 'x', 'x', 'x', 2, 'x', 'x', 'x', 2], ['BN', 'R', 'R', 'BN', 'BN', 'BN', 'EN', 'BN', 'BN', 'BN', 'L']]), ('regression: PDF overflow priority', [['LRE', 'L', 'PDF', 'PDF', 'ON', 'RLE', 'LRE', 'EN', 'PDF', 'EN'], 1, 3], [['x', 2, 'x', 'x', 1, 'x', 'x', 3, 'x', 3], ['BN', 'L', 'BN', 'BN', 'ON', 'BN', 'BN', 'EN', 'BN', 'EN']]), ('regression: PDF overflow priority', [['R', 'LRO', 'R', 'RLO', 'PDF', 'R', 'EN', 'RLO', 'LRE', 'RLE', 'PDF', 'L'], 0, 2], [[0, 'x', 2, 'x', 'x', 2, 2, 'x', 'x', 'x', 'x', 2], ['R', 'BN', 'L', 'BN', 'BN', 'L', 'L', 'BN', 'BN', 'BN', 'BN', 'L']]), ('regression: PDF overflow priority', [['PDF', 'LRE', 'RLE', 'RLE', 'LRE', 'EN', 'LRE', 'PDF', 'EN', 'ON', 'EN', 'ON'], 0, 4], [['x', 'x', 'x', 'x', 'x', 3, 'x', 'x', 3, 3, 3, 3], ['BN', 'BN', 'BN', 'BN', 'BN', 'EN', 'BN', 'BN', 'EN', 'ON', 'EN', 'ON']]), ('RLE from odd level', [['RLE', 'RLE', 'L'], 0, 6], [['x', 'x', 3], ['BN', 'BN', 'L']]), ('depth limit exactly reached', [['RLE', 'LRE', 'L', 'PDF', 'L'], 0, 2], [['x', 'x', 2, 'x', 1], ['BN', 'BN', 'L', 'BN', 'L']]), ('control layout', [['RLE', 'PDF', 'RLE', 'LRE', 'ON', 'L', 'ON', 'PDF', 'LRE', 'PDF', 'ON'], 0, 3], [['x', 'x', 'x', 'x', 2, 2, 2, 'x', 'x', 'x', 1], ['BN', 'BN', 'BN', 'BN', 'ON', 'L', 'ON', 'BN', 'BN', 'BN', 'ON']]), ('control layout', [['R', 'EN', 'ON'], 1, 3], [[1, 1, 1], ['R', 'EN', 'ON']])], [('regression: PDF overflow priority', [['RLE', 'L', 'ON', 'RLE', 'L', 'EN', 'ON', 'PDF', 'L'], 1, 3], [['x', 3, 3, 'x', 3, 3, 3, 'x', 3], ['BN', 'L', 'ON', 'BN', 'L', 'EN', 'ON', 'BN', 'L']]), ('regression: PDF overflow priority', [['L', 'L', 'PDF', 'LRE', 'ON', 'ON', 'RLO', 'LRE', 'R', 'L', 'PDF', 'EN', 'RLO', 'L'], 0, 3], [[0, 0, 'x', 'x', 2, 2, 'x', 'x', 3, 3, 'x', 3, 'x', 3], ['L', 'L', 'BN', 'BN', 'ON', 'ON', 'BN', 'BN', 'R', 'R', 'BN', 'R', 'BN', 'R']]), ('regression: PDF overflow priority', [['R', 'WS', 'RLE', 'LRE', 'PDF', 'L', 'RLO', 'LRE', 'L', 'RLE', 'L', 'PDF', 'ON', 'PDF'], 1, 4], [[1, 1, 'x', 'x', 'x', 3, 'x', 'x', 3, 'x', 3, 'x', 3, 'x'], ['R', 'WS', 'BN', 'BN', 'BN', 'L', 'BN', 'BN', 'L', 'BN', 'L', 'BN', 'ON', 'BN']]), ('regression: PDF overflow priority', [['R', 'LRO', 'R', 'RLO', 'PDF', 'R', 'EN', 'RLO', 'LRE', 'RLE', 'PDF', 'L'], 0, 2], [[0, 'x', 2, 'x', 'x', 2, 2, 'x', 'x', 'x', 'x', 2], ['R', 'BN', 'L', 'BN', 'BN', 'L', 'L', 'BN', 'BN', 'BN', 'BN', 'L']]), ('depth limit exactly reached', [['RLE', 'LRE', 'L', 'PDF', 'L'], 0, 2], [['x', 'x', 2, 'x', 1], ['BN', 'BN', 'L', 'BN', 'L']]), ('RLE from odd level', [['RLE', 'RLE', 'L'], 0, 6], [['x', 'x', 3], ['BN', 'BN', 'L']]), ('control layout', [['R', 'EN', 'EN', 'PDF', 'LRO', 'PDF', 'RLE', 'RLO'], 0, 4], [[0, 0, 0, 'x', 'x', 'x', 'x', 'x'], ['R', 'EN', 'EN', 'BN', 'BN', 'BN', 'BN', 'BN']]), ('control layout', [['R', 'EN', 'L', 'R', 'RLE', 'RLE', 'LRE', 'R', 'EN', 'L', 'RLE', 'EN', 'R'], 0, 2], [[0, 0, 0, 0, 'x', 'x', 'x', 1, 1, 1, 'x', 1, 1], ['R', 'EN', 'L', 'R', 'BN', 'BN', 'BN', 'R', 'EN', 'L', 'BN', 'EN', 'R']])], [('regression: PDF overflow priority', [['RLE', 'L', 'LRE', 'EN', 'RLE', 'PDF', 'L'], 0, 2], [['x', 1, 'x', 2, 'x', 'x', 2], ['BN', 'L', 'BN', 'EN', 'BN', 'BN', 'L']]), ('regression: PDF overflow priority', [['L', 'L', 'L', 'R', 'RLE', 'LRE', 'PDF', 'LRE', 'PDF', 'L', 'R', 'PDF', 'LRE', 'R'], 1, 3], [[1, 1, 1, 1, 'x', 'x', 'x', 'x', 'x', 3, 3, 'x', 'x', 2], ['L', 'L', 'L', 'R', 'BN', 'BN', 'BN', 'BN', 'BN', 'L', 'R', 'BN', 'BN', 'R']]), ('regression: PDF overflow priority', [['RLO', 'EN', 'R', 'ON', 'EN', 'L', 'ON', 'R', 'RLO', 'RLE', 'LRE', 'PDF', 'EN', 'LRE'], 1, 3], [['x', 3, 3, 3, 3, 3, 3, 3, 'x', 'x', 'x', 'x', 3, 'x'], ['BN', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'BN', 'BN', 'BN', 'BN', 'R', 'BN']]), ('regression: PDF overflow priority', [['LRE', 'RLE', 'L', 'R', 'EN', 'PDF', 'RLE', 'L', 'L', 'L', 'ON', 'RLE'], 1, 2], [['x', 'x', 2, 2, 2, 'x', 'x', 2, 2, 2, 2, 'x'], ['BN', 'BN', 'L', 'R', 'EN', 'BN', 'BN', 'L', 'L', 'L', 'ON', 'BN']]), ('override on neutrals', [['RLO', 'ON', 'L', 'WS'], 0, 6], [['x', 1, 1, 1], ['BN', 'R', 'R', 'R']]), ('RLE from odd level', [['RLE', 'RLE', 'L'], 0, 6], [['x', 'x', 3], ['BN', 'BN', 'L']]), ('control layout', [['L', 'PDF', 'L', 'WS'], 1, 4], [[1, 'x', 1, 1], ['L', 'BN', 'L', 'WS']]), ('control layout', [['RLE', 'LRO', 'L', 'WS', 'R', 'EN', 'EN', 'R', 'L', 'PDF', 'ON', 'L', 'ON'], 0, 6], [['x', 'x', 2, 2, 2, 2, 2, 2, 2, 'x', 1, 1, 1], ['BN', 'BN', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'BN', 'ON', 'L', 'ON']])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    classes, para, max_depth = x
    stack = [(para, None)]
    overflow = 0
    levels = []
    types = []
    for c in classes:
        if c in ('RLE', 'LRE', 'RLO', 'LRO'):
            cur = stack[-1][0]
            if c in ('RLE', 'RLO'):
                new = cur + 1 if cur % 2 == 0 else cur + 2
            else:
                new = cur + 2 if cur % 2 == 0 else cur + 1
            if new <= max_depth and overflow == 0:
                ovr = None if c in ('RLE', 'LRE') else ('R' if c == 'RLO' else 'L')
                stack.append((new, ovr))
            else:
                overflow += 1
            levels.append('x')
            types.append('BN')
        elif c == 'PDF':
            if overflow > 0:
                overflow -= 1
            if len(stack) > 1:
                stack.pop()
            levels.append('x')
            types.append('BN')
        else:
            lv, ovr = stack[-1]
            levels.append(lv)
            types.append(ovr if ovr else c)
    return [levels, types]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: PDF overflow priority', [['RLO', 'EN', 'R', 'ON', 'EN', 'L', 'ON', 'R', 'RLO', 'RLE', 'LRE', 'PDF', 'EN', 'LRE'], 1, 3], [['x', 3, 3, 3, 3, 3, 3, 3, 'x', 'x', 'x', 'x', 3, 'x'], ['BN', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'BN', 'BN', 'BN', 'BN', 'R', 'BN']]), ('regression: PDF overflow priority', [['PDF', 'RLO', 'RLE', 'LRE', 'LRO', 'PDF', 'PDF', 'EN', 'PDF', 'R', 'L', 'EN', 'L'], 1, 5], [['x', 'x', 'x', 'x', 'x', 'x', 'x', 5, 'x', 3, 3, 3, 3], ['BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'EN', 'BN', 'R', 'R', 'R', 'R']]), ('regression: PDF overflow priority', [['LRE', 'R', 'R', 'LRE', 'LRE', 'LRE', 'EN', 'PDF', 'RLO', 'PDF', 'L'], 0, 3], [['x', 2, 2, 'x', 'x', 'x', 2, 'x', 'x', 'x', 2], ['BN', 'R', 'R', 'BN', 'BN', 'BN', 'EN', 'BN', 'BN', 'BN', 'L']]), ('regression: PDF overflow priority', [['LRE', 'R', 'RLO', 'L', 'R', 'PDF', 'WS', 'LRE', 'RLE', 'PDF', 'L'], 0, 4], [['x', 2, 'x', 3, 3, 'x', 2, 'x', 'x', 'x', 4], ['BN', 'R', 'BN', 'R', 'R', 'BN', 'WS', 'BN', 'BN', 'BN', 'L']]), ('RLE from odd level', [['RLE', 'RLE', 'L'], 0, 6], [['x', 'x', 3], ['BN', 'BN', 'L']]), ('depth limit exactly reached', [['RLE', 'LRE', 'L', 'PDF', 'L'], 0, 2], [['x', 'x', 2, 'x', 1], ['BN', 'BN', 'L', 'BN', 'L']]), ('control layout', [['RLE', 'PDF', 'L', 'L', 'R'], 1, 6], [['x', 'x', 1, 1, 1], ['BN', 'BN', 'L', 'L', 'R']]), ('control layout', [['ON', 'L', 'PDF', 'RLO', 'R'], 1, 4], [[1, 1, 'x', 'x', 3], ['ON', 'L', 'BN', 'BN', 'R']])], [('regression: PDF overflow priority', [['RLE', 'L', 'LRE', 'EN', 'RLE', 'PDF', 'L'], 0, 2], [['x', 1, 'x', 2, 'x', 'x', 2], ['BN', 'L', 'BN', 'EN', 'BN', 'BN', 'L']]), ('regression: PDF overflow priority', [['L', 'L', 'L', 'R', 'RLE', 'LRE', 'PDF', 'LRE', 'PDF', 'L', 'R', 'PDF', 'LRE', 'R'], 1, 3], [[1, 1, 1, 1, 'x', 'x', 'x', 'x', 'x', 3, 3, 'x', 'x', 2], ['L', 'L', 'L', 'R', 'BN', 'BN', 'BN', 'BN', 'BN', 'L', 'R', 'BN', 'BN', 'R']]), ('regression: PDF overflow priority', [['ON', 'ON', 'RLE', 'RLE', 'EN', 'L', 'LRO', 'RLE', 'EN', 'PDF', 'R'], 0, 4], [[0, 0, 'x', 'x', 3, 3, 'x', 'x', 4, 'x', 4], ['ON', 'ON', 'BN', 'BN', 'EN', 'L', 'BN', 'BN', 'L', 'BN', 'L']]), ('regression: PDF overflow priority', [['L', 'PDF', 'EN', 'LRE', 'R', 'LRE', 'RLE', 'PDF', 'WS', 'RLO', 'ON', 'L', 'R', 'R'], 1, 3], [[1, 'x', 1, 'x', 2, 'x', 'x', 'x', 2, 'x', 2, 2, 2, 2], ['L', 'BN', 'EN', 'BN', 'R', 'BN', 'BN', 'BN', 'WS', 'BN', 'ON', 'L', 'R', 'R']]), ('override on neutrals', [['RLO', 'ON', 'L', 'WS'], 0, 6], [['x', 1, 1, 1], ['BN', 'R', 'R', 'R']]), ('depth limit exactly reached', [['RLE', 'LRE', 'L', 'PDF', 'L'], 0, 2], [['x', 'x', 2, 'x', 1], ['BN', 'BN', 'L', 'BN', 'L']]), ('control layout', [['PDF', 'RLE', 'L', 'L', 'RLE', 'PDF', 'PDF', 'L', 'R', 'L', 'PDF', 'EN', 'WS'], 0, 4], [['x', 'x', 1, 1, 'x', 'x', 'x', 0, 0, 0, 'x', 0, 0], ['BN', 'BN', 'L', 'L', 'BN', 'BN', 'BN', 'L', 'R', 'L', 'BN', 'EN', 'WS']]), ('control layout', [['R', 'L', 'RLE', 'WS', 'R', 'LRE', 'ON', 'PDF', 'RLE'], 0, 4], [[0, 0, 'x', 1, 1, 'x', 2, 'x', 'x'], ['R', 'L', 'BN', 'WS', 'R', 'BN', 'ON', 'BN', 'BN']])], [('regression: PDF overflow priority', [['LRE', 'R', 'R', 'LRE', 'LRE', 'LRE', 'EN', 'PDF', 'RLO', 'PDF', 'L'], 0, 3], [['x', 2, 2, 'x', 'x', 'x', 2, 'x', 'x', 'x', 2], ['BN', 'R', 'R', 'BN', 'BN', 'BN', 'EN', 'BN', 'BN', 'BN', 'L']]), ('regression: PDF overflow priority', [['LRE', 'L', 'PDF', 'PDF', 'ON', 'RLE', 'LRE', 'EN', 'PDF', 'EN'], 1, 3], [['x', 2, 'x', 'x', 1, 'x', 'x', 3, 'x', 3], ['BN', 'L', 'BN', 'BN', 'ON', 'BN', 'BN', 'EN', 'BN', 'EN']]), ('regression: PDF overflow priority', [['R', 'LRO', 'R', 'RLO', 'PDF', 'R', 'EN', 'RLO', 'LRE', 'RLE', 'PDF', 'L'], 0, 2], [[0, 'x', 2, 'x', 'x', 2, 2, 'x', 'x', 'x', 'x', 2], ['R', 'BN', 'L', 'BN', 'BN', 'L', 'L', 'BN', 'BN', 'BN', 'BN', 'L']]), ('regression: PDF overflow priority', [['PDF', 'LRE', 'RLE', 'RLE', 'LRE', 'EN', 'LRE', 'PDF', 'EN', 'ON', 'EN', 'ON'], 0, 4], [['x', 'x', 'x', 'x', 'x', 3, 'x', 'x', 3, 3, 3, 3], ['BN', 'BN', 'BN', 'BN', 'BN', 'EN', 'BN', 'BN', 'EN', 'ON', 'EN', 'ON']]), ('RLE from odd level', [['RLE', 'RLE', 'L'], 0, 6], [['x', 'x', 3], ['BN', 'BN', 'L']]), ('depth limit exactly reached', [['RLE', 'LRE', 'L', 'PDF', 'L'], 0, 2], [['x', 'x', 2, 'x', 1], ['BN', 'BN', 'L', 'BN', 'L']]), ('control layout', [['RLE', 'PDF', 'RLE', 'LRE', 'ON', 'L', 'ON', 'PDF', 'LRE', 'PDF', 'ON'], 0, 3], [['x', 'x', 'x', 'x', 2, 2, 2, 'x', 'x', 'x', 1], ['BN', 'BN', 'BN', 'BN', 'ON', 'L', 'ON', 'BN', 'BN', 'BN', 'ON']]), ('control layout', [['R', 'EN', 'ON'], 1, 3], [[1, 1, 1], ['R', 'EN', 'ON']])], [('regression: PDF overflow priority', [['RLE', 'L', 'ON', 'RLE', 'L', 'EN', 'ON', 'PDF', 'L'], 1, 3], [['x', 3, 3, 'x', 3, 3, 3, 'x', 3], ['BN', 'L', 'ON', 'BN', 'L', 'EN', 'ON', 'BN', 'L']]), ('regression: PDF overflow priority', [['L', 'L', 'PDF', 'LRE', 'ON', 'ON', 'RLO', 'LRE', 'R', 'L', 'PDF', 'EN', 'RLO', 'L'], 0, 3], [[0, 0, 'x', 'x', 2, 2, 'x', 'x', 3, 3, 'x', 3, 'x', 3], ['L', 'L', 'BN', 'BN', 'ON', 'ON', 'BN', 'BN', 'R', 'R', 'BN', 'R', 'BN', 'R']]), ('regression: PDF overflow priority', [['R', 'WS', 'RLE', 'LRE', 'PDF', 'L', 'RLO', 'LRE', 'L', 'RLE', 'L', 'PDF', 'ON', 'PDF'], 1, 4], [[1, 1, 'x', 'x', 'x', 3, 'x', 'x', 3, 'x', 3, 'x', 3, 'x'], ['R', 'WS', 'BN', 'BN', 'BN', 'L', 'BN', 'BN', 'L', 'BN', 'L', 'BN', 'ON', 'BN']]), ('regression: PDF overflow priority', [['R', 'LRO', 'R', 'RLO', 'PDF', 'R', 'EN', 'RLO', 'LRE', 'RLE', 'PDF', 'L'], 0, 2], [[0, 'x', 2, 'x', 'x', 2, 2, 'x', 'x', 'x', 'x', 2], ['R', 'BN', 'L', 'BN', 'BN', 'L', 'L', 'BN', 'BN', 'BN', 'BN', 'L']]), ('depth limit exactly reached', [['RLE', 'LRE', 'L', 'PDF', 'L'], 0, 2], [['x', 'x', 2, 'x', 1], ['BN', 'BN', 'L', 'BN', 'L']]), ('RLE from odd level', [['RLE', 'RLE', 'L'], 0, 6], [['x', 'x', 3], ['BN', 'BN', 'L']]), ('control layout', [['R', 'EN', 'EN', 'PDF', 'LRO', 'PDF', 'RLE', 'RLO'], 0, 4], [[0, 0, 0, 'x', 'x', 'x', 'x', 'x'], ['R', 'EN', 'EN', 'BN', 'BN', 'BN', 'BN', 'BN']]), ('control layout', [['R', 'EN', 'L', 'R', 'RLE', 'RLE', 'LRE', 'R', 'EN', 'L', 'RLE', 'EN', 'R'], 0, 2], [[0, 0, 0, 0, 'x', 'x', 'x', 1, 1, 1, 'x', 1, 1], ['R', 'EN', 'L', 'R', 'BN', 'BN', 'BN', 'R', 'EN', 'L', 'BN', 'EN', 'R']])], [('regression: PDF overflow priority', [['RLE', 'L', 'LRE', 'EN', 'RLE', 'PDF', 'L'], 0, 2], [['x', 1, 'x', 2, 'x', 'x', 2], ['BN', 'L', 'BN', 'EN', 'BN', 'BN', 'L']]), ('regression: PDF overflow priority', [['L', 'L', 'L', 'R', 'RLE', 'LRE', 'PDF', 'LRE', 'PDF', 'L', 'R', 'PDF', 'LRE', 'R'], 1, 3], [[1, 1, 1, 1, 'x', 'x', 'x', 'x', 'x', 3, 3, 'x', 'x', 2], ['L', 'L', 'L', 'R', 'BN', 'BN', 'BN', 'BN', 'BN', 'L', 'R', 'BN', 'BN', 'R']]), ('regression: PDF overflow priority', [['RLO', 'EN', 'R', 'ON', 'EN', 'L', 'ON', 'R', 'RLO', 'RLE', 'LRE', 'PDF', 'EN', 'LRE'], 1, 3], [['x', 3, 3, 3, 3, 3, 3, 3, 'x', 'x', 'x', 'x', 3, 'x'], ['BN', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'BN', 'BN', 'BN', 'BN', 'R', 'BN']]), ('regression: PDF overflow priority', [['LRE', 'RLE', 'L', 'R', 'EN', 'PDF', 'RLE', 'L', 'L', 'L', 'ON', 'RLE'], 1, 2], [['x', 'x', 2, 2, 2, 'x', 'x', 2, 2, 2, 2, 'x'], ['BN', 'BN', 'L', 'R', 'EN', 'BN', 'BN', 'L', 'L', 'L', 'ON', 'BN']]), ('override on neutrals', [['RLO', 'ON', 'L', 'WS'], 0, 6], [['x', 1, 1, 1], ['BN', 'R', 'R', 'R']]), ('RLE from odd level', [['RLE', 'RLE', 'L'], 0, 6], [['x', 'x', 3], ['BN', 'BN', 'L']]), ('control layout', [['L', 'PDF', 'L', 'WS'], 1, 4], [[1, 'x', 1, 1], ['L', 'BN', 'L', 'WS']]), ('control layout', [['RLE', 'LRO', 'L', 'WS', 'R', 'EN', 'EN', 'R', 'L', 'PDF', 'ON', 'L', 'ON'], 0, 6], [['x', 'x', 2, 2, 2, 2, 2, 2, 2, 'x', 1, 1, 1], ['BN', 'BN', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'BN', 'ON', 'L', 'ON']])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A PDF closes a real embedding while an overflowed one is still open.

Input [classes, paragraph level, max depth]. RLE/RLO push the next odd level, LRE/LRO the next even level (RLO/LRO set an R/L override, RLE/LRE clear it) if the level <= max depth and no overflow is pending, else count an overflow. PDF first cancels an overflow, else pops if above the base. Codes get level "x" and class BN; other characters take the top level and the override class if any. Return [levels, classes].

split: open-access


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

N = 1
observations = []
def solve(x):
    classes, para, max_depth = x
    stack = [(para, None)]
    overflow = 0
    levels = []
    types = []
    for c in classes:
        if c in ('RLE', 'LRE', 'RLO', 'LRO'):
            cur = stack[-1][0]
            if c in ('RLE', 'RLO'):
                new = cur + 1 if cur % 2 == 0 else cur + 2
            else:
                new = cur + 2 if cur % 2 == 0 else cur + 1
            if new <= max_depth and overflow == 0:
                ovr = None if c in ('RLE', 'LRE') else ('R' if c == 'RLO' else 'L')
                stack.append((new, ovr))
            else:
                overflow += 1
            levels.append('x')
            types.append('BN')
        elif c == 'PDF':
            if overflow > 0:
                overflow -= 1
            elif len(stack) > 1:
                stack.pop()
            levels.append('x')
            types.append('BN')
        else:
            lv, ovr = stack[-1]
            levels.append(lv)
            types.append(ovr if ovr and c not in ('ON', 'WS') else c)
    return [levels, types]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('override on neutrals', [['RLO', 'ON', 'L', 'WS'], 0, 6], [['x', 1, 1, 1], ['BN', 'R', 'R', 'R']]), ('regression: override scope', [['L', 'L', 'EN', 'EN', 'LRO', 'R', 'R', 'EN', 'EN', 'EN', 'WS', 'R'], 1, 2], [[1, 1, 1, 1, 'x', 2, 2, 2, 2, 2, 2, 2], ['L', 'L', 'EN', 'EN', 'BN', 'L', 'L', 'L', 'L', 'L', 'L', 'L']]), ('regression: override scope', [['RLO', 'PDF', 'RLO', 'L', 'L', 'WS', 'EN', 'PDF'], 0, 6], [['x', 'x', 'x', 1, 1, 1, 1, 'x'], ['BN', 'BN', 'BN', 'R', 'R', 'R', 'R', 'BN']]), ('regression: override scope', [['EN', 'PDF', 'RLE', 'RLO', 'WS', 'L', 'RLE', 'PDF'], 0, 5], [[0, 'x', 'x', 'x', 3, 3, 'x', 'x'], ['EN', 'BN', 'BN', 'BN', 'R', 'R', 'BN', 'BN']]), ('depth limit exactly reached', [['RLE', 'LRE', 'L', 'PDF', 'L'], 0, 2], [['x', 'x', 2, 'x', 1], ['BN', 'BN', 'L', 'BN', 'L']]), ('RLE from odd level', [['RLE', 'RLE', 'L'], 0, 6], [['x', 'x', 3], ['BN', 'BN', 'L']]), ('control layout', [['EN', 'R', 'L', 'R', 'PDF', 'L', 'R', 'RLE', 'RLE', 'RLE', 'LRO'], 0, 5], [[0, 0, 0, 0, 'x', 0, 0, 'x', 'x', 'x', 'x'], ['EN', 'R', 'L', 'R', 'BN', 'L', 'R', 'BN', 'BN', 'BN', 'BN']]), ('control layout', [['PDF', 'R', 'L', 'RLE', 'ON', 'PDF', 'ON', 'R', 'LRE', 'PDF', 'R'], 0, 5], [['x', 0, 0, 'x', 1, 'x', 0, 0, 'x', 'x', 0], ['BN', 'R', 'L', 'BN', 'ON', 'BN', 'ON', 'R', 'BN', 'BN', 'R']])], [('regression: override scope', [['RLO', 'ON', 'RLE', 'RLE', 'L', 'R'], 0, 4], [['x', 1, 'x', 'x', 3, 3], ['BN', 'R', 'BN', 'BN', 'L', 'R']]), ('regression: override scope', [['PDF', 'LRO', 'EN', 'WS', 'LRO', 'RLE'], 1, 6], [['x', 'x', 2, 2, 'x', 'x'], ['BN', 'BN', 'L', 'L', 'BN', 'BN']]), ('regression: override scope', [['RLE', 'LRO', 'L', 'WS', 'R', 'EN', 'EN', 'R', 'L', 'PDF', 'ON', 'L', 'ON'], 0, 6], [['x', 'x', 2, 2, 2, 2, 2, 2, 2, 'x', 1, 1, 1], ['BN', 'BN', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'BN', 'ON', 'L', 'ON']]), ('regression: override scope', [['RLO', 'WS', 'ON', 'R', 'RLE', 'ON', 'RLE', 'PDF', 'RLE', 'R', 'ON'], 0, 5], [['x', 1, 1, 1, 'x', 3, 'x', 'x', 'x', 5, 5], ['BN', 'R', 'R', 'R', 'BN', 'ON', 'BN', 'BN', 'BN', 'R', 'ON']]), ('override on neutrals', [['RLO', 'ON', 'L', 'WS'], 0, 6], [['x', 1, 1, 1], ['BN', 'R', 'R', 'R']]), ('RLE from odd level', [['RLE', 'RLE', 'L'], 0, 6], [['x', 'x', 3], ['BN', 'BN', 'L']]), ('control layout', [['R', 'LRE', 'R', 'R', 'ON', 'EN', 'RLE', 'ON'], 1, 3], [[1, 'x', 2, 2, 2, 2, 'x', 3], ['R', 'BN', 'R', 'R', 'ON', 'EN', 'BN', 'ON']]), ('control layout', [['RLE', 'R'], 1, 5], [['x', 3], ['BN', 'R']])], [('regression: override scope', [['RLE', 'LRO', 'LRE', 'LRE', 'WS', 'LRE', 'L', 'RLE', 'PDF', 'ON', 'L', 'PDF', 'L'], 0, 3], [['x', 'x', 'x', 'x', 2, 'x', 2, 'x', 'x', 2, 2, 'x', 2], ['BN', 'BN', 'BN', 'BN', 'L', 'BN', 'L', 'BN', 'BN', 'L', 'L', 'BN', 'L']]), ('regression: override scope', [['RLO', 'ON', 'RLE', 'RLE', 'L', 'R'], 0, 4], [['x', 1, 'x', 'x', 3, 3], ['BN', 'R', 'BN', 'BN', 'L', 'R']]), ('regression: override scope', [['EN', 'PDF', 'RLE', 'RLO', 'WS', 'L', 'RLE', 'PDF'], 0, 5], [[0, 'x', 'x', 'x', 3, 3, 'x', 'x'], ['EN', 'BN', 'BN', 'BN', 'R', 'R', 'BN', 'BN']]), ('regression: override scope', [['PDF', 'LRO', 'EN', 'WS', 'LRO', 'RLE'], 1, 6], [['x', 'x', 2, 2, 'x', 'x'], ['BN', 'BN', 'L', 'L', 'BN', 'BN']]), ('RLE from odd level', [['RLE', 'RLE', 'L'], 0, 6], [['x', 'x', 3], ['BN', 'BN', 'L']]), ('LRE from odd level', [['LRE', 'R'], 1, 6], [['x', 2], ['BN', 'R']]), ('control layout', [['LRE', 'PDF'], 0, 2], [['x', 'x'], ['BN', 'BN']]), ('control layout', [['R', 'L', 'ON', 'PDF', 'R', 'L', 'ON', 'LRE', 'RLE'], 0, 4], [[0, 0, 0, 'x', 0, 0, 0, 'x', 'x'], ['R', 'L', 'ON', 'BN', 'R', 'L', 'ON', 'BN', 'BN']])], [('regression: override scope', [['RLO', 'LRO', 'EN', 'LRE', 'LRE', 'L', 'L', 'RLE', 'ON', 'EN', 'L', 'ON'], 1, 5], [['x', 'x', 4, 'x', 'x', 4, 4, 'x', 4, 4, 4, 4], ['BN', 'BN', 'L', 'BN', 'BN', 'L', 'L', 'BN', 'L', 'L', 'L', 'L']]), ('regression: override scope', [['LRO', 'ON', 'RLE', 'L', 'ON', 'ON', 'PDF'], 1, 6], [['x', 2, 'x', 3, 3, 3, 'x'], ['BN', 'L', 'BN', 'L', 'ON', 'ON', 'BN']]), ('regression: override scope', [['PDF', 'EN', 'EN', 'R', 'L', 'R', 'L', 'RLO', 'EN', 'WS', 'PDF', 'PDF', 'ON'], 1, 5], [['x', 1, 1, 1, 1, 1, 1, 'x', 3, 3, 'x', 'x', 1], ['BN', 'EN', 'EN', 'R', 'L', 'R', 'L', 'BN', 'R', 'R', 'BN', 'BN', 'ON']]), ('regression: override scope', [['LRO', 'R', 'PDF', 'RLE', 'PDF', 'R', 'L', 'PDF', 'EN', 'ON', 'WS', 'LRO', 'WS', 'LRE'], 0, 5], [['x', 2, 'x', 'x', 'x', 0, 0, 'x', 0, 0, 0, 'x', 2, 'x'], ['BN', 'L', 'BN', 'BN', 'BN', 'R', 'L', 'BN', 'EN', 'ON', 'WS', 'BN', 'L', 'BN']]), ('depth limit exactly reached', [['RLE', 'LRE', 'L', 'PDF', 'L'], 0, 2], [['x', 'x', 2, 'x', 1], ['BN', 'BN', 'L', 'BN', 'L']]), ('override on neutrals', [['RLO', 'ON', 'L', 'WS'], 0, 6], [['x', 1, 1, 1], ['BN', 'R', 'R', 'R']]), ('control layout', [['EN', 'PDF', 'L', 'LRE', 'R', 'L', 'ON'], 0, 5], [[0, 'x', 0, 'x', 2, 2, 2], ['EN', 'BN', 'L', 'BN', 'R', 'L', 'ON']]), ('control layout', [['ON', 'LRO', 'EN'], 1, 2], [[1, 'x', 2], ['ON', 'BN', 'L']])], [('regression: override scope', [['R', 'RLO', 'ON', 'L', 'RLE', 'RLE'], 0, 3], [[0, 'x', 1, 1, 'x', 'x'], ['R', 'BN', 'R', 'R', 'BN', 'BN']]), ('regression: override scope', [['EN', 'L', 'ON', 'R', 'LRO', 'L', 'ON', 'WS', 'ON'], 1, 6], [[1, 1, 1, 1, 'x', 2, 2, 2, 2], ['EN', 'L', 'ON', 'R', 'BN', 'L', 'L', 'L', 'L']]), ('regression: override scope', [['PDF', 'LRO', 'EN', 'WS', 'LRO', 'RLE'], 1, 6], [['x', 'x', 2, 2, 'x', 'x'], ['BN', 'BN', 'L', 'L', 'BN', 'BN']]), ('override on neutrals', [['RLO', 'ON', 'L', 'WS'], 0, 6], [['x', 1, 1, 1], ['BN', 'R', 'R', 'R']]), ('LRE from odd level', [['LRE', 'R'], 1, 6], [['x', 2], ['BN', 'R']]), ('RLE from odd level', [['RLE', 'RLE', 'L'], 0, 6], [['x', 'x', 3], ['BN', 'BN', 'L']]), ('control layout', [['L', 'R', 'EN', 'LRO', 'L', 'LRE', 'L', 'L', 'L', 'L'], 0, 5], [[0, 0, 0, 'x', 2, 'x', 4, 4, 4, 4], ['L', 'R', 'EN', 'BN', 'L', 'BN', 'L', 'L', 'L', 'L']]), ('control layout', [['PDF', 'EN', 'ON', 'RLE', 'ON', 'PDF', 'WS', 'L', 'ON', 'EN', 'ON'], 0, 2], [['x', 0, 0, 'x', 1, 'x', 0, 0, 0, 0, 0], ['BN', 'EN', 'ON', 'BN', 'ON', 'BN', 'WS', 'L', 'ON', 'EN', 'ON']])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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(x):
    classes, para, max_depth = x
    stack = [(para, None)]
    overflow = 0
    levels = []
    types = []
    for c in classes:
        if c in ('RLE', 'LRE', 'RLO', 'LRO'):
            cur = stack[-1][0]
            if c in ('RLE', 'RLO'):
                new = cur + 1 if cur % 2 == 0 else cur + 2
            else:
                new = cur + 2 if cur % 2 == 0 else cur + 1
            if new <= max_depth and overflow == 0:
                ovr = None if c in ('RLE', 'LRE') else ('R' if c == 'RLO' else 'L')
                stack.append((new, ovr))
            else:
                overflow += 1
            levels.append('x')
            types.append('BN')
        elif c == 'PDF':
            if overflow > 0:
                overflow -= 1
            elif len(stack) > 1:
                stack.pop()
            levels.append('x')
            types.append('BN')
        else:
            lv, ovr = stack[-1]
            levels.append(lv)
            types.append(ovr if ovr and c != 'WS' else c)
    return [levels, types]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('override on neutrals', [['RLO', 'ON', 'L', 'WS'], 0, 6], [['x', 1, 1, 1], ['BN', 'R', 'R', 'R']]), ('regression: override scope', [['L', 'L', 'EN', 'EN', 'LRO', 'R', 'R', 'EN', 'EN', 'EN', 'WS', 'R'], 1, 2], [[1, 1, 1, 1, 'x', 2, 2, 2, 2, 2, 2, 2], ['L', 'L', 'EN', 'EN', 'BN', 'L', 'L', 'L', 'L', 'L', 'L', 'L']]), ('regression: override scope', [['RLO', 'PDF', 'RLO', 'L', 'L', 'WS', 'EN', 'PDF'], 0, 6], [['x', 'x', 'x', 1, 1, 1, 1, 'x'], ['BN', 'BN', 'BN', 'R', 'R', 'R', 'R', 'BN']]), ('regression: override scope', [['EN', 'PDF', 'RLE', 'RLO', 'WS', 'L', 'RLE', 'PDF'], 0, 5], [[0, 'x', 'x', 'x', 3, 3, 'x', 'x'], ['EN', 'BN', 'BN', 'BN', 'R', 'R', 'BN', 'BN']]), ('depth limit exactly reached', [['RLE', 'LRE', 'L', 'PDF', 'L'], 0, 2], [['x', 'x', 2, 'x', 1], ['BN', 'BN', 'L', 'BN', 'L']]), ('RLE from odd level', [['RLE', 'RLE', 'L'], 0, 6], [['x', 'x', 3], ['BN', 'BN', 'L']]), ('control layout', [['EN', 'R', 'L', 'R', 'PDF', 'L', 'R', 'RLE', 'RLE', 'RLE', 'LRO'], 0, 5], [[0, 0, 0, 0, 'x', 0, 0, 'x', 'x', 'x', 'x'], ['EN', 'R', 'L', 'R', 'BN', 'L', 'R', 'BN', 'BN', 'BN', 'BN']]), ('control layout', [['PDF', 'R', 'L', 'RLE', 'ON', 'PDF', 'ON', 'R', 'LRE', 'PDF', 'R'], 0, 5], [['x', 0, 0, 'x', 1, 'x', 0, 0, 'x', 'x', 0], ['BN', 'R', 'L', 'BN', 'ON', 'BN', 'ON', 'R', 'BN', 'BN', 'R']])], [('regression: override scope', [['RLO', 'ON', 'RLE', 'RLE', 'L', 'R'], 0, 4], [['x', 1, 'x', 'x', 3, 3], ['BN', 'R', 'BN', 'BN', 'L', 'R']]), ('regression: override scope', [['PDF', 'LRO', 'EN', 'WS', 'LRO', 'RLE'], 1, 6], [['x', 'x', 2, 2, 'x', 'x'], ['BN', 'BN', 'L', 'L', 'BN', 'BN']]), ('regression: override scope', [['RLE', 'LRO', 'L', 'WS', 'R', 'EN', 'EN', 'R', 'L', 'PDF', 'ON', 'L', 'ON'], 0, 6], [['x', 'x', 2, 2, 2, 2, 2, 2, 2, 'x', 1, 1, 1], ['BN', 'BN', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'BN', 'ON', 'L', 'ON']]), ('regression: override scope', [['RLO', 'WS', 'ON', 'R', 'RLE', 'ON', 'RLE', 'PDF', 'RLE', 'R', 'ON'], 0, 5], [['x', 1, 1, 1, 'x', 3, 'x', 'x', 'x', 5, 5], ['BN', 'R', 'R', 'R', 'BN', 'ON', 'BN', 'BN', 'BN', 'R', 'ON']]), ('override on neutrals', [['RLO', 'ON', 'L', 'WS'], 0, 6], [['x', 1, 1, 1], ['BN', 'R', 'R', 'R']]), ('RLE from odd level', [['RLE', 'RLE', 'L'], 0, 6], [['x', 'x', 3], ['BN', 'BN', 'L']]), ('control layout', [['R', 'LRE', 'R', 'R', 'ON', 'EN', 'RLE', 'ON'], 1, 3], [[1, 'x', 2, 2, 2, 2, 'x', 3], ['R', 'BN', 'R', 'R', 'ON', 'EN', 'BN', 'ON']]), ('control layout', [['RLE', 'R'], 1, 5], [['x', 3], ['BN', 'R']])], [('regression: override scope', [['RLE', 'LRO', 'LRE', 'LRE', 'WS', 'LRE', 'L', 'RLE', 'PDF', 'ON', 'L', 'PDF', 'L'], 0, 3], [['x', 'x', 'x', 'x', 2, 'x', 2, 'x', 'x', 2, 2, 'x', 2], ['BN', 'BN', 'BN', 'BN', 'L', 'BN', 'L', 'BN', 'BN', 'L', 'L', 'BN', 'L']]), ('regression: override scope', [['RLO', 'ON', 'RLE', 'RLE', 'L', 'R'], 0, 4], [['x', 1, 'x', 'x', 3, 3], ['BN', 'R', 'BN', 'BN', 'L', 'R']]), ('regression: override scope', [['EN', 'PDF', 'RLE', 'RLO', 'WS', 'L', 'RLE', 'PDF'], 0, 5], [[0, 'x', 'x', 'x', 3, 3, 'x', 'x'], ['EN', 'BN', 'BN', 'BN', 'R', 'R', 'BN', 'BN']]), ('regression: override scope', [['PDF', 'LRO', 'EN', 'WS', 'LRO', 'RLE'], 1, 6], [['x', 'x', 2, 2, 'x', 'x'], ['BN', 'BN', 'L', 'L', 'BN', 'BN']]), ('RLE from odd level', [['RLE', 'RLE', 'L'], 0, 6], [['x', 'x', 3], ['BN', 'BN', 'L']]), ('LRE from odd level', [['LRE', 'R'], 1, 6], [['x', 2], ['BN', 'R']]), ('control layout', [['LRE', 'PDF'], 0, 2], [['x', 'x'], ['BN', 'BN']]), ('control layout', [['R', 'L', 'ON', 'PDF', 'R', 'L', 'ON', 'LRE', 'RLE'], 0, 4], [[0, 0, 0, 'x', 0, 0, 0, 'x', 'x'], ['R', 'L', 'ON', 'BN', 'R', 'L', 'ON', 'BN', 'BN']])], [('regression: override scope', [['RLO', 'LRO', 'EN', 'LRE', 'LRE', 'L', 'L', 'RLE', 'ON', 'EN', 'L', 'ON'], 1, 5], [['x', 'x', 4, 'x', 'x', 4, 4, 'x', 4, 4, 4, 4], ['BN', 'BN', 'L', 'BN', 'BN', 'L', 'L', 'BN', 'L', 'L', 'L', 'L']]), ('regression: override scope', [['LRO', 'ON', 'RLE', 'L', 'ON', 'ON', 'PDF'], 1, 6], [['x', 2, 'x', 3, 3, 3, 'x'], ['BN', 'L', 'BN', 'L', 'ON', 'ON', 'BN']]), ('regression: override scope', [['PDF', 'EN', 'EN', 'R', 'L', 'R', 'L', 'RLO', 'EN', 'WS', 'PDF', 'PDF', 'ON'], 1, 5], [['x', 1, 1, 1, 1, 1, 1, 'x', 3, 3, 'x', 'x', 1], ['BN', 'EN', 'EN', 'R', 'L', 'R', 'L', 'BN', 'R', 'R', 'BN', 'BN', 'ON']]), ('regression: override scope', [['LRO', 'R', 'PDF', 'RLE', 'PDF', 'R', 'L', 'PDF', 'EN', 'ON', 'WS', 'LRO', 'WS', 'LRE'], 0, 5], [['x', 2, 'x', 'x', 'x', 0, 0, 'x', 0, 0, 0, 'x', 2, 'x'], ['BN', 'L', 'BN', 'BN', 'BN', 'R', 'L', 'BN', 'EN', 'ON', 'WS', 'BN', 'L', 'BN']]), ('depth limit exactly reached', [['RLE', 'LRE', 'L', 'PDF', 'L'], 0, 2], [['x', 'x', 2, 'x', 1], ['BN', 'BN', 'L', 'BN', 'L']]), ('override on neutrals', [['RLO', 'ON', 'L', 'WS'], 0, 6], [['x', 1, 1, 1], ['BN', 'R', 'R', 'R']]), ('control layout', [['EN', 'PDF', 'L', 'LRE', 'R', 'L', 'ON'], 0, 5], [[0, 'x', 0, 'x', 2, 2, 2], ['EN', 'BN', 'L', 'BN', 'R', 'L', 'ON']]), ('control layout', [['ON', 'LRO', 'EN'], 1, 2], [[1, 'x', 2], ['ON', 'BN', 'L']])], [('regression: override scope', [['R', 'RLO', 'ON', 'L', 'RLE', 'RLE'], 0, 3], [[0, 'x', 1, 1, 'x', 'x'], ['R', 'BN', 'R', 'R', 'BN', 'BN']]), ('regression: override scope', [['EN', 'L', 'ON', 'R', 'LRO', 'L', 'ON', 'WS', 'ON'], 1, 6], [[1, 1, 1, 1, 'x', 2, 2, 2, 2], ['EN', 'L', 'ON', 'R', 'BN', 'L', 'L', 'L', 'L']]), ('regression: override scope', [['PDF', 'LRO', 'EN', 'WS', 'LRO', 'RLE'], 1, 6], [['x', 'x', 2, 2, 'x', 'x'], ['BN', 'BN', 'L', 'L', 'BN', 'BN']]), ('override on neutrals', [['RLO', 'ON', 'L', 'WS'], 0, 6], [['x', 1, 1, 1], ['BN', 'R', 'R', 'R']]), ('LRE from odd level', [['LRE', 'R'], 1, 6], [['x', 2], ['BN', 'R']]), ('RLE from odd level', [['RLE', 'RLE', 'L'], 0, 6], [['x', 'x', 3], ['BN', 'BN', 'L']]), ('control layout', [['L', 'R', 'EN', 'LRO', 'L', 'LRE', 'L', 'L', 'L', 'L'], 0, 5], [[0, 0, 0, 'x', 2, 'x', 4, 4, 4, 4], ['L', 'R', 'EN', 'BN', 'L', 'BN', 'L', 'L', 'L', 'L']]), ('control layout', [['PDF', 'EN', 'ON', 'RLE', 'ON', 'PDF', 'WS', 'L', 'ON', 'EN', 'ON'], 0, 2], [['x', 0, 0, 'x', 1, 'x', 0, 0, 0, 0, 0], ['BN', 'EN', 'ON', 'BN', 'ON', 'BN', 'WS', 'L', 'ON', 'EN', 'ON']])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Punctuation inside an override keeps its own class.

Input [classes, paragraph level, max depth]. RLE/RLO push the next odd level, LRE/LRO the next even level (RLO/LRO set an R/L override, RLE/LRE clear it) if the level <= max depth and no overflow is pending, else count an overflow. PDF first cancels an overflow, else pops if above the base. Codes get level "x" and class BN; other characters take the top level and the override class if any. Return [levels, classes].

split: open-access


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

N = 1
observations = []
def solve(x):
    classes, para, max_depth = x
    stack = [(para, None)]
    overflow = 0
    levels = []
    types = []
    for c in classes:
        if c in ('RLE', 'LRE', 'RLO', 'LRO'):
            cur = stack[-1][0]
            if c in ('RLE', 'RLO'):
                new = cur + 1 if cur % 2 == 0 else cur + 2
            else:
                new = cur + 2 if cur % 2 == 0 else cur + 1
            if new <= max_depth and overflow == 0:
                ovr = stack[-1][1] if c in ('RLE', 'LRE') else ('R' if c == 'RLO' else 'L')
                stack.append((new, ovr))
            else:
                overflow += 1
            levels.append('x')
            types.append('BN')
        elif c == 'PDF':
            if overflow > 0:
                overflow -= 1
            elif len(stack) > 1:
                stack.pop()
            levels.append('x')
            types.append('BN')
        else:
            lv, ovr = stack[-1]
            levels.append(lv)
            types.append(ovr if ovr else c)
    return [levels, types]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: embedding clears override', [['R', 'EN', 'LRO', 'LRE', 'R', 'RLO', 'RLE', 'LRO', 'PDF', 'L', 'R', 'ON'], 0, 5], [[0, 0, 'x', 'x', 4, 'x', 'x', 'x', 'x', 5, 5, 5], ['R', 'EN', 'BN', 'BN', 'R', 'BN', 'BN', 'BN', 'BN', 'R', 'R', 'R']]), ('regression: embedding clears override', [['RLO', 'ON', 'RLE', 'RLE', 'L', 'R'], 0, 4], [['x', 1, 'x', 'x', 3, 3], ['BN', 'R', 'BN', 'BN', 'L', 'R']]), ('partial-repair probe', [['R', 'L', 'LRE', 'LRE', 'ON', 'LRO', 'RLE', 'EN', 'LRE', 'EN'], 1, 2], [[1, 1, 'x', 'x', 2, 'x', 'x', 2, 'x', 2], ['R', 'L', 'BN', 'BN', 'ON', 'BN', 'BN', 'EN', 'BN', 'EN']]), ('partial-repair probe', [['RLO', 'PDF', 'RLE', 'LRE', 'EN', 'ON', 'WS', 'RLE', 'LRO', 'L', 'L'], 1, 4], [['x', 'x', 'x', 'x', 4, 4, 4, 'x', 'x', 4, 4], ['BN', 'BN', 'BN', 'BN', 'EN', 'ON', 'WS', 'BN', 'BN', 'L', 'L']]), ('RLE from odd level', [['RLE', 'RLE', 'L'], 0, 6], [['x', 'x', 3], ['BN', 'BN', 'L']]), ('override on neutrals', [['RLO', 'ON', 'L', 'WS'], 0, 6], [['x', 1, 1, 1], ['BN', 'R', 'R', 'R']]), ('control layout', [['R', 'LRO', 'R', 'RLO', 'PDF', 'R', 'EN', 'RLO', 'LRE', 'RLE', 'PDF', 'L'], 0, 2], [[0, 'x', 2, 'x', 'x', 2, 2, 'x', 'x', 'x', 'x', 2], ['R', 'BN', 'L', 'BN', 'BN', 'L', 'L', 'BN', 'BN', 'BN', 'BN', 'L']]), ('control layout', [['LRO', 'LRO', 'LRE', 'WS', 'LRO', 'RLO', 'LRE'], 0, 2], [['x', 'x', 'x', 2, 'x', 'x', 'x'], ['BN', 'BN', 'BN', 'L', 'BN', 'BN', 'BN']])], [('regression: embedding clears override', [['PDF', 'PDF', 'RLO', 'WS', 'ON', 'LRE', 'ON', 'LRO', 'R', 'L', 'EN', 'R'], 0, 4], [['x', 'x', 'x', 1, 1, 'x', 2, 'x', 4, 4, 4, 4], ['BN', 'BN', 'BN', 'R', 'R', 'BN', 'ON', 'BN', 'L', 'L', 'L', 'L']]), ('regression: embedding clears override', [['R', 'PDF', 'EN', 'L', 'R', 'LRO', 'ON', 'RLE', 'RLO', 'R', 'EN', 'ON', 'R'], 1, 3], [[1, 'x', 1, 1, 1, 'x', 2, 'x', 'x', 3, 3, 3, 3], ['R', 'BN', 'EN', 'L', 'R', 'BN', 'L', 'BN', 'BN', 'R', 'EN', 'ON', 'R']]), ('partial-repair probe', [['L', 'PDF', 'PDF', 'LRE', 'RLE', 'PDF', 'EN'], 1, 4], [[1, 'x', 'x', 'x', 'x', 'x', 2], ['L', 'BN', 'BN', 'BN', 'BN', 'BN', 'EN']]), ('partial-repair probe', [['RLO', 'PDF', 'RLE', 'LRE', 'EN', 'ON', 'WS', 'RLE', 'LRO', 'L', 'L'], 1, 4], [['x', 'x', 'x', 'x', 4, 4, 4, 'x', 'x', 4, 4], ['BN', 'BN', 'BN', 'BN', 'EN', 'ON', 'WS', 'BN', 'BN', 'L', 'L']]), ('LRE from odd level', [['LRE', 'R'], 1, 6], [['x', 2], ['BN', 'R']]), ('depth limit exactly reached', [['RLE', 'LRE', 'L', 'PDF', 'L'], 0, 2], [['x', 'x', 2, 'x', 1], ['BN', 'BN', 'L', 'BN', 'L']]), ('control layout', [['PDF', 'PDF'], 0, 5], [['x', 'x'], ['BN', 'BN']]), ('control layout', [['ON', 'LRO', 'EN'], 1, 2], [[1, 'x', 2], ['ON', 'BN', 'L']])], [('regression: embedding clears override', [['LRE', 'RLE', 'L', 'LRO', 'RLE', 'ON', 'LRO', 'PDF'], 1, 5], [['x', 'x', 3, 'x', 'x', 5, 'x', 'x'], ['BN', 'BN', 'L', 'BN', 'BN', 'ON', 'BN', 'BN']]), ('regression: embedding clears override', [['RLO', 'RLO', 'LRE', 'LRE', 'L'], 0, 4], [['x', 'x', 'x', 'x', 4], ['BN', 'BN', 'BN', 'BN', 'L']]), ('partial-repair probe', [['L', 'L', 'PDF', 'LRE', 'ON', 'ON', 'RLO', 'LRE', 'R', 'L', 'PDF', 'EN', 'RLO', 'L'], 0, 3], [[0, 0, 'x', 'x', 2, 2, 'x', 'x', 3, 3, 'x', 3, 'x', 3], ['L', 'L', 'BN', 'BN', 'ON', 'ON', 'BN', 'BN', 'R', 'R', 'BN', 'R', 'BN', 'R']]), ('partial-repair probe', [['R', 'L', 'RLE', 'WS', 'R', 'LRE', 'ON', 'PDF', 'RLE'], 0, 4], [[0, 0, 'x', 1, 1, 'x', 2, 'x', 'x'], ['R', 'L', 'BN', 'WS', 'R', 'BN', 'ON', 'BN', 'BN']]), ('RLE from odd level', [['RLE', 'RLE', 'L'], 0, 6], [['x', 'x', 3], ['BN', 'BN', 'L']]), ('depth limit exactly reached', [['RLE', 'LRE', 'L', 'PDF', 'L'], 0, 2], [['x', 'x', 2, 'x', 1], ['BN', 'BN', 'L', 'BN', 'L']]), ('control layout', [['R', 'L', 'EN'], 0, 6], [[0, 0, 0], ['R', 'L', 'EN']]), ('control layout', [['LRO', 'ON', 'EN', 'RLE', 'PDF', 'PDF', 'L'], 1, 3], [['x', 2, 2, 'x', 'x', 'x', 1], ['BN', 'L', 'L', 'BN', 'BN', 'BN', 'L']])], [('regression: embedding clears override', [['R', 'PDF', 'EN', 'L', 'R', 'LRO', 'ON', 'RLE', 'RLO', 'R', 'EN', 'ON', 'R'], 1, 3], [[1, 'x', 1, 1, 1, 'x', 2, 'x', 'x', 3, 3, 3, 3], ['R', 'BN', 'EN', 'L', 'R', 'BN', 'L', 'BN', 'BN', 'R', 'EN', 'ON', 'R']]), ('regression: embedding clears override', [['LRO', 'L', 'RLE', 'LRE', 'RLE', 'L', 'RLO', 'WS', 'RLO'], 0, 3], [['x', 2, 'x', 'x', 'x', 3, 'x', 3, 'x'], ['BN', 'L', 'BN', 'BN', 'BN', 'L', 'BN', 'WS', 'BN']]), ('partial-repair probe', [['L', 'R', 'LRE', 'L', 'R', 'WS', 'L', 'R', 'L', 'L', 'EN', 'PDF'], 1, 5], [[1, 1, 'x', 2, 2, 2, 2, 2, 2, 2, 2, 'x'], ['L', 'R', 'BN', 'L', 'R', 'WS', 'L', 'R', 'L', 'L', 'EN', 'BN']]), ('partial-repair probe', [['R', 'LRE', 'R'], 1, 6], [[1, 'x', 2], ['R', 'BN', 'R']]), ('depth limit exactly reached', [['RLE', 'LRE', 'L', 'PDF', 'L'], 0, 2], [['x', 'x', 2, 'x', 1], ['BN', 'BN', 'L', 'BN', 'L']]), ('RLE from odd level', [['RLE', 'RLE', 'L'], 0, 6], [['x', 'x', 3], ['BN', 'BN', 'L']]), ('control layout', [['ON', 'ON'], 0, 4], [[0, 0], ['ON', 'ON']]), ('control layout', [['EN', 'PDF', 'PDF', 'LRO', 'L', 'LRE', 'PDF', 'ON'], 1, 2], [[1, 'x', 'x', 'x', 2, 'x', 'x', 2], ['EN', 'BN', 'BN', 'BN', 'L', 'BN', 'BN', 'L']])], [('regression: embedding clears override', [['RLO', 'WS', 'ON', 'R', 'RLE', 'ON', 'RLE', 'PDF', 'RLE', 'R', 'ON'], 0, 5], [['x', 1, 1, 1, 'x', 3, 'x', 'x', 'x', 5, 5], ['BN', 'R', 'R', 'R', 'BN', 'ON', 'BN', 'BN', 'BN', 'R', 'ON']]), ('regression: embedding clears override', [['PDF', 'PDF', 'RLO', 'WS', 'ON', 'LRE', 'ON', 'LRO', 'R', 'L', 'EN', 'R'], 0, 4], [['x', 'x', 'x', 1, 1, 'x', 2, 'x', 4, 4, 4, 4], ['BN', 'BN', 'BN', 'R', 'R', 'BN', 'ON', 'BN', 'L', 'L', 'L', 'L']]), ('partial-repair probe', [['RLE', 'LRE', 'R', 'R', 'PDF', 'EN', 'L', 'LRE'], 1, 4], [['x', 'x', 4, 4, 'x', 3, 3, 'x'], ['BN', 'BN', 'R', 'R', 'BN', 'EN', 'L', 'BN']]), ('partial-repair probe', [['LRE', 'ON', 'LRO', 'PDF', 'PDF', 'R', 'ON'], 0, 2], [['x', 2, 'x', 'x', 'x', 0, 0], ['BN', 'ON', 'BN', 'BN', 'BN', 'R', 'ON']]), ('RLE from odd level', [['RLE', 'RLE', 'L'], 0, 6], [['x', 'x', 3], ['BN', 'BN', 'L']]), ('override on neutrals', [['RLO', 'ON', 'L', 'WS'], 0, 6], [['x', 1, 1, 1], ['BN', 'R', 'R', 'R']]), ('control layout', [['RLE', 'PDF', 'RLE', 'L', 'EN', 'L', 'L'], 0, 6], [['x', 'x', 'x', 1, 1, 1, 1], ['BN', 'BN', 'BN', 'L', 'EN', 'L', 'L']]), ('control layout', [['WS', 'EN', 'LRE', 'L'], 1, 4], [[1, 1, 'x', 2], ['WS', 'EN', 'BN', 'L']])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    classes, para, max_depth = x
    stack = [(para, None)]
    overflow = 0
    levels = []
    types = []
    for c in classes:
        if c in ('RLE', 'LRE', 'RLO', 'LRO'):
            cur = stack[-1][0]
            if c in ('RLE', 'RLO'):
                new = cur + 1 if cur % 2 == 0 else cur + 2
            else:
                new = cur + 2 if cur % 2 == 0 else cur + 1
            if new <= max_depth and overflow == 0:
                ovr = None if c == 'RLE' else ('R' if c == 'RLO' else 'L')
                stack.append((new, ovr))
            else:
                overflow += 1
            levels.append('x')
            types.append('BN')
        elif c == 'PDF':
            if overflow > 0:
                overflow -= 1
            elif len(stack) > 1:
                stack.pop()
            levels.append('x')
            types.append('BN')
        else:
            lv, ovr = stack[-1]
            levels.append(lv)
            types.append(ovr if ovr else c)
    return [levels, types]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: embedding clears override', [['R', 'EN', 'LRO', 'LRE', 'R', 'RLO', 'RLE', 'LRO', 'PDF', 'L', 'R', 'ON'], 0, 5], [[0, 0, 'x', 'x', 4, 'x', 'x', 'x', 'x', 5, 5, 5], ['R', 'EN', 'BN', 'BN', 'R', 'BN', 'BN', 'BN', 'BN', 'R', 'R', 'R']]), ('regression: embedding clears override', [['RLO', 'ON', 'RLE', 'RLE', 'L', 'R'], 0, 4], [['x', 1, 'x', 'x', 3, 3], ['BN', 'R', 'BN', 'BN', 'L', 'R']]), ('partial-repair probe', [['R', 'L', 'LRE', 'LRE', 'ON', 'LRO', 'RLE', 'EN', 'LRE', 'EN'], 1, 2], [[1, 1, 'x', 'x', 2, 'x', 'x', 2, 'x', 2], ['R', 'L', 'BN', 'BN', 'ON', 'BN', 'BN', 'EN', 'BN', 'EN']]), ('partial-repair probe', [['RLO', 'PDF', 'RLE', 'LRE', 'EN', 'ON', 'WS', 'RLE', 'LRO', 'L', 'L'], 1, 4], [['x', 'x', 'x', 'x', 4, 4, 4, 'x', 'x', 4, 4], ['BN', 'BN', 'BN', 'BN', 'EN', 'ON', 'WS', 'BN', 'BN', 'L', 'L']]), ('RLE from odd level', [['RLE', 'RLE', 'L'], 0, 6], [['x', 'x', 3], ['BN', 'BN', 'L']]), ('override on neutrals', [['RLO', 'ON', 'L', 'WS'], 0, 6], [['x', 1, 1, 1], ['BN', 'R', 'R', 'R']]), ('control layout', [['R', 'LRO', 'R', 'RLO', 'PDF', 'R', 'EN', 'RLO', 'LRE', 'RLE', 'PDF', 'L'], 0, 2], [[0, 'x', 2, 'x', 'x', 2, 2, 'x', 'x', 'x', 'x', 2], ['R', 'BN', 'L', 'BN', 'BN', 'L', 'L', 'BN', 'BN', 'BN', 'BN', 'L']]), ('control layout', [['LRO', 'LRO', 'LRE', 'WS', 'LRO', 'RLO', 'LRE'], 0, 2], [['x', 'x', 'x', 2, 'x', 'x', 'x'], ['BN', 'BN', 'BN', 'L', 'BN', 'BN', 'BN']])], [('regression: embedding clears override', [['PDF', 'PDF', 'RLO', 'WS', 'ON', 'LRE', 'ON', 'LRO', 'R', 'L', 'EN', 'R'], 0, 4], [['x', 'x', 'x', 1, 1, 'x', 2, 'x', 4, 4, 4, 4], ['BN', 'BN', 'BN', 'R', 'R', 'BN', 'ON', 'BN', 'L', 'L', 'L', 'L']]), ('regression: embedding clears override', [['R', 'PDF', 'EN', 'L', 'R', 'LRO', 'ON', 'RLE', 'RLO', 'R', 'EN', 'ON', 'R'], 1, 3], [[1, 'x', 1, 1, 1, 'x', 2, 'x', 'x', 3, 3, 3, 3], ['R', 'BN', 'EN', 'L', 'R', 'BN', 'L', 'BN', 'BN', 'R', 'EN', 'ON', 'R']]), ('partial-repair probe', [['L', 'PDF', 'PDF', 'LRE', 'RLE', 'PDF', 'EN'], 1, 4], [[1, 'x', 'x', 'x', 'x', 'x', 2], ['L', 'BN', 'BN', 'BN', 'BN', 'BN', 'EN']]), ('partial-repair probe', [['RLO', 'PDF', 'RLE', 'LRE', 'EN', 'ON', 'WS', 'RLE', 'LRO', 'L', 'L'], 1, 4], [['x', 'x', 'x', 'x', 4, 4, 4, 'x', 'x', 4, 4], ['BN', 'BN', 'BN', 'BN', 'EN', 'ON', 'WS', 'BN', 'BN', 'L', 'L']]), ('LRE from odd level', [['LRE', 'R'], 1, 6], [['x', 2], ['BN', 'R']]), ('depth limit exactly reached', [['RLE', 'LRE', 'L', 'PDF', 'L'], 0, 2], [['x', 'x', 2, 'x', 1], ['BN', 'BN', 'L', 'BN', 'L']]), ('control layout', [['PDF', 'PDF'], 0, 5], [['x', 'x'], ['BN', 'BN']]), ('control layout', [['ON', 'LRO', 'EN'], 1, 2], [[1, 'x', 2], ['ON', 'BN', 'L']])], [('regression: embedding clears override', [['LRE', 'RLE', 'L', 'LRO', 'RLE', 'ON', 'LRO', 'PDF'], 1, 5], [['x', 'x', 3, 'x', 'x', 5, 'x', 'x'], ['BN', 'BN', 'L', 'BN', 'BN', 'ON', 'BN', 'BN']]), ('regression: embedding clears override', [['RLO', 'RLO', 'LRE', 'LRE', 'L'], 0, 4], [['x', 'x', 'x', 'x', 4], ['BN', 'BN', 'BN', 'BN', 'L']]), ('partial-repair probe', [['L', 'L', 'PDF', 'LRE', 'ON', 'ON', 'RLO', 'LRE', 'R', 'L', 'PDF', 'EN', 'RLO', 'L'], 0, 3], [[0, 0, 'x', 'x', 2, 2, 'x', 'x', 3, 3, 'x', 3, 'x', 3], ['L', 'L', 'BN', 'BN', 'ON', 'ON', 'BN', 'BN', 'R', 'R', 'BN', 'R', 'BN', 'R']]), ('partial-repair probe', [['R', 'L', 'RLE', 'WS', 'R', 'LRE', 'ON', 'PDF', 'RLE'], 0, 4], [[0, 0, 'x', 1, 1, 'x', 2, 'x', 'x'], ['R', 'L', 'BN', 'WS', 'R', 'BN', 'ON', 'BN', 'BN']]), ('RLE from odd level', [['RLE', 'RLE', 'L'], 0, 6], [['x', 'x', 3], ['BN', 'BN', 'L']]), ('depth limit exactly reached', [['RLE', 'LRE', 'L', 'PDF', 'L'], 0, 2], [['x', 'x', 2, 'x', 1], ['BN', 'BN', 'L', 'BN', 'L']]), ('control layout', [['R', 'L', 'EN'], 0, 6], [[0, 0, 0], ['R', 'L', 'EN']]), ('control layout', [['LRO', 'ON', 'EN', 'RLE', 'PDF', 'PDF', 'L'], 1, 3], [['x', 2, 2, 'x', 'x', 'x', 1], ['BN', 'L', 'L', 'BN', 'BN', 'BN', 'L']])], [('regression: embedding clears override', [['R', 'PDF', 'EN', 'L', 'R', 'LRO', 'ON', 'RLE', 'RLO', 'R', 'EN', 'ON', 'R'], 1, 3], [[1, 'x', 1, 1, 1, 'x', 2, 'x', 'x', 3, 3, 3, 3], ['R', 'BN', 'EN', 'L', 'R', 'BN', 'L', 'BN', 'BN', 'R', 'EN', 'ON', 'R']]), ('regression: embedding clears override', [['LRO', 'L', 'RLE', 'LRE', 'RLE', 'L', 'RLO', 'WS', 'RLO'], 0, 3], [['x', 2, 'x', 'x', 'x', 3, 'x', 3, 'x'], ['BN', 'L', 'BN', 'BN', 'BN', 'L', 'BN', 'WS', 'BN']]), ('partial-repair probe', [['L', 'R', 'LRE', 'L', 'R', 'WS', 'L', 'R', 'L', 'L', 'EN', 'PDF'], 1, 5], [[1, 1, 'x', 2, 2, 2, 2, 2, 2, 2, 2, 'x'], ['L', 'R', 'BN', 'L', 'R', 'WS', 'L', 'R', 'L', 'L', 'EN', 'BN']]), ('partial-repair probe', [['R', 'LRE', 'R'], 1, 6], [[1, 'x', 2], ['R', 'BN', 'R']]), ('depth limit exactly reached', [['RLE', 'LRE', 'L', 'PDF', 'L'], 0, 2], [['x', 'x', 2, 'x', 1], ['BN', 'BN', 'L', 'BN', 'L']]), ('RLE from odd level', [['RLE', 'RLE', 'L'], 0, 6], [['x', 'x', 3], ['BN', 'BN', 'L']]), ('control layout', [['ON', 'ON'], 0, 4], [[0, 0], ['ON', 'ON']]), ('control layout', [['EN', 'PDF', 'PDF', 'LRO', 'L', 'LRE', 'PDF', 'ON'], 1, 2], [[1, 'x', 'x', 'x', 2, 'x', 'x', 2], ['EN', 'BN', 'BN', 'BN', 'L', 'BN', 'BN', 'L']])], [('regression: embedding clears override', [['RLO', 'WS', 'ON', 'R', 'RLE', 'ON', 'RLE', 'PDF', 'RLE', 'R', 'ON'], 0, 5], [['x', 1, 1, 1, 'x', 3, 'x', 'x', 'x', 5, 5], ['BN', 'R', 'R', 'R', 'BN', 'ON', 'BN', 'BN', 'BN', 'R', 'ON']]), ('regression: embedding clears override', [['PDF', 'PDF', 'RLO', 'WS', 'ON', 'LRE', 'ON', 'LRO', 'R', 'L', 'EN', 'R'], 0, 4], [['x', 'x', 'x', 1, 1, 'x', 2, 'x', 4, 4, 4, 4], ['BN', 'BN', 'BN', 'R', 'R', 'BN', 'ON', 'BN', 'L', 'L', 'L', 'L']]), ('partial-repair probe', [['RLE', 'LRE', 'R', 'R', 'PDF', 'EN', 'L', 'LRE'], 1, 4], [['x', 'x', 4, 4, 'x', 3, 3, 'x'], ['BN', 'BN', 'R', 'R', 'BN', 'EN', 'L', 'BN']]), ('partial-repair probe', [['LRE', 'ON', 'LRO', 'PDF', 'PDF', 'R', 'ON'], 0, 2], [['x', 2, 'x', 'x', 'x', 0, 0], ['BN', 'ON', 'BN', 'BN', 'BN', 'R', 'ON']]), ('RLE from odd level', [['RLE', 'RLE', 'L'], 0, 6], [['x', 'x', 3], ['BN', 'BN', 'L']]), ('override on neutrals', [['RLO', 'ON', 'L', 'WS'], 0, 6], [['x', 1, 1, 1], ['BN', 'R', 'R', 'R']]), ('control layout', [['RLE', 'PDF', 'RLE', 'L', 'EN', 'L', 'L'], 0, 6], [['x', 'x', 'x', 1, 1, 1, 1], ['BN', 'BN', 'BN', 'L', 'EN', 'L', 'L']]), ('control layout', [['WS', 'EN', 'LRE', 'L'], 1, 4], [[1, 1, 'x', 2], ['WS', 'EN', 'BN', 'L']])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Text inside an embedding nested in an override is still overridden.

Input [classes, paragraph level, max depth]. RLE/RLO push the next odd level, LRE/LRO the next even level (RLO/LRO set an R/L override, RLE/LRE clear it) if the level <= max depth and no overflow is pending, else count an overflow. PDF first cancels an overflow, else pops if above the base. Codes get level "x" and class BN; other characters take the top level and the override class if any. Return [levels, classes].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import itertools
N = 1
observations = []
def solve(x):
    text, levels = x
    M = {'(': ')', ')': '(', '[': ']', ']': '[', '{': '}', '}': '{', '<': '>', '>': '<', '«': '»', '»': '«'}
    n = len(text)
    glyphs = [M.get(ch, ch) if levels[i] > 0 else ch for i, ch in enumerate(text)]
    order = list(range(n))
    odd = [l for l in levels if l % 2]
    if odd:
        for lev in range(max(levels), min(odd) - 1, -1):
            runs = []
            for key, grp in itertools.groupby(order, key=lambda i: levels[i] >= lev):
                g = list(grp)
                runs.extend(g[::-1] if key else g)
            order = runs
    return ''.join(glyphs[i] for i in order)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('regression: mirroring parity', ['y)', [2, 2]], 'y)'), ('partial-repair probe', ['>a)]]a[><', [0, 0, 0, 0, 3, 3, 3, 3, 0]], '>a)]<]a[<'), ('partial-repair probe', ['<yy«<b){{a<', [1, 3, 3, 3, 3, 3, 1, 1, 1, 3, 3]], '>a}}(b>»yy>'), ('bracket in RTL run', ['a(b)', [1, 1, 1, 1]], '(b)a'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('control layout', ['y', [2]], 'y'), ('control layout', ['b<ya', [1, 1, 1, 1]], 'ay>b')], [('regression: mirroring parity', ['»»<y{aa}<y<>', [4, 4, 4, 3, 3, 4, 1, 1, 1, 1, 1, 1]], '<>y>{aa}y»»<'), ('regression: mirroring parity', ['a{»a(>}»[»»', [4, 4, 4, 4, 3, 3, 3, 1, 3, 1, 1]], '««]«{<)a{»a'), ('partial-repair probe', ['y[axy«»»)>', [1, 1, 3, 3, 3, 3, 1, 1, 1, 1]], '<(««»yxa]y'), ('regression: mirroring parity', ['()>}>])}y»(>', [1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 4, 2]], '(«y{(>[<{<()'), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('control layout', ['{', [1]], '}'), ('control layout', ['ay«', [1, 1, 1]], '»ya')], [('regression: mirroring parity', [']a>}>x)aa((', [1, 1, 1, 1, 4, 4, 4, 4, 1, 1, 1]], '))a>x)a{<a['), ('regression: mirroring parity', ['a»}[byx}{}', [1, 1, 1, 1, 0, 0, 2, 2, 0, 2]], ']{«abyx}{}'), ('partial-repair probe', ['x((a»b»ayb]', [2, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3]], 'x((a»b»[bya'), ('regression: mirroring parity', [']]{}xby<b{{', [2, 3, 3, 3, 3, 0, 0, 0, 0, 1, 1]], ']x{}[by<b}}'), ('bracket in RTL run', ['a(b)', [1, 1, 1, 1]], '(b)a'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('control layout', ['[»', [0, 0]], '[»'), ('control layout', ['<yy', [0, 0, 0]], '<yy')], [('regression: mirroring parity', ['{xba', [4, 4, 4, 2]], '{xba'), ('regression: mirroring parity', ['y«{»]<]', [2, 2, 2, 1, 1, 4, 4]], '<][«y«{'), ('partial-repair probe', ['{', [3]], '}'), ('partial-repair probe', ['b[<[«<}y}}x', [1, 1, 1, 0, 1, 1, 1, 3, 3, 0, 0]], '>]b[{y{>»}x'), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('control layout', ['>>(', [0, 0, 0]], '>>('), ('control layout', ['[»', [0, 0]], '[»')], [('regression: mirroring parity', ['{xyayb}{', [2, 1, 1, 1, 1, 1, 2, 2]], '}{byayx{'), ('regression: mirroring parity', ['}>', [2, 2]], '}>'), ('partial-repair probe', ['>y[y<', [0, 0, 0, 2, 3]], '>y[y>'), ('regression: mirroring parity', ['}<y<]{y>y}«', [2, 1, 1, 3, 3, 3, 2, 2, 2, 2, 1]], '»}[>y>y}y>}'), ('bracket in RTL run', ['a(b)', [1, 1, 1, 1]], '(b)a'), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('control layout', ['a', [2]], 'a'), ('control layout', ['a<<[x>', [2, 0, 0, 0, 0, 0]], 'a<<[x>')]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import itertools
N = 1
observations = []
def solve(x):
    text, levels = x
    M = {'(': ')', ')': '(', '[': ']', ']': '[', '{': '}', '}': '{', '<': '>', '>': '<', '«': '»', '»': '«'}
    n = len(text)
    glyphs = [M.get(ch, ch) if levels[i] == 1 else ch for i, ch in enumerate(text)]
    order = list(range(n))
    odd = [l for l in levels if l % 2]
    if odd:
        for lev in range(max(levels), min(odd) - 1, -1):
            runs = []
            for key, grp in itertools.groupby(order, key=lambda i: levels[i] >= lev):
                g = list(grp)
                runs.extend(g[::-1] if key else g)
            order = runs
    return ''.join(glyphs[i] for i in order)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('regression: mirroring parity', ['y)', [2, 2]], 'y)'), ('partial-repair probe', ['>a)]]a[><', [0, 0, 0, 0, 3, 3, 3, 3, 0]], '>a)]<]a[<'), ('partial-repair probe', ['<yy«<b){{a<', [1, 3, 3, 3, 3, 3, 1, 1, 1, 3, 3]], '>a}}(b>»yy>'), ('bracket in RTL run', ['a(b)', [1, 1, 1, 1]], '(b)a'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('control layout', ['y', [2]], 'y'), ('control layout', ['b<ya', [1, 1, 1, 1]], 'ay>b')], [('regression: mirroring parity', ['»»<y{aa}<y<>', [4, 4, 4, 3, 3, 4, 1, 1, 1, 1, 1, 1]], '<>y>{aa}y»»<'), ('regression: mirroring parity', ['a{»a(>}»[»»', [4, 4, 4, 4, 3, 3, 3, 1, 3, 1, 1]], '««]«{<)a{»a'), ('partial-repair probe', ['y[axy«»»)>', [1, 1, 3, 3, 3, 3, 1, 1, 1, 1]], '<(««»yxa]y'), ('regression: mirroring parity', ['()>}>])}y»(>', [1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 4, 2]], '(«y{(>[<{<()'), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('control layout', ['{', [1]], '}'), ('control layout', ['ay«', [1, 1, 1]], '»ya')], [('regression: mirroring parity', [']a>}>x)aa((', [1, 1, 1, 1, 4, 4, 4, 4, 1, 1, 1]], '))a>x)a{<a['), ('regression: mirroring parity', ['a»}[byx}{}', [1, 1, 1, 1, 0, 0, 2, 2, 0, 2]], ']{«abyx}{}'), ('partial-repair probe', ['x((a»b»ayb]', [2, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3]], 'x((a»b»[bya'), ('regression: mirroring parity', [']]{}xby<b{{', [2, 3, 3, 3, 3, 0, 0, 0, 0, 1, 1]], ']x{}[by<b}}'), ('bracket in RTL run', ['a(b)', [1, 1, 1, 1]], '(b)a'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('control layout', ['[»', [0, 0]], '[»'), ('control layout', ['<yy', [0, 0, 0]], '<yy')], [('regression: mirroring parity', ['{xba', [4, 4, 4, 2]], '{xba'), ('regression: mirroring parity', ['y«{»]<]', [2, 2, 2, 1, 1, 4, 4]], '<][«y«{'), ('partial-repair probe', ['{', [3]], '}'), ('partial-repair probe', ['b[<[«<}y}}x', [1, 1, 1, 0, 1, 1, 1, 3, 3, 0, 0]], '>]b[{y{>»}x'), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('control layout', ['>>(', [0, 0, 0]], '>>('), ('control layout', ['[»', [0, 0]], '[»')], [('regression: mirroring parity', ['{xyayb}{', [2, 1, 1, 1, 1, 1, 2, 2]], '}{byayx{'), ('regression: mirroring parity', ['}>', [2, 2]], '}>'), ('partial-repair probe', ['>y[y<', [0, 0, 0, 2, 3]], '>y[y>'), ('regression: mirroring parity', ['}<y<]{y>y}«', [2, 1, 1, 3, 3, 3, 2, 2, 2, 2, 1]], '»}[>y>y}y>}'), ('bracket in RTL run', ['a(b)', [1, 1, 1, 1]], '(b)a'), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('control layout', ['a', [2]], 'a'), ('control layout', ['a<<[x>', [2, 0, 0, 0, 0, 0]], 'a<<[x>')]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Brackets inside LTR embeddings of RTL text are flipped.

Input [text, resolved levels]. Characters at odd levels with a mirror pair ( ) [ ] { } < > « » are replaced by their mirror, decided per logical character; then runs are reversed from the highest level to the lowest odd level. Return the visual string.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import itertools
N = 1
observations = []
def solve(x):
    text, levels = x
    M = {'(': ')', '[': ']', '{': '}', '<': '>', '«': '»'}
    n = len(text)
    glyphs = [M.get(ch, ch) if levels[i] % 2 == 1 else ch for i, ch in enumerate(text)]
    order = list(range(n))
    odd = [l for l in levels if l % 2]
    if odd:
        for lev in range(max(levels), min(odd) - 1, -1):
            runs = []
            for key, grp in itertools.groupby(order, key=lambda i: levels[i] >= lev):
                g = list(grp)
                runs.extend(g[::-1] if key else g)
            order = runs
    return ''.join(glyphs[i] for i in order)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('bracket in RTL run', ['a(b)', [1, 1, 1, 1]], '(b)a'), ('regression: mirror table symmetry', ['b(][)]{«({b]', [3, 3, 3, 3, 1, 1, 1, 1, 2, 2, 2, 2]], '({b]»}[(][)b'), ('regression: mirror table symmetry', ['>»yyb)', [3, 3, 3, 3, 3, 1]], '(byy«<'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('control layout', ['<<«a', [2, 2, 2, 2]], '<<«a'), ('control layout', ['xy(>(xb', [2, 2, 2, 2, 2, 2, 2]], 'xy(>(xb'), ('control layout', ['y(x«[', [1, 0, 0, 0, 0]], 'y(x«[')], [('regression: mirror table symmetry', [')', [1]], '('), ('regression: mirror table symmetry', ['<[}y{([y', [1, 1, 1, 1, 1, 3, 3, 0]], '])}y{]>y'), ('regression: mirror table symmetry', ['{<[b«}x>«x', [0, 0, 0, 0, 0, 0, 0, 3, 3, 3]], '{<[b«}xx»<'), ('regression: mirror table symmetry', ['}«<)<yya<[y(', [1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1]], ')y]>yay>(>»{'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('control layout', ['a[', [1, 1]], ']a'), ('control layout', ['»a[', [0, 0, 0]], '»a[')], [('regression: mirror table symmetry', ['«])ay}xb', [2, 2, 2, 2, 2, 3, 3, 4]], '«])aybx{'), ('regression: mirror table symmetry', ['xy(»«y{(', [2, 2, 4, 3, 3, 3, 3, 1]], ')xy}y»«('), ('regression: mirror table symmetry', ['<»b«{', [1, 1, 1, 4, 3]], '}«b«>'), ('regression: mirror table symmetry', ['y]«', [3, 3, 3]], '»[y'), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('bracket in RTL run', ['a(b)', [1, 1, 1, 1]], '(b)a'), ('control layout', ['»»}<y[«}ay{x', [2, 2, 2, 2, 2, 1, 2, 2, 1, 1, 4, 4]], '{xya«}]»»}<y'), ('control layout', ['ay]»y[', [2, 2, 2, 2, 1, 2]], '[yay]»')], [('regression: mirror table symmetry', ['x}b>y]({}>({', [0, 0, 1, 3, 0, 0, 0, 0, 1, 2, 2, 0]], 'x}<by]({>({{'), ('regression: mirror table symmetry', ['«]x)<', [1, 1, 1, 0, 1]], 'x[»)>'), ('regression: mirror table symmetry', ['}«<)<yya<[y(', [1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1]], ')y]>yay>(>»{'), ('regression: mirror table symmetry', ['xy(»«y{(', [2, 2, 4, 3, 3, 3, 3, 1]], ')xy}y»«('), ('bracket in RTL run', ['a(b)', [1, 1, 1, 1]], '(b)a'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('control layout', ['a', [2]], 'a'), ('control layout', ['b({()', [1, 1, 1, 0, 0]], '})b()')], [('regression: mirror table symmetry', ['<<(b]b)]]»', [3, 3, 3, 1, 1, 1, 0, 0, 0, 2]], 'b[b)>>)]]»'), ('regression: mirror table symmetry', ['()»<x»)yy', [3, 3, 0, 0, 0, 0, 0, 0, 0]], '()»<x»)yy'), ('partial-repair probe', ['yy(«x', [1, 1, 1, 1, 2]], 'x»)yy'), ('partial-repair probe', ['y[([ay[«', [1, 1, 1, 1, 1, 2, 2, 1]], '»y[a])]y'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('control layout', ['ba', [3, 3]], 'ab'), ('control layout', ['y', [3]], 'y')]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import itertools
N = 1
observations = []
def solve(x):
    text, levels = x
    M = {'(': ')', ')': '(', '[': ']', ']': '[', '{': '}', '}': '{', '<': '>', '>': '<'}
    n = len(text)
    glyphs = [M.get(ch, ch) if levels[i] % 2 == 1 else ch for i, ch in enumerate(text)]
    order = list(range(n))
    odd = [l for l in levels if l % 2]
    if odd:
        for lev in range(max(levels), min(odd) - 1, -1):
            runs = []
            for key, grp in itertools.groupby(order, key=lambda i: levels[i] >= lev):
                g = list(grp)
                runs.extend(g[::-1] if key else g)
            order = runs
    return ''.join(glyphs[i] for i in order)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('bracket in RTL run', ['a(b)', [1, 1, 1, 1]], '(b)a'), ('regression: mirror table symmetry', ['b(][)]{«({b]', [3, 3, 3, 3, 1, 1, 1, 1, 2, 2, 2, 2]], '({b]»}[(][)b'), ('regression: mirror table symmetry', ['>»yyb)', [3, 3, 3, 3, 3, 1]], '(byy«<'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('control layout', ['<<«a', [2, 2, 2, 2]], '<<«a'), ('control layout', ['xy(>(xb', [2, 2, 2, 2, 2, 2, 2]], 'xy(>(xb'), ('control layout', ['y(x«[', [1, 0, 0, 0, 0]], 'y(x«[')], [('regression: mirror table symmetry', [')', [1]], '('), ('regression: mirror table symmetry', ['<[}y{([y', [1, 1, 1, 1, 1, 3, 3, 0]], '])}y{]>y'), ('regression: mirror table symmetry', ['{<[b«}x>«x', [0, 0, 0, 0, 0, 0, 0, 3, 3, 3]], '{<[b«}xx»<'), ('regression: mirror table symmetry', ['}«<)<yya<[y(', [1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1]], ')y]>yay>(>»{'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('control layout', ['a[', [1, 1]], ']a'), ('control layout', ['»a[', [0, 0, 0]], '»a[')], [('regression: mirror table symmetry', ['«])ay}xb', [2, 2, 2, 2, 2, 3, 3, 4]], '«])aybx{'), ('regression: mirror table symmetry', ['xy(»«y{(', [2, 2, 4, 3, 3, 3, 3, 1]], ')xy}y»«('), ('regression: mirror table symmetry', ['<»b«{', [1, 1, 1, 4, 3]], '}«b«>'), ('regression: mirror table symmetry', ['y]«', [3, 3, 3]], '»[y'), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('bracket in RTL run', ['a(b)', [1, 1, 1, 1]], '(b)a'), ('control layout', ['»»}<y[«}ay{x', [2, 2, 2, 2, 2, 1, 2, 2, 1, 1, 4, 4]], '{xya«}]»»}<y'), ('control layout', ['ay]»y[', [2, 2, 2, 2, 1, 2]], '[yay]»')], [('regression: mirror table symmetry', ['x}b>y]({}>({', [0, 0, 1, 3, 0, 0, 0, 0, 1, 2, 2, 0]], 'x}<by]({>({{'), ('regression: mirror table symmetry', ['«]x)<', [1, 1, 1, 0, 1]], 'x[»)>'), ('regression: mirror table symmetry', ['}«<)<yya<[y(', [1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1]], ')y]>yay>(>»{'), ('regression: mirror table symmetry', ['xy(»«y{(', [2, 2, 4, 3, 3, 3, 3, 1]], ')xy}y»«('), ('bracket in RTL run', ['a(b)', [1, 1, 1, 1]], '(b)a'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('control layout', ['a', [2]], 'a'), ('control layout', ['b({()', [1, 1, 1, 0, 0]], '})b()')], [('regression: mirror table symmetry', ['<<(b]b)]]»', [3, 3, 3, 1, 1, 1, 0, 0, 0, 2]], 'b[b)>>)]]»'), ('regression: mirror table symmetry', ['()»<x»)yy', [3, 3, 0, 0, 0, 0, 0, 0, 0]], '()»<x»)yy'), ('partial-repair probe', ['yy(«x', [1, 1, 1, 1, 2]], 'x»)yy'), ('partial-repair probe', ['y[([ay[«', [1, 1, 1, 1, 1, 2, 2, 1]], '»y[a])]y'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('control layout', ['ba', [3, 3]], 'ab'), ('control layout', ['y', [3]], 'y')]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Closing brackets in RTL text render unflipped.

Input [text, resolved levels]. Characters at odd levels with a mirror pair ( ) [ ] { } < > « » are replaced by their mirror, decided per logical character; then runs are reversed from the highest level to the lowest odd level. Return the visual string.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import itertools
N = 1
observations = []
def solve(x):
    text, levels = x
    M = {'(': ')', ')': '(', '[': ']', ']': '[', '{': '}', '}': '{', '<': '>', '>': '<', '«': '»', '»': '«'}
    n = len(text)
    glyphs = list(text)
    order = list(range(n))
    odd = [l for l in levels if l % 2]
    if odd:
        for lev in range(max(levels), min(odd) - 1, -1):
            runs = []
            for key, grp in itertools.groupby(order, key=lambda i: levels[i] >= lev):
                g = list(grp)
                runs.extend(g[::-1] if key else g)
            order = runs
    return ''.join(M.get(text[i], text[i]) if levels[v] % 2 == 1 else text[i] for v, i in enumerate(order))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: mirror level lookup', ['y[]x}<()]a', [4, 4, 2, 1, 3, 3, 2, 2, 1, 3]], 'a[>{()xy[]'), ('regression: mirror level lookup', ['{»{»}(»a>', [2, 2, 2, 1, 4, 2, 2, 2, 4]], '}(»a>«{»{'), ('regression: mirror level lookup', [']]{)«)<x»<}[', [1, 4, 4, 4, 4, 1, 1, 1, 2, 2, 2, 3]], '»<}]x>(]{)«['), ('regression: mirror level lookup', ['[}a[y{]}»', [2, 1, 1, 3, 2, 2, 2, 2, 3]], ']y{]}«a{['), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('control layout', ['y<', [1, 1]], '>y'), ('control layout', ['ba', [3, 3]], 'ab')], [('regression: mirror level lookup', ['>[){x', [3, 3, 3, 3, 4]], 'x}(]<'), ('regression: mirror level lookup', ['»>x»', [1, 2, 2, 2]], '>x»«'), ('regression: mirror level lookup', ['}<a<(a>«]', [1, 1, 1, 2, 2, 2, 2, 2, 2]], '<(a>«]a>{'), ('regression: mirror level lookup', ['[]<<«y»]xb)', [2, 2, 2, 2, 2, 3, 3, 3, 3, 1, 3]], '(b[]<<«x[«y'), ('bracket in RTL run', ['a(b)', [1, 1, 1, 1]], '(b)a'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('control layout', ['»', [2]], '»'), ('control layout', ['«{>}]]ax}', [1, 1, 1, 1, 1, 1, 1, 1, 1]], '{xa[[{<}»')], [('regression: mirror level lookup', ['}«x[[ab', [1, 1, 1, 1, 2, 1, 1]], 'ba[]x»{'), ('regression: mirror level lookup', ['y«{»]<]', [2, 2, 2, 1, 1, 4, 4]], '<][«y«{'), ('regression: mirror level lookup', ['>b<x<b»b)b', [0, 0, 0, 0, 1, 1, 1, 1, 2, 2]], '>b<x)bb«b>'), ('partial-repair probe', [')}<)<>[(a', [0, 0, 0, 0, 3, 3, 3, 3, 1]], ')}<)a)]<>'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('bracket in RTL run', ['a(b)', [1, 1, 1, 1]], '(b)a'), ('control layout', ['ya[', [1, 1, 1]], ']ay'), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)')], [('regression: mirror level lookup', ['ay]»y[', [2, 2, 2, 2, 1, 2]], '[yay]»'), ('regression: mirror level lookup', ['xx>>}(b]{]«', [1, 1, 2, 1, 3, 3, 3, 3, 1, 1, 3]], '»[}[b){<>xx'), ('regression: mirror level lookup', ['«])ay}xb', [2, 2, 2, 2, 2, 3, 3, 4]], '«])aybx{'), ('partial-repair probe', ['««a<>x{)}>', [1, 1, 2, 2, 2, 4, 2, 2, 1, 1]], '<{a<>x{)»»'), ('bracket in RTL run', ['a(b)', [1, 1, 1, 1]], '(b)a'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('control layout', ['a[', [1, 1]], ']a'), ('control layout', ['(x)](', [1, 1, 1, 1, 3]], ')[(x)')], [('regression: mirror level lookup', ['a]»y]«)<»<x)', [3, 3, 3, 2, 4, 2, 2, 2, 2, 1, 1, 1]], '(x>«[ay]«)<»'), ('regression: mirror level lookup', [']]b{{{)', [3, 2, 2, 1, 1, 1, 1]], '(}}}[]b'), ('regression: mirror level lookup', ['xy(»«y{(', [2, 2, 4, 3, 3, 3, 3, 1]], ')xy}y»«('), ('regression: mirror level lookup', ['y{]]>[[x>>', [1, 1, 1, 2, 2, 2, 2, 2, 1, 2]], '><]>[[x[}y'), ('bracket in RTL run', ['a(b)', [1, 1, 1, 1]], '(b)a'), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('control layout', [')>b»', [1, 1, 1, 1]], '«b<('), ('control layout', ['«x', [3, 3]], 'x»')]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import itertools
N = 1
observations = []
def solve(x):
    text, levels = x
    M = {'(': ')', ')': '(', '[': ']', ']': '[', '{': '}', '}': '{', '<': '>', '>': '<', '«': '»', '»': '«'}
    n = len(text)
    glyphs = [M.get(ch, ch) if levels[0] % 2 == 1 else ch for i, ch in enumerate(text)]
    order = list(range(n))
    odd = [l for l in levels if l % 2]
    if odd:
        for lev in range(max(levels), min(odd) - 1, -1):
            runs = []
            for key, grp in itertools.groupby(order, key=lambda i: levels[i] >= lev):
                g = list(grp)
                runs.extend(g[::-1] if key else g)
            order = runs
    return ''.join(glyphs[i] for i in order)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: mirror level lookup', ['y[]x}<()]a', [4, 4, 2, 1, 3, 3, 2, 2, 1, 3]], 'a[>{()xy[]'), ('regression: mirror level lookup', ['{»{»}(»a>', [2, 2, 2, 1, 4, 2, 2, 2, 4]], '}(»a>«{»{'), ('regression: mirror level lookup', [']]{)«)<x»<}[', [1, 4, 4, 4, 4, 1, 1, 1, 2, 2, 2, 3]], '»<}]x>(]{)«['), ('regression: mirror level lookup', ['[}a[y{]}»', [2, 1, 1, 3, 2, 2, 2, 2, 3]], ']y{]}«a{['), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('control layout', ['y<', [1, 1]], '>y'), ('control layout', ['ba', [3, 3]], 'ab')], [('regression: mirror level lookup', ['>[){x', [3, 3, 3, 3, 4]], 'x}(]<'), ('regression: mirror level lookup', ['»>x»', [1, 2, 2, 2]], '>x»«'), ('regression: mirror level lookup', ['}<a<(a>«]', [1, 1, 1, 2, 2, 2, 2, 2, 2]], '<(a>«]a>{'), ('regression: mirror level lookup', ['[]<<«y»]xb)', [2, 2, 2, 2, 2, 3, 3, 3, 3, 1, 3]], '(b[]<<«x[«y'), ('bracket in RTL run', ['a(b)', [1, 1, 1, 1]], '(b)a'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('control layout', ['»', [2]], '»'), ('control layout', ['«{>}]]ax}', [1, 1, 1, 1, 1, 1, 1, 1, 1]], '{xa[[{<}»')], [('regression: mirror level lookup', ['}«x[[ab', [1, 1, 1, 1, 2, 1, 1]], 'ba[]x»{'), ('regression: mirror level lookup', ['y«{»]<]', [2, 2, 2, 1, 1, 4, 4]], '<][«y«{'), ('regression: mirror level lookup', ['>b<x<b»b)b', [0, 0, 0, 0, 1, 1, 1, 1, 2, 2]], '>b<x)bb«b>'), ('partial-repair probe', [')}<)<>[(a', [0, 0, 0, 0, 3, 3, 3, 3, 1]], ')}<)a)]<>'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('bracket in RTL run', ['a(b)', [1, 1, 1, 1]], '(b)a'), ('control layout', ['ya[', [1, 1, 1]], ']ay'), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)')], [('regression: mirror level lookup', ['ay]»y[', [2, 2, 2, 2, 1, 2]], '[yay]»'), ('regression: mirror level lookup', ['xx>>}(b]{]«', [1, 1, 2, 1, 3, 3, 3, 3, 1, 1, 3]], '»[}[b){<>xx'), ('regression: mirror level lookup', ['«])ay}xb', [2, 2, 2, 2, 2, 3, 3, 4]], '«])aybx{'), ('partial-repair probe', ['««a<>x{)}>', [1, 1, 2, 2, 2, 4, 2, 2, 1, 1]], '<{a<>x{)»»'), ('bracket in RTL run', ['a(b)', [1, 1, 1, 1]], '(b)a'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('control layout', ['a[', [1, 1]], ']a'), ('control layout', ['(x)](', [1, 1, 1, 1, 3]], ')[(x)')], [('regression: mirror level lookup', ['a]»y]«)<»<x)', [3, 3, 3, 2, 4, 2, 2, 2, 2, 1, 1, 1]], '(x>«[ay]«)<»'), ('regression: mirror level lookup', [']]b{{{)', [3, 2, 2, 1, 1, 1, 1]], '(}}}[]b'), ('regression: mirror level lookup', ['xy(»«y{(', [2, 2, 4, 3, 3, 3, 3, 1]], ')xy}y»«('), ('regression: mirror level lookup', ['y{]]>[[x>>', [1, 1, 1, 2, 2, 2, 2, 2, 1, 2]], '><]>[[x[}y'), ('bracket in RTL run', ['a(b)', [1, 1, 1, 1]], '(b)a'), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('control layout', [')>b»', [1, 1, 1, 1]], '«b<('), ('control layout', ['«x', [3, 3]], 'x»')]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Brackets are mirrored based on the level found at their visual slot.

Input [text, resolved levels]. Characters at odd levels with a mirror pair ( ) [ ] { } < > « » are replaced by their mirror, decided per logical character; then runs are reversed from the highest level to the lowest odd level. Return the visual string.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import itertools
N = 1
observations = []
def solve(x):
    text, levels = x
    M = {'(': ')', ')': '(', '[': ']', ']': '[', '{': '}', '}': '{', '<': '>', '>': '<', '«': '»', '»': '«'}
    n = len(text)
    glyphs = [M.get(ch, ch) if levels[i] % 2 == 1 else ch for i, ch in enumerate(text)]
    order = list(range(n))
    odd = [l for l in levels if l % 2]
    if odd:
        for lev in range(max(levels), min(odd) - 1, -1):
            runs = []
            for key, grp in itertools.groupby(order, key=lambda i: levels[i] == lev):
                g = list(grp)
                runs.extend(g[::-1] if key else g)
            order = runs
    return ''.join(glyphs[i] for i in order)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: reversal grouping key', ['{]x(x«}[<[ab', [4, 4, 1, 1, 1, 1, 1, 1, 4, 4, 4, 4]], '<[ab]{»x)x{]'), ('regression: reversal grouping key', ['<x{(>}bx<', [2, 2, 2, 4, 4, 3, 3, 3, 1]], '><x{xb{(>'), ('regression: reversal grouping key', ['a»>»)b«', [1, 4, 4, 1, 1, 1, 1]], '»b(«»>a'), ('partial-repair probe', ['ba', [3, 3]], 'ab'), ('bracket in RTL run', ['a(b)', [1, 1, 1, 1]], '(b)a'), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('control layout', ['<', [2]], '<'), ('control layout', ['by>»', [4, 4, 4, 4]], 'by>»')], [('regression: reversal grouping key', ['<x{(>}bx<', [2, 2, 2, 4, 4, 3, 3, 3, 1]], '><x{xb{(>'), ('regression: reversal grouping key', ['}«<)<yya<[y(', [1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1]], ')y]>yay>(>»{'), ('regression: reversal grouping key', ['«»«[yx{', [1, 1, 1, 2, 2, 2, 2]], '[yx{»«»'), ('regression: reversal grouping key', ['(»x({}(]}»', [2, 2, 2, 2, 2, 2, 2, 2, 1, 1]], '«{(»x({}(]'), ('bracket in RTL run', ['a(b)', [1, 1, 1, 1]], '(b)a'), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('control layout', ['><', [2, 2]], '><'), ('control layout', ['xx}yb[}x>', [2, 2, 2, 2, 2, 2, 2, 4, 4]], 'xx}yb[}x>')], [('regression: reversal grouping key', ['abx«>x)x{x', [2, 2, 2, 2, 2, 1, 1, 2, 1, 1]], 'x}x(xabx«>'), ('regression: reversal grouping key', ['»«a<b(«)>', [3, 3, 4, 4, 2, 2, 2, 2, 1]], '<a<»«b(«)'), ('partial-repair probe', [']){b', [3, 3, 3, 3]], 'b}(['), ('partial-repair probe', ['{«x[<b', [1, 1, 1, 0, 0, 0]], 'x»}[<b'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('control layout', ['<<', [3, 3]], '>>'), ('control layout', ['a', [2]], 'a')], [('regression: reversal grouping key', ['>«>>([[»[', [1, 1, 1, 1, 2, 2, 2, 4, 2]], '([[»[<<»<'), ('regression: reversal grouping key', ['«b[a)}', [4, 4, 4, 1, 1, 4]], '}(a«b['), ('regression: reversal grouping key', [')by{}[][', [1, 1, 1, 1, 2, 2, 2, 2]], '}[][}yb('), ('partial-repair probe', ['»))<)[«', [0, 0, 1, 1, 1, 1, 1]], '»)»](>('), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('control layout', ['y', [0]], 'y'), ('control layout', ['x[]', [2, 2, 1]], '[x[')], [('regression: reversal grouping key', ['by)bb}»)[', [4, 4, 3, 2, 2, 2, 2, 1, 1]], ']((bybb}»'), ('regression: reversal grouping key', ['ax{]b>b)', [0, 0, 0, 0, 0, 3, 3, 1]], 'ax{]b(b<'), ('partial-repair probe', [')]y))»>', [0, 0, 0, 0, 1, 1, 1]], ')]y)<«('), ('partial-repair probe', ['<)«>>»»)»', [3, 3, 3, 3, 0, 1, 1, 1, 1]], '<»(>>«(««'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('control layout', ['yxb][<<[<', [0, 0, 0, 0, 0, 2, 2, 0, 0]], 'yxb][<<[<'), ('control layout', ['<<', [3, 3]], '>>')]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import itertools
N = 1
observations = []
def solve(x):
    text, levels = x
    M = {'(': ')', ')': '(', '[': ']', ']': '[', '{': '}', '}': '{', '<': '>', '>': '<', '«': '»', '»': '«'}
    n = len(text)
    glyphs = [M.get(ch, ch) if levels[i] % 2 == 1 else ch for i, ch in enumerate(text)]
    order = list(range(n))
    odd = [l for l in levels if l % 2]
    if odd:
        for lev in range(max(levels), min(odd) - 1, -1):
            runs = []
            for key, grp in itertools.groupby(order, key=lambda i: levels[i] > lev):
                g = list(grp)
                runs.extend(g[::-1] if key else g)
            order = runs
    return ''.join(glyphs[i] for i in order)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: reversal grouping key', ['{]x(x«}[<[ab', [4, 4, 1, 1, 1, 1, 1, 1, 4, 4, 4, 4]], '<[ab]{»x)x{]'), ('regression: reversal grouping key', ['<x{(>}bx<', [2, 2, 2, 4, 4, 3, 3, 3, 1]], '><x{xb{(>'), ('regression: reversal grouping key', ['a»>»)b«', [1, 4, 4, 1, 1, 1, 1]], '»b(«»>a'), ('partial-repair probe', ['ba', [3, 3]], 'ab'), ('bracket in RTL run', ['a(b)', [1, 1, 1, 1]], '(b)a'), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('control layout', ['<', [2]], '<'), ('control layout', ['by>»', [4, 4, 4, 4]], 'by>»')], [('regression: reversal grouping key', ['<x{(>}bx<', [2, 2, 2, 4, 4, 3, 3, 3, 1]], '><x{xb{(>'), ('regression: reversal grouping key', ['}«<)<yya<[y(', [1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1]], ')y]>yay>(>»{'), ('regression: reversal grouping key', ['«»«[yx{', [1, 1, 1, 2, 2, 2, 2]], '[yx{»«»'), ('regression: reversal grouping key', ['(»x({}(]}»', [2, 2, 2, 2, 2, 2, 2, 2, 1, 1]], '«{(»x({}(]'), ('bracket in RTL run', ['a(b)', [1, 1, 1, 1]], '(b)a'), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('control layout', ['><', [2, 2]], '><'), ('control layout', ['xx}yb[}x>', [2, 2, 2, 2, 2, 2, 2, 4, 4]], 'xx}yb[}x>')], [('regression: reversal grouping key', ['abx«>x)x{x', [2, 2, 2, 2, 2, 1, 1, 2, 1, 1]], 'x}x(xabx«>'), ('regression: reversal grouping key', ['»«a<b(«)>', [3, 3, 4, 4, 2, 2, 2, 2, 1]], '<a<»«b(«)'), ('partial-repair probe', [']){b', [3, 3, 3, 3]], 'b}(['), ('partial-repair probe', ['{«x[<b', [1, 1, 1, 0, 0, 0]], 'x»}[<b'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('control layout', ['<<', [3, 3]], '>>'), ('control layout', ['a', [2]], 'a')], [('regression: reversal grouping key', ['>«>>([[»[', [1, 1, 1, 1, 2, 2, 2, 4, 2]], '([[»[<<»<'), ('regression: reversal grouping key', ['«b[a)}', [4, 4, 4, 1, 1, 4]], '}(a«b['), ('regression: reversal grouping key', [')by{}[][', [1, 1, 1, 1, 2, 2, 2, 2]], '}[][}yb('), ('partial-repair probe', ['»))<)[«', [0, 0, 1, 1, 1, 1, 1]], '»)»](>('), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('control layout', ['y', [0]], 'y'), ('control layout', ['x[]', [2, 2, 1]], '[x[')], [('regression: reversal grouping key', ['by)bb}»)[', [4, 4, 3, 2, 2, 2, 2, 1, 1]], ']((bybb}»'), ('regression: reversal grouping key', ['ax{]b>b)', [0, 0, 0, 0, 0, 3, 3, 1]], 'ax{]b(b<'), ('partial-repair probe', [')]y))»>', [0, 0, 0, 0, 1, 1, 1]], ')]y)<«('), ('partial-repair probe', ['<)«>>»»)»', [3, 3, 3, 3, 0, 1, 1, 1, 1]], '<»(>>«(««'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('control layout', ['yxb][<<[<', [0, 0, 0, 0, 0, 2, 2, 0, 0]], 'yxb][<<[<'), ('control layout', ['<<', [3, 3]], '>>')]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Higher-level runs nested inside a reversal are left in place.

Input [text, resolved levels]. Characters at odd levels with a mirror pair ( ) [ ] { } < > « » are replaced by their mirror, decided per logical character; then runs are reversed from the highest level to the lowest odd level. Return the visual string.

split: open-access


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

N = 1
observations = []
def solve(x):
    text, classes, limit = x
    OPEN = {'(': ')', '[': ']', '{': '}'}
    CLOSE = {')', ']', '}'}
    stack = []
    pairs = []
    for i, ch in enumerate(text):
        if classes[i] == 'L':
            continue
        if ch in OPEN:
            if len(stack) >= limit:
                break
            stack.append((OPEN[ch], i))
        elif ch in CLOSE:
            for k in range(len(stack) - 1, -1, -1):
                if stack[k][0] == ch:
                    pairs.append([stack[k][1], i])
                    del stack[k:]
                    break
    return sorted(pairs)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('overridden bracket ignored', ['(a)', ['R', 'L', 'ON'], 4], []), ('regression: bracket class filter', ['}(][(]}()(}', ['ON', 'R', 'ON', 'ON', 'ON', 'L', 'ON', 'ON', 'ON', 'R', 'R'], 3], [[7, 8]]), ('regression: bracket class filter', [']]({}', ['ON', 'ON', 'ON', 'R', 'ON'], 4], []), ('regression: bracket class filter', ['{{)(([))[', ['ON', 'ON', 'L', 'ON', 'R', 'ON', 'ON', 'ON', 'R'], 4], [[3, 6]]), ('stack overflow stops', ['((()))', ['ON', 'ON', 'ON', 'ON', 'ON', 'ON'], 2], []), ('mismatched inner bracket', ['([)]', ['ON', 'ON', 'ON', 'ON'], 4], [[0, 2]]), ('control layout', [']()({)a(]a', ['R', 'ON', 'ON', 'ON', 'ON', 'ON', 'R', 'ON', 'ON', 'L'], 3], [[1, 2], [3, 5]]), ('control layout', ['{{)}()[]}', ['ON', 'ON', 'ON', 'ON', 'ON', 'ON', 'ON', 'ON', 'L'], 3], [[1, 3], [4, 5], [6, 7]])], [('regression: bracket class filter', ['((}}aa]()(()a', ['L', 'ON', 'ON', 'ON', 'R', 'L', 'ON', 'ON', 'R', 'ON', 'ON', 'ON', 'L'], 2], []), ('regression: bracket class filter', ['(aa]a])([[(]{a', ['ON', 'R', 'L', 'ON', 'L', 'ON', 'R', 'ON', 'ON', 'ON', 'ON', 'ON', 'ON', 'R'], 2], []), ('regression: bracket class filter', [')((({}}(]', ['L', 'ON', 'ON', 'L', 'ON', 'R', 'ON', 'ON', 'ON'], 3], [[4, 6]]), ('regression: bracket class filter', ['a(){', ['R', 'R', 'ON', 'ON'], 4], []), ('stack overflow stops', ['((()))', ['ON', 'ON', 'ON', 'ON', 'ON', 'ON'], 2], []), ('mismatched inner bracket', ['([)]', ['ON', 'ON', 'ON', 'ON'], 4], [[0, 2]]), ('control layout', [')]])([', ['R', 'ON', 'ON', 'ON', 'ON', 'ON'], 2], []), ('control layout', ['}}]', ['ON', 'ON', 'ON'], 4], [])], [('regression: bracket class filter', ['a[()}a]aa', ['R', 'ON', 'R', 'ON', 'ON', 'R', 'L', 'R', 'L'], 3], []), ('regression: bracket class filter', ['{{({()}]}', ['L', 'ON', 'ON', 'ON', 'R', 'ON', 'ON', 'ON', 'ON'], 4], [[1, 6], [2, 5]]), ('regression: bracket class filter', ['{)[}[(((]{(]{', ['ON', 'ON', 'ON', 'R', 'ON', 'ON', 'ON', 'L', 'ON', 'ON', 'ON', 'ON', 'ON'], 2], []), ('regression: bracket class filter', ['{{)(([))[', ['ON', 'ON', 'L', 'ON', 'R', 'ON', 'ON', 'ON', 'R'], 4], [[3, 6]]), ('mismatched inner bracket', ['([)]', ['ON', 'ON', 'ON', 'ON'], 4], [[0, 2]]), ('stack overflow stops', ['((()))', ['ON', 'ON', 'ON', 'ON', 'ON', 'ON'], 2], []), ('control layout', ['[[]', ['ON', 'ON', 'ON'], 3], [[1, 2]]), ('control layout', ['a]]{)a((](a', ['R', 'ON', 'R', 'ON', 'ON', 'L', 'ON', 'ON', 'ON', 'ON', 'L'], 2], [])], [('regression: bracket class filter', ['[]a}}[](a](((', ['ON', 'R', 'R', 'ON', 'R', 'ON', 'ON', 'ON', 'L', 'R', 'L', 'ON', 'R'], 1], []), ('regression: bracket class filter', ['((}}aa]()(()a', ['L', 'ON', 'ON', 'ON', 'R', 'L', 'ON', 'ON', 'R', 'ON', 'ON', 'ON', 'L'], 2], []), ('regression: bracket class filter', ['][](((({})a()', ['ON', 'R', 'ON', 'ON', 'ON', 'L', 'ON', 'ON', 'ON', 'ON', 'R', 'ON', 'ON'], 2], []), ('overridden bracket ignored', ['(a)', ['R', 'L', 'ON'], 4], []), ('stack overflow stops', ['((()))', ['ON', 'ON', 'ON', 'ON', 'ON', 'ON'], 2], []), ('mismatched inner bracket', ['([)]', ['ON', 'ON', 'ON', 'ON'], 4], [[0, 2]]), ('control layout', ['{}}a{([(([{', ['ON', 'ON', 'ON', 'L', 'ON', 'L', 'ON', 'L', 'ON', 'ON', 'ON'], 2], [[0, 1]]), ('control layout', ['}{', ['ON', 'ON'], 3], [])], [('regression: bracket class filter', ['}}}{(]}((', ['R', 'ON', 'ON', 'ON', 'ON', 'ON', 'R', 'ON', 'ON'], 2], []), ('regression: bracket class filter', ['([(]}}))(}a(', ['L', 'R', 'ON', 'ON', 'ON', 'ON', 'ON', 'ON', 'ON', 'ON', 'R', 'ON'], 3], [[2, 6]]), ('regression: bracket class filter', ['}a()[a(({]', ['ON', 'L', 'R', 'ON', 'R', 'L', 'ON', 'ON', 'ON', 'L'], 3], []), ('regression: bracket class filter', ['[((({a}', ['ON', 'R', 'ON', 'ON', 'ON', 'L', 'ON'], 4], [[4, 6]]), ('overridden bracket ignored', ['(a)', ['R', 'L', 'ON'], 4], []), ('stack overflow stops', ['((()))', ['ON', 'ON', 'ON', 'ON', 'ON', 'ON'], 2], []), ('control layout', ['}{', ['ON', 'ON'], 3], []), ('control layout', ['((][{]a{{)}', ['ON', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'R', 'L', 'ON', 'R'], 4], [[1, 9], [3, 5]])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    text, classes, limit = x
    OPEN = {'(': ')', '[': ']', '{': '}'}
    CLOSE = {')', ']', '}'}
    stack = []
    pairs = []
    for i, ch in enumerate(text):
        if classes[i] not in ('ON', 'R'):
            continue
        if ch in OPEN:
            if len(stack) >= limit:
                break
            stack.append((OPEN[ch], i))
        elif ch in CLOSE:
            for k in range(len(stack) - 1, -1, -1):
                if stack[k][0] == ch:
                    pairs.append([stack[k][1], i])
                    del stack[k:]
                    break
    return sorted(pairs)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('overridden bracket ignored', ['(a)', ['R', 'L', 'ON'], 4], []), ('regression: bracket class filter', ['}(][(]}()(}', ['ON', 'R', 'ON', 'ON', 'ON', 'L', 'ON', 'ON', 'ON', 'R', 'R'], 3], [[7, 8]]), ('regression: bracket class filter', [']]({}', ['ON', 'ON', 'ON', 'R', 'ON'], 4], []), ('regression: bracket class filter', ['{{)(([))[', ['ON', 'ON', 'L', 'ON', 'R', 'ON', 'ON', 'ON', 'R'], 4], [[3, 6]]), ('stack overflow stops', ['((()))', ['ON', 'ON', 'ON', 'ON', 'ON', 'ON'], 2], []), ('mismatched inner bracket', ['([)]', ['ON', 'ON', 'ON', 'ON'], 4], [[0, 2]]), ('control layout', [']()({)a(]a', ['R', 'ON', 'ON', 'ON', 'ON', 'ON', 'R', 'ON', 'ON', 'L'], 3], [[1, 2], [3, 5]]), ('control layout', ['{{)}()[]}', ['ON', 'ON', 'ON', 'ON', 'ON', 'ON', 'ON', 'ON', 'L'], 3], [[1, 3], [4, 5], [6, 7]])], [('regression: bracket class filter', ['((}}aa]()(()a', ['L', 'ON', 'ON', 'ON', 'R', 'L', 'ON', 'ON', 'R', 'ON', 'ON', 'ON', 'L'], 2], []), ('regression: bracket class filter', ['(aa]a])([[(]{a', ['ON', 'R', 'L', 'ON', 'L', 'ON', 'R', 'ON', 'ON', 'ON', 'ON', 'ON', 'ON', 'R'], 2], []), ('regression: bracket class filter', [')((({}}(]', ['L', 'ON', 'ON', 'L', 'ON', 'R', 'ON', 'ON', 'ON'], 3], [[4, 6]]), ('regression: bracket class filter', ['a(){', ['R', 'R', 'ON', 'ON'], 4], []), ('stack overflow stops', ['((()))', ['ON', 'ON', 'ON', 'ON', 'ON', 'ON'], 2], []), ('mismatched inner bracket', ['([)]', ['ON', 'ON', 'ON', 'ON'], 4], [[0, 2]]), ('control layout', [')]])([', ['R', 'ON', 'ON', 'ON', 'ON', 'ON'], 2], []), ('control layout', ['}}]', ['ON', 'ON', 'ON'], 4], [])], [('regression: bracket class filter', ['a[()}a]aa', ['R', 'ON', 'R', 'ON', 'ON', 'R', 'L', 'R', 'L'], 3], []), ('regression: bracket class filter', ['{{({()}]}', ['L', 'ON', 'ON', 'ON', 'R', 'ON', 'ON', 'ON', 'ON'], 4], [[1, 6], [2, 5]]), ('regression: bracket class filter', ['{)[}[(((]{(]{', ['ON', 'ON', 'ON', 'R', 'ON', 'ON', 'ON', 'L', 'ON', 'ON', 'ON', 'ON', 'ON'], 2], []), ('regression: bracket class filter', ['{{)(([))[', ['ON', 'ON', 'L', 'ON', 'R', 'ON', 'ON', 'ON', 'R'], 4], [[3, 6]]), ('mismatched inner bracket', ['([)]', ['ON', 'ON', 'ON', 'ON'], 4], [[0, 2]]), ('stack overflow stops', ['((()))', ['ON', 'ON', 'ON', 'ON', 'ON', 'ON'], 2], []), ('control layout', ['[[]', ['ON', 'ON', 'ON'], 3], [[1, 2]]), ('control layout', ['a]]{)a((](a', ['R', 'ON', 'R', 'ON', 'ON', 'L', 'ON', 'ON', 'ON', 'ON', 'L'], 2], [])], [('regression: bracket class filter', ['[]a}}[](a](((', ['ON', 'R', 'R', 'ON', 'R', 'ON', 'ON', 'ON', 'L', 'R', 'L', 'ON', 'R'], 1], []), ('regression: bracket class filter', ['((}}aa]()(()a', ['L', 'ON', 'ON', 'ON', 'R', 'L', 'ON', 'ON', 'R', 'ON', 'ON', 'ON', 'L'], 2], []), ('regression: bracket class filter', ['][](((({})a()', ['ON', 'R', 'ON', 'ON', 'ON', 'L', 'ON', 'ON', 'ON', 'ON', 'R', 'ON', 'ON'], 2], []), ('overridden bracket ignored', ['(a)', ['R', 'L', 'ON'], 4], []), ('stack overflow stops', ['((()))', ['ON', 'ON', 'ON', 'ON', 'ON', 'ON'], 2], []), ('mismatched inner bracket', ['([)]', ['ON', 'ON', 'ON', 'ON'], 4], [[0, 2]]), ('control layout', ['{}}a{([(([{', ['ON', 'ON', 'ON', 'L', 'ON', 'L', 'ON', 'L', 'ON', 'ON', 'ON'], 2], [[0, 1]]), ('control layout', ['}{', ['ON', 'ON'], 3], [])], [('regression: bracket class filter', ['}}}{(]}((', ['R', 'ON', 'ON', 'ON', 'ON', 'ON', 'R', 'ON', 'ON'], 2], []), ('regression: bracket class filter', ['([(]}}))(}a(', ['L', 'R', 'ON', 'ON', 'ON', 'ON', 'ON', 'ON', 'ON', 'ON', 'R', 'ON'], 3], [[2, 6]]), ('regression: bracket class filter', ['}a()[a(({]', ['ON', 'L', 'R', 'ON', 'R', 'L', 'ON', 'ON', 'ON', 'L'], 3], []), ('regression: bracket class filter', ['[((({a}', ['ON', 'R', 'ON', 'ON', 'ON', 'L', 'ON'], 4], [[4, 6]]), ('overridden bracket ignored', ['(a)', ['R', 'L', 'ON'], 4], []), ('stack overflow stops', ['((()))', ['ON', 'ON', 'ON', 'ON', 'ON', 'ON'], 2], []), ('control layout', ['}{', ['ON', 'ON'], 3], []), ('control layout', ['((][{]a{{)}', ['ON', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'R', 'L', 'ON', 'R'], 4], [[1, 9], [3, 5]])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Brackets forced to R by an override are still paired.

Input [text, classes, stack limit]. Only characters of class ON take part. Openers ( [ { are pushed; on overflow of the stack limit stop and keep pairs found so far. A closer searches the stack from the top for its opener; if found it pairs and discards that entry and everything above; otherwise it is ignored. Return pairs sorted by opener.

split: open-access