N = int(input()) A = list(map(int, input().split())) S = sum(A) i = 1 while True: if (i+1) ** 2 > S: break i += 1 pyramid = [j for j in range(1, i+1)] + [j for j in range(i-1, 0, -1)] if len(pyramid) > len(A): A += [0] * (len(pyramid) - len(A)) else: pyramid += [0] * (len(A) - len(pyramid)) ans = sum(A_i - pyramid_i for A_i, pyramid_i in zip(A, pyramid) if A_i > pyramid_i) print(ans)