malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 15, maxx = 10;   long long a[maxn], b[maxn], c[maxn];   void Init() {     for (int i = 1; i <= maxx; i++) {       long long x = i, l = 1, r = 0;       while (x--) l *= 10, r = r * 10 + 9;       l /= 10;       a[i] = (r - l + 1) * i;       b[i] = b[i - 1] + a[i];       c[i] = c[i - 1] + (b[i - 1] + i + b[i]) * (r - l + 1) / 2;     }   }   int main() {     ios::sync_with_stdio(0);     Init();     long long t, n, pos;     cin >> t;     while (t--) {       cin >> n;       pos = lower_bound(c + 1, c + maxx + 1, n) - c;       n = n - c[pos - 1];       long long l = 1, r = 0, x = pos, t = b[pos - 1];       while (x--) l *= 10, r = 10 * r + 9;       l /= 10;       long long L = l;       while (l <= r) {         long long mid = (l + r) >> 1;         long long cnt = mid - L + 1;         if ((2 * t + pos + cnt * pos) * cnt / 2 >= n)           r = mid - 1;         else           l = mid + 1;       }       long long cnt = l - L;       n -= (2 * t + pos + cnt * pos) * cnt / 2;       pos = lower_bound(b + 1, b + maxx + 1, n) - b;       n -= b[pos - 1];       int ans = 1;       for (int i = 1; i < pos; i++) ans *= 10;       t = (n - 1) / pos;       n -= t * pos;       ans += t;       n = pos - n;       while (n--) ans /= 10;       cout << ans % 10 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool flag;   int n, a[1010], vis[2010], T;   pair<int, int> ans[5];   void read(int &x) {     char ch = getchar();     int mark = 1;     for (; ch !=  -  && (ch <  0  || ch >  9 ); ch = getchar())       ;     if (ch ==  - ) mark = -1, ch = getchar();     for (x = 0; ch >=  0  && ch <=  9 ; ch = getchar()) x = x * 10 + ch - 48;     x *= mark;   }   bool check(int step) {     for (int i = 1; i <= n; i++)       if (a[i] != i) return 0;     return 1;   }   void rev(int *a, int l, int r) {     for (int i = 0; i <= (r - l - 1) / 2; i++) swap(a[i + l], a[r - i]);   }   int expect() {     int ans = 1;     for (int i = 2; i <= n; i++)       if (abs(a[i] - a[i - 1]) != 1) ans++;     return ans;   }   void dfs(int step) {     if (check(step - 1)) {       printf( %d n , step - 1);       for (int i = step - 1; i; i--)         printf( %d %d n , ans[i].first, ans[i].second);       flag = 1;       return;     }     if (step > 3) return;     int c[1010];     for (int i = 1; i <= n; i++) {       for (int j = i + 1; j <= n; j++)         if (abs(a[i - 1] - a[j]) == 1 || abs(a[i] - a[j + 1]) == 1) {           for (int k = i; k <= j; k++) c[k] = a[k];           rev(a, i, j);           if (expect() <= (3 - step) * 2 + 1) {             ans[step] = make_pair(i, j);             dfs(step + 1);             if (flag) return;           }           for (int k = i; k <= j; k++) a[k] = c[k];         }     }   }   int main() {     read(n);     for (int i = 1; i <= n; i++) read(a[i]);     a[n + 1] = n + 1;     dfs(1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool test(long long k, long long x, long long n, long long m, long long p1,             long long l1, long long r1, long long p2, long long l2,             long long r2) {     if (p1 * 2 + l1 + r1 > n) return false;     if (p2 * 2 + l2 + r2 > m) return false;     for (long long i = 0; i < k - 2; i++) {       long long p3 = p1 + p2 + (r1 * l2);       long long l3 = l1;       long long r3 = r2;       l1 = l2;       r1 = r2;       p1 = p2;       l2 = l3;       r2 = r3;       p2 = p3;       if (p2 > x) return false;     }     return p2 == x;   }   string build(long long n, long long p, long long l, long long r) {     string s(n,  X );     if (l) s[0] =  C ;     if (r) s[n - 1] =  A ;     for (long long i = 0; i < p; i++) {       s[l + i * 2] =  A ;       s[l + i * 2 + 1] =  C ;     }     return s;   }   signed main() {     ios::sync_with_stdio(false);     long long k, x, n, m;     cin >> k >> x >> n >> m;     for (long long p1 = 0; p1 <= n / 2; p1++) {       for (long long l1 = 0; l1 <= 1; l1++) {         for (long long r1 = 0; r1 <= 1; r1++) {           for (long long p2 = 0; p2 <= m / 2; p2++) {             for (long long l2 = 0; l2 <= 1; l2++) {               for (long long r2 = 0; r2 <= 1; r2++) {                 if (test(k, x, n, m, p1, l1, r1, p2, l2, r2)) {                   string s1 = build(n, p1, l1, r1);                   string s2 = build(m, p2, l2, r2);                   cout << s1 <<   n  << s2 <<   n ;                   return 0;                 }               }             }           }         }       }     }     cout <<  Happy new year! n ;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize 2   using namespace std;   const int N = 2e4 + 9;   struct stree {     int l, r, lazy, sum;   } t[N << 2];   int dp[20005];   inline void pushdown(int now) {     int lazy = t[now].lazy;     if (!lazy) return;     if (t[now].l != t[now].r)       t[now * 2].lazy += lazy, t[now * 2 + 1].lazy += lazy;     t[now].sum += lazy;     t[now].lazy = 0;   }   inline void build(int now, int l, int r) {     t[now].l = l, t[now].r = r, t[now].lazy = 0;     if (l == r) {       t[now].sum = dp[l];       return;     }     int mid = (l + r) / 2;     build(now * 2, l, mid), build(now * 2 + 1, mid + 1, r);     t[now].sum = max(t[now * 2].sum, t[now * 2 + 1].sum);   }   inline void change(int now, int l, int r, int d) {     if (l > r) return;     pushdown(now);     if (t[now].l == l && t[now].r == r) {       t[now].lazy += d;       return;     }     pushdown(now);     if (t[now * 2].r >= r)       change(now * 2, l, r, d);     else if (t[now * 2 + 1].l <= l)       change(now * 2 + 1, l, r, d);     else       change(now * 2, l, t[now * 2].r, d),           change(now * 2 + 1, t[now * 2 + 1].l, r, d);     pushdown(now);     if (t[now].l != t[now].r)       pushdown(now * 2), pushdown(now * 2 + 1),           t[now].sum = max(t[now * 2].sum, t[now * 2 + 1].sum);   }   inline int query(int now, int l, int r) {     pushdown(now);     if (l > r) return 0;     if (t[now].l == l && t[now].r == r) return t[now].sum;     if (t[now * 2].r >= r)       return query(now * 2, l, r);     else if (t[now * 2 + 1].l <= l)       return query(now * 2 + 1, l, r);     else       return max(query(now * 2, l, t[now * 2].r),                  query(now * 2 + 1, t[now * 2 + 1].l, r));   }   int qzh[55][20005], a[55][20005], cf[20005];   int main() {     int n, m, k;     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> a[i][j];         qzh[i][j] = qzh[i][j - 1] + a[i][j];       }     }     int ans = 0;     for (int i = 1; i <= n; i++) {       if (i != 1) {         for (int j = 1; j <= k; j++) dp[j] -= qzh[i][k] - qzh[i][j - 1];       }       build(1, 1, m);       memset(dp, 0, sizeof dp);       for (int j = 1; j <= m - k + 1; j++) {         dp[j] = query(1, 1, m) - qzh[i][j - 1] - qzh[i + 1][j - 1] +                 qzh[i][j + k - 1] + qzh[i + 1][j + k - 1];         if (i != 1)           change(1, max(1, j - k + 1), min(m, j), a[i][j]),               change(1, max(1, j + 1), min(m, j + k), -a[i][j + k]);         ans = max(ans, dp[j]);       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const double eps = 1e-6;   template <class T>   T gcd(T a, T b) {     if (!b) return a;     return gcd(b, a % b);   }   const int maxn = 1e6 + 10;   int n, m;   int phi[maxn];   int a[maxn];   int get(int x) {     int res = x;     for (long long i = 2; i * i <= x; i++) {       if (x % i == 0) {         res = res / i * (i - 1);         while (x % i == 0) x /= i;       }     }     if (x > 1) res = res / x * (x - 1);     return res;   }   int qpow(int b, int n, int mod) {     int res = 1;     while (n) {       if (n & 1) res = 1LL * res * b >= mod ? 1LL * res * b % mod + mod : res * b;       b = 1LL * b * b >= mod ? 1LL * b * b % mod + mod : b * b;       n >>= 1;     }     return res;   }   int solve(int l, int r, int k) {     if (phi[k] == 1) return 1;     if (l == r) {       if (a[l] < phi[k])         return a[l];       else         return a[l] % phi[k] + phi[k];     } else       return qpow(a[l], solve(l + 1, r, k + 1), phi[k]);   }   int main() {     scanf( %d , &n);     scanf( %d , &phi[0]);     while (phi[m] != 1) {       phi[m + 1] = get(phi[m]);       m++;     }     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     int q;     scanf( %d , &q);     for (int i = 0; i < q; i++) {       int l, r;       scanf( %d , &l);       scanf( %d , &r);       int ans = solve(l, r, 0) % phi[0];       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long M = 1000000007;   long long bigMod(long long n, long long power, long long mod = M) {     if (power == 0) return 1;     if (power == 1)       return n % mod;     else if (power % 2 == 0) {       long long v = bigMod(n, power / 2, mod);       return ((v % mod) * (v % mod)) % mod;     } else {       long long v = bigMod(n, power - 1, mod) % mod;       return ((v % mod) * (n % mod)) % mod;     }   }   int main() {     long long n;     scanf( %lld , &n);     long long number = bigMod(2, n);     cout << ((number * (number + 1)) / 2) % M << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3005;   int n, a[N];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d , a + i);     }     int ans = 0;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < i; ++j) {         if (a[j] > a[i]) {           ++ans;         }       }     }     printf( %.12f n , (double)(ans / 2 * 4 + ans % 2));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, K;   int pover[64000];   int ipover[64000];   int dt[503][503];   int lsum[2][503][503];   const int mod = 1000000007;   int main() {     scanf( %d%d , &n, &K);     int maxval = 0;     pover[0] = 1;     for (int i = 1; i < 64000; i++) {       pover[i] = (pover[i - 1] * (long long)2) % mod;     }     ipover[0] = 1;     for (int i = 1; i < 64000; i++) {       ipover[i] = (ipover[i - 1] * (long long)500000004) % mod;     }     for (int j = 0; j <= 0; j++) {       dt[0][j] = 1;     }     for (int k = 0; k <= n; k++) {       long long ksum = 0;       for (int j = 0; j < k; j++) {         long long mul = pover[(k - j) * (n - k + 1)];         ksum = (ksum + dt[0][j] * mul) % mod;         lsum[1][j][k] = ksum;       }     }     for (int i = 1; i <= K; i++) {       int ci = i % 2;       for (int j = 1; j <= n; j++) {         for (int k = 1; k <= j; k++) {           long long baseCnt = lsum[ci][k - 1][j];           long long tot = baseCnt * ipover[j - k + 1] % mod;           dt[i][j] = (dt[i][j] + tot) % mod;         }       }       int ni = 1 - i % 2;       memset(lsum[ni], 0, sizeof(lsum[0]));       for (int k = 0; k <= n; k++) {         long long ksum = 0;         for (int j = 0; j < k; j++) {           long long mul = pover[(k - j) * (n - k + 1)];           ksum = (ksum + dt[i][j] * mul) % mod;           lsum[ni][j][k] = ksum;         }       }     }     long long ans = 0;     for (int i = 0; i <= n; i++) {       ans += dt[K][i];       ans %= mod;     }     ans %= mod;     printf( %d n , (int)ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int d[1005], s[1005], sufmax[1005], mxpos[1005], pred[1005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, k;     cin >> n >> k;     ++n;     for (int i = 1; i < n; ++i) cin >> d[i];     for (int i = 1; i < n; ++i) cin >> s[i];     for (int i = n - 1; i >= 1; --i) {       if (s[i] > sufmax[i + 1]) {         mxpos[i] = i;         sufmax[i] = s[i];       } else {         mxpos[i] = mxpos[i + 1];         sufmax[i] = sufmax[i + 1];       }     }     for (int i = 1; i < n; ++i) pred[i] = pred[i - 1] + d[i];     int tott = 0, oil = s[1];     for (int i = 1; i < n;) {       int j = i;       do {         oil -= d[j];         ++j;         while (oil < 0) tott += k, oil += s[i];         oil += s[j];       } while (s[j] < s[i] && j < n);       i = j;     }     cout << tott + pred[n - 1] << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 10, B = 1e6 + 3;   int n, m, p1[N][2], p2[N][2], x, y;   long long ans = 1;   int main() {     scanf( %d%d n , &n, &m);     char a[n + 3][m + 3];     for (int i = 0; i < n; ++i) gets(a[i]);     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j)         if (a[i][j] !=  . ) {           x = (a[i][j] <  2 ) || (a[i][j] >  3 );           y = i % 2;           p1[j][x ^ y] = 1;           x = a[i][j] <  3 ;           y = j % 2;           p2[i][x ^ y] = 1;         }     }     for (int i = 0; i < m; ++i) ans = (ans * (2 - p1[i][0] - p1[i][1])) % B;     for (int i = 0; i < n; ++i) ans = (ans * (2 - p2[i][0] - p2[i][1])) % B;     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( O3 )   #pragma GCC target( avx,avx2,sse,sse2,sse3,sse4,popcnt,fma )   #pragma GCC optimize( unroll-loops )   const long long int MAXN = 2e5 + 5;   const long long int mod = 1000000007;   const long long int N = 200005;   void solve() {     map<pair<int, int>, vector<int>> mpX, mpY;     int n, m, k;     cin >> n >> m >> k;     vector<int> xec(n), yec(m);     map<int, int> haveX, haveY;     for (int i = 0; i < n; i++) {       cin >> xec[i], haveX[xec[i]] += 1;     }     for (int i = 0; i < m; i++) {       cin >> yec[i], haveY[yec[i]] += 1;     }     for (int i = 0; i < k; i++) {       int x, y;       cin >> x >> y;       if (haveX[x] && haveY[y]) continue;       if (haveX[x]) {         int idx = lower_bound(yec.begin(), yec.end(), y) - yec.begin();         mpX[{yec[idx - 1], yec[idx]}].push_back(x);       }       if (haveY[y]) {         int idx = lower_bound(xec.begin(), xec.end(), x) - xec.begin();         mpY[{xec[idx - 1], xec[idx]}].push_back(y);       }     }     long long int ans = 0;     for (auto [a, b] : mpX) {       sort(b.begin(), b.end());       map<int, int> mpTemp;       int total = b.size();       for (auto x : b) {         mpTemp[x] += 1;       }       for (auto [c, d] : mpTemp) {         ans += (long long int)d * (long long int)(total - d);       }     }     for (auto [a, b] : mpY) {       sort(b.begin(), b.end());       map<int, int> mpTemp;       int total = b.size();       for (auto y : b) {         mpTemp[y] += 1;       }       for (auto [c, d] : mpTemp) {         ans += (long long int)d * (long long int)(total - d);       }     }     cout << ans / 2ll <<   n ;     return;   }   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, c0, c1, h;       cin >> n >> c0 >> c1 >> h;       string s;       cin >> s;       int o = 0, z = 0;       for (int i = 0; i < n; i++) {         if (s[i] ==  1 )           o++;         else           z++;       }       int ans = 0;       if (c0 < c1) {         if (c0 + h <= c1)           ans = z * c0 + o * (c0 + h);         else           ans = z * c0 + o * c1;       } else {         if (c1 + h <= c0)           ans = c1 * o + z * (c1 + h);         else           ans = c1 * o + c0 * z;       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 500010;   int m, k, n, s, a[maxn], b[maxn], c[maxn], maxx, tong[maxn], ansl, ansr,       vis[maxn];   bool check(int l, int r) {     memcpy(c, tong, sizeof(c));     for (int i = l; i <= r; i++) c[a[i]]--;     for (int i = 1; i <= maxx; i++)       if (c[i] > 0) {         return false;       }     return true;   }   void gen(int l, int r) {     int temp = l - (min(n - 1, (l - 1) / k) * k + 1);     temp += max(0, r - l + 1 - k);     if (temp <= m - n * k) {       printf( %d n , temp);       int num = 0;       for (int i = min(n - 1, (l - 1) / k) * k + 1; i < l; i++) {         printf( %d  , i);         num++;       }       int num2 = 0;       memset(c, 0, sizeof(c));       for (int i = l; i <= r; i++)         if (c[a[i]] + 1 <= tong[a[i]]) {           vis[i] = 1;           c[a[i]]++;           num2++;         }       num2 = r - l + 1 - num2;       num += num2;       for (int i = l; i <= r; i++)         if (!vis[i] && num > temp) {           num--;           vis[i] = 1;         }       for (int i = l; i <= r; i++)         if (!vis[i]) printf( %d  , i);       exit(0);     }   }   void solve(int x) {     memset(c, 0, sizeof(c));     int cur = m;     for (int i = x; i <= m; i++) c[a[i]]++;     for (int i = x - 1; i >= 1; i--) {       c[a[i]]++;       while (cur > i) {         if (c[a[cur]] - 1 >= tong[a[cur]] &&             c[a[cur - 1]] + 1 >= tong[a[cur - 1]]) {           c[a[cur]]--;           cur--;         } else           break;       }       gen(i, cur);     }   }   int main() {     scanf( %d%d%d%d , &m, &k, &n, &s);     for (int i = 1; i <= m; i++) scanf( %d , &a[i]);     for (int i = 1; i <= s; i++) {       scanf( %d , &b[i]);       maxx = max(maxx, b[i]);       tong[b[i]]++;     }     int l = 1, r = m, res = 0;     while (l <= r) {       int mid = (l + r) >> 1;       if (check(mid, m)) {         res = mid;         l = mid + 1;       } else         r = mid - 1;     }     if (res) {       gen(res, m);       solve(res);       puts( -1 );     } else       puts( -1 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2005;   bool can = 1;   char arr[N][N];   int n, m, vis[N][N], dp[N][N];   bool valid(pair<int, int> a) {     return min(a.first, a.second) > -1 && a.first < n && a.second < m &&            arr[a.first][a.second] !=  # ;   }   pair<int, int> get_next(pair<int, int> a) {     if (arr[a.first][a.second] ==  < ) return {a.first, a.second - 1};     if (arr[a.first][a.second] ==  > ) return {a.first, a.second + 1};     if (arr[a.first][a.second] ==  ^ ) return {a.first - 1, a.second};     return {a.first + 1, a.second};   }   void dfs(pair<int, int> u) {     vis[u.first][u.second] = 1;     pair<int, int> c = get_next(u);     if (valid(c)) {       if (vis[c.first][c.second] == 0)         dfs(c);       else if (vis[c.first][c.second] == 1) {         can = 0;         return;       }     }     vis[u.first][u.second] = 2;   }   bool go(pair<int, int> u) {     vis[u.first][u.second] = 1;     pair<int, int> c = get_next(u);     bool ret = 1;     if (valid(c)) {       if (vis[c.first][c.second] == 0)         ret &= go(c);       else         ret = 0;     }     return ret;   }   int solve(pair<int, int> u) {     if (!valid(u)) return 0;     if (~dp[u.first][u.second]) return dp[u.first][u.second];     pair<int, int> c = get_next(u);     return dp[u.first][u.second] = solve(c) + 1;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     memset(dp, -1, sizeof(dp));     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) cin >> arr[i][j];     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j)         if (!vis[i][j] && valid({i, j})) dfs({i, j});     if (can) {       vector<pair<int, pair<int, int>>> v;       for (int i = 0; i < n; ++i)         for (int j = 0; j < m; ++j) v.push_back({solve({i, j}), {i, j}});       sort(v.rbegin(), v.rend());       if (v.size() == 1 || v[0].first == 0)         cout << v[0].first;       else {         int ans1 = v[0].first, ans2 = v[0].first - 1;         memset(vis, 0, sizeof(vis));         go(v[0].second);         for (int i = 1; i < v.size(); ++i) {           if (v[i].first < v[i - 1].first) break;           if (go(v[i].second)) {             ans2 = ans1;             break;           }         }         cout << ans1 + ans2;       }     } else       cout << -1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1.01e9;   const double eps = 1e-9;   const int N = 1e5 + 10;   int t[N];   int mem[N];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; (i) < (n); ++i) scanf( %d , &t[i]);     int s = 0;     for (int i = 0; (i) < (n); ++i) {       int v = s + 20;       if (i) {         int l = lower_bound(t, t + i, t[i] - 90 + 1) - t;         v = min(v, mem[l] + 50);       }       if (i) {         int l = lower_bound(t, t + i, t[i] - 1440 + 1) - t;         v = min(v, mem[l] + 120);       }       mem[i + 1] = v;       printf( %d n , v - s);       s = v;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int x, y;     scanf( %d %d , &x, &y);     long long ans = 0;     for (int val = 1; val <= x; ++val) {       ans += (int)floor((y - (5 - (val % 5))) / 5.0) + 1;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double PI = 3.14159265359;   const long long MOD = (long long)1e9 + 7;   const long long MAXN = (long long)1e5 + 10;   const long long INF = (long long)9223372036854775;   const long double EPS = (long double)1e-8;   long long par[MAXN], sz[MAXN], ln[MAXN], pw[MAXN];   pair<pair<long long, long long>, long long> a[MAXN];   long long get_par(long long node) {     if (node == par[node]) return node;     par[node] = get_par(par[node]);     return par[node];   }   void merge(long long a, long long b) {     long long x = get_par(a);     long long y = get_par(b);     if (x == y) return;     ln[y] += ln[x];     sz[y] += sz[x];     par[x] = y;   }   bool CMPx(pair<pair<long long, long long>, long long> a,             pair<pair<long long, long long>, long long> b) {     return a.first.first < b.first.first;   }   bool CMPy(pair<pair<long long, long long>, long long> a,             pair<pair<long long, long long>, long long> b) {     return a.first.second < b.first.second;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     for (int i = 0; i < MAXN; i++) par[i] = i;     pw[0] = 1;     for (int i = 1; i < MAXN; i++) pw[i] = (pw[i - 1] * 2ll) % MOD;     fill(sz, sz + MAXN, 1);     long long n;     scanf( %lld , &n);     for (int i = 0; i < n; i++) {       scanf( %lld%lld , &a[i].first.first, &a[i].first.second);       a[i].second = i;     }     sort(a, a + n, CMPx);     ln[get_par(a[0].second)]++;     for (int i = 1; i < n; i++) {       if (a[i].first.first == a[i - 1].first.first) {         merge(a[i].second, a[i - 1].second);       } else {         ln[get_par(a[i].second)]++;       }     }     sort(a, a + n, CMPy);     ln[get_par(a[0].second)]++;     for (int i = 1; i < n; i++) {       if (a[i].first.second == a[i - 1].first.second) {         merge(a[i].second, a[i - 1].second);       } else {         ln[get_par(a[i].second)]++;       }     }     long long ans = 1;     for (int i = 0; i < n; i++) {       if (par[i] == i) {         if (ln[i] <= sz[i]) {           ans *= pw[ln[i]];         } else {           ans *= (pw[ln[i]] - 1);         }         ans %= MOD;       }     }     printf( %lld , ans);     return 0;   }