#include <bits/stdc++.h>
using namespace std;
int SD() {
  int i;
  scanf("%d", &i);
  return i;
}
long long SLL() {
  long long i;
  scanf("%lld", &i);
  return i;
}
const int AKA = 1e6 + 6;
long long n, ans, v;
map<int, int> mp;
int main() {
  int ACCEPTED = 1;
  while (ACCEPTED--) {
    n = SLL();
    for (int i = 1; i <= n; ++i) {
      v = SLL();
      mp[v] = i;
    }
    for (int i = 1; i < n; ++i) ans += abs(mp[i] - mp[i + 1]);
    printf("%lld", ans);
  }
}
