#include <bits/stdc++.h>
using namespace std;
int f[200001];
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int p;
  for (int i = 1; i <= n; i++) {
    cin >> p;
    f[p] = i;
  }
  long long ans = 0;
  for (int i = 1; i <= n - 1; i++) {
    ans += abs(f[i] - f[i + 1]);
  }
  cout << ans << endl;
}
