HDD hard drives group data by sectors. All files are split to fragments and each of them are written in some sector of hard drive. Note the fragments can be written in sectors in arbitrary order.

One of the problems of HDD hard drives is the following: the magnetic head should move from one sector to another to read some file.

Find the time need to read file split to n fragments. The i-th sector contains the f_{i}-th fragment of the file (1 ≤ f_{i} ≤ n). Note different sectors contains the different fragments. At the start the magnetic head is in the position that contains the first fragment. The file are reading in the following manner: at first the first fragment is read, then the magnetic head moves to the sector that contains the second fragment, then the second fragment is read and so on until the n-th fragment is read. The fragments are read in the order from the first to the n-th.

It takes |a - b| time units to move the magnetic head from the sector a to the sector b. Reading a fragment takes no time.


-----Input-----

The first line contains a positive integer n (1 ≤ n ≤ 2·10^5) — the number of fragments.

The second line contains n different integers f_{i} (1 ≤ f_{i} ≤ n) — the number of the fragment written in the i-th sector.


-----Output-----

Print the only integer — the number of time units needed to read the file.


-----Examples-----
Input
3
3 1 2

Output
3

Input
5
1 3 5 4 2

Output
10



-----Note-----

In the second example the head moves in the following way:  1->2 means movement from the sector 1 to the sector 5, i.e. it takes 4 time units  2->3 means movement from the sector 5 to the sector 2, i.e. it takes 3 time units  3->4 means movement from the sector 2 to the sector 4, i.e. it takes 2 time units  4->5 means movement from the sector 4 to the sector 3, i.e. it takes 1 time units 

So the answer to the second example is 4 + 3 + 2 + 1 = 10.

Difficulty: interview

Starter code:

Solutions:
k=0

d = [0] * 200005
x = int(input())
p = list(map(int, input().split(' ')))
for i in range(len(p)):
    d[p[i]] = i

for i in range(1, x):
    k += abs(d[i+1] - d[i])

print(k)


n = int(input())
a = [int(i) for i in input().split()]
b = [0 for i in range(n)]
for i, j in enumerate(a):
    b[j-1] = i
sum = 0
for i in range(1, n):
    sum += abs(b[i]-b[i-1])
print(sum)



import sys
#fin = open("ecr4b.in", "r")
fin = sys.stdin

n = int(fin.readline())
file = [None] * n
disk = tuple(map(int, input().split()))
for i in range(n):
    file[disk[i] - 1] = i
ctime = 0
for i in range(1, n):
    ctime += abs(file[i] - file[i - 1])
print(ctime)

n=int(input())
thing=input().split(' ')

l=[]
for i in range (n):
    l.append(int(thing[i]))

m=[-1]*n

for i in range (n):
    m[l[i]-1]=i

t=0
for i in range (n-1):
    t+=abs(m[i]-m[i+1])

print(t)


n = int(input())
lst = list(map(int, input().split()))
d = []
for i in range(n):
    d.append((lst[i], i))
d.sort()    
s = 0
for i in range(1, n):
    s += abs(d[i][1] - d[i - 1][1])
print(s)    
    


n = int(input())
f = input().split(" ")
pos = [0 for i in range(n)]
for i in range(n):
    pos[int(f[i])-1]=i
ret = 0
for i in range(n-1):
    ret += abs(pos[i+1]-pos[i])
print(ret)
    


n = int(input())
a = [0] * n
for i, x in enumerate(map(int, input().split())):
    a[x - 1] = i
print(sum(abs(a[i + 1] - a[i]) for i in range(n - 1)))

n = int(input())
index = [0 for i in range(n + 1)]
a = list(map(int, input().split()))
for i in range(n):
    index[a[i]] = i

ans = 0
lab = 1
while lab != n:
    ans += abs(index[lab] - index[lab + 1])
    lab += 1
    
print(ans)

import math

n = int(input())
f = [int(x) for x in input().split()]
l = list(sorted(enumerate(f), key = lambda x : x[1]))
s = 0
for i in range(1,n):
    s += abs(l[i][0] - l[i-1][0])
print(s)
    


n = int(input())

c = [0 for i in range(n)]

f = list([int(x) - 1 for x in input().split()])

for i in range(n):
    c[f[i]] = i

sum = 0
for i in range(n - 1):
    sum += abs(c[i] - c[i + 1])

print(sum)


input()
l = list(map(int, input().split()))
ans = 0
l2 = [0]*int(2e5+5)
for i in range(len(l)):
    l2[l[i]] = i+1
for i in range(1, len(l)):
    ans += abs(l2[i]-l2[i+1])
print(ans)


def solve():
    N = int(input())
    F = list(map(int, input().split()))
    G = []

    for i in range(N):
        G.append((F[i], i))

    G.sort()

    p = G[0][1]
    ans = 0

    for f, np in G:
        ans += abs(np - p)
        p = np

    print(ans)


def __starting_point():
    solve()

__starting_point()

n=int(input())
a=[];v=[];o=0
a=list(map(int,input().split()))
for i in range(0,n+1):
    v.append(0)
for i in range(n):
    v[a[i]]=i+1
for i in range(1,n):
    o+=abs(v[i]-v[i+1])
print(o)
    


n = int(input())
f = list(map(int, input().split()))
a = [None] * n
for i in range(n):
    a[f[i] - 1] = i
ans = sum(abs(a[i] - a[i - 1]) for i in range(1, n))
print(ans)


n=int(input())
ls=list(map(int,input().split()))
arr=[0]*n
for x in range(n):
	arr[ls[x]-1]=x
su=0
for x in range(1,n):
	su+=abs(arr[x]-arr[x-1])
print(su)

##n,p,q=map(int,input().split())
##
##s=input()
##
##l=list()
##
##while len(s):
##    if len(s)%p!=0 and len(s)>=q:
##        l.append(s[0:q])
##        s=s[q:]
##    elif len(s)%p==0 and len(s)>=p:
##        l.append(s[0:p])
##        s=s[p:]
##    else:
##        break
##if len(s):
##    print(-1)
##else:
##    print(len(l))
##    for x in l:
##        print(x)

n=input()
s=list(input().split())

i=1
l=list()
for x in s:
    l.append((int(x),i))
    i+=1
l.sort()
ans=0
for i in range(1,len(l)):
    ans+=abs(l[i][1]-l[i-1][1])
    
print(ans)


# Input starts.
n = int(input())
f = [int(s) for s in str(input()).split()]

# print('n', n)
# print('f', f)

# Input ends.

# Solution starts.
sortedF = [None] * n
for i in range(n):
    sortedF[f[i] - 1] = i

# print('sortedF', sortedF)

moves = 0
for i in range(n - 1):
    moves += abs(sortedF[i + 1] - sortedF[i])
print(moves)

# print('moves', moves)

# Solution ends.


import sys
n=int(sys.stdin.readline())
l=list(map(int,sys.stdin.readline().split()))
k=0
q=0
z=[0]*n
for i in range(n):
    z[l[i]-1]=i
ans=0
while k<n-1:
    ans+=abs(z[k]-z[k+1])
    k+=1
print(ans)

# import sys 
# import os
# import time
# from DataStructs import FenwickTree, SegTree, DWGraph
from _ast import arg, GtE
withFile = 0

if(withFile == 1):
    fin     = open('input.txt', 'r')
    fout    = open('output.txt', 'w')

def getl():
    nonlocal withFile
    if(withFile == 0):
        return input()
    else:
        return fin.readline()
    
def printl(s):
    nonlocal withFile
    if(withFile == 0):
        print(s)
    else:
        fout.write(str(s))

def get_arr():
    nonlocal withFile
    x = getl().split(' ')
    if(x[-1] == ''):
        x.pop()
    return list(map(int, x))

def __starting_point():
#     die(12)
    n = get_arr()[0]
    a   = sorted([[x, i] for i, x in enumerate(get_arr())])
    res = 0
    for i in range(1, len(a)):
        res += abs(a[i][1] - a[i-1][1])
    print(res)
    
if(withFile == 1):
    fin.close()
    fout.close()
__starting_point()

a,b,t=int(input()),list(map(int,input().split())),0
c=[0]*a
for i in range(a):c[b[i]-1]=i
for i in range(a-1):t+=abs(c[i]-c[i+1])
print(t)

import sys
if False:
	inp = open('A.txt', 'r')
else:
	inp = sys.stdin

n = int(inp.readline())
sectors = list(zip(list(map(int, inp.readline().split())), [x+1 for x in range(n)]))

sectors.sort(key = lambda x: x[0])
ans = 0
for i in range(n-1):
	ans += max(sectors[i][1]-sectors[i+1][1], sectors[i+1][1] - sectors[i][1])
print(ans)






from bisect import bisect
from itertools import permutations,combinations
n=int(input())
a=list(map(int,input().split()))

cnt=1
b = []
for x in a:
    b.append([x,cnt])
    cnt+=1
b.sort()
res = 0
for i in range(1,n):
    res+=abs(b[i][1]-b[i-1][1])
print(res)

n=int(input())
f=list(map(int,input().split()))
t=[]
for i in range(n):
    t.append((f[i],i))
t=sorted(t,key=lambda x:x[0])
ans=0
for i in range(1,n):
    ans+=abs(t[i][1]-t[i-1][1])
print(ans)

n = int(input())
location = {int(val): i for i, val in enumerate(input().split())}
result = sum((abs(location[i] - location[i-1]) for i in range(2, n+1)))
print(result)