#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 6;
map<int, int> m;
long long int ans;
int n, x;
int main(int argc, char const *argv[]) {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &x);
    m[x] = i + 1;
  }
  for (int i = 1; i < n; ++i) {
    ans += abs(m[i] - m[i + 1]);
  }
  printf("%I64d\n", ans);
  return 0;
}
