n=int(input())
l=list(map(int,input().split()))
temp=[0]*n
for i in range(len(l)):
	x=l[i]-1
	temp[x]=1

d1,d2,k1,k2={},{},0,n-1
for i in range(len(temp)):
	if temp[i]==1:
		d1.update({i:k1})
		k1+=2
for i in range(len(temp)-1,-1,-1):
	if temp[i]==1:
		d2.update({i:k2})
		k2-=2
a,b=0,0
for i in range(len(temp)):
	if temp[i]==1:
		a=a+abs(i-d1[i])
for i in range(len(temp)-1,-1,-1):
	if temp[i]==1:
		b=b+abs(i-d2[i])
print(min(a,b))