#include <bits/stdc++.h>
using namespace std;
long long n, times, file[200005], pos[200005];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &file[i]);
    pos[file[i]] = i;
  }
  for (int i = 2; i <= n; i++) times += abs(pos[i] - pos[i - 1]);
  cout << times;
}
