#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int ans, p[200002], a, n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a;
    p[a] = i;
  }
  p[0] = p[1];
  for (int i = 1; i <= n; i++) ans += abs(p[i - 1] - p[i]);
  cout << ans << endl;
}
