func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   const int MOD = 1e9 + 7;   int add(int a, int b) { return a + b >= MOD ? a + b - MOD : a + b; }   int mul(int a, int b) { return 1ll * a * b % MOD; }   int n, x[N], y[N];   vector<int> g[N];   map<int, int> px, py;   int far[N], cnt, cir;   void dfs(int u, int fa) {     if (!px.count(x[u])) cnt++;     px[x[u]] = u;     if (!py.count(y[u])) cnt++;     py[y[u]] = u;     for (auto v : g[u]) {       if (v == fa) continue;       if (~far[v]) {         cir = 1;         continue;       }       far[v] = u;       dfs(v, u);     }   }   int pw2[N * 2];   void solve() {     for (int i = (0); i < (n); ++i) g[i].clear();     px.clear();     py.clear();     for (int i = (0); i < (n); ++i) {       int &x = ::x[i], &y = ::y[i];       scanf( %d%d , &x, &y);       if (px.count(x)) {         int j = px[x];         g[i].push_back(j);         g[j].push_back(i);       }       px[x] = i;       if (py.count(y)) {         int j = py[y];         g[i].push_back(j);         g[j].push_back(i);       }       py[y] = i;     }     int ans = 1;     fill_n(far, n, -1);     pw2[0] = 1;     for (int i = (1); i < (2 * n + 1); ++i) pw2[i] = add(pw2[i - 1], pw2[i - 1]);     for (int i = (0); i < (n); ++i)       if (!~far[i]) {         px.clear();         py.clear();         far[i] = cnt = cir = 0;         dfs(i, -1);         ans = mul(ans, pw2[cnt] - !cir);       }     printf( %d n , ans);   }   int main() {     while (~scanf( %d , &n)) solve();     return 0;   }   