#include <bits/stdc++.h>
using namespace std;
long long n;
vector<pair<long long, long long>> p;
void solve() {
  cin >> n;
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    p.emplace_back(x, i);
  }
  sort(p.begin(), p.end());
  long long ans = 0;
  for (long long i = 1; i < n; i++) {
    ans += abs(p[i].second - p[i - 1].second);
  }
  cout << ans << '\n';
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long tt = 1;
  while (tt--) {
    solve();
  }
}
