#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  long long arr[n];
  for (long long i = 0; i < n; ++i) {
    long long x;
    cin >> x;
    --x;
    arr[x] = i;
  }
  long long cnt = 0;
  for (long long i = 1; i < n; ++i) {
    cnt += abs(arr[i] - arr[i - 1]);
  }
  cout << cnt << '\n';
  return 0;
}
