#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[200000];
  int n, m;
  long long int sum = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &m);
    a[m] = i;
  }
  for (int i = 2; i <= n; i++) {
    sum += max(a[i] - a[i - 1], a[i - 1] - a[i]);
  }
  printf("%lld\n", sum);
  return 0;
}
