#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  map<long long int, long long int> M;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    M[x] = i;
  }
  long long int ans = 0;
  for (int i = 2; i <= n; ++i) {
    ans += abs(M[i - 1] - M[i]);
  }
  cout << ans << endl;
}
