# Run alongside the canonical cap236.txt. Exact mask union enumeration.
from collections import Counter
from itertools import product
from pathlib import Path
from hashlib import sha256
r=Path(__file__).with_name('cap236.txt').read_bytes();assert sha256(r).hexdigest()=='1d6a5c73bd44d4cd99e40cf97644dd4a0c37f1bd39e3f6edfc47fd9756240efe'
def pos(x):return next((v for v in x if v),0)==1
for t in '01':
 X={tuple(map(int,s[1:])) for s in r.decode().splitlines() if s[0]==t};R=sorted(x for x in X if pos(x));rows=[]
 for z in product(range(3),repeat=6):
  if not pos(z) or z in X:continue
  edges=set()
  for j,x in enumerate(R):
   for s in (1,-1):
    y=tuple((a+s*b)%3 for a,b in zip(x,z))
    if y in X:edges.add(tuple(sorted((j,R.index(y if pos(y) else tuple(-a%3 for a in y))))))
  assert len(edges)==10 and len(set(v for e in edges for v in e))==20
  rows.append(edges)
 for p in ([-1] if t=='0' else range(56)):
  q=[sum(1<<v for e in edges if p not in e for v in e) for edges in rows]; budget,depth=(42,7) if t=='0' else (37,5);counts=[0]*depth
  def walk(q,u,d):
   for j,b in enumerate(q):
    w=u|b
    if w.bit_count()>budget:continue
    counts[d]+=1
    if d+1<depth:walk([c for c in q[j+1:] if (w|c).bit_count()<=budget],w,d+1)
  walk(q,0,0);assert counts==([308,47278,3763620,4061190,42084,2814,0] if t=='0' else [308,46783,429330,900,0]);print(t,p,counts,flush=True)
