#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int arr1[2*n] , arr2[n + 1];
arr2[0] = 0;
int c = 1;
int b = 1;
int sum = 0;
for ( int i = 0 ; i < 2*n ; i ++ )
{
cin >> arr1[i];
if ( arr1[i] == c )
{
arr2[c] = i;
c ++;
}
else if ( arr1[i] == b )
{
sum += abs ( arr2[b] - i );
b ++;
}
}
cout << sum;
return 0;
}