#include <bits/stdc++.h>
int b[200005];
int main() {
  int n, i, k = 0, j = 0, q = 1;
  long long int sum = 0;
  scanf("%d", &n);
  int a[n];
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    b[a[i]] = i + 1;
  }
  for (i = 1; i < n; i++) sum = sum + abs(b[i] - b[i + 1]);
  printf("%lld\n", sum);
  return 0;
}
