#include <bits/stdc++.h>
using namespace std;
long long a[200005];
int main() {
  int n;
  cin >> n;
  int aq;
  for (int i = 1; i <= n; i++) {
    cin >> aq;
    a[aq] = i;
  }
  long long ans = 0;
  for (int i = 2; i <= n; i++) {
    ans = ans + abs(a[i] - a[i - 1]);
  }
  cout << ans;
  return 0;
}
