func_code_string: #include <bits/stdc++.h>   using namespace std;   int gi() {     int x = 0, w = 1;     char ch = getchar();     while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar();     if (ch ==  - ) w = 0, ch = getchar();     while (ch >=  0  && ch <=  9 )       x = (x << 3) + (x << 1) + ch -  0 , ch = getchar();     return w ? x : -x;   }   const int N = 3e5 + 5;   int q, fa[N + N], top;   pair<int, int> sz[N + N], sta[N];   map<pair<int, int>, int> M;   vector<pair<int, int> > vec[N << 2];   long long ans;   pair<int, int> operator+(pair<int, int> a, pair<int, int> b) {     return make_pair(a.first + b.first, a.second + b.second);   }   pair<int, int> operator-(pair<int, int> a, pair<int, int> b) {     return make_pair(a.first - b.first, a.second - b.second);   }   int find(int x) { return x == fa[x] ? x : find(fa[x]); }   void modify(int x, int l, int r, int ql, int qr, pair<int, int> p) {     if (l >= ql && r <= qr) {       vec[x].push_back(p);       return;     }     int mid = l + r >> 1;     if (ql <= mid) modify(x << 1, l, mid, ql, qr, p);     if (qr > mid) modify(x << 1 | 1, mid + 1, r, ql, qr, p);   }   void dfs(int x, int l, int r) {     int tt = top;     for (pair<int, int> p : vec[x])       if (find(p.first) != find(p.second)) {         int u = find(p.first), v = find(p.second);         if (sz[u].first + sz[u].second < sz[v].first + sz[v].second) swap(u, v);         sta[++top] = make_pair(u, v);         ans -= 1ll * sz[u].first * sz[u].second;         ans -= 1ll * sz[v].first * sz[v].second;         fa[v] = u;         sz[u] = sz[u] + sz[v];         ans += 1ll * sz[u].first * sz[u].second;       }     if (l == r)       printf( %lld  , ans);     else {       int mid = l + r >> 1;       dfs(x << 1, l, mid);       dfs(x << 1 | 1, mid + 1, r);     }     while (top > tt) {       int u = sta[top].first, v = sta[top].second;       --top;       ans -= 1ll * sz[u].first * sz[u].second;       fa[v] = v;       sz[u] = sz[u] - sz[v];       ans += 1ll * sz[u].first * sz[u].second;       ans += 1ll * sz[v].first * sz[v].second;     }   }   int main() {     q = gi();     for (int i = 1; i <= q; ++i) {       int x = gi(), y = gi() + N;       if (M.find(make_pair(x, y)) == M.end())         M[make_pair(x, y)] = i;       else         modify(1, 1, q, M[make_pair(x, y)], i - 1, make_pair(x, y)),             M.erase(make_pair(x, y));     }     for (auto it = M.begin(); it != M.end(); ++it)       modify(1, 1, q, (*it).second, q, (*it).first);     for (int i = 1; i < N + N; ++i) fa[i] = i, sz[i] = make_pair(i < N, i >= N);     dfs(1, 1, q);     return 0;   }   