#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  while (cin >> n) {
    vector<long long> a(200000);
    long long x;
    for (int i = 1; i <= n; i++) {
      cin >> x;
      a[x] = i;
    }
    long long sum = 0;
    for (int i = 1; i < n; i++) {
      sum += abs(a[i] - a[i + 1]);
    }
    cout << sum << endl;
  }
  return 0;
}
