#include <bits/stdc++.h>
using namespace std;
long long factorial(long long n) {
  return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
bool sortByVal(const pair<long long, long long> &a,
               const pair<long long, long long> &b) {
  return (a.second > b.second);
}
long long Powb(long long b, long long n) {
  if (n == 0) return 1LL;
  if (n == 1) return b;
  long long temp = Powb(b, n / 2);
  if (n % 2 == 0) {
    return (temp * temp) % 1000000007;
  } else {
    return (b * ((temp * temp) % 1000000007)) % 1000000007;
  }
}
long long sumofdigit(long long n) {
  long long c = 0, d = 0, sum = 0, i;
  while (n > 0) {
    c = n % 10;
    sum += c;
    n /= 10;
  }
  return sum;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int t = 1;
  while (t--) {
    long long k, i = 0, j = 0, c = 0, d = 0, e = 0, f = 0, sum = 0, g = 0,
                 h = 0, n, maxi = 0;
    cin >> n;
    map<long long, long long> m;
    vector<long long> a(n);
    vector<pair<long long, long long> > v1;
    vector<pair<long long, long long> > v2;
    for (i = 0; i < n; i++) {
      cin >> a[i];
      m[a[i]] = i;
    }
    for (i = 2; i <= n; i++) {
      c = abs(m[i] - m[i - 1]);
      sum += c;
    }
    cout << sum << "\n";
  }
}
