import math # p=[1, 1, 1, 1, 1, 1, 1, 1, 1] numofstone = raw_input() p = map(int,raw_input().split()) for i in xrange(100): p.append(0) s = sum(p) # print s r = math.sqrt(s) delete = 0 if r==int(r): r=int(r) else: for i in xrange(1,1000): s-=1 r = math.sqrt(s) if r==int(r): delete=i r=int(r) break # print r # print "delete",delete # print r # print ans=0 husoku=0 dasoku=0 n=-1 for i in xrange(1,r+1): n+=1 sa=abs(p[n]-i) if p[n]>i: dasoku+=sa else: husoku+=sa for i in xrange(r-1,0,-1): n+=1 sa=abs(p[n]-i) if p[n]>i: dasoku+=sa else: husoku+=sa for i in xrange(2*r-1,len(p)): n+=1 sa=p[n] # print 0,sa dasoku+=sa print dasoku # print husoku # if delete>0: # print ans+delete # else: # print ans/2