#include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; int main() { int N; cin >> N; vector A(N); for (int i = 0; i < N; ++i) { cin >> A[i]; } if (N == 1) { cout << A[0] << endl; return 0; } ll dp[2][N][N]; memset(dp, -1, sizeof(dp)); dp[0][1][N - 1] = A[0]; dp[1][0][N - 2] = A[N - 1]; for (int l = 0; l < N; ++l) { for (int r = l + 1; r < N; ++r) { if (dp[0][l][r] != -1) { ll next_l_l_time = max(A[l], dp[0][l][r] + 1); if (dp[0][l + 1][r] == -1) { dp[0][l + 1][r] = next_l_l_time; } dp[0][l + 1][r] = min(dp[0][l + 1][r], next_l_l_time); ll next_l_r_time = max(A[r], dp[0][l][r] + r - (l - 1)); if (dp[1][l][r - 1] == -1) { dp[1][l][r - 1] = next_l_r_time; } dp[1][l][r - 1] = min(dp[1][l][r - 1], next_l_r_time); } if (dp[1][l][r] != -1) { ll next_r_l_time = max(A[l], dp[1][l][r] + (r + 1) - l); if (dp[0][l + 1][r] == -1) { dp[0][l + 1][r] = next_r_l_time; } dp[0][l + 1][r] = min(dp[0][l + 1][r], next_r_l_time); ll next_r_r_time = max(A[r], dp[1][l][r] + 1); if (dp[1][l][r - 1] == -1) { dp[1][l][r - 1] = next_r_r_time; } dp[1][l][r - 1] = min(dp[1][l][r - 1], next_r_r_time); } } } ll ans = LLONG_MAX; for (int i = 0; i < N; ++i) { ll time = max(dp[0][i][i], dp[1][i][i]); if (time == -1) continue; // fprintf(stderr, "i: %d, (%lld, %lld)\n", i, dp[0][i][i], dp[1][i][i]); ans = min(ans, max(max(dp[0][i][i], dp[1][i][i]) + 1, A[i])); } cout << ans << endl; return 0; }