import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np N = int(readline()) A = np.array(read().split() + [0] * 110,np.int64) S = A.sum() max_ht = int(S ** .5) answer = 10 ** 18 for h in range(max_ht+1): p = np.hstack([np.arange(1,h+1), np.arange(1,h)[::-1]]) n = len(p) x = np.maximum(0, p - A[:n]).sum() + (S - h*h) if answer > x: answer = x print(answer)