#include <bits/stdc++.h>
using namespace std;
void task();
int main() {
  task();
  return 0;
}
const int N = (int)2e5 + 10;
const long long int MODULO = (long long int)1e9 + 7;
const long long int INF = (long long int)1e18 + 10;
const int BUF_SIZE = (int)1e4 + 10;
int a[N];
void task() {
  ios_base::sync_with_stdio(0);
  long long int ans = 0;
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int b;
    cin >> b;
    a[b] = i;
  }
  for (int i = 2; i < n + 1; ++i) {
    ans += abs(a[i - 1] - a[i]);
  }
  cout << ans;
}
