#include <bits/stdc++.h>
using namespace std;
char ch[102][28];
int main() {
  int count1[200005];
  memset(count1, 0, sizeof(count1));
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    count1[temp] = i + 1;
  }
  long long int ans = 0;
  for (int i = 2; i <= n; i++) {
    ans += (abs(count1[i] - count1[i - 1]));
  }
  cout << ans;
  return 0;
}
