malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long n, m, cnt[100005], root, par[100005], br[100005], st[100005], brcnt;   vector<long long> a[100005];   pair<long long, long long> vert[100005];   map<pair<long long, long long>, long long> mm;   set<long long> brcl;   long long tmp = 1;   void dfs(long long v) {     if (a[v].size() > 0)       for (long long i = 0; i <= a[v].size() - 1; ++i) {         if (v == root) {           brcnt++;           st[brcnt] = tmp;         }         if (a[v][i] != par[v]) {           br[a[v][i]] = brcnt;           mm[make_pair(v, a[v][i])] = tmp++;           par[a[v][i]] = v;           dfs(a[v][i]);         }       }   }   inline long long finddist(long long req1, long long req2) {     if (brcl.empty()) return req2 - req1 + 1;     set<long long>::iterator curr = (brcl.lower_bound(req2));     if (*curr == req2) return -1;     if (curr == brcl.begin()) return req2 - req1 + 1;     curr--;     if (*curr >= req1 && *curr <= req2)       return -1;     else       return req2 - req1 + 1;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (long long i = 1; i <= n - 1; ++i) {       long long u, v;       cin >> u >> v;       cnt[u]++;       cnt[v]++;       if (cnt[u] > 2)         root = u;       else if (cnt[v] > 2)         root = v;       a[u].push_back(v);       a[v].push_back(u);       vert[i] = make_pair(u, v);     }     if (root == 0) root = 1;     par[root] = 0;     dfs(root);     for (long long i = 1; i <= n - 1; ++i)       if (vert[i].second == par[vert[i].first])         swap(vert[i].first, vert[i].second);     cin >> m;     for (long long loop = 1; loop <= m; ++loop) {       long long ty, id;       cin >> ty >> id;       if (ty == 1) {         long long edge = mm[vert[id]];         set<long long>::iterator it = brcl.find(edge);         brcl.erase(it);       } else if (ty == 2) {         long long edge = mm[vert[id]];         brcl.insert(edge);       } else {         long long en;         cin >> en;         if (en == id) {           cout << 0 << endl;           continue;         }         if (en == root) swap(en, id);         if (id == root) {           long long req1 = st[br[en]], req2 = mm[make_pair(par[en], en)];           cout << finddist(req1, req2) << endl;         } else if (br[id] == br[en]) {           if (mm[make_pair(par[en], en)] < mm[make_pair(par[id], id)])             swap(id, en);           long long v;           for (long long i = 0; i <= a[id].size() - 1; ++i)             if (a[id][i] != par[id]) v = a[id][i];           long long req1 = mm[make_pair(id, v)],                     req2 = mm[make_pair(par[en], en)];           cout << finddist(req1, req2) << endl;         } else {           long long req1 = st[br[en]], req2 = mm[make_pair(par[en], en)];           long long dist = finddist(req1, req2);           req1 = st[br[id]], req2 = mm[make_pair(par[id], id)];           cout << ((dist == -1 || finddist(req1, req2) == -1)                        ? -1                        : (finddist(req1, req2) + dist))                << endl;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long i, j, c, pi, pj, max, a[10][10];     char s[10][10];     c = 3;     for (i = 0; i < 6; i++) {       if (i % 2 == 0 && i > 0) c--;       a[i][0] = c;       a[i][1] = c;     }     c = 4;     for (i = 0; i < 6; i++) {       if (i % 2 == 0 && i > 0) c--;       a[i][3] = c;       a[i][4] = c;     }     c = 3;     for (i = 0; i < 6; i++) {       if (i % 2 == 0 && i > 0) c--;       a[i][6] = c;       a[i][7] = c;     }     for (i = 0; i < 6; i++) cin >> s[i];     pi = -1;     pj = -1;     max = 0;     for (i = 0; i < 6; i++)       for (j = 0; j < 8; j++)         if (j != 2 && j != 5) {           if (s[i][j] ==  . ) {             if (a[i][j] > max) {               max = a[i][j];               pi = i;               pj = j;             }           }         }     s[pi][pj] =  P ;     for (i = 0; i < 6; i++) cout << s[i] <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> A(n + 10, 0);     for (int i = 0; i < n; i++) cin >> A[i];     unordered_map<long long, int> fir, sec;     fir[A[0]] = 1;     for (int i = 1; i < n; i++) sec[A[i]]++;     long long S = 0;     for (int i = 0; i < n; i++) S += A[i];     long long sdash = 0;     if (S & 1) {       cout <<  NO  << endl;       return 0;     }     for (int i = 0; i < n; i++) {       sdash += A[i];       if (sdash == S / 2) {         cout <<  YES ;         return 0;       }       if (sdash < S / 2) {         long long x = S / 2 - sdash;         if (sec[x] > 0) {           cout <<  YES ;           return 0;         }       } else {         long long y = sdash - S / 2;         if (fir[y] > 0) {           cout <<  YES ;           return 0;         }       }       fir[A[i + 1]]++;       sec[A[i + 1]]--;     }     cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long double dist(long double x, long double y, long double a, long double b) {     return sqrt((a - x) * (a - x) + (y - b) * (y - b));   }   long double distMan(long double x, long double y, long double a,                       long double b) {     return abs(x - a) + abs(y - b);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long tt = 1;     while (tt--) {       long double a, b, c;       cin >> a >> b >> c;       long double x1, y1, x2, y2;       cin >> x1 >> y1 >> x2 >> y2;       if (a == 0 || b == 0) {         cout <<     << fixed << setprecision(20) <<                  << abs(x1 - x2) + abs(y1 - y2) <<   n ;       } else {         long double ans = abs(x2 - x1) + abs(y2 - y1);         long double x3, y3, x4, y4;         x3 = x1, x4 = x2;         y3 = (-a * x3 - c) / b, y4 = (-a * x4 - c) / b;         ans = min(ans, distMan(x1, y1, x3, y3) + distMan(x2, y2, x4, y4) +                            dist(x4, y4, x3, y3));         x3 = x1, y4 = y2;         y3 = (-a * x3 - c) / b, x4 = (-b * y4 - c) / a;         ans = min(ans, distMan(x1, y1, x3, y3) + distMan(x2, y2, x4, y4) +                            dist(x4, y4, x3, y3));         y3 = y1, x4 = x2;         x3 = (-b * y3 - c) / a, y4 = (-a * x4 - c) / b;         ans = min(ans, distMan(x1, y1, x3, y3) + distMan(x2, y2, x4, y4) +                            dist(x4, y4, x3, y3));         y3 = y1, y4 = y2;         x3 = (-b * y3 - c) / a, x4 = (-b * y4 - c) / a;         ans = min(ans, distMan(x1, y1, x3, y3) + distMan(x2, y2, x4, y4) +                            dist(x4, y4, x3, y3));         cout <<     << fixed << setprecision(20) <<     << ans <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   long long fp(long long x, long long y) {     long long res = 1;     while (y) res = (y & 1) ? res * x % mod : res, x = x * x % mod, y >>= 1;     return res;   }   int t;   int n, m, rb, cb, rd, cd, lx = 1, ly = 1;   long long p;   void dfs(int x, int y, int dx, int dy, vector<long long>& v) {     int nx = x + dx, ny = y + dy;     if (nx > n || nx < 1) dx = -dx;     if (ny > m || ny < 1) dy = -dy;     if ((x == rb && y == cb && v.size() != 0 && dx == lx && dy == ly)) return;     if (x == rd || y == cd)       v.push_back(p);     else       v.push_back(1);     nx = x + dx, ny = y + dy;     dfs(nx, ny, dx, dy, v);   }   int main() {     scanf( %d , &t);     while (t--) {       scanf( %d%d%d%d%d%d%lld , &n, &m, &rb, &cb, &rd, &cd, &p);       vector<long long> v;       long long fz = 1;       long long ny = fp(100, mod - 2), xx = 1;       p = (100ll - p) * ny % mod;       lx = 1, ly = 1;       int nx = rb + lx, nn = cb + ly;       if (nx > n || nx < 1) lx = -lx;       if (nn > m || nn < 1) ly = -ly;       dfs(rb, cb, lx, ly, v);       for (int i = 0; i < (int)v.size(); i++) {         fz = (fz * v[i]) % mod;       }       long long val = 0;       for (int i = 0; i < (int)v.size(); i++) {         xx = (v[i] * xx) % mod;         val += xx;         val %= mod;       }       fz = (1 - fz + mod) % mod;       val = (val * fp(fz, mod - 2)) % mod;       printf( %lld n , val);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 5005;   int n, T;   int pp[MAX];   int t[MAX];   double p[MAX];   double ps[MAX];   double pl[MAX];   double dp[2][MAX];   int main(void) {     scanf( %d%d , &n, &T);     for (int i = (0); i < (n); ++i) scanf( %d%d , pp + i, t + i);     for (int i = (0); i < (n); ++i) {       p[i] = 0.01 * pp[i];       double cp = 0.0;       double lp = p[i];       for (int j = (0); j < (t[i] - 1); ++j) {         cp *= (1.0 - p[i]);         cp += p[i];       }       for (int j = (0); j < (t[i] - 2); ++j) lp *= (1.0 - p[i]);       ps[i] = 1.0 - cp;       pl[i] = lp;     }     for (int i = n - 1; i >= 0; --i) {       int I = i % 2;       dp[I][0] = 0.0;       for (int tt = 1; tt <= T; ++tt) {         dp[I][tt] = dp[I][tt - 1];         if (t[i] == 1) {           dp[I][tt] = 1.0 + dp[I ^ 1][tt - 1];         } else {           if (tt - t[i] - 1 >= 0)             dp[I][tt] -= ps[i] * (1 + dp[I ^ 1][tt - t[i] - 1]);           if (tt - t[i] >= 0) dp[I][tt] -= pl[i] * (1.0 + dp[I ^ 1][tt - t[i]]);           dp[I][tt] *= (1.0 - p[i]);           dp[I][tt] += p[i] * (1.0 + dp[I ^ 1][tt - 1]);           if (tt - t[i] >= 0) dp[I][tt] += ps[i] * (1.0 + dp[I ^ 1][tt - t[i]]);         }       }     }     printf( %.10lf n , dp[0][T]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long int n;     cin >> n;     ;     long long int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     long long int dp[n];     memset(dp, 0, sizeof(dp));     long long int ans = 0;     int c1 = 0;     int f = 0;     while (f == 0) {       f = 1;       for (int i = 0; i < n; i++) {         if (dp[i] == 0 && a[i] >= c1) {           dp[i] = 1;           c1++;         }       }       if (c1 > 0) {         ans++;         f = 0;       }       c1 = 0;     }     cout << ans;     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int x, t, a, b, da, db;     cin >> x >> t >> a >> b >> da >> db;     if (x == 0) {       cout <<  YES  << endl;       return 0;     }     for (int i = 0; i < t; i++) {       if (a - da * i == x) {         cout <<  YES  << endl;         return 0;       }       if (b - db * i == x) {         cout <<  YES  << endl;         return 0;       }     }     for (int i = 0; i < t; i++) {       for (int j = 0; j < t; j++) {         if (a - da * i + b - db * j == x) {           cout <<  YES  << endl;           return 0;         }       }     }     cout <<  NO  << endl;   }
#include <bits/stdc++.h>   using namespace std;   void FAST() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int gcd(int x, int y) {     if (x == 0) return y;     return gcd(y % x, x);   }   int powM(int x, int y, int m) {     int ans = 1, r = 1;     x %= m;     while (r > 0 && r <= y) {       if (r & y) {         ans *= x;         ans %= m;       }       r <<= 1;       x *= x;       x %= m;     }     return ans;   }   map<long long, long long> factorize(long long n) {     map<long long, long long> ans;     for (long long i = 2; i * i <= n; i++) {       while (n % i == 0) {         ans[i]++;         n /= i;       }     }     if (n > 1) {       ans[n]++;       n = 1;     }     return ans;   }   const double pi = 3.14159265;   int main() {     FAST();     int n;     cin >> n;     string s;     cin >> s;     int o = 0, c = 0;     for (auto x : s) {       if (x ==  ( )         o++;       else         c++;     }     if (o != c)       cout << -1;     else {       int depth = 0, last = -1, ans = 0;       for (int i = 0; i < n; i++) {         if (s[i] ==  ( ) {           depth++;         } else {           depth--;         }         if (depth == 0 && s[i] ==  ( ) {           ans += (i - last);           last = i;         }         if (depth == 0) last = i;       }       cout << ans;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using LL = long long int;   struct point {     LL x, y;     point(LL x_ = 0, LL y_ = 0) : x(x_), y(y_) {}     point operator-(const point& b) { return point(x - b.x, y - b.y); }     point operator+(const point& b) { return point(x + b.x, y + b.y); }   };   LL cross_abs(const point& a, const point& b) {     return abs(a.x * b.y - b.x * a.y);   }   bool mult(const point& sp, const point& ep, const point& op) {     return (sp.x - op.x) * (ep.y - op.y) >= (ep.x - op.x) * (sp.y - op.y);   }   bool operator<(const point& l, const point& r) {     return (l.y < r.y) || (l.y == r.y && l.x < r.x);   }   int graham(point pnt[], int n, point res[]) {     int i = 0, len = 0, k = 0, top = 1;     sort(pnt, pnt + n);     if (n == 0) return 0;     res[0] = pnt[0];     if (n == 1) return 1;     res[1] = pnt[1];     if (n == 2) return 2;     res[2] = pnt[2];     for (i = 2; i < n; i++) {       while (top && mult(pnt[i], res[top], res[top - 1])) top--;       res[++top] = pnt[i];     }     len = top;     res[++top] = pnt[n - 2];     for (i = n - 3; i >= 0; i--) {       while (top != len && mult(pnt[i], res[top], res[top - 1])) top--;       res[++top] = pnt[i];     }     return top;   }   int n = 0;   LL ss = 0;   const int maxn = 5e3 + 5;   point p[maxn], cp[maxn];   LL maxs = 0;   int ansa = 0, ansb = 0, ansc = 0;   int main(void) {     scanf( %d %lld , &n, &ss);     for (int i = 0; i < n; ++i) scanf( %lld %lld , &p[i].x, &p[i].y);     int cnt = graham(p, n, cp);     for (int i = 0; i < cnt; ++i) {       for (int j = i + 1, k = (j + 1) % cnt; j < cnt && k != i; ++j) {         while (cross_abs(cp[i] - cp[k], cp[j] - cp[k]) <                cross_abs(cp[i] - cp[(k + 1) % cnt], cp[j] - cp[(k + 1) % cnt]))           k = (k + 1) % cnt;         if (k == i || k == j) continue;         LL s = cross_abs(cp[i] - cp[k], cp[j] - cp[k]);         if (s > maxs) {           maxs = s;           ansa = i, ansb = j, ansc = k;         }       }     }     point a = cp[ansa] - cp[ansb] + cp[ansc];     point b = cp[ansa] + cp[ansb] - cp[ansc];     point c = cp[ansb] + cp[ansc] - cp[ansa];     printf( %lld %lld n , a.x, a.y);     printf( %lld %lld n , b.x, b.y);     printf( %lld %lld n , c.x, c.y);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   void solve() {     int n;     cin >> n;     vector<long long> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     if (n == 1) {       cout <<  1 n ;       return;     }     vector<long long> difs(n - 1);     for (int i = 0; i < n - 1; i++) difs[i] = abs(a[i + 1] - a[i]);     vector<long long> cj(n);     vector<long long> fj(n);     cj[n - 1] = 0;     fj[n - 1] = 1;     long long res = 0;     for (int i = n - 2; i >= 0; i--) {       if (gcd(difs[i], fj[i + 1]) > 1) {         cj[i] = cj[i + 1] + 1;         fj[i] = gcd(difs[i], fj[i + 1]);       } else {         cj[i] = int(difs[i] > 1ll);         fj[i] = difs[i];         for (int k = 1; k < cj[i + 1]; k++) {           if (gcd(fj[i], difs[i + k]) > 1) {             cj[i]++;             fj[i] = gcd(fj[i], difs[i + k]);           } else             break;         }       }       res = max(res, cj[i]);     }     cout << res + 1 <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int tst;     cin >> tst;     while (tst--) solve();     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /stack:247474112 )   #pragma GCC optimize( Ofast )   using namespace std;   const long long maxn = 2e5 + 10;   long long mx[maxn], val[maxn], sum[maxn];   vector<long long> g[maxn];   long long pass[maxn];   bool ok = 0;   long long ans = LLONG_MIN;   void dfs(long long aa = 1, long long aaa = 0) {     vector<long long> v;     sum[aa] = val[aa];     for (long long a : g[aa]) {       if (a == aaa) continue;       dfs(a, aa);       sum[aa] += sum[a];       v.push_back(pass[a]);     }     if (!v.empty()) {       sort(v.begin(), v.end());       pass[aa] = max(v.back(), sum[aa]);       if (v.size() >= 2) {         ans = max(ans, v[v.size() - 1] + v[v.size() - 2]);       }     } else {       pass[aa] = sum[aa];     }   }   int32_t main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long n;     cin >> n;     for (long long i = 1; i <= n; ++i) cin >> val[i];     for (long long i = 1; i <= n; ++i) mx[i] = LLONG_MIN;     for (long long i = 1; i < n; ++i) {       long long u, v;       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     for (long long i = 1; i <= n; ++i) pass[i] = LLONG_MIN;     dfs(1);     if (ans == LLONG_MIN)       cout <<  Impossible ;     else       cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long second;   long long a1[1231], a2[2131];   long long b[1231];   long long sum[1231];   int main() {     int n;     cin >> n;     for (int i = 2; i <= n; i++) cin >> a1[i];     for (int i = 1; i <= n - 1; i++) cin >> a2[i];     for (int i = 1; i <= n; i++) {       cin >> b[i];       second += a1[i];       sum[i] = b[i] + second;     }     second = 0;     for (int i = n; i >= 1; i--) {       second += a2[i];       sum[i] += second;     }     sort(sum, sum + n + 1);     cout << sum[1] + sum[2];   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s[50];     bool ada[256] = {0};     double dekat[256];     for (int i = 0; i < 256; i++) dekat[i] = 1000000000.0;     int n, m;     double x;     cin >> n >> m >> x;     for (int i = 0; i < n; i++) cin >> s[i];     vector<pair<int, int> > v;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (s[i][j] ==  S ) v.push_back(make_pair(i, j));       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (s[i][j] ==  S ) continue;         ada[s[i][j]] = 1;         for (int k = 0; k < v.size(); k++) {           double temp = sqrt((v[k].first - i) * (v[k].first - i) +                              (v[k].second - j) * (v[k].second - j));           dekat[s[i][j]] = min(dekat[s[i][j]], temp);         }       }     }     int q;     cin >> q;     string qw;     cin >> qw;     int ans = 0;     for (int i = 0; i < qw.length(); i++) {       if (ada[qw[i]] == 1) continue;       if (qw[i] >=  a  && qw[i] <=  z  && v.size() > 0) {         if (ada[qw[i] - 32] == 0) {           ans = -1;           break;         } else {           if (dekat[qw[i] - 32] > x) {             ans++;           }         }       } else if (qw[i] >=  A  && qw[i] <=  Z  && v.size() > 0) {         if (ada[qw[i] + 32] == 0) {           ans = -1;           break;         } else {           if (dekat[qw[i] + 32] > x) {             ans++;           }         }       } else {         ans = -1;         break;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, b, cnt = 1, point = 0;     vector<int> x;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a >> b;       if (b == 0)         x.push_back(a);       else {         cnt += (b - 1);         point += a;       }     }     sort(x.begin(), x.end());     for (int j = x.size() - 1; j >= 0 && cnt > 0; j--, cnt--) {       point += x[j];     }     cout << point << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     char ch = getchar();     int nega = 1;     while (!isdigit(ch)) {       if (ch ==  - ) nega = -1;       ch = getchar();     }     int ans = 0;     while (isdigit(ch)) {       ans = ans * 10 + ch - 48;       ch = getchar();     }     if (nega == -1) return -ans;     return ans;   }   int fa[200005 * 2], siz[200005 * 2], n;   int find(int u) { return fa[u] == u ? u : fa[u] = find(fa[u]); }   int a[200005], b[200005];   vector<int> v[200005];   void merge(int u, int v) {     u = find(u), v = find(v);     if (u == v) return;     fa[u] = v;     siz[v] += siz[u];   }   bool vis[200005 * 2], ch[200005 * 2];   void work() {     cin >> n;     for (int i = 1; i <= n; i++) v[i].clear();     for (int i = 1; i <= n; i++) a[i] = read(), v[a[i]].push_back(i);     for (int i = 1; i <= n; i++) b[i] = read(), v[b[i]].push_back(i + n);     for (int i = 1; i <= 2 * n; i++) fa[i] = i;     for (int i = 1; i <= n; i++) siz[i] = 1;     for (int i = n + 1; i <= 2 * n; i++) siz[i] = 0;     for (int i = 1; i <= n * 2; i++) vis[i] = ch[i] = 0;     for (int i = 1; i <= n; i++) {       if (v[i].size() != 2) {         cout <<  -1 n ;         return;       }       int a = v[i][0], b = v[i][1];       if (a > b) swap(a, b);       if (a == b - n) continue;       if (a > n) {         a -= n, b -= n;         merge(a, b + n), merge(a + n, b);       } else if (b <= n)         merge(a, b + n), merge(a + n, b);       else {         b -= n;         merge(a, b), merge(a + n, b + n);       }     }     for (int i = 1; i <= n; i++) {       if (find(i) == find(i + n)) {         cout <<  -1 n ;         return;       }     }     int ans = 0;     for (int i = 1; i <= n; i++) {       int u = find(i), v = find(i + n);       if (vis[u] || vis[v]) continue;       ans += min(siz[u], siz[v]);       vis[u] = vis[v] = 1;       if (siz[u] < siz[v])         ch[u] = 1;       else         ch[v] = 1;     }     cout << ans << endl;     for (int i = 1; i <= n; i++) {       int u = find(i);       if (ch[u]) printf( %d  , i);     }     cout <<   n ;   }   signed main() {     int T = read();     while (T--) work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, x[101000], y[101000], fa[101000], sz[101000], tot[101000], u, v;   map<int, vector<int> > xx, yy;   map<int, vector<int> >::iterator it;   long long ans = 1, er[202000];   int GF(int x) { return fa[x] == x ? x : fa[x] = GF(fa[x]); }   void doit(vector<int> &the) {     for (int i = 1; i < (int)the.size(); i++)       if ((u = GF(the[i - 1])) != (v = GF(the[i]))) {         sz[v] += sz[u];         tot[v] += tot[u];         fa[u] = v;       }     tot[GF(the[0])]++;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> x[i] >> y[i];       xx[x[i]].push_back(i);       yy[y[i]].push_back(i);       fa[i] = i;       sz[i] = 1;     }     for (it = xx.begin(); it != xx.end(); it++) doit(it->second);     for (it = yy.begin(); it != yy.end(); it++) doit(it->second);     er[0] = 1;     for (int i = 1; i < 202000; i++) er[i] = er[i - 1] * 2 % 1000000007;     for (int i = 1; i <= n; i++)       if (fa[i] == i) ans = ans * (er[tot[i]] - (tot[i] > sz[i])) % 1000000007;     cout << (ans + 1000000007) % 1000000007;   }