#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, x, freq[200005];
  cin >> N;
  for (int i = 1; i <= N; ++i) {
    cin >> x;
    freq[x] = i;
  }
  long long answer = 0;
  for (int i = 1; i < N; ++i) {
    answer += 1LL * (freq[i] > freq[i + 1] ? freq[i] - freq[i + 1]
                                           : freq[i + 1] - freq[i]);
  }
  cout << answer << '\n';
  return 0;
}
