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