#include <bits/stdc++.h>
using namespace std;
const int maxn = 2 * 1e5 + 5;
int data[maxn];
int main() {
  int n, temp;
  while (scanf("%d", &n) == 1) {
    for (int i = 1; i <= n; i++) {
      scanf("%d", &temp);
      data[temp] = i;
    }
    long long ans = 0;
    for (int i = 1; i < n; i++) {
      ans = ans + abs(data[i + 1] - data[i]);
    }
    printf("%lld\n", ans);
  }
  return 0;
}
