#!/bin/sh python3 - <<'EOF' S=[(3,6),(5,1),(0,2),(5,0),(0,3),(3,1),(4,1),(1,5)] T=[(5,2),(2,3),(0,1),(2,0),(5,4),(5,6)] def m(p,x,z): a=p[x]; b=p[z]; q=min(a,b) return tuple(q if p[i]==a or p[i]==b else p[i] for i in range(7)) def f(p,E): return set((p[u],p[v]) for u,v in E) def g(A,B): return sorted((x,y,z) for x,y in A for u,z in B if y==u and x!=z and y!=z) r=tuple(range(7)); V={r}; D=[r]; E=[] while D: p=D.pop(); A=f(p,S); B=f(p,T); C=g(A,B) if not C: E.append((p,A,B)); continue x,y,z=C[0] for q in (m(p,x,z),m(p,y,z)): if q not in V: V.add(q); D.append(q) def ok(p,A,B): return all(any([all(r==v for u,v in B if u==s), all(s==v for u,v in B if u==s)]) for r,s in A) def mc(p): return 7-len(set(p)) R=sum(1 for p,A,B in E if ok(p,A,B)); K=len(E) M=sum(mc(p) for p,A,B in E) W=sum(mc(p) for p,A,B in E if ok(p,A,B)) X=K-R; G=len(V); N=sum([3000*G,2000*(G-K),1000*K,700*R,100*X,10*M,W]) print('G',G,'B',G-K,'K',K,'R',R,'X',X,'M',M,'V',W,'N',N) for p,A,B in E: print(p,sorted(A),sorted(B),ok(p,A,B),mc(p)) EOF