#include <bits/stdc++.h>
using namespace std;
int main() {
  long n, f;
  long long sum = 0;
  scanf("%ld", &n);
  long arr[200005];
  for (long i = 1; i <= n; i++) {
    scanf("%ld", &f);
    arr[f] = i;
  }
  for (long i = 1; i < n; i++) {
    sum += abs(arr[i] - arr[i + 1]);
  }
  cout << sum;
  return 0;
}
