#include #include #include using namespace std; typedef long long int64; const int kMaxN = 1e5+10; int first[kMaxN], v[kMaxN]; int popcount[1<<20]; struct Bitset { int v[1700]; Bitset operator ^ (const Bitset& other) { Bitset b; for (int i = 0; i < 1700; ++i) { b.v[i] = v[i] ^ other.v[i]; } return b; } void flip(int x) { v[x/30] ^= (1<<(x%30)); } int count() { int ans = 0; for (int i = 0; i < 1700; ++i) { ans += popcount[v[i]>>15] + popcount[v[i]&((1<<15)-1)]; } return ans; } }b[kMaxN]; void precalc() { for (int i = 1; i < (1<<20); ++i) { popcount[i] = popcount[i - (i&(-i))] + 1; } } int main() { precalc(); int n; cin >> n; for (int i = 1; i <= 2*n; ++i) { cin >> v[i]; } int64 rez = 0; for (int i = 1; i <= 2*n; ++i) { b[i] = b[i-1]; b[i].flip(v[i]); if (first[v[i]] == 0) { first[v[i]] = i; } else { auto ans = b[i] ^ b[first[v[i]] - 1]; rez += ans.count(); } } cout << rez/2 << "\n"; }