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

N = 1
observations = []
def solve(games, best_of):
    sets = []
    a = b = 0
    won = {'A': 0, 'B': 0}
    need = best_of // 2
    for g in games:
        if g == 'A':
            a += 1
        else:
            b += 1
        if (max(a, b) >= 6 and abs(a - b) >= 2) or max(a, b) == 7:
            w = 'A' if a > b else 'B'
            won[w] += 1
            sets.append('%d-%d' % (a, b))
            a = b = 0
            if won[w] == need:
                return [sets, w]
    if a or b:
        sets.append('%d-%d' % (a, b))
    return [sets, None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control bagel set', ('AAAAAA', 3), [['6-0'], None]),
  ('boundary seven-five', ('AAAAABBBBBAA', 3), [['7-5'], None]),
  ('boundary tiebreak set', ('AAAAABBBBBABB', 3), [['6-7'], None]),
  ('control straight sets', ('AAAAAAAAAAAA', 3), [['6-0', '6-0'], 'A']),
  ('control in-progress set', ('AAAAAAB', 3), [['6-0', '0-1'], None]),
  ('control empty', ('', 5), [[], None]),
  ('regression: sets needed', ('BAAABBAAABBA', 3), [['6-3', '1-2'], None]),
  ('regression: sets needed', ('AAAAAABBBABAAAAABAABBAAAABBB', 5), [['6-0', '6-4', '6-3'], 'A']),
  ('variant scenario 1', ('AABBBABBA', 3), [['4-5'], None]),
  ('variant scenario 2', ('AAABAAAABBBABBB', 5), [['6-1', '2-6'], None])],
 [('control bagel set', ('AAAAAA', 3), [['6-0'], None]),
  ('boundary seven-five', ('AAAAABBBBBAA', 3), [['7-5'], None]),
  ('boundary tiebreak set', ('AAAAABBBBBABB', 3), [['6-7'], None]),
  ('control straight sets', ('AAAAAAAAAAAA', 3), [['6-0', '6-0'], 'A']),
  ('control in-progress set', ('AAAAAAB', 3), [['6-0', '0-1'], None]),
  ('control empty', ('', 5), [[], None]),
  ('regression: sets needed', ('AAAAABAABBBAAAAAAABBBAAABBBAA', 3), [['6-1', '6-3'], 'A']),
  ('regression: sets needed', ('BBAABAAAAABBAAABBAAAAAAAA', 5), [['6-3', '6-4', '6-0'], 'A']),
  ('variant scenario 1', ('ABBAABAABBAABABB', 3), [['7-5', '1-3'], None]),
  ('variant scenario 2', ('AABAAAAABAABBABAABABBAAAABA', 3), [['6-1', '6-4'], 'A'])],
 [('control bagel set', ('AAAAAA', 3), [['6-0'], None]),
  ('boundary seven-five', ('AAAAABBBBBAA', 3), [['7-5'], None]),
  ('boundary tiebreak set', ('AAAAABBBBBABB', 3), [['6-7'], None]),
  ('control straight sets', ('AAAAAAAAAAAA', 3), [['6-0', '6-0'], 'A']),
  ('control in-progress set', ('AAAAAAB', 3), [['6-0', '0-1'], None]),
  ('control empty', ('', 5), [[], None]),
  ('regression: sets needed', ('BBABBBBBBABAABBBBAAABBBABBABBAB', 5), [['1-6', '3-6', '4-6'], 'B']),
  ('variant scenario 1', ('AAABAA', 5), [['5-1'], None]),
  ('variant scenario 2', ('AABAABBBAABAAAABBAAABAAB', 5), [['6-4', '6-3', '3-2'], None])],
 [('control bagel set', ('AAAAAA', 3), [['6-0'], None]),
  ('boundary seven-five', ('AAAAABBBBBAA', 3), [['7-5'], None]),
  ('boundary tiebreak set', ('AAAAABBBBBABB', 3), [['6-7'], None]),
  ('control straight sets', ('AAAAAAAAAAAA', 3), [['6-0', '6-0'], 'A']),
  ('control in-progress set', ('AAAAAAB', 3), [['6-0', '0-1'], None]),
  ('control empty', ('', 5), [[], None]),
  ('regression: sets needed', ('ABBABBAABBABABA', 3), [['4-6', '3-2'], None]),
  ('regression: sets needed',
   ('AAAAAAAAABABBBAAABAABAAABABAAAABABBB', 5),
   [['6-0', '6-4', '6-2'], 'A']),
  ('variant scenario 1', ('BABAA', 3), [['3-2'], None]),
  ('variant scenario 2',
   ('BAABABBBAAAAABBBAABBABBABAAABBAAAABBBABAABAABABBA', 3),
   [['7-5', '4-6', '6-4'], 'A'])],
 [('control bagel set', ('AAAAAA', 3), [['6-0'], None]),
  ('boundary seven-five', ('AAAAABBBBBAA', 3), [['7-5'], None]),
  ('boundary tiebreak set', ('AAAAABBBBBABB', 3), [['6-7'], None]),
  ('control straight sets', ('AAAAAAAAAAAA', 3), [['6-0', '6-0'], 'A']),
  ('control in-progress set', ('AAAAAAB', 3), [['6-0', '0-1'], None]),
  ('control empty', ('', 5), [[], None]),
  ('regression: sets needed', ('BABAAABBAAAABAAABAABBABBBBAAA', 3), [['6-4', '6-2'], 'A']),
  ('regression: sets needed',
   ('AAAAAAAABAAAAAAABAAAABAABBAAAAAABAABBAAABA', 5),
   [['6-0', '6-1', '6-1'], 'A']),
  ('variant scenario 1',
   ('BBBABBBAAABAAAAAAAAABABAAABAAAAAABABA', 3),
   [['1-6', '6-1', '6-0'], 'A']),
  ('variant scenario 2', ('BBAAAAAABABBABBABAAAAAAAAABAABBA', 3), [['6-2', '3-6', '6-0'], 'A'])]]
for label, args, expected in cases[N - 1]:
    check(label, run(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(games, best_of):
    sets = []
    a = b = 0
    won = {'A': 0, 'B': 0}
    need = best_of - 1
    for g in games:
        if g == 'A':
            a += 1
        else:
            b += 1
        if (max(a, b) >= 6 and abs(a - b) >= 2) or max(a, b) == 7:
            w = 'A' if a > b else 'B'
            won[w] += 1
            sets.append('%d-%d' % (a, b))
            a = b = 0
            if won[w] == need:
                return [sets, w]
    if a or b:
        sets.append('%d-%d' % (a, b))
    return [sets, None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control bagel set', ('AAAAAA', 3), [['6-0'], None]),
  ('boundary seven-five', ('AAAAABBBBBAA', 3), [['7-5'], None]),
  ('boundary tiebreak set', ('AAAAABBBBBABB', 3), [['6-7'], None]),
  ('control straight sets', ('AAAAAAAAAAAA', 3), [['6-0', '6-0'], 'A']),
  ('control in-progress set', ('AAAAAAB', 3), [['6-0', '0-1'], None]),
  ('control empty', ('', 5), [[], None]),
  ('regression: sets needed', ('BAAABBAAABBA', 3), [['6-3', '1-2'], None]),
  ('regression: sets needed', ('AAAAAABBBABAAAAABAABBAAAABBB', 5), [['6-0', '6-4', '6-3'], 'A']),
  ('variant scenario 1', ('AABBBABBA', 3), [['4-5'], None]),
  ('variant scenario 2', ('AAABAAAABBBABBB', 5), [['6-1', '2-6'], None])],
 [('control bagel set', ('AAAAAA', 3), [['6-0'], None]),
  ('boundary seven-five', ('AAAAABBBBBAA', 3), [['7-5'], None]),
  ('boundary tiebreak set', ('AAAAABBBBBABB', 3), [['6-7'], None]),
  ('control straight sets', ('AAAAAAAAAAAA', 3), [['6-0', '6-0'], 'A']),
  ('control in-progress set', ('AAAAAAB', 3), [['6-0', '0-1'], None]),
  ('control empty', ('', 5), [[], None]),
  ('regression: sets needed', ('AAAAABAABBBAAAAAAABBBAAABBBAA', 3), [['6-1', '6-3'], 'A']),
  ('regression: sets needed', ('BBAABAAAAABBAAABBAAAAAAAA', 5), [['6-3', '6-4', '6-0'], 'A']),
  ('variant scenario 1', ('ABBAABAABBAABABB', 3), [['7-5', '1-3'], None]),
  ('variant scenario 2', ('AABAAAAABAABBABAABABBAAAABA', 3), [['6-1', '6-4'], 'A'])],
 [('control bagel set', ('AAAAAA', 3), [['6-0'], None]),
  ('boundary seven-five', ('AAAAABBBBBAA', 3), [['7-5'], None]),
  ('boundary tiebreak set', ('AAAAABBBBBABB', 3), [['6-7'], None]),
  ('control straight sets', ('AAAAAAAAAAAA', 3), [['6-0', '6-0'], 'A']),
  ('control in-progress set', ('AAAAAAB', 3), [['6-0', '0-1'], None]),
  ('control empty', ('', 5), [[], None]),
  ('regression: sets needed', ('BBABBBBBBABAABBBBAAABBBABBABBAB', 5), [['1-6', '3-6', '4-6'], 'B']),
  ('variant scenario 1', ('AAABAA', 5), [['5-1'], None]),
  ('variant scenario 2', ('AABAABBBAABAAAABBAAABAAB', 5), [['6-4', '6-3', '3-2'], None])],
 [('control bagel set', ('AAAAAA', 3), [['6-0'], None]),
  ('boundary seven-five', ('AAAAABBBBBAA', 3), [['7-5'], None]),
  ('boundary tiebreak set', ('AAAAABBBBBABB', 3), [['6-7'], None]),
  ('control straight sets', ('AAAAAAAAAAAA', 3), [['6-0', '6-0'], 'A']),
  ('control in-progress set', ('AAAAAAB', 3), [['6-0', '0-1'], None]),
  ('control empty', ('', 5), [[], None]),
  ('regression: sets needed', ('ABBABBAABBABABA', 3), [['4-6', '3-2'], None]),
  ('regression: sets needed',
   ('AAAAAAAAABABBBAAABAABAAABABAAAABABBB', 5),
   [['6-0', '6-4', '6-2'], 'A']),
  ('variant scenario 1', ('BABAA', 3), [['3-2'], None]),
  ('variant scenario 2',
   ('BAABABBBAAAAABBBAABBABBABAAABBAAAABBBABAABAABABBA', 3),
   [['7-5', '4-6', '6-4'], 'A'])],
 [('control bagel set', ('AAAAAA', 3), [['6-0'], None]),
  ('boundary seven-five', ('AAAAABBBBBAA', 3), [['7-5'], None]),
  ('boundary tiebreak set', ('AAAAABBBBBABB', 3), [['6-7'], None]),
  ('control straight sets', ('AAAAAAAAAAAA', 3), [['6-0', '6-0'], 'A']),
  ('control in-progress set', ('AAAAAAB', 3), [['6-0', '0-1'], None]),
  ('control empty', ('', 5), [[], None]),
  ('regression: sets needed', ('BABAAABBAAAABAAABAABBABBBBAAA', 3), [['6-4', '6-2'], 'A']),
  ('regression: sets needed',
   ('AAAAAAAABAAAAAAABAAAABAABBAAAAAABAABBAAABA', 5),
   [['6-0', '6-1', '6-1'], 'A']),
  ('variant scenario 1',
   ('BBBABBBAAABAAAAAAAAABABAAABAAAAAABABA', 3),
   [['1-6', '6-1', '6-0'], 'A']),
  ('variant scenario 2', ('BBAAAAAABABBABBABAAAAAAAAABAABBA', 3), [['6-2', '3-6', '6-0'], 'A'])]]
for label, args, expected in cases[N - 1]:
    check(label, run(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 best-of-five match is declared over while a player has only two sets.

games is a string of game winners (A/B); best_of is 3 or 5. A set is won by the first player to 6 games with a lead of two, or at 7 games (7-5, or 7-6 after the tiebreak game played at 6-6). The match ends when a player has won best_of // 2 + 1 sets; later games are ignored. Return [set scores as "a-b" strings in A-B order, match winner or None]; an unfinished set with at least one game is appended as its current score.

split: open-access


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

N = 1
observations = []
def solve(games, best_of):
    sets = []
    a = b = 0
    won = {'A': 0, 'B': 0}
    need = best_of // 2 + 1
    for g in games:
        if g == 'A':
            a += 1
        else:
            b += 1
        if (max(a, b) >= 6 and abs(a - b) >= 2) or max(a, b) == 7:
            w = 'A' if a > b else 'B'
            won[w] += 1
            sets.append('%d-%d' % (a, b))
            a = b = 0
            if won[w] == need:
                return [sets, w]
    if False:
        sets.append('%d-%d' % (a, b))
    return [sets, None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control bagel set', ('AAAAAA', 3), [['6-0'], None]),
  ('boundary seven-five', ('AAAAABBBBBAA', 3), [['7-5'], None]),
  ('boundary tiebreak set', ('AAAAABBBBBABB', 3), [['6-7'], None]),
  ('control straight sets', ('AAAAAAAAAAAA', 3), [['6-0', '6-0'], 'A']),
  ('control in-progress set', ('AAAAAAB', 3), [['6-0', '0-1'], None]),
  ('control empty', ('', 5), [[], None]),
  ('regression: in progress set report', ('BAAAABAAAAAAAABA', 5), [['6-2', '6-0', '1-1'], None]),
  ('regression: in progress set report',
   ('ABAAAAABBBABABAABBBAAAAAA', 5),
   [['6-1', '4-6', '6-2'], None]),
  ('variant scenario 1', ('BBBAAABABAAAABBAAAAAABB', 5), [['7-5', '6-2', '1-2'], None]),
  ('variant scenario 2', ('ABBAABBAAABABAABAAA', 3), [['6-4', '6-3'], 'A'])],
 [('control bagel set', ('AAAAAA', 3), [['6-0'], None]),
  ('boundary seven-five', ('AAAAABBBBBAA', 3), [['7-5'], None]),
  ('boundary tiebreak set', ('AAAAABBBBBABB', 3), [['6-7'], None]),
  ('control straight sets', ('AAAAAAAAAAAA', 3), [['6-0', '6-0'], 'A']),
  ('control in-progress set', ('AAAAAAB', 3), [['6-0', '0-1'], None]),
  ('control empty', ('', 5), [[], None]),
  ('regression: in progress set report',
   ('AABBBABABABABAABBBBAAAABBABB', 3),
   [['6-7', '6-4', '1-4'], None]),
  ('regression: in progress set report', ('AAAAAA', 5), [['6-0'], None]),
  ('variant scenario 1', ('ABAAAABAABAAABBBAAAABAAA', 3), [['6-2', '6-4'], 'A']),
  ('variant scenario 2', ('AAAAB', 3), [['4-1'], None])],
 [('control bagel set', ('AAAAAA', 3), [['6-0'], None]),
  ('boundary seven-five', ('AAAAABBBBBAA', 3), [['7-5'], None]),
  ('boundary tiebreak set', ('AAAAABBBBBABB', 3), [['6-7'], None]),
  ('control straight sets', ('AAAAAAAAAAAA', 3), [['6-0', '6-0'], 'A']),
  ('control in-progress set', ('AAAAAAB', 3), [['6-0', '0-1'], None]),
  ('control empty', ('', 5), [[], None]),
  ('regression: in progress set report',
   ('BBBBBABBBBABBABBBBAAAABABBAABBAABAABABAAABBA', 5),
   [['1-6', '2-6', '7-6', '7-5', '2-2'], None]),
  ('regression: in progress set report', ('AABBABBAAAAAAABBBBBABAB', 3), [['6-4', '6-7'], None]),
  ('variant scenario 1', ('ABABBBBABAAABBBAABAAAABBAABAAAABBA', 3), [['3-6', '6-4', '6-3'], 'A']),
  ('variant scenario 2', ('ABBBAAABBABABABBAABAABAAAAAABBBB', 3), [['6-7', '6-4', '5-4'], None])],
 [('control bagel set', ('AAAAAA', 3), [['6-0'], None]),
  ('boundary seven-five', ('AAAAABBBBBAA', 3), [['7-5'], None]),
  ('boundary tiebreak set', ('AAAAABBBBBABB', 3), [['6-7'], None]),
  ('control straight sets', ('AAAAAAAAAAAA', 3), [['6-0', '6-0'], 'A']),
  ('control in-progress set', ('AAAAAAB', 3), [['6-0', '0-1'], None]),
  ('control empty', ('', 5), [[], None]),
  ('regression: in progress set report', ('ABABBAAABAABBABABABB', 3), [['6-4', '4-6'], None]),
  ('regression: in progress set report',
   ('BBAAABABAAABAABBAABBBBABABA', 3),
   [['6-4', '5-7', '3-2'], None]),
  ('variant scenario 1',
   ('AABABBABBBBAAAAABABBAAAAABAABABAAABAAABAABABBBBAA', 5),
   [['4-6', '6-2', '6-3', '6-3'], 'A']),
  ('variant scenario 2',
   ('ABAABBBBBAAABAABBAABBABABBAAAAABBABAAABBAAA', 5),
   [['3-6', '6-3', '7-5', '7-5'], 'A'])],
 [('control bagel set', ('AAAAAA', 3), [['6-0'], None]),
  ('boundary seven-five', ('AAAAABBBBBAA', 3), [['7-5'], None]),
  ('boundary tiebreak set', ('AAAAABBBBBABB', 3), [['6-7'], None]),
  ('control straight sets', ('AAAAAAAAAAAA', 3), [['6-0', '6-0'], 'A']),
  ('control in-progress set', ('AAAAAAB', 3), [['6-0', '0-1'], None]),
  ('control empty', ('', 5), [[], None]),
  ('regression: in progress set report', ('BAAAAAAABAABAABAB', 5), [['6-1', '6-3', '0-1'], None]),
  ('regression: in progress set report', ('BBAAABBBAAABA', 5), [['7-6'], None]),
  ('variant scenario 1',
   ('BBBBABAAAAABBAABBAAABAABABBAABAABABAABABBBBBAABABABBBBAABBB', 5),
   [['6-7', '6-3', '6-4', '4-6', '4-6'], 'B']),
  ('variant scenario 2', ('ABBBB', 3), [['1-4'], None])]]
for label, args, expected in cases[N - 1]:
    check(label, run(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(games, best_of):
    sets = []
    a = b = 0
    won = {'A': 0, 'B': 0}
    need = best_of // 2 + 1
    for g in games:
        if g == 'A':
            a += 1
        else:
            b += 1
        if (max(a, b) >= 6 and abs(a - b) >= 2) or max(a, b) == 7:
            w = 'A' if a > b else 'B'
            won[w] += 1
            sets.append('%d-%d' % (a, b))
            a = b = 0
            if won[w] == need:
                return [sets, w]
    if True:
        sets.append('%d-%d' % (a, b))
    return [sets, None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control bagel set', ('AAAAAA', 3), [['6-0'], None]),
  ('boundary seven-five', ('AAAAABBBBBAA', 3), [['7-5'], None]),
  ('boundary tiebreak set', ('AAAAABBBBBABB', 3), [['6-7'], None]),
  ('control straight sets', ('AAAAAAAAAAAA', 3), [['6-0', '6-0'], 'A']),
  ('control in-progress set', ('AAAAAAB', 3), [['6-0', '0-1'], None]),
  ('control empty', ('', 5), [[], None]),
  ('regression: in progress set report', ('BAAAABAAAAAAAABA', 5), [['6-2', '6-0', '1-1'], None]),
  ('regression: in progress set report',
   ('ABAAAAABBBABABAABBBAAAAAA', 5),
   [['6-1', '4-6', '6-2'], None]),
  ('variant scenario 1', ('BBBAAABABAAAABBAAAAAABB', 5), [['7-5', '6-2', '1-2'], None]),
  ('variant scenario 2', ('ABBAABBAAABABAABAAA', 3), [['6-4', '6-3'], 'A'])],
 [('control bagel set', ('AAAAAA', 3), [['6-0'], None]),
  ('boundary seven-five', ('AAAAABBBBBAA', 3), [['7-5'], None]),
  ('boundary tiebreak set', ('AAAAABBBBBABB', 3), [['6-7'], None]),
  ('control straight sets', ('AAAAAAAAAAAA', 3), [['6-0', '6-0'], 'A']),
  ('control in-progress set', ('AAAAAAB', 3), [['6-0', '0-1'], None]),
  ('control empty', ('', 5), [[], None]),
  ('regression: in progress set report',
   ('AABBBABABABABAABBBBAAAABBABB', 3),
   [['6-7', '6-4', '1-4'], None]),
  ('regression: in progress set report', ('AAAAAA', 5), [['6-0'], None]),
  ('variant scenario 1', ('ABAAAABAABAAABBBAAAABAAA', 3), [['6-2', '6-4'], 'A']),
  ('variant scenario 2', ('AAAAB', 3), [['4-1'], None])],
 [('control bagel set', ('AAAAAA', 3), [['6-0'], None]),
  ('boundary seven-five', ('AAAAABBBBBAA', 3), [['7-5'], None]),
  ('boundary tiebreak set', ('AAAAABBBBBABB', 3), [['6-7'], None]),
  ('control straight sets', ('AAAAAAAAAAAA', 3), [['6-0', '6-0'], 'A']),
  ('control in-progress set', ('AAAAAAB', 3), [['6-0', '0-1'], None]),
  ('control empty', ('', 5), [[], None]),
  ('regression: in progress set report',
   ('BBBBBABBBBABBABBBBAAAABABBAABBAABAABABAAABBA', 5),
   [['1-6', '2-6', '7-6', '7-5', '2-2'], None]),
  ('regression: in progress set report', ('AABBABBAAAAAAABBBBBABAB', 3), [['6-4', '6-7'], None]),
  ('variant scenario 1', ('ABABBBBABAAABBBAABAAAABBAABAAAABBA', 3), [['3-6', '6-4', '6-3'], 'A']),
  ('variant scenario 2', ('ABBBAAABBABABABBAABAABAAAAAABBBB', 3), [['6-7', '6-4', '5-4'], None])],
 [('control bagel set', ('AAAAAA', 3), [['6-0'], None]),
  ('boundary seven-five', ('AAAAABBBBBAA', 3), [['7-5'], None]),
  ('boundary tiebreak set', ('AAAAABBBBBABB', 3), [['6-7'], None]),
  ('control straight sets', ('AAAAAAAAAAAA', 3), [['6-0', '6-0'], 'A']),
  ('control in-progress set', ('AAAAAAB', 3), [['6-0', '0-1'], None]),
  ('control empty', ('', 5), [[], None]),
  ('regression: in progress set report', ('ABABBAAABAABBABABABB', 3), [['6-4', '4-6'], None]),
  ('regression: in progress set report',
   ('BBAAABABAAABAABBAABBBBABABA', 3),
   [['6-4', '5-7', '3-2'], None]),
  ('variant scenario 1',
   ('AABABBABBBBAAAAABABBAAAAABAABABAAABAAABAABABBBBAA', 5),
   [['4-6', '6-2', '6-3', '6-3'], 'A']),
  ('variant scenario 2',
   ('ABAABBBBBAAABAABBAABBABABBAAAAABBABAAABBAAA', 5),
   [['3-6', '6-3', '7-5', '7-5'], 'A'])],
 [('control bagel set', ('AAAAAA', 3), [['6-0'], None]),
  ('boundary seven-five', ('AAAAABBBBBAA', 3), [['7-5'], None]),
  ('boundary tiebreak set', ('AAAAABBBBBABB', 3), [['6-7'], None]),
  ('control straight sets', ('AAAAAAAAAAAA', 3), [['6-0', '6-0'], 'A']),
  ('control in-progress set', ('AAAAAAB', 3), [['6-0', '0-1'], None]),
  ('control empty', ('', 5), [[], None]),
  ('regression: in progress set report', ('BAAAAAAABAABAABAB', 5), [['6-1', '6-3', '0-1'], None]),
  ('regression: in progress set report', ('BBAAABBBAAABA', 5), [['7-6'], None]),
  ('variant scenario 1',
   ('BBBBABAAAAABBAABBAAABAABABBAABAABABAABABBBBBAABABABBBBAABBB', 5),
   [['6-7', '6-3', '6-4', '4-6', '4-6'], 'B']),
  ('variant scenario 2', ('ABBBB', 3), [['1-4'], None])]]
for label, args, expected in cases[N - 1]:
    check(label, run(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:
An in-progress set is missing from the scoreboard, or a phantom "0-0" set appears after a set ends.

games is a string of game winners (A/B); best_of is 3 or 5. A set is won by the first player to 6 games with a lead of two, or at 7 games (7-5, or 7-6 after the tiebreak game played at 6-6). The match ends when a player has won best_of // 2 + 1 sets; later games are ignored. Return [set scores as "a-b" strings in A-B order, match winner or None]; an unfinished set with at least one game is appended as its current score.

split: open-access


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

N = 1
observations = []
def solve(games, best_of):
    sets = []
    a = b = 0
    won = {'A': 0, 'B': 0}
    need = best_of // 2 + 1
    for g in games:
        if g == 'A':
            a += 1
        else:
            b += 1
        if (max(a, b) >= 6) or max(a, b) == 7:
            w = 'A' if a > b else 'B'
            won[w] += 1
            sets.append('%d-%d' % (a, b))
            a = b = 0
            if won[w] == need:
                return [sets, w]
    if a or b:
        sets.append('%d-%d' % (a, b))
    return [sets, None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control bagel set', ('AAAAAA', 3), [['6-0'], None]),
  ('boundary seven-five', ('AAAAABBBBBAA', 3), [['7-5'], None]),
  ('boundary tiebreak set', ('AAAAABBBBBABB', 3), [['6-7'], None]),
  ('control straight sets', ('AAAAAAAAAAAA', 3), [['6-0', '6-0'], 'A']),
  ('control in-progress set', ('AAAAAAB', 3), [['6-0', '0-1'], None]),
  ('control empty', ('', 5), [[], None]),
  ('regression: six game lead', ('BBAABAABABAABBBBBAAAAB', 3), [['7-5', '4-6'], None]),
  ('regression: six game lead', ('BABBBBBABAABBBBAAAAABBA', 3), [['1-6', '7-5', '2-2'], None]),
  ('variant scenario 1', ('AAABBAAAAAABB', 5), [['6-2', '3-2'], None]),
  ('variant scenario 2', ('BAAAAABAABBBBAAAABABAABAABA', 3), [['6-2', '7-6'], 'A'])],
 [('control bagel set', ('AAAAAA', 3), [['6-0'], None]),
  ('boundary seven-five', ('AAAAABBBBBAA', 3), [['7-5'], None]),
  ('boundary tiebreak set', ('AAAAABBBBBABB', 3), [['6-7'], None]),
  ('control straight sets', ('AAAAAAAAAAAA', 3), [['6-0', '6-0'], 'A']),
  ('control in-progress set', ('AAAAAAB', 3), [['6-0', '0-1'], None]),
  ('control empty', ('', 5), [[], None]),
  ('regression: six game lead', ('AAAABAAABBBBAAABBAABBAABA', 5), [['6-1', '4-6', '5-3'], None]),
  ('regression: six game lead', ('BAAAABBBABBAAAAA', 3), [['7-6', '3-0'], None]),
  ('variant scenario 1', ('BAAAA', 3), [['4-1'], None]),
  ('variant scenario 2',
   ('BAAAABABABABAABBBABABAAAAAAAAAA', 5),
   [['6-3', '4-6', '6-1', '5-0'], None])],
 [('control bagel set', ('AAAAAA', 3), [['6-0'], None]),
  ('boundary seven-five', ('AAAAABBBBBAA', 3), [['7-5'], None]),
  ('boundary tiebreak set', ('AAAAABBBBBABB', 3), [['6-7'], None]),
  ('control straight sets', ('AAAAAAAAAAAA', 3), [['6-0', '6-0'], 'A']),
  ('control in-progress set', ('AAAAAAB', 3), [['6-0', '0-1'], None]),
  ('control empty', ('', 5), [[], None]),
  ('regression: six game lead', ('BBBBBBBBBABAABABBBBBAAAAA', 3), [['0-6', '4-6'], 'B']),
  ('regression: six game lead',
   ('BBABAAAABBAAABBABAABABBAAABBBABBAAABAA', 3),
   [['7-5', '7-6'], 'A']),
  ('variant scenario 1', ('ABAABABBBABBBAABBBAAAAA', 5), [['5-7', '6-4', '1-0'], None]),
  ('variant scenario 2', ('BAAABBAABABB', 3), [['6-4', '0-2'], None])],
 [('control bagel set', ('AAAAAA', 3), [['6-0'], None]),
  ('boundary seven-five', ('AAAAABBBBBAA', 3), [['7-5'], None]),
  ('boundary tiebreak set', ('AAAAABBBBBABB', 3), [['6-7'], None]),
  ('control straight sets', ('AAAAAAAAAAAA', 3), [['6-0', '6-0'], 'A']),
  ('control in-progress set', ('AAAAAAB', 3), [['6-0', '0-1'], None]),
  ('control empty', ('', 5), [[], None]),
  ('regression: six game lead',
   ('BAAAAAAAAABBBAABBABBBBAABBBAA', 5),
   [['6-1', '6-7', '4-5'], None]),
  ('regression: six game lead',
   ('BAABAAABBBABBABABBABBBBBAABBABBBABBAAAABABBABAA', 3),
   [['6-7', '3-6'], 'B']),
  ('variant scenario 1', ('AAABA', 5), [['4-1'], None]),
  ('variant scenario 2', ('BBAAABABAABAAAAAAAAAAAABABB', 5), [['6-4', '6-1', '6-0'], 'A'])],
 [('control bagel set', ('AAAAAA', 3), [['6-0'], None]),
  ('boundary seven-five', ('AAAAABBBBBAA', 3), [['7-5'], None]),
  ('boundary tiebreak set', ('AAAAABBBBBABB', 3), [['6-7'], None]),
  ('control straight sets', ('AAAAAAAAAAAA', 3), [['6-0', '6-0'], 'A']),
  ('control in-progress set', ('AAAAAAB', 3), [['6-0', '0-1'], None]),
  ('control empty', ('', 5), [[], None]),
  ('regression: six game lead',
   ('ABABBAABABAABAAAABAABAABBBAAAABAAAAAABBAAAABBBAAAABBAABBAB', 3),
   [['7-5', '6-2'], 'A']),
  ('regression: six game lead',
   ('ABBAABBBBAABABABAAABBABAABAAAABBAAAA', 3),
   [['3-6', '6-3', '6-4'], 'A']),
  ('variant scenario 1', ('BAAABAABABAAABABAABABBBBBB', 3), [['6-3', '6-3'], 'A']),
  ('variant scenario 2', ('AAABAAAAAABAAAABAAAABBABBAAABBAAABABAAA', 3), [['6-1', '6-1'], 'A'])]]
for label, args, expected in cases[N - 1]:
    check(label, run(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(games, best_of):
    sets = []
    a = b = 0
    won = {'A': 0, 'B': 0}
    need = best_of // 2 + 1
    for g in games:
        if g == 'A':
            a += 1
        else:
            b += 1
        if (a >= 6 and a - b >= 2) or max(a, b) == 7:
            w = 'A' if a > b else 'B'
            won[w] += 1
            sets.append('%d-%d' % (a, b))
            a = b = 0
            if won[w] == need:
                return [sets, w]
    if a or b:
        sets.append('%d-%d' % (a, b))
    return [sets, None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control bagel set', ('AAAAAA', 3), [['6-0'], None]),
  ('boundary seven-five', ('AAAAABBBBBAA', 3), [['7-5'], None]),
  ('boundary tiebreak set', ('AAAAABBBBBABB', 3), [['6-7'], None]),
  ('control straight sets', ('AAAAAAAAAAAA', 3), [['6-0', '6-0'], 'A']),
  ('control in-progress set', ('AAAAAAB', 3), [['6-0', '0-1'], None]),
  ('control empty', ('', 5), [[], None]),
  ('regression: six game lead', ('BBAABAABABAABBBBBAAAAB', 3), [['7-5', '4-6'], None]),
  ('regression: six game lead', ('BABBBBBABAABBBBAAAAABBA', 3), [['1-6', '7-5', '2-2'], None]),
  ('variant scenario 1', ('AAABBAAAAAABB', 5), [['6-2', '3-2'], None]),
  ('variant scenario 2', ('BAAAAABAABBBBAAAABABAABAABA', 3), [['6-2', '7-6'], 'A'])],
 [('control bagel set', ('AAAAAA', 3), [['6-0'], None]),
  ('boundary seven-five', ('AAAAABBBBBAA', 3), [['7-5'], None]),
  ('boundary tiebreak set', ('AAAAABBBBBABB', 3), [['6-7'], None]),
  ('control straight sets', ('AAAAAAAAAAAA', 3), [['6-0', '6-0'], 'A']),
  ('control in-progress set', ('AAAAAAB', 3), [['6-0', '0-1'], None]),
  ('control empty', ('', 5), [[], None]),
  ('regression: six game lead', ('AAAABAAABBBBAAABBAABBAABA', 5), [['6-1', '4-6', '5-3'], None]),
  ('regression: six game lead', ('BAAAABBBABBAAAAA', 3), [['7-6', '3-0'], None]),
  ('variant scenario 1', ('BAAAA', 3), [['4-1'], None]),
  ('variant scenario 2',
   ('BAAAABABABABAABBBABABAAAAAAAAAA', 5),
   [['6-3', '4-6', '6-1', '5-0'], None])],
 [('control bagel set', ('AAAAAA', 3), [['6-0'], None]),
  ('boundary seven-five', ('AAAAABBBBBAA', 3), [['7-5'], None]),
  ('boundary tiebreak set', ('AAAAABBBBBABB', 3), [['6-7'], None]),
  ('control straight sets', ('AAAAAAAAAAAA', 3), [['6-0', '6-0'], 'A']),
  ('control in-progress set', ('AAAAAAB', 3), [['6-0', '0-1'], None]),
  ('control empty', ('', 5), [[], None]),
  ('regression: six game lead', ('BBBBBBBBBABAABABBBBBAAAAA', 3), [['0-6', '4-6'], 'B']),
  ('regression: six game lead',
   ('BBABAAAABBAAABBABAABABBAAABBBABBAAABAA', 3),
   [['7-5', '7-6'], 'A']),
  ('variant scenario 1', ('ABAABABBBABBBAABBBAAAAA', 5), [['5-7', '6-4', '1-0'], None]),
  ('variant scenario 2', ('BAAABBAABABB', 3), [['6-4', '0-2'], None])],
 [('control bagel set', ('AAAAAA', 3), [['6-0'], None]),
  ('boundary seven-five', ('AAAAABBBBBAA', 3), [['7-5'], None]),
  ('boundary tiebreak set', ('AAAAABBBBBABB', 3), [['6-7'], None]),
  ('control straight sets', ('AAAAAAAAAAAA', 3), [['6-0', '6-0'], 'A']),
  ('control in-progress set', ('AAAAAAB', 3), [['6-0', '0-1'], None]),
  ('control empty', ('', 5), [[], None]),
  ('regression: six game lead',
   ('BAAAAAAAAABBBAABBABBBBAABBBAA', 5),
   [['6-1', '6-7', '4-5'], None]),
  ('regression: six game lead',
   ('BAABAAABBBABBABABBABBBBBAABBABBBABBAAAABABBABAA', 3),
   [['6-7', '3-6'], 'B']),
  ('variant scenario 1', ('AAABA', 5), [['4-1'], None]),
  ('variant scenario 2', ('BBAAABABAABAAAAAAAAAAAABABB', 5), [['6-4', '6-1', '6-0'], 'A'])],
 [('control bagel set', ('AAAAAA', 3), [['6-0'], None]),
  ('boundary seven-five', ('AAAAABBBBBAA', 3), [['7-5'], None]),
  ('boundary tiebreak set', ('AAAAABBBBBABB', 3), [['6-7'], None]),
  ('control straight sets', ('AAAAAAAAAAAA', 3), [['6-0', '6-0'], 'A']),
  ('control in-progress set', ('AAAAAAB', 3), [['6-0', '0-1'], None]),
  ('control empty', ('', 5), [[], None]),
  ('regression: six game lead',
   ('ABABBAABABAABAAAABAABAABBBAAAABAAAAAABBAAAABBBAAAABBAABBAB', 3),
   [['7-5', '6-2'], 'A']),
  ('regression: six game lead',
   ('ABBAABBBBAABABABAAABBABAABAAAABBAAAA', 3),
   [['3-6', '6-3', '6-4'], 'A']),
  ('variant scenario 1', ('BAAABAABABAAABABAABABBBBBB', 3), [['6-3', '6-3'], 'A']),
  ('variant scenario 2', ('AAABAAAAAABAAAABAAAABBABBAAABBAAABABAAA', 3), [['6-1', '6-1'], 'A'])]]
for label, args, expected in cases[N - 1]:
    check(label, run(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 6-5 set is recorded as complete.

games is a string of game winners (A/B); best_of is 3 or 5. A set is won by the first player to 6 games with a lead of two, or at 7 games (7-5, or 7-6 after the tiebreak game played at 6-6). The match ends when a player has won best_of // 2 + 1 sets; later games are ignored. Return [set scores as "a-b" strings in A-B order, match winner or None]; an unfinished set with at least one game is appended as its current score.

split: open-access


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

N = 1
observations = []
def solve(rallies, first_serve):
    won = {'A': 0, 'B': 0}
    sets = []
    a = b = 0
    set_index = 0
    server = first_serve
    rot = {'A': 0, 'B': 0}
    for r in rallies:
        if r == 'A':
            a += 1
        else:
            b += 1
        if r != server:
            rot[r] = (rot[r] + 1) % 6
            server = r
        target = 15 if set_index == 5 else 25
        if max(a, b) >= target and abs(a - b) >= 2:
            w = 'A' if a > b else 'B'
            won[w] += 1
            sets.append([a, b])
            if won[w] == 3:
                return [sets, w, rot]
            a = b = 0
            set_index += 1
            rot = {'A': 0, 'B': 0}
            server = first_serve if set_index % 2 == 0 else ('B' if first_serve == 'A' else 'A')
    return [sets + ([[a, b]] if a or b else []), None, rot]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control first rally held by server', ('A', 'A'), [[[1, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary side-out rotates receiver', ('B', 'A'), [[[0, 1]], None, {'A': 0, 'B': 1}]),
  ('control clean set', ('AAAAAAAAAAAAAAAAAAAAAAAAA', 'A'), [[[25, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary second set served by other team',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAA', 'A'),
   [[[25, 0], [1, 0]], None, {'A': 1, 'B': 0}]),
  ('boundary deuce in set',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABAA', 'A'),
   [[[26, 24]], None, {'A': 0, 'B': 0}]),
  ('control straight-sets match',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', 'B'),
   [[[25, 0], [25, 0], [25, 0]], 'A', {'A': 1, 'B': 0}]),
  ('regression: deciding set target',
   ('AAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBBBBAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBBBBAAAAAAAAAAAAAAA',
    'A'),
   [[[25, 0], [0, 25], [25, 0], [0, 25], [15, 0]], 'A', {'A': 0, 'B': 0}]),
  ('variant scenario 1',
   ('ABAABAAAAABBBABBAAAAABBBAAABBBABB', 'A'),
   [[[18, 15]], None, {'A': 0, 'B': 1}]),
  ('variant scenario 2', ('AAABBAAAABBAAABABBAAAAA', 'A'), [[[16, 7]], None, {'A': 4, 'B': 4}])],
 [('control first rally held by server', ('A', 'A'), [[[1, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary side-out rotates receiver', ('B', 'A'), [[[0, 1]], None, {'A': 0, 'B': 1}]),
  ('control clean set', ('AAAAAAAAAAAAAAAAAAAAAAAAA', 'A'), [[[25, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary second set served by other team',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAA', 'A'),
   [[[25, 0], [1, 0]], None, {'A': 1, 'B': 0}]),
  ('boundary deuce in set',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABAA', 'A'),
   [[[26, 24]], None, {'A': 0, 'B': 0}]),
  ('control straight-sets match',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', 'B'),
   [[[25, 0], [25, 0], [25, 0]], 'A', {'A': 1, 'B': 0}]),
  ('regression: deciding set target',
   ('AAAAAABAAAAAAAAABABAAAAAAABABABAABBAAABBABABAAAAAAAAAAABBAAABAAAABABABBBBAAAAAABBBBAAAAAAAABBBABAAAAABBAAAABBABABBAABBBAAA',
    'A'),
   [[[25, 5], [25, 10], [25, 16]], 'A', {'A': 1, 'B': 1}]),
  ('regression: deciding set target',
   ('AAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBBBBAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBBBBAAAAAAAAAAAAAAA',
    'A'),
   [[[25, 0], [0, 25], [25, 0], [0, 25], [15, 0]], 'A', {'A': 0, 'B': 0}]),
  ('variant scenario 1',
   ('BAABAAAABAABAAABBBAAABBAAAAAAAAAABAABAAAABABAAABBABBBA', 'B'),
   [[[25, 10], [11, 8]], None, {'A': 5, 'B': 5}]),
  ('variant scenario 2',
   ('AABAAAABABAAAAAAABAAABABBBABBBBABBBAABBAAABBBBBAAAAABABBABABBAAAABABB', 'B'),
   [[[25, 17], [13, 14]], None, {'A': 0, 'B': 1}])],
 [('control first rally held by server', ('A', 'A'), [[[1, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary side-out rotates receiver', ('B', 'A'), [[[0, 1]], None, {'A': 0, 'B': 1}]),
  ('control clean set', ('AAAAAAAAAAAAAAAAAAAAAAAAA', 'A'), [[[25, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary second set served by other team',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAA', 'A'),
   [[[25, 0], [1, 0]], None, {'A': 1, 'B': 0}]),
  ('boundary deuce in set',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABAA', 'A'),
   [[[26, 24]], None, {'A': 0, 'B': 0}]),
  ('control straight-sets match',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', 'B'),
   [[[25, 0], [25, 0], [25, 0]], 'A', {'A': 1, 'B': 0}]),
  ('regression: deciding set target',
   ('AABAAABAAAABAAAABAAAAABBAAABABABABABABAAAABAABBBBABAABBAABAABBBAAAAAAAAABBAAABABBABBABABAAAAAAAAAAB',
    'A'),
   [[[25, 10], [25, 16], [15, 8]], None, {'A': 5, 'B': 0}]),
  ('regression: deciding set target',
   ('AAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBBBBAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBBBBAAAAAAAAAAAAAAA',
    'A'),
   [[[25, 0], [0, 25], [25, 0], [0, 25], [15, 0]], 'A', {'A': 0, 'B': 0}]),
  ('variant scenario 1',
   ('BABAAABABAABAAAAABAAAAABABABABBABABBBABABBAAABBBAABBAABAABABAAAABAAAABABBAABAAAABAABAAAAABAABABBAAAAAAABBBBBBAAAAAABBBAAABBAAAABBBBABBBBBBABBBAAABAAABBBAB',
    'A'),
   [[[25, 18], [25, 14], [25, 14]], 'A', {'A': 0, 'B': 0}]),
  ('variant scenario 2',
   ('BAAAABAAAAAAAAABAABAAAABBAAABAAAAAAAAABBBAAAABAAABABBAABABABAABAAAAAAAAABABBBABBBAABAAAAAAABBABBABABBAABAAA',
    'A'),
   [[[25, 7], [25, 11], [23, 16]], None, {'A': 3, 'B': 3}])],
 [('control first rally held by server', ('A', 'A'), [[[1, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary side-out rotates receiver', ('B', 'A'), [[[0, 1]], None, {'A': 0, 'B': 1}]),
  ('control clean set', ('AAAAAAAAAAAAAAAAAAAAAAAAA', 'A'), [[[25, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary second set served by other team',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAA', 'A'),
   [[[25, 0], [1, 0]], None, {'A': 1, 'B': 0}]),
  ('boundary deuce in set',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABAA', 'A'),
   [[[26, 24]], None, {'A': 0, 'B': 0}]),
  ('control straight-sets match',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', 'B'),
   [[[25, 0], [25, 0], [25, 0]], 'A', {'A': 1, 'B': 0}]),
  ('regression: deciding set target',
   ('BAAABABBBBBAAAABABAABAAAAAABAAABBBBAAAAABABABABAAAABAABAABAABBAABAAAAAAAAAAAABBBAABAAAAAABAAABAAAAABBAABAAABBBBABABBABABAAABBABAABBBAAAABBBAABBAAABAABABBBAAABBBABAAAABBAAAABBBBBABA',
    'A'),
   [[[25, 15], [25, 10], [25, 14]], 'A', {'A': 2, 'B': 2}]),
  ('regression: deciding set target',
   ('AAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBBBBAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBBBBAAAAAAAAAAAAAAA',
    'A'),
   [[[25, 0], [0, 25], [25, 0], [0, 25], [15, 0]], 'A', {'A': 0, 'B': 0}]),
  ('variant scenario 1',
   ('ABABAAAAAAAABBAABAABAABBAAAABABAAABAAAABBABABBBBAABABABABABBABBAABBBBABBAABA', 'A'),
   [[[25, 11], [18, 22]], None, {'A': 1, 'B': 0}]),
  ('variant scenario 2',
   ('AABBAABBABAAAAAABABBBABBBBBBBAAAAABAAAAABABABBAABAABBAAAAAAABABAAABBBBBABAAAAAAAAAABAABAABAAAAAAABBAABABBAABABABBBBAAABABAAAAAAABABBBBBBBAAAAAAAABBBBAAAAABAAAABBBBAAAAABABAAAABABBBBB',
    'B'),
   [[[25, 19], [25, 13], [25, 16]], 'A', {'A': 0, 'B': 5}])],
 [('control first rally held by server', ('A', 'A'), [[[1, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary side-out rotates receiver', ('B', 'A'), [[[0, 1]], None, {'A': 0, 'B': 1}]),
  ('control clean set', ('AAAAAAAAAAAAAAAAAAAAAAAAA', 'A'), [[[25, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary second set served by other team',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAA', 'A'),
   [[[25, 0], [1, 0]], None, {'A': 1, 'B': 0}]),
  ('boundary deuce in set',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABAA', 'A'),
   [[[26, 24]], None, {'A': 0, 'B': 0}]),
  ('control straight-sets match',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', 'B'),
   [[[25, 0], [25, 0], [25, 0]], 'A', {'A': 1, 'B': 0}]),
  ('regression: deciding set target',
   ('AAAABAAAAAAAAAAAAAAABBAAABAAABABABAAAABABBBAABAAAAAAABBAAABABAABBABAABAAAABBAAABAABABAAAAAAAAABAABBAAAAAAABAABAAABAABBABABABABAAABABAABBAAABBABABAAAAAAAABAAAAAAAAABAABABABAAAABAAABAABABAAAAAAAABAAABBBABAABBA',
    'A'),
   [[[25, 4], [25, 15], [25, 9]], 'A', {'A': 1, 'B': 1}]),
  ('regression: deciding set target',
   ('AAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBBBBAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBBBBAAAAAAAAAAAAAAA',
    'A'),
   [[[25, 0], [0, 25], [25, 0], [0, 25], [15, 0]], 'A', {'A': 0, 'B': 0}]),
  ('variant scenario 1', ('AAAAAAAAABABAABBBBAAAA', 'A'), [[[16, 6]], None, {'A': 3, 'B': 3}]),
  ('variant scenario 2',
   ('AAAABAABAAABABBAAAAAAAABAABAABAAABAABAABBABAAABBABBAAAABABBAAABBABABAAABBAAAAABAABABAB', 'A'),
   [[[25, 8], [25, 18], [6, 4]], None, {'A': 3, 'B': 4}])]]
for label, args, expected in cases[N - 1]:
    check(label, run(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(rallies, first_serve):
    won = {'A': 0, 'B': 0}
    sets = []
    a = b = 0
    set_index = 0
    server = first_serve
    rot = {'A': 0, 'B': 0}
    for r in rallies:
        if r == 'A':
            a += 1
        else:
            b += 1
        if r != server:
            rot[r] = (rot[r] + 1) % 6
            server = r
        target = 15 if won['A'] == 2 or won['B'] == 2 else 25
        if max(a, b) >= target and abs(a - b) >= 2:
            w = 'A' if a > b else 'B'
            won[w] += 1
            sets.append([a, b])
            if won[w] == 3:
                return [sets, w, rot]
            a = b = 0
            set_index += 1
            rot = {'A': 0, 'B': 0}
            server = first_serve if set_index % 2 == 0 else ('B' if first_serve == 'A' else 'A')
    return [sets + ([[a, b]] if a or b else []), None, rot]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control first rally held by server', ('A', 'A'), [[[1, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary side-out rotates receiver', ('B', 'A'), [[[0, 1]], None, {'A': 0, 'B': 1}]),
  ('control clean set', ('AAAAAAAAAAAAAAAAAAAAAAAAA', 'A'), [[[25, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary second set served by other team',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAA', 'A'),
   [[[25, 0], [1, 0]], None, {'A': 1, 'B': 0}]),
  ('boundary deuce in set',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABAA', 'A'),
   [[[26, 24]], None, {'A': 0, 'B': 0}]),
  ('control straight-sets match',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', 'B'),
   [[[25, 0], [25, 0], [25, 0]], 'A', {'A': 1, 'B': 0}]),
  ('regression: deciding set target',
   ('AAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBBBBAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBBBBAAAAAAAAAAAAAAA',
    'A'),
   [[[25, 0], [0, 25], [25, 0], [0, 25], [15, 0]], 'A', {'A': 0, 'B': 0}]),
  ('variant scenario 1',
   ('ABAABAAAAABBBABBAAAAABBBAAABBBABB', 'A'),
   [[[18, 15]], None, {'A': 0, 'B': 1}]),
  ('variant scenario 2', ('AAABBAAAABBAAABABBAAAAA', 'A'), [[[16, 7]], None, {'A': 4, 'B': 4}])],
 [('control first rally held by server', ('A', 'A'), [[[1, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary side-out rotates receiver', ('B', 'A'), [[[0, 1]], None, {'A': 0, 'B': 1}]),
  ('control clean set', ('AAAAAAAAAAAAAAAAAAAAAAAAA', 'A'), [[[25, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary second set served by other team',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAA', 'A'),
   [[[25, 0], [1, 0]], None, {'A': 1, 'B': 0}]),
  ('boundary deuce in set',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABAA', 'A'),
   [[[26, 24]], None, {'A': 0, 'B': 0}]),
  ('control straight-sets match',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', 'B'),
   [[[25, 0], [25, 0], [25, 0]], 'A', {'A': 1, 'B': 0}]),
  ('regression: deciding set target',
   ('AAAAAABAAAAAAAAABABAAAAAAABABABAABBAAABBABABAAAAAAAAAAABBAAABAAAABABABBBBAAAAAABBBBAAAAAAAABBBABAAAAABBAAAABBABABBAABBBAAA',
    'A'),
   [[[25, 5], [25, 10], [25, 16]], 'A', {'A': 1, 'B': 1}]),
  ('regression: deciding set target',
   ('AAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBBBBAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBBBBAAAAAAAAAAAAAAA',
    'A'),
   [[[25, 0], [0, 25], [25, 0], [0, 25], [15, 0]], 'A', {'A': 0, 'B': 0}]),
  ('variant scenario 1',
   ('BAABAAAABAABAAABBBAAABBAAAAAAAAAABAABAAAABABAAABBABBBA', 'B'),
   [[[25, 10], [11, 8]], None, {'A': 5, 'B': 5}]),
  ('variant scenario 2',
   ('AABAAAABABAAAAAAABAAABABBBABBBBABBBAABBAAABBBBBAAAAABABBABABBAAAABABB', 'B'),
   [[[25, 17], [13, 14]], None, {'A': 0, 'B': 1}])],
 [('control first rally held by server', ('A', 'A'), [[[1, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary side-out rotates receiver', ('B', 'A'), [[[0, 1]], None, {'A': 0, 'B': 1}]),
  ('control clean set', ('AAAAAAAAAAAAAAAAAAAAAAAAA', 'A'), [[[25, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary second set served by other team',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAA', 'A'),
   [[[25, 0], [1, 0]], None, {'A': 1, 'B': 0}]),
  ('boundary deuce in set',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABAA', 'A'),
   [[[26, 24]], None, {'A': 0, 'B': 0}]),
  ('control straight-sets match',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', 'B'),
   [[[25, 0], [25, 0], [25, 0]], 'A', {'A': 1, 'B': 0}]),
  ('regression: deciding set target',
   ('AABAAABAAAABAAAABAAAAABBAAABABABABABABAAAABAABBBBABAABBAABAABBBAAAAAAAAABBAAABABBABBABABAAAAAAAAAAB',
    'A'),
   [[[25, 10], [25, 16], [15, 8]], None, {'A': 5, 'B': 0}]),
  ('regression: deciding set target',
   ('AAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBBBBAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBBBBAAAAAAAAAAAAAAA',
    'A'),
   [[[25, 0], [0, 25], [25, 0], [0, 25], [15, 0]], 'A', {'A': 0, 'B': 0}]),
  ('variant scenario 1',
   ('BABAAABABAABAAAAABAAAAABABABABBABABBBABABBAAABBBAABBAABAABABAAAABAAAABABBAABAAAABAABAAAAABAABABBAAAAAAABBBBBBAAAAAABBBAAABBAAAABBBBABBBBBBABBBAAABAAABBBAB',
    'A'),
   [[[25, 18], [25, 14], [25, 14]], 'A', {'A': 0, 'B': 0}]),
  ('variant scenario 2',
   ('BAAAABAAAAAAAAABAABAAAABBAAABAAAAAAAAABBBAAAABAAABABBAABABABAABAAAAAAAAABABBBABBBAABAAAAAAABBABBABABBAABAAA',
    'A'),
   [[[25, 7], [25, 11], [23, 16]], None, {'A': 3, 'B': 3}])],
 [('control first rally held by server', ('A', 'A'), [[[1, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary side-out rotates receiver', ('B', 'A'), [[[0, 1]], None, {'A': 0, 'B': 1}]),
  ('control clean set', ('AAAAAAAAAAAAAAAAAAAAAAAAA', 'A'), [[[25, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary second set served by other team',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAA', 'A'),
   [[[25, 0], [1, 0]], None, {'A': 1, 'B': 0}]),
  ('boundary deuce in set',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABAA', 'A'),
   [[[26, 24]], None, {'A': 0, 'B': 0}]),
  ('control straight-sets match',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', 'B'),
   [[[25, 0], [25, 0], [25, 0]], 'A', {'A': 1, 'B': 0}]),
  ('regression: deciding set target',
   ('BAAABABBBBBAAAABABAABAAAAAABAAABBBBAAAAABABABABAAAABAABAABAABBAABAAAAAAAAAAAABBBAABAAAAAABAAABAAAAABBAABAAABBBBABABBABABAAABBABAABBBAAAABBBAABBAAABAABABBBAAABBBABAAAABBAAAABBBBBABA',
    'A'),
   [[[25, 15], [25, 10], [25, 14]], 'A', {'A': 2, 'B': 2}]),
  ('regression: deciding set target',
   ('AAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBBBBAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBBBBAAAAAAAAAAAAAAA',
    'A'),
   [[[25, 0], [0, 25], [25, 0], [0, 25], [15, 0]], 'A', {'A': 0, 'B': 0}]),
  ('variant scenario 1',
   ('ABABAAAAAAAABBAABAABAABBAAAABABAAABAAAABBABABBBBAABABABABABBABBAABBBBABBAABA', 'A'),
   [[[25, 11], [18, 22]], None, {'A': 1, 'B': 0}]),
  ('variant scenario 2',
   ('AABBAABBABAAAAAABABBBABBBBBBBAAAAABAAAAABABABBAABAABBAAAAAAABABAAABBBBBABAAAAAAAAAABAABAABAAAAAAABBAABABBAABABABBBBAAABABAAAAAAABABBBBBBBAAAAAAAABBBBAAAAABAAAABBBBAAAAABABAAAABABBBBB',
    'B'),
   [[[25, 19], [25, 13], [25, 16]], 'A', {'A': 0, 'B': 5}])],
 [('control first rally held by server', ('A', 'A'), [[[1, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary side-out rotates receiver', ('B', 'A'), [[[0, 1]], None, {'A': 0, 'B': 1}]),
  ('control clean set', ('AAAAAAAAAAAAAAAAAAAAAAAAA', 'A'), [[[25, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary second set served by other team',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAA', 'A'),
   [[[25, 0], [1, 0]], None, {'A': 1, 'B': 0}]),
  ('boundary deuce in set',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABAA', 'A'),
   [[[26, 24]], None, {'A': 0, 'B': 0}]),
  ('control straight-sets match',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', 'B'),
   [[[25, 0], [25, 0], [25, 0]], 'A', {'A': 1, 'B': 0}]),
  ('regression: deciding set target',
   ('AAAABAAAAAAAAAAAAAAABBAAABAAABABABAAAABABBBAABAAAAAAABBAAABABAABBABAABAAAABBAAABAABABAAAAAAAAABAABBAAAAAAABAABAAABAABBABABABABAAABABAABBAAABBABABAAAAAAAABAAAAAAAAABAABABABAAAABAAABAABABAAAAAAAABAAABBBABAABBA',
    'A'),
   [[[25, 4], [25, 15], [25, 9]], 'A', {'A': 1, 'B': 1}]),
  ('regression: deciding set target',
   ('AAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBBBBAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBBBBAAAAAAAAAAAAAAA',
    'A'),
   [[[25, 0], [0, 25], [25, 0], [0, 25], [15, 0]], 'A', {'A': 0, 'B': 0}]),
  ('variant scenario 1', ('AAAAAAAAABABAABBBBAAAA', 'A'), [[[16, 6]], None, {'A': 3, 'B': 3}]),
  ('variant scenario 2',
   ('AAAABAABAAABABBAAAAAAAABAABAABAAABAABAABBABAAABBABBAAAABABBAAABBABABAAABBAAAAABAABABAB', 'A'),
   [[[25, 8], [25, 18], [6, 4]], None, {'A': 3, 'B': 4}])]]
for label, args, expected in cases[N - 1]:
    check(label, run(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 deciding set is not closed at 15-13 and continues to 25.

Best-of-five volleyball with rally scoring. rallies is a string of rally winners (A/B). Sets 1-4 are played to 25 and set 5 to 15, always win by two with no cap. The rally winner serves next; when the receiving team wins a rally (side-out) that team rotates once (rotation counter modulo 6). At the start of each set both rotation counters reset to 0 and the first server is first_serve in odd-numbered sets and the other team in even-numbered sets. Return [completed and current set scores as [a, b], match winner or None, rotation counters].

split: open-access


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

N = 1
observations = []
def solve(rallies, first_serve):
    won = {'A': 0, 'B': 0}
    sets = []
    a = b = 0
    set_index = 0
    server = first_serve
    rot = {'A': 0, 'B': 0}
    for r in rallies:
        if r == 'A':
            a += 1
        else:
            b += 1
        rot[r] = (rot[r] + 1) % 6
        server = r
        target = 15 if set_index == 4 else 25
        if max(a, b) >= target and abs(a - b) >= 2:
            w = 'A' if a > b else 'B'
            won[w] += 1
            sets.append([a, b])
            if won[w] == 3:
                return [sets, w, rot]
            a = b = 0
            set_index += 1
            rot = {'A': 0, 'B': 0}
            server = first_serve if set_index % 2 == 0 else ('B' if first_serve == 'A' else 'A')
    return [sets + ([[a, b]] if a or b else []), None, rot]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control first rally held by server', ('A', 'A'), [[[1, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary side-out rotates receiver', ('B', 'A'), [[[0, 1]], None, {'A': 0, 'B': 1}]),
  ('control clean set', ('AAAAAAAAAAAAAAAAAAAAAAAAA', 'A'), [[[25, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary second set served by other team',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAA', 'A'),
   [[[25, 0], [1, 0]], None, {'A': 1, 'B': 0}]),
  ('boundary deuce in set',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABAA', 'A'),
   [[[26, 24]], None, {'A': 0, 'B': 0}]),
  ('control straight-sets match',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', 'B'),
   [[[25, 0], [25, 0], [25, 0]], 'A', {'A': 1, 'B': 0}]),
  ('regression: side out rotation',
   ('ABBABABAAAABAABABAAAAAABABBBAABBAAAAABBABABABBAAABABAABBABAABBAABABBAAABBBABBBAABABA', 'B'),
   [[[25, 15], [22, 22]], None, {'A': 2, 'B': 2}]),
  ('regression: side out rotation',
   ('AAABBBABAAAAABBAABBBAAAAABAABBAABBAA', 'B'),
   [[[22, 14]], None, {'A': 2, 'B': 1}]),
  ('variant scenario 1',
   ('BBABBBABBBBBBABAABAABAABBBAAABAAAAABBABAAABABAAABABAA', 'B'),
   [[[25, 23], [3, 2]], None, {'A': 2, 'B': 2}]),
  ('variant scenario 2',
   ('BABBBBABBAABBABBBAABBAAABBABAAABAAABAAAABABBBBBABAAABABAAAAABAAAABBAAABABAAABBBBBAABABBAABBBBBBAA',
    'A'),
   [[[22, 25], [25, 16], [3, 6]], None, {'A': 1, 'B': 1}])],
 [('control first rally held by server', ('A', 'A'), [[[1, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary side-out rotates receiver', ('B', 'A'), [[[0, 1]], None, {'A': 0, 'B': 1}]),
  ('control clean set', ('AAAAAAAAAAAAAAAAAAAAAAAAA', 'A'), [[[25, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary second set served by other team',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAA', 'A'),
   [[[25, 0], [1, 0]], None, {'A': 1, 'B': 0}]),
  ('boundary deuce in set',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABAA', 'A'),
   [[[26, 24]], None, {'A': 0, 'B': 0}]),
  ('control straight-sets match',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', 'B'),
   [[[25, 0], [25, 0], [25, 0]], 'A', {'A': 1, 'B': 0}]),
  ('regression: side out rotation',
   ('BABBAABAAAABAABABBAAAA', 'A'),
   [[[14, 8]], None, {'A': 0, 'B': 0}]),
  ('regression: side out rotation',
   ('BAABABAABBAAAABABBBBAA', 'B'),
   [[[12, 10]], None, {'A': 0, 'B': 5}]),
  ('variant scenario 1',
   ('ABABBBAABABAABABBABBBAABAAABAAABABBBBBBBBAAABABABAAABAABAAAABBAAAAABBAABAAAAAABBBAA', 'B'),
   [[[22, 25], [25, 11]], None, {'A': 0, 'B': 0}]),
  ('variant scenario 2',
   ('ABAABABAAABAABAAABBABBBAABAAABABBAAAAABBAABABABBBAAABABABBAAAABBAAAABAABBAABAABAABABABBABAAAABAA',
    'A'),
   [[[25, 16], [25, 17], [8, 5]], None, {'A': 4, 'B': 4}])],
 [('control first rally held by server', ('A', 'A'), [[[1, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary side-out rotates receiver', ('B', 'A'), [[[0, 1]], None, {'A': 0, 'B': 1}]),
  ('control clean set', ('AAAAAAAAAAAAAAAAAAAAAAAAA', 'A'), [[[25, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary second set served by other team',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAA', 'A'),
   [[[25, 0], [1, 0]], None, {'A': 1, 'B': 0}]),
  ('boundary deuce in set',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABAA', 'A'),
   [[[26, 24]], None, {'A': 0, 'B': 0}]),
  ('control straight-sets match',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', 'B'),
   [[[25, 0], [25, 0], [25, 0]], 'A', {'A': 1, 'B': 0}]),
  ('regression: side out rotation',
   ('BAAAABABABAABAABAAAAABAABBBAABBAAAAABBAAABAAAABAABAABABBABAAAABAABABAAABABBBAAABBBBBABBBAABAAABBAAAAABBBAAAAAAAAAABABBAAAAA',
    'A'),
   [[[25, 14], [25, 14], [25, 17]], 'A', {'A': 1, 'B': 1}]),
  ('regression: side out rotation',
   ('BBAAAAAABABAAABAABAAABABBBBBBAB', 'A'),
   [[[17, 14]], None, {'A': 1, 'B': 2}]),
  ('variant scenario 1',
   ('BBBAAAABBAABBABBABBBAABAAABABAAAAAAABBBABAAABAAAABABAABAAAAAAABBABBBBABABAAAAABBAABABAAAABBBAABAABABBAABAABAAAABAAAAAAAABBAAAAAAAAABABAAAABBABABAAAABBA',
    'A'),
   [[[25, 19], [25, 15], [25, 11]], 'A', {'A': 2, 'B': 2}]),
  ('variant scenario 2',
   ('AAABBABBBAAABABAAAABAAAAAABBBAAABABBABAAAABBBBAABABAABAABAABBAAAABBABBABBBABAABBAABABAAAAAAAAABBABABAA',
    'A'),
   [[[25, 15], [25, 22], [11, 4]], None, {'A': 3, 'B': 3}])],
 [('control first rally held by server', ('A', 'A'), [[[1, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary side-out rotates receiver', ('B', 'A'), [[[0, 1]], None, {'A': 0, 'B': 1}]),
  ('control clean set', ('AAAAAAAAAAAAAAAAAAAAAAAAA', 'A'), [[[25, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary second set served by other team',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAA', 'A'),
   [[[25, 0], [1, 0]], None, {'A': 1, 'B': 0}]),
  ('boundary deuce in set',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABAA', 'A'),
   [[[26, 24]], None, {'A': 0, 'B': 0}]),
  ('control straight-sets match',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', 'B'),
   [[[25, 0], [25, 0], [25, 0]], 'A', {'A': 1, 'B': 0}]),
  ('regression: side out rotation',
   ('AAAAAAAABAAABAAABAABAAAAAABABBABAABABBBBAAAAAAAAABABBBABBBBBABAABBBBBBBBBAAABAABAABAAAAAAAAABBAABAAAABABBBAAABABABAAAAAAABABABAAAABAAAAAABAAB',
    'B'),
   [[[25, 8], [19, 25], [25, 11], [21, 7]], None, {'A': 0, 'B': 1}]),
  ('variant scenario 1',
   ('AAABBABAABAABABBAAAAAAABBBAABAAAAB', 'B'),
   [[[22, 12]], None, {'A': 2, 'B': 2}]),
  ('variant scenario 2',
   ('BABABABAAABAAAAABAAABAAAAABABBBAABBBAAB', 'B'),
   [[[24, 15]], None, {'A': 4, 'B': 4}])],
 [('control first rally held by server', ('A', 'A'), [[[1, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary side-out rotates receiver', ('B', 'A'), [[[0, 1]], None, {'A': 0, 'B': 1}]),
  ('control clean set', ('AAAAAAAAAAAAAAAAAAAAAAAAA', 'A'), [[[25, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary second set served by other team',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAA', 'A'),
   [[[25, 0], [1, 0]], None, {'A': 1, 'B': 0}]),
  ('boundary deuce in set',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABAA', 'A'),
   [[[26, 24]], None, {'A': 0, 'B': 0}]),
  ('control straight-sets match',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', 'B'),
   [[[25, 0], [25, 0], [25, 0]], 'A', {'A': 1, 'B': 0}]),
  ('regression: side out rotation',
   ('AAAABAABABAAABAABAAABAABAAABAAABAAAABAAAABAAABAABAAAAAAAABABAAABBAAAAAAAABABAAAABABAABBAA',
    'B'),
   [[[25, 9], [25, 8], [16, 6]], None, {'A': 0, 'B': 5}]),
  ('variant scenario 1',
   ('ABBBABAAAAABABAAAABBABAAABABBAAAAABBBAABBAABAAAABBBABBAABABABAAAAABABABBABBABAABAAABAABAAABAAABABAAAAAAABAAAAABAAAABABABABAAABABAAAAAABABAA',
    'A'),
   [[[25, 17], [25, 18], [25, 7]], 'A', {'A': 1, 'B': 1}]),
  ('variant scenario 2',
   ('AABAAAAABBABABAABAAAABAAABABAAAAABBBBAAABAABBAAABBAAABABAABBABAAAAAAAABAAAAABBBAAABBAAAAAABAAAAAABABAABBAAABBAAAAAAAABAABBBAABABBAABABBAAABBABABAABBAABAAABAAABAABAABBAAABBAABAAABAAAAABBAAAAAABAABAAAAABAABBBAAAAABAABAABA',
    'B'),
   [[[25, 13], [25, 11], [25, 12]], 'A', {'A': 2, 'B': 1}])]]
for label, args, expected in cases[N - 1]:
    check(label, run(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(rallies, first_serve):
    won = {'A': 0, 'B': 0}
    sets = []
    a = b = 0
    set_index = 0
    server = first_serve
    rot = {'A': 0, 'B': 0}
    for r in rallies:
        if r == 'A':
            a += 1
        else:
            b += 1
        if r != server:
            rot[server] = (rot[server] + 1) % 6
            server = r
        target = 15 if set_index == 4 else 25
        if max(a, b) >= target and abs(a - b) >= 2:
            w = 'A' if a > b else 'B'
            won[w] += 1
            sets.append([a, b])
            if won[w] == 3:
                return [sets, w, rot]
            a = b = 0
            set_index += 1
            rot = {'A': 0, 'B': 0}
            server = first_serve if set_index % 2 == 0 else ('B' if first_serve == 'A' else 'A')
    return [sets + ([[a, b]] if a or b else []), None, rot]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control first rally held by server', ('A', 'A'), [[[1, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary side-out rotates receiver', ('B', 'A'), [[[0, 1]], None, {'A': 0, 'B': 1}]),
  ('control clean set', ('AAAAAAAAAAAAAAAAAAAAAAAAA', 'A'), [[[25, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary second set served by other team',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAA', 'A'),
   [[[25, 0], [1, 0]], None, {'A': 1, 'B': 0}]),
  ('boundary deuce in set',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABAA', 'A'),
   [[[26, 24]], None, {'A': 0, 'B': 0}]),
  ('control straight-sets match',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', 'B'),
   [[[25, 0], [25, 0], [25, 0]], 'A', {'A': 1, 'B': 0}]),
  ('regression: side out rotation',
   ('ABBABABAAAABAABABAAAAAABABBBAABBAAAAABBABABABBAAABABAABBABAABBAABABBAAABBBABBBAABABA', 'B'),
   [[[25, 15], [22, 22]], None, {'A': 2, 'B': 2}]),
  ('regression: side out rotation',
   ('AAABBBABAAAAABBAABBBAAAAABAABBAABBAA', 'B'),
   [[[22, 14]], None, {'A': 2, 'B': 1}]),
  ('variant scenario 1',
   ('BBABBBABBBBBBABAABAABAABBBAAABAAAAABBABAAABABAAABABAA', 'B'),
   [[[25, 23], [3, 2]], None, {'A': 2, 'B': 2}]),
  ('variant scenario 2',
   ('BABBBBABBAABBABBBAABBAAABBABAAABAAABAAAABABBBBBABAAABABAAAAABAAAABBAAABABAAABBBBBAABABBAABBBBBBAA',
    'A'),
   [[[22, 25], [25, 16], [3, 6]], None, {'A': 1, 'B': 1}])],
 [('control first rally held by server', ('A', 'A'), [[[1, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary side-out rotates receiver', ('B', 'A'), [[[0, 1]], None, {'A': 0, 'B': 1}]),
  ('control clean set', ('AAAAAAAAAAAAAAAAAAAAAAAAA', 'A'), [[[25, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary second set served by other team',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAA', 'A'),
   [[[25, 0], [1, 0]], None, {'A': 1, 'B': 0}]),
  ('boundary deuce in set',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABAA', 'A'),
   [[[26, 24]], None, {'A': 0, 'B': 0}]),
  ('control straight-sets match',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', 'B'),
   [[[25, 0], [25, 0], [25, 0]], 'A', {'A': 1, 'B': 0}]),
  ('regression: side out rotation',
   ('BABBAABAAAABAABABBAAAA', 'A'),
   [[[14, 8]], None, {'A': 0, 'B': 0}]),
  ('regression: side out rotation',
   ('BAABABAABBAAAABABBBBAA', 'B'),
   [[[12, 10]], None, {'A': 0, 'B': 5}]),
  ('variant scenario 1',
   ('ABABBBAABABAABABBABBBAABAAABAAABABBBBBBBBAAABABABAAABAABAAAABBAAAAABBAABAAAAAABBBAA', 'B'),
   [[[22, 25], [25, 11]], None, {'A': 0, 'B': 0}]),
  ('variant scenario 2',
   ('ABAABABAAABAABAAABBABBBAABAAABABBAAAAABBAABABABBBAAABABABBAAAABBAAAABAABBAABAABAABABABBABAAAABAA',
    'A'),
   [[[25, 16], [25, 17], [8, 5]], None, {'A': 4, 'B': 4}])],
 [('control first rally held by server', ('A', 'A'), [[[1, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary side-out rotates receiver', ('B', 'A'), [[[0, 1]], None, {'A': 0, 'B': 1}]),
  ('control clean set', ('AAAAAAAAAAAAAAAAAAAAAAAAA', 'A'), [[[25, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary second set served by other team',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAA', 'A'),
   [[[25, 0], [1, 0]], None, {'A': 1, 'B': 0}]),
  ('boundary deuce in set',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABAA', 'A'),
   [[[26, 24]], None, {'A': 0, 'B': 0}]),
  ('control straight-sets match',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', 'B'),
   [[[25, 0], [25, 0], [25, 0]], 'A', {'A': 1, 'B': 0}]),
  ('regression: side out rotation',
   ('BAAAABABABAABAABAAAAABAABBBAABBAAAAABBAAABAAAABAABAABABBABAAAABAABABAAABABBBAAABBBBBABBBAABAAABBAAAAABBBAAAAAAAAAABABBAAAAA',
    'A'),
   [[[25, 14], [25, 14], [25, 17]], 'A', {'A': 1, 'B': 1}]),
  ('regression: side out rotation',
   ('BBAAAAAABABAAABAABAAABABBBBBBAB', 'A'),
   [[[17, 14]], None, {'A': 1, 'B': 2}]),
  ('variant scenario 1',
   ('BBBAAAABBAABBABBABBBAABAAABABAAAAAAABBBABAAABAAAABABAABAAAAAAABBABBBBABABAAAAABBAABABAAAABBBAABAABABBAABAABAAAABAAAAAAAABBAAAAAAAAABABAAAABBABABAAAABBA',
    'A'),
   [[[25, 19], [25, 15], [25, 11]], 'A', {'A': 2, 'B': 2}]),
  ('variant scenario 2',
   ('AAABBABBBAAABABAAAABAAAAAABBBAAABABBABAAAABBBBAABABAABAABAABBAAAABBABBABBBABAABBAABABAAAAAAAAABBABABAA',
    'A'),
   [[[25, 15], [25, 22], [11, 4]], None, {'A': 3, 'B': 3}])],
 [('control first rally held by server', ('A', 'A'), [[[1, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary side-out rotates receiver', ('B', 'A'), [[[0, 1]], None, {'A': 0, 'B': 1}]),
  ('control clean set', ('AAAAAAAAAAAAAAAAAAAAAAAAA', 'A'), [[[25, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary second set served by other team',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAA', 'A'),
   [[[25, 0], [1, 0]], None, {'A': 1, 'B': 0}]),
  ('boundary deuce in set',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABAA', 'A'),
   [[[26, 24]], None, {'A': 0, 'B': 0}]),
  ('control straight-sets match',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', 'B'),
   [[[25, 0], [25, 0], [25, 0]], 'A', {'A': 1, 'B': 0}]),
  ('regression: side out rotation',
   ('AAAAAAAABAAABAAABAABAAAAAABABBABAABABBBBAAAAAAAAABABBBABBBBBABAABBBBBBBBBAAABAABAABAAAAAAAAABBAABAAAABABBBAAABABABAAAAAAABABABAAAABAAAAAABAAB',
    'B'),
   [[[25, 8], [19, 25], [25, 11], [21, 7]], None, {'A': 0, 'B': 1}]),
  ('variant scenario 1',
   ('AAABBABAABAABABBAAAAAAABBBAABAAAAB', 'B'),
   [[[22, 12]], None, {'A': 2, 'B': 2}]),
  ('variant scenario 2',
   ('BABABABAAABAAAAABAAABAAAAABABBBAABBBAAB', 'B'),
   [[[24, 15]], None, {'A': 4, 'B': 4}])],
 [('control first rally held by server', ('A', 'A'), [[[1, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary side-out rotates receiver', ('B', 'A'), [[[0, 1]], None, {'A': 0, 'B': 1}]),
  ('control clean set', ('AAAAAAAAAAAAAAAAAAAAAAAAA', 'A'), [[[25, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary second set served by other team',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAA', 'A'),
   [[[25, 0], [1, 0]], None, {'A': 1, 'B': 0}]),
  ('boundary deuce in set',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABAA', 'A'),
   [[[26, 24]], None, {'A': 0, 'B': 0}]),
  ('control straight-sets match',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', 'B'),
   [[[25, 0], [25, 0], [25, 0]], 'A', {'A': 1, 'B': 0}]),
  ('regression: side out rotation',
   ('AAAABAABABAAABAABAAABAABAAABAAABAAAABAAAABAAABAABAAAAAAAABABAAABBAAAAAAAABABAAAABABAABBAA',
    'B'),
   [[[25, 9], [25, 8], [16, 6]], None, {'A': 0, 'B': 5}]),
  ('variant scenario 1',
   ('ABBBABAAAAABABAAAABBABAAABABBAAAAABBBAABBAABAAAABBBABBAABABABAAAAABABABBABBABAABAAABAABAAABAAABABAAAAAAABAAAAABAAAABABABABAAABABAAAAAABABAA',
    'A'),
   [[[25, 17], [25, 18], [25, 7]], 'A', {'A': 1, 'B': 1}]),
  ('variant scenario 2',
   ('AABAAAAABBABABAABAAAABAAABABAAAAABBBBAAABAABBAAABBAAABABAABBABAAAAAAAABAAAAABBBAAABBAAAAAABAAAAAABABAABBAAABBAAAAAAAABAABBBAABABBAABABBAAABBABABAABBAABAAABAAABAABAABBAAABBAABAAABAAAAABBAAAAAABAABAAAAABAABBBAAAAABAABAABA',
    'B'),
   [[[25, 13], [25, 11], [25, 12]], 'A', {'A': 2, 'B': 1}])]]
for label, args, expected in cases[N - 1]:
    check(label, run(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 serving team that keeps winning rallies is shown rotating through positions.

Best-of-five volleyball with rally scoring. rallies is a string of rally winners (A/B). Sets 1-4 are played to 25 and set 5 to 15, always win by two with no cap. The rally winner serves next; when the receiving team wins a rally (side-out) that team rotates once (rotation counter modulo 6). At the start of each set both rotation counters reset to 0 and the first server is first_serve in odd-numbered sets and the other team in even-numbered sets. Return [completed and current set scores as [a, b], match winner or None, rotation counters].

split: open-access


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

N = 1
observations = []
def solve(rallies, first_serve):
    won = {'A': 0, 'B': 0}
    sets = []
    a = b = 0
    set_index = 0
    server = first_serve
    rot = {'A': 0, 'B': 0}
    for r in rallies:
        if r == 'A':
            a += 1
        else:
            b += 1
        if r != server:
            rot[r] = (rot[r] + 1) % 6
            server = r
        target = 15 if set_index == 4 else 25
        if max(a, b) >= target and abs(a - b) >= 2:
            w = 'A' if a > b else 'B'
            won[w] += 1
            sets.append([a, b])
            if won[w] == 3:
                return [sets, w, rot]
            a = b = 0
            set_index += 1
            server = first_serve if set_index % 2 == 0 else ('B' if first_serve == 'A' else 'A')
    return [sets + ([[a, b]] if a or b else []), None, rot]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control first rally held by server', ('A', 'A'), [[[1, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary side-out rotates receiver', ('B', 'A'), [[[0, 1]], None, {'A': 0, 'B': 1}]),
  ('control clean set', ('AAAAAAAAAAAAAAAAAAAAAAAAA', 'A'), [[[25, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary second set served by other team',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAA', 'A'),
   [[[25, 0], [1, 0]], None, {'A': 1, 'B': 0}]),
  ('boundary deuce in set',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABAA', 'A'),
   [[[26, 24]], None, {'A': 0, 'B': 0}]),
  ('control straight-sets match',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', 'B'),
   [[[25, 0], [25, 0], [25, 0]], 'A', {'A': 1, 'B': 0}]),
  ('regression: rotation reset per set',
   ('AABAAABABABBBAABABBAAAABABBBBABABBAABABABAAAABABAB', 'A'),
   [[[25, 20], [2, 3]], None, {'A': 2, 'B': 2}]),
  ('variant scenario 1',
   ('ABBAAAABABAAABBAAABBABABBAAABBAABBBA', 'A'),
   [[[20, 16]], None, {'A': 3, 'B': 3}]),
  ('variant scenario 2',
   ('AAABAABAAAABAABAAABBABBAABBBBBAABAABBABBABB', 'B'),
   [[[23, 20]], None, {'A': 5, 'B': 5}])],
 [('control first rally held by server', ('A', 'A'), [[[1, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary side-out rotates receiver', ('B', 'A'), [[[0, 1]], None, {'A': 0, 'B': 1}]),
  ('control clean set', ('AAAAAAAAAAAAAAAAAAAAAAAAA', 'A'), [[[25, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary second set served by other team',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAA', 'A'),
   [[[25, 0], [1, 0]], None, {'A': 1, 'B': 0}]),
  ('boundary deuce in set',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABAA', 'A'),
   [[[26, 24]], None, {'A': 0, 'B': 0}]),
  ('control straight-sets match',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', 'B'),
   [[[25, 0], [25, 0], [25, 0]], 'A', {'A': 1, 'B': 0}]),
  ('regression: rotation reset per set',
   ('ABAAABAAABABAABAAAAABBBAAAAAABABBAAAABABAABBBBBAABABABAAABAABAAAAABBBAABAAAABAAABBBAB', 'A'),
   [[[25, 11], [25, 17], [3, 4]], None, {'A': 1, 'B': 2}]),
  ('variant scenario 1',
   ('ABAAAAABABBAABABBABAAABAABABABBBABAAAAAAAABAAAAAAABAAABBAABBAAAAA', 'A'),
   [[[25, 15], [19, 6]], None, {'A': 5, 'B': 4}]),
  ('variant scenario 2',
   ('ABABAAAABAABBAABAAAABBABBAABBBABABAABABABABABAABABBAAABBBBBABAAABBBAAABAABBAAAAABAABAAABA',
    'A'),
   [[[25, 19], [25, 18], [1, 1]], None, {'A': 1, 'B': 1}])],
 [('control first rally held by server', ('A', 'A'), [[[1, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary side-out rotates receiver', ('B', 'A'), [[[0, 1]], None, {'A': 0, 'B': 1}]),
  ('control clean set', ('AAAAAAAAAAAAAAAAAAAAAAAAA', 'A'), [[[25, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary second set served by other team',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAA', 'A'),
   [[[25, 0], [1, 0]], None, {'A': 1, 'B': 0}]),
  ('boundary deuce in set',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABAA', 'A'),
   [[[26, 24]], None, {'A': 0, 'B': 0}]),
  ('control straight-sets match',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', 'B'),
   [[[25, 0], [25, 0], [25, 0]], 'A', {'A': 1, 'B': 0}]),
  ('regression: rotation reset per set',
   ('ABBABABBBAAAABABBAAAABAABAAAABAABBAAABABABAAAAABBBBBBBABBAAAABAAAABBBAAABBAAAAABBABAABBAABBBABBBBABABBAABAABBAAAABABBABAABAAAAABBBAAAAAABAAAABBBBAABABAAAABAAAAAAABAAABBAABBABA',
    'B'),
   [[[25, 16], [25, 19], [25, 23]], 'A', {'A': 0, 'B': 5}]),
  ('variant scenario 1',
   ('AAABABAABAAAABBAAAABBAAAAABBABBAABAAABBABABBAAABABBBAAABABABAABBABBABABAABBAAAAABBBBAAABBABABBAABBABABBABAAABAAAABBAABBBA',
    'A'),
   [[[25, 12], [26, 24], [17, 17]], None, {'A': 4, 'B': 4}]),
  ('variant scenario 2',
   ('AABAABBABBBBAAAAABABBABBBBABABABABABABBAAAAAABAAAABAAAAABBAABABAAAAAAAAABAAABBAAAAAAABABAABBABAABABBAABAAABAAAAAAAAAAABABAABBABBABAAB',
    'A'),
   [[[25, 22], [25, 8], [25, 10]], 'A', {'A': 2, 'B': 2}])],
 [('control first rally held by server', ('A', 'A'), [[[1, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary side-out rotates receiver', ('B', 'A'), [[[0, 1]], None, {'A': 0, 'B': 1}]),
  ('control clean set', ('AAAAAAAAAAAAAAAAAAAAAAAAA', 'A'), [[[25, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary second set served by other team',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAA', 'A'),
   [[[25, 0], [1, 0]], None, {'A': 1, 'B': 0}]),
  ('boundary deuce in set',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABAA', 'A'),
   [[[26, 24]], None, {'A': 0, 'B': 0}]),
  ('control straight-sets match',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', 'B'),
   [[[25, 0], [25, 0], [25, 0]], 'A', {'A': 1, 'B': 0}]),
  ('regression: rotation reset per set',
   ('AABAABBAAABAAAAABBABAAAAAAABBABBBAAAAAAAAAABBAAABAABAAAABAABBAAAABAAAABBABAAAAAAAABABBABAAABAAAAAABAAAAAABBBABBAABAAAAAABAAABAAAAAABBAAABAAABBABABABAABBBAAAAAAABABAAAAAAABBAAAABBABAABBBBA',
    'A'),
   [[[25, 12], [25, 8], [25, 9]], 'A', {'A': 1, 'B': 1}]),
  ('variant scenario 1',
   ('AAABAAAAAAABAAABABBBAABAAABABABBAABAABAAAB', 'A'),
   [[[25, 12], [3, 2]], None, {'A': 1, 'B': 1}]),
  ('variant scenario 2',
   ('ABABAAAABAAAAABAAAAABABABBAABAAABAABAABABAABAABBABABAABBAAABBBAAAAAAAAAB', 'A'),
   [[[25, 10], [23, 14]], None, {'A': 3, 'B': 3}])],
 [('control first rally held by server', ('A', 'A'), [[[1, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary side-out rotates receiver', ('B', 'A'), [[[0, 1]], None, {'A': 0, 'B': 1}]),
  ('control clean set', ('AAAAAAAAAAAAAAAAAAAAAAAAA', 'A'), [[[25, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary second set served by other team',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAA', 'A'),
   [[[25, 0], [1, 0]], None, {'A': 1, 'B': 0}]),
  ('boundary deuce in set',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABAA', 'A'),
   [[[26, 24]], None, {'A': 0, 'B': 0}]),
  ('control straight-sets match',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', 'B'),
   [[[25, 0], [25, 0], [25, 0]], 'A', {'A': 1, 'B': 0}]),
  ('regression: rotation reset per set',
   ('ABAABBBBAAAAABABBBBAAABABBBAAAAAAAAAAAAAAAAAAAAAABBAABAAAAAAAAABAAABAAABAAABAABAAAABAAABABBAAAAABAAAAAABBAAAABAAAAAAABABAAAABBAAAABABAABABAAABAAABAAABBBAAAABAABAAAAAABAAAAAAABBAAAABAABAAAAAAAAA',
    'B'),
   [[[25, 14], [25, 5], [25, 8]], 'A', {'A': 2, 'B': 1}]),
  ('variant scenario 1',
   ('AAAAAAAAAABABABBBABABAABAAAAAABBABBAAAABAAABAABAABAAAABAABBAAAABAABAAAAABABAAAAAAABBABAABBABABAABBAAAABABAAAAAABAAAAAAAAABBABBBAAABABA',
    'B'),
   [[[25, 12], [25, 9], [25, 13]], 'A', {'A': 5, 'B': 4}]),
  ('variant scenario 2',
   ('BBAABAABBAAAAABBABAABAAAAABABABAAAABAAAABAAAAAABAAAAAABBBAABABAAAABAAABBAABAABAAABAAABAAABABAABBABAAABAABAAAAAABBABAABAB',
    'B'),
   [[[25, 13], [25, 10], [25, 11]], 'A', {'A': 5, 'B': 4}])]]
for label, args, expected in cases[N - 1]:
    check(label, run(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(rallies, first_serve):
    won = {'A': 0, 'B': 0}
    sets = []
    a = b = 0
    set_index = 0
    server = first_serve
    rot = {'A': 0, 'B': 0}
    for r in rallies:
        if r == 'A':
            a += 1
        else:
            b += 1
        if r != server:
            rot[r] = (rot[r] + 1) % 6
            server = r
        target = 15 if set_index == 4 else 25
        if max(a, b) >= target and abs(a - b) >= 2:
            w = 'A' if a > b else 'B'
            won[w] += 1
            sets.append([a, b])
            if won[w] == 3:
                return [sets, w, rot]
            a = b = 0
            set_index += 1
            rot[w] = 0
            server = first_serve if set_index % 2 == 0 else ('B' if first_serve == 'A' else 'A')
    return [sets + ([[a, b]] if a or b else []), None, rot]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control first rally held by server', ('A', 'A'), [[[1, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary side-out rotates receiver', ('B', 'A'), [[[0, 1]], None, {'A': 0, 'B': 1}]),
  ('control clean set', ('AAAAAAAAAAAAAAAAAAAAAAAAA', 'A'), [[[25, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary second set served by other team',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAA', 'A'),
   [[[25, 0], [1, 0]], None, {'A': 1, 'B': 0}]),
  ('boundary deuce in set',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABAA', 'A'),
   [[[26, 24]], None, {'A': 0, 'B': 0}]),
  ('control straight-sets match',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', 'B'),
   [[[25, 0], [25, 0], [25, 0]], 'A', {'A': 1, 'B': 0}]),
  ('regression: rotation reset per set',
   ('AABAAABABABBBAABABBAAAABABBBBABABBAABABABAAAABABAB', 'A'),
   [[[25, 20], [2, 3]], None, {'A': 2, 'B': 2}]),
  ('variant scenario 1',
   ('ABBAAAABABAAABBAAABBABABBAAABBAABBBA', 'A'),
   [[[20, 16]], None, {'A': 3, 'B': 3}]),
  ('variant scenario 2',
   ('AAABAABAAAABAABAAABBABBAABBBBBAABAABBABBABB', 'B'),
   [[[23, 20]], None, {'A': 5, 'B': 5}])],
 [('control first rally held by server', ('A', 'A'), [[[1, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary side-out rotates receiver', ('B', 'A'), [[[0, 1]], None, {'A': 0, 'B': 1}]),
  ('control clean set', ('AAAAAAAAAAAAAAAAAAAAAAAAA', 'A'), [[[25, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary second set served by other team',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAA', 'A'),
   [[[25, 0], [1, 0]], None, {'A': 1, 'B': 0}]),
  ('boundary deuce in set',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABAA', 'A'),
   [[[26, 24]], None, {'A': 0, 'B': 0}]),
  ('control straight-sets match',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', 'B'),
   [[[25, 0], [25, 0], [25, 0]], 'A', {'A': 1, 'B': 0}]),
  ('regression: rotation reset per set',
   ('ABAAABAAABABAABAAAAABBBAAAAAABABBAAAABABAABBBBBAABABABAAABAABAAAAABBBAABAAAABAAABBBAB', 'A'),
   [[[25, 11], [25, 17], [3, 4]], None, {'A': 1, 'B': 2}]),
  ('variant scenario 1',
   ('ABAAAAABABBAABABBABAAABAABABABBBABAAAAAAAABAAAAAAABAAABBAABBAAAAA', 'A'),
   [[[25, 15], [19, 6]], None, {'A': 5, 'B': 4}]),
  ('variant scenario 2',
   ('ABABAAAABAABBAABAAAABBABBAABBBABABAABABABABABAABABBAAABBBBBABAAABBBAAABAABBAAAAABAABAAABA',
    'A'),
   [[[25, 19], [25, 18], [1, 1]], None, {'A': 1, 'B': 1}])],
 [('control first rally held by server', ('A', 'A'), [[[1, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary side-out rotates receiver', ('B', 'A'), [[[0, 1]], None, {'A': 0, 'B': 1}]),
  ('control clean set', ('AAAAAAAAAAAAAAAAAAAAAAAAA', 'A'), [[[25, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary second set served by other team',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAA', 'A'),
   [[[25, 0], [1, 0]], None, {'A': 1, 'B': 0}]),
  ('boundary deuce in set',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABAA', 'A'),
   [[[26, 24]], None, {'A': 0, 'B': 0}]),
  ('control straight-sets match',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', 'B'),
   [[[25, 0], [25, 0], [25, 0]], 'A', {'A': 1, 'B': 0}]),
  ('regression: rotation reset per set',
   ('ABBABABBBAAAABABBAAAABAABAAAABAABBAAABABABAAAAABBBBBBBABBAAAABAAAABBBAAABBAAAAABBABAABBAABBBABBBBABABBAABAABBAAAABABBABAABAAAAABBBAAAAAABAAAABBBBAABABAAAABAAAAAAABAAABBAABBABA',
    'B'),
   [[[25, 16], [25, 19], [25, 23]], 'A', {'A': 0, 'B': 5}]),
  ('variant scenario 1',
   ('AAABABAABAAAABBAAAABBAAAAABBABBAABAAABBABABBAAABABBBAAABABABAABBABBABABAABBAAAAABBBBAAABBABABBAABBABABBABAAABAAAABBAABBBA',
    'A'),
   [[[25, 12], [26, 24], [17, 17]], None, {'A': 4, 'B': 4}]),
  ('variant scenario 2',
   ('AABAABBABBBBAAAAABABBABBBBABABABABABABBAAAAAABAAAABAAAAABBAABABAAAAAAAAABAAABBAAAAAAABABAABBABAABABBAABAAABAAAAAAAAAAABABAABBABBABAAB',
    'A'),
   [[[25, 22], [25, 8], [25, 10]], 'A', {'A': 2, 'B': 2}])],
 [('control first rally held by server', ('A', 'A'), [[[1, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary side-out rotates receiver', ('B', 'A'), [[[0, 1]], None, {'A': 0, 'B': 1}]),
  ('control clean set', ('AAAAAAAAAAAAAAAAAAAAAAAAA', 'A'), [[[25, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary second set served by other team',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAA', 'A'),
   [[[25, 0], [1, 0]], None, {'A': 1, 'B': 0}]),
  ('boundary deuce in set',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABAA', 'A'),
   [[[26, 24]], None, {'A': 0, 'B': 0}]),
  ('control straight-sets match',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', 'B'),
   [[[25, 0], [25, 0], [25, 0]], 'A', {'A': 1, 'B': 0}]),
  ('regression: rotation reset per set',
   ('AABAABBAAABAAAAABBABAAAAAAABBABBBAAAAAAAAAABBAAABAABAAAABAABBAAAABAAAABBABAAAAAAAABABBABAAABAAAAAABAAAAAABBBABBAABAAAAAABAAABAAAAAABBAAABAAABBABABABAABBBAAAAAAABABAAAAAAABBAAAABBABAABBBBA',
    'A'),
   [[[25, 12], [25, 8], [25, 9]], 'A', {'A': 1, 'B': 1}]),
  ('variant scenario 1',
   ('AAABAAAAAAABAAABABBBAABAAABABABBAABAABAAAB', 'A'),
   [[[25, 12], [3, 2]], None, {'A': 1, 'B': 1}]),
  ('variant scenario 2',
   ('ABABAAAABAAAAABAAAAABABABBAABAAABAABAABABAABAABBABABAABBAAABBBAAAAAAAAAB', 'A'),
   [[[25, 10], [23, 14]], None, {'A': 3, 'B': 3}])],
 [('control first rally held by server', ('A', 'A'), [[[1, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary side-out rotates receiver', ('B', 'A'), [[[0, 1]], None, {'A': 0, 'B': 1}]),
  ('control clean set', ('AAAAAAAAAAAAAAAAAAAAAAAAA', 'A'), [[[25, 0]], None, {'A': 0, 'B': 0}]),
  ('boundary second set served by other team',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAA', 'A'),
   [[[25, 0], [1, 0]], None, {'A': 1, 'B': 0}]),
  ('boundary deuce in set',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABAA', 'A'),
   [[[26, 24]], None, {'A': 0, 'B': 0}]),
  ('control straight-sets match',
   ('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', 'B'),
   [[[25, 0], [25, 0], [25, 0]], 'A', {'A': 1, 'B': 0}]),
  ('regression: rotation reset per set',
   ('ABAABBBBAAAAABABBBBAAABABBBAAAAAAAAAAAAAAAAAAAAAABBAABAAAAAAAAABAAABAAABAAABAABAAAABAAABABBAAAAABAAAAAABBAAAABAAAAAAABABAAAABBAAAABABAABABAAABAAABAAABBBAAAABAABAAAAAABAAAAAAABBAAAABAABAAAAAAAAA',
    'B'),
   [[[25, 14], [25, 5], [25, 8]], 'A', {'A': 2, 'B': 1}]),
  ('variant scenario 1',
   ('AAAAAAAAAABABABBBABABAABAAAAAABBABBAAAABAAABAABAABAAAABAABBAAAABAABAAAAABABAAAAAAABBABAABBABABAABBAAAABABAAAAAABAAAAAAAAABBABBBAAABABA',
    'B'),
   [[[25, 12], [25, 9], [25, 13]], 'A', {'A': 5, 'B': 4}]),
  ('variant scenario 2',
   ('BBAABAABBAAAAABBABAABAAAAABABABAAAABAAAABAAAAAABAAAAAABBBAABABAAAABAAABBAABAABAAABAAABAAABABAABBABAAABAABAAAAAABBABAABAB',
    'B'),
   [[[25, 13], [25, 10], [25, 11]], 'A', {'A': 5, 'B': 4}])]]
for label, args, expected in cases[N - 1]:
    check(label, run(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The rotation counters at the start of set two still reflect set one.

Best-of-five volleyball with rally scoring. rallies is a string of rally winners (A/B). Sets 1-4 are played to 25 and set 5 to 15, always win by two with no cap. The rally winner serves next; when the receiving team wins a rally (side-out) that team rotates once (rotation counter modulo 6). At the start of each set both rotation counters reset to 0 and the first server is first_serve in odd-numbered sets and the other team in even-numbered sets. Return [completed and current set scores as [a, b], match winner or None, rotation counters].

split: open-access