#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;

    int arr[2 * n];

    for (int i = 0; i < 2 * n; i++)
    {
        cin >> arr[i];
    }

    int chortke[n + 1];
    for (int i = 0; i < n + 1; i++)
    {
        chortke[i] = -1;
    }

    long long sum = 0;

    for (int i = 0; i < 2 * n; i++)
    {
        if (chortke[arr[i]] == -1)
        {
            chortke[arr[i]] = i;
        }
        else
        {
            sum += i - chortke[arr[i]];
        }
    }

    cout << sum;

    return 0;
}