#include <bits/stdc++.h>
using namespace std;
using double_type = double;
using long_type = long long;
using namespace std;
const int N = 1e6;
int n, a[N], b[N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    --a[i];
    b[a[i]] = i;
  }
  long_type answer = 0;
  for (int i = 0; i + 1 < n; ++i) {
    answer += abs(b[i] - b[i + 1]);
  }
  cout << answer << "\n";
  return 0;
}
