malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   struct node {     int x, l;   } a[200005];   int skip[200005][25];   int mx[200005];   long long f[200005][25];   inline int read() {     register int x = 0, f = 1;     register char s = getchar();     while (s >  9  || s <  0 ) {       if (s ==  - ) f = -1;       s = getchar();     }     while (s >=  0  && s <=  9 ) {       x = x * 10 + s -  0 ;       s = getchar();     }     return x * f;   }   inline int max(const int &x, const int &y) { return x > y ? x : y; }   int main() {     int n = read();     for (register int i = 1; i <= n; ++i) {       a[i].x = read();       a[i].l = read();     }     for (register int i = n - 1; i >= 1; --i) {       int cur = i + 1;       mx[i] = a[i].x + a[i].l;       while (cur && a[i].x + a[i].l >= a[cur].x) {         mx[i] = max(mx[i], mx[cur]);         cur = skip[cur][0];       }       skip[i][0] = cur;       f[i][0] = a[cur].x - mx[i];     }     for (register int i = 1; i <= 20; ++i) {       for (register int x = 1; x <= n; ++x) {         f[x][i] = f[x][i - 1] + f[skip[x][i - 1]][i - 1];         skip[x][i] = skip[skip[x][i - 1]][i - 1];       }     }     int Q = read();     while (Q--) {       int l = read(), r = read();       if (skip[l][0] > r) {         printf( 0 n );       } else {         long long ans = 0;         for (register int i = 20; i >= 0; --i) {           if (skip[l][i] && skip[l][i] <= r) {             ans += f[l][i];             l = skip[l][i];           }         }         printf( %lld n , ans);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     cin >> q;     while (q--) {       int n;       cin >> n;       vector<int> v(n);       set<int> st;       for (int i = 0; i < n; i++) {         cin >> v[i];         st.insert(v[i]);       }       sort(v.begin(), v.end());       int mx = v.back();       int ans = mx;       if (mx % 2 == 0 && mx % 3 == 0 && mx % 5 == 0) {         if (st.find(mx / 2) != st.end() && st.find(mx / 3) != st.end() &&             st.find(mx / 5) != st.end()) {           ans = max(ans, mx / 2 + mx / 3 + mx / 5);         }       }       vector<int> tmp;       while (!st.empty() && tmp.size() < 3) {         int x = *st.rbegin();         st.erase(prev(st.end()));         bool f = 1;         for (auto it : tmp) {           if (it % x == 0 || x % it == 0) f = 0;         }         if (f) tmp.push_back(x);       }       int sum = 0;       for (auto it : tmp) sum += it;       ans = max(ans, sum);       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, q, i, j, u, v, k;   int a[300003];   int last[19];   int go[300003][19];   int main() {     cin >> n >> q;     for (i = 0; i < n; i++) cin >> a[i];     for (i = 0; i < 19; i++) {       go[n][i] = n;       last[i] = n;     }     for (i = n - 1; i >= 0; i--) {       for (j = 0; j < 19; j++) go[i][j] = n;       for (j = 0; j < 19; j++) {         if ((a[i] >> j) & 1) {           for (k = 0; k < 19; k++) go[i][k] = min(go[i][k], go[last[j]][k]);           last[j] = i;           go[i][j] = i;         }       }     }     for (i = 0; i < q; i++) {       cin >> u >> v;       u--, v--;       bool good = false;       for (j = 0; j < 19; j++) good |= (((a[v] >> j) & 1) && go[u][j] <= v);       if (good)         cout <<  Shi n ;       else         cout <<  Fou n ;     }   }
#include <bits/stdc++.h>   using namespace std;   vector<int> arr(78498);   vector<vector<int>> in(505, vector<int>(505));   vector<vector<int>> out(505, vector<int>(505));   void SieveOfEratosthenes(int n) {     vector<bool> prime(n + 1, true);     for (int p = 2; p * p <= n; p++) {       if (prime[p] == true) {         for (int i = p * p; i <= n; i += p) prime[i] = false;       }     }     int i = 0;     for (int p = 2; p <= n; p++)       if (prime[p]) arr[i++] = p;   }   int f(int val) {     int l = 0, u = arr.size() - 1, res = -1;     while (l <= u) {       int mid = (l + u) / 2;       if (val == arr[mid])         return -2;       else if (val < arr[mid]) {         res = mid;         u = mid - 1;       } else         l = mid + 1;     }     return res;   }   int main() {     SieveOfEratosthenes(1000000);     sort(arr.begin(), arr.end());     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) cin >> in[i][j];     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         int res = f(in[i][j]);         if (res == -2)           out[i][j] = 0;         else if (res == -1)           cout <<  error  << endl;         else {           out[i][j] = arr[res] - in[i][j];         }       }     }     long long mini = pow(10, 18);     for (int i = 0; i < n; i++) {       long long tot = 0;       for (int j = 0; j < m; j++) tot += (long long)out[i][j];       mini = min(mini, tot);     }     for (int j = 0; j < m; j++) {       long long tot = 0;       for (int i = 0; i < n; i++) tot += (long long)out[i][j];       mini = min(mini, tot);     }     cout << mini << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     char a[103], c;     int length, i, m;     gets(a);     length = strlen(a);     for (i = length - 2; i >= 0; --i) {       if (a[i] !=    ) {         c = a[i];         break;       }     }     if (c ==  a  || c ==  e  || c ==  i  || c ==  o  || c ==  u  || c ==  y  ||         c ==  A  || c ==  E  || c ==  I  || c ==  O  || c ==  U  || c ==  Y ) {       printf( YES n );     } else {       printf( NO n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int vp, vd, t, f, c, ans;     double cc, d;     scanf( %d%d%d%d%d , &vp, &vd, &t, &f, &c);     if (vd <= vp) {       printf( 0 n );       return 0;     }     d = vp * t;     cc = c;     ans = 0;     while (1) {       if (d + d / (vd - vp) * vp >= cc - 1e-9) break;       ans++;       d = d + (2 * d / (vd - vp) + f) * vp;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> v;   int n, x, now;   long long ans;   char a[3];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a;       if (a[0] ==  a ) {         cin >> x;         v.insert(lower_bound(v.begin(), v.end(), x), x);       }       if (a[0] ==  d ) {         cin >> x;         v.erase(lower_bound(v.begin(), v.end(), x));       }       if (a[0] ==  s ) {         ans = 0;         for (int i = 2; i < v.size(); i += 5) ans += v[i];         cout << ans << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   class Jora {    public:     int a;     int b;   };   int myfunc(Jora A, Jora B) {     if (A.a < B.a) return 1;     if (A.a > B.a) return 0;     return A.b < B.b;   }   Jora jrr[200200];   int n;   vector<int> ser;   map<int, int> taken;   map<int, vector<int> > mp;   int sss;   int cal() {     map<int, int> val, ans;     for (int i = 0; i < ser.size(); i++) {       val[ser[i]] = 2000000000;       ans[ser[i]] = 0;     }     int sum = 0;     int cur = 0;     int tim = 1;     for (int i = 0; i < ser.size(); i++) {       int to = ser[i];       int uu = ((to - cur) + sum) % 1000000007;       if (val[to] > uu) {         val[to] = uu;         ans[to] = tim;       } else if (val[to] == uu) {         ans[to] = (ans[to] + tim) % 1000000007;       }       int aa = val[to];       int bb = ans[to];       vector<int> &vvv = mp[to];       for (int j : vvv) {         if (val[j] > aa) {           val[j] = aa;           ans[j] = bb;         } else if (val[j] == aa) {           ans[j] = (ans[j] + bb) % 1000000007;         }       }       sum = aa;       cur = to;       tim = bb;     }     int tot = 0;     int value = 2000000000;     map<int, int> mrk;     for (int i = 1; i <= n; i++) {       int u = jrr[i].a;       if (mrk[u] != 1 && u > sss) {         if (val[u] < value) {           value = val[u];           tot = ans[u];         } else if (val[u] == value)           tot = (tot + ans[u]) % 1000000007;       }       mrk[u] = 1;     }     return tot;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &jrr[i].a, &jrr[i].b);       mp[jrr[i].b].push_back(jrr[i].a);       if (taken[jrr[i].a] != 1) ser.push_back(jrr[i].a);       if (taken[jrr[i].b] != 1) ser.push_back(jrr[i].b);       taken[jrr[i].a] = 1;       taken[jrr[i].b] = 1;       sss = max(sss, jrr[i].b);     }     sort(ser.begin(), ser.end());     printf( %d n , cal());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long f(long long l) {     if (l < 10ll) return l;     long long L = l, t = 1ll, ans = 0ll;     int x = 0, last;     while (L) {       x++;       last = L % 10;       L /= 10;     }     for (int i = 1; i < x; i++) {       ans += 9ll * t;       if (i >= 2) t *= 10ll;     }     ans += (last - 1ll) * t;     if (x >= 2) t *= 10ll;     l -= t * 1ll * last;     ans += l / 10ll;     if (l % 10 >= last) ans++;     return ans;   }   int main() {     long long l, r;     cin >> l >> r;     cout << f(r) - f(l - 1);     return 0;   }
#include <bits/stdc++.h>   int main() {     long long k, l, c = 0;     scanf( %I64d , &k);     scanf( %I64d , &l);     while (l % k == 0) {       l /= k;       c++;     }     if (c >= 0 && l == 1)       printf( YES n%I64d , c - 1);     else       printf( NO );   }
#include <bits/stdc++.h>   using namespace std;   struct Node {     int id, fail, next[26];     void init() {       id = -1;       fail = -1;       memset(next, 0, sizeof(int) * 26);     }   } node[2000050];   int e;   void insert(char *str, int id) {     int len = strlen(str);     int pos = 0;     for (int i = 0; i < len; i++) {       int tmp = str[i] -  a ;       if (node[pos].next[tmp] == 0) {         node[++e].init();         node[pos].next[tmp] = e;       }       pos = node[pos].next[tmp];     }     node[pos].id = id;   }   int head, tail, q[2000050];   void bfs() {     head = tail = 0;     q[tail++] = 0;     while (head < tail) {       int u = q[head++];       for (int i = 0; i < 26; i++) {         if (node[u].next[i]) {           int tmp = node[u].fail;           while (tmp != -1 && node[tmp].next[i] == 0) tmp = node[tmp].fail;           if (tmp == -1)             tmp = 0;           else             tmp = node[tmp].next[i];           node[node[u].next[i]].fail = tmp;           q[tail++] = node[u].next[i];         }       }     }   }   int n, k, g;   char record[2000050];   char word[2000050];   int dp[2000050];   int ans[2000050];   int cnt[2000050];   void solve() {     memcpy(record + k * n, record, k * n);     memset(dp, -1, sizeof(int) * (n * k));     int pos = 0;     for (int i = 0; i < k * n * 2; i++) {       while (pos != 0 && node[pos].next[record[i] -  a ] == 0)         pos = node[pos].fail;       pos = node[pos].next[record[i] -  a ];       if (node[pos].id != -1) dp[i % (n * k)] = node[pos].id;     }     memset(cnt, 0, sizeof(int) * g);     for (int st = 0; st < k; st++) {       bool flag = true;       pos = st;       for (int i = 0; i < n; i++) {         if (dp[pos] == -1 || cnt[dp[pos]] > 0) {           flag = false;           while (pos >= 0) {             cnt[dp[pos]] = 0;             pos -= k;           }           break;         }         cnt[dp[pos]] = 1;         ans[i] = dp[pos] + 1;         pos += k;       }       if (flag) {         printf( YES n );         for (int i = 0; i < n; i++) printf( %d  , ans[i]);         printf(  n );         return;       }     }     printf( NO n );   }   int main() {     while (scanf( %d%d , &n, &k) == 2) {       scanf( %s , record);       scanf( %d , &g);       e = 0;       node[0].init();       for (int i = 0; i < g; i++) {         scanf( %s , word);         insert(word, i);       }       bfs();       solve();     }   }
#include <bits/stdc++.h>   const int xn = 200001, xe = 399999;   int head[xn], next[xe], to[xe], N, E, fa[xn], q[xn], ue[xn], O[xn * 5], L,       col[xn], D;   int main() {     scanf( %d , &N);     bool allblack = 1;     for (int i = 1; i <= N; i++) {       scanf( %d , col + i);       if (col[i] == -1) allblack = 0;     }     if (allblack) {       puts( 1 );       return 0;     }     for (int i = 1, u, v; i < N; i++) {       scanf( %d%d , &u, &v);       next[++E] = head[u], to[E] = v, head[u] = E;       next[++E] = head[v], to[E] = u, head[v] = E;     }     q[1] = 1;     ue[1] = head[1];     D = 1;     O[L = 1] = 1;     while (D) {       if (to[ue[D]] == fa[q[D]]) ue[D] = next[ue[D]];       if (ue[D]) {         int To = to[ue[D]];         ue[D] = next[ue[D]];         O[++L] = To;         fa[To] = q[D];         q[++D] = To;         ue[D] = head[To];       } else {         if (D > 1) {           O[++L] = q[D - 1];           col[q[D - 1]] *= col[q[D]];         }         D--;       }     }     printf( 1 );     for (int i = 1; i < L - 1; i++)       if (O[i] == fa[O[i + 1]] && col[O[i + 1]] == 1)         printf(  %d %d %d , O[i + 1], O[i], O[i + 1]);       else         printf(  %d , O[i + 1]);     if (col[1] == 1) printf(  1 );     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, cntu[1000006], cntd[1000006], preu[1000006], pred[1000006];   string s;   vector<long long> lisu, lisd;   int main() {     ios::sync_with_stdio(0);     cin >> n >> s;     lisd.push_back(0);     lisu.push_back(0);     for (int i = 1; i <= n; i++) {       if (s[i - 1] ==  D )         cntd[i]++;       else         cntu[i]++;       cntd[i] += cntd[i - 1];       cntu[i] += cntu[i - 1];       if (s[i - 1] ==  D )         pred[i] += i;       else         preu[i] += i;       pred[i] += pred[i - 1];       preu[i] += preu[i - 1];       if (s[i - 1] ==  D ) {         lisd.push_back(lisd.back() + i);       } else {         lisu.push_back(lisu.back() + i);       }     }     for (int i = 1; i <= n; i++) {       if (s[i - 1] ==  U ) {         long long down_after = cntd[n] - cntd[i];         long long up_before = cntu[i - 1];         if (down_after <= up_before)           cout << 2 * (pred[n] - pred[i]) +                       2 * (-lisu[cntu[i - 1]] + lisu[cntu[i - 1] - down_after]) +                       n - i + 1                <<    ;         else           cout << 2 * (lisd[cntd[i] + up_before + 1] - i - lisd[cntd[i]] -                        lisu[cntu[i - 1]] + lisu[cntu[i - 1] - up_before]) +                       i                <<    ;       } else {         long long down_after = cntd[n] - cntd[i];         long long up_before = cntu[i - 1];         if (up_before <= down_after)           cout << 2 * (lisd[cntd[i] + up_before] - lisd[cntd[i]] -                        lisu[cntu[i - 1]] + lisu[cntu[i - 1] - up_before]) +                       i                <<    ;         else           cout << 2 * (lisd[cntd[i] + down_after] - lisd[cntd[i]] -                        lisu[cntu[i - 1]] + lisu[cntu[i - 1] - down_after - 1] +                        i) +                       n - i + 1                <<    ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long a;       cin >> a;       long long b;       cin >> b;       if (b >= a) {         if (b % a == 0 && pow(2, (long long)log2(b / a)) == b / a) {           if ((long long)(log2(b / a)) % 3 == 0) {             cout << (long long)log2(b / a) / 3 << endl;           } else {             cout << (long long)(1 + (log2(b / a) / 3)) << endl;           }         } else {           cout << -1 << endl;         }       } else {         if (a % b == 0 && pow(2, (long long)log2(a / b)) == a / b) {           if ((long long)(log2(a / b)) % 3 == 0) {             cout << (long long)log2(a / b) / 3 << endl;           } else {             cout << (long long)(1 + (log2(a / b) / 3)) << endl;           }         } else {           cout << -1 << endl;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, count = 0;     for (int i = 0; i < 5; i++) {       for (int j = 0; j < 5; j++) {         cin >> n;         if (n == 1) {           count = abs(2 - i) + abs(2 - j);           cout << count << endl;           return 0;         }       }     }     cout << count << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, v;     int sum = 0;     int cnt[10];     memset(cnt, 0, sizeof cnt);     cin >> n;     while (n--) {       cin >> v;       cnt[v]++;       sum += v;     }     if (cnt[0] == 0) {       cout <<  -1 ;       return 0;     }     int mod = sum % 3;     if (mod != 0) {       bool deleted = 0;       for (int i = mod; i < 9; i += 3) {         if (cnt[i] > 0) {           deleted = 1;           cnt[i]--;           break;         }       }       if (!deleted) {         int left = 2;         for (int i = mod == 1 ? 2 : 1; i < 9 && left; i += 3) {           int take = min(left, cnt[i]);           left -= take;           cnt[i] -= take;         }       }     }     string res;     for (int i = 9; i >= 0; i--) {       if (i == 0 && res.empty()) cnt[0] = 1;       res += string(cnt[i],  0  + i);     }     cout << res;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<long long, string> > v[10020];   int main() {     long long n, m;     pair<long long, string> p;     long long temp;     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> p.second;       cin >> temp;       cin >> p.first;       v[temp].push_back(p);     }     for (int i = 1; i <= m; i++) {       sort(v[i].begin(), v[i].end());     }     for (int i = 1; i <= m; i++) {       int k = v[i].size();       if (k < 2 || (k > 2 && v[i][k - 2].first == v[i][k - 3].first)) {         cout <<  ?  << endl;       } else {         cout << v[i][k - 1].second <<     << v[i][k - 2].second << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   const double EPS = 1e-9;   const double PI = acos(-1.);   const int INF = 1e8;   const int MAXN = 505;   const long long MOD = 1e9 + 7;   int v[MAXN];   int dp[MAXN][MAXN];   void solve() {     int n, i, j, k, lim, fl;     scanf( %d , &n);     for ((i) = (0); (i) < (int)(n); (i)++) {       scanf( %d , &v[i]);     }     for ((i) = (0); (i) < (int)(n); (i)++) {       for ((j) = (0); (j) < (int)(n); (j)++) {         dp[i][j] = INF;       }     }     for (i = n - 1; i >= 0; i--) {       dp[i][i] = 1;       if (i < n - 1) {         dp[i][i + 1] = 2;         if (v[i] == v[i + 1]) {           dp[i][i + 1] = 1;         }       }       for (j = i + 2; j < n; j++) {         for (k = i; k < j; k++) {           dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j]);         }         if (v[i] == v[j]) {           dp[i][j] = min(dp[i][j], dp[i + 1][j - 1]);         }       }     }     printf( %d n , dp[0][n - 1]);   }   int main() {     int t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int n, a[110], suml[110], sumr[110], ans = 0;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) suml[i] = suml[i - 1] + (a[i] == 0);     for (int i = n; i >= 1; i--) sumr[i] = sumr[i + 1] + (a[i] == 1);     for (int i = 1; i <= n; i++) ans = max(ans, suml[i] + sumr[i]);     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long int n;     cin >> n;     vector<vector<long double> > dist(n + 1, vector<long double>(n + 1));     vector<long double> x(n + 1), y(n + 1), z(n + 1);     vector<long long int> vis(n + 1, 0);     for (long long int i = 1; i <= n; i++) cin >> x[i] >> y[i] >> z[i];     for (long long int i = 1; i <= n; i++) {       for (long long int j = 1; j <= n; j++) {         dist[i][j] = (x[i] - x[j]) * (x[i] - x[j]) +                      (y[i] - y[j]) * (y[i] - y[j]) +                      (z[i] - z[j]) * (z[i] - z[j]);         dist[i][j] = sqrt(dist[i][j]);       }     }     for (long long int i = 1; i <= n; i++) {       if (vis[i] == 0) {         long double big = 1e18 * 1.0;         long long int ans;         for (long long int j = i + 1; j <= n; j++) {           if (vis[j] == 0) {             if (dist[i][j] < big) {               big = dist[i][j];               ans = j;             }           }         }         vis[ans] = 1;         vis[i] = 1;         cout << i <<     << ans <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int xx[4] = {0, 0, 1, -1};   int yy[4] = {1, -1, 0, 0};   int n, m, b, s;   int x[int(1e5)], y[int(1e5)];   int main() {     scanf( %d%d , &n, &m);     scanf( %d , &b);     for (int i = (1), _b = (b); i <= _b; i++) {       scanf( %d , &s);       x[s] = true;     }     scanf( %d , &b);     for (int i = (1), _b = (b); i <= _b; i++) {       scanf( %d , &s);       y[s] = true;     }     for (int i = (0), _b = (2 * n * m); i <= _b; i++) {       int u = i % n;       int v = i % m;       if (x[u] || y[v]) {         x[u] = true;         y[v] = true;       }     }     for (int i = (0), _b = (n - 1); i <= _b; i++)       if (!x[i]) {         cout <<  No  << endl;         return 0;       }     for (int i = (0), _b = (m - 1); i <= _b; i++)       if (!y[i]) {         cout <<  No  << endl;         return 0;       }     cout <<  Yes  << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5e3 + 10;   int ad[N][N];   long long n;   pair<int, int> t[N];   bool ok;   int c[N];   void connect(int k) {     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         if (abs(t[i].first - t[j].first) + abs(t[i].second - t[j].second) > k)           ad[i][j] = ad[j][i] = 1;         else           ad[i][j] = ad[j][i] = 0;       }     }   }   void dfs(int v, int col) {     c[v] = col;     for (int i = 0; i < n; i++) {       if (ad[v][i] && c[i] == 0)         dfs(i, 3 - col);       else if (ad[v][i] && c[i] == col) {         ok = 0;         return;       }     }   }   int tt = 10000;   int bs() {     long long top = 10100, low = 0;     while (top > low + 1) {       int md = (low + top) / 2;       connect(md);       ok = true;       for (int i = 0; i < n; i++) c[i] = 0;       for (int i = 0; i < n; i++) {         if (!c[i]) {           dfs(i, 1);         }       }       if (ok)         top = md;       else         low = md;       tt = top;     }     return top;   }   bool mark[N] = {0};   void dfsp(int v) {     mark[v] = 1;     for (int i = 0; i < n; i++) {       if (ad[v][i] && mark[i] == 0) dfsp(i);     }   }   const int M = 1e9 + 7;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     if (n == 2) {       cout << 0 << endl << 2;       return 0;     }     for (int i = 0; i < n; i++) cin >> t[i].first >> t[i].second;     cout << bs() << endl;     connect(tt);     long long x = 1;     for (int i = 0; i < n; i++) {       if (mark[i] == 0) {         x *= 2;         x %= M;         dfsp(i);       }     }     cout << x << endl;     return 0;   }