#include <iostream>
using namespace std;
int main()
{
    int n;    cin >> n;
    int arr[2*n];
    for ( int i = 0 ; i < n*2 ; i ++ )
    {
        cin >> arr[i];
    }

   int i = 0;
   int j = 1;
   int metr = 0;
   while ( i < n )
   {
        if ( arr[i] == arr[j] )
        {
            metr += abs ( i - j );
            i ++;
            j ++;
        }

        else 
        {
            j ++;
        }

        if ( j == 2*n )
        {
            j = i + 1;
        }
   }

   cout << metr;

    return 0;
}