#include <iostream>

using namespace std;

int main()
{

    int n;
    cin >> n;
    int a[2 * n];
    int chortke[2 * n];
    for ( int i = 0; i < (2 * n); i++ )
    {
        cin >> a[i];
        chortke[ a[i] ] = -1;
    }
    int index = -2;
    long long int x = 0;
    for ( int i = 0; i < 2 * n; i++ )
    {
        if ( chortke[ a[i] ] == -1 )
        {
            index = i;
            chortke[ a[i] ] = index;
        }
        else
        {
            x += (i - chortke[ a[i] ]);
        }
    }
    cout << x;

    return 0;
}