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