#include <bits/stdc++.h>
using namespace std;
int bowl[2000005];
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    int temp;
    for (int i = 1; i <= n; ++i) {
      scanf("%d", &temp);
      bowl[temp] = i;
    }
    long long result = 0;
    for (int i = 2; i <= n; ++i) result += abs(bowl[i] - bowl[i - 1]);
    printf("%I64d\n", result);
  }
  return 0;
}
