#include using namespace std; int n; int a[110]; int main(){ cin >>n; int s = 0; for(int i=0;i>a[i]; s+=a[i]; } int mi = 0x3fffffff; for(int k = 0; 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); } int r = s - (c - d + k * k); mi = min(mi, c + r); } cout << mi << endl; }