#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> soldiers(2 * N);
vector<pair<int, int>> pos(N + 1, {-1, -1});
for (int i = 0; i < 2 * N; i++) {
cin >> soldiers[i];
if (pos[soldiers[i]].first == -1) {
pos[soldiers[i]].first = i;
} else {
pos[soldiers[i]].second = i;
}
}
long long defenseValue = 0;
for (int num = 1; num <= N; num++) {
int left = pos[num].first;
int right = pos[num].second;
vector<int> between;
for (int i = left + 1; i < right; i++) {
between.push_back(soldiers[i]);
}
sort(between.begin(), between.end());
// 計算有多少不同的數字在between中出現至少兩次
int cnt = 0;
for (int i = 0; i < between.size(); ) {
if (between[i] > num) {
int j = i;
while (j < between.size() && between[j] == between[i]) j++;
if (j - i >= 2) cnt++;
i = j;
} else {
i++;
}
}
defenseValue += cnt;
}
cout << defenseValue << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8YWxnb3JpdGhtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CiAgICBpbnQgTjsKICAgIGNpbiA+PiBOOwogICAgdmVjdG9yPGludD4gc29sZGllcnMoMiAqIE4pOwogICAgdmVjdG9yPHBhaXI8aW50LCBpbnQ+PiBwb3MoTiArIDEsIHstMSwgLTF9KTsKICAgIAogICAgZm9yIChpbnQgaSA9IDA7IGkgPCAyICogTjsgaSsrKSB7CiAgICAgICAgY2luID4+IHNvbGRpZXJzW2ldOwogICAgICAgIGlmIChwb3Nbc29sZGllcnNbaV1dLmZpcnN0ID09IC0xKSB7CiAgICAgICAgICAgIHBvc1tzb2xkaWVyc1tpXV0uZmlyc3QgPSBpOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHBvc1tzb2xkaWVyc1tpXV0uc2Vjb25kID0gaTsKICAgICAgICB9CiAgICB9CiAgICAKICAgIGxvbmcgbG9uZyBkZWZlbnNlVmFsdWUgPSAwOwogICAgCiAgICBmb3IgKGludCBudW0gPSAxOyBudW0gPD0gTjsgbnVtKyspIHsKICAgICAgICBpbnQgbGVmdCA9IHBvc1tudW1dLmZpcnN0OwogICAgICAgIGludCByaWdodCA9IHBvc1tudW1dLnNlY29uZDsKICAgICAgICAKICAgICAgICB2ZWN0b3I8aW50PiBiZXR3ZWVuOwogICAgICAgIGZvciAoaW50IGkgPSBsZWZ0ICsgMTsgaSA8IHJpZ2h0OyBpKyspIHsKICAgICAgICAgICAgYmV0d2Vlbi5wdXNoX2JhY2soc29sZGllcnNbaV0pOwogICAgICAgIH0KICAgICAgICAKICAgICAgICBzb3J0KGJldHdlZW4uYmVnaW4oKSwgYmV0d2Vlbi5lbmQoKSk7CiAgICAgICAgCiAgICAgICAgLy8g6KiI566X5pyJ5aSa5bCR5LiN5ZCM55qE5pW45a2X5ZyoYmV0d2VlbuS4reWHuuePvuiHs+WwkeWFqeasoQogICAgICAgIGludCBjbnQgPSAwOwogICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgYmV0d2Vlbi5zaXplKCk7ICkgewogICAgICAgICAgICBpZiAoYmV0d2VlbltpXSA+IG51bSkgewogICAgICAgICAgICAgICAgaW50IGogPSBpOwogICAgICAgICAgICAgICAgd2hpbGUgKGogPCBiZXR3ZWVuLnNpemUoKSAmJiBiZXR3ZWVuW2pdID09IGJldHdlZW5baV0pIGorKzsKICAgICAgICAgICAgICAgIGlmIChqIC0gaSA+PSAyKSBjbnQrKzsKICAgICAgICAgICAgICAgIGkgPSBqOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgaSsrOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGRlZmVuc2VWYWx1ZSArPSBjbnQ7CiAgICB9CiAgICAKICAgIGNvdXQgPDwgZGVmZW5zZVZhbHVlIDw8IGVuZGw7CiAgICByZXR1cm4gMDsKfQ==