#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  vector<int> F(n), S(n);
  for (int i = 0; i < n; ++i) scanf("%d", &F[i]), S[F[i] - 1] = i;
  long long ans = 0;
  for (int i = 1; i < n; ++i) ans += abs(S[i] - S[i - 1]);
  printf("%lld\n", ans);
}
