#include <bits/stdc++.h>
int main() {
  int n, f[200002];
  scanf("%d", &n);
  int i;
  for (i = 0; i < n; ++i) {
    int in;
    scanf("%d", &in);
    f[in] = i;
  }
  long long ans = 0;
  for (i = 2; i <= n; ++i) ans += labs(f[i] - f[i - 1]);
  printf("%I64d\n", ans);
  return 0;
}
