#include <bits/stdc++.h>
using namespace std;
int const N = 200200;
int p[N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < (n); ++i) {
    int x;
    scanf("%d", &x);
    p[x] = i;
  }
  long long ans = 0;
  for (int i = 2; i <= n; ++i) {
    ans += max(p[i] - p[i - 1], p[i - 1] - p[i]);
  }
  printf("%I64d\n", ans);
  return 0;
}
