#include <bits/stdc++.h>
using namespace std;
int p[200005], n;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int t;
    scanf("%d", &t);
    p[t] = i;
  }
  long long ret = 0;
  for (int i = 1; i < n; i++) {
    ret += abs(p[i + 1] - p[i]);
  }
  cout << ret;
}
