#include using namespace std; using uint = unsigned int; using ll = long long; using pii = pair; #define dbg(x) cerr<<#x": "<<(x)<<'\n' #define dbg_v(x, n) cerr<<#x"[]: ";for(long long _=0;_ ev[NMAX]; void update(int pos, int val) { for(; pos < NMAX; pos += pos & -pos) bit[pos] += val; } int query(int pos) { int res; for(res = 0; pos; pos &= pos - 1) res += bit[pos]; return res; } int main() { #ifndef ONLINE_JUDGE freopen("data.in", "r", stdin); freopen("data.out", "w", stdout); #endif ios_base::sync_with_stdio(false); int i, n, a; ll ans; cin >> n; for(i = 1; i <= 2 * n; ++i) { cin >> a; if(!firstPos[a]) firstPos[a] = i, ev[i] = {1, a}; else secondPos[a] = i, ev[i] = {2, a}; } ans = 0; for(i = 1; i <= 2 * n; ++i) { if(ev[i].first == 2) { ans += query(i - 1) - query(firstPos[ev[i].second]); update(firstPos[ev[i].second], -2); update(i, 1); } else update(i, 1); } cout << ans / 2 << '\n'; return 0; }