import pycosat, time def solve(cp, w, N): """Masked inverse problem: free neighbour trace e(t) for tw+t, start row has its leftmost lit cell at exactly -w.""" p=len(cp); nv=[0]; cl=[] def new(): nv[0]+=1; return nv[0] T_=new(); cl.append([T_]); F_=-T_ val={} for t in range(N+2): val[(0,t)]= T_ if cp[t%p] else F_ for t in range(N): val[(1,t)]=new() for t in range(N-p): # lit-phase coordinates repeat if cp[t%p]==1: a,b=val[(1,t)],val[(1,t+p)]; cl+= [[-a,b],[a,-b]] for k in range(1,N): for t in range(0,N-k): if (k,t+1) not in val or (k,t) not in val or (k-1,t) not in val: continue y=new(); x=val[(k,t+1)]; a=val[(k,t)]; b=val[(k-1,t)] o=new(); cl+= [[-a,o],[-b,o],[-o,a,b]] cl+= [[-y,x,o],[-y,-x,-o],[y,-x,o],[y,x,-o]] val[(k+1,t)]=y for (k,t),v in val.items(): if k>w+t and k>=1: cl.append([-v]) # dark outside the light cone if (w,0) not in val: return None cl.append([val[(w,0)]]) # leftmost lit lamp exactly at -w (nonzero, width w) return pycosat.solve(cl)!="UNSAT" def death_time(cp,w,Nmax): lo,hi=1,Nmax if solve(cp,w,hi): return None while lo230: break print(f"Mia {''.join(map(str,cp))}: certified horizon by which no hidden configuration exists: "+" ".join(row),flush=True) if time.time()-t0>230: break