#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define loop(i,a,b) for(int i=a;i pii; typedef vector vi; typedef vector vvi; typedef vector vp; typedef vector vvp; typedef vector vs; typedef vector vd; typedef vector vvd; typedef pair pip; typedef vectorvip; const double PI=acos(-1); const double EPS=1e-7; const int inf=1e8; const ll INF=1e16; int dx[4]={0,1,0,-1}; int dy[4]={1,0,-1,0}; int main(){ ll n; cin>>n; vi in(n); rep(i,n)cin>>in[i]; if(n==1){ cout<dp(2,vvi(n,vi(n,INF))); dp[0][1][n-1]=in[0]; dp[1][0][n-2]=in[n-1]; queue >que; que.push(mt(0,1,n-1,in[0])); que.push(mt(1,0,n-2,in[n-1])); ll out=INF; while(!que.empty()){ ll a,b,c,d; tie(a,b,c,d)=que.front(); que.pop(); if(dp[a][b][c]t){ dp[a][b+1][c]=t; que.push(mt(a,b+1,c,t)); } t=max(in[c],d+c-b+1); if(dp[1][b][c-1]>t){ dp[1][b][c-1]=t; que.push(mt(1,b,c-1,t)); } }else{ t=max(in[b],d+c-b+1); if(dp[0][b+1][c]>t){ dp[0][b+1][c]=t; que.push(mt(0,b+1,c,t)); } t=max(in[c],d+1); if(dp[a][b][c-1]>t){ dp[a][b][c-1]=t; que.push(mt(a,b,c-1,t)); } } } cout<