#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int arr[2*n];
for ( int i = 0 ; i < 2*n ; i ++ )
{
cin >> arr[i];
}
int z = n;
int one = 0;
int two = 0;
int sum = 0;
for ( int i = 0 ; i < n ; i ++ )
{
for ( int v = 0 ; v < 2*n ; v ++ )
{
if ( arr[v] == z )
{
one = v;
break;
}
}
for ( int h = 0 ; h < 2*n ; h ++ )
{
if ( arr[h] == z && h != one )
{
two = h;
break;
}
}
z --;
sum = sum + abs(one - two);
}
cout << sum;
return 0;
}