#include using namespace std; // #define int long long #define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i) #define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i) #define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--) #define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--) #define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i) #define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i) #define SORT(v, n) sort(v, v + n); #define REVERSE(v, n) reverse(v, v+n); #define vsort(v) sort(v.begin(), v.end()); #define all(v) v.begin(), v.end() #define mp(n, m) make_pair(n, m); #define cout(d) cout<; using vvi = vector; using vll = vector; using vvll = vector; using pii = pair; using pll = pair; using vs = vector; using vpll = vector>; using vtp = vector>; using vb = vector; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const ll INF = 1e9; const ll MOD = 1e9+7; const ll LINF = 1e18; ll dp[2][2005][2005]; // isRight,l,r [l,r)がまだ未訪問の状態で、そのセルに居ることができる最短時間 signed main() { cin.tie( 0 ); ios::sync_with_stdio( false ); ll n; cin>>n; vll a(n); rep(i,n) cin>>a[i]; rep(i,n+1) rep(j,n+1){ dp[0][i][j]=LINF; dp[1][i][j]=LINF; } dp[0][0][n]=dp[1][0][n]=0; for(ll len=n-1; len>=0; len--){ for(ll i=0; i+len<=n; i++){ ll j=i+len; if(i>0){ chmin(dp[0][i][j], max(dp[0][i-1][j],a[i-1])+1); chmin(dp[0][i][j], max(dp[1][i-1][j]+(j-i),a[i-1])+1); } if(j