#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int total = 0; for (int i = 0; i < n; i++) total += a[i]; int ans = 1000000000; int cnt = 0; for (int i = 1; i <= n; i++) { if (i%2 == 0) continue; cnt++; if (total < cnt*cnt) continue; for (int bias = 0; bias <= n-i; bias++) { int k = 0, s = 0; for (int j = 0; j < i/2; j++) { if (a[j+bias] > j+1) { k += a[j+bias]-(j+1); }else { s += j+1-a[j+bias]; } } for (int j = i/2, l = i/2; j < i; j++,l--) { if (a[j+bias] > l+1) { k += a[j+bias]-(l+1); }else { s += l+1-a[j+bias]; } } for (int j = 0; j < bias; j++) k += a[j]; for (int j = i+bias; j < n; j++) k += a[j]; ans = min(k, ans); // cout << sum << " " << i << endl; } } cout << ans << endl; }