n=int(input()) a=list(map(int,input().split())) ch=[0]*n cj=[0]*n for i in range(0,len(a)) : if ch[a[i]-1]==0 : ch[a[i]-1]=i else : cj[a[i]-1]=i o=0 for i in range(n) : o+=abs(cj[i]-ch[i]) print(o)