n=int(input())
a=[]
m=0
x=0
for i in range(n):
    b=int(input())
    a.append(b)
c=[]
d=a
for i in a:
    c.append(min(a))
    a.pop(a.index(min(a)))
    if len(a)==1:
        c.append(a[0])
for i in range(n):
    o=d.index(c[i])
    p=c.index(c[i])
    x=o-p
    if x<0:
        x*=-1
    m+=x
print(m)
    
