#include <iostream>
using namespace std;
int main()
{
int n; cin >> n;
int arr1[2*n] , arr2[2*n];
for ( int i = 0 ; i < 2*n ; i ++ )
{
cin >> arr1[i];
arr2[i] = i;
}
int metr = 0;
for ( int i = 0 ; i < 2*n ; i ++ )
{
for ( int j = 0 ; j < 2*n ; j ++ )
{
if ( arr1[i] > arr1[j] && i < j )
{
swap ( arr1[i] , arr1[j] );
swap ( arr2[i] , arr2[j] );
}
}
if ( i % 2 == 1 && i > 0 )
{
metr += abs ( arr2[i] - arr2[i - 1] );
}
}
cout << metr;
return 0;
}