#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const double eps = 1e-9;
const long long mod = 1e9 + 7;
const long long llinf = (1ll << 60);
const long long N = 500;
const long long MX = 1e7;
bool m[MX + 5];
vector<long long> prime;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout.precision(15);
  int n, a;
  cin >> n;
  map<int, int> k;
  for (long long i = (0); i <= ((n)-1); i += (+1)) {
    cin >> a;
    k[a] = i + 1;
  }
  long long sum = 0;
  for (int i = 1; i < n; i++) {
    sum += abs(k[i + 1] - k[i]);
  }
  cout << sum << '\n';
}
