N = int(input()) A = list(map(int, input().split())) + [0] * N a = sum(A) ans = a - 1 for i in range(1, N): if (i + 1) ** 2 > a: break ans = min(ans, sum([A[j] - j - 1 if A[j] > j else 0 for j in range(i)]) + sum([A[j] - 2 * i - 1 + j if A[j] > 2 * i - j else 0 for j in range(i, 2 * i + 1)]) + sum([A[j] for j in range(2 * i + 1, 2 * N)])) print(ans)