#include "iostream" #include "climits" #include "list" #include "queue" #include "stack" #include "set" #include "functional" #include "algorithm" #include "math.h" #include "utility" #include "map" using namespace std; const long long int MOD = 1000000007; typedef pair P; int N; long long int num[2000]; long long int dis[2000]; bool flag[2000]; bool fflag[2001]; bool gflag[2000]; long long int ff; long long int ans=LLONG_MAX; long long int box; long long int bag; long long int current; priority_queue, greater >Q; long long int node; int main() { cin >> N; for (int i = 0; i < N; i++) { cin >> num[i]; gflag[i] = true; } for (int i = 0; i < N; i++) { if (num[i] + N < ans/*&&gflag[i]*/) { for (int j = 0; j < N; j++) { dis[j] = LLONG_MAX; flag[j] = true; fflag[j] = true; } fflag[2000] = true; dis[i] = num[i]; Q.push((dis[i] * 10000 + i) * 10000 + 2000); box = 0; while (!Q.empty() && box < N) { if (flag[(Q.top() % 100000000) / 10000] && fflag[(Q.top() % 10000)]) { current = Q.top(); node = (current % 100000000) / 10000; dis[node] = current / 100000000; if (dis[node] == num[node]) { gflag[node] = false; } Q.pop(); box++; flag[node] = false; fflag[current % 10000] = false; for (int j = 0; j < N; j++) { if (flag[j]) { if (max(dis[node] + abs(j - node), num[j]) < dis[j]) { Q.push(max(dis[node] + abs(j - node), num[j]) * 100000000 + j * 10000 + node); } } } } else { Q.pop(); } } while (!Q.empty()) { Q.pop(); } bag = 0; for (int j = 0; j < N; j++) { bag = max(bag, dis[j]); } ans = min(ans, bag); } } cout << ans << endl; return 0; }