#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x;
  cin >> n;
  map<int, int> mp;
  for (int i = 1; i <= n; ++i) {
    cin >> x;
    mp[x] = i;
  }
  long long ans = 0;
  for (int i = 1; i < n; ++i) {
    ans += abs(mp[i] - mp[i + 1]);
  }
  cout << ans << '\n';
}
