N = int(input()) A = [int(i) for i in input().split()] a,b = 1,3 while a+b<= sum(A): a+=b b+=2 L = b - 2 B = [0 for i in range(L)] for i in range(L): if i < L // 2: B[i] = (i + 1) elif i > L // 2: B[i] = L - i else: B[i] = L // 2 + 1 m = 10 ** 9 + 7 while len(A) < L: A.append(0) N = len(A) for i in range(N - L + 1): plus,minus = 0,0 for j in range(L): if A[i + j] >= B[j]: minus += A[i + j] - B[j] else: plus += B[j] - A[i + j] m = min(m,sum(A) - sum(B) + plus) print(m)