#include <bits/stdc++.h>
using namespace std;
int n;
int t[200010], pos[200010];
long long int sol = 0;
inline int abss(int x) {
  if (x < 0)
    return (-x);
  else
    return x;
}
int main() {
  scanf("%d", &n);
  int cpos;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &t[i]);
    pos[t[i]] = i;
    if (t[i] == 1) cpos = i;
  }
  for (int i = 1; i < n; i++) {
    sol = sol + abss(cpos - pos[i + 1]);
    cpos = pos[i + 1];
  }
  printf("%I64d", sol);
  return 0;
}
