#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  map<long long, long long> m;
  for (long long i = 1; i <= n; i++) {
    long long x;
    cin >> x;
    m[x] = i;
  }
  long long ans = 0, prev = m.begin()->second;
  for (auto x : m) {
    ans += abs(x.second - prev);
    prev = x.second;
  }
  cout << ans << '\n';
  return 0;
}
