n = int(input()) houses = list(map(int, input().split())) l = 0 for i in range(1, n + 1): first = houses.index(i) second = houses.index(i, first + 1) l += abs(second - first) print(l)