#include #include using namespace std; #define rep(i,s,n) for(int i=(s); i<(int)(n); ++i) int n; int a[110]; int main(){ cin >> n; int s = 0; rep(i, 0, n) { cin >> a[i]; s += a[i]; } int mi = 0x3fffffff; for(int k = 1; k * k <= s && 2 * k - 1 <= n; k++){ int c = 0; int d = 0; for(int j = 0; j < k - 1; j ++) { int t = a[j] - j - 1; c += max(t, 0); d += max(0, -t); } for (int j = 0; j < k; j++) { int t = a[j + k - 1] - k + j; c += max(t, 0); d += max(0, -t); } mi = min(mi, s - k * k + d); } cout << mi << endl; }