#include <bits/stdc++.h>
using namespace std;
int ma[222222], x, n;
long long res;
int main() {
  res = 0;
  memset(ma, 0, sizeof(ma));
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &x);
    ma[x] = i;
  }
  for (int i = 1, j = 2; j <= n; i++, j++) {
    res += (long long)abs(ma[j] - ma[i]);
  }
  cout << res << endl;
  return 0;
}
