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