b[1<<21],s,i,j;main(n){for(;~scanf("%d",&n)?b[n]=s,s=1:b[i]&&j<1e6?s=fmax(s,b[j+=i]?b[j]=fmax(b[j],b[i]+1):0):(j=++i)<1e6;);printf("%d",s);}