broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import re
N = 1
observations = []
def solve(a, b, mode, strip_cr, ignore_blank):
    def norm(line):
        if strip_cr and line.endswith('\r'):
            line = line[:-1]
        if mode == 'w':
            return ''.join(line.split())
        if mode == 'b':
            return re.sub(r'[ \t]+', ' ', line).rstrip(' \t')
        return line
    ka = [norm(x) for x in a]
    kb = [norm(x) for x in b]
    if ignore_blank:
        ka = [x for x in ka if x.strip() != '']
        kb = [x for x in kb if x.strip() != '']
    return {'a': ka, 'b': kb, 'equal': ka == kb}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {
    1: [('amount of whitespace ignored', [['a  b', 'c\t\td  '], ['a b', 'c d'], 'b', False, False], {'a': ['a b', 'c d'], 'b': ['a b', 'c d'], 'equal': True}), ('leading whitespace presence matters under -b', [['  x'], ['x'], 'b', False, False], {'a': [' x'], 'b': ['x'], 'equal': False}), ('all whitespace ignored', [['a b c', ' \t'], ['abc', ''], 'w', False, False], {'a': ['abc', ''], 'b': ['abc', ''], 'equal': True}), ('carriage return stripped once', [['line\r', 'two\r\r'], ['line', 'two\r'], 'none', True, False], {'a': ['line', 'two\r'], 'b': ['line', 'two'], 'equal': False}), ('carriage return kept without the flag', [['cr\r'], ['cr'], 'b', False, False], {'a': ['cr\r'], 'b': ['cr'], 'equal': False}), ('interior carriage return is content', [['a\rb'], ['ab'], 'none', True, False], {'a': ['a\rb'], 'b': ['ab'], 'equal': False}), ('whitespace-only line is blank only when normalized empty', [['x', '   ', 'y'], ['x', 'y'], 'none', False, True], {'a': ['x', '   ', 'y'], 'b': ['x', 'y'], 'equal': False}), ('blank lines ignored under -w', [['x', ' \t ', 'y', ''], ['x', 'y'], 'w', False, True], {'a': ['x', 'y'], 'b': ['x', 'y'], 'equal': True}), ('tabs under -w', [['k\tv', 'q'], ['kv', 'q'], 'w', False, False], {'a': ['kv', 'q'], 'b': ['kv', 'q'], 'equal': True}), ('vertical tab under -w', [['m\x0bn'], ['mn'], 'w', False, False], {'a': ['mn'], 'b': ['mn'], 'equal': True})],
    2: [('amount of whitespace ignored', [['a  b', 'c\t\td  '], ['a b', 'c d'], 'b', False, False], {'a': ['a b', 'c d'], 'b': ['a b', 'c d'], 'equal': True}), ('leading whitespace presence matters under -b', [['  x'], ['x'], 'b', False, False], {'a': [' x'], 'b': ['x'], 'equal': False}), ('all whitespace ignored', [['a b c', ' \t'], ['abc', ''], 'w', False, False], {'a': ['abc', ''], 'b': ['abc', ''], 'equal': True}), ('carriage return stripped once', [['line\r', 'two\r\r'], ['line', 'two\r'], 'none', True, False], {'a': ['line', 'two\r'], 'b': ['line', 'two'], 'equal': False}), ('carriage return kept without the flag', [['cr\r'], ['cr'], 'b', False, False], {'a': ['cr\r'], 'b': ['cr'], 'equal': False}), ('interior carriage return is content', [['a\rb'], ['ab'], 'none', True, False], {'a': ['a\rb'], 'b': ['ab'], 'equal': False}), ('whitespace-only line is blank only when normalized empty', [['x', '   ', 'y'], ['x', 'y'], 'none', False, True], {'a': ['x', '   ', 'y'], 'b': ['x', 'y'], 'equal': False}), ('blank lines ignored under -w', [['x', ' \t ', 'y', '', ''], ['x', 'y'], 'w', False, True], {'a': ['x', 'y'], 'b': ['x', 'y'], 'equal': True}), ('tabs under -w', [['k\tv', 'q'], ['kv', 'q'], 'w', False, False], {'a': ['kv', 'q'], 'b': ['kv', 'q'], 'equal': True}), ('vertical tab under -w', [['m\x0bn'], ['mn'], 'w', False, False], {'a': ['mn'], 'b': ['mn'], 'equal': True})],
    3: [('amount of whitespace ignored', [['a  b', 'c\t\td  '], ['a b', 'c d'], 'b', False, False], {'a': ['a b', 'c d'], 'b': ['a b', 'c d'], 'equal': True}), ('leading whitespace presence matters under -b', [['  x'], ['x'], 'b', False, False], {'a': [' x'], 'b': ['x'], 'equal': False}), ('all whitespace ignored', [['a b c', ' \t'], ['abc', ''], 'w', False, False], {'a': ['abc', ''], 'b': ['abc', ''], 'equal': True}), ('carriage return stripped once', [['line\r', 'two\r\r'], ['line', 'two\r'], 'none', True, False], {'a': ['line', 'two\r'], 'b': ['line', 'two'], 'equal': False}), ('carriage return kept without the flag', [['cr\r'], ['cr'], 'b', False, False], {'a': ['cr\r'], 'b': ['cr'], 'equal': False}), ('interior carriage return is content', [['a\rb'], ['ab'], 'none', True, False], {'a': ['a\rb'], 'b': ['ab'], 'equal': False}), ('whitespace-only line is blank only when normalized empty', [['x', '   ', 'y'], ['x', 'y'], 'none', False, True], {'a': ['x', '   ', 'y'], 'b': ['x', 'y'], 'equal': False}), ('blank lines ignored under -w', [['x', ' \t ', 'y', '', '', ''], ['x', 'y'], 'w', False, True], {'a': ['x', 'y'], 'b': ['x', 'y'], 'equal': True}), ('tabs under -w', [['k\tv', 'q'], ['kv', 'q'], 'w', False, False], {'a': ['kv', 'q'], 'b': ['kv', 'q'], 'equal': True}), ('vertical tab under -w', [['m\x0bn'], ['mn'], 'w', False, False], {'a': ['mn'], 'b': ['mn'], 'equal': True})],
    4: [('amount of whitespace ignored', [['a  b', 'c\t\td  '], ['a b', 'c d'], 'b', False, False], {'a': ['a b', 'c d'], 'b': ['a b', 'c d'], 'equal': True}), ('leading whitespace presence matters under -b', [['  x'], ['x'], 'b', False, False], {'a': [' x'], 'b': ['x'], 'equal': False}), ('all whitespace ignored', [['a b c', ' \t'], ['abc', ''], 'w', False, False], {'a': ['abc', ''], 'b': ['abc', ''], 'equal': True}), ('carriage return stripped once', [['line\r', 'two\r\r'], ['line', 'two\r'], 'none', True, False], {'a': ['line', 'two\r'], 'b': ['line', 'two'], 'equal': False}), ('carriage return kept without the flag', [['cr\r'], ['cr'], 'b', False, False], {'a': ['cr\r'], 'b': ['cr'], 'equal': False}), ('interior carriage return is content', [['a\rb'], ['ab'], 'none', True, False], {'a': ['a\rb'], 'b': ['ab'], 'equal': False}), ('whitespace-only line is blank only when normalized empty', [['x', '   ', 'y'], ['x', 'y'], 'none', False, True], {'a': ['x', '   ', 'y'], 'b': ['x', 'y'], 'equal': False}), ('blank lines ignored under -w', [['x', ' \t ', 'y', '', '', '', ''], ['x', 'y'], 'w', False, True], {'a': ['x', 'y'], 'b': ['x', 'y'], 'equal': True}), ('tabs under -w', [['k\tv', 'q'], ['kv', 'q'], 'w', False, False], {'a': ['kv', 'q'], 'b': ['kv', 'q'], 'equal': True}), ('vertical tab under -w', [['m\x0bn'], ['mn'], 'w', False, False], {'a': ['mn'], 'b': ['mn'], 'equal': True})],
    5: [('amount of whitespace ignored', [['a  b', 'c\t\td  '], ['a b', 'c d'], 'b', False, False], {'a': ['a b', 'c d'], 'b': ['a b', 'c d'], 'equal': True}), ('leading whitespace presence matters under -b', [['  x'], ['x'], 'b', False, False], {'a': [' x'], 'b': ['x'], 'equal': False}), ('all whitespace ignored', [['a b c', ' \t'], ['abc', ''], 'w', False, False], {'a': ['abc', ''], 'b': ['abc', ''], 'equal': True}), ('carriage return stripped once', [['line\r', 'two\r\r'], ['line', 'two\r'], 'none', True, False], {'a': ['line', 'two\r'], 'b': ['line', 'two'], 'equal': False}), ('carriage return kept without the flag', [['cr\r'], ['cr'], 'b', False, False], {'a': ['cr\r'], 'b': ['cr'], 'equal': False}), ('interior carriage return is content', [['a\rb'], ['ab'], 'none', True, False], {'a': ['a\rb'], 'b': ['ab'], 'equal': False}), ('whitespace-only line is blank only when normalized empty', [['x', '   ', 'y'], ['x', 'y'], 'none', False, True], {'a': ['x', '   ', 'y'], 'b': ['x', 'y'], 'equal': False}), ('blank lines ignored under -w', [['x', ' \t ', 'y', '', '', '', '', ''], ['x', 'y'], 'w', False, True], {'a': ['x', 'y'], 'b': ['x', 'y'], 'equal': True}), ('tabs under -w', [['k\tv', 'q'], ['kv', 'q'], 'w', False, False], {'a': ['kv', 'q'], 'b': ['kv', 'q'], 'equal': True}), ('vertical tab under -w', [['m\x0bn'], ['mn'], 'w', False, False], {'a': ['mn'], 'b': ['mn'], 'equal': True})],
}[N]
for label, args, expected in cases:
    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 re
N = 1
observations = []
def solve(a, b, mode, strip_cr, ignore_blank):
    def norm(line):
        if strip_cr and line.endswith('\r'):
            line = line[:-1]
        if mode == 'w':
            return ''.join(line.split())
        if mode == 'b':
            return re.sub(r'[ \t]+', ' ', line).rstrip(' \t')
        return line
    ka = [norm(x) for x in a]
    kb = [norm(x) for x in b]
    if ignore_blank:
        ka = [k for k, x in zip(ka, a) if x != '']
        kb = [k for k, x in zip(kb, b) if x != '']
    return {'a': ka, 'b': kb, 'equal': ka == kb}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {
    1: [('amount of whitespace ignored', [['a  b', 'c\t\td  '], ['a b', 'c d'], 'b', False, False], {'a': ['a b', 'c d'], 'b': ['a b', 'c d'], 'equal': True}), ('leading whitespace presence matters under -b', [['  x'], ['x'], 'b', False, False], {'a': [' x'], 'b': ['x'], 'equal': False}), ('all whitespace ignored', [['a b c', ' \t'], ['abc', ''], 'w', False, False], {'a': ['abc', ''], 'b': ['abc', ''], 'equal': True}), ('carriage return stripped once', [['line\r', 'two\r\r'], ['line', 'two\r'], 'none', True, False], {'a': ['line', 'two\r'], 'b': ['line', 'two'], 'equal': False}), ('carriage return kept without the flag', [['cr\r'], ['cr'], 'b', False, False], {'a': ['cr\r'], 'b': ['cr'], 'equal': False}), ('interior carriage return is content', [['a\rb'], ['ab'], 'none', True, False], {'a': ['a\rb'], 'b': ['ab'], 'equal': False}), ('whitespace-only line is blank only when normalized empty', [['x', '   ', 'y'], ['x', 'y'], 'none', False, True], {'a': ['x', '   ', 'y'], 'b': ['x', 'y'], 'equal': False}), ('blank lines ignored under -w', [['x', ' \t ', 'y', ''], ['x', 'y'], 'w', False, True], {'a': ['x', 'y'], 'b': ['x', 'y'], 'equal': True}), ('tabs under -w', [['k\tv', 'q'], ['kv', 'q'], 'w', False, False], {'a': ['kv', 'q'], 'b': ['kv', 'q'], 'equal': True}), ('vertical tab under -w', [['m\x0bn'], ['mn'], 'w', False, False], {'a': ['mn'], 'b': ['mn'], 'equal': True})],
    2: [('amount of whitespace ignored', [['a  b', 'c\t\td  '], ['a b', 'c d'], 'b', False, False], {'a': ['a b', 'c d'], 'b': ['a b', 'c d'], 'equal': True}), ('leading whitespace presence matters under -b', [['  x'], ['x'], 'b', False, False], {'a': [' x'], 'b': ['x'], 'equal': False}), ('all whitespace ignored', [['a b c', ' \t'], ['abc', ''], 'w', False, False], {'a': ['abc', ''], 'b': ['abc', ''], 'equal': True}), ('carriage return stripped once', [['line\r', 'two\r\r'], ['line', 'two\r'], 'none', True, False], {'a': ['line', 'two\r'], 'b': ['line', 'two'], 'equal': False}), ('carriage return kept without the flag', [['cr\r'], ['cr'], 'b', False, False], {'a': ['cr\r'], 'b': ['cr'], 'equal': False}), ('interior carriage return is content', [['a\rb'], ['ab'], 'none', True, False], {'a': ['a\rb'], 'b': ['ab'], 'equal': False}), ('whitespace-only line is blank only when normalized empty', [['x', '   ', 'y'], ['x', 'y'], 'none', False, True], {'a': ['x', '   ', 'y'], 'b': ['x', 'y'], 'equal': False}), ('blank lines ignored under -w', [['x', ' \t ', 'y', '', ''], ['x', 'y'], 'w', False, True], {'a': ['x', 'y'], 'b': ['x', 'y'], 'equal': True}), ('tabs under -w', [['k\tv', 'q'], ['kv', 'q'], 'w', False, False], {'a': ['kv', 'q'], 'b': ['kv', 'q'], 'equal': True}), ('vertical tab under -w', [['m\x0bn'], ['mn'], 'w', False, False], {'a': ['mn'], 'b': ['mn'], 'equal': True})],
    3: [('amount of whitespace ignored', [['a  b', 'c\t\td  '], ['a b', 'c d'], 'b', False, False], {'a': ['a b', 'c d'], 'b': ['a b', 'c d'], 'equal': True}), ('leading whitespace presence matters under -b', [['  x'], ['x'], 'b', False, False], {'a': [' x'], 'b': ['x'], 'equal': False}), ('all whitespace ignored', [['a b c', ' \t'], ['abc', ''], 'w', False, False], {'a': ['abc', ''], 'b': ['abc', ''], 'equal': True}), ('carriage return stripped once', [['line\r', 'two\r\r'], ['line', 'two\r'], 'none', True, False], {'a': ['line', 'two\r'], 'b': ['line', 'two'], 'equal': False}), ('carriage return kept without the flag', [['cr\r'], ['cr'], 'b', False, False], {'a': ['cr\r'], 'b': ['cr'], 'equal': False}), ('interior carriage return is content', [['a\rb'], ['ab'], 'none', True, False], {'a': ['a\rb'], 'b': ['ab'], 'equal': False}), ('whitespace-only line is blank only when normalized empty', [['x', '   ', 'y'], ['x', 'y'], 'none', False, True], {'a': ['x', '   ', 'y'], 'b': ['x', 'y'], 'equal': False}), ('blank lines ignored under -w', [['x', ' \t ', 'y', '', '', ''], ['x', 'y'], 'w', False, True], {'a': ['x', 'y'], 'b': ['x', 'y'], 'equal': True}), ('tabs under -w', [['k\tv', 'q'], ['kv', 'q'], 'w', False, False], {'a': ['kv', 'q'], 'b': ['kv', 'q'], 'equal': True}), ('vertical tab under -w', [['m\x0bn'], ['mn'], 'w', False, False], {'a': ['mn'], 'b': ['mn'], 'equal': True})],
    4: [('amount of whitespace ignored', [['a  b', 'c\t\td  '], ['a b', 'c d'], 'b', False, False], {'a': ['a b', 'c d'], 'b': ['a b', 'c d'], 'equal': True}), ('leading whitespace presence matters under -b', [['  x'], ['x'], 'b', False, False], {'a': [' x'], 'b': ['x'], 'equal': False}), ('all whitespace ignored', [['a b c', ' \t'], ['abc', ''], 'w', False, False], {'a': ['abc', ''], 'b': ['abc', ''], 'equal': True}), ('carriage return stripped once', [['line\r', 'two\r\r'], ['line', 'two\r'], 'none', True, False], {'a': ['line', 'two\r'], 'b': ['line', 'two'], 'equal': False}), ('carriage return kept without the flag', [['cr\r'], ['cr'], 'b', False, False], {'a': ['cr\r'], 'b': ['cr'], 'equal': False}), ('interior carriage return is content', [['a\rb'], ['ab'], 'none', True, False], {'a': ['a\rb'], 'b': ['ab'], 'equal': False}), ('whitespace-only line is blank only when normalized empty', [['x', '   ', 'y'], ['x', 'y'], 'none', False, True], {'a': ['x', '   ', 'y'], 'b': ['x', 'y'], 'equal': False}), ('blank lines ignored under -w', [['x', ' \t ', 'y', '', '', '', ''], ['x', 'y'], 'w', False, True], {'a': ['x', 'y'], 'b': ['x', 'y'], 'equal': True}), ('tabs under -w', [['k\tv', 'q'], ['kv', 'q'], 'w', False, False], {'a': ['kv', 'q'], 'b': ['kv', 'q'], 'equal': True}), ('vertical tab under -w', [['m\x0bn'], ['mn'], 'w', False, False], {'a': ['mn'], 'b': ['mn'], 'equal': True})],
    5: [('amount of whitespace ignored', [['a  b', 'c\t\td  '], ['a b', 'c d'], 'b', False, False], {'a': ['a b', 'c d'], 'b': ['a b', 'c d'], 'equal': True}), ('leading whitespace presence matters under -b', [['  x'], ['x'], 'b', False, False], {'a': [' x'], 'b': ['x'], 'equal': False}), ('all whitespace ignored', [['a b c', ' \t'], ['abc', ''], 'w', False, False], {'a': ['abc', ''], 'b': ['abc', ''], 'equal': True}), ('carriage return stripped once', [['line\r', 'two\r\r'], ['line', 'two\r'], 'none', True, False], {'a': ['line', 'two\r'], 'b': ['line', 'two'], 'equal': False}), ('carriage return kept without the flag', [['cr\r'], ['cr'], 'b', False, False], {'a': ['cr\r'], 'b': ['cr'], 'equal': False}), ('interior carriage return is content', [['a\rb'], ['ab'], 'none', True, False], {'a': ['a\rb'], 'b': ['ab'], 'equal': False}), ('whitespace-only line is blank only when normalized empty', [['x', '   ', 'y'], ['x', 'y'], 'none', False, True], {'a': ['x', '   ', 'y'], 'b': ['x', 'y'], 'equal': False}), ('blank lines ignored under -w', [['x', ' \t ', 'y', '', '', '', '', ''], ['x', 'y'], 'w', False, True], {'a': ['x', 'y'], 'b': ['x', 'y'], 'equal': True}), ('tabs under -w', [['k\tv', 'q'], ['kv', 'q'], 'w', False, False], {'a': ['kv', 'q'], 'b': ['kv', 'q'], 'equal': True}), ('vertical tab under -w', [['m\x0bn'], ['mn'], 'w', False, False], {'a': ['mn'], 'b': ['mn'], 'equal': True})],
}[N]
for label, args, expected in cases:
    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:
Without a whitespace option, adding a line of spaces is ignored as a blank line.

Normalize each line: with strip_cr remove one trailing "\r"; mode "w" deletes all whitespace (str.split semantics); mode "b" collapses runs of spaces and tabs to one space and strips trailing spaces and tabs; mode "none" leaves the line. With ignore_blank, drop lines whose normalized key is empty. Return both key lists and whether they are equal.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import re
N = 1
observations = []
def solve(a, b, mode, strip_cr, ignore_blank):
    def norm(line):
        if strip_cr and line.endswith('\r'):
            line = line[:-1]
        if mode == 'w':
            return line.replace(' ', '')
        if mode == 'b':
            return re.sub(r'[ \t]+', ' ', line).rstrip(' \t')
        return line
    ka = [norm(x) for x in a]
    kb = [norm(x) for x in b]
    if ignore_blank:
        ka = [x for x in ka if x != '']
        kb = [x for x in kb if x != '']
    return {'a': ka, 'b': kb, 'equal': ka == kb}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {
    1: [('amount of whitespace ignored', [['a  b', 'c\t\td  '], ['a b', 'c d'], 'b', False, False], {'a': ['a b', 'c d'], 'b': ['a b', 'c d'], 'equal': True}), ('leading whitespace presence matters under -b', [['  x'], ['x'], 'b', False, False], {'a': [' x'], 'b': ['x'], 'equal': False}), ('all whitespace ignored', [['a b c', ' \t'], ['abc', ''], 'w', False, False], {'a': ['abc', ''], 'b': ['abc', ''], 'equal': True}), ('carriage return stripped once', [['line\r', 'two\r\r'], ['line', 'two\r'], 'none', True, False], {'a': ['line', 'two\r'], 'b': ['line', 'two'], 'equal': False}), ('carriage return kept without the flag', [['cr\r'], ['cr'], 'b', False, False], {'a': ['cr\r'], 'b': ['cr'], 'equal': False}), ('interior carriage return is content', [['a\rb'], ['ab'], 'none', True, False], {'a': ['a\rb'], 'b': ['ab'], 'equal': False}), ('whitespace-only line is blank only when normalized empty', [['x', '   ', 'y'], ['x', 'y'], 'none', False, True], {'a': ['x', '   ', 'y'], 'b': ['x', 'y'], 'equal': False}), ('blank lines ignored under -w', [['x', ' \t ', 'y', ''], ['x', 'y'], 'w', False, True], {'a': ['x', 'y'], 'b': ['x', 'y'], 'equal': True}), ('tabs under -w', [['k\tv', 'q'], ['kv', 'q'], 'w', False, False], {'a': ['kv', 'q'], 'b': ['kv', 'q'], 'equal': True}), ('vertical tab under -w', [['m\x0bn'], ['mn'], 'w', False, False], {'a': ['mn'], 'b': ['mn'], 'equal': True})],
    2: [('amount of whitespace ignored', [['a  b', 'c\t\td  '], ['a b', 'c d'], 'b', False, False], {'a': ['a b', 'c d'], 'b': ['a b', 'c d'], 'equal': True}), ('leading whitespace presence matters under -b', [['  x'], ['x'], 'b', False, False], {'a': [' x'], 'b': ['x'], 'equal': False}), ('all whitespace ignored', [['a b c', ' \t'], ['abc', ''], 'w', False, False], {'a': ['abc', ''], 'b': ['abc', ''], 'equal': True}), ('carriage return stripped once', [['line\r', 'two\r\r'], ['line', 'two\r'], 'none', True, False], {'a': ['line', 'two\r'], 'b': ['line', 'two'], 'equal': False}), ('carriage return kept without the flag', [['cr\r'], ['cr'], 'b', False, False], {'a': ['cr\r'], 'b': ['cr'], 'equal': False}), ('interior carriage return is content', [['a\rb'], ['ab'], 'none', True, False], {'a': ['a\rb'], 'b': ['ab'], 'equal': False}), ('whitespace-only line is blank only when normalized empty', [['x', '   ', 'y'], ['x', 'y'], 'none', False, True], {'a': ['x', '   ', 'y'], 'b': ['x', 'y'], 'equal': False}), ('blank lines ignored under -w', [['x', ' \t ', 'y', '', ''], ['x', 'y'], 'w', False, True], {'a': ['x', 'y'], 'b': ['x', 'y'], 'equal': True}), ('tabs under -w', [['k\tv', 'q'], ['kv', 'q'], 'w', False, False], {'a': ['kv', 'q'], 'b': ['kv', 'q'], 'equal': True}), ('vertical tab under -w', [['m\x0bn'], ['mn'], 'w', False, False], {'a': ['mn'], 'b': ['mn'], 'equal': True})],
    3: [('amount of whitespace ignored', [['a  b', 'c\t\td  '], ['a b', 'c d'], 'b', False, False], {'a': ['a b', 'c d'], 'b': ['a b', 'c d'], 'equal': True}), ('leading whitespace presence matters under -b', [['  x'], ['x'], 'b', False, False], {'a': [' x'], 'b': ['x'], 'equal': False}), ('all whitespace ignored', [['a b c', ' \t'], ['abc', ''], 'w', False, False], {'a': ['abc', ''], 'b': ['abc', ''], 'equal': True}), ('carriage return stripped once', [['line\r', 'two\r\r'], ['line', 'two\r'], 'none', True, False], {'a': ['line', 'two\r'], 'b': ['line', 'two'], 'equal': False}), ('carriage return kept without the flag', [['cr\r'], ['cr'], 'b', False, False], {'a': ['cr\r'], 'b': ['cr'], 'equal': False}), ('interior carriage return is content', [['a\rb'], ['ab'], 'none', True, False], {'a': ['a\rb'], 'b': ['ab'], 'equal': False}), ('whitespace-only line is blank only when normalized empty', [['x', '   ', 'y'], ['x', 'y'], 'none', False, True], {'a': ['x', '   ', 'y'], 'b': ['x', 'y'], 'equal': False}), ('blank lines ignored under -w', [['x', ' \t ', 'y', '', '', ''], ['x', 'y'], 'w', False, True], {'a': ['x', 'y'], 'b': ['x', 'y'], 'equal': True}), ('tabs under -w', [['k\tv', 'q'], ['kv', 'q'], 'w', False, False], {'a': ['kv', 'q'], 'b': ['kv', 'q'], 'equal': True}), ('vertical tab under -w', [['m\x0bn'], ['mn'], 'w', False, False], {'a': ['mn'], 'b': ['mn'], 'equal': True})],
    4: [('amount of whitespace ignored', [['a  b', 'c\t\td  '], ['a b', 'c d'], 'b', False, False], {'a': ['a b', 'c d'], 'b': ['a b', 'c d'], 'equal': True}), ('leading whitespace presence matters under -b', [['  x'], ['x'], 'b', False, False], {'a': [' x'], 'b': ['x'], 'equal': False}), ('all whitespace ignored', [['a b c', ' \t'], ['abc', ''], 'w', False, False], {'a': ['abc', ''], 'b': ['abc', ''], 'equal': True}), ('carriage return stripped once', [['line\r', 'two\r\r'], ['line', 'two\r'], 'none', True, False], {'a': ['line', 'two\r'], 'b': ['line', 'two'], 'equal': False}), ('carriage return kept without the flag', [['cr\r'], ['cr'], 'b', False, False], {'a': ['cr\r'], 'b': ['cr'], 'equal': False}), ('interior carriage return is content', [['a\rb'], ['ab'], 'none', True, False], {'a': ['a\rb'], 'b': ['ab'], 'equal': False}), ('whitespace-only line is blank only when normalized empty', [['x', '   ', 'y'], ['x', 'y'], 'none', False, True], {'a': ['x', '   ', 'y'], 'b': ['x', 'y'], 'equal': False}), ('blank lines ignored under -w', [['x', ' \t ', 'y', '', '', '', ''], ['x', 'y'], 'w', False, True], {'a': ['x', 'y'], 'b': ['x', 'y'], 'equal': True}), ('tabs under -w', [['k\tv', 'q'], ['kv', 'q'], 'w', False, False], {'a': ['kv', 'q'], 'b': ['kv', 'q'], 'equal': True}), ('vertical tab under -w', [['m\x0bn'], ['mn'], 'w', False, False], {'a': ['mn'], 'b': ['mn'], 'equal': True})],
    5: [('amount of whitespace ignored', [['a  b', 'c\t\td  '], ['a b', 'c d'], 'b', False, False], {'a': ['a b', 'c d'], 'b': ['a b', 'c d'], 'equal': True}), ('leading whitespace presence matters under -b', [['  x'], ['x'], 'b', False, False], {'a': [' x'], 'b': ['x'], 'equal': False}), ('all whitespace ignored', [['a b c', ' \t'], ['abc', ''], 'w', False, False], {'a': ['abc', ''], 'b': ['abc', ''], 'equal': True}), ('carriage return stripped once', [['line\r', 'two\r\r'], ['line', 'two\r'], 'none', True, False], {'a': ['line', 'two\r'], 'b': ['line', 'two'], 'equal': False}), ('carriage return kept without the flag', [['cr\r'], ['cr'], 'b', False, False], {'a': ['cr\r'], 'b': ['cr'], 'equal': False}), ('interior carriage return is content', [['a\rb'], ['ab'], 'none', True, False], {'a': ['a\rb'], 'b': ['ab'], 'equal': False}), ('whitespace-only line is blank only when normalized empty', [['x', '   ', 'y'], ['x', 'y'], 'none', False, True], {'a': ['x', '   ', 'y'], 'b': ['x', 'y'], 'equal': False}), ('blank lines ignored under -w', [['x', ' \t ', 'y', '', '', '', '', ''], ['x', 'y'], 'w', False, True], {'a': ['x', 'y'], 'b': ['x', 'y'], 'equal': True}), ('tabs under -w', [['k\tv', 'q'], ['kv', 'q'], 'w', False, False], {'a': ['kv', 'q'], 'b': ['kv', 'q'], 'equal': True}), ('vertical tab under -w', [['m\x0bn'], ['mn'], 'w', False, False], {'a': ['mn'], 'b': ['mn'], 'equal': True})],
}[N]
for label, args, expected in cases:
    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
import re
N = 1
observations = []
def solve(a, b, mode, strip_cr, ignore_blank):
    def norm(line):
        if strip_cr and line.endswith('\r'):
            line = line[:-1]
        if mode == 'w':
            return re.sub(r'[ \t]', '', line)
        if mode == 'b':
            return re.sub(r'[ \t]+', ' ', line).rstrip(' \t')
        return line
    ka = [norm(x) for x in a]
    kb = [norm(x) for x in b]
    if ignore_blank:
        ka = [x for x in ka if x != '']
        kb = [x for x in kb if x != '']
    return {'a': ka, 'b': kb, 'equal': ka == kb}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {
    1: [('amount of whitespace ignored', [['a  b', 'c\t\td  '], ['a b', 'c d'], 'b', False, False], {'a': ['a b', 'c d'], 'b': ['a b', 'c d'], 'equal': True}), ('leading whitespace presence matters under -b', [['  x'], ['x'], 'b', False, False], {'a': [' x'], 'b': ['x'], 'equal': False}), ('all whitespace ignored', [['a b c', ' \t'], ['abc', ''], 'w', False, False], {'a': ['abc', ''], 'b': ['abc', ''], 'equal': True}), ('carriage return stripped once', [['line\r', 'two\r\r'], ['line', 'two\r'], 'none', True, False], {'a': ['line', 'two\r'], 'b': ['line', 'two'], 'equal': False}), ('carriage return kept without the flag', [['cr\r'], ['cr'], 'b', False, False], {'a': ['cr\r'], 'b': ['cr'], 'equal': False}), ('interior carriage return is content', [['a\rb'], ['ab'], 'none', True, False], {'a': ['a\rb'], 'b': ['ab'], 'equal': False}), ('whitespace-only line is blank only when normalized empty', [['x', '   ', 'y'], ['x', 'y'], 'none', False, True], {'a': ['x', '   ', 'y'], 'b': ['x', 'y'], 'equal': False}), ('blank lines ignored under -w', [['x', ' \t ', 'y', ''], ['x', 'y'], 'w', False, True], {'a': ['x', 'y'], 'b': ['x', 'y'], 'equal': True}), ('tabs under -w', [['k\tv', 'q'], ['kv', 'q'], 'w', False, False], {'a': ['kv', 'q'], 'b': ['kv', 'q'], 'equal': True}), ('vertical tab under -w', [['m\x0bn'], ['mn'], 'w', False, False], {'a': ['mn'], 'b': ['mn'], 'equal': True})],
    2: [('amount of whitespace ignored', [['a  b', 'c\t\td  '], ['a b', 'c d'], 'b', False, False], {'a': ['a b', 'c d'], 'b': ['a b', 'c d'], 'equal': True}), ('leading whitespace presence matters under -b', [['  x'], ['x'], 'b', False, False], {'a': [' x'], 'b': ['x'], 'equal': False}), ('all whitespace ignored', [['a b c', ' \t'], ['abc', ''], 'w', False, False], {'a': ['abc', ''], 'b': ['abc', ''], 'equal': True}), ('carriage return stripped once', [['line\r', 'two\r\r'], ['line', 'two\r'], 'none', True, False], {'a': ['line', 'two\r'], 'b': ['line', 'two'], 'equal': False}), ('carriage return kept without the flag', [['cr\r'], ['cr'], 'b', False, False], {'a': ['cr\r'], 'b': ['cr'], 'equal': False}), ('interior carriage return is content', [['a\rb'], ['ab'], 'none', True, False], {'a': ['a\rb'], 'b': ['ab'], 'equal': False}), ('whitespace-only line is blank only when normalized empty', [['x', '   ', 'y'], ['x', 'y'], 'none', False, True], {'a': ['x', '   ', 'y'], 'b': ['x', 'y'], 'equal': False}), ('blank lines ignored under -w', [['x', ' \t ', 'y', '', ''], ['x', 'y'], 'w', False, True], {'a': ['x', 'y'], 'b': ['x', 'y'], 'equal': True}), ('tabs under -w', [['k\tv', 'q'], ['kv', 'q'], 'w', False, False], {'a': ['kv', 'q'], 'b': ['kv', 'q'], 'equal': True}), ('vertical tab under -w', [['m\x0bn'], ['mn'], 'w', False, False], {'a': ['mn'], 'b': ['mn'], 'equal': True})],
    3: [('amount of whitespace ignored', [['a  b', 'c\t\td  '], ['a b', 'c d'], 'b', False, False], {'a': ['a b', 'c d'], 'b': ['a b', 'c d'], 'equal': True}), ('leading whitespace presence matters under -b', [['  x'], ['x'], 'b', False, False], {'a': [' x'], 'b': ['x'], 'equal': False}), ('all whitespace ignored', [['a b c', ' \t'], ['abc', ''], 'w', False, False], {'a': ['abc', ''], 'b': ['abc', ''], 'equal': True}), ('carriage return stripped once', [['line\r', 'two\r\r'], ['line', 'two\r'], 'none', True, False], {'a': ['line', 'two\r'], 'b': ['line', 'two'], 'equal': False}), ('carriage return kept without the flag', [['cr\r'], ['cr'], 'b', False, False], {'a': ['cr\r'], 'b': ['cr'], 'equal': False}), ('interior carriage return is content', [['a\rb'], ['ab'], 'none', True, False], {'a': ['a\rb'], 'b': ['ab'], 'equal': False}), ('whitespace-only line is blank only when normalized empty', [['x', '   ', 'y'], ['x', 'y'], 'none', False, True], {'a': ['x', '   ', 'y'], 'b': ['x', 'y'], 'equal': False}), ('blank lines ignored under -w', [['x', ' \t ', 'y', '', '', ''], ['x', 'y'], 'w', False, True], {'a': ['x', 'y'], 'b': ['x', 'y'], 'equal': True}), ('tabs under -w', [['k\tv', 'q'], ['kv', 'q'], 'w', False, False], {'a': ['kv', 'q'], 'b': ['kv', 'q'], 'equal': True}), ('vertical tab under -w', [['m\x0bn'], ['mn'], 'w', False, False], {'a': ['mn'], 'b': ['mn'], 'equal': True})],
    4: [('amount of whitespace ignored', [['a  b', 'c\t\td  '], ['a b', 'c d'], 'b', False, False], {'a': ['a b', 'c d'], 'b': ['a b', 'c d'], 'equal': True}), ('leading whitespace presence matters under -b', [['  x'], ['x'], 'b', False, False], {'a': [' x'], 'b': ['x'], 'equal': False}), ('all whitespace ignored', [['a b c', ' \t'], ['abc', ''], 'w', False, False], {'a': ['abc', ''], 'b': ['abc', ''], 'equal': True}), ('carriage return stripped once', [['line\r', 'two\r\r'], ['line', 'two\r'], 'none', True, False], {'a': ['line', 'two\r'], 'b': ['line', 'two'], 'equal': False}), ('carriage return kept without the flag', [['cr\r'], ['cr'], 'b', False, False], {'a': ['cr\r'], 'b': ['cr'], 'equal': False}), ('interior carriage return is content', [['a\rb'], ['ab'], 'none', True, False], {'a': ['a\rb'], 'b': ['ab'], 'equal': False}), ('whitespace-only line is blank only when normalized empty', [['x', '   ', 'y'], ['x', 'y'], 'none', False, True], {'a': ['x', '   ', 'y'], 'b': ['x', 'y'], 'equal': False}), ('blank lines ignored under -w', [['x', ' \t ', 'y', '', '', '', ''], ['x', 'y'], 'w', False, True], {'a': ['x', 'y'], 'b': ['x', 'y'], 'equal': True}), ('tabs under -w', [['k\tv', 'q'], ['kv', 'q'], 'w', False, False], {'a': ['kv', 'q'], 'b': ['kv', 'q'], 'equal': True}), ('vertical tab under -w', [['m\x0bn'], ['mn'], 'w', False, False], {'a': ['mn'], 'b': ['mn'], 'equal': True})],
    5: [('amount of whitespace ignored', [['a  b', 'c\t\td  '], ['a b', 'c d'], 'b', False, False], {'a': ['a b', 'c d'], 'b': ['a b', 'c d'], 'equal': True}), ('leading whitespace presence matters under -b', [['  x'], ['x'], 'b', False, False], {'a': [' x'], 'b': ['x'], 'equal': False}), ('all whitespace ignored', [['a b c', ' \t'], ['abc', ''], 'w', False, False], {'a': ['abc', ''], 'b': ['abc', ''], 'equal': True}), ('carriage return stripped once', [['line\r', 'two\r\r'], ['line', 'two\r'], 'none', True, False], {'a': ['line', 'two\r'], 'b': ['line', 'two'], 'equal': False}), ('carriage return kept without the flag', [['cr\r'], ['cr'], 'b', False, False], {'a': ['cr\r'], 'b': ['cr'], 'equal': False}), ('interior carriage return is content', [['a\rb'], ['ab'], 'none', True, False], {'a': ['a\rb'], 'b': ['ab'], 'equal': False}), ('whitespace-only line is blank only when normalized empty', [['x', '   ', 'y'], ['x', 'y'], 'none', False, True], {'a': ['x', '   ', 'y'], 'b': ['x', 'y'], 'equal': False}), ('blank lines ignored under -w', [['x', ' \t ', 'y', '', '', '', '', ''], ['x', 'y'], 'w', False, True], {'a': ['x', 'y'], 'b': ['x', 'y'], 'equal': True}), ('tabs under -w', [['k\tv', 'q'], ['kv', 'q'], 'w', False, False], {'a': ['kv', 'q'], 'b': ['kv', 'q'], 'equal': True}), ('vertical tab under -w', [['m\x0bn'], ['mn'], 'w', False, False], {'a': ['mn'], 'b': ['mn'], 'equal': True})],
}[N]
for label, args, expected in cases:
    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:
Tab and other whitespace differences are still reported under -w.

Normalize each line: with strip_cr remove one trailing "\r"; mode "w" deletes all whitespace (str.split semantics); mode "b" collapses runs of spaces and tabs to one space and strips trailing spaces and tabs; mode "none" leaves the line. With ignore_blank, drop lines whose normalized key is empty. Return both key lists and whether they are equal.

split: open-access


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

N = 1
observations = []
def solve(diffs):
    res = []
    diffs = [list(d) for d in diffs if d[1] != '']
    i = 0
    while i < len(diffs):
        if diffs[i][0] == 0:
            if res and res[-1][0] == 0:
                res[-1][1] += diffs[i][1]
            else:
                res.append([0, diffs[i][1]])
            i += 1
            continue
        dl = ins = ''
        while i < len(diffs) and diffs[i][0] != 0:
            if diffs[i][0] == -1:
                dl += diffs[i][1]
            else:
                ins += diffs[i][1]
            i += 1
        suffix = ''
        if dl and ins:
            p = 0
            while p < min(len(dl), len(ins)) and dl[p] == ins[p]:
                p += 1
            if p:
                res.append([0, dl[:p]])
                dl, ins = dl[p:], ins[p:]
            s = 0
            while s < min(len(dl), len(ins)) and dl[-1 - s] == ins[-1 - s]:
                s += 1
            suffix = dl[len(dl) - s:]
            dl, ins = dl[:len(dl) - s], ins[:len(ins) - s]
        if dl:
            res.append([-1, dl])
        if ins:
            res.append([1, ins])
        if suffix:
            if i < len(diffs) and diffs[i][0] == 0:
                diffs[i] = [0, suffix + diffs[i][1]]
            else:
                res.append([0, suffix])
    return res
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {
    1: [('adjacent equalities merge', [[[0, 'ab'], [0, 'cd']]], [[0, 'abcd']]), ('empty entries are dropped', [[[0, 'a'], [-1, ''], [1, 'b'], [0, '']]], [[0, 'a'], [1, 'b']]), ('common prefix moves into the previous equality', [[[0, 'x'], [-1, 'abc'], [1, 'abd'], [0, 'y']]], [[0, 'xab'], [-1, 'c'], [1, 'd'], [0, 'y']]), ('common suffix moves into the next equality', [[[0, 'p'], [-1, 'kz'], [1, 'mz'], [0, 'q']]], [[0, 'p'], [-1, 'k'], [1, 'm'], [0, 'zq']]), ('no common affix', [[[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]], [[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]), ('interleaved edits are grouped deletion first', [[[1, 'I'], [-1, 'D'], [1, 'J'], [-1, 'E']]], [[-1, 'DE'], [1, 'IJ']]), ('suffix at the end of the text', [[[0, 'st'], [-1, 'xyz1'], [1, 'uvz1']]], [[0, 'st'], [-1, 'xy'], [1, 'uv'], [0, 'z1']]), ('prefix at the start of the text', [[[-1, 'prea'], [1, 'preb'], [0, 'tail']]], [[0, 'pre'], [-1, 'a'], [1, 'b'], [0, 'tail']]), ('insertion only', [[[0, 'a'], [1, 'b'], [0, 'c']]], [[0, 'a'], [1, 'b'], [0, 'c']]), ('empty equality between edits', [[[0, 'k'], [-1, 'ab1'], [0, ''], [1, 'ac1']]], [[0, 'ka'], [-1, 'b'], [1, 'c'], [0, '1']])],
    2: [('adjacent equalities merge', [[[0, 'ab'], [0, 'cd']]], [[0, 'abcd']]), ('empty entries are dropped', [[[0, 'a'], [-1, ''], [1, 'b'], [0, '']]], [[0, 'a'], [1, 'b']]), ('common prefix moves into the previous equality', [[[0, 'x'], [-1, 'abc'], [1, 'abd'], [0, 'y']]], [[0, 'xab'], [-1, 'c'], [1, 'd'], [0, 'y']]), ('common suffix moves into the next equality', [[[0, 'p'], [-1, 'kz'], [1, 'mz'], [0, 'q']]], [[0, 'p'], [-1, 'k'], [1, 'm'], [0, 'zq']]), ('no common affix', [[[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]], [[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]), ('interleaved edits are grouped deletion first', [[[1, 'I'], [-1, 'D'], [1, 'J'], [-1, 'E']]], [[-1, 'DE'], [1, 'IJ']]), ('suffix at the end of the text', [[[0, 'st'], [-1, 'xyz2'], [1, 'uvz2']]], [[0, 'st'], [-1, 'xy'], [1, 'uv'], [0, 'z2']]), ('prefix at the start of the text', [[[-1, 'preprea'], [1, 'prepreb'], [0, 'tail']]], [[0, 'prepre'], [-1, 'a'], [1, 'b'], [0, 'tail']]), ('insertion only', [[[0, 'a'], [1, 'b'], [0, 'c']]], [[0, 'a'], [1, 'b'], [0, 'c']]), ('empty equality between edits', [[[0, 'k'], [-1, 'ab2'], [0, ''], [1, 'ac2']]], [[0, 'ka'], [-1, 'b'], [1, 'c'], [0, '2']])],
    3: [('adjacent equalities merge', [[[0, 'ab'], [0, 'cd']]], [[0, 'abcd']]), ('empty entries are dropped', [[[0, 'a'], [-1, ''], [1, 'b'], [0, '']]], [[0, 'a'], [1, 'b']]), ('common prefix moves into the previous equality', [[[0, 'x'], [-1, 'abc'], [1, 'abd'], [0, 'y']]], [[0, 'xab'], [-1, 'c'], [1, 'd'], [0, 'y']]), ('common suffix moves into the next equality', [[[0, 'p'], [-1, 'kz'], [1, 'mz'], [0, 'q']]], [[0, 'p'], [-1, 'k'], [1, 'm'], [0, 'zq']]), ('no common affix', [[[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]], [[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]), ('interleaved edits are grouped deletion first', [[[1, 'I'], [-1, 'D'], [1, 'J'], [-1, 'E']]], [[-1, 'DE'], [1, 'IJ']]), ('suffix at the end of the text', [[[0, 'st'], [-1, 'xyz3'], [1, 'uvz3']]], [[0, 'st'], [-1, 'xy'], [1, 'uv'], [0, 'z3']]), ('prefix at the start of the text', [[[-1, 'prepreprea'], [1, 'preprepreb'], [0, 'tail']]], [[0, 'preprepre'], [-1, 'a'], [1, 'b'], [0, 'tail']]), ('insertion only', [[[0, 'a'], [1, 'b'], [0, 'c']]], [[0, 'a'], [1, 'b'], [0, 'c']]), ('empty equality between edits', [[[0, 'k'], [-1, 'ab3'], [0, ''], [1, 'ac3']]], [[0, 'ka'], [-1, 'b'], [1, 'c'], [0, '3']])],
    4: [('adjacent equalities merge', [[[0, 'ab'], [0, 'cd']]], [[0, 'abcd']]), ('empty entries are dropped', [[[0, 'a'], [-1, ''], [1, 'b'], [0, '']]], [[0, 'a'], [1, 'b']]), ('common prefix moves into the previous equality', [[[0, 'x'], [-1, 'abc'], [1, 'abd'], [0, 'y']]], [[0, 'xab'], [-1, 'c'], [1, 'd'], [0, 'y']]), ('common suffix moves into the next equality', [[[0, 'p'], [-1, 'kz'], [1, 'mz'], [0, 'q']]], [[0, 'p'], [-1, 'k'], [1, 'm'], [0, 'zq']]), ('no common affix', [[[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]], [[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]), ('interleaved edits are grouped deletion first', [[[1, 'I'], [-1, 'D'], [1, 'J'], [-1, 'E']]], [[-1, 'DE'], [1, 'IJ']]), ('suffix at the end of the text', [[[0, 'st'], [-1, 'xyz4'], [1, 'uvz4']]], [[0, 'st'], [-1, 'xy'], [1, 'uv'], [0, 'z4']]), ('prefix at the start of the text', [[[-1, 'preprepreprea'], [1, 'prepreprepreb'], [0, 'tail']]], [[0, 'prepreprepre'], [-1, 'a'], [1, 'b'], [0, 'tail']]), ('insertion only', [[[0, 'a'], [1, 'b'], [0, 'c']]], [[0, 'a'], [1, 'b'], [0, 'c']]), ('empty equality between edits', [[[0, 'k'], [-1, 'ab4'], [0, ''], [1, 'ac4']]], [[0, 'ka'], [-1, 'b'], [1, 'c'], [0, '4']])],
    5: [('adjacent equalities merge', [[[0, 'ab'], [0, 'cd']]], [[0, 'abcd']]), ('empty entries are dropped', [[[0, 'a'], [-1, ''], [1, 'b'], [0, '']]], [[0, 'a'], [1, 'b']]), ('common prefix moves into the previous equality', [[[0, 'x'], [-1, 'abc'], [1, 'abd'], [0, 'y']]], [[0, 'xab'], [-1, 'c'], [1, 'd'], [0, 'y']]), ('common suffix moves into the next equality', [[[0, 'p'], [-1, 'kz'], [1, 'mz'], [0, 'q']]], [[0, 'p'], [-1, 'k'], [1, 'm'], [0, 'zq']]), ('no common affix', [[[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]], [[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]), ('interleaved edits are grouped deletion first', [[[1, 'I'], [-1, 'D'], [1, 'J'], [-1, 'E']]], [[-1, 'DE'], [1, 'IJ']]), ('suffix at the end of the text', [[[0, 'st'], [-1, 'xyz5'], [1, 'uvz5']]], [[0, 'st'], [-1, 'xy'], [1, 'uv'], [0, 'z5']]), ('prefix at the start of the text', [[[-1, 'prepreprepreprea'], [1, 'preprepreprepreb'], [0, 'tail']]], [[0, 'preprepreprepre'], [-1, 'a'], [1, 'b'], [0, 'tail']]), ('insertion only', [[[0, 'a'], [1, 'b'], [0, 'c']]], [[0, 'a'], [1, 'b'], [0, 'c']]), ('empty equality between edits', [[[0, 'k'], [-1, 'ab5'], [0, ''], [1, 'ac5']]], [[0, 'ka'], [-1, 'b'], [1, 'c'], [0, '5']])],
}[N]
for label, args, expected in cases:
    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(diffs):
    res = []
    diffs = [list(d) for d in diffs if d[1] != '']
    i = 0
    while i < len(diffs):
        if diffs[i][0] == 0:
            if res and res[-1][0] == 0:
                res[-1][1] += diffs[i][1]
            else:
                res.append([0, diffs[i][1]])
            i += 1
            continue
        dl = ins = ''
        while i < len(diffs) and diffs[i][0] != 0:
            if diffs[i][0] == -1:
                dl += diffs[i][1]
            else:
                ins += diffs[i][1]
            i += 1
        suffix = ''
        if dl and ins:
            p = 0
            while p < min(len(dl), len(ins)) and dl[p] == ins[p]:
                p += 1
            if p:
                if res and res[-1][0] == 0:
                    res[-1][1] += dl[:p]
                else:
                    res.append([0, dl[:p]])
            s = 0
            while s < min(len(dl), len(ins)) and dl[-1 - s] == ins[-1 - s]:
                s += 1
            suffix = dl[len(dl) - s:]
            dl, ins = dl[:len(dl) - s], ins[:len(ins) - s]
        if dl:
            res.append([-1, dl])
        if ins:
            res.append([1, ins])
        if suffix:
            if i < len(diffs) and diffs[i][0] == 0:
                diffs[i] = [0, suffix + diffs[i][1]]
            else:
                res.append([0, suffix])
    return res
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {
    1: [('adjacent equalities merge', [[[0, 'ab'], [0, 'cd']]], [[0, 'abcd']]), ('empty entries are dropped', [[[0, 'a'], [-1, ''], [1, 'b'], [0, '']]], [[0, 'a'], [1, 'b']]), ('common prefix moves into the previous equality', [[[0, 'x'], [-1, 'abc'], [1, 'abd'], [0, 'y']]], [[0, 'xab'], [-1, 'c'], [1, 'd'], [0, 'y']]), ('common suffix moves into the next equality', [[[0, 'p'], [-1, 'kz'], [1, 'mz'], [0, 'q']]], [[0, 'p'], [-1, 'k'], [1, 'm'], [0, 'zq']]), ('no common affix', [[[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]], [[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]), ('interleaved edits are grouped deletion first', [[[1, 'I'], [-1, 'D'], [1, 'J'], [-1, 'E']]], [[-1, 'DE'], [1, 'IJ']]), ('suffix at the end of the text', [[[0, 'st'], [-1, 'xyz1'], [1, 'uvz1']]], [[0, 'st'], [-1, 'xy'], [1, 'uv'], [0, 'z1']]), ('prefix at the start of the text', [[[-1, 'prea'], [1, 'preb'], [0, 'tail']]], [[0, 'pre'], [-1, 'a'], [1, 'b'], [0, 'tail']]), ('insertion only', [[[0, 'a'], [1, 'b'], [0, 'c']]], [[0, 'a'], [1, 'b'], [0, 'c']]), ('empty equality between edits', [[[0, 'k'], [-1, 'ab1'], [0, ''], [1, 'ac1']]], [[0, 'ka'], [-1, 'b'], [1, 'c'], [0, '1']])],
    2: [('adjacent equalities merge', [[[0, 'ab'], [0, 'cd']]], [[0, 'abcd']]), ('empty entries are dropped', [[[0, 'a'], [-1, ''], [1, 'b'], [0, '']]], [[0, 'a'], [1, 'b']]), ('common prefix moves into the previous equality', [[[0, 'x'], [-1, 'abc'], [1, 'abd'], [0, 'y']]], [[0, 'xab'], [-1, 'c'], [1, 'd'], [0, 'y']]), ('common suffix moves into the next equality', [[[0, 'p'], [-1, 'kz'], [1, 'mz'], [0, 'q']]], [[0, 'p'], [-1, 'k'], [1, 'm'], [0, 'zq']]), ('no common affix', [[[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]], [[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]), ('interleaved edits are grouped deletion first', [[[1, 'I'], [-1, 'D'], [1, 'J'], [-1, 'E']]], [[-1, 'DE'], [1, 'IJ']]), ('suffix at the end of the text', [[[0, 'st'], [-1, 'xyz2'], [1, 'uvz2']]], [[0, 'st'], [-1, 'xy'], [1, 'uv'], [0, 'z2']]), ('prefix at the start of the text', [[[-1, 'preprea'], [1, 'prepreb'], [0, 'tail']]], [[0, 'prepre'], [-1, 'a'], [1, 'b'], [0, 'tail']]), ('insertion only', [[[0, 'a'], [1, 'b'], [0, 'c']]], [[0, 'a'], [1, 'b'], [0, 'c']]), ('empty equality between edits', [[[0, 'k'], [-1, 'ab2'], [0, ''], [1, 'ac2']]], [[0, 'ka'], [-1, 'b'], [1, 'c'], [0, '2']])],
    3: [('adjacent equalities merge', [[[0, 'ab'], [0, 'cd']]], [[0, 'abcd']]), ('empty entries are dropped', [[[0, 'a'], [-1, ''], [1, 'b'], [0, '']]], [[0, 'a'], [1, 'b']]), ('common prefix moves into the previous equality', [[[0, 'x'], [-1, 'abc'], [1, 'abd'], [0, 'y']]], [[0, 'xab'], [-1, 'c'], [1, 'd'], [0, 'y']]), ('common suffix moves into the next equality', [[[0, 'p'], [-1, 'kz'], [1, 'mz'], [0, 'q']]], [[0, 'p'], [-1, 'k'], [1, 'm'], [0, 'zq']]), ('no common affix', [[[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]], [[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]), ('interleaved edits are grouped deletion first', [[[1, 'I'], [-1, 'D'], [1, 'J'], [-1, 'E']]], [[-1, 'DE'], [1, 'IJ']]), ('suffix at the end of the text', [[[0, 'st'], [-1, 'xyz3'], [1, 'uvz3']]], [[0, 'st'], [-1, 'xy'], [1, 'uv'], [0, 'z3']]), ('prefix at the start of the text', [[[-1, 'prepreprea'], [1, 'preprepreb'], [0, 'tail']]], [[0, 'preprepre'], [-1, 'a'], [1, 'b'], [0, 'tail']]), ('insertion only', [[[0, 'a'], [1, 'b'], [0, 'c']]], [[0, 'a'], [1, 'b'], [0, 'c']]), ('empty equality between edits', [[[0, 'k'], [-1, 'ab3'], [0, ''], [1, 'ac3']]], [[0, 'ka'], [-1, 'b'], [1, 'c'], [0, '3']])],
    4: [('adjacent equalities merge', [[[0, 'ab'], [0, 'cd']]], [[0, 'abcd']]), ('empty entries are dropped', [[[0, 'a'], [-1, ''], [1, 'b'], [0, '']]], [[0, 'a'], [1, 'b']]), ('common prefix moves into the previous equality', [[[0, 'x'], [-1, 'abc'], [1, 'abd'], [0, 'y']]], [[0, 'xab'], [-1, 'c'], [1, 'd'], [0, 'y']]), ('common suffix moves into the next equality', [[[0, 'p'], [-1, 'kz'], [1, 'mz'], [0, 'q']]], [[0, 'p'], [-1, 'k'], [1, 'm'], [0, 'zq']]), ('no common affix', [[[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]], [[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]), ('interleaved edits are grouped deletion first', [[[1, 'I'], [-1, 'D'], [1, 'J'], [-1, 'E']]], [[-1, 'DE'], [1, 'IJ']]), ('suffix at the end of the text', [[[0, 'st'], [-1, 'xyz4'], [1, 'uvz4']]], [[0, 'st'], [-1, 'xy'], [1, 'uv'], [0, 'z4']]), ('prefix at the start of the text', [[[-1, 'preprepreprea'], [1, 'prepreprepreb'], [0, 'tail']]], [[0, 'prepreprepre'], [-1, 'a'], [1, 'b'], [0, 'tail']]), ('insertion only', [[[0, 'a'], [1, 'b'], [0, 'c']]], [[0, 'a'], [1, 'b'], [0, 'c']]), ('empty equality between edits', [[[0, 'k'], [-1, 'ab4'], [0, ''], [1, 'ac4']]], [[0, 'ka'], [-1, 'b'], [1, 'c'], [0, '4']])],
    5: [('adjacent equalities merge', [[[0, 'ab'], [0, 'cd']]], [[0, 'abcd']]), ('empty entries are dropped', [[[0, 'a'], [-1, ''], [1, 'b'], [0, '']]], [[0, 'a'], [1, 'b']]), ('common prefix moves into the previous equality', [[[0, 'x'], [-1, 'abc'], [1, 'abd'], [0, 'y']]], [[0, 'xab'], [-1, 'c'], [1, 'd'], [0, 'y']]), ('common suffix moves into the next equality', [[[0, 'p'], [-1, 'kz'], [1, 'mz'], [0, 'q']]], [[0, 'p'], [-1, 'k'], [1, 'm'], [0, 'zq']]), ('no common affix', [[[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]], [[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]), ('interleaved edits are grouped deletion first', [[[1, 'I'], [-1, 'D'], [1, 'J'], [-1, 'E']]], [[-1, 'DE'], [1, 'IJ']]), ('suffix at the end of the text', [[[0, 'st'], [-1, 'xyz5'], [1, 'uvz5']]], [[0, 'st'], [-1, 'xy'], [1, 'uv'], [0, 'z5']]), ('prefix at the start of the text', [[[-1, 'prepreprepreprea'], [1, 'preprepreprepreb'], [0, 'tail']]], [[0, 'preprepreprepre'], [-1, 'a'], [1, 'b'], [0, 'tail']]), ('insertion only', [[[0, 'a'], [1, 'b'], [0, 'c']]], [[0, 'a'], [1, 'b'], [0, 'c']]), ('empty equality between edits', [[[0, 'k'], [-1, 'ab5'], [0, ''], [1, 'ac5']]], [[0, 'ka'], [-1, 'b'], [1, 'c'], [0, '5']])],
}[N]
for label, args, expected in cases:
    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:
Two equalities sit next to each other after cleanup, so identical changes normalize differently.

Normalize a character diff of [op, text] (op -1 delete, 0 equal, 1 insert): drop empty texts, merge adjacent equalities, collect each run of edits into one deletion and one insertion (deletion first), move their common prefix into the preceding equality (creating one at the start if needed) and their common suffix into the following equality (appending one at the end if needed).

split: open-access


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

N = 1
observations = []
def solve(diffs):
    res = []
    diffs = [list(d) for d in diffs if d[1] != '']
    i = 0
    while i < len(diffs):
        if diffs[i][0] == 0:
            if res and res[-1][0] == 0:
                res[-1][1] += diffs[i][1]
            else:
                res.append([0, diffs[i][1]])
            i += 1
            continue
        dl = ins = ''
        while i < len(diffs) and diffs[i][0] != 0:
            if diffs[i][0] == -1:
                dl += diffs[i][1]
            else:
                ins += diffs[i][1]
            i += 1
        suffix = ''
        if dl and ins:
            p = 0
            while p < min(len(dl), len(ins)) and dl[p] == ins[p]:
                p += 1
            if p:
                if res and res[-1][0] == 0:
                    res[-1][1] += dl[:p]
                else:
                    res.append([0, dl[:p]])
                dl, ins = dl[p:], ins[p:]
            s = 0
            while s < min(len(dl), len(ins)) and dl[-1 - s] == ins[-1 - s]:
                s += 1
            suffix = dl[-s:]
            dl, ins = dl[:len(dl) - s], ins[:len(ins) - s]
        if dl:
            res.append([-1, dl])
        if ins:
            res.append([1, ins])
        if suffix:
            if i < len(diffs) and diffs[i][0] == 0:
                diffs[i] = [0, suffix + diffs[i][1]]
            else:
                res.append([0, suffix])
    return res
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {
    1: [('adjacent equalities merge', [[[0, 'ab'], [0, 'cd']]], [[0, 'abcd']]), ('empty entries are dropped', [[[0, 'a'], [-1, ''], [1, 'b'], [0, '']]], [[0, 'a'], [1, 'b']]), ('common prefix moves into the previous equality', [[[0, 'x'], [-1, 'abc'], [1, 'abd'], [0, 'y']]], [[0, 'xab'], [-1, 'c'], [1, 'd'], [0, 'y']]), ('common suffix moves into the next equality', [[[0, 'p'], [-1, 'kz'], [1, 'mz'], [0, 'q']]], [[0, 'p'], [-1, 'k'], [1, 'm'], [0, 'zq']]), ('no common affix', [[[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]], [[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]), ('interleaved edits are grouped deletion first', [[[1, 'I'], [-1, 'D'], [1, 'J'], [-1, 'E']]], [[-1, 'DE'], [1, 'IJ']]), ('suffix at the end of the text', [[[0, 'st'], [-1, 'xyz1'], [1, 'uvz1']]], [[0, 'st'], [-1, 'xy'], [1, 'uv'], [0, 'z1']]), ('prefix at the start of the text', [[[-1, 'prea'], [1, 'preb'], [0, 'tail']]], [[0, 'pre'], [-1, 'a'], [1, 'b'], [0, 'tail']]), ('insertion only', [[[0, 'a'], [1, 'b'], [0, 'c']]], [[0, 'a'], [1, 'b'], [0, 'c']]), ('empty equality between edits', [[[0, 'k'], [-1, 'ab1'], [0, ''], [1, 'ac1']]], [[0, 'ka'], [-1, 'b'], [1, 'c'], [0, '1']])],
    2: [('adjacent equalities merge', [[[0, 'ab'], [0, 'cd']]], [[0, 'abcd']]), ('empty entries are dropped', [[[0, 'a'], [-1, ''], [1, 'b'], [0, '']]], [[0, 'a'], [1, 'b']]), ('common prefix moves into the previous equality', [[[0, 'x'], [-1, 'abc'], [1, 'abd'], [0, 'y']]], [[0, 'xab'], [-1, 'c'], [1, 'd'], [0, 'y']]), ('common suffix moves into the next equality', [[[0, 'p'], [-1, 'kz'], [1, 'mz'], [0, 'q']]], [[0, 'p'], [-1, 'k'], [1, 'm'], [0, 'zq']]), ('no common affix', [[[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]], [[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]), ('interleaved edits are grouped deletion first', [[[1, 'I'], [-1, 'D'], [1, 'J'], [-1, 'E']]], [[-1, 'DE'], [1, 'IJ']]), ('suffix at the end of the text', [[[0, 'st'], [-1, 'xyz2'], [1, 'uvz2']]], [[0, 'st'], [-1, 'xy'], [1, 'uv'], [0, 'z2']]), ('prefix at the start of the text', [[[-1, 'preprea'], [1, 'prepreb'], [0, 'tail']]], [[0, 'prepre'], [-1, 'a'], [1, 'b'], [0, 'tail']]), ('insertion only', [[[0, 'a'], [1, 'b'], [0, 'c']]], [[0, 'a'], [1, 'b'], [0, 'c']]), ('empty equality between edits', [[[0, 'k'], [-1, 'ab2'], [0, ''], [1, 'ac2']]], [[0, 'ka'], [-1, 'b'], [1, 'c'], [0, '2']])],
    3: [('adjacent equalities merge', [[[0, 'ab'], [0, 'cd']]], [[0, 'abcd']]), ('empty entries are dropped', [[[0, 'a'], [-1, ''], [1, 'b'], [0, '']]], [[0, 'a'], [1, 'b']]), ('common prefix moves into the previous equality', [[[0, 'x'], [-1, 'abc'], [1, 'abd'], [0, 'y']]], [[0, 'xab'], [-1, 'c'], [1, 'd'], [0, 'y']]), ('common suffix moves into the next equality', [[[0, 'p'], [-1, 'kz'], [1, 'mz'], [0, 'q']]], [[0, 'p'], [-1, 'k'], [1, 'm'], [0, 'zq']]), ('no common affix', [[[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]], [[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]), ('interleaved edits are grouped deletion first', [[[1, 'I'], [-1, 'D'], [1, 'J'], [-1, 'E']]], [[-1, 'DE'], [1, 'IJ']]), ('suffix at the end of the text', [[[0, 'st'], [-1, 'xyz3'], [1, 'uvz3']]], [[0, 'st'], [-1, 'xy'], [1, 'uv'], [0, 'z3']]), ('prefix at the start of the text', [[[-1, 'prepreprea'], [1, 'preprepreb'], [0, 'tail']]], [[0, 'preprepre'], [-1, 'a'], [1, 'b'], [0, 'tail']]), ('insertion only', [[[0, 'a'], [1, 'b'], [0, 'c']]], [[0, 'a'], [1, 'b'], [0, 'c']]), ('empty equality between edits', [[[0, 'k'], [-1, 'ab3'], [0, ''], [1, 'ac3']]], [[0, 'ka'], [-1, 'b'], [1, 'c'], [0, '3']])],
    4: [('adjacent equalities merge', [[[0, 'ab'], [0, 'cd']]], [[0, 'abcd']]), ('empty entries are dropped', [[[0, 'a'], [-1, ''], [1, 'b'], [0, '']]], [[0, 'a'], [1, 'b']]), ('common prefix moves into the previous equality', [[[0, 'x'], [-1, 'abc'], [1, 'abd'], [0, 'y']]], [[0, 'xab'], [-1, 'c'], [1, 'd'], [0, 'y']]), ('common suffix moves into the next equality', [[[0, 'p'], [-1, 'kz'], [1, 'mz'], [0, 'q']]], [[0, 'p'], [-1, 'k'], [1, 'm'], [0, 'zq']]), ('no common affix', [[[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]], [[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]), ('interleaved edits are grouped deletion first', [[[1, 'I'], [-1, 'D'], [1, 'J'], [-1, 'E']]], [[-1, 'DE'], [1, 'IJ']]), ('suffix at the end of the text', [[[0, 'st'], [-1, 'xyz4'], [1, 'uvz4']]], [[0, 'st'], [-1, 'xy'], [1, 'uv'], [0, 'z4']]), ('prefix at the start of the text', [[[-1, 'preprepreprea'], [1, 'prepreprepreb'], [0, 'tail']]], [[0, 'prepreprepre'], [-1, 'a'], [1, 'b'], [0, 'tail']]), ('insertion only', [[[0, 'a'], [1, 'b'], [0, 'c']]], [[0, 'a'], [1, 'b'], [0, 'c']]), ('empty equality between edits', [[[0, 'k'], [-1, 'ab4'], [0, ''], [1, 'ac4']]], [[0, 'ka'], [-1, 'b'], [1, 'c'], [0, '4']])],
    5: [('adjacent equalities merge', [[[0, 'ab'], [0, 'cd']]], [[0, 'abcd']]), ('empty entries are dropped', [[[0, 'a'], [-1, ''], [1, 'b'], [0, '']]], [[0, 'a'], [1, 'b']]), ('common prefix moves into the previous equality', [[[0, 'x'], [-1, 'abc'], [1, 'abd'], [0, 'y']]], [[0, 'xab'], [-1, 'c'], [1, 'd'], [0, 'y']]), ('common suffix moves into the next equality', [[[0, 'p'], [-1, 'kz'], [1, 'mz'], [0, 'q']]], [[0, 'p'], [-1, 'k'], [1, 'm'], [0, 'zq']]), ('no common affix', [[[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]], [[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]), ('interleaved edits are grouped deletion first', [[[1, 'I'], [-1, 'D'], [1, 'J'], [-1, 'E']]], [[-1, 'DE'], [1, 'IJ']]), ('suffix at the end of the text', [[[0, 'st'], [-1, 'xyz5'], [1, 'uvz5']]], [[0, 'st'], [-1, 'xy'], [1, 'uv'], [0, 'z5']]), ('prefix at the start of the text', [[[-1, 'prepreprepreprea'], [1, 'preprepreprepreb'], [0, 'tail']]], [[0, 'preprepreprepre'], [-1, 'a'], [1, 'b'], [0, 'tail']]), ('insertion only', [[[0, 'a'], [1, 'b'], [0, 'c']]], [[0, 'a'], [1, 'b'], [0, 'c']]), ('empty equality between edits', [[[0, 'k'], [-1, 'ab5'], [0, ''], [1, 'ac5']]], [[0, 'ka'], [-1, 'b'], [1, 'c'], [0, '5']])],
}[N]
for label, args, expected in cases:
    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(diffs):
    res = []
    diffs = [list(d) for d in diffs if d[1] != '']
    i = 0
    while i < len(diffs):
        if diffs[i][0] == 0:
            if res and res[-1][0] == 0:
                res[-1][1] += diffs[i][1]
            else:
                res.append([0, diffs[i][1]])
            i += 1
            continue
        dl = ins = ''
        while i < len(diffs) and diffs[i][0] != 0:
            if diffs[i][0] == -1:
                dl += diffs[i][1]
            else:
                ins += diffs[i][1]
            i += 1
        suffix = ''
        if dl and ins:
            p = 0
            while p < min(len(dl), len(ins)) and dl[p] == ins[p]:
                p += 1
            if p:
                if res and res[-1][0] == 0:
                    res[-1][1] += dl[:p]
                else:
                    res.append([0, dl[:p]])
                dl, ins = dl[p:], ins[p:]
            s = 0
            while s < min(len(dl), len(ins)) and dl[-1 - s] == ins[-1 - s]:
                s += 1
            suffix = dl[-s:] if not dl else dl[len(dl) - s:] if s else dl[-1:]
            dl, ins = dl[:len(dl) - s], ins[:len(ins) - s]
        if dl:
            res.append([-1, dl])
        if ins:
            res.append([1, ins])
        if suffix:
            if i < len(diffs) and diffs[i][0] == 0:
                diffs[i] = [0, suffix + diffs[i][1]]
            else:
                res.append([0, suffix])
    return res
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {
    1: [('adjacent equalities merge', [[[0, 'ab'], [0, 'cd']]], [[0, 'abcd']]), ('empty entries are dropped', [[[0, 'a'], [-1, ''], [1, 'b'], [0, '']]], [[0, 'a'], [1, 'b']]), ('common prefix moves into the previous equality', [[[0, 'x'], [-1, 'abc'], [1, 'abd'], [0, 'y']]], [[0, 'xab'], [-1, 'c'], [1, 'd'], [0, 'y']]), ('common suffix moves into the next equality', [[[0, 'p'], [-1, 'kz'], [1, 'mz'], [0, 'q']]], [[0, 'p'], [-1, 'k'], [1, 'm'], [0, 'zq']]), ('no common affix', [[[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]], [[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]), ('interleaved edits are grouped deletion first', [[[1, 'I'], [-1, 'D'], [1, 'J'], [-1, 'E']]], [[-1, 'DE'], [1, 'IJ']]), ('suffix at the end of the text', [[[0, 'st'], [-1, 'xyz1'], [1, 'uvz1']]], [[0, 'st'], [-1, 'xy'], [1, 'uv'], [0, 'z1']]), ('prefix at the start of the text', [[[-1, 'prea'], [1, 'preb'], [0, 'tail']]], [[0, 'pre'], [-1, 'a'], [1, 'b'], [0, 'tail']]), ('insertion only', [[[0, 'a'], [1, 'b'], [0, 'c']]], [[0, 'a'], [1, 'b'], [0, 'c']]), ('empty equality between edits', [[[0, 'k'], [-1, 'ab1'], [0, ''], [1, 'ac1']]], [[0, 'ka'], [-1, 'b'], [1, 'c'], [0, '1']])],
    2: [('adjacent equalities merge', [[[0, 'ab'], [0, 'cd']]], [[0, 'abcd']]), ('empty entries are dropped', [[[0, 'a'], [-1, ''], [1, 'b'], [0, '']]], [[0, 'a'], [1, 'b']]), ('common prefix moves into the previous equality', [[[0, 'x'], [-1, 'abc'], [1, 'abd'], [0, 'y']]], [[0, 'xab'], [-1, 'c'], [1, 'd'], [0, 'y']]), ('common suffix moves into the next equality', [[[0, 'p'], [-1, 'kz'], [1, 'mz'], [0, 'q']]], [[0, 'p'], [-1, 'k'], [1, 'm'], [0, 'zq']]), ('no common affix', [[[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]], [[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]), ('interleaved edits are grouped deletion first', [[[1, 'I'], [-1, 'D'], [1, 'J'], [-1, 'E']]], [[-1, 'DE'], [1, 'IJ']]), ('suffix at the end of the text', [[[0, 'st'], [-1, 'xyz2'], [1, 'uvz2']]], [[0, 'st'], [-1, 'xy'], [1, 'uv'], [0, 'z2']]), ('prefix at the start of the text', [[[-1, 'preprea'], [1, 'prepreb'], [0, 'tail']]], [[0, 'prepre'], [-1, 'a'], [1, 'b'], [0, 'tail']]), ('insertion only', [[[0, 'a'], [1, 'b'], [0, 'c']]], [[0, 'a'], [1, 'b'], [0, 'c']]), ('empty equality between edits', [[[0, 'k'], [-1, 'ab2'], [0, ''], [1, 'ac2']]], [[0, 'ka'], [-1, 'b'], [1, 'c'], [0, '2']])],
    3: [('adjacent equalities merge', [[[0, 'ab'], [0, 'cd']]], [[0, 'abcd']]), ('empty entries are dropped', [[[0, 'a'], [-1, ''], [1, 'b'], [0, '']]], [[0, 'a'], [1, 'b']]), ('common prefix moves into the previous equality', [[[0, 'x'], [-1, 'abc'], [1, 'abd'], [0, 'y']]], [[0, 'xab'], [-1, 'c'], [1, 'd'], [0, 'y']]), ('common suffix moves into the next equality', [[[0, 'p'], [-1, 'kz'], [1, 'mz'], [0, 'q']]], [[0, 'p'], [-1, 'k'], [1, 'm'], [0, 'zq']]), ('no common affix', [[[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]], [[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]), ('interleaved edits are grouped deletion first', [[[1, 'I'], [-1, 'D'], [1, 'J'], [-1, 'E']]], [[-1, 'DE'], [1, 'IJ']]), ('suffix at the end of the text', [[[0, 'st'], [-1, 'xyz3'], [1, 'uvz3']]], [[0, 'st'], [-1, 'xy'], [1, 'uv'], [0, 'z3']]), ('prefix at the start of the text', [[[-1, 'prepreprea'], [1, 'preprepreb'], [0, 'tail']]], [[0, 'preprepre'], [-1, 'a'], [1, 'b'], [0, 'tail']]), ('insertion only', [[[0, 'a'], [1, 'b'], [0, 'c']]], [[0, 'a'], [1, 'b'], [0, 'c']]), ('empty equality between edits', [[[0, 'k'], [-1, 'ab3'], [0, ''], [1, 'ac3']]], [[0, 'ka'], [-1, 'b'], [1, 'c'], [0, '3']])],
    4: [('adjacent equalities merge', [[[0, 'ab'], [0, 'cd']]], [[0, 'abcd']]), ('empty entries are dropped', [[[0, 'a'], [-1, ''], [1, 'b'], [0, '']]], [[0, 'a'], [1, 'b']]), ('common prefix moves into the previous equality', [[[0, 'x'], [-1, 'abc'], [1, 'abd'], [0, 'y']]], [[0, 'xab'], [-1, 'c'], [1, 'd'], [0, 'y']]), ('common suffix moves into the next equality', [[[0, 'p'], [-1, 'kz'], [1, 'mz'], [0, 'q']]], [[0, 'p'], [-1, 'k'], [1, 'm'], [0, 'zq']]), ('no common affix', [[[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]], [[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]), ('interleaved edits are grouped deletion first', [[[1, 'I'], [-1, 'D'], [1, 'J'], [-1, 'E']]], [[-1, 'DE'], [1, 'IJ']]), ('suffix at the end of the text', [[[0, 'st'], [-1, 'xyz4'], [1, 'uvz4']]], [[0, 'st'], [-1, 'xy'], [1, 'uv'], [0, 'z4']]), ('prefix at the start of the text', [[[-1, 'preprepreprea'], [1, 'prepreprepreb'], [0, 'tail']]], [[0, 'prepreprepre'], [-1, 'a'], [1, 'b'], [0, 'tail']]), ('insertion only', [[[0, 'a'], [1, 'b'], [0, 'c']]], [[0, 'a'], [1, 'b'], [0, 'c']]), ('empty equality between edits', [[[0, 'k'], [-1, 'ab4'], [0, ''], [1, 'ac4']]], [[0, 'ka'], [-1, 'b'], [1, 'c'], [0, '4']])],
    5: [('adjacent equalities merge', [[[0, 'ab'], [0, 'cd']]], [[0, 'abcd']]), ('empty entries are dropped', [[[0, 'a'], [-1, ''], [1, 'b'], [0, '']]], [[0, 'a'], [1, 'b']]), ('common prefix moves into the previous equality', [[[0, 'x'], [-1, 'abc'], [1, 'abd'], [0, 'y']]], [[0, 'xab'], [-1, 'c'], [1, 'd'], [0, 'y']]), ('common suffix moves into the next equality', [[[0, 'p'], [-1, 'kz'], [1, 'mz'], [0, 'q']]], [[0, 'p'], [-1, 'k'], [1, 'm'], [0, 'zq']]), ('no common affix', [[[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]], [[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]), ('interleaved edits are grouped deletion first', [[[1, 'I'], [-1, 'D'], [1, 'J'], [-1, 'E']]], [[-1, 'DE'], [1, 'IJ']]), ('suffix at the end of the text', [[[0, 'st'], [-1, 'xyz5'], [1, 'uvz5']]], [[0, 'st'], [-1, 'xy'], [1, 'uv'], [0, 'z5']]), ('prefix at the start of the text', [[[-1, 'prepreprepreprea'], [1, 'preprepreprepreb'], [0, 'tail']]], [[0, 'preprepreprepre'], [-1, 'a'], [1, 'b'], [0, 'tail']]), ('insertion only', [[[0, 'a'], [1, 'b'], [0, 'c']]], [[0, 'a'], [1, 'b'], [0, 'c']]), ('empty equality between edits', [[[0, 'k'], [-1, 'ab5'], [0, ''], [1, 'ac5']]], [[0, 'ka'], [-1, 'b'], [1, 'c'], [0, '5']])],
}[N]
for label, args, expected in cases:
    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:
Edits without a common suffix duplicate their deleted text into the next equality.

Normalize a character diff of [op, text] (op -1 delete, 0 equal, 1 insert): drop empty texts, merge adjacent equalities, collect each run of edits into one deletion and one insertion (deletion first), move their common prefix into the preceding equality (creating one at the start if needed) and their common suffix into the following equality (appending one at the end if needed).

split: open-access


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

N = 1
observations = []
def solve(diffs):
    res = []
    diffs = [list(d) for d in diffs]
    i = 0
    while i < len(diffs):
        if diffs[i][0] == 0:
            if res and res[-1][0] == 0:
                res[-1][1] += diffs[i][1]
            else:
                res.append([0, diffs[i][1]])
            i += 1
            continue
        dl = ins = ''
        while i < len(diffs) and diffs[i][0] != 0:
            if diffs[i][0] == -1:
                dl += diffs[i][1]
            else:
                ins += diffs[i][1]
            i += 1
        suffix = ''
        if dl and ins:
            p = 0
            while p < min(len(dl), len(ins)) and dl[p] == ins[p]:
                p += 1
            if p:
                if res and res[-1][0] == 0:
                    res[-1][1] += dl[:p]
                else:
                    res.append([0, dl[:p]])
                dl, ins = dl[p:], ins[p:]
            s = 0
            while s < min(len(dl), len(ins)) and dl[-1 - s] == ins[-1 - s]:
                s += 1
            suffix = dl[len(dl) - s:]
            dl, ins = dl[:len(dl) - s], ins[:len(ins) - s]
        if dl:
            res.append([-1, dl])
        if ins:
            res.append([1, ins])
        if suffix:
            if i < len(diffs) and diffs[i][0] == 0:
                diffs[i] = [0, suffix + diffs[i][1]]
            else:
                res.append([0, suffix])
    return res
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {
    1: [('adjacent equalities merge', [[[0, 'ab'], [0, 'cd']]], [[0, 'abcd']]), ('empty entries are dropped', [[[0, 'a'], [-1, ''], [1, 'b'], [0, '']]], [[0, 'a'], [1, 'b']]), ('common prefix moves into the previous equality', [[[0, 'x'], [-1, 'abc'], [1, 'abd'], [0, 'y']]], [[0, 'xab'], [-1, 'c'], [1, 'd'], [0, 'y']]), ('common suffix moves into the next equality', [[[0, 'p'], [-1, 'kz'], [1, 'mz'], [0, 'q']]], [[0, 'p'], [-1, 'k'], [1, 'm'], [0, 'zq']]), ('no common affix', [[[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]], [[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]), ('interleaved edits are grouped deletion first', [[[1, 'I'], [-1, 'D'], [1, 'J'], [-1, 'E']]], [[-1, 'DE'], [1, 'IJ']]), ('suffix at the end of the text', [[[0, 'st'], [-1, 'xyz1'], [1, 'uvz1']]], [[0, 'st'], [-1, 'xy'], [1, 'uv'], [0, 'z1']]), ('prefix at the start of the text', [[[-1, 'prea'], [1, 'preb'], [0, 'tail']]], [[0, 'pre'], [-1, 'a'], [1, 'b'], [0, 'tail']]), ('insertion only', [[[0, 'a'], [1, 'b'], [0, 'c']]], [[0, 'a'], [1, 'b'], [0, 'c']]), ('empty equality between edits', [[[0, 'k'], [-1, 'ab1'], [0, ''], [1, 'ac1']]], [[0, 'ka'], [-1, 'b'], [1, 'c'], [0, '1']])],
    2: [('adjacent equalities merge', [[[0, 'ab'], [0, 'cd']]], [[0, 'abcd']]), ('empty entries are dropped', [[[0, 'a'], [-1, ''], [1, 'b'], [0, '']]], [[0, 'a'], [1, 'b']]), ('common prefix moves into the previous equality', [[[0, 'x'], [-1, 'abc'], [1, 'abd'], [0, 'y']]], [[0, 'xab'], [-1, 'c'], [1, 'd'], [0, 'y']]), ('common suffix moves into the next equality', [[[0, 'p'], [-1, 'kz'], [1, 'mz'], [0, 'q']]], [[0, 'p'], [-1, 'k'], [1, 'm'], [0, 'zq']]), ('no common affix', [[[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]], [[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]), ('interleaved edits are grouped deletion first', [[[1, 'I'], [-1, 'D'], [1, 'J'], [-1, 'E']]], [[-1, 'DE'], [1, 'IJ']]), ('suffix at the end of the text', [[[0, 'st'], [-1, 'xyz2'], [1, 'uvz2']]], [[0, 'st'], [-1, 'xy'], [1, 'uv'], [0, 'z2']]), ('prefix at the start of the text', [[[-1, 'preprea'], [1, 'prepreb'], [0, 'tail']]], [[0, 'prepre'], [-1, 'a'], [1, 'b'], [0, 'tail']]), ('insertion only', [[[0, 'a'], [1, 'b'], [0, 'c']]], [[0, 'a'], [1, 'b'], [0, 'c']]), ('empty equality between edits', [[[0, 'k'], [-1, 'ab2'], [0, ''], [1, 'ac2']]], [[0, 'ka'], [-1, 'b'], [1, 'c'], [0, '2']])],
    3: [('adjacent equalities merge', [[[0, 'ab'], [0, 'cd']]], [[0, 'abcd']]), ('empty entries are dropped', [[[0, 'a'], [-1, ''], [1, 'b'], [0, '']]], [[0, 'a'], [1, 'b']]), ('common prefix moves into the previous equality', [[[0, 'x'], [-1, 'abc'], [1, 'abd'], [0, 'y']]], [[0, 'xab'], [-1, 'c'], [1, 'd'], [0, 'y']]), ('common suffix moves into the next equality', [[[0, 'p'], [-1, 'kz'], [1, 'mz'], [0, 'q']]], [[0, 'p'], [-1, 'k'], [1, 'm'], [0, 'zq']]), ('no common affix', [[[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]], [[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]), ('interleaved edits are grouped deletion first', [[[1, 'I'], [-1, 'D'], [1, 'J'], [-1, 'E']]], [[-1, 'DE'], [1, 'IJ']]), ('suffix at the end of the text', [[[0, 'st'], [-1, 'xyz3'], [1, 'uvz3']]], [[0, 'st'], [-1, 'xy'], [1, 'uv'], [0, 'z3']]), ('prefix at the start of the text', [[[-1, 'prepreprea'], [1, 'preprepreb'], [0, 'tail']]], [[0, 'preprepre'], [-1, 'a'], [1, 'b'], [0, 'tail']]), ('insertion only', [[[0, 'a'], [1, 'b'], [0, 'c']]], [[0, 'a'], [1, 'b'], [0, 'c']]), ('empty equality between edits', [[[0, 'k'], [-1, 'ab3'], [0, ''], [1, 'ac3']]], [[0, 'ka'], [-1, 'b'], [1, 'c'], [0, '3']])],
    4: [('adjacent equalities merge', [[[0, 'ab'], [0, 'cd']]], [[0, 'abcd']]), ('empty entries are dropped', [[[0, 'a'], [-1, ''], [1, 'b'], [0, '']]], [[0, 'a'], [1, 'b']]), ('common prefix moves into the previous equality', [[[0, 'x'], [-1, 'abc'], [1, 'abd'], [0, 'y']]], [[0, 'xab'], [-1, 'c'], [1, 'd'], [0, 'y']]), ('common suffix moves into the next equality', [[[0, 'p'], [-1, 'kz'], [1, 'mz'], [0, 'q']]], [[0, 'p'], [-1, 'k'], [1, 'm'], [0, 'zq']]), ('no common affix', [[[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]], [[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]), ('interleaved edits are grouped deletion first', [[[1, 'I'], [-1, 'D'], [1, 'J'], [-1, 'E']]], [[-1, 'DE'], [1, 'IJ']]), ('suffix at the end of the text', [[[0, 'st'], [-1, 'xyz4'], [1, 'uvz4']]], [[0, 'st'], [-1, 'xy'], [1, 'uv'], [0, 'z4']]), ('prefix at the start of the text', [[[-1, 'preprepreprea'], [1, 'prepreprepreb'], [0, 'tail']]], [[0, 'prepreprepre'], [-1, 'a'], [1, 'b'], [0, 'tail']]), ('insertion only', [[[0, 'a'], [1, 'b'], [0, 'c']]], [[0, 'a'], [1, 'b'], [0, 'c']]), ('empty equality between edits', [[[0, 'k'], [-1, 'ab4'], [0, ''], [1, 'ac4']]], [[0, 'ka'], [-1, 'b'], [1, 'c'], [0, '4']])],
    5: [('adjacent equalities merge', [[[0, 'ab'], [0, 'cd']]], [[0, 'abcd']]), ('empty entries are dropped', [[[0, 'a'], [-1, ''], [1, 'b'], [0, '']]], [[0, 'a'], [1, 'b']]), ('common prefix moves into the previous equality', [[[0, 'x'], [-1, 'abc'], [1, 'abd'], [0, 'y']]], [[0, 'xab'], [-1, 'c'], [1, 'd'], [0, 'y']]), ('common suffix moves into the next equality', [[[0, 'p'], [-1, 'kz'], [1, 'mz'], [0, 'q']]], [[0, 'p'], [-1, 'k'], [1, 'm'], [0, 'zq']]), ('no common affix', [[[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]], [[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]), ('interleaved edits are grouped deletion first', [[[1, 'I'], [-1, 'D'], [1, 'J'], [-1, 'E']]], [[-1, 'DE'], [1, 'IJ']]), ('suffix at the end of the text', [[[0, 'st'], [-1, 'xyz5'], [1, 'uvz5']]], [[0, 'st'], [-1, 'xy'], [1, 'uv'], [0, 'z5']]), ('prefix at the start of the text', [[[-1, 'prepreprepreprea'], [1, 'preprepreprepreb'], [0, 'tail']]], [[0, 'preprepreprepre'], [-1, 'a'], [1, 'b'], [0, 'tail']]), ('insertion only', [[[0, 'a'], [1, 'b'], [0, 'c']]], [[0, 'a'], [1, 'b'], [0, 'c']]), ('empty equality between edits', [[[0, 'k'], [-1, 'ab5'], [0, ''], [1, 'ac5']]], [[0, 'ka'], [-1, 'b'], [1, 'c'], [0, '5']])],
}[N]
for label, args, expected in cases:
    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(diffs):
    res = []
    diffs = [list(d) for d in diffs if d[1] != '' or d[0] == 0]
    i = 0
    while i < len(diffs):
        if diffs[i][0] == 0:
            if res and res[-1][0] == 0:
                res[-1][1] += diffs[i][1]
            else:
                res.append([0, diffs[i][1]])
            i += 1
            continue
        dl = ins = ''
        while i < len(diffs) and diffs[i][0] != 0:
            if diffs[i][0] == -1:
                dl += diffs[i][1]
            else:
                ins += diffs[i][1]
            i += 1
        suffix = ''
        if dl and ins:
            p = 0
            while p < min(len(dl), len(ins)) and dl[p] == ins[p]:
                p += 1
            if p:
                if res and res[-1][0] == 0:
                    res[-1][1] += dl[:p]
                else:
                    res.append([0, dl[:p]])
                dl, ins = dl[p:], ins[p:]
            s = 0
            while s < min(len(dl), len(ins)) and dl[-1 - s] == ins[-1 - s]:
                s += 1
            suffix = dl[len(dl) - s:]
            dl, ins = dl[:len(dl) - s], ins[:len(ins) - s]
        if dl:
            res.append([-1, dl])
        if ins:
            res.append([1, ins])
        if suffix:
            if i < len(diffs) and diffs[i][0] == 0:
                diffs[i] = [0, suffix + diffs[i][1]]
            else:
                res.append([0, suffix])
    return res
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {
    1: [('adjacent equalities merge', [[[0, 'ab'], [0, 'cd']]], [[0, 'abcd']]), ('empty entries are dropped', [[[0, 'a'], [-1, ''], [1, 'b'], [0, '']]], [[0, 'a'], [1, 'b']]), ('common prefix moves into the previous equality', [[[0, 'x'], [-1, 'abc'], [1, 'abd'], [0, 'y']]], [[0, 'xab'], [-1, 'c'], [1, 'd'], [0, 'y']]), ('common suffix moves into the next equality', [[[0, 'p'], [-1, 'kz'], [1, 'mz'], [0, 'q']]], [[0, 'p'], [-1, 'k'], [1, 'm'], [0, 'zq']]), ('no common affix', [[[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]], [[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]), ('interleaved edits are grouped deletion first', [[[1, 'I'], [-1, 'D'], [1, 'J'], [-1, 'E']]], [[-1, 'DE'], [1, 'IJ']]), ('suffix at the end of the text', [[[0, 'st'], [-1, 'xyz1'], [1, 'uvz1']]], [[0, 'st'], [-1, 'xy'], [1, 'uv'], [0, 'z1']]), ('prefix at the start of the text', [[[-1, 'prea'], [1, 'preb'], [0, 'tail']]], [[0, 'pre'], [-1, 'a'], [1, 'b'], [0, 'tail']]), ('insertion only', [[[0, 'a'], [1, 'b'], [0, 'c']]], [[0, 'a'], [1, 'b'], [0, 'c']]), ('empty equality between edits', [[[0, 'k'], [-1, 'ab1'], [0, ''], [1, 'ac1']]], [[0, 'ka'], [-1, 'b'], [1, 'c'], [0, '1']])],
    2: [('adjacent equalities merge', [[[0, 'ab'], [0, 'cd']]], [[0, 'abcd']]), ('empty entries are dropped', [[[0, 'a'], [-1, ''], [1, 'b'], [0, '']]], [[0, 'a'], [1, 'b']]), ('common prefix moves into the previous equality', [[[0, 'x'], [-1, 'abc'], [1, 'abd'], [0, 'y']]], [[0, 'xab'], [-1, 'c'], [1, 'd'], [0, 'y']]), ('common suffix moves into the next equality', [[[0, 'p'], [-1, 'kz'], [1, 'mz'], [0, 'q']]], [[0, 'p'], [-1, 'k'], [1, 'm'], [0, 'zq']]), ('no common affix', [[[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]], [[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]), ('interleaved edits are grouped deletion first', [[[1, 'I'], [-1, 'D'], [1, 'J'], [-1, 'E']]], [[-1, 'DE'], [1, 'IJ']]), ('suffix at the end of the text', [[[0, 'st'], [-1, 'xyz2'], [1, 'uvz2']]], [[0, 'st'], [-1, 'xy'], [1, 'uv'], [0, 'z2']]), ('prefix at the start of the text', [[[-1, 'preprea'], [1, 'prepreb'], [0, 'tail']]], [[0, 'prepre'], [-1, 'a'], [1, 'b'], [0, 'tail']]), ('insertion only', [[[0, 'a'], [1, 'b'], [0, 'c']]], [[0, 'a'], [1, 'b'], [0, 'c']]), ('empty equality between edits', [[[0, 'k'], [-1, 'ab2'], [0, ''], [1, 'ac2']]], [[0, 'ka'], [-1, 'b'], [1, 'c'], [0, '2']])],
    3: [('adjacent equalities merge', [[[0, 'ab'], [0, 'cd']]], [[0, 'abcd']]), ('empty entries are dropped', [[[0, 'a'], [-1, ''], [1, 'b'], [0, '']]], [[0, 'a'], [1, 'b']]), ('common prefix moves into the previous equality', [[[0, 'x'], [-1, 'abc'], [1, 'abd'], [0, 'y']]], [[0, 'xab'], [-1, 'c'], [1, 'd'], [0, 'y']]), ('common suffix moves into the next equality', [[[0, 'p'], [-1, 'kz'], [1, 'mz'], [0, 'q']]], [[0, 'p'], [-1, 'k'], [1, 'm'], [0, 'zq']]), ('no common affix', [[[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]], [[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]), ('interleaved edits are grouped deletion first', [[[1, 'I'], [-1, 'D'], [1, 'J'], [-1, 'E']]], [[-1, 'DE'], [1, 'IJ']]), ('suffix at the end of the text', [[[0, 'st'], [-1, 'xyz3'], [1, 'uvz3']]], [[0, 'st'], [-1, 'xy'], [1, 'uv'], [0, 'z3']]), ('prefix at the start of the text', [[[-1, 'prepreprea'], [1, 'preprepreb'], [0, 'tail']]], [[0, 'preprepre'], [-1, 'a'], [1, 'b'], [0, 'tail']]), ('insertion only', [[[0, 'a'], [1, 'b'], [0, 'c']]], [[0, 'a'], [1, 'b'], [0, 'c']]), ('empty equality between edits', [[[0, 'k'], [-1, 'ab3'], [0, ''], [1, 'ac3']]], [[0, 'ka'], [-1, 'b'], [1, 'c'], [0, '3']])],
    4: [('adjacent equalities merge', [[[0, 'ab'], [0, 'cd']]], [[0, 'abcd']]), ('empty entries are dropped', [[[0, 'a'], [-1, ''], [1, 'b'], [0, '']]], [[0, 'a'], [1, 'b']]), ('common prefix moves into the previous equality', [[[0, 'x'], [-1, 'abc'], [1, 'abd'], [0, 'y']]], [[0, 'xab'], [-1, 'c'], [1, 'd'], [0, 'y']]), ('common suffix moves into the next equality', [[[0, 'p'], [-1, 'kz'], [1, 'mz'], [0, 'q']]], [[0, 'p'], [-1, 'k'], [1, 'm'], [0, 'zq']]), ('no common affix', [[[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]], [[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]), ('interleaved edits are grouped deletion first', [[[1, 'I'], [-1, 'D'], [1, 'J'], [-1, 'E']]], [[-1, 'DE'], [1, 'IJ']]), ('suffix at the end of the text', [[[0, 'st'], [-1, 'xyz4'], [1, 'uvz4']]], [[0, 'st'], [-1, 'xy'], [1, 'uv'], [0, 'z4']]), ('prefix at the start of the text', [[[-1, 'preprepreprea'], [1, 'prepreprepreb'], [0, 'tail']]], [[0, 'prepreprepre'], [-1, 'a'], [1, 'b'], [0, 'tail']]), ('insertion only', [[[0, 'a'], [1, 'b'], [0, 'c']]], [[0, 'a'], [1, 'b'], [0, 'c']]), ('empty equality between edits', [[[0, 'k'], [-1, 'ab4'], [0, ''], [1, 'ac4']]], [[0, 'ka'], [-1, 'b'], [1, 'c'], [0, '4']])],
    5: [('adjacent equalities merge', [[[0, 'ab'], [0, 'cd']]], [[0, 'abcd']]), ('empty entries are dropped', [[[0, 'a'], [-1, ''], [1, 'b'], [0, '']]], [[0, 'a'], [1, 'b']]), ('common prefix moves into the previous equality', [[[0, 'x'], [-1, 'abc'], [1, 'abd'], [0, 'y']]], [[0, 'xab'], [-1, 'c'], [1, 'd'], [0, 'y']]), ('common suffix moves into the next equality', [[[0, 'p'], [-1, 'kz'], [1, 'mz'], [0, 'q']]], [[0, 'p'], [-1, 'k'], [1, 'm'], [0, 'zq']]), ('no common affix', [[[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]], [[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]), ('interleaved edits are grouped deletion first', [[[1, 'I'], [-1, 'D'], [1, 'J'], [-1, 'E']]], [[-1, 'DE'], [1, 'IJ']]), ('suffix at the end of the text', [[[0, 'st'], [-1, 'xyz5'], [1, 'uvz5']]], [[0, 'st'], [-1, 'xy'], [1, 'uv'], [0, 'z5']]), ('prefix at the start of the text', [[[-1, 'prepreprepreprea'], [1, 'preprepreprepreb'], [0, 'tail']]], [[0, 'preprepreprepre'], [-1, 'a'], [1, 'b'], [0, 'tail']]), ('insertion only', [[[0, 'a'], [1, 'b'], [0, 'c']]], [[0, 'a'], [1, 'b'], [0, 'c']]), ('empty equality between edits', [[[0, 'k'], [-1, 'ab5'], [0, ''], [1, 'ac5']]], [[0, 'ka'], [-1, 'b'], [1, 'c'], [0, '5']])],
}[N]
for label, args, expected in cases:
    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:
Normalized diffs contain empty equalities that split merges and render as nothing.

Normalize a character diff of [op, text] (op -1 delete, 0 equal, 1 insert): drop empty texts, merge adjacent equalities, collect each run of edits into one deletion and one insertion (deletion first), move their common prefix into the preceding equality (creating one at the start if needed) and their common suffix into the following equality (appending one at the end if needed).

split: open-access


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

N = 1
observations = []
def solve(diffs):
    res = []
    diffs = [list(d) for d in diffs if d[1] != '']
    i = 0
    while i < len(diffs):
        if diffs[i][0] == 0:
            if res and res[-1][0] == 0:
                res[-1][1] += diffs[i][1]
            else:
                res.append([0, diffs[i][1]])
            i += 1
            continue
        dl = ins = ''
        while i < len(diffs) and diffs[i][0] != 0:
            if diffs[i][0] == -1:
                dl += diffs[i][1]
            else:
                ins += diffs[i][1]
            i += 1
        suffix = ''
        if dl and ins:
            p = 0
            while p < min(len(dl), len(ins)) and dl[p] == ins[p]:
                p += 1
            if p:
                if res and res[-1][0] == 0:
                    res[-1][1] += dl[:p]
                else:
                    res.append([0, dl[:p]])
                dl, ins = dl[p:], ins[p:]
            s = 0
            while s < min(len(dl), len(ins)) and dl[-1 - s] == ins[-1 - s]:
                s += 1
            suffix = dl[len(dl) - s:]
            dl, ins = dl[:len(dl) - s], ins[:len(ins) - s]
        if ins:
            res.append([1, ins])
        if dl:
            res.append([-1, dl])
        if suffix:
            if i < len(diffs) and diffs[i][0] == 0:
                diffs[i] = [0, suffix + diffs[i][1]]
            else:
                res.append([0, suffix])
    return res
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {
    1: [('adjacent equalities merge', [[[0, 'ab'], [0, 'cd']]], [[0, 'abcd']]), ('empty entries are dropped', [[[0, 'a'], [-1, ''], [1, 'b'], [0, '']]], [[0, 'a'], [1, 'b']]), ('common prefix moves into the previous equality', [[[0, 'x'], [-1, 'abc'], [1, 'abd'], [0, 'y']]], [[0, 'xab'], [-1, 'c'], [1, 'd'], [0, 'y']]), ('common suffix moves into the next equality', [[[0, 'p'], [-1, 'kz'], [1, 'mz'], [0, 'q']]], [[0, 'p'], [-1, 'k'], [1, 'm'], [0, 'zq']]), ('no common affix', [[[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]], [[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]), ('interleaved edits are grouped deletion first', [[[1, 'I'], [-1, 'D'], [1, 'J'], [-1, 'E']]], [[-1, 'DE'], [1, 'IJ']]), ('suffix at the end of the text', [[[0, 'st'], [-1, 'xyz1'], [1, 'uvz1']]], [[0, 'st'], [-1, 'xy'], [1, 'uv'], [0, 'z1']]), ('prefix at the start of the text', [[[-1, 'prea'], [1, 'preb'], [0, 'tail']]], [[0, 'pre'], [-1, 'a'], [1, 'b'], [0, 'tail']]), ('insertion only', [[[0, 'a'], [1, 'b'], [0, 'c']]], [[0, 'a'], [1, 'b'], [0, 'c']]), ('empty equality between edits', [[[0, 'k'], [-1, 'ab1'], [0, ''], [1, 'ac1']]], [[0, 'ka'], [-1, 'b'], [1, 'c'], [0, '1']])],
    2: [('adjacent equalities merge', [[[0, 'ab'], [0, 'cd']]], [[0, 'abcd']]), ('empty entries are dropped', [[[0, 'a'], [-1, ''], [1, 'b'], [0, '']]], [[0, 'a'], [1, 'b']]), ('common prefix moves into the previous equality', [[[0, 'x'], [-1, 'abc'], [1, 'abd'], [0, 'y']]], [[0, 'xab'], [-1, 'c'], [1, 'd'], [0, 'y']]), ('common suffix moves into the next equality', [[[0, 'p'], [-1, 'kz'], [1, 'mz'], [0, 'q']]], [[0, 'p'], [-1, 'k'], [1, 'm'], [0, 'zq']]), ('no common affix', [[[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]], [[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]), ('interleaved edits are grouped deletion first', [[[1, 'I'], [-1, 'D'], [1, 'J'], [-1, 'E']]], [[-1, 'DE'], [1, 'IJ']]), ('suffix at the end of the text', [[[0, 'st'], [-1, 'xyz2'], [1, 'uvz2']]], [[0, 'st'], [-1, 'xy'], [1, 'uv'], [0, 'z2']]), ('prefix at the start of the text', [[[-1, 'preprea'], [1, 'prepreb'], [0, 'tail']]], [[0, 'prepre'], [-1, 'a'], [1, 'b'], [0, 'tail']]), ('insertion only', [[[0, 'a'], [1, 'b'], [0, 'c']]], [[0, 'a'], [1, 'b'], [0, 'c']]), ('empty equality between edits', [[[0, 'k'], [-1, 'ab2'], [0, ''], [1, 'ac2']]], [[0, 'ka'], [-1, 'b'], [1, 'c'], [0, '2']])],
    3: [('adjacent equalities merge', [[[0, 'ab'], [0, 'cd']]], [[0, 'abcd']]), ('empty entries are dropped', [[[0, 'a'], [-1, ''], [1, 'b'], [0, '']]], [[0, 'a'], [1, 'b']]), ('common prefix moves into the previous equality', [[[0, 'x'], [-1, 'abc'], [1, 'abd'], [0, 'y']]], [[0, 'xab'], [-1, 'c'], [1, 'd'], [0, 'y']]), ('common suffix moves into the next equality', [[[0, 'p'], [-1, 'kz'], [1, 'mz'], [0, 'q']]], [[0, 'p'], [-1, 'k'], [1, 'm'], [0, 'zq']]), ('no common affix', [[[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]], [[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]), ('interleaved edits are grouped deletion first', [[[1, 'I'], [-1, 'D'], [1, 'J'], [-1, 'E']]], [[-1, 'DE'], [1, 'IJ']]), ('suffix at the end of the text', [[[0, 'st'], [-1, 'xyz3'], [1, 'uvz3']]], [[0, 'st'], [-1, 'xy'], [1, 'uv'], [0, 'z3']]), ('prefix at the start of the text', [[[-1, 'prepreprea'], [1, 'preprepreb'], [0, 'tail']]], [[0, 'preprepre'], [-1, 'a'], [1, 'b'], [0, 'tail']]), ('insertion only', [[[0, 'a'], [1, 'b'], [0, 'c']]], [[0, 'a'], [1, 'b'], [0, 'c']]), ('empty equality between edits', [[[0, 'k'], [-1, 'ab3'], [0, ''], [1, 'ac3']]], [[0, 'ka'], [-1, 'b'], [1, 'c'], [0, '3']])],
    4: [('adjacent equalities merge', [[[0, 'ab'], [0, 'cd']]], [[0, 'abcd']]), ('empty entries are dropped', [[[0, 'a'], [-1, ''], [1, 'b'], [0, '']]], [[0, 'a'], [1, 'b']]), ('common prefix moves into the previous equality', [[[0, 'x'], [-1, 'abc'], [1, 'abd'], [0, 'y']]], [[0, 'xab'], [-1, 'c'], [1, 'd'], [0, 'y']]), ('common suffix moves into the next equality', [[[0, 'p'], [-1, 'kz'], [1, 'mz'], [0, 'q']]], [[0, 'p'], [-1, 'k'], [1, 'm'], [0, 'zq']]), ('no common affix', [[[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]], [[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]), ('interleaved edits are grouped deletion first', [[[1, 'I'], [-1, 'D'], [1, 'J'], [-1, 'E']]], [[-1, 'DE'], [1, 'IJ']]), ('suffix at the end of the text', [[[0, 'st'], [-1, 'xyz4'], [1, 'uvz4']]], [[0, 'st'], [-1, 'xy'], [1, 'uv'], [0, 'z4']]), ('prefix at the start of the text', [[[-1, 'preprepreprea'], [1, 'prepreprepreb'], [0, 'tail']]], [[0, 'prepreprepre'], [-1, 'a'], [1, 'b'], [0, 'tail']]), ('insertion only', [[[0, 'a'], [1, 'b'], [0, 'c']]], [[0, 'a'], [1, 'b'], [0, 'c']]), ('empty equality between edits', [[[0, 'k'], [-1, 'ab4'], [0, ''], [1, 'ac4']]], [[0, 'ka'], [-1, 'b'], [1, 'c'], [0, '4']])],
    5: [('adjacent equalities merge', [[[0, 'ab'], [0, 'cd']]], [[0, 'abcd']]), ('empty entries are dropped', [[[0, 'a'], [-1, ''], [1, 'b'], [0, '']]], [[0, 'a'], [1, 'b']]), ('common prefix moves into the previous equality', [[[0, 'x'], [-1, 'abc'], [1, 'abd'], [0, 'y']]], [[0, 'xab'], [-1, 'c'], [1, 'd'], [0, 'y']]), ('common suffix moves into the next equality', [[[0, 'p'], [-1, 'kz'], [1, 'mz'], [0, 'q']]], [[0, 'p'], [-1, 'k'], [1, 'm'], [0, 'zq']]), ('no common affix', [[[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]], [[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]), ('interleaved edits are grouped deletion first', [[[1, 'I'], [-1, 'D'], [1, 'J'], [-1, 'E']]], [[-1, 'DE'], [1, 'IJ']]), ('suffix at the end of the text', [[[0, 'st'], [-1, 'xyz5'], [1, 'uvz5']]], [[0, 'st'], [-1, 'xy'], [1, 'uv'], [0, 'z5']]), ('prefix at the start of the text', [[[-1, 'prepreprepreprea'], [1, 'preprepreprepreb'], [0, 'tail']]], [[0, 'preprepreprepre'], [-1, 'a'], [1, 'b'], [0, 'tail']]), ('insertion only', [[[0, 'a'], [1, 'b'], [0, 'c']]], [[0, 'a'], [1, 'b'], [0, 'c']]), ('empty equality between edits', [[[0, 'k'], [-1, 'ab5'], [0, ''], [1, 'ac5']]], [[0, 'ka'], [-1, 'b'], [1, 'c'], [0, '5']])],
}[N]
for label, args, expected in cases:
    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(diffs):
    res = []
    diffs = [list(d) for d in diffs if d[1] != '']
    i = 0
    while i < len(diffs):
        if diffs[i][0] == 0:
            if res and res[-1][0] == 0:
                res[-1][1] += diffs[i][1]
            else:
                res.append([0, diffs[i][1]])
            i += 1
            continue
        dl = ins = ''
        while i < len(diffs) and diffs[i][0] != 0:
            if diffs[i][0] == -1:
                dl += diffs[i][1]
            else:
                ins += diffs[i][1]
            i += 1
        suffix = ''
        if dl and ins:
            p = 0
            while p < min(len(dl), len(ins)) and dl[p] == ins[p]:
                p += 1
            if p:
                if res and res[-1][0] == 0:
                    res[-1][1] += dl[:p]
                else:
                    res.append([0, dl[:p]])
                dl, ins = dl[p:], ins[p:]
            s = 0
            while s < min(len(dl), len(ins)) and dl[-1 - s] == ins[-1 - s]:
                s += 1
            suffix = dl[len(dl) - s:]
            dl, ins = dl[:len(dl) - s], ins[:len(ins) - s]
        res.extend(sorted([x for x in ([-1, dl], [1, ins]) if x[1]], key=lambda d: d[1]))
        if suffix:
            if i < len(diffs) and diffs[i][0] == 0:
                diffs[i] = [0, suffix + diffs[i][1]]
            else:
                res.append([0, suffix])
    return res
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {
    1: [('adjacent equalities merge', [[[0, 'ab'], [0, 'cd']]], [[0, 'abcd']]), ('empty entries are dropped', [[[0, 'a'], [-1, ''], [1, 'b'], [0, '']]], [[0, 'a'], [1, 'b']]), ('common prefix moves into the previous equality', [[[0, 'x'], [-1, 'abc'], [1, 'abd'], [0, 'y']]], [[0, 'xab'], [-1, 'c'], [1, 'd'], [0, 'y']]), ('common suffix moves into the next equality', [[[0, 'p'], [-1, 'kz'], [1, 'mz'], [0, 'q']]], [[0, 'p'], [-1, 'k'], [1, 'm'], [0, 'zq']]), ('no common affix', [[[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]], [[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]), ('interleaved edits are grouped deletion first', [[[1, 'I'], [-1, 'D'], [1, 'J'], [-1, 'E']]], [[-1, 'DE'], [1, 'IJ']]), ('suffix at the end of the text', [[[0, 'st'], [-1, 'xyz1'], [1, 'uvz1']]], [[0, 'st'], [-1, 'xy'], [1, 'uv'], [0, 'z1']]), ('prefix at the start of the text', [[[-1, 'prea'], [1, 'preb'], [0, 'tail']]], [[0, 'pre'], [-1, 'a'], [1, 'b'], [0, 'tail']]), ('insertion only', [[[0, 'a'], [1, 'b'], [0, 'c']]], [[0, 'a'], [1, 'b'], [0, 'c']]), ('empty equality between edits', [[[0, 'k'], [-1, 'ab1'], [0, ''], [1, 'ac1']]], [[0, 'ka'], [-1, 'b'], [1, 'c'], [0, '1']])],
    2: [('adjacent equalities merge', [[[0, 'ab'], [0, 'cd']]], [[0, 'abcd']]), ('empty entries are dropped', [[[0, 'a'], [-1, ''], [1, 'b'], [0, '']]], [[0, 'a'], [1, 'b']]), ('common prefix moves into the previous equality', [[[0, 'x'], [-1, 'abc'], [1, 'abd'], [0, 'y']]], [[0, 'xab'], [-1, 'c'], [1, 'd'], [0, 'y']]), ('common suffix moves into the next equality', [[[0, 'p'], [-1, 'kz'], [1, 'mz'], [0, 'q']]], [[0, 'p'], [-1, 'k'], [1, 'm'], [0, 'zq']]), ('no common affix', [[[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]], [[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]), ('interleaved edits are grouped deletion first', [[[1, 'I'], [-1, 'D'], [1, 'J'], [-1, 'E']]], [[-1, 'DE'], [1, 'IJ']]), ('suffix at the end of the text', [[[0, 'st'], [-1, 'xyz2'], [1, 'uvz2']]], [[0, 'st'], [-1, 'xy'], [1, 'uv'], [0, 'z2']]), ('prefix at the start of the text', [[[-1, 'preprea'], [1, 'prepreb'], [0, 'tail']]], [[0, 'prepre'], [-1, 'a'], [1, 'b'], [0, 'tail']]), ('insertion only', [[[0, 'a'], [1, 'b'], [0, 'c']]], [[0, 'a'], [1, 'b'], [0, 'c']]), ('empty equality between edits', [[[0, 'k'], [-1, 'ab2'], [0, ''], [1, 'ac2']]], [[0, 'ka'], [-1, 'b'], [1, 'c'], [0, '2']])],
    3: [('adjacent equalities merge', [[[0, 'ab'], [0, 'cd']]], [[0, 'abcd']]), ('empty entries are dropped', [[[0, 'a'], [-1, ''], [1, 'b'], [0, '']]], [[0, 'a'], [1, 'b']]), ('common prefix moves into the previous equality', [[[0, 'x'], [-1, 'abc'], [1, 'abd'], [0, 'y']]], [[0, 'xab'], [-1, 'c'], [1, 'd'], [0, 'y']]), ('common suffix moves into the next equality', [[[0, 'p'], [-1, 'kz'], [1, 'mz'], [0, 'q']]], [[0, 'p'], [-1, 'k'], [1, 'm'], [0, 'zq']]), ('no common affix', [[[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]], [[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]), ('interleaved edits are grouped deletion first', [[[1, 'I'], [-1, 'D'], [1, 'J'], [-1, 'E']]], [[-1, 'DE'], [1, 'IJ']]), ('suffix at the end of the text', [[[0, 'st'], [-1, 'xyz3'], [1, 'uvz3']]], [[0, 'st'], [-1, 'xy'], [1, 'uv'], [0, 'z3']]), ('prefix at the start of the text', [[[-1, 'prepreprea'], [1, 'preprepreb'], [0, 'tail']]], [[0, 'preprepre'], [-1, 'a'], [1, 'b'], [0, 'tail']]), ('insertion only', [[[0, 'a'], [1, 'b'], [0, 'c']]], [[0, 'a'], [1, 'b'], [0, 'c']]), ('empty equality between edits', [[[0, 'k'], [-1, 'ab3'], [0, ''], [1, 'ac3']]], [[0, 'ka'], [-1, 'b'], [1, 'c'], [0, '3']])],
    4: [('adjacent equalities merge', [[[0, 'ab'], [0, 'cd']]], [[0, 'abcd']]), ('empty entries are dropped', [[[0, 'a'], [-1, ''], [1, 'b'], [0, '']]], [[0, 'a'], [1, 'b']]), ('common prefix moves into the previous equality', [[[0, 'x'], [-1, 'abc'], [1, 'abd'], [0, 'y']]], [[0, 'xab'], [-1, 'c'], [1, 'd'], [0, 'y']]), ('common suffix moves into the next equality', [[[0, 'p'], [-1, 'kz'], [1, 'mz'], [0, 'q']]], [[0, 'p'], [-1, 'k'], [1, 'm'], [0, 'zq']]), ('no common affix', [[[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]], [[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]), ('interleaved edits are grouped deletion first', [[[1, 'I'], [-1, 'D'], [1, 'J'], [-1, 'E']]], [[-1, 'DE'], [1, 'IJ']]), ('suffix at the end of the text', [[[0, 'st'], [-1, 'xyz4'], [1, 'uvz4']]], [[0, 'st'], [-1, 'xy'], [1, 'uv'], [0, 'z4']]), ('prefix at the start of the text', [[[-1, 'preprepreprea'], [1, 'prepreprepreb'], [0, 'tail']]], [[0, 'prepreprepre'], [-1, 'a'], [1, 'b'], [0, 'tail']]), ('insertion only', [[[0, 'a'], [1, 'b'], [0, 'c']]], [[0, 'a'], [1, 'b'], [0, 'c']]), ('empty equality between edits', [[[0, 'k'], [-1, 'ab4'], [0, ''], [1, 'ac4']]], [[0, 'ka'], [-1, 'b'], [1, 'c'], [0, '4']])],
    5: [('adjacent equalities merge', [[[0, 'ab'], [0, 'cd']]], [[0, 'abcd']]), ('empty entries are dropped', [[[0, 'a'], [-1, ''], [1, 'b'], [0, '']]], [[0, 'a'], [1, 'b']]), ('common prefix moves into the previous equality', [[[0, 'x'], [-1, 'abc'], [1, 'abd'], [0, 'y']]], [[0, 'xab'], [-1, 'c'], [1, 'd'], [0, 'y']]), ('common suffix moves into the next equality', [[[0, 'p'], [-1, 'kz'], [1, 'mz'], [0, 'q']]], [[0, 'p'], [-1, 'k'], [1, 'm'], [0, 'zq']]), ('no common affix', [[[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]], [[0, 'h'], [-1, 'ab'], [1, 'cd'], [0, 'e']]), ('interleaved edits are grouped deletion first', [[[1, 'I'], [-1, 'D'], [1, 'J'], [-1, 'E']]], [[-1, 'DE'], [1, 'IJ']]), ('suffix at the end of the text', [[[0, 'st'], [-1, 'xyz5'], [1, 'uvz5']]], [[0, 'st'], [-1, 'xy'], [1, 'uv'], [0, 'z5']]), ('prefix at the start of the text', [[[-1, 'prepreprepreprea'], [1, 'preprepreprepreb'], [0, 'tail']]], [[0, 'preprepreprepre'], [-1, 'a'], [1, 'b'], [0, 'tail']]), ('insertion only', [[[0, 'a'], [1, 'b'], [0, 'c']]], [[0, 'a'], [1, 'b'], [0, 'c']]), ('empty equality between edits', [[[0, 'k'], [-1, 'ab5'], [0, ''], [1, 'ac5']]], [[0, 'ka'], [-1, 'b'], [1, 'c'], [0, '5']])],
}[N]
for label, args, expected in cases:
    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:
The same replacement normalizes to insertion-first output, unlike the canonical form.

Normalize a character diff of [op, text] (op -1 delete, 0 equal, 1 insert): drop empty texts, merge adjacent equalities, collect each run of edits into one deletion and one insertion (deletion first), move their common prefix into the preceding equality (creating one at the start if needed) and their common suffix into the following equality (appending one at the end if needed).

split: open-access