#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  unordered_map<int, int> frag(n);
  int val = 0;
  for (int i = 1; i <= n; i++) {
    cin >> val;
    frag.emplace(val, i);
  }
  long long cost = 0;
  for (int i = 2; i <= n; i++) {
    cost += abs(frag[i] - frag[i - 1]);
  }
  cout << cost << endl;
  return 0;
}
