#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > v;
int main() {
  long long n, i, ans = 0, x, y;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> x;
    v.push_back(make_pair(x, i));
  }
  sort(v.begin(), v.end());
  for (i = 1; i < n; i++) {
    ans += (abs(v[i].second - v[i - 1].second));
  }
  cout << ans;
  return 0;
}
