#include #include #include #include #include using namespace std; int main() { int n; cin >> n; vector a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } long long ans = 1e18; for (int ii = 0; ii < n; ii++) { long long rr = 0; long long tt = 0; set> st; for (int i = 0; i < n; i++) { long long y = a[i]; long long x = i - ii; y += max(0LL, x - y); y += max(0LL, -x - y); long long yy = y + x; long long xx = y - x; assert(yy >= 0); assert(xx >= 0); rr = max(rr, xx); tt = max(tt, yy); st.emplace(xx, yy); } if (st.count(make_pair(rr, tt))) { ans = min(ans, (tt + 1) / 2 + (rr + 1) / 2); } else { ans = min(ans, (tt + rr + 1) / 2); } } cout << ans << endl; }