#include <bits/stdc++.h>
signed main() {
  signed n;
  scanf("%d", &n);
  signed f[n + 1], k;
  for (long long i = 0; i < n && scanf("%d", &k); i++) f[k] = i;
  long long ans = 0;
  for (long long i = 2; i <= n; i++) ans += abs(f[i] - f[i - 1]);
  printf("%lld\n", ans);
}
