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