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