#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int loc[maxn];
int ab(int a) { return a < 0 ? -a : a; }
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int s;
    cin >> s;
    loc[s] = i;
  }
  long long sum = 0;
  for (int i = 1; i < n; i++) {
    sum += ab(loc[i] - loc[i + 1]);
  }
  cout << sum << endl;
  return 0;
}
