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
            rot = {'A': 0, 'B': 0}
    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: set first server',
   ('AAABAAABABABAAABABABABAAABBBBABAABBBABAABBBAABBAAAABAABAABBA', 'A'),
   [[[25, 20], [9, 6]], None, {'A': 4, 'B': 3}]),
  ('variant scenario 1',
   ('BABBBAABBABABBBABAABAAAAABAABBABABABAABBABBABBAABBAB', 'A'),
   [[[24, 26], [1, 1]], None, {'A': 1, 'B': 1}]),
  ('variant scenario 2',
   ('ABAABAAAAABAABBBBAABBAABBAABABAAAAAABAABBAA', 'B'),
   [[[25, 14], [2, 2]], 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: set first server',
   ('ABAABAAAAAAABABABAABBBAABBAAABBABAAAAABBAAAAAABABABABABBBBAAAABAABBBAAABAAAAAABABAAAA', 'B'),
   [[[25, 13], [25, 15], [5, 2]], None, {'A': 2, 'B': 1}]),
  ('variant scenario 1',
   ('BAAAAABABBAABBABBAAAAABBBBBAABA', 'A'),
   [[[17, 14]], None, {'A': 1, 'B': 1}]),
  ('variant scenario 2',
   ('AAABBAAAABAAAAABBAAAABBBAAAABBAAABBAAAAAABBAABAAAAABBAAABBABBABABABBAAABAAAABAABAABBBBABBAABAAAAABBA',
    'A'),
   [[[25, 12], [25, 14], [13, 11]], None, {'A': 0, 'B': 0}])],
 [('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: set first server',
   ('AAAAAAAAAAAABBAABAAAAABBAABAAAABBAABBAAAAAABAABABBBBABAAABBAABAAAAABAAABABBAAABABBAAAAAABABABAAAABBABAB',
    'B'),
   [[[25, 6], [25, 15], [19, 13]], None, {'A': 3, 'B': 3}]),
  ('variant scenario 1',
   ('ABAABAAAAABAABBABBBAAAAAAABAABBBAAABBABABBBAAABAAAAAABAABBABBAABBAABAAABAABABABAAAAABAAAABAAABABBBBAAABAA',
    'A'),
   [[[25, 15], [25, 16], [16, 8]], None, {'A': 5, 'B': 5}]),
  ('variant scenario 2',
   ('ABABABAAAABAAAAABAAABAABBAAAAABAAABBBBABBAABAAABAABBAAAAABAAABAA', 'A'),
   [[[25, 9], [18, 12]], None, {'A': 1, 'B': 0}])],
 [('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: set first server',
   ('AAABBAAAAAAAABABAAABABAAABABBAABAABBABBBBBABA', 'A'),
   [[[25, 12], [2, 6]], None, {'A': 2, 'B': 1}]),
  ('variant scenario 1',
   ('BAAABAAAAAAABAABBAAAABAAAAAABAAAAAAAAAAABAAABABAAABABABBAAABAAAAABAABBAAABABABBBBAAABAAAABBABAABBABABBBBABAAAAAABBAAAAAAABBABABBAB',
    'A'),
   [[[25, 7], [25, 8], [25, 21]], 'A', {'A': 0, 'B': 0}]),
  ('variant scenario 2',
   ('ABAAAAAAAABBBABAAAAAAABBBBBAAABAAAABBABABAABAABBABBAAAAAABAABAABAA', 'B'),
   [[[25, 13], [18, 10]], None, {'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: set first server',
   ('AAAAAABAABABABAAABBABBAAAAAABAABAAAAABAAAABAAAABABBAABAABBABABAABAABBBABAABABBAABAAAAAAABAA',
    'B'),
   [[[25, 10], [25, 16], [11, 4]], None, {'A': 3, 'B': 2}]),
  ('variant scenario 1',
   ('ABAABAABAAAABAAABBBBAAAAABBABABABAAABBBAAAAABAABBABABABAAABAAAAAAAABAAAAAAAABAAAAAAAABBAAAABABABAABABAABAABAAABBBAAABAAAABAAAAAAABAAAABAABBBBAABBAABAABBAAAABBAABBAAA',
    'A'),
   [[[25, 16], [25, 8], [25, 10]], 'A', {'A': 3, 'B': 3}]),
  ('variant scenario 2',
   ('AAABBAABBBBBAAAAABBAAABBAABAAABAAABAABBAAABAABBBBBBBAABBAAAAABAAAABBAABBAABABBBAAAAAABAABAAAAABBBBBBABAABABAAAAABB',
    'A'),
   [[[25, 16], [25, 19], [16, 13]], None, {'A': 0, '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[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 = w
    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: set first server',
   ('AAABAAABABABAAABABABABAAABBBBABAABBBABAABBBAABBAAAABAABAABBA', 'A'),
   [[[25, 20], [9, 6]], None, {'A': 4, 'B': 3}]),
  ('variant scenario 1',
   ('BABBBAABBABABBBABAABAAAAABAABBABABABAABBABBABBAABBAB', 'A'),
   [[[24, 26], [1, 1]], None, {'A': 1, 'B': 1}]),
  ('variant scenario 2',
   ('ABAABAAAAABAABBBBAABBAABBAABABAAAAAABAABBAA', 'B'),
   [[[25, 14], [2, 2]], 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: set first server',
   ('ABAABAAAAAAABABABAABBBAABBAAABBABAAAAABBAAAAAABABABABABBBBAAAABAABBBAAABAAAAAABABAAAA', 'B'),
   [[[25, 13], [25, 15], [5, 2]], None, {'A': 2, 'B': 1}]),
  ('variant scenario 1',
   ('BAAAAABABBAABBABBAAAAABBBBBAABA', 'A'),
   [[[17, 14]], None, {'A': 1, 'B': 1}]),
  ('variant scenario 2',
   ('AAABBAAAABAAAAABBAAAABBBAAAABBAAABBAAAAAABBAABAAAAABBAAABBABBABABABBAAABAAAABAABAABBBBABBAABAAAAABBA',
    'A'),
   [[[25, 12], [25, 14], [13, 11]], None, {'A': 0, 'B': 0}])],
 [('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: set first server',
   ('AAAAAAAAAAAABBAABAAAAABBAABAAAABBAABBAAAAAABAABABBBBABAAABBAABAAAAABAAABABBAAABABBAAAAAABABABAAAABBABAB',
    'B'),
   [[[25, 6], [25, 15], [19, 13]], None, {'A': 3, 'B': 3}]),
  ('variant scenario 1',
   ('ABAABAAAAABAABBABBBAAAAAAABAABBBAAABBABABBBAAABAAAAAABAABBABBAABBAABAAABAABABABAAAAABAAAABAAABABBBBAAABAA',
    'A'),
   [[[25, 15], [25, 16], [16, 8]], None, {'A': 5, 'B': 5}]),
  ('variant scenario 2',
   ('ABABABAAAABAAAAABAAABAABBAAAAABAAABBBBABBAABAAABAABBAAAAABAAABAA', 'A'),
   [[[25, 9], [18, 12]], None, {'A': 1, 'B': 0}])],
 [('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: set first server',
   ('AAABBAAAAAAAABABAAABABAAABABBAABAABBABBBBBABA', 'A'),
   [[[25, 12], [2, 6]], None, {'A': 2, 'B': 1}]),
  ('variant scenario 1',
   ('BAAABAAAAAAABAABBAAAABAAAAAABAAAAAAAAAAABAAABABAAABABABBAAABAAAAABAABBAAABABABBBBAAABAAAABBABAABBABABBBBABAAAAAABBAAAAAAABBABABBAB',
    'A'),
   [[[25, 7], [25, 8], [25, 21]], 'A', {'A': 0, 'B': 0}]),
  ('variant scenario 2',
   ('ABAAAAAAAABBBABAAAAAAABBBBBAAABAAAABBABABAABAABBABBAAAAAABAABAABAA', 'B'),
   [[[25, 13], [18, 10]], None, {'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: set first server',
   ('AAAAAABAABABABAAABBABBAAAAAABAABAAAAABAAAABAAAABABBAABAABBABABAABAABBBABAABABBAABAAAAAAABAA',
    'B'),
   [[[25, 10], [25, 16], [11, 4]], None, {'A': 3, 'B': 2}]),
  ('variant scenario 1',
   ('ABAABAABAAAABAAABBBBAAAAABBABABABAAABBBAAAAABAABBABABABAAABAAAAAAAABAAAAAAAABAAAAAAAABBAAAABABABAABABAABAABAAABBBAAABAAAABAAAAAAABAAAABAABBBBAABBAABAABBAAAABBAABBAAA',
    'A'),
   [[[25, 16], [25, 8], [25, 10]], 'A', {'A': 3, 'B': 3}]),
  ('variant scenario 2',
   ('AAABBAABBBBBAAAAABBAAABBAABAAABAAABAABBAAABAABBBBBBBAABBAAAAABAAAABBAABBAABABBBAAAAAABAABAAAAABBBBBBABAABABAAAAABB',
    'A'),
   [[[25, 16], [25, 19], [16, 13]], None, {'A': 0, '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:
After a set the team that won the last rally keeps serving instead of the alternating first server.

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) >= 1:
            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: win by two without cap',
   ('ABBBAABAAABAAABAABABBABAABBABBBBAAAABBBABBBAABABBAABAAAAAABBABBABAAAABBAAAABBBBAAABAABBBAB',
    'A'),
   [[[28, 26], [20, 16]], None, {'A': 2, 'B': 2}]),
  ('variant scenario 1',
   ('AABBBAABAABAAAAABAABBABBBBBBAABBBBAAAAAAABABABBBBBABBBBBABAAABABABAAABBABAABABBAAABAABABBAA',
    'B'),
   [[[25, 20], [22, 24]], None, {'A': 1, 'B': 1}]),
  ('variant scenario 2',
   ('AAAABBBBBBABABABABAAAABAABAABBBAAAAABAAABAABBAAABAAABBAAABBABBAAAAA', 'A'),
   [[[25, 17], [16, 9]], None, {'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: win by two without cap',
   ('BAAABBBAAABABABBAABABAAAAABBBBABABBBAAABABBABBBAABAAAAAAAAAAAABBAABAAAA', 'A'),
   [[[27, 25], [16, 3]], None, {'A': 3, 'B': 2}]),
  ('regression: win by two without cap',
   ('BAAAAABAABBABABAABBAAAABAAAABAAAABBAABBABBABAAAAABBBBBBAABBAABAABBAAABBBAAABBBAAAABBAABABAAABABABBAAAAAABABABA',
    'B'),
   [[[25, 12], [28, 26], [12, 7]], None, {'A': 1, 'B': 0}]),
  ('variant scenario 1',
   ('ABAABBBAAAAABAABBAAAABBBAAAABABAABAAAAAAABBAABBAAAAAAABA', 'B'),
   [[[25, 13], [13, 5]], None, {'A': 3, 'B': 3}]),
  ('variant scenario 2',
   ('ABBAABBABBAAABAAAABBABABAAABABBAABBAAABBABAAABABAAABABABAAAAAABBBABBBABBABBAAAABBABAABAABBAAAAABBABBBABAABAAABBABBBBBBABBAABBAAAAABABAAABAAA',
    'A'),
   [[[25, 19], [25, 19], [25, 23]], 'A', {'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: win by two without cap',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABA', 'A'),
   [[[27, 26]], None, {'A': 2, 'B': 2}]),
  ('variant scenario 1',
   ('ABBAABAAAAAAAABBBBABBBBBBAAABBAAAAAAABAABBBBABAABBBAAAAAAAAAAABBABBBBABAAABABABAAAABABBBAAAAABAABABABAAAAAABABBAABBBBAAABABBBBBAAAAB',
    'A'),
   [[[25, 20], [25, 15], [25, 20]], 'A', {'A': 4, 'B': 4}]),
  ('variant scenario 2',
   ('AAAAABAAAAAAABAAAAAABABAABAAAAAAABAAABAAAAABBABABBAABAABABABABBBBABAABAAABAABAAAABABAAAAABBBBBBABAAAAAABABAAAABBAAAA',
    'A'),
   [[[25, 5], [25, 17], [25, 13]], '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: win by two without cap',
   ('ABAAAABBBBBBAAAAABABABABBABBAABAAAABBBAAAABAAAAABAAABAABBAAABAAAAABAAAAAABAABABBABBABAAAAABBBAAABBBAABABAAABBABBBABABABBAAABABBBABAABABA',
    'A'),
   [[[25, 19], [25, 7], [25, 27], [5, 3]], None, {'A': 4, 'B': 3}]),
  ('regression: win by two without cap',
   ('AAAAAABBAABBAAABABABAABAABAAAABBBBBBABBABABBAAAABBAABAAABAAABAAAABBBBAABABABABBAAAAAAABABABAAABBBBBBBAAAABBABBABABBBABAABAAABBAABABAABABAAAABAAAAAABABA',
    'A'),
   [[[25, 20], [25, 14], [28, 26]], 'A', {'A': 3, 'B': 3}]),
  ('variant scenario 1',
   ('ABBBAAABAABBAABAABAABABBABBAAABBBBAABAAABAABBAABBAAABBAABBAB', 'A'),
   [[[25, 21], [7, 7]], None, {'A': 4, 'B': 4}]),
  ('variant scenario 2',
   ('BAAAABBAAABBAAAAAAAAABABABABBBBAAABBABABBBAAABAAABAABABAABAABBBBBBABBBAAAABAAAAAAAABBABABABBBABAAAAABABABABAAABAABABAAAAAAABAABAABAAAAAABABBBABBBBAAAABAAAAAAAABBABABAAAAABABB',
    'A'),
   [[[25, 18], [25, 15], [25, 15]], 'A', {'A': 0, 'B': 0}])],
 [('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: win by two without cap',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABA', 'A'),
   [[[27, 26]], None, {'A': 2, 'B': 2}]),
  ('variant scenario 1',
   ('BAAAAAABABBABABABBABBBABABAAAABABABBBABABBABAABABAAAAAABBBBAAAAAABAAABAABABAAABBBBBABBBBABBBAABABABAAAAABABBBABBAAAABAAAAAABBBAAABABAABABAAAABAAAABBABAAAAAAAAAABBABBAAABBAAABBAAABAAAAABABAAAAAABBABAABAABBABAAAA',
    'A'),
   [[[25, 23], [25, 21], [25, 15]], 'A', {'A': 4, 'B': 4}]),
  ('variant scenario 2',
   ('ABAAAAAAABAABAAABABAAABAAAAABBAAABAABBBBAAABAABAAAABAABBABABABAAAAAAAAAABAAAABAAABBBAABBAABAAAAAABAAAAAABAAAABABBBAAAABBAAABAAABAAAABBBABAAAABABBBAAB',
    'B'),
   [[[25, 8], [25, 13], [25, 10]], '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)

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(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 or max(a, b) >= target + 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: win by two without cap',
   ('ABBBAABAAABAAABAABABBABAABBABBBBAAAABBBABBBAABABBAABAAAAAABBABBABAAAABBAAAABBBBAAABAABBBAB',
    'A'),
   [[[28, 26], [20, 16]], None, {'A': 2, 'B': 2}]),
  ('variant scenario 1',
   ('AABBBAABAABAAAAABAABBABBBBBBAABBBBAAAAAAABABABBBBBABBBBBABAAABABABAAABBABAABABBAAABAABABBAA',
    'B'),
   [[[25, 20], [22, 24]], None, {'A': 1, 'B': 1}]),
  ('variant scenario 2',
   ('AAAABBBBBBABABABABAAAABAABAABBBAAAAABAAABAABBAAABAAABBAAABBABBAAAAA', 'A'),
   [[[25, 17], [16, 9]], None, {'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: win by two without cap',
   ('BAAABBBAAABABABBAABABAAAAABBBBABABBBAAABABBABBBAABAAAAAAAAAAAABBAABAAAA', 'A'),
   [[[27, 25], [16, 3]], None, {'A': 3, 'B': 2}]),
  ('regression: win by two without cap',
   ('BAAAAABAABBABABAABBAAAABAAAABAAAABBAABBABBABAAAAABBBBBBAABBAABAABBAAABBBAAABBBAAAABBAABABAAABABABBAAAAAABABABA',
    'B'),
   [[[25, 12], [28, 26], [12, 7]], None, {'A': 1, 'B': 0}]),
  ('variant scenario 1',
   ('ABAABBBAAAAABAABBAAAABBBAAAABABAABAAAAAAABBAABBAAAAAAABA', 'B'),
   [[[25, 13], [13, 5]], None, {'A': 3, 'B': 3}]),
  ('variant scenario 2',
   ('ABBAABBABBAAABAAAABBABABAAABABBAABBAAABBABAAABABAAABABABAAAAAABBBABBBABBABBAAAABBABAABAABBAAAAABBABBBABAABAAABBABBBBBBABBAABBAAAAABABAAABAAA',
    'A'),
   [[[25, 19], [25, 19], [25, 23]], 'A', {'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: win by two without cap',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABA', 'A'),
   [[[27, 26]], None, {'A': 2, 'B': 2}]),
  ('variant scenario 1',
   ('ABBAABAAAAAAAABBBBABBBBBBAAABBAAAAAAABAABBBBABAABBBAAAAAAAAAAABBABBBBABAAABABABAAAABABBBAAAAABAABABABAAAAAABABBAABBBBAAABABBBBBAAAAB',
    'A'),
   [[[25, 20], [25, 15], [25, 20]], 'A', {'A': 4, 'B': 4}]),
  ('variant scenario 2',
   ('AAAAABAAAAAAABAAAAAABABAABAAAAAAABAAABAAAAABBABABBAABAABABABABBBBABAABAAABAABAAAABABAAAAABBBBBBABAAAAAABABAAAABBAAAA',
    'A'),
   [[[25, 5], [25, 17], [25, 13]], '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: win by two without cap',
   ('ABAAAABBBBBBAAAAABABABABBABBAABAAAABBBAAAABAAAAABAAABAABBAAABAAAAABAAAAAABAABABBABBABAAAAABBBAAABBBAABABAAABBABBBABABABBAAABABBBABAABABA',
    'A'),
   [[[25, 19], [25, 7], [25, 27], [5, 3]], None, {'A': 4, 'B': 3}]),
  ('regression: win by two without cap',
   ('AAAAAABBAABBAAABABABAABAABAAAABBBBBBABBABABBAAAABBAABAAABAAABAAAABBBBAABABABABBAAAAAAABABABAAABBBBBBBAAAABBABBABABBBABAABAAABBAABABAABABAAAABAAAAAABABA',
    'A'),
   [[[25, 20], [25, 14], [28, 26]], 'A', {'A': 3, 'B': 3}]),
  ('variant scenario 1',
   ('ABBBAAABAABBAABAABAABABBABBAAABBBBAABAAABAABBAABBAAABBAABBAB', 'A'),
   [[[25, 21], [7, 7]], None, {'A': 4, 'B': 4}]),
  ('variant scenario 2',
   ('BAAAABBAAABBAAAAAAAAABABABABBBBAAABBABABBBAAABAAABAABABAABAABBBBBBABBBAAAABAAAAAAAABBABABABBBABAAAAABABABABAAABAABABAAAAAAABAABAABAAAAAABABBBABBBBAAAABAAAAAAAABBABABAAAAABABB',
    'A'),
   [[[25, 18], [25, 15], [25, 15]], 'A', {'A': 0, 'B': 0}])],
 [('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: win by two without cap',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABA', 'A'),
   [[[27, 26]], None, {'A': 2, 'B': 2}]),
  ('variant scenario 1',
   ('BAAAAAABABBABABABBABBBABABAAAABABABBBABABBABAABABAAAAAABBBBAAAAAABAAABAABABAAABBBBBABBBBABBBAABABABAAAAABABBBABBAAAABAAAAAABBBAAABABAABABAAAABAAAABBABAAAAAAAAAABBABBAAABBAAABBAAABAAAAABABAAAAAABBABAABAABBABAAAA',
    'A'),
   [[[25, 23], [25, 21], [25, 15]], 'A', {'A': 4, 'B': 4}]),
  ('variant scenario 2',
   ('ABAAAAAAABAABAAABABAAABAAAAABBAAABAABBBBAAABAABAAAABAABBABABABAAAAAAAAAABAAAABAAABBBAABBAABAAAAAABAAAAAABAAAABABBBAAAABBAAABAAABAAAABBBABAAAABABBBAAB',
    'B'),
   [[[25, 8], [25, 13], [25, 10]], '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 set is closed at 25-24 or at a 27-26 cap instead of continuing until a two-point lead.

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_server):
    a = b = 0
    server = first_server
    for r in rallies:
        if r == 'A':
            a += 1
        else:
            b += 1
        server = r
        if (max(a, b) >= 21 and abs(a - b) >= 2):
            return [a, b, r, None, None]
    own = a if server == 'A' else b
    return [a, b, None, server, 'right' if own % 2 == 0 else 'left']
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 opening serve', ('', 'B'), [0, 0, None, 'B', 'right']),
  ('control server wins odd point', ('A', 'A'), [1, 0, None, 'A', 'left']),
  ('boundary receiver wins rally', ('AB', 'A'), [1, 1, None, 'B', 'left']),
  ('boundary game at 21-19',
   ('AAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBAA', 'A'),
   [21, 19, 'A', None, None]),
  ('boundary cap at 30',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABB', 'A'),
   [29, 30, 'B', None, None]),
  ('control 20-all continues',
   ('ABABABABABABABABABABABABABABABABABABABAB', 'A'),
   [20, 20, None, 'B', 'right']),
  ('regression: thirty point cap',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABB', 'A'),
   [28, 29, None, 'B', 'left']),
  ('regression: thirty point cap',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAA', 'B'),
   [30, 29, 'A', None, None]),
  ('variant scenario 1', ('BABBBABBABBBABBABBABAABABBBBBBABBBB', 'B'), [9, 21, 'B', None, None]),
  ('variant scenario 2', ('BBABAABABABBBBBAAABBABBBABBA', 'A'), [11, 17, None, 'A', 'left'])],
 [('control opening serve', ('', 'B'), [0, 0, None, 'B', 'right']),
  ('control server wins odd point', ('A', 'A'), [1, 0, None, 'A', 'left']),
  ('boundary receiver wins rally', ('AB', 'A'), [1, 1, None, 'B', 'left']),
  ('boundary game at 21-19',
   ('AAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBAA', 'A'),
   [21, 19, 'A', None, None]),
  ('boundary cap at 30',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABB', 'A'),
   [29, 30, 'B', None, None]),
  ('control 20-all continues',
   ('ABABABABABABABABABABABABABABABABABABABAB', 'A'),
   [20, 20, None, 'B', 'right']),
  ('regression: thirty point cap',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABBAA', 'A'),
   [29, 28, None, 'A', 'left']),
  ('regression: thirty point cap',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA', 'A'),
   [30, 29, 'A', None, None]),
  ('variant scenario 1',
   ('BAAABBBABABBABBABAAAAABBBBABAABBBBABBBBABBABBABA', 'B'),
   [16, 21, 'B', None, None]),
  ('variant scenario 2', ('BBAABABAAABBBB', 'A'), [6, 8, None, 'B', 'right'])],
 [('control opening serve', ('', 'B'), [0, 0, None, 'B', 'right']),
  ('control server wins odd point', ('A', 'A'), [1, 0, None, 'A', 'left']),
  ('boundary receiver wins rally', ('AB', 'A'), [1, 1, None, 'B', 'left']),
  ('boundary game at 21-19',
   ('AAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBAA', 'A'),
   [21, 19, 'A', None, None]),
  ('boundary cap at 30',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABB', 'A'),
   [29, 30, 'B', None, None]),
  ('control 20-all continues',
   ('ABABABABABABABABABABABABABABABABABABABAB', 'A'),
   [20, 20, None, 'B', 'right']),
  ('regression: thirty point cap',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABA', 'A'),
   [29, 28, None, 'A', 'left']),
  ('regression: thirty point cap',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABB', 'B'),
   [29, 30, 'B', None, None]),
  ('variant scenario 1', ('BBAABAAA', 'A'), [5, 3, None, 'A', 'left']),
  ('variant scenario 2', ('BAABABBAAAAABBAABABABBBBBABAA', 'A'), [15, 14, None, 'A', 'left'])],
 [('control opening serve', ('', 'B'), [0, 0, None, 'B', 'right']),
  ('control server wins odd point', ('A', 'A'), [1, 0, None, 'A', 'left']),
  ('boundary receiver wins rally', ('AB', 'A'), [1, 1, None, 'B', 'left']),
  ('boundary game at 21-19',
   ('AAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBAA', 'A'),
   [21, 19, 'A', None, None]),
  ('boundary cap at 30',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABB', 'A'),
   [29, 30, 'B', None, None]),
  ('control 20-all continues',
   ('ABABABABABABABABABABABABABABABABABABABAB', 'A'),
   [20, 20, None, 'B', 'right']),
  ('regression: thirty point cap',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABAAB', 'B'),
   [30, 28, 'A', None, None]),
  ('regression: thirty point cap',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABBAA', 'B'),
   [30, 29, 'A', None, None]),
  ('variant scenario 1',
   ('ABABABABBBABBABBBAAAAAABABABAABAABBABAAABAAAAABABBBBABAAAABBABABB', 'A'),
   [21, 18, 'A', None, None]),
  ('variant scenario 2',
   ('ABABABABABABABABABABABABABABABABABABABBAA', 'B'),
   [21, 20, None, 'A', 'left'])],
 [('control opening serve', ('', 'B'), [0, 0, None, 'B', 'right']),
  ('control server wins odd point', ('A', 'A'), [1, 0, None, 'A', 'left']),
  ('boundary receiver wins rally', ('AB', 'A'), [1, 1, None, 'B', 'left']),
  ('boundary game at 21-19',
   ('AAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBAA', 'A'),
   [21, 19, 'A', None, None]),
  ('boundary cap at 30',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABB', 'A'),
   [29, 30, 'B', None, None]),
  ('control 20-all continues',
   ('ABABABABABABABABABABABABABABABABABABABAB', 'A'),
   [20, 20, None, 'B', 'right']),
  ('regression: thirty point cap',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA', 'B'),
   [30, 29, 'A', None, None]),
  ('variant scenario 1',
   ('AAAAABBBAAABBBAAAABBBBABBBBABABBBBAABBBBABBBABBBBAAABBBBABABBAAABAABABAABBBABB', 'A'),
   [17, 21, 'B', None, None]),
  ('variant scenario 2',
   ('BAABABBAABABABBBABABBABBABBABBBBBAABABBBBBBABBABBBABABBBABABAABBBA', 'A'),
   [12, 21, 'B', None, 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)

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

N = 1
observations = []
def solve(rallies, first_server):
    a = b = 0
    server = first_server
    for r in rallies:
        if r == 'A':
            a += 1
        else:
            b += 1
        server = r
        if (max(a, b) >= 21 and abs(a - b) >= 2) or max(a, b) == 29:
            return [a, b, r, None, None]
    own = a if server == 'A' else b
    return [a, b, None, server, 'right' if own % 2 == 0 else 'left']
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 opening serve', ('', 'B'), [0, 0, None, 'B', 'right']),
  ('control server wins odd point', ('A', 'A'), [1, 0, None, 'A', 'left']),
  ('boundary receiver wins rally', ('AB', 'A'), [1, 1, None, 'B', 'left']),
  ('boundary game at 21-19',
   ('AAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBAA', 'A'),
   [21, 19, 'A', None, None]),
  ('boundary cap at 30',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABB', 'A'),
   [29, 30, 'B', None, None]),
  ('control 20-all continues',
   ('ABABABABABABABABABABABABABABABABABABABAB', 'A'),
   [20, 20, None, 'B', 'right']),
  ('regression: thirty point cap',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABB', 'A'),
   [28, 29, None, 'B', 'left']),
  ('regression: thirty point cap',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAA', 'B'),
   [30, 29, 'A', None, None]),
  ('variant scenario 1', ('BABBBABBABBBABBABBABAABABBBBBBABBBB', 'B'), [9, 21, 'B', None, None]),
  ('variant scenario 2', ('BBABAABABABBBBBAAABBABBBABBA', 'A'), [11, 17, None, 'A', 'left'])],
 [('control opening serve', ('', 'B'), [0, 0, None, 'B', 'right']),
  ('control server wins odd point', ('A', 'A'), [1, 0, None, 'A', 'left']),
  ('boundary receiver wins rally', ('AB', 'A'), [1, 1, None, 'B', 'left']),
  ('boundary game at 21-19',
   ('AAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBAA', 'A'),
   [21, 19, 'A', None, None]),
  ('boundary cap at 30',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABB', 'A'),
   [29, 30, 'B', None, None]),
  ('control 20-all continues',
   ('ABABABABABABABABABABABABABABABABABABABAB', 'A'),
   [20, 20, None, 'B', 'right']),
  ('regression: thirty point cap',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABBAA', 'A'),
   [29, 28, None, 'A', 'left']),
  ('regression: thirty point cap',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA', 'A'),
   [30, 29, 'A', None, None]),
  ('variant scenario 1',
   ('BAAABBBABABBABBABAAAAABBBBABAABBBBABBBBABBABBABA', 'B'),
   [16, 21, 'B', None, None]),
  ('variant scenario 2', ('BBAABABAAABBBB', 'A'), [6, 8, None, 'B', 'right'])],
 [('control opening serve', ('', 'B'), [0, 0, None, 'B', 'right']),
  ('control server wins odd point', ('A', 'A'), [1, 0, None, 'A', 'left']),
  ('boundary receiver wins rally', ('AB', 'A'), [1, 1, None, 'B', 'left']),
  ('boundary game at 21-19',
   ('AAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBAA', 'A'),
   [21, 19, 'A', None, None]),
  ('boundary cap at 30',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABB', 'A'),
   [29, 30, 'B', None, None]),
  ('control 20-all continues',
   ('ABABABABABABABABABABABABABABABABABABABAB', 'A'),
   [20, 20, None, 'B', 'right']),
  ('regression: thirty point cap',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABA', 'A'),
   [29, 28, None, 'A', 'left']),
  ('regression: thirty point cap',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABB', 'B'),
   [29, 30, 'B', None, None]),
  ('variant scenario 1', ('BBAABAAA', 'A'), [5, 3, None, 'A', 'left']),
  ('variant scenario 2', ('BAABABBAAAAABBAABABABBBBBABAA', 'A'), [15, 14, None, 'A', 'left'])],
 [('control opening serve', ('', 'B'), [0, 0, None, 'B', 'right']),
  ('control server wins odd point', ('A', 'A'), [1, 0, None, 'A', 'left']),
  ('boundary receiver wins rally', ('AB', 'A'), [1, 1, None, 'B', 'left']),
  ('boundary game at 21-19',
   ('AAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBAA', 'A'),
   [21, 19, 'A', None, None]),
  ('boundary cap at 30',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABB', 'A'),
   [29, 30, 'B', None, None]),
  ('control 20-all continues',
   ('ABABABABABABABABABABABABABABABABABABABAB', 'A'),
   [20, 20, None, 'B', 'right']),
  ('regression: thirty point cap',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABAAB', 'B'),
   [30, 28, 'A', None, None]),
  ('regression: thirty point cap',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABBAA', 'B'),
   [30, 29, 'A', None, None]),
  ('variant scenario 1',
   ('ABABABABBBABBABBBAAAAAABABABAABAABBABAAABAAAAABABBBBABAAAABBABABB', 'A'),
   [21, 18, 'A', None, None]),
  ('variant scenario 2',
   ('ABABABABABABABABABABABABABABABABABABABBAA', 'B'),
   [21, 20, None, 'A', 'left'])],
 [('control opening serve', ('', 'B'), [0, 0, None, 'B', 'right']),
  ('control server wins odd point', ('A', 'A'), [1, 0, None, 'A', 'left']),
  ('boundary receiver wins rally', ('AB', 'A'), [1, 1, None, 'B', 'left']),
  ('boundary game at 21-19',
   ('AAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBAA', 'A'),
   [21, 19, 'A', None, None]),
  ('boundary cap at 30',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABB', 'A'),
   [29, 30, 'B', None, None]),
  ('control 20-all continues',
   ('ABABABABABABABABABABABABABABABABABABABAB', 'A'),
   [20, 20, None, 'B', 'right']),
  ('regression: thirty point cap',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA', 'B'),
   [30, 29, 'A', None, None]),
  ('variant scenario 1',
   ('AAAAABBBAAABBBAAAABBBBABBBBABABBBBAABBBBABBBABBBBAAABBBBABABBAAABAABABAABBBABB', 'A'),
   [17, 21, 'B', None, None]),
  ('variant scenario 2',
   ('BAABABBAABABABBBABABBABBABBABBBBBAABABBBBBBABBABBBABABBBABABAABBBA', 'A'),
   [12, 21, 'B', None, 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:
At 29-29 the next rally does not end the game.

One badminton singles game. rallies is a string of rally winners (A/B). A game is won at 21 points with a two-point lead, or by the first player to 30 points (29-29 next point wins). The rally winner serves next. The server serves from the right court when the server's own score is even and from the left court when odd. Return [a, b, winner, None, None] when finished (later rallies ignored) or [a, b, None, next server, "right"/"left"].

split: open-access


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

N = 1
observations = []
def solve(rallies, first_server):
    a = b = 0
    server = first_server
    for r in rallies:
        if r == 'A':
            a += 1
        else:
            b += 1
        server = r
        if (max(a, b) >= 21 and abs(a - b) >= 2) or max(a, b) == 30:
            return [a, b, r, None, None]
    own = a + b
    return [a, b, None, server, 'right' if own % 2 == 0 else 'left']
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 opening serve', ('', 'B'), [0, 0, None, 'B', 'right']),
  ('control server wins odd point', ('A', 'A'), [1, 0, None, 'A', 'left']),
  ('boundary receiver wins rally', ('AB', 'A'), [1, 1, None, 'B', 'left']),
  ('boundary game at 21-19',
   ('AAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBAA', 'A'),
   [21, 19, 'A', None, None]),
  ('boundary cap at 30',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABB', 'A'),
   [29, 30, 'B', None, None]),
  ('control 20-all continues',
   ('ABABABABABABABABABABABABABABABABABABABAB', 'A'),
   [20, 20, None, 'B', 'right']),
  ('regression: service court parity', ('BABBAABBB', 'B'), [3, 6, None, 'B', 'right']),
  ('regression: service court parity',
   ('BABABABABBAAABABABAABBBAA', 'B'),
   [13, 12, None, 'A', 'left']),
  ('variant scenario 1',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABBB', 'A'),
   [26, 28, 'B', None, None]),
  ('variant scenario 2', ('AAABBBBBABBBAAABABABBBBBBABBBBBAAAB', 'A'), [10, 21, 'B', None, None])],
 [('control opening serve', ('', 'B'), [0, 0, None, 'B', 'right']),
  ('control server wins odd point', ('A', 'A'), [1, 0, None, 'A', 'left']),
  ('boundary receiver wins rally', ('AB', 'A'), [1, 1, None, 'B', 'left']),
  ('boundary game at 21-19',
   ('AAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBAA', 'A'),
   [21, 19, 'A', None, None]),
  ('boundary cap at 30',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABB', 'A'),
   [29, 30, 'B', None, None]),
  ('control 20-all continues',
   ('ABABABABABABABABABABABABABABABABABABABAB', 'A'),
   [20, 20, None, 'B', 'right']),
  ('regression: service court parity', ('AAABBBABAAA', 'B'), [7, 4, None, 'A', 'left']),
  ('regression: service court parity', ('BBAAABABABBB', 'A'), [5, 7, None, 'B', 'left']),
  ('variant scenario 1',
   ('ABABABABABABABABABABABABABABABABABABABABABABAA', 'A'),
   [24, 22, 'A', None, None]),
  ('variant scenario 2',
   ('AAABBBBAAAAABBBABBAAAAAABABBBABABBABBBBBABBAABA', 'B'),
   [19, 21, 'B', None, None])],
 [('control opening serve', ('', 'B'), [0, 0, None, 'B', 'right']),
  ('control server wins odd point', ('A', 'A'), [1, 0, None, 'A', 'left']),
  ('boundary receiver wins rally', ('AB', 'A'), [1, 1, None, 'B', 'left']),
  ('boundary game at 21-19',
   ('AAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBAA', 'A'),
   [21, 19, 'A', None, None]),
  ('boundary cap at 30',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABB', 'A'),
   [29, 30, 'B', None, None]),
  ('control 20-all continues',
   ('ABABABABABABABABABABABABABABABABABABABAB', 'A'),
   [20, 20, None, 'B', 'right']),
  ('regression: service court parity',
   ('BBBAAAAAAAAABAABBBBAABBBABBAAA', 'B'),
   [17, 13, None, 'A', 'left']),
  ('regression: service court parity',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABBAB', 'A'),
   [27, 28, None, 'B', 'right']),
  ('variant scenario 1', ('BBAABAABABABBAAAABAABBBB', 'A'), [12, 12, None, 'B', 'right']),
  ('variant scenario 2', ('BBABABAAAAAABAAAAAABABAAAABAABAA', 'A'), [21, 8, 'A', None, None])],
 [('control opening serve', ('', 'B'), [0, 0, None, 'B', 'right']),
  ('control server wins odd point', ('A', 'A'), [1, 0, None, 'A', 'left']),
  ('boundary receiver wins rally', ('AB', 'A'), [1, 1, None, 'B', 'left']),
  ('boundary game at 21-19',
   ('AAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBAA', 'A'),
   [21, 19, 'A', None, None]),
  ('boundary cap at 30',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABB', 'A'),
   [29, 30, 'B', None, None]),
  ('control 20-all continues',
   ('ABABABABABABABABABABABABABABABABABABABAB', 'A'),
   [20, 20, None, 'B', 'right']),
  ('regression: service court parity',
   ('ABAAABAAABBAABBAAABBABBAA', 'B'),
   [15, 10, None, 'A', 'left']),
  ('regression: service court parity',
   ('ABABABABABABABABABABABABABABABABABABABB', 'B'),
   [19, 20, None, 'B', 'right']),
  ('variant scenario 1',
   ('ABAAABABBAABBBBABAAABAABABBBAAAABBAABBBBAAABBAA', 'A'),
   [22, 20, 'A', None, None]),
  ('variant scenario 2',
   ('ABBABBBAABABBBBBBBBAABABABAAABBBBAABABBABABBAB', 'A'),
   [12, 21, 'B', None, None])],
 [('control opening serve', ('', 'B'), [0, 0, None, 'B', 'right']),
  ('control server wins odd point', ('A', 'A'), [1, 0, None, 'A', 'left']),
  ('boundary receiver wins rally', ('AB', 'A'), [1, 1, None, 'B', 'left']),
  ('boundary game at 21-19',
   ('AAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBAA', 'A'),
   [21, 19, 'A', None, None]),
  ('boundary cap at 30',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABB', 'A'),
   [29, 30, 'B', None, None]),
  ('control 20-all continues',
   ('ABABABABABABABABABABABABABABABABABABABAB', 'A'),
   [20, 20, None, 'B', 'right']),
  ('regression: service court parity', ('AAABABBBBBABAABAAB', 'B'), [9, 9, None, 'B', 'left']),
  ('regression: service court parity',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABB', 'A'),
   [26, 27, None, 'B', 'left']),
  ('variant scenario 1',
   ('BABBBAABBAABBAABAAAAABBBBBABBBBBABAABBABABBBABBBBABAABAABAABAABAAAAAAAABABBBAB', 'B'),
   [16, 21, 'B', None, None]),
  ('variant scenario 2',
   ('BAAABABBAAABABAAABABABABAABABABBABBAABABABBBBAAAABBB', 'B'),
   [21, 16, 'A', None, 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)

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

N = 1
observations = []
def solve(rallies, first_server):
    a = b = 0
    server = first_server
    for r in rallies:
        if r == 'A':
            a += 1
        else:
            b += 1
        server = r
        if (max(a, b) >= 21 and abs(a - b) >= 2) or max(a, b) == 30:
            return [a, b, r, None, None]
    own = a if first_server == 'A' else b
    return [a, b, None, server, 'right' if own % 2 == 0 else 'left']
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 opening serve', ('', 'B'), [0, 0, None, 'B', 'right']),
  ('control server wins odd point', ('A', 'A'), [1, 0, None, 'A', 'left']),
  ('boundary receiver wins rally', ('AB', 'A'), [1, 1, None, 'B', 'left']),
  ('boundary game at 21-19',
   ('AAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBAA', 'A'),
   [21, 19, 'A', None, None]),
  ('boundary cap at 30',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABB', 'A'),
   [29, 30, 'B', None, None]),
  ('control 20-all continues',
   ('ABABABABABABABABABABABABABABABABABABABAB', 'A'),
   [20, 20, None, 'B', 'right']),
  ('regression: service court parity', ('BABBAABBB', 'B'), [3, 6, None, 'B', 'right']),
  ('regression: service court parity',
   ('BABABABABBAAABABABAABBBAA', 'B'),
   [13, 12, None, 'A', 'left']),
  ('variant scenario 1',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABBB', 'A'),
   [26, 28, 'B', None, None]),
  ('variant scenario 2', ('AAABBBBBABBBAAABABABBBBBBABBBBBAAAB', 'A'), [10, 21, 'B', None, None])],
 [('control opening serve', ('', 'B'), [0, 0, None, 'B', 'right']),
  ('control server wins odd point', ('A', 'A'), [1, 0, None, 'A', 'left']),
  ('boundary receiver wins rally', ('AB', 'A'), [1, 1, None, 'B', 'left']),
  ('boundary game at 21-19',
   ('AAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBAA', 'A'),
   [21, 19, 'A', None, None]),
  ('boundary cap at 30',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABB', 'A'),
   [29, 30, 'B', None, None]),
  ('control 20-all continues',
   ('ABABABABABABABABABABABABABABABABABABABAB', 'A'),
   [20, 20, None, 'B', 'right']),
  ('regression: service court parity', ('AAABBBABAAA', 'B'), [7, 4, None, 'A', 'left']),
  ('regression: service court parity', ('BBAAABABABBB', 'A'), [5, 7, None, 'B', 'left']),
  ('variant scenario 1',
   ('ABABABABABABABABABABABABABABABABABABABABABABAA', 'A'),
   [24, 22, 'A', None, None]),
  ('variant scenario 2',
   ('AAABBBBAAAAABBBABBAAAAAABABBBABABBABBBBBABBAABA', 'B'),
   [19, 21, 'B', None, None])],
 [('control opening serve', ('', 'B'), [0, 0, None, 'B', 'right']),
  ('control server wins odd point', ('A', 'A'), [1, 0, None, 'A', 'left']),
  ('boundary receiver wins rally', ('AB', 'A'), [1, 1, None, 'B', 'left']),
  ('boundary game at 21-19',
   ('AAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBAA', 'A'),
   [21, 19, 'A', None, None]),
  ('boundary cap at 30',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABB', 'A'),
   [29, 30, 'B', None, None]),
  ('control 20-all continues',
   ('ABABABABABABABABABABABABABABABABABABABAB', 'A'),
   [20, 20, None, 'B', 'right']),
  ('regression: service court parity',
   ('BBBAAAAAAAAABAABBBBAABBBABBAAA', 'B'),
   [17, 13, None, 'A', 'left']),
  ('regression: service court parity',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABBAB', 'A'),
   [27, 28, None, 'B', 'right']),
  ('variant scenario 1', ('BBAABAABABABBAAAABAABBBB', 'A'), [12, 12, None, 'B', 'right']),
  ('variant scenario 2', ('BBABABAAAAAABAAAAAABABAAAABAABAA', 'A'), [21, 8, 'A', None, None])],
 [('control opening serve', ('', 'B'), [0, 0, None, 'B', 'right']),
  ('control server wins odd point', ('A', 'A'), [1, 0, None, 'A', 'left']),
  ('boundary receiver wins rally', ('AB', 'A'), [1, 1, None, 'B', 'left']),
  ('boundary game at 21-19',
   ('AAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBAA', 'A'),
   [21, 19, 'A', None, None]),
  ('boundary cap at 30',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABB', 'A'),
   [29, 30, 'B', None, None]),
  ('control 20-all continues',
   ('ABABABABABABABABABABABABABABABABABABABAB', 'A'),
   [20, 20, None, 'B', 'right']),
  ('regression: service court parity',
   ('ABAAABAAABBAABBAAABBABBAA', 'B'),
   [15, 10, None, 'A', 'left']),
  ('regression: service court parity',
   ('ABABABABABABABABABABABABABABABABABABABB', 'B'),
   [19, 20, None, 'B', 'right']),
  ('variant scenario 1',
   ('ABAAABABBAABBBBABAAABAABABBBAAAABBAABBBBAAABBAA', 'A'),
   [22, 20, 'A', None, None]),
  ('variant scenario 2',
   ('ABBABBBAABABBBBBBBBAABABABAAABBBBAABABBABABBAB', 'A'),
   [12, 21, 'B', None, None])],
 [('control opening serve', ('', 'B'), [0, 0, None, 'B', 'right']),
  ('control server wins odd point', ('A', 'A'), [1, 0, None, 'A', 'left']),
  ('boundary receiver wins rally', ('AB', 'A'), [1, 1, None, 'B', 'left']),
  ('boundary game at 21-19',
   ('AAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBAA', 'A'),
   [21, 19, 'A', None, None]),
  ('boundary cap at 30',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABB', 'A'),
   [29, 30, 'B', None, None]),
  ('control 20-all continues',
   ('ABABABABABABABABABABABABABABABABABABABAB', 'A'),
   [20, 20, None, 'B', 'right']),
  ('regression: service court parity', ('AAABABBBBBABAABAAB', 'B'), [9, 9, None, 'B', 'left']),
  ('regression: service court parity',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABB', 'A'),
   [26, 27, None, 'B', 'left']),
  ('variant scenario 1',
   ('BABBBAABBAABBAABAAAAABBBBBABBBBBABAABBABABBBABBBBABAABAABAABAABAAAAAAAABABBBAB', 'B'),
   [16, 21, 'B', None, None]),
  ('variant scenario 2',
   ('BAAABABBAAABABAAABABABABAABABABBABBAABABABBBBAAAABBB', 'B'),
   [21, 16, 'A', None, 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:
The server is sent to the wrong court when the scores have different parity.

One badminton singles game. rallies is a string of rally winners (A/B). A game is won at 21 points with a two-point lead, or by the first player to 30 points (29-29 next point wins). The rally winner serves next. The server serves from the right court when the server's own score is even and from the left court when odd. Return [a, b, winner, None, None] when finished (later rallies ignored) or [a, b, None, next server, "right"/"left"].

split: open-access


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

N = 1
observations = []
def solve(rallies, first_server):
    a = b = 0
    server = first_server
    for r in rallies:
        if r == 'A':
            a += 1
        else:
            b += 1
        if (max(a, b) >= 21 and abs(a - b) >= 2) or max(a, b) == 30:
            return [a, b, r, None, None]
    own = a if server == 'A' else b
    return [a, b, None, server, 'right' if own % 2 == 0 else 'left']
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 opening serve', ('', 'B'), [0, 0, None, 'B', 'right']),
  ('control server wins odd point', ('A', 'A'), [1, 0, None, 'A', 'left']),
  ('boundary receiver wins rally', ('AB', 'A'), [1, 1, None, 'B', 'left']),
  ('boundary game at 21-19',
   ('AAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBAA', 'A'),
   [21, 19, 'A', None, None]),
  ('boundary cap at 30',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABB', 'A'),
   [29, 30, 'B', None, None]),
  ('control 20-all continues',
   ('ABABABABABABABABABABABABABABABABABABABAB', 'A'),
   [20, 20, None, 'B', 'right']),
  ('regression: serve follows rally', ('BBBBAABAABABBBBAA', 'A'), [7, 10, None, 'A', 'left']),
  ('regression: serve follows rally',
   ('ABABABABABABABABABABABABABABABABABABAB', 'A'),
   [19, 19, None, 'B', 'left']),
  ('variant scenario 1',
   ('BABBAAABBBAABBBABBABABAABABAABAAAAAAAA', 'A'),
   [21, 16, 'A', None, None]),
  ('variant scenario 2',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABBB', 'B'),
   [28, 30, 'B', None, None])],
 [('control opening serve', ('', 'B'), [0, 0, None, 'B', 'right']),
  ('control server wins odd point', ('A', 'A'), [1, 0, None, 'A', 'left']),
  ('boundary receiver wins rally', ('AB', 'A'), [1, 1, None, 'B', 'left']),
  ('boundary game at 21-19',
   ('AAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBAA', 'A'),
   [21, 19, 'A', None, None]),
  ('boundary cap at 30',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABB', 'A'),
   [29, 30, 'B', None, None]),
  ('control 20-all continues',
   ('ABABABABABABABABABABABABABABABABABABABAB', 'A'),
   [20, 20, None, 'B', 'right']),
  ('regression: serve follows rally',
   ('AAAABAAABABBBAAABABBAABBBBAABBAB', 'A'),
   [17, 15, None, 'B', 'left']),
  ('variant scenario 1', ('BAABBAABAAABAAAAAAAABBAAAABBBBBBAABB', 'B'), [21, 13, 'A', None, None]),
  ('variant scenario 2', ('BBBAAABABABBABABAAB', 'B'), [9, 10, None, 'B', 'right'])],
 [('control opening serve', ('', 'B'), [0, 0, None, 'B', 'right']),
  ('control server wins odd point', ('A', 'A'), [1, 0, None, 'A', 'left']),
  ('boundary receiver wins rally', ('AB', 'A'), [1, 1, None, 'B', 'left']),
  ('boundary game at 21-19',
   ('AAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBAA', 'A'),
   [21, 19, 'A', None, None]),
  ('boundary cap at 30',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABB', 'A'),
   [29, 30, 'B', None, None]),
  ('control 20-all continues',
   ('ABABABABABABABABABABABABABABABABABABABAB', 'A'),
   [20, 20, None, 'B', 'right']),
  ('regression: serve follows rally', ('AAABAAABBBBA', 'B'), [7, 5, None, 'A', 'left']),
  ('variant scenario 1',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABBAA', 'A'),
   [29, 30, 'B', None, None]),
  ('variant scenario 2',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABBAA', 'B'),
   [28, 27, None, 'A', 'right'])],
 [('control opening serve', ('', 'B'), [0, 0, None, 'B', 'right']),
  ('control server wins odd point', ('A', 'A'), [1, 0, None, 'A', 'left']),
  ('boundary receiver wins rally', ('AB', 'A'), [1, 1, None, 'B', 'left']),
  ('boundary game at 21-19',
   ('AAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBAA', 'A'),
   [21, 19, 'A', None, None]),
  ('boundary cap at 30',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABB', 'A'),
   [29, 30, 'B', None, None]),
  ('control 20-all continues',
   ('ABABABABABABABABABABABABABABABABABABABAB', 'A'),
   [20, 20, None, 'B', 'right']),
  ('regression: serve follows rally',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABAB', 'A'),
   [26, 26, None, 'B', 'right']),
  ('variant scenario 1',
   ('BBBBBABABBBBBAABBABABABBAAAABAAAABABABABAABBBBBAAABABABABBBBBA', 'B'),
   [17, 21, 'B', None, None]),
  ('variant scenario 2',
   ('ABABABABABABABABABABABABABABABABABABABABAB', 'B'),
   [21, 21, None, 'B', 'left'])],
 [('control opening serve', ('', 'B'), [0, 0, None, 'B', 'right']),
  ('control server wins odd point', ('A', 'A'), [1, 0, None, 'A', 'left']),
  ('boundary receiver wins rally', ('AB', 'A'), [1, 1, None, 'B', 'left']),
  ('boundary game at 21-19',
   ('AAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBAA', 'A'),
   [21, 19, 'A', None, None]),
  ('boundary cap at 30',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABB', 'A'),
   [29, 30, 'B', None, None]),
  ('control 20-all continues',
   ('ABABABABABABABABABABABABABABABABABABABAB', 'A'),
   [20, 20, None, 'B', 'right']),
  ('regression: serve follows rally',
   ('ABABABABABABABABABABABABABABABABABABABABABABABBAA', 'B'),
   [25, 24, None, 'A', 'left']),
  ('regression: serve follows rally',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABAB', 'A'),
   [27, 27, None, 'B', 'left']),
  ('variant scenario 1',
   ('ABABABABABABABABABABABABABABABABABABABAA', 'B'),
   [21, 19, 'A', None, None]),
  ('variant scenario 2',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABA', 'B'),
   [26, 25, None, 'A', 'right'])]]
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_server):
    a = b = 0
    server = first_server
    for r in rallies:
        if r == 'A':
            a += 1
        else:
            b += 1
        server = 'B' if server == 'A' else 'A'
        if (max(a, b) >= 21 and abs(a - b) >= 2) or max(a, b) == 30:
            return [a, b, r, None, None]
    own = a if server == 'A' else b
    return [a, b, None, server, 'right' if own % 2 == 0 else 'left']
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 opening serve', ('', 'B'), [0, 0, None, 'B', 'right']),
  ('control server wins odd point', ('A', 'A'), [1, 0, None, 'A', 'left']),
  ('boundary receiver wins rally', ('AB', 'A'), [1, 1, None, 'B', 'left']),
  ('boundary game at 21-19',
   ('AAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBAA', 'A'),
   [21, 19, 'A', None, None]),
  ('boundary cap at 30',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABB', 'A'),
   [29, 30, 'B', None, None]),
  ('control 20-all continues',
   ('ABABABABABABABABABABABABABABABABABABABAB', 'A'),
   [20, 20, None, 'B', 'right']),
  ('regression: serve follows rally', ('BBBBAABAABABBBBAA', 'A'), [7, 10, None, 'A', 'left']),
  ('regression: serve follows rally',
   ('ABABABABABABABABABABABABABABABABABABAB', 'A'),
   [19, 19, None, 'B', 'left']),
  ('variant scenario 1',
   ('BABBAAABBBAABBBABBABABAABABAABAAAAAAAA', 'A'),
   [21, 16, 'A', None, None]),
  ('variant scenario 2',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABBB', 'B'),
   [28, 30, 'B', None, None])],
 [('control opening serve', ('', 'B'), [0, 0, None, 'B', 'right']),
  ('control server wins odd point', ('A', 'A'), [1, 0, None, 'A', 'left']),
  ('boundary receiver wins rally', ('AB', 'A'), [1, 1, None, 'B', 'left']),
  ('boundary game at 21-19',
   ('AAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBAA', 'A'),
   [21, 19, 'A', None, None]),
  ('boundary cap at 30',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABB', 'A'),
   [29, 30, 'B', None, None]),
  ('control 20-all continues',
   ('ABABABABABABABABABABABABABABABABABABABAB', 'A'),
   [20, 20, None, 'B', 'right']),
  ('regression: serve follows rally',
   ('AAAABAAABABBBAAABABBAABBBBAABBAB', 'A'),
   [17, 15, None, 'B', 'left']),
  ('variant scenario 1', ('BAABBAABAAABAAAAAAAABBAAAABBBBBBAABB', 'B'), [21, 13, 'A', None, None]),
  ('variant scenario 2', ('BBBAAABABABBABABAAB', 'B'), [9, 10, None, 'B', 'right'])],
 [('control opening serve', ('', 'B'), [0, 0, None, 'B', 'right']),
  ('control server wins odd point', ('A', 'A'), [1, 0, None, 'A', 'left']),
  ('boundary receiver wins rally', ('AB', 'A'), [1, 1, None, 'B', 'left']),
  ('boundary game at 21-19',
   ('AAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBAA', 'A'),
   [21, 19, 'A', None, None]),
  ('boundary cap at 30',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABB', 'A'),
   [29, 30, 'B', None, None]),
  ('control 20-all continues',
   ('ABABABABABABABABABABABABABABABABABABABAB', 'A'),
   [20, 20, None, 'B', 'right']),
  ('regression: serve follows rally', ('AAABAAABBBBA', 'B'), [7, 5, None, 'A', 'left']),
  ('variant scenario 1',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABBAA', 'A'),
   [29, 30, 'B', None, None]),
  ('variant scenario 2',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABBAA', 'B'),
   [28, 27, None, 'A', 'right'])],
 [('control opening serve', ('', 'B'), [0, 0, None, 'B', 'right']),
  ('control server wins odd point', ('A', 'A'), [1, 0, None, 'A', 'left']),
  ('boundary receiver wins rally', ('AB', 'A'), [1, 1, None, 'B', 'left']),
  ('boundary game at 21-19',
   ('AAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBAA', 'A'),
   [21, 19, 'A', None, None]),
  ('boundary cap at 30',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABB', 'A'),
   [29, 30, 'B', None, None]),
  ('control 20-all continues',
   ('ABABABABABABABABABABABABABABABABABABABAB', 'A'),
   [20, 20, None, 'B', 'right']),
  ('regression: serve follows rally',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABAB', 'A'),
   [26, 26, None, 'B', 'right']),
  ('variant scenario 1',
   ('BBBBBABABBBBBAABBABABABBAAAABAAAABABABABAABBBBBAAABABABABBBBBA', 'B'),
   [17, 21, 'B', None, None]),
  ('variant scenario 2',
   ('ABABABABABABABABABABABABABABABABABABABABAB', 'B'),
   [21, 21, None, 'B', 'left'])],
 [('control opening serve', ('', 'B'), [0, 0, None, 'B', 'right']),
  ('control server wins odd point', ('A', 'A'), [1, 0, None, 'A', 'left']),
  ('boundary receiver wins rally', ('AB', 'A'), [1, 1, None, 'B', 'left']),
  ('boundary game at 21-19',
   ('AAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBAA', 'A'),
   [21, 19, 'A', None, None]),
  ('boundary cap at 30',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABB', 'A'),
   [29, 30, 'B', None, None]),
  ('control 20-all continues',
   ('ABABABABABABABABABABABABABABABABABABABAB', 'A'),
   [20, 20, None, 'B', 'right']),
  ('regression: serve follows rally',
   ('ABABABABABABABABABABABABABABABABABABABABABABABBAA', 'B'),
   [25, 24, None, 'A', 'left']),
  ('regression: serve follows rally',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABABAB', 'A'),
   [27, 27, None, 'B', 'left']),
  ('variant scenario 1',
   ('ABABABABABABABABABABABABABABABABABABABAA', 'B'),
   [21, 19, 'A', None, None]),
  ('variant scenario 2',
   ('ABABABABABABABABABABABABABABABABABABABABABABABABABA', 'B'),
   [26, 25, None, 'A', 'right'])]]
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:
After a side-out the wrong player is shown serving.

One badminton singles game. rallies is a string of rally winners (A/B). A game is won at 21 points with a two-point lead, or by the first player to 30 points (29-29 next point wins). The rally winner serves next. The server serves from the right court when the server's own score is even and from the left court when odd. Return [a, b, winner, None, None] when finished (later rallies ignored) or [a, b, None, next server, "right"/"left"].

split: open-access


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

N = 1
observations = []
def solve(rallies, first_server):
    a = b = 0
    for r in rallies:
        if r == 'A':
            a += 1
        else:
            b += 1
        if max(a, b) >= 11 and abs(a - b) >= 2:
            return [a, b, r, None]
    k = a + b
    other = 'B' if first_server == 'A' else 'A'
    if a >= 10 or b >= 10:
        block = k - 10
    else:
        block = k // 2
    return [a, b, None, first_server if block % 2 == 0 else other]
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 opening server', ('', 'A'), [0, 0, None, 'A']),
  ('boundary second point same server', ('B', 'A'), [0, 1, None, 'A']),
  ('boundary change after two points', ('BA', 'A'), [1, 1, None, 'B']),
  ('boundary ten-all', ('ABABABABABABABABABAB', 'A'), [10, 10, None, 'A']),
  ('boundary eleven-ten alternates each point',
   ('ABABABABABABABABABABA', 'A'),
   [11, 10, None, 'B']),
  ('control eleven-nine', ('AAAAAAAAABBBBBBBBBAA', 'B'), [11, 9, 'A', None]),
  ('regression: expedited deuce condition', ('ABABABABABABABABAB', 'B'), [9, 9, None, 'A']),
  ('regression: expedited deuce condition', ('ABBAAABABAABAABABB', 'A'), [10, 8, None, 'B']),
  ('variant scenario 1', ('BBBBAABBBBABBBBBBBAA', 'B'), [3, 11, 'B', None]),
  ('variant scenario 2', ('ABABABABABABABABABABABAB', 'A'), [12, 12, None, 'A'])],
 [('control opening server', ('', 'A'), [0, 0, None, 'A']),
  ('boundary second point same server', ('B', 'A'), [0, 1, None, 'A']),
  ('boundary change after two points', ('BA', 'A'), [1, 1, None, 'B']),
  ('boundary ten-all', ('ABABABABABABABABABAB', 'A'), [10, 10, None, 'A']),
  ('boundary eleven-ten alternates each point',
   ('ABABABABABABABABABABA', 'A'),
   [11, 10, None, 'B']),
  ('control eleven-nine', ('AAAAAAAAABBBBBBBBBAA', 'B'), [11, 9, 'A', None]),
  ('regression: expedited deuce condition', ('ABABABABABABABABAB', 'B'), [9, 9, None, 'A']),
  ('regression: expedited deuce condition', ('BAABABAAAAAAA', 'B'), [10, 3, None, 'B']),
  ('variant scenario 1', ('ABABABABABABABABABABAA', 'A'), [12, 10, 'A', None]),
  ('variant scenario 2', ('BABABAAA', 'B'), [5, 3, None, 'B'])],
 [('control opening server', ('', 'A'), [0, 0, None, 'A']),
  ('boundary second point same server', ('B', 'A'), [0, 1, None, 'A']),
  ('boundary change after two points', ('BA', 'A'), [1, 1, None, 'B']),
  ('boundary ten-all', ('ABABABABABABABABABAB', 'A'), [10, 10, None, 'A']),
  ('boundary eleven-ten alternates each point',
   ('ABABABABABABABABABABA', 'A'),
   [11, 10, None, 'B']),
  ('control eleven-nine', ('AAAAAAAAABBBBBBBBBAA', 'B'), [11, 9, 'A', None]),
  ('regression: expedited deuce condition', ('ABABABABABABABABAB', 'B'), [9, 9, None, 'A']),
  ('regression: expedited deuce condition', ('BBBBAAABBBBBB', 'B'), [3, 10, None, 'B']),
  ('variant scenario 1', ('ABABABABABABABABABAB', 'A'), [10, 10, None, 'A']),
  ('variant scenario 2', ('BAB', 'A'), [1, 2, None, 'B'])],
 [('control opening server', ('', 'A'), [0, 0, None, 'A']),
  ('boundary second point same server', ('B', 'A'), [0, 1, None, 'A']),
  ('boundary change after two points', ('BA', 'A'), [1, 1, None, 'B']),
  ('boundary ten-all', ('ABABABABABABABABABAB', 'A'), [10, 10, None, 'A']),
  ('boundary eleven-ten alternates each point',
   ('ABABABABABABABABABABA', 'A'),
   [11, 10, None, 'B']),
  ('control eleven-nine', ('AAAAAAAAABBBBBBBBBAA', 'B'), [11, 9, 'A', None]),
  ('regression: expedited deuce condition', ('ABABBAAABBAAAABBAB', 'A'), [10, 8, None, 'B']),
  ('variant scenario 1', ('ABBAAAAAAAABBBAAB', 'B'), [11, 5, 'A', None]),
  ('variant scenario 2', ('ABABABABABABABABABABA', 'A'), [11, 10, None, 'B'])],
 [('control opening server', ('', 'A'), [0, 0, None, 'A']),
  ('boundary second point same server', ('B', 'A'), [0, 1, None, 'A']),
  ('boundary change after two points', ('BA', 'A'), [1, 1, None, 'B']),
  ('boundary ten-all', ('ABABABABABABABABABAB', 'A'), [10, 10, None, 'A']),
  ('boundary eleven-ten alternates each point',
   ('ABABABABABABABABABABA', 'A'),
   [11, 10, None, 'B']),
  ('control eleven-nine', ('AAAAAAAAABBBBBBBBBAA', 'B'), [11, 9, 'A', None]),
  ('regression: expedited deuce condition', ('ABABABABABABABABAB', 'A'), [9, 9, None, 'B']),
  ('regression: expedited deuce condition', ('BABAAABBBBAAAABBAA', 'A'), [10, 8, None, 'B']),
  ('variant scenario 1', ('ABBAAAAABABABBABAABAAABBAABBAAAB', 'A'), [11, 7, 'A', None]),
  ('variant scenario 2', ('BBBBABAAABABA', 'A'), [6, 7, None, '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(rallies, first_server):
    a = b = 0
    for r in rallies:
        if r == 'A':
            a += 1
        else:
            b += 1
        if max(a, b) >= 11 and abs(a - b) >= 2:
            return [a, b, r, None]
    k = a + b
    other = 'B' if first_server == 'A' else 'A'
    if a + b >= 18:
        block = k - 10
    else:
        block = k // 2
    return [a, b, None, first_server if block % 2 == 0 else other]
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 opening server', ('', 'A'), [0, 0, None, 'A']),
  ('boundary second point same server', ('B', 'A'), [0, 1, None, 'A']),
  ('boundary change after two points', ('BA', 'A'), [1, 1, None, 'B']),
  ('boundary ten-all', ('ABABABABABABABABABAB', 'A'), [10, 10, None, 'A']),
  ('boundary eleven-ten alternates each point',
   ('ABABABABABABABABABABA', 'A'),
   [11, 10, None, 'B']),
  ('control eleven-nine', ('AAAAAAAAABBBBBBBBBAA', 'B'), [11, 9, 'A', None]),
  ('regression: expedited deuce condition', ('ABABABABABABABABAB', 'B'), [9, 9, None, 'A']),
  ('regression: expedited deuce condition', ('ABBAAABABAABAABABB', 'A'), [10, 8, None, 'B']),
  ('variant scenario 1', ('BBBBAABBBBABBBBBBBAA', 'B'), [3, 11, 'B', None]),
  ('variant scenario 2', ('ABABABABABABABABABABABAB', 'A'), [12, 12, None, 'A'])],
 [('control opening server', ('', 'A'), [0, 0, None, 'A']),
  ('boundary second point same server', ('B', 'A'), [0, 1, None, 'A']),
  ('boundary change after two points', ('BA', 'A'), [1, 1, None, 'B']),
  ('boundary ten-all', ('ABABABABABABABABABAB', 'A'), [10, 10, None, 'A']),
  ('boundary eleven-ten alternates each point',
   ('ABABABABABABABABABABA', 'A'),
   [11, 10, None, 'B']),
  ('control eleven-nine', ('AAAAAAAAABBBBBBBBBAA', 'B'), [11, 9, 'A', None]),
  ('regression: expedited deuce condition', ('ABABABABABABABABAB', 'B'), [9, 9, None, 'A']),
  ('regression: expedited deuce condition', ('BAABABAAAAAAA', 'B'), [10, 3, None, 'B']),
  ('variant scenario 1', ('ABABABABABABABABABABAA', 'A'), [12, 10, 'A', None]),
  ('variant scenario 2', ('BABABAAA', 'B'), [5, 3, None, 'B'])],
 [('control opening server', ('', 'A'), [0, 0, None, 'A']),
  ('boundary second point same server', ('B', 'A'), [0, 1, None, 'A']),
  ('boundary change after two points', ('BA', 'A'), [1, 1, None, 'B']),
  ('boundary ten-all', ('ABABABABABABABABABAB', 'A'), [10, 10, None, 'A']),
  ('boundary eleven-ten alternates each point',
   ('ABABABABABABABABABABA', 'A'),
   [11, 10, None, 'B']),
  ('control eleven-nine', ('AAAAAAAAABBBBBBBBBAA', 'B'), [11, 9, 'A', None]),
  ('regression: expedited deuce condition', ('ABABABABABABABABAB', 'B'), [9, 9, None, 'A']),
  ('regression: expedited deuce condition', ('BBBBAAABBBBBB', 'B'), [3, 10, None, 'B']),
  ('variant scenario 1', ('ABABABABABABABABABAB', 'A'), [10, 10, None, 'A']),
  ('variant scenario 2', ('BAB', 'A'), [1, 2, None, 'B'])],
 [('control opening server', ('', 'A'), [0, 0, None, 'A']),
  ('boundary second point same server', ('B', 'A'), [0, 1, None, 'A']),
  ('boundary change after two points', ('BA', 'A'), [1, 1, None, 'B']),
  ('boundary ten-all', ('ABABABABABABABABABAB', 'A'), [10, 10, None, 'A']),
  ('boundary eleven-ten alternates each point',
   ('ABABABABABABABABABABA', 'A'),
   [11, 10, None, 'B']),
  ('control eleven-nine', ('AAAAAAAAABBBBBBBBBAA', 'B'), [11, 9, 'A', None]),
  ('regression: expedited deuce condition', ('ABABBAAABBAAAABBAB', 'A'), [10, 8, None, 'B']),
  ('variant scenario 1', ('ABBAAAAAAAABBBAAB', 'B'), [11, 5, 'A', None]),
  ('variant scenario 2', ('ABABABABABABABABABABA', 'A'), [11, 10, None, 'B'])],
 [('control opening server', ('', 'A'), [0, 0, None, 'A']),
  ('boundary second point same server', ('B', 'A'), [0, 1, None, 'A']),
  ('boundary change after two points', ('BA', 'A'), [1, 1, None, 'B']),
  ('boundary ten-all', ('ABABABABABABABABABAB', 'A'), [10, 10, None, 'A']),
  ('boundary eleven-ten alternates each point',
   ('ABABABABABABABABABABA', 'A'),
   [11, 10, None, 'B']),
  ('control eleven-nine', ('AAAAAAAAABBBBBBBBBAA', 'B'), [11, 9, 'A', None]),
  ('regression: expedited deuce condition', ('ABABABABABABABABAB', 'A'), [9, 9, None, 'B']),
  ('regression: expedited deuce condition', ('BABAAABBBBAAAABBAA', 'A'), [10, 8, None, 'B']),
  ('variant scenario 1', ('ABBAAAAABABABBABAABAAABBAABBAAAB', 'A'), [11, 7, 'A', None]),
  ('variant scenario 2', ('BBBBABAAABABA', 'A'), [6, 7, None, '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:
At 10-6 the server changes every point instead of every two points.

One table tennis game to 11 with a two-point lead; later rallies are ignored. Service changes after every two points; once both players have at least 10 points it changes after every point. Return [a, b, winner, None] when finished, else [a, b, None, next server].

split: open-access


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

N = 1
observations = []
def solve(rallies, first_server):
    a = b = 0
    for r in rallies:
        if r == 'A':
            a += 1
        else:
            b += 1
        if max(a, b) >= 11 and abs(a - b) >= 2:
            return [a, b, r, None]
    k = a + b
    other = 'B' if first_server == 'A' else 'A'
    if a >= 10 and b >= 10:
        block = k - 10
    else:
        block = k
    return [a, b, None, first_server if block % 2 == 0 else other]
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 opening server', ('', 'A'), [0, 0, None, 'A']),
  ('boundary second point same server', ('B', 'A'), [0, 1, None, 'A']),
  ('boundary change after two points', ('BA', 'A'), [1, 1, None, 'B']),
  ('boundary ten-all', ('ABABABABABABABABABAB', 'A'), [10, 10, None, 'A']),
  ('boundary eleven-ten alternates each point',
   ('ABABABABABABABABABABA', 'A'),
   [11, 10, None, 'B']),
  ('control eleven-nine', ('AAAAAAAAABBBBBBBBBAA', 'B'), [11, 9, 'A', None]),
  ('regression: two point service block', ('AAABABA', 'B'), [5, 2, None, 'A']),
  ('regression: two point service block', ('AABBABBBBB', 'B'), [3, 7, None, 'A']),
  ('variant scenario 1', ('ABABABABABABABABABAB', 'B'), [10, 10, None, 'B']),
  ('variant scenario 2', ('ABABABABABABABABABBB', 'A'), [9, 11, 'B', None])],
 [('control opening server', ('', 'A'), [0, 0, None, 'A']),
  ('boundary second point same server', ('B', 'A'), [0, 1, None, 'A']),
  ('boundary change after two points', ('BA', 'A'), [1, 1, None, 'B']),
  ('boundary ten-all', ('ABABABABABABABABABAB', 'A'), [10, 10, None, 'A']),
  ('boundary eleven-ten alternates each point',
   ('ABABABABABABABABABABA', 'A'),
   [11, 10, None, 'B']),
  ('control eleven-nine', ('AAAAAAAAABBBBBBBBBAA', 'B'), [11, 9, 'A', None]),
  ('regression: two point service block', ('ABABABABABABABABABB', 'A'), [9, 10, None, 'B']),
  ('regression: two point service block', ('ABABABABABABABABAB', 'B'), [9, 9, None, 'A']),
  ('variant scenario 1', ('ABABABABABABABABABABAB', 'B'), [11, 11, None, 'B']),
  ('variant scenario 2', ('ABABABABABABABABABABABABBB', 'A'), [12, 14, 'B', None])],
 [('control opening server', ('', 'A'), [0, 0, None, 'A']),
  ('boundary second point same server', ('B', 'A'), [0, 1, None, 'A']),
  ('boundary change after two points', ('BA', 'A'), [1, 1, None, 'B']),
  ('boundary ten-all', ('ABABABABABABABABABAB', 'A'), [10, 10, None, 'A']),
  ('boundary eleven-ten alternates each point',
   ('ABABABABABABABABABABA', 'A'),
   [11, 10, None, 'B']),
  ('control eleven-nine', ('AAAAAAAAABBBBBBBBBAA', 'B'), [11, 9, 'A', None]),
  ('regression: two point service block', ('ABABABABABABABABABB', 'A'), [9, 10, None, 'B']),
  ('regression: two point service block', ('ABBBA', 'A'), [2, 3, None, 'A']),
  ('variant scenario 1', ('ABABABABABABABABABAB', 'B'), [10, 10, None, 'B']),
  ('variant scenario 2', ('ABABABABABABABABABABAB', 'B'), [11, 11, None, 'B'])],
 [('control opening server', ('', 'A'), [0, 0, None, 'A']),
  ('boundary second point same server', ('B', 'A'), [0, 1, None, 'A']),
  ('boundary change after two points', ('BA', 'A'), [1, 1, None, 'B']),
  ('boundary ten-all', ('ABABABABABABABABABAB', 'A'), [10, 10, None, 'A']),
  ('boundary eleven-ten alternates each point',
   ('ABABABABABABABABABABA', 'A'),
   [11, 10, None, 'B']),
  ('control eleven-nine', ('AAAAAAAAABBBBBBBBBAA', 'B'), [11, 9, 'A', None]),
  ('regression: two point service block', ('ABABABABABABABABAB', 'B'), [9, 9, None, 'A']),
  ('regression: two point service block', ('BBAAABAAAAABBBABB', 'B'), [9, 8, None, 'B']),
  ('variant scenario 1', ('BABAAAAAAAAABBBAAABBABABAABA', 'A'), [11, 5, 'A', None]),
  ('variant scenario 2', ('BBBAAAABAABABAAABBBABBAABA', 'A'), [11, 9, 'A', None])],
 [('control opening server', ('', 'A'), [0, 0, None, 'A']),
  ('boundary second point same server', ('B', 'A'), [0, 1, None, 'A']),
  ('boundary change after two points', ('BA', 'A'), [1, 1, None, 'B']),
  ('boundary ten-all', ('ABABABABABABABABABAB', 'A'), [10, 10, None, 'A']),
  ('boundary eleven-ten alternates each point',
   ('ABABABABABABABABABABA', 'A'),
   [11, 10, None, 'B']),
  ('control eleven-nine', ('AAAAAAAAABBBBBBBBBAA', 'B'), [11, 9, 'A', None]),
  ('regression: two point service block', ('BABBBAABAB', 'B'), [4, 6, None, 'A']),
  ('regression: two point service block', ('AABAABABBAAABBABABB', 'A'), [10, 9, None, 'B']),
  ('variant scenario 1', ('ABABABABABABABABABABABBB', 'B'), [11, 13, 'B', None]),
  ('variant scenario 2', ('BBBBBBABBBBAABABBBBAABAABBAA', 'A'), [3, 11, 'B', 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)

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

N = 1
observations = []
def solve(rallies, first_server):
    a = b = 0
    for r in rallies:
        if r == 'A':
            a += 1
        else:
            b += 1
        if max(a, b) >= 11 and abs(a - b) >= 2:
            return [a, b, r, None]
    k = a + b
    other = 'B' if first_server == 'A' else 'A'
    if a >= 10 and b >= 10:
        block = k - 10
    else:
        block = (k + 1) // 2
    return [a, b, None, first_server if block % 2 == 0 else other]
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 opening server', ('', 'A'), [0, 0, None, 'A']),
  ('boundary second point same server', ('B', 'A'), [0, 1, None, 'A']),
  ('boundary change after two points', ('BA', 'A'), [1, 1, None, 'B']),
  ('boundary ten-all', ('ABABABABABABABABABAB', 'A'), [10, 10, None, 'A']),
  ('boundary eleven-ten alternates each point',
   ('ABABABABABABABABABABA', 'A'),
   [11, 10, None, 'B']),
  ('control eleven-nine', ('AAAAAAAAABBBBBBBBBAA', 'B'), [11, 9, 'A', None]),
  ('regression: two point service block', ('AAABABA', 'B'), [5, 2, None, 'A']),
  ('regression: two point service block', ('AABBABBBBB', 'B'), [3, 7, None, 'A']),
  ('variant scenario 1', ('ABABABABABABABABABAB', 'B'), [10, 10, None, 'B']),
  ('variant scenario 2', ('ABABABABABABABABABBB', 'A'), [9, 11, 'B', None])],
 [('control opening server', ('', 'A'), [0, 0, None, 'A']),
  ('boundary second point same server', ('B', 'A'), [0, 1, None, 'A']),
  ('boundary change after two points', ('BA', 'A'), [1, 1, None, 'B']),
  ('boundary ten-all', ('ABABABABABABABABABAB', 'A'), [10, 10, None, 'A']),
  ('boundary eleven-ten alternates each point',
   ('ABABABABABABABABABABA', 'A'),
   [11, 10, None, 'B']),
  ('control eleven-nine', ('AAAAAAAAABBBBBBBBBAA', 'B'), [11, 9, 'A', None]),
  ('regression: two point service block', ('ABABABABABABABABABB', 'A'), [9, 10, None, 'B']),
  ('regression: two point service block', ('ABABABABABABABABAB', 'B'), [9, 9, None, 'A']),
  ('variant scenario 1', ('ABABABABABABABABABABAB', 'B'), [11, 11, None, 'B']),
  ('variant scenario 2', ('ABABABABABABABABABABABABBB', 'A'), [12, 14, 'B', None])],
 [('control opening server', ('', 'A'), [0, 0, None, 'A']),
  ('boundary second point same server', ('B', 'A'), [0, 1, None, 'A']),
  ('boundary change after two points', ('BA', 'A'), [1, 1, None, 'B']),
  ('boundary ten-all', ('ABABABABABABABABABAB', 'A'), [10, 10, None, 'A']),
  ('boundary eleven-ten alternates each point',
   ('ABABABABABABABABABABA', 'A'),
   [11, 10, None, 'B']),
  ('control eleven-nine', ('AAAAAAAAABBBBBBBBBAA', 'B'), [11, 9, 'A', None]),
  ('regression: two point service block', ('ABABABABABABABABABB', 'A'), [9, 10, None, 'B']),
  ('regression: two point service block', ('ABBBA', 'A'), [2, 3, None, 'A']),
  ('variant scenario 1', ('ABABABABABABABABABAB', 'B'), [10, 10, None, 'B']),
  ('variant scenario 2', ('ABABABABABABABABABABAB', 'B'), [11, 11, None, 'B'])],
 [('control opening server', ('', 'A'), [0, 0, None, 'A']),
  ('boundary second point same server', ('B', 'A'), [0, 1, None, 'A']),
  ('boundary change after two points', ('BA', 'A'), [1, 1, None, 'B']),
  ('boundary ten-all', ('ABABABABABABABABABAB', 'A'), [10, 10, None, 'A']),
  ('boundary eleven-ten alternates each point',
   ('ABABABABABABABABABABA', 'A'),
   [11, 10, None, 'B']),
  ('control eleven-nine', ('AAAAAAAAABBBBBBBBBAA', 'B'), [11, 9, 'A', None]),
  ('regression: two point service block', ('ABABABABABABABABAB', 'B'), [9, 9, None, 'A']),
  ('regression: two point service block', ('BBAAABAAAAABBBABB', 'B'), [9, 8, None, 'B']),
  ('variant scenario 1', ('BABAAAAAAAAABBBAAABBABABAABA', 'A'), [11, 5, 'A', None]),
  ('variant scenario 2', ('BBBAAAABAABABAAABBBABBAABA', 'A'), [11, 9, 'A', None])],
 [('control opening server', ('', 'A'), [0, 0, None, 'A']),
  ('boundary second point same server', ('B', 'A'), [0, 1, None, 'A']),
  ('boundary change after two points', ('BA', 'A'), [1, 1, None, 'B']),
  ('boundary ten-all', ('ABABABABABABABABABAB', 'A'), [10, 10, None, 'A']),
  ('boundary eleven-ten alternates each point',
   ('ABABABABABABABABABABA', 'A'),
   [11, 10, None, 'B']),
  ('control eleven-nine', ('AAAAAAAAABBBBBBBBBAA', 'B'), [11, 9, 'A', None]),
  ('regression: two point service block', ('BABBBAABAB', 'B'), [4, 6, None, 'A']),
  ('regression: two point service block', ('AABAABABBAAABBABABB', 'A'), [10, 9, None, 'B']),
  ('variant scenario 1', ('ABABABABABABABABABABABBB', 'B'), [11, 13, 'B', None]),
  ('variant scenario 2', ('BBBBBBABBBBAABABBBBAABAABBAA', 'A'), [3, 11, 'B', 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:
The next server is wrong after the first point of the game.

One table tennis game to 11 with a two-point lead; later rallies are ignored. Service changes after every two points; once both players have at least 10 points it changes after every point. Return [a, b, winner, None] when finished, else [a, b, None, next server].

split: open-access