N = int(raw_input()) A = map(int,raw_input().split()) ans = 1e10 for n in range(1,10001,2): P = [min(i,n+1-i) for i in range(1,n+1)] if sum(P) > sum(A): break for j in range(N-len(P)+1): over = lack = 0 for k in range(n): tmp = A[j+k]-P[k] over += max(0,tmp) lack += abs(min(0,tmp)) ans = min(ans, max(over,lack)+max(0,sum(A)-sum(P)-abs(over-lack))) print ans