malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 15;   const int M = 20;   bool used[N];   vector<int> adj[N];   int a[N], b[N], w[N];   int out[N];   int dsu[N];   int f(int x) { return dsu[x] == x ? x : dsu[x] = f(dsu[x]); }   bool merge(int id) {     int u = f(a[id]), v = f(b[id]);     if (u != v) {       dsu[u] = v;       return true;     }     return false;   }   int anc[N][M], wa[N][M];   int depth[N];   void construct(int node, int par) {     for (int i = 1; i < M; ++i) {       anc[node][i] = anc[anc[node][i - 1]][i - 1];       wa[node][i] = max(wa[node][i - 1], wa[anc[node][i - 1]][i - 1]);     }     for (int eid : adj[node]) {       int ch = a[eid] ^ b[eid] ^ node;       if (ch != par) {         depth[ch] = depth[node] + 1;         anc[ch][0] = node;         wa[ch][0] = w[eid];         construct(ch, node);       }     }   }   pair<int, int> getAnc(int x, int y) {     if (depth[x] < depth[y]) swap(x, y);     int diff = depth[x] - depth[y], ret = 0;     for (int i = 0; i < M; ++i) {       if (diff & (1 << i)) {         ret = max(ret, wa[x][i]);         x = anc[x][i];       }     }     if (x != y) {       for (int i = M - 1; i >= 0; --i) {         if (anc[x][i] != anc[y][i]) {           ret = max(ret, max(wa[x][i], wa[y][i]));           x = anc[x][i];           y = anc[y][i];         }       }       ret = max(ret, max(wa[x][0], wa[y][0]));       x = anc[x][0];     }     return {ret, x};   }   multiset<int> g[N];   vector<int> ed[N];   void dfs(int node, int par) {     for (int eid : adj[node]) {       int ch = a[eid] ^ b[eid] ^ node;       if (ch != par) {         dfs(ch, node);         out[eid] = g[ch].size() == 0 ? -1 : (*g[ch].begin()) - 1;         if (g[node].size() < g[ch].size()) {           swap(g[node], g[ch]);         }         for (int x : g[ch]) g[node].insert(x);       }     }     for (int val : ed[node]) {       assert(g[node].find(val) != g[node].end());       g[node].erase(g[node].find(val));       assert(g[node].find(val) != g[node].end());       g[node].erase(g[node].find(val));     }   }   void solve2() {     int n, m;     scanf( %d %d , &n, &m);     vector<pair<int, int> > edges;     for (int i = 0; i < m; ++i) {       scanf( %d %d %d  , &a[i], &b[i], &w[i]);       edges.push_back({w[i], i});     }     for (int i = n; i; --i) dsu[i] = i;     sort(edges.begin(), edges.end());     for (int i = 0; i < m; ++i) {       int id = edges[i].second;       if (merge(id)) {         used[id] = true;         adj[a[id]].push_back(id);         adj[b[id]].push_back(id);       }     }     construct(1, 0);     for (int i = 0; i < m; ++i) {       if (!used[i]) {         pair<int, int> tmp = getAnc(a[i], b[i]);         out[i] = tmp.first - 1;         g[a[i]].insert(w[i]);         g[b[i]].insert(w[i]);         ed[tmp.second].push_back(w[i]);       }     }     dfs(1, 0);     for (int i = 0; i < m; ++i) {       printf( %d n , out[i]);     }   }   void solve() { solve2(); }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   int n, p[1002];   long long f[1002][2];   int main() {     int i;     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d , &p[i]);     f[1][1] = 0;     f[1][0] = 1;     for (i = 2; i <= n + 1; i++) {       f[i][1] = (f[i - 1][0] + 1) % MOD;       f[i][0] = (f[i][1] + f[i][1] - f[p[i]][1] + MOD + 1) % MOD;     }     printf( %d n , f[n + 1][1]);     return 0;   }
#include<bits/stdc++.h>   using namespace std;   typedef long long int ll;   #define MAX 2000000000   vector<ll> feaseable;   void setfun(){       for(ll i = 3; i<MAX; i+=2){           ll sq = i * i;           if(sq>MAX){               break;           }           ll c = (sq + 1)/2;           feaseable.push_back(c);       }   }      int main(){       int t;       cin>>t;       setfun();       while(t--){           int n;           cin>>n;           auto x = upper_bound(feaseable.begin(),feaseable.end(),n);           int ans = x - feaseable.begin();           cout<<ans<<endl;       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long n, k, a;     cin >> n >> k >> a;     long n_moves;     cin >> n_moves;     set<pair<long, long> > s;     s.insert(make_pair(n, 1));     long max_ships = (n + 1) / (a + 1);     for (int i = 1; i <= n_moves; i++) {       long x;       cin >> x;       set<pair<long, long> >::iterator it = s.lower_bound(make_pair(x, -1));       long l = it->second;       long r = it->first;       max_ships -= (r - l + 2) / (a + 1);       if ((x - 1) >= l) {         max_ships += ((x - 1) - l + 2) / (a + 1);       }       if ((x + 1) <= r) {         max_ships += (r - (x + 1) + 2) / (a + 1);       }       if (max_ships < k) {         cout << i;         return 0;       }       s.erase(it);       if ((x - 1) >= l) s.insert(make_pair(x - 1, l));       if ((x + 1) <= r) s.insert(make_pair(r, x + 1));     }     cout <<  -1 ;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   #pragma GCC optimization( unroll-loops )   using namespace std;   int parent[150000];   int size[150000];   long long int edges[150000];   struct dsu {     void init(int n) {       for (int i = 0; i < n; ++i) {         parent[i] = i;         size[i] = 1;         edges[i] = 0;       }     }     int p(int x) {       if (parent[x] == x) return x;       return parent[x] = p(parent[x]);     }     void unite(int x, int y) {       int supx = p(x);       int supy = p(y);       if (supx != supy) {         if (size[supx] > size[supy]) {           parent[supy] = supx;           size[supx] += size[supy];           edges[supx] += edges[supy] + 1;         } else {           parent[supx] = supy;           size[supy] += size[supx];           edges[supy] += edges[supx] + 1;         }       } else {         edges[supx]++;       }     }   };   int n, m, x, y;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     cin >> n >> m;     dsu d;     d.init(n);     for (int i = 0; i < m; ++i) {       cin >> x >> y;       x--;       y--;       d.unite(x, y);     }     for (int i = 0; i < n; ++i) {       if (parent[i] == i) {         long long int ed = edges[i];         long long int vertices = size[i];         if (ed != (vertices * (vertices - 1)) / 2) {           cout <<  NO ;           return 0;         }       }     }     cout <<  YES ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100 + 10;   char s[maxn][maxn];   int main() {     int a, b;     for (int i = 0; i < 11; i++) gets(s[i]);     scanf( %d%d , &a, &b);     int r = (a - 1) % 3, c = (b - 1) % 3;     int flag = 0;     for (int i = r * 3 + r; i < (r + 1) * 3 + r; i++) {       for (int j = c * 3 + c; j < (c + 1) * 3 + c; j++) {         if (s[i][j] ==  . ) {           flag = 1;           break;         }       }     }     if (flag) {       for (int i = r * 3 + r; i < (r + 1) * 3 + r; i++) {         for (int j = c * 4; j < c * 4 + 3; j++) {           if (s[i][j] ==  . ) s[i][j] =  ! ;         }       }       for (int i = 0; i < 11; i++) printf( %s n , s[i]);     } else {       for (int i = 0; i < 11; i++) {         for (int j = 0; j < 11; j++)           if (s[i][j] ==  . ) s[i][j] =  ! ;       }       for (int i = 0; i < 11; i++) printf( %s n , s[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     char arr[100][100];     int m, n, k = 0;     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     if (m == 1 || n == 1) {       cout << 0;       return 0;     }     for (int i = 0; i < n - 1; i++) {       for (int j = 0; j < m - 1; j++) {         if ( f  != arr[i][j] &&  f  != arr[i + 1][j] &&  f  != arr[i][j + 1] &&              f  != arr[i + 1][j + 1])           continue;         if ( a  != arr[i][j] &&  a  != arr[i + 1][j] &&  a  != arr[i][j + 1] &&              a  != arr[i + 1][j + 1])           continue;         if ( c  != arr[i][j] &&  c  != arr[i + 1][j] &&  c  != arr[i][j + 1] &&              c  != arr[i + 1][j + 1])           continue;         if ( e  != arr[i][j] &&  e  != arr[i + 1][j] &&  e  != arr[i][j + 1] &&              e  != arr[i + 1][j + 1])           continue;         k++;       }     }     cout << k;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int m, n, count = 0, count1 = 0, x = 0;     cin >> m >> n;     int a[m][n], b[m][n];     for (int i = 0; i < m; i++) {       for (int j = 0; j < n; j++) {         cin >> b[i][j];         a[i][j] = 1;       }     }     for (int i = 0; i < m; i++) {       for (int j = 0; j < n; j++) {         if (b[i][j] == 0) {           for (int k = 0; k < n; k++) {             if (a[i][k] == 1) {               a[i][k] = 0;               count++;               if (count == n * m) break;             }           }           for (int k = 0; k < m; k++) {             if (a[k][j] == 1) {               a[k][j] = 0;               count++;               if (count == n * m) break;             }           }         }         if (count == n * m) break;       }       if (count == n * m) break;     }     if (count == n * m) {       for (int i = 0; i < m; i++) {         for (int j = 0; j < n; j++) {           if (b[i][j] == 1) {             cout <<  NO ;             count = 0;             break;           }         }         if (count == 0) break;       }       if (count != 0) {         cout <<  YES  << endl;         for (int i = 0; i < m; i++) {           for (int j = 0; j < n; j++) cout << a[i][j] <<    ;           cout << endl;         }       }     } else {       for (int i = 0; i < m; i++) {         for (int j = 0; j < n; j++) {           x = 0;           if (b[i][j] == 1) {             for (int k = 0; k < m; k++) x = x || a[k][j];             for (int k = 0; k < n; k++) x = x || a[i][k];             if (x != 1) {               cout <<  NO ;               count1++;               break;             }           }         }         if (count1 > 0) break;       }       if (count1 == 0) {         cout <<  YES  << endl;         for (int i = 0; i < m; i++) {           for (int j = 0; j < n; j++) {             cout << a[i][j] <<    ;           }           cout << endl;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   long long int getLength(long long int x) {     long long int c = 0;     while (x > 0) {       c++;       x /= 10;     }     return c;   }   int main() {     long long int n, k, i, j;     cin >> n >> k;     long long int a[n], lengths[n];     for (i = 0; i < n; i++) {       cin >> a[i];       lengths[i] = getLength(a[i]);     }     vector<vector<long long int>> v(11);     long long int l, m;     for (i = 0; i < n; i++) {       l = lengths[i];       m = a[i] % k;       v[l].push_back(m);     }     for (i = 0; i <= 10; i++) {       sort(v[i].begin(), v[i].end());     }     long long int ans = 0, avail, req;     for (i = 0; i < n; i++) {       for (j = 1; j <= 10; j++) {         avail = (a[i] % k * ((long long int)(pow(10, j)) % k)) % k;         req = (k - avail) % k;         auto l = lower_bound(v[j].begin(), v[j].end(), req);         auto r = upper_bound(v[j].begin(), v[j].end(), req);         ans += (r - l);         if (lengths[i] == j && (avail + a[i] % k) % k == 0) --ans;       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long int eet(long long int a, long long int b, long long int *x,                     long long int *y) {     if (a == 0) {       *x = 0;       *y = 1;       return b;     }     long long int x1, y1;     long long int gcd = eet(b % a, a, &x1, &y1);     *x = y1 - (b / a) * x1;     *y = x1;     return gcd;   }   int main() {     long long int n, m, i, j, k, cnt = 0, sum = 0, mn = INT_MAX, ind,                                  rem = 1000000007, ok = 0, size, lcm,                                  mx = INT_MIN, diff, num, x, y, z, ee;     int flag = 0, t = 1;     string s, str, s1, s2, s3;     char ch;     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     while (t--) {       long long int a, b, c;       cin >> a >> b >> c;       c = -c;       long long int GCD = eet(a, b, &x, &y);       if (c % GCD != 0) {         cout << -1;         return 0;       }       long long int mul = c / GCD;       cout << x * mul <<     << y * mul;       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   long long ans;   vector<long long> all, aa, bb;   int main() {     aa.clear();     bb.clear();     all.clear();     long long a, b;     cin >> a >> b;     ans = 2 * (a + b + 1);     for (long long i = 1; i * i <= (a + b); i++)       if ((a + b) % i == 0) all.push_back(i);     for (long long i = 1; i * i <= a; i++)       if (a % i == 0) aa.push_back(i);     for (long long i = 1; i * i <= b; i++)       if (b % i == 0) bb.push_back(i);     int now1 = 0, now2 = 0;     while (now1 < aa.size() && now2 < all.size()) {       if (aa[now1] <= all[now2] && (a / aa[now1]) <= (a + b) / (all[now2])) {         ans = min(ans, 2 * (all[now2] + (a + b) / all[now2]));         now2++;       } else if (aa[now1] > all[now2])         now2++;       else         now1++;     }     now1 = 0, now2 = 0;     while (now1 < bb.size() && now2 < all.size()) {       if (bb[now1] <= all[now2] && (b / bb[now1]) <= (a + b) / (all[now2])) {         ans = min(ans, 2 * (all[now2] + (a + b) / all[now2]));         now2++;       } else if (bb[now1] > all[now2])         now2++;       else         now1++;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, d;   int v[50 + 5];   bool F[5000000 + 5];   int main() {     scanf( %d%d , &n, &d);     for (int i = 1; i <= n; i++) scanf( %d , &v[i]);     F[0] = true;     int sum = 0;     for (int i = 1; i <= n; i++) {       sum += v[i];       for (int j = sum; j >= v[i]; j--) F[j] |= F[j - v[i]];     }     int ans = 0, day = 0;     bool found = false;     while (1) {       for (int i = d; i >= 1; i--) {         if (F[ans + i]) {           ans += i;           day++;           found = true;           break;         }       }       if (!found)         break;       else         found = false;     }     printf( %d %d n , ans, day);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string c1, c2;   int main() {     int x;     cin >> c1 >> c2;     for (int i = 0; i < c1.size(); i++) {       if (c1[i] < 92) {         c1[i] += 32;       }       if (c2[i] < 92) {         c2[i] += 32;       }     }     if (c1 < c2) {       x = -1;     } else if (c1 > c2) {       x = 1;     } else {       x = 0;     }     printf( %d n , x);     return 0;   }
#include <bits/stdc++.h>   const int MAXN = 10010100;   const int MAZN = 301010;   int ch[MAXN][3];   int n, cnt, cout[MAXN];   int arr[MAZN];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &arr[i]);     }     for (int i = 1; i <= n; i++) {       int tem, p = 0;       scanf( %d , &tem);       for (int k = 29; k >= 0; k--) {         int tmp = (tem >> k) & 1;         if (ch[p][tmp])           p = ch[p][tmp];         else           p = ch[p][tmp] = ++cnt;         cout[p]++;       }     }     for (int i = 1; i <= n; i++) {       int x = arr[i];       int ans = 0, p = 0;       for (int j = 29; j >= 0; j--) {         int tmp = (x >> j) & 1;         if (ch[p][tmp] && cout[ch[p][tmp]]) {           p = ch[p][tmp];         } else {           p = ch[p][!tmp];           ans += (1 << j);         }         cout[p]--;       }       printf( %d  , ans);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, ans = 0;     string s;     cin >> n;     while (cin >> s) {       int cnt = 0;       for (int i = 0; i < s.length(); ++i) {         if (s[i] >=  A  && s[i] <=  Z ) {           ++cnt;         }       }       ans = max(ans, cnt);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gi() {     char cc = getchar();     int cn = 0, flus = 1;     while (cc <  0  || cc >  9 ) {       if (cc ==  - ) flus = -flus;       cc = getchar();     }     while (cc >=  0  && cc <=  9 ) cn = cn * 10 + cc -  0 , cc = getchar();     return cn * flus;   }   const int N = 1e5 + 5;   int n, m, q, L[N];   struct SegmentBeats {     int bef, mx, se, tot, tag;   } tr[N << 2];   void cmax(int &x, int y) { x = (x < y) ? y : x; }   inline void pushup(int x) {     tr[x].tot = tr[x].se = 0,     tr[x].mx = max(tr[(x << 1)].mx, tr[(x << 1 | 1)].mx);     if (tr[x].mx == tr[(x << 1)].mx)       tr[x].tot += tr[(x << 1)].tot, cmax(tr[x].se, tr[(x << 1)].se);     else       cmax(tr[x].se, tr[(x << 1)].mx);     if (tr[x].mx == tr[(x << 1 | 1)].mx)       tr[x].tot += tr[(x << 1 | 1)].tot, cmax(tr[x].se, tr[(x << 1 | 1)].se);     else       cmax(tr[x].se, tr[(x << 1 | 1)].mx);     tr[x].bef = tr[x].mx;   }   inline void push(int x, int k) { tr[x].mx = k, tr[x].tag = k; }   inline void pushmark(int x) {     if (!tr[x].tag) return;     if (tr[(x << 1)].mx == tr[x].bef) push((x << 1), tr[x].tag);     if (tr[(x << 1 | 1)].mx == tr[x].bef) push((x << 1 | 1), tr[x].tag);     tr[x].tag = 0, tr[x].bef = tr[x].mx;   }   int query(int x, int l, int r, int k) {     if (l == r) return tr[x].mx;     int mid = (l + r) >> 1;     pushmark(x);     if (k <= mid)       return query((x << 1), l, mid, k);     else       return query((x << 1 | 1), mid + 1, r, k);   }   void update(int x, int l, int r, int k, int d) {     if (l == r) return tr[x].mx = d, tr[x].se = 0, tr[x].tot = 1, void();     int mid = (l + r) >> 1;     pushmark(x);     if (k <= mid)       update((x << 1), l, mid, k, d);     else       update((x << 1 | 1), mid + 1, r, k, d);     pushup(x);   }   void modify(int x, int l, int r, int ql, int qr, int y, int z) {     if (tr[x].mx < y || r < ql || qr < l) return;     if ((ql <= l && r <= qr) && (tr[x].se < y && tr[x].mx >= y))       return push(x, z);     int mid = (l + r) >> 1;     pushmark(x);     modify((x << 1), l, mid, ql, qr, y, z),         modify((x << 1 | 1), mid + 1, r, ql, qr, y, z), pushup(x);   }   vector<pair<int, int> > p[N];   int ans[N];   signed main() {     n = gi(), m = gi();     int x, y;     for (int i = (1); i <= (m); ++i) x = gi(), y = gi(), L[y] = x;     q = gi();     for (int i = (1); i <= (q); ++i)       x = gi(), y = gi(), p[y].push_back(make_pair(x, i));     for (int i = (1); i <= (n); ++i) {       update(1, 1, n, i, i);       if (L[i]) modify(1, 1, n, 1, L[i], L[i], i);       for (auto u : p[i]) ans[u.second] = query(1, 1, n, u.first);     }     for (int i = (1); i <= (q); ++i) printf( %d n , ans[i]);     return 0;   }
#include <bits/stdc++.h>   const int N = 3003;   const long long mod = 998244353;   using namespace std;   int n;   int c;   int a[N];   int p[N];   int res[N];   int d[N][N];   int g[N][N];   int f1[N][1 << 12];   void upd(int &x, int y) {     x += y;     if (x >= mod) {       x -= mod;     } else if (x < 0) {       x += mod;     }   }   void solve1() {     int nj, nk, last = (1 << c) - 1;     for (int i = 1; i <= n; i++) {       for (int j = (i - 1) / c; j >= 0; j--) {         for (int k = last - 1; k >= 0; k--) {           nj = j;           nk = k | (1 << a[i]);           if (nk == last) {             nj += 1;             nk = 0;             upd(d[i][nj], f1[j][k]);           }           upd(f1[nj][nk], f1[j][k]);         }       }       if (c == 1) {         upd(d[i][1], 1);         upd(f1[1][0], 1);       } else {         upd(f1[0][1 << a[i]], 1);       }     }   }   long long pw(long long x, long long n) {     long long res = 1;     while (n) {       if (n & 1) {         res = res * x % mod;       }       x = x * x % mod;       n /= 2;     }     return res;   }   int t[N];   int inv[N];   void solve2() {     for (int i = 1; i < n; i++) {       inv[i] = pw(p[i] - 1, mod - 2);     }     for (int i = 1; i <= n; i++) {       for (int j = 0; j < c; j++) {         t[j] = 0;       }       int j = i - 1;       int sad = c;       while (j < n && sad) {         j += 1;         t[a[j]] += 1;         sad -= t[a[j]] == 1;       }       if (sad) {         break;       }       long long res = 1;       for (int h = 0; h < c; h++) {         res = res * (p[t[h]] - 1) % mod;       }       sad = 1;       for (; j <= n; j++) {         res = res * inv[t[a[j]]] % mod;         g[i][j] = res;         if (sad) {           sad = 0;         } else {           t[a[j]] += 1;         }         res = res * (p[t[a[j]]] - 1) % mod;       }     }     d[0][0] = 1;     int k = n / c;     d[0][0] = 1;     long long sum, MOD = mod, MOD2 = mod * mod;     for (int r = 1; r <= k; r++) {       d[0][r] = 0;       for (int i = r * c - 1; i < n; i++) {         sum = 0;         for (int j = i; j >= (r - 1) * c; j--) {           sum += 1LL * g[j + 1][i + 1] * d[j][r - 1];           if (sum >= MOD2) sum -= MOD2;         }         d[i + 1][r] = (sum % MOD);       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> c;     for (int i = 1; i <= n; i++) {       cin >> a[i];       a[i] -= 1;     }     p[0] = 1;     for (int i = 1; i <= n; i++) {       p[i] = p[i - 1];       upd(p[i], p[i]);     }     if (c <= 10) {       solve1();     } else {       solve2();     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         upd(res[j], 1ll * d[i][j] * p[n - i] % mod);       }     }     res[0] = p[n];     upd(res[0], -1);     for (int i = 0; i <= n; i++) {       upd(res[i], -res[i + 1]);       cout << res[i] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100 + 10;   const long long inf = 0x3f3f3f3f3f3f3f3f;   string s;   int a[maxn];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int flag = 0;       int n;       cin >> n;       for (int i = 0; i < n; i++) cin >> a[i];       sort(a, a + n);       for (int i = 1; i < n; i++) {         if (a[i] - a[i - 1] == 1) {           flag = 1;           break;         }       }       if (flag)         cout << 2 << endl;       else         cout << 1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const int MOD = 1000000007;   void solve() {     int n;     cin >> n;     vector<vector<int>> dp(4, vector<int>(n + 1, 0));     dp[3][0] = 1;     for (int i = 1; i < n + 1; i++)       for (int j = 0; j < 4; j++)         for (int k = 0; k < 4; k++)           if (k != j) dp[j][i] = (dp[j][i] + dp[k][i - 1]) % MOD;     cout << dp[3][n] <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long l, r, n, k;   string Bad;   int ask(long long l, long long r) {     cout << l <<     << r << endl;     cout.flush();     cin >> Bad;     if (Bad[0] ==  B ) exit(0);     if (Bad[0] ==  Y ) {       if (l == r) exit(0);       return 1;     }     return 0;   }   int main() {     srand(2109888);     cin >> n >> k;     l = 1;     r = n;     while (l <= r) {       long long mid = (l + r) >> 1;       if (ask(l, mid))         r = mid;       else         l = mid + 1;       l = max(1ll, l - k);       r = min(n, r + k);       mid = l + rand() % (r - l + 1);       ask(mid, mid);       l = max(1ll, l - k);       r = min(n, r + k);     }     return 0;   }