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

N = 1
observations = []
def solve(x):
    R='23456789TJQKA'; S='cdhs'
    razz=x['variant']!='stud'
    def rv(c):
        if razz and c[0]=='A': return 1
        return R.index(c[0])+2
    def k(p):
        c=x['up'][p]
        return (rv(c), S.index(c[1]))
    players=sorted(x['up'])
    return max(players, key=k) if razz else min(players, key=k)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('lowest deuce', {'up': {'a': 'Kh', 'b': '2d', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('deuce suit tie', {'up': {'a': '2h', 'b': '2c', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('ace is high in stud', {'up': {'a': 'Ah', 'b': '3d', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('razz ace low', {'up': {'a': 'Ah', 'b': '3d', 'c': 'Ks'}, 'variant': 'razz'}, 'c'),
  ('razz ace vs deuce', {'up': {'a': 'Ah', 'b': '2d', 'c': '5s'}, 'variant': 'razz'}, 'c'),
  ('razz suit tie', {'up': {'a': 'Kc', 'b': 'Ks', 'c': '5s'}, 'variant': 'razz'}, 'b'),
  ('stud8 uses stud rule', {'up': {'a': 'Kh', 'b': '2d', 'c': '9s'}, 'variant': 'stud8'}, 'b'),
  ('stud8 ace high', {'up': {'a': 'Ad', 'b': '4d', 'c': '9s'}, 'variant': 'stud8'}, 'b')],
 [('razz ace low', {'up': {'a': 'Ah', 'b': '3d', 'c': 'Ks'}, 'variant': 'razz'}, 'c'),
  ('razz ace vs deuce', {'up': {'a': 'Ah', 'b': '2d', 'c': '5s'}, 'variant': 'razz'}, 'c'),
  ('razz suit tie', {'up': {'a': 'Kc', 'b': 'Ks', 'c': '5s'}, 'variant': 'razz'}, 'b'),
  ('stud8 uses stud rule', {'up': {'a': 'Kh', 'b': '2d', 'c': '9s'}, 'variant': 'stud8'}, 'b'),
  ('stud8 ace high', {'up': {'a': 'Ad', 'b': '4d', 'c': '9s'}, 'variant': 'stud8'}, 'b'),
  ('spade vs heart tie stud', {'up': {'a': '4s', 'b': '4h', 'c': 'Js'}, 'variant': 'stud'}, 'b'),
  ('diamond vs club tie stud', {'up': {'a': '5d', 'b': '5c'}, 'variant': 'stud'}, 'b'),
  ('razz heart vs diamond', {'up': {'a': 'Qd', 'b': 'Qh', 'c': '2s'}, 'variant': 'razz'}, 'b')],
 [('lowest deuce', {'up': {'a': 'Kh', 'b': '2d', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('deuce suit tie', {'up': {'a': '2h', 'b': '2c', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('ace is high in stud', {'up': {'a': 'Ah', 'b': '3d', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('stud8 uses stud rule', {'up': {'a': 'Kh', 'b': '2d', 'c': '9s'}, 'variant': 'stud8'}, 'b'),
  ('stud8 ace high', {'up': {'a': 'Ad', 'b': '4d', 'c': '9s'}, 'variant': 'stud8'}, 'b'),
  ('spade vs heart tie stud', {'up': {'a': '4s', 'b': '4h', 'c': 'Js'}, 'variant': 'stud'}, 'b'),
  ('diamond vs club tie stud', {'up': {'a': '5d', 'b': '5c'}, 'variant': 'stud'}, 'b'),
  ('razz heart vs diamond', {'up': {'a': 'Qd', 'b': 'Qh', 'c': '2s'}, 'variant': 'razz'}, 'b')],
 [('lowest deuce', {'up': {'a': 'Kh', 'b': '2d', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('deuce suit tie', {'up': {'a': '2h', 'b': '2c', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('ace is high in stud', {'up': {'a': 'Ah', 'b': '3d', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('razz ace low', {'up': {'a': 'Ah', 'b': '3d', 'c': 'Ks'}, 'variant': 'razz'}, 'c'),
  ('razz ace vs deuce', {'up': {'a': 'Ah', 'b': '2d', 'c': '5s'}, 'variant': 'razz'}, 'c'),
  ('razz suit tie', {'up': {'a': 'Kc', 'b': 'Ks', 'c': '5s'}, 'variant': 'razz'}, 'b'),
  ('stud8 uses stud rule', {'up': {'a': 'Kh', 'b': '2d', 'c': '9s'}, 'variant': 'stud8'}, 'b'),
  ('stud8 ace high', {'up': {'a': 'Ad', 'b': '4d', 'c': '9s'}, 'variant': 'stud8'}, 'b')],
 [('deuce suit tie', {'up': {'a': '2h', 'b': '2c', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('ace is high in stud', {'up': {'a': 'Ah', 'b': '3d', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('razz ace low', {'up': {'a': 'Ah', 'b': '3d', 'c': 'Ks'}, 'variant': 'razz'}, 'c'),
  ('razz ace vs deuce', {'up': {'a': 'Ah', 'b': '2d', 'c': '5s'}, 'variant': 'razz'}, 'c'),
  ('razz suit tie', {'up': {'a': 'Kc', 'b': 'Ks', 'c': '5s'}, 'variant': 'razz'}, 'b'),
  ('stud8 uses stud rule', {'up': {'a': 'Kh', 'b': '2d', 'c': '9s'}, 'variant': 'stud8'}, 'b'),
  ('stud8 ace high', {'up': {'a': 'Ad', 'b': '4d', 'c': '9s'}, 'variant': 'stud8'}, 'b'),
  ('spade vs heart tie stud', {'up': {'a': '4s', 'b': '4h', 'c': 'Js'}, 'variant': 'stud'}, 'b')]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'error:' + type(exc).__name__
    check(label, actual, expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    R='23456789TJQKA'; S='cdhs'
    razz=x['variant'][-1]!='d'
    def rv(c):
        if razz and c[0]=='A': return 1
        return R.index(c[0])+2
    def k(p):
        c=x['up'][p]
        return (rv(c), S.index(c[1]))
    players=sorted(x['up'])
    return max(players, key=k) if razz else min(players, key=k)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('lowest deuce', {'up': {'a': 'Kh', 'b': '2d', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('deuce suit tie', {'up': {'a': '2h', 'b': '2c', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('ace is high in stud', {'up': {'a': 'Ah', 'b': '3d', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('razz ace low', {'up': {'a': 'Ah', 'b': '3d', 'c': 'Ks'}, 'variant': 'razz'}, 'c'),
  ('razz ace vs deuce', {'up': {'a': 'Ah', 'b': '2d', 'c': '5s'}, 'variant': 'razz'}, 'c'),
  ('razz suit tie', {'up': {'a': 'Kc', 'b': 'Ks', 'c': '5s'}, 'variant': 'razz'}, 'b'),
  ('stud8 uses stud rule', {'up': {'a': 'Kh', 'b': '2d', 'c': '9s'}, 'variant': 'stud8'}, 'b'),
  ('stud8 ace high', {'up': {'a': 'Ad', 'b': '4d', 'c': '9s'}, 'variant': 'stud8'}, 'b')],
 [('razz ace low', {'up': {'a': 'Ah', 'b': '3d', 'c': 'Ks'}, 'variant': 'razz'}, 'c'),
  ('razz ace vs deuce', {'up': {'a': 'Ah', 'b': '2d', 'c': '5s'}, 'variant': 'razz'}, 'c'),
  ('razz suit tie', {'up': {'a': 'Kc', 'b': 'Ks', 'c': '5s'}, 'variant': 'razz'}, 'b'),
  ('stud8 uses stud rule', {'up': {'a': 'Kh', 'b': '2d', 'c': '9s'}, 'variant': 'stud8'}, 'b'),
  ('stud8 ace high', {'up': {'a': 'Ad', 'b': '4d', 'c': '9s'}, 'variant': 'stud8'}, 'b'),
  ('spade vs heart tie stud', {'up': {'a': '4s', 'b': '4h', 'c': 'Js'}, 'variant': 'stud'}, 'b'),
  ('diamond vs club tie stud', {'up': {'a': '5d', 'b': '5c'}, 'variant': 'stud'}, 'b'),
  ('razz heart vs diamond', {'up': {'a': 'Qd', 'b': 'Qh', 'c': '2s'}, 'variant': 'razz'}, 'b')],
 [('lowest deuce', {'up': {'a': 'Kh', 'b': '2d', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('deuce suit tie', {'up': {'a': '2h', 'b': '2c', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('ace is high in stud', {'up': {'a': 'Ah', 'b': '3d', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('stud8 uses stud rule', {'up': {'a': 'Kh', 'b': '2d', 'c': '9s'}, 'variant': 'stud8'}, 'b'),
  ('stud8 ace high', {'up': {'a': 'Ad', 'b': '4d', 'c': '9s'}, 'variant': 'stud8'}, 'b'),
  ('spade vs heart tie stud', {'up': {'a': '4s', 'b': '4h', 'c': 'Js'}, 'variant': 'stud'}, 'b'),
  ('diamond vs club tie stud', {'up': {'a': '5d', 'b': '5c'}, 'variant': 'stud'}, 'b'),
  ('razz heart vs diamond', {'up': {'a': 'Qd', 'b': 'Qh', 'c': '2s'}, 'variant': 'razz'}, 'b')],
 [('lowest deuce', {'up': {'a': 'Kh', 'b': '2d', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('deuce suit tie', {'up': {'a': '2h', 'b': '2c', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('ace is high in stud', {'up': {'a': 'Ah', 'b': '3d', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('razz ace low', {'up': {'a': 'Ah', 'b': '3d', 'c': 'Ks'}, 'variant': 'razz'}, 'c'),
  ('razz ace vs deuce', {'up': {'a': 'Ah', 'b': '2d', 'c': '5s'}, 'variant': 'razz'}, 'c'),
  ('razz suit tie', {'up': {'a': 'Kc', 'b': 'Ks', 'c': '5s'}, 'variant': 'razz'}, 'b'),
  ('stud8 uses stud rule', {'up': {'a': 'Kh', 'b': '2d', 'c': '9s'}, 'variant': 'stud8'}, 'b'),
  ('stud8 ace high', {'up': {'a': 'Ad', 'b': '4d', 'c': '9s'}, 'variant': 'stud8'}, 'b')],
 [('deuce suit tie', {'up': {'a': '2h', 'b': '2c', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('ace is high in stud', {'up': {'a': 'Ah', 'b': '3d', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('razz ace low', {'up': {'a': 'Ah', 'b': '3d', 'c': 'Ks'}, 'variant': 'razz'}, 'c'),
  ('razz ace vs deuce', {'up': {'a': 'Ah', 'b': '2d', 'c': '5s'}, 'variant': 'razz'}, 'c'),
  ('razz suit tie', {'up': {'a': 'Kc', 'b': 'Ks', 'c': '5s'}, 'variant': 'razz'}, 'b'),
  ('stud8 uses stud rule', {'up': {'a': 'Kh', 'b': '2d', 'c': '9s'}, 'variant': 'stud8'}, 'b'),
  ('stud8 ace high', {'up': {'a': 'Ad', 'b': '4d', 'c': '9s'}, 'variant': 'stud8'}, 'b'),
  ('spade vs heart tie stud', {'up': {'a': '4s', 'b': '4h', 'c': 'Js'}, 'variant': 'stud'}, 'b')]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'error:' + type(exc).__name__
    check(label, actual, 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:
In stud8 the highest card brings in.

Input: {"variant": "stud", "stud8" or "razz", "up": {player: door card}}. In stud and stud8 the lowest door card brings in (ace high); ties are broken by suit with clubs lowest, then diamonds, hearts, spades. In razz the highest door card brings in (ace low), ties going to the highest suit. Return the bring-in player.

split: open-access


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

N = 1
observations = []
def solve(x):
    R='23456789TJQKA'; S='cdhs'
    razz=x['variant']=='razz'
    def rv(c):
        if razz and c[0]=='A': return 1
        return R.index(c[0])+2
    def k(p):
        c=x['up'][p]
        return (rv(c), S.index(c[1]))
    players=sorted(x['up'])
    return min(players, key=k)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('lowest deuce', {'up': {'a': 'Kh', 'b': '2d', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('deuce suit tie', {'up': {'a': '2h', 'b': '2c', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('ace is high in stud', {'up': {'a': 'Ah', 'b': '3d', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('razz ace low', {'up': {'a': 'Ah', 'b': '3d', 'c': 'Ks'}, 'variant': 'razz'}, 'c'),
  ('razz ace vs deuce', {'up': {'a': 'Ah', 'b': '2d', 'c': '5s'}, 'variant': 'razz'}, 'c'),
  ('razz suit tie', {'up': {'a': 'Kc', 'b': 'Ks', 'c': '5s'}, 'variant': 'razz'}, 'b'),
  ('stud8 uses stud rule', {'up': {'a': 'Kh', 'b': '2d', 'c': '9s'}, 'variant': 'stud8'}, 'b'),
  ('stud8 ace high', {'up': {'a': 'Ad', 'b': '4d', 'c': '9s'}, 'variant': 'stud8'}, 'b')],
 [('deuce suit tie', {'up': {'a': '2h', 'b': '2c', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('razz ace low', {'up': {'a': 'Ah', 'b': '3d', 'c': 'Ks'}, 'variant': 'razz'}, 'c'),
  ('razz ace vs deuce', {'up': {'a': 'Ah', 'b': '2d', 'c': '5s'}, 'variant': 'razz'}, 'c'),
  ('razz suit tie', {'up': {'a': 'Kc', 'b': 'Ks', 'c': '5s'}, 'variant': 'razz'}, 'b'),
  ('stud8 ace high', {'up': {'a': 'Ad', 'b': '4d', 'c': '9s'}, 'variant': 'stud8'}, 'b'),
  ('spade vs heart tie stud', {'up': {'a': '4s', 'b': '4h', 'c': 'Js'}, 'variant': 'stud'}, 'b'),
  ('diamond vs club tie stud', {'up': {'a': '5d', 'b': '5c'}, 'variant': 'stud'}, 'b'),
  ('razz heart vs diamond', {'up': {'a': 'Qd', 'b': 'Qh', 'c': '2s'}, 'variant': 'razz'}, 'b')],
 [('lowest deuce', {'up': {'a': 'Kh', 'b': '2d', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('ace is high in stud', {'up': {'a': 'Ah', 'b': '3d', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('razz ace vs deuce', {'up': {'a': 'Ah', 'b': '2d', 'c': '5s'}, 'variant': 'razz'}, 'c'),
  ('razz suit tie', {'up': {'a': 'Kc', 'b': 'Ks', 'c': '5s'}, 'variant': 'razz'}, 'b'),
  ('stud8 uses stud rule', {'up': {'a': 'Kh', 'b': '2d', 'c': '9s'}, 'variant': 'stud8'}, 'b'),
  ('spade vs heart tie stud', {'up': {'a': '4s', 'b': '4h', 'c': 'Js'}, 'variant': 'stud'}, 'b'),
  ('diamond vs club tie stud', {'up': {'a': '5d', 'b': '5c'}, 'variant': 'stud'}, 'b'),
  ('razz heart vs diamond', {'up': {'a': 'Qd', 'b': 'Qh', 'c': '2s'}, 'variant': 'razz'}, 'b')],
 [('lowest deuce', {'up': {'a': 'Kh', 'b': '2d', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('deuce suit tie', {'up': {'a': '2h', 'b': '2c', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('ace is high in stud', {'up': {'a': 'Ah', 'b': '3d', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('razz ace low', {'up': {'a': 'Ah', 'b': '3d', 'c': 'Ks'}, 'variant': 'razz'}, 'c'),
  ('stud8 uses stud rule', {'up': {'a': 'Kh', 'b': '2d', 'c': '9s'}, 'variant': 'stud8'}, 'b'),
  ('stud8 ace high', {'up': {'a': 'Ad', 'b': '4d', 'c': '9s'}, 'variant': 'stud8'}, 'b'),
  ('diamond vs club tie stud', {'up': {'a': '5d', 'b': '5c'}, 'variant': 'stud'}, 'b'),
  ('razz heart vs diamond', {'up': {'a': 'Qd', 'b': 'Qh', 'c': '2s'}, 'variant': 'razz'}, 'b')],
 [('deuce suit tie', {'up': {'a': '2h', 'b': '2c', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('ace is high in stud', {'up': {'a': 'Ah', 'b': '3d', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('razz ace low', {'up': {'a': 'Ah', 'b': '3d', 'c': 'Ks'}, 'variant': 'razz'}, 'c'),
  ('razz ace vs deuce', {'up': {'a': 'Ah', 'b': '2d', 'c': '5s'}, 'variant': 'razz'}, 'c'),
  ('razz suit tie', {'up': {'a': 'Kc', 'b': 'Ks', 'c': '5s'}, 'variant': 'razz'}, 'b'),
  ('stud8 uses stud rule', {'up': {'a': 'Kh', 'b': '2d', 'c': '9s'}, 'variant': 'stud8'}, 'b'),
  ('stud8 ace high', {'up': {'a': 'Ad', 'b': '4d', 'c': '9s'}, 'variant': 'stud8'}, 'b'),
  ('razz heart vs diamond', {'up': {'a': 'Qd', 'b': 'Qh', 'c': '2s'}, 'variant': 'razz'}, 'b')]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'error:' + type(exc).__name__
    check(label, actual, expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

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

N = 1
observations = []
def solve(x):
    R='23456789TJQKA'; S='cdhs'
    razz=x['variant']=='razz'
    def rv(c):
        if razz and c[0]=='A': return 1
        return R.index(c[0])+2
    def k(p):
        c=x['up'][p]
        return (rv(c), S.index(c[1]))
    players=sorted(x['up'])
    return (max if razz else min)(players, key=lambda p: k(p)[0])
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('lowest deuce', {'up': {'a': 'Kh', 'b': '2d', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('deuce suit tie', {'up': {'a': '2h', 'b': '2c', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('ace is high in stud', {'up': {'a': 'Ah', 'b': '3d', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('razz ace low', {'up': {'a': 'Ah', 'b': '3d', 'c': 'Ks'}, 'variant': 'razz'}, 'c'),
  ('razz ace vs deuce', {'up': {'a': 'Ah', 'b': '2d', 'c': '5s'}, 'variant': 'razz'}, 'c'),
  ('razz suit tie', {'up': {'a': 'Kc', 'b': 'Ks', 'c': '5s'}, 'variant': 'razz'}, 'b'),
  ('stud8 uses stud rule', {'up': {'a': 'Kh', 'b': '2d', 'c': '9s'}, 'variant': 'stud8'}, 'b'),
  ('stud8 ace high', {'up': {'a': 'Ad', 'b': '4d', 'c': '9s'}, 'variant': 'stud8'}, 'b')],
 [('deuce suit tie', {'up': {'a': '2h', 'b': '2c', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('razz ace low', {'up': {'a': 'Ah', 'b': '3d', 'c': 'Ks'}, 'variant': 'razz'}, 'c'),
  ('razz ace vs deuce', {'up': {'a': 'Ah', 'b': '2d', 'c': '5s'}, 'variant': 'razz'}, 'c'),
  ('razz suit tie', {'up': {'a': 'Kc', 'b': 'Ks', 'c': '5s'}, 'variant': 'razz'}, 'b'),
  ('stud8 ace high', {'up': {'a': 'Ad', 'b': '4d', 'c': '9s'}, 'variant': 'stud8'}, 'b'),
  ('spade vs heart tie stud', {'up': {'a': '4s', 'b': '4h', 'c': 'Js'}, 'variant': 'stud'}, 'b'),
  ('diamond vs club tie stud', {'up': {'a': '5d', 'b': '5c'}, 'variant': 'stud'}, 'b'),
  ('razz heart vs diamond', {'up': {'a': 'Qd', 'b': 'Qh', 'c': '2s'}, 'variant': 'razz'}, 'b')],
 [('lowest deuce', {'up': {'a': 'Kh', 'b': '2d', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('ace is high in stud', {'up': {'a': 'Ah', 'b': '3d', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('razz ace vs deuce', {'up': {'a': 'Ah', 'b': '2d', 'c': '5s'}, 'variant': 'razz'}, 'c'),
  ('razz suit tie', {'up': {'a': 'Kc', 'b': 'Ks', 'c': '5s'}, 'variant': 'razz'}, 'b'),
  ('stud8 uses stud rule', {'up': {'a': 'Kh', 'b': '2d', 'c': '9s'}, 'variant': 'stud8'}, 'b'),
  ('spade vs heart tie stud', {'up': {'a': '4s', 'b': '4h', 'c': 'Js'}, 'variant': 'stud'}, 'b'),
  ('diamond vs club tie stud', {'up': {'a': '5d', 'b': '5c'}, 'variant': 'stud'}, 'b'),
  ('razz heart vs diamond', {'up': {'a': 'Qd', 'b': 'Qh', 'c': '2s'}, 'variant': 'razz'}, 'b')],
 [('lowest deuce', {'up': {'a': 'Kh', 'b': '2d', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('deuce suit tie', {'up': {'a': '2h', 'b': '2c', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('ace is high in stud', {'up': {'a': 'Ah', 'b': '3d', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('razz ace low', {'up': {'a': 'Ah', 'b': '3d', 'c': 'Ks'}, 'variant': 'razz'}, 'c'),
  ('stud8 uses stud rule', {'up': {'a': 'Kh', 'b': '2d', 'c': '9s'}, 'variant': 'stud8'}, 'b'),
  ('stud8 ace high', {'up': {'a': 'Ad', 'b': '4d', 'c': '9s'}, 'variant': 'stud8'}, 'b'),
  ('diamond vs club tie stud', {'up': {'a': '5d', 'b': '5c'}, 'variant': 'stud'}, 'b'),
  ('razz heart vs diamond', {'up': {'a': 'Qd', 'b': 'Qh', 'c': '2s'}, 'variant': 'razz'}, 'b')],
 [('deuce suit tie', {'up': {'a': '2h', 'b': '2c', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('ace is high in stud', {'up': {'a': 'Ah', 'b': '3d', 'c': '9s'}, 'variant': 'stud'}, 'b'),
  ('razz ace low', {'up': {'a': 'Ah', 'b': '3d', 'c': 'Ks'}, 'variant': 'razz'}, 'c'),
  ('razz ace vs deuce', {'up': {'a': 'Ah', 'b': '2d', 'c': '5s'}, 'variant': 'razz'}, 'c'),
  ('razz suit tie', {'up': {'a': 'Kc', 'b': 'Ks', 'c': '5s'}, 'variant': 'razz'}, 'b'),
  ('stud8 uses stud rule', {'up': {'a': 'Kh', 'b': '2d', 'c': '9s'}, 'variant': 'stud8'}, 'b'),
  ('stud8 ace high', {'up': {'a': 'Ad', 'b': '4d', 'c': '9s'}, 'variant': 'stud8'}, 'b'),
  ('razz heart vs diamond', {'up': {'a': 'Qd', 'b': 'Qh', 'c': '2s'}, 'variant': 'razz'}, 'b')]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'error:' + type(exc).__name__
    check(label, actual, 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:
In razz the deuce brings in instead of the king.

Input: {"variant": "stud", "stud8" or "razz", "up": {player: door card}}. In stud and stud8 the lowest door card brings in (ace high); ties are broken by suit with clubs lowest, then diamonds, hearts, spades. In razz the highest door card brings in (ace low), ties going to the highest suit. Return the bring-in player.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import collections
N = 1
observations = []
def solve(x):
    R='23456789TJQKA'
    def show(cards):
        vals=sorted((R.index(c[0])+2 for c in cards), reverse=True)
        cnt=collections.Counter(vals)
        order=sorted(cnt, key=lambda v:(cnt[v],v), reverse=True)
        shape=sorted(cnt.values(), reverse=True)
        return (shape, order)
    best=None; who=None
    for p in x['seats']:
        if p in x['folded']: continue
        k=show(x['hands'][p]['up']+x['hands'][p]['down'])
        if best is None or k>best: best, who = k, p
    return who
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('pair beats ace king',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['7h', '7d']},
              'c': {'down': ['2h', '3h'], 'up': ['9h', '4d']}},
    'seats': ['a', 'b', 'c']},
   'b'),
  ('hidden pair ignored',
   {'folded': [],
    'hands': {'a': {'down': ['Ac', 'Kc'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'a'),
  ('hidden trips ignored',
   {'folded': [],
    'hands': {'a': {'down': ['9c', '9s'], 'up': ['9h', '4d']},
              'b': {'down': ['5d', '3d'], 'up': ['Th', '2d']}},
    'seats': ['a', 'b']},
   'b'),
  ('tie seat order not name',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Qh', 'Qd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qs', 'Qc']}},
    'seats': ['b', 'a']},
   'b'),
  ('folded best board',
   {'folded': ['a'],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'b'),
  ('trips beat two pair',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Kh', 'Kd', 'Qc', 'Qs']},
              'b': {'down': ['2d', '4d'], 'up': ['3h', '3d', '3s', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('high cards only',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Kh', '9d', '4c']},
              'b': {'down': ['2d', '4d'], 'up': ['Kc', 'Td', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('three-way tie later seat',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Jh', '7d']},
              'b': {'down': ['2d', '4d'], 'up': ['Jc', '7h']},
              'c': {'down': ['2h', '4h'], 'up': ['Js', '7c']}},
    'seats': ['b', 'c', 'a']},
   'b')],
 [('pair beats ace king',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['7h', '7d']},
              'c': {'down': ['2h', '3h'], 'up': ['9h', '4d']}},
    'seats': ['a', 'b', 'c']},
   'b'),
  ('hidden trips ignored',
   {'folded': [],
    'hands': {'a': {'down': ['9c', '9s'], 'up': ['9h', '4d']},
              'b': {'down': ['5d', '3d'], 'up': ['Th', '2d']}},
    'seats': ['a', 'b']},
   'b'),
  ('tie goes to earlier seat',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['As', 'Kc']},
              'c': {'down': ['2h', '3h'], 'up': ['9h', '4d']}},
    'seats': ['c', 'a', 'b']},
   'a'),
  ('two pair beats pair',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad', 'Kc']},
              'b': {'down': ['2d', '3d'], 'up': ['5h', '5d', '4c', '4s']}},
    'seats': ['a', 'b']},
   'b'),
  ('higher pair wins',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['8h', '8d', 'Ac']},
              'b': {'down': ['2d', '3d'], 'up': ['9h', '9d', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('trips beat two pair',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Kh', 'Kd', 'Qc', 'Qs']},
              'b': {'down': ['2d', '4d'], 'up': ['3h', '3d', '3s', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('high cards only',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Kh', '9d', '4c']},
              'b': {'down': ['2d', '4d'], 'up': ['Kc', 'Td', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('three-way tie later seat',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Jh', '7d']},
              'b': {'down': ['2d', '4d'], 'up': ['Jc', '7h']},
              'c': {'down': ['2h', '4h'], 'up': ['Js', '7c']}},
    'seats': ['b', 'c', 'a']},
   'b')],
 [('pair beats ace king',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['7h', '7d']},
              'c': {'down': ['2h', '3h'], 'up': ['9h', '4d']}},
    'seats': ['a', 'b', 'c']},
   'b'),
  ('hidden pair ignored',
   {'folded': [],
    'hands': {'a': {'down': ['Ac', 'Kc'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'a'),
  ('hidden trips ignored',
   {'folded': [],
    'hands': {'a': {'down': ['9c', '9s'], 'up': ['9h', '4d']},
              'b': {'down': ['5d', '3d'], 'up': ['Th', '2d']}},
    'seats': ['a', 'b']},
   'b'),
  ('tie goes to earlier seat',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['As', 'Kc']},
              'c': {'down': ['2h', '3h'], 'up': ['9h', '4d']}},
    'seats': ['c', 'a', 'b']},
   'a'),
  ('tie seat order not name',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Qh', 'Qd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qs', 'Qc']}},
    'seats': ['b', 'a']},
   'b'),
  ('folded best board',
   {'folded': ['a'],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'b'),
  ('two pair beats pair',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad', 'Kc']},
              'b': {'down': ['2d', '3d'], 'up': ['5h', '5d', '4c', '4s']}},
    'seats': ['a', 'b']},
   'b'),
  ('higher pair wins',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['8h', '8d', 'Ac']},
              'b': {'down': ['2d', '3d'], 'up': ['9h', '9d', '2s']}},
    'seats': ['a', 'b']},
   'b')],
 [('hidden pair ignored',
   {'folded': [],
    'hands': {'a': {'down': ['Ac', 'Kc'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'a'),
  ('hidden trips ignored',
   {'folded': [],
    'hands': {'a': {'down': ['9c', '9s'], 'up': ['9h', '4d']},
              'b': {'down': ['5d', '3d'], 'up': ['Th', '2d']}},
    'seats': ['a', 'b']},
   'b'),
  ('tie seat order not name',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Qh', 'Qd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qs', 'Qc']}},
    'seats': ['b', 'a']},
   'b'),
  ('folded best board',
   {'folded': ['a'],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'b'),
  ('two pair beats pair',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad', 'Kc']},
              'b': {'down': ['2d', '3d'], 'up': ['5h', '5d', '4c', '4s']}},
    'seats': ['a', 'b']},
   'b'),
  ('higher pair wins',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['8h', '8d', 'Ac']},
              'b': {'down': ['2d', '3d'], 'up': ['9h', '9d', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('trips beat two pair',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Kh', 'Kd', 'Qc', 'Qs']},
              'b': {'down': ['2d', '4d'], 'up': ['3h', '3d', '3s', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('high cards only',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Kh', '9d', '4c']},
              'b': {'down': ['2d', '4d'], 'up': ['Kc', 'Td', '2s']}},
    'seats': ['a', 'b']},
   'b')],
 [('pair beats ace king',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['7h', '7d']},
              'c': {'down': ['2h', '3h'], 'up': ['9h', '4d']}},
    'seats': ['a', 'b', 'c']},
   'b'),
  ('hidden trips ignored',
   {'folded': [],
    'hands': {'a': {'down': ['9c', '9s'], 'up': ['9h', '4d']},
              'b': {'down': ['5d', '3d'], 'up': ['Th', '2d']}},
    'seats': ['a', 'b']},
   'b'),
  ('tie seat order not name',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Qh', 'Qd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qs', 'Qc']}},
    'seats': ['b', 'a']},
   'b'),
  ('folded best board',
   {'folded': ['a'],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'b'),
  ('higher pair wins',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['8h', '8d', 'Ac']},
              'b': {'down': ['2d', '3d'], 'up': ['9h', '9d', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('trips beat two pair',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Kh', 'Kd', 'Qc', 'Qs']},
              'b': {'down': ['2d', '4d'], 'up': ['3h', '3d', '3s', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('high cards only',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Kh', '9d', '4c']},
              'b': {'down': ['2d', '4d'], 'up': ['Kc', 'Td', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('three-way tie later seat',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Jh', '7d']},
              'b': {'down': ['2d', '4d'], 'up': ['Jc', '7h']},
              'c': {'down': ['2h', '4h'], 'up': ['Js', '7c']}},
    'seats': ['b', 'c', 'a']},
   'b')]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'error:' + type(exc).__name__
    check(label, actual, 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
import collections
N = 1
observations = []
def solve(x):
    R='23456789TJQKA'
    def show(cards):
        vals=sorted((R.index(c[0])+2 for c in cards), reverse=True)
        cnt=collections.Counter(vals)
        order=sorted(cnt, key=lambda v:(cnt[v],v), reverse=True)
        shape=sorted(cnt.values(), reverse=True)
        return (shape, order)
    best=None; who=None
    for p in x['seats']:
        if p in x['folded']: continue
        k=show(x['hands'][p]['down'])
        if best is None or k>best: best, who = k, p
    return who
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('pair beats ace king',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['7h', '7d']},
              'c': {'down': ['2h', '3h'], 'up': ['9h', '4d']}},
    'seats': ['a', 'b', 'c']},
   'b'),
  ('hidden pair ignored',
   {'folded': [],
    'hands': {'a': {'down': ['Ac', 'Kc'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'a'),
  ('hidden trips ignored',
   {'folded': [],
    'hands': {'a': {'down': ['9c', '9s'], 'up': ['9h', '4d']},
              'b': {'down': ['5d', '3d'], 'up': ['Th', '2d']}},
    'seats': ['a', 'b']},
   'b'),
  ('tie seat order not name',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Qh', 'Qd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qs', 'Qc']}},
    'seats': ['b', 'a']},
   'b'),
  ('folded best board',
   {'folded': ['a'],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'b'),
  ('trips beat two pair',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Kh', 'Kd', 'Qc', 'Qs']},
              'b': {'down': ['2d', '4d'], 'up': ['3h', '3d', '3s', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('high cards only',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Kh', '9d', '4c']},
              'b': {'down': ['2d', '4d'], 'up': ['Kc', 'Td', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('three-way tie later seat',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Jh', '7d']},
              'b': {'down': ['2d', '4d'], 'up': ['Jc', '7h']},
              'c': {'down': ['2h', '4h'], 'up': ['Js', '7c']}},
    'seats': ['b', 'c', 'a']},
   'b')],
 [('pair beats ace king',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['7h', '7d']},
              'c': {'down': ['2h', '3h'], 'up': ['9h', '4d']}},
    'seats': ['a', 'b', 'c']},
   'b'),
  ('hidden trips ignored',
   {'folded': [],
    'hands': {'a': {'down': ['9c', '9s'], 'up': ['9h', '4d']},
              'b': {'down': ['5d', '3d'], 'up': ['Th', '2d']}},
    'seats': ['a', 'b']},
   'b'),
  ('tie goes to earlier seat',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['As', 'Kc']},
              'c': {'down': ['2h', '3h'], 'up': ['9h', '4d']}},
    'seats': ['c', 'a', 'b']},
   'a'),
  ('two pair beats pair',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad', 'Kc']},
              'b': {'down': ['2d', '3d'], 'up': ['5h', '5d', '4c', '4s']}},
    'seats': ['a', 'b']},
   'b'),
  ('higher pair wins',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['8h', '8d', 'Ac']},
              'b': {'down': ['2d', '3d'], 'up': ['9h', '9d', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('trips beat two pair',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Kh', 'Kd', 'Qc', 'Qs']},
              'b': {'down': ['2d', '4d'], 'up': ['3h', '3d', '3s', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('high cards only',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Kh', '9d', '4c']},
              'b': {'down': ['2d', '4d'], 'up': ['Kc', 'Td', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('three-way tie later seat',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Jh', '7d']},
              'b': {'down': ['2d', '4d'], 'up': ['Jc', '7h']},
              'c': {'down': ['2h', '4h'], 'up': ['Js', '7c']}},
    'seats': ['b', 'c', 'a']},
   'b')],
 [('pair beats ace king',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['7h', '7d']},
              'c': {'down': ['2h', '3h'], 'up': ['9h', '4d']}},
    'seats': ['a', 'b', 'c']},
   'b'),
  ('hidden pair ignored',
   {'folded': [],
    'hands': {'a': {'down': ['Ac', 'Kc'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'a'),
  ('hidden trips ignored',
   {'folded': [],
    'hands': {'a': {'down': ['9c', '9s'], 'up': ['9h', '4d']},
              'b': {'down': ['5d', '3d'], 'up': ['Th', '2d']}},
    'seats': ['a', 'b']},
   'b'),
  ('tie goes to earlier seat',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['As', 'Kc']},
              'c': {'down': ['2h', '3h'], 'up': ['9h', '4d']}},
    'seats': ['c', 'a', 'b']},
   'a'),
  ('tie seat order not name',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Qh', 'Qd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qs', 'Qc']}},
    'seats': ['b', 'a']},
   'b'),
  ('folded best board',
   {'folded': ['a'],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'b'),
  ('two pair beats pair',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad', 'Kc']},
              'b': {'down': ['2d', '3d'], 'up': ['5h', '5d', '4c', '4s']}},
    'seats': ['a', 'b']},
   'b'),
  ('higher pair wins',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['8h', '8d', 'Ac']},
              'b': {'down': ['2d', '3d'], 'up': ['9h', '9d', '2s']}},
    'seats': ['a', 'b']},
   'b')],
 [('hidden pair ignored',
   {'folded': [],
    'hands': {'a': {'down': ['Ac', 'Kc'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'a'),
  ('hidden trips ignored',
   {'folded': [],
    'hands': {'a': {'down': ['9c', '9s'], 'up': ['9h', '4d']},
              'b': {'down': ['5d', '3d'], 'up': ['Th', '2d']}},
    'seats': ['a', 'b']},
   'b'),
  ('tie seat order not name',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Qh', 'Qd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qs', 'Qc']}},
    'seats': ['b', 'a']},
   'b'),
  ('folded best board',
   {'folded': ['a'],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'b'),
  ('two pair beats pair',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad', 'Kc']},
              'b': {'down': ['2d', '3d'], 'up': ['5h', '5d', '4c', '4s']}},
    'seats': ['a', 'b']},
   'b'),
  ('higher pair wins',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['8h', '8d', 'Ac']},
              'b': {'down': ['2d', '3d'], 'up': ['9h', '9d', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('trips beat two pair',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Kh', 'Kd', 'Qc', 'Qs']},
              'b': {'down': ['2d', '4d'], 'up': ['3h', '3d', '3s', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('high cards only',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Kh', '9d', '4c']},
              'b': {'down': ['2d', '4d'], 'up': ['Kc', 'Td', '2s']}},
    'seats': ['a', 'b']},
   'b')],
 [('pair beats ace king',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['7h', '7d']},
              'c': {'down': ['2h', '3h'], 'up': ['9h', '4d']}},
    'seats': ['a', 'b', 'c']},
   'b'),
  ('hidden trips ignored',
   {'folded': [],
    'hands': {'a': {'down': ['9c', '9s'], 'up': ['9h', '4d']},
              'b': {'down': ['5d', '3d'], 'up': ['Th', '2d']}},
    'seats': ['a', 'b']},
   'b'),
  ('tie seat order not name',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Qh', 'Qd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qs', 'Qc']}},
    'seats': ['b', 'a']},
   'b'),
  ('folded best board',
   {'folded': ['a'],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'b'),
  ('higher pair wins',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['8h', '8d', 'Ac']},
              'b': {'down': ['2d', '3d'], 'up': ['9h', '9d', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('trips beat two pair',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Kh', 'Kd', 'Qc', 'Qs']},
              'b': {'down': ['2d', '4d'], 'up': ['3h', '3d', '3s', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('high cards only',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Kh', '9d', '4c']},
              'b': {'down': ['2d', '4d'], 'up': ['Kc', 'Td', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('three-way tie later seat',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Jh', '7d']},
              'b': {'down': ['2d', '4d'], 'up': ['Jc', '7h']},
              'c': {'down': ['2h', '4h'], 'up': ['Js', '7c']}},
    'seats': ['b', 'c', 'a']},
   'b')]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'error:' + type(exc).__name__
    check(label, actual, expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A player with a hidden pair is made to act first over a better board.

Input: {"seats": [clockwise order from the dealer's left], "hands": {player: {"up": [...], "down": [...]}}, "folded": [...]}. On fourth street and later the live player with the best exposed hand acts first. Exposed hands rank by group shape (quads > trips > two pair > pair > no pair), then by group ranks; only up cards count. Exact ties go to the player earliest in seat order.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import collections
N = 1
observations = []
def solve(x):
    R='23456789TJQKA'
    def show(cards):
        vals=sorted((R.index(c[0])+2 for c in cards), reverse=True)
        cnt=collections.Counter(vals)
        order=sorted(cnt, key=lambda v:(cnt[v],v), reverse=True)
        shape=sorted(cnt.values(), reverse=True)
        return (shape, order)
    best=None; who=None
    for p in sorted(x['hands']):
        if p in x['folded']: continue
        k=show(x['hands'][p]['up'])
        if best is None or k>best: best, who = k, p
    return who
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('pair beats ace king',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['7h', '7d']},
              'c': {'down': ['2h', '3h'], 'up': ['9h', '4d']}},
    'seats': ['a', 'b', 'c']},
   'b'),
  ('hidden pair ignored',
   {'folded': [],
    'hands': {'a': {'down': ['Ac', 'Kc'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'a'),
  ('hidden trips ignored',
   {'folded': [],
    'hands': {'a': {'down': ['9c', '9s'], 'up': ['9h', '4d']},
              'b': {'down': ['5d', '3d'], 'up': ['Th', '2d']}},
    'seats': ['a', 'b']},
   'b'),
  ('tie goes to earlier seat',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['As', 'Kc']},
              'c': {'down': ['2h', '3h'], 'up': ['9h', '4d']}},
    'seats': ['c', 'a', 'b']},
   'a'),
  ('tie seat order not name',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Qh', 'Qd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qs', 'Qc']}},
    'seats': ['b', 'a']},
   'b'),
  ('folded best board',
   {'folded': ['a'],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'b'),
  ('two pair beats pair',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad', 'Kc']},
              'b': {'down': ['2d', '3d'], 'up': ['5h', '5d', '4c', '4s']}},
    'seats': ['a', 'b']},
   'b'),
  ('three-way tie later seat',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Jh', '7d']},
              'b': {'down': ['2d', '4d'], 'up': ['Jc', '7h']},
              'c': {'down': ['2h', '4h'], 'up': ['Js', '7c']}},
    'seats': ['b', 'c', 'a']},
   'b')],
 [('tie goes to earlier seat',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['As', 'Kc']},
              'c': {'down': ['2h', '3h'], 'up': ['9h', '4d']}},
    'seats': ['c', 'a', 'b']},
   'a'),
  ('tie seat order not name',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Qh', 'Qd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qs', 'Qc']}},
    'seats': ['b', 'a']},
   'b'),
  ('folded best board',
   {'folded': ['a'],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'b'),
  ('two pair beats pair',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad', 'Kc']},
              'b': {'down': ['2d', '3d'], 'up': ['5h', '5d', '4c', '4s']}},
    'seats': ['a', 'b']},
   'b'),
  ('higher pair wins',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['8h', '8d', 'Ac']},
              'b': {'down': ['2d', '3d'], 'up': ['9h', '9d', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('trips beat two pair',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Kh', 'Kd', 'Qc', 'Qs']},
              'b': {'down': ['2d', '4d'], 'up': ['3h', '3d', '3s', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('high cards only',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Kh', '9d', '4c']},
              'b': {'down': ['2d', '4d'], 'up': ['Kc', 'Td', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('three-way tie later seat',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Jh', '7d']},
              'b': {'down': ['2d', '4d'], 'up': ['Jc', '7h']},
              'c': {'down': ['2h', '4h'], 'up': ['Js', '7c']}},
    'seats': ['b', 'c', 'a']},
   'b')],
 [('pair beats ace king',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['7h', '7d']},
              'c': {'down': ['2h', '3h'], 'up': ['9h', '4d']}},
    'seats': ['a', 'b', 'c']},
   'b'),
  ('hidden pair ignored',
   {'folded': [],
    'hands': {'a': {'down': ['Ac', 'Kc'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'a'),
  ('hidden trips ignored',
   {'folded': [],
    'hands': {'a': {'down': ['9c', '9s'], 'up': ['9h', '4d']},
              'b': {'down': ['5d', '3d'], 'up': ['Th', '2d']}},
    'seats': ['a', 'b']},
   'b'),
  ('tie goes to earlier seat',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['As', 'Kc']},
              'c': {'down': ['2h', '3h'], 'up': ['9h', '4d']}},
    'seats': ['c', 'a', 'b']},
   'a'),
  ('tie seat order not name',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Qh', 'Qd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qs', 'Qc']}},
    'seats': ['b', 'a']},
   'b'),
  ('trips beat two pair',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Kh', 'Kd', 'Qc', 'Qs']},
              'b': {'down': ['2d', '4d'], 'up': ['3h', '3d', '3s', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('high cards only',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Kh', '9d', '4c']},
              'b': {'down': ['2d', '4d'], 'up': ['Kc', 'Td', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('three-way tie later seat',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Jh', '7d']},
              'b': {'down': ['2d', '4d'], 'up': ['Jc', '7h']},
              'c': {'down': ['2h', '4h'], 'up': ['Js', '7c']}},
    'seats': ['b', 'c', 'a']},
   'b')],
 [('pair beats ace king',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['7h', '7d']},
              'c': {'down': ['2h', '3h'], 'up': ['9h', '4d']}},
    'seats': ['a', 'b', 'c']},
   'b'),
  ('hidden pair ignored',
   {'folded': [],
    'hands': {'a': {'down': ['Ac', 'Kc'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'a'),
  ('hidden trips ignored',
   {'folded': [],
    'hands': {'a': {'down': ['9c', '9s'], 'up': ['9h', '4d']},
              'b': {'down': ['5d', '3d'], 'up': ['Th', '2d']}},
    'seats': ['a', 'b']},
   'b'),
  ('tie goes to earlier seat',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['As', 'Kc']},
              'c': {'down': ['2h', '3h'], 'up': ['9h', '4d']}},
    'seats': ['c', 'a', 'b']},
   'a'),
  ('tie seat order not name',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Qh', 'Qd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qs', 'Qc']}},
    'seats': ['b', 'a']},
   'b'),
  ('folded best board',
   {'folded': ['a'],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'b'),
  ('two pair beats pair',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad', 'Kc']},
              'b': {'down': ['2d', '3d'], 'up': ['5h', '5d', '4c', '4s']}},
    'seats': ['a', 'b']},
   'b'),
  ('three-way tie later seat',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Jh', '7d']},
              'b': {'down': ['2d', '4d'], 'up': ['Jc', '7h']},
              'c': {'down': ['2h', '4h'], 'up': ['Js', '7c']}},
    'seats': ['b', 'c', 'a']},
   'b')],
 [('hidden pair ignored',
   {'folded': [],
    'hands': {'a': {'down': ['Ac', 'Kc'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'a'),
  ('hidden trips ignored',
   {'folded': [],
    'hands': {'a': {'down': ['9c', '9s'], 'up': ['9h', '4d']},
              'b': {'down': ['5d', '3d'], 'up': ['Th', '2d']}},
    'seats': ['a', 'b']},
   'b'),
  ('tie seat order not name',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Qh', 'Qd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qs', 'Qc']}},
    'seats': ['b', 'a']},
   'b'),
  ('folded best board',
   {'folded': ['a'],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'b'),
  ('two pair beats pair',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad', 'Kc']},
              'b': {'down': ['2d', '3d'], 'up': ['5h', '5d', '4c', '4s']}},
    'seats': ['a', 'b']},
   'b'),
  ('higher pair wins',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['8h', '8d', 'Ac']},
              'b': {'down': ['2d', '3d'], 'up': ['9h', '9d', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('trips beat two pair',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Kh', 'Kd', 'Qc', 'Qs']},
              'b': {'down': ['2d', '4d'], 'up': ['3h', '3d', '3s', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('three-way tie later seat',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Jh', '7d']},
              'b': {'down': ['2d', '4d'], 'up': ['Jc', '7h']},
              'c': {'down': ['2h', '4h'], 'up': ['Js', '7c']}},
    'seats': ['b', 'c', 'a']},
   'b')]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'error:' + type(exc).__name__
    check(label, actual, 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
import collections
N = 1
observations = []
def solve(x):
    R='23456789TJQKA'
    def show(cards):
        vals=sorted((R.index(c[0])+2 for c in cards), reverse=True)
        cnt=collections.Counter(vals)
        order=sorted(cnt, key=lambda v:(cnt[v],v), reverse=True)
        shape=sorted(cnt.values(), reverse=True)
        return (shape, order)
    best=None; who=None
    for p in reversed(x['seats']):
        if p in x['folded']: continue
        k=show(x['hands'][p]['up'])
        if best is None or k>best: best, who = k, p
    return who
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('pair beats ace king',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['7h', '7d']},
              'c': {'down': ['2h', '3h'], 'up': ['9h', '4d']}},
    'seats': ['a', 'b', 'c']},
   'b'),
  ('hidden pair ignored',
   {'folded': [],
    'hands': {'a': {'down': ['Ac', 'Kc'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'a'),
  ('hidden trips ignored',
   {'folded': [],
    'hands': {'a': {'down': ['9c', '9s'], 'up': ['9h', '4d']},
              'b': {'down': ['5d', '3d'], 'up': ['Th', '2d']}},
    'seats': ['a', 'b']},
   'b'),
  ('tie goes to earlier seat',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['As', 'Kc']},
              'c': {'down': ['2h', '3h'], 'up': ['9h', '4d']}},
    'seats': ['c', 'a', 'b']},
   'a'),
  ('tie seat order not name',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Qh', 'Qd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qs', 'Qc']}},
    'seats': ['b', 'a']},
   'b'),
  ('folded best board',
   {'folded': ['a'],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'b'),
  ('two pair beats pair',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad', 'Kc']},
              'b': {'down': ['2d', '3d'], 'up': ['5h', '5d', '4c', '4s']}},
    'seats': ['a', 'b']},
   'b'),
  ('three-way tie later seat',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Jh', '7d']},
              'b': {'down': ['2d', '4d'], 'up': ['Jc', '7h']},
              'c': {'down': ['2h', '4h'], 'up': ['Js', '7c']}},
    'seats': ['b', 'c', 'a']},
   'b')],
 [('tie goes to earlier seat',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['As', 'Kc']},
              'c': {'down': ['2h', '3h'], 'up': ['9h', '4d']}},
    'seats': ['c', 'a', 'b']},
   'a'),
  ('tie seat order not name',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Qh', 'Qd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qs', 'Qc']}},
    'seats': ['b', 'a']},
   'b'),
  ('folded best board',
   {'folded': ['a'],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'b'),
  ('two pair beats pair',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad', 'Kc']},
              'b': {'down': ['2d', '3d'], 'up': ['5h', '5d', '4c', '4s']}},
    'seats': ['a', 'b']},
   'b'),
  ('higher pair wins',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['8h', '8d', 'Ac']},
              'b': {'down': ['2d', '3d'], 'up': ['9h', '9d', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('trips beat two pair',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Kh', 'Kd', 'Qc', 'Qs']},
              'b': {'down': ['2d', '4d'], 'up': ['3h', '3d', '3s', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('high cards only',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Kh', '9d', '4c']},
              'b': {'down': ['2d', '4d'], 'up': ['Kc', 'Td', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('three-way tie later seat',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Jh', '7d']},
              'b': {'down': ['2d', '4d'], 'up': ['Jc', '7h']},
              'c': {'down': ['2h', '4h'], 'up': ['Js', '7c']}},
    'seats': ['b', 'c', 'a']},
   'b')],
 [('pair beats ace king',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['7h', '7d']},
              'c': {'down': ['2h', '3h'], 'up': ['9h', '4d']}},
    'seats': ['a', 'b', 'c']},
   'b'),
  ('hidden pair ignored',
   {'folded': [],
    'hands': {'a': {'down': ['Ac', 'Kc'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'a'),
  ('hidden trips ignored',
   {'folded': [],
    'hands': {'a': {'down': ['9c', '9s'], 'up': ['9h', '4d']},
              'b': {'down': ['5d', '3d'], 'up': ['Th', '2d']}},
    'seats': ['a', 'b']},
   'b'),
  ('tie goes to earlier seat',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['As', 'Kc']},
              'c': {'down': ['2h', '3h'], 'up': ['9h', '4d']}},
    'seats': ['c', 'a', 'b']},
   'a'),
  ('tie seat order not name',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Qh', 'Qd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qs', 'Qc']}},
    'seats': ['b', 'a']},
   'b'),
  ('trips beat two pair',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Kh', 'Kd', 'Qc', 'Qs']},
              'b': {'down': ['2d', '4d'], 'up': ['3h', '3d', '3s', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('high cards only',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Kh', '9d', '4c']},
              'b': {'down': ['2d', '4d'], 'up': ['Kc', 'Td', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('three-way tie later seat',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Jh', '7d']},
              'b': {'down': ['2d', '4d'], 'up': ['Jc', '7h']},
              'c': {'down': ['2h', '4h'], 'up': ['Js', '7c']}},
    'seats': ['b', 'c', 'a']},
   'b')],
 [('pair beats ace king',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['7h', '7d']},
              'c': {'down': ['2h', '3h'], 'up': ['9h', '4d']}},
    'seats': ['a', 'b', 'c']},
   'b'),
  ('hidden pair ignored',
   {'folded': [],
    'hands': {'a': {'down': ['Ac', 'Kc'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'a'),
  ('hidden trips ignored',
   {'folded': [],
    'hands': {'a': {'down': ['9c', '9s'], 'up': ['9h', '4d']},
              'b': {'down': ['5d', '3d'], 'up': ['Th', '2d']}},
    'seats': ['a', 'b']},
   'b'),
  ('tie goes to earlier seat',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['As', 'Kc']},
              'c': {'down': ['2h', '3h'], 'up': ['9h', '4d']}},
    'seats': ['c', 'a', 'b']},
   'a'),
  ('tie seat order not name',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Qh', 'Qd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qs', 'Qc']}},
    'seats': ['b', 'a']},
   'b'),
  ('folded best board',
   {'folded': ['a'],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'b'),
  ('two pair beats pair',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad', 'Kc']},
              'b': {'down': ['2d', '3d'], 'up': ['5h', '5d', '4c', '4s']}},
    'seats': ['a', 'b']},
   'b'),
  ('three-way tie later seat',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Jh', '7d']},
              'b': {'down': ['2d', '4d'], 'up': ['Jc', '7h']},
              'c': {'down': ['2h', '4h'], 'up': ['Js', '7c']}},
    'seats': ['b', 'c', 'a']},
   'b')],
 [('hidden pair ignored',
   {'folded': [],
    'hands': {'a': {'down': ['Ac', 'Kc'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'a'),
  ('hidden trips ignored',
   {'folded': [],
    'hands': {'a': {'down': ['9c', '9s'], 'up': ['9h', '4d']},
              'b': {'down': ['5d', '3d'], 'up': ['Th', '2d']}},
    'seats': ['a', 'b']},
   'b'),
  ('tie seat order not name',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Qh', 'Qd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qs', 'Qc']}},
    'seats': ['b', 'a']},
   'b'),
  ('folded best board',
   {'folded': ['a'],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'b'),
  ('two pair beats pair',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad', 'Kc']},
              'b': {'down': ['2d', '3d'], 'up': ['5h', '5d', '4c', '4s']}},
    'seats': ['a', 'b']},
   'b'),
  ('higher pair wins',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['8h', '8d', 'Ac']},
              'b': {'down': ['2d', '3d'], 'up': ['9h', '9d', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('trips beat two pair',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Kh', 'Kd', 'Qc', 'Qs']},
              'b': {'down': ['2d', '4d'], 'up': ['3h', '3d', '3s', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('three-way tie later seat',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Jh', '7d']},
              'b': {'down': ['2d', '4d'], 'up': ['Jc', '7h']},
              'c': {'down': ['2h', '4h'], 'up': ['Js', '7c']}},
    'seats': ['b', 'c', 'a']},
   'b')]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'error:' + type(exc).__name__
    check(label, actual, 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:
With identical boards, the player whose name sorts first acts, not the earliest seat.

Input: {"seats": [clockwise order from the dealer's left], "hands": {player: {"up": [...], "down": [...]}}, "folded": [...]}. On fourth street and later the live player with the best exposed hand acts first. Exposed hands rank by group shape (quads > trips > two pair > pair > no pair), then by group ranks; only up cards count. Exact ties go to the player earliest in seat order.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import collections
N = 1
observations = []
def solve(x):
    R='23456789TJQKA'
    def show(cards):
        vals=sorted((R.index(c[0])+2 for c in cards), reverse=True)
        cnt=collections.Counter(vals)
        order=sorted(cnt, key=lambda v:(cnt[v],v), reverse=True)
        shape=sorted(cnt.values(), reverse=True)
        return (shape, order)
    best=None; who=None
    for p in x['seats']:
        if not x['hands'][p]['up']: continue
        k=show(x['hands'][p]['up'])
        if best is None or k>best: best, who = k, p
    return who
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('pair beats ace king',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['7h', '7d']},
              'c': {'down': ['2h', '3h'], 'up': ['9h', '4d']}},
    'seats': ['a', 'b', 'c']},
   'b'),
  ('hidden pair ignored',
   {'folded': [],
    'hands': {'a': {'down': ['Ac', 'Kc'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'a'),
  ('hidden trips ignored',
   {'folded': [],
    'hands': {'a': {'down': ['9c', '9s'], 'up': ['9h', '4d']},
              'b': {'down': ['5d', '3d'], 'up': ['Th', '2d']}},
    'seats': ['a', 'b']},
   'b'),
  ('tie goes to earlier seat',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['As', 'Kc']},
              'c': {'down': ['2h', '3h'], 'up': ['9h', '4d']}},
    'seats': ['c', 'a', 'b']},
   'a'),
  ('tie seat order not name',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Qh', 'Qd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qs', 'Qc']}},
    'seats': ['b', 'a']},
   'b'),
  ('folded best board',
   {'folded': ['a'],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'b'),
  ('two pair beats pair',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad', 'Kc']},
              'b': {'down': ['2d', '3d'], 'up': ['5h', '5d', '4c', '4s']}},
    'seats': ['a', 'b']},
   'b'),
  ('higher pair wins',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['8h', '8d', 'Ac']},
              'b': {'down': ['2d', '3d'], 'up': ['9h', '9d', '2s']}},
    'seats': ['a', 'b']},
   'b')],
 [('tie goes to earlier seat',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['As', 'Kc']},
              'c': {'down': ['2h', '3h'], 'up': ['9h', '4d']}},
    'seats': ['c', 'a', 'b']},
   'a'),
  ('tie seat order not name',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Qh', 'Qd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qs', 'Qc']}},
    'seats': ['b', 'a']},
   'b'),
  ('folded best board',
   {'folded': ['a'],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'b'),
  ('two pair beats pair',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad', 'Kc']},
              'b': {'down': ['2d', '3d'], 'up': ['5h', '5d', '4c', '4s']}},
    'seats': ['a', 'b']},
   'b'),
  ('higher pair wins',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['8h', '8d', 'Ac']},
              'b': {'down': ['2d', '3d'], 'up': ['9h', '9d', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('trips beat two pair',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Kh', 'Kd', 'Qc', 'Qs']},
              'b': {'down': ['2d', '4d'], 'up': ['3h', '3d', '3s', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('high cards only',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Kh', '9d', '4c']},
              'b': {'down': ['2d', '4d'], 'up': ['Kc', 'Td', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('three-way tie later seat',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Jh', '7d']},
              'b': {'down': ['2d', '4d'], 'up': ['Jc', '7h']},
              'c': {'down': ['2h', '4h'], 'up': ['Js', '7c']}},
    'seats': ['b', 'c', 'a']},
   'b')],
 [('pair beats ace king',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['7h', '7d']},
              'c': {'down': ['2h', '3h'], 'up': ['9h', '4d']}},
    'seats': ['a', 'b', 'c']},
   'b'),
  ('hidden pair ignored',
   {'folded': [],
    'hands': {'a': {'down': ['Ac', 'Kc'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'a'),
  ('hidden trips ignored',
   {'folded': [],
    'hands': {'a': {'down': ['9c', '9s'], 'up': ['9h', '4d']},
              'b': {'down': ['5d', '3d'], 'up': ['Th', '2d']}},
    'seats': ['a', 'b']},
   'b'),
  ('folded best board',
   {'folded': ['a'],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'b'),
  ('higher pair wins',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['8h', '8d', 'Ac']},
              'b': {'down': ['2d', '3d'], 'up': ['9h', '9d', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('trips beat two pair',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Kh', 'Kd', 'Qc', 'Qs']},
              'b': {'down': ['2d', '4d'], 'up': ['3h', '3d', '3s', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('high cards only',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Kh', '9d', '4c']},
              'b': {'down': ['2d', '4d'], 'up': ['Kc', 'Td', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('three-way tie later seat',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Jh', '7d']},
              'b': {'down': ['2d', '4d'], 'up': ['Jc', '7h']},
              'c': {'down': ['2h', '4h'], 'up': ['Js', '7c']}},
    'seats': ['b', 'c', 'a']},
   'b')],
 [('pair beats ace king',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['7h', '7d']},
              'c': {'down': ['2h', '3h'], 'up': ['9h', '4d']}},
    'seats': ['a', 'b', 'c']},
   'b'),
  ('hidden pair ignored',
   {'folded': [],
    'hands': {'a': {'down': ['Ac', 'Kc'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'a'),
  ('hidden trips ignored',
   {'folded': [],
    'hands': {'a': {'down': ['9c', '9s'], 'up': ['9h', '4d']},
              'b': {'down': ['5d', '3d'], 'up': ['Th', '2d']}},
    'seats': ['a', 'b']},
   'b'),
  ('tie goes to earlier seat',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['As', 'Kc']},
              'c': {'down': ['2h', '3h'], 'up': ['9h', '4d']}},
    'seats': ['c', 'a', 'b']},
   'a'),
  ('tie seat order not name',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Qh', 'Qd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qs', 'Qc']}},
    'seats': ['b', 'a']},
   'b'),
  ('folded best board',
   {'folded': ['a'],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'b'),
  ('two pair beats pair',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad', 'Kc']},
              'b': {'down': ['2d', '3d'], 'up': ['5h', '5d', '4c', '4s']}},
    'seats': ['a', 'b']},
   'b'),
  ('three-way tie later seat',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Jh', '7d']},
              'b': {'down': ['2d', '4d'], 'up': ['Jc', '7h']},
              'c': {'down': ['2h', '4h'], 'up': ['Js', '7c']}},
    'seats': ['b', 'c', 'a']},
   'b')],
 [('hidden pair ignored',
   {'folded': [],
    'hands': {'a': {'down': ['Ac', 'Kc'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'a'),
  ('hidden trips ignored',
   {'folded': [],
    'hands': {'a': {'down': ['9c', '9s'], 'up': ['9h', '4d']},
              'b': {'down': ['5d', '3d'], 'up': ['Th', '2d']}},
    'seats': ['a', 'b']},
   'b'),
  ('tie goes to earlier seat',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['As', 'Kc']},
              'c': {'down': ['2h', '3h'], 'up': ['9h', '4d']}},
    'seats': ['c', 'a', 'b']},
   'a'),
  ('tie seat order not name',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Qh', 'Qd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qs', 'Qc']}},
    'seats': ['b', 'a']},
   'b'),
  ('folded best board',
   {'folded': ['a'],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'b'),
  ('two pair beats pair',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad', 'Kc']},
              'b': {'down': ['2d', '3d'], 'up': ['5h', '5d', '4c', '4s']}},
    'seats': ['a', 'b']},
   'b'),
  ('higher pair wins',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['8h', '8d', 'Ac']},
              'b': {'down': ['2d', '3d'], 'up': ['9h', '9d', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('trips beat two pair',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Kh', 'Kd', 'Qc', 'Qs']},
              'b': {'down': ['2d', '4d'], 'up': ['3h', '3d', '3s', '2s']}},
    'seats': ['a', 'b']},
   'b')]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'error:' + type(exc).__name__
    check(label, actual, 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
import collections
N = 1
observations = []
def solve(x):
    R='23456789TJQKA'
    def show(cards):
        vals=sorted((R.index(c[0])+2 for c in cards), reverse=True)
        cnt=collections.Counter(vals)
        order=sorted(cnt, key=lambda v:(cnt[v],v), reverse=True)
        shape=sorted(cnt.values(), reverse=True)
        return (shape, order)
    best=None; who=None
    for p in x['seats']:
        if p in x['folded'][1:]: continue
        k=show(x['hands'][p]['up'])
        if best is None or k>best: best, who = k, p
    return who
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('pair beats ace king',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['7h', '7d']},
              'c': {'down': ['2h', '3h'], 'up': ['9h', '4d']}},
    'seats': ['a', 'b', 'c']},
   'b'),
  ('hidden pair ignored',
   {'folded': [],
    'hands': {'a': {'down': ['Ac', 'Kc'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'a'),
  ('hidden trips ignored',
   {'folded': [],
    'hands': {'a': {'down': ['9c', '9s'], 'up': ['9h', '4d']},
              'b': {'down': ['5d', '3d'], 'up': ['Th', '2d']}},
    'seats': ['a', 'b']},
   'b'),
  ('tie goes to earlier seat',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['As', 'Kc']},
              'c': {'down': ['2h', '3h'], 'up': ['9h', '4d']}},
    'seats': ['c', 'a', 'b']},
   'a'),
  ('tie seat order not name',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Qh', 'Qd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qs', 'Qc']}},
    'seats': ['b', 'a']},
   'b'),
  ('folded best board',
   {'folded': ['a'],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'b'),
  ('two pair beats pair',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad', 'Kc']},
              'b': {'down': ['2d', '3d'], 'up': ['5h', '5d', '4c', '4s']}},
    'seats': ['a', 'b']},
   'b'),
  ('higher pair wins',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['8h', '8d', 'Ac']},
              'b': {'down': ['2d', '3d'], 'up': ['9h', '9d', '2s']}},
    'seats': ['a', 'b']},
   'b')],
 [('tie goes to earlier seat',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['As', 'Kc']},
              'c': {'down': ['2h', '3h'], 'up': ['9h', '4d']}},
    'seats': ['c', 'a', 'b']},
   'a'),
  ('tie seat order not name',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Qh', 'Qd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qs', 'Qc']}},
    'seats': ['b', 'a']},
   'b'),
  ('folded best board',
   {'folded': ['a'],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'b'),
  ('two pair beats pair',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad', 'Kc']},
              'b': {'down': ['2d', '3d'], 'up': ['5h', '5d', '4c', '4s']}},
    'seats': ['a', 'b']},
   'b'),
  ('higher pair wins',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['8h', '8d', 'Ac']},
              'b': {'down': ['2d', '3d'], 'up': ['9h', '9d', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('trips beat two pair',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Kh', 'Kd', 'Qc', 'Qs']},
              'b': {'down': ['2d', '4d'], 'up': ['3h', '3d', '3s', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('high cards only',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Kh', '9d', '4c']},
              'b': {'down': ['2d', '4d'], 'up': ['Kc', 'Td', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('three-way tie later seat',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Jh', '7d']},
              'b': {'down': ['2d', '4d'], 'up': ['Jc', '7h']},
              'c': {'down': ['2h', '4h'], 'up': ['Js', '7c']}},
    'seats': ['b', 'c', 'a']},
   'b')],
 [('pair beats ace king',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['7h', '7d']},
              'c': {'down': ['2h', '3h'], 'up': ['9h', '4d']}},
    'seats': ['a', 'b', 'c']},
   'b'),
  ('hidden pair ignored',
   {'folded': [],
    'hands': {'a': {'down': ['Ac', 'Kc'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'a'),
  ('hidden trips ignored',
   {'folded': [],
    'hands': {'a': {'down': ['9c', '9s'], 'up': ['9h', '4d']},
              'b': {'down': ['5d', '3d'], 'up': ['Th', '2d']}},
    'seats': ['a', 'b']},
   'b'),
  ('folded best board',
   {'folded': ['a'],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'b'),
  ('higher pair wins',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['8h', '8d', 'Ac']},
              'b': {'down': ['2d', '3d'], 'up': ['9h', '9d', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('trips beat two pair',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Kh', 'Kd', 'Qc', 'Qs']},
              'b': {'down': ['2d', '4d'], 'up': ['3h', '3d', '3s', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('high cards only',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Kh', '9d', '4c']},
              'b': {'down': ['2d', '4d'], 'up': ['Kc', 'Td', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('three-way tie later seat',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Jh', '7d']},
              'b': {'down': ['2d', '4d'], 'up': ['Jc', '7h']},
              'c': {'down': ['2h', '4h'], 'up': ['Js', '7c']}},
    'seats': ['b', 'c', 'a']},
   'b')],
 [('pair beats ace king',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['7h', '7d']},
              'c': {'down': ['2h', '3h'], 'up': ['9h', '4d']}},
    'seats': ['a', 'b', 'c']},
   'b'),
  ('hidden pair ignored',
   {'folded': [],
    'hands': {'a': {'down': ['Ac', 'Kc'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'a'),
  ('hidden trips ignored',
   {'folded': [],
    'hands': {'a': {'down': ['9c', '9s'], 'up': ['9h', '4d']},
              'b': {'down': ['5d', '3d'], 'up': ['Th', '2d']}},
    'seats': ['a', 'b']},
   'b'),
  ('tie goes to earlier seat',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['As', 'Kc']},
              'c': {'down': ['2h', '3h'], 'up': ['9h', '4d']}},
    'seats': ['c', 'a', 'b']},
   'a'),
  ('tie seat order not name',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Qh', 'Qd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qs', 'Qc']}},
    'seats': ['b', 'a']},
   'b'),
  ('folded best board',
   {'folded': ['a'],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'b'),
  ('two pair beats pair',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad', 'Kc']},
              'b': {'down': ['2d', '3d'], 'up': ['5h', '5d', '4c', '4s']}},
    'seats': ['a', 'b']},
   'b'),
  ('three-way tie later seat',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Jh', '7d']},
              'b': {'down': ['2d', '4d'], 'up': ['Jc', '7h']},
              'c': {'down': ['2h', '4h'], 'up': ['Js', '7c']}},
    'seats': ['b', 'c', 'a']},
   'b')],
 [('hidden pair ignored',
   {'folded': [],
    'hands': {'a': {'down': ['Ac', 'Kc'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'a'),
  ('hidden trips ignored',
   {'folded': [],
    'hands': {'a': {'down': ['9c', '9s'], 'up': ['9h', '4d']},
              'b': {'down': ['5d', '3d'], 'up': ['Th', '2d']}},
    'seats': ['a', 'b']},
   'b'),
  ('tie goes to earlier seat',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Kd']},
              'b': {'down': ['2d', '3d'], 'up': ['As', 'Kc']},
              'c': {'down': ['2h', '3h'], 'up': ['9h', '4d']}},
    'seats': ['c', 'a', 'b']},
   'a'),
  ('tie seat order not name',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Qh', 'Qd']},
              'b': {'down': ['2d', '3d'], 'up': ['Qs', 'Qc']}},
    'seats': ['b', 'a']},
   'b'),
  ('folded best board',
   {'folded': ['a'],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad']},
              'b': {'down': ['2d', '3d'], 'up': ['Qh', 'Jd']}},
    'seats': ['a', 'b']},
   'b'),
  ('two pair beats pair',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Ah', 'Ad', 'Kc']},
              'b': {'down': ['2d', '3d'], 'up': ['5h', '5d', '4c', '4s']}},
    'seats': ['a', 'b']},
   'b'),
  ('higher pair wins',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['8h', '8d', 'Ac']},
              'b': {'down': ['2d', '3d'], 'up': ['9h', '9d', '2s']}},
    'seats': ['a', 'b']},
   'b'),
  ('trips beat two pair',
   {'folded': [],
    'hands': {'a': {'down': ['2c', '3c'], 'up': ['Kh', 'Kd', 'Qc', 'Qs']},
              'b': {'down': ['2d', '4d'], 'up': ['3h', '3d', '3s', '2s']}},
    'seats': ['a', 'b']},
   'b')]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'error:' + type(exc).__name__
    check(label, actual, expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A player who folded a pair of aces is named first to act.

Input: {"seats": [clockwise order from the dealer's left], "hands": {player: {"up": [...], "down": [...]}}, "folded": [...]}. On fourth street and later the live player with the best exposed hand acts first. Exposed hands rank by group shape (quads > trips > two pair > pair > no pair), then by group ranks; only up cards count. Exact ties go to the player earliest in seat order.

split: open-access