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