const int maxn=20000+5; int n,m; int det[maxn]; int sa[maxn],rnk[maxn],tp[maxn];
int c[maxn]; void Sort() { for(register int i=0;i<=m;++i)c[i]=0; for(register int i=1;i<=n;++i)c[rnk[i]]++; for(register int i=1;i<=m;++i)c[i]+=c[i-1]; for(register int i=n;i;--i)sa[c[rnk[tp[i]]]--]=tp[i]; }
int height[maxn]; void GetHeight() { for(register int i=1;i<=n;++i)rnk[i]=det[i],tp[i]=i; Sort(); for(register int w=1,p=0;p<n;m=p,w<<=1) { p=0; for(register int i=1;i<=w;++i)tp[++p]=n-w+i; for(register int i=1;i<=n;++i)if(sa[i]>w)tp[++p]=sa[i]-w; Sort(); swap(tp,rnk); rnk[sa[1]]=1,p=1; for(register int i=2;i<=n;++i) rnk[sa[i]]=(tp[sa[i]]==tp[sa[i-1]] && tp[sa[i]+w]==tp[sa[i-1]+w])?p:++p; } for(register int i=1,k=0;i<=n;++i) { if(k)--k; int j=sa[rnk[i]-1]; while(det[i+k]==det[j+k])++k; height[rnk[i]]=k; } }
bool Check(int len) { int xx; for(register int i=1;i<=n;i=xx+1) { xx=i; while(height[xx+1]>=len)++xx; int mn=0x3f3f3f3f,mx=0; for(register int j=i;j<=xx;++j) { mn=min(mn,sa[j]); mx=max(mx,sa[j]); } if(mx-mn>len)return true; } return false; }
int main() { while(scanf("%d",&n),n) { m=88*2; for(register int i=1,last=0;i<=n;++i) { int x; read(x); det[i]=x-last+88;//防止出现负数 last=x; } GetHeight(); register int l=4,r=n-1,ans=-1; while(l<=r) { int mid=(l+r)>>1; if(Check(mid)) ans=mid,l=mid+1; else r=mid-1; } printf("%d\n",ans+1); } return 0; }