python3 -c 'r=17;s=41;q=73 X=[];Y=[];T=[];Pp=[] for i in range(72): r=(5*r+3*s+7*i+11)%97 s=(2*r+7*s+q+5*i+13)%89 q=(3*r+s+5*q+11*i+17)%83 t=20+i+i//4 X.append(4+((7*r+3*s+5*q+2*i)%23)) Y.append(3+((5*r+2*s+7*q+3*i)%17)) T.append(t) Pp.append(1 if (r+2*s+q+i)%6 in (0,1,4) else -1) M=[(-2,5,-1),(-1,-4,3),(0,4,-3),(1,2,2),(2,-5,1),(-2,1,-4),(1,-4,-2),(2,3,-3)] from collections import defaultdict P=[defaultdict(int) for h in range(8)] N=[defaultdict(int) for h in range(8)] Lp=[defaultdict(lambda:-1000) for h in range(8)] Lm=[defaultdict(lambda:-1000) for h in range(8)] A=[0]*8;O=[0]*8;J=[0]*8;C=[0]*8;D=[0]*8 Z=[[0]*8 for i in range(72)] U=[[0]*72 for h in range(8)];V=[[0]*72 for h in range(8)] H=0 for i in range(72): for h in range(8): w,xi,eta=M[h];x=X[i];y=Y[i];t=T[i];p=Pp[i] u=x+((112-t)*(w*(y-11)+xi))//128 v=y+((112-t)*(-w*(x-15)+eta))//128 U[h][i]=u;V[h][i]=v if not(0<=u<=30 and 0<=v<=22):z=0 else: a=u//3;b=v//3;key=(a,b) last=(Lp if p==1 else Lm)[h][key] if t-last<=7:z=1 if p==1 else 2 else: z=3 if p==1 else 4 p0=P[h][key];n0=N[h][key] if p==1:P[h][key]=p0+1 else:N[h][key]=n0+1 if p==1:Lp[h][key]=t else:Lm[h][key]=t AA[h]+=1;O[h]+=(p0+n0==0);J[h]+=p;C[h]+=2*p*(p0-n0)+1 if (p==1 and n0>0) or (p==-1 and p0>0):D[h]+=1 Z[i][h]=z H=(37*H+19*(i+1)+23*(h+1)+11*(u+32)+13*(v+32)+17*(z+1)+C[h]+7*AA[h]+5*O[h]+3*D[h]+J[h]+72)%9973 Vh=[88*C[h]-J[h]*J[h] for h in range(8)] Kh=[AA[h]-2*D[h] for h in range(8)] best=max(range(8),key=lambda h:(Vh[h],Kh[h],-O[h],-h)) dx=1 if M[best][1]>0 else -1;dy=1 if M[best][2]>0 else -1 Ep=[defaultdict(lambda:-1000) for h in range(11)] Em=[defaultdict(lambda:-1000) for h in range(11)] S=0 for i in range(72): if Z[i][best] in (3,4): u=U[best][i];v=V[best][i];a=u//3;b=v//3;ap=a-dx;bp=b-dy;t=T[i];p=Pp[i] e1=(Ep if p==1 else Em)[a][b];e2=(Em if p==1 else Ep)[a][b] e3=(Ep if p==1 else Em)[ap][bp];e4=(Em if p==1 else Ep)[ap][bp] qs=(4<=t-e1<=12)+(4<=t-e3<=12) qo=(1<=t-e2<=6)+(1<=t-e4<=6) S+=qs>=1 and qo==0 if p==1:Ep[a][b]=t else:Em[a][b]=t print(best,S,H,Vh,Kh,AA,O,J,C,D)'