malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   inline void print(char pt) { printf( %c n , pt); }   inline void print(int pt) { printf( %d n , pt); }   inline void print(long long pt) { printf( %I64d n , pt); }   inline void print(double pt) { printf( %.20f n , pt); }   inline void print(char pt[]) { printf( %s n , pt); }   inline void print() { printf(  n ); }   inline int scan(int &pt) { return scanf( %d , &pt); }   inline int scan(char &pt) { return scanf( %c , &pt); }   inline int scan(long long &pt) { return scanf( %I64d , &pt); }   inline int scan(double &pt) { return scanf( %lf , &pt); }   inline int scan(char pt[]) { return scanf( %s , pt); }   long long moda = 109098827479487ll;   using namespace std;   int n, k, m;   char stra[1000];   int a[300000];   int c[300000];   int main() {     scan(n);     int maxai = 0;     long long sums = 0;     for (int i = 0; i < n; i++) {       scan(a[i]);       sums += a[i];       c[a[i]]++;       maxai = max(a[i], maxai);     }     int maxn = min(maxai + 1, 200001);     for (int i = 1; i <= maxn; i++) {       c[i] += c[i - 1];     }     sort(a, a + n);     long long suma = 0;     long long maxa = 0;     for (int i = 0; i < n; i++) {       if (suma >= sums - maxa) break;       suma += a[i];       if (i && a[i] == a[i] - 1) {         continue;       }       long long nowa = 0;       for (int j = 1, tj = a[i];; j++, tj += a[i]) {         if (tj + a[i] - 1 >= maxn) {           nowa += 1ll * j * (c[maxn] - c[tj - 1]);           break;         }         nowa += 1ll * j * (c[tj + a[i] - 1] - c[tj - 1]);       }       nowa *= a[i];       maxa = max(maxa, nowa);     }     print(maxa);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int T, n, m;   int x[15];   char s[15][10005];   int v[10005], cnt[25], tmp[25];   int P[10005];   int ans;   void dfs(int p, int sum) {     if (p == n + 1) {       int cur = m, res = sum;       for (int i = 20; i >= 0; i--) {         res += (i - 10) * (cur * 2 - cnt[i] + 1) * cnt[i] / 2;         cur -= cnt[i];       }       tmp[0] = cnt[0];       for (int i = 1; i <= 20; i++) tmp[i] = tmp[i - 1] + cnt[i];       if (ans <= res) {         ans = res;         for (int i = 1; i <= m; i++) {           P[i] = tmp[v[i] + 10]--;         }       }       return;     }     for (int i = 1; i <= m; i++) {       if (s[p][i] ==  1 ) {         cnt[v[i] + 10]--;         v[i]++;         cnt[v[i] + 10]++;       }     }     dfs(p + 1, sum - x[p]);     for (int i = 1; i <= m; i++) {       if (s[p][i] ==  1 ) {         cnt[v[i] + 10]--;         v[i] -= 2;         cnt[v[i] + 10]++;       }     }     dfs(p + 1, sum + x[p]);     for (int i = 1; i <= m; i++) {       if (s[p][i] ==  1 ) {         cnt[v[i] + 10]--;         v[i]++;         cnt[v[i] + 10]++;       }     }   }   void solve() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &x[i]);     for (int i = 1; i <= n; i++) {       scanf( %s , &s[i][1]);     }     for (int i = 1; i <= m; i++) v[i] = 0;     for (int i = 0; i <= 20; i++) cnt[i] = 0;     cnt[10] = m;     ans = 0;     dfs(1, 0);     for (int i = 1; i <= m; i++) printf( %d  , P[i]);     printf(  n );   }   int main() {     scanf( %d , &T);     while (T--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2005;   string s, ans;   bool f, at;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> s;     int n = s.size();     f = at = false;     for (int i = 0; i < n; i++) {       if (i < n - 3 && s[i] ==  d  && s[i + 1] ==  o  && s[i + 2] ==  t ) {         if (f) {           ans +=  . ;           i += 2;         } else {           ans += s[i];           f = true;         }       } else if (i < n - 2 && s[i] ==  a  && s[i + 1] ==  t ) {         if (!at && f) {           ans +=  @ ;           i++;           at = true;         } else {           ans += s[i];         }       } else {         if (!f) f = true;         ans += s[i];       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 3e5 + 10;   const long long inf = 1e18 + 10;   const long long mod = 1e1;   long long a[M], p[M], dp[3][M];   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n;       scanf( %d , &n);       for (int i = 0; i <= n; i++) dp[0][i] = dp[1][i] = dp[2][i] = inf;       for (int i = 1; i <= n; i++) {         scanf( %lld%lld , &a[i], &p[i]);       }       dp[0][1] = 0;       dp[1][1] = p[1];       dp[2][1] = 2 * p[1];       for (int i = 2; i <= n; i++) {         if (a[i - 1] == a[i]) {           dp[0][i] = min(dp[1][i - 1], dp[2][i - 1]);           dp[1][i] = min(dp[0][i - 1], dp[2][i - 1]) + p[i];           dp[2][i] = min(dp[0][i - 1], dp[1][i - 1]) + 2 * p[i];         } else if (a[i - 1] + 1 == a[i]) {           dp[0][i] = min(dp[0][i - 1], dp[2][i - 1]);           dp[1][i] = min(dp[1][i - 1], dp[0][i - 1]) + p[i];           dp[2][i] =               min(dp[0][i - 1], min(dp[2][i - 1], dp[1][i - 1])) + 2 * p[i];         } else if (a[i - 1] + 2 == a[i]) {           dp[0][i] = min(dp[0][i - 1], dp[1][i - 1]);           dp[1][i] = min(dp[0][i - 1], min(dp[1][i - 1], dp[2][i - 1])) + p[i];           dp[2][i] =               min(dp[0][i - 1], min(dp[1][i - 1], dp[2][i - 1])) + 2 * p[i];         } else if (a[i - 1] == a[i] + 1) {           dp[0][i] = min(dp[0][i - 1], min(dp[1][i - 1], dp[2][i - 1]));           dp[1][i] = min(dp[1][i - 1], dp[2][i - 1]) + p[i];           dp[2][i] = min(dp[0][i - 1], dp[2][i - 1]) + 2 * p[i];         } else if (a[i - 1] == a[i] + 2) {           dp[0][i] = min(dp[0][i - 1], min(dp[1][i - 1], dp[2][i - 1]));           dp[1][i] = min(dp[0][i - 1], min(dp[1][i - 1], dp[2][i - 1])) + p[i];           dp[2][i] = min(dp[1][i - 1], dp[2][i - 1]) + 2 * p[i];         } else {           dp[0][i] = min(dp[0][i - 1], min(dp[1][i - 1], dp[2][i - 1]));           dp[1][i] = min(dp[0][i - 1], min(dp[1][i - 1], dp[2][i - 1])) + p[i];           dp[2][i] =               min(dp[0][i - 1], min(dp[1][i - 1], dp[2][i - 1])) + 2 * p[i];         }       }       printf( %lld n , min(dp[0][n], min(dp[1][n], dp[2][n])));     }     return 0;   }
#include<bits/stdc++.h>   using namespace std;   using ll = long long;   using ii = pair<int,int>;      #define ff first   #define se second   #define pb push_back   #define all(x) (x).begin(),(x).end()      const int mod = 1e9+7;   const int inf = 1e9;   const int mx  = 1e6+5;      #define exitYes {cout<< Yes n ; return;}   #define exitNo  {cout<< No n ;  return;}      bool can(vector<ll> a){       for(int i=1; i<a.size(); i++){           if(a[i-1] > a[i]) return false;           a[i] -= a[i-1]; a[i-1] = 0;       }return (a.back() == 0);   }      void solve(int cs){   //    cout <<  Case   << cs <<  :  ;       int n; cin >> n;       vector<ll> v(n);       for(auto &u:v) cin >> u;          if(can(v)) exitYes       if(n == 1) exitNo          swap(v[0], v[1]);       if(can(v)) exitYes swap(v[0],v[1]);       swap(v[n-1], v[n-2]);   if(can(v)) exitYes swap(v[n-1], v[n-2]);          vector<ll> p(n), s(n), b = v;          p[0] = b[0];       for(int i=1; i<n; i++){           if(p[i-1]==-1 || b[i-1]>b[i]) p[i]=-1;           else b[i]-=b[i-1], b[i-1]=0, p[i]=b[i];       }b = v;          s[n-1] = b[n-1];       for(int i=n-2; i>=0; i--){           if(s[i+1]==-1 || b[i+1]>b[i]) s[i]=-1;           else b[i]-=b[i+1], b[i+1]=0, s[i]=b[i];       }          for(int i=1; i+2<n; i++){           if(p[i-1] == -1 || s[i+2]==-1) continue;           vector<ll> c = {p[i-1], v[i], v[i+1], s[i+2]};           swap(c[1], c[2]); if(can(c)) exitYes       }exitNo   }      int main(){          ios_base::sync_with_stdio(false);       cin.tie(nullptr); cout.tie(nullptr);          int tc = 1, cs = 1;       cin >> tc;       while(tc--) solve(cs++);          return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline void read(int &x) {     x = 0;     char c = getchar();     int f = 1;     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) {       x = x * 10 + c -  0 ;       c = getchar();     }     x *= f;   }   const int N = 303000;   int n, m, head[N], to[N], nxt[N], val[N], edgenum = 1;   inline void add(int u, int v, int w) {     to[++edgenum] = v;     val[edgenum] = w;     nxt[edgenum] = head[u];     head[u] = edgenum;   }   struct Gauss {     int v[32];     inline void add(int x) {       for (int i = 30; i >= 0; i--)         if ((x >> i) & 1)           if (!v[i]) {             v[i] = x;             break;           } else             x ^= v[i];     }     inline int query(int x) {       for (int i = 30; i >= 0; i--) x = (x ^ v[i]) < x ? x ^ v[i] : x;       return x;     }   } gauss;   int vis[N], tree[N], v[N];   inline void dfs(int u, int Val) {     vis[u] = 1;     v[u] = Val;     for (int i = head[u]; i != 0; i = nxt[i])       if (!vis[to[i]]) {         tree[i >> 1] = 1;         dfs(to[i], Val ^ val[i]);       } else if (!tree[i >> 1]) {         gauss.add(v[to[i]] ^ v[u] ^ val[i]);       }   }   int main() {     read(n);     read(m);     for (int i = 1; i <= m; i++) {       int a, b, c;       read(a);       read(b);       read(c);       add(a, b, c);       add(b, a, c);     }     dfs(1, 0);     printf( %d , gauss.query(v[n]));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<long long, long long> > points;   vector<pair<long long, pair<long long, long long> > > areas;   map<long long, vector<long long> > pm;   int main() {     int n, m, k;     scanf( %i%i%i , &n, &m, &k);     for (int i = 0; i < n; i++) {       int x, y;       scanf( %i%i , &x, &y);       points.push_back(pair<long long, long long>(x, y));     }     for (int i = 0; i < m; i++) {       int c1, c2, r;       scanf( %i%i%i , &r, &c1, &c2);       areas.push_back(pair<long long, pair<long long, long long> >(           r, pair<long long, long long>(c1, c2)));     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if ((points[i].first - areas[j].second.first) *                     (points[i].first - areas[j].second.first) +                 (points[i].second - areas[j].second.second) *                     (points[i].second - areas[j].second.second) <             areas[j].first * areas[j].first) {           pm[i].push_back(j);         }       }       sort(pm[i].begin(), pm[i].end());     }     for (int i = 0; i < k; i++) {       int a, b;       scanf( %i%i , &a, &b);       a -= 1;       b -= 1;       vector<long long> tmp1 = pm[a];       vector<long long> tmp2 = pm[b];       int p = 0;       int cnt = 0;       for (int i = 0; i < tmp1.size(); i++) {         while (p < tmp2.size() && tmp2[p] < tmp1[i]) {           cnt++;           p++;         }         if (p == tmp2.size() || tmp2[p] != tmp1[i]) {           cnt++;         }         if (p != tmp2.size() && tmp2[p] == tmp1[i]) {           p++;         }       }       printf( %i n , cnt + (tmp2.size() - p));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int arr[5010], n;   int solve(int l, int r, int h) {     int i, j, k;     if (l > r) return 0;     int ans = 0, val = 1000000007;     for (i = l; i <= r; i++) val = min(val, arr[i]);     int pos = l - 1;     ans = val - h;     for (i = l; i <= r; i++) {       if (arr[i] == val) {         ans += solve(pos + 1, i - 1, val);         pos = i;       }     }     ans += solve(pos + 1, r, val);     return min(r - l + 1, ans);   }   int main(void) {     int i, k;     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d , &arr[i]);     k = solve(1, n, 0);     printf( %d  , k);     printf(  n );     ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, u, r;   vector<int> a, b, k, p;   long long s, current;   int lastChoice;   void input();   void solve();   void go(int k);   int main() {     input();     solve();   }   void input() {     cin >> n >> u >> r;     a.resize(n);     b.resize(n);     k.resize(n);     p.resize(n);     int val;     for (int i = 0; i <= n - 1; ++i) {       cin >> val;       a[i] = val;     }     for (int i = 0; i <= n - 1; ++i) {       cin >> val;       b[i] = val;     }     for (int i = 0; i <= n - 1; ++i) {       cin >> val;       k[i] = val;     }     for (int i = 0; i <= n - 1; ++i) {       cin >> val;       p[i] = val - 1;     }   }   void solve() {     s = (long long)(-1e12);     lastChoice = 1;     go(1);     cout << s;   }   void go(int x) {     if ((x - 1) % 2 == u % 2) {       long long sum = 0;       for (int i = 0; i <= n - 1; ++i) sum += a[i] * k[i];       s = max(s, sum);     }     if (x >= u + 1) {       return;     }     vector<int> _a(n);     int _lastChoice = lastChoice;     for (int i = 0; i <= n - 1; ++i) _a[i] = a[i];     lastChoice = 1;     for (int i = 0; i <= n - 1; ++i) {       a[i] = _a[p[i]] + r;     }     go(x + 1);     for (int i = 0; i <= n - 1; ++i) a[i] = _a[i];     lastChoice = _lastChoice;     if (lastChoice == 0) {       return;     } else {       _lastChoice = lastChoice;       for (int i = 0; i <= n - 1; ++i) _a[i] = a[i];       lastChoice = 0;       for (int i = 0; i <= n - 1; ++i) {         a[i] = (_a[i] ^ b[i]);       }       go(x + 1);       lastChoice = _lastChoice;       for (int i = 0; i <= n - 1; ++i) a[i] = _a[i];     }   }
#include <bits/stdc++.h>   using namespace std;   int ans[3][1010], dp[3][1010][55][55];   int n, p, k, r, s, x;   int teto(int a, int b) { return (a + b - 1) / b; }   int main() {     while (scanf( %d %d %d , &n, &p, &k) != EOF) {       memset(ans, 0, sizeof(ans));       scanf( %d , &r);       for (int i = 0; i < r; i++) {         scanf( %d , &x);         x--;         ans[0][x] = 1;       }       scanf( %d , &s);       for (int i = 0; i < s; i++) {         scanf( %d , &x);         x--;         ans[1][x] = 1;       }       if (p >= 2 * teto(n, k)) {         int cnt = 0;         for (int i = 0; i < n; i++) {           if (ans[0][i] == 1 || ans[1][i] == 1) {             cnt++;           }         }         printf( %d n , cnt);         continue;       }       int A = min(n, k), B = min(n, k);       for (int pos = n; pos >= 0; pos--) {         int pos1 = pos % 2, pos2 = (pos + 1) % 2;         for (int used = 0; used <= p; used++) {           for (int a = 0; a <= A; a++) {             for (int b = 0; b <= B; b++) {               if (pos == n) {                 dp[pos1][used][a][b] = 0;               } else {                 int max_ =                     dp[pos2][used][max(a - 1, 0)][max(b - 1, 0)] +                     max((a >= 1) * (ans[0][pos]), (b >= 1) * (ans[1][pos]));                 if (used + 1 <= p) {                   max_ =                       max(max_, dp[pos2][used + 1][k - 1][max(0, b - 1)] +                                     max(ans[0][pos], (b >= 1) * (ans[1][pos])));                   max_ =                       max(max_, dp[pos2][used + 1][max(a - 1, 0)][k - 1] +                                     max((a >= 1) * (ans[0][pos]), ans[1][pos]));                 }                 if (used + 2 <= p) {                   max_ = max(max_, dp[pos2][used + 2][k - 1][k - 1]);                 }                 dp[pos1][used][a][b] = max_;               }             }           }         }       }       printf( %d n , dp[0][0][0][0]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   int n;   int a[maxn];   long long dp[maxn][3][3];   int main(void) {     scanf( %d , &n);     for (int i = 0; i < n - 1; i++) scanf( %d , &a[i]);     for (int i = 1; i < n; i++) {       if (a[i - 1] == 0) continue;       int b = a[i - 1];       if (b % 2 == 0) b--;       dp[i][0][0] = dp[i - 1][0][0] + b;       b = a[i - 1];       if (b <= 1) continue;       if (b % 2 == 1) b--;       dp[i][0][1] = dp[i - 1][0][1] + b;       dp[i][0][0] = max(dp[i][0][0], dp[i][0][1]);     }     for (int i = n - 2; i >= 0; i--) {       if (a[i] == 0) continue;       int b = a[i];       if (b % 2 == 0) b--;       dp[i][1][0] = dp[i + 1][1][0] + b;       b = a[i];       if (b <= 1) continue;       if (b % 2 == 1) b--;       dp[i][1][1] = dp[i + 1][1][1] + b;       dp[i][1][0] = max(dp[i][1][0], dp[i][1][1]);     }     long long sol = 0;     sol = dp[0][1][0];     sol = max(sol, dp[n - 1][0][0]);     for (int i = 1; i < n - 1; i++) {       long long c1 = dp[i][1][0];       if (a[i - 1] > 1) {         int add = a[i - 1];         if (add % 2 == 1) add--;         c1 += dp[i - 1][0][1] + add;       }       sol = max(sol, c1);       long long c2 = dp[i][0][0];       if (a[i] > 1) {         int add = a[i];         if (add % 2 == 1) add--;         c2 += dp[i + 1][1][1] + add;       }       sol = max(sol, c2);     }     printf( %lld n , sol);     return 0;   }
#include <bits/stdc++.h>   const int N = 25, Mod = 1e6 + 3;   const int n = 11;   int y[N], k, inv[Mod + 2];   int fm[] = {404910, 950915, 220896, 410947, 30845, 962989,               30845,  410947, 220896, 950915, 404910};   inline int po(int x, int y) {     int r = 1;     while (y) {       if (y & 1) r = 1ll * r * x % Mod;       x = 1ll * x * x % Mod, y >>= 1;     }     return r;   }   int judge(int k) {     int ans = 0, base = 1;     for (int i = 1; i <= n; ++i)       if (k != i) base = 1ll * base * (k - i) % Mod;     if (1 <= k && k <= 11)       return (1ll * base * fm[k - 1] % Mod * y[k] % Mod + Mod) % Mod;     base = (base + Mod) % Mod;     for (int i = 1; i <= n; ++i)       ans = (ans + 1ll * base * inv[(k - i + Mod) % Mod] % Mod * fm[i - 1] % Mod *                        y[i] % Mod) %             Mod;     return ans;   }   int main() {     for (int i = 1; i <= n; ++i) {       printf( ? %d n , i);       fflush(stdout);       scanf( %d , &y[i]);     }     inv[0] = inv[1] = 1;     for (int i = 2; i < Mod; ++i)       inv[i] = 1ll * (Mod - Mod / i) * inv[Mod % i] % Mod;     for (int k = 0; k < Mod; ++k)       if (!judge(k)) {         printf( ! %d n , k);         fflush(stdout);         return 0;       }     printf( ! -1 n );     fflush(stdout);   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:256000000 )   #pragma warning(disable : 4996 4018)   using namespace std;   long long n, k, p;   int main() {     cin.tie(0);     ios_base::sync_with_stdio(0);     cin >> n >> k >> p;     if ((n & 1) && k) {       n--;       k--;     }     while (p--) {       long long nm;       cin >> nm;       if (nm > n) {         cout <<  X ;         continue;       }       if (!k) {         cout <<  . ;         continue;       }       if (nm & 1) {         if (k > n / 2) {           long long rest = k - n / 2;           long long nd = n / 2;           long long val = nd - (nm / 2.0) + 1;           if (val <= rest)             cout <<  X ;           else             cout <<  . ;         } else           cout <<  . ;       } else {         long long nd = n / 2;         long long val = nd - (nm / 2) + 1;         if (val <= k)           cout <<  X ;         else           cout <<  . ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000 * 100 * 2 + 152;   long long n, m, x, y, z, q, mark[maxn], k = 1, par1[maxn], sum[maxn], h[maxn];   pair<long long, long long> par[17][maxn];   vector<pair<long long, long long> > v[maxn];   pair<long long, pair<long long, long long> > edg[maxn];   void dfs(int x) {     mark[x] = k;     for (int i = 0; i < v[x].size(); i++)       if (!mark[v[x][i].first]) {         sum[k] += v[x][i].second;         par[0][v[x][i].first] = make_pair(x, v[x][i].second);         h[v[x][i].first] = h[x] + 1;         dfs(v[x][i].first);       }   }   int find_par(int x) {     if (x == par1[x]) return x;     return par1[x] = find_par(par1[x]);   }   long long LCA(int x, int y) {     if (h[x] > h[y]) swap(x, y);     long long fa = h[y] - h[x], jack = 0, MAX = 0;     for (int i = 0; i < 17; i++)       if ((1 << i) & fa) {         MAX = max(MAX, par[i][y].second);         y = par[i][y].first;       }     for (int i = 16; i >= 0; i--)       if (par[i][x].first != par[i][y].first) {         MAX = max(MAX, max(par[i][x].second, par[i][y].second));         x = par[i][x].first;         y = par[i][y].first;       }     if (x != y) MAX = max(MAX, max(par[0][x].second, par[0][y].second));     return MAX;   }   int main() {     cin >> n >> m;     for (int i = 0; i < m; i++)       cin >> edg[i].second.first >> edg[i].second.second >> edg[i].first;     for (int i = 1; i <= n; i++) par1[i] = i;     sort(edg, edg + m);     for (int i = 0; i < m; i++) {       int x = find_par(edg[i].second.first), y = find_par(edg[i].second.second);       if (x == y) continue;       v[edg[i].second.first].push_back(           make_pair(edg[i].second.second, edg[i].first));       v[edg[i].second.second].push_back(           make_pair(edg[i].second.first, edg[i].first));       par1[x] = y;     }     for (int i = 1; i <= n; i++)       if (!mark[i]) {         dfs(i);         k++;       }     for (int i = 1; i < 17; i++)       for (int j = 1; j <= n; j++)         par[i][j] = make_pair(             par[i - 1][par[i - 1][j].first].first,             max(par[i - 1][j].second, par[i - 1][par[i - 1][j].first].second));     cin >> q;     while (q--) {       cin >> x >> y;       if (k > 3 || (k == 3 && mark[x] == mark[y])) {         cout << -1 << endl;         continue;       }       if (k == 3) {         cout << sum[1] + sum[2] << endl;         continue;       }       long long jack = LCA(x, y);       cout << sum[1] - jack << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5e4 + 5, inf = 0x3f3f3f3f;   int n, front, x, ans = -inf, nxt;   vector<int> interact(int _) {     printf( ? %d n , _);     fflush(stdout);     int a, b;     scanf( %d%d , &a, &b);     return vector<int>({a, b});   }   void give(int _) {     printf( ! %d n , _);     fflush(stdout);   }   int seed, seed2;   void srand(int x, int y) {     seed = x;     seed2 = y;   }   int frand() { return (seed *= 19260817) += ((seed2 += 114514) ^= 1919810); }   int rand() {     int res = frand();     while (res <= 0) res += n;     return res;   }   int main() {     srand(998244353, 1000000007);     scanf( %d%d%d , &n, &front, &x);     nxt = front;     for (int(i) = (1); (i) <= (min(n, 1000) - 1); (i)++) {       int pos = rand() % n + 1;       vector<int> res = interact(pos);       if (res[0] <= x && res[0] > ans) nxt = res[1], ans = res[0];     }     if (ans == x) return give(x), 0;     for (int(i) = (1); (i) <= (1000); (i)++) {       if (nxt == -1) break;       vector<int> res = interact(nxt);       if (res[0] >= x) return give(res[0]), 0;       ans = res[0];       nxt = res[1];     }     give(ans >= x ? ans : -1);     return 0;     int lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;   }