#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int j = 0;
int sim = 0;
int x , y , arr[2*n];
for ( int i = 0 ; i < 2*n ; i ++ )
{
cin >> arr[i];
}
for ( int c = 0 ; c < n ; c ++ )
{
j ++;
for ( int i = 0 ; i < 2*n ; i ++ )
{
if ( arr[i] == j )
{
x = i;
for ( int b = i + 1 ; b < 2*n ; b ++ )
{
if ( arr[b] == j )
{
y = b;
}
}
}
}
if ( x > y )
{
sim = sim + ( x - y );
}
else
{
sim = sim + ( y - x );
}
}
cout << sim;
return 0;
}