#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const long long NINF = -INF;
const long long MAXN = 1e+6 + 8;
int dx8[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy8[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};
long long n, a[200005], ind[200005];
void MAIN() {
  cin >> n;
  for (long long i = (1); i <= (n); i++) cin >> a[i], ind[a[i]] = i;
  long long ans = 0;
  for (long long i = (1); i <= (n - 1); i++) {
    ans += abs(ind[i] - ind[i + 1]);
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t = 1;
  while (t--) {
    MAIN();
  }
}
