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

N = 1
observations = []
def solve(rank_a, rank_b, coins, clicks, length):
    out, team = [], []
    ia = ib = ci = 0
    while len(out) < length:
        while ia < len(rank_a) and rank_a[ia] in out:
            ia += 1
        while ib < len(rank_b) and rank_b[ib] in out:
            ib += 1
        has_a, has_b = ia < len(rank_a), ib < len(rank_b)
        if not has_a and not has_b:
            break
        na, nb = team.count('A'), team.count('B')
        if na == nb:
            pick_a = coins[ci % len(coins)] == 0
            ci += 1
        else:
            pick_a = na < nb
            ci += 1
        if pick_a and not has_a:
            pick_a = False
        elif not pick_a and not has_b:
            pick_a = True
        if pick_a:
            out.append(rank_a[ia])
            team.append('A')
        else:
            out.append(rank_b[ib])
            team.append('B')
    credit_a = sum(1 for i in clicks if i < len(out) and team[i] == 'A')
    credit_b = sum(1 for i in clicks if i < len(out) and team[i] == 'B')
    winner = 'A' if credit_a > credit_b else 'B' if credit_b > credit_a else 'tie'
    return [out, team, winner]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('shared top document is placed once',
   [['d1', 'd2', 'd3'], ['d1', 'd3', 'd4'], [0, 1], [1], 4],
   [['d1', 'd3', 'd4', 'd2'], ['A', 'B', 'B', 'A'], 'B']),
  ('coins are consumed only on ties',
   [['d1', 'd2', 'd3'], ['d4', 'd5', 'd6'], [1, 0], [0, 3], 6],
   [['d4', 'd1', 'd2', 'd5', 'd6', 'd3'], ['B', 'A', 'A', 'B', 'B', 'A'], 'B']),
  ('team behind picks next',
   [['d1', 'd2'], ['d3', 'd4'], [0], [2], 4],
   [['d1', 'd3', 'd2', 'd4'], ['A', 'B', 'A', 'B'], 'A']),
  ('shared document credits the team that placed it',
   [['d1', 'd2'], ['d2', 'd1'], [1], [0], 2],
   [['d2', 'd1'], ['B', 'A'], 'B']),
  ('exhausted ranking yields',
   [['d1'], ['d2', 'd3', 'd4'], [0], [3], 4],
   [['d1', 'd2', 'd3', 'd4'], ['A', 'B', 'B', 'B'], 'B']),
  ('query sample 1',
   [['d4', 'd3', 'd2'], ['d5', 'd6'], [0], [], 6],
   [['d4', 'd5', 'd3', 'd6', 'd2'], ['A', 'B', 'A', 'B', 'A'], 'tie']),
  ('query sample 2',
   [['d6', 'd5', 'd1', 'd2'], ['d6', 'd5'], [1, 1, 1], [], 4],
   [['d6', 'd5', 'd1', 'd2'], ['B', 'A', 'A', 'A'], 'tie']),
  ('query sample 3',
   [['d5', 'd4'], ['d6', 'd3', 'd5', 'd1'], [0], [], 5],
   [['d5', 'd6', 'd4', 'd3', 'd1'], ['A', 'B', 'A', 'B', 'B'], 'tie'])],
 [('coins are consumed only on ties',
   [['d1', 'd2', 'd3'], ['d4', 'd5', 'd6'], [1, 0], [0, 3], 6],
   [['d4', 'd1', 'd2', 'd5', 'd6', 'd3'], ['B', 'A', 'A', 'B', 'B', 'A'], 'B']),
  ('team behind picks next',
   [['d1', 'd2'], ['d3', 'd4'], [0], [2], 4],
   [['d1', 'd3', 'd2', 'd4'], ['A', 'B', 'A', 'B'], 'A']),
  ('shared document credits the team that placed it',
   [['d1', 'd2'], ['d2', 'd1'], [1], [0], 2],
   [['d2', 'd1'], ['B', 'A'], 'B']),
  ('exhausted ranking yields',
   [['d1'], ['d2', 'd3', 'd4'], [0], [3], 4],
   [['d1', 'd2', 'd3', 'd4'], ['A', 'B', 'B', 'B'], 'B']),
  ('no clicks is a tie', [['d1', 'd2'], ['d3'], [1], [], 3], [['d3', 'd1', 'd2'], ['B', 'A', 'A'], 'tie']),
  ('query sample 6',
   [['d1', 'd4', 'd5'], ['d5', 'd3', 'd2'], [0], [1], 6],
   [['d1', 'd5', 'd4', 'd3', 'd2'], ['A', 'B', 'A', 'B', 'B'], 'B']),
  ('query sample 7',
   [['d4', 'd1', 'd6'], ['d1', 'd6', 'd2', 'd4', 'd3'], [0, 0, 1], [4, 5], 5],
   [['d4', 'd1', 'd6', 'd2', 'd3'], ['A', 'B', 'A', 'B', 'B'], 'B']),
  ('query sample 12',
   [['d1', 'd4', 'd5', 'd6', 'd2'], ['d6', 'd2', 'd5'], [0, 1, 0], [], 3],
   [['d1', 'd6', 'd2'], ['A', 'B', 'B'], 'tie'])],
 [('shared top document is placed once',
   [['d1', 'd2', 'd3'], ['d1', 'd3', 'd4'], [0, 1], [1], 4],
   [['d1', 'd3', 'd4', 'd2'], ['A', 'B', 'B', 'A'], 'B']),
  ('team behind picks next',
   [['d1', 'd2'], ['d3', 'd4'], [0], [2], 4],
   [['d1', 'd3', 'd2', 'd4'], ['A', 'B', 'A', 'B'], 'A']),
  ('shared document credits the team that placed it',
   [['d1', 'd2'], ['d2', 'd1'], [1], [0], 2],
   [['d2', 'd1'], ['B', 'A'], 'B']),
  ('exhausted ranking yields',
   [['d1'], ['d2', 'd3', 'd4'], [0], [3], 4],
   [['d1', 'd2', 'd3', 'd4'], ['A', 'B', 'B', 'B'], 'B']),
  ('no clicks is a tie', [['d1', 'd2'], ['d3'], [1], [], 3], [['d3', 'd1', 'd2'], ['B', 'A', 'A'], 'tie']),
  ('query sample 11',
   [['d4', 'd2', 'd5'], ['d5', 'd2', 'd1', 'd6'], [1, 0], [], 6],
   [['d5', 'd4', 'd2', 'd1', 'd6'], ['B', 'A', 'A', 'B', 'B'], 'tie']),
  ('query sample 12',
   [['d1', 'd4', 'd5', 'd6', 'd2'], ['d6', 'd2', 'd5'], [0, 1, 0], [], 3],
   [['d1', 'd6', 'd2'], ['A', 'B', 'B'], 'tie']),
  ('query sample 41',
   [['d5', 'd2', 'd3', 'd1', 'd4'], ['d5', 'd3'], [1, 0, 1], [1], 6],
   [['d5', 'd2', 'd3', 'd1', 'd4'], ['B', 'A', 'A', 'A', 'A'], 'A'])],
 [('shared top document is placed once',
   [['d1', 'd2', 'd3'], ['d1', 'd3', 'd4'], [0, 1], [1], 4],
   [['d1', 'd3', 'd4', 'd2'], ['A', 'B', 'B', 'A'], 'B']),
  ('coins are consumed only on ties',
   [['d1', 'd2', 'd3'], ['d4', 'd5', 'd6'], [1, 0], [0, 3], 6],
   [['d4', 'd1', 'd2', 'd5', 'd6', 'd3'], ['B', 'A', 'A', 'B', 'B', 'A'], 'B']),
  ('shared document credits the team that placed it',
   [['d1', 'd2'], ['d2', 'd1'], [1], [0], 2],
   [['d2', 'd1'], ['B', 'A'], 'B']),
  ('exhausted ranking yields',
   [['d1'], ['d2', 'd3', 'd4'], [0], [3], 4],
   [['d1', 'd2', 'd3', 'd4'], ['A', 'B', 'B', 'B'], 'B']),
  ('no clicks is a tie', [['d1', 'd2'], ['d3'], [1], [], 3], [['d3', 'd1', 'd2'], ['B', 'A', 'A'], 'tie']),
  ('query sample 16',
   [['d1', 'd3', 'd4', 'd2'], ['d3', 'd2', 'd1', 'd5'], [0, 1, 1], [], 4],
   [['d1', 'd3', 'd2', 'd4'], ['A', 'B', 'B', 'A'], 'tie']),
  ('query sample 17',
   [['d4', 'd2'], ['d3', 'd5', 'd6', 'd4', 'd2'], [1, 1], [], 5],
   [['d3', 'd4', 'd5', 'd2', 'd6'], ['B', 'A', 'B', 'A', 'B'], 'tie']),
  ('query sample 51',
   [['d1', 'd2'], ['d5', 'd1', 'd4'], [0, 0, 1], [], 3],
   [['d1', 'd5', 'd2'], ['A', 'B', 'A'], 'tie'])],
 [('shared top document is placed once',
   [['d1', 'd2', 'd3'], ['d1', 'd3', 'd4'], [0, 1], [1], 4],
   [['d1', 'd3', 'd4', 'd2'], ['A', 'B', 'B', 'A'], 'B']),
  ('coins are consumed only on ties',
   [['d1', 'd2', 'd3'], ['d4', 'd5', 'd6'], [1, 0], [0, 3], 6],
   [['d4', 'd1', 'd2', 'd5', 'd6', 'd3'], ['B', 'A', 'A', 'B', 'B', 'A'], 'B']),
  ('team behind picks next',
   [['d1', 'd2'], ['d3', 'd4'], [0], [2], 4],
   [['d1', 'd3', 'd2', 'd4'], ['A', 'B', 'A', 'B'], 'A']),
  ('exhausted ranking yields',
   [['d1'], ['d2', 'd3', 'd4'], [0], [3], 4],
   [['d1', 'd2', 'd3', 'd4'], ['A', 'B', 'B', 'B'], 'B']),
  ('no clicks is a tie', [['d1', 'd2'], ['d3'], [1], [], 3], [['d3', 'd1', 'd2'], ['B', 'A', 'A'], 'tie']),
  ('query sample 10',
   [['d4', 'd2', 'd1', 'd3'], ['d2', 'd3', 'd1'], [0, 0, 1], [1, 2], 6],
   [['d4', 'd2', 'd1', 'd3'], ['A', 'B', 'A', 'B'], 'tie']),
  ('query sample 21',
   [['d5', 'd3'], ['d2', 'd3', 'd6', 'd4', 'd5'], [1, 1], [], 5],
   [['d2', 'd5', 'd3', 'd6', 'd4'], ['B', 'A', 'B', 'B', 'B'], 'tie']),
  ('query sample 22',
   [['d1', 'd4'], ['d1', 'd6', 'd3', 'd5', 'd2'], [0], [4], 4],
   [['d1', 'd6', 'd4', 'd3'], ['A', 'B', 'A', 'B'], 'tie'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(rank_a, rank_b, coins, clicks, length):
    out, team = [], []
    ia = ib = ci = 0
    while len(out) < length:
        while ia < len(rank_a) and rank_a[ia] in out:
            ia += 1
        while ib < len(rank_b) and rank_b[ib] in out:
            ib += 1
        has_a, has_b = ia < len(rank_a), ib < len(rank_b)
        if not has_a and not has_b:
            break
        na, nb = team.count('A'), team.count('B')
        if na == nb:
            pick_a = coins[len(out) % len(coins)] == 0
            ci += 1
        else:
            pick_a = na < nb
        if pick_a and not has_a:
            pick_a = False
        elif not pick_a and not has_b:
            pick_a = True
        if pick_a:
            out.append(rank_a[ia])
            team.append('A')
        else:
            out.append(rank_b[ib])
            team.append('B')
    credit_a = sum(1 for i in clicks if i < len(out) and team[i] == 'A')
    credit_b = sum(1 for i in clicks if i < len(out) and team[i] == 'B')
    winner = 'A' if credit_a > credit_b else 'B' if credit_b > credit_a else 'tie'
    return [out, team, winner]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('shared top document is placed once',
   [['d1', 'd2', 'd3'], ['d1', 'd3', 'd4'], [0, 1], [1], 4],
   [['d1', 'd3', 'd4', 'd2'], ['A', 'B', 'B', 'A'], 'B']),
  ('coins are consumed only on ties',
   [['d1', 'd2', 'd3'], ['d4', 'd5', 'd6'], [1, 0], [0, 3], 6],
   [['d4', 'd1', 'd2', 'd5', 'd6', 'd3'], ['B', 'A', 'A', 'B', 'B', 'A'], 'B']),
  ('team behind picks next',
   [['d1', 'd2'], ['d3', 'd4'], [0], [2], 4],
   [['d1', 'd3', 'd2', 'd4'], ['A', 'B', 'A', 'B'], 'A']),
  ('shared document credits the team that placed it',
   [['d1', 'd2'], ['d2', 'd1'], [1], [0], 2],
   [['d2', 'd1'], ['B', 'A'], 'B']),
  ('exhausted ranking yields',
   [['d1'], ['d2', 'd3', 'd4'], [0], [3], 4],
   [['d1', 'd2', 'd3', 'd4'], ['A', 'B', 'B', 'B'], 'B']),
  ('query sample 1',
   [['d4', 'd3', 'd2'], ['d5', 'd6'], [0], [], 6],
   [['d4', 'd5', 'd3', 'd6', 'd2'], ['A', 'B', 'A', 'B', 'A'], 'tie']),
  ('query sample 2',
   [['d6', 'd5', 'd1', 'd2'], ['d6', 'd5'], [1, 1, 1], [], 4],
   [['d6', 'd5', 'd1', 'd2'], ['B', 'A', 'A', 'A'], 'tie']),
  ('query sample 3',
   [['d5', 'd4'], ['d6', 'd3', 'd5', 'd1'], [0], [], 5],
   [['d5', 'd6', 'd4', 'd3', 'd1'], ['A', 'B', 'A', 'B', 'B'], 'tie'])],
 [('coins are consumed only on ties',
   [['d1', 'd2', 'd3'], ['d4', 'd5', 'd6'], [1, 0], [0, 3], 6],
   [['d4', 'd1', 'd2', 'd5', 'd6', 'd3'], ['B', 'A', 'A', 'B', 'B', 'A'], 'B']),
  ('team behind picks next',
   [['d1', 'd2'], ['d3', 'd4'], [0], [2], 4],
   [['d1', 'd3', 'd2', 'd4'], ['A', 'B', 'A', 'B'], 'A']),
  ('shared document credits the team that placed it',
   [['d1', 'd2'], ['d2', 'd1'], [1], [0], 2],
   [['d2', 'd1'], ['B', 'A'], 'B']),
  ('exhausted ranking yields',
   [['d1'], ['d2', 'd3', 'd4'], [0], [3], 4],
   [['d1', 'd2', 'd3', 'd4'], ['A', 'B', 'B', 'B'], 'B']),
  ('no clicks is a tie', [['d1', 'd2'], ['d3'], [1], [], 3], [['d3', 'd1', 'd2'], ['B', 'A', 'A'], 'tie']),
  ('query sample 6',
   [['d1', 'd4', 'd5'], ['d5', 'd3', 'd2'], [0], [1], 6],
   [['d1', 'd5', 'd4', 'd3', 'd2'], ['A', 'B', 'A', 'B', 'B'], 'B']),
  ('query sample 7',
   [['d4', 'd1', 'd6'], ['d1', 'd6', 'd2', 'd4', 'd3'], [0, 0, 1], [4, 5], 5],
   [['d4', 'd1', 'd6', 'd2', 'd3'], ['A', 'B', 'A', 'B', 'B'], 'B']),
  ('query sample 12',
   [['d1', 'd4', 'd5', 'd6', 'd2'], ['d6', 'd2', 'd5'], [0, 1, 0], [], 3],
   [['d1', 'd6', 'd2'], ['A', 'B', 'B'], 'tie'])],
 [('shared top document is placed once',
   [['d1', 'd2', 'd3'], ['d1', 'd3', 'd4'], [0, 1], [1], 4],
   [['d1', 'd3', 'd4', 'd2'], ['A', 'B', 'B', 'A'], 'B']),
  ('team behind picks next',
   [['d1', 'd2'], ['d3', 'd4'], [0], [2], 4],
   [['d1', 'd3', 'd2', 'd4'], ['A', 'B', 'A', 'B'], 'A']),
  ('shared document credits the team that placed it',
   [['d1', 'd2'], ['d2', 'd1'], [1], [0], 2],
   [['d2', 'd1'], ['B', 'A'], 'B']),
  ('exhausted ranking yields',
   [['d1'], ['d2', 'd3', 'd4'], [0], [3], 4],
   [['d1', 'd2', 'd3', 'd4'], ['A', 'B', 'B', 'B'], 'B']),
  ('no clicks is a tie', [['d1', 'd2'], ['d3'], [1], [], 3], [['d3', 'd1', 'd2'], ['B', 'A', 'A'], 'tie']),
  ('query sample 11',
   [['d4', 'd2', 'd5'], ['d5', 'd2', 'd1', 'd6'], [1, 0], [], 6],
   [['d5', 'd4', 'd2', 'd1', 'd6'], ['B', 'A', 'A', 'B', 'B'], 'tie']),
  ('query sample 12',
   [['d1', 'd4', 'd5', 'd6', 'd2'], ['d6', 'd2', 'd5'], [0, 1, 0], [], 3],
   [['d1', 'd6', 'd2'], ['A', 'B', 'B'], 'tie']),
  ('query sample 41',
   [['d5', 'd2', 'd3', 'd1', 'd4'], ['d5', 'd3'], [1, 0, 1], [1], 6],
   [['d5', 'd2', 'd3', 'd1', 'd4'], ['B', 'A', 'A', 'A', 'A'], 'A'])],
 [('shared top document is placed once',
   [['d1', 'd2', 'd3'], ['d1', 'd3', 'd4'], [0, 1], [1], 4],
   [['d1', 'd3', 'd4', 'd2'], ['A', 'B', 'B', 'A'], 'B']),
  ('coins are consumed only on ties',
   [['d1', 'd2', 'd3'], ['d4', 'd5', 'd6'], [1, 0], [0, 3], 6],
   [['d4', 'd1', 'd2', 'd5', 'd6', 'd3'], ['B', 'A', 'A', 'B', 'B', 'A'], 'B']),
  ('shared document credits the team that placed it',
   [['d1', 'd2'], ['d2', 'd1'], [1], [0], 2],
   [['d2', 'd1'], ['B', 'A'], 'B']),
  ('exhausted ranking yields',
   [['d1'], ['d2', 'd3', 'd4'], [0], [3], 4],
   [['d1', 'd2', 'd3', 'd4'], ['A', 'B', 'B', 'B'], 'B']),
  ('no clicks is a tie', [['d1', 'd2'], ['d3'], [1], [], 3], [['d3', 'd1', 'd2'], ['B', 'A', 'A'], 'tie']),
  ('query sample 16',
   [['d1', 'd3', 'd4', 'd2'], ['d3', 'd2', 'd1', 'd5'], [0, 1, 1], [], 4],
   [['d1', 'd3', 'd2', 'd4'], ['A', 'B', 'B', 'A'], 'tie']),
  ('query sample 17',
   [['d4', 'd2'], ['d3', 'd5', 'd6', 'd4', 'd2'], [1, 1], [], 5],
   [['d3', 'd4', 'd5', 'd2', 'd6'], ['B', 'A', 'B', 'A', 'B'], 'tie']),
  ('query sample 51',
   [['d1', 'd2'], ['d5', 'd1', 'd4'], [0, 0, 1], [], 3],
   [['d1', 'd5', 'd2'], ['A', 'B', 'A'], 'tie'])],
 [('shared top document is placed once',
   [['d1', 'd2', 'd3'], ['d1', 'd3', 'd4'], [0, 1], [1], 4],
   [['d1', 'd3', 'd4', 'd2'], ['A', 'B', 'B', 'A'], 'B']),
  ('coins are consumed only on ties',
   [['d1', 'd2', 'd3'], ['d4', 'd5', 'd6'], [1, 0], [0, 3], 6],
   [['d4', 'd1', 'd2', 'd5', 'd6', 'd3'], ['B', 'A', 'A', 'B', 'B', 'A'], 'B']),
  ('team behind picks next',
   [['d1', 'd2'], ['d3', 'd4'], [0], [2], 4],
   [['d1', 'd3', 'd2', 'd4'], ['A', 'B', 'A', 'B'], 'A']),
  ('exhausted ranking yields',
   [['d1'], ['d2', 'd3', 'd4'], [0], [3], 4],
   [['d1', 'd2', 'd3', 'd4'], ['A', 'B', 'B', 'B'], 'B']),
  ('no clicks is a tie', [['d1', 'd2'], ['d3'], [1], [], 3], [['d3', 'd1', 'd2'], ['B', 'A', 'A'], 'tie']),
  ('query sample 10',
   [['d4', 'd2', 'd1', 'd3'], ['d2', 'd3', 'd1'], [0, 0, 1], [1, 2], 6],
   [['d4', 'd2', 'd1', 'd3'], ['A', 'B', 'A', 'B'], 'tie']),
  ('query sample 21',
   [['d5', 'd3'], ['d2', 'd3', 'd6', 'd4', 'd5'], [1, 1], [], 5],
   [['d2', 'd5', 'd3', 'd6', 'd4'], ['B', 'A', 'B', 'B', 'B'], 'tie']),
  ('query sample 22',
   [['d1', 'd4'], ['d1', 'd6', 'd3', 'd5', 'd2'], [0], [4], 4],
   [['d1', 'd6', 'd4', 'd3'], ['A', 'B', 'A', 'B'], 'tie'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Tie-break draws no longer follow the logged coin sequence, so replays disagree.

Build an interleaved list of up to length documents. Each round both teams skip documents already placed; when both teams have the same number of picks, the next coin (cycled, consumed only on ties) chooses A on 0 and B on 1; otherwise the team with fewer picks goes. An exhausted team yields to the other. Clicks are positions; each credits the team that placed that document. Return [documents, teams, winner A/B/tie].

split: open-access


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

N = 1
observations = []
def solve(rank_a, rank_b, coins, clicks, length):
    out, team = [], []
    ia = ib = ci = 0
    while len(out) < length:
        while ia < len(rank_a) and rank_a[ia] in out:
            ia += 1
        while ib < len(rank_b) and rank_b[ib] in out:
            ib += 1
        has_a, has_b = ia < len(rank_a), ib < len(rank_b)
        if not has_a and not has_b:
            break
        na, nb = team.count('A'), team.count('B')
        if na == nb:
            pick_a = coins[ci % len(coins)] == 0
            ci += 1
        else:
            pick_a = na > nb
        if pick_a and not has_a:
            pick_a = False
        elif not pick_a and not has_b:
            pick_a = True
        if pick_a:
            out.append(rank_a[ia])
            team.append('A')
        else:
            out.append(rank_b[ib])
            team.append('B')
    credit_a = sum(1 for i in clicks if i < len(out) and team[i] == 'A')
    credit_b = sum(1 for i in clicks if i < len(out) and team[i] == 'B')
    winner = 'A' if credit_a > credit_b else 'B' if credit_b > credit_a else 'tie'
    return [out, team, winner]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('shared top document is placed once',
   [['d1', 'd2', 'd3'], ['d1', 'd3', 'd4'], [0, 1], [1], 4],
   [['d1', 'd3', 'd4', 'd2'], ['A', 'B', 'B', 'A'], 'B']),
  ('coins are consumed only on ties',
   [['d1', 'd2', 'd3'], ['d4', 'd5', 'd6'], [1, 0], [0, 3], 6],
   [['d4', 'd1', 'd2', 'd5', 'd6', 'd3'], ['B', 'A', 'A', 'B', 'B', 'A'], 'B']),
  ('team behind picks next',
   [['d1', 'd2'], ['d3', 'd4'], [0], [2], 4],
   [['d1', 'd3', 'd2', 'd4'], ['A', 'B', 'A', 'B'], 'A']),
  ('shared document credits the team that placed it',
   [['d1', 'd2'], ['d2', 'd1'], [1], [0], 2],
   [['d2', 'd1'], ['B', 'A'], 'B']),
  ('exhausted ranking yields',
   [['d1'], ['d2', 'd3', 'd4'], [0], [3], 4],
   [['d1', 'd2', 'd3', 'd4'], ['A', 'B', 'B', 'B'], 'B']),
  ('query sample 1',
   [['d4', 'd3', 'd2'], ['d5', 'd6'], [0], [], 6],
   [['d4', 'd5', 'd3', 'd6', 'd2'], ['A', 'B', 'A', 'B', 'A'], 'tie']),
  ('query sample 2',
   [['d6', 'd5', 'd1', 'd2'], ['d6', 'd5'], [1, 1, 1], [], 4],
   [['d6', 'd5', 'd1', 'd2'], ['B', 'A', 'A', 'A'], 'tie']),
  ('query sample 3',
   [['d5', 'd4'], ['d6', 'd3', 'd5', 'd1'], [0], [], 5],
   [['d5', 'd6', 'd4', 'd3', 'd1'], ['A', 'B', 'A', 'B', 'B'], 'tie'])],
 [('coins are consumed only on ties',
   [['d1', 'd2', 'd3'], ['d4', 'd5', 'd6'], [1, 0], [0, 3], 6],
   [['d4', 'd1', 'd2', 'd5', 'd6', 'd3'], ['B', 'A', 'A', 'B', 'B', 'A'], 'B']),
  ('team behind picks next',
   [['d1', 'd2'], ['d3', 'd4'], [0], [2], 4],
   [['d1', 'd3', 'd2', 'd4'], ['A', 'B', 'A', 'B'], 'A']),
  ('shared document credits the team that placed it',
   [['d1', 'd2'], ['d2', 'd1'], [1], [0], 2],
   [['d2', 'd1'], ['B', 'A'], 'B']),
  ('exhausted ranking yields',
   [['d1'], ['d2', 'd3', 'd4'], [0], [3], 4],
   [['d1', 'd2', 'd3', 'd4'], ['A', 'B', 'B', 'B'], 'B']),
  ('no clicks is a tie', [['d1', 'd2'], ['d3'], [1], [], 3], [['d3', 'd1', 'd2'], ['B', 'A', 'A'], 'tie']),
  ('query sample 4',
   [['d5', 'd6'], ['d3', 'd4'], [1, 0], [0, 4], 4],
   [['d3', 'd5', 'd6', 'd4'], ['B', 'A', 'A', 'B'], 'B']),
  ('query sample 6',
   [['d1', 'd4', 'd5'], ['d5', 'd3', 'd2'], [0], [1], 6],
   [['d1', 'd5', 'd4', 'd3', 'd2'], ['A', 'B', 'A', 'B', 'B'], 'B']),
  ('query sample 14',
   [['d2', 'd6', 'd3', 'd5'], ['d1', 'd4', 'd2', 'd5'], [0, 1], [5], 4],
   [['d2', 'd1', 'd4', 'd6'], ['A', 'B', 'B', 'A'], 'tie'])],
 [('shared top document is placed once',
   [['d1', 'd2', 'd3'], ['d1', 'd3', 'd4'], [0, 1], [1], 4],
   [['d1', 'd3', 'd4', 'd2'], ['A', 'B', 'B', 'A'], 'B']),
  ('team behind picks next',
   [['d1', 'd2'], ['d3', 'd4'], [0], [2], 4],
   [['d1', 'd3', 'd2', 'd4'], ['A', 'B', 'A', 'B'], 'A']),
  ('shared document credits the team that placed it',
   [['d1', 'd2'], ['d2', 'd1'], [1], [0], 2],
   [['d2', 'd1'], ['B', 'A'], 'B']),
  ('exhausted ranking yields',
   [['d1'], ['d2', 'd3', 'd4'], [0], [3], 4],
   [['d1', 'd2', 'd3', 'd4'], ['A', 'B', 'B', 'B'], 'B']),
  ('no clicks is a tie', [['d1', 'd2'], ['d3'], [1], [], 3], [['d3', 'd1', 'd2'], ['B', 'A', 'A'], 'tie']),
  ('query sample 11',
   [['d4', 'd2', 'd5'], ['d5', 'd2', 'd1', 'd6'], [1, 0], [], 6],
   [['d5', 'd4', 'd2', 'd1', 'd6'], ['B', 'A', 'A', 'B', 'B'], 'tie']),
  ('query sample 12',
   [['d1', 'd4', 'd5', 'd6', 'd2'], ['d6', 'd2', 'd5'], [0, 1, 0], [], 3],
   [['d1', 'd6', 'd2'], ['A', 'B', 'B'], 'tie']),
  ('query sample 26',
   [['d1', 'd3', 'd5'], ['d1', 'd4', 'd2', 'd5'], [1], [0], 6],
   [['d1', 'd3', 'd4', 'd5', 'd2'], ['B', 'A', 'B', 'A', 'B'], 'B'])],
 [('shared top document is placed once',
   [['d1', 'd2', 'd3'], ['d1', 'd3', 'd4'], [0, 1], [1], 4],
   [['d1', 'd3', 'd4', 'd2'], ['A', 'B', 'B', 'A'], 'B']),
  ('coins are consumed only on ties',
   [['d1', 'd2', 'd3'], ['d4', 'd5', 'd6'], [1, 0], [0, 3], 6],
   [['d4', 'd1', 'd2', 'd5', 'd6', 'd3'], ['B', 'A', 'A', 'B', 'B', 'A'], 'B']),
  ('shared document credits the team that placed it',
   [['d1', 'd2'], ['d2', 'd1'], [1], [0], 2],
   [['d2', 'd1'], ['B', 'A'], 'B']),
  ('exhausted ranking yields',
   [['d1'], ['d2', 'd3', 'd4'], [0], [3], 4],
   [['d1', 'd2', 'd3', 'd4'], ['A', 'B', 'B', 'B'], 'B']),
  ('no clicks is a tie', [['d1', 'd2'], ['d3'], [1], [], 3], [['d3', 'd1', 'd2'], ['B', 'A', 'A'], 'tie']),
  ('query sample 16',
   [['d1', 'd3', 'd4', 'd2'], ['d3', 'd2', 'd1', 'd5'], [0, 1, 1], [], 4],
   [['d1', 'd3', 'd2', 'd4'], ['A', 'B', 'B', 'A'], 'tie']),
  ('query sample 18',
   [['d2', 'd5'], ['d5', 'd4'], [1], [5], 4],
   [['d5', 'd2', 'd4'], ['B', 'A', 'B'], 'tie']),
  ('query sample 35',
   [['d5', 'd6', 'd1', 'd4'], ['d2', 'd5', 'd4', 'd3', 'd1'], [1, 0, 0], [0, 1], 3],
   [['d2', 'd5', 'd6'], ['B', 'A', 'A'], 'tie'])],
 [('shared top document is placed once',
   [['d1', 'd2', 'd3'], ['d1', 'd3', 'd4'], [0, 1], [1], 4],
   [['d1', 'd3', 'd4', 'd2'], ['A', 'B', 'B', 'A'], 'B']),
  ('coins are consumed only on ties',
   [['d1', 'd2', 'd3'], ['d4', 'd5', 'd6'], [1, 0], [0, 3], 6],
   [['d4', 'd1', 'd2', 'd5', 'd6', 'd3'], ['B', 'A', 'A', 'B', 'B', 'A'], 'B']),
  ('team behind picks next',
   [['d1', 'd2'], ['d3', 'd4'], [0], [2], 4],
   [['d1', 'd3', 'd2', 'd4'], ['A', 'B', 'A', 'B'], 'A']),
  ('exhausted ranking yields',
   [['d1'], ['d2', 'd3', 'd4'], [0], [3], 4],
   [['d1', 'd2', 'd3', 'd4'], ['A', 'B', 'B', 'B'], 'B']),
  ('no clicks is a tie', [['d1', 'd2'], ['d3'], [1], [], 3], [['d3', 'd1', 'd2'], ['B', 'A', 'A'], 'tie']),
  ('query sample 21',
   [['d5', 'd3'], ['d2', 'd3', 'd6', 'd4', 'd5'], [1, 1], [], 5],
   [['d2', 'd5', 'd3', 'd6', 'd4'], ['B', 'A', 'B', 'B', 'B'], 'tie']),
  ('query sample 25',
   [['d5', 'd3', 'd2'], ['d2', 'd3', 'd4'], [1], [0, 2], 5],
   [['d2', 'd5', 'd3', 'd4'], ['B', 'A', 'B', 'B'], 'B']),
  ('query sample 46',
   [['d4', 'd2', 'd5', 'd6'], ['d2', 'd6'], [1, 1], [], 5],
   [['d2', 'd4', 'd6', 'd5'], ['B', 'A', 'B', 'A'], 'tie'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

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

N = 1
observations = []
def solve(rank_a, rank_b, coins, clicks, length):
    out, team = [], []
    ia = ib = ci = 0
    while len(out) < length:
        while ia < len(rank_a) and rank_a[ia] in out:
            ia += 1
        while ib < len(rank_b) and rank_b[ib] in out:
            ib += 1
        has_a, has_b = ia < len(rank_a), ib < len(rank_b)
        if not has_a and not has_b:
            break
        na, nb = team.count('A'), team.count('B')
        if na == nb:
            pick_a = coins[ci % len(coins)] == 0
            ci += 1
        else:
            pick_a = len(out) % 2 == 0
        if pick_a and not has_a:
            pick_a = False
        elif not pick_a and not has_b:
            pick_a = True
        if pick_a:
            out.append(rank_a[ia])
            team.append('A')
        else:
            out.append(rank_b[ib])
            team.append('B')
    credit_a = sum(1 for i in clicks if i < len(out) and team[i] == 'A')
    credit_b = sum(1 for i in clicks if i < len(out) and team[i] == 'B')
    winner = 'A' if credit_a > credit_b else 'B' if credit_b > credit_a else 'tie'
    return [out, team, winner]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('shared top document is placed once',
   [['d1', 'd2', 'd3'], ['d1', 'd3', 'd4'], [0, 1], [1], 4],
   [['d1', 'd3', 'd4', 'd2'], ['A', 'B', 'B', 'A'], 'B']),
  ('coins are consumed only on ties',
   [['d1', 'd2', 'd3'], ['d4', 'd5', 'd6'], [1, 0], [0, 3], 6],
   [['d4', 'd1', 'd2', 'd5', 'd6', 'd3'], ['B', 'A', 'A', 'B', 'B', 'A'], 'B']),
  ('team behind picks next',
   [['d1', 'd2'], ['d3', 'd4'], [0], [2], 4],
   [['d1', 'd3', 'd2', 'd4'], ['A', 'B', 'A', 'B'], 'A']),
  ('shared document credits the team that placed it',
   [['d1', 'd2'], ['d2', 'd1'], [1], [0], 2],
   [['d2', 'd1'], ['B', 'A'], 'B']),
  ('exhausted ranking yields',
   [['d1'], ['d2', 'd3', 'd4'], [0], [3], 4],
   [['d1', 'd2', 'd3', 'd4'], ['A', 'B', 'B', 'B'], 'B']),
  ('query sample 1',
   [['d4', 'd3', 'd2'], ['d5', 'd6'], [0], [], 6],
   [['d4', 'd5', 'd3', 'd6', 'd2'], ['A', 'B', 'A', 'B', 'A'], 'tie']),
  ('query sample 2',
   [['d6', 'd5', 'd1', 'd2'], ['d6', 'd5'], [1, 1, 1], [], 4],
   [['d6', 'd5', 'd1', 'd2'], ['B', 'A', 'A', 'A'], 'tie']),
  ('query sample 3',
   [['d5', 'd4'], ['d6', 'd3', 'd5', 'd1'], [0], [], 5],
   [['d5', 'd6', 'd4', 'd3', 'd1'], ['A', 'B', 'A', 'B', 'B'], 'tie'])],
 [('coins are consumed only on ties',
   [['d1', 'd2', 'd3'], ['d4', 'd5', 'd6'], [1, 0], [0, 3], 6],
   [['d4', 'd1', 'd2', 'd5', 'd6', 'd3'], ['B', 'A', 'A', 'B', 'B', 'A'], 'B']),
  ('team behind picks next',
   [['d1', 'd2'], ['d3', 'd4'], [0], [2], 4],
   [['d1', 'd3', 'd2', 'd4'], ['A', 'B', 'A', 'B'], 'A']),
  ('shared document credits the team that placed it',
   [['d1', 'd2'], ['d2', 'd1'], [1], [0], 2],
   [['d2', 'd1'], ['B', 'A'], 'B']),
  ('exhausted ranking yields',
   [['d1'], ['d2', 'd3', 'd4'], [0], [3], 4],
   [['d1', 'd2', 'd3', 'd4'], ['A', 'B', 'B', 'B'], 'B']),
  ('no clicks is a tie', [['d1', 'd2'], ['d3'], [1], [], 3], [['d3', 'd1', 'd2'], ['B', 'A', 'A'], 'tie']),
  ('query sample 4',
   [['d5', 'd6'], ['d3', 'd4'], [1, 0], [0, 4], 4],
   [['d3', 'd5', 'd6', 'd4'], ['B', 'A', 'A', 'B'], 'B']),
  ('query sample 6',
   [['d1', 'd4', 'd5'], ['d5', 'd3', 'd2'], [0], [1], 6],
   [['d1', 'd5', 'd4', 'd3', 'd2'], ['A', 'B', 'A', 'B', 'B'], 'B']),
  ('query sample 14',
   [['d2', 'd6', 'd3', 'd5'], ['d1', 'd4', 'd2', 'd5'], [0, 1], [5], 4],
   [['d2', 'd1', 'd4', 'd6'], ['A', 'B', 'B', 'A'], 'tie'])],
 [('shared top document is placed once',
   [['d1', 'd2', 'd3'], ['d1', 'd3', 'd4'], [0, 1], [1], 4],
   [['d1', 'd3', 'd4', 'd2'], ['A', 'B', 'B', 'A'], 'B']),
  ('team behind picks next',
   [['d1', 'd2'], ['d3', 'd4'], [0], [2], 4],
   [['d1', 'd3', 'd2', 'd4'], ['A', 'B', 'A', 'B'], 'A']),
  ('shared document credits the team that placed it',
   [['d1', 'd2'], ['d2', 'd1'], [1], [0], 2],
   [['d2', 'd1'], ['B', 'A'], 'B']),
  ('exhausted ranking yields',
   [['d1'], ['d2', 'd3', 'd4'], [0], [3], 4],
   [['d1', 'd2', 'd3', 'd4'], ['A', 'B', 'B', 'B'], 'B']),
  ('no clicks is a tie', [['d1', 'd2'], ['d3'], [1], [], 3], [['d3', 'd1', 'd2'], ['B', 'A', 'A'], 'tie']),
  ('query sample 11',
   [['d4', 'd2', 'd5'], ['d5', 'd2', 'd1', 'd6'], [1, 0], [], 6],
   [['d5', 'd4', 'd2', 'd1', 'd6'], ['B', 'A', 'A', 'B', 'B'], 'tie']),
  ('query sample 12',
   [['d1', 'd4', 'd5', 'd6', 'd2'], ['d6', 'd2', 'd5'], [0, 1, 0], [], 3],
   [['d1', 'd6', 'd2'], ['A', 'B', 'B'], 'tie']),
  ('query sample 26',
   [['d1', 'd3', 'd5'], ['d1', 'd4', 'd2', 'd5'], [1], [0], 6],
   [['d1', 'd3', 'd4', 'd5', 'd2'], ['B', 'A', 'B', 'A', 'B'], 'B'])],
 [('shared top document is placed once',
   [['d1', 'd2', 'd3'], ['d1', 'd3', 'd4'], [0, 1], [1], 4],
   [['d1', 'd3', 'd4', 'd2'], ['A', 'B', 'B', 'A'], 'B']),
  ('coins are consumed only on ties',
   [['d1', 'd2', 'd3'], ['d4', 'd5', 'd6'], [1, 0], [0, 3], 6],
   [['d4', 'd1', 'd2', 'd5', 'd6', 'd3'], ['B', 'A', 'A', 'B', 'B', 'A'], 'B']),
  ('shared document credits the team that placed it',
   [['d1', 'd2'], ['d2', 'd1'], [1], [0], 2],
   [['d2', 'd1'], ['B', 'A'], 'B']),
  ('exhausted ranking yields',
   [['d1'], ['d2', 'd3', 'd4'], [0], [3], 4],
   [['d1', 'd2', 'd3', 'd4'], ['A', 'B', 'B', 'B'], 'B']),
  ('no clicks is a tie', [['d1', 'd2'], ['d3'], [1], [], 3], [['d3', 'd1', 'd2'], ['B', 'A', 'A'], 'tie']),
  ('query sample 16',
   [['d1', 'd3', 'd4', 'd2'], ['d3', 'd2', 'd1', 'd5'], [0, 1, 1], [], 4],
   [['d1', 'd3', 'd2', 'd4'], ['A', 'B', 'B', 'A'], 'tie']),
  ('query sample 18',
   [['d2', 'd5'], ['d5', 'd4'], [1], [5], 4],
   [['d5', 'd2', 'd4'], ['B', 'A', 'B'], 'tie']),
  ('query sample 35',
   [['d5', 'd6', 'd1', 'd4'], ['d2', 'd5', 'd4', 'd3', 'd1'], [1, 0, 0], [0, 1], 3],
   [['d2', 'd5', 'd6'], ['B', 'A', 'A'], 'tie'])],
 [('shared top document is placed once',
   [['d1', 'd2', 'd3'], ['d1', 'd3', 'd4'], [0, 1], [1], 4],
   [['d1', 'd3', 'd4', 'd2'], ['A', 'B', 'B', 'A'], 'B']),
  ('coins are consumed only on ties',
   [['d1', 'd2', 'd3'], ['d4', 'd5', 'd6'], [1, 0], [0, 3], 6],
   [['d4', 'd1', 'd2', 'd5', 'd6', 'd3'], ['B', 'A', 'A', 'B', 'B', 'A'], 'B']),
  ('team behind picks next',
   [['d1', 'd2'], ['d3', 'd4'], [0], [2], 4],
   [['d1', 'd3', 'd2', 'd4'], ['A', 'B', 'A', 'B'], 'A']),
  ('exhausted ranking yields',
   [['d1'], ['d2', 'd3', 'd4'], [0], [3], 4],
   [['d1', 'd2', 'd3', 'd4'], ['A', 'B', 'B', 'B'], 'B']),
  ('no clicks is a tie', [['d1', 'd2'], ['d3'], [1], [], 3], [['d3', 'd1', 'd2'], ['B', 'A', 'A'], 'tie']),
  ('query sample 21',
   [['d5', 'd3'], ['d2', 'd3', 'd6', 'd4', 'd5'], [1, 1], [], 5],
   [['d2', 'd5', 'd3', 'd6', 'd4'], ['B', 'A', 'B', 'B', 'B'], 'tie']),
  ('query sample 25',
   [['d5', 'd3', 'd2'], ['d2', 'd3', 'd4'], [1], [0, 2], 5],
   [['d2', 'd5', 'd3', 'd4'], ['B', 'A', 'B', 'B'], 'B']),
  ('query sample 46',
   [['d4', 'd2', 'd5', 'd6'], ['d2', 'd6'], [1, 1], [], 5],
   [['d2', 'd4', 'd6', 'd5'], ['B', 'A', 'B', 'A'], 'tie'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
One ranker dominates the interleaved list whenever it wins the first coin.

Build an interleaved list of up to length documents. Each round both teams skip documents already placed; when both teams have the same number of picks, the next coin (cycled, consumed only on ties) chooses A on 0 and B on 1; otherwise the team with fewer picks goes. An exhausted team yields to the other. Clicks are positions; each credits the team that placed that document. Return [documents, teams, winner A/B/tie].

split: open-access


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

N = 1
observations = []
def solve(rank_a, rank_b, coins, clicks, length):
    out, team = [], []
    ia = ib = ci = 0
    while len(out) < length:
        while ia < len(rank_a) and rank_a[ia] in out:
            ia += 1
        while ib < len(rank_b) and rank_b[ib] in out:
            ib += 1
        has_a, has_b = ia < len(rank_a), ib < len(rank_b)
        if not has_a and not has_b:
            break
        na, nb = team.count('A'), team.count('B')
        if na == nb:
            pick_a = coins[ci % len(coins)] == 0
            ci += 1
        else:
            pick_a = na < nb
        if pick_a and not has_a:
            pick_a = False
        elif not pick_a and not has_b:
            pick_a = True
        if pick_a:
            out.append(rank_a[ia])
            team.append('A')
        else:
            out.append(rank_b[ib])
            team.append('B')
    credit_a = sum(1 for i in clicks if i < len(out) and out[i] in rank_a)
    credit_b = sum(1 for i in clicks if i < len(out) and out[i] in rank_b)
    winner = 'A' if credit_a > credit_b else 'B' if credit_b > credit_a else 'tie'
    return [out, team, winner]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('shared top document is placed once',
   [['d1', 'd2', 'd3'], ['d1', 'd3', 'd4'], [0, 1], [1], 4],
   [['d1', 'd3', 'd4', 'd2'], ['A', 'B', 'B', 'A'], 'B']),
  ('coins are consumed only on ties',
   [['d1', 'd2', 'd3'], ['d4', 'd5', 'd6'], [1, 0], [0, 3], 6],
   [['d4', 'd1', 'd2', 'd5', 'd6', 'd3'], ['B', 'A', 'A', 'B', 'B', 'A'], 'B']),
  ('team behind picks next',
   [['d1', 'd2'], ['d3', 'd4'], [0], [2], 4],
   [['d1', 'd3', 'd2', 'd4'], ['A', 'B', 'A', 'B'], 'A']),
  ('shared document credits the team that placed it',
   [['d1', 'd2'], ['d2', 'd1'], [1], [0], 2],
   [['d2', 'd1'], ['B', 'A'], 'B']),
  ('exhausted ranking yields',
   [['d1'], ['d2', 'd3', 'd4'], [0], [3], 4],
   [['d1', 'd2', 'd3', 'd4'], ['A', 'B', 'B', 'B'], 'B']),
  ('query sample 1',
   [['d4', 'd3', 'd2'], ['d5', 'd6'], [0], [], 6],
   [['d4', 'd5', 'd3', 'd6', 'd2'], ['A', 'B', 'A', 'B', 'A'], 'tie']),
  ('query sample 2',
   [['d6', 'd5', 'd1', 'd2'], ['d6', 'd5'], [1, 1, 1], [], 4],
   [['d6', 'd5', 'd1', 'd2'], ['B', 'A', 'A', 'A'], 'tie']),
  ('query sample 3',
   [['d5', 'd4'], ['d6', 'd3', 'd5', 'd1'], [0], [], 5],
   [['d5', 'd6', 'd4', 'd3', 'd1'], ['A', 'B', 'A', 'B', 'B'], 'tie'])],
 [('coins are consumed only on ties',
   [['d1', 'd2', 'd3'], ['d4', 'd5', 'd6'], [1, 0], [0, 3], 6],
   [['d4', 'd1', 'd2', 'd5', 'd6', 'd3'], ['B', 'A', 'A', 'B', 'B', 'A'], 'B']),
  ('team behind picks next',
   [['d1', 'd2'], ['d3', 'd4'], [0], [2], 4],
   [['d1', 'd3', 'd2', 'd4'], ['A', 'B', 'A', 'B'], 'A']),
  ('shared document credits the team that placed it',
   [['d1', 'd2'], ['d2', 'd1'], [1], [0], 2],
   [['d2', 'd1'], ['B', 'A'], 'B']),
  ('exhausted ranking yields',
   [['d1'], ['d2', 'd3', 'd4'], [0], [3], 4],
   [['d1', 'd2', 'd3', 'd4'], ['A', 'B', 'B', 'B'], 'B']),
  ('no clicks is a tie', [['d1', 'd2'], ['d3'], [1], [], 3], [['d3', 'd1', 'd2'], ['B', 'A', 'A'], 'tie']),
  ('query sample 6',
   [['d1', 'd4', 'd5'], ['d5', 'd3', 'd2'], [0], [1], 6],
   [['d1', 'd5', 'd4', 'd3', 'd2'], ['A', 'B', 'A', 'B', 'B'], 'B']),
  ('query sample 7',
   [['d4', 'd1', 'd6'], ['d1', 'd6', 'd2', 'd4', 'd3'], [0, 0, 1], [4, 5], 5],
   [['d4', 'd1', 'd6', 'd2', 'd3'], ['A', 'B', 'A', 'B', 'B'], 'B']),
  ('query sample 31',
   [['d2', 'd4', 'd5', 'd6', 'd3'], ['d1', 'd3'], [1], [2, 5], 5],
   [['d1', 'd2', 'd3', 'd4', 'd5'], ['B', 'A', 'B', 'A', 'A'], 'B'])],
 [('shared top document is placed once',
   [['d1', 'd2', 'd3'], ['d1', 'd3', 'd4'], [0, 1], [1], 4],
   [['d1', 'd3', 'd4', 'd2'], ['A', 'B', 'B', 'A'], 'B']),
  ('team behind picks next',
   [['d1', 'd2'], ['d3', 'd4'], [0], [2], 4],
   [['d1', 'd3', 'd2', 'd4'], ['A', 'B', 'A', 'B'], 'A']),
  ('shared document credits the team that placed it',
   [['d1', 'd2'], ['d2', 'd1'], [1], [0], 2],
   [['d2', 'd1'], ['B', 'A'], 'B']),
  ('exhausted ranking yields',
   [['d1'], ['d2', 'd3', 'd4'], [0], [3], 4],
   [['d1', 'd2', 'd3', 'd4'], ['A', 'B', 'B', 'B'], 'B']),
  ('no clicks is a tie', [['d1', 'd2'], ['d3'], [1], [], 3], [['d3', 'd1', 'd2'], ['B', 'A', 'A'], 'tie']),
  ('query sample 6',
   [['d1', 'd4', 'd5'], ['d5', 'd3', 'd2'], [0], [1], 6],
   [['d1', 'd5', 'd4', 'd3', 'd2'], ['A', 'B', 'A', 'B', 'B'], 'B']),
  ('query sample 11',
   [['d4', 'd2', 'd5'], ['d5', 'd2', 'd1', 'd6'], [1, 0], [], 6],
   [['d5', 'd4', 'd2', 'd1', 'd6'], ['B', 'A', 'A', 'B', 'B'], 'tie']),
  ('query sample 12',
   [['d1', 'd4', 'd5', 'd6', 'd2'], ['d6', 'd2', 'd5'], [0, 1, 0], [], 3],
   [['d1', 'd6', 'd2'], ['A', 'B', 'B'], 'tie'])],
 [('shared top document is placed once',
   [['d1', 'd2', 'd3'], ['d1', 'd3', 'd4'], [0, 1], [1], 4],
   [['d1', 'd3', 'd4', 'd2'], ['A', 'B', 'B', 'A'], 'B']),
  ('coins are consumed only on ties',
   [['d1', 'd2', 'd3'], ['d4', 'd5', 'd6'], [1, 0], [0, 3], 6],
   [['d4', 'd1', 'd2', 'd5', 'd6', 'd3'], ['B', 'A', 'A', 'B', 'B', 'A'], 'B']),
  ('shared document credits the team that placed it',
   [['d1', 'd2'], ['d2', 'd1'], [1], [0], 2],
   [['d2', 'd1'], ['B', 'A'], 'B']),
  ('exhausted ranking yields',
   [['d1'], ['d2', 'd3', 'd4'], [0], [3], 4],
   [['d1', 'd2', 'd3', 'd4'], ['A', 'B', 'B', 'B'], 'B']),
  ('no clicks is a tie', [['d1', 'd2'], ['d3'], [1], [], 3], [['d3', 'd1', 'd2'], ['B', 'A', 'A'], 'tie']),
  ('query sample 16',
   [['d1', 'd3', 'd4', 'd2'], ['d3', 'd2', 'd1', 'd5'], [0, 1, 1], [], 4],
   [['d1', 'd3', 'd2', 'd4'], ['A', 'B', 'B', 'A'], 'tie']),
  ('query sample 17',
   [['d4', 'd2'], ['d3', 'd5', 'd6', 'd4', 'd2'], [1, 1], [], 5],
   [['d3', 'd4', 'd5', 'd2', 'd6'], ['B', 'A', 'B', 'A', 'B'], 'tie']),
  ('query sample 45',
   [['d4', 'd1'], ['d5', 'd2', 'd3', 'd4'], [0, 1], [0, 5], 4],
   [['d4', 'd5', 'd2', 'd1'], ['A', 'B', 'B', 'A'], 'A'])],
 [('shared top document is placed once',
   [['d1', 'd2', 'd3'], ['d1', 'd3', 'd4'], [0, 1], [1], 4],
   [['d1', 'd3', 'd4', 'd2'], ['A', 'B', 'B', 'A'], 'B']),
  ('coins are consumed only on ties',
   [['d1', 'd2', 'd3'], ['d4', 'd5', 'd6'], [1, 0], [0, 3], 6],
   [['d4', 'd1', 'd2', 'd5', 'd6', 'd3'], ['B', 'A', 'A', 'B', 'B', 'A'], 'B']),
  ('team behind picks next',
   [['d1', 'd2'], ['d3', 'd4'], [0], [2], 4],
   [['d1', 'd3', 'd2', 'd4'], ['A', 'B', 'A', 'B'], 'A']),
  ('exhausted ranking yields',
   [['d1'], ['d2', 'd3', 'd4'], [0], [3], 4],
   [['d1', 'd2', 'd3', 'd4'], ['A', 'B', 'B', 'B'], 'B']),
  ('no clicks is a tie', [['d1', 'd2'], ['d3'], [1], [], 3], [['d3', 'd1', 'd2'], ['B', 'A', 'A'], 'tie']),
  ('query sample 21',
   [['d5', 'd3'], ['d2', 'd3', 'd6', 'd4', 'd5'], [1, 1], [], 5],
   [['d2', 'd5', 'd3', 'd6', 'd4'], ['B', 'A', 'B', 'B', 'B'], 'tie']),
  ('query sample 22',
   [['d1', 'd4'], ['d1', 'd6', 'd3', 'd5', 'd2'], [0], [4], 4],
   [['d1', 'd6', 'd4', 'd3'], ['A', 'B', 'A', 'B'], 'tie']),
  ('query sample 25',
   [['d5', 'd3', 'd2'], ['d2', 'd3', 'd4'], [1], [0, 2], 5],
   [['d2', 'd5', 'd3', 'd4'], ['B', 'A', 'B', 'B'], 'B'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(rank_a, rank_b, coins, clicks, length):
    out, team = [], []
    ia = ib = ci = 0
    while len(out) < length:
        while ia < len(rank_a) and rank_a[ia] in out:
            ia += 1
        while ib < len(rank_b) and rank_b[ib] in out:
            ib += 1
        has_a, has_b = ia < len(rank_a), ib < len(rank_b)
        if not has_a and not has_b:
            break
        na, nb = team.count('A'), team.count('B')
        if na == nb:
            pick_a = coins[ci % len(coins)] == 0
            ci += 1
        else:
            pick_a = na < nb
        if pick_a and not has_a:
            pick_a = False
        elif not pick_a and not has_b:
            pick_a = True
        if pick_a:
            out.append(rank_a[ia])
            team.append('A')
        else:
            out.append(rank_b[ib])
            team.append('B')
    credit_a = sum(1 for i in clicks if i < len(out) and out[i] in rank_a and out[i] not in rank_b)
    credit_b = sum(1 for i in clicks if i < len(out) and out[i] in rank_b and out[i] not in rank_a)
    winner = 'A' if credit_a > credit_b else 'B' if credit_b > credit_a else 'tie'
    return [out, team, winner]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('shared top document is placed once',
   [['d1', 'd2', 'd3'], ['d1', 'd3', 'd4'], [0, 1], [1], 4],
   [['d1', 'd3', 'd4', 'd2'], ['A', 'B', 'B', 'A'], 'B']),
  ('coins are consumed only on ties',
   [['d1', 'd2', 'd3'], ['d4', 'd5', 'd6'], [1, 0], [0, 3], 6],
   [['d4', 'd1', 'd2', 'd5', 'd6', 'd3'], ['B', 'A', 'A', 'B', 'B', 'A'], 'B']),
  ('team behind picks next',
   [['d1', 'd2'], ['d3', 'd4'], [0], [2], 4],
   [['d1', 'd3', 'd2', 'd4'], ['A', 'B', 'A', 'B'], 'A']),
  ('shared document credits the team that placed it',
   [['d1', 'd2'], ['d2', 'd1'], [1], [0], 2],
   [['d2', 'd1'], ['B', 'A'], 'B']),
  ('exhausted ranking yields',
   [['d1'], ['d2', 'd3', 'd4'], [0], [3], 4],
   [['d1', 'd2', 'd3', 'd4'], ['A', 'B', 'B', 'B'], 'B']),
  ('query sample 1',
   [['d4', 'd3', 'd2'], ['d5', 'd6'], [0], [], 6],
   [['d4', 'd5', 'd3', 'd6', 'd2'], ['A', 'B', 'A', 'B', 'A'], 'tie']),
  ('query sample 2',
   [['d6', 'd5', 'd1', 'd2'], ['d6', 'd5'], [1, 1, 1], [], 4],
   [['d6', 'd5', 'd1', 'd2'], ['B', 'A', 'A', 'A'], 'tie']),
  ('query sample 3',
   [['d5', 'd4'], ['d6', 'd3', 'd5', 'd1'], [0], [], 5],
   [['d5', 'd6', 'd4', 'd3', 'd1'], ['A', 'B', 'A', 'B', 'B'], 'tie'])],
 [('coins are consumed only on ties',
   [['d1', 'd2', 'd3'], ['d4', 'd5', 'd6'], [1, 0], [0, 3], 6],
   [['d4', 'd1', 'd2', 'd5', 'd6', 'd3'], ['B', 'A', 'A', 'B', 'B', 'A'], 'B']),
  ('team behind picks next',
   [['d1', 'd2'], ['d3', 'd4'], [0], [2], 4],
   [['d1', 'd3', 'd2', 'd4'], ['A', 'B', 'A', 'B'], 'A']),
  ('shared document credits the team that placed it',
   [['d1', 'd2'], ['d2', 'd1'], [1], [0], 2],
   [['d2', 'd1'], ['B', 'A'], 'B']),
  ('exhausted ranking yields',
   [['d1'], ['d2', 'd3', 'd4'], [0], [3], 4],
   [['d1', 'd2', 'd3', 'd4'], ['A', 'B', 'B', 'B'], 'B']),
  ('no clicks is a tie', [['d1', 'd2'], ['d3'], [1], [], 3], [['d3', 'd1', 'd2'], ['B', 'A', 'A'], 'tie']),
  ('query sample 6',
   [['d1', 'd4', 'd5'], ['d5', 'd3', 'd2'], [0], [1], 6],
   [['d1', 'd5', 'd4', 'd3', 'd2'], ['A', 'B', 'A', 'B', 'B'], 'B']),
  ('query sample 7',
   [['d4', 'd1', 'd6'], ['d1', 'd6', 'd2', 'd4', 'd3'], [0, 0, 1], [4, 5], 5],
   [['d4', 'd1', 'd6', 'd2', 'd3'], ['A', 'B', 'A', 'B', 'B'], 'B']),
  ('query sample 31',
   [['d2', 'd4', 'd5', 'd6', 'd3'], ['d1', 'd3'], [1], [2, 5], 5],
   [['d1', 'd2', 'd3', 'd4', 'd5'], ['B', 'A', 'B', 'A', 'A'], 'B'])],
 [('shared top document is placed once',
   [['d1', 'd2', 'd3'], ['d1', 'd3', 'd4'], [0, 1], [1], 4],
   [['d1', 'd3', 'd4', 'd2'], ['A', 'B', 'B', 'A'], 'B']),
  ('team behind picks next',
   [['d1', 'd2'], ['d3', 'd4'], [0], [2], 4],
   [['d1', 'd3', 'd2', 'd4'], ['A', 'B', 'A', 'B'], 'A']),
  ('shared document credits the team that placed it',
   [['d1', 'd2'], ['d2', 'd1'], [1], [0], 2],
   [['d2', 'd1'], ['B', 'A'], 'B']),
  ('exhausted ranking yields',
   [['d1'], ['d2', 'd3', 'd4'], [0], [3], 4],
   [['d1', 'd2', 'd3', 'd4'], ['A', 'B', 'B', 'B'], 'B']),
  ('no clicks is a tie', [['d1', 'd2'], ['d3'], [1], [], 3], [['d3', 'd1', 'd2'], ['B', 'A', 'A'], 'tie']),
  ('query sample 6',
   [['d1', 'd4', 'd5'], ['d5', 'd3', 'd2'], [0], [1], 6],
   [['d1', 'd5', 'd4', 'd3', 'd2'], ['A', 'B', 'A', 'B', 'B'], 'B']),
  ('query sample 11',
   [['d4', 'd2', 'd5'], ['d5', 'd2', 'd1', 'd6'], [1, 0], [], 6],
   [['d5', 'd4', 'd2', 'd1', 'd6'], ['B', 'A', 'A', 'B', 'B'], 'tie']),
  ('query sample 12',
   [['d1', 'd4', 'd5', 'd6', 'd2'], ['d6', 'd2', 'd5'], [0, 1, 0], [], 3],
   [['d1', 'd6', 'd2'], ['A', 'B', 'B'], 'tie'])],
 [('shared top document is placed once',
   [['d1', 'd2', 'd3'], ['d1', 'd3', 'd4'], [0, 1], [1], 4],
   [['d1', 'd3', 'd4', 'd2'], ['A', 'B', 'B', 'A'], 'B']),
  ('coins are consumed only on ties',
   [['d1', 'd2', 'd3'], ['d4', 'd5', 'd6'], [1, 0], [0, 3], 6],
   [['d4', 'd1', 'd2', 'd5', 'd6', 'd3'], ['B', 'A', 'A', 'B', 'B', 'A'], 'B']),
  ('shared document credits the team that placed it',
   [['d1', 'd2'], ['d2', 'd1'], [1], [0], 2],
   [['d2', 'd1'], ['B', 'A'], 'B']),
  ('exhausted ranking yields',
   [['d1'], ['d2', 'd3', 'd4'], [0], [3], 4],
   [['d1', 'd2', 'd3', 'd4'], ['A', 'B', 'B', 'B'], 'B']),
  ('no clicks is a tie', [['d1', 'd2'], ['d3'], [1], [], 3], [['d3', 'd1', 'd2'], ['B', 'A', 'A'], 'tie']),
  ('query sample 16',
   [['d1', 'd3', 'd4', 'd2'], ['d3', 'd2', 'd1', 'd5'], [0, 1, 1], [], 4],
   [['d1', 'd3', 'd2', 'd4'], ['A', 'B', 'B', 'A'], 'tie']),
  ('query sample 17',
   [['d4', 'd2'], ['d3', 'd5', 'd6', 'd4', 'd2'], [1, 1], [], 5],
   [['d3', 'd4', 'd5', 'd2', 'd6'], ['B', 'A', 'B', 'A', 'B'], 'tie']),
  ('query sample 45',
   [['d4', 'd1'], ['d5', 'd2', 'd3', 'd4'], [0, 1], [0, 5], 4],
   [['d4', 'd5', 'd2', 'd1'], ['A', 'B', 'B', 'A'], 'A'])],
 [('shared top document is placed once',
   [['d1', 'd2', 'd3'], ['d1', 'd3', 'd4'], [0, 1], [1], 4],
   [['d1', 'd3', 'd4', 'd2'], ['A', 'B', 'B', 'A'], 'B']),
  ('coins are consumed only on ties',
   [['d1', 'd2', 'd3'], ['d4', 'd5', 'd6'], [1, 0], [0, 3], 6],
   [['d4', 'd1', 'd2', 'd5', 'd6', 'd3'], ['B', 'A', 'A', 'B', 'B', 'A'], 'B']),
  ('team behind picks next',
   [['d1', 'd2'], ['d3', 'd4'], [0], [2], 4],
   [['d1', 'd3', 'd2', 'd4'], ['A', 'B', 'A', 'B'], 'A']),
  ('exhausted ranking yields',
   [['d1'], ['d2', 'd3', 'd4'], [0], [3], 4],
   [['d1', 'd2', 'd3', 'd4'], ['A', 'B', 'B', 'B'], 'B']),
  ('no clicks is a tie', [['d1', 'd2'], ['d3'], [1], [], 3], [['d3', 'd1', 'd2'], ['B', 'A', 'A'], 'tie']),
  ('query sample 21',
   [['d5', 'd3'], ['d2', 'd3', 'd6', 'd4', 'd5'], [1, 1], [], 5],
   [['d2', 'd5', 'd3', 'd6', 'd4'], ['B', 'A', 'B', 'B', 'B'], 'tie']),
  ('query sample 22',
   [['d1', 'd4'], ['d1', 'd6', 'd3', 'd5', 'd2'], [0], [4], 4],
   [['d1', 'd6', 'd4', 'd3'], ['A', 'B', 'A', 'B'], 'tie']),
  ('query sample 25',
   [['d5', 'd3', 'd2'], ['d2', 'd3', 'd4'], [1], [0, 2], 5],
   [['d2', 'd5', 'd3', 'd4'], ['B', 'A', 'B', 'B'], 'B'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Clicks on documents both rankers returned count for both, masking real preferences.

Build an interleaved list of up to length documents. Each round both teams skip documents already placed; when both teams have the same number of picks, the next coin (cycled, consumed only on ties) chooses A on 0 and B on 1; otherwise the team with fewer picks goes. An exhausted team yields to the other. Clicks are positions; each credits the team that placed that document. Return [documents, teams, winner A/B/tie].

split: open-access


prompt:
A result that was significant yesterday becomes insignificant today, breaking always-valid guarantees.

diffs is a stream of paired differences with known variance sigma2; the normal-mixture likelihood ratio after n observations with running mean m is sqrt(sigma2 / (sigma2 + n tau2)) exp(n^2 tau2 m^2 / (2 sigma2 (sigma2 + n tau2))). The always-valid p-value starts at 1 and is the running minimum of 1 / ratio. Return the p-value after each observation rounded to 6.

split: open-access


prompt:
Evidence accumulates too slowly, delaying every decision.

diffs is a stream of paired differences with known variance sigma2; the normal-mixture likelihood ratio after n observations with running mean m is sqrt(sigma2 / (sigma2 + n tau2)) exp(n^2 tau2 m^2 / (2 sigma2 (sigma2 + n tau2))). The always-valid p-value starts at 1 and is the running minimum of 1 / ratio. Return the p-value after each observation rounded to 6.

split: open-access


prompt:
Likelihood ratios are too large for long streams, overstating significance.

diffs is a stream of paired differences with known variance sigma2; the normal-mixture likelihood ratio after n observations with running mean m is sqrt(sigma2 / (sigma2 + n tau2)) exp(n^2 tau2 m^2 / (2 sigma2 (sigma2 + n tau2))). The always-valid p-value starts at 1 and is the running minimum of 1 / ratio. Return the p-value after each observation rounded to 6.

split: open-access


prompt:
One noisy observation swings the evidence regardless of history.

diffs is a stream of paired differences with known variance sigma2; the normal-mixture likelihood ratio after n observations with running mean m is sqrt(sigma2 / (sigma2 + n tau2)) exp(n^2 tau2 m^2 / (2 sigma2 (sigma2 + n tau2))). The always-valid p-value starts at 1 and is the running minimum of 1 / ratio. Return the p-value after each observation rounded to 6.

split: open-access


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

N = 1
observations = []
def solve(events, block_len, washout, schedule):
    sums = {'A': 0.0, 'B': 0.0}
    counts = {'A': 0, 'B': 0}
    excluded = 0
    for minute, value in events:
        b = minute // block_len
        arm = schedule[b % len(schedule)]
        prev = schedule[(b - 1) % len(schedule)] if b > 0 else arm
        if minute - b * block_len < washout:
            excluded += 1
            continue
        sums[arm] += value
        counts[arm] += 1
    means = [round(sums[k] / counts[k], 6) if counts[k] else None for k in ('A', 'B')]
    return means + [excluded]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('no washout when the arm repeats', [[[31, 5], [65, 1]], 30, 10, ['A', 'A', 'B']], [5.0, None, 1]),
  ('washout after a switch', [[[31, 5], [45, 2]], 30, 10, ['A', 'B']], [None, 2.0, 1]),
  ('washout boundary is exclusive', [[[40, 7], [39, 1]], 30, 10, ['A', 'B']], [None, 7.0, 1]),
  ('block boundary minute starts the new block', [[[30, 4], [29, 3]], 30, 0, ['A', 'B']], [3.0, 4.0, 0]),
  ('opening minutes are kept when the schedule ends on the other arm',
   [[[1, 4], [40, 6]], 30, 5, ['A', 'B']],
   [4.0, 6.0, 0]),
  ('first block has no carryover', [[[2, 3], [35, 9]], 30, 5, ['B', 'A', 'A', 'B']], [9.0, 3.0, 0]),
  ('switchback sample 1',
   [[[99, 2], [56, 1], [112, 1], [41, 10], [149, 2], [27, 1], [159, 1]], 60, 5, ['B', 'A', 'A', 'B']],
   [1.5, 4.0, 0]),
  ('switchback sample 2',
   [[[0, 3], [104, 10], [69, 3], [65, 10], [45, 10]], 30, 10, ['A', 'A', 'B']],
   [7.666667, None, 2])],
 [('no washout when the arm repeats', [[[31, 5], [65, 1]], 30, 10, ['A', 'A', 'B']], [5.0, None, 1]),
  ('washout after a switch', [[[31, 5], [45, 2]], 30, 10, ['A', 'B']], [None, 2.0, 1]),
  ('washout boundary is exclusive', [[[40, 7], [39, 1]], 30, 10, ['A', 'B']], [None, 7.0, 1]),
  ('block boundary minute starts the new block', [[[30, 4], [29, 3]], 30, 0, ['A', 'B']], [3.0, 4.0, 0]),
  ('opening minutes are kept when the schedule ends on the other arm',
   [[[1, 4], [40, 6]], 30, 5, ['A', 'B']],
   [4.0, 6.0, 0]),
  ('first block has no carryover', [[[2, 3], [35, 9]], 30, 5, ['B', 'A', 'A', 'B']], [9.0, 3.0, 0]),
  ('switchback sample 6',
   [[[208, 2], [14, 10], [126, 1], [28, 10], [215, 2], [149, 3], [156, 2]], 60, 10, ['A', 'A', 'B']],
   [6.0, 2.5, 1]),
  ('switchback sample 18', [[[5, 3], [24, 1], [24, 10], [38, 1]], 10, 10, ['A', 'B']], [3.0, None, 3])],
 [('no washout when the arm repeats', [[[31, 5], [65, 1]], 30, 10, ['A', 'A', 'B']], [5.0, None, 1]),
  ('washout boundary is exclusive', [[[40, 7], [39, 1]], 30, 10, ['A', 'B']], [None, 7.0, 1]),
  ('block boundary minute starts the new block', [[[30, 4], [29, 3]], 30, 0, ['A', 'B']], [3.0, 4.0, 0]),
  ('opening minutes are kept when the schedule ends on the other arm',
   [[[1, 4], [40, 6]], 30, 5, ['A', 'B']],
   [4.0, 6.0, 0]),
  ('first block has no carryover', [[[2, 3], [35, 9]], 30, 5, ['B', 'A', 'A', 'B']], [9.0, 3.0, 0]),
  ('second cycle wraps the schedule', [[[61, 8], [95, 2]], 30, 5, ['A', 'B']], [None, 2.0, 1]),
  ('switchback sample 11',
   [[[1, 1], [35, 3], [7, 10], [11, 2], [26, 3]], 10, 10, ['A', 'B']],
   [5.5, None, 3]),
  ('switchback sample 53',
   [[[26, 10], [77, 10], [1, 10], [8, 10], [3, 1]], 60, 10, ['A', 'B']],
   [7.75, 10.0, 0])],
 [('no washout when the arm repeats', [[[31, 5], [65, 1]], 30, 10, ['A', 'A', 'B']], [5.0, None, 1]),
  ('block boundary minute starts the new block', [[[30, 4], [29, 3]], 30, 0, ['A', 'B']], [3.0, 4.0, 0]),
  ('opening minutes are kept when the schedule ends on the other arm',
   [[[1, 4], [40, 6]], 30, 5, ['A', 'B']],
   [4.0, 6.0, 0]),
  ('first block has no carryover', [[[2, 3], [35, 9]], 30, 5, ['B', 'A', 'A', 'B']], [9.0, 3.0, 0]),
  ('second cycle wraps the schedule', [[[61, 8], [95, 2]], 30, 5, ['A', 'B']], [None, 2.0, 1]),
  ('late minute in a block rounds down', [[[59, 6]], 30, 0, ['A', 'B']], [None, 6.0, 0]),
  ('switchback sample 16', [[[104, 10], [75, 1], [9, 3]], 30, 10, ['A', 'A', 'B']], [6.5, 1.0, 0]),
  ('switchback sample 17',
   [[[25, 2], [8, 10], [16, 1], [8, 10], [36, 1], [26, 10], [39, 3]], 10, 0, ['A', 'B', 'B']],
   [6.0, 4.333333, 0])],
 [('no washout when the arm repeats', [[[31, 5], [65, 1]], 30, 10, ['A', 'A', 'B']], [5.0, None, 1]),
  ('opening minutes are kept when the schedule ends on the other arm',
   [[[1, 4], [40, 6]], 30, 5, ['A', 'B']],
   [4.0, 6.0, 0]),
  ('first block has no carryover', [[[2, 3], [35, 9]], 30, 5, ['B', 'A', 'A', 'B']], [9.0, 3.0, 0]),
  ('second cycle wraps the schedule', [[[61, 8], [95, 2]], 30, 5, ['A', 'B']], [None, 2.0, 1]),
  ('late minute in a block rounds down', [[[59, 6]], 30, 0, ['A', 'B']], [None, 6.0, 0]),
  ('switchback sample 21', [[[14, 10]], 10, 10, ['B', 'A', 'A', 'B']], [None, None, 1]),
  ('switchback sample 22', [[[16, 2]], 10, 10, ['B', 'A', 'A', 'B']], [None, None, 1]),
  ('switchback sample 37',
   [[[7, 2], [114, 1], [217, 3], [61, 3], [230, 10]], 60, 5, ['A', 'A', 'B']],
   [3.8, None, 0])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(events, block_len, washout, schedule):
    sums = {'A': 0.0, 'B': 0.0}
    counts = {'A': 0, 'B': 0}
    excluded = 0
    for minute, value in events:
        b = minute // block_len
        arm = schedule[b % len(schedule)]
        prev = schedule[(b - 1) % len(schedule)] if b > 0 else arm
        if b > 0 and minute - b * block_len < washout:
            excluded += 1
            continue
        sums[arm] += value
        counts[arm] += 1
    means = [round(sums[k] / counts[k], 6) if counts[k] else None for k in ('A', 'B')]
    return means + [excluded]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('no washout when the arm repeats', [[[31, 5], [65, 1]], 30, 10, ['A', 'A', 'B']], [5.0, None, 1]),
  ('washout after a switch', [[[31, 5], [45, 2]], 30, 10, ['A', 'B']], [None, 2.0, 1]),
  ('washout boundary is exclusive', [[[40, 7], [39, 1]], 30, 10, ['A', 'B']], [None, 7.0, 1]),
  ('block boundary minute starts the new block', [[[30, 4], [29, 3]], 30, 0, ['A', 'B']], [3.0, 4.0, 0]),
  ('opening minutes are kept when the schedule ends on the other arm',
   [[[1, 4], [40, 6]], 30, 5, ['A', 'B']],
   [4.0, 6.0, 0]),
  ('first block has no carryover', [[[2, 3], [35, 9]], 30, 5, ['B', 'A', 'A', 'B']], [9.0, 3.0, 0]),
  ('switchback sample 1',
   [[[99, 2], [56, 1], [112, 1], [41, 10], [149, 2], [27, 1], [159, 1]], 60, 5, ['B', 'A', 'A', 'B']],
   [1.5, 4.0, 0]),
  ('switchback sample 2',
   [[[0, 3], [104, 10], [69, 3], [65, 10], [45, 10]], 30, 10, ['A', 'A', 'B']],
   [7.666667, None, 2])],
 [('no washout when the arm repeats', [[[31, 5], [65, 1]], 30, 10, ['A', 'A', 'B']], [5.0, None, 1]),
  ('washout after a switch', [[[31, 5], [45, 2]], 30, 10, ['A', 'B']], [None, 2.0, 1]),
  ('washout boundary is exclusive', [[[40, 7], [39, 1]], 30, 10, ['A', 'B']], [None, 7.0, 1]),
  ('block boundary minute starts the new block', [[[30, 4], [29, 3]], 30, 0, ['A', 'B']], [3.0, 4.0, 0]),
  ('opening minutes are kept when the schedule ends on the other arm',
   [[[1, 4], [40, 6]], 30, 5, ['A', 'B']],
   [4.0, 6.0, 0]),
  ('first block has no carryover', [[[2, 3], [35, 9]], 30, 5, ['B', 'A', 'A', 'B']], [9.0, 3.0, 0]),
  ('switchback sample 6',
   [[[208, 2], [14, 10], [126, 1], [28, 10], [215, 2], [149, 3], [156, 2]], 60, 10, ['A', 'A', 'B']],
   [6.0, 2.5, 1]),
  ('switchback sample 18', [[[5, 3], [24, 1], [24, 10], [38, 1]], 10, 10, ['A', 'B']], [3.0, None, 3])],
 [('no washout when the arm repeats', [[[31, 5], [65, 1]], 30, 10, ['A', 'A', 'B']], [5.0, None, 1]),
  ('washout boundary is exclusive', [[[40, 7], [39, 1]], 30, 10, ['A', 'B']], [None, 7.0, 1]),
  ('block boundary minute starts the new block', [[[30, 4], [29, 3]], 30, 0, ['A', 'B']], [3.0, 4.0, 0]),
  ('opening minutes are kept when the schedule ends on the other arm',
   [[[1, 4], [40, 6]], 30, 5, ['A', 'B']],
   [4.0, 6.0, 0]),
  ('first block has no carryover', [[[2, 3], [35, 9]], 30, 5, ['B', 'A', 'A', 'B']], [9.0, 3.0, 0]),
  ('second cycle wraps the schedule', [[[61, 8], [95, 2]], 30, 5, ['A', 'B']], [None, 2.0, 1]),
  ('switchback sample 11',
   [[[1, 1], [35, 3], [7, 10], [11, 2], [26, 3]], 10, 10, ['A', 'B']],
   [5.5, None, 3]),
  ('switchback sample 53',
   [[[26, 10], [77, 10], [1, 10], [8, 10], [3, 1]], 60, 10, ['A', 'B']],
   [7.75, 10.0, 0])],
 [('no washout when the arm repeats', [[[31, 5], [65, 1]], 30, 10, ['A', 'A', 'B']], [5.0, None, 1]),
  ('block boundary minute starts the new block', [[[30, 4], [29, 3]], 30, 0, ['A', 'B']], [3.0, 4.0, 0]),
  ('opening minutes are kept when the schedule ends on the other arm',
   [[[1, 4], [40, 6]], 30, 5, ['A', 'B']],
   [4.0, 6.0, 0]),
  ('first block has no carryover', [[[2, 3], [35, 9]], 30, 5, ['B', 'A', 'A', 'B']], [9.0, 3.0, 0]),
  ('second cycle wraps the schedule', [[[61, 8], [95, 2]], 30, 5, ['A', 'B']], [None, 2.0, 1]),
  ('late minute in a block rounds down', [[[59, 6]], 30, 0, ['A', 'B']], [None, 6.0, 0]),
  ('switchback sample 16', [[[104, 10], [75, 1], [9, 3]], 30, 10, ['A', 'A', 'B']], [6.5, 1.0, 0]),
  ('switchback sample 17',
   [[[25, 2], [8, 10], [16, 1], [8, 10], [36, 1], [26, 10], [39, 3]], 10, 0, ['A', 'B', 'B']],
   [6.0, 4.333333, 0])],
 [('no washout when the arm repeats', [[[31, 5], [65, 1]], 30, 10, ['A', 'A', 'B']], [5.0, None, 1]),
  ('opening minutes are kept when the schedule ends on the other arm',
   [[[1, 4], [40, 6]], 30, 5, ['A', 'B']],
   [4.0, 6.0, 0]),
  ('first block has no carryover', [[[2, 3], [35, 9]], 30, 5, ['B', 'A', 'A', 'B']], [9.0, 3.0, 0]),
  ('second cycle wraps the schedule', [[[61, 8], [95, 2]], 30, 5, ['A', 'B']], [None, 2.0, 1]),
  ('late minute in a block rounds down', [[[59, 6]], 30, 0, ['A', 'B']], [None, 6.0, 0]),
  ('switchback sample 21', [[[14, 10]], 10, 10, ['B', 'A', 'A', 'B']], [None, None, 1]),
  ('switchback sample 22', [[[16, 2]], 10, 10, ['B', 'A', 'A', 'B']], [None, None, 1]),
  ('switchback sample 37',
   [[[7, 2], [114, 1], [217, 3], [61, 3], [230, 10]], 60, 5, ['A', 'A', 'B']],
   [3.8, None, 0])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Data after repeated-arm blocks is discarded, wasting sample for no carryover.

Time is split into blocks of block_len minutes; block b runs schedule[b % len(schedule)]. Events [minute, value] in the first washout minutes of a block are excluded only when that block's arm differs from the previous block's arm (block 0 has no previous block). Return [mean A, mean B, excluded count] with None for an arm without events.

split: open-access


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

N = 1
observations = []
def solve(events, block_len, washout, schedule):
    sums = {'A': 0.0, 'B': 0.0}
    counts = {'A': 0, 'B': 0}
    excluded = 0
    for minute, value in events:
        b = minute // block_len
        arm = schedule[b % len(schedule)]
        prev = schedule[(b - 1) % len(schedule)] if b > 0 else arm
        if prev != arm and minute - b * block_len <= washout:
            excluded += 1
            continue
        sums[arm] += value
        counts[arm] += 1
    means = [round(sums[k] / counts[k], 6) if counts[k] else None for k in ('A', 'B')]
    return means + [excluded]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('no washout when the arm repeats', [[[31, 5], [65, 1]], 30, 10, ['A', 'A', 'B']], [5.0, None, 1]),
  ('washout after a switch', [[[31, 5], [45, 2]], 30, 10, ['A', 'B']], [None, 2.0, 1]),
  ('washout boundary is exclusive', [[[40, 7], [39, 1]], 30, 10, ['A', 'B']], [None, 7.0, 1]),
  ('block boundary minute starts the new block', [[[30, 4], [29, 3]], 30, 0, ['A', 'B']], [3.0, 4.0, 0]),
  ('opening minutes are kept when the schedule ends on the other arm',
   [[[1, 4], [40, 6]], 30, 5, ['A', 'B']],
   [4.0, 6.0, 0]),
  ('second cycle wraps the schedule', [[[61, 8], [95, 2]], 30, 5, ['A', 'B']], [None, 2.0, 1]),
  ('switchback sample 1',
   [[[99, 2], [56, 1], [112, 1], [41, 10], [149, 2], [27, 1], [159, 1]], 60, 5, ['B', 'A', 'A', 'B']],
   [1.5, 4.0, 0]),
  ('switchback sample 2',
   [[[0, 3], [104, 10], [69, 3], [65, 10], [45, 10]], 30, 10, ['A', 'A', 'B']],
   [7.666667, None, 2])],
 [('washout after a switch', [[[31, 5], [45, 2]], 30, 10, ['A', 'B']], [None, 2.0, 1]),
  ('washout boundary is exclusive', [[[40, 7], [39, 1]], 30, 10, ['A', 'B']], [None, 7.0, 1]),
  ('block boundary minute starts the new block', [[[30, 4], [29, 3]], 30, 0, ['A', 'B']], [3.0, 4.0, 0]),
  ('opening minutes are kept when the schedule ends on the other arm',
   [[[1, 4], [40, 6]], 30, 5, ['A', 'B']],
   [4.0, 6.0, 0]),
  ('first block has no carryover', [[[2, 3], [35, 9]], 30, 5, ['B', 'A', 'A', 'B']], [9.0, 3.0, 0]),
  ('second cycle wraps the schedule', [[[61, 8], [95, 2]], 30, 5, ['A', 'B']], [None, 2.0, 1]),
  ('switchback sample 6',
   [[[208, 2], [14, 10], [126, 1], [28, 10], [215, 2], [149, 3], [156, 2]], 60, 10, ['A', 'A', 'B']],
   [6.0, 2.5, 1]),
  ('switchback sample 55',
   [[[39, 10], [10, 2], [2, 1], [27, 1], [11, 2], [34, 3]], 10, 5, ['A', 'B', 'B']],
   [5.5, 1.0, 3])],
 [('washout boundary is exclusive', [[[40, 7], [39, 1]], 30, 10, ['A', 'B']], [None, 7.0, 1]),
  ('block boundary minute starts the new block', [[[30, 4], [29, 3]], 30, 0, ['A', 'B']], [3.0, 4.0, 0]),
  ('opening minutes are kept when the schedule ends on the other arm',
   [[[1, 4], [40, 6]], 30, 5, ['A', 'B']],
   [4.0, 6.0, 0]),
  ('first block has no carryover', [[[2, 3], [35, 9]], 30, 5, ['B', 'A', 'A', 'B']], [9.0, 3.0, 0]),
  ('second cycle wraps the schedule', [[[61, 8], [95, 2]], 30, 5, ['A', 'B']], [None, 2.0, 1]),
  ('switchback sample 11',
   [[[1, 1], [35, 3], [7, 10], [11, 2], [26, 3]], 10, 10, ['A', 'B']],
   [5.5, None, 3]),
  ('switchback sample 12', [[[23, 2], [102, 3], [57, 10], [78, 3]], 30, 0, ['A', 'B']], [2.5, 6.5, 0]),
  ('switchback sample 45',
   [[[30, 1], [39, 3], [1, 3], [6, 10], [4, 3], [11, 1], [13, 2], [24, 3]], 10, 10, ['A', 'B']],
   [5.333333, None, 5])],
 [('washout boundary is exclusive', [[[40, 7], [39, 1]], 30, 10, ['A', 'B']], [None, 7.0, 1]),
  ('block boundary minute starts the new block', [[[30, 4], [29, 3]], 30, 0, ['A', 'B']], [3.0, 4.0, 0]),
  ('opening minutes are kept when the schedule ends on the other arm',
   [[[1, 4], [40, 6]], 30, 5, ['A', 'B']],
   [4.0, 6.0, 0]),
  ('first block has no carryover', [[[2, 3], [35, 9]], 30, 5, ['B', 'A', 'A', 'B']], [9.0, 3.0, 0]),
  ('second cycle wraps the schedule', [[[61, 8], [95, 2]], 30, 5, ['A', 'B']], [None, 2.0, 1]),
  ('late minute in a block rounds down', [[[59, 6]], 30, 0, ['A', 'B']], [None, 6.0, 0]),
  ('switchback sample 7', [[[39, 2], [28, 3], [74, 2], [47, 1]], 30, 10, ['A', 'B']], [2.5, 1.0, 1]),
  ('switchback sample 16', [[[104, 10], [75, 1], [9, 3]], 30, 10, ['A', 'A', 'B']], [6.5, 1.0, 0])],
 [('no washout when the arm repeats', [[[31, 5], [65, 1]], 30, 10, ['A', 'A', 'B']], [5.0, None, 1]),
  ('washout boundary is exclusive', [[[40, 7], [39, 1]], 30, 10, ['A', 'B']], [None, 7.0, 1]),
  ('opening minutes are kept when the schedule ends on the other arm',
   [[[1, 4], [40, 6]], 30, 5, ['A', 'B']],
   [4.0, 6.0, 0]),
  ('first block has no carryover', [[[2, 3], [35, 9]], 30, 5, ['B', 'A', 'A', 'B']], [9.0, 3.0, 0]),
  ('second cycle wraps the schedule', [[[61, 8], [95, 2]], 30, 5, ['A', 'B']], [None, 2.0, 1]),
  ('late minute in a block rounds down', [[[59, 6]], 30, 0, ['A', 'B']], [None, 6.0, 0]),
  ('switchback sample 2',
   [[[0, 3], [104, 10], [69, 3], [65, 10], [45, 10]], 30, 10, ['A', 'A', 'B']],
   [7.666667, None, 2]),
  ('switchback sample 21', [[[14, 10]], 10, 10, ['B', 'A', 'A', 'B']], [None, None, 1])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(events, block_len, washout, schedule):
    sums = {'A': 0.0, 'B': 0.0}
    counts = {'A': 0, 'B': 0}
    excluded = 0
    for minute, value in events:
        b = minute // block_len
        arm = schedule[b % len(schedule)]
        prev = schedule[(b - 1) % len(schedule)] if b > 0 else arm
        if prev != arm and minute - b * block_len < washout - 1:
            excluded += 1
            continue
        sums[arm] += value
        counts[arm] += 1
    means = [round(sums[k] / counts[k], 6) if counts[k] else None for k in ('A', 'B')]
    return means + [excluded]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('no washout when the arm repeats', [[[31, 5], [65, 1]], 30, 10, ['A', 'A', 'B']], [5.0, None, 1]),
  ('washout after a switch', [[[31, 5], [45, 2]], 30, 10, ['A', 'B']], [None, 2.0, 1]),
  ('washout boundary is exclusive', [[[40, 7], [39, 1]], 30, 10, ['A', 'B']], [None, 7.0, 1]),
  ('block boundary minute starts the new block', [[[30, 4], [29, 3]], 30, 0, ['A', 'B']], [3.0, 4.0, 0]),
  ('opening minutes are kept when the schedule ends on the other arm',
   [[[1, 4], [40, 6]], 30, 5, ['A', 'B']],
   [4.0, 6.0, 0]),
  ('second cycle wraps the schedule', [[[61, 8], [95, 2]], 30, 5, ['A', 'B']], [None, 2.0, 1]),
  ('switchback sample 1',
   [[[99, 2], [56, 1], [112, 1], [41, 10], [149, 2], [27, 1], [159, 1]], 60, 5, ['B', 'A', 'A', 'B']],
   [1.5, 4.0, 0]),
  ('switchback sample 2',
   [[[0, 3], [104, 10], [69, 3], [65, 10], [45, 10]], 30, 10, ['A', 'A', 'B']],
   [7.666667, None, 2])],
 [('washout after a switch', [[[31, 5], [45, 2]], 30, 10, ['A', 'B']], [None, 2.0, 1]),
  ('washout boundary is exclusive', [[[40, 7], [39, 1]], 30, 10, ['A', 'B']], [None, 7.0, 1]),
  ('block boundary minute starts the new block', [[[30, 4], [29, 3]], 30, 0, ['A', 'B']], [3.0, 4.0, 0]),
  ('opening minutes are kept when the schedule ends on the other arm',
   [[[1, 4], [40, 6]], 30, 5, ['A', 'B']],
   [4.0, 6.0, 0]),
  ('first block has no carryover', [[[2, 3], [35, 9]], 30, 5, ['B', 'A', 'A', 'B']], [9.0, 3.0, 0]),
  ('second cycle wraps the schedule', [[[61, 8], [95, 2]], 30, 5, ['A', 'B']], [None, 2.0, 1]),
  ('switchback sample 6',
   [[[208, 2], [14, 10], [126, 1], [28, 10], [215, 2], [149, 3], [156, 2]], 60, 10, ['A', 'A', 'B']],
   [6.0, 2.5, 1]),
  ('switchback sample 55',
   [[[39, 10], [10, 2], [2, 1], [27, 1], [11, 2], [34, 3]], 10, 5, ['A', 'B', 'B']],
   [5.5, 1.0, 3])],
 [('washout boundary is exclusive', [[[40, 7], [39, 1]], 30, 10, ['A', 'B']], [None, 7.0, 1]),
  ('block boundary minute starts the new block', [[[30, 4], [29, 3]], 30, 0, ['A', 'B']], [3.0, 4.0, 0]),
  ('opening minutes are kept when the schedule ends on the other arm',
   [[[1, 4], [40, 6]], 30, 5, ['A', 'B']],
   [4.0, 6.0, 0]),
  ('first block has no carryover', [[[2, 3], [35, 9]], 30, 5, ['B', 'A', 'A', 'B']], [9.0, 3.0, 0]),
  ('second cycle wraps the schedule', [[[61, 8], [95, 2]], 30, 5, ['A', 'B']], [None, 2.0, 1]),
  ('switchback sample 11',
   [[[1, 1], [35, 3], [7, 10], [11, 2], [26, 3]], 10, 10, ['A', 'B']],
   [5.5, None, 3]),
  ('switchback sample 12', [[[23, 2], [102, 3], [57, 10], [78, 3]], 30, 0, ['A', 'B']], [2.5, 6.5, 0]),
  ('switchback sample 45',
   [[[30, 1], [39, 3], [1, 3], [6, 10], [4, 3], [11, 1], [13, 2], [24, 3]], 10, 10, ['A', 'B']],
   [5.333333, None, 5])],
 [('washout boundary is exclusive', [[[40, 7], [39, 1]], 30, 10, ['A', 'B']], [None, 7.0, 1]),
  ('block boundary minute starts the new block', [[[30, 4], [29, 3]], 30, 0, ['A', 'B']], [3.0, 4.0, 0]),
  ('opening minutes are kept when the schedule ends on the other arm',
   [[[1, 4], [40, 6]], 30, 5, ['A', 'B']],
   [4.0, 6.0, 0]),
  ('first block has no carryover', [[[2, 3], [35, 9]], 30, 5, ['B', 'A', 'A', 'B']], [9.0, 3.0, 0]),
  ('second cycle wraps the schedule', [[[61, 8], [95, 2]], 30, 5, ['A', 'B']], [None, 2.0, 1]),
  ('late minute in a block rounds down', [[[59, 6]], 30, 0, ['A', 'B']], [None, 6.0, 0]),
  ('switchback sample 7', [[[39, 2], [28, 3], [74, 2], [47, 1]], 30, 10, ['A', 'B']], [2.5, 1.0, 1]),
  ('switchback sample 16', [[[104, 10], [75, 1], [9, 3]], 30, 10, ['A', 'A', 'B']], [6.5, 1.0, 0])],
 [('no washout when the arm repeats', [[[31, 5], [65, 1]], 30, 10, ['A', 'A', 'B']], [5.0, None, 1]),
  ('washout boundary is exclusive', [[[40, 7], [39, 1]], 30, 10, ['A', 'B']], [None, 7.0, 1]),
  ('opening minutes are kept when the schedule ends on the other arm',
   [[[1, 4], [40, 6]], 30, 5, ['A', 'B']],
   [4.0, 6.0, 0]),
  ('first block has no carryover', [[[2, 3], [35, 9]], 30, 5, ['B', 'A', 'A', 'B']], [9.0, 3.0, 0]),
  ('second cycle wraps the schedule', [[[61, 8], [95, 2]], 30, 5, ['A', 'B']], [None, 2.0, 1]),
  ('late minute in a block rounds down', [[[59, 6]], 30, 0, ['A', 'B']], [None, 6.0, 0]),
  ('switchback sample 2',
   [[[0, 3], [104, 10], [69, 3], [65, 10], [45, 10]], 30, 10, ['A', 'A', 'B']],
   [7.666667, None, 2]),
  ('switchback sample 21', [[[14, 10]], 10, 10, ['B', 'A', 'A', 'B']], [None, None, 1])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Events at exactly the washout offset are discarded.

Time is split into blocks of block_len minutes; block b runs schedule[b % len(schedule)]. Events [minute, value] in the first washout minutes of a block are excluded only when that block's arm differs from the previous block's arm (block 0 has no previous block). Return [mean A, mean B, excluded count] with None for an arm without events.

split: open-access


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

N = 1
observations = []
def solve(events, block_len, washout, schedule):
    sums = {'A': 0.0, 'B': 0.0}
    counts = {'A': 0, 'B': 0}
    excluded = 0
    for minute, value in events:
        b = round(minute / block_len)
        arm = schedule[b % len(schedule)]
        prev = schedule[(b - 1) % len(schedule)] if b > 0 else arm
        if prev != arm and minute - b * block_len < washout:
            excluded += 1
            continue
        sums[arm] += value
        counts[arm] += 1
    means = [round(sums[k] / counts[k], 6) if counts[k] else None for k in ('A', 'B')]
    return means + [excluded]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('no washout when the arm repeats', [[[31, 5], [65, 1]], 30, 10, ['A', 'A', 'B']], [5.0, None, 1]),
  ('washout after a switch', [[[31, 5], [45, 2]], 30, 10, ['A', 'B']], [None, 2.0, 1]),
  ('washout boundary is exclusive', [[[40, 7], [39, 1]], 30, 10, ['A', 'B']], [None, 7.0, 1]),
  ('block boundary minute starts the new block', [[[30, 4], [29, 3]], 30, 0, ['A', 'B']], [3.0, 4.0, 0]),
  ('opening minutes are kept when the schedule ends on the other arm',
   [[[1, 4], [40, 6]], 30, 5, ['A', 'B']],
   [4.0, 6.0, 0]),
  ('late minute in a block rounds down', [[[59, 6]], 30, 0, ['A', 'B']], [None, 6.0, 0]),
  ('switchback sample 1',
   [[[99, 2], [56, 1], [112, 1], [41, 10], [149, 2], [27, 1], [159, 1]], 60, 5, ['B', 'A', 'A', 'B']],
   [1.5, 4.0, 0]),
  ('switchback sample 2',
   [[[0, 3], [104, 10], [69, 3], [65, 10], [45, 10]], 30, 10, ['A', 'A', 'B']],
   [7.666667, None, 2])],
 [('washout after a switch', [[[31, 5], [45, 2]], 30, 10, ['A', 'B']], [None, 2.0, 1]),
  ('washout boundary is exclusive', [[[40, 7], [39, 1]], 30, 10, ['A', 'B']], [None, 7.0, 1]),
  ('block boundary minute starts the new block', [[[30, 4], [29, 3]], 30, 0, ['A', 'B']], [3.0, 4.0, 0]),
  ('opening minutes are kept when the schedule ends on the other arm',
   [[[1, 4], [40, 6]], 30, 5, ['A', 'B']],
   [4.0, 6.0, 0]),
  ('first block has no carryover', [[[2, 3], [35, 9]], 30, 5, ['B', 'A', 'A', 'B']], [9.0, 3.0, 0]),
  ('late minute in a block rounds down', [[[59, 6]], 30, 0, ['A', 'B']], [None, 6.0, 0]),
  ('switchback sample 6',
   [[[208, 2], [14, 10], [126, 1], [28, 10], [215, 2], [149, 3], [156, 2]], 60, 10, ['A', 'A', 'B']],
   [6.0, 2.5, 1]),
  ('switchback sample 52',
   [[[2, 2], [3, 3], [25, 1], [10, 10], [7, 3], [17, 3]], 10, 0, ['A', 'B', 'B']],
   [2.666667, 4.666667, 0])],
 [('washout boundary is exclusive', [[[40, 7], [39, 1]], 30, 10, ['A', 'B']], [None, 7.0, 1]),
  ('block boundary minute starts the new block', [[[30, 4], [29, 3]], 30, 0, ['A', 'B']], [3.0, 4.0, 0]),
  ('opening minutes are kept when the schedule ends on the other arm',
   [[[1, 4], [40, 6]], 30, 5, ['A', 'B']],
   [4.0, 6.0, 0]),
  ('first block has no carryover', [[[2, 3], [35, 9]], 30, 5, ['B', 'A', 'A', 'B']], [9.0, 3.0, 0]),
  ('second cycle wraps the schedule', [[[61, 8], [95, 2]], 30, 5, ['A', 'B']], [None, 2.0, 1]),
  ('switchback sample 11',
   [[[1, 1], [35, 3], [7, 10], [11, 2], [26, 3]], 10, 10, ['A', 'B']],
   [5.5, None, 3]),
  ('switchback sample 15',
   [[[94, 2], [33, 3], [40, 3], [77, 2]], 30, 0, ['B', 'A', 'A', 'B']],
   [2.666667, 2.0, 0]),
  ('switchback sample 23',
   [[[14, 3], [37, 2], [5, 2], [0, 3]], 10, 10, ['A', 'A', 'B']],
   [2.666667, None, 1])],
 [('block boundary minute starts the new block', [[[30, 4], [29, 3]], 30, 0, ['A', 'B']], [3.0, 4.0, 0]),
  ('opening minutes are kept when the schedule ends on the other arm',
   [[[1, 4], [40, 6]], 30, 5, ['A', 'B']],
   [4.0, 6.0, 0]),
  ('first block has no carryover', [[[2, 3], [35, 9]], 30, 5, ['B', 'A', 'A', 'B']], [9.0, 3.0, 0]),
  ('second cycle wraps the schedule', [[[61, 8], [95, 2]], 30, 5, ['A', 'B']], [None, 2.0, 1]),
  ('late minute in a block rounds down', [[[59, 6]], 30, 0, ['A', 'B']], [None, 6.0, 0]),
  ('switchback sample 16', [[[104, 10], [75, 1], [9, 3]], 30, 10, ['A', 'A', 'B']], [6.5, 1.0, 0]),
  ('switchback sample 25',
   [[[3, 1], [68, 10], [66, 2], [84, 10], [10, 2], [11, 10]], 30, 0, ['A', 'B', 'B']],
   [4.333333, 7.333333, 0]),
  ('switchback sample 59',
   [[[20, 3], [23, 1], [39, 3], [2, 1], [7, 1], [30, 1], [27, 10]], 10, 5, ['A', 'A', 'B']],
   [1.666667, 10.0, 3])],
 [('no washout when the arm repeats', [[[31, 5], [65, 1]], 30, 10, ['A', 'A', 'B']], [5.0, None, 1]),
  ('opening minutes are kept when the schedule ends on the other arm',
   [[[1, 4], [40, 6]], 30, 5, ['A', 'B']],
   [4.0, 6.0, 0]),
  ('first block has no carryover', [[[2, 3], [35, 9]], 30, 5, ['B', 'A', 'A', 'B']], [9.0, 3.0, 0]),
  ('second cycle wraps the schedule', [[[61, 8], [95, 2]], 30, 5, ['A', 'B']], [None, 2.0, 1]),
  ('late minute in a block rounds down', [[[59, 6]], 30, 0, ['A', 'B']], [None, 6.0, 0]),
  ('switchback sample 21', [[[14, 10]], 10, 10, ['B', 'A', 'A', 'B']], [None, None, 1]),
  ('switchback sample 35',
   [[[31, 10], [15, 10], [71, 10], [211, 3], [196, 10], [195, 1], [59, 2], [108, 3]],
    60,
    10,
    ['A', 'A', 'B']],
   [6.125, None, 0]),
  ('switchback sample 46',
   [[[30, 1], [12, 2], [34, 3], [34, 1]], 10, 10, ['B', 'A', 'A', 'B']],
   [None, None, 4])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(events, block_len, washout, schedule):
    sums = {'A': 0.0, 'B': 0.0}
    counts = {'A': 0, 'B': 0}
    excluded = 0
    for minute, value in events:
        b = (minute - 1) // block_len
        arm = schedule[b % len(schedule)]
        prev = schedule[(b - 1) % len(schedule)] if b > 0 else arm
        if prev != arm and minute - b * block_len < washout:
            excluded += 1
            continue
        sums[arm] += value
        counts[arm] += 1
    means = [round(sums[k] / counts[k], 6) if counts[k] else None for k in ('A', 'B')]
    return means + [excluded]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('no washout when the arm repeats', [[[31, 5], [65, 1]], 30, 10, ['A', 'A', 'B']], [5.0, None, 1]),
  ('washout after a switch', [[[31, 5], [45, 2]], 30, 10, ['A', 'B']], [None, 2.0, 1]),
  ('washout boundary is exclusive', [[[40, 7], [39, 1]], 30, 10, ['A', 'B']], [None, 7.0, 1]),
  ('block boundary minute starts the new block', [[[30, 4], [29, 3]], 30, 0, ['A', 'B']], [3.0, 4.0, 0]),
  ('opening minutes are kept when the schedule ends on the other arm',
   [[[1, 4], [40, 6]], 30, 5, ['A', 'B']],
   [4.0, 6.0, 0]),
  ('late minute in a block rounds down', [[[59, 6]], 30, 0, ['A', 'B']], [None, 6.0, 0]),
  ('switchback sample 1',
   [[[99, 2], [56, 1], [112, 1], [41, 10], [149, 2], [27, 1], [159, 1]], 60, 5, ['B', 'A', 'A', 'B']],
   [1.5, 4.0, 0]),
  ('switchback sample 2',
   [[[0, 3], [104, 10], [69, 3], [65, 10], [45, 10]], 30, 10, ['A', 'A', 'B']],
   [7.666667, None, 2])],
 [('washout after a switch', [[[31, 5], [45, 2]], 30, 10, ['A', 'B']], [None, 2.0, 1]),
  ('washout boundary is exclusive', [[[40, 7], [39, 1]], 30, 10, ['A', 'B']], [None, 7.0, 1]),
  ('block boundary minute starts the new block', [[[30, 4], [29, 3]], 30, 0, ['A', 'B']], [3.0, 4.0, 0]),
  ('opening minutes are kept when the schedule ends on the other arm',
   [[[1, 4], [40, 6]], 30, 5, ['A', 'B']],
   [4.0, 6.0, 0]),
  ('first block has no carryover', [[[2, 3], [35, 9]], 30, 5, ['B', 'A', 'A', 'B']], [9.0, 3.0, 0]),
  ('late minute in a block rounds down', [[[59, 6]], 30, 0, ['A', 'B']], [None, 6.0, 0]),
  ('switchback sample 6',
   [[[208, 2], [14, 10], [126, 1], [28, 10], [215, 2], [149, 3], [156, 2]], 60, 10, ['A', 'A', 'B']],
   [6.0, 2.5, 1]),
  ('switchback sample 52',
   [[[2, 2], [3, 3], [25, 1], [10, 10], [7, 3], [17, 3]], 10, 0, ['A', 'B', 'B']],
   [2.666667, 4.666667, 0])],
 [('washout boundary is exclusive', [[[40, 7], [39, 1]], 30, 10, ['A', 'B']], [None, 7.0, 1]),
  ('block boundary minute starts the new block', [[[30, 4], [29, 3]], 30, 0, ['A', 'B']], [3.0, 4.0, 0]),
  ('opening minutes are kept when the schedule ends on the other arm',
   [[[1, 4], [40, 6]], 30, 5, ['A', 'B']],
   [4.0, 6.0, 0]),
  ('first block has no carryover', [[[2, 3], [35, 9]], 30, 5, ['B', 'A', 'A', 'B']], [9.0, 3.0, 0]),
  ('second cycle wraps the schedule', [[[61, 8], [95, 2]], 30, 5, ['A', 'B']], [None, 2.0, 1]),
  ('switchback sample 11',
   [[[1, 1], [35, 3], [7, 10], [11, 2], [26, 3]], 10, 10, ['A', 'B']],
   [5.5, None, 3]),
  ('switchback sample 15',
   [[[94, 2], [33, 3], [40, 3], [77, 2]], 30, 0, ['B', 'A', 'A', 'B']],
   [2.666667, 2.0, 0]),
  ('switchback sample 23',
   [[[14, 3], [37, 2], [5, 2], [0, 3]], 10, 10, ['A', 'A', 'B']],
   [2.666667, None, 1])],
 [('block boundary minute starts the new block', [[[30, 4], [29, 3]], 30, 0, ['A', 'B']], [3.0, 4.0, 0]),
  ('opening minutes are kept when the schedule ends on the other arm',
   [[[1, 4], [40, 6]], 30, 5, ['A', 'B']],
   [4.0, 6.0, 0]),
  ('first block has no carryover', [[[2, 3], [35, 9]], 30, 5, ['B', 'A', 'A', 'B']], [9.0, 3.0, 0]),
  ('second cycle wraps the schedule', [[[61, 8], [95, 2]], 30, 5, ['A', 'B']], [None, 2.0, 1]),
  ('late minute in a block rounds down', [[[59, 6]], 30, 0, ['A', 'B']], [None, 6.0, 0]),
  ('switchback sample 16', [[[104, 10], [75, 1], [9, 3]], 30, 10, ['A', 'A', 'B']], [6.5, 1.0, 0]),
  ('switchback sample 25',
   [[[3, 1], [68, 10], [66, 2], [84, 10], [10, 2], [11, 10]], 30, 0, ['A', 'B', 'B']],
   [4.333333, 7.333333, 0]),
  ('switchback sample 59',
   [[[20, 3], [23, 1], [39, 3], [2, 1], [7, 1], [30, 1], [27, 10]], 10, 5, ['A', 'A', 'B']],
   [1.666667, 10.0, 3])],
 [('no washout when the arm repeats', [[[31, 5], [65, 1]], 30, 10, ['A', 'A', 'B']], [5.0, None, 1]),
  ('opening minutes are kept when the schedule ends on the other arm',
   [[[1, 4], [40, 6]], 30, 5, ['A', 'B']],
   [4.0, 6.0, 0]),
  ('first block has no carryover', [[[2, 3], [35, 9]], 30, 5, ['B', 'A', 'A', 'B']], [9.0, 3.0, 0]),
  ('second cycle wraps the schedule', [[[61, 8], [95, 2]], 30, 5, ['A', 'B']], [None, 2.0, 1]),
  ('late minute in a block rounds down', [[[59, 6]], 30, 0, ['A', 'B']], [None, 6.0, 0]),
  ('switchback sample 21', [[[14, 10]], 10, 10, ['B', 'A', 'A', 'B']], [None, None, 1]),
  ('switchback sample 35',
   [[[31, 10], [15, 10], [71, 10], [211, 3], [196, 10], [195, 1], [59, 2], [108, 3]],
    60,
    10,
    ['A', 'A', 'B']],
   [6.125, None, 0]),
  ('switchback sample 46',
   [[[30, 1], [12, 2], [34, 3], [34, 1]], 10, 10, ['B', 'A', 'A', 'B']],
   [None, None, 4])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Events late in a block are credited to the next block's arm.

Time is split into blocks of block_len minutes; block b runs schedule[b % len(schedule)]. Events [minute, value] in the first washout minutes of a block are excluded only when that block's arm differs from the previous block's arm (block 0 has no previous block). Return [mean A, mean B, excluded count] with None for an arm without events.

split: open-access


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

N = 1
observations = []
def solve(events, block_len, washout, schedule):
    sums = {'A': 0.0, 'B': 0.0}
    counts = {'A': 0, 'B': 0}
    excluded = 0
    for minute, value in events:
        b = minute // block_len
        arm = schedule[b % len(schedule)]
        prev = schedule[(b - 1) % len(schedule)]
        if prev != arm and minute - b * block_len < washout:
            excluded += 1
            continue
        sums[arm] += value
        counts[arm] += 1
    means = [round(sums[k] / counts[k], 6) if counts[k] else None for k in ('A', 'B')]
    return means + [excluded]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('no washout when the arm repeats', [[[31, 5], [65, 1]], 30, 10, ['A', 'A', 'B']], [5.0, None, 1]),
  ('washout after a switch', [[[31, 5], [45, 2]], 30, 10, ['A', 'B']], [None, 2.0, 1]),
  ('washout boundary is exclusive', [[[40, 7], [39, 1]], 30, 10, ['A', 'B']], [None, 7.0, 1]),
  ('block boundary minute starts the new block', [[[30, 4], [29, 3]], 30, 0, ['A', 'B']], [3.0, 4.0, 0]),
  ('opening minutes are kept when the schedule ends on the other arm',
   [[[1, 4], [40, 6]], 30, 5, ['A', 'B']],
   [4.0, 6.0, 0]),
  ('first block has no carryover', [[[2, 3], [35, 9]], 30, 5, ['B', 'A', 'A', 'B']], [9.0, 3.0, 0]),
  ('switchback sample 1',
   [[[99, 2], [56, 1], [112, 1], [41, 10], [149, 2], [27, 1], [159, 1]], 60, 5, ['B', 'A', 'A', 'B']],
   [1.5, 4.0, 0]),
  ('switchback sample 2',
   [[[0, 3], [104, 10], [69, 3], [65, 10], [45, 10]], 30, 10, ['A', 'A', 'B']],
   [7.666667, None, 2])],
 [('washout after a switch', [[[31, 5], [45, 2]], 30, 10, ['A', 'B']], [None, 2.0, 1]),
  ('washout boundary is exclusive', [[[40, 7], [39, 1]], 30, 10, ['A', 'B']], [None, 7.0, 1]),
  ('block boundary minute starts the new block', [[[30, 4], [29, 3]], 30, 0, ['A', 'B']], [3.0, 4.0, 0]),
  ('opening minutes are kept when the schedule ends on the other arm',
   [[[1, 4], [40, 6]], 30, 5, ['A', 'B']],
   [4.0, 6.0, 0]),
  ('first block has no carryover', [[[2, 3], [35, 9]], 30, 5, ['B', 'A', 'A', 'B']], [9.0, 3.0, 0]),
  ('switchback sample 6',
   [[[208, 2], [14, 10], [126, 1], [28, 10], [215, 2], [149, 3], [156, 2]], 60, 10, ['A', 'A', 'B']],
   [6.0, 2.5, 1]),
  ('switchback sample 21', [[[14, 10]], 10, 10, ['B', 'A', 'A', 'B']], [None, None, 1]),
  ('switchback sample 41',
   [[[96, 3], [9, 1], [43, 2], [66, 3], [91, 2], [7, 10], [4, 1], [9, 3]], 30, 10, ['A', 'B', 'B']],
   [3.75, 2.5, 2])],
 [('washout boundary is exclusive', [[[40, 7], [39, 1]], 30, 10, ['A', 'B']], [None, 7.0, 1]),
  ('block boundary minute starts the new block', [[[30, 4], [29, 3]], 30, 0, ['A', 'B']], [3.0, 4.0, 0]),
  ('opening minutes are kept when the schedule ends on the other arm',
   [[[1, 4], [40, 6]], 30, 5, ['A', 'B']],
   [4.0, 6.0, 0]),
  ('first block has no carryover', [[[2, 3], [35, 9]], 30, 5, ['B', 'A', 'A', 'B']], [9.0, 3.0, 0]),
  ('second cycle wraps the schedule', [[[61, 8], [95, 2]], 30, 5, ['A', 'B']], [None, 2.0, 1]),
  ('switchback sample 2',
   [[[0, 3], [104, 10], [69, 3], [65, 10], [45, 10]], 30, 10, ['A', 'A', 'B']],
   [7.666667, None, 2]),
  ('switchback sample 11',
   [[[1, 1], [35, 3], [7, 10], [11, 2], [26, 3]], 10, 10, ['A', 'B']],
   [5.5, None, 3]),
  ('switchback sample 44', [[[11, 3], [37, 10], [38, 10], [16, 1]], 10, 5, ['A', 'B', 'B']], [10.0, 1.0, 1])],
 [('block boundary minute starts the new block', [[[30, 4], [29, 3]], 30, 0, ['A', 'B']], [3.0, 4.0, 0]),
  ('opening minutes are kept when the schedule ends on the other arm',
   [[[1, 4], [40, 6]], 30, 5, ['A', 'B']],
   [4.0, 6.0, 0]),
  ('first block has no carryover', [[[2, 3], [35, 9]], 30, 5, ['B', 'A', 'A', 'B']], [9.0, 3.0, 0]),
  ('second cycle wraps the schedule', [[[61, 8], [95, 2]], 30, 5, ['A', 'B']], [None, 2.0, 1]),
  ('late minute in a block rounds down', [[[59, 6]], 30, 0, ['A', 'B']], [None, 6.0, 0]),
  ('switchback sample 16', [[[104, 10], [75, 1], [9, 3]], 30, 10, ['A', 'A', 'B']], [6.5, 1.0, 0]),
  ('switchback sample 42',
   [[[8, 1], [37, 2], [27, 1], [1, 10], [27, 3], [38, 10]], 10, 5, ['A', 'B', 'B']],
   [5.75, 2.0, 0]),
  ('switchback sample 59',
   [[[20, 3], [23, 1], [39, 3], [2, 1], [7, 1], [30, 1], [27, 10]], 10, 5, ['A', 'A', 'B']],
   [1.666667, 10.0, 3])],
 [('no washout when the arm repeats', [[[31, 5], [65, 1]], 30, 10, ['A', 'A', 'B']], [5.0, None, 1]),
  ('opening minutes are kept when the schedule ends on the other arm',
   [[[1, 4], [40, 6]], 30, 5, ['A', 'B']],
   [4.0, 6.0, 0]),
  ('first block has no carryover', [[[2, 3], [35, 9]], 30, 5, ['B', 'A', 'A', 'B']], [9.0, 3.0, 0]),
  ('second cycle wraps the schedule', [[[61, 8], [95, 2]], 30, 5, ['A', 'B']], [None, 2.0, 1]),
  ('late minute in a block rounds down', [[[59, 6]], 30, 0, ['A', 'B']], [None, 6.0, 0]),
  ('switchback sample 9',
   [[[91, 10], [112, 10], [87, 10], [7, 3], [110, 1], [37, 10], [43, 2]], 30, 10, ['A', 'B']],
   [6.5, 4.333333, 2]),
  ('switchback sample 18', [[[5, 3], [24, 1], [24, 10], [38, 1]], 10, 10, ['A', 'B']], [3.0, None, 3]),
  ('switchback sample 21', [[[14, 10]], 10, 10, ['B', 'A', 'A', 'B']], [None, None, 1])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(events, block_len, washout, schedule):
    sums = {'A': 0.0, 'B': 0.0}
    counts = {'A': 0, 'B': 0}
    excluded = 0
    for minute, value in events:
        b = minute // block_len
        arm = schedule[b % len(schedule)]
        prev = schedule[(b + 1) % len(schedule)]
        if prev != arm and minute - b * block_len < washout:
            excluded += 1
            continue
        sums[arm] += value
        counts[arm] += 1
    means = [round(sums[k] / counts[k], 6) if counts[k] else None for k in ('A', 'B')]
    return means + [excluded]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('no washout when the arm repeats', [[[31, 5], [65, 1]], 30, 10, ['A', 'A', 'B']], [5.0, None, 1]),
  ('washout after a switch', [[[31, 5], [45, 2]], 30, 10, ['A', 'B']], [None, 2.0, 1]),
  ('washout boundary is exclusive', [[[40, 7], [39, 1]], 30, 10, ['A', 'B']], [None, 7.0, 1]),
  ('block boundary minute starts the new block', [[[30, 4], [29, 3]], 30, 0, ['A', 'B']], [3.0, 4.0, 0]),
  ('opening minutes are kept when the schedule ends on the other arm',
   [[[1, 4], [40, 6]], 30, 5, ['A', 'B']],
   [4.0, 6.0, 0]),
  ('first block has no carryover', [[[2, 3], [35, 9]], 30, 5, ['B', 'A', 'A', 'B']], [9.0, 3.0, 0]),
  ('switchback sample 1',
   [[[99, 2], [56, 1], [112, 1], [41, 10], [149, 2], [27, 1], [159, 1]], 60, 5, ['B', 'A', 'A', 'B']],
   [1.5, 4.0, 0]),
  ('switchback sample 2',
   [[[0, 3], [104, 10], [69, 3], [65, 10], [45, 10]], 30, 10, ['A', 'A', 'B']],
   [7.666667, None, 2])],
 [('washout after a switch', [[[31, 5], [45, 2]], 30, 10, ['A', 'B']], [None, 2.0, 1]),
  ('washout boundary is exclusive', [[[40, 7], [39, 1]], 30, 10, ['A', 'B']], [None, 7.0, 1]),
  ('block boundary minute starts the new block', [[[30, 4], [29, 3]], 30, 0, ['A', 'B']], [3.0, 4.0, 0]),
  ('opening minutes are kept when the schedule ends on the other arm',
   [[[1, 4], [40, 6]], 30, 5, ['A', 'B']],
   [4.0, 6.0, 0]),
  ('first block has no carryover', [[[2, 3], [35, 9]], 30, 5, ['B', 'A', 'A', 'B']], [9.0, 3.0, 0]),
  ('switchback sample 6',
   [[[208, 2], [14, 10], [126, 1], [28, 10], [215, 2], [149, 3], [156, 2]], 60, 10, ['A', 'A', 'B']],
   [6.0, 2.5, 1]),
  ('switchback sample 21', [[[14, 10]], 10, 10, ['B', 'A', 'A', 'B']], [None, None, 1]),
  ('switchback sample 41',
   [[[96, 3], [9, 1], [43, 2], [66, 3], [91, 2], [7, 10], [4, 1], [9, 3]], 30, 10, ['A', 'B', 'B']],
   [3.75, 2.5, 2])],
 [('washout boundary is exclusive', [[[40, 7], [39, 1]], 30, 10, ['A', 'B']], [None, 7.0, 1]),
  ('block boundary minute starts the new block', [[[30, 4], [29, 3]], 30, 0, ['A', 'B']], [3.0, 4.0, 0]),
  ('opening minutes are kept when the schedule ends on the other arm',
   [[[1, 4], [40, 6]], 30, 5, ['A', 'B']],
   [4.0, 6.0, 0]),
  ('first block has no carryover', [[[2, 3], [35, 9]], 30, 5, ['B', 'A', 'A', 'B']], [9.0, 3.0, 0]),
  ('second cycle wraps the schedule', [[[61, 8], [95, 2]], 30, 5, ['A', 'B']], [None, 2.0, 1]),
  ('switchback sample 2',
   [[[0, 3], [104, 10], [69, 3], [65, 10], [45, 10]], 30, 10, ['A', 'A', 'B']],
   [7.666667, None, 2]),
  ('switchback sample 11',
   [[[1, 1], [35, 3], [7, 10], [11, 2], [26, 3]], 10, 10, ['A', 'B']],
   [5.5, None, 3]),
  ('switchback sample 44', [[[11, 3], [37, 10], [38, 10], [16, 1]], 10, 5, ['A', 'B', 'B']], [10.0, 1.0, 1])],
 [('block boundary minute starts the new block', [[[30, 4], [29, 3]], 30, 0, ['A', 'B']], [3.0, 4.0, 0]),
  ('opening minutes are kept when the schedule ends on the other arm',
   [[[1, 4], [40, 6]], 30, 5, ['A', 'B']],
   [4.0, 6.0, 0]),
  ('first block has no carryover', [[[2, 3], [35, 9]], 30, 5, ['B', 'A', 'A', 'B']], [9.0, 3.0, 0]),
  ('second cycle wraps the schedule', [[[61, 8], [95, 2]], 30, 5, ['A', 'B']], [None, 2.0, 1]),
  ('late minute in a block rounds down', [[[59, 6]], 30, 0, ['A', 'B']], [None, 6.0, 0]),
  ('switchback sample 16', [[[104, 10], [75, 1], [9, 3]], 30, 10, ['A', 'A', 'B']], [6.5, 1.0, 0]),
  ('switchback sample 42',
   [[[8, 1], [37, 2], [27, 1], [1, 10], [27, 3], [38, 10]], 10, 5, ['A', 'B', 'B']],
   [5.75, 2.0, 0]),
  ('switchback sample 59',
   [[[20, 3], [23, 1], [39, 3], [2, 1], [7, 1], [30, 1], [27, 10]], 10, 5, ['A', 'A', 'B']],
   [1.666667, 10.0, 3])],
 [('no washout when the arm repeats', [[[31, 5], [65, 1]], 30, 10, ['A', 'A', 'B']], [5.0, None, 1]),
  ('opening minutes are kept when the schedule ends on the other arm',
   [[[1, 4], [40, 6]], 30, 5, ['A', 'B']],
   [4.0, 6.0, 0]),
  ('first block has no carryover', [[[2, 3], [35, 9]], 30, 5, ['B', 'A', 'A', 'B']], [9.0, 3.0, 0]),
  ('second cycle wraps the schedule', [[[61, 8], [95, 2]], 30, 5, ['A', 'B']], [None, 2.0, 1]),
  ('late minute in a block rounds down', [[[59, 6]], 30, 0, ['A', 'B']], [None, 6.0, 0]),
  ('switchback sample 9',
   [[[91, 10], [112, 10], [87, 10], [7, 3], [110, 1], [37, 10], [43, 2]], 30, 10, ['A', 'B']],
   [6.5, 4.333333, 2]),
  ('switchback sample 18', [[[5, 3], [24, 1], [24, 10], [38, 1]], 10, 10, ['A', 'B']], [3.0, None, 3]),
  ('switchback sample 21', [[[14, 10]], 10, 10, ['B', 'A', 'A', 'B']], [None, None, 1])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Opening minutes of the experiment are washed out as if a switch had occurred.

Time is split into blocks of block_len minutes; block b runs schedule[b % len(schedule)]. Events [minute, value] in the first washout minutes of a block are excluded only when that block's arm differs from the previous block's arm (block 0 has no previous block). Return [mean A, mean B, excluded count] with None for an arm without events.

split: open-access


prompt:
Bounds are reported as log points while the estimate is a percent change.

L = ln(mean_t / mean_c) with standard error sqrt((se_t / mean_t)^2 + (se_c / mean_c)^2). Report the percent change 100 (e^L - 1) and the interval 100 (e^(L -/+ z se) - 1), each rounded to 4. Nonpositive means -> None.

split: open-access


prompt:
Intervals are wrong whenever treatment and control means differ.

L = ln(mean_t / mean_c) with standard error sqrt((se_t / mean_t)^2 + (se_c / mean_c)^2). Report the percent change 100 (e^L - 1) and the interval 100 (e^(L -/+ z se) - 1), each rounded to 4. Nonpositive means -> None.

split: open-access


prompt:
The headline change disagrees with its own interval.

L = ln(mean_t / mean_c) with standard error sqrt((se_t / mean_t)^2 + (se_c / mean_c)^2). Report the percent change 100 (e^L - 1) and the interval 100 (e^(L -/+ z se) - 1), each rounded to 4. Nonpositive means -> None.

split: open-access