#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[100001];

    for (int i = 0; i <= n; 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 << endl;

    return 0;
}