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

N = 1
observations = []
def solve(x):
    words, width, limit = x
    queue = [list(w) for w in words]
    lines = []
    cur = ''
    streak = 0
    k = 0
    while k < len(queue):
        syl = queue[k]
        token = ''.join(syl)
        need = len(token) if cur == '' else len(cur) + 1 + len(token)
        if need <= width:
            cur = token if cur == '' else cur + ' ' + token
            k += 1
            continue
        split = None
        if streak < limit and k < len(queue) - 1:
            for cut in range(len(syl) - 1, 0, -1):
                head = ''.join(syl[:cut]) + '-'
                room = len(head) if cur == '' else len(cur) + len(head) + 1
                if room <= width:
                    split = cut
                    break
        if split is not None:
            head = ''.join(syl[:split]) + '-'
            lines.append(head if cur == '' else cur + ' ' + head)
            queue[k] = syl[split:]
            cur = ''
            streak += 1
        elif cur == '':
            lines.append(token)
            k += 1
            streak = 0
        else:
            lines.append(cur)
            cur, streak = '', streak
    if cur:
        lines.append(cur)
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('regression: streak reset on plain break', [[['line'], ['set', 'ting'], ['in', 'ter', 'na', 'tion', 'al'], ['jus', 'ti', 'fied'], ['a'], ['kern', 'ing'], ['text'], ['col', 'umn'], ['break', 'ing'], ['text'], ['col', 'umn']], 9, 1], ['line set-', 'ting', 'interna-', 'tional', 'justified', 'a kerning', 'text col-', 'umn', 'breaking', 'text', 'column']), ('regression: streak reset on plain break', [[['to'], ['jus', 'ti', 'fied'], ['set', 'ting'], ['type'], ['hy', 'phen', 'a', 'tion'], ['set', 'ting'], ['in', 'ter', 'na', 'tion', 'al'], ['set', 'ting'], ['kern', 'ing'], ['text'], ['pa', 'ra', 'graph']], 10, 3], ['to justi-', 'fied set-', 'ting type', 'hyphena-', 'tion set-', 'ting in-', 'ternational', 'setting', 'kerning', 'text', 'paragraph']), ('regression: streak reset on plain break', [[['jus', 'ti', 'fied'], ['hy', 'phen', 'a', 'tion'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['lead', 'ing'], ['lead', 'ing'], ['hy', 'phen', 'a', 'tion'], ['of'], ['to']], 6, 3], ['justi-', 'fied', 'hy-', 'phena-', 'tion', 'compo-', 'sition', 'inter-', 'na-', 'tional', 'lead-', 'ing', 'lead-', 'ing', 'hy-', 'phena-', 'tion', 'of to']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('control layout', [[['hy', 'phen', 'a', 'tion'], ['break', 'ing'], ['of'], ['set', 'ting'], ['col', 'umn'], ['a']], 11, 1], ['hyphenation', 'breaking of', 'setting', 'column a']), ('control layout', [[['col', 'umn'], ['lead', 'ing'], ['of'], ['jus', 'ti', 'fied'], ['line']], 12, 3], ['column lead-', 'ing of jus-', 'tified line']), ('control layout', [[['kern', 'ing'], ['jus', 'ti', 'fied'], ['in', 'ter', 'na', 'tion', 'al'], ['set', 'ting'], ['a'], ['break', 'ing'], ['in', 'ter', 'na', 'tion', 'al'], ['to'], ['com', 'po', 'si', 'tion']], 10, 3], ['kerning', 'justified', 'interna-', 'tional', 'setting a', 'breaking', 'interna-', 'tional to', 'composition'])], [('regression: streak reset on plain break', [[['a'], ['break', 'ing'], ['text'], ['to'], ['mar', 'gin'], ['set', 'ting'], ['in', 'ter', 'na', 'tion', 'al'], ['in', 'ter', 'na', 'tion', 'al']], 6, 3], ['a', 'break-', 'ing', 'text', 'to', 'margin', 'set-', 'ting', 'inter-', 'na-', 'tional', 'international']), ('regression: streak reset on plain break', [[['pa', 'ra', 'graph'], ['hy', 'phen', 'a', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['jus', 'ti', 'fied'], ['hy', 'phen', 'a', 'tion'], ['to'], ['kern', 'ing'], ['mar', 'gin'], ['to'], ['lead', 'ing']], 6, 2], ['para-', 'graph', 'hy-', 'phena-', 'tion', 'inter-', 'na-', 'tional', 'justi-', 'fied', 'hy-', 'phena-', 'tion', 'to', 'kern-', 'ing', 'margin', 'to', 'leading']), ('regression: streak reset on plain break', [[['in', 'ter', 'na', 'tion', 'al'], ['in', 'ter', 'na', 'tion', 'al'], ['pa', 'ra', 'graph'], ['set', 'ting'], ['to'], ['mar', 'gin'], ['to'], ['jus', 'ti', 'fied'], ['jus', 'ti', 'fied'], ['in', 'ter', 'na', 'tion', 'al'], ['hy', 'phen', 'a', 'tion'], ['text']], 6, 2], ['inter-', 'na-', 'tional', 'inter-', 'na-', 'tional', 'para-', 'graph', 'set-', 'ting', 'to', 'margin', 'to', 'justi-', 'fied', 'justi-', 'fied', 'inter-', 'na-', 'tional', 'hy-', 'phena-', 'tion', 'text']), ('regression: streak reset on plain break', [[['type'], ['in', 'ter', 'na', 'tion', 'al'], ['hy', 'phen', 'a', 'tion'], ['type'], ['hy', 'phen', 'a', 'tion'], ['hy', 'phen', 'a', 'tion'], ['lead', 'ing'], ['mar', 'gin'], ['com', 'po', 'si', 'tion'], ['col', 'umn']], 12, 3], ['type inter-', 'national hy-', 'phenation', 'type hyphen-', 'ation hy-', 'phenation', 'leading mar-', 'gin composi-', 'tion column']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('control layout', [[['type'], ['col', 'umn'], ['lead', 'ing'], ['lead', 'ing'], ['of'], ['mar', 'gin'], ['in', 'ter', 'na', 'tion', 'al']], 10, 1], ['type col-', 'umn', 'leading', 'leading of', 'margin', 'international']), ('control layout', [[['a'], ['of'], ['type'], ['to'], ['col', 'umn'], ['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['pa', 'ra', 'graph'], ['break', 'ing'], ['col', 'umn'], ['lead', 'ing'], ['com', 'po', 'si', 'tion']], 8, 3], ['a of', 'type to', 'column', 'interna-', 'tional', 'composi-', 'tion pa-', 'ragraph', 'breaking', 'column', 'leading', 'composition'])], [('regression: streak reset on plain break', [[['set', 'ting'], ['lead', 'ing'], ['jus', 'ti', 'fied'], ['of'], ['in', 'ter', 'na', 'tion', 'al'], ['to'], ['jus', 'ti', 'fied'], ['mar', 'gin'], ['line']], 8, 1], ['setting', 'leading', 'justi-', 'fied of', 'interna-', 'tional', 'to jus-', 'tified', 'margin', 'line']), ('regression: streak reset on plain break', [[['hy', 'phen', 'a', 'tion'], ['hy', 'phen', 'a', 'tion'], ['set', 'ting'], ['jus', 'ti', 'fied'], ['col', 'umn'], ['text'], ['pa', 'ra', 'graph'], ['jus', 'ti', 'fied'], ['a']], 9, 1], ['hyphena-', 'tion', 'hyphena-', 'tion', 'setting', 'justified', 'column', 'text pa-', 'ragraph', 'justified', 'a']), ('regression: streak reset on plain break', [[['set', 'ting'], ['set', 'ting'], ['pa', 'ra', 'graph'], ['col', 'umn'], ['to'], ['type'], ['col', 'umn'], ['in', 'ter', 'na', 'tion', 'al'], ['a'], ['com', 'po', 'si', 'tion'], ['kern', 'ing'], ['col', 'umn']], 12, 2], ['setting set-', 'ting para-', 'graph column', 'to type col-', 'umn interna-', 'tional a', 'composition', 'kerning', 'column']), ('regression: streak reset on plain break', [[['jus', 'ti', 'fied'], ['hy', 'phen', 'a', 'tion'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['lead', 'ing'], ['lead', 'ing'], ['hy', 'phen', 'a', 'tion'], ['of'], ['to']], 6, 3], ['justi-', 'fied', 'hy-', 'phena-', 'tion', 'compo-', 'sition', 'inter-', 'na-', 'tional', 'lead-', 'ing', 'lead-', 'ing', 'hy-', 'phena-', 'tion', 'of to']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('control layout', [[['col', 'umn'], ['pa', 'ra', 'graph'], ['text'], ['pa', 'ra', 'graph'], ['break', 'ing'], ['of'], ['hy', 'phen', 'a', 'tion'], ['kern', 'ing'], ['of'], ['jus', 'ti', 'fied'], ['in', 'ter', 'na', 'tion', 'al']], 11, 2], ['column pa-', 'ragraph', 'text para-', 'graph', 'breaking of', 'hyphenation', 'kerning of', 'justified', 'international']), ('control layout', [[['in', 'ter', 'na', 'tion', 'al'], ['of'], ['mar', 'gin'], ['set', 'ting'], ['pa', 'ra', 'graph'], ['com', 'po', 'si', 'tion']], 13, 2], ['international', 'of margin', 'setting para-', 'graph', 'composition'])], [('regression: streak reset on plain break', [[['line'], ['mar', 'gin'], ['lead', 'ing'], ['pa', 'ra', 'graph'], ['hy', 'phen', 'a', 'tion'], ['of'], ['jus', 'ti', 'fied'], ['pa', 'ra', 'graph'], ['a'], ['type']], 7, 1], ['line', 'margin', 'leading', 'para-', 'graph', 'hyphen-', 'ation', 'of jus-', 'tified', 'para-', 'graph a', 'type']), ('regression: streak reset on plain break', [[['a'], ['jus', 'ti', 'fied'], ['hy', 'phen', 'a', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['of'], ['text'], ['line'], ['pa', 'ra', 'graph'], ['of']], 7, 1], ['a jus-', 'tified', 'hyphen-', 'ation', 'inter-', 'national', 'of text', 'line', 'para-', 'graph', 'of']), ('regression: streak reset on plain break', [[['of'], ['jus', 'ti', 'fied'], ['set', 'ting'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['pa', 'ra', 'graph'], ['break', 'ing']], 8, 3], ['of jus-', 'tified', 'setting', 'composi-', 'tion in-', 'terna-', 'tional', 'composi-', 'tion in-', 'terna-', 'tional', 'para-', 'graph', 'breaking']), ('regression: streak reset on plain break', [[['jus', 'ti', 'fied'], ['hy', 'phen', 'a', 'tion'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['lead', 'ing'], ['lead', 'ing'], ['hy', 'phen', 'a', 'tion'], ['of'], ['to']], 6, 3], ['justi-', 'fied', 'hy-', 'phena-', 'tion', 'compo-', 'sition', 'inter-', 'na-', 'tional', 'lead-', 'ing', 'lead-', 'ing', 'hy-', 'phena-', 'tion', 'of to']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('control layout', [[['pa', 'ra', 'graph'], ['line'], ['col', 'umn'], ['jus', 'ti', 'fied'], ['mar', 'gin'], ['mar', 'gin'], ['to'], ['a'], ['col', 'umn'], ['hy', 'phen', 'a', 'tion'], ['jus', 'ti', 'fied'], ['break', 'ing']], 11, 3], ['paragraph', 'line column', 'justified', 'margin mar-', 'gin to a', 'column hy-', 'phenation', 'justified', 'breaking']), ('control layout', [[['jus', 'ti', 'fied'], ['col', 'umn'], ['line'], ['mar', 'gin'], ['hy', 'phen', 'a', 'tion'], ['a'], ['jus', 'ti', 'fied'], ['pa', 'ra', 'graph'], ['type'], ['mar', 'gin']], 11, 2], ['justified', 'column line', 'margin hy-', 'phenation a', 'justified', 'paragraph', 'type margin'])], [('regression: streak reset on plain break', [[['col', 'umn'], ['of'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['a'], ['lead', 'ing'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['set', 'ting'], ['line'], ['col', 'umn']], 6, 3], ['column', 'of', 'compo-', 'sition', 'inter-', 'na-', 'tional', 'a', 'lead-', 'ing', 'compo-', 'sition', 'inter-', 'na-', 'tional', 'set-', 'ting', 'line', 'column']), ('regression: streak reset on plain break', [[['hy', 'phen', 'a', 'tion'], ['lead', 'ing'], ['col', 'umn'], ['of'], ['set', 'ting'], ['pa', 'ra', 'graph'], ['kern', 'ing']], 13, 1], ['hyphenation', 'leading col-', 'umn of', 'setting para-', 'graph kerning']), ('regression: streak reset on plain break', [[['in', 'ter', 'na', 'tion', 'al'], ['to'], ['com', 'po', 'si', 'tion'], ['jus', 'ti', 'fied'], ['jus', 'ti', 'fied'], ['break', 'ing'], ['pa', 'ra', 'graph'], ['type']], 7, 2], ['inter-', 'nation-', 'al to', 'compo-', 'sition', 'justi-', 'fied', 'justi-', 'fied', 'break-', 'ing pa-', 'ragraph', 'type']), ('regression: streak reset on plain break', [[['col', 'umn'], ['kern', 'ing'], ['com', 'po', 'si', 'tion'], ['a'], ['in', 'ter', 'na', 'tion', 'al'], ['lead', 'ing'], ['kern', 'ing'], ['hy', 'phen', 'a', 'tion'], ['text'], ['mar', 'gin'], ['to']], 13, 3], ['column kern-', 'ing composi-', 'tion a inter-', 'national', 'leading kern-', 'ing hyphena-', 'tion text', 'margin to']), ('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('control layout', [[['mar', 'gin'], ['pa', 'ra', 'graph'], ['jus', 'ti', 'fied'], ['kern', 'ing'], ['col', 'umn'], ['jus', 'ti', 'fied'], ['text'], ['a'], ['jus', 'ti', 'fied'], ['break', 'ing']], 11, 2], ['margin pa-', 'ragraph', 'justified', 'kerning', 'column jus-', 'tified text', 'a justified', 'breaking']), ('control layout', [[['lead', 'ing'], ['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['break', 'ing'], ['mar', 'gin'], ['pa', 'ra', 'graph'], ['lead', 'ing']], 10, 3], ['leading', 'interna-', 'tional', 'composi-', 'tion', 'breaking', 'margin pa-', 'ragraph', 'leading'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    words, width, limit = x
    queue = [list(w) for w in words]
    lines = []
    cur = ''
    streak = 0
    k = 0
    while k < len(queue):
        syl = queue[k]
        token = ''.join(syl)
        need = len(token) if cur == '' else len(cur) + 1 + len(token)
        if need <= width:
            cur = token if cur == '' else cur + ' ' + token
            k += 1
            continue
        split = None
        if streak < limit and k < len(queue) - 1:
            for cut in range(len(syl) - 1, 0, -1):
                head = ''.join(syl[:cut]) + '-'
                room = len(head) if cur == '' else len(cur) + len(head) + 1
                if room <= width:
                    split = cut
                    break
        if split is not None:
            head = ''.join(syl[:split]) + '-'
            lines.append(head if cur == '' else cur + ' ' + head)
            queue[k] = syl[split:]
            cur = ''
            streak += 1
        elif cur == '':
            lines.append(token)
            k += 1
            streak = 0
        else:
            lines.append(cur)
            cur, streak = '', max(streak - 1, 0)
    if cur:
        lines.append(cur)
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('regression: streak reset on plain break', [[['line'], ['set', 'ting'], ['in', 'ter', 'na', 'tion', 'al'], ['jus', 'ti', 'fied'], ['a'], ['kern', 'ing'], ['text'], ['col', 'umn'], ['break', 'ing'], ['text'], ['col', 'umn']], 9, 1], ['line set-', 'ting', 'interna-', 'tional', 'justified', 'a kerning', 'text col-', 'umn', 'breaking', 'text', 'column']), ('regression: streak reset on plain break', [[['to'], ['jus', 'ti', 'fied'], ['set', 'ting'], ['type'], ['hy', 'phen', 'a', 'tion'], ['set', 'ting'], ['in', 'ter', 'na', 'tion', 'al'], ['set', 'ting'], ['kern', 'ing'], ['text'], ['pa', 'ra', 'graph']], 10, 3], ['to justi-', 'fied set-', 'ting type', 'hyphena-', 'tion set-', 'ting in-', 'ternational', 'setting', 'kerning', 'text', 'paragraph']), ('regression: streak reset on plain break', [[['jus', 'ti', 'fied'], ['hy', 'phen', 'a', 'tion'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['lead', 'ing'], ['lead', 'ing'], ['hy', 'phen', 'a', 'tion'], ['of'], ['to']], 6, 3], ['justi-', 'fied', 'hy-', 'phena-', 'tion', 'compo-', 'sition', 'inter-', 'na-', 'tional', 'lead-', 'ing', 'lead-', 'ing', 'hy-', 'phena-', 'tion', 'of to']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('control layout', [[['hy', 'phen', 'a', 'tion'], ['break', 'ing'], ['of'], ['set', 'ting'], ['col', 'umn'], ['a']], 11, 1], ['hyphenation', 'breaking of', 'setting', 'column a']), ('control layout', [[['col', 'umn'], ['lead', 'ing'], ['of'], ['jus', 'ti', 'fied'], ['line']], 12, 3], ['column lead-', 'ing of jus-', 'tified line']), ('control layout', [[['kern', 'ing'], ['jus', 'ti', 'fied'], ['in', 'ter', 'na', 'tion', 'al'], ['set', 'ting'], ['a'], ['break', 'ing'], ['in', 'ter', 'na', 'tion', 'al'], ['to'], ['com', 'po', 'si', 'tion']], 10, 3], ['kerning', 'justified', 'interna-', 'tional', 'setting a', 'breaking', 'interna-', 'tional to', 'composition'])], [('regression: streak reset on plain break', [[['a'], ['break', 'ing'], ['text'], ['to'], ['mar', 'gin'], ['set', 'ting'], ['in', 'ter', 'na', 'tion', 'al'], ['in', 'ter', 'na', 'tion', 'al']], 6, 3], ['a', 'break-', 'ing', 'text', 'to', 'margin', 'set-', 'ting', 'inter-', 'na-', 'tional', 'international']), ('regression: streak reset on plain break', [[['pa', 'ra', 'graph'], ['hy', 'phen', 'a', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['jus', 'ti', 'fied'], ['hy', 'phen', 'a', 'tion'], ['to'], ['kern', 'ing'], ['mar', 'gin'], ['to'], ['lead', 'ing']], 6, 2], ['para-', 'graph', 'hy-', 'phena-', 'tion', 'inter-', 'na-', 'tional', 'justi-', 'fied', 'hy-', 'phena-', 'tion', 'to', 'kern-', 'ing', 'margin', 'to', 'leading']), ('regression: streak reset on plain break', [[['in', 'ter', 'na', 'tion', 'al'], ['in', 'ter', 'na', 'tion', 'al'], ['pa', 'ra', 'graph'], ['set', 'ting'], ['to'], ['mar', 'gin'], ['to'], ['jus', 'ti', 'fied'], ['jus', 'ti', 'fied'], ['in', 'ter', 'na', 'tion', 'al'], ['hy', 'phen', 'a', 'tion'], ['text']], 6, 2], ['inter-', 'na-', 'tional', 'inter-', 'na-', 'tional', 'para-', 'graph', 'set-', 'ting', 'to', 'margin', 'to', 'justi-', 'fied', 'justi-', 'fied', 'inter-', 'na-', 'tional', 'hy-', 'phena-', 'tion', 'text']), ('regression: streak reset on plain break', [[['type'], ['in', 'ter', 'na', 'tion', 'al'], ['hy', 'phen', 'a', 'tion'], ['type'], ['hy', 'phen', 'a', 'tion'], ['hy', 'phen', 'a', 'tion'], ['lead', 'ing'], ['mar', 'gin'], ['com', 'po', 'si', 'tion'], ['col', 'umn']], 12, 3], ['type inter-', 'national hy-', 'phenation', 'type hyphen-', 'ation hy-', 'phenation', 'leading mar-', 'gin composi-', 'tion column']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('control layout', [[['type'], ['col', 'umn'], ['lead', 'ing'], ['lead', 'ing'], ['of'], ['mar', 'gin'], ['in', 'ter', 'na', 'tion', 'al']], 10, 1], ['type col-', 'umn', 'leading', 'leading of', 'margin', 'international']), ('control layout', [[['a'], ['of'], ['type'], ['to'], ['col', 'umn'], ['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['pa', 'ra', 'graph'], ['break', 'ing'], ['col', 'umn'], ['lead', 'ing'], ['com', 'po', 'si', 'tion']], 8, 3], ['a of', 'type to', 'column', 'interna-', 'tional', 'composi-', 'tion pa-', 'ragraph', 'breaking', 'column', 'leading', 'composition'])], [('regression: streak reset on plain break', [[['set', 'ting'], ['lead', 'ing'], ['jus', 'ti', 'fied'], ['of'], ['in', 'ter', 'na', 'tion', 'al'], ['to'], ['jus', 'ti', 'fied'], ['mar', 'gin'], ['line']], 8, 1], ['setting', 'leading', 'justi-', 'fied of', 'interna-', 'tional', 'to jus-', 'tified', 'margin', 'line']), ('regression: streak reset on plain break', [[['hy', 'phen', 'a', 'tion'], ['hy', 'phen', 'a', 'tion'], ['set', 'ting'], ['jus', 'ti', 'fied'], ['col', 'umn'], ['text'], ['pa', 'ra', 'graph'], ['jus', 'ti', 'fied'], ['a']], 9, 1], ['hyphena-', 'tion', 'hyphena-', 'tion', 'setting', 'justified', 'column', 'text pa-', 'ragraph', 'justified', 'a']), ('regression: streak reset on plain break', [[['set', 'ting'], ['set', 'ting'], ['pa', 'ra', 'graph'], ['col', 'umn'], ['to'], ['type'], ['col', 'umn'], ['in', 'ter', 'na', 'tion', 'al'], ['a'], ['com', 'po', 'si', 'tion'], ['kern', 'ing'], ['col', 'umn']], 12, 2], ['setting set-', 'ting para-', 'graph column', 'to type col-', 'umn interna-', 'tional a', 'composition', 'kerning', 'column']), ('regression: streak reset on plain break', [[['jus', 'ti', 'fied'], ['hy', 'phen', 'a', 'tion'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['lead', 'ing'], ['lead', 'ing'], ['hy', 'phen', 'a', 'tion'], ['of'], ['to']], 6, 3], ['justi-', 'fied', 'hy-', 'phena-', 'tion', 'compo-', 'sition', 'inter-', 'na-', 'tional', 'lead-', 'ing', 'lead-', 'ing', 'hy-', 'phena-', 'tion', 'of to']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('control layout', [[['col', 'umn'], ['pa', 'ra', 'graph'], ['text'], ['pa', 'ra', 'graph'], ['break', 'ing'], ['of'], ['hy', 'phen', 'a', 'tion'], ['kern', 'ing'], ['of'], ['jus', 'ti', 'fied'], ['in', 'ter', 'na', 'tion', 'al']], 11, 2], ['column pa-', 'ragraph', 'text para-', 'graph', 'breaking of', 'hyphenation', 'kerning of', 'justified', 'international']), ('control layout', [[['in', 'ter', 'na', 'tion', 'al'], ['of'], ['mar', 'gin'], ['set', 'ting'], ['pa', 'ra', 'graph'], ['com', 'po', 'si', 'tion']], 13, 2], ['international', 'of margin', 'setting para-', 'graph', 'composition'])], [('regression: streak reset on plain break', [[['line'], ['mar', 'gin'], ['lead', 'ing'], ['pa', 'ra', 'graph'], ['hy', 'phen', 'a', 'tion'], ['of'], ['jus', 'ti', 'fied'], ['pa', 'ra', 'graph'], ['a'], ['type']], 7, 1], ['line', 'margin', 'leading', 'para-', 'graph', 'hyphen-', 'ation', 'of jus-', 'tified', 'para-', 'graph a', 'type']), ('regression: streak reset on plain break', [[['a'], ['jus', 'ti', 'fied'], ['hy', 'phen', 'a', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['of'], ['text'], ['line'], ['pa', 'ra', 'graph'], ['of']], 7, 1], ['a jus-', 'tified', 'hyphen-', 'ation', 'inter-', 'national', 'of text', 'line', 'para-', 'graph', 'of']), ('regression: streak reset on plain break', [[['of'], ['jus', 'ti', 'fied'], ['set', 'ting'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['pa', 'ra', 'graph'], ['break', 'ing']], 8, 3], ['of jus-', 'tified', 'setting', 'composi-', 'tion in-', 'terna-', 'tional', 'composi-', 'tion in-', 'terna-', 'tional', 'para-', 'graph', 'breaking']), ('regression: streak reset on plain break', [[['jus', 'ti', 'fied'], ['hy', 'phen', 'a', 'tion'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['lead', 'ing'], ['lead', 'ing'], ['hy', 'phen', 'a', 'tion'], ['of'], ['to']], 6, 3], ['justi-', 'fied', 'hy-', 'phena-', 'tion', 'compo-', 'sition', 'inter-', 'na-', 'tional', 'lead-', 'ing', 'lead-', 'ing', 'hy-', 'phena-', 'tion', 'of to']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('control layout', [[['pa', 'ra', 'graph'], ['line'], ['col', 'umn'], ['jus', 'ti', 'fied'], ['mar', 'gin'], ['mar', 'gin'], ['to'], ['a'], ['col', 'umn'], ['hy', 'phen', 'a', 'tion'], ['jus', 'ti', 'fied'], ['break', 'ing']], 11, 3], ['paragraph', 'line column', 'justified', 'margin mar-', 'gin to a', 'column hy-', 'phenation', 'justified', 'breaking']), ('control layout', [[['jus', 'ti', 'fied'], ['col', 'umn'], ['line'], ['mar', 'gin'], ['hy', 'phen', 'a', 'tion'], ['a'], ['jus', 'ti', 'fied'], ['pa', 'ra', 'graph'], ['type'], ['mar', 'gin']], 11, 2], ['justified', 'column line', 'margin hy-', 'phenation a', 'justified', 'paragraph', 'type margin'])], [('regression: streak reset on plain break', [[['col', 'umn'], ['of'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['a'], ['lead', 'ing'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['set', 'ting'], ['line'], ['col', 'umn']], 6, 3], ['column', 'of', 'compo-', 'sition', 'inter-', 'na-', 'tional', 'a', 'lead-', 'ing', 'compo-', 'sition', 'inter-', 'na-', 'tional', 'set-', 'ting', 'line', 'column']), ('regression: streak reset on plain break', [[['hy', 'phen', 'a', 'tion'], ['lead', 'ing'], ['col', 'umn'], ['of'], ['set', 'ting'], ['pa', 'ra', 'graph'], ['kern', 'ing']], 13, 1], ['hyphenation', 'leading col-', 'umn of', 'setting para-', 'graph kerning']), ('regression: streak reset on plain break', [[['in', 'ter', 'na', 'tion', 'al'], ['to'], ['com', 'po', 'si', 'tion'], ['jus', 'ti', 'fied'], ['jus', 'ti', 'fied'], ['break', 'ing'], ['pa', 'ra', 'graph'], ['type']], 7, 2], ['inter-', 'nation-', 'al to', 'compo-', 'sition', 'justi-', 'fied', 'justi-', 'fied', 'break-', 'ing pa-', 'ragraph', 'type']), ('regression: streak reset on plain break', [[['col', 'umn'], ['kern', 'ing'], ['com', 'po', 'si', 'tion'], ['a'], ['in', 'ter', 'na', 'tion', 'al'], ['lead', 'ing'], ['kern', 'ing'], ['hy', 'phen', 'a', 'tion'], ['text'], ['mar', 'gin'], ['to']], 13, 3], ['column kern-', 'ing composi-', 'tion a inter-', 'national', 'leading kern-', 'ing hyphena-', 'tion text', 'margin to']), ('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('control layout', [[['mar', 'gin'], ['pa', 'ra', 'graph'], ['jus', 'ti', 'fied'], ['kern', 'ing'], ['col', 'umn'], ['jus', 'ti', 'fied'], ['text'], ['a'], ['jus', 'ti', 'fied'], ['break', 'ing']], 11, 2], ['margin pa-', 'ragraph', 'justified', 'kerning', 'column jus-', 'tified text', 'a justified', 'breaking']), ('control layout', [[['lead', 'ing'], ['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['break', 'ing'], ['mar', 'gin'], ['pa', 'ra', 'graph'], ['lead', 'ing']], 10, 3], ['leading', 'interna-', 'tional', 'composi-', 'tion', 'breaking', 'margin pa-', 'ragraph', 'leading'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Hyphenation stops for the rest of the paragraph after the first ladder.

Input [words as syllable lists, width, limit]. Greedy fill with 1-unit spaces and characters. A word that does not fit may be split at the latest syllable boundary whose head plus "-" fits, only if fewer than limit immediately preceding lines ended in a hyphen and the word is not the paragraph's last word. A line ended without hyphen resets the streak; a word too long for an empty line is set alone. Return the lines.

split: open-access


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

N = 1
observations = []
def solve(x):
    words, width, limit = x
    queue = [list(w) for w in words]
    lines = []
    cur = ''
    streak = 0
    k = 0
    while k < len(queue):
        syl = queue[k]
        token = ''.join(syl)
        need = len(token) if cur == '' else len(cur) + 1 + len(token)
        if need <= width:
            cur = token if cur == '' else cur + ' ' + token
            k += 1
            continue
        split = None
        if streak <= limit and k < len(queue) - 1:
            for cut in range(len(syl) - 1, 0, -1):
                head = ''.join(syl[:cut]) + '-'
                room = len(head) if cur == '' else len(cur) + len(head) + 1
                if room <= width:
                    split = cut
                    break
        if split is not None:
            head = ''.join(syl[:split]) + '-'
            lines.append(head if cur == '' else cur + ' ' + head)
            queue[k] = syl[split:]
            cur = ''
            streak += 1
        elif cur == '':
            lines.append(token)
            k += 1
            streak = 0
        else:
            lines.append(cur)
            cur, streak = '', 0
    if cur:
        lines.append(cur)
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('regression: ladder limit comparison', [[['to'], ['line'], ['com', 'po', 'si', 'tion'], ['mar', 'gin'], ['mar', 'gin'], ['type'], ['kern', 'ing'], ['in', 'ter', 'na', 'tion', 'al'], ['col', 'umn'], ['line'], ['com', 'po', 'si', 'tion'], ['to']], 14, 1], ['to line compo-', 'sition margin', 'margin type', 'kerning inter-', 'national', 'column line', 'composition to']), ('partial-repair probe', [[['jus', 'ti', 'fied'], ['pa', 'ra', 'graph'], ['jus', 'ti', 'fied'], ['pa', 'ra', 'graph'], ['kern', 'ing'], ['to'], ['lead', 'ing'], ['a']], 7, 1], ['justi-', 'fied', 'para-', 'graph', 'justi-', 'fied', 'para-', 'graph', 'kerning', 'to', 'leading', 'a']), ('partial-repair probe', [[['lead', 'ing'], ['a'], ['col', 'umn'], ['col', 'umn'], ['com', 'po', 'si', 'tion'], ['a']], 11, 2], ['leading a', 'column col-', 'umn compo-', 'sition a']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('control layout', [[['col', 'umn'], ['kern', 'ing'], ['text'], ['col', 'umn'], ['line'], ['line'], ['a']], 12, 2], ['column kern-', 'ing text', 'column line', 'line a']), ('control layout', [[['line'], ['of'], ['mar', 'gin'], ['a'], ['text'], ['line'], ['a'], ['pa', 'ra', 'graph'], ['of'], ['com', 'po', 'si', 'tion'], ['kern', 'ing'], ['break', 'ing']], 7, 3], ['line of', 'margin', 'a text', 'line a', 'para-', 'graph', 'of com-', 'posi-', 'tion', 'kerning', 'breaking']), ('control layout', [[['kern', 'ing'], ['hy', 'phen', 'a', 'tion'], ['type'], ['col', 'umn'], ['mar', 'gin'], ['kern', 'ing'], ['set', 'ting']], 8, 2], ['kerning', 'hyphena-', 'tion', 'type', 'column', 'margin', 'kerning', 'setting'])], [('regression: ladder limit comparison', [[['mar', 'gin'], ['mar', 'gin'], ['break', 'ing'], ['text'], ['of'], ['lead', 'ing'], ['hy', 'phen', 'a', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['line']], 8, 2], ['margin', 'margin', 'breaking', 'text of', 'leading', 'hyphena-', 'tion in-', 'ternational', 'line']), ('regression: ladder limit comparison', [[['mar', 'gin'], ['kern', 'ing'], ['col', 'umn'], ['hy', 'phen', 'a', 'tion'], ['a'], ['col', 'umn'], ['pa', 'ra', 'graph']], 6, 1], ['margin', 'kern-', 'ing', 'column', 'hy-', 'phenation', 'a col-', 'umn', 'paragraph']), ('regression: ladder limit comparison', [[['kern', 'ing'], ['to'], ['kern', 'ing'], ['hy', 'phen', 'a', 'tion'], ['to'], ['hy', 'phen', 'a', 'tion'], ['mar', 'gin'], ['to'], ['pa', 'ra', 'graph']], 10, 1], ['kerning to', 'kerning', 'hyphena-', 'tion to', 'hyphena-', 'tion', 'margin to', 'paragraph']), ('partial-repair probe', [[['com', 'po', 'si', 'tion'], ['to'], ['break', 'ing'], ['to'], ['text'], ['jus', 'ti', 'fied'], ['set', 'ting'], ['of'], ['kern', 'ing']], 12, 2], ['composition', 'to breaking', 'to text jus-', 'tified set-', 'ting of', 'kerning']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('control layout', [[['lead', 'ing'], ['break', 'ing'], ['a'], ['in', 'ter', 'na', 'tion', 'al'], ['a'], ['mar', 'gin'], ['text'], ['pa', 'ra', 'graph'], ['line']], 12, 3], ['leading', 'breaking a', 'internation-', 'al a margin', 'text para-', 'graph line']), ('control layout', [[['col', 'umn'], ['pa', 'ra', 'graph'], ['text'], ['pa', 'ra', 'graph'], ['break', 'ing'], ['of'], ['hy', 'phen', 'a', 'tion'], ['kern', 'ing'], ['of'], ['jus', 'ti', 'fied'], ['in', 'ter', 'na', 'tion', 'al']], 11, 2], ['column pa-', 'ragraph', 'text para-', 'graph', 'breaking of', 'hyphenation', 'kerning of', 'justified', 'international'])], [('regression: ladder limit comparison', [[['jus', 'ti', 'fied'], ['to'], ['type'], ['of'], ['kern', 'ing'], ['com', 'po', 'si', 'tion'], ['to'], ['kern', 'ing'], ['in', 'ter', 'na', 'tion', 'al'], ['lead', 'ing'], ['type'], ['hy', 'phen', 'a', 'tion']], 14, 3], ['justified to', 'type of kern-', 'ing composi-', 'tion to kern-', 'ing', 'international', 'leading type', 'hyphenation']), ('regression: ladder limit comparison', [[['com', 'po', 'si', 'tion'], ['jus', 'ti', 'fied'], ['hy', 'phen', 'a', 'tion'], ['set', 'ting'], ['mar', 'gin'], ['com', 'po', 'si', 'tion']], 6, 1], ['compo-', 'sition', 'justi-', 'fied', 'hy-', 'phenation', 'set-', 'ting', 'margin', 'composition']), ('partial-repair probe', [[['text'], ['col', 'umn'], ['text'], ['a'], ['jus', 'ti', 'fied'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['to'], ['text'], ['a']], 7, 1], ['text', 'column', 'text a', 'justi-', 'fied', 'compo-', 'sition', 'hyphen-', 'ation', 'to text', 'a']), ('regression: ladder limit comparison', [[['break', 'ing'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['set', 'ting'], ['com', 'po', 'si', 'tion'], ['com', 'po', 'si', 'tion'], ['to'], ['break', 'ing'], ['in', 'ter', 'na', 'tion', 'al']], 13, 1], ['breaking com-', 'position', 'international', 'setting com-', 'position', 'composition', 'to breaking', 'international']), ('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('control layout', [[['line'], ['lead', 'ing'], ['in', 'ter', 'na', 'tion', 'al'], ['mar', 'gin'], ['set', 'ting'], ['col', 'umn'], ['jus', 'ti', 'fied'], ['of'], ['col', 'umn'], ['pa', 'ra', 'graph'], ['a']], 13, 3], ['line leading', 'international', 'margin set-', 'ting column', 'justified of', 'column para-', 'graph a']), ('control layout', [[['col', 'umn'], ['pa', 'ra', 'graph'], ['text'], ['pa', 'ra', 'graph'], ['break', 'ing'], ['of'], ['hy', 'phen', 'a', 'tion'], ['kern', 'ing'], ['of'], ['jus', 'ti', 'fied'], ['in', 'ter', 'na', 'tion', 'al']], 11, 2], ['column pa-', 'ragraph', 'text para-', 'graph', 'breaking of', 'hyphenation', 'kerning of', 'justified', 'international'])], [('regression: ladder limit comparison', [[['pa', 'ra', 'graph'], ['in', 'ter', 'na', 'tion', 'al'], ['type'], ['break', 'ing'], ['set', 'ting'], ['hy', 'phen', 'a', 'tion'], ['set', 'ting'], ['jus', 'ti', 'fied'], ['text']], 9, 1], ['paragraph', 'interna-', 'tional', 'type', 'breaking', 'setting', 'hyphena-', 'tion', 'setting', 'justified', 'text']), ('regression: ladder limit comparison', [[['lead', 'ing'], ['type'], ['col', 'umn'], ['col', 'umn'], ['hy', 'phen', 'a', 'tion'], ['line'], ['in', 'ter', 'na', 'tion', 'al'], ['pa', 'ra', 'graph']], 9, 1], ['leading', 'type col-', 'umn', 'column', 'hyphena-', 'tion line', 'interna-', 'tional', 'paragraph']), ('regression: ladder limit comparison', [[['mar', 'gin'], ['of'], ['col', 'umn'], ['in', 'ter', 'na', 'tion', 'al'], ['in', 'ter', 'na', 'tion', 'al'], ['kern', 'ing'], ['mar', 'gin'], ['pa', 'ra', 'graph']], 8, 2], ['margin', 'of col-', 'umn in-', 'ternational', 'interna-', 'tional', 'kerning', 'margin', 'paragraph']), ('partial-repair probe', [[['of'], ['jus', 'ti', 'fied'], ['set', 'ting'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['pa', 'ra', 'graph'], ['break', 'ing']], 8, 3], ['of jus-', 'tified', 'setting', 'composi-', 'tion in-', 'terna-', 'tional', 'composi-', 'tion in-', 'terna-', 'tional', 'para-', 'graph', 'breaking']), ('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('control layout', [[['lead', 'ing'], ['pa', 'ra', 'graph'], ['to'], ['mar', 'gin'], ['line'], ['jus', 'ti', 'fied']], 14, 3], ['leading para-', 'graph to mar-', 'gin line', 'justified']), ('control layout', [[['of'], ['type'], ['type'], ['com', 'po', 'si', 'tion'], ['text'], ['jus', 'ti', 'fied'], ['hy', 'phen', 'a', 'tion']], 9, 3], ['of type', 'type com-', 'position', 'text jus-', 'tified', 'hyphenation'])], [('regression: ladder limit comparison', [[['line'], ['in', 'ter', 'na', 'tion', 'al'], ['in', 'ter', 'na', 'tion', 'al'], ['text'], ['com', 'po', 'si', 'tion'], ['to'], ['hy', 'phen', 'a', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['kern', 'ing'], ['com', 'po', 'si', 'tion'], ['text'], ['hy', 'phen', 'a', 'tion']], 13, 1], ['line interna-', 'tional', 'international', 'text composi-', 'tion to', 'hyphenation', 'international', 'kerning com-', 'position text', 'hyphenation']), ('regression: ladder limit comparison', [[['lead', 'ing'], ['lead', 'ing'], ['set', 'ting'], ['kern', 'ing'], ['break', 'ing'], ['type'], ['mar', 'gin'], ['type'], ['set', 'ting'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['jus', 'ti', 'fied']], 8, 2], ['leading', 'leading', 'setting', 'kerning', 'breaking', 'type', 'margin', 'type', 'setting', 'composi-', 'tion in-', 'ternational', 'justified']), ('regression: ladder limit comparison', [[['a'], ['kern', 'ing'], ['in', 'ter', 'na', 'tion', 'al'], ['set', 'ting'], ['pa', 'ra', 'graph']], 11, 1], ['a kerning', 'interna-', 'tional', 'setting', 'paragraph']), ('partial-repair probe', [[['set', 'ting'], ['lead', 'ing'], ['jus', 'ti', 'fied'], ['of'], ['in', 'ter', 'na', 'tion', 'al'], ['to'], ['jus', 'ti', 'fied'], ['mar', 'gin'], ['line']], 8, 1], ['setting', 'leading', 'justi-', 'fied of', 'interna-', 'tional', 'to jus-', 'tified', 'margin', 'line']), ('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('control layout', [[['type'], ['set', 'ting'], ['a'], ['a'], ['break', 'ing'], ['kern', 'ing'], ['mar', 'gin'], ['type'], ['of'], ['hy', 'phen', 'a', 'tion']], 10, 3], ['type set-', 'ting a a', 'breaking', 'kerning', 'margin', 'type of', 'hyphenation']), ('control layout', [[['break', 'ing'], ['mar', 'gin'], ['mar', 'gin'], ['lead', 'ing'], ['in', 'ter', 'na', 'tion', 'al'], ['line'], ['lead', 'ing']], 12, 2], ['breaking', 'margin mar-', 'gin leading', 'internation-', 'al line', 'leading'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

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

N = 1
observations = []
def solve(x):
    words, width, limit = x
    queue = [list(w) for w in words]
    lines = []
    cur = ''
    streak = 0
    k = 0
    while k < len(queue):
        syl = queue[k]
        token = ''.join(syl)
        need = len(token) if cur == '' else len(cur) + 1 + len(token)
        if need <= width:
            cur = token if cur == '' else cur + ' ' + token
            k += 1
            continue
        split = None
        if streak < limit - 1 and k < len(queue) - 1:
            for cut in range(len(syl) - 1, 0, -1):
                head = ''.join(syl[:cut]) + '-'
                room = len(head) if cur == '' else len(cur) + len(head) + 1
                if room <= width:
                    split = cut
                    break
        if split is not None:
            head = ''.join(syl[:split]) + '-'
            lines.append(head if cur == '' else cur + ' ' + head)
            queue[k] = syl[split:]
            cur = ''
            streak += 1
        elif cur == '':
            lines.append(token)
            k += 1
            streak = 0
        else:
            lines.append(cur)
            cur, streak = '', 0
    if cur:
        lines.append(cur)
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('regression: ladder limit comparison', [[['to'], ['line'], ['com', 'po', 'si', 'tion'], ['mar', 'gin'], ['mar', 'gin'], ['type'], ['kern', 'ing'], ['in', 'ter', 'na', 'tion', 'al'], ['col', 'umn'], ['line'], ['com', 'po', 'si', 'tion'], ['to']], 14, 1], ['to line compo-', 'sition margin', 'margin type', 'kerning inter-', 'national', 'column line', 'composition to']), ('partial-repair probe', [[['jus', 'ti', 'fied'], ['pa', 'ra', 'graph'], ['jus', 'ti', 'fied'], ['pa', 'ra', 'graph'], ['kern', 'ing'], ['to'], ['lead', 'ing'], ['a']], 7, 1], ['justi-', 'fied', 'para-', 'graph', 'justi-', 'fied', 'para-', 'graph', 'kerning', 'to', 'leading', 'a']), ('partial-repair probe', [[['lead', 'ing'], ['a'], ['col', 'umn'], ['col', 'umn'], ['com', 'po', 'si', 'tion'], ['a']], 11, 2], ['leading a', 'column col-', 'umn compo-', 'sition a']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('control layout', [[['col', 'umn'], ['kern', 'ing'], ['text'], ['col', 'umn'], ['line'], ['line'], ['a']], 12, 2], ['column kern-', 'ing text', 'column line', 'line a']), ('control layout', [[['line'], ['of'], ['mar', 'gin'], ['a'], ['text'], ['line'], ['a'], ['pa', 'ra', 'graph'], ['of'], ['com', 'po', 'si', 'tion'], ['kern', 'ing'], ['break', 'ing']], 7, 3], ['line of', 'margin', 'a text', 'line a', 'para-', 'graph', 'of com-', 'posi-', 'tion', 'kerning', 'breaking']), ('control layout', [[['kern', 'ing'], ['hy', 'phen', 'a', 'tion'], ['type'], ['col', 'umn'], ['mar', 'gin'], ['kern', 'ing'], ['set', 'ting']], 8, 2], ['kerning', 'hyphena-', 'tion', 'type', 'column', 'margin', 'kerning', 'setting'])], [('regression: ladder limit comparison', [[['mar', 'gin'], ['mar', 'gin'], ['break', 'ing'], ['text'], ['of'], ['lead', 'ing'], ['hy', 'phen', 'a', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['line']], 8, 2], ['margin', 'margin', 'breaking', 'text of', 'leading', 'hyphena-', 'tion in-', 'ternational', 'line']), ('regression: ladder limit comparison', [[['mar', 'gin'], ['kern', 'ing'], ['col', 'umn'], ['hy', 'phen', 'a', 'tion'], ['a'], ['col', 'umn'], ['pa', 'ra', 'graph']], 6, 1], ['margin', 'kern-', 'ing', 'column', 'hy-', 'phenation', 'a col-', 'umn', 'paragraph']), ('regression: ladder limit comparison', [[['kern', 'ing'], ['to'], ['kern', 'ing'], ['hy', 'phen', 'a', 'tion'], ['to'], ['hy', 'phen', 'a', 'tion'], ['mar', 'gin'], ['to'], ['pa', 'ra', 'graph']], 10, 1], ['kerning to', 'kerning', 'hyphena-', 'tion to', 'hyphena-', 'tion', 'margin to', 'paragraph']), ('partial-repair probe', [[['com', 'po', 'si', 'tion'], ['to'], ['break', 'ing'], ['to'], ['text'], ['jus', 'ti', 'fied'], ['set', 'ting'], ['of'], ['kern', 'ing']], 12, 2], ['composition', 'to breaking', 'to text jus-', 'tified set-', 'ting of', 'kerning']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('control layout', [[['lead', 'ing'], ['break', 'ing'], ['a'], ['in', 'ter', 'na', 'tion', 'al'], ['a'], ['mar', 'gin'], ['text'], ['pa', 'ra', 'graph'], ['line']], 12, 3], ['leading', 'breaking a', 'internation-', 'al a margin', 'text para-', 'graph line']), ('control layout', [[['col', 'umn'], ['pa', 'ra', 'graph'], ['text'], ['pa', 'ra', 'graph'], ['break', 'ing'], ['of'], ['hy', 'phen', 'a', 'tion'], ['kern', 'ing'], ['of'], ['jus', 'ti', 'fied'], ['in', 'ter', 'na', 'tion', 'al']], 11, 2], ['column pa-', 'ragraph', 'text para-', 'graph', 'breaking of', 'hyphenation', 'kerning of', 'justified', 'international'])], [('regression: ladder limit comparison', [[['jus', 'ti', 'fied'], ['to'], ['type'], ['of'], ['kern', 'ing'], ['com', 'po', 'si', 'tion'], ['to'], ['kern', 'ing'], ['in', 'ter', 'na', 'tion', 'al'], ['lead', 'ing'], ['type'], ['hy', 'phen', 'a', 'tion']], 14, 3], ['justified to', 'type of kern-', 'ing composi-', 'tion to kern-', 'ing', 'international', 'leading type', 'hyphenation']), ('regression: ladder limit comparison', [[['com', 'po', 'si', 'tion'], ['jus', 'ti', 'fied'], ['hy', 'phen', 'a', 'tion'], ['set', 'ting'], ['mar', 'gin'], ['com', 'po', 'si', 'tion']], 6, 1], ['compo-', 'sition', 'justi-', 'fied', 'hy-', 'phenation', 'set-', 'ting', 'margin', 'composition']), ('partial-repair probe', [[['text'], ['col', 'umn'], ['text'], ['a'], ['jus', 'ti', 'fied'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['to'], ['text'], ['a']], 7, 1], ['text', 'column', 'text a', 'justi-', 'fied', 'compo-', 'sition', 'hyphen-', 'ation', 'to text', 'a']), ('regression: ladder limit comparison', [[['break', 'ing'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['set', 'ting'], ['com', 'po', 'si', 'tion'], ['com', 'po', 'si', 'tion'], ['to'], ['break', 'ing'], ['in', 'ter', 'na', 'tion', 'al']], 13, 1], ['breaking com-', 'position', 'international', 'setting com-', 'position', 'composition', 'to breaking', 'international']), ('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('control layout', [[['line'], ['lead', 'ing'], ['in', 'ter', 'na', 'tion', 'al'], ['mar', 'gin'], ['set', 'ting'], ['col', 'umn'], ['jus', 'ti', 'fied'], ['of'], ['col', 'umn'], ['pa', 'ra', 'graph'], ['a']], 13, 3], ['line leading', 'international', 'margin set-', 'ting column', 'justified of', 'column para-', 'graph a']), ('control layout', [[['col', 'umn'], ['pa', 'ra', 'graph'], ['text'], ['pa', 'ra', 'graph'], ['break', 'ing'], ['of'], ['hy', 'phen', 'a', 'tion'], ['kern', 'ing'], ['of'], ['jus', 'ti', 'fied'], ['in', 'ter', 'na', 'tion', 'al']], 11, 2], ['column pa-', 'ragraph', 'text para-', 'graph', 'breaking of', 'hyphenation', 'kerning of', 'justified', 'international'])], [('regression: ladder limit comparison', [[['pa', 'ra', 'graph'], ['in', 'ter', 'na', 'tion', 'al'], ['type'], ['break', 'ing'], ['set', 'ting'], ['hy', 'phen', 'a', 'tion'], ['set', 'ting'], ['jus', 'ti', 'fied'], ['text']], 9, 1], ['paragraph', 'interna-', 'tional', 'type', 'breaking', 'setting', 'hyphena-', 'tion', 'setting', 'justified', 'text']), ('regression: ladder limit comparison', [[['lead', 'ing'], ['type'], ['col', 'umn'], ['col', 'umn'], ['hy', 'phen', 'a', 'tion'], ['line'], ['in', 'ter', 'na', 'tion', 'al'], ['pa', 'ra', 'graph']], 9, 1], ['leading', 'type col-', 'umn', 'column', 'hyphena-', 'tion line', 'interna-', 'tional', 'paragraph']), ('regression: ladder limit comparison', [[['mar', 'gin'], ['of'], ['col', 'umn'], ['in', 'ter', 'na', 'tion', 'al'], ['in', 'ter', 'na', 'tion', 'al'], ['kern', 'ing'], ['mar', 'gin'], ['pa', 'ra', 'graph']], 8, 2], ['margin', 'of col-', 'umn in-', 'ternational', 'interna-', 'tional', 'kerning', 'margin', 'paragraph']), ('partial-repair probe', [[['of'], ['jus', 'ti', 'fied'], ['set', 'ting'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['pa', 'ra', 'graph'], ['break', 'ing']], 8, 3], ['of jus-', 'tified', 'setting', 'composi-', 'tion in-', 'terna-', 'tional', 'composi-', 'tion in-', 'terna-', 'tional', 'para-', 'graph', 'breaking']), ('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('control layout', [[['lead', 'ing'], ['pa', 'ra', 'graph'], ['to'], ['mar', 'gin'], ['line'], ['jus', 'ti', 'fied']], 14, 3], ['leading para-', 'graph to mar-', 'gin line', 'justified']), ('control layout', [[['of'], ['type'], ['type'], ['com', 'po', 'si', 'tion'], ['text'], ['jus', 'ti', 'fied'], ['hy', 'phen', 'a', 'tion']], 9, 3], ['of type', 'type com-', 'position', 'text jus-', 'tified', 'hyphenation'])], [('regression: ladder limit comparison', [[['line'], ['in', 'ter', 'na', 'tion', 'al'], ['in', 'ter', 'na', 'tion', 'al'], ['text'], ['com', 'po', 'si', 'tion'], ['to'], ['hy', 'phen', 'a', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['kern', 'ing'], ['com', 'po', 'si', 'tion'], ['text'], ['hy', 'phen', 'a', 'tion']], 13, 1], ['line interna-', 'tional', 'international', 'text composi-', 'tion to', 'hyphenation', 'international', 'kerning com-', 'position text', 'hyphenation']), ('regression: ladder limit comparison', [[['lead', 'ing'], ['lead', 'ing'], ['set', 'ting'], ['kern', 'ing'], ['break', 'ing'], ['type'], ['mar', 'gin'], ['type'], ['set', 'ting'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['jus', 'ti', 'fied']], 8, 2], ['leading', 'leading', 'setting', 'kerning', 'breaking', 'type', 'margin', 'type', 'setting', 'composi-', 'tion in-', 'ternational', 'justified']), ('regression: ladder limit comparison', [[['a'], ['kern', 'ing'], ['in', 'ter', 'na', 'tion', 'al'], ['set', 'ting'], ['pa', 'ra', 'graph']], 11, 1], ['a kerning', 'interna-', 'tional', 'setting', 'paragraph']), ('partial-repair probe', [[['set', 'ting'], ['lead', 'ing'], ['jus', 'ti', 'fied'], ['of'], ['in', 'ter', 'na', 'tion', 'al'], ['to'], ['jus', 'ti', 'fied'], ['mar', 'gin'], ['line']], 8, 1], ['setting', 'leading', 'justi-', 'fied of', 'interna-', 'tional', 'to jus-', 'tified', 'margin', 'line']), ('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('control layout', [[['type'], ['set', 'ting'], ['a'], ['a'], ['break', 'ing'], ['kern', 'ing'], ['mar', 'gin'], ['type'], ['of'], ['hy', 'phen', 'a', 'tion']], 10, 3], ['type set-', 'ting a a', 'breaking', 'kerning', 'margin', 'type of', 'hyphenation']), ('control layout', [[['break', 'ing'], ['mar', 'gin'], ['mar', 'gin'], ['lead', 'ing'], ['in', 'ter', 'na', 'tion', 'al'], ['line'], ['lead', 'ing']], 12, 2], ['breaking', 'margin mar-', 'gin leading', 'internation-', 'al line', 'leading'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
One more consecutive hyphen than allowed is produced.

Input [words as syllable lists, width, limit]. Greedy fill with 1-unit spaces and characters. A word that does not fit may be split at the latest syllable boundary whose head plus "-" fits, only if fewer than limit immediately preceding lines ended in a hyphen and the word is not the paragraph's last word. A line ended without hyphen resets the streak; a word too long for an empty line is set alone. Return the lines.

split: open-access


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

N = 1
observations = []
def solve(x):
    words, width, limit = x
    queue = [list(w) for w in words]
    lines = []
    cur = ''
    streak = 0
    k = 0
    while k < len(queue):
        syl = queue[k]
        token = ''.join(syl)
        need = len(token) if cur == '' else len(cur) + 1 + len(token)
        if need <= width:
            cur = token if cur == '' else cur + ' ' + token
            k += 1
            continue
        split = None
        if streak < limit and k < len(queue):
            for cut in range(len(syl) - 1, 0, -1):
                head = ''.join(syl[:cut]) + '-'
                room = len(head) if cur == '' else len(cur) + len(head) + 1
                if room <= width:
                    split = cut
                    break
        if split is not None:
            head = ''.join(syl[:split]) + '-'
            lines.append(head if cur == '' else cur + ' ' + head)
            queue[k] = syl[split:]
            cur = ''
            streak += 1
        elif cur == '':
            lines.append(token)
            k += 1
            streak = 0
        else:
            lines.append(cur)
            cur, streak = '', 0
    if cur:
        lines.append(cur)
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('regression: final word protection', [[['to'], ['in', 'ter', 'na', 'tion', 'al'], ['a'], ['mar', 'gin'], ['a'], ['text'], ['a'], ['break', 'ing']], 7, 3], ['to in-', 'terna-', 'tional', 'a mar-', 'gin a', 'text a', 'breaking']), ('partial-repair probe', [[['text'], ['jus', 'ti', 'fied'], ['a'], ['hy', 'phen', 'a', 'tion'], ['set', 'ting'], ['line'], ['line'], ['jus', 'ti', 'fied'], ['col', 'umn'], ['jus', 'ti', 'fied'], ['com', 'po', 'si', 'tion']], 11, 1], ['text justi-', 'fied a', 'hyphenation', 'setting', 'line line', 'justified', 'column jus-', 'tified', 'composition']), ('regression: final word protection', [[['line'], ['pa', 'ra', 'graph'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['pa', 'ra', 'graph'], ['in', 'ter', 'na', 'tion', 'al'], ['kern', 'ing']], 6, 1], ['line', 'para-', 'graph', 'compo-', 'sition', 'hy-', 'phenation', 'para-', 'graph', 'inter-', 'national', 'kerning']), ('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('control layout', [[['kern', 'ing'], ['line'], ['type'], ['jus', 'ti', 'fied'], ['set', 'ting']], 11, 2], ['kerning', 'line type', 'justified', 'setting']), ('control layout', [[['hy', 'phen', 'a', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['set', 'ting'], ['set', 'ting'], ['a']], 10, 2], ['hyphena-', 'tion in-', 'ternational', 'setting', 'setting a']), ('control layout', [[['col', 'umn'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['lead', 'ing'], ['type'], ['of'], ['of'], ['line'], ['set', 'ting'], ['pa', 'ra', 'graph'], ['kern', 'ing'], ['line']], 7, 3], ['column', 'compo-', 'sition', 'hyphen-', 'ation', 'leading', 'type of', 'of line', 'setting', 'para-', 'graph', 'kerning', 'line'])], [('regression: final word protection', [[['break', 'ing'], ['mar', 'gin'], ['hy', 'phen', 'a', 'tion'], ['jus', 'ti', 'fied'], ['a'], ['hy', 'phen', 'a', 'tion'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion']], 10, 3], ['breaking', 'margin hy-', 'phenation', 'justified', 'a hyphena-', 'tion com-', 'position', 'hyphenation']), ('regression: final word protection', [[['pa', 'ra', 'graph'], ['break', 'ing'], ['mar', 'gin'], ['hy', 'phen', 'a', 'tion'], ['kern', 'ing'], ['jus', 'ti', 'fied'], ['to'], ['kern', 'ing'], ['hy', 'phen', 'a', 'tion']], 12, 1], ['paragraph', 'breaking', 'margin hy-', 'phenation', 'kerning jus-', 'tified to', 'kerning', 'hyphenation']), ('partial-repair probe', [[['break', 'ing'], ['in', 'ter', 'na', 'tion', 'al'], ['text'], ['of'], ['set', 'ting'], ['in', 'ter', 'na', 'tion', 'al'], ['line'], ['a'], ['in', 'ter', 'na', 'tion', 'al'], ['set', 'ting']], 9, 3], ['breaking', 'interna-', 'tional', 'text of', 'setting', 'interna-', 'tional', 'line a', 'interna-', 'tional', 'setting']), ('regression: final word protection', [[['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['mar', 'gin'], ['break', 'ing'], ['mar', 'gin'], ['line'], ['set', 'ting'], ['in', 'ter', 'na', 'tion', 'al']], 6, 1], ['compo-', 'sition', 'inter-', 'national', 'margin', 'break-', 'ing', 'margin', 'line', 'set-', 'ting', 'international']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('control layout', [[['set', 'ting'], ['jus', 'ti', 'fied'], ['break', 'ing'], ['type'], ['type'], ['text'], ['break', 'ing'], ['hy', 'phen', 'a', 'tion'], ['a'], ['set', 'ting']], 11, 2], ['setting', 'justified', 'breaking', 'type type', 'text break-', 'ing hyphen-', 'ation a', 'setting']), ('control layout', [[['a'], ['line'], ['lead', 'ing'], ['break', 'ing'], ['text'], ['of'], ['com', 'po', 'si', 'tion'], ['to'], ['hy', 'phen', 'a', 'tion'], ['to'], ['type']], 6, 2], ['a line', 'lead-', 'ing', 'break-', 'ing', 'text', 'of', 'compo-', 'sition', 'to hy-', 'phena-', 'tion', 'to', 'type'])], [('regression: final word protection', [[['set', 'ting'], ['of'], ['mar', 'gin'], ['kern', 'ing'], ['set', 'ting'], ['col', 'umn'], ['line'], ['set', 'ting'], ['a'], ['in', 'ter', 'na', 'tion', 'al'], ['mar', 'gin']], 11, 2], ['setting of', 'margin', 'kerning', 'setting', 'column line', 'setting a', 'interna-', 'tional', 'margin']), ('regression: final word protection', [[['a'], ['type'], ['in', 'ter', 'na', 'tion', 'al'], ['lead', 'ing'], ['to'], ['to'], ['break', 'ing'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['type'], ['text'], ['hy', 'phen', 'a', 'tion']], 10, 3], ['a type in-', 'ternation-', 'al leading', 'to to', 'breaking', 'composi-', 'tion hy-', 'phenation', 'type text', 'hyphenation']), ('regression: final word protection', [[['text'], ['line'], ['to'], ['text'], ['lead', 'ing'], ['jus', 'ti', 'fied'], ['set', 'ting'], ['jus', 'ti', 'fied'], ['of'], ['break', 'ing'], ['com', 'po', 'si', 'tion']], 10, 3], ['text line', 'to text', 'leading', 'justified', 'setting', 'justified', 'of break-', 'ing', 'composition']), ('regression: final word protection', [[['break', 'ing'], ['of'], ['set', 'ting'], ['mar', 'gin'], ['in', 'ter', 'na', 'tion', 'al']], 9, 3], ['breaking', 'of set-', 'ting mar-', 'gin', 'international']), ('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('control layout', [[['kern', 'ing'], ['set', 'ting'], ['col', 'umn'], ['of'], ['text']], 7, 3], ['kerning', 'setting', 'column', 'of text']), ('control layout', [[['line'], ['in', 'ter', 'na', 'tion', 'al'], ['pa', 'ra', 'graph'], ['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['mar', 'gin'], ['to'], ['set', 'ting'], ['text'], ['mar', 'gin'], ['kern', 'ing'], ['jus', 'ti', 'fied']], 14, 1], ['line interna-', 'tional', 'paragraph in-', 'ternational', 'composition', 'margin to set-', 'ting text', 'margin kerning', 'justified'])], [('regression: final word protection', [[['line'], ['pa', 'ra', 'graph'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['pa', 'ra', 'graph'], ['in', 'ter', 'na', 'tion', 'al'], ['kern', 'ing']], 6, 1], ['line', 'para-', 'graph', 'compo-', 'sition', 'hy-', 'phenation', 'para-', 'graph', 'inter-', 'national', 'kerning']), ('regression: final word protection', [[['a'], ['break', 'ing'], ['text'], ['to'], ['mar', 'gin'], ['set', 'ting'], ['in', 'ter', 'na', 'tion', 'al'], ['in', 'ter', 'na', 'tion', 'al']], 6, 3], ['a', 'break-', 'ing', 'text', 'to', 'margin', 'set-', 'ting', 'inter-', 'na-', 'tional', 'international']), ('partial-repair probe', [[['jus', 'ti', 'fied'], ['break', 'ing'], ['to'], ['hy', 'phen', 'a', 'tion'], ['col', 'umn']], 9, 3], ['justified', 'breaking', 'to hy-', 'phenation', 'column']), ('regression: final word protection', [[['break', 'ing'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['break', 'ing'], ['text'], ['set', 'ting'], ['lead', 'ing']], 11, 3], ['breaking', 'composition', 'interna-', 'tional', 'breaking', 'text set-', 'ting', 'leading']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('control layout', [[['mar', 'gin'], ['text'], ['lead', 'ing'], ['col', 'umn'], ['hy', 'phen', 'a', 'tion'], ['mar', 'gin'], ['in', 'ter', 'na', 'tion', 'al'], ['mar', 'gin'], ['set', 'ting'], ['to'], ['jus', 'ti', 'fied'], ['lead', 'ing']], 13, 1], ['margin text', 'leading col-', 'umn', 'hyphenation', 'margin inter-', 'national', 'margin set-', 'ting to', 'justified', 'leading']), ('control layout', [[['to'], ['set', 'ting'], ['of'], ['lead', 'ing'], ['lead', 'ing'], ['of'], ['com', 'po', 'si', 'tion'], ['set', 'ting'], ['lead', 'ing']], 12, 2], ['to setting', 'of leading', 'leading of', 'composition', 'setting', 'leading'])], [('regression: final word protection', [[['hy', 'phen', 'a', 'tion'], ['hy', 'phen', 'a', 'tion'], ['lead', 'ing'], ['break', 'ing'], ['of'], ['text'], ['a'], ['jus', 'ti', 'fied'], ['jus', 'ti', 'fied'], ['to'], ['com', 'po', 'si', 'tion']], 10, 3], ['hyphena-', 'tion hy-', 'phenation', 'leading', 'breaking', 'of text a', 'justified', 'justified', 'to', 'composition']), ('regression: final word protection', [[['kern', 'ing'], ['com', 'po', 'si', 'tion'], ['to'], ['in', 'ter', 'na', 'tion', 'al'], ['line'], ['col', 'umn'], ['hy', 'phen', 'a', 'tion'], ['set', 'ting'], ['line'], ['set', 'ting']], 11, 3], ['kerning', 'composition', 'to interna-', 'tional line', 'column hy-', 'phenation', 'setting', 'line', 'setting']), ('partial-repair probe', [[['in', 'ter', 'na', 'tion', 'al'], ['in', 'ter', 'na', 'tion', 'al'], ['jus', 'ti', 'fied'], ['hy', 'phen', 'a', 'tion'], ['type'], ['hy', 'phen', 'a', 'tion'], ['text']], 12, 2], ['internation-', 'al interna-', 'tional', 'justified', 'hyphenation', 'type hyphen-', 'ation text']), ('partial-repair probe', [[['to'], ['hy', 'phen', 'a', 'tion'], ['line'], ['com', 'po', 'si', 'tion'], ['of']], 6, 3], ['to hy-', 'phena-', 'tion', 'line', 'compo-', 'sition', 'of']), ('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('control layout', [[['of'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['kern', 'ing'], ['type'], ['to'], ['jus', 'ti', 'fied'], ['to'], ['kern', 'ing'], ['type'], ['a']], 13, 3], ['of composi-', 'tion interna-', 'tional kern-', 'ing type to', 'justified to', 'kerning type', 'a']), ('control layout', [[['of'], ['break', 'ing'], ['type'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['hy', 'phen', 'a', 'tion'], ['break', 'ing']], 12, 3], ['of breaking', 'type compo-', 'sition in-', 'ternational', 'hyphenation', 'breaking'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    words, width, limit = x
    queue = [list(w) for w in words]
    lines = []
    cur = ''
    streak = 0
    k = 0
    while k < len(queue):
        syl = queue[k]
        token = ''.join(syl)
        need = len(token) if cur == '' else len(cur) + 1 + len(token)
        if need <= width:
            cur = token if cur == '' else cur + ' ' + token
            k += 1
            continue
        split = None
        if streak < limit and k < len(queue) - 2:
            for cut in range(len(syl) - 1, 0, -1):
                head = ''.join(syl[:cut]) + '-'
                room = len(head) if cur == '' else len(cur) + len(head) + 1
                if room <= width:
                    split = cut
                    break
        if split is not None:
            head = ''.join(syl[:split]) + '-'
            lines.append(head if cur == '' else cur + ' ' + head)
            queue[k] = syl[split:]
            cur = ''
            streak += 1
        elif cur == '':
            lines.append(token)
            k += 1
            streak = 0
        else:
            lines.append(cur)
            cur, streak = '', 0
    if cur:
        lines.append(cur)
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('regression: final word protection', [[['to'], ['in', 'ter', 'na', 'tion', 'al'], ['a'], ['mar', 'gin'], ['a'], ['text'], ['a'], ['break', 'ing']], 7, 3], ['to in-', 'terna-', 'tional', 'a mar-', 'gin a', 'text a', 'breaking']), ('partial-repair probe', [[['text'], ['jus', 'ti', 'fied'], ['a'], ['hy', 'phen', 'a', 'tion'], ['set', 'ting'], ['line'], ['line'], ['jus', 'ti', 'fied'], ['col', 'umn'], ['jus', 'ti', 'fied'], ['com', 'po', 'si', 'tion']], 11, 1], ['text justi-', 'fied a', 'hyphenation', 'setting', 'line line', 'justified', 'column jus-', 'tified', 'composition']), ('regression: final word protection', [[['line'], ['pa', 'ra', 'graph'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['pa', 'ra', 'graph'], ['in', 'ter', 'na', 'tion', 'al'], ['kern', 'ing']], 6, 1], ['line', 'para-', 'graph', 'compo-', 'sition', 'hy-', 'phenation', 'para-', 'graph', 'inter-', 'national', 'kerning']), ('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('control layout', [[['kern', 'ing'], ['line'], ['type'], ['jus', 'ti', 'fied'], ['set', 'ting']], 11, 2], ['kerning', 'line type', 'justified', 'setting']), ('control layout', [[['hy', 'phen', 'a', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['set', 'ting'], ['set', 'ting'], ['a']], 10, 2], ['hyphena-', 'tion in-', 'ternational', 'setting', 'setting a']), ('control layout', [[['col', 'umn'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['lead', 'ing'], ['type'], ['of'], ['of'], ['line'], ['set', 'ting'], ['pa', 'ra', 'graph'], ['kern', 'ing'], ['line']], 7, 3], ['column', 'compo-', 'sition', 'hyphen-', 'ation', 'leading', 'type of', 'of line', 'setting', 'para-', 'graph', 'kerning', 'line'])], [('regression: final word protection', [[['break', 'ing'], ['mar', 'gin'], ['hy', 'phen', 'a', 'tion'], ['jus', 'ti', 'fied'], ['a'], ['hy', 'phen', 'a', 'tion'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion']], 10, 3], ['breaking', 'margin hy-', 'phenation', 'justified', 'a hyphena-', 'tion com-', 'position', 'hyphenation']), ('regression: final word protection', [[['pa', 'ra', 'graph'], ['break', 'ing'], ['mar', 'gin'], ['hy', 'phen', 'a', 'tion'], ['kern', 'ing'], ['jus', 'ti', 'fied'], ['to'], ['kern', 'ing'], ['hy', 'phen', 'a', 'tion']], 12, 1], ['paragraph', 'breaking', 'margin hy-', 'phenation', 'kerning jus-', 'tified to', 'kerning', 'hyphenation']), ('partial-repair probe', [[['break', 'ing'], ['in', 'ter', 'na', 'tion', 'al'], ['text'], ['of'], ['set', 'ting'], ['in', 'ter', 'na', 'tion', 'al'], ['line'], ['a'], ['in', 'ter', 'na', 'tion', 'al'], ['set', 'ting']], 9, 3], ['breaking', 'interna-', 'tional', 'text of', 'setting', 'interna-', 'tional', 'line a', 'interna-', 'tional', 'setting']), ('regression: final word protection', [[['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['mar', 'gin'], ['break', 'ing'], ['mar', 'gin'], ['line'], ['set', 'ting'], ['in', 'ter', 'na', 'tion', 'al']], 6, 1], ['compo-', 'sition', 'inter-', 'national', 'margin', 'break-', 'ing', 'margin', 'line', 'set-', 'ting', 'international']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('control layout', [[['set', 'ting'], ['jus', 'ti', 'fied'], ['break', 'ing'], ['type'], ['type'], ['text'], ['break', 'ing'], ['hy', 'phen', 'a', 'tion'], ['a'], ['set', 'ting']], 11, 2], ['setting', 'justified', 'breaking', 'type type', 'text break-', 'ing hyphen-', 'ation a', 'setting']), ('control layout', [[['a'], ['line'], ['lead', 'ing'], ['break', 'ing'], ['text'], ['of'], ['com', 'po', 'si', 'tion'], ['to'], ['hy', 'phen', 'a', 'tion'], ['to'], ['type']], 6, 2], ['a line', 'lead-', 'ing', 'break-', 'ing', 'text', 'of', 'compo-', 'sition', 'to hy-', 'phena-', 'tion', 'to', 'type'])], [('regression: final word protection', [[['set', 'ting'], ['of'], ['mar', 'gin'], ['kern', 'ing'], ['set', 'ting'], ['col', 'umn'], ['line'], ['set', 'ting'], ['a'], ['in', 'ter', 'na', 'tion', 'al'], ['mar', 'gin']], 11, 2], ['setting of', 'margin', 'kerning', 'setting', 'column line', 'setting a', 'interna-', 'tional', 'margin']), ('regression: final word protection', [[['a'], ['type'], ['in', 'ter', 'na', 'tion', 'al'], ['lead', 'ing'], ['to'], ['to'], ['break', 'ing'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['type'], ['text'], ['hy', 'phen', 'a', 'tion']], 10, 3], ['a type in-', 'ternation-', 'al leading', 'to to', 'breaking', 'composi-', 'tion hy-', 'phenation', 'type text', 'hyphenation']), ('regression: final word protection', [[['text'], ['line'], ['to'], ['text'], ['lead', 'ing'], ['jus', 'ti', 'fied'], ['set', 'ting'], ['jus', 'ti', 'fied'], ['of'], ['break', 'ing'], ['com', 'po', 'si', 'tion']], 10, 3], ['text line', 'to text', 'leading', 'justified', 'setting', 'justified', 'of break-', 'ing', 'composition']), ('regression: final word protection', [[['break', 'ing'], ['of'], ['set', 'ting'], ['mar', 'gin'], ['in', 'ter', 'na', 'tion', 'al']], 9, 3], ['breaking', 'of set-', 'ting mar-', 'gin', 'international']), ('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('control layout', [[['kern', 'ing'], ['set', 'ting'], ['col', 'umn'], ['of'], ['text']], 7, 3], ['kerning', 'setting', 'column', 'of text']), ('control layout', [[['line'], ['in', 'ter', 'na', 'tion', 'al'], ['pa', 'ra', 'graph'], ['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['mar', 'gin'], ['to'], ['set', 'ting'], ['text'], ['mar', 'gin'], ['kern', 'ing'], ['jus', 'ti', 'fied']], 14, 1], ['line interna-', 'tional', 'paragraph in-', 'ternational', 'composition', 'margin to set-', 'ting text', 'margin kerning', 'justified'])], [('regression: final word protection', [[['line'], ['pa', 'ra', 'graph'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['pa', 'ra', 'graph'], ['in', 'ter', 'na', 'tion', 'al'], ['kern', 'ing']], 6, 1], ['line', 'para-', 'graph', 'compo-', 'sition', 'hy-', 'phenation', 'para-', 'graph', 'inter-', 'national', 'kerning']), ('regression: final word protection', [[['a'], ['break', 'ing'], ['text'], ['to'], ['mar', 'gin'], ['set', 'ting'], ['in', 'ter', 'na', 'tion', 'al'], ['in', 'ter', 'na', 'tion', 'al']], 6, 3], ['a', 'break-', 'ing', 'text', 'to', 'margin', 'set-', 'ting', 'inter-', 'na-', 'tional', 'international']), ('partial-repair probe', [[['jus', 'ti', 'fied'], ['break', 'ing'], ['to'], ['hy', 'phen', 'a', 'tion'], ['col', 'umn']], 9, 3], ['justified', 'breaking', 'to hy-', 'phenation', 'column']), ('regression: final word protection', [[['break', 'ing'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['break', 'ing'], ['text'], ['set', 'ting'], ['lead', 'ing']], 11, 3], ['breaking', 'composition', 'interna-', 'tional', 'breaking', 'text set-', 'ting', 'leading']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('control layout', [[['mar', 'gin'], ['text'], ['lead', 'ing'], ['col', 'umn'], ['hy', 'phen', 'a', 'tion'], ['mar', 'gin'], ['in', 'ter', 'na', 'tion', 'al'], ['mar', 'gin'], ['set', 'ting'], ['to'], ['jus', 'ti', 'fied'], ['lead', 'ing']], 13, 1], ['margin text', 'leading col-', 'umn', 'hyphenation', 'margin inter-', 'national', 'margin set-', 'ting to', 'justified', 'leading']), ('control layout', [[['to'], ['set', 'ting'], ['of'], ['lead', 'ing'], ['lead', 'ing'], ['of'], ['com', 'po', 'si', 'tion'], ['set', 'ting'], ['lead', 'ing']], 12, 2], ['to setting', 'of leading', 'leading of', 'composition', 'setting', 'leading'])], [('regression: final word protection', [[['hy', 'phen', 'a', 'tion'], ['hy', 'phen', 'a', 'tion'], ['lead', 'ing'], ['break', 'ing'], ['of'], ['text'], ['a'], ['jus', 'ti', 'fied'], ['jus', 'ti', 'fied'], ['to'], ['com', 'po', 'si', 'tion']], 10, 3], ['hyphena-', 'tion hy-', 'phenation', 'leading', 'breaking', 'of text a', 'justified', 'justified', 'to', 'composition']), ('regression: final word protection', [[['kern', 'ing'], ['com', 'po', 'si', 'tion'], ['to'], ['in', 'ter', 'na', 'tion', 'al'], ['line'], ['col', 'umn'], ['hy', 'phen', 'a', 'tion'], ['set', 'ting'], ['line'], ['set', 'ting']], 11, 3], ['kerning', 'composition', 'to interna-', 'tional line', 'column hy-', 'phenation', 'setting', 'line', 'setting']), ('partial-repair probe', [[['in', 'ter', 'na', 'tion', 'al'], ['in', 'ter', 'na', 'tion', 'al'], ['jus', 'ti', 'fied'], ['hy', 'phen', 'a', 'tion'], ['type'], ['hy', 'phen', 'a', 'tion'], ['text']], 12, 2], ['internation-', 'al interna-', 'tional', 'justified', 'hyphenation', 'type hyphen-', 'ation text']), ('partial-repair probe', [[['to'], ['hy', 'phen', 'a', 'tion'], ['line'], ['com', 'po', 'si', 'tion'], ['of']], 6, 3], ['to hy-', 'phena-', 'tion', 'line', 'compo-', 'sition', 'of']), ('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('control layout', [[['of'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['kern', 'ing'], ['type'], ['to'], ['jus', 'ti', 'fied'], ['to'], ['kern', 'ing'], ['type'], ['a']], 13, 3], ['of composi-', 'tion interna-', 'tional kern-', 'ing type to', 'justified to', 'kerning type', 'a']), ('control layout', [[['of'], ['break', 'ing'], ['type'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['hy', 'phen', 'a', 'tion'], ['break', 'ing']], 12, 3], ['of breaking', 'type compo-', 'sition in-', 'ternational', 'hyphenation', 'breaking'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The paragraph's last word is split across lines.

Input [words as syllable lists, width, limit]. Greedy fill with 1-unit spaces and characters. A word that does not fit may be split at the latest syllable boundary whose head plus "-" fits, only if fewer than limit immediately preceding lines ended in a hyphen and the word is not the paragraph's last word. A line ended without hyphen resets the streak; a word too long for an empty line is set alone. Return the lines.

split: open-access