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

N = 1
observations = []
def solve(x):
    paras, H, orphan, widow = x
    pages = []
    used = 0
    for p in paras:
        rem = p
        started = True
        while rem > 0:
            room = H - used
            if rem <= room:
                used += rem
                rem = 0
                continue
            a = room
            if used > 0:
                if rem - a < widow:
                    a = max(rem - widow, 0)
                if started and a < widow:
                    a = 0
            used += a
            rem -= a
            if a > 0:
                started = False
            pages.append(used)
            used = 0
    if used > 0:
        pages.append(used)
    return pages
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: orphan parameter binding', [[3, 7, 8, 6, 7, 4, 2, 6], 6, 3, 1], [6, 4, 6, 6, 6, 6, 6, 3]), ('regression: orphan parameter binding', [[8, 4, 7, 9, 2], 7, 3, 1], [7, 5, 7, 7, 4]), ('regression: orphan parameter binding', [[1, 5, 3], 7, 2, 1], [6, 3]), ('regression: orphan parameter binding', [[2, 9, 7], 12, 2, 1], [11, 7]), ('paragraph exactly fills page', [[2, 4, 3], 6, 2, 2], [6, 3]), ('long paragraph continuation', [[2, 14], 6, 2, 2], [6, 6, 4]), ('control layout', [[1, 7, 1, 2, 1, 8], 8, 3, 2], [8, 8, 4]), ('control layout', [[1, 2, 8, 5, 8, 6, 7, 9], 7, 3, 3], [7, 4, 5, 7, 7, 7, 7, 2])], [('regression: orphan parameter binding', [[6, 8, 9, 2], 4, 1, 3], [4, 4, 4, 4, 4, 3, 2]), ('regression: orphan parameter binding', [[6, 8, 1, 3, 8, 9], 4, 1, 3], [4, 4, 4, 3, 4, 4, 4, 4, 4]), ('regression: orphan parameter binding', [[6, 6, 3, 3, 5, 7, 8], 11, 3, 2], [10, 11, 9, 8]), ('regression: orphan parameter binding', [[5, 4, 2, 8, 5], 5, 2, 1], [5, 4, 5, 5, 5]), ('orphan pushed forward', [[5, 3], 6, 2, 2], [5, 3]), ('long paragraph continuation', [[2, 14], 6, 2, 2], [6, 6, 4]), ('control layout', [[6, 2, 9, 7, 8, 9, 7], 8, 1, 3], [8, 8, 8, 8, 8, 8]), ('control layout', [[6, 9, 1, 5, 1, 8], 11, 2, 1], [11, 11, 8])], [('regression: orphan parameter binding', [[7, 8, 6, 2, 2, 9, 5, 6], 7, 1, 2], [7, 7, 7, 7, 7, 7, 3]), ('regression: orphan parameter binding', [[5, 3, 1, 2, 2, 9, 4, 4], 8, 3, 1], [8, 8, 6, 8]), ('regression: orphan parameter binding', [[6, 4, 6, 7, 5, 3], 8, 3, 2], [6, 8, 7, 7, 3]), ('regression: orphan parameter binding', [[6, 3, 8], 4, 3, 1], [4, 2, 3, 4, 4]), ('long paragraph continuation', [[2, 14], 6, 2, 2], [6, 6, 4]), ('single widow pulled back', [[3, 4], 6, 2, 2], [5, 2]), ('control layout', [[6, 3, 6, 7], 5, 1, 1], [5, 5, 5, 5, 2]), ('control layout', [[7, 2, 8, 7, 3, 2], 9, 2, 3], [9, 8, 7, 5])], [('regression: orphan parameter binding', [[5, 1, 5, 6, 7, 7, 5, 1], 10, 2, 3], [8, 9, 10, 10]), ('regression: orphan parameter binding', [[7, 6, 7, 1], 4, 3, 1], [4, 3, 4, 2, 4, 4]), ('regression: orphan parameter binding', [[9, 8, 9, 1, 6, 3, 2, 5], 5, 2, 1], [5, 4, 5, 5, 5, 5, 4, 5, 5]), ('regression: orphan parameter binding', [[5, 3, 7], 7, 3, 1], [5, 7, 3]), ('single widow pulled back', [[3, 4], 6, 2, 2], [5, 2]), ('paragraph exactly fills page', [[2, 4, 3], 6, 2, 2], [6, 3]), ('control layout', [[5, 9, 1, 5], 9, 1, 1], [9, 9, 2]), ('control layout', [[3, 4, 6, 6], 11, 1, 3], [10, 9])], [('regression: orphan parameter binding', [[1, 5, 6, 3], 7, 1, 2], [7, 6, 2]), ('regression: orphan parameter binding', [[5, 6, 5, 6, 7], 6, 3, 1], [5, 6, 5, 6, 6, 1]), ('regression: orphan parameter binding', [[7, 3, 1, 1, 8, 4, 9, 2], 5, 2, 1], [5, 5, 5, 5, 4, 5, 4, 2]), ('regression: orphan parameter binding', [[1, 7, 9, 4, 5, 8, 4], 10, 3, 2], [8, 9, 9, 8, 4]), ('single widow pulled back', [[3, 4], 6, 2, 2], [5, 2]), ('long paragraph continuation', [[2, 14], 6, 2, 2], [6, 6, 4]), ('control layout', [[7, 5, 3], 9, 3, 3], [7, 8]), ('control layout', [[5, 4, 4, 7, 8, 1, 5, 8], 6, 3, 3], [5, 4, 4, 6, 6, 4, 5, 6, 2])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    paras, H, orphan, widow = x
    pages = []
    used = 0
    for p in paras:
        rem = p
        started = True
        while rem > 0:
            room = H - used
            if rem <= room:
                used += rem
                rem = 0
                continue
            a = room
            if used > 0:
                if rem - a < widow:
                    a = max(rem - widow, 0)
                if started and a < min(orphan, widow):
                    a = 0
            used += a
            rem -= a
            if a > 0:
                started = False
            pages.append(used)
            used = 0
    if used > 0:
        pages.append(used)
    return pages
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: orphan parameter binding', [[3, 7, 8, 6, 7, 4, 2, 6], 6, 3, 1], [6, 4, 6, 6, 6, 6, 6, 3]), ('regression: orphan parameter binding', [[8, 4, 7, 9, 2], 7, 3, 1], [7, 5, 7, 7, 4]), ('regression: orphan parameter binding', [[1, 5, 3], 7, 2, 1], [6, 3]), ('regression: orphan parameter binding', [[2, 9, 7], 12, 2, 1], [11, 7]), ('paragraph exactly fills page', [[2, 4, 3], 6, 2, 2], [6, 3]), ('long paragraph continuation', [[2, 14], 6, 2, 2], [6, 6, 4]), ('control layout', [[1, 7, 1, 2, 1, 8], 8, 3, 2], [8, 8, 4]), ('control layout', [[1, 2, 8, 5, 8, 6, 7, 9], 7, 3, 3], [7, 4, 5, 7, 7, 7, 7, 2])], [('regression: orphan parameter binding', [[6, 8, 9, 2], 4, 1, 3], [4, 4, 4, 4, 4, 3, 2]), ('regression: orphan parameter binding', [[6, 8, 1, 3, 8, 9], 4, 1, 3], [4, 4, 4, 3, 4, 4, 4, 4, 4]), ('regression: orphan parameter binding', [[6, 6, 3, 3, 5, 7, 8], 11, 3, 2], [10, 11, 9, 8]), ('regression: orphan parameter binding', [[5, 4, 2, 8, 5], 5, 2, 1], [5, 4, 5, 5, 5]), ('orphan pushed forward', [[5, 3], 6, 2, 2], [5, 3]), ('long paragraph continuation', [[2, 14], 6, 2, 2], [6, 6, 4]), ('control layout', [[6, 2, 9, 7, 8, 9, 7], 8, 1, 3], [8, 8, 8, 8, 8, 8]), ('control layout', [[6, 9, 1, 5, 1, 8], 11, 2, 1], [11, 11, 8])], [('regression: orphan parameter binding', [[7, 8, 6, 2, 2, 9, 5, 6], 7, 1, 2], [7, 7, 7, 7, 7, 7, 3]), ('regression: orphan parameter binding', [[5, 3, 1, 2, 2, 9, 4, 4], 8, 3, 1], [8, 8, 6, 8]), ('regression: orphan parameter binding', [[6, 4, 6, 7, 5, 3], 8, 3, 2], [6, 8, 7, 7, 3]), ('regression: orphan parameter binding', [[6, 3, 8], 4, 3, 1], [4, 2, 3, 4, 4]), ('long paragraph continuation', [[2, 14], 6, 2, 2], [6, 6, 4]), ('single widow pulled back', [[3, 4], 6, 2, 2], [5, 2]), ('control layout', [[6, 3, 6, 7], 5, 1, 1], [5, 5, 5, 5, 2]), ('control layout', [[7, 2, 8, 7, 3, 2], 9, 2, 3], [9, 8, 7, 5])], [('regression: orphan parameter binding', [[5, 1, 5, 6, 7, 7, 5, 1], 10, 2, 3], [8, 9, 10, 10]), ('regression: orphan parameter binding', [[7, 6, 7, 1], 4, 3, 1], [4, 3, 4, 2, 4, 4]), ('regression: orphan parameter binding', [[9, 8, 9, 1, 6, 3, 2, 5], 5, 2, 1], [5, 4, 5, 5, 5, 5, 4, 5, 5]), ('regression: orphan parameter binding', [[5, 3, 7], 7, 3, 1], [5, 7, 3]), ('single widow pulled back', [[3, 4], 6, 2, 2], [5, 2]), ('paragraph exactly fills page', [[2, 4, 3], 6, 2, 2], [6, 3]), ('control layout', [[5, 9, 1, 5], 9, 1, 1], [9, 9, 2]), ('control layout', [[3, 4, 6, 6], 11, 1, 3], [10, 9])], [('regression: orphan parameter binding', [[1, 5, 6, 3], 7, 1, 2], [7, 6, 2]), ('regression: orphan parameter binding', [[5, 6, 5, 6, 7], 6, 3, 1], [5, 6, 5, 6, 6, 1]), ('regression: orphan parameter binding', [[7, 3, 1, 1, 8, 4, 9, 2], 5, 2, 1], [5, 5, 5, 5, 4, 5, 4, 2]), ('regression: orphan parameter binding', [[1, 7, 9, 4, 5, 8, 4], 10, 3, 2], [8, 9, 9, 8, 4]), ('single widow pulled back', [[3, 4], 6, 2, 2], [5, 2]), ('long paragraph continuation', [[2, 14], 6, 2, 2], [6, 6, 4]), ('control layout', [[7, 5, 3], 9, 3, 3], [7, 8]), ('control layout', [[5, 4, 4, 7, 8, 1, 5, 8], 6, 3, 3], [5, 4, 4, 6, 6, 4, 5, 6, 2])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Orphan decisions follow the widow minimum.

Input [paragraph line counts, page height, min orphan lines, min widow lines]. Lines flow onto pages. When a paragraph must break on a page that already holds lines, at least min widow lines must carry to the next page (move lines forward) and, if the paragraph starts on this page, at least min orphan lines must stay (else move it all). A paragraph that exactly fits stays. Constraints are waived on an empty page. Return lines per page.

split: open-access


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

N = 1
observations = []
def solve(x):
    text, L = x
    NO_START = '、。，．）」』！？ーぁぃぅぇぉっゃゅょ'
    NO_END = '（「『'
    HANG = '、。，．'
    lines = []
    pos = 0
    n = len(text)
    while pos < n:
        end = pos + L
        if end >= n:
            lines.append(text[pos:])
            break
        if text[end] in NO_START and (end + 1 >= n or text[end + 1] not in NO_START):
            end += 1
        else:
            while end > pos + 1 and text[end] in NO_START:
                end -= 1
            while end > pos + 1 and text[end - 1] in NO_END:
                end -= 1
        lines.append(text[pos:end])
        pos = end
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('closing bracket pushes out', ['日本語文」字組版', 4], ['日本語', '文」字組', '版']), ('regression: hanging punctuation set', ['（ーう「語っい」えあえ', 7], ['（ーう「語っ', 'い」えあえ']), ('regression: hanging punctuation set', ['い本いおお（）こーお』」きくこおきか', 3], ['い本い', 'おお', '（）', 'こー', 'お』」', 'きくこ', 'おきか']), ('regression: hanging punctuation set', ['、あゃく文え、『か、）版」日ゃ（文『か', 3], ['、あゃ', 'く文え、', '『', 'か、）', '版」', '日ゃ', '（文', '『か']), ('period hangs past the measure', ['日本語文。字組版', 4], ['日本語文。', '字組版']), ('period followed by bracket cannot hang', ['日本語文。」字組', 4], ['日本語', '文。」字', '組']), ('control layout', ['文字くい「「いおい字こく字っーー、かお本', 6], ['文字くい', '「「いおい字', 'こく字っーー、', 'かお本']), ('control layout', ['』おゃ本版「文おゃ「」。語き', 7], ['』おゃ本版「文', 'おゃ「」。語き'])], [('regression: hanging punctuation set', ['版うゃかくかうけー', 4], ['版うゃか', 'くかう', 'けー']), ('regression: hanging punctuation set', ['文か）うこ「け組ゃ版ゃ字ゃい、本え版', 5], ['文か）うこ', '「け組ゃ', '版ゃ字ゃい、', '本え版']), ('regression: hanging punctuation set', ['文け『い、あ。「日っ」『', 3], ['文け', '『い、', 'あ。', '「', '日っ」', '『']), ('regression: hanging punctuation set', ['「『ゃうくゃ組え（日本う」」」語（ー', 3], ['「『ゃ', 'うくゃ', '組え', '（日本', 'う', '」」」', '語（ー']), ('period followed by bracket cannot hang', ['日本語文。」字組', 4], ['日本語', '文。」字', '組']), ('small kana prohibited at line start', ['日本語かっこいい', 4], ['日本語', 'かっこい', 'い']), ('control layout', ['かいあ』え」き』', 8], ['かいあ』え」き』']), ('control layout', ['」う』（文え））ー文、本うく語」え、ー』（』っ', 5], ['」う』（文', 'え））ー文、', '本うく語」', 'え、ー』', '（』っ'])], [('regression: hanging punctuation set', ['「うえ『いーあ』『ー日）字日こく', 5], ['「うえ', '『いーあ』', '『ー日）字', '日こく']), ('regression: hanging punctuation set', ['かかー語ういいえ『。組おくこ、く」', 4], ['かかー語', 'ういいえ', '『。組お', 'くこ、', 'く」']), ('regression: hanging punctuation set', ['ゃ（版）文う字あゃ本語『組」', 3], ['ゃ', '（版）', '文う字', 'あゃ本', '語', '『組」']), ('regression: hanging punctuation set', ['く』』えき字『（っおゃく」く版えあ版文、', 6], ['く』』えき字', '『（っおゃ', 'く」く版えあ', '版文、']), ('period followed by bracket cannot hang', ['日本語文。」字組', 4], ['日本語', '文。」字', '組']), ('opening bracket at line end', ['日本語「文字」組版', 4], ['日本語', '「文字」', '組版']), ('control layout', ['文語日（語く文あ', 4], ['文語日', '（語く文', 'あ']), ('control layout', ['（い）」『ーえけかえ字っーき組っ', 7], ['（い）」『ーえ', 'けかえ字っーき', '組っ'])], [('regression: hanging punctuation set', ['「版お語あ「）版」『字いか日本', 6], ['「版お語あ', '「）版」『字', 'いか日本']), ('regression: hanging punctuation set', ['きき組え』うおっ（い', 7], ['きき組え』う', 'おっ（い']), ('regression: hanging punctuation set', ['く文『けいえ「日）語）文』、こっ（か文お「）」', 4], ['く文『け', 'いえ', '「日）', '語）文』、', 'こっ（か', '文お', '「）」']), ('regression: hanging punctuation set', ['ゃ「、お。おっけ）い本文きっ』え版日』）本', 8], ['ゃ「、お。おっ', 'け）い本文きっ』', 'え版日』）本']), ('closing bracket pushes out', ['日本語文」字組版', 4], ['日本語', '文」字組', '版']), ('period followed by bracket cannot hang', ['日本語文。」字組', 4], ['日本語', '文。」字', '組']), ('control layout', ['か）ーお組こ『組文ーっ版っっ文。', 3], ['か）ー', 'お組こ', '『組', '文ーっ', '版っっ', '文。']), ('control layout', ['。き日く。文。き。', 8], ['。き日く。文。き。'])], [('regression: hanging punctuation set', ['え本『」お、版あ、くあゃお、かきこ語日」おい（語', 5], ['え本『」お、', '版あ、く', 'あゃお、か', 'きこ語日」', 'おい（語']), ('regression: hanging punctuation set', ['』（『組け字』、き『あ）っ組』か語ゃ', 3], ['』', '（『組', 'け字』、', 'き', '『', 'あ）っ', '組』か', '語ゃ']), ('regression: hanging punctuation set', ['お」本版「きうい）おかきえ字）', 5], ['お」本版', '「きうい）', 'おかきえ', '字）']), ('regression: hanging punctuation set', ['」日あっ日っ）うゃ文（版けうーくこ）「', 6], ['」日あっ', '日っ）うゃ文', '（版けうーく', 'こ）「']), ('closing bracket pushes out', ['日本語文」字組版', 4], ['日本語', '文」字組', '版']), ('small kana prohibited at line start', ['日本語かっこいい', 4], ['日本語', 'かっこい', 'い']), ('control layout', ['き字こ版、）語版い字ゃいお字こ字ゃ', 3], ['き字こ', '版、）', '語版い', '字ゃい', 'お字こ', '字ゃ']), ('control layout', ['え、かけ語か「『いい日う字え', 6], ['え、かけ語か', '「『いい日う', '字え'])]]
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):
    text, L = x
    NO_START = '、。，．）」』！？ーぁぃぅぇぉっゃゅょ'
    NO_END = '（「『'
    HANG = '、。，．'
    lines = []
    pos = 0
    n = len(text)
    while pos < n:
        end = pos + L
        if end >= n:
            lines.append(text[pos:])
            break
        if text[end] in HANG + '）」' and (end + 1 >= n or text[end + 1] not in NO_START):
            end += 1
        else:
            while end > pos + 1 and text[end] in NO_START:
                end -= 1
            while end > pos + 1 and text[end - 1] in NO_END:
                end -= 1
        lines.append(text[pos:end])
        pos = end
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('closing bracket pushes out', ['日本語文」字組版', 4], ['日本語', '文」字組', '版']), ('regression: hanging punctuation set', ['（ーう「語っい」えあえ', 7], ['（ーう「語っ', 'い」えあえ']), ('regression: hanging punctuation set', ['い本いおお（）こーお』」きくこおきか', 3], ['い本い', 'おお', '（）', 'こー', 'お』」', 'きくこ', 'おきか']), ('regression: hanging punctuation set', ['、あゃく文え、『か、）版」日ゃ（文『か', 3], ['、あゃ', 'く文え、', '『', 'か、）', '版」', '日ゃ', '（文', '『か']), ('period hangs past the measure', ['日本語文。字組版', 4], ['日本語文。', '字組版']), ('period followed by bracket cannot hang', ['日本語文。」字組', 4], ['日本語', '文。」字', '組']), ('control layout', ['文字くい「「いおい字こく字っーー、かお本', 6], ['文字くい', '「「いおい字', 'こく字っーー、', 'かお本']), ('control layout', ['』おゃ本版「文おゃ「」。語き', 7], ['』おゃ本版「文', 'おゃ「」。語き'])], [('regression: hanging punctuation set', ['版うゃかくかうけー', 4], ['版うゃか', 'くかう', 'けー']), ('regression: hanging punctuation set', ['文か）うこ「け組ゃ版ゃ字ゃい、本え版', 5], ['文か）うこ', '「け組ゃ', '版ゃ字ゃい、', '本え版']), ('regression: hanging punctuation set', ['文け『い、あ。「日っ」『', 3], ['文け', '『い、', 'あ。', '「', '日っ」', '『']), ('regression: hanging punctuation set', ['「『ゃうくゃ組え（日本う」」」語（ー', 3], ['「『ゃ', 'うくゃ', '組え', '（日本', 'う', '」」」', '語（ー']), ('period followed by bracket cannot hang', ['日本語文。」字組', 4], ['日本語', '文。」字', '組']), ('small kana prohibited at line start', ['日本語かっこいい', 4], ['日本語', 'かっこい', 'い']), ('control layout', ['かいあ』え」き』', 8], ['かいあ』え」き』']), ('control layout', ['」う』（文え））ー文、本うく語」え、ー』（』っ', 5], ['」う』（文', 'え））ー文、', '本うく語」', 'え、ー』', '（』っ'])], [('regression: hanging punctuation set', ['「うえ『いーあ』『ー日）字日こく', 5], ['「うえ', '『いーあ』', '『ー日）字', '日こく']), ('regression: hanging punctuation set', ['かかー語ういいえ『。組おくこ、く」', 4], ['かかー語', 'ういいえ', '『。組お', 'くこ、', 'く」']), ('regression: hanging punctuation set', ['ゃ（版）文う字あゃ本語『組」', 3], ['ゃ', '（版）', '文う字', 'あゃ本', '語', '『組」']), ('regression: hanging punctuation set', ['く』』えき字『（っおゃく」く版えあ版文、', 6], ['く』』えき字', '『（っおゃ', 'く」く版えあ', '版文、']), ('period followed by bracket cannot hang', ['日本語文。」字組', 4], ['日本語', '文。」字', '組']), ('opening bracket at line end', ['日本語「文字」組版', 4], ['日本語', '「文字」', '組版']), ('control layout', ['文語日（語く文あ', 4], ['文語日', '（語く文', 'あ']), ('control layout', ['（い）」『ーえけかえ字っーき組っ', 7], ['（い）」『ーえ', 'けかえ字っーき', '組っ'])], [('regression: hanging punctuation set', ['「版お語あ「）版」『字いか日本', 6], ['「版お語あ', '「）版」『字', 'いか日本']), ('regression: hanging punctuation set', ['きき組え』うおっ（い', 7], ['きき組え』う', 'おっ（い']), ('regression: hanging punctuation set', ['く文『けいえ「日）語）文』、こっ（か文お「）」', 4], ['く文『け', 'いえ', '「日）', '語）文』、', 'こっ（か', '文お', '「）」']), ('regression: hanging punctuation set', ['ゃ「、お。おっけ）い本文きっ』え版日』）本', 8], ['ゃ「、お。おっ', 'け）い本文きっ』', 'え版日』）本']), ('closing bracket pushes out', ['日本語文」字組版', 4], ['日本語', '文」字組', '版']), ('period followed by bracket cannot hang', ['日本語文。」字組', 4], ['日本語', '文。」字', '組']), ('control layout', ['か）ーお組こ『組文ーっ版っっ文。', 3], ['か）ー', 'お組こ', '『組', '文ーっ', '版っっ', '文。']), ('control layout', ['。き日く。文。き。', 8], ['。き日く。文。き。'])], [('regression: hanging punctuation set', ['え本『」お、版あ、くあゃお、かきこ語日」おい（語', 5], ['え本『」お、', '版あ、く', 'あゃお、か', 'きこ語日」', 'おい（語']), ('regression: hanging punctuation set', ['』（『組け字』、き『あ）っ組』か語ゃ', 3], ['』', '（『組', 'け字』、', 'き', '『', 'あ）っ', '組』か', '語ゃ']), ('regression: hanging punctuation set', ['お」本版「きうい）おかきえ字）', 5], ['お」本版', '「きうい）', 'おかきえ', '字）']), ('regression: hanging punctuation set', ['」日あっ日っ）うゃ文（版けうーくこ）「', 6], ['」日あっ', '日っ）うゃ文', '（版けうーく', 'こ）「']), ('closing bracket pushes out', ['日本語文」字組版', 4], ['日本語', '文」字組', '版']), ('small kana prohibited at line start', ['日本語かっこいい', 4], ['日本語', 'かっこい', 'い']), ('control layout', ['き字こ版、）語版い字ゃいお字こ字ゃ', 3], ['き字こ', '版、）', '語版い', '字ゃい', 'お字こ', '字ゃ']), ('control layout', ['え、かけ語か「『いい日う字え', 6], ['え、かけ語か', '「『いい日う', '字え'])]]
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:
Long vowel marks and closing brackets hang outside the measure.

Input [text of full-width characters, line length L]. Lines take L characters. If the next character is a hanging comma/period (、。，．) and is not itself followed by a line-start-prohibited character, it hangs on the line (burasage). Otherwise move characters to the next line while the next line would start with a prohibited character (、。，．）」』！？ー and small kana), then while the line would end with an opening bracket; a line keeps at least one character. Return the lines.

split: open-access


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

N = 1
observations = []
def solve(x):
    text, L = x
    NO_START = '、。，．）」』！？ーぁぃぅぇぉっゃゅょ'
    NO_END = '（「『'
    HANG = '、。，．'
    lines = []
    pos = 0
    n = len(text)
    while pos < n:
        end = pos + L
        if end >= n:
            lines.append(text[pos:])
            break
        if text[end] in HANG:
            end += 1
        else:
            while end > pos + 1 and text[end] in NO_START:
                end -= 1
            while end > pos + 1 and text[end - 1] in NO_END:
                end -= 1
        lines.append(text[pos:end])
        pos = end
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('period followed by bracket cannot hang', ['日本語文。」字組', 4], ['日本語', '文。」字', '組']), ('regression: hang followed by closer', ['くき）『いえ本（本『、字）ー。っ」字', 3], ['くき）', '『いえ', '本（本', '『、', '字', '）', 'ー', '。っ」', '字']), ('regression: hang followed by closer', ['文字、」（ゃ日き日』組文っー、、組本きっ組', 7], ['文字、」（ゃ日', 'き日』組', '文っー、、組本', 'きっ組']), ('regression: hang followed by closer', ['「）。文お。い組、、い）、、っ」け「あえいけ日、', 4], ['「）。文', 'お。い', '組、、', 'い', '）', '、、っ」', 'け「あえ', 'いけ日、']), ('closing bracket pushes out', ['日本語文」字組版', 4], ['日本語', '文」字組', '版']), ('small kana prohibited at line start', ['日本語かっこいい', 4], ['日本語', 'かっこい', 'い']), ('control layout', ['か本うくい日「、け字ー『こ字え。う', 3], ['か本う', 'くい日', '「、け', '字ー', '『こ字', 'え。う']), ('control layout', ['け。。「）ゃおお」けゃ」かあうう）か『か字い', 5], ['け。。', '「）ゃお', 'お」けゃ」', 'かあうう）', 'か『か字い'])], [('regression: hang followed by closer', ['う」』』え組「。。『お文組う', 7], ['う」』』え組', '「。。『お文組', 'う']), ('regression: hang followed by closer', ['文字、」（ゃ日き日』組文っー、、組本きっ組', 7], ['文字、」（ゃ日', 'き日』組', '文っー、、組本', 'きっ組']), ('regression: hang followed by closer', ['日ーゃ語文「っ日あこけ語っこい語。』本『', 8], ['日ーゃ語文「っ日', 'あこけ語っこい', '語。』本『']), ('regression: hang followed by closer', ['文版ゃき、。語。あ日ーっ日『、」』、組ゃか』え', 4], ['文版ゃ', 'き、。語。', 'あ日ーっ', '日', '『、」』、', '組ゃか』', 'え']), ('closing bracket pushes out', ['日本語文」字組版', 4], ['日本語', '文」字組', '版']), ('period hangs past the measure', ['日本語文。字組版', 4], ['日本語文。', '字組版']), ('control layout', ['こ版あ）え『本）う）あい（え日組ーー『こ。き日', 6], ['こ版あ）え', '『本）う）あ', 'い（え日', '組ーー『こ。', 'き日']), ('control layout', ['）。あおく本ー』い', 4], ['）。あお', 'く本ー』', 'い'])], [('regression: hang followed by closer', ['版っ日けおく、）」版（「', 6], ['版っ日けお', 'く、）」版', '（「']), ('regression: hang followed by closer', ['文字、」（ゃ日き日』組文っー、、組本きっ組', 7], ['文字、」（ゃ日', 'き日』組', '文っー、、組本', 'きっ組']), ('regression: hang followed by closer', ['版っ』い「）ー）。）', 3], ['版っ』', 'い', '「', '）', 'ー', '）。）']), ('partial-repair probe', ['語お』、「っお日けあ版））「か字字かこえ字組版', 3], ['語お』、', '「っお', '日けあ', '版））', '「か字', '字かこ', 'え字組', '版']), ('closing bracket pushes out', ['日本語文」字組版', 4], ['日本語', '文」字組', '版']), ('opening bracket at line end', ['日本語「文字」組版', 4], ['日本語', '「文字」', '組版']), ('control layout', ['『』字）（ゃ『語けあ語か』え『い。え。日こ', 8], ['『』字）（ゃ『語', 'けあ語か』え『い。', 'え。日こ']), ('control layout', ['本かーこ））ー、文本本', 3], ['本かー', 'こ', '））ー、', '文本本'])], [('regression: hang followed by closer', ['「『日、く）、」組）っうお。（', 6], ['「『日、', 'く）、」', '組）っうお。', '（']), ('regression: hang followed by closer', ['』く「本え語おっかえい、。、きけこ組ゃこ『きあ』', 3], ['』く', '「本え', '語おっ', 'かえ', 'い、。、', 'きけこ', '組ゃこ', '『き', 'あ』']), ('regression: hang followed by closer', ['（日おあ」『こか、語。）本文っ、文えあゃ。', 5], ['（日おあ」', '『こか、', '語。）本', '文っ、文え', 'あゃ。']), ('regression: hang followed by closer', ['日組こ、『っ、ー日ーあ』っ「、き「字っ', 6], ['日組こ、', '『っ、ー日ー', 'あ』っ「、き', '「字っ']), ('period hangs past the measure', ['日本語文。字組版', 4], ['日本語文。', '字組版']), ('closing bracket pushes out', ['日本語文」字組版', 4], ['日本語', '文」字組', '版']), ('control layout', ['かい』けえ』ゃ』版日けっ）', 7], ['かい』け', 'え』ゃ』版日', 'けっ）']), ('control layout', ['文くこ、』本）。版（』（『いえ『本こ」かっか', 4], ['文く', 'こ、』', '本）。版', '（』', '（『いえ', '『本こ」', 'かっか'])], [('regression: hang followed by closer', ['うこ文版」」。。か字えーっあ」っけ』いか語いっ', 6], ['うこ文', '版」」。。か', '字えーっ', 'あ」っけ』い', 'か語いっ']), ('regression: hang followed by closer', ['いあ『本く）く。ー', 3], ['いあ', '『本', 'く）', 'く。ー']), ('regression: hang followed by closer', ['くけおけあき組。か語おき「版（。っ組えく組', 5], ['くけおけあ', 'き組。か語', 'おき「版', '（。っ組え', 'く組']), ('partial-repair probe', ['』あ「組えか語おえきゃ）組。あ文、『」えこう', 8], ['』あ「組えか語お', 'えきゃ）組。あ文、', '『」えこう']), ('period followed by bracket cannot hang', ['日本語文。」字組', 4], ['日本語', '文。」字', '組']), ('closing bracket pushes out', ['日本語文」字組版', 4], ['日本語', '文」字組', '版']), ('control layout', ['、ーく」ゃ』』ー本え組きけ本日こ』', 7], ['、ー', 'く」ゃ』』ー本', 'え組きけ本日', 'こ』']), ('control layout', ['組本）かゃ組っー', 6], ['組本）かゃ', '組っー'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    text, L = x
    NO_START = '、。，．）」』！？ーぁぃぅぇぉっゃゅょ'
    NO_END = '（「『'
    HANG = '、。，．'
    lines = []
    pos = 0
    n = len(text)
    while pos < n:
        end = pos + L
        if end >= n:
            lines.append(text[pos:])
            break
        if text[end] in HANG and (end + 1 >= n or text[end + 1] not in NO_END):
            end += 1
        else:
            while end > pos + 1 and text[end] in NO_START:
                end -= 1
            while end > pos + 1 and text[end - 1] in NO_END:
                end -= 1
        lines.append(text[pos:end])
        pos = end
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('period followed by bracket cannot hang', ['日本語文。」字組', 4], ['日本語', '文。」字', '組']), ('regression: hang followed by closer', ['くき）『いえ本（本『、字）ー。っ」字', 3], ['くき）', '『いえ', '本（本', '『、', '字', '）', 'ー', '。っ」', '字']), ('regression: hang followed by closer', ['文字、」（ゃ日き日』組文っー、、組本きっ組', 7], ['文字、」（ゃ日', 'き日』組', '文っー、、組本', 'きっ組']), ('regression: hang followed by closer', ['「）。文お。い組、、い）、、っ」け「あえいけ日、', 4], ['「）。文', 'お。い', '組、、', 'い', '）', '、、っ」', 'け「あえ', 'いけ日、']), ('closing bracket pushes out', ['日本語文」字組版', 4], ['日本語', '文」字組', '版']), ('small kana prohibited at line start', ['日本語かっこいい', 4], ['日本語', 'かっこい', 'い']), ('control layout', ['か本うくい日「、け字ー『こ字え。う', 3], ['か本う', 'くい日', '「、け', '字ー', '『こ字', 'え。う']), ('control layout', ['け。。「）ゃおお」けゃ」かあうう）か『か字い', 5], ['け。。', '「）ゃお', 'お」けゃ」', 'かあうう）', 'か『か字い'])], [('regression: hang followed by closer', ['う」』』え組「。。『お文組う', 7], ['う」』』え組', '「。。『お文組', 'う']), ('regression: hang followed by closer', ['文字、」（ゃ日き日』組文っー、、組本きっ組', 7], ['文字、」（ゃ日', 'き日』組', '文っー、、組本', 'きっ組']), ('regression: hang followed by closer', ['日ーゃ語文「っ日あこけ語っこい語。』本『', 8], ['日ーゃ語文「っ日', 'あこけ語っこい', '語。』本『']), ('regression: hang followed by closer', ['文版ゃき、。語。あ日ーっ日『、」』、組ゃか』え', 4], ['文版ゃ', 'き、。語。', 'あ日ーっ', '日', '『、」』、', '組ゃか』', 'え']), ('closing bracket pushes out', ['日本語文」字組版', 4], ['日本語', '文」字組', '版']), ('period hangs past the measure', ['日本語文。字組版', 4], ['日本語文。', '字組版']), ('control layout', ['こ版あ）え『本）う）あい（え日組ーー『こ。き日', 6], ['こ版あ）え', '『本）う）あ', 'い（え日', '組ーー『こ。', 'き日']), ('control layout', ['）。あおく本ー』い', 4], ['）。あお', 'く本ー』', 'い'])], [('regression: hang followed by closer', ['版っ日けおく、）」版（「', 6], ['版っ日けお', 'く、）」版', '（「']), ('regression: hang followed by closer', ['文字、」（ゃ日き日』組文っー、、組本きっ組', 7], ['文字、」（ゃ日', 'き日』組', '文っー、、組本', 'きっ組']), ('regression: hang followed by closer', ['版っ』い「）ー）。）', 3], ['版っ』', 'い', '「', '）', 'ー', '）。）']), ('partial-repair probe', ['語お』、「っお日けあ版））「か字字かこえ字組版', 3], ['語お』、', '「っお', '日けあ', '版））', '「か字', '字かこ', 'え字組', '版']), ('closing bracket pushes out', ['日本語文」字組版', 4], ['日本語', '文」字組', '版']), ('opening bracket at line end', ['日本語「文字」組版', 4], ['日本語', '「文字」', '組版']), ('control layout', ['『』字）（ゃ『語けあ語か』え『い。え。日こ', 8], ['『』字）（ゃ『語', 'けあ語か』え『い。', 'え。日こ']), ('control layout', ['本かーこ））ー、文本本', 3], ['本かー', 'こ', '））ー、', '文本本'])], [('regression: hang followed by closer', ['「『日、く）、」組）っうお。（', 6], ['「『日、', 'く）、」', '組）っうお。', '（']), ('regression: hang followed by closer', ['』く「本え語おっかえい、。、きけこ組ゃこ『きあ』', 3], ['』く', '「本え', '語おっ', 'かえ', 'い、。、', 'きけこ', '組ゃこ', '『き', 'あ』']), ('regression: hang followed by closer', ['（日おあ」『こか、語。）本文っ、文えあゃ。', 5], ['（日おあ」', '『こか、', '語。）本', '文っ、文え', 'あゃ。']), ('regression: hang followed by closer', ['日組こ、『っ、ー日ーあ』っ「、き「字っ', 6], ['日組こ、', '『っ、ー日ー', 'あ』っ「、き', '「字っ']), ('period hangs past the measure', ['日本語文。字組版', 4], ['日本語文。', '字組版']), ('closing bracket pushes out', ['日本語文」字組版', 4], ['日本語', '文」字組', '版']), ('control layout', ['かい』けえ』ゃ』版日けっ）', 7], ['かい』け', 'え』ゃ』版日', 'けっ）']), ('control layout', ['文くこ、』本）。版（』（『いえ『本こ」かっか', 4], ['文く', 'こ、』', '本）。版', '（』', '（『いえ', '『本こ」', 'かっか'])], [('regression: hang followed by closer', ['うこ文版」」。。か字えーっあ」っけ』いか語いっ', 6], ['うこ文', '版」」。。か', '字えーっ', 'あ」っけ』い', 'か語いっ']), ('regression: hang followed by closer', ['いあ『本く）く。ー', 3], ['いあ', '『本', 'く）', 'く。ー']), ('regression: hang followed by closer', ['くけおけあき組。か語おき「版（。っ組えく組', 5], ['くけおけあ', 'き組。か語', 'おき「版', '（。っ組え', 'く組']), ('partial-repair probe', ['』あ「組えか語おえきゃ）組。あ文、『」えこう', 8], ['』あ「組えか語お', 'えきゃ）組。あ文、', '『」えこう']), ('period followed by bracket cannot hang', ['日本語文。」字組', 4], ['日本語', '文。」字', '組']), ('closing bracket pushes out', ['日本語文」字組版', 4], ['日本語', '文」字組', '版']), ('control layout', ['、ーく」ゃ』』ー本え組きけ本日こ』', 7], ['、ー', 'く」ゃ』』ー本', 'え組きけ本日', 'こ』']), ('control layout', ['組本）かゃ組っー', 6], ['組本）かゃ', '組っー'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A period hangs while its closing bracket starts the next line.

Input [text of full-width characters, line length L]. Lines take L characters. If the next character is a hanging comma/period (、。，．) and is not itself followed by a line-start-prohibited character, it hangs on the line (burasage). Otherwise move characters to the next line while the next line would start with a prohibited character (、。，．）」』！？ー and small kana), then while the line would end with an opening bracket; a line keeps at least one character. Return the lines.

split: open-access


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

N = 1
observations = []
def solve(x):
    text, L = x
    NO_START = '、。，．）」』！？ーぁぃぅぇぉっゃゅょ'
    NO_END = '（「『'
    HANG = '、。，．'
    lines = []
    pos = 0
    n = len(text)
    while pos < n:
        end = pos + L
        if end >= n:
            lines.append(text[pos:])
            break
        if text[end] in HANG and (end + 1 >= n or text[end + 1] not in NO_START):
            end += 1
        else:
            if end > pos + 1 and text[end] in NO_START:
                end -= 1
            while end > pos + 1 and text[end - 1] in NO_END:
                end -= 1
        lines.append(text[pos:end])
        pos = end
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: push-out chain', ['、本おう）こきかえ文日おいーゃ。（け', 7], ['、本おう）こき', 'かえ文日お', 'いーゃ。（け']), ('regression: push-out chain', ['文ーう文おっ日いあうあ）いゃ）』日『字', 5], ['文ーう文', 'おっ日いあ', 'うあ）', 'いゃ）』日', '『字']), ('partial-repair probe', ['字う『、え組こ、文、ーえ」、』語う。', 8], ['字う『、え組こ、', '文、ーえ」、』語', 'う。']), ('partial-repair probe', ['本』。。くゃ（か『「', 6], ['本』。。くゃ', '（か『「']), ('closing bracket pushes out', ['日本語文」字組版', 4], ['日本語', '文」字組', '版']), ('period followed by bracket cannot hang', ['日本語文。」字組', 4], ['日本語', '文。」字', '組']), ('control layout', ['あっけあ『（き版', 4], ['あっけあ', '『（き版']), ('control layout', ['語あ』文か（おく本」', 6], ['語あ』文か', '（おく本」'])], [('regression: push-out chain', ['ゃ『くかこけう」字（く、っ『語ゃ組', 6], ['ゃ『くかこけ', 'う」字', '（く、っ', '『語ゃ組']), ('regression: push-out chain', ['けけーうけゃ）（っ』』）ゃっ組）お', 4], ['けけーう', 'けゃ）', '（', 'っ', '』', '』）ゃっ', '組）お']), ('partial-repair probe', ['か語組ゃっうこうくきくゃ日', 5], ['か語組ゃっ', 'うこうくき', 'くゃ日']), ('partial-repair probe', ['お。）語うきき文』く「日本本組『ゃ文日', 4], ['お。）語', 'うきき', '文』く', '「日本本', '組『ゃ文', '日']), ('small kana prohibited at line start', ['日本語かっこいい', 4], ['日本語', 'かっこい', 'い']), ('period hangs past the measure', ['日本語文。字組版', 4], ['日本語文。', '字組版']), ('control layout', ['文字くい「「いおい字こく字っーー、かお本', 6], ['文字くい', '「「いおい字', 'こく字っーー、', 'かお本']), ('control layout', ['お語）日版』「か文え日日こ（ー（お', 7], ['お語）日版』', '「か文え日日こ', '（ー（お'])], [('regression: push-out chain', ['い。（）。けう組。き文文日文文えっ、』あ』字組本', 6], ['い。（）。け', 'う組。き文文', '日文文', 'えっ、』あ』', '字組本']), ('regression: push-out chain', ['う版あう。、っ』、）「字。あかか、『。いおきゃ', 4], ['う版あ', 'う', '。', '、', 'っ』、）', '「字。あ', 'かか、『。', 'いおきゃ']), ('partial-repair probe', ['こあ）ー、あ）っこ、「（あ「けけっ。えかきー文', 8], ['こあ）ー、あ）っ', 'こ、「（あ「け', 'けっ。えかきー文']), ('partial-repair probe', ['。け』かあ『組け』、字', 8], ['。け』かあ『組', 'け』、字']), ('period followed by bracket cannot hang', ['日本語文。」字組', 4], ['日本語', '文。」字', '組']), ('small kana prohibited at line start', ['日本語かっこいい', 4], ['日本語', 'かっこい', 'い']), ('control layout', ['お語）日版』「か文え日日こ（ー（お', 7], ['お語）日版』', '「か文え日日こ', '（ー（お']), ('control layout', ['日うああ版字お日。日お日', 4], ['日うああ', '版字お日。', '日お日'])], [('regression: push-out chain', ['」』こ）「。きゃ」語文うう『', 4], ['」』こ）', '「。', 'きゃ」語', '文うう『']), ('regression: push-out chain', ['語け本日ゃ」）「字、字字', 5], ['語け本', '日ゃ」）', '「字、字字']), ('regression: push-out chain', ['（ゃえい。く、ああ（おあ）「文）（か語ゃ。ーけき', 3], ['（ゃえ', 'い。く、', 'ああ', '（お', 'あ）', '「文）', '（か', '語', 'ゃ。ー', 'けき']), ('partial-repair probe', ['（）本）『組こ日本）版、（かけ本', 3], ['（）', '本）', '『組こ', '日本）', '版、', '（かけ', '本']), ('small kana prohibited at line start', ['日本語かっこいい', 4], ['日本語', 'かっこい', 'い']), ('closing bracket pushes out', ['日本語文」字組版', 4], ['日本語', '文」字組', '版']), ('control layout', ['ー』版）本うかえお日', 8], ['ー』版）本うかえ', 'お日']), ('control layout', ['こう）あ、く。日語', 8], ['こう）あ、く。日', '語'])], [('regression: push-out chain', ['（『あ（日字（字「い語。字『うく版文ーゃーあ', 7], ['（『あ（日字', '（字「い語。字', '『うく版', '文ーゃーあ']), ('regression: push-out chain', ['こっ（『おあゃお字」。。組うう組、こえけ）語', 5], ['こっ（『お', 'あゃお', '字」。。組', 'うう組、こ', 'えけ）語']), ('regression: push-out chain', ['、けゃ語え語字「か語く文（、字）っ。おか、ー', 7], ['、けゃ語え語字', '「か語く文（、', '字）っ。お', 'か、ー']), ('partial-repair probe', ['かあ語、本ゃっけ」', 8], ['かあ語、本ゃっ', 'け」']), ('period followed by bracket cannot hang', ['日本語文。」字組', 4], ['日本語', '文。」字', '組']), ('opening bracket at line end', ['日本語「文字」組版', 4], ['日本語', '「文字」', '組版']), ('control layout', ['け本こ日ゃき、こう」版（', 8], ['け本こ日ゃき、こ', 'う」版（']), ('control layout', ['日」』版、。字文うえこ日', 5], ['日」』版、。', '字文うえこ', '日'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    text, L = x
    NO_START = '、。，．）」』！？ーぁぃぅぇぉっゃゅょ'
    NO_END = '（「『'
    HANG = '、。，．'
    lines = []
    pos = 0
    n = len(text)
    while pos < n:
        end = pos + L
        if end >= n:
            lines.append(text[pos:])
            break
        if text[end] in HANG and (end + 1 >= n or text[end + 1] not in NO_START):
            end += 1
        else:
            while end > pos + 1 and text[end - 1] in NO_START:
                end -= 1
            while end > pos + 1 and text[end - 1] in NO_END:
                end -= 1
        lines.append(text[pos:end])
        pos = end
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: push-out chain', ['、本おう）こきかえ文日おいーゃ。（け', 7], ['、本おう）こき', 'かえ文日お', 'いーゃ。（け']), ('regression: push-out chain', ['文ーう文おっ日いあうあ）いゃ）』日『字', 5], ['文ーう文', 'おっ日いあ', 'うあ）', 'いゃ）』日', '『字']), ('partial-repair probe', ['字う『、え組こ、文、ーえ」、』語う。', 8], ['字う『、え組こ、', '文、ーえ」、』語', 'う。']), ('partial-repair probe', ['本』。。くゃ（か『「', 6], ['本』。。くゃ', '（か『「']), ('closing bracket pushes out', ['日本語文」字組版', 4], ['日本語', '文」字組', '版']), ('period followed by bracket cannot hang', ['日本語文。」字組', 4], ['日本語', '文。」字', '組']), ('control layout', ['あっけあ『（き版', 4], ['あっけあ', '『（き版']), ('control layout', ['語あ』文か（おく本」', 6], ['語あ』文か', '（おく本」'])], [('regression: push-out chain', ['ゃ『くかこけう」字（く、っ『語ゃ組', 6], ['ゃ『くかこけ', 'う」字', '（く、っ', '『語ゃ組']), ('regression: push-out chain', ['けけーうけゃ）（っ』』）ゃっ組）お', 4], ['けけーう', 'けゃ）', '（', 'っ', '』', '』）ゃっ', '組）お']), ('partial-repair probe', ['か語組ゃっうこうくきくゃ日', 5], ['か語組ゃっ', 'うこうくき', 'くゃ日']), ('partial-repair probe', ['お。）語うきき文』く「日本本組『ゃ文日', 4], ['お。）語', 'うきき', '文』く', '「日本本', '組『ゃ文', '日']), ('small kana prohibited at line start', ['日本語かっこいい', 4], ['日本語', 'かっこい', 'い']), ('period hangs past the measure', ['日本語文。字組版', 4], ['日本語文。', '字組版']), ('control layout', ['文字くい「「いおい字こく字っーー、かお本', 6], ['文字くい', '「「いおい字', 'こく字っーー、', 'かお本']), ('control layout', ['お語）日版』「か文え日日こ（ー（お', 7], ['お語）日版』', '「か文え日日こ', '（ー（お'])], [('regression: push-out chain', ['い。（）。けう組。き文文日文文えっ、』あ』字組本', 6], ['い。（）。け', 'う組。き文文', '日文文', 'えっ、』あ』', '字組本']), ('regression: push-out chain', ['う版あう。、っ』、）「字。あかか、『。いおきゃ', 4], ['う版あ', 'う', '。', '、', 'っ』、）', '「字。あ', 'かか、『。', 'いおきゃ']), ('partial-repair probe', ['こあ）ー、あ）っこ、「（あ「けけっ。えかきー文', 8], ['こあ）ー、あ）っ', 'こ、「（あ「け', 'けっ。えかきー文']), ('partial-repair probe', ['。け』かあ『組け』、字', 8], ['。け』かあ『組', 'け』、字']), ('period followed by bracket cannot hang', ['日本語文。」字組', 4], ['日本語', '文。」字', '組']), ('small kana prohibited at line start', ['日本語かっこいい', 4], ['日本語', 'かっこい', 'い']), ('control layout', ['お語）日版』「か文え日日こ（ー（お', 7], ['お語）日版』', '「か文え日日こ', '（ー（お']), ('control layout', ['日うああ版字お日。日お日', 4], ['日うああ', '版字お日。', '日お日'])], [('regression: push-out chain', ['」』こ）「。きゃ」語文うう『', 4], ['」』こ）', '「。', 'きゃ」語', '文うう『']), ('regression: push-out chain', ['語け本日ゃ」）「字、字字', 5], ['語け本', '日ゃ」）', '「字、字字']), ('regression: push-out chain', ['（ゃえい。く、ああ（おあ）「文）（か語ゃ。ーけき', 3], ['（ゃえ', 'い。く、', 'ああ', '（お', 'あ）', '「文）', '（か', '語', 'ゃ。ー', 'けき']), ('partial-repair probe', ['（）本）『組こ日本）版、（かけ本', 3], ['（）', '本）', '『組こ', '日本）', '版、', '（かけ', '本']), ('small kana prohibited at line start', ['日本語かっこいい', 4], ['日本語', 'かっこい', 'い']), ('closing bracket pushes out', ['日本語文」字組版', 4], ['日本語', '文」字組', '版']), ('control layout', ['ー』版）本うかえお日', 8], ['ー』版）本うかえ', 'お日']), ('control layout', ['こう）あ、く。日語', 8], ['こう）あ、く。日', '語'])], [('regression: push-out chain', ['（『あ（日字（字「い語。字『うく版文ーゃーあ', 7], ['（『あ（日字', '（字「い語。字', '『うく版', '文ーゃーあ']), ('regression: push-out chain', ['こっ（『おあゃお字」。。組うう組、こえけ）語', 5], ['こっ（『お', 'あゃお', '字」。。組', 'うう組、こ', 'えけ）語']), ('regression: push-out chain', ['、けゃ語え語字「か語く文（、字）っ。おか、ー', 7], ['、けゃ語え語字', '「か語く文（、', '字）っ。お', 'か、ー']), ('partial-repair probe', ['かあ語、本ゃっけ」', 8], ['かあ語、本ゃっ', 'け」']), ('period followed by bracket cannot hang', ['日本語文。」字組', 4], ['日本語', '文。」字', '組']), ('opening bracket at line end', ['日本語「文字」組版', 4], ['日本語', '「文字」', '組版']), ('control layout', ['け本こ日ゃき、こう」版（', 8], ['け本こ日ゃき、こ', 'う」版（']), ('control layout', ['日」』版、。字文うえこ日', 5], ['日」』版、。', '字文うえこ', '日'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A run of two prohibited characters still starts the next line.

Input [text of full-width characters, line length L]. Lines take L characters. If the next character is a hanging comma/period (、。，．) and is not itself followed by a line-start-prohibited character, it hangs on the line (burasage). Otherwise move characters to the next line while the next line would start with a prohibited character (、。，．）」』！？ー and small kana), then while the line would end with an opening bracket; a line keeps at least one character. Return the lines.

split: open-access


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

N = 1
observations = []
def solve(x):
    text, L = x
    NO_START = '、。，．）」』！？ーぁぃぅぇぉっゃゅょ'
    NO_END = '（「『'
    HANG = '、。，．'
    lines = []
    pos = 0
    n = len(text)
    while pos < n:
        end = pos + L
        if end >= n:
            lines.append(text[pos:])
            break
        if text[end] in HANG and (end + 1 >= n or text[end + 1] not in NO_START):
            end += 1
        else:
            while end > pos + 1 and text[end] in NO_START:
                end -= 1
            while end > pos + 1 and text[end] in NO_END:
                end -= 1
        lines.append(text[pos:end])
        pos = end
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('opening bracket at line end', ['日本語「文字」組版', 4], ['日本語', '「文字」', '組版']), ('regression: line-end prohibition index', ['、「組ー『ここっーかえあくい語『うき組、』。え', 5], ['、「組ー', '『ここっー', 'かえあくい', '語『うき', '組、』。え']), ('partial-repair probe', ['」「、本え』え日字字ゃゃ。き組。こ組う字版（', 3], ['」「、', '本え』', 'え日字', '字ゃゃ。', 'き組。', 'こ組う', '字版（']), ('regression: line-end prohibition index', ['いこ組うい）（「く文き語文くっ本『』語お版', 6], ['いこ組うい）', '（「く文き語', '文くっ本『』', '語お版']), ('period hangs past the measure', ['日本語文。字組版', 4], ['日本語文。', '字組版']), ('small kana prohibited at line start', ['日本語かっこいい', 4], ['日本語', 'かっこい', 'い']), ('control layout', ['あお組い、おっ字こ版、』けあ）', 4], ['あお組い、', 'おっ字こ', '版、』け', 'あ）']), ('control layout', ['日」』版、。字文うえこ日', 5], ['日」』版、。', '字文うえこ', '日'])], [('regression: line-end prohibition index', ['日」（日かくっ（』版き版け本く「』え日、文「（', 5], ['日」（日か', 'くっ（』版', 'き版け本く', '「』え日、', '文「（']), ('regression: line-end prohibition index', ['』（版あけ）う文え版えくく（字「いっえ）本', 5], ['』（版あ', 'け）う文え', '版えくく', '（字「いっ', 'え）本']), ('regression: line-end prohibition index', ['お（おっ文ゃっかうあああっ字（語っ「語文くっあ本', 6], ['お（おっ', '文ゃっかうあ', 'ああっ字', '（語っ「語文', 'くっあ本']), ('regression: line-end prohibition index', ['文（（字本）あ版', 3], ['文', '（（字', '本）あ', '版']), ('period hangs past the measure', ['日本語文。字組版', 4], ['日本語文。', '字組版']), ('opening bracket at line end', ['日本語「文字」組版', 4], ['日本語', '「文字」', '組版']), ('control layout', ['）ー』文え文』きく版こああ', 3], ['）ー』', '文え', '文』き', 'く版こ', 'ああ']), ('control layout', ['本い」文か』』おこかあっ、。日』', 3], ['本い」', '文', 'か』』', 'おこか', 'あっ、。', '日』'])], [('regression: line-end prohibition index', ['っ）文日くこ版日か『文日こおえ', 3], ['っ）文', '日くこ', '版日か', '『文日', 'こおえ']), ('regression: line-end prohibition index', ['「「字）』（っ』お』く『文組こー版', 7], ['「「字）』', '（っ』お』く', '『文組こー版']), ('regression: line-end prohibition index', ['文」け本「か。「あ組ゃ「。あえ組くかー文本', 5], ['文」け本', '「か。「あ', '組ゃ「。あ', 'え組くかー', '文本']), ('regression: line-end prohibition index', ['こ語え語（こお組う日本文文うく「おか', 8], ['こ語え語（こお組', 'う日本文文うく', '「おか']), ('closing bracket pushes out', ['日本語文」字組版', 4], ['日本語', '文」字組', '版']), ('opening bracket at line end', ['日本語「文字」組版', 4], ['日本語', '「文字」', '組版']), ('control layout', ['え文お文あ本かーゃ『。えけ文', 8], ['え文お文あ本', 'かーゃ『。えけ文']), ('control layout', ['、お『組えっ版字』ゃ版。組う日く」、。', 8], ['、お『組えっ版', '字』ゃ版。組う日', 'く」、。'])], [('regression: line-end prohibition index', ['ーゃゃ文。語語うくか」いか。えあ『か組', 8], ['ーゃゃ文。語語う', 'くか」いか。えあ', '『か組']), ('regression: line-end prohibition index', ['いあ『本く）く。ー', 3], ['いあ', '『本', 'く）', 'く。ー']), ('partial-repair probe', ['く字日本（）あ。え。『日、組文', 3], ['く字日', '本（）', 'あ。え。', '『日、', '組文']), ('regression: line-end prohibition index', ['版か語文っ」「か』お」。本。け「くうゃ『い本', 6], ['版か語文っ」', '「か』お」。', '本。け「く', 'うゃ『い本']), ('closing bracket pushes out', ['日本語文」字組版', 4], ['日本語', '文」字組', '版']), ('period hangs past the measure', ['日本語文。字組版', 4], ['日本語文。', '字組版']), ('control layout', ['」かき、え字版語、組お字', 5], ['」かき、え', '字版語、組', 'お字']), ('control layout', ['「かーき語組語「', 6], ['「かーき語組', '語「'])], [('regression: line-end prohibition index', ['「日う（っ。き「。け日「あ『ーか版文文あ（「', 6], ['「日う（っ。', 'き「。け日', '「あ『ーか版', '文文あ（「']), ('regression: line-end prohibition index', ['語語字けかあ版本『』字くえいき（組版あえ組こ語', 5], ['語語字けか', 'あ版本『』', '字くえいき', '（組版あえ', '組こ語']), ('regression: line-end prohibition index', ['っ「かっ版（ー『う」ー字（語う本ゃゃ本ー。あ』', 8], ['っ「かっ版（ー', '『う」ー字（語う', '本ゃゃ本ー。あ』']), ('regression: line-end prohibition index', ['『か、えあ字『こ日', 7], ['『か、えあ字', '『こ日']), ('opening bracket at line end', ['日本語「文字」組版', 4], ['日本語', '「文字」', '組版']), ('small kana prohibited at line start', ['日本語かっこいい', 4], ['日本語', 'かっこい', 'い']), ('control layout', ['」）版こあうかくーい版ー文「文き（', 6], ['」）版こあう', 'かくーい版ー', '文「文き（']), ('control layout', ['「かーき語組語「', 6], ['「かーき語組', '語「'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    text, L = x
    NO_START = '、。，．）」』！？ーぁぃぅぇぉっゃゅょ'
    NO_END = '（「『'
    HANG = '、。，．'
    lines = []
    pos = 0
    n = len(text)
    while pos < n:
        end = pos + L
        if end >= n:
            lines.append(text[pos:])
            break
        if text[end] in HANG and (end + 1 >= n or text[end + 1] not in NO_START):
            end += 1
        else:
            while end > pos + 1 and text[end] in NO_START:
                end -= 1
            while end > pos + 1 and text[end - 2] in NO_END:
                end -= 1
        lines.append(text[pos:end])
        pos = end
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('opening bracket at line end', ['日本語「文字」組版', 4], ['日本語', '「文字」', '組版']), ('regression: line-end prohibition index', ['、「組ー『ここっーかえあくい語『うき組、』。え', 5], ['、「組ー', '『ここっー', 'かえあくい', '語『うき', '組、』。え']), ('partial-repair probe', ['」「、本え』え日字字ゃゃ。き組。こ組う字版（', 3], ['」「、', '本え』', 'え日字', '字ゃゃ。', 'き組。', 'こ組う', '字版（']), ('regression: line-end prohibition index', ['いこ組うい）（「く文き語文くっ本『』語お版', 6], ['いこ組うい）', '（「く文き語', '文くっ本『』', '語お版']), ('period hangs past the measure', ['日本語文。字組版', 4], ['日本語文。', '字組版']), ('small kana prohibited at line start', ['日本語かっこいい', 4], ['日本語', 'かっこい', 'い']), ('control layout', ['あお組い、おっ字こ版、』けあ）', 4], ['あお組い、', 'おっ字こ', '版、』け', 'あ）']), ('control layout', ['日」』版、。字文うえこ日', 5], ['日」』版、。', '字文うえこ', '日'])], [('regression: line-end prohibition index', ['日」（日かくっ（』版き版け本く「』え日、文「（', 5], ['日」（日か', 'くっ（』版', 'き版け本く', '「』え日、', '文「（']), ('regression: line-end prohibition index', ['』（版あけ）う文え版えくく（字「いっえ）本', 5], ['』（版あ', 'け）う文え', '版えくく', '（字「いっ', 'え）本']), ('regression: line-end prohibition index', ['お（おっ文ゃっかうあああっ字（語っ「語文くっあ本', 6], ['お（おっ', '文ゃっかうあ', 'ああっ字', '（語っ「語文', 'くっあ本']), ('regression: line-end prohibition index', ['文（（字本）あ版', 3], ['文', '（（字', '本）あ', '版']), ('period hangs past the measure', ['日本語文。字組版', 4], ['日本語文。', '字組版']), ('opening bracket at line end', ['日本語「文字」組版', 4], ['日本語', '「文字」', '組版']), ('control layout', ['）ー』文え文』きく版こああ', 3], ['）ー』', '文え', '文』き', 'く版こ', 'ああ']), ('control layout', ['本い」文か』』おこかあっ、。日』', 3], ['本い」', '文', 'か』』', 'おこか', 'あっ、。', '日』'])], [('regression: line-end prohibition index', ['っ）文日くこ版日か『文日こおえ', 3], ['っ）文', '日くこ', '版日か', '『文日', 'こおえ']), ('regression: line-end prohibition index', ['「「字）』（っ』お』く『文組こー版', 7], ['「「字）』', '（っ』お』く', '『文組こー版']), ('regression: line-end prohibition index', ['文」け本「か。「あ組ゃ「。あえ組くかー文本', 5], ['文」け本', '「か。「あ', '組ゃ「。あ', 'え組くかー', '文本']), ('regression: line-end prohibition index', ['こ語え語（こお組う日本文文うく「おか', 8], ['こ語え語（こお組', 'う日本文文うく', '「おか']), ('closing bracket pushes out', ['日本語文」字組版', 4], ['日本語', '文」字組', '版']), ('opening bracket at line end', ['日本語「文字」組版', 4], ['日本語', '「文字」', '組版']), ('control layout', ['え文お文あ本かーゃ『。えけ文', 8], ['え文お文あ本', 'かーゃ『。えけ文']), ('control layout', ['、お『組えっ版字』ゃ版。組う日く」、。', 8], ['、お『組えっ版', '字』ゃ版。組う日', 'く」、。'])], [('regression: line-end prohibition index', ['ーゃゃ文。語語うくか」いか。えあ『か組', 8], ['ーゃゃ文。語語う', 'くか」いか。えあ', '『か組']), ('regression: line-end prohibition index', ['いあ『本く）く。ー', 3], ['いあ', '『本', 'く）', 'く。ー']), ('partial-repair probe', ['く字日本（）あ。え。『日、組文', 3], ['く字日', '本（）', 'あ。え。', '『日、', '組文']), ('regression: line-end prohibition index', ['版か語文っ」「か』お」。本。け「くうゃ『い本', 6], ['版か語文っ」', '「か』お」。', '本。け「く', 'うゃ『い本']), ('closing bracket pushes out', ['日本語文」字組版', 4], ['日本語', '文」字組', '版']), ('period hangs past the measure', ['日本語文。字組版', 4], ['日本語文。', '字組版']), ('control layout', ['」かき、え字版語、組お字', 5], ['」かき、え', '字版語、組', 'お字']), ('control layout', ['「かーき語組語「', 6], ['「かーき語組', '語「'])], [('regression: line-end prohibition index', ['「日う（っ。き「。け日「あ『ーか版文文あ（「', 6], ['「日う（っ。', 'き「。け日', '「あ『ーか版', '文文あ（「']), ('regression: line-end prohibition index', ['語語字けかあ版本『』字くえいき（組版あえ組こ語', 5], ['語語字けか', 'あ版本『』', '字くえいき', '（組版あえ', '組こ語']), ('regression: line-end prohibition index', ['っ「かっ版（ー『う」ー字（語う本ゃゃ本ー。あ』', 8], ['っ「かっ版（ー', '『う」ー字（語う', '本ゃゃ本ー。あ』']), ('regression: line-end prohibition index', ['『か、えあ字『こ日', 7], ['『か、えあ字', '『こ日']), ('opening bracket at line end', ['日本語「文字」組版', 4], ['日本語', '「文字」', '組版']), ('small kana prohibited at line start', ['日本語かっこいい', 4], ['日本語', 'かっこい', 'い']), ('control layout', ['」）版こあうかくーい版ー文「文き（', 6], ['」）版こあう', 'かくーい版ー', '文「文き（']), ('control layout', ['「かーき語組語「', 6], ['「かーき語組', '語「'])]]
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:
Lines end with an opening bracket.

Input [text of full-width characters, line length L]. Lines take L characters. If the next character is a hanging comma/period (、。，．) and is not itself followed by a line-start-prohibited character, it hangs on the line (burasage). Otherwise move characters to the next line while the next line would start with a prohibited character (、。，．）」』！？ー and small kana), then while the line would end with an opening bracket; a line keeps at least one character. Return the lines.

split: open-access


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

N = 1
observations = []
def solve(x):
    text, L = x
    NO_START = '、。，．）」』！？ーぁぃぅぇぉっゃゅょ'
    NO_END = '（「『'
    HANG = '、。，．'
    lines = []
    pos = 0
    n = len(text)
    while pos < n:
        end = pos + L
        if end >= n:
            lines.append(text[pos:])
            break
        if text[end] in HANG and (end + 1 >= n or text[end + 1] not in NO_START):
            end += 1
        else:
            while end > pos + 2 and text[end] in NO_START:
                end -= 1
            while end > pos + 1 and text[end - 1] in NO_END:
                end -= 1
        lines.append(text[pos:end])
        pos = end
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: minimum line content', ['『ー』かい組ー（本」ー、、本か語っけーえ組か', 3], ['『ー』', 'かい', '組ー', '（', '本', '」ー、、', '本か', '語っ', 'けーえ', '組か']), ('regression: minimum line content', ['ゃ、』ーっお字き『あーけお（こ文けゃ』本語組ゃ文', 4], ['ゃ', '、』ーっ', 'お字き', '『あーけ', 'お（こ文', 'けゃ』本', '語組ゃ文']), ('regression: minimum line content', ['う版あう。、っ』、）「字。あかか、『。いおきゃ', 4], ['う版あ', 'う', '。', '、', 'っ』、）', '「字。あ', 'かか、『。', 'いおきゃ']), ('partial-repair probe', ['、ーく」ゃ』』ー本え組きけ本日こ』', 7], ['、ー', 'く」ゃ』』ー本', 'え組きけ本日', 'こ』']), ('small kana prohibited at line start', ['日本語かっこいい', 4], ['日本語', 'かっこい', 'い']), ('period followed by bracket cannot hang', ['日本語文。」字組', 4], ['日本語', '文。」字', '組']), ('control layout', ['）っ（こき文う字）お字本かー語本（字か', 4], ['）っ（こ', 'き文う', '字）お字', '本かー語', '本（字か']), ('control layout', ['こえきかう「（（版', 7], ['こえきかう', '「（（版'])], [('regression: minimum line content', ['文け『い、あ。「日っ」『', 3], ['文け', '『い、', 'あ。', '「', '日っ」', '『']), ('regression: minimum line content', ['け（こーっ版く」）あ）う組）けあ（う', 3], ['け', '（', 'こーっ', '版', 'く」）', 'あ）う', '組）け', 'あ（う']), ('regression: minimum line content', ['「）。文お。い組、、い）、、っ」け「あえいけ日、', 4], ['「）。文', 'お。い', '組、、', 'い', '）', '、、っ」', 'け「あえ', 'いけ日、']), ('regression: minimum line content', ['けけーうけゃ）（っ』』）ゃっ組）お', 4], ['けけーう', 'けゃ）', '（', 'っ', '』', '』）ゃっ', '組）お']), ('closing bracket pushes out', ['日本語文」字組版', 4], ['日本語', '文」字組', '版']), ('period hangs past the measure', ['日本語文。字組版', 4], ['日本語文。', '字組版']), ('control layout', ['（）字「文版い字ー「版ーっ「。』組字組けあか「', 8], ['（）字「文版い', '字ー「版ーっ', '「。』組字組けあ', 'か「']), ('control layout', ['『ー組い、文おけええ「本文か語、ゃお版（か語版『', 6], ['『ー組い、文', 'おけええ「本', '文か語、ゃお', '版（か語版『'])], [('regression: minimum line content', ['、あゃく文え、『か、）版」日ゃ（文『か', 3], ['、あゃ', 'く文え、', '『', 'か、）', '版」', '日ゃ', '（文', '『か']), ('regression: minimum line content', ['文え（』い。版組（あえう語』、）ー本。『組', 3], ['文え', '（』い。', '版組', '（あえ', 'う', '語', '』', '、）ー', '本。', '『組']), ('regression: minimum line content', ['字きあ）ー『、いあけーけ字字、（き。ー』」」』（', 5], ['字きあ）ー', '『、いあ', 'けーけ字字、', '（', 'き', '。', 'ー』」」』', '（']), ('regression: minimum line content', ['版（組）ーー。）日くああ本', 5], ['版', '（', '組', '）ーー。）', '日くああ本']), ('period followed by bracket cannot hang', ['日本語文。」字組', 4], ['日本語', '文。」字', '組']), ('small kana prohibited at line start', ['日本語かっこいい', 4], ['日本語', 'かっこい', 'い']), ('control layout', ['え、かけ語か「『いい日う字え', 6], ['え、かけ語か', '「『いい日う', '字え']), ('control layout', ['けいかお本。。き、こお」こ語語「か組っ「本「', 5], ['けいかお', '本。。き、', 'こお」こ語', '語「か組っ', '「本「'])], [('regression: minimum line content', ['け（こーっ版く」）あ）う組）けあ（う', 3], ['け', '（', 'こーっ', '版', 'く」）', 'あ）う', '組）け', 'あ（う']), ('regression: minimum line content', ['けこけ」組』かお字本いく』「本（い（ゃゃ）かゃ字', 3], ['けこ', 'け」', '組』か', 'お字本', 'いく』', '「本', '（い', '（', 'ゃゃ）', 'かゃ字']), ('regression: minimum line content', ['あく』』ゃあ版き「文』日ううあこ', 4], ['あ', 'く』』ゃ', 'あ版き', '「文』日', 'ううあこ']), ('regression: minimum line content', ['う版あう。、っ』、）「字。あかか、『。いおきゃ', 4], ['う版あ', 'う', '。', '、', 'っ』、）', '「字。あ', 'かか、『。', 'いおきゃ']), ('opening bracket at line end', ['日本語「文字」組版', 4], ['日本語', '「文字」', '組版']), ('period hangs past the measure', ['日本語文。字組版', 4], ['日本語文。', '字組版']), ('control layout', ['本。け本きえこ』', 5], ['本。け本き', 'えこ』']), ('control layout', ['ゃ語く）う、『こ日お組』き『日くこおおい」文ゃ『', 5], ['ゃ語く）う、', '『こ日お', '組』き『日', 'くこおお', 'い」文ゃ『'])], [('regression: minimum line content', ['文ゃー語あ。かこ本か、字、字「ゃおゃ』」、っ', 4], ['文ゃー語', 'あ。かこ', '本か、字、', '字「ゃ', 'お', 'ゃ', '』」、っ']), ('regression: minimum line content', ['字きあ）ー『、いあけーけ字字、（き。ー』」」』（', 5], ['字きあ）ー', '『、いあ', 'けーけ字字、', '（', 'き', '。', 'ー』」」』', '（']), ('regression: minimum line content', ['けけーうけゃ）（っ』』）ゃっ組）お', 4], ['けけーう', 'けゃ）', '（', 'っ', '』', '』）ゃっ', '組）お']), ('regression: minimum line content', ['語字、え『えくゃえー』』ーこ組「日『。（', 4], ['語字、え', '『えくゃ', 'え', 'ー』』ー', 'こ組「日', '『。（']), ('period hangs past the measure', ['日本語文。字組版', 4], ['日本語文。', '字組版']), ('period followed by bracket cannot hang', ['日本語文。」字組', 4], ['日本語', '文。」字', '組']), ('control layout', ['語け本日ゃ」）「字、字字', 5], ['語け本', '日ゃ」）', '「字、字字']), ('control layout', ['「『日、く）、」組）っうお。（', 6], ['「『日、', 'く）、」', '組）っうお。', '（'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    text, L = x
    NO_START = '、。，．）」』！？ーぁぃぅぇぉっゃゅょ'
    NO_END = '（「『'
    HANG = '、。，．'
    lines = []
    pos = 0
    n = len(text)
    while pos < n:
        end = pos + L
        if end >= n:
            lines.append(text[pos:])
            break
        if text[end] in HANG and (end + 1 >= n or text[end + 1] not in NO_START):
            end += 1
        else:
            while end > pos + L // 2 and text[end] in NO_START:
                end -= 1
            while end > pos + 1 and text[end - 1] in NO_END:
                end -= 1
        lines.append(text[pos:end])
        pos = end
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: minimum line content', ['『ー』かい組ー（本」ー、、本か語っけーえ組か', 3], ['『ー』', 'かい', '組ー', '（', '本', '」ー、、', '本か', '語っ', 'けーえ', '組か']), ('regression: minimum line content', ['ゃ、』ーっお字き『あーけお（こ文けゃ』本語組ゃ文', 4], ['ゃ', '、』ーっ', 'お字き', '『あーけ', 'お（こ文', 'けゃ』本', '語組ゃ文']), ('regression: minimum line content', ['う版あう。、っ』、）「字。あかか、『。いおきゃ', 4], ['う版あ', 'う', '。', '、', 'っ』、）', '「字。あ', 'かか、『。', 'いおきゃ']), ('partial-repair probe', ['、ーく」ゃ』』ー本え組きけ本日こ』', 7], ['、ー', 'く」ゃ』』ー本', 'え組きけ本日', 'こ』']), ('small kana prohibited at line start', ['日本語かっこいい', 4], ['日本語', 'かっこい', 'い']), ('period followed by bracket cannot hang', ['日本語文。」字組', 4], ['日本語', '文。」字', '組']), ('control layout', ['）っ（こき文う字）お字本かー語本（字か', 4], ['）っ（こ', 'き文う', '字）お字', '本かー語', '本（字か']), ('control layout', ['こえきかう「（（版', 7], ['こえきかう', '「（（版'])], [('regression: minimum line content', ['文け『い、あ。「日っ」『', 3], ['文け', '『い、', 'あ。', '「', '日っ」', '『']), ('regression: minimum line content', ['け（こーっ版く」）あ）う組）けあ（う', 3], ['け', '（', 'こーっ', '版', 'く」）', 'あ）う', '組）け', 'あ（う']), ('regression: minimum line content', ['「）。文お。い組、、い）、、っ」け「あえいけ日、', 4], ['「）。文', 'お。い', '組、、', 'い', '）', '、、っ」', 'け「あえ', 'いけ日、']), ('regression: minimum line content', ['けけーうけゃ）（っ』』）ゃっ組）お', 4], ['けけーう', 'けゃ）', '（', 'っ', '』', '』）ゃっ', '組）お']), ('closing bracket pushes out', ['日本語文」字組版', 4], ['日本語', '文」字組', '版']), ('period hangs past the measure', ['日本語文。字組版', 4], ['日本語文。', '字組版']), ('control layout', ['（）字「文版い字ー「版ーっ「。』組字組けあか「', 8], ['（）字「文版い', '字ー「版ーっ', '「。』組字組けあ', 'か「']), ('control layout', ['『ー組い、文おけええ「本文か語、ゃお版（か語版『', 6], ['『ー組い、文', 'おけええ「本', '文か語、ゃお', '版（か語版『'])], [('regression: minimum line content', ['、あゃく文え、『か、）版」日ゃ（文『か', 3], ['、あゃ', 'く文え、', '『', 'か、）', '版」', '日ゃ', '（文', '『か']), ('regression: minimum line content', ['文え（』い。版組（あえう語』、）ー本。『組', 3], ['文え', '（』い。', '版組', '（あえ', 'う', '語', '』', '、）ー', '本。', '『組']), ('regression: minimum line content', ['字きあ）ー『、いあけーけ字字、（き。ー』」」』（', 5], ['字きあ）ー', '『、いあ', 'けーけ字字、', '（', 'き', '。', 'ー』」」』', '（']), ('regression: minimum line content', ['版（組）ーー。）日くああ本', 5], ['版', '（', '組', '）ーー。）', '日くああ本']), ('period followed by bracket cannot hang', ['日本語文。」字組', 4], ['日本語', '文。」字', '組']), ('small kana prohibited at line start', ['日本語かっこいい', 4], ['日本語', 'かっこい', 'い']), ('control layout', ['え、かけ語か「『いい日う字え', 6], ['え、かけ語か', '「『いい日う', '字え']), ('control layout', ['けいかお本。。き、こお」こ語語「か組っ「本「', 5], ['けいかお', '本。。き、', 'こお」こ語', '語「か組っ', '「本「'])], [('regression: minimum line content', ['け（こーっ版く」）あ）う組）けあ（う', 3], ['け', '（', 'こーっ', '版', 'く」）', 'あ）う', '組）け', 'あ（う']), ('regression: minimum line content', ['けこけ」組』かお字本いく』「本（い（ゃゃ）かゃ字', 3], ['けこ', 'け」', '組』か', 'お字本', 'いく』', '「本', '（い', '（', 'ゃゃ）', 'かゃ字']), ('regression: minimum line content', ['あく』』ゃあ版き「文』日ううあこ', 4], ['あ', 'く』』ゃ', 'あ版き', '「文』日', 'ううあこ']), ('regression: minimum line content', ['う版あう。、っ』、）「字。あかか、『。いおきゃ', 4], ['う版あ', 'う', '。', '、', 'っ』、）', '「字。あ', 'かか、『。', 'いおきゃ']), ('opening bracket at line end', ['日本語「文字」組版', 4], ['日本語', '「文字」', '組版']), ('period hangs past the measure', ['日本語文。字組版', 4], ['日本語文。', '字組版']), ('control layout', ['本。け本きえこ』', 5], ['本。け本き', 'えこ』']), ('control layout', ['ゃ語く）う、『こ日お組』き『日くこおおい」文ゃ『', 5], ['ゃ語く）う、', '『こ日お', '組』き『日', 'くこおお', 'い」文ゃ『'])], [('regression: minimum line content', ['文ゃー語あ。かこ本か、字、字「ゃおゃ』」、っ', 4], ['文ゃー語', 'あ。かこ', '本か、字、', '字「ゃ', 'お', 'ゃ', '』」、っ']), ('regression: minimum line content', ['字きあ）ー『、いあけーけ字字、（き。ー』」」』（', 5], ['字きあ）ー', '『、いあ', 'けーけ字字、', '（', 'き', '。', 'ー』」」』', '（']), ('regression: minimum line content', ['けけーうけゃ）（っ』』）ゃっ組）お', 4], ['けけーう', 'けゃ）', '（', 'っ', '』', '』）ゃっ', '組）お']), ('regression: minimum line content', ['語字、え『えくゃえー』』ーこ組「日『。（', 4], ['語字、え', '『えくゃ', 'え', 'ー』』ー', 'こ組「日', '『。（']), ('period hangs past the measure', ['日本語文。字組版', 4], ['日本語文。', '字組版']), ('period followed by bracket cannot hang', ['日本語文。」字組', 4], ['日本語', '文。」字', '組']), ('control layout', ['語け本日ゃ」）「字、字字', 5], ['語け本', '日ゃ」）', '「字、字字']), ('control layout', ['「『日、く）、」組）っうお。（', 6], ['「『日、', 'く）、」', '組）っうお。', '（'])]]
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:
Short measures leave two-character lines where one would be legal.

Input [text of full-width characters, line length L]. Lines take L characters. If the next character is a hanging comma/period (、。，．) and is not itself followed by a line-start-prohibited character, it hangs on the line (burasage). Otherwise move characters to the next line while the next line would start with a prohibited character (、。，．）」』！？ー and small kana), then while the line would end with an opening bracket; a line keeps at least one character. Return the lines.

split: open-access


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

N = 1
observations = []
def solve(x):
    text, L = x
    NO_START = '、。，．）」』！？'
    NO_END = '（「『'
    HANG = '、。，．'
    lines = []
    pos = 0
    n = len(text)
    while pos < n:
        end = pos + L
        if end >= n:
            lines.append(text[pos:])
            break
        if text[end] in HANG and (end + 1 >= n or text[end + 1] not in NO_START):
            end += 1
        else:
            while end > pos + 1 and text[end] in NO_START:
                end -= 1
            while end > pos + 1 and text[end - 1] in NO_END:
                end -= 1
        lines.append(text[pos:end])
        pos = end
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('small kana prohibited at line start', ['日本語かっこいい', 4], ['日本語', 'かっこい', 'い']), ('regression: small kana strictness', ['こあ）ー、あ）っこ、「（あ「けけっ。えかきー文', 8], ['こあ）ー、あ）っ', 'こ、「（あ「け', 'けっ。えかきー文']), ('regression: small kana strictness', ['（）字「文版い字ー「版ーっ「。』組字組けあか「', 8], ['（）字「文版い', '字ー「版ーっ', '「。』組字組けあ', 'か「']), ('regression: small kana strictness', ['語かおい。字ー」きくおあけ『', 6], ['語かおい。', '字ー」きくお', 'あけ『']), ('period hangs past the measure', ['日本語文。字組版', 4], ['日本語文。', '字組版']), ('period followed by bracket cannot hang', ['日本語文。」字組', 4], ['日本語', '文。」字', '組']), ('control layout', ['組『「（くお字き「本け、くえ日「。。」（お', 8], ['組『「（くお字き', '「本け、くえ日', '「。。」（お']), ('control layout', ['、』ゃあこけ字文お」かーかー。けきー', 8], ['、』ゃあこけ字文', 'お」かーかー。け', 'きー'])], [('regression: small kana strictness', ['きあ。えーくーゃい', 4], ['きあ。', 'えー', 'くーゃい']), ('regression: small kana strictness', ['本『く、ゃ本かっ', 7], ['本『く、ゃ本', 'かっ']), ('regression: small kana strictness', ['語字、え『えくゃえー』』ーこ組「日『。（', 4], ['語字、え', '『えくゃ', 'え', 'ー』』ー', 'こ組「日', '『。（']), ('regression: small kana strictness', ['けこ。語く「組き語け）おい組文うー', 8], ['けこ。語く「組き', '語け）おい組文', 'うー']), ('closing bracket pushes out', ['日本語文」字組版', 4], ['日本語', '文」字組', '版']), ('period followed by bracket cannot hang', ['日本語文。」字組', 4], ['日本語', '文。」字', '組']), ('control layout', ['、け）「文本、語文『こ（字けこ', 5], ['、け）「文', '本、語文', '『こ（字け', 'こ']), ('control layout', ['け（え）けうけ語「組『けーく字え字', 5], ['け（え）け', 'うけ語「組', '『けーく字', 'え字'])], [('regression: small kana strictness', ['日組こ、『っ、ー日ーあ』っ「、き「字っ', 6], ['日組こ、', '『っ、ー日ー', 'あ』っ「、き', '「字っ']), ('regression: small kana strictness', ['えい語く』うっき版うく『）ゃけか', 3], ['えい語', 'く』', 'うっき', '版うく', '『）ゃ', 'けか']), ('regression: small kana strictness', ['（）字「文版い字ー「版ーっ「。』組字組けあか「', 8], ['（）字「文版い', '字ー「版ーっ', '「。』組字組けあ', 'か「']), ('regression: small kana strictness', ['版っ』い「）ー）。）', 3], ['版っ』', 'い', '「', '）', 'ー', '）。）']), ('opening bracket at line end', ['日本語「文字」組版', 4], ['日本語', '「文字」', '組版']), ('closing bracket pushes out', ['日本語文」字組版', 4], ['日本語', '文」字組', '版']), ('control layout', ['っ日本語字こ（く」『、こう文かいえ。。ー', 8], ['っ日本語字こ', '（く」『、こう文', 'かいえ。。ー']), ('control layout', ['語う版っこう『」', 8], ['語う版っこう『」'])], [('regression: small kana strictness', ['）文っ語（く」（。いお、『』ー版版', 7], ['）文っ語（く」', '（。いお、', '『』ー版版']), ('regression: small kana strictness', ['きあ。えーくーゃい', 4], ['きあ。', 'えー', 'くーゃい']), ('regression: small kana strictness', ['いあ『本く）く。ー', 3], ['いあ', '『本', 'く）', 'く。ー']), ('regression: small kana strictness', ['語字、え『えくゃえー』』ーこ組「日『。（', 4], ['語字、え', '『えくゃ', 'え', 'ー』』ー', 'こ組「日', '『。（']), ('period followed by bracket cannot hang', ['日本語文。」字組', 4], ['日本語', '文。」字', '組']), ('opening bracket at line end', ['日本語「文字」組版', 4], ['日本語', '「文字」', '組版']), ('control layout', ['）、えゃ語うかえ「本あこ（字）ーえ字あか版』', 6], ['）、えゃ語う', 'かえ「本あこ', '（字）ーえ字', 'あか版』']), ('control layout', ['あ。」あ文（け版。日）語え』', 6], ['あ。」あ文', '（け版。日）', '語え』'])], [('regression: small kana strictness', ['版ー『版かゃき組本字』', 5], ['版ー『版', 'かゃき組本', '字』']), ('regression: small kana strictness', ['（日おあ」『こか、語。）本文っ、文えあゃ。', 5], ['（日おあ」', '『こか、', '語。）本', '文っ、文え', 'あゃ。']), ('regression: small kana strictness', ['文。いいおっけー本。う「ういおくかえ', 7], ['文。いいおっ', 'けー本。う「う', 'いおくかえ']), ('regression: small kana strictness', ['きっ文こ」あ。けけききき「日ー文ーか、い。', 7], ['きっ文こ」あ。', 'けけききき', '「日ー文ーか、', 'い。']), ('opening bracket at line end', ['日本語「文字」組版', 4], ['日本語', '「文字」', '組版']), ('period hangs past the measure', ['日本語文。字組版', 4], ['日本語文。', '字組版']), ('control layout', ['版っ日けおく、）」版（「', 6], ['版っ日けお', 'く、）」版', '（「']), ('control layout', ['こあく。（く版「うえけ。。。え', 8], ['こあく。（く版', '「うえけ。。。え'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    text, L = x
    NO_START = '、。，．）」』！？ぁぃぅぇぉっゃゅょ'
    NO_END = '（「『'
    HANG = '、。，．'
    lines = []
    pos = 0
    n = len(text)
    while pos < n:
        end = pos + L
        if end >= n:
            lines.append(text[pos:])
            break
        if text[end] in HANG and (end + 1 >= n or text[end + 1] not in NO_START):
            end += 1
        else:
            while end > pos + 1 and text[end] in NO_START:
                end -= 1
            while end > pos + 1 and text[end - 1] in NO_END:
                end -= 1
        lines.append(text[pos:end])
        pos = end
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('small kana prohibited at line start', ['日本語かっこいい', 4], ['日本語', 'かっこい', 'い']), ('regression: small kana strictness', ['こあ）ー、あ）っこ、「（あ「けけっ。えかきー文', 8], ['こあ）ー、あ）っ', 'こ、「（あ「け', 'けっ。えかきー文']), ('regression: small kana strictness', ['（）字「文版い字ー「版ーっ「。』組字組けあか「', 8], ['（）字「文版い', '字ー「版ーっ', '「。』組字組けあ', 'か「']), ('regression: small kana strictness', ['語かおい。字ー」きくおあけ『', 6], ['語かおい。', '字ー」きくお', 'あけ『']), ('period hangs past the measure', ['日本語文。字組版', 4], ['日本語文。', '字組版']), ('period followed by bracket cannot hang', ['日本語文。」字組', 4], ['日本語', '文。」字', '組']), ('control layout', ['組『「（くお字き「本け、くえ日「。。」（お', 8], ['組『「（くお字き', '「本け、くえ日', '「。。」（お']), ('control layout', ['、』ゃあこけ字文お」かーかー。けきー', 8], ['、』ゃあこけ字文', 'お」かーかー。け', 'きー'])], [('regression: small kana strictness', ['きあ。えーくーゃい', 4], ['きあ。', 'えー', 'くーゃい']), ('regression: small kana strictness', ['本『く、ゃ本かっ', 7], ['本『く、ゃ本', 'かっ']), ('regression: small kana strictness', ['語字、え『えくゃえー』』ーこ組「日『。（', 4], ['語字、え', '『えくゃ', 'え', 'ー』』ー', 'こ組「日', '『。（']), ('regression: small kana strictness', ['けこ。語く「組き語け）おい組文うー', 8], ['けこ。語く「組き', '語け）おい組文', 'うー']), ('closing bracket pushes out', ['日本語文」字組版', 4], ['日本語', '文」字組', '版']), ('period followed by bracket cannot hang', ['日本語文。」字組', 4], ['日本語', '文。」字', '組']), ('control layout', ['、け）「文本、語文『こ（字けこ', 5], ['、け）「文', '本、語文', '『こ（字け', 'こ']), ('control layout', ['け（え）けうけ語「組『けーく字え字', 5], ['け（え）け', 'うけ語「組', '『けーく字', 'え字'])], [('regression: small kana strictness', ['日組こ、『っ、ー日ーあ』っ「、き「字っ', 6], ['日組こ、', '『っ、ー日ー', 'あ』っ「、き', '「字っ']), ('regression: small kana strictness', ['えい語く』うっき版うく『）ゃけか', 3], ['えい語', 'く』', 'うっき', '版うく', '『）ゃ', 'けか']), ('regression: small kana strictness', ['（）字「文版い字ー「版ーっ「。』組字組けあか「', 8], ['（）字「文版い', '字ー「版ーっ', '「。』組字組けあ', 'か「']), ('regression: small kana strictness', ['版っ』い「）ー）。）', 3], ['版っ』', 'い', '「', '）', 'ー', '）。）']), ('opening bracket at line end', ['日本語「文字」組版', 4], ['日本語', '「文字」', '組版']), ('closing bracket pushes out', ['日本語文」字組版', 4], ['日本語', '文」字組', '版']), ('control layout', ['っ日本語字こ（く」『、こう文かいえ。。ー', 8], ['っ日本語字こ', '（く」『、こう文', 'かいえ。。ー']), ('control layout', ['語う版っこう『」', 8], ['語う版っこう『」'])], [('regression: small kana strictness', ['）文っ語（く」（。いお、『』ー版版', 7], ['）文っ語（く」', '（。いお、', '『』ー版版']), ('regression: small kana strictness', ['きあ。えーくーゃい', 4], ['きあ。', 'えー', 'くーゃい']), ('regression: small kana strictness', ['いあ『本く）く。ー', 3], ['いあ', '『本', 'く）', 'く。ー']), ('regression: small kana strictness', ['語字、え『えくゃえー』』ーこ組「日『。（', 4], ['語字、え', '『えくゃ', 'え', 'ー』』ー', 'こ組「日', '『。（']), ('period followed by bracket cannot hang', ['日本語文。」字組', 4], ['日本語', '文。」字', '組']), ('opening bracket at line end', ['日本語「文字」組版', 4], ['日本語', '「文字」', '組版']), ('control layout', ['）、えゃ語うかえ「本あこ（字）ーえ字あか版』', 6], ['）、えゃ語う', 'かえ「本あこ', '（字）ーえ字', 'あか版』']), ('control layout', ['あ。」あ文（け版。日）語え』', 6], ['あ。」あ文', '（け版。日）', '語え』'])], [('regression: small kana strictness', ['版ー『版かゃき組本字』', 5], ['版ー『版', 'かゃき組本', '字』']), ('regression: small kana strictness', ['（日おあ」『こか、語。）本文っ、文えあゃ。', 5], ['（日おあ」', '『こか、', '語。）本', '文っ、文え', 'あゃ。']), ('regression: small kana strictness', ['文。いいおっけー本。う「ういおくかえ', 7], ['文。いいおっ', 'けー本。う「う', 'いおくかえ']), ('regression: small kana strictness', ['きっ文こ」あ。けけききき「日ー文ーか、い。', 7], ['きっ文こ」あ。', 'けけききき', '「日ー文ーか、', 'い。']), ('opening bracket at line end', ['日本語「文字」組版', 4], ['日本語', '「文字」', '組版']), ('period hangs past the measure', ['日本語文。字組版', 4], ['日本語文。', '字組版']), ('control layout', ['版っ日けおく、）」版（「', 6], ['版っ日けお', 'く、）」版', '（「']), ('control layout', ['こあく。（く版「うえけ。。。え', 8], ['こあく。（く版', '「うえけ。。。え'])]]
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:
Small kana and long vowel marks begin lines.

Input [text of full-width characters, line length L]. Lines take L characters. If the next character is a hanging comma/period (、。，．) and is not itself followed by a line-start-prohibited character, it hangs on the line (burasage). Otherwise move characters to the next line while the next line would start with a prohibited character (、。，．）」』！？ー and small kana), then while the line would end with an opening bracket; a line keeps at least one character. Return the lines.

split: open-access


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

N = 1
observations = []
def solve(x):
    items, width = x
    lines = []
    start = 0
    n = len(items)
    while start < n:
        while start < n and items[start][0] != 'b':
            start += 1
        if start >= n:
            break
        total = 0
        last = None
        result = None
        i = start
        while i < n:
            it = items[i]
            if it[0] == 'p':
                if it[2] <= -10000:
                    result = (i, total + it[1], 'forced')
                    break
                if it[2] < 10000:
                    last = (i, total + it[1], 'penalty')
            elif it[0] == 'g':
                if items[i - 1][0] != 'g':
                    last = (i, total, 'glue')
                total += it[1]
            else:
                total += it[1]
            if total > width and last is not None:
                result = last
                break
            i += 1
        if result is None:
            lines.append([total, 'end'])
            break
        lines.append([result[1], result[2]])
        start = result[0] + 1
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: glue legality context', [[['b', 7], ['p', 1, 50, True], ['g', 1], ['b', 4], ['p', 1, 50, True], ['g', 1], ['g', 1], ['b', 2], ['p', 1, 50, True], ['g', 1], ['b', 7], ['g', 1], ['b', 1], ['g', 1], ['b', 5], ['p', 1, 50, True], ['g', 1]], 7], [[8, 'penalty'], [5, 'penalty'], [3, 'penalty'], [7, 'glue'], [8, 'penalty']]), ('regression: glue legality context', [[['b', 5], ['g', 1], ['b', 2], ['g', 1], ['b', 6], ['g', 2], ['b', 6], ['g', 1], ['g', 1], ['b', 4], ['p', 0, 10000, False], ['g', 2], ['b', 5], ['g', 1]], 6], [[5, 'glue'], [2, 'glue'], [6, 'glue'], [6, 'glue'], [11, 'glue']]), ('regression: glue legality context', [[['b', 3], ['g', 2], ['b', 2], ['p', 0, -10000, False], ['g', 2], ['b', 6], ['g', 1], ['b', 4], ['p', 0, 10000, False], ['g', 1], ['b', 6], ['p', 1, 50, True], ['g', 1], ['g', 1], ['b', 4], ['g', 2]], 13], [[7, 'forced'], [6, 'glue'], [12, 'penalty'], [6, 'end']]), ('partial-repair probe', [[['b', 7], ['g', 2], ['b', 4], ['g', 1], ['b', 6], ['g', 1], ['b', 1], ['g', 1], ['b', 5], ['g', 2], ['b', 6], ['g', 2], ['b', 6], ['g', 1], ['g', 1], ['b', 6], ['p', 1, 50, True], ['p', 1, 50, True], ['g', 1], ['b', 6], ['g', 1], ['b', 6], ['p', 0, -10000, False], ['g', 2]], 16], [[13, 'glue'], [14, 'glue'], [14, 'glue'], [13, 'glue'], [6, 'forced']]), ('hyphen penalty taken', [[['b', 5], ['p', 1, 50, True], ['b', 4], ['g', 1], ['b', 3]], 7], [[6, 'penalty'], [4, 'glue'], [3, 'end']]), ('forced break', [[['b', 2], ['g', 1], ['b', 2], ['p', 0, -10000, False], ['b', 3]], 20], [[5, 'forced'], [3, 'end']]), ('control layout', [[['b', 6], ['g', 2], ['b', 2], ['g', 2], ['b', 2], ['g', 2], ['b', 3], ['g', 2], ['b', 1], ['p', 0, -10000, False], ['g', 1], ['b', 3], ['p', 1, 50, True], ['g', 2], ['b', 4], ['g', 1], ['b', 1], ['p', 0, -10000, False], ['g', 1], ['b', 1], ['g', 1]], 13], [[10, 'glue'], [10, 'forced'], [11, 'forced'], [2, 'end']]), ('control layout', [[['b', 4], ['p', 0, 10000, False], ['g', 1], ['b', 5], ['g', 1], ['b', 5], ['g', 1], ['g', 1], ['b', 3], ['g', 1], ['b', 6], ['g', 1], ['b', 7], ['g', 2], ['b', 3], ['g', 1], ['b', 7], ['g', 1], ['b', 1], ['p', 0, -10000, False], ['g', 1]], 12], [[10, 'glue'], [10, 'glue'], [6, 'glue'], [12, 'glue'], [9, 'forced']])], [('regression: glue legality context', [[['b', 5], ['p', 1, 50, True], ['g', 1], ['b', 3], ['g', 2], ['b', 4], ['g', 2], ['b', 2], ['g', 2], ['b', 4], ['p', 1, 50, True], ['g', 2], ['b', 6], ['g', 2], ['b', 1], ['g', 1], ['b', 6], ['p', 0, 900, False], ['g', 1], ['b', 6], ['p', 1, 50, True], ['g', 1], ['b', 6], ['p', 0, 900, False], ['g', 1]], 6], [[6, 'penalty'], [3, 'glue'], [4, 'glue'], [2, 'glue'], [5, 'penalty'], [6, 'glue'], [1, 'glue'], [6, 'penalty'], [7, 'penalty'], [6, 'penalty']]), ('regression: glue legality context', [[['b', 7], ['p', 0, -10000, False], ['g', 2], ['b', 7], ['g', 1], ['b', 4], ['p', 0, 9999, False], ['g', 1], ['g', 1], ['b', 6], ['p', 1, 50, True], ['g', 1]], 6], [[7, 'forced'], [7, 'glue'], [4, 'penalty'], [7, 'penalty']]), ('regression: glue legality context', [[['b', 4], ['p', 1, 50, True], ['g', 1], ['g', 1], ['b', 2], ['g', 2], ['b', 7], ['g', 2], ['b', 1], ['g', 1]], 7], [[5, 'penalty'], [2, 'glue'], [7, 'glue'], [2, 'end']]), ('regression: glue legality context', [[['b', 1], ['p', 1, 50, True], ['g', 2], ['b', 4], ['g', 2], ['b', 1], ['p', 0, -5000, False], ['g', 2], ['b', 7], ['p', 0, 10000, False], ['g', 2], ['b', 4], ['p', 1, 50, True], ['g', 1], ['b', 4], ['g', 1], ['g', 1], ['b', 6], ['p', 1, 50, True], ['g', 1], ['b', 6], ['g', 2], ['b', 3], ['p', 0, -10000, False], ['p', 1, 50, True], ['g', 1], ['b', 6], ['p', 0, 900, False], ['p', 1, 50, True], ['g', 1]], 11], [[10, 'penalty'], [14, 'penalty'], [4, 'glue'], [7, 'penalty'], [11, 'forced'], [7, 'end']]), ('forced break', [[['b', 2], ['g', 1], ['b', 2], ['p', 0, -10000, False], ['b', 3]], 20], [[5, 'forced'], [3, 'end']]), ('inhibited penalty', [[['b', 5], ['p', 0, 10000, False], ['b', 4], ['g', 1], ['b', 3]], 7], [[9, 'glue'], [3, 'end']]), ('control layout', [[['b', 7], ['p', 0, -10000, False], ['g', 2], ['b', 2], ['p', 1, 50, True], ['g', 1], ['b', 6], ['p', 0, 10000, False], ['g', 1], ['g', 1], ['b', 1], ['p', 1, 50, True], ['g', 1], ['b', 2], ['g', 2], ['b', 2], ['p', 1, 50, True], ['p', 1, 50, True], ['g', 1], ['b', 5], ['g', 2]], 16], [[7, 'forced'], [15, 'glue'], [10, 'end']]), ('control layout', [[['b', 5], ['g', 1], ['b', 4], ['g', 1], ['b', 4], ['g', 1], ['b', 7], ['g', 2], ['b', 7], ['g', 2], ['b', 1], ['g', 1], ['b', 2], ['g', 1], ['b', 6], ['g', 1], ['g', 1], ['b', 1], ['p', 0, -10000, False], ['g', 1], ['b', 1], ['g', 1]], 16], [[15, 'glue'], [16, 'glue'], [14, 'forced'], [2, 'end']])], [('regression: glue legality context', [[['b', 7], ['p', 1, 50, True], ['g', 1], ['b', 3], ['p', 1, 50, True], ['g', 1], ['b', 7], ['g', 1], ['b', 4], ['p', 0, -5000, False], ['g', 2], ['b', 2], ['g', 1], ['b', 3], ['g', 2], ['b', 2], ['g', 1], ['b', 6], ['g', 1], ['g', 1], ['b', 6], ['p', 1, 50, True], ['g', 1], ['b', 4], ['g', 2]], 17], [[12, 'penalty'], [16, 'glue'], [14, 'glue'], [13, 'end']]), ('regression: glue legality context', [[['b', 6], ['g', 1], ['b', 4], ['g', 1], ['b', 6], ['p', 1, 50, True], ['g', 1], ['b', 4], ['p', 1, 50, True], ['g', 1], ['b', 6], ['g', 1], ['b', 6], ['g', 2], ['b', 5], ['g', 1], ['b', 3], ['g', 1], ['b', 2], ['g', 1]], 10], [[6, 'glue'], [4, 'glue'], [7, 'penalty'], [5, 'penalty'], [6, 'glue'], [6, 'glue'], [9, 'glue'], [3, 'end']]), ('partial-repair probe', [[['b', 5], ['g', 2], ['b', 6], ['p', 1, 50, True], ['g', 1], ['b', 1], ['g', 1], ['b', 6], ['g', 1], ['g', 1], ['b', 1], ['g', 2]], 8], [[5, 'glue'], [8, 'glue'], [6, 'glue'], [3, 'end']]), ('regression: glue legality context', [[['b', 3], ['p', 0, -10000, False], ['g', 2], ['b', 6], ['p', 0, 10000, False], ['g', 1], ['b', 6], ['g', 1], ['b', 1], ['p', 0, 10000, False], ['p', 1, 50, True], ['g', 1], ['b', 3], ['g', 1], ['g', 1], ['b', 4], ['p', 0, -5000, False], ['g', 1], ['g', 1], ['b', 6], ['g', 1], ['b', 3], ['g', 1], ['g', 1], ['b', 3], ['g', 1]], 13], [[3, 'forced'], [13, 'glue'], [11, 'penalty'], [10, 'glue'], [4, 'end']]), ('forced break', [[['b', 2], ['g', 1], ['b', 2], ['p', 0, -10000, False], ['b', 3]], 20], [[5, 'forced'], [3, 'end']]), ('inhibited penalty', [[['b', 5], ['p', 0, 10000, False], ['b', 4], ['g', 1], ['b', 3]], 7], [[9, 'glue'], [3, 'end']]), ('control layout', [[['b', 4], ['p', 0, 9999, False], ['p', 1, 50, True], ['g', 1], ['b', 6], ['g', 2], ['b', 7], ['p', 0, 10000, False], ['g', 1], ['b', 1], ['p', 1, 50, True], ['g', 1], ['b', 1], ['p', 1, 50, True], ['g', 2], ['b', 3], ['g', 2], ['b', 3], ['g', 2], ['b', 4], ['g', 2], ['b', 6], ['g', 1], ['b', 5], ['p', 1, 50, True], ['g', 2]], 16], [[11, 'glue'], [16, 'glue'], [9, 'glue'], [14, 'end']]), ('control layout', [[['b', 3], ['g', 2], ['b', 5], ['g', 2], ['b', 2], ['g', 1], ['b', 7], ['g', 1], ['b', 7], ['g', 2], ['b', 2], ['g', 1], ['g', 1], ['b', 7], ['p', 1, 50, True], ['g', 1]], 16], [[14, 'glue'], [15, 'glue'], [12, 'end']])], [('regression: glue legality context', [[['b', 2], ['p', 1, 50, True], ['g', 1], ['b', 4], ['p', 0, 10000, False], ['g', 2], ['b', 2], ['g', 2], ['b', 4], ['g', 1], ['b', 2], ['p', 1, 50, True], ['g', 1], ['b', 6], ['g', 1]], 7], [[3, 'penalty'], [8, 'glue'], [8, 'penalty'], [7, 'end']]), ('regression: glue legality context', [[['b', 1], ['g', 1], ['g', 1], ['b', 1], ['g', 1], ['b', 5], ['p', 0, 10000, False], ['g', 1], ['b', 2], ['g', 2], ['b', 7], ['p', 1, 50, True], ['g', 1]], 12], [[4, 'glue'], [8, 'glue'], [8, 'end']]), ('regression: glue legality context', [[['b', 1], ['p', 0, 10000, False], ['g', 2], ['b', 6], ['p', 1, 50, True], ['g', 1], ['b', 1], ['g', 1], ['b', 2], ['g', 2], ['b', 6], ['g', 1], ['g', 1], ['b', 7], ['g', 1], ['b', 3], ['p', 0, 10000, False], ['g', 2], ['b', 6], ['g', 1], ['b', 1], ['p', 1, 50, True], ['g', 1], ['b', 2], ['g', 1]], 12], [[11, 'glue'], [10, 'glue'], [7, 'glue'], [11, 'glue'], [5, 'end']]), ('partial-repair probe', [[['b', 7], ['g', 2], ['b', 2], ['g', 1], ['g', 1], ['b', 6], ['g', 1], ['b', 6], ['p', 0, -10000, False], ['g', 2], ['b', 1], ['g', 2]], 15], [[11, 'glue'], [13, 'forced'], [3, 'end']]), ('inhibited penalty', [[['b', 5], ['p', 0, 10000, False], ['b', 4], ['g', 1], ['b', 3]], 7], [[9, 'glue'], [3, 'end']]), ('hyphen penalty taken', [[['b', 5], ['p', 1, 50, True], ['b', 4], ['g', 1], ['b', 3]], 7], [[6, 'penalty'], [4, 'glue'], [3, 'end']]), ('control layout', [[['b', 1], ['p', 0, -10000, False], ['g', 1], ['g', 1], ['b', 7], ['p', 1, 50, True], ['g', 2], ['b', 4], ['g', 2], ['b', 4], ['g', 1], ['b', 7], ['g', 1], ['b', 4], ['p', 1, 50, True], ['g', 2], ['b', 1], ['g', 1], ['g', 1]], 14], [[1, 'forced'], [13, 'glue'], [12, 'glue'], [9, 'end']]), ('control layout', [[['b', 6], ['g', 2], ['b', 4], ['p', 0, -10000, False], ['g', 1], ['b', 5], ['g', 2], ['b', 4], ['g', 1], ['b', 6], ['g', 1], ['b', 3], ['p', 1, 50, True], ['g', 1], ['b', 1], ['p', 0, -10000, False], ['g', 1], ['b', 4], ['p', 0, -10000, False], ['g', 2], ['b', 2], ['g', 2], ['b', 7], ['g', 2]], 13], [[12, 'forced'], [11, 'glue'], [12, 'forced'], [4, 'forced'], [13, 'end']])], [('regression: glue legality context', [[['b', 4], ['p', 1, 50, True], ['g', 1], ['b', 7], ['g', 2], ['b', 3], ['g', 2], ['b', 7], ['p', 0, -5000, False], ['g', 2], ['b', 3], ['p', 0, -10000, False], ['g', 2], ['b', 5], ['p', 1, 50, True], ['g', 1]], 7], [[5, 'penalty'], [7, 'glue'], [3, 'glue'], [7, 'penalty'], [3, 'forced'], [6, 'end']]), ('regression: glue legality context', [[['b', 3], ['g', 1], ['b', 6], ['p', 1, 50, True], ['g', 1], ['b', 4], ['g', 2], ['b', 2], ['g', 1], ['g', 1], ['b', 1], ['g', 2]], 11], [[11, 'penalty'], [11, 'glue']]), ('partial-repair probe', [[['b', 6], ['g', 1], ['b', 6], ['g', 2], ['b', 3], ['p', 0, 10000, False], ['g', 1], ['g', 1], ['b', 1], ['p', 0, 10000, False], ['g', 2], ['b', 4], ['g', 1], ['b', 2], ['g', 2], ['b', 5], ['g', 1], ['b', 2], ['g', 1], ['g', 1]], 13], [[13, 'glue'], [12, 'glue'], [12, 'glue']]), ('regression: glue legality context', [[['b', 6], ['p', 1, 50, True], ['g', 1], ['g', 1], ['b', 6], ['p', 0, 10000, False], ['g', 1], ['b', 2], ['p', 0, -10000, False], ['g', 2], ['b', 1], ['p', 0, 10000, False], ['g', 2], ['b', 7], ['g', 2], ['b', 1], ['p', 0, -10000, False], ['g', 1], ['b', 3], ['g', 2], ['b', 2], ['p', 0, 900, False], ['g', 2], ['b', 1], ['p', 1, 50, True], ['g', 1], ['b', 6], ['g', 2]], 7], [[7, 'penalty'], [9, 'forced'], [10, 'glue'], [1, 'forced'], [7, 'penalty'], [2, 'penalty'], [6, 'glue']]), ('hyphen penalty taken', [[['b', 5], ['p', 1, 50, True], ['b', 4], ['g', 1], ['b', 3]], 7], [[6, 'penalty'], [4, 'glue'], [3, 'end']]), ('forced break', [[['b', 2], ['g', 1], ['b', 2], ['p', 0, -10000, False], ['b', 3]], 20], [[5, 'forced'], [3, 'end']]), ('control layout', [[['b', 4], ['g', 1], ['b', 2], ['g', 1], ['g', 1], ['b', 2], ['g', 1], ['g', 1], ['b', 1], ['p', 1, 50, True], ['g', 1]], 11], [[11, 'glue'], [2, 'end']]), ('control layout', [[['b', 1], ['p', 1, 50, True], ['g', 1], ['b', 3], ['p', 1, 50, True], ['g', 1], ['b', 4], ['g', 2], ['b', 2], ['p', 1, 50, True], ['g', 1]], 15], [[15, 'end']])]]
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):
    items, width = x
    lines = []
    start = 0
    n = len(items)
    while start < n:
        while start < n and items[start][0] != 'b':
            start += 1
        if start >= n:
            break
        total = 0
        last = None
        result = None
        i = start
        while i < n:
            it = items[i]
            if it[0] == 'p':
                if it[2] <= -10000:
                    result = (i, total + it[1], 'forced')
                    break
                if it[2] < 10000:
                    last = (i, total + it[1], 'penalty')
            elif it[0] == 'g':
                if items[i - 1][0] in ('b', 'g'):
                    last = (i, total, 'glue')
                total += it[1]
            else:
                total += it[1]
            if total > width and last is not None:
                result = last
                break
            i += 1
        if result is None:
            lines.append([total, 'end'])
            break
        lines.append([result[1], result[2]])
        start = result[0] + 1
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: glue legality context', [[['b', 7], ['p', 1, 50, True], ['g', 1], ['b', 4], ['p', 1, 50, True], ['g', 1], ['g', 1], ['b', 2], ['p', 1, 50, True], ['g', 1], ['b', 7], ['g', 1], ['b', 1], ['g', 1], ['b', 5], ['p', 1, 50, True], ['g', 1]], 7], [[8, 'penalty'], [5, 'penalty'], [3, 'penalty'], [7, 'glue'], [8, 'penalty']]), ('regression: glue legality context', [[['b', 5], ['g', 1], ['b', 2], ['g', 1], ['b', 6], ['g', 2], ['b', 6], ['g', 1], ['g', 1], ['b', 4], ['p', 0, 10000, False], ['g', 2], ['b', 5], ['g', 1]], 6], [[5, 'glue'], [2, 'glue'], [6, 'glue'], [6, 'glue'], [11, 'glue']]), ('regression: glue legality context', [[['b', 3], ['g', 2], ['b', 2], ['p', 0, -10000, False], ['g', 2], ['b', 6], ['g', 1], ['b', 4], ['p', 0, 10000, False], ['g', 1], ['b', 6], ['p', 1, 50, True], ['g', 1], ['g', 1], ['b', 4], ['g', 2]], 13], [[7, 'forced'], [6, 'glue'], [12, 'penalty'], [6, 'end']]), ('partial-repair probe', [[['b', 7], ['g', 2], ['b', 4], ['g', 1], ['b', 6], ['g', 1], ['b', 1], ['g', 1], ['b', 5], ['g', 2], ['b', 6], ['g', 2], ['b', 6], ['g', 1], ['g', 1], ['b', 6], ['p', 1, 50, True], ['p', 1, 50, True], ['g', 1], ['b', 6], ['g', 1], ['b', 6], ['p', 0, -10000, False], ['g', 2]], 16], [[13, 'glue'], [14, 'glue'], [14, 'glue'], [13, 'glue'], [6, 'forced']]), ('hyphen penalty taken', [[['b', 5], ['p', 1, 50, True], ['b', 4], ['g', 1], ['b', 3]], 7], [[6, 'penalty'], [4, 'glue'], [3, 'end']]), ('forced break', [[['b', 2], ['g', 1], ['b', 2], ['p', 0, -10000, False], ['b', 3]], 20], [[5, 'forced'], [3, 'end']]), ('control layout', [[['b', 6], ['g', 2], ['b', 2], ['g', 2], ['b', 2], ['g', 2], ['b', 3], ['g', 2], ['b', 1], ['p', 0, -10000, False], ['g', 1], ['b', 3], ['p', 1, 50, True], ['g', 2], ['b', 4], ['g', 1], ['b', 1], ['p', 0, -10000, False], ['g', 1], ['b', 1], ['g', 1]], 13], [[10, 'glue'], [10, 'forced'], [11, 'forced'], [2, 'end']]), ('control layout', [[['b', 4], ['p', 0, 10000, False], ['g', 1], ['b', 5], ['g', 1], ['b', 5], ['g', 1], ['g', 1], ['b', 3], ['g', 1], ['b', 6], ['g', 1], ['b', 7], ['g', 2], ['b', 3], ['g', 1], ['b', 7], ['g', 1], ['b', 1], ['p', 0, -10000, False], ['g', 1]], 12], [[10, 'glue'], [10, 'glue'], [6, 'glue'], [12, 'glue'], [9, 'forced']])], [('regression: glue legality context', [[['b', 5], ['p', 1, 50, True], ['g', 1], ['b', 3], ['g', 2], ['b', 4], ['g', 2], ['b', 2], ['g', 2], ['b', 4], ['p', 1, 50, True], ['g', 2], ['b', 6], ['g', 2], ['b', 1], ['g', 1], ['b', 6], ['p', 0, 900, False], ['g', 1], ['b', 6], ['p', 1, 50, True], ['g', 1], ['b', 6], ['p', 0, 900, False], ['g', 1]], 6], [[6, 'penalty'], [3, 'glue'], [4, 'glue'], [2, 'glue'], [5, 'penalty'], [6, 'glue'], [1, 'glue'], [6, 'penalty'], [7, 'penalty'], [6, 'penalty']]), ('regression: glue legality context', [[['b', 7], ['p', 0, -10000, False], ['g', 2], ['b', 7], ['g', 1], ['b', 4], ['p', 0, 9999, False], ['g', 1], ['g', 1], ['b', 6], ['p', 1, 50, True], ['g', 1]], 6], [[7, 'forced'], [7, 'glue'], [4, 'penalty'], [7, 'penalty']]), ('regression: glue legality context', [[['b', 4], ['p', 1, 50, True], ['g', 1], ['g', 1], ['b', 2], ['g', 2], ['b', 7], ['g', 2], ['b', 1], ['g', 1]], 7], [[5, 'penalty'], [2, 'glue'], [7, 'glue'], [2, 'end']]), ('regression: glue legality context', [[['b', 1], ['p', 1, 50, True], ['g', 2], ['b', 4], ['g', 2], ['b', 1], ['p', 0, -5000, False], ['g', 2], ['b', 7], ['p', 0, 10000, False], ['g', 2], ['b', 4], ['p', 1, 50, True], ['g', 1], ['b', 4], ['g', 1], ['g', 1], ['b', 6], ['p', 1, 50, True], ['g', 1], ['b', 6], ['g', 2], ['b', 3], ['p', 0, -10000, False], ['p', 1, 50, True], ['g', 1], ['b', 6], ['p', 0, 900, False], ['p', 1, 50, True], ['g', 1]], 11], [[10, 'penalty'], [14, 'penalty'], [4, 'glue'], [7, 'penalty'], [11, 'forced'], [7, 'end']]), ('forced break', [[['b', 2], ['g', 1], ['b', 2], ['p', 0, -10000, False], ['b', 3]], 20], [[5, 'forced'], [3, 'end']]), ('inhibited penalty', [[['b', 5], ['p', 0, 10000, False], ['b', 4], ['g', 1], ['b', 3]], 7], [[9, 'glue'], [3, 'end']]), ('control layout', [[['b', 7], ['p', 0, -10000, False], ['g', 2], ['b', 2], ['p', 1, 50, True], ['g', 1], ['b', 6], ['p', 0, 10000, False], ['g', 1], ['g', 1], ['b', 1], ['p', 1, 50, True], ['g', 1], ['b', 2], ['g', 2], ['b', 2], ['p', 1, 50, True], ['p', 1, 50, True], ['g', 1], ['b', 5], ['g', 2]], 16], [[7, 'forced'], [15, 'glue'], [10, 'end']]), ('control layout', [[['b', 5], ['g', 1], ['b', 4], ['g', 1], ['b', 4], ['g', 1], ['b', 7], ['g', 2], ['b', 7], ['g', 2], ['b', 1], ['g', 1], ['b', 2], ['g', 1], ['b', 6], ['g', 1], ['g', 1], ['b', 1], ['p', 0, -10000, False], ['g', 1], ['b', 1], ['g', 1]], 16], [[15, 'glue'], [16, 'glue'], [14, 'forced'], [2, 'end']])], [('regression: glue legality context', [[['b', 7], ['p', 1, 50, True], ['g', 1], ['b', 3], ['p', 1, 50, True], ['g', 1], ['b', 7], ['g', 1], ['b', 4], ['p', 0, -5000, False], ['g', 2], ['b', 2], ['g', 1], ['b', 3], ['g', 2], ['b', 2], ['g', 1], ['b', 6], ['g', 1], ['g', 1], ['b', 6], ['p', 1, 50, True], ['g', 1], ['b', 4], ['g', 2]], 17], [[12, 'penalty'], [16, 'glue'], [14, 'glue'], [13, 'end']]), ('regression: glue legality context', [[['b', 6], ['g', 1], ['b', 4], ['g', 1], ['b', 6], ['p', 1, 50, True], ['g', 1], ['b', 4], ['p', 1, 50, True], ['g', 1], ['b', 6], ['g', 1], ['b', 6], ['g', 2], ['b', 5], ['g', 1], ['b', 3], ['g', 1], ['b', 2], ['g', 1]], 10], [[6, 'glue'], [4, 'glue'], [7, 'penalty'], [5, 'penalty'], [6, 'glue'], [6, 'glue'], [9, 'glue'], [3, 'end']]), ('partial-repair probe', [[['b', 5], ['g', 2], ['b', 6], ['p', 1, 50, True], ['g', 1], ['b', 1], ['g', 1], ['b', 6], ['g', 1], ['g', 1], ['b', 1], ['g', 2]], 8], [[5, 'glue'], [8, 'glue'], [6, 'glue'], [3, 'end']]), ('regression: glue legality context', [[['b', 3], ['p', 0, -10000, False], ['g', 2], ['b', 6], ['p', 0, 10000, False], ['g', 1], ['b', 6], ['g', 1], ['b', 1], ['p', 0, 10000, False], ['p', 1, 50, True], ['g', 1], ['b', 3], ['g', 1], ['g', 1], ['b', 4], ['p', 0, -5000, False], ['g', 1], ['g', 1], ['b', 6], ['g', 1], ['b', 3], ['g', 1], ['g', 1], ['b', 3], ['g', 1]], 13], [[3, 'forced'], [13, 'glue'], [11, 'penalty'], [10, 'glue'], [4, 'end']]), ('forced break', [[['b', 2], ['g', 1], ['b', 2], ['p', 0, -10000, False], ['b', 3]], 20], [[5, 'forced'], [3, 'end']]), ('inhibited penalty', [[['b', 5], ['p', 0, 10000, False], ['b', 4], ['g', 1], ['b', 3]], 7], [[9, 'glue'], [3, 'end']]), ('control layout', [[['b', 4], ['p', 0, 9999, False], ['p', 1, 50, True], ['g', 1], ['b', 6], ['g', 2], ['b', 7], ['p', 0, 10000, False], ['g', 1], ['b', 1], ['p', 1, 50, True], ['g', 1], ['b', 1], ['p', 1, 50, True], ['g', 2], ['b', 3], ['g', 2], ['b', 3], ['g', 2], ['b', 4], ['g', 2], ['b', 6], ['g', 1], ['b', 5], ['p', 1, 50, True], ['g', 2]], 16], [[11, 'glue'], [16, 'glue'], [9, 'glue'], [14, 'end']]), ('control layout', [[['b', 3], ['g', 2], ['b', 5], ['g', 2], ['b', 2], ['g', 1], ['b', 7], ['g', 1], ['b', 7], ['g', 2], ['b', 2], ['g', 1], ['g', 1], ['b', 7], ['p', 1, 50, True], ['g', 1]], 16], [[14, 'glue'], [15, 'glue'], [12, 'end']])], [('regression: glue legality context', [[['b', 2], ['p', 1, 50, True], ['g', 1], ['b', 4], ['p', 0, 10000, False], ['g', 2], ['b', 2], ['g', 2], ['b', 4], ['g', 1], ['b', 2], ['p', 1, 50, True], ['g', 1], ['b', 6], ['g', 1]], 7], [[3, 'penalty'], [8, 'glue'], [8, 'penalty'], [7, 'end']]), ('regression: glue legality context', [[['b', 1], ['g', 1], ['g', 1], ['b', 1], ['g', 1], ['b', 5], ['p', 0, 10000, False], ['g', 1], ['b', 2], ['g', 2], ['b', 7], ['p', 1, 50, True], ['g', 1]], 12], [[4, 'glue'], [8, 'glue'], [8, 'end']]), ('regression: glue legality context', [[['b', 1], ['p', 0, 10000, False], ['g', 2], ['b', 6], ['p', 1, 50, True], ['g', 1], ['b', 1], ['g', 1], ['b', 2], ['g', 2], ['b', 6], ['g', 1], ['g', 1], ['b', 7], ['g', 1], ['b', 3], ['p', 0, 10000, False], ['g', 2], ['b', 6], ['g', 1], ['b', 1], ['p', 1, 50, True], ['g', 1], ['b', 2], ['g', 1]], 12], [[11, 'glue'], [10, 'glue'], [7, 'glue'], [11, 'glue'], [5, 'end']]), ('partial-repair probe', [[['b', 7], ['g', 2], ['b', 2], ['g', 1], ['g', 1], ['b', 6], ['g', 1], ['b', 6], ['p', 0, -10000, False], ['g', 2], ['b', 1], ['g', 2]], 15], [[11, 'glue'], [13, 'forced'], [3, 'end']]), ('inhibited penalty', [[['b', 5], ['p', 0, 10000, False], ['b', 4], ['g', 1], ['b', 3]], 7], [[9, 'glue'], [3, 'end']]), ('hyphen penalty taken', [[['b', 5], ['p', 1, 50, True], ['b', 4], ['g', 1], ['b', 3]], 7], [[6, 'penalty'], [4, 'glue'], [3, 'end']]), ('control layout', [[['b', 1], ['p', 0, -10000, False], ['g', 1], ['g', 1], ['b', 7], ['p', 1, 50, True], ['g', 2], ['b', 4], ['g', 2], ['b', 4], ['g', 1], ['b', 7], ['g', 1], ['b', 4], ['p', 1, 50, True], ['g', 2], ['b', 1], ['g', 1], ['g', 1]], 14], [[1, 'forced'], [13, 'glue'], [12, 'glue'], [9, 'end']]), ('control layout', [[['b', 6], ['g', 2], ['b', 4], ['p', 0, -10000, False], ['g', 1], ['b', 5], ['g', 2], ['b', 4], ['g', 1], ['b', 6], ['g', 1], ['b', 3], ['p', 1, 50, True], ['g', 1], ['b', 1], ['p', 0, -10000, False], ['g', 1], ['b', 4], ['p', 0, -10000, False], ['g', 2], ['b', 2], ['g', 2], ['b', 7], ['g', 2]], 13], [[12, 'forced'], [11, 'glue'], [12, 'forced'], [4, 'forced'], [13, 'end']])], [('regression: glue legality context', [[['b', 4], ['p', 1, 50, True], ['g', 1], ['b', 7], ['g', 2], ['b', 3], ['g', 2], ['b', 7], ['p', 0, -5000, False], ['g', 2], ['b', 3], ['p', 0, -10000, False], ['g', 2], ['b', 5], ['p', 1, 50, True], ['g', 1]], 7], [[5, 'penalty'], [7, 'glue'], [3, 'glue'], [7, 'penalty'], [3, 'forced'], [6, 'end']]), ('regression: glue legality context', [[['b', 3], ['g', 1], ['b', 6], ['p', 1, 50, True], ['g', 1], ['b', 4], ['g', 2], ['b', 2], ['g', 1], ['g', 1], ['b', 1], ['g', 2]], 11], [[11, 'penalty'], [11, 'glue']]), ('partial-repair probe', [[['b', 6], ['g', 1], ['b', 6], ['g', 2], ['b', 3], ['p', 0, 10000, False], ['g', 1], ['g', 1], ['b', 1], ['p', 0, 10000, False], ['g', 2], ['b', 4], ['g', 1], ['b', 2], ['g', 2], ['b', 5], ['g', 1], ['b', 2], ['g', 1], ['g', 1]], 13], [[13, 'glue'], [12, 'glue'], [12, 'glue']]), ('regression: glue legality context', [[['b', 6], ['p', 1, 50, True], ['g', 1], ['g', 1], ['b', 6], ['p', 0, 10000, False], ['g', 1], ['b', 2], ['p', 0, -10000, False], ['g', 2], ['b', 1], ['p', 0, 10000, False], ['g', 2], ['b', 7], ['g', 2], ['b', 1], ['p', 0, -10000, False], ['g', 1], ['b', 3], ['g', 2], ['b', 2], ['p', 0, 900, False], ['g', 2], ['b', 1], ['p', 1, 50, True], ['g', 1], ['b', 6], ['g', 2]], 7], [[7, 'penalty'], [9, 'forced'], [10, 'glue'], [1, 'forced'], [7, 'penalty'], [2, 'penalty'], [6, 'glue']]), ('hyphen penalty taken', [[['b', 5], ['p', 1, 50, True], ['b', 4], ['g', 1], ['b', 3]], 7], [[6, 'penalty'], [4, 'glue'], [3, 'end']]), ('forced break', [[['b', 2], ['g', 1], ['b', 2], ['p', 0, -10000, False], ['b', 3]], 20], [[5, 'forced'], [3, 'end']]), ('control layout', [[['b', 4], ['g', 1], ['b', 2], ['g', 1], ['g', 1], ['b', 2], ['g', 1], ['g', 1], ['b', 1], ['p', 1, 50, True], ['g', 1]], 11], [[11, 'glue'], [2, 'end']]), ('control layout', [[['b', 1], ['p', 1, 50, True], ['g', 1], ['b', 3], ['p', 1, 50, True], ['g', 1], ['b', 4], ['g', 2], ['b', 2], ['p', 1, 50, True], ['g', 1]], 15], [[15, 'end']])]]
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:
Breaks are taken at glue that follows a penalty.

Input [items, width]; items are ["b",w], ["g",w] or ["p",w,cost,flag]. Legal breaks: glue immediately after a box; penalty with cost < 10000 (width counted only if broken there); cost <= -10000 forces a break. Discardable glue/penalties at a line start are dropped. First-fit: when the running width exceeds the measure, break at the last legal breakpoint. Return [[line width, break kind]] with kinds glue/penalty/forced/end.

split: open-access