#include <iostream>
#include <vector>
using namespace std;
int main()
{
int n;
cin >> n;
vector<int> houses(2 * n);
for (int i = 0; i < 2 * n; i++)
{
cin >> houses[i];
}
vector<int> house(n + 1, -1);
long long totalLength = 0;
for (int i = 0; i < 2 * n; i++)
{
int houseNumber = houses[i];
if (house[houseNumber] != -1)
{
totalLength += i - house[houseNumber];
}
house[houseNumber] = i;
}
cout << totalLength << endl;
return 0;
}