#include <bits/stdc++.h>
using namespace std;
using int64 = long long int;
using uint = unsigned int;
using uint64 = unsigned long long int;
using pii = pair<int, int>;
using pll = pair<int64, int64>;
const int nmax = 2 * 1e5 + 10;
int pos[nmax];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    pos[x] = i;
  }
  int64 result = 0;
  for (int i = 2; i <= n; ++i) result += abs(pos[i] - pos[i - 1]);
  cout << result << '\n';
  return 0;
}
