#include <iostream>
using namespace std;
int main()
{
int n; cin >> n;
int arr[2*n] , copy[n + 1];
long long answer = 0;
copy[0] = -1;
for ( int i = 0 ; i < 2*n ; i ++ )
{
cin >> arr[i];
}
for ( int i = 1 ; i < n + 1 ; i ++ )
{
copy[i] = -1;
}
for ( int i = 0 ; i < 2*n ; i ++ )
{
if ( copy[arr[i]] == -1 )
{
copy[arr[i]] = i;
}
else
{
answer += abs (copy[arr[i]] - i);
}
}
cout << answer;
return 0;
}