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