#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  long long int ans = 0;
  unordered_map<int, int> frag2sec;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int tmp;
    cin >> tmp;
    frag2sec[tmp] = i;
  }
  int cur = frag2sec[1];
  for (int i = 2; i <= n; ++i) {
    ans += abs(cur - frag2sec[i]);
    cur = frag2sec[i];
  }
  cout << ans << "\n";
  return 0;
}
