#include <bits/stdc++.h>
using namespace std;
ifstream fin("input.txt");
ofstream fout("output.txt");
int main() {
  long long n, y;
  cin >> n;
  vector<long long> v(n);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    a--;
    v[a] = i;
  }
  long long ans = 0;
  for (long long i = 1; i < n; i++) {
    ans += abs(v[i] - v[i - 1]);
  }
  cout << ans;
  return 0;
}
