# Place canonical cap236.txt beside this script; run python3 intact_layers.py.
from collections import Counter
from pathlib import Path
from itertools import product
from hashlib import sha256
r=Path(__file__).with_name('cap236.txt').read_bytes(); assert sha256(r).hexdigest()=='1d6a5c73bd44d4cd99e40cf97644dd4a0c37f1bd39e3f6edfc47fd9756240efe'
P=list(product(range(3),repeat=6)); first=lambda x:next((a for a in x if a),0)
for t in '01':
 A={tuple(map(int,s[1:])) for s in r.decode().splitlines() if s[0]==t}; assert len(A)==112 and A=={tuple(-a%3 for a in x) for x in A}
 h=Counter((3*sum(sum(a*b for a,b in zip(v,x))%3==0 for x in A)-112)//2 for v in P[1:]);assert h=={4:616,-23:112}
 R=sorted(x for x in A if first(x)==1);p=[]
 for z in P:
  if first(z)!=1 or z in A:continue
  p.append(sum(1<<j for j,x in enumerate(R) if any(tuple((a+s*b)%3 for a,b in zip(x,z)) in A for s in (1,-1))))
 assert len(p)==308 and all(b.bit_count()==20 for b in p)
 for budget,depth,expected in [(36,4,[308,45738,4620,0])]+([(40,7,[308,47278,2105460,71190,16884,2814,0])] if t=='0' else []):
  counts=[0]*depth
  def walk(opts,u,d):
   for j,b in enumerate(opts):
    w=u|b
    if w.bit_count()>budget:continue
    counts[d]+=1
    if d+1<depth:walk([c for c in opts[j+1:] if (w|c).bit_count()<=budget],w,d+1)
  walk(p,0,0);print(t,budget,counts,flush=True);assert counts==expected
