#include <bits/stdc++.h>
using namespace std;
struct node {
  int a, pos;
} p[200005];
bool cmp(node x, node y) { return x.a < y.a; }
int main() {
  int n;
  while (cin >> n) {
    for (int i = 1; i <= n; i++) {
      cin >> p[i].a;
      p[i].pos = i;
    }
    sort(p + 1, p + n + 1, cmp);
    long long ans = 0;
    for (int i = 2; i <= n; i++) {
      int res = p[i].pos - p[i - 1].pos;
      if (res >= 0)
        ans += (long long)res;
      else
        ans -= (long long)res;
    }
    cout << ans << endl;
  }
  return 0;
}
