#include <bits/stdc++.h>
using namespace std;
int dif, i, a[200004], b[200005], n, p, pp;
long long sum = 0LL;
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) scanf("%d", &a[i]), b[a[i]] = i;
  p = b[1];
  for (i = 2; i <= n; ++i) {
    pp = b[i];
    dif = p - pp;
    if (dif < 0) dif = -dif;
    sum += 1LL * dif;
    p = pp;
  }
  printf("%I64d\n", sum);
  return 0;
}
