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