#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long freq[n], arr[n];
  for (long long i = 1; i <= n; i++) {
    cin >> arr[i];
    freq[arr[i]] = i;
  }
  long long ans = 0;
  for (long long i = 1; i < n; i++) {
    ans += abs(freq[i] - freq[i + 1]);
  }
  cout << ans << endl;
}
