broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import collections
import itertools
N = 1
observations = []
def solve(x):
    R='23456789TJQKA'
    def key5(h):
        vals=sorted((R.index(c[0])+2 for c in h), reverse=True)
        cnt=collections.Counter(vals)
        order=sorted(cnt, key=lambda v:(cnt[v],v), reverse=True)
        shape=sorted(cnt.values(), reverse=True)
        flush=len({c[1] for c in h})==1
        straight=len(cnt)==5 and (vals[0]-vals[4]==4 or vals==[14,5,4,3,2])
        top=5 if vals==[14,5,4,3,2] else vals[0]
        if straight and flush: return (8,[top])
        if shape==[4,1]: return (7,order)
        if shape==[3,2]: return (6,order)
        if flush: return (5,vals)
        if straight: return (4,[top])
        if shape==[3,1,1]: return (3,order)
        if shape==[2,2,1]: return (2,order)
        if shape==[2,1,1,1]: return (1,order)
        return (0,vals)

    board=x['board']; folded=x.get('folded',[])
    scores={}
    for name,hole in x['players'].items():
        if not hole: continue
        scores[name]=max(key5(c) for c in itertools.combinations(hole+board,5))
    best=max(scores.values())
    return sorted(n for n,k in scores.items() if k==best)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('board plays for both',
   {'board': ['Th', 'Jd', 'Qc', 'Ks', 'Ah'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['4h', '5s']}},
   ['ann', 'bob']),
  ('one hole card plays',
   {'board': ['Ah', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('kicker on paired board',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', 'Jd'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('folded best hand ignored',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': ['ann', 'dee'],
    'players': {'ann': ['9c', '9s'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['cat']),
  ('folded first then other',
   {'board': ['2h', '7d', '9c', 'Js', '4h'],
    'folded': ['cat', 'ann'],
    'players': {'ann': ['Jc', 'Jh'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['bob']),
  ('flush second card decides',
   {'board': ['2h', '7h', '9h', 'Jd', '4s'],
    'folded': [],
    'players': {'ann': ['Ah', '3h'], 'bob': ['Kh', 'Qh']}},
   ['ann']),
  ('flush fourth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['7h', '2c'], 'bob': ['8h', '2d']}},
   ['bob']),
  ('flush fifth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['2h', 'Kc'], 'bob': ['Kd', '2d']}},
   ['ann'])],
 [('folded best hand ignored',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': ['ann', 'dee'],
    'players': {'ann': ['9c', '9s'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['cat']),
  ('folded first then other',
   {'board': ['2h', '7d', '9c', 'Js', '4h'],
    'folded': ['cat', 'ann'],
    'players': {'ann': ['Jc', 'Jh'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['bob']),
  ('flush second card decides',
   {'board': ['2h', '7h', '9h', 'Jd', '4s'],
    'folded': [],
    'players': {'ann': ['Ah', '3h'], 'bob': ['Kh', 'Qh']}},
   ['ann']),
  ('flush fourth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['7h', '2c'], 'bob': ['8h', '2d']}},
   ['bob']),
  ('flush fifth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['2h', 'Kc'], 'bob': ['Kd', '2d']}},
   ['ann']),
  ('flush kickers deep',
   {'board': ['Ah', 'Kh', '9h', '3d', '4s'],
    'folded': [],
    'players': {'ann': ['7h', '2h'], 'bob': ['8h', '2c']}},
   ['ann']),
  ('same category different kicker',
   {'board': ['Ah', '8d', '7c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['8c', 'Kd'], 'bob': ['8s', 'Qd']}},
   ['ann']),
  ('two pair split',
   {'board': ['Kh', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['As', '4d']}},
   ['ann', 'bob'])],
 [('folded best hand ignored',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': ['ann', 'dee'],
    'players': {'ann': ['9c', '9s'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['cat']),
  ('folded first then other',
   {'board': ['2h', '7d', '9c', 'Js', '4h'],
    'folded': ['cat', 'ann'],
    'players': {'ann': ['Jc', 'Jh'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['bob']),
  ('flush kickers deep',
   {'board': ['Ah', 'Kh', '9h', '3d', '4s'],
    'folded': [],
    'players': {'ann': ['7h', '2h'], 'bob': ['8h', '2c']}},
   ['ann']),
  ('same category different kicker',
   {'board': ['Ah', '8d', '7c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['8c', 'Kd'], 'bob': ['8s', 'Qd']}},
   ['ann']),
  ('two pair split',
   {'board': ['Kh', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['As', '4d']}},
   ['ann', 'bob']),
  ('set beats two pair',
   {'board': ['Kh', '8d', '7c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['8c', '8s'], 'bob': ['Kc', '7d']}},
   ['ann']),
  ('three-way split',
   {'board': ['6h', '7d', '8c', '9s', 'Th'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['2h', '3c'], 'cat': ['2d', '4c']}},
   ['ann', 'bob', 'cat']),
  ('single hole flush',
   {'board': ['2s', '7s', '9s', 'Js', '4d'],
    'folded': [],
    'players': {'ann': ['As', 'Kd'], 'bob': ['Qc', 'Qd']}},
   ['ann'])],
 [('board plays for both',
   {'board': ['Th', 'Jd', 'Qc', 'Ks', 'Ah'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['4h', '5s']}},
   ['ann', 'bob']),
  ('one hole card plays',
   {'board': ['Ah', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('kicker on paired board',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', 'Jd'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('folded best hand ignored',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': ['ann', 'dee'],
    'players': {'ann': ['9c', '9s'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['cat']),
  ('folded first then other',
   {'board': ['2h', '7d', '9c', 'Js', '4h'],
    'folded': ['cat', 'ann'],
    'players': {'ann': ['Jc', 'Jh'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['bob']),
  ('set beats two pair',
   {'board': ['Kh', '8d', '7c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['8c', '8s'], 'bob': ['Kc', '7d']}},
   ['ann']),
  ('three-way split',
   {'board': ['6h', '7d', '8c', '9s', 'Th'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['2h', '3c'], 'cat': ['2d', '4c']}},
   ['ann', 'bob', 'cat']),
  ('single hole flush',
   {'board': ['2s', '7s', '9s', 'Js', '4d'],
    'folded': [],
    'players': {'ann': ['As', 'Kd'], 'bob': ['Qc', 'Qd']}},
   ['ann'])],
 [('board plays for both',
   {'board': ['Th', 'Jd', 'Qc', 'Ks', 'Ah'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['4h', '5s']}},
   ['ann', 'bob']),
  ('one hole card plays',
   {'board': ['Ah', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('kicker on paired board',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', 'Jd'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('folded best hand ignored',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': ['ann', 'dee'],
    'players': {'ann': ['9c', '9s'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['cat']),
  ('folded first then other',
   {'board': ['2h', '7d', '9c', 'Js', '4h'],
    'folded': ['cat', 'ann'],
    'players': {'ann': ['Jc', 'Jh'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['bob']),
  ('flush second card decides',
   {'board': ['2h', '7h', '9h', 'Jd', '4s'],
    'folded': [],
    'players': {'ann': ['Ah', '3h'], 'bob': ['Kh', 'Qh']}},
   ['ann']),
  ('flush fourth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['7h', '2c'], 'bob': ['8h', '2d']}},
   ['bob']),
  ('flush fifth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['2h', 'Kc'], 'bob': ['Kd', '2d']}},
   ['ann'])]]
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
import itertools
N = 1
observations = []
def solve(x):
    R='23456789TJQKA'
    def key5(h):
        vals=sorted((R.index(c[0])+2 for c in h), reverse=True)
        cnt=collections.Counter(vals)
        order=sorted(cnt, key=lambda v:(cnt[v],v), reverse=True)
        shape=sorted(cnt.values(), reverse=True)
        flush=len({c[1] for c in h})==1
        straight=len(cnt)==5 and (vals[0]-vals[4]==4 or vals==[14,5,4,3,2])
        top=5 if vals==[14,5,4,3,2] else vals[0]
        if straight and flush: return (8,[top])
        if shape==[4,1]: return (7,order)
        if shape==[3,2]: return (6,order)
        if flush: return (5,vals)
        if straight: return (4,[top])
        if shape==[3,1,1]: return (3,order)
        if shape==[2,2,1]: return (2,order)
        if shape==[2,1,1,1]: return (1,order)
        return (0,vals)

    board=x['board']; folded=x.get('folded',[])
    scores={}
    for name,hole in x['players'].items():
        if folded and name==folded[-1]: continue
        scores[name]=max(key5(c) for c in itertools.combinations(hole+board,5))
    best=max(scores.values())
    return sorted(n for n,k in scores.items() if k==best)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('board plays for both',
   {'board': ['Th', 'Jd', 'Qc', 'Ks', 'Ah'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['4h', '5s']}},
   ['ann', 'bob']),
  ('one hole card plays',
   {'board': ['Ah', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('kicker on paired board',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', 'Jd'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('folded best hand ignored',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': ['ann', 'dee'],
    'players': {'ann': ['9c', '9s'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['cat']),
  ('folded first then other',
   {'board': ['2h', '7d', '9c', 'Js', '4h'],
    'folded': ['cat', 'ann'],
    'players': {'ann': ['Jc', 'Jh'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['bob']),
  ('flush second card decides',
   {'board': ['2h', '7h', '9h', 'Jd', '4s'],
    'folded': [],
    'players': {'ann': ['Ah', '3h'], 'bob': ['Kh', 'Qh']}},
   ['ann']),
  ('flush fourth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['7h', '2c'], 'bob': ['8h', '2d']}},
   ['bob']),
  ('flush fifth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['2h', 'Kc'], 'bob': ['Kd', '2d']}},
   ['ann'])],
 [('folded best hand ignored',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': ['ann', 'dee'],
    'players': {'ann': ['9c', '9s'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['cat']),
  ('folded first then other',
   {'board': ['2h', '7d', '9c', 'Js', '4h'],
    'folded': ['cat', 'ann'],
    'players': {'ann': ['Jc', 'Jh'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['bob']),
  ('flush second card decides',
   {'board': ['2h', '7h', '9h', 'Jd', '4s'],
    'folded': [],
    'players': {'ann': ['Ah', '3h'], 'bob': ['Kh', 'Qh']}},
   ['ann']),
  ('flush fourth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['7h', '2c'], 'bob': ['8h', '2d']}},
   ['bob']),
  ('flush fifth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['2h', 'Kc'], 'bob': ['Kd', '2d']}},
   ['ann']),
  ('flush kickers deep',
   {'board': ['Ah', 'Kh', '9h', '3d', '4s'],
    'folded': [],
    'players': {'ann': ['7h', '2h'], 'bob': ['8h', '2c']}},
   ['ann']),
  ('same category different kicker',
   {'board': ['Ah', '8d', '7c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['8c', 'Kd'], 'bob': ['8s', 'Qd']}},
   ['ann']),
  ('two pair split',
   {'board': ['Kh', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['As', '4d']}},
   ['ann', 'bob'])],
 [('folded best hand ignored',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': ['ann', 'dee'],
    'players': {'ann': ['9c', '9s'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['cat']),
  ('folded first then other',
   {'board': ['2h', '7d', '9c', 'Js', '4h'],
    'folded': ['cat', 'ann'],
    'players': {'ann': ['Jc', 'Jh'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['bob']),
  ('flush kickers deep',
   {'board': ['Ah', 'Kh', '9h', '3d', '4s'],
    'folded': [],
    'players': {'ann': ['7h', '2h'], 'bob': ['8h', '2c']}},
   ['ann']),
  ('same category different kicker',
   {'board': ['Ah', '8d', '7c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['8c', 'Kd'], 'bob': ['8s', 'Qd']}},
   ['ann']),
  ('two pair split',
   {'board': ['Kh', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['As', '4d']}},
   ['ann', 'bob']),
  ('set beats two pair',
   {'board': ['Kh', '8d', '7c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['8c', '8s'], 'bob': ['Kc', '7d']}},
   ['ann']),
  ('three-way split',
   {'board': ['6h', '7d', '8c', '9s', 'Th'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['2h', '3c'], 'cat': ['2d', '4c']}},
   ['ann', 'bob', 'cat']),
  ('single hole flush',
   {'board': ['2s', '7s', '9s', 'Js', '4d'],
    'folded': [],
    'players': {'ann': ['As', 'Kd'], 'bob': ['Qc', 'Qd']}},
   ['ann'])],
 [('board plays for both',
   {'board': ['Th', 'Jd', 'Qc', 'Ks', 'Ah'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['4h', '5s']}},
   ['ann', 'bob']),
  ('one hole card plays',
   {'board': ['Ah', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('kicker on paired board',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', 'Jd'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('folded best hand ignored',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': ['ann', 'dee'],
    'players': {'ann': ['9c', '9s'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['cat']),
  ('folded first then other',
   {'board': ['2h', '7d', '9c', 'Js', '4h'],
    'folded': ['cat', 'ann'],
    'players': {'ann': ['Jc', 'Jh'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['bob']),
  ('set beats two pair',
   {'board': ['Kh', '8d', '7c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['8c', '8s'], 'bob': ['Kc', '7d']}},
   ['ann']),
  ('three-way split',
   {'board': ['6h', '7d', '8c', '9s', 'Th'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['2h', '3c'], 'cat': ['2d', '4c']}},
   ['ann', 'bob', 'cat']),
  ('single hole flush',
   {'board': ['2s', '7s', '9s', 'Js', '4d'],
    'folded': [],
    'players': {'ann': ['As', 'Kd'], 'bob': ['Qc', 'Qd']}},
   ['ann'])],
 [('board plays for both',
   {'board': ['Th', 'Jd', 'Qc', 'Ks', 'Ah'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['4h', '5s']}},
   ['ann', 'bob']),
  ('one hole card plays',
   {'board': ['Ah', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('kicker on paired board',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', 'Jd'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('folded best hand ignored',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': ['ann', 'dee'],
    'players': {'ann': ['9c', '9s'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['cat']),
  ('folded first then other',
   {'board': ['2h', '7d', '9c', 'Js', '4h'],
    'folded': ['cat', 'ann'],
    'players': {'ann': ['Jc', 'Jh'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['bob']),
  ('flush second card decides',
   {'board': ['2h', '7h', '9h', 'Jd', '4s'],
    'folded': [],
    'players': {'ann': ['Ah', '3h'], 'bob': ['Kh', 'Qh']}},
   ['ann']),
  ('flush fourth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['7h', '2c'], 'bob': ['8h', '2d']}},
   ['bob']),
  ('flush fifth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['2h', 'Kc'], 'bob': ['Kd', '2d']}},
   ['ann'])]]
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 set is declared the winner.

Input: {"board": five community cards, "players": {name: two hole cards}, "folded": [names]}. Each live player uses the best five of their seven cards (zero, one or two hole cards may play). Return the sorted list of live players holding the best hand; ties split.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import collections
import itertools
N = 1
observations = []
def solve(x):
    R='23456789TJQKA'
    def key5(h):
        vals=sorted((R.index(c[0])+2 for c in h), reverse=True)
        cnt=collections.Counter(vals)
        order=sorted(cnt, key=lambda v:(cnt[v],v), reverse=True)
        shape=sorted(cnt.values(), reverse=True)
        flush=len({c[1] for c in h})==1
        straight=len(cnt)==5 and (vals[0]-vals[4]==4 or vals==[14,5,4,3,2])
        top=5 if vals==[14,5,4,3,2] else vals[0]
        if straight and flush: return (8,[top])
        if shape==[4,1]: return (7,order)
        if shape==[3,2]: return (6,order)
        if flush: return (5,vals)
        if straight: return (4,[top])
        if shape==[3,1,1]: return (3,order)
        if shape==[2,2,1]: return (2,order)
        if shape==[2,1,1,1]: return (1,order)
        return (0,vals)

    board=x['board']; folded=x.get('folded',[])
    scores={}
    for name,hole in x['players'].items():
        if name in folded: continue
        scores[name]=max(key5(c) for c in itertools.combinations(hole+board,5))
    best=max(scores.values())
    return [max(scores, key=scores.get)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('board plays for both',
   {'board': ['Th', 'Jd', 'Qc', 'Ks', 'Ah'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['4h', '5s']}},
   ['ann', 'bob']),
  ('one hole card plays',
   {'board': ['Ah', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('kicker on paired board',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', 'Jd'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('folded best hand ignored',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': ['ann', 'dee'],
    'players': {'ann': ['9c', '9s'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['cat']),
  ('folded first then other',
   {'board': ['2h', '7d', '9c', 'Js', '4h'],
    'folded': ['cat', 'ann'],
    'players': {'ann': ['Jc', 'Jh'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['bob']),
  ('flush fifth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['2h', 'Kc'], 'bob': ['Kd', '2d']}},
   ['ann']),
  ('flush kickers deep',
   {'board': ['Ah', 'Kh', '9h', '3d', '4s'],
    'folded': [],
    'players': {'ann': ['7h', '2h'], 'bob': ['8h', '2c']}},
   ['ann']),
  ('two pair split',
   {'board': ['Kh', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['As', '4d']}},
   ['ann', 'bob'])],
 [('board plays for both',
   {'board': ['Th', 'Jd', 'Qc', 'Ks', 'Ah'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['4h', '5s']}},
   ['ann', 'bob']),
  ('kicker on paired board',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', 'Jd'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('flush second card decides',
   {'board': ['2h', '7h', '9h', 'Jd', '4s'],
    'folded': [],
    'players': {'ann': ['Ah', '3h'], 'bob': ['Kh', 'Qh']}},
   ['ann']),
  ('flush kickers deep',
   {'board': ['Ah', 'Kh', '9h', '3d', '4s'],
    'folded': [],
    'players': {'ann': ['7h', '2h'], 'bob': ['8h', '2c']}},
   ['ann']),
  ('two pair split',
   {'board': ['Kh', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['As', '4d']}},
   ['ann', 'bob']),
  ('set beats two pair',
   {'board': ['Kh', '8d', '7c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['8c', '8s'], 'bob': ['Kc', '7d']}},
   ['ann']),
  ('three-way split',
   {'board': ['6h', '7d', '8c', '9s', 'Th'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['2h', '3c'], 'cat': ['2d', '4c']}},
   ['ann', 'bob', 'cat']),
  ('single hole flush',
   {'board': ['2s', '7s', '9s', 'Js', '4d'],
    'folded': [],
    'players': {'ann': ['As', 'Kd'], 'bob': ['Qc', 'Qd']}},
   ['ann'])],
 [('board plays for both',
   {'board': ['Th', 'Jd', 'Qc', 'Ks', 'Ah'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['4h', '5s']}},
   ['ann', 'bob']),
  ('one hole card plays',
   {'board': ['Ah', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('kicker on paired board',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', 'Jd'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('flush second card decides',
   {'board': ['2h', '7h', '9h', 'Jd', '4s'],
    'folded': [],
    'players': {'ann': ['Ah', '3h'], 'bob': ['Kh', 'Qh']}},
   ['ann']),
  ('flush fourth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['7h', '2c'], 'bob': ['8h', '2d']}},
   ['bob']),
  ('same category different kicker',
   {'board': ['Ah', '8d', '7c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['8c', 'Kd'], 'bob': ['8s', 'Qd']}},
   ['ann']),
  ('two pair split',
   {'board': ['Kh', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['As', '4d']}},
   ['ann', 'bob']),
  ('three-way split',
   {'board': ['6h', '7d', '8c', '9s', 'Th'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['2h', '3c'], 'cat': ['2d', '4c']}},
   ['ann', 'bob', 'cat'])],
 [('board plays for both',
   {'board': ['Th', 'Jd', 'Qc', 'Ks', 'Ah'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['4h', '5s']}},
   ['ann', 'bob']),
  ('folded best hand ignored',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': ['ann', 'dee'],
    'players': {'ann': ['9c', '9s'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['cat']),
  ('folded first then other',
   {'board': ['2h', '7d', '9c', 'Js', '4h'],
    'folded': ['cat', 'ann'],
    'players': {'ann': ['Jc', 'Jh'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['bob']),
  ('flush second card decides',
   {'board': ['2h', '7h', '9h', 'Jd', '4s'],
    'folded': [],
    'players': {'ann': ['Ah', '3h'], 'bob': ['Kh', 'Qh']}},
   ['ann']),
  ('flush fourth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['7h', '2c'], 'bob': ['8h', '2d']}},
   ['bob']),
  ('same category different kicker',
   {'board': ['Ah', '8d', '7c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['8c', 'Kd'], 'bob': ['8s', 'Qd']}},
   ['ann']),
  ('two pair split',
   {'board': ['Kh', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['As', '4d']}},
   ['ann', 'bob']),
  ('three-way split',
   {'board': ['6h', '7d', '8c', '9s', 'Th'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['2h', '3c'], 'cat': ['2d', '4c']}},
   ['ann', 'bob', 'cat'])],
 [('one hole card plays',
   {'board': ['Ah', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('folded best hand ignored',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': ['ann', 'dee'],
    'players': {'ann': ['9c', '9s'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['cat']),
  ('folded first then other',
   {'board': ['2h', '7d', '9c', 'Js', '4h'],
    'folded': ['cat', 'ann'],
    'players': {'ann': ['Jc', 'Jh'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['bob']),
  ('flush fifth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['2h', 'Kc'], 'bob': ['Kd', '2d']}},
   ['ann']),
  ('flush kickers deep',
   {'board': ['Ah', 'Kh', '9h', '3d', '4s'],
    'folded': [],
    'players': {'ann': ['7h', '2h'], 'bob': ['8h', '2c']}},
   ['ann']),
  ('same category different kicker',
   {'board': ['Ah', '8d', '7c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['8c', 'Kd'], 'bob': ['8s', 'Qd']}},
   ['ann']),
  ('two pair split',
   {'board': ['Kh', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['As', '4d']}},
   ['ann', 'bob']),
  ('three-way split',
   {'board': ['6h', '7d', '8c', '9s', 'Th'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['2h', '3c'], 'cat': ['2d', '4c']}},
   ['ann', 'bob', 'cat'])]]
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
import collections
import itertools
N = 1
observations = []
def solve(x):
    R='23456789TJQKA'
    def key5(h):
        vals=sorted((R.index(c[0])+2 for c in h), reverse=True)
        cnt=collections.Counter(vals)
        order=sorted(cnt, key=lambda v:(cnt[v],v), reverse=True)
        shape=sorted(cnt.values(), reverse=True)
        flush=len({c[1] for c in h})==1
        straight=len(cnt)==5 and (vals[0]-vals[4]==4 or vals==[14,5,4,3,2])
        top=5 if vals==[14,5,4,3,2] else vals[0]
        if straight and flush: return (8,[top])
        if shape==[4,1]: return (7,order)
        if shape==[3,2]: return (6,order)
        if flush: return (5,vals)
        if straight: return (4,[top])
        if shape==[3,1,1]: return (3,order)
        if shape==[2,2,1]: return (2,order)
        if shape==[2,1,1,1]: return (1,order)
        return (0,vals)

    board=x['board']; folded=x.get('folded',[])
    scores={}
    for name,hole in x['players'].items():
        if name in folded: continue
        scores[name]=max(key5(c) for c in itertools.combinations(hole+board,5))
    best=max(scores.values())
    return sorted(n for n,k in scores.items() if k[0]==best[0])
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('board plays for both',
   {'board': ['Th', 'Jd', 'Qc', 'Ks', 'Ah'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['4h', '5s']}},
   ['ann', 'bob']),
  ('one hole card plays',
   {'board': ['Ah', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('kicker on paired board',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', 'Jd'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('folded best hand ignored',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': ['ann', 'dee'],
    'players': {'ann': ['9c', '9s'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['cat']),
  ('folded first then other',
   {'board': ['2h', '7d', '9c', 'Js', '4h'],
    'folded': ['cat', 'ann'],
    'players': {'ann': ['Jc', 'Jh'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['bob']),
  ('flush fifth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['2h', 'Kc'], 'bob': ['Kd', '2d']}},
   ['ann']),
  ('flush kickers deep',
   {'board': ['Ah', 'Kh', '9h', '3d', '4s'],
    'folded': [],
    'players': {'ann': ['7h', '2h'], 'bob': ['8h', '2c']}},
   ['ann']),
  ('two pair split',
   {'board': ['Kh', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['As', '4d']}},
   ['ann', 'bob'])],
 [('board plays for both',
   {'board': ['Th', 'Jd', 'Qc', 'Ks', 'Ah'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['4h', '5s']}},
   ['ann', 'bob']),
  ('kicker on paired board',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', 'Jd'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('flush second card decides',
   {'board': ['2h', '7h', '9h', 'Jd', '4s'],
    'folded': [],
    'players': {'ann': ['Ah', '3h'], 'bob': ['Kh', 'Qh']}},
   ['ann']),
  ('flush kickers deep',
   {'board': ['Ah', 'Kh', '9h', '3d', '4s'],
    'folded': [],
    'players': {'ann': ['7h', '2h'], 'bob': ['8h', '2c']}},
   ['ann']),
  ('two pair split',
   {'board': ['Kh', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['As', '4d']}},
   ['ann', 'bob']),
  ('set beats two pair',
   {'board': ['Kh', '8d', '7c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['8c', '8s'], 'bob': ['Kc', '7d']}},
   ['ann']),
  ('three-way split',
   {'board': ['6h', '7d', '8c', '9s', 'Th'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['2h', '3c'], 'cat': ['2d', '4c']}},
   ['ann', 'bob', 'cat']),
  ('single hole flush',
   {'board': ['2s', '7s', '9s', 'Js', '4d'],
    'folded': [],
    'players': {'ann': ['As', 'Kd'], 'bob': ['Qc', 'Qd']}},
   ['ann'])],
 [('board plays for both',
   {'board': ['Th', 'Jd', 'Qc', 'Ks', 'Ah'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['4h', '5s']}},
   ['ann', 'bob']),
  ('one hole card plays',
   {'board': ['Ah', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('kicker on paired board',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', 'Jd'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('flush second card decides',
   {'board': ['2h', '7h', '9h', 'Jd', '4s'],
    'folded': [],
    'players': {'ann': ['Ah', '3h'], 'bob': ['Kh', 'Qh']}},
   ['ann']),
  ('flush fourth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['7h', '2c'], 'bob': ['8h', '2d']}},
   ['bob']),
  ('same category different kicker',
   {'board': ['Ah', '8d', '7c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['8c', 'Kd'], 'bob': ['8s', 'Qd']}},
   ['ann']),
  ('two pair split',
   {'board': ['Kh', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['As', '4d']}},
   ['ann', 'bob']),
  ('three-way split',
   {'board': ['6h', '7d', '8c', '9s', 'Th'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['2h', '3c'], 'cat': ['2d', '4c']}},
   ['ann', 'bob', 'cat'])],
 [('board plays for both',
   {'board': ['Th', 'Jd', 'Qc', 'Ks', 'Ah'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['4h', '5s']}},
   ['ann', 'bob']),
  ('folded best hand ignored',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': ['ann', 'dee'],
    'players': {'ann': ['9c', '9s'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['cat']),
  ('folded first then other',
   {'board': ['2h', '7d', '9c', 'Js', '4h'],
    'folded': ['cat', 'ann'],
    'players': {'ann': ['Jc', 'Jh'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['bob']),
  ('flush second card decides',
   {'board': ['2h', '7h', '9h', 'Jd', '4s'],
    'folded': [],
    'players': {'ann': ['Ah', '3h'], 'bob': ['Kh', 'Qh']}},
   ['ann']),
  ('flush fourth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['7h', '2c'], 'bob': ['8h', '2d']}},
   ['bob']),
  ('same category different kicker',
   {'board': ['Ah', '8d', '7c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['8c', 'Kd'], 'bob': ['8s', 'Qd']}},
   ['ann']),
  ('two pair split',
   {'board': ['Kh', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['As', '4d']}},
   ['ann', 'bob']),
  ('three-way split',
   {'board': ['6h', '7d', '8c', '9s', 'Th'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['2h', '3c'], 'cat': ['2d', '4c']}},
   ['ann', 'bob', 'cat'])],
 [('one hole card plays',
   {'board': ['Ah', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('folded best hand ignored',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': ['ann', 'dee'],
    'players': {'ann': ['9c', '9s'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['cat']),
  ('folded first then other',
   {'board': ['2h', '7d', '9c', 'Js', '4h'],
    'folded': ['cat', 'ann'],
    'players': {'ann': ['Jc', 'Jh'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['bob']),
  ('flush fifth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['2h', 'Kc'], 'bob': ['Kd', '2d']}},
   ['ann']),
  ('flush kickers deep',
   {'board': ['Ah', 'Kh', '9h', '3d', '4s'],
    'folded': [],
    'players': {'ann': ['7h', '2h'], 'bob': ['8h', '2c']}},
   ['ann']),
  ('same category different kicker',
   {'board': ['Ah', '8d', '7c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['8c', 'Kd'], 'bob': ['8s', 'Qd']}},
   ['ann']),
  ('two pair split',
   {'board': ['Kh', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['As', '4d']}},
   ['ann', 'bob']),
  ('three-way split',
   {'board': ['6h', '7d', '8c', '9s', 'Th'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['2h', '3c'], 'cat': ['2d', '4c']}},
   ['ann', 'bob', 'cat'])]]
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:
When the board plays, only one player is returned instead of a split.

Input: {"board": five community cards, "players": {name: two hole cards}, "folded": [names]}. Each live player uses the best five of their seven cards (zero, one or two hole cards may play). Return the sorted list of live players holding the best hand; ties split.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import collections
import itertools
N = 1
observations = []
def solve(x):
    R='23456789TJQKA'
    def key5(h):
        vals=sorted((R.index(c[0])+2 for c in h), reverse=True)
        cnt=collections.Counter(vals)
        order=sorted(cnt, key=lambda v:(cnt[v],v), reverse=True)
        shape=sorted(cnt.values(), reverse=True)
        flush=len({c[1] for c in h})==1
        straight=len(cnt)==5 and (vals[0]-vals[4]==4 or vals==[14,5,4,3,2])
        top=5 if vals==[14,5,4,3,2] else vals[0]
        if straight and flush: return (8,[top])
        if shape==[4,1]: return (7,order)
        if shape==[3,2]: return (6,order)
        if flush: return (5,[vals[0]])
        if straight: return (4,[top])
        if shape==[3,1,1]: return (3,order)
        if shape==[2,2,1]: return (2,order)
        if shape==[2,1,1,1]: return (1,order)
        return (0,vals)

    board=x['board']; folded=x.get('folded',[])
    scores={}
    for name,hole in x['players'].items():
        if name in folded: continue
        scores[name]=max(key5(c) for c in itertools.combinations(hole+board,5))
    best=max(scores.values())
    return sorted(n for n,k in scores.items() if k==best)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('board plays for both',
   {'board': ['Th', 'Jd', 'Qc', 'Ks', 'Ah'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['4h', '5s']}},
   ['ann', 'bob']),
  ('one hole card plays',
   {'board': ['Ah', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('kicker on paired board',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', 'Jd'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('folded best hand ignored',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': ['ann', 'dee'],
    'players': {'ann': ['9c', '9s'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['cat']),
  ('folded first then other',
   {'board': ['2h', '7d', '9c', 'Js', '4h'],
    'folded': ['cat', 'ann'],
    'players': {'ann': ['Jc', 'Jh'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['bob']),
  ('flush second card decides',
   {'board': ['2h', '7h', '9h', 'Jd', '4s'],
    'folded': [],
    'players': {'ann': ['Ah', '3h'], 'bob': ['Kh', 'Qh']}},
   ['ann']),
  ('flush fourth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['7h', '2c'], 'bob': ['8h', '2d']}},
   ['bob']),
  ('flush fifth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['2h', 'Kc'], 'bob': ['Kd', '2d']}},
   ['ann'])],
 [('folded best hand ignored',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': ['ann', 'dee'],
    'players': {'ann': ['9c', '9s'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['cat']),
  ('folded first then other',
   {'board': ['2h', '7d', '9c', 'Js', '4h'],
    'folded': ['cat', 'ann'],
    'players': {'ann': ['Jc', 'Jh'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['bob']),
  ('flush second card decides',
   {'board': ['2h', '7h', '9h', 'Jd', '4s'],
    'folded': [],
    'players': {'ann': ['Ah', '3h'], 'bob': ['Kh', 'Qh']}},
   ['ann']),
  ('flush fourth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['7h', '2c'], 'bob': ['8h', '2d']}},
   ['bob']),
  ('flush fifth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['2h', 'Kc'], 'bob': ['Kd', '2d']}},
   ['ann']),
  ('flush kickers deep',
   {'board': ['Ah', 'Kh', '9h', '3d', '4s'],
    'folded': [],
    'players': {'ann': ['7h', '2h'], 'bob': ['8h', '2c']}},
   ['ann']),
  ('same category different kicker',
   {'board': ['Ah', '8d', '7c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['8c', 'Kd'], 'bob': ['8s', 'Qd']}},
   ['ann']),
  ('two pair split',
   {'board': ['Kh', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['As', '4d']}},
   ['ann', 'bob'])],
 [('flush fourth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['7h', '2c'], 'bob': ['8h', '2d']}},
   ['bob']),
  ('flush fifth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['2h', 'Kc'], 'bob': ['Kd', '2d']}},
   ['ann']),
  ('flush kickers deep',
   {'board': ['Ah', 'Kh', '9h', '3d', '4s'],
    'folded': [],
    'players': {'ann': ['7h', '2h'], 'bob': ['8h', '2c']}},
   ['ann']),
  ('same category different kicker',
   {'board': ['Ah', '8d', '7c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['8c', 'Kd'], 'bob': ['8s', 'Qd']}},
   ['ann']),
  ('two pair split',
   {'board': ['Kh', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['As', '4d']}},
   ['ann', 'bob']),
  ('set beats two pair',
   {'board': ['Kh', '8d', '7c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['8c', '8s'], 'bob': ['Kc', '7d']}},
   ['ann']),
  ('three-way split',
   {'board': ['6h', '7d', '8c', '9s', 'Th'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['2h', '3c'], 'cat': ['2d', '4c']}},
   ['ann', 'bob', 'cat']),
  ('single hole flush',
   {'board': ['2s', '7s', '9s', 'Js', '4d'],
    'folded': [],
    'players': {'ann': ['As', 'Kd'], 'bob': ['Qc', 'Qd']}},
   ['ann'])],
 [('board plays for both',
   {'board': ['Th', 'Jd', 'Qc', 'Ks', 'Ah'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['4h', '5s']}},
   ['ann', 'bob']),
  ('one hole card plays',
   {'board': ['Ah', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('kicker on paired board',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', 'Jd'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('flush fourth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['7h', '2c'], 'bob': ['8h', '2d']}},
   ['bob']),
  ('two pair split',
   {'board': ['Kh', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['As', '4d']}},
   ['ann', 'bob']),
  ('set beats two pair',
   {'board': ['Kh', '8d', '7c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['8c', '8s'], 'bob': ['Kc', '7d']}},
   ['ann']),
  ('three-way split',
   {'board': ['6h', '7d', '8c', '9s', 'Th'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['2h', '3c'], 'cat': ['2d', '4c']}},
   ['ann', 'bob', 'cat']),
  ('single hole flush',
   {'board': ['2s', '7s', '9s', 'Js', '4d'],
    'folded': [],
    'players': {'ann': ['As', 'Kd'], 'bob': ['Qc', 'Qd']}},
   ['ann'])],
 [('board plays for both',
   {'board': ['Th', 'Jd', 'Qc', 'Ks', 'Ah'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['4h', '5s']}},
   ['ann', 'bob']),
  ('one hole card plays',
   {'board': ['Ah', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('kicker on paired board',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', 'Jd'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('folded best hand ignored',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': ['ann', 'dee'],
    'players': {'ann': ['9c', '9s'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['cat']),
  ('folded first then other',
   {'board': ['2h', '7d', '9c', 'Js', '4h'],
    'folded': ['cat', 'ann'],
    'players': {'ann': ['Jc', 'Jh'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['bob']),
  ('flush second card decides',
   {'board': ['2h', '7h', '9h', 'Jd', '4s'],
    'folded': [],
    'players': {'ann': ['Ah', '3h'], 'bob': ['Kh', 'Qh']}},
   ['ann']),
  ('flush fourth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['7h', '2c'], 'bob': ['8h', '2d']}},
   ['bob']),
  ('single hole flush',
   {'board': ['2s', '7s', '9s', 'Js', '4d'],
    'folded': [],
    'players': {'ann': ['As', 'Kd'], 'bob': ['Qc', 'Qd']}},
   ['ann'])]]
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
import itertools
N = 1
observations = []
def solve(x):
    R='23456789TJQKA'
    def key5(h):
        vals=sorted((R.index(c[0])+2 for c in h), reverse=True)
        cnt=collections.Counter(vals)
        order=sorted(cnt, key=lambda v:(cnt[v],v), reverse=True)
        shape=sorted(cnt.values(), reverse=True)
        flush=len({c[1] for c in h})==1
        straight=len(cnt)==5 and (vals[0]-vals[4]==4 or vals==[14,5,4,3,2])
        top=5 if vals==[14,5,4,3,2] else vals[0]
        if straight and flush: return (8,[top])
        if shape==[4,1]: return (7,order)
        if shape==[3,2]: return (6,order)
        if flush: return (5,vals[:2])
        if straight: return (4,[top])
        if shape==[3,1,1]: return (3,order)
        if shape==[2,2,1]: return (2,order)
        if shape==[2,1,1,1]: return (1,order)
        return (0,vals)

    board=x['board']; folded=x.get('folded',[])
    scores={}
    for name,hole in x['players'].items():
        if name in folded: continue
        scores[name]=max(key5(c) for c in itertools.combinations(hole+board,5))
    best=max(scores.values())
    return sorted(n for n,k in scores.items() if k==best)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('board plays for both',
   {'board': ['Th', 'Jd', 'Qc', 'Ks', 'Ah'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['4h', '5s']}},
   ['ann', 'bob']),
  ('one hole card plays',
   {'board': ['Ah', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('kicker on paired board',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', 'Jd'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('folded best hand ignored',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': ['ann', 'dee'],
    'players': {'ann': ['9c', '9s'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['cat']),
  ('folded first then other',
   {'board': ['2h', '7d', '9c', 'Js', '4h'],
    'folded': ['cat', 'ann'],
    'players': {'ann': ['Jc', 'Jh'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['bob']),
  ('flush second card decides',
   {'board': ['2h', '7h', '9h', 'Jd', '4s'],
    'folded': [],
    'players': {'ann': ['Ah', '3h'], 'bob': ['Kh', 'Qh']}},
   ['ann']),
  ('flush fourth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['7h', '2c'], 'bob': ['8h', '2d']}},
   ['bob']),
  ('flush fifth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['2h', 'Kc'], 'bob': ['Kd', '2d']}},
   ['ann'])],
 [('folded best hand ignored',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': ['ann', 'dee'],
    'players': {'ann': ['9c', '9s'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['cat']),
  ('folded first then other',
   {'board': ['2h', '7d', '9c', 'Js', '4h'],
    'folded': ['cat', 'ann'],
    'players': {'ann': ['Jc', 'Jh'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['bob']),
  ('flush second card decides',
   {'board': ['2h', '7h', '9h', 'Jd', '4s'],
    'folded': [],
    'players': {'ann': ['Ah', '3h'], 'bob': ['Kh', 'Qh']}},
   ['ann']),
  ('flush fourth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['7h', '2c'], 'bob': ['8h', '2d']}},
   ['bob']),
  ('flush fifth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['2h', 'Kc'], 'bob': ['Kd', '2d']}},
   ['ann']),
  ('flush kickers deep',
   {'board': ['Ah', 'Kh', '9h', '3d', '4s'],
    'folded': [],
    'players': {'ann': ['7h', '2h'], 'bob': ['8h', '2c']}},
   ['ann']),
  ('same category different kicker',
   {'board': ['Ah', '8d', '7c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['8c', 'Kd'], 'bob': ['8s', 'Qd']}},
   ['ann']),
  ('two pair split',
   {'board': ['Kh', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['As', '4d']}},
   ['ann', 'bob'])],
 [('flush fourth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['7h', '2c'], 'bob': ['8h', '2d']}},
   ['bob']),
  ('flush fifth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['2h', 'Kc'], 'bob': ['Kd', '2d']}},
   ['ann']),
  ('flush kickers deep',
   {'board': ['Ah', 'Kh', '9h', '3d', '4s'],
    'folded': [],
    'players': {'ann': ['7h', '2h'], 'bob': ['8h', '2c']}},
   ['ann']),
  ('same category different kicker',
   {'board': ['Ah', '8d', '7c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['8c', 'Kd'], 'bob': ['8s', 'Qd']}},
   ['ann']),
  ('two pair split',
   {'board': ['Kh', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['As', '4d']}},
   ['ann', 'bob']),
  ('set beats two pair',
   {'board': ['Kh', '8d', '7c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['8c', '8s'], 'bob': ['Kc', '7d']}},
   ['ann']),
  ('three-way split',
   {'board': ['6h', '7d', '8c', '9s', 'Th'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['2h', '3c'], 'cat': ['2d', '4c']}},
   ['ann', 'bob', 'cat']),
  ('single hole flush',
   {'board': ['2s', '7s', '9s', 'Js', '4d'],
    'folded': [],
    'players': {'ann': ['As', 'Kd'], 'bob': ['Qc', 'Qd']}},
   ['ann'])],
 [('board plays for both',
   {'board': ['Th', 'Jd', 'Qc', 'Ks', 'Ah'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['4h', '5s']}},
   ['ann', 'bob']),
  ('one hole card plays',
   {'board': ['Ah', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('kicker on paired board',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', 'Jd'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('flush fourth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['7h', '2c'], 'bob': ['8h', '2d']}},
   ['bob']),
  ('two pair split',
   {'board': ['Kh', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['As', '4d']}},
   ['ann', 'bob']),
  ('set beats two pair',
   {'board': ['Kh', '8d', '7c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['8c', '8s'], 'bob': ['Kc', '7d']}},
   ['ann']),
  ('three-way split',
   {'board': ['6h', '7d', '8c', '9s', 'Th'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['2h', '3c'], 'cat': ['2d', '4c']}},
   ['ann', 'bob', 'cat']),
  ('single hole flush',
   {'board': ['2s', '7s', '9s', 'Js', '4d'],
    'folded': [],
    'players': {'ann': ['As', 'Kd'], 'bob': ['Qc', 'Qd']}},
   ['ann'])],
 [('board plays for both',
   {'board': ['Th', 'Jd', 'Qc', 'Ks', 'Ah'],
    'folded': [],
    'players': {'ann': ['2c', '3d'], 'bob': ['4h', '5s']}},
   ['ann', 'bob']),
  ('one hole card plays',
   {'board': ['Ah', 'Kd', '7c', '7s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', '3d'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('kicker on paired board',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': [],
    'players': {'ann': ['Ac', 'Jd'], 'bob': ['Kc', 'Qs']}},
   ['ann']),
  ('folded best hand ignored',
   {'board': ['9h', '9d', '5c', '4s', '2h'],
    'folded': ['ann', 'dee'],
    'players': {'ann': ['9c', '9s'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['cat']),
  ('folded first then other',
   {'board': ['2h', '7d', '9c', 'Js', '4h'],
    'folded': ['cat', 'ann'],
    'players': {'ann': ['Jc', 'Jh'], 'bob': ['Kc', 'Qs'], 'cat': ['Ac', '3s']}},
   ['bob']),
  ('flush second card decides',
   {'board': ['2h', '7h', '9h', 'Jd', '4s'],
    'folded': [],
    'players': {'ann': ['Ah', '3h'], 'bob': ['Kh', 'Qh']}},
   ['ann']),
  ('flush fourth card decides',
   {'board': ['Ah', 'Th', '9h', '3h', '4s'],
    'folded': [],
    'players': {'ann': ['7h', '2c'], 'bob': ['8h', '2d']}},
   ['bob']),
  ('single hole flush',
   {'board': ['2s', '7s', '9s', 'Js', '4d'],
    'folded': [],
    'players': {'ann': ['As', 'Kd'], 'bob': ['Qc', 'Qd']}},
   ['ann'])]]
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:
Two ace-high flushes are split although one has a better second or fifth card.

Input: {"board": five community cards, "players": {name: two hole cards}, "folded": [names]}. Each live player uses the best five of their seven cards (zero, one or two hole cards may play). Return the sorted list of live players holding the best hand; ties split.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import collections
import itertools
N = 1
observations = []
def solve(x):
    R='23456789TJQKA'
    def key5(h):
        vals=sorted((R.index(c[0])+2 for c in h), reverse=True)
        cnt=collections.Counter(vals)
        order=sorted(cnt, key=lambda v:(cnt[v],v), reverse=True)
        shape=sorted(cnt.values(), reverse=True)
        flush=len({c[1] for c in h})==1
        straight=len(cnt)==5 and (vals[0]-vals[4]==4 or vals==[14,5,4,3,2])
        top=5 if vals==[14,5,4,3,2] else vals[0]
        if straight and flush: return (8,[top])
        if shape==[4,1]: return (7,order)
        if shape==[3,2]: return (6,order)
        if flush: return (5,vals)
        if straight: return (4,[top])
        if shape==[3,1,1]: return (3,order)
        if shape==[2,2,1]: return (2,order)
        if shape==[2,1,1,1]: return (1,order)
        return (0,vals)

    NAMES=['high card','one pair','two pair','three of a kind','straight','flush','full house','four of a kind','straight flush']
    hole=x['hole']; board=x['board']
    if len(hole)!={'plo':4,'plo5':5}[x['variant']]: return 'invalid'
    if not 3<=len(board)<=5: return 'invalid'
    allc=hole+board
    if len(set(allc))!=len(allc): return 'invalid'
    cands=list(itertools.combinations(hole+board,5))
    return NAMES[max(key5(c) for c in cands)[0]]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('board flush one suited hole card',
   {'board': ['2h', '5h', '7h', '9h', 'Th'], 'hole': ['Ah', 'Kd', 'Qc', 'Js'], 'variant': 'plo'},
   'high card'),
  ('board straight',
   {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['2c', '2d', '3c', '3s'], 'variant': 'plo'},
   'one pair'),
  ('real flush',
   {'board': ['2h', '5h', '7h', '9d', 'Tc'], 'hole': ['Ah', 'Kh', 'Qc', 'Js'], 'variant': 'plo'},
   'flush'),
  ('turn board',
   {'board': ['Tc', 'Jd', '2c', '5h'], 'hole': ['8h', '9d', 'Kc', 'Ks'], 'variant': 'plo'},
   'one pair'),
  ('two card board', {'board': ['Ac', '7d'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'},
   'invalid'),
  ('plo with five holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks', '2d'], 'variant': 'plo'},
   'invalid'),
  ('plo5 with four holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo5'}, 'invalid'),
  ('duplicate across hole and board',
   {'board': ['Ah', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'}, 'invalid')],
 [('board flush one suited hole card',
   {'board': ['2h', '5h', '7h', '9h', 'Th'], 'hole': ['Ah', 'Kd', 'Qc', 'Js'], 'variant': 'plo'},
   'high card'),
  ('board straight',
   {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['2c', '2d', '3c', '3s'], 'variant': 'plo'},
   'one pair'),
  ('four aces in hand',
   {'board': ['2h', '7d', '9c', 'Js', '4h'], 'hole': ['Ah', 'Ad', 'Ac', 'As'], 'variant': 'plo'},
   'one pair'),
  ('plo with five holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks', '2d'], 'variant': 'plo'},
   'invalid'),
  ('plo5 with four holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo5'}, 'invalid'),
  ('duplicate across hole and board',
   {'board': ['Ah', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'}, 'invalid'),
  ('duplicate inside hole',
   {'board': ['Qh', '7d', '2c'], 'hole': ['Ah', 'Ah', 'Kc', 'Ks'], 'variant': 'plo'}, 'invalid'),
  ('duplicate on board',
   {'board': ['Qh', 'Qh', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'}, 'invalid')],
 [('board flush one suited hole card',
   {'board': ['2h', '5h', '7h', '9h', 'Th'], 'hole': ['Ah', 'Kd', 'Qc', 'Js'], 'variant': 'plo'},
   'high card'),
  ('board straight',
   {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['2c', '2d', '3c', '3s'], 'variant': 'plo'},
   'one pair'),
  ('four aces in hand',
   {'board': ['2h', '7d', '9c', 'Js', '4h'], 'hole': ['Ah', 'Ad', 'Ac', 'As'], 'variant': 'plo'},
   'one pair'),
  ('flop only', {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'},
   'three of a kind'),
  ('plo5 five holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks', '2d'], 'variant': 'plo5'},
   'three of a kind'),
  ('duplicate inside hole',
   {'board': ['Qh', '7d', '2c'], 'hole': ['Ah', 'Ah', 'Kc', 'Ks'], 'variant': 'plo'}, 'invalid'),
  ('duplicate on board',
   {'board': ['Qh', 'Qh', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'}, 'invalid'),
  ('six card board',
   {'board': ['Qh', 'Jh', '2c', '3c', '4c', '5c'],
    'hole': ['Ah', 'Ad', 'Kc', 'Ks'],
    'variant': 'plo'},
   'invalid')],
 [('board flush one suited hole card',
   {'board': ['2h', '5h', '7h', '9h', 'Th'], 'hole': ['Ah', 'Kd', 'Qc', 'Js'], 'variant': 'plo'},
   'high card'),
  ('board straight',
   {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['2c', '2d', '3c', '3s'], 'variant': 'plo'},
   'one pair'),
  ('four aces in hand',
   {'board': ['2h', '7d', '9c', 'Js', '4h'], 'hole': ['Ah', 'Ad', 'Ac', 'As'], 'variant': 'plo'},
   'one pair'),
  ('real flush',
   {'board': ['2h', '5h', '7h', '9d', 'Tc'], 'hole': ['Ah', 'Kh', 'Qc', 'Js'], 'variant': 'plo'},
   'flush'),
  ('flop only', {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'},
   'three of a kind'),
  ('turn board',
   {'board': ['Tc', 'Jd', '2c', '5h'], 'hole': ['8h', '9d', 'Kc', 'Ks'], 'variant': 'plo'},
   'one pair'),
  ('plo5 five holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks', '2d'], 'variant': 'plo5'},
   'three of a kind'),
  ('full house two pairs in hand',
   {'board': ['Kc', '7d', '2c', '3h', '9s'], 'hole': ['Kh', 'Kd', '7c', '7s'], 'variant': 'plo'},
   'three of a kind')],
 [('board flush one suited hole card',
   {'board': ['2h', '5h', '7h', '9h', 'Th'], 'hole': ['Ah', 'Kd', 'Qc', 'Js'], 'variant': 'plo'},
   'high card'),
  ('board straight',
   {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['2c', '2d', '3c', '3s'], 'variant': 'plo'},
   'one pair'),
  ('real flush',
   {'board': ['2h', '5h', '7h', '9d', 'Tc'], 'hole': ['Ah', 'Kh', 'Qc', 'Js'], 'variant': 'plo'},
   'flush'),
  ('flop only', {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'},
   'three of a kind'),
  ('turn board',
   {'board': ['Tc', 'Jd', '2c', '5h'], 'hole': ['8h', '9d', 'Kc', 'Ks'], 'variant': 'plo'},
   'one pair'),
  ('two card board', {'board': ['Ac', '7d'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'},
   'invalid'),
  ('plo5 five holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks', '2d'], 'variant': 'plo5'},
   'three of a kind'),
  ('full house two pairs in hand',
   {'board': ['Kc', '7d', '2c', '3h', '9s'], 'hole': ['Kh', 'Kd', '7c', '7s'], 'variant': 'plo'},
   'three of a kind')]]
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
import itertools
N = 1
observations = []
def solve(x):
    R='23456789TJQKA'
    def key5(h):
        vals=sorted((R.index(c[0])+2 for c in h), reverse=True)
        cnt=collections.Counter(vals)
        order=sorted(cnt, key=lambda v:(cnt[v],v), reverse=True)
        shape=sorted(cnt.values(), reverse=True)
        flush=len({c[1] for c in h})==1
        straight=len(cnt)==5 and (vals[0]-vals[4]==4 or vals==[14,5,4,3,2])
        top=5 if vals==[14,5,4,3,2] else vals[0]
        if straight and flush: return (8,[top])
        if shape==[4,1]: return (7,order)
        if shape==[3,2]: return (6,order)
        if flush: return (5,vals)
        if straight: return (4,[top])
        if shape==[3,1,1]: return (3,order)
        if shape==[2,2,1]: return (2,order)
        if shape==[2,1,1,1]: return (1,order)
        return (0,vals)

    NAMES=['high card','one pair','two pair','three of a kind','straight','flush','full house','four of a kind','straight flush']
    hole=x['hole']; board=x['board']
    if len(hole)!={'plo':4,'plo5':5}[x['variant']]: return 'invalid'
    if not 3<=len(board)<=5: return 'invalid'
    allc=hole+board
    if len(set(allc))!=len(allc): return 'invalid'
    cands=[hc+bc for hc in itertools.combinations(hole,2) for bc in itertools.combinations(board,3)]+list(itertools.combinations(board,5))
    return NAMES[max(key5(c) for c in cands)[0]]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('board flush one suited hole card',
   {'board': ['2h', '5h', '7h', '9h', 'Th'], 'hole': ['Ah', 'Kd', 'Qc', 'Js'], 'variant': 'plo'},
   'high card'),
  ('board straight',
   {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['2c', '2d', '3c', '3s'], 'variant': 'plo'},
   'one pair'),
  ('real flush',
   {'board': ['2h', '5h', '7h', '9d', 'Tc'], 'hole': ['Ah', 'Kh', 'Qc', 'Js'], 'variant': 'plo'},
   'flush'),
  ('turn board',
   {'board': ['Tc', 'Jd', '2c', '5h'], 'hole': ['8h', '9d', 'Kc', 'Ks'], 'variant': 'plo'},
   'one pair'),
  ('two card board', {'board': ['Ac', '7d'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'},
   'invalid'),
  ('plo with five holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks', '2d'], 'variant': 'plo'},
   'invalid'),
  ('plo5 with four holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo5'}, 'invalid'),
  ('duplicate across hole and board',
   {'board': ['Ah', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'}, 'invalid')],
 [('board flush one suited hole card',
   {'board': ['2h', '5h', '7h', '9h', 'Th'], 'hole': ['Ah', 'Kd', 'Qc', 'Js'], 'variant': 'plo'},
   'high card'),
  ('board straight',
   {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['2c', '2d', '3c', '3s'], 'variant': 'plo'},
   'one pair'),
  ('four aces in hand',
   {'board': ['2h', '7d', '9c', 'Js', '4h'], 'hole': ['Ah', 'Ad', 'Ac', 'As'], 'variant': 'plo'},
   'one pair'),
  ('plo with five holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks', '2d'], 'variant': 'plo'},
   'invalid'),
  ('plo5 with four holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo5'}, 'invalid'),
  ('duplicate across hole and board',
   {'board': ['Ah', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'}, 'invalid'),
  ('duplicate inside hole',
   {'board': ['Qh', '7d', '2c'], 'hole': ['Ah', 'Ah', 'Kc', 'Ks'], 'variant': 'plo'}, 'invalid'),
  ('duplicate on board',
   {'board': ['Qh', 'Qh', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'}, 'invalid')],
 [('board flush one suited hole card',
   {'board': ['2h', '5h', '7h', '9h', 'Th'], 'hole': ['Ah', 'Kd', 'Qc', 'Js'], 'variant': 'plo'},
   'high card'),
  ('board straight',
   {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['2c', '2d', '3c', '3s'], 'variant': 'plo'},
   'one pair'),
  ('four aces in hand',
   {'board': ['2h', '7d', '9c', 'Js', '4h'], 'hole': ['Ah', 'Ad', 'Ac', 'As'], 'variant': 'plo'},
   'one pair'),
  ('flop only', {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'},
   'three of a kind'),
  ('plo5 five holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks', '2d'], 'variant': 'plo5'},
   'three of a kind'),
  ('duplicate inside hole',
   {'board': ['Qh', '7d', '2c'], 'hole': ['Ah', 'Ah', 'Kc', 'Ks'], 'variant': 'plo'}, 'invalid'),
  ('duplicate on board',
   {'board': ['Qh', 'Qh', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'}, 'invalid'),
  ('six card board',
   {'board': ['Qh', 'Jh', '2c', '3c', '4c', '5c'],
    'hole': ['Ah', 'Ad', 'Kc', 'Ks'],
    'variant': 'plo'},
   'invalid')],
 [('board flush one suited hole card',
   {'board': ['2h', '5h', '7h', '9h', 'Th'], 'hole': ['Ah', 'Kd', 'Qc', 'Js'], 'variant': 'plo'},
   'high card'),
  ('board straight',
   {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['2c', '2d', '3c', '3s'], 'variant': 'plo'},
   'one pair'),
  ('four aces in hand',
   {'board': ['2h', '7d', '9c', 'Js', '4h'], 'hole': ['Ah', 'Ad', 'Ac', 'As'], 'variant': 'plo'},
   'one pair'),
  ('real flush',
   {'board': ['2h', '5h', '7h', '9d', 'Tc'], 'hole': ['Ah', 'Kh', 'Qc', 'Js'], 'variant': 'plo'},
   'flush'),
  ('flop only', {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'},
   'three of a kind'),
  ('turn board',
   {'board': ['Tc', 'Jd', '2c', '5h'], 'hole': ['8h', '9d', 'Kc', 'Ks'], 'variant': 'plo'},
   'one pair'),
  ('plo5 five holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks', '2d'], 'variant': 'plo5'},
   'three of a kind'),
  ('full house two pairs in hand',
   {'board': ['Kc', '7d', '2c', '3h', '9s'], 'hole': ['Kh', 'Kd', '7c', '7s'], 'variant': 'plo'},
   'three of a kind')],
 [('board flush one suited hole card',
   {'board': ['2h', '5h', '7h', '9h', 'Th'], 'hole': ['Ah', 'Kd', 'Qc', 'Js'], 'variant': 'plo'},
   'high card'),
  ('board straight',
   {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['2c', '2d', '3c', '3s'], 'variant': 'plo'},
   'one pair'),
  ('real flush',
   {'board': ['2h', '5h', '7h', '9d', 'Tc'], 'hole': ['Ah', 'Kh', 'Qc', 'Js'], 'variant': 'plo'},
   'flush'),
  ('flop only', {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'},
   'three of a kind'),
  ('turn board',
   {'board': ['Tc', 'Jd', '2c', '5h'], 'hole': ['8h', '9d', 'Kc', 'Ks'], 'variant': 'plo'},
   'one pair'),
  ('two card board', {'board': ['Ac', '7d'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'},
   'invalid'),
  ('plo5 five holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks', '2d'], 'variant': 'plo5'},
   'three of a kind'),
  ('full house two pairs in hand',
   {'board': ['Kc', '7d', '2c', '3h', '9s'], 'hole': ['Kh', 'Kd', '7c', '7s'], 'variant': 'plo'},
   'three of a kind')]]
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 single suited hole card makes a flush on a four-flush board, and four aces in hand count as quads.

Input: {"variant": "plo" (4 hole cards) or "plo5" (5 hole cards), "hole": [...], "board": 3 to 5 cards}. The hand must use exactly two hole cards and exactly three board cards. Return the best category name, or "invalid" for a wrong hole count, a board outside 3-5 cards, or a duplicated card.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import collections
import itertools
N = 1
observations = []
def solve(x):
    R='23456789TJQKA'
    def key5(h):
        vals=sorted((R.index(c[0])+2 for c in h), reverse=True)
        cnt=collections.Counter(vals)
        order=sorted(cnt, key=lambda v:(cnt[v],v), reverse=True)
        shape=sorted(cnt.values(), reverse=True)
        flush=len({c[1] for c in h})==1
        straight=len(cnt)==5 and (vals[0]-vals[4]==4 or vals==[14,5,4,3,2])
        top=5 if vals==[14,5,4,3,2] else vals[0]
        if straight and flush: return (8,[top])
        if shape==[4,1]: return (7,order)
        if shape==[3,2]: return (6,order)
        if flush: return (5,vals)
        if straight: return (4,[top])
        if shape==[3,1,1]: return (3,order)
        if shape==[2,2,1]: return (2,order)
        if shape==[2,1,1,1]: return (1,order)
        return (0,vals)

    NAMES=['high card','one pair','two pair','three of a kind','straight','flush','full house','four of a kind','straight flush']
    hole=x['hole']; board=x['board']
    if len(hole)!=4: return 'invalid'
    if not 3<=len(board)<=5: return 'invalid'
    allc=hole+board
    if len(set(allc))!=len(allc): return 'invalid'
    cands=[hc+bc for hc in itertools.combinations(hole,2) for bc in itertools.combinations(board,3)]
    return NAMES[max(key5(c) for c in cands)[0]]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('board flush one suited hole card',
   {'board': ['2h', '5h', '7h', '9h', 'Th'], 'hole': ['Ah', 'Kd', 'Qc', 'Js'], 'variant': 'plo'},
   'high card'),
  ('board straight',
   {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['2c', '2d', '3c', '3s'], 'variant': 'plo'},
   'one pair'),
  ('four aces in hand',
   {'board': ['2h', '7d', '9c', 'Js', '4h'], 'hole': ['Ah', 'Ad', 'Ac', 'As'], 'variant': 'plo'},
   'one pair'),
  ('real flush',
   {'board': ['2h', '5h', '7h', '9d', 'Tc'], 'hole': ['Ah', 'Kh', 'Qc', 'Js'], 'variant': 'plo'},
   'flush'),
  ('flop only', {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'},
   'three of a kind'),
  ('plo5 five holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks', '2d'], 'variant': 'plo5'},
   'three of a kind'),
  ('plo with five holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks', '2d'], 'variant': 'plo'},
   'invalid'),
  ('plo5 with four holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo5'}, 'invalid')],
 [('real flush',
   {'board': ['2h', '5h', '7h', '9d', 'Tc'], 'hole': ['Ah', 'Kh', 'Qc', 'Js'], 'variant': 'plo'},
   'flush'),
  ('flop only', {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'},
   'three of a kind'),
  ('turn board',
   {'board': ['Tc', 'Jd', '2c', '5h'], 'hole': ['8h', '9d', 'Kc', 'Ks'], 'variant': 'plo'},
   'one pair'),
  ('two card board', {'board': ['Ac', '7d'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'},
   'invalid'),
  ('plo5 five holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks', '2d'], 'variant': 'plo5'},
   'three of a kind'),
  ('plo with five holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks', '2d'], 'variant': 'plo'},
   'invalid'),
  ('plo5 with four holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo5'}, 'invalid'),
  ('duplicate across hole and board',
   {'board': ['Ah', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'}, 'invalid')],
 [('two card board', {'board': ['Ac', '7d'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'},
   'invalid'),
  ('plo5 five holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks', '2d'], 'variant': 'plo5'},
   'three of a kind'),
  ('plo with five holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks', '2d'], 'variant': 'plo'},
   'invalid'),
  ('plo5 with four holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo5'}, 'invalid'),
  ('duplicate across hole and board',
   {'board': ['Ah', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'}, 'invalid'),
  ('duplicate inside hole',
   {'board': ['Qh', '7d', '2c'], 'hole': ['Ah', 'Ah', 'Kc', 'Ks'], 'variant': 'plo'}, 'invalid'),
  ('duplicate on board',
   {'board': ['Qh', 'Qh', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'}, 'invalid'),
  ('six card board',
   {'board': ['Qh', 'Jh', '2c', '3c', '4c', '5c'],
    'hole': ['Ah', 'Ad', 'Kc', 'Ks'],
    'variant': 'plo'},
   'invalid')],
 [('board flush one suited hole card',
   {'board': ['2h', '5h', '7h', '9h', 'Th'], 'hole': ['Ah', 'Kd', 'Qc', 'Js'], 'variant': 'plo'},
   'high card'),
  ('board straight',
   {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['2c', '2d', '3c', '3s'], 'variant': 'plo'},
   'one pair'),
  ('plo5 five holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks', '2d'], 'variant': 'plo5'},
   'three of a kind'),
  ('plo with five holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks', '2d'], 'variant': 'plo'},
   'invalid'),
  ('plo5 with four holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo5'}, 'invalid'),
  ('duplicate on board',
   {'board': ['Qh', 'Qh', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'}, 'invalid'),
  ('six card board',
   {'board': ['Qh', 'Jh', '2c', '3c', '4c', '5c'],
    'hole': ['Ah', 'Ad', 'Kc', 'Ks'],
    'variant': 'plo'},
   'invalid'),
  ('full house two pairs in hand',
   {'board': ['Kc', '7d', '2c', '3h', '9s'], 'hole': ['Kh', 'Kd', '7c', '7s'], 'variant': 'plo'},
   'three of a kind')],
 [('board flush one suited hole card',
   {'board': ['2h', '5h', '7h', '9h', 'Th'], 'hole': ['Ah', 'Kd', 'Qc', 'Js'], 'variant': 'plo'},
   'high card'),
  ('board straight',
   {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['2c', '2d', '3c', '3s'], 'variant': 'plo'},
   'one pair'),
  ('four aces in hand',
   {'board': ['2h', '7d', '9c', 'Js', '4h'], 'hole': ['Ah', 'Ad', 'Ac', 'As'], 'variant': 'plo'},
   'one pair'),
  ('real flush',
   {'board': ['2h', '5h', '7h', '9d', 'Tc'], 'hole': ['Ah', 'Kh', 'Qc', 'Js'], 'variant': 'plo'},
   'flush'),
  ('flop only', {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'},
   'three of a kind'),
  ('plo5 five holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks', '2d'], 'variant': 'plo5'},
   'three of a kind'),
  ('plo with five holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks', '2d'], 'variant': 'plo'},
   'invalid'),
  ('plo5 with four holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo5'}, 'invalid')]]
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
import itertools
N = 1
observations = []
def solve(x):
    R='23456789TJQKA'
    def key5(h):
        vals=sorted((R.index(c[0])+2 for c in h), reverse=True)
        cnt=collections.Counter(vals)
        order=sorted(cnt, key=lambda v:(cnt[v],v), reverse=True)
        shape=sorted(cnt.values(), reverse=True)
        flush=len({c[1] for c in h})==1
        straight=len(cnt)==5 and (vals[0]-vals[4]==4 or vals==[14,5,4,3,2])
        top=5 if vals==[14,5,4,3,2] else vals[0]
        if straight and flush: return (8,[top])
        if shape==[4,1]: return (7,order)
        if shape==[3,2]: return (6,order)
        if flush: return (5,vals)
        if straight: return (4,[top])
        if shape==[3,1,1]: return (3,order)
        if shape==[2,2,1]: return (2,order)
        if shape==[2,1,1,1]: return (1,order)
        return (0,vals)

    NAMES=['high card','one pair','two pair','three of a kind','straight','flush','full house','four of a kind','straight flush']
    hole=x['hole']; board=x['board']
    if len(hole)<4: return 'invalid'
    if not 3<=len(board)<=5: return 'invalid'
    allc=hole+board
    if len(set(allc))!=len(allc): return 'invalid'
    cands=[hc+bc for hc in itertools.combinations(hole,2) for bc in itertools.combinations(board,3)]
    return NAMES[max(key5(c) for c in cands)[0]]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('board flush one suited hole card',
   {'board': ['2h', '5h', '7h', '9h', 'Th'], 'hole': ['Ah', 'Kd', 'Qc', 'Js'], 'variant': 'plo'},
   'high card'),
  ('board straight',
   {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['2c', '2d', '3c', '3s'], 'variant': 'plo'},
   'one pair'),
  ('four aces in hand',
   {'board': ['2h', '7d', '9c', 'Js', '4h'], 'hole': ['Ah', 'Ad', 'Ac', 'As'], 'variant': 'plo'},
   'one pair'),
  ('real flush',
   {'board': ['2h', '5h', '7h', '9d', 'Tc'], 'hole': ['Ah', 'Kh', 'Qc', 'Js'], 'variant': 'plo'},
   'flush'),
  ('flop only', {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'},
   'three of a kind'),
  ('plo5 five holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks', '2d'], 'variant': 'plo5'},
   'three of a kind'),
  ('plo with five holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks', '2d'], 'variant': 'plo'},
   'invalid'),
  ('plo5 with four holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo5'}, 'invalid')],
 [('real flush',
   {'board': ['2h', '5h', '7h', '9d', 'Tc'], 'hole': ['Ah', 'Kh', 'Qc', 'Js'], 'variant': 'plo'},
   'flush'),
  ('flop only', {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'},
   'three of a kind'),
  ('turn board',
   {'board': ['Tc', 'Jd', '2c', '5h'], 'hole': ['8h', '9d', 'Kc', 'Ks'], 'variant': 'plo'},
   'one pair'),
  ('two card board', {'board': ['Ac', '7d'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'},
   'invalid'),
  ('plo5 five holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks', '2d'], 'variant': 'plo5'},
   'three of a kind'),
  ('plo with five holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks', '2d'], 'variant': 'plo'},
   'invalid'),
  ('plo5 with four holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo5'}, 'invalid'),
  ('duplicate across hole and board',
   {'board': ['Ah', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'}, 'invalid')],
 [('two card board', {'board': ['Ac', '7d'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'},
   'invalid'),
  ('plo5 five holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks', '2d'], 'variant': 'plo5'},
   'three of a kind'),
  ('plo with five holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks', '2d'], 'variant': 'plo'},
   'invalid'),
  ('plo5 with four holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo5'}, 'invalid'),
  ('duplicate across hole and board',
   {'board': ['Ah', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'}, 'invalid'),
  ('duplicate inside hole',
   {'board': ['Qh', '7d', '2c'], 'hole': ['Ah', 'Ah', 'Kc', 'Ks'], 'variant': 'plo'}, 'invalid'),
  ('duplicate on board',
   {'board': ['Qh', 'Qh', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'}, 'invalid'),
  ('six card board',
   {'board': ['Qh', 'Jh', '2c', '3c', '4c', '5c'],
    'hole': ['Ah', 'Ad', 'Kc', 'Ks'],
    'variant': 'plo'},
   'invalid')],
 [('board flush one suited hole card',
   {'board': ['2h', '5h', '7h', '9h', 'Th'], 'hole': ['Ah', 'Kd', 'Qc', 'Js'], 'variant': 'plo'},
   'high card'),
  ('board straight',
   {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['2c', '2d', '3c', '3s'], 'variant': 'plo'},
   'one pair'),
  ('plo5 five holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks', '2d'], 'variant': 'plo5'},
   'three of a kind'),
  ('plo with five holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks', '2d'], 'variant': 'plo'},
   'invalid'),
  ('plo5 with four holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo5'}, 'invalid'),
  ('duplicate on board',
   {'board': ['Qh', 'Qh', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'}, 'invalid'),
  ('six card board',
   {'board': ['Qh', 'Jh', '2c', '3c', '4c', '5c'],
    'hole': ['Ah', 'Ad', 'Kc', 'Ks'],
    'variant': 'plo'},
   'invalid'),
  ('full house two pairs in hand',
   {'board': ['Kc', '7d', '2c', '3h', '9s'], 'hole': ['Kh', 'Kd', '7c', '7s'], 'variant': 'plo'},
   'three of a kind')],
 [('board flush one suited hole card',
   {'board': ['2h', '5h', '7h', '9h', 'Th'], 'hole': ['Ah', 'Kd', 'Qc', 'Js'], 'variant': 'plo'},
   'high card'),
  ('board straight',
   {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['2c', '2d', '3c', '3s'], 'variant': 'plo'},
   'one pair'),
  ('four aces in hand',
   {'board': ['2h', '7d', '9c', 'Js', '4h'], 'hole': ['Ah', 'Ad', 'Ac', 'As'], 'variant': 'plo'},
   'one pair'),
  ('real flush',
   {'board': ['2h', '5h', '7h', '9d', 'Tc'], 'hole': ['Ah', 'Kh', 'Qc', 'Js'], 'variant': 'plo'},
   'flush'),
  ('flop only', {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'},
   'three of a kind'),
  ('plo5 five holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks', '2d'], 'variant': 'plo5'},
   'three of a kind'),
  ('plo with five holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks', '2d'], 'variant': 'plo'},
   'invalid'),
  ('plo5 with four holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo5'}, 'invalid')]]
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:
Every plo5 hand is reported invalid, and a plo hand with five hole cards is not.

Input: {"variant": "plo" (4 hole cards) or "plo5" (5 hole cards), "hole": [...], "board": 3 to 5 cards}. The hand must use exactly two hole cards and exactly three board cards. Return the best category name, or "invalid" for a wrong hole count, a board outside 3-5 cards, or a duplicated card.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import collections
import itertools
N = 1
observations = []
def solve(x):
    R='23456789TJQKA'
    def key5(h):
        vals=sorted((R.index(c[0])+2 for c in h), reverse=True)
        cnt=collections.Counter(vals)
        order=sorted(cnt, key=lambda v:(cnt[v],v), reverse=True)
        shape=sorted(cnt.values(), reverse=True)
        flush=len({c[1] for c in h})==1
        straight=len(cnt)==5 and (vals[0]-vals[4]==4 or vals==[14,5,4,3,2])
        top=5 if vals==[14,5,4,3,2] else vals[0]
        if straight and flush: return (8,[top])
        if shape==[4,1]: return (7,order)
        if shape==[3,2]: return (6,order)
        if flush: return (5,vals)
        if straight: return (4,[top])
        if shape==[3,1,1]: return (3,order)
        if shape==[2,2,1]: return (2,order)
        if shape==[2,1,1,1]: return (1,order)
        return (0,vals)

    NAMES=['high card','one pair','two pair','three of a kind','straight','flush','full house','four of a kind','straight flush']
    hole=x['hole']; board=x['board']
    if len(hole)!={'plo':4,'plo5':5}[x['variant']]: return 'invalid'
    if len(board)<5: return 'invalid'
    allc=hole+board
    if len(set(allc))!=len(allc): return 'invalid'
    cands=[hc+bc for hc in itertools.combinations(hole,2) for bc in itertools.combinations(board,3)]
    return NAMES[max(key5(c) for c in cands)[0]]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('board flush one suited hole card',
   {'board': ['2h', '5h', '7h', '9h', 'Th'], 'hole': ['Ah', 'Kd', 'Qc', 'Js'], 'variant': 'plo'},
   'high card'),
  ('board straight',
   {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['2c', '2d', '3c', '3s'], 'variant': 'plo'},
   'one pair'),
  ('four aces in hand',
   {'board': ['2h', '7d', '9c', 'Js', '4h'], 'hole': ['Ah', 'Ad', 'Ac', 'As'], 'variant': 'plo'},
   'one pair'),
  ('real flush',
   {'board': ['2h', '5h', '7h', '9d', 'Tc'], 'hole': ['Ah', 'Kh', 'Qc', 'Js'], 'variant': 'plo'},
   'flush'),
  ('flop only', {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'},
   'three of a kind'),
  ('turn board',
   {'board': ['Tc', 'Jd', '2c', '5h'], 'hole': ['8h', '9d', 'Kc', 'Ks'], 'variant': 'plo'},
   'one pair'),
  ('two card board', {'board': ['Ac', '7d'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'},
   'invalid'),
  ('plo with five holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks', '2d'], 'variant': 'plo'},
   'invalid')],
 [('real flush',
   {'board': ['2h', '5h', '7h', '9d', 'Tc'], 'hole': ['Ah', 'Kh', 'Qc', 'Js'], 'variant': 'plo'},
   'flush'),
  ('turn board',
   {'board': ['Tc', 'Jd', '2c', '5h'], 'hole': ['8h', '9d', 'Kc', 'Ks'], 'variant': 'plo'},
   'one pair'),
  ('two card board', {'board': ['Ac', '7d'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'},
   'invalid'),
  ('plo5 five holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks', '2d'], 'variant': 'plo5'},
   'three of a kind'),
  ('plo with five holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks', '2d'], 'variant': 'plo'},
   'invalid'),
  ('plo5 with four holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo5'}, 'invalid'),
  ('duplicate across hole and board',
   {'board': ['Ah', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'}, 'invalid'),
  ('duplicate inside hole',
   {'board': ['Qh', '7d', '2c'], 'hole': ['Ah', 'Ah', 'Kc', 'Ks'], 'variant': 'plo'}, 'invalid')],
 [('flop only', {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'},
   'three of a kind'),
  ('two card board', {'board': ['Ac', '7d'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'},
   'invalid'),
  ('plo5 five holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks', '2d'], 'variant': 'plo5'},
   'three of a kind'),
  ('duplicate across hole and board',
   {'board': ['Ah', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'}, 'invalid'),
  ('duplicate inside hole',
   {'board': ['Qh', '7d', '2c'], 'hole': ['Ah', 'Ah', 'Kc', 'Ks'], 'variant': 'plo'}, 'invalid'),
  ('duplicate on board',
   {'board': ['Qh', 'Qh', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'}, 'invalid'),
  ('six card board',
   {'board': ['Qh', 'Jh', '2c', '3c', '4c', '5c'],
    'hole': ['Ah', 'Ad', 'Kc', 'Ks'],
    'variant': 'plo'},
   'invalid'),
  ('full house two pairs in hand',
   {'board': ['Kc', '7d', '2c', '3h', '9s'], 'hole': ['Kh', 'Kd', '7c', '7s'], 'variant': 'plo'},
   'three of a kind')],
 [('board flush one suited hole card',
   {'board': ['2h', '5h', '7h', '9h', 'Th'], 'hole': ['Ah', 'Kd', 'Qc', 'Js'], 'variant': 'plo'},
   'high card'),
  ('board straight',
   {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['2c', '2d', '3c', '3s'], 'variant': 'plo'},
   'one pair'),
  ('flop only', {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'},
   'three of a kind'),
  ('turn board',
   {'board': ['Tc', 'Jd', '2c', '5h'], 'hole': ['8h', '9d', 'Kc', 'Ks'], 'variant': 'plo'},
   'one pair'),
  ('two card board', {'board': ['Ac', '7d'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'},
   'invalid'),
  ('plo5 five holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks', '2d'], 'variant': 'plo5'},
   'three of a kind'),
  ('six card board',
   {'board': ['Qh', 'Jh', '2c', '3c', '4c', '5c'],
    'hole': ['Ah', 'Ad', 'Kc', 'Ks'],
    'variant': 'plo'},
   'invalid'),
  ('full house two pairs in hand',
   {'board': ['Kc', '7d', '2c', '3h', '9s'], 'hole': ['Kh', 'Kd', '7c', '7s'], 'variant': 'plo'},
   'three of a kind')],
 [('board flush one suited hole card',
   {'board': ['2h', '5h', '7h', '9h', 'Th'], 'hole': ['Ah', 'Kd', 'Qc', 'Js'], 'variant': 'plo'},
   'high card'),
  ('board straight',
   {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['2c', '2d', '3c', '3s'], 'variant': 'plo'},
   'one pair'),
  ('four aces in hand',
   {'board': ['2h', '7d', '9c', 'Js', '4h'], 'hole': ['Ah', 'Ad', 'Ac', 'As'], 'variant': 'plo'},
   'one pair'),
  ('flop only', {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'},
   'three of a kind'),
  ('turn board',
   {'board': ['Tc', 'Jd', '2c', '5h'], 'hole': ['8h', '9d', 'Kc', 'Ks'], 'variant': 'plo'},
   'one pair'),
  ('two card board', {'board': ['Ac', '7d'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'},
   'invalid'),
  ('plo5 five holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks', '2d'], 'variant': 'plo5'},
   'three of a kind'),
  ('six card board',
   {'board': ['Qh', 'Jh', '2c', '3c', '4c', '5c'],
    'hole': ['Ah', 'Ad', 'Kc', 'Ks'],
    'variant': 'plo'},
   'invalid')]]
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
import itertools
N = 1
observations = []
def solve(x):
    R='23456789TJQKA'
    def key5(h):
        vals=sorted((R.index(c[0])+2 for c in h), reverse=True)
        cnt=collections.Counter(vals)
        order=sorted(cnt, key=lambda v:(cnt[v],v), reverse=True)
        shape=sorted(cnt.values(), reverse=True)
        flush=len({c[1] for c in h})==1
        straight=len(cnt)==5 and (vals[0]-vals[4]==4 or vals==[14,5,4,3,2])
        top=5 if vals==[14,5,4,3,2] else vals[0]
        if straight and flush: return (8,[top])
        if shape==[4,1]: return (7,order)
        if shape==[3,2]: return (6,order)
        if flush: return (5,vals)
        if straight: return (4,[top])
        if shape==[3,1,1]: return (3,order)
        if shape==[2,2,1]: return (2,order)
        if shape==[2,1,1,1]: return (1,order)
        return (0,vals)

    NAMES=['high card','one pair','two pair','three of a kind','straight','flush','full house','four of a kind','straight flush']
    hole=x['hole']; board=x['board']
    if len(hole)!={'plo':4,'plo5':5}[x['variant']]: return 'invalid'
    if len(board)<2 or len(board)>5: return 'invalid'
    allc=hole+board
    if len(set(allc))!=len(allc): return 'invalid'
    cands=[hc+bc for hc in itertools.combinations(hole,2) for bc in itertools.combinations(board,3)]
    return NAMES[max(key5(c) for c in cands)[0]]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('board flush one suited hole card',
   {'board': ['2h', '5h', '7h', '9h', 'Th'], 'hole': ['Ah', 'Kd', 'Qc', 'Js'], 'variant': 'plo'},
   'high card'),
  ('board straight',
   {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['2c', '2d', '3c', '3s'], 'variant': 'plo'},
   'one pair'),
  ('four aces in hand',
   {'board': ['2h', '7d', '9c', 'Js', '4h'], 'hole': ['Ah', 'Ad', 'Ac', 'As'], 'variant': 'plo'},
   'one pair'),
  ('real flush',
   {'board': ['2h', '5h', '7h', '9d', 'Tc'], 'hole': ['Ah', 'Kh', 'Qc', 'Js'], 'variant': 'plo'},
   'flush'),
  ('flop only', {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'},
   'three of a kind'),
  ('turn board',
   {'board': ['Tc', 'Jd', '2c', '5h'], 'hole': ['8h', '9d', 'Kc', 'Ks'], 'variant': 'plo'},
   'one pair'),
  ('two card board', {'board': ['Ac', '7d'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'},
   'invalid'),
  ('plo with five holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks', '2d'], 'variant': 'plo'},
   'invalid')],
 [('real flush',
   {'board': ['2h', '5h', '7h', '9d', 'Tc'], 'hole': ['Ah', 'Kh', 'Qc', 'Js'], 'variant': 'plo'},
   'flush'),
  ('turn board',
   {'board': ['Tc', 'Jd', '2c', '5h'], 'hole': ['8h', '9d', 'Kc', 'Ks'], 'variant': 'plo'},
   'one pair'),
  ('two card board', {'board': ['Ac', '7d'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'},
   'invalid'),
  ('plo5 five holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks', '2d'], 'variant': 'plo5'},
   'three of a kind'),
  ('plo with five holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks', '2d'], 'variant': 'plo'},
   'invalid'),
  ('plo5 with four holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo5'}, 'invalid'),
  ('duplicate across hole and board',
   {'board': ['Ah', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'}, 'invalid'),
  ('duplicate inside hole',
   {'board': ['Qh', '7d', '2c'], 'hole': ['Ah', 'Ah', 'Kc', 'Ks'], 'variant': 'plo'}, 'invalid')],
 [('flop only', {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'},
   'three of a kind'),
  ('two card board', {'board': ['Ac', '7d'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'},
   'invalid'),
  ('plo5 five holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks', '2d'], 'variant': 'plo5'},
   'three of a kind'),
  ('duplicate across hole and board',
   {'board': ['Ah', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'}, 'invalid'),
  ('duplicate inside hole',
   {'board': ['Qh', '7d', '2c'], 'hole': ['Ah', 'Ah', 'Kc', 'Ks'], 'variant': 'plo'}, 'invalid'),
  ('duplicate on board',
   {'board': ['Qh', 'Qh', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'}, 'invalid'),
  ('six card board',
   {'board': ['Qh', 'Jh', '2c', '3c', '4c', '5c'],
    'hole': ['Ah', 'Ad', 'Kc', 'Ks'],
    'variant': 'plo'},
   'invalid'),
  ('full house two pairs in hand',
   {'board': ['Kc', '7d', '2c', '3h', '9s'], 'hole': ['Kh', 'Kd', '7c', '7s'], 'variant': 'plo'},
   'three of a kind')],
 [('board flush one suited hole card',
   {'board': ['2h', '5h', '7h', '9h', 'Th'], 'hole': ['Ah', 'Kd', 'Qc', 'Js'], 'variant': 'plo'},
   'high card'),
  ('board straight',
   {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['2c', '2d', '3c', '3s'], 'variant': 'plo'},
   'one pair'),
  ('flop only', {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'},
   'three of a kind'),
  ('turn board',
   {'board': ['Tc', 'Jd', '2c', '5h'], 'hole': ['8h', '9d', 'Kc', 'Ks'], 'variant': 'plo'},
   'one pair'),
  ('two card board', {'board': ['Ac', '7d'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'},
   'invalid'),
  ('plo5 five holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks', '2d'], 'variant': 'plo5'},
   'three of a kind'),
  ('six card board',
   {'board': ['Qh', 'Jh', '2c', '3c', '4c', '5c'],
    'hole': ['Ah', 'Ad', 'Kc', 'Ks'],
    'variant': 'plo'},
   'invalid'),
  ('full house two pairs in hand',
   {'board': ['Kc', '7d', '2c', '3h', '9s'], 'hole': ['Kh', 'Kd', '7c', '7s'], 'variant': 'plo'},
   'three of a kind')],
 [('board flush one suited hole card',
   {'board': ['2h', '5h', '7h', '9h', 'Th'], 'hole': ['Ah', 'Kd', 'Qc', 'Js'], 'variant': 'plo'},
   'high card'),
  ('board straight',
   {'board': ['9h', 'Td', 'Jc', 'Qs', 'Kh'], 'hole': ['2c', '2d', '3c', '3s'], 'variant': 'plo'},
   'one pair'),
  ('four aces in hand',
   {'board': ['2h', '7d', '9c', 'Js', '4h'], 'hole': ['Ah', 'Ad', 'Ac', 'As'], 'variant': 'plo'},
   'one pair'),
  ('flop only', {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'},
   'three of a kind'),
  ('turn board',
   {'board': ['Tc', 'Jd', '2c', '5h'], 'hole': ['8h', '9d', 'Kc', 'Ks'], 'variant': 'plo'},
   'one pair'),
  ('two card board', {'board': ['Ac', '7d'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks'], 'variant': 'plo'},
   'invalid'),
  ('plo5 five holes',
   {'board': ['Ac', '7d', '2c'], 'hole': ['Ah', 'Ad', 'Kc', 'Ks', '2d'], 'variant': 'plo5'},
   'three of a kind'),
  ('six card board',
   {'board': ['Qh', 'Jh', '2c', '3c', '4c', '5c'],
    'hole': ['Ah', 'Ad', 'Kc', 'Ks'],
    'variant': 'plo'},
   'invalid')]]
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:
Hands on a three- or four-card board are reported invalid.

Input: {"variant": "plo" (4 hole cards) or "plo5" (5 hole cards), "hole": [...], "board": 3 to 5 cards}. The hand must use exactly two hole cards and exactly three board cards. Return the best category name, or "invalid" for a wrong hole count, a board outside 3-5 cards, or a duplicated card.

split: open-access