#include <iostream>
#include <string.h>
using namespace std;
int main()
{
int n;
cin >> n;
int arr[n + 1];
memset(arr, -1, (n + 1) * sizeof(int));
long long ans = 0;
for (int i = 0; i < 2 * n; i++)
{
int x;
cin >> x;
if (arr[x] == -1)
arr[x] = i;
else
ans += i - arr[x];
}
cout << ans;
return 0;
}