#include<bits/stdc++.h>
using namespace std;
int n,a[4000001],b[4000001],c[4000001],ans=-2147483647,maxn=-2147483647,minn=2147483647;
//teacher said this question is a water question.
//but I don't think so.
//I use three fors in this question.
//so the time is O(n^3).
//n<=3*10^3,it will TLE.
//1<=n<=100,it will not TLE.
//so I get 80 point in this question.
//I can't think for the best code.
//I think the best time is O(n^2).
//but I can't do it so I do the O(n^3).
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
b[i]=a[i]+i;
c[i]=a[i]-i;
}
for(int i=n;i>=1;i--){
minn=min(minn,b[i]);
ans=max(ans,b[i]-minn-1);
}
for(int i=1;i<=n;i++){
maxn=max(maxn,c[i]);
ans=max(ans,maxn-c[i]-1);
}
printf("%d",ans);
return 0;
}