#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long a[n], b[n];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    b[a[i] - 1] = i;
  }
  long long diff = 0;
  for (long long j = 0; j < n - 1; j++) {
    diff = diff + abs(b[j] - b[j + 1]);
  }
  cout << diff;
  return 0;
}
