#include <bits/stdc++.h>
using namespace std;
const int N = 2000005;
int n;
int a;
int pos[N];
int main() {
  while (cin >> n) {
    for (int i = 0; i < n; i++) {
      scanf("%d", &a);
      pos[a] = i + 1;
    }
    long long ans = 0;
    for (int i = 2; i <= n; i++) {
      ans += abs(pos[i] - pos[i - 1]);
    }
    cout << ans << endl;
  }
  return 0;
}
