malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include<bits/stdc++.h>   #define X first   #define Y second   #define sz(a) (int)a.size()   #define ll long long   //#define int long long   using namespace std;   const int mod = 1e9 + 7;   const int N = 3e5;      signed main()   {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);       int n, k;       cin >> n >> k;       string s;       cin >> s;       vector <int> vec;       for(int i = 0; i < n; i++)       {           if(s[i] ==  ? )           {               vec.push_back(-1);           }           else           {               vec.push_back(s[i] -  a );           }       }       vector <vector <int> > right(k, vector <int> (n, 0));       for(int i = 0; i < k; i++)       {           for(int j = n - 1; j >= 0; j--)           {               if(vec[j] == i || vec[j] == -1)               {                   if(j == n - 1)                   {                       right[i][j] = 1;                   }                   else                   {                       right[i][j] = right[i][j + 1] + 1;                   }               }      //         cout << right[i][j] <<    ;           }        //   cout <<   n ;       }       int l = 0, r = n + 1;       while(r - l > 1)       {           int midd = (r + l) / 2;           vector <vector <int> > mass(26);           for(int i = 0; i < k; i++)           {               for(int j = 0; j < n; j++)               {                   if(right[i][j] >= midd)                   {                       mass[i].push_back(j);                   }               }           }           vector <int> dp(1 << k, 1e9);           dp[0] = -1;           vector <int> iter(k, 0);           vector <vector <int> > mass1(n + 1);           mass1[0].push_back(0);           for(int i = 0; i < n; i++)           {               for(int j = 0; j < k; j++)               {                   while(iter[j] < sz(mass[j]) && mass[j][iter[j]] < i)                   {                       iter[j]++;                   }               }               for(auto p : mass1[i])               {                   if(dp[p] != i - 1)                   {                       continue;                   }                   for(int j = 0; j < k; j++)                   {                       if((1 << j) & p)                       {                           continue;                       }                       if(iter[j] < sz(mass[j]))                       {                           int u = mass[j][iter[j]];                           if(dp[(1 << j) | p] > u + midd - 1)                           {                               dp[(1 << j) | p] = u + midd - 1;                               mass1[u + midd].push_back((1 << j) | p);                           }                       }                   }               }           }           if(dp[(1 << k) - 1] < n)           {               l = midd;           }           else           {               r = midd;           }       }       cout << l;       return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   int n, k, tot, root;   int ak[30];   int son[20000005][2], g[20000005];   long long ans;   void calc(int v, int *a) {     memset(a, 0, 120);     int i = 0;     while (v) {       a[i++] = v & 1;       v >>= 1;     }     return;   }   int make_node() {     ++tot;     return tot;   }   int get_ans(int x, int d) {     if (!son[x][d]) return 0;     return g[son[x][d]];   }   int ax[30];   void update(int x) {     int nd = root;     g[root]++;     for (int i = 30 - 1; i >= 0; i--) {       if (!son[nd][ax[i]]) son[nd][ax[i]] = make_node();       nd = son[nd][ax[i]];       g[nd]++;     }     return;   }   void query(int x) {     int nd = root;     for (int i = 30 - 1; i >= 0; i--) {       if (!ak[i]) {         ans += get_ans(nd, ax[i] ^ 1);         nd = son[nd][ax[i]];       } else         nd = son[nd][ax[i] ^ 1];       if (!nd) return;     }     ans += g[nd];     return;   }   int main() {     int x, y = 0;     scanf( %d %d , &n, &k);     root = make_node();     update(0);     calc(k, ak);     for (int i = 1; i <= n; i++) {       scanf( %d , &x);       y ^= x;       calc(y, ax);       query(y);       update(y);     }     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000000;   vector<int> T;   int l, size;   void Stworz(int n) {     int p = 1;     while (p < n) p *= 2;     l = p;     size = 2 * p - 1;     for (int i = 0; i <= size; ++i) T.push_back(INF);   }   void Ustaw(int a, int x) {     a += l;     T[a] = x;     a /= 2;     while (a != 0) {       T[a] = min(T[2 * a], T[2 * a + 1]);       a /= 2;     }   }   int Mini(int a, int b) {     a += l;     b += l;     int m = min(T[a], T[b]);     while (a / 2 != b / 2) {       if (a % 2 == 0) m = min(m, T[a + 1]);       if (b % 2 == 1) m = min(m, T[b - 1]);       a /= 2;       b /= 2;     }     return m;   }   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     vector<int> a(n);     map<int, int> wyst, pier;     for (int i = 0; i < n; ++i) {       cin >> a[i];       wyst[a[i]] = 0;       pier[a[i]] = INF;     }     Stworz(n);     vector<int> odp;     for (int L = 0; L < n;) {       int P = L;       while (P < n) {         ++wyst[a[P]];         if (pier[a[P]] == INF) pier[a[P]] = P;         Ustaw(P, pier[a[P]]);         if (pier[a[P]] + 1 <= P - 1) {           int ind = Mini(pier[a[P]] + 1, P - 1);           if (ind < pier[a[P]]) {             odp.push_back(a[ind]);             odp.push_back(a[P]);             odp.push_back(a[ind]);             odp.push_back(a[P]);             break;           }         }         if (wyst[a[P]] >= 4) {           for (int i = 0; i < 4; ++i) odp.push_back(a[P]);           break;         }         ++P;       }       for (int i = L; i <= min(P, n); ++i) {         --wyst[a[i]];         pier[a[i]] = INF;       }       L = P + 1;     }     cout << odp.size() << endl;     for (int i = 0; i < odp.size(); ++i) cout << odp[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d, y, x, h, n;     cin >> a >> b >> c >> d;     y = (a * 3) / 10, x = (a - ((a / 250) * c)), h = (b * 3) / 10,     n = (b - ((b / 250) * d));     if (max(y, x) > max(n, h))       cout <<  Misha ;     else if (max(y, x) < max(n, h))       cout <<  Vasya ;     else       cout <<  Tie ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using P = pair<int, int>;   using Pl = pair<ll, int>;   const int mod = 1e9 + 7, INF = 1 << 30;   const double EPS = 1e-12, PI = 3.1415926535897932384626;   const ll LINF = 1LL << 60, lmod = 1e9 + 7;   const int MAX_N = 102;   vector<P> graph[MAX_N];   int memo[2][MAX_N][MAX_N][30];   int solve(bool is_first, int a, int b, int score) {     if (memo[int(is_first)][a][b][score] != -1)       return memo[int(is_first)][a][b][score];     if (is_first) {       bool win = false;       for (auto p : graph[a]) {         int u, c;         tie(u, c) = p;         if (c >= score) {           win |= (solve(false, u, b, c) == 1);         }       }       if (!win)         return memo[int(is_first)][a][b][score] = 0;       else         return memo[int(is_first)][a][b][score] = 1;     } else {       bool win = true;       for (auto p : graph[b]) {         int u, c;         tie(u, c) = p;         if (c >= score) {           win &= (solve(true, a, u, c) == 1);         }       }       if (win)         return memo[int(is_first)][a][b][score] = 1;       else         return memo[int(is_first)][a][b][score] = 0;     }   }   int main() {     int N, M;     cin >> N >> M;     for (int i = 0; i < M; i++) {       int a, b;       char c;       cin >> a >> b >> c;       a--;       b--;       graph[a].push_back(P(b, int(c -  a )));     }     for (int i = 0; i < 2; i++)       for (int j = 0; j < MAX_N; j++)         for (int k = 0; k < MAX_N; k++)           for (int l = 0; l < 30; l++) memo[i][j][k][l] = -1;     for (int i = 0; i < N; i++) {       for (int j = 0; j < N; j++) cout << (solve(true, i, j, 0) == 1 ?  A  :  B );       cout <<    << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     cin >> n;     vector<pair<int, int>> v;     for (int i = 0; i < n; i++) {       long long a, b;       cin >> a >> b;       v.push_back(make_pair(a, b));     }     int c = 0;     for (int i = 0; i < n; i++) {       int up = 0, lo = 0, r = 0, l = 0;       for (int j = 0; j < n; j++) {         if (v[i].first > v[j].first && v[i].second == v[j].second) up = 1;         if (v[i].first < v[j].first && v[i].second == v[j].second) lo = 1;         if (v[i].first == v[j].first && v[i].second < v[j].second) l = 1;         if (v[i].first == v[j].first && v[i].second > v[j].second) r = 1;       }       if (up + lo + l + r == 4) c++;     }     cout << c;   }
#include <bits/stdc++.h>   using namespace std;   const short int N = 1000;   short int n, m, ax[] = {0, 0, 1, -1}, ay[] = {1, -1, 0, 0}, man_dis[N][N];   bool vis[N][N], v[N][N], g[N][N];   void good() {     for (short int i = 0; i < n; i++) {       for (short int j = 0; j < m; j++) {         bool f = 0;         if (i and v[i][j] == v[i - 1][j]) f = 1;         if (j and v[i][j] == v[i][j - 1]) f = 1;         if (i < n - 1 and v[i][j] == v[i + 1][j]) f = 1;         if (j < m - 1 and v[i][j] == v[i][j + 1]) f = 1;         g[i][j] = f;       }     }   }   void man_dist() {     queue<pair<short int, short int>> q;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (g[i][j]) man_dis[i][j] = 0, q.push({i, j}), vis[i][j] = true;     while (q.size()) {       short int y = q.front().first, x = q.front().second;       q.pop();       for (int i = 0; i < 4; i++) {         int nx = x + ax[i], ny = y + ay[i];         if (nx < 0 || ny < 0 || nx >= m || ny >= n || vis[ny][nx]) continue;         man_dis[ny][nx] = man_dis[y][x] + 1;         vis[ny][nx] = true;         q.push({ny, nx});       }     }   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int tt, ii = 0;     short int k = 0;     cin >> n >> m >> tt;     for (short int i = 0; i < n; i++)       for (short int j = 0; j < m; j++) {         char x;         cin >> x;         v[i][j] = (x ==  1 );       }     good();     man_dist();     while (ii++ < tt) {       short int i, j;       long long p;       cin >> i >> j >> p;       i--, j--;       if (n + m == 2) {         cout << v[i][j] << endl;         continue;       }       short int f = man_dis[i][j];       if (p <= f || !vis[i][j])         cout << v[i][j] << endl;       else         cout << (p - f + v[i][j]) % 2 << endl;     }     cerr <<  [Execution :   << (1.0 * clock()) / CLOCKS_PER_SEC <<  s] n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool oppSign(double a, double b) {     if (a == 0 || b == 0) return false;     if (a > 0 && b < 0) return true;     if (a < 0 && b > 0) return true;     return false;   }   void parr(vector<double>& a) {     for (int i = 0; i < a.size(); ++i) {       cout << a[i] <<    ;     }     cout << endl;   }   int main() {     int n;     cin >> n;     double a, b;     cin >> a >> b;     vector<pair<double, double> > v;     for (int i = 0; i < (n); ++i) {       double x, y;       scanf( %lf%lf , &x, &y);       double y1, y2;       y1 = x * a + y;       y2 = x * b + y;       v.push_back(make_pair((y1), (y2)));     }     sort(v.begin(), v.end());     vector<double> ar, br;     for (int i = 0; i < v.size(); ++i) {       double x = v[i].first;       double y = v[i].second;       ar.push_back(x);       br.push_back(y);     }     vector<double> bkr(br.size());     bkr[br.size() - 1] = br[br.size() - 1];     for (int i = br.size() - 2; i >= 0; --i) {       if (br[i] > bkr[i + 1])         bkr[i] = bkr[i + 1];       else         bkr[i] = br[i];     }     bool flag = false;     for (int i = 0; i < ar.size() - 1; ++i) {       if (ar[i] != ar[i + 1] && br[i] != bkr[i + 1] &&           oppSign((ar[i] - ar[i + 1]), (br[i] - bkr[i + 1]))) {         flag = true;         break;       }     }     if (flag == false)       cout <<  NO n ;     else       cout <<  YES n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   long long ans;   int a[150000 + 1];   int main() {     scanf( %d , &n);     for (register int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       ans += 1LL * a[i] * (n - a[i] + 1);     }     for (register int i = 1; i <= n; ++i)       ans -= 1LL * min(a[i], a[i + 1]) * (n - max(a[i], a[i + 1]) + 1);     printf( %lld , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int inf = ~0u >> 1, N = 1000005;   int n, r, x, ans, fr;   char o[N];   void output(int x, int y) {     for (int i = n; i; --i)       if (x >= y)         o[i - 1] =  T , x -= y;       else         o[i - 1] =  B , y -= x;   }   int evaluate(int x, int y) {     int sta = 0, stb = 0, t;     while (x != 0 && y != 0 && sta <= n) {       if (x > y) {         if (x % y != 0) {           t = x / y;           sta += t;           stb += t - 1;           x %= y;         } else {           t = x / y - 1;           sta += t;           stb += t - 1;           x = y;           ++sta;           y = 0;         }       } else {         if (y % x != 0) {           t = y / x;           sta += t;           stb += t - 1;           y %= x;         } else {           t = y / x - 1;           sta += t;           stb += t - 1;           y = x;           ++sta;           x = 0;         }       }     }     if (x == 0 && y == 1 && sta == n)       return stb;     else       return -1;   }   void nrun() {     ans = n;     for (int i = 1; i < r; ++i) {       x = evaluate(i, r);       if (x != -1 && x <= ans) ans = x, fr = i;       x = evaluate(r, i);       if (x != -1 && x <= ans) ans = x, fr = -i;     }     if (ans == n)       printf( IMPOSSIBLE n );     else {       printf( %d n , ans);       if (fr > 0)         output(fr, r);       else         output(r, -fr);       puts(o);     }   }   int main() {     scanf( %d%d , &n, &r);     if (r == 1) {       printf(n == 1 ?  0 nT n  :  IMPOSSIBLE n );     } else       nrun();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6;   int n, k, a, b;   vector<int> v;   int ret(int lt, int rt) {     int id2 = upper_bound(v.begin(), v.end(), rt) - v.begin();     int id1 = lower_bound(v.begin(), v.end(), lt) - v.begin();     return id2 - id1;   }   long long dfs(int lt, int rt) {     int nm = ret(lt, rt);     if (!nm) return a;     long long on = b * 1LL;     on *= nm;     on *= (rt - lt + 1);     if (lt == rt) return on;     int md = (lt + rt) / 2;     long long tw = dfs(lt, md) + dfs(md + 1, rt);     return min(on, tw);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> k >> a >> b;     for (int i = 1; i <= k; i++) {       int x;       cin >> x;       v.push_back(x);     }     sort(v.begin(), v.end());     cout << dfs(1, 1 << n) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     int a[2 * n], ans = 0;     for (int i = 0; i <= 2 * n - 1; i++) cin >> a[i];     for (int i = 0; i < 2 * n; i += 2) {       int j = i + 1;       while (a[j] != a[i]) j++;       ans += j - i - 1;       for (int k = j; k >= i + 2; k--) a[k] = a[k - 1];     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int inf = 1e9 + 9;   const long long MOD = 1e9 + 696969;   const long long INF = 1e18;   int n, m, k, a, b, c, w, h;   char s[1000100];   int dp[1000100][26], last[1000100][26];   pair<int, int> SECOND, MIN;   inline pair<int, int> minexc(int x) {     if (x != MIN.second) return MIN;     return SECOND;   }   char ret[1000100];   int main() {     scanf( %d%d , &n, &k) ?: 0;     scanf( %s , s + 1) ?: 0;     for (int i = 1; i <= n; ++i)       for (int j = 0; j < k; ++j) dp[i][j] = inf;     MIN = {0, -1};     SECOND = {0, 0};     for (int i = 1; i <= n; ++i) {       for (int j = 0; j < k; ++j)         if (s[i] == (char)j +  A ) {           dp[i][j] = minexc(j).first;           last[i][j] = minexc(j).second;         } else           dp[i][j] = minexc(j).first + 1, last[i][j] = minexc(j).second;       MIN = {inf, inf};       SECOND = {inf, inf};       for (int j = 0; j < k; ++j)         if (dp[i][j] < MIN.first) {           SECOND = MIN;           MIN = make_pair(dp[i][j], j);         } else if (dp[i][j] < SECOND.first)           SECOND = make_pair(dp[i][j], j);     }     int res = inf, poz = inf;     for (int i = 0; i < k; ++i)       if (dp[n][i] < res) res = dp[n][i], poz = i;     cout << res << endl;     if (res == 0) {       for (int i = 1; i <= n; ++i) printf( %c , s[i]);       exit(0);     }     for (int i = n; i > 0; --i) {       ret[i] = poz +  A ;       poz = last[i][poz];     }     for (int i = 1; i <= n; ++i) printf( %c , ret[i]);   }
#include <bits/stdc++.h>   using namespace std;   const int INF = (int)1e9;   const long long INF64 = (long long)1e18;   const long double eps = 1e-9;   const long double pi = 3.14159265358979323846;   int dp[20][50];   int frmP[20][50], frmQ[20][50], frmE[20][50];   long long ten[20];   char str[60];   vector<long long> arr;   pair<long long, long long> rev[60];   long long num[20];   void update(int p1, int q1, int p2, int q2, int val) {     if (dp[p1][q1] == 0) {       dp[p1][q1] = 1;       frmP[p1][q1] = p2;       frmQ[p1][q1] = q2;       frmE[p1][q1] = val;     }   }   void re(int p1, int q1, int dep) {     if (p1) {       re(frmP[p1][q1], frmQ[p1][q1], dep + 1);       int xx, yy;       int i;       long long val;       val = arr[frmE[p1][q1]];       xx = rev[val].first;       yy = rev[val].second;       for (i = 0; i < xx; i++) num[i] += (4LL * ten[dep]);       for (i = 0; i < yy; i++) num[i + xx] += (7LL * ten[dep]);     }   }   int main() {     long long i, j, k;     for (i = 0; i <= 6; i++) {       for (j = 0; j + i <= 6; j++) {         arr.push_back(i * 4 + 7 * j);         rev[i * 4 + 7 * j] = (make_pair(i, j));       }     }     sort((arr).begin(), (arr).end());     int tn;     int len;     long long t;     t = 1;     for (i = 0; i <= 18; i++) {       ten[i] = t;       t *= 10LL;     }     cin >> tn;     while (tn--) {       cin >> str;       len = strlen(str);       memset(dp, 0, sizeof(dp));       dp[0][0] = 1;       for (i = 1; i <= len; i++) {         for (j = 0; j < 50; j++) {           if (dp[i - 1][j]) {             t = j * 10LL + (str[i - 1] -  0 );             for (k = 0; k < (int((arr).size())) && arr[k] <= t; k++) {               if (t - arr[k] < 50LL) {                 update(i, t - arr[k], i - 1, j, k);               }             }           }         }       }       if (!dp[len][0])         printf( -1 n );       else {         memset(num, 0, sizeof(num));         re(len, 0, 0);         for (i = 0; i < 6; i++) {           if (i) printf(   );           cout << num[i];         }         puts(  );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9 + 7;   const long long llinf = 1e18 + 7;   const double eps = 1e-15;   const int N = 2e5 + 5;   int cnt0[N], cnt1[N];   long long sum(int cnt[N], int l, int r) {     long long ret = cnt[r];     if (l) ret -= cnt[l - 1];     return ret;   }   int main() {     string a, b;     cin >> a >> b;     memset(cnt0, 0, sizeof cnt0);     memset(cnt1, 0, sizeof cnt1);     for (int i = 0; i < b.size(); ++i) {       cnt0[i] += b[i] ==  0 ;       if (i) cnt0[i] += cnt0[i - 1];       cnt1[i] += b[i] ==  1 ;       if (i) cnt1[i] += cnt1[i - 1];     }     long long ans = 0;     for (int i = 0; i < a.size(); ++i) {       int lastloc = int(b.size()) - int(a.size()) + i;       if (a[i] ==  1 ) {         ans += sum(cnt0, i, lastloc);       } else         ans += sum(cnt1, i, lastloc);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, r1, r2;     cin >> n >> r1 >> r2;     int a[n + 2];     for (int i = 1; i <= n; i++)       if (i != r1)         cin >> a[i];       else         a[i] = 0;     int v = r2, x = a[r2];     do {       int y = a[x];       a[x] = v;       v = x;       x = y;     } while (x != 0);     for (int i = 1; i <= n; i++)       if (i != r2) cout << a[i] <<    ;   }
#include<bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int,int>;   using pll = pair<ll,ll>;   #ifdef eclipse   #define debug(...) do{    fprintf(stderr,  LINE %d: (%s) =  ,__LINE__, #__VA_ARGS__ );     _do(__VA_ARGS__);    }while(0)   template<typename T> void _do(T &&_x) {cerr << _x << endl;}   template<typename T, typename ...S> void _do(T &&_x, S &&..._t) {cerr << _x <<  ,  ; _do(_t...);}   #else   #define debug(...)   #endif      const int MAXN = 300005;   int n, in[MAXN], in2[MAXN];      int calc() {    int ans = 0;    for (int i = 1; i < n - 1; ++i) {     if (in[i] < min(in[i-1], in[i+1])) ans++;     else if (in[i] > max(in[i-1], in[i+1])) ans++;    }     return ans;   }         int calc2(int idx) {    int x, y; x = y = 0;    for (int i = idx - 1; i <= idx + 1; ++i) {     if (i == 0 || i == n - 1) continue;     if (in[i] < min(in[i-1], in[i+1])) y++;     else if (in[i] > max(in[i-1], in[i+1])) y++;    }       for (int i = idx - 1; i <= idx + 1; ++i) {     if (i == 0 || i == n - 1) continue;     if (in2[i] < min(in2[i-1], in2[i+1])) x++;     else if (in2[i] > max(in2[i-1], in2[i+1])) x++;    }    return x - y;   }      signed main (){    ios::sync_with_stdio(0),cin.tie(0);    int t;    cin >> t;    while (t--) {     cin >> n;     for (int i = 0; i < n; ++i) cin >> in[i];     for (int i = 0; i < n; ++i) in2[i] = in[i];     int ans, now = calc();     ans = now;     for (int i = 1; i < n - 1; ++i) {      int tmp = in[i];      in[i] = in[i-1];      ans = min(ans, now - calc2(i));      in[i] = in[i+1];      ans = min(ans, now - calc2(i));      in[i] = tmp;     }      cout << ans <<   n ;    }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n;   int resp;   int ask(long long x) {     printf( ? %lld n , x);     fflush(stdout);     scanf( %d , &resp);     return resp;   }   void ans(long long x) {     printf( = %lld n , x);     fflush(stdout);   }   void solve() {     scanf( %lld , &n);     if (n == 2ll) {       resp = ask(1ll);       resp = ask(2ll);       if (resp)         ans(1ll);       else         ans(2ll);       return;     } else if (n == 3ll) {       resp = ask(2ll);       resp = ask(1ll);       if (resp)         ans(1ll);       else {         resp = ask(3ll);         if (resp)           ans(2ll);         else           ans(3ll);       }       return;     }     vector<long long> path_mid_to_hi;     long long lf = 1ll, rg = n - 1ll;     for (long long md; lf <= rg;) {       md = (lf + rg) / 2ll;       path_mid_to_hi.push_back(md);       if (lf == rg && md == n - 1ll) break;       lf = md + 1ll;     }     long long st = n, bf = n;     reverse(path_mid_to_hi.begin(), path_mid_to_hi.end());     bool go_left = 1;     for (long long i : path_mid_to_hi) {       bf = st;       if (go_left)         st -= i;       else         st += i;       go_left ^= 1;     }     if (bf < st)       go_left = 1;     else       go_left = 0;     lf = 1ll, rg = n - 1ll;     long long res = n;     resp = ask(st);     for (long long md; lf <= rg;) {       md = (lf + rg) / 2;       if (go_left)         st -= md;       else         st += md;       resp = ask(st);       if (resp) {         res = md;         rg = md - 1;       } else         lf = md + 1;       go_left ^= 1;     }     ans(res);     return;   }   int main() {     int tc;     scanf( %d , &tc);     for (; tc--;) solve();     return 0;   }