#include <bits/stdc++.h>
using namespace std;
long long a[2000001];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    a[x - 1] = i;
  }
  long long sum = 0;
  for (int i = 1; i < n; ++i) sum += abs(a[i] - a[i - 1]);
  cout << sum << endl;
}
