################### ###蟻本を読もう!### ################### n = input() a = map(int, raw_input().split()) k = 1 while((k+1)**2 <= sum(a)):k+=1 a += [0] * (k*3) extra = sum(a) - k*k res = 0 for x in xrange(len(a)): if x < k: res += abs(a[x] - (x+1)) elif x < k * 2-1: res += abs(a[x] - (k*2-x)) else: res += a[x] print (res + extra) / 2