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

N = 1
observations = []
def solve(x):
    classes, levels, para = x
    out = list(levels)
    n = len(classes)
    RESETTABLE = ('WS', 'FSI', 'LRI', 'RLI', 'PDI')
    j = n - 1
    while j >= 0 and classes[j] in RESETTABLE:
        out[j] = para
        j -= 1
    for i, c in enumerate(classes):
        if c in ('S', 'B'):
            out[i] = para
            k = i - 1
            if k >= 0 and classes[k] in RESETTABLE:
                out[k] = para
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: whitespace before separator', [['FSI', 'RLI', 'B', 'R', 'ON', 'RLI', 'LRI', 'ON', 'WS'], [2, 2, 2, 2, 2, 1, 2, 0, 0], 1], [1, 1, 1, 2, 2, 1, 2, 0, 1]), ('regression: whitespace before separator', [['WS', 'WS', 'WS', 'S', 'WS'], [1, 1, 1, 1, 2], 0], [0, 0, 0, 0, 0]), ('partial-repair probe', [['PDI', 'S', 'ON', 'R'], [3, 3, 1, 1], 1], [1, 1, 1, 1]), ('partial-repair probe', [['WS', 'S', 'FSI', 'FSI', 'EN', 'ON'], [1, 1, 1, 1, 1, 1], 0], [0, 0, 1, 1, 1, 1]), ('all whitespace line', [['WS', 'WS'], [1, 1], 0], [0, 0]), ('trailing isolate and space', [['R', 'R', 'PDI', 'WS'], [1, 1, 1, 1], 0], [1, 1, 0, 0]), ('control layout', [['L', 'WS', 'L', 'WS', 'WS', 'ON', 'S', 'WS', 'WS'], [2, 2, 2, 1, 1, 1, 1, 1, 1], 0], [2, 2, 2, 1, 1, 1, 0, 0, 0]), ('control layout', [['ON', 'WS', 'ON'], [1, 1, 1], 0], [1, 1, 1])], [('regression: whitespace before separator', [['L', 'B', 'RLI', 'WS', 'B', 'R', 'WS', 'RLI', 'L'], [1, 1, 1, 1, 3, 3, 3, 1, 2], 0], [1, 0, 0, 0, 0, 3, 3, 1, 2]), ('regression: whitespace before separator', [['WS', 'WS', 'RLI', 'S', 'WS', 'WS', 'WS', 'PDI', 'LRI', 'ON'], [4, 4, 4, 3, 3, 4, 4, 4, 4, 4], 0], [0, 0, 0, 0, 3, 4, 4, 4, 4, 4]), ('regression: whitespace before separator', [['PDI', 'WS', 'LRI', 'B'], [0, 1, 1, 1], 1], [1, 1, 1, 1]), ('regression: whitespace before separator', [['FSI', 'LRI', 'FSI', 'WS', 'B', 'RLI', 'WS', 'WS'], [1, 1, 3, 3, 2, 2, 2, 2], 0], [0, 0, 0, 0, 0, 0, 0, 0]), ('all whitespace line', [['WS', 'WS'], [1, 1], 0], [0, 0]), ('space before tab', [['R', 'WS', 'S', 'R'], [1, 1, 1, 1], 0], [1, 0, 0, 1]), ('control layout', [['FSI'], [1], 1], [1]), ('control layout', [['EN', 'L'], [2, 2], 0], [2, 2])], [('regression: whitespace before separator', [['LRI', 'L', 'FSI', 'R', 'WS', 'FSI', 'S', 'R', 'WS'], [1, 1, 2, 2, 2, 0, 0, 0, 0], 0], [1, 1, 2, 2, 0, 0, 0, 0, 0]), ('regression: whitespace before separator', [['S', 'WS', 'WS', 'FSI', 'B', 'ON', 'S', 'R'], [1, 1, 1, 1, 1, 1, 1, 1], 0], [0, 0, 0, 0, 0, 1, 0, 1]), ('partial-repair probe', [['PDI', 'S', 'ON', 'R'], [3, 3, 1, 1], 1], [1, 1, 1, 1]), ('partial-repair probe', [['WS', 'S'], [3, 3], 0], [0, 0]), ('trailing isolate and space', [['R', 'R', 'PDI', 'WS'], [1, 1, 1, 1], 0], [1, 1, 0, 0]), ('all whitespace line', [['WS', 'WS'], [1, 1], 0], [0, 0]), ('control layout', [['FSI'], [1], 1], [1]), ('control layout', [['ON', 'B', 'WS', 'LRI', 'R'], [1, 2, 2, 2, 2], 0], [1, 0, 2, 2, 2])], [('regression: whitespace before separator', [['FSI', 'LRI', 'FSI', 'WS', 'B', 'RLI', 'WS', 'WS'], [1, 1, 3, 3, 2, 2, 2, 2], 0], [0, 0, 0, 0, 0, 0, 0, 0]), ('regression: whitespace before separator', [['ON', 'R', 'PDI', 'B', 'WS', 'RLI', 'FSI', 'B', 'WS'], [0, 0, 0, 0, 1, 1, 1, 3, 3], 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]), ('regression: whitespace before separator', [['PDI', 'WS', 'LRI', 'B'], [0, 1, 1, 1], 1], [1, 1, 1, 1]), ('regression: whitespace before separator', [['WS', 'WS', 'S', 'L', 'R', 'R', 'R'], [2, 2, 2, 2, 2, 0, 0], 0], [0, 0, 0, 2, 2, 0, 0]), ('all whitespace line', [['WS', 'WS'], [1, 1], 0], [0, 0]), ('space before tab', [['R', 'WS', 'S', 'R'], [1, 1, 1, 1], 0], [1, 0, 0, 1]), ('control layout', [['FSI', 'R', 'S', 'RLI', 'S', 'R', 'PDI', 'ON', 'LRI', 'L', 'WS'], [1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1], 1], [1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1]), ('control layout', [['L', 'L', 'RLI', 'PDI'], [1, 1, 2, 1], 1], [1, 1, 1, 1])], [('regression: whitespace before separator', [['EN', 'LRI', 'LRI', 'S', 'B', 'FSI', 'R', 'ON', 'PDI', 'B'], [2, 2, 2, 2, 2, 2, 2, 2, 2, 3], 1], [2, 1, 1, 1, 1, 2, 2, 2, 1, 1]), ('regression: whitespace before separator', [['ON', 'S', 'B', 'WS', 'WS', 'FSI', 'S', 'R', 'S', 'L', 'PDI'], [4, 4, 4, 4, 3, 3, 2, 1, 1, 1, 1], 0], [4, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0]), ('partial-repair probe', [['WS', 'S', 'L', 'R', 'PDI', 'R', 'B', 'WS', 'RLI', 'LRI'], [0, 2, 2, 2, 2, 3, 3, 0, 0, 0], 1], [1, 1, 2, 2, 2, 3, 1, 1, 1, 1]), ('regression: whitespace before separator', [['WS', 'WS', 'RLI', 'S', 'WS', 'WS', 'WS', 'PDI', 'LRI', 'ON'], [4, 4, 4, 3, 3, 4, 4, 4, 4, 4], 0], [0, 0, 0, 0, 3, 4, 4, 4, 4, 4]), ('space before tab', [['R', 'WS', 'S', 'R'], [1, 1, 1, 1], 0], [1, 0, 0, 1]), ('trailing isolate and space', [['R', 'R', 'PDI', 'WS'], [1, 1, 1, 1], 0], [1, 1, 0, 0]), ('control layout', [['RLI', 'L', 'PDI', 'WS', 'L'], [4, 4, 4, 1, 4], 0], [4, 4, 4, 1, 4]), ('control layout', [['EN', 'WS'], [1, 1], 1], [1, 1])]]
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, levels, para = x
    out = list(levels)
    n = len(classes)
    RESETTABLE = ('WS', 'FSI', 'LRI', 'RLI', 'PDI')
    j = n - 1
    while j >= 0 and classes[j] in RESETTABLE:
        out[j] = para
        j -= 1
    for i, c in enumerate(classes):
        if c in ('S', 'B'):
            out[i] = para
            k = i - 1
            while k > 0 and classes[k] in RESETTABLE:
                out[k] = para
                k -= 1
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: whitespace before separator', [['FSI', 'RLI', 'B', 'R', 'ON', 'RLI', 'LRI', 'ON', 'WS'], [2, 2, 2, 2, 2, 1, 2, 0, 0], 1], [1, 1, 1, 2, 2, 1, 2, 0, 1]), ('regression: whitespace before separator', [['WS', 'WS', 'WS', 'S', 'WS'], [1, 1, 1, 1, 2], 0], [0, 0, 0, 0, 0]), ('partial-repair probe', [['PDI', 'S', 'ON', 'R'], [3, 3, 1, 1], 1], [1, 1, 1, 1]), ('partial-repair probe', [['WS', 'S', 'FSI', 'FSI', 'EN', 'ON'], [1, 1, 1, 1, 1, 1], 0], [0, 0, 1, 1, 1, 1]), ('all whitespace line', [['WS', 'WS'], [1, 1], 0], [0, 0]), ('trailing isolate and space', [['R', 'R', 'PDI', 'WS'], [1, 1, 1, 1], 0], [1, 1, 0, 0]), ('control layout', [['L', 'WS', 'L', 'WS', 'WS', 'ON', 'S', 'WS', 'WS'], [2, 2, 2, 1, 1, 1, 1, 1, 1], 0], [2, 2, 2, 1, 1, 1, 0, 0, 0]), ('control layout', [['ON', 'WS', 'ON'], [1, 1, 1], 0], [1, 1, 1])], [('regression: whitespace before separator', [['L', 'B', 'RLI', 'WS', 'B', 'R', 'WS', 'RLI', 'L'], [1, 1, 1, 1, 3, 3, 3, 1, 2], 0], [1, 0, 0, 0, 0, 3, 3, 1, 2]), ('regression: whitespace before separator', [['WS', 'WS', 'RLI', 'S', 'WS', 'WS', 'WS', 'PDI', 'LRI', 'ON'], [4, 4, 4, 3, 3, 4, 4, 4, 4, 4], 0], [0, 0, 0, 0, 3, 4, 4, 4, 4, 4]), ('regression: whitespace before separator', [['PDI', 'WS', 'LRI', 'B'], [0, 1, 1, 1], 1], [1, 1, 1, 1]), ('regression: whitespace before separator', [['FSI', 'LRI', 'FSI', 'WS', 'B', 'RLI', 'WS', 'WS'], [1, 1, 3, 3, 2, 2, 2, 2], 0], [0, 0, 0, 0, 0, 0, 0, 0]), ('all whitespace line', [['WS', 'WS'], [1, 1], 0], [0, 0]), ('space before tab', [['R', 'WS', 'S', 'R'], [1, 1, 1, 1], 0], [1, 0, 0, 1]), ('control layout', [['FSI'], [1], 1], [1]), ('control layout', [['EN', 'L'], [2, 2], 0], [2, 2])], [('regression: whitespace before separator', [['LRI', 'L', 'FSI', 'R', 'WS', 'FSI', 'S', 'R', 'WS'], [1, 1, 2, 2, 2, 0, 0, 0, 0], 0], [1, 1, 2, 2, 0, 0, 0, 0, 0]), ('regression: whitespace before separator', [['S', 'WS', 'WS', 'FSI', 'B', 'ON', 'S', 'R'], [1, 1, 1, 1, 1, 1, 1, 1], 0], [0, 0, 0, 0, 0, 1, 0, 1]), ('partial-repair probe', [['PDI', 'S', 'ON', 'R'], [3, 3, 1, 1], 1], [1, 1, 1, 1]), ('partial-repair probe', [['WS', 'S'], [3, 3], 0], [0, 0]), ('trailing isolate and space', [['R', 'R', 'PDI', 'WS'], [1, 1, 1, 1], 0], [1, 1, 0, 0]), ('all whitespace line', [['WS', 'WS'], [1, 1], 0], [0, 0]), ('control layout', [['FSI'], [1], 1], [1]), ('control layout', [['ON', 'B', 'WS', 'LRI', 'R'], [1, 2, 2, 2, 2], 0], [1, 0, 2, 2, 2])], [('regression: whitespace before separator', [['FSI', 'LRI', 'FSI', 'WS', 'B', 'RLI', 'WS', 'WS'], [1, 1, 3, 3, 2, 2, 2, 2], 0], [0, 0, 0, 0, 0, 0, 0, 0]), ('regression: whitespace before separator', [['ON', 'R', 'PDI', 'B', 'WS', 'RLI', 'FSI', 'B', 'WS'], [0, 0, 0, 0, 1, 1, 1, 3, 3], 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]), ('regression: whitespace before separator', [['PDI', 'WS', 'LRI', 'B'], [0, 1, 1, 1], 1], [1, 1, 1, 1]), ('regression: whitespace before separator', [['WS', 'WS', 'S', 'L', 'R', 'R', 'R'], [2, 2, 2, 2, 2, 0, 0], 0], [0, 0, 0, 2, 2, 0, 0]), ('all whitespace line', [['WS', 'WS'], [1, 1], 0], [0, 0]), ('space before tab', [['R', 'WS', 'S', 'R'], [1, 1, 1, 1], 0], [1, 0, 0, 1]), ('control layout', [['FSI', 'R', 'S', 'RLI', 'S', 'R', 'PDI', 'ON', 'LRI', 'L', 'WS'], [1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1], 1], [1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1]), ('control layout', [['L', 'L', 'RLI', 'PDI'], [1, 1, 2, 1], 1], [1, 1, 1, 1])], [('regression: whitespace before separator', [['EN', 'LRI', 'LRI', 'S', 'B', 'FSI', 'R', 'ON', 'PDI', 'B'], [2, 2, 2, 2, 2, 2, 2, 2, 2, 3], 1], [2, 1, 1, 1, 1, 2, 2, 2, 1, 1]), ('regression: whitespace before separator', [['ON', 'S', 'B', 'WS', 'WS', 'FSI', 'S', 'R', 'S', 'L', 'PDI'], [4, 4, 4, 4, 3, 3, 2, 1, 1, 1, 1], 0], [4, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0]), ('partial-repair probe', [['WS', 'S', 'L', 'R', 'PDI', 'R', 'B', 'WS', 'RLI', 'LRI'], [0, 2, 2, 2, 2, 3, 3, 0, 0, 0], 1], [1, 1, 2, 2, 2, 3, 1, 1, 1, 1]), ('regression: whitespace before separator', [['WS', 'WS', 'RLI', 'S', 'WS', 'WS', 'WS', 'PDI', 'LRI', 'ON'], [4, 4, 4, 3, 3, 4, 4, 4, 4, 4], 0], [0, 0, 0, 0, 3, 4, 4, 4, 4, 4]), ('space before tab', [['R', 'WS', 'S', 'R'], [1, 1, 1, 1], 0], [1, 0, 0, 1]), ('trailing isolate and space', [['R', 'R', 'PDI', 'WS'], [1, 1, 1, 1], 0], [1, 1, 0, 0]), ('control layout', [['RLI', 'L', 'PDI', 'WS', 'L'], [4, 4, 4, 1, 4], 0], [4, 4, 4, 1, 4]), ('control layout', [['EN', 'WS'], [1, 1], 1], [1, 1])]]
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:
Only one space before a tab is reset.

Input [original classes, resolved levels, paragraph level]. Reset to the paragraph level: every S and B; any run of WS and isolate formatting characters (FSI LRI RLI PDI) immediately before an S or B; and such a run at the end of the line. Return levels.

split: open-access


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

N = 1
observations = []
def solve(x):
    classes, levels, para = x
    out = list(levels)
    n = len(classes)
    RESETTABLE = ('WS', 'FSI', 'LRI', 'RLI', 'PDI')
    j = n - 1
    while j >= 0 and classes[j] in RESETTABLE:
        out[j] = min(levels)
        j -= 1
    for i, c in enumerate(classes):
        if c in ('S', 'B'):
            out[i] = para
            k = i - 1
            while k >= 0 and classes[k] in RESETTABLE:
                out[k] = para
                k -= 1
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('trailing isolate and space', [['R', 'R', 'PDI', 'WS'], [1, 1, 1, 1], 0], [1, 1, 0, 0]), ('regression: reset target level', [['ON', 'WS'], [2, 2], 1], [2, 1]), ('partial-repair probe', [['R', 'R', 'PDI', 'R', 'PDI'], [2, 1, 1, 1, 1], 1], [2, 1, 1, 1, 1]), ('regression: reset target level', [['L', 'R', 'WS'], [2, 2, 2], 1], [2, 2, 1]), ('all whitespace line', [['WS', 'WS'], [1, 1], 0], [0, 0]), ('space before tab', [['R', 'WS', 'S', 'R'], [1, 1, 1, 1], 0], [1, 0, 0, 1]), ('control layout', [['RLI', 'ON'], [2, 2], 1], [2, 2]), ('control layout', [['PDI', 'S', 'WS', 'R'], [4, 4, 4, 4], 1], [1, 1, 4, 4])], [('regression: reset target level', [['R', 'L', 'RLI', 'L', 'LRI', 'B', 'L', 'ON', 'PDI'], [1, 2, 2, 2, 2, 0, 0, 0, 1], 1], [1, 2, 2, 2, 1, 1, 0, 0, 1]), ('regression: reset target level', [['WS', 'R', 'L', 'WS', 'R', 'EN', 'FSI'], [3, 3, 2, 2, 2, 2, 3], 1], [3, 3, 2, 2, 2, 2, 1]), ('regression: reset target level', [['LRI'], [2], 0], [0]), ('regression: reset target level', [['WS', 'L', 'FSI', 'R', 'ON', 'R', 'WS'], [3, 3, 0, 0, 1, 3, 3], 1], [3, 3, 0, 0, 1, 3, 1]), ('all whitespace line', [['WS', 'WS'], [1, 1], 0], [0, 0]), ('space before tab', [['R', 'WS', 'S', 'R'], [1, 1, 1, 1], 0], [1, 0, 0, 1]), ('control layout', [['WS', 'ON', 'L', 'WS', 'WS', 'ON', 'L', 'LRI', 'WS', 'EN', 'WS', 'L'], [4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3], 1], [4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3]), ('control layout', [['ON', 'WS', 'S', 'L', 'R', 'ON'], [1, 1, 1, 0, 1, 1], 1], [1, 1, 1, 0, 1, 1])], [('regression: reset target level', [['WS', 'L', 'R', 'WS', 'WS', 'L', 'WS', 'RLI'], [3, 3, 3, 3, 2, 2, 2, 0], 1], [3, 3, 3, 3, 2, 2, 1, 1]), ('regression: reset target level', [['WS'], [0], 1], [1]), ('regression: reset target level', [['ON', 'PDI', 'FSI', 'L', 'B', 'PDI', 'S', 'L', 'WS', 'L', 'RLI', 'WS'], [3, 3, 3, 3, 2, 2, 2, 2, 0, 0, 0, 0], 1], [3, 3, 3, 3, 1, 1, 1, 2, 0, 0, 1, 1]), ('partial-repair probe', [['FSI', 'R', 'WS', 'ON', 'B', 'LRI'], [2, 2, 2, 0, 0, 3], 0], [2, 2, 2, 0, 0, 0]), ('trailing isolate and space', [['R', 'R', 'PDI', 'WS'], [1, 1, 1, 1], 0], [1, 1, 0, 0]), ('all whitespace line', [['WS', 'WS'], [1, 1], 0], [0, 0]), ('control layout', [['WS', 'R', 'WS', 'B', 'FSI', 'WS'], [1, 1, 1, 1, 1, 1], 1], [1, 1, 1, 1, 1, 1]), ('control layout', [['R', 'PDI', 'L', 'LRI', 'ON'], [2, 2, 2, 2, 2], 0], [2, 2, 2, 2, 2])], [('regression: reset target level', [['RLI', 'WS', 'WS'], [2, 2, 3], 1], [1, 1, 1]), ('regression: reset target level', [['L', 'B', 'WS', 'PDI', 'L', 'B', 'L', 'L', 'RLI'], [2, 2, 2, 2, 3, 3, 3, 2, 2], 1], [2, 1, 2, 2, 3, 1, 3, 2, 1]), ('regression: reset target level', [['B', 'L', 'R', 'L', 'PDI', 'ON', 'L', 'S', 'WS', 'ON', 'WS'], [4, 4, 4, 2, 2, 2, 2, 4, 4, 4, 3], 0], [0, 4, 4, 2, 2, 2, 2, 0, 4, 4, 0]), ('regression: reset target level', [['R', 'EN', 'PDI', 'S', 'WS'], [0, 0, 0, 0, 2], 1], [0, 0, 1, 1, 1]), ('trailing isolate and space', [['R', 'R', 'PDI', 'WS'], [1, 1, 1, 1], 0], [1, 1, 0, 0]), ('all whitespace line', [['WS', 'WS'], [1, 1], 0], [0, 0]), ('control layout', [['RLI', 'L', 'ON', 'WS', 'WS', 'FSI', 'ON', 'WS', 'L'], [2, 3, 3, 3, 3, 0, 0, 2, 2], 1], [2, 3, 3, 3, 3, 0, 0, 2, 2]), ('control layout', [['WS', 'FSI', 'S', 'B', 'R', 'L'], [1, 1, 1, 1, 4, 1], 1], [1, 1, 1, 1, 4, 1])], [('regression: reset target level', [['R', 'EN', 'PDI', 'S', 'WS'], [0, 0, 0, 0, 2], 1], [0, 0, 1, 1, 1]), ('regression: reset target level', [['L', 'L', 'WS', 'PDI'], [2, 2, 2, 2], 0], [2, 2, 0, 0]), ('partial-repair probe', [['RLI', 'PDI', 'WS', 'S', 'L', 'R', 'R', 'R', 'WS', 'LRI'], [2, 2, 2, 2, 2, 2, 2, 1, 1, 1], 1], [1, 1, 1, 1, 2, 2, 2, 1, 1, 1]), ('regression: reset target level', [['S', 'R', 'ON', 'LRI', 'WS', 'R', 'WS', 'LRI', 'WS', 'R', 'WS'], [0, 0, 0, 0, 3, 3, 0, 3, 3, 3, 3], 1], [1, 0, 0, 0, 3, 3, 0, 3, 3, 3, 1]), ('trailing isolate and space', [['R', 'R', 'PDI', 'WS'], [1, 1, 1, 1], 0], [1, 1, 0, 0]), ('space before tab', [['R', 'WS', 'S', 'R'], [1, 1, 1, 1], 0], [1, 0, 0, 1]), ('control layout', [['RLI', 'PDI', 'FSI', 'PDI', 'EN', 'L', 'WS', 'WS', 'ON'], [2, 2, 2, 2, 2, 2, 2, 1, 4], 1], [2, 2, 2, 2, 2, 2, 2, 1, 4]), ('control layout', [['R', 'WS', 'R', 'EN', 'R'], [4, 4, 2, 2, 2], 0], [4, 4, 2, 2, 2])]]
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, levels, para = x
    out = list(levels)
    n = len(classes)
    RESETTABLE = ('WS', 'FSI', 'LRI', 'RLI', 'PDI')
    j = n - 1
    while j >= 0 and classes[j] in RESETTABLE:
        out[j] = levels[0]
        j -= 1
    for i, c in enumerate(classes):
        if c in ('S', 'B'):
            out[i] = para
            k = i - 1
            while k >= 0 and classes[k] in RESETTABLE:
                out[k] = para
                k -= 1
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('trailing isolate and space', [['R', 'R', 'PDI', 'WS'], [1, 1, 1, 1], 0], [1, 1, 0, 0]), ('regression: reset target level', [['ON', 'WS'], [2, 2], 1], [2, 1]), ('partial-repair probe', [['R', 'R', 'PDI', 'R', 'PDI'], [2, 1, 1, 1, 1], 1], [2, 1, 1, 1, 1]), ('regression: reset target level', [['L', 'R', 'WS'], [2, 2, 2], 1], [2, 2, 1]), ('all whitespace line', [['WS', 'WS'], [1, 1], 0], [0, 0]), ('space before tab', [['R', 'WS', 'S', 'R'], [1, 1, 1, 1], 0], [1, 0, 0, 1]), ('control layout', [['RLI', 'ON'], [2, 2], 1], [2, 2]), ('control layout', [['PDI', 'S', 'WS', 'R'], [4, 4, 4, 4], 1], [1, 1, 4, 4])], [('regression: reset target level', [['R', 'L', 'RLI', 'L', 'LRI', 'B', 'L', 'ON', 'PDI'], [1, 2, 2, 2, 2, 0, 0, 0, 1], 1], [1, 2, 2, 2, 1, 1, 0, 0, 1]), ('regression: reset target level', [['WS', 'R', 'L', 'WS', 'R', 'EN', 'FSI'], [3, 3, 2, 2, 2, 2, 3], 1], [3, 3, 2, 2, 2, 2, 1]), ('regression: reset target level', [['LRI'], [2], 0], [0]), ('regression: reset target level', [['WS', 'L', 'FSI', 'R', 'ON', 'R', 'WS'], [3, 3, 0, 0, 1, 3, 3], 1], [3, 3, 0, 0, 1, 3, 1]), ('all whitespace line', [['WS', 'WS'], [1, 1], 0], [0, 0]), ('space before tab', [['R', 'WS', 'S', 'R'], [1, 1, 1, 1], 0], [1, 0, 0, 1]), ('control layout', [['WS', 'ON', 'L', 'WS', 'WS', 'ON', 'L', 'LRI', 'WS', 'EN', 'WS', 'L'], [4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3], 1], [4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3]), ('control layout', [['ON', 'WS', 'S', 'L', 'R', 'ON'], [1, 1, 1, 0, 1, 1], 1], [1, 1, 1, 0, 1, 1])], [('regression: reset target level', [['WS', 'L', 'R', 'WS', 'WS', 'L', 'WS', 'RLI'], [3, 3, 3, 3, 2, 2, 2, 0], 1], [3, 3, 3, 3, 2, 2, 1, 1]), ('regression: reset target level', [['WS'], [0], 1], [1]), ('regression: reset target level', [['ON', 'PDI', 'FSI', 'L', 'B', 'PDI', 'S', 'L', 'WS', 'L', 'RLI', 'WS'], [3, 3, 3, 3, 2, 2, 2, 2, 0, 0, 0, 0], 1], [3, 3, 3, 3, 1, 1, 1, 2, 0, 0, 1, 1]), ('partial-repair probe', [['FSI', 'R', 'WS', 'ON', 'B', 'LRI'], [2, 2, 2, 0, 0, 3], 0], [2, 2, 2, 0, 0, 0]), ('trailing isolate and space', [['R', 'R', 'PDI', 'WS'], [1, 1, 1, 1], 0], [1, 1, 0, 0]), ('all whitespace line', [['WS', 'WS'], [1, 1], 0], [0, 0]), ('control layout', [['WS', 'R', 'WS', 'B', 'FSI', 'WS'], [1, 1, 1, 1, 1, 1], 1], [1, 1, 1, 1, 1, 1]), ('control layout', [['R', 'PDI', 'L', 'LRI', 'ON'], [2, 2, 2, 2, 2], 0], [2, 2, 2, 2, 2])], [('regression: reset target level', [['RLI', 'WS', 'WS'], [2, 2, 3], 1], [1, 1, 1]), ('regression: reset target level', [['L', 'B', 'WS', 'PDI', 'L', 'B', 'L', 'L', 'RLI'], [2, 2, 2, 2, 3, 3, 3, 2, 2], 1], [2, 1, 2, 2, 3, 1, 3, 2, 1]), ('regression: reset target level', [['B', 'L', 'R', 'L', 'PDI', 'ON', 'L', 'S', 'WS', 'ON', 'WS'], [4, 4, 4, 2, 2, 2, 2, 4, 4, 4, 3], 0], [0, 4, 4, 2, 2, 2, 2, 0, 4, 4, 0]), ('regression: reset target level', [['R', 'EN', 'PDI', 'S', 'WS'], [0, 0, 0, 0, 2], 1], [0, 0, 1, 1, 1]), ('trailing isolate and space', [['R', 'R', 'PDI', 'WS'], [1, 1, 1, 1], 0], [1, 1, 0, 0]), ('all whitespace line', [['WS', 'WS'], [1, 1], 0], [0, 0]), ('control layout', [['RLI', 'L', 'ON', 'WS', 'WS', 'FSI', 'ON', 'WS', 'L'], [2, 3, 3, 3, 3, 0, 0, 2, 2], 1], [2, 3, 3, 3, 3, 0, 0, 2, 2]), ('control layout', [['WS', 'FSI', 'S', 'B', 'R', 'L'], [1, 1, 1, 1, 4, 1], 1], [1, 1, 1, 1, 4, 1])], [('regression: reset target level', [['R', 'EN', 'PDI', 'S', 'WS'], [0, 0, 0, 0, 2], 1], [0, 0, 1, 1, 1]), ('regression: reset target level', [['L', 'L', 'WS', 'PDI'], [2, 2, 2, 2], 0], [2, 2, 0, 0]), ('partial-repair probe', [['RLI', 'PDI', 'WS', 'S', 'L', 'R', 'R', 'R', 'WS', 'LRI'], [2, 2, 2, 2, 2, 2, 2, 1, 1, 1], 1], [1, 1, 1, 1, 2, 2, 2, 1, 1, 1]), ('regression: reset target level', [['S', 'R', 'ON', 'LRI', 'WS', 'R', 'WS', 'LRI', 'WS', 'R', 'WS'], [0, 0, 0, 0, 3, 3, 0, 3, 3, 3, 3], 1], [1, 0, 0, 0, 3, 3, 0, 3, 3, 3, 1]), ('trailing isolate and space', [['R', 'R', 'PDI', 'WS'], [1, 1, 1, 1], 0], [1, 1, 0, 0]), ('space before tab', [['R', 'WS', 'S', 'R'], [1, 1, 1, 1], 0], [1, 0, 0, 1]), ('control layout', [['RLI', 'PDI', 'FSI', 'PDI', 'EN', 'L', 'WS', 'WS', 'ON'], [2, 2, 2, 2, 2, 2, 2, 1, 4], 1], [2, 2, 2, 2, 2, 2, 2, 1, 4]), ('control layout', [['R', 'WS', 'R', 'EN', 'R'], [4, 4, 2, 2, 2], 0], [4, 4, 2, 2, 2])]]
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:
Trailing whitespace is reset to the lowest level on the line.

Input [original classes, resolved levels, paragraph level]. Reset to the paragraph level: every S and B; any run of WS and isolate formatting characters (FSI LRI RLI PDI) immediately before an S or B; and such a run at the end of the line. Return levels.

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
            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 else c)
    return [levels, types]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('RLE from odd level', [['RLE', 'RLE', 'L'], 0, 6], [['x', 'x', 3], ['BN', 'BN', 'L']]), ('regression: next odd level', [['L', 'L', 'ON', 'PDF', 'RLE', 'L', 'RLO', 'R'], 0, 4], [[0, 0, 0, 'x', 'x', 1, 'x', 3], ['L', 'L', 'ON', 'BN', 'BN', 'L', 'BN', 'R']]), ('partial-repair probe', [['RLE', 'LRE', 'PDF', 'ON', 'R', 'RLO'], 0, 4], [['x', 'x', 'x', 1, 1, 'x'], ['BN', 'BN', 'BN', 'ON', 'R', 'BN']]), ('partial-repair probe', [['R', 'RLO', 'PDF', 'R', 'L', 'RLE', 'LRE', 'ON', 'R', 'RLE', 'ON', 'LRE', 'R'], 0, 4], [[0, 'x', 'x', 0, 0, 'x', 'x', 2, 2, 'x', 3, 'x', 4], ['R', 'BN', 'BN', 'R', 'L', 'BN', 'BN', 'ON', 'R', 'BN', 'ON', 'BN', 'R']]), ('LRE from odd level', [['LRE', 'R'], 1, 6], [['x', 2], ['BN', 'R']]), ('override on neutrals', [['RLO', 'ON', 'L', 'WS'], 0, 6], [['x', 1, 1, 1], ['BN', 'R', 'R', 'R']]), ('control layout', [['PDF', 'LRO', 'R', 'EN', 'LRE', 'L', 'L', 'L', 'RLE', 'R', 'L', 'LRO'], 1, 3], [['x', 'x', 2, 2, 'x', 2, 2, 2, 'x', 2, 2, 'x'], ['BN', 'BN', 'L', 'L', 'BN', 'L', 'L', 'L', 'BN', 'L', 'L', 'BN']]), ('control layout', [['R', 'LRO'], 0, 4], [[0, 'x'], ['R', 'BN']])], [('regression: next odd level', [['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: next odd level', [['WS', 'PDF', 'RLE', 'RLE', 'L'], 1, 5], [[1, 'x', 'x', 'x', 5], ['WS', 'BN', 'BN', 'BN', 'L']]), ('partial-repair probe', [['R', 'RLO', 'RLE', 'PDF', 'R', 'LRE', 'L', 'ON', 'R', 'ON', 'RLO'], 0, 3], [[0, 'x', 'x', 'x', 1, 'x', 2, 2, 2, 2, 'x'], ['R', 'BN', 'BN', 'BN', 'R', 'BN', 'L', 'ON', 'R', 'ON', 'BN']]), ('regression: next odd level', [['ON', 'L', 'EN', 'PDF', 'RLE', 'R', 'RLO', 'L', 'PDF'], 0, 5], [[0, 0, 0, 'x', 'x', 1, 'x', 3, 'x'], ['ON', 'L', 'EN', 'BN', 'BN', 'R', 'BN', 'R', 'BN']]), ('depth limit exactly reached', [['RLE', 'LRE', 'L', 'PDF', 'L'], 0, 2], [['x', 'x', 2, 'x', 1], ['BN', 'BN', 'L', 'BN', 'L']]), ('LRE from odd level', [['LRE', 'R'], 1, 6], [['x', 2], ['BN', 'R']]), ('control layout', [['EN', 'R'], 0, 5], [[0, 0], ['EN', 'R']]), ('control layout', [['L', 'R', 'ON', 'R', 'PDF', 'ON', 'ON'], 1, 4], [[1, 1, 1, 1, 'x', 1, 1], ['L', 'R', 'ON', 'R', 'BN', 'ON', 'ON']])], [('regression: next odd level', [['PDF', 'PDF', 'R', 'L', 'RLO', 'ON', 'R', 'ON'], 1, 2], [['x', 'x', 1, 1, 'x', 1, 1, 1], ['BN', 'BN', 'R', 'L', 'BN', 'ON', 'R', 'ON']]), ('regression: next odd level', [['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: next odd level', [['ON', 'L', 'PDF', 'RLO', 'R'], 1, 4], [[1, 1, 'x', 'x', 3], ['ON', 'L', 'BN', 'BN', 'R']]), ('partial-repair probe', [['WS', 'L', 'L', 'RLE', 'R', 'RLO'], 0, 5], [[0, 0, 0, 'x', 1, 'x'], ['WS', 'L', 'L', 'BN', 'R', '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', [['ON', 'ON', 'L', 'EN', 'WS'], 1, 4], [[1, 1, 1, 1, 1], ['ON', 'ON', 'L', 'EN', 'WS']]), ('control layout', [['L', 'R', 'WS', 'ON', 'RLE', 'LRE'], 0, 5], [[0, 0, 0, 0, 'x', 'x'], ['L', 'R', 'WS', 'ON', 'BN', 'BN']])], [('regression: next odd level', [['PDF', 'PDF', 'R', 'L', 'RLO', 'ON', 'R', 'ON'], 1, 2], [['x', 'x', 1, 1, 'x', 1, 1, 1], ['BN', 'BN', 'R', 'L', 'BN', 'ON', 'R', 'ON']]), ('regression: next odd level', [['RLE', 'RLO', 'EN', 'L', 'EN', 'PDF', 'L', 'LRE', 'EN', 'LRO', 'R', 'WS', 'LRE'], 1, 3], [['x', 'x', 3, 3, 3, 'x', 3, 'x', 3, 'x', 3, 3, 'x'], ['BN', 'BN', 'EN', 'L', 'EN', 'BN', 'L', 'BN', 'EN', 'BN', 'R', 'WS', 'BN']]), ('regression: next odd level', [['RLO', 'R'], 1, 3], [['x', 3], ['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']]), ('LRE from odd level', [['LRE', 'R'], 1, 6], [['x', 2], ['BN', 'R']]), ('override on neutrals', [['RLO', 'ON', 'L', 'WS'], 0, 6], [['x', 1, 1, 1], ['BN', 'R', 'R', 'R']]), ('control layout', [['EN', 'LRO', 'LRO', 'LRE', 'RLO', 'EN', 'PDF', 'RLE'], 0, 3], [[0, 'x', 'x', 'x', 'x', 2, 'x', 'x'], ['EN', 'BN', 'BN', 'BN', 'BN', 'L', 'BN', 'BN']]), ('control layout', [['ON', 'RLE', 'LRE', 'RLE', 'LRE', 'R', 'L', 'LRO', 'EN', 'PDF', 'L', 'L', 'LRE', 'PDF'], 0, 4], [[0, 'x', 'x', 'x', 'x', 4, 4, 'x', 4, 'x', 4, 4, 'x', 'x'], ['ON', 'BN', 'BN', 'BN', 'BN', 'R', 'L', 'BN', 'EN', 'BN', 'L', 'L', 'BN', 'BN']])], [('regression: next odd level', [['RLO', 'ON', 'EN', 'EN', 'ON', 'R'], 1, 2], [['x', 1, 1, 1, 1, 1], ['BN', 'ON', 'EN', 'EN', 'ON', 'R']]), ('regression: next odd level', [['RLE', 'RLO', 'EN', 'L', 'EN', 'PDF', 'L', 'LRE', 'EN', 'LRO', 'R', 'WS', 'LRE'], 1, 3], [['x', 'x', 3, 3, 3, 'x', 3, 'x', 3, 'x', 3, 3, 'x'], ['BN', 'BN', 'EN', 'L', 'EN', 'BN', 'L', 'BN', 'EN', 'BN', 'R', 'WS', 'BN']]), ('regression: next odd level', [['RLO', 'R'], 1, 3], [['x', 3], ['BN', 'R']]), ('regression: next odd level', [['L', 'L', 'RLO', 'RLO', 'L', 'R', 'RLE', 'RLE', 'R', 'R', 'L', 'LRE', 'EN'], 1, 6], [[1, 1, 'x', 'x', 5, 5, 'x', 'x', 5, 5, 5, 'x', 5], ['L', 'L', 'BN', 'BN', 'R', 'R', 'BN', 'BN', 'R', 'R', 'R', 'BN', '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', [['R', 'L', 'LRE', 'LRO', 'RLE'], 1, 3], [[1, 1, 'x', 'x', 'x'], ['R', 'L', 'BN', 'BN', 'BN']]), ('control layout', [['ON', 'L', 'LRO', 'RLO', 'PDF', 'PDF', 'R', 'R', 'ON', 'L', 'ON', 'L'], 1, 3], [[1, 1, 'x', 'x', 'x', 'x', 1, 1, 1, 1, 1, 1], ['ON', 'L', 'BN', 'BN', 'BN', 'BN', 'R', 'R', 'ON', 'L', 'ON', '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 == 1 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 else c)
    return [levels, types]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('RLE from odd level', [['RLE', 'RLE', 'L'], 0, 6], [['x', 'x', 3], ['BN', 'BN', 'L']]), ('regression: next odd level', [['L', 'L', 'ON', 'PDF', 'RLE', 'L', 'RLO', 'R'], 0, 4], [[0, 0, 0, 'x', 'x', 1, 'x', 3], ['L', 'L', 'ON', 'BN', 'BN', 'L', 'BN', 'R']]), ('partial-repair probe', [['RLE', 'LRE', 'PDF', 'ON', 'R', 'RLO'], 0, 4], [['x', 'x', 'x', 1, 1, 'x'], ['BN', 'BN', 'BN', 'ON', 'R', 'BN']]), ('partial-repair probe', [['R', 'RLO', 'PDF', 'R', 'L', 'RLE', 'LRE', 'ON', 'R', 'RLE', 'ON', 'LRE', 'R'], 0, 4], [[0, 'x', 'x', 0, 0, 'x', 'x', 2, 2, 'x', 3, 'x', 4], ['R', 'BN', 'BN', 'R', 'L', 'BN', 'BN', 'ON', 'R', 'BN', 'ON', 'BN', 'R']]), ('LRE from odd level', [['LRE', 'R'], 1, 6], [['x', 2], ['BN', 'R']]), ('override on neutrals', [['RLO', 'ON', 'L', 'WS'], 0, 6], [['x', 1, 1, 1], ['BN', 'R', 'R', 'R']]), ('control layout', [['PDF', 'LRO', 'R', 'EN', 'LRE', 'L', 'L', 'L', 'RLE', 'R', 'L', 'LRO'], 1, 3], [['x', 'x', 2, 2, 'x', 2, 2, 2, 'x', 2, 2, 'x'], ['BN', 'BN', 'L', 'L', 'BN', 'L', 'L', 'L', 'BN', 'L', 'L', 'BN']]), ('control layout', [['R', 'LRO'], 0, 4], [[0, 'x'], ['R', 'BN']])], [('regression: next odd level', [['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: next odd level', [['WS', 'PDF', 'RLE', 'RLE', 'L'], 1, 5], [[1, 'x', 'x', 'x', 5], ['WS', 'BN', 'BN', 'BN', 'L']]), ('partial-repair probe', [['R', 'RLO', 'RLE', 'PDF', 'R', 'LRE', 'L', 'ON', 'R', 'ON', 'RLO'], 0, 3], [[0, 'x', 'x', 'x', 1, 'x', 2, 2, 2, 2, 'x'], ['R', 'BN', 'BN', 'BN', 'R', 'BN', 'L', 'ON', 'R', 'ON', 'BN']]), ('regression: next odd level', [['ON', 'L', 'EN', 'PDF', 'RLE', 'R', 'RLO', 'L', 'PDF'], 0, 5], [[0, 0, 0, 'x', 'x', 1, 'x', 3, 'x'], ['ON', 'L', 'EN', 'BN', 'BN', 'R', 'BN', 'R', 'BN']]), ('depth limit exactly reached', [['RLE', 'LRE', 'L', 'PDF', 'L'], 0, 2], [['x', 'x', 2, 'x', 1], ['BN', 'BN', 'L', 'BN', 'L']]), ('LRE from odd level', [['LRE', 'R'], 1, 6], [['x', 2], ['BN', 'R']]), ('control layout', [['EN', 'R'], 0, 5], [[0, 0], ['EN', 'R']]), ('control layout', [['L', 'R', 'ON', 'R', 'PDF', 'ON', 'ON'], 1, 4], [[1, 1, 1, 1, 'x', 1, 1], ['L', 'R', 'ON', 'R', 'BN', 'ON', 'ON']])], [('regression: next odd level', [['PDF', 'PDF', 'R', 'L', 'RLO', 'ON', 'R', 'ON'], 1, 2], [['x', 'x', 1, 1, 'x', 1, 1, 1], ['BN', 'BN', 'R', 'L', 'BN', 'ON', 'R', 'ON']]), ('regression: next odd level', [['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: next odd level', [['ON', 'L', 'PDF', 'RLO', 'R'], 1, 4], [[1, 1, 'x', 'x', 3], ['ON', 'L', 'BN', 'BN', 'R']]), ('partial-repair probe', [['WS', 'L', 'L', 'RLE', 'R', 'RLO'], 0, 5], [[0, 0, 0, 'x', 1, 'x'], ['WS', 'L', 'L', 'BN', 'R', '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', [['ON', 'ON', 'L', 'EN', 'WS'], 1, 4], [[1, 1, 1, 1, 1], ['ON', 'ON', 'L', 'EN', 'WS']]), ('control layout', [['L', 'R', 'WS', 'ON', 'RLE', 'LRE'], 0, 5], [[0, 0, 0, 0, 'x', 'x'], ['L', 'R', 'WS', 'ON', 'BN', 'BN']])], [('regression: next odd level', [['PDF', 'PDF', 'R', 'L', 'RLO', 'ON', 'R', 'ON'], 1, 2], [['x', 'x', 1, 1, 'x', 1, 1, 1], ['BN', 'BN', 'R', 'L', 'BN', 'ON', 'R', 'ON']]), ('regression: next odd level', [['RLE', 'RLO', 'EN', 'L', 'EN', 'PDF', 'L', 'LRE', 'EN', 'LRO', 'R', 'WS', 'LRE'], 1, 3], [['x', 'x', 3, 3, 3, 'x', 3, 'x', 3, 'x', 3, 3, 'x'], ['BN', 'BN', 'EN', 'L', 'EN', 'BN', 'L', 'BN', 'EN', 'BN', 'R', 'WS', 'BN']]), ('regression: next odd level', [['RLO', 'R'], 1, 3], [['x', 3], ['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']]), ('LRE from odd level', [['LRE', 'R'], 1, 6], [['x', 2], ['BN', 'R']]), ('override on neutrals', [['RLO', 'ON', 'L', 'WS'], 0, 6], [['x', 1, 1, 1], ['BN', 'R', 'R', 'R']]), ('control layout', [['EN', 'LRO', 'LRO', 'LRE', 'RLO', 'EN', 'PDF', 'RLE'], 0, 3], [[0, 'x', 'x', 'x', 'x', 2, 'x', 'x'], ['EN', 'BN', 'BN', 'BN', 'BN', 'L', 'BN', 'BN']]), ('control layout', [['ON', 'RLE', 'LRE', 'RLE', 'LRE', 'R', 'L', 'LRO', 'EN', 'PDF', 'L', 'L', 'LRE', 'PDF'], 0, 4], [[0, 'x', 'x', 'x', 'x', 4, 4, 'x', 4, 'x', 4, 4, 'x', 'x'], ['ON', 'BN', 'BN', 'BN', 'BN', 'R', 'L', 'BN', 'EN', 'BN', 'L', 'L', 'BN', 'BN']])], [('regression: next odd level', [['RLO', 'ON', 'EN', 'EN', 'ON', 'R'], 1, 2], [['x', 1, 1, 1, 1, 1], ['BN', 'ON', 'EN', 'EN', 'ON', 'R']]), ('regression: next odd level', [['RLE', 'RLO', 'EN', 'L', 'EN', 'PDF', 'L', 'LRE', 'EN', 'LRO', 'R', 'WS', 'LRE'], 1, 3], [['x', 'x', 3, 3, 3, 'x', 3, 'x', 3, 'x', 3, 3, 'x'], ['BN', 'BN', 'EN', 'L', 'EN', 'BN', 'L', 'BN', 'EN', 'BN', 'R', 'WS', 'BN']]), ('regression: next odd level', [['RLO', 'R'], 1, 3], [['x', 3], ['BN', 'R']]), ('regression: next odd level', [['L', 'L', 'RLO', 'RLO', 'L', 'R', 'RLE', 'RLE', 'R', 'R', 'L', 'LRE', 'EN'], 1, 6], [[1, 1, 'x', 'x', 5, 5, 'x', 'x', 5, 5, 5, 'x', 5], ['L', 'L', 'BN', 'BN', 'R', 'R', 'BN', 'BN', 'R', 'R', 'R', 'BN', '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', [['R', 'L', 'LRE', 'LRO', 'RLE'], 1, 3], [[1, 1, 'x', 'x', 'x'], ['R', 'L', 'BN', 'BN', 'BN']]), ('control layout', [['ON', 'L', 'LRO', 'RLO', 'PDF', 'PDF', 'R', 'R', 'ON', 'L', 'ON', 'L'], 1, 3], [[1, 1, 'x', 'x', 'x', 'x', 1, 1, 1, 1, 1, 1], ['ON', 'L', 'BN', 'BN', 'BN', 'BN', 'R', 'R', 'ON', 'L', 'ON', '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:
RLE inside an RTL embedding produces an even level.

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 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 else c)
    return [levels, types]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('LRE from odd level', [['LRE', 'R'], 1, 6], [['x', 2], ['BN', 'R']]), ('regression: next even level', [['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: next even level', [['PDF', 'L', 'R', 'LRE', 'LRE', 'R', 'RLO', 'ON', 'L', 'ON', 'LRE'], 1, 5], [['x', 1, 1, 'x', 'x', 4, 'x', 5, 5, 5, 'x'], ['BN', 'L', 'R', 'BN', 'BN', 'R', 'BN', 'R', 'R', 'R', 'BN']]), ('partial-repair probe', [['LRE', 'LRE', 'LRE', 'LRO', 'RLE', 'L'], 0, 6], [['x', 'x', 'x', 'x', 'x', 6], ['BN', 'BN', 'BN', 'BN', 'BN', 'L']]), ('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', 'EN'], 0, 5], [[0, 0], ['R', 'EN']]), ('control layout', [['L', 'RLE', 'PDF', 'R', 'R', 'R', 'L', 'L'], 1, 5], [[1, 'x', 'x', 1, 1, 1, 1, 1], ['L', 'BN', 'BN', 'R', 'R', 'R', 'L', 'L']])], [('regression: next even level', [['WS', 'LRO', 'RLO', 'LRO', 'LRO', 'EN', 'L', 'PDF', 'ON', 'ON', 'LRO', 'R'], 1, 5], [[1, 'x', 'x', 'x', 'x', 4, 4, 'x', 4, 4, 'x', 4], ['WS', 'BN', 'BN', 'BN', 'BN', 'L', 'L', 'BN', 'L', 'L', 'BN', 'L']]), ('regression: next even level', [['PDF', 'L', 'R', 'LRE', 'LRE', 'R', 'RLO', 'ON', 'L', 'ON', 'LRE'], 1, 5], [['x', 1, 1, 'x', 'x', 4, 'x', 5, 5, 5, 'x'], ['BN', 'L', 'R', 'BN', 'BN', 'R', 'BN', 'R', 'R', 'R', 'BN']]), ('regression: next even level', [['RLO', 'RLO', 'LRE', 'LRE', 'L'], 0, 4], [['x', 'x', 'x', 'x', 4], ['BN', 'BN', 'BN', 'BN', 'L']]), ('partial-repair probe', [['R', 'PDF', 'WS', 'RLE', 'PDF', 'WS', 'LRE', 'R', 'WS', 'LRO', 'PDF', 'LRO', 'LRE', 'RLE'], 0, 5], [[0, 'x', 0, 'x', 'x', 0, 'x', 2, 2, 'x', 'x', 'x', 'x', 'x'], ['R', 'BN', 'WS', 'BN', 'BN', 'WS', 'BN', 'R', 'WS', 'BN', 'BN', 'BN', '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', [['R', 'WS'], 1, 4], [[1, 1], ['R', 'WS']]), ('control layout', [['WS', 'R', 'R', 'R', 'L', 'R', 'WS', 'R', 'PDF', 'EN', 'PDF', 'WS'], 1, 6], [[1, 1, 1, 1, 1, 1, 1, 1, 'x', 1, 'x', 1], ['WS', 'R', 'R', 'R', 'L', 'R', 'WS', 'R', 'BN', 'EN', 'BN', 'WS']])], [('regression: next even level', [['RLE', 'L', 'R', 'L', 'WS', 'ON', 'PDF', 'LRO', 'RLO', 'RLO', 'R', 'ON', 'EN', 'L'], 1, 4], [['x', 3, 3, 3, 3, 3, 'x', 'x', 'x', 'x', 3, 3, 3, 3], ['BN', 'L', 'R', 'L', 'WS', 'ON', 'BN', 'BN', 'BN', 'BN', 'R', 'R', 'R', 'R']]), ('regression: next even level', [['LRE', 'RLE', 'L', 'PDF', 'ON', 'R', 'PDF'], 1, 2], [['x', 'x', 2, 'x', 2, 2, 'x'], ['BN', 'BN', 'L', 'BN', 'ON', 'R', 'BN']]), ('regression: next even level', [['PDF', 'R', 'LRO', 'R', 'LRE', 'ON', 'L', 'RLO', 'ON'], 1, 5], [['x', 1, 'x', 2, 'x', 4, 4, 'x', 5], ['BN', 'R', 'BN', 'L', 'BN', 'ON', 'L', 'BN', 'R']]), ('partial-repair probe', [['R', 'WS', 'L', 'ON', 'LRE', 'L', 'R'], 0, 5], [[0, 0, 0, 0, 'x', 2, 2], ['R', 'WS', 'L', 'ON', 'BN', 'L', 'R']]), ('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', 'ON', 'PDF', 'RLO', 'WS', 'EN', 'ON', 'L', 'LRE'], 1, 5], [[1, 1, 'x', 'x', 3, 3, 3, 3, 'x'], ['L', 'ON', 'BN', 'BN', 'R', 'R', 'R', 'R', 'BN']]), ('control layout', [['EN', 'RLO', 'RLE', 'RLO'], 1, 4], [[1, 'x', 'x', 'x'], ['EN', 'BN', 'BN', 'BN']])], [('regression: next even level', [['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']]), ('regression: next even level', [['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: next even level', [['ON', 'RLE', 'L', 'EN', 'R', 'LRE', 'R', 'ON', 'WS', 'RLE', 'L', 'PDF', 'LRE', 'R'], 0, 3], [[0, 'x', 1, 1, 1, 'x', 2, 2, 2, 'x', 3, 'x', 'x', 2], ['ON', 'BN', 'L', 'EN', 'R', 'BN', 'R', 'ON', 'WS', 'BN', 'L', 'BN', 'BN', 'R']]), ('regression: next even level', [['PDF', 'L', 'R', 'LRE', 'LRE', 'R', 'RLO', 'ON', 'L', 'ON', 'LRE'], 1, 5], [['x', 1, 1, 'x', 'x', 4, 'x', 5, 5, 5, 'x'], ['BN', 'L', 'R', 'BN', 'BN', 'R', 'BN', 'R', 'R', 'R', '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', [['ON', 'L', 'LRO', 'RLO', 'PDF', 'PDF', 'R', 'R', 'ON', 'L', 'ON', 'L'], 1, 3], [[1, 1, 'x', 'x', 'x', 'x', 1, 1, 1, 1, 1, 1], ['ON', 'L', 'BN', 'BN', 'BN', 'BN', 'R', 'R', 'ON', 'L', 'ON', 'L']]), ('control layout', [['L', 'RLE', 'RLE', 'RLE', 'L', 'LRO', 'L', 'RLE', 'WS', 'L', 'RLE'], 0, 2], [[0, 'x', 'x', 'x', 1, 'x', 1, 'x', 1, 1, 'x'], ['L', 'BN', 'BN', 'BN', 'L', 'BN', 'L', 'BN', 'WS', 'L', 'BN']])], [('regression: next even level', [['L', 'WS', 'R', 'L', 'L', 'LRE', 'L', 'PDF', 'ON', 'ON', 'PDF', 'L', 'ON'], 1, 4], [[1, 1, 1, 1, 1, 'x', 2, 'x', 1, 1, 'x', 1, 1], ['L', 'WS', 'R', 'L', 'L', 'BN', 'L', 'BN', 'ON', 'ON', 'BN', 'L', 'ON']]), ('regression: next even level', [['R', 'L', 'L', 'RLE', 'ON', 'ON', 'PDF', 'LRE', 'L'], 1, 3], [[1, 1, 1, 'x', 3, 3, 'x', 'x', 2], ['R', 'L', 'L', 'BN', 'ON', 'ON', 'BN', 'BN', 'L']]), ('regression: next even level', [['R', 'RLO', 'PDF', 'R', 'L', 'RLE', 'LRE', 'ON', 'R', 'RLE', 'ON', 'LRE', 'R'], 0, 4], [[0, 'x', 'x', 0, 0, 'x', 'x', 2, 2, 'x', 3, 'x', 4], ['R', 'BN', 'BN', 'R', 'L', 'BN', 'BN', 'ON', 'R', 'BN', 'ON', 'BN', 'R']]), ('regression: next even level', [['LRE', 'RLE', 'EN', 'LRE', 'EN', 'PDF', 'PDF', 'L', 'ON', 'RLE'], 0, 6], [['x', 'x', 3, 'x', 4, 'x', 'x', 2, 2, 'x'], ['BN', 'BN', 'EN', 'BN', 'EN', 'BN', 'BN', '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', [['ON', 'R', 'RLE'], 1, 2], [[1, 1, 'x'], ['ON', 'R', 'BN']]), ('control layout', [['L', 'RLO', 'R', 'RLE', 'ON', 'ON', 'RLE', 'PDF', 'PDF', 'ON', 'R'], 0, 2], [[0, 'x', 1, 'x', 1, 1, 'x', 'x', 'x', 1, 1], ['L', 'BN', 'R', 'BN', 'R', 'R', 'BN', 'BN', 'BN', 'R', 'R']])]]
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 == 1 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 else c)
    return [levels, types]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('LRE from odd level', [['LRE', 'R'], 1, 6], [['x', 2], ['BN', 'R']]), ('regression: next even level', [['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: next even level', [['PDF', 'L', 'R', 'LRE', 'LRE', 'R', 'RLO', 'ON', 'L', 'ON', 'LRE'], 1, 5], [['x', 1, 1, 'x', 'x', 4, 'x', 5, 5, 5, 'x'], ['BN', 'L', 'R', 'BN', 'BN', 'R', 'BN', 'R', 'R', 'R', 'BN']]), ('partial-repair probe', [['LRE', 'LRE', 'LRE', 'LRO', 'RLE', 'L'], 0, 6], [['x', 'x', 'x', 'x', 'x', 6], ['BN', 'BN', 'BN', 'BN', 'BN', 'L']]), ('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', 'EN'], 0, 5], [[0, 0], ['R', 'EN']]), ('control layout', [['L', 'RLE', 'PDF', 'R', 'R', 'R', 'L', 'L'], 1, 5], [[1, 'x', 'x', 1, 1, 1, 1, 1], ['L', 'BN', 'BN', 'R', 'R', 'R', 'L', 'L']])], [('regression: next even level', [['WS', 'LRO', 'RLO', 'LRO', 'LRO', 'EN', 'L', 'PDF', 'ON', 'ON', 'LRO', 'R'], 1, 5], [[1, 'x', 'x', 'x', 'x', 4, 4, 'x', 4, 4, 'x', 4], ['WS', 'BN', 'BN', 'BN', 'BN', 'L', 'L', 'BN', 'L', 'L', 'BN', 'L']]), ('regression: next even level', [['PDF', 'L', 'R', 'LRE', 'LRE', 'R', 'RLO', 'ON', 'L', 'ON', 'LRE'], 1, 5], [['x', 1, 1, 'x', 'x', 4, 'x', 5, 5, 5, 'x'], ['BN', 'L', 'R', 'BN', 'BN', 'R', 'BN', 'R', 'R', 'R', 'BN']]), ('regression: next even level', [['RLO', 'RLO', 'LRE', 'LRE', 'L'], 0, 4], [['x', 'x', 'x', 'x', 4], ['BN', 'BN', 'BN', 'BN', 'L']]), ('partial-repair probe', [['R', 'PDF', 'WS', 'RLE', 'PDF', 'WS', 'LRE', 'R', 'WS', 'LRO', 'PDF', 'LRO', 'LRE', 'RLE'], 0, 5], [[0, 'x', 0, 'x', 'x', 0, 'x', 2, 2, 'x', 'x', 'x', 'x', 'x'], ['R', 'BN', 'WS', 'BN', 'BN', 'WS', 'BN', 'R', 'WS', 'BN', 'BN', 'BN', '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', [['R', 'WS'], 1, 4], [[1, 1], ['R', 'WS']]), ('control layout', [['WS', 'R', 'R', 'R', 'L', 'R', 'WS', 'R', 'PDF', 'EN', 'PDF', 'WS'], 1, 6], [[1, 1, 1, 1, 1, 1, 1, 1, 'x', 1, 'x', 1], ['WS', 'R', 'R', 'R', 'L', 'R', 'WS', 'R', 'BN', 'EN', 'BN', 'WS']])], [('regression: next even level', [['RLE', 'L', 'R', 'L', 'WS', 'ON', 'PDF', 'LRO', 'RLO', 'RLO', 'R', 'ON', 'EN', 'L'], 1, 4], [['x', 3, 3, 3, 3, 3, 'x', 'x', 'x', 'x', 3, 3, 3, 3], ['BN', 'L', 'R', 'L', 'WS', 'ON', 'BN', 'BN', 'BN', 'BN', 'R', 'R', 'R', 'R']]), ('regression: next even level', [['LRE', 'RLE', 'L', 'PDF', 'ON', 'R', 'PDF'], 1, 2], [['x', 'x', 2, 'x', 2, 2, 'x'], ['BN', 'BN', 'L', 'BN', 'ON', 'R', 'BN']]), ('regression: next even level', [['PDF', 'R', 'LRO', 'R', 'LRE', 'ON', 'L', 'RLO', 'ON'], 1, 5], [['x', 1, 'x', 2, 'x', 4, 4, 'x', 5], ['BN', 'R', 'BN', 'L', 'BN', 'ON', 'L', 'BN', 'R']]), ('partial-repair probe', [['R', 'WS', 'L', 'ON', 'LRE', 'L', 'R'], 0, 5], [[0, 0, 0, 0, 'x', 2, 2], ['R', 'WS', 'L', 'ON', 'BN', 'L', 'R']]), ('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', 'ON', 'PDF', 'RLO', 'WS', 'EN', 'ON', 'L', 'LRE'], 1, 5], [[1, 1, 'x', 'x', 3, 3, 3, 3, 'x'], ['L', 'ON', 'BN', 'BN', 'R', 'R', 'R', 'R', 'BN']]), ('control layout', [['EN', 'RLO', 'RLE', 'RLO'], 1, 4], [[1, 'x', 'x', 'x'], ['EN', 'BN', 'BN', 'BN']])], [('regression: next even level', [['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']]), ('regression: next even level', [['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: next even level', [['ON', 'RLE', 'L', 'EN', 'R', 'LRE', 'R', 'ON', 'WS', 'RLE', 'L', 'PDF', 'LRE', 'R'], 0, 3], [[0, 'x', 1, 1, 1, 'x', 2, 2, 2, 'x', 3, 'x', 'x', 2], ['ON', 'BN', 'L', 'EN', 'R', 'BN', 'R', 'ON', 'WS', 'BN', 'L', 'BN', 'BN', 'R']]), ('regression: next even level', [['PDF', 'L', 'R', 'LRE', 'LRE', 'R', 'RLO', 'ON', 'L', 'ON', 'LRE'], 1, 5], [['x', 1, 1, 'x', 'x', 4, 'x', 5, 5, 5, 'x'], ['BN', 'L', 'R', 'BN', 'BN', 'R', 'BN', 'R', 'R', 'R', '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', [['ON', 'L', 'LRO', 'RLO', 'PDF', 'PDF', 'R', 'R', 'ON', 'L', 'ON', 'L'], 1, 3], [[1, 1, 'x', 'x', 'x', 'x', 1, 1, 1, 1, 1, 1], ['ON', 'L', 'BN', 'BN', 'BN', 'BN', 'R', 'R', 'ON', 'L', 'ON', 'L']]), ('control layout', [['L', 'RLE', 'RLE', 'RLE', 'L', 'LRO', 'L', 'RLE', 'WS', 'L', 'RLE'], 0, 2], [[0, 'x', 'x', 'x', 1, 'x', 1, 'x', 1, 1, 'x'], ['L', 'BN', 'BN', 'BN', 'L', 'BN', 'L', 'BN', 'WS', 'L', 'BN']])], [('regression: next even level', [['L', 'WS', 'R', 'L', 'L', 'LRE', 'L', 'PDF', 'ON', 'ON', 'PDF', 'L', 'ON'], 1, 4], [[1, 1, 1, 1, 1, 'x', 2, 'x', 1, 1, 'x', 1, 1], ['L', 'WS', 'R', 'L', 'L', 'BN', 'L', 'BN', 'ON', 'ON', 'BN', 'L', 'ON']]), ('regression: next even level', [['R', 'L', 'L', 'RLE', 'ON', 'ON', 'PDF', 'LRE', 'L'], 1, 3], [[1, 1, 1, 'x', 3, 3, 'x', 'x', 2], ['R', 'L', 'L', 'BN', 'ON', 'ON', 'BN', 'BN', 'L']]), ('regression: next even level', [['R', 'RLO', 'PDF', 'R', 'L', 'RLE', 'LRE', 'ON', 'R', 'RLE', 'ON', 'LRE', 'R'], 0, 4], [[0, 'x', 'x', 0, 0, 'x', 'x', 2, 2, 'x', 3, 'x', 4], ['R', 'BN', 'BN', 'R', 'L', 'BN', 'BN', 'ON', 'R', 'BN', 'ON', 'BN', 'R']]), ('regression: next even level', [['LRE', 'RLE', 'EN', 'LRE', 'EN', 'PDF', 'PDF', 'L', 'ON', 'RLE'], 0, 6], [['x', 'x', 3, 'x', 4, 'x', 'x', 2, 2, 'x'], ['BN', 'BN', 'EN', 'BN', 'EN', 'BN', 'BN', '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', [['ON', 'R', 'RLE'], 1, 2], [[1, 1, 'x'], ['ON', 'R', 'BN']]), ('control layout', [['L', 'RLO', 'R', 'RLE', 'ON', 'ON', 'RLE', 'PDF', 'PDF', 'ON', 'R'], 0, 2], [[0, 'x', 1, 'x', 1, 1, 'x', 'x', 'x', 1, 1], ['L', 'BN', 'R', 'BN', 'R', 'R', 'BN', 'BN', 'BN', 'R', 'R']])]]
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:
LRE inside an RTL embedding skips a level.

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 else c)
    return [levels, types]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('depth limit exactly reached', [['RLE', 'LRE', 'L', 'PDF', 'L'], 0, 2], [['x', 'x', 2, 'x', 1], ['BN', 'BN', 'L', 'BN', 'L']]), ('regression: maximum depth bound', [['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']]), ('partial-repair probe', [['L', 'PDF', 'LRO', 'R', 'R', 'LRE', 'WS', 'L'], 0, 3], [[0, 'x', 'x', 2, 2, 'x', 2, 2], ['L', 'BN', 'BN', 'L', 'L', 'BN', 'L', 'L']]), ('partial-repair probe', [['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']]), ('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', 'R', 'LRE', 'L', 'L', 'LRE', 'WS', 'R', 'RLE', 'WS', 'PDF', 'EN', 'LRO'], 1, 6], [[1, 1, 'x', 2, 2, 'x', 4, 4, 'x', 5, 'x', 4, 'x'], ['R', 'R', 'BN', 'L', 'L', 'BN', 'WS', 'R', 'BN', 'WS', 'BN', 'EN', 'BN']]), ('control layout', [['L', 'WS', 'LRE', 'RLE', 'LRE', 'EN', 'R', 'L', 'RLE'], 0, 5], [[0, 0, 'x', 'x', 'x', 4, 4, 4, 'x'], ['L', 'WS', 'BN', 'BN', 'BN', 'EN', 'R', 'L', 'BN']])], [('regression: maximum depth bound', [['ON', 'LRO', 'EN'], 1, 2], [[1, 'x', 2], ['ON', 'BN', 'L']]), ('regression: maximum depth bound', [['RLE', 'L', 'LRO', 'RLE', 'L', 'R', 'L', 'R', 'RLE', 'L', 'LRO', 'L'], 0, 3], [['x', 1, 'x', 'x', 3, 3, 3, 3, 'x', 3, 'x', 3], ['BN', 'L', 'BN', 'BN', 'L', 'R', 'L', 'R', 'BN', 'L', 'BN', 'L']]), ('partial-repair probe', [['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']]), ('partial-repair probe', [['RLO', 'ON', 'RLE', 'RLE', 'L', 'R'], 0, 4], [['x', 1, 'x', 'x', 3, 3], ['BN', 'R', 'BN', 'BN', 'L', 'R']]), ('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', [['R', 'EN', 'RLO', 'PDF', 'R', 'PDF', 'L', 'LRO'], 0, 6], [[0, 0, 'x', 'x', 0, 'x', 0, 'x'], ['R', 'EN', 'BN', 'BN', 'R', 'BN', 'L', 'BN']]), ('control layout', [['ON', 'RLE', 'L', 'ON', 'R'], 0, 2], [[0, 'x', 1, 1, 1], ['ON', 'BN', 'L', 'ON', 'R']])], [('regression: maximum depth bound', [['R', 'R', 'R', 'RLO', 'R', 'LRE', 'LRE', 'ON', 'RLE', 'PDF', 'RLE', 'L'], 0, 5], [[0, 0, 0, 'x', 1, 'x', 'x', 4, 'x', 'x', 'x', 5], ['R', 'R', 'R', 'BN', 'R', 'BN', 'BN', 'ON', 'BN', 'BN', 'BN', 'L']]), ('regression: maximum depth bound', [['RLE', 'L', 'LRO', 'RLE', 'L', 'R', 'L', 'R', 'RLE', 'L', 'LRO', 'L'], 0, 3], [['x', 1, 'x', 'x', 3, 3, 3, 3, 'x', 3, 'x', 3], ['BN', 'L', 'BN', 'BN', 'L', 'R', 'L', 'R', 'BN', 'L', 'BN', 'L']]), ('partial-repair probe', [['L', 'RLO', 'ON', 'RLE', 'RLE', 'WS', 'LRE', 'L', 'PDF', 'R', 'RLE', 'L'], 1, 2], [[1, 'x', 1, 'x', 'x', 1, 'x', 1, 'x', 1, 'x', 1], ['L', 'BN', 'ON', 'BN', 'BN', 'WS', 'BN', 'L', 'BN', 'R', 'BN', 'L']]), ('partial-repair probe', [['RLO', 'ON', 'RLE', 'RLE', 'L', 'R'], 0, 4], [['x', 1, 'x', 'x', 3, 3], ['BN', 'R', 'BN', 'BN', 'L', 'R']]), ('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', [['PDF', 'LRO'], 0, 5], [['x', 'x'], ['BN', 'BN']]), ('control layout', [['PDF', 'L', 'R', 'RLE'], 0, 5], [['x', 0, 0, 'x'], ['BN', 'L', 'R', 'BN']])], [('regression: maximum depth bound', [['LRE', 'ON', 'R', 'R', 'RLO', 'LRO'], 1, 2], [['x', 2, 2, 2, 'x', 'x'], ['BN', 'ON', 'R', 'R', 'BN', 'BN']]), ('regression: maximum depth bound', [['LRE', 'L', 'R', 'PDF', 'RLE'], 1, 2], [['x', 2, 2, 'x', 'x'], ['BN', 'L', 'R', 'BN', 'BN']]), ('regression: maximum depth bound', [['ON', 'RLE', 'L', 'EN', 'R', 'LRE', 'R', 'ON', 'WS', 'RLE', 'L', 'PDF', 'LRE', 'R'], 0, 3], [[0, 'x', 1, 1, 1, 'x', 2, 2, 2, 'x', 3, 'x', 'x', 2], ['ON', 'BN', 'L', 'EN', 'R', 'BN', 'R', 'ON', 'WS', 'BN', 'L', 'BN', 'BN', 'R']]), ('partial-repair probe', [['R', 'R', 'EN', 'RLE', 'EN', 'RLE', 'ON', 'PDF', 'LRO'], 1, 2], [[1, 1, 1, 'x', 1, 'x', 1, 'x', 'x'], ['R', 'R', 'EN', 'BN', 'EN', 'BN', 'ON', 'BN', 'BN']]), ('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', [['L', 'EN', 'ON', 'L', 'EN', 'L', 'PDF', 'R', 'L', 'RLE', 'PDF', 'LRE'], 0, 3], [[0, 0, 0, 0, 0, 0, 'x', 0, 0, 'x', 'x', 'x'], ['L', 'EN', 'ON', 'L', 'EN', 'L', 'BN', 'R', 'L', 'BN', 'BN', 'BN']]), ('control layout', [['ON', 'R', 'RLE'], 1, 2], [[1, 1, 'x'], ['ON', 'R', 'BN']])], [('regression: maximum depth bound', [['L', 'ON', 'ON', 'ON', 'RLO', 'PDF', 'R', 'LRO', 'EN', 'PDF', 'PDF'], 1, 2], [[1, 1, 1, 1, 'x', 'x', 1, 'x', 2, 'x', 'x'], ['L', 'ON', 'ON', 'ON', 'BN', 'BN', 'R', 'BN', 'L', 'BN', 'BN']]), ('regression: maximum depth bound', [['LRO', 'EN', 'RLO', 'RLE', 'LRE'], 1, 2], [['x', 2, 'x', 'x', 'x'], ['BN', 'L', 'BN', 'BN', 'BN']]), ('partial-repair probe', [['L', 'RLO', 'ON', 'RLE', 'RLE', 'WS', 'LRE', 'L', 'PDF', 'R', 'RLE', 'L'], 1, 2], [[1, 'x', 1, 'x', 'x', 1, 'x', 1, 'x', 1, 'x', 1], ['L', 'BN', 'ON', 'BN', 'BN', 'WS', 'BN', 'L', 'BN', 'R', 'BN', 'L']]), ('partial-repair probe', [['RLE', 'L', 'R', 'L', 'WS', 'ON', 'PDF', 'LRO', 'RLO', 'RLO', 'R', 'ON', 'EN', 'L'], 1, 4], [['x', 3, 3, 3, 3, 3, 'x', 'x', 'x', 'x', 3, 3, 3, 3], ['BN', 'L', 'R', 'L', 'WS', 'ON', 'BN', 'BN', 'BN', 'BN', 'R', 'R', 'R', 'R']]), ('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', [['ON', 'R', 'L', 'R', 'EN', 'R', 'PDF'], 1, 3], [[1, 1, 1, 1, 1, 1, 'x'], ['ON', 'R', 'L', 'R', 'EN', 'R', 'BN']]), ('control layout', [['PDF', 'R', 'ON', 'L', 'ON', 'EN', 'PDF', 'L', 'RLO', 'PDF', 'R', 'R'], 1, 6], [['x', 1, 1, 1, 1, 1, 'x', 1, 'x', 'x', 1, 1], ['BN', 'R', 'ON', 'L', 'ON', 'EN', 'BN', 'L', 'BN', 'BN', 'R', 'R']])]]
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 cur < 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 else c)
    return [levels, types]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('depth limit exactly reached', [['RLE', 'LRE', 'L', 'PDF', 'L'], 0, 2], [['x', 'x', 2, 'x', 1], ['BN', 'BN', 'L', 'BN', 'L']]), ('regression: maximum depth bound', [['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']]), ('partial-repair probe', [['L', 'PDF', 'LRO', 'R', 'R', 'LRE', 'WS', 'L'], 0, 3], [[0, 'x', 'x', 2, 2, 'x', 2, 2], ['L', 'BN', 'BN', 'L', 'L', 'BN', 'L', 'L']]), ('partial-repair probe', [['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']]), ('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', 'R', 'LRE', 'L', 'L', 'LRE', 'WS', 'R', 'RLE', 'WS', 'PDF', 'EN', 'LRO'], 1, 6], [[1, 1, 'x', 2, 2, 'x', 4, 4, 'x', 5, 'x', 4, 'x'], ['R', 'R', 'BN', 'L', 'L', 'BN', 'WS', 'R', 'BN', 'WS', 'BN', 'EN', 'BN']]), ('control layout', [['L', 'WS', 'LRE', 'RLE', 'LRE', 'EN', 'R', 'L', 'RLE'], 0, 5], [[0, 0, 'x', 'x', 'x', 4, 4, 4, 'x'], ['L', 'WS', 'BN', 'BN', 'BN', 'EN', 'R', 'L', 'BN']])], [('regression: maximum depth bound', [['ON', 'LRO', 'EN'], 1, 2], [[1, 'x', 2], ['ON', 'BN', 'L']]), ('regression: maximum depth bound', [['RLE', 'L', 'LRO', 'RLE', 'L', 'R', 'L', 'R', 'RLE', 'L', 'LRO', 'L'], 0, 3], [['x', 1, 'x', 'x', 3, 3, 3, 3, 'x', 3, 'x', 3], ['BN', 'L', 'BN', 'BN', 'L', 'R', 'L', 'R', 'BN', 'L', 'BN', 'L']]), ('partial-repair probe', [['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']]), ('partial-repair probe', [['RLO', 'ON', 'RLE', 'RLE', 'L', 'R'], 0, 4], [['x', 1, 'x', 'x', 3, 3], ['BN', 'R', 'BN', 'BN', 'L', 'R']]), ('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', [['R', 'EN', 'RLO', 'PDF', 'R', 'PDF', 'L', 'LRO'], 0, 6], [[0, 0, 'x', 'x', 0, 'x', 0, 'x'], ['R', 'EN', 'BN', 'BN', 'R', 'BN', 'L', 'BN']]), ('control layout', [['ON', 'RLE', 'L', 'ON', 'R'], 0, 2], [[0, 'x', 1, 1, 1], ['ON', 'BN', 'L', 'ON', 'R']])], [('regression: maximum depth bound', [['R', 'R', 'R', 'RLO', 'R', 'LRE', 'LRE', 'ON', 'RLE', 'PDF', 'RLE', 'L'], 0, 5], [[0, 0, 0, 'x', 1, 'x', 'x', 4, 'x', 'x', 'x', 5], ['R', 'R', 'R', 'BN', 'R', 'BN', 'BN', 'ON', 'BN', 'BN', 'BN', 'L']]), ('regression: maximum depth bound', [['RLE', 'L', 'LRO', 'RLE', 'L', 'R', 'L', 'R', 'RLE', 'L', 'LRO', 'L'], 0, 3], [['x', 1, 'x', 'x', 3, 3, 3, 3, 'x', 3, 'x', 3], ['BN', 'L', 'BN', 'BN', 'L', 'R', 'L', 'R', 'BN', 'L', 'BN', 'L']]), ('partial-repair probe', [['L', 'RLO', 'ON', 'RLE', 'RLE', 'WS', 'LRE', 'L', 'PDF', 'R', 'RLE', 'L'], 1, 2], [[1, 'x', 1, 'x', 'x', 1, 'x', 1, 'x', 1, 'x', 1], ['L', 'BN', 'ON', 'BN', 'BN', 'WS', 'BN', 'L', 'BN', 'R', 'BN', 'L']]), ('partial-repair probe', [['RLO', 'ON', 'RLE', 'RLE', 'L', 'R'], 0, 4], [['x', 1, 'x', 'x', 3, 3], ['BN', 'R', 'BN', 'BN', 'L', 'R']]), ('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', [['PDF', 'LRO'], 0, 5], [['x', 'x'], ['BN', 'BN']]), ('control layout', [['PDF', 'L', 'R', 'RLE'], 0, 5], [['x', 0, 0, 'x'], ['BN', 'L', 'R', 'BN']])], [('regression: maximum depth bound', [['LRE', 'ON', 'R', 'R', 'RLO', 'LRO'], 1, 2], [['x', 2, 2, 2, 'x', 'x'], ['BN', 'ON', 'R', 'R', 'BN', 'BN']]), ('regression: maximum depth bound', [['LRE', 'L', 'R', 'PDF', 'RLE'], 1, 2], [['x', 2, 2, 'x', 'x'], ['BN', 'L', 'R', 'BN', 'BN']]), ('regression: maximum depth bound', [['ON', 'RLE', 'L', 'EN', 'R', 'LRE', 'R', 'ON', 'WS', 'RLE', 'L', 'PDF', 'LRE', 'R'], 0, 3], [[0, 'x', 1, 1, 1, 'x', 2, 2, 2, 'x', 3, 'x', 'x', 2], ['ON', 'BN', 'L', 'EN', 'R', 'BN', 'R', 'ON', 'WS', 'BN', 'L', 'BN', 'BN', 'R']]), ('partial-repair probe', [['R', 'R', 'EN', 'RLE', 'EN', 'RLE', 'ON', 'PDF', 'LRO'], 1, 2], [[1, 1, 1, 'x', 1, 'x', 1, 'x', 'x'], ['R', 'R', 'EN', 'BN', 'EN', 'BN', 'ON', 'BN', 'BN']]), ('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', [['L', 'EN', 'ON', 'L', 'EN', 'L', 'PDF', 'R', 'L', 'RLE', 'PDF', 'LRE'], 0, 3], [[0, 0, 0, 0, 0, 0, 'x', 0, 0, 'x', 'x', 'x'], ['L', 'EN', 'ON', 'L', 'EN', 'L', 'BN', 'R', 'L', 'BN', 'BN', 'BN']]), ('control layout', [['ON', 'R', 'RLE'], 1, 2], [[1, 1, 'x'], ['ON', 'R', 'BN']])], [('regression: maximum depth bound', [['L', 'ON', 'ON', 'ON', 'RLO', 'PDF', 'R', 'LRO', 'EN', 'PDF', 'PDF'], 1, 2], [[1, 1, 1, 1, 'x', 'x', 1, 'x', 2, 'x', 'x'], ['L', 'ON', 'ON', 'ON', 'BN', 'BN', 'R', 'BN', 'L', 'BN', 'BN']]), ('regression: maximum depth bound', [['LRO', 'EN', 'RLO', 'RLE', 'LRE'], 1, 2], [['x', 2, 'x', 'x', 'x'], ['BN', 'L', 'BN', 'BN', 'BN']]), ('partial-repair probe', [['L', 'RLO', 'ON', 'RLE', 'RLE', 'WS', 'LRE', 'L', 'PDF', 'R', 'RLE', 'L'], 1, 2], [[1, 'x', 1, 'x', 'x', 1, 'x', 1, 'x', 1, 'x', 1], ['L', 'BN', 'ON', 'BN', 'BN', 'WS', 'BN', 'L', 'BN', 'R', 'BN', 'L']]), ('partial-repair probe', [['RLE', 'L', 'R', 'L', 'WS', 'ON', 'PDF', 'LRO', 'RLO', 'RLO', 'R', 'ON', 'EN', 'L'], 1, 4], [['x', 3, 3, 3, 3, 3, 'x', 'x', 'x', 'x', 3, 3, 3, 3], ['BN', 'L', 'R', 'L', 'WS', 'ON', 'BN', 'BN', 'BN', 'BN', 'R', 'R', 'R', 'R']]), ('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', [['ON', 'R', 'L', 'R', 'EN', 'R', 'PDF'], 1, 3], [[1, 1, 1, 1, 1, 1, 'x'], ['ON', 'R', 'L', 'R', 'EN', 'R', 'BN']]), ('control layout', [['PDF', 'R', 'ON', 'L', 'ON', 'EN', 'PDF', 'L', 'RLO', 'PDF', 'R', 'R'], 1, 6], [['x', 1, 1, 1, 1, 1, 'x', 1, 'x', 'x', 1, 1], ['BN', 'R', 'ON', 'L', 'ON', 'EN', 'BN', 'L', 'BN', 'BN', 'R', 'R']])]]
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:
Embeddings exactly at the maximum depth are rejected.

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:
                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 else c)
    return [levels, types]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: overflow blocking', [['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: overflow blocking', [['PDF', 'RLE', 'EN', 'ON', 'L', 'RLE', 'ON', 'LRE', 'LRE', 'WS', 'L', 'RLE', 'R', 'R'], 1, 2], [['x', 'x', 1, 1, 1, 'x', 1, 'x', 'x', 1, 1, 'x', 1, 1], ['BN', 'BN', 'EN', 'ON', 'L', 'BN', 'ON', 'BN', 'BN', 'WS', 'L', 'BN', 'R', 'R']]), ('regression: overflow blocking', [['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']]), ('regression: overflow blocking', [['ON', 'LRE', 'R', 'ON', 'RLE', 'PDF', 'LRE', 'L', 'LRE', 'PDF', 'RLE', 'PDF', 'R', 'EN'], 0, 3], [[0, 'x', 2, 2, 'x', 'x', 'x', 2, 'x', 'x', 'x', 'x', 2, 2], ['ON', 'BN', 'R', 'ON', 'BN', 'BN', 'BN', 'L', 'BN', 'BN', 'BN', 'BN', 'R', 'EN']]), ('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', [['PDF', 'LRO'], 0, 5], [['x', 'x'], ['BN', 'BN']]), ('control layout', [['RLE', 'L', 'LRE', 'EN', 'RLE', 'PDF', 'L'], 0, 2], [['x', 1, 'x', 2, 'x', 'x', 2], ['BN', 'L', 'BN', 'EN', 'BN', 'BN', 'L']])], [('regression: overflow blocking', [['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: overflow blocking', [['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']]), ('regression: overflow blocking', [['PDF', 'LRO', 'R', 'EN', 'LRE', 'L', 'L', 'L', 'RLE', 'R', 'L', 'LRO'], 1, 3], [['x', 'x', 2, 2, 'x', 2, 2, 2, 'x', 2, 2, 'x'], ['BN', 'BN', 'L', 'L', 'BN', 'L', 'L', 'L', 'BN', 'L', 'L', 'BN']]), ('regression: overflow blocking', [['ON', 'RLE', 'PDF', 'R', 'RLE', 'LRE', 'ON', 'PDF', 'R', 'ON'], 1, 2], [[1, 'x', 'x', 1, 'x', 'x', 1, 'x', 1, 1], ['ON', 'BN', 'BN', 'R', 'BN', 'BN', 'ON', 'BN', 'R', 'ON']]), ('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', [['EN', 'L', 'L', 'R', 'ON', 'R', 'ON'], 1, 4], [[1, 1, 1, 1, 1, 1, 1], ['EN', 'L', 'L', 'R', 'ON', 'R', 'ON']]), ('control layout', [['L', 'LRO', 'LRE', 'LRO'], 1, 6], [[1, 'x', 'x', 'x'], ['L', 'BN', 'BN', 'BN']])], [('regression: overflow blocking', [['L', 'L', 'RLO', 'RLO', 'L', 'R', 'RLE', 'RLE', 'R', 'R', 'L', 'LRE', 'EN'], 1, 6], [[1, 1, 'x', 'x', 5, 5, 'x', 'x', 5, 5, 5, 'x', 5], ['L', 'L', 'BN', 'BN', 'R', 'R', 'BN', 'BN', 'R', 'R', 'R', 'BN', 'R']]), ('regression: overflow blocking', [['PDF', 'PDF', 'RLO', 'L', 'LRO', 'R', 'R', 'PDF', 'PDF', 'RLO', 'PDF'], 1, 2], [['x', 'x', 'x', 1, 'x', 1, 1, 'x', 'x', 'x', 'x'], ['BN', 'BN', 'BN', 'L', 'BN', 'R', 'R', 'BN', 'BN', 'BN', 'BN']]), ('regression: overflow blocking', [['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: overflow blocking', [['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']]), ('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', [['WS', 'L', 'RLO', 'PDF', 'LRE'], 1, 3], [[1, 1, 'x', 'x', 'x'], ['WS', 'L', 'BN', 'BN', 'BN']]), ('control layout', [['L', 'R', 'RLE', 'LRO', 'R', 'L', 'WS', 'PDF', 'RLO', 'R', 'EN', 'WS', 'L', 'PDF'], 0, 4], [[0, 0, 'x', 'x', 2, 2, 2, 'x', 'x', 3, 3, 3, 3, 'x'], ['L', 'R', 'BN', 'BN', 'L', 'L', 'L', 'BN', 'BN', 'R', 'R', 'R', 'R', 'BN']])], [('regression: overflow blocking', [['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: overflow blocking', [['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']]), ('regression: overflow blocking', [['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: overflow blocking', [['ON', 'LRE', 'R', 'ON', 'RLE', 'PDF', 'LRE', 'L', 'LRE', 'PDF', 'RLE', 'PDF', 'R', 'EN'], 0, 3], [[0, 'x', 2, 2, 'x', 'x', 'x', 2, 'x', 'x', 'x', 'x', 2, 2], ['ON', 'BN', 'R', 'ON', 'BN', 'BN', 'BN', 'L', 'BN', 'BN', 'BN', 'BN', 'R', 'EN']]), ('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', [['ON', 'LRE'], 0, 6], [[0, 'x'], ['ON', 'BN']]), ('control layout', [['R', 'ON', 'R', 'EN', 'R', 'PDF', 'PDF', 'LRE', 'EN', 'RLE'], 0, 5], [[0, 0, 0, 0, 0, 'x', 'x', 'x', 2, 'x'], ['R', 'ON', 'R', 'EN', 'R', 'BN', 'BN', 'BN', 'EN', 'BN']])], [('regression: overflow blocking', [['RLE', 'RLE', 'ON', 'RLO', 'LRE', 'LRE', 'R', 'RLE', 'R'], 1, 2], [['x', 'x', 1, 'x', 'x', 'x', 1, 'x', 1], ['BN', 'BN', 'ON', 'BN', 'BN', 'BN', 'R', 'BN', 'R']]), ('regression: overflow blocking', [['ON', 'RLE', 'PDF', 'R', 'RLE', 'LRE', 'ON', 'PDF', 'R', 'ON'], 1, 2], [[1, 'x', 'x', 1, 'x', 'x', 1, 'x', 1, 1], ['ON', 'BN', 'BN', 'R', 'BN', 'BN', 'ON', 'BN', 'R', 'ON']]), ('regression: overflow blocking', [['LRO', 'R', 'ON', 'EN', 'ON', 'LRE', 'RLE', 'L', 'ON', 'WS', 'ON', 'ON', 'RLE', 'WS'], 1, 3], [['x', 2, 2, 2, 2, 'x', 'x', 2, 2, 2, 2, 2, 'x', 2], ['BN', 'L', 'L', 'L', 'L', 'BN', 'BN', 'L', 'L', 'L', 'L', 'L', 'BN', 'L']]), ('regression: overflow blocking', [['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']]), ('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', [['RLE', 'L', 'LRO', 'RLE', 'L', 'R', 'L', 'R', 'RLE', 'L', 'LRO', 'L'], 0, 3], [['x', 1, 'x', 'x', 3, 3, 3, 3, 'x', 3, 'x', 3], ['BN', 'L', 'BN', 'BN', 'L', 'R', 'L', 'R', 'BN', 'L', 'BN', 'L']]), ('control layout', [['RLE', 'ON', 'LRO'], 0, 4], [['x', 1, 'x'], ['BN', 'ON', 'BN']])]]
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 <= 1:
                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 else c)
    return [levels, types]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: overflow blocking', [['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: overflow blocking', [['PDF', 'RLE', 'EN', 'ON', 'L', 'RLE', 'ON', 'LRE', 'LRE', 'WS', 'L', 'RLE', 'R', 'R'], 1, 2], [['x', 'x', 1, 1, 1, 'x', 1, 'x', 'x', 1, 1, 'x', 1, 1], ['BN', 'BN', 'EN', 'ON', 'L', 'BN', 'ON', 'BN', 'BN', 'WS', 'L', 'BN', 'R', 'R']]), ('regression: overflow blocking', [['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']]), ('regression: overflow blocking', [['ON', 'LRE', 'R', 'ON', 'RLE', 'PDF', 'LRE', 'L', 'LRE', 'PDF', 'RLE', 'PDF', 'R', 'EN'], 0, 3], [[0, 'x', 2, 2, 'x', 'x', 'x', 2, 'x', 'x', 'x', 'x', 2, 2], ['ON', 'BN', 'R', 'ON', 'BN', 'BN', 'BN', 'L', 'BN', 'BN', 'BN', 'BN', 'R', 'EN']]), ('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', [['PDF', 'LRO'], 0, 5], [['x', 'x'], ['BN', 'BN']]), ('control layout', [['RLE', 'L', 'LRE', 'EN', 'RLE', 'PDF', 'L'], 0, 2], [['x', 1, 'x', 2, 'x', 'x', 2], ['BN', 'L', 'BN', 'EN', 'BN', 'BN', 'L']])], [('regression: overflow blocking', [['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: overflow blocking', [['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']]), ('regression: overflow blocking', [['PDF', 'LRO', 'R', 'EN', 'LRE', 'L', 'L', 'L', 'RLE', 'R', 'L', 'LRO'], 1, 3], [['x', 'x', 2, 2, 'x', 2, 2, 2, 'x', 2, 2, 'x'], ['BN', 'BN', 'L', 'L', 'BN', 'L', 'L', 'L', 'BN', 'L', 'L', 'BN']]), ('regression: overflow blocking', [['ON', 'RLE', 'PDF', 'R', 'RLE', 'LRE', 'ON', 'PDF', 'R', 'ON'], 1, 2], [[1, 'x', 'x', 1, 'x', 'x', 1, 'x', 1, 1], ['ON', 'BN', 'BN', 'R', 'BN', 'BN', 'ON', 'BN', 'R', 'ON']]), ('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', [['EN', 'L', 'L', 'R', 'ON', 'R', 'ON'], 1, 4], [[1, 1, 1, 1, 1, 1, 1], ['EN', 'L', 'L', 'R', 'ON', 'R', 'ON']]), ('control layout', [['L', 'LRO', 'LRE', 'LRO'], 1, 6], [[1, 'x', 'x', 'x'], ['L', 'BN', 'BN', 'BN']])], [('regression: overflow blocking', [['L', 'L', 'RLO', 'RLO', 'L', 'R', 'RLE', 'RLE', 'R', 'R', 'L', 'LRE', 'EN'], 1, 6], [[1, 1, 'x', 'x', 5, 5, 'x', 'x', 5, 5, 5, 'x', 5], ['L', 'L', 'BN', 'BN', 'R', 'R', 'BN', 'BN', 'R', 'R', 'R', 'BN', 'R']]), ('regression: overflow blocking', [['PDF', 'PDF', 'RLO', 'L', 'LRO', 'R', 'R', 'PDF', 'PDF', 'RLO', 'PDF'], 1, 2], [['x', 'x', 'x', 1, 'x', 1, 1, 'x', 'x', 'x', 'x'], ['BN', 'BN', 'BN', 'L', 'BN', 'R', 'R', 'BN', 'BN', 'BN', 'BN']]), ('regression: overflow blocking', [['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: overflow blocking', [['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']]), ('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', [['WS', 'L', 'RLO', 'PDF', 'LRE'], 1, 3], [[1, 1, 'x', 'x', 'x'], ['WS', 'L', 'BN', 'BN', 'BN']]), ('control layout', [['L', 'R', 'RLE', 'LRO', 'R', 'L', 'WS', 'PDF', 'RLO', 'R', 'EN', 'WS', 'L', 'PDF'], 0, 4], [[0, 0, 'x', 'x', 2, 2, 2, 'x', 'x', 3, 3, 3, 3, 'x'], ['L', 'R', 'BN', 'BN', 'L', 'L', 'L', 'BN', 'BN', 'R', 'R', 'R', 'R', 'BN']])], [('regression: overflow blocking', [['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: overflow blocking', [['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']]), ('regression: overflow blocking', [['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: overflow blocking', [['ON', 'LRE', 'R', 'ON', 'RLE', 'PDF', 'LRE', 'L', 'LRE', 'PDF', 'RLE', 'PDF', 'R', 'EN'], 0, 3], [[0, 'x', 2, 2, 'x', 'x', 'x', 2, 'x', 'x', 'x', 'x', 2, 2], ['ON', 'BN', 'R', 'ON', 'BN', 'BN', 'BN', 'L', 'BN', 'BN', 'BN', 'BN', 'R', 'EN']]), ('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', [['ON', 'LRE'], 0, 6], [[0, 'x'], ['ON', 'BN']]), ('control layout', [['R', 'ON', 'R', 'EN', 'R', 'PDF', 'PDF', 'LRE', 'EN', 'RLE'], 0, 5], [[0, 0, 0, 0, 0, 'x', 'x', 'x', 2, 'x'], ['R', 'ON', 'R', 'EN', 'R', 'BN', 'BN', 'BN', 'EN', 'BN']])], [('regression: overflow blocking', [['RLE', 'RLE', 'ON', 'RLO', 'LRE', 'LRE', 'R', 'RLE', 'R'], 1, 2], [['x', 'x', 1, 'x', 'x', 'x', 1, 'x', 1], ['BN', 'BN', 'ON', 'BN', 'BN', 'BN', 'R', 'BN', 'R']]), ('regression: overflow blocking', [['ON', 'RLE', 'PDF', 'R', 'RLE', 'LRE', 'ON', 'PDF', 'R', 'ON'], 1, 2], [[1, 'x', 'x', 1, 'x', 'x', 1, 'x', 1, 1], ['ON', 'BN', 'BN', 'R', 'BN', 'BN', 'ON', 'BN', 'R', 'ON']]), ('regression: overflow blocking', [['LRO', 'R', 'ON', 'EN', 'ON', 'LRE', 'RLE', 'L', 'ON', 'WS', 'ON', 'ON', 'RLE', 'WS'], 1, 3], [['x', 2, 2, 2, 2, 'x', 'x', 2, 2, 2, 2, 2, 'x', 2], ['BN', 'L', 'L', 'L', 'L', 'BN', 'BN', 'L', 'L', 'L', 'L', 'L', 'BN', 'L']]), ('regression: overflow blocking', [['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']]), ('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', [['RLE', 'L', 'LRO', 'RLE', 'L', 'R', 'L', 'R', 'RLE', 'L', 'LRO', 'L'], 0, 3], [['x', 1, 'x', 'x', 3, 3, 3, 3, 'x', 3, 'x', 3], ['BN', 'L', 'BN', 'BN', 'L', 'R', 'L', 'R', 'BN', 'L', 'BN', 'L']]), ('control layout', [['RLE', 'ON', 'LRO'], 0, 4], [['x', 1, 'x'], ['BN', 'ON', 'BN']])]]
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:
After an overflow, later shallower codes push levels that should be ignored.

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