malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 110000;   char a[N];   int chk[N];   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     cin >> a;     if (n == 1) {       cout <<  Yes  << endl;       return 0;     }     for (int i = 0; i < n; i++) chk[a[i]]++;     bool flg = 1;     for (int i = 0; i < 256; i++) {       if (chk[i] != 1 && chk[i] != 0) flg = 0;     }     if (flg)       cout <<  No  << endl;     else       cout <<  Yes  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 9;   int n, v[MAX];   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n;     for (int i = 0, x; i < n; i++) cin >> x, v[x % n] = i;     for (int i = 0, x; i < n; i++) cin >> x, cout << v[x % n] + 1 <<    ;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 1000000000 + 7;   const int N = 200000 + 10;   const int NUMHASH = 3;   const long long hashNum[3] = {M, M + 2, M + 14};   struct re {     int x, y;   };   int n, q;   string s;   int cnt[26][N], f[26][N], g[26][N];   long long h[NUMHASH][26][N], p[NUMHASH][N];   int countLetter(int x, int y, int c) { return cnt[c][x] - cnt[c][y + 1]; }   int getHash(int x, int l, int c, int k) {     return (h[k][c][x + l - 1] - (h[k][c][x - 1] * p[k][l] % hashNum[k]) +             hashNum[k]) %            hashNum[k];   }   bool equalHash(int x, int i, int y, int j, int l) {     for (int k = (0); (k <= (NUMHASH - 1)); ++k) {       if (getHash(x, l, i, k) != getHash(y, l, j, k)) return false;     }     return true;   }   bool iso(int x, int y, int l) {     for (int i = (0); (i <= (25)); ++i) {       int pos = f[i][x];       if (pos < l) {         int j = s[y - 1 + pos] -  a ;         if (f[j][y] != pos) return false;         if (countLetter(x, x + l - 1, i) != countLetter(y, y + l - 1, j))           return false;         if (!equalHash(x, i, y, j, l)) return false;       }     }     return true;   }   int main() {     cin >> n >> q;     cin >> s;     for (int i = (n); (i >= (1)); --i) {       for (int j = (0); (j <= (25)); ++j)         cnt[j][i] = cnt[j][i + 1], f[j][i] = f[j][i + 1] + 1;       int j = s[i - 1] -  a ;       cnt[j][i] = cnt[j][i + 1] + 1;       f[j][i] = 0;       g[j][i] = 1;     }     for (int k = (0); (k <= (NUMHASH - 1)); ++k) {       p[k][0] = 1;       for (int i = (1); (i <= (n)); ++i) p[k][i] = (p[k][i - 1] * 2) % hashNum[k];       for (int j = (0); (j <= (25)); ++j) {         for (int i = (1); (i <= (n)); ++i)           h[k][j][i] = (h[k][j][i - 1] * 2 + g[j][i]) % hashNum[k];       }     }     while (q--) {       int x, y, len;       cin >> x >> y >> len;       if (iso(x, y, len))         cout <<  YES ;       else         cout <<  NO ;       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, ans = -1;     cin >> n;     pair<int, int> g[n];     for (i = 0; i < n; i++) {       cin >> g[i].first >> g[i].second;     }     sort(g, g + n);     for (i = 0; i < n; i++) {       if (ans <= g[i].second)         ans = g[i].second;       else         ans = g[i].first;     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int main(void) {     int n, k;     cin >> n >> k;     int r[257] = {};     for (int i = 0; i < 257; i++) {       r[i] = -1;     }     int p;     for (int i = 0; i < n; i++) {       cin >> p;       if (r[p] == -1) {         for (int j = (p - k + 1 >= 0) ? p - k + 1 : 0; j <= p; j++) {           if (r[j] == -1) {             for (int x = j; x <= p; x++) {               if (r[x] != -1) break;               r[x] = j;             }             break;           } else if (r[j + 1] == -1) {             if (r[j] + k - 1 >= p) {               for (int x = j + 1; x <= p; x++) {                 r[x] = r[j];               }               break;             }           }         }       }       cout << r[p] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> p[300100];   int per[300300];   long long sz[300300];   long long mx[300300];   int res[300300];   long long dfs(int x) {     sz[x]++;     for (int i = 0; i < p[x].size(); i++) {       long long t = dfs(p[x][i]);       sz[x] += t;       mx[x] = max(mx[x], t);     }     return sz[x];   }   bool ch(int x, int y) {     if (mx[y] * 2 > sz[x]) return 0;     if ((sz[x] - sz[y]) * 2 > sz[x]) return 0;     return 1;   }   void f(int x) {     int st = x, maxx = 0;     if (ch(x, x)) res[x] = x;     for (int i = 0; i < p[x].size(); i++) {       f(p[x][i]);       if (maxx < sz[p[x][i]]) {         maxx = sz[p[x][i]];         st = res[p[x][i]];       }     }     while (1) {       if (ch(x, st)) {         res[x] = st;         break;       }       st = per[st];     }   }   int main() {     int n, q, z;     cin >> n >> q;     for (int i = 2; i <= n; i++) {       scanf( %d , &z);       per[i] = z;       p[z].push_back(i);     }     dfs(1);     f(1);     for (int i = 0; i < q; i++) {       scanf( %d , &z);       printf( %d n , res[z]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1234567;   int a[N], gcd[N], is_max[N], cnt[N];   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> a[i];       a[i + n] = a[i];     }     for (int i = 1; i <= n; ++i) {       if (n % i == 0) {         for (int j = i; j <= n; j += i) {           gcd[j] = i;         }       }     }     long long ans = 0ll;     for (int i = 1; i <= n; ++i) {       if (n % i == 0) {         for (int j = 0; j < i; ++j) {           int m = 0;           for (int q = j; q < n; q += i) {             m = max(m, a[q]);           }           for (int q = j; q < n * 2; q += i) {             is_max[q] = a[q] == m;           }         }         for (int j = 1; j < n * 2; ++j) {           if (is_max[j]) {             is_max[j] += is_max[j - 1];           }         }         cnt[0] = 0;         for (int j = 1; j < n; ++j) {           cnt[j] = cnt[j - 1] + (gcd[j] == i);         }         for (int j = n; j < n * 2; ++j) {           ans += cnt[min(is_max[j], n - 1)];         }       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, i, j, ans = 0, f[30][30], h, t, l;   char st[20];   int main() {     scanf( %d n , &n);     memset(f, 0, sizeof(f));     while (n--) {       gets(st);       l = strlen(st);       h = (int)st[0] - 97;       t = (int)st[l - 1] - 97;       for (i = 0; i < 26; i++)         if (f[i][h] && (f[i][t] < f[i][h] + l)) {           f[i][t] = f[i][h] + l;           if (t == i && ans < f[i][t]) ans = f[i][t];         }       if (f[h][t] < l) {         f[h][t] = l;         if (t == h) ans = max(ans, l);       }     }     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 10, mod = 1e9 + 7;   long long n, dp[2][N], d[2][N], t[2][N];   vector<long long> ch[N];   void dfs(long long v) {     if (!ch[v].size()) {       dp[0][v] = 0;       dp[1][v] = 1;       return;     }     for (long long i : ch[v]) dfs(i);     d[0][0] = 1;     for (long long i = 1; i <= ch[v].size(); i++) {       long long u = ch[v][i - 1];       d[0][i] = ((dp[0][u] + 1) * d[0][i - 1] + dp[1][u] * d[1][i - 1]) % mod;       d[1][i] = ((dp[0][u] + 1) * d[1][i - 1] + dp[1][u] * d[0][i - 1]) % mod;     }     dp[0][v] = (2 * d[0][ch[v].size()]) % mod;     dp[1][v] = (2 * d[1][ch[v].size()]) % mod;     long long bad = dp[0][ch[v][0]] + 1;     for (long long i = 1; i < ch[v].size(); i++)       bad = (bad * (dp[0][ch[v][i]] + 1)) % mod;     dp[0][v] = (dp[0][v] - bad) % mod;     t[0][0] = 1;     t[1][0] = dp[1][ch[v][0]];     for (long long i = 1; i < ch[v].size(); i++) {       t[0][i] = (t[0][i - 1] + t[1][i - 1] * dp[1][ch[v][i]]) % mod;       t[1][i] = (t[1][i - 1] + t[0][i - 1] * dp[1][ch[v][i]]) % mod;     }     dp[1][v] = (dp[1][v] - t[1][(long long)ch[v].size() - 1]) % mod;     swap(dp[0][v], dp[1][v]);   }   int32_t main() {     cin >> n;     for (long long i = 1; i < n; i++) {       long long p;       cin >> p;       p--;       ch[p].push_back(i);     }     dfs(0);     cout << (((dp[0][0] + dp[1][0]) % mod) + mod) % mod;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int N = 1e6 + 10;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3f;   inline int read() {     static char buf[1000000], *p1 = buf, *p2 = buf;     register int x = false;     register char ch =         p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)             ? EOF             : *p1++;     ;     register bool sgn = false;     while (ch !=  -  && (ch <  0  || ch >  9 ))       ch = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)                ? EOF                : *p1++;     ;     if (ch ==  - )       sgn = true,       ch = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)                ? EOF                : *p1++;     ;     while (ch >=  0  && ch <=  9 )       x = (x << 1) + (x << 3) + (ch ^ 48),       ch = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)                ? EOF                : *p1++;     ;     return sgn ? -x : x;   }   long long fpow(long long a, int b, int mod) {     long long res = 1;     for (; b > 0; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   long long d[N];   long long cnt[26];   long long fac[N];   char s[N];   int len;   long long num[N];   long long calc(int x) {     long long tot = 0;     for (int i = 0; i < x; i++) tot += cnt[i];     return tot;   }   long long dfs(int d) {     if (d == len + 1) return 0;     long long tot = calc(s[d] -  a ) * fac[len - d] % mod;     if (cnt[s[d] -  a ]) {       cnt[s[d] -  a ]--;       long long u = dfs(d + 1);       cnt[s[d] -  a ]++;       tot = (tot + cnt[s[d] -  a ] * u % mod) % mod;     }     return tot;   }   int main() {     fac[0] = 1;     for (long long i = 1; i < N; i++) {       fac[i] = (fac[i - 1] * i) % mod;     }     scanf( %s , s + 1);     len = strlen(s + 1);     for (int i = 1; i <= len; i++) cnt[s[i] -  a ]++;     long long ans = dfs(1);     scanf( %s , s + 1);     ans = (dfs(1) - ans + mod) % mod;     for (int i = 0; i < 26; i++) {       if (cnt[i] >= 1) ans = ans * fpow(fac[cnt[i]], mod - 2, mod) % mod;     }     cout << ans - 1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b;     cin >> a >> b;     int p = 0;     int aa = a;     while (aa > 0) {       p = max(p, aa % 10);       aa = aa / 10;     }     int bb = b;     while (bb > 0) {       p = max(p, bb % 10);       bb = bb / 10;     }     p++;     int carry = 0;     int num = 0;     while (a > 0 or b > 0 or carry > 0) {       carry = ((a % 10) + (b % 10) + carry) / p;       a = a / 10;       b = b / 10;       num++;     }     cout << num << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long k, d, t, cnt = 0;   bool f(double T) {     long long interval = ((long long)ceil(k / (d * 1.0))) * d;     long long no_of_interval = T / interval;     double t_on = no_of_interval * k, t_off = (interval - k) * no_of_interval;     double rem = T - no_of_interval * interval;     if (rem <= (double)k)       t_on += rem;     else {       t_on += k;       t_off += rem - k;     }     return t_on + t_off / 2 >= t;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> k >> d >> t;     double s = t, e = 2 * t, mid;     while (cnt++ <= 10000) {       mid = (s + e) / 2;       if (f(mid))         e = mid;       else         s = mid;     }     cout << setprecision(20) << mid;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t--) {       long long int n, rock = 0, peper = 0, sec = 0, de = 0;       cin >> n;       cin >> rock >> peper >> sec;       string s, ans;       cin >> s;       for (long long int i = 0; i < n; i++) {         if (s[i] ==  R  && peper > 0) {           ans = ans +  P ;           peper--;           de++;           continue;         } else if (s[i] ==  P  && sec > 0) {           sec--;           ans = ans +  S ;           de++;           continue;         } else if (s[i] ==  S  && rock > 0) {           rock--;           ans = ans +  R ;           de++;           continue;         } else {           ans = ans +  1 ;         }       }       for (long long int i = 0; i < n; i++) {         if (ans[i] ==  1 ) {           if (rock > 0) {             ans[i] =  R ;             rock--;           } else if (peper > 0) {             ans[i] =  P ;             peper--;           } else if (sec > 0) {             sec--;             ans[i] =  S ;           }         }       }       if (n % 2 == 0)         n = n / 2;       else         n = (n + 1) / 2;       if (de >= n) {         cout <<  YES               <<   n ;         cout << ans <<   n ;       } else         cout <<  NO               <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   template <class T, class U>   bool cmp_second(const pair<T, U> &a, const pair<T, U> &b) {     return a.second < b.second;   }   pair<int, int> operator+(const pair<int, int> &a, const pair<int, int> &b) {     return make_pair(a.first + b.first, a.second + b.second);   }   pair<int, int> operator-(const pair<int, int> &a, const pair<int, int> &b) {     return make_pair(a.first - b.first, a.second - b.second);   }   pair<int, int> &operator+=(pair<int, int> &a, const pair<int, int> &b) {     a.first += b.first;     a.second += b.second;     return a;   }   pair<int, int> &operator-=(pair<int, int> &a, const pair<int, int> &b) {     a.first -= b.first;     a.second -= b.second;     return a;   }   inline int sg(int x) { return x ? (x > 0 ? 1 : -1) : 0; }   const double pi = acos(-1.0);   int main(void) {     double w, h, a;     scanf( %lf %lf %lf , &w, &h, &a);     if (a > 90.0) a = 180.0 - a;     a = a / 180.0 * pi;     double d = sqrt(w * w + h * h) * 0.5;     double sol;     if ((d * d + d * d - min(w, h) * min(w, h)) / (2 * d * d) <= cos(a)) {       double A = 1 + cos(a);       double B = sin(a);       double x = (A * w - B * h) / (A * A - B * B);       double y = (A * h - B * w) / (A * A - B * B);       sol = w * h - (x * x + y * y) * sin(a) * cos(a);     } else {       double s = min(w, h);       double z = s / sin(a);       sol = z * z * sin(a);     }     printf( %.12lf n , sol);     return 0;   }
#include <bits/stdc++.h>   int fac[100100];   int n, m, i, x, j, l, r, p, ans, st, dr, mn, mx, M;   void init() {     int i, j;     for (i = 2; i <= 100000; i++)       if (!fac[i]) {         fac[i] = i;         if (i > 316) continue;         for (j = i * i; j <= 100000; j += i)           if (!fac[j]) fac[j] = i;       }   }   int solve(int x, int y) {     int v[20];     int N;     int i, j, lim, ind, nr, rez = 0;     if (y == 0) return 0;     v[0] = 0;     N = 0;     for (i = x; i > 1; i /= fac[i])       if (N == 0 || v[N - 1] != fac[i]) v[N++] = fac[i];     lim = 1 << N;     for (i = 0; i < lim; i++) {       ind = 0;       nr = 1;       for (j = 0; j < N; j++)         if (i & (1 << j)) {           ind++;           nr = nr * v[j];         }       int ax = y / nr;       if (ind % 2 == 1)         rez = (long long)((long long)((long long)rez - (long long)(M + 1) * ax +                                       (long long)nr * ax * ((long long)ax + 1) /                                           2) %                               p +                           (long long)p) %               p;       else         rez = (long long)((long long)((long long)rez + (long long)(M + 1) * ax -                                       (long long)nr * ax * ((long long)ax + 1) /                                           2) %                               p +                           (long long)p) %               p;     }     rez = (long long)((long long)rez * ((long long)n - x + 1)) % p;     return ((int)rez);   }   int main() {     scanf( %d%d%d%d%d , &n, &M, &l, &r, &p);     init();     for (x = 1; x <= n; x++) {       for (st = 0, dr = 100001; st < dr;) {         m = (st + dr) / 2;         if ((long long)x * x + (long long)m * m >= (long long)l * l)           dr = m;         else           st = m + 1;       }       mn = st;       for (st = 0, dr = 100001; st < dr;) {         m = (st + dr) / 2 + 1;         if ((long long)x * x + (long long)m * m <= (long long)r * r)           st = m;         else           dr = m - 1;       }       if (mn < 1) mn = 1;       mx = st;       if (mx > M) mx = M;       if (mn > mx) continue;       ans = (long long)((long long)((long long)ans + solve(x, mx) -                                     solve(x, mn - 1)) %                             p +                         p) %             p;     }     ans = (long long)ans * 2 % p;     if (l <= 1)       ans = (long long)((long long)ans + n * ((long long)M + 1) +                         ((long long)n + 1) * M) %             p;     printf( %d , ans);     return 0;   }
#include  bits/stdc++.h       using namespace std;   using ll = long long;   using pii = pair<int,int>;      vector<tuple<int,int,int>> edges;      void add(int x, int y, int z) {     edges.push_back({x,y,z});   }      int solve(int l, int r) {     if (l > 1) {       int k = solve(1,r-l+1);       add(k,k+1,l-1);       return k+1;     }     if ((r&(-r)) == r) // r is a power of 2      {       int k = __builtin_ctz(r); // Count Trailing Zeros       add(1,2,1);       for (int i = 3; i <= k+2; i++) {         add(1,i,1);         for (int j = 2; j < i; j++)           add(j,i,1<<(j-2));       }       return k+2;     }     int k =0;     while(1<<(k+1) <= r-1) k++;     solve(1,1<<k);     add(1,k+3,1);     for (int i = 0; i <= k; i++){       if ((r-1)>>i&1)         add(i+2,k+3,1+((r-1)>>(i+1)<<(i+1)));     }     return k+3;   }      int main()   {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int l,r;     cin >> l >> r;     cout <<  YES n ;     int n = solve(l,r);     cout << n <<     << edges.size() <<   n ;     for (auto [x,y,z] : edges) cout << x <<     << y <<     << z <<   n ;   }      // DAG   // Good if all paths from 1 to n are between L and R   // All possible distances should be represented, once each   //   // How many different distances can I have? n nodes an give 2^n-1 paths. Always   // possible?   //   // Seems like we can do binary magic to solve   //
#include <bits/stdc++.h>   using namespace std;   bitset<501> bt[1010];   int c[505];   int ans[250001], tot;   int main() {     tot = 0;     int n, k;     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %d , &c[i]);     bt[0].set(0);     int maxn = 0;     for (int i = 1; i <= n; i++) {       int lim = maxn;       for (int j = lim; j >= 0; j--) {         if (j + c[i] > k) continue;         bt[j + c[i]] |= bt[j];         bt[j + c[i]] |= bt[j] << c[i];       }       maxn = maxn + c[i];     }     for (int i = 0; i <= 500; i++) {       if (bt[k].test(i)) {         ans[tot++] = i;       }     }     printf( %d n , tot);     for (int i = 0; i < tot; i++) {       printf( %d , ans[i]);       if (i == tot - 1)         printf(  n );       else         printf(   );     }   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1024000000,1024000000 )   using namespace std;   int main() {     int n;     cin >> n;     if (n % 2 == 0) {       cout << (n / 2) - 1 << endl;     } else {       cout << n / 2 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> v;   long long a[200011];   string s;   int main() {     long long n, k, i, x, res = 0, j;     cin >> n >> k;     for (i = 0; i < n; i++) cin >> a[i];     cin >> s;     char C =  A ;     for (i = 0; i < n; i++) {       x = k;       if (s[i] == C) v.push_back(a[i]);       if (s[i] != C || i == n - 1) {         if (i == n - 1 && s[i] != C) res += a[i];         C = s[i];         sort(v.begin(), v.end());         if (v.size()) {           for (j = v.size() - 1; j >= 0; j--) {             if (x > 0) {               res += v[j];               x--;             }           }           v.erase(v.begin(), v.end());         }         v.push_back(a[i]);       }     }     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 13;   int n, m;   int a[maxn];   int main() {     int T;     scanf( %d , &T);     while (T--) {       long long n;       long long x, y;       scanf( %lld , &n);       if (n == 1) {         printf( 1 1 n );         continue;       }       long long p = sqrt(n);       if (p * p != n) p++;       if (p * p - n < p) {         x = p;         y = p * p - n + 1;       } else {         y = p;         x = n - (p - 1) * (p - 1);       }       printf( %lld %lld n , x, y);     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = ((int)2e6) + 5;   int energy[maxn];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, u;     cin >> n >> u;     for (int i = 0; i < n; i++) cin >> energy[i];     int curr = 2;     double eff = -1;     for (int i = 1; i < n - 1; i++) {       int ei = energy[i - 1];       int ej = energy[i];       while (energy[curr] - ei > u) {         curr--;       }       while (curr < n && energy[curr] - ei <= u) {         eff = max(eff, (energy[curr] - ej) / (energy[curr] - ei + 0.0));         curr++;       }       if (curr == n) curr--;     }     if (eff < 1e-7) {       cout << -1;     } else {       cout << fixed << setprecision(9) << eff;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline char gc() { return getchar(); }   template <class T>   int read(T &ans) {     ans = 0;     char ch = gc();     T f = 1;     while (!isdigit(ch)) {       if (ch == EOF) return -1;       if (ch ==  - ) f = -1;       ch = gc();     }     while (isdigit(ch)) ans = ans * 10 + ch -  0 , ch = gc();     ans *= f;     return 1;   }   template <class T1, class T2>   int read(T1 &a, T2 &b) {     return read(a) != EOF && read(b) != EOF ? 2 : EOF;   }   template <class T1, class T2, class T3>   int read(T1 &a, T2 &b, T3 &c) {     return read(a, b) != EOF && read(c) != EOF ? 3 : EOF;   }   const int Maxn = 1100;   const int inf = 0x3f3f3f3f;   int a[Maxn], b[Maxn], c[Maxn], tims;   long long n, L, v;   pair<long long, long long> ans[Maxn];   long long query(long long a, long long b) {     printf( ? %I64d %I64d n , a, b);     fflush(stdout);     long long ans;     read(ans);     return ans;   }   long long find(int x, long long k, long long l, long long r) {     long long mid = l + r >> 1;     while (1) {       long long y = query(x, mid);       if (y == k) return mid;       if (y < k)         l = mid + 1;       else         r = mid - 1;       mid = l + r >> 1;     }   }   void kth(int l, int r, int k, long long ql, long long qr) {     if (l == r) return;     int x = rand() % (r - l + 1) + l;     long long y = find(a[x], (L / n) * k, ql, qr);     int mid = k - l + 1;     int l1 = l - 1, l2 = r + 1, l3 = 0;     c[++l3] = a[x];     for (int i = l; i <= r; i++) {       if (i == x) continue;       long long sxz = query(a[i], y);       if (sxz < (L / n) * k) b[--l2] = a[i];       if (sxz == (L / n) * k) c[++l3] = a[i];       if (sxz > (L / n) * k) b[++l1] = a[i];     }     while (l1 < k && l3) b[++l1] = c[l3--];     if (l1 == k) {       v = y;       while (l3) b[--l2] = c[l3--];       for (int i = l; i <= r; i++) a[i] = b[i];       return;     }     if (l1 < k) {       for (int i = l; i <= r; i++) a[i] = b[i];       kth(l1 + 1, r, k, ql, qr);       return;     }     while (l3) b[--l2] = c[l3--];     for (int i = l; i <= r; i++) a[i] = b[i];     kth(l, l1, k, ql, qr);   }   void solve(int l, int r, long long ql, long long qr) {     if (l == r) {       ans[a[l]] = make_pair(ql, qr);       return;     }     int mid = l + r >> 1;     kth(l, r, mid, ql, qr);     long long x = v;     solve(l, mid, ql, x);     solve(mid + 1, r, x, qr);   }   signed main() {     read(n, L);     for (int i = 1; i <= n; i++) a[i] = i;     solve(1, n, 0, 1000000000000000000ll);     puts( ! );     for (int i = 1; i <= n; i++)       printf( %I64d %I64d n , ans[i].first, ans[i].second);     fflush(stdout);     return 0;   }