#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)3e5 + 10;
const int inf = (int)1e9 + 5;
const long long llinf = (long long)1e18 + 5;
long long a[maxn];
long long x, x2, y2, j, j2, i, n, m, k, z, query, step;
pair<int, int> c[maxn];
int main() {
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    c[i] = make_pair(a[i], i);
  }
  sort(c, c + n);
  x = 0;
  for (i = 0; i < n - 1; i++) {
    x += abs(c[i + 1].second - c[i].second);
  }
  cout << x;
  return 0;
}
