codeforces 612 B. HDD is Outdated Technology

http://codeforces.com/contest/612/problem/B 水。

/* ***********************************************
Author :111qqz
Created Time :2015年12月25日 星期五 22时58分38秒
File Name :code/cf/edu4/B.cpp
************************************************ */

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#define fst first
#define sec second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define ms(a,x) memset(a,x,sizeof(a))
typedef long long LL;
#define pi pair < int ,int >
#define MP make_pair

using namespace std;
const double eps = 1E-8;
const int dx4[4]={1,0,0,-1};
const int dy4[4]={0,-1,1,0};
const int inf = 0x3f3f3f3f;
const int N=2E5+7;
int n;
struct node
{
    int val;
    int id;

    bool operator <(node b)const
    {
	return val<b.val;
    }
}q[N];
int main()
{
	#ifndef  ONLINE_JUDGE 
	freopen("code/in.txt","r",stdin);
  #endif
	cin>>n;
	for ( int i = 1 ;  i <= n ; i++ )
	{
	    scanf("%d",&q[i].val);
	    q[i].id = i;
	}
	sort(q+1,q+n+1);
	LL ans = 0 ;
	q[0].id = 0 ;
	for ( int i = 1 ; i <= n-1 ; i++)
	{
	    ans += LL (abs(q[i+1].id-q[i].id));
	}
	cout<<ans<<endl;

  #ifndef ONLINE_JUDGE  
  fclose(stdin);
  #endif
    return 0;
}