#include #define show(x) cout << #x << " = " << x << endl using namespace std; using ll = long long; using pii = pair; using vi = vector; template ostream& operator<<(ostream& os, const vector& v) { os << "sz=" << v.size() << "\n["; for (const auto& p : v) { os << p << ","; } os << "]\n"; return os; } template ostream& operator<<(ostream& os, const pair& p) { os << "(" << p.first << "," << p.second << ")"; return os; } constexpr ll MOD = 1e9 + 7; template constexpr T INF = numeric_limits::max() / 100; int main() { int N; cin >> N; vector A(N, 0); int sum = 0; for (ll i = 0; i < N; i++) { cin >> A[i]; sum += A[i]; } const int maxi = (int)sqrt(sum); int mini = 1000000; for (int m = 1; m <= maxi; m++) { const int maximum = 2 * maxi - 2; int plus = 0; int minus = 0; for (int i = 0; i < N; i++) { const int num = (i > maximum) ? 0 : (i < maxi) ? i + 1 : maximum - i + 1; if (A[i] > num) { plus += A[i] - num; } else if (A[i] < num) { minus += num - A[i]; } } mini = min(mini, max(plus, minus)); } cout << mini << endl; return 0; }