#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
using dou = long double;
string yes = "yes";
string Yes = "Yes";
string YES = "YES";
string no = "no";
string No = "No";
string NO = "NO";
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const long long mod = 1000000007ll;
struct mint {
  long long x;
  mint(long long x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(long long t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
long long ceili(long long a, long long b) { return ((a + b - 1) / b); }
const int INF = 2000000000;
const long long INF64 = 4223372036854775807ll;
const long long MOD = 1000000007ll;
const long long OD = 1000000000000007ll;
const dou pi = 3.141592653589793;
long long modpow(long long a, long long n) {
  long long resize = 1;
  while (n > 0) {
    if (n & 1) resize = resize * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return resize;
}
vector<long long> divisor(long long n) {
  vector<long long> ret;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
int main() {
  int n;
  std::cin >> n;
  std::vector<int> a(n);
  for (long long i = 0; i < (long long)(n); i++) std::cin >> a[i];
  ;
  for (auto& i : a) i--;
  long long ans = 0;
  std::vector<int> p(n);
  for (long long i = 0; i < (long long)(n); i++) {
    p[a[i]] = i;
  }
  for (long long i = 0; i < (long long)(n - 1); i++) {
    ans += abs(p[i + 1] - p[i]);
  }
  std::cout << ans << std::endl;
}
