#include <bits/stdc++.h>
using namespace std;
int n, a;
long long res = 0;
vector<pair<int, int> > v;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a);
    v.push_back({a, i});
  }
  sort(v.begin(), v.end());
  for (int i = 1; i <= v.size() - 1; i++)
    res += abs(v[i].second - v[i - 1].second);
  printf("%I64d\n", res);
  return 0;
}
