#include <bits/stdc++.h>
int main(void) {
  long long array[200002];
  long long n, i, j, k;
  scanf("%lld", &n);
  for (i = 1; i <= n; ++i) {
    scanf("%lld", &j);
    array[j] = i;
  }
  k = 0;
  for (i = 2; i <= n; ++i) {
    k += abs(array[i - 1] - array[i]);
  }
  printf("%lld\n", k);
  return 0;
}
