#include <bits/stdc++.h>
using namespace std;
long long s[300005];
int x, n;
int main() {
  long long sum = 0;
  scanf("%d\n", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    s[x] = i;
  }
  for (int i = 2; i <= n; i++) {
    sum += (long long)fabs(s[i] - s[i - 1]);
  }
  printf("%lld\n", sum);
  return 0;
}
