#include #define For(i, a, b) for(long long i = a; i < b; i++) #define rep(i, n) For(i, 0, n) #define rFor(i, a, b) for(long long i = a; i >= b; i--) #define ALL(v) (v).begin(), (v).end() #define rALL(v) (v).rbegin(), (v).rend() using namespace std; using lint = long long; using ld = long double; int main() { int n; cin >> n; vector a(n); rep(i, n) { cin >> a[i]; } int sum = accumulate(ALL(a), 0); int ans = 2000000000; for (int i = 1; ; i += 2) { int h = (i + 1) / 2; if (h * h > sum) { break; } vector len(i); for (int j = 0; j < h; j++) { len[j] = len[i - 1 - j] = j + 1; } int more = 0, less = 0; rep(j, max(i, n)) { if (j < n && j < i) { if (a[j] > len[j]) { more += a[j] - len[j]; } else { less += len[j] - a[j]; } } else if (j < n) { more += a[j]; } else { less += len[j]; } } ans = min(ans, max(more, less)); } cout << ans << endl; }