n = int(input()) b = list(map(int, input().split())) i = 1 p = 1 while True: i = i + 1 p = i * i if p > sum(b): i = i - 1 p = i * i break to_top = [x for x in range(1, i+1)] to_bottom = [y for y in range(i-1, 0, -1)] pyramid = to_top + to_bottom if len(pyramid) < len(b): pyramid = pyramid + [0] * (len(b)-len(pyramid)) if len(b) < len(pyramid): b = b + [0] * (len(pyramid)-len(b)) pb = 0 mb = 0 for j, k in zip(pyramid,b): if k > j: mb += k - j elif j > k: pb += j - k if sum(b) > p: print(mb) else: print(pb)