#include <bits/stdc++.h>
using namespace std;
const int maxn = 3 * 1e5;
int v[maxn];
int main() {
  ios::sync_with_stdio(false);
  int n, tmp;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> tmp;
    v[tmp - 1] = i;
  }
  long long res = 0;
  for (int i = 0; i + 1 < n; ++i) {
    res += abs(v[i + 1] - v[i]);
  }
  cout << res << '\n';
  return 0;
}
