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