def abs(a)
  if a<0
    return a*(-1)
  else
    return a
  end
end

n=gets.to_i
a=Array.new(n)
b=Hash.new(n)
a=gets.split(/ /).map{|i| i.to_i}
for i in 0..n-1
  b[a[i]]=i
end
c=a.sort
cnt=0
for i in 0..n-1
  cnt+=abs(i-b[c[i]])
end
puts cnt-n+1