#include #include int N, sum; int A[101]; int main(){ scanf("%d", &N); for(int i=1;i<=N;i++){scanf("%d", A+i); sum += A[i];} int M; { int lb = 0, ub = 101; while(ub - lb > 1){ int mid = (lb+ub) / 2; if(mid*mid <= sum){lb = mid;} else{ub = mid;} } M = lb - 1; } // printf("%d\n", M); int res = 0; for(int i=1;i<=N;i++){ int expected = i<=M?i:(i<=2*M+1?2*M+2-i:0); // printf("%d: %d, %d, %d, %d\n", i, A[i], expected, stock, res); if(A[i] >= expected){ res += std::abs(A[i] - expected); } } printf("%d\n", res); }