#include using namespace std; #define int long long // <-----!!!!!!!!!!!!!!!!!!! #define rep(i,n) for (int i=0;i<(n);i++) #define rep2(i,a,b) for (int i=(a);i<(b);i++) #define rrep(i,n) for (int i=(n)-1;i>=0;i--) #define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--) #define all(a) (a).begin(),(a).end() typedef long long ll; typedef pair P; const int WIDTH = 1000; const int TOP = 105; int sumBlock(int t) { return t * t; } signed main() { std::ios::sync_with_stdio(false); std::cin.tie(0); int N; cin >> N; vector a(WIDTH, 0); int sum_a = 0; rep(i, N) { cin >> a[i]; sum_a += a[i]; } int ans = 99999999; rep2(t, 1, TOP) { if (sumBlock(t) > sum_a) break; int cnt = sum_a - sumBlock(t); // 捨てる分 rep(i, t) { // 足りない分を移動回数に足す cnt += max(0ll, (i + 1) - a[i]); // 鏡写しの反対側 if (i != t - 1) cnt += max(0ll, (i + 1) - a[2 * (t - 1) - i]); } ans = min(ans, cnt); } cout << ans << endl; }