#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int cities[2 * n];
for (int i = 0; i < 2 * n; i++)
{
cin >> cities[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[cities[i]] == -1)
{
chortke[cities[i]] = i;
}
else
{
sum += (i - chortke[cities[i]]);
}
}
cout << sum << endl;
return 0;
}