#include <bits/stdc++.h>
using namespace std;
void run_case() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  map<long long int, long long int> m;
  for (int i = 0; i < n; i++) {
    m[a[i]] = i;
  }
  long long int sum = 0;
  int s = -1;
  for (auto it : m) {
    if (s == -1) {
      s = it.second;
    } else {
      sum += abs(it.second - s);
      s = it.second;
    }
  }
  cout << sum << "\n";
}
int main() { run_case(); }
