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