#include #include using namespace std; int aib[100004]; int N; int freq[100004]; void update(int pos, int value) { for(;pos <= 2 * N; pos += pos & (-pos)) { aib[pos] += value; } } int query(int pos) { int ans = 0; for(;pos;pos -= pos & (-pos)) { ans += aib[pos]; } return ans; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); #endif // ONLINE_JUDGE cin >> N; int ans = 0; int x; for(int i = 1; i <= 2 * N; ++i) { cin >> x; if(freq[x] == 0) { freq[x] = i; update(i, 1); } else { update(freq[x], -1); ans += query(i) - query(freq[x]); freq[x] = 0; } } cout << ans << '\n'; return 0; }