#include <bits/stdc++.h>
int abs(int a, int b) {
  if (a > b)
    return a - b;
  else
    return b - a;
}
int main() {
  int n;
  int f[200005], hash[200005];
  long long ans = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", f + i);
    hash[f[i]] = i;
  }
  if (n == 1)
    printf("0");
  else {
    for (int i = 2; i <= n; ++i) {
      ans += abs(hash[i], hash[i - 1]);
    }
    printf("%I64d", ans);
  }
  return 0;
}
