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