N = int(input()) A = list(map(int,input().split())) B = A[:] for i in range(1,N): B[i] += B[i-1] suma = sum(A) x = int(suma ** 0.5) y = 2 * x - 1 A = A + [0] * y NA = len(A) ans = 100 * 100 C = list(range(1,x+1)) + list(reversed(range(1,x))) + [0] * N for i in range(NA - y + 1): tmp = 0 for j in range(NA): tmp += max(0,A[j] - C[j - i]) ans = min(ans,tmp) print(ans)