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