malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   using i64 = long long;   constexpr int MAX = 400010;   constexpr int MOD = 1000000007;   i64 fac[MAX], inv[MAX];   int l[MAX], r[MAX], x[MAX], cnt[MAX];   i64 ModPow(i64 a, i64 b, i64 p = MOD) {     i64 ret = 1;     for (a %= p; b; b >>= 1) {       if (b & 1) ret = ret * a % p;       a = a * a % p;     }     return ret;   }   inline i64 Inv(i64 x, i64 p = MOD) { return ModPow(x, p - 2, p); }   void Init() {     fac[0] = 1;     inv[0] = 1;     for (int i = 1; i < MAX; ++i) {       fac[i] = fac[i - 1] * i % MOD;       inv[i] = Inv(fac[i]);     }   }   inline i64 C(int n, int m) {     return n < m ? 0 : fac[n] * inv[m] % MOD * inv[n - m] % MOD;   }   i64 Solve(int n, int k) {     int m = 0;     for (int i = 0; i < n; ++i) {       l[i] <<= 1;       r[i] = ((r[i] << 1) | 1);       x[m++] = l[i];       x[m++] = r[i];     }     sort(x, x + m);     int a = x[0], b = x[m - 1];     x[m++] = a - 1;     x[m++] = b + 1;     sort(x, x + m);     m = unique(x, x + m) - x;     memset(cnt, 0, sizeof(cnt));     for (int i = 0; i < n; ++i) {       int u = lower_bound(x, x + m, l[i]) - x;       int v = lower_bound(x, x + m, r[i]) - x;       ++cnt[u];       --cnt[v];     }     i64 ret = 0;     for (int i = 1; i < m - 1; ++i) {       cnt[i] += cnt[i - 1];       if (cnt[i] >= k) {         int u = ((x[i + 1] + 1) >> 1), v = ((x[i] + 1) >> 1);         int d = u - v;         i64 cur = C(cnt[i], k) * d % MOD;         ret = (ret + cur) % MOD;       }     }     return ret;   }   int main() {     Init();     int n, k;     while (~scanf( %d%d , &n, &k)) {       for (int i = 0; i < n; ++i) {         scanf( %d%d , &l[i], &r[i]);       }       printf( %d n , (int)Solve(n, k));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[2555], t[2555];   int n, ans[2555 * 3], o;   int main() {     scanf( %d , &n);     scanf( %s , s);     scanf( %s , t);     o = 0;     for (int i = n - 1; i >= 0; i--) {       int j = n - 1 - i;       while (j < n && s[j] != t[i]) j++;       if (j == n) {         printf( -1 n );         return 0;       }       ans[o++] = n;       ans[o++] = j;       ans[o++] = 1;       reverse(s + j, s + n);       reverse(s, s + n);       reverse(s + 1, s + n);     }     cout << o << endl;     for (int i = 0; i < o; i++) printf( %d  , ans[i]);     printf(  n );   }
#include <bits/stdc++.h>   using namespace std;   vector<int> a;   void init(int x) {     vector<int> b;     while (x > 0) {       int tmp = x % 10;       b.push_back(tmp);       x /= 10;     }     for (int i = b.size() - 1; i >= 0; i--) {       a.push_back(b[i]);     }   }   int main() {     for (int i = 0; i <= 1000; ++i) init(i);     int n;     while (~scanf( %d , &n)) cout << a[n - 1] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[505][505];   int main() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         scanf(  %c , &s[i][j]);       }     }     bool ok = 1;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (s[i][j] ==  W ) {           if (s[i + 1][j] ==  . )             s[i + 1][j] =  D ;           else if (s[i + 1][j] ==  S )             ok = 0;           if (s[i - 1][j] ==  . )             s[i - 1][j] =  D ;           else if (s[i - 1][j] ==  S )             ok = 0;           if (s[i][j + 1] ==  . )             s[i][j + 1] =  D ;           else if (s[i][j + 1] ==  S )             ok = 0;           if (s[i][j - 1] ==  . )             s[i][j - 1] =  D ;           else if (s[i][j - 1] ==  S )             ok = 0;           if (!ok) {             cout <<  No  << endl;             return 0;           }         }       }     }     cout <<  Yes  << endl;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         printf( %c , s[i][j]);       }       printf(  n );     }   }
#include <bits/stdc++.h>   using namespace std;   long long int _seive_size;   bitset<1000000> bs;   vector<long long int> primes;   void seive(long long int upperbound) {     _seive_size = upperbound + 1;     bs.set();     bs[0] = bs[1] = 0;     for (long long int i = 2; i <= _seive_size; i++) {       if (bs[i]) {         for (long long int j = i * i; j <= _seive_size; j += i) {           bs[j] = 0;         }         primes.push_back((int)i);       }     }   }   bool isTrime(long long int N) {     long long int temp;     long long int start = 0;     long long int end = primes.size() - 1;     while (start <= end) {       long long int mid = start + (end - start) / 2;       temp = primes[mid] * primes[mid];       if (temp == N) {         return true;       } else if (temp < N) {         start = mid + 1;       } else {         end = mid - 1;       }     }     return false;   }   int main() {     seive(1000000);     long long int n;     cin >> n;     long long int arr[n];     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     for (int i = 0; i < n; i++) {       if (isTrime(arr[i])) {         cout <<  YES  << endl;       } else {         cout <<  NO  << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = (1LL << 22) + 2;   long long n, m;   long long a[N];   bool vis[2][N];   void dfs(long long k, long long cur) {     if (vis[cur][k]) return;     vis[cur][k] = 1;     if (cur == 1) return dfs(k, cur ^ 1);     for (long long i = 0; i < n; i++) {       if ((k & (1LL << i)) == 0) dfs(k | (1LL << i), 0);     }     dfs(((1LL << n) - 1) ^ k, 1);   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n >> m;     for (long long i = 0; i < N; i++) vis[1][i] = 1;     for (long long i = 1; i <= m; i++) {       cin >> a[i];       vis[1][a[i]] = 0;     }     long long ans = 0;     for (long long i = 1; i <= m; i++) {       if (vis[1][a[i]]) continue;       ans++;       dfs(a[i], 1);     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 998244353;   const int MAXN = 1000010;   int get() {     int x;     bool f = 0;     char c;     while (!isdigit(c = getchar()))       if (c ==  - ) f = 1;     x = c - 48;     while (isdigit(c = getchar())) x = (x << 1) + (x << 3) + c - 48;     if (f)       return -x;     else       return x;   }   int N, A[MAXN];   int add(int x, int v) {     x += v;     if (x >= MOD) x -= MOD;     return x;   }   int main() {     N = get();     for (int i = 1; i <= N; ++i) A[i] = get();     int F = 0, G = 0, v = 0;     for (int i = 1; i <= N; ++i) {       v = add(1LL * v * 2 % MOD, A[i]);       F = add(G, v);       G = add(G, F);     }     cout << F << endl;     return 0;   }
#include <iostream>   #include <algorithm>   #include <string.h>   #include <queue>   #include <vector>      #define INF 987654321      using namespace std;      int main() {       int t;       scanf( %d ,&t);       while(t--){           int a,b,flag=0;           scanf( %d %d ,&a,&b);           if(a==b)printf( YES n );           else if(a>b)printf( NO n );           else{               //여기가 실제로 계산해야되는 부분.               //2^n꼴은 무조건 1->2->4->8->16으로만 이동이 가능함.               // 3=11으로서, 3+1, 3+10, 3+11 3개가 가능함. 3->4,5,6다 가능하다.               // 7=111으로서, 7->8,9,10,11,12,13,14다 가능하다.               // 결국 우리가 그럼 찾아야 되는 값은 5,6과 같은 중간에 비는값이 있는 값들.                  // 5 = 101으로, 5+1, 5+100, 5+101.  5->6,9,10로 이동이 가능.               // 6 = 110으로, 6+10, 6+100, 6+110. 6->8,10,12로 이동이 가능.               // 결론. 3은 11,13,14를 못감. 8 =1000, 9=1001, 10=1010, 11=1011               // 와 그럼 3=11 숫자가 2개다보니, 11과 같이 3개가 필요한 곳은 못간다.               for(int i=0;i<30;i++)               {                 if((a>>i)&1)flag++;                 if((b>>i)&1)flag--;                 if(flag<0)                 {                     printf( NO n );                     break;                 }               }               if(flag>=0)               {                 printf( YES n );               }           }       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long f[1200];   long long mod = 1000000007;   int arr[1100];   long long pw(long long x, long long sum) {     long long res = 1, power = sum, val = x;     while (power) {       if (power & 1) {         res *= val;         res %= mod;       }       val *= val;       val %= mod;       power >>= 1ll;     }     return res;   }   int main() {     f[0] = 1;     for (int i = 1; i <= 1000; i++) f[i] = (f[i - 1] * i) % mod;     int n, m;     cin >> n >> m;     long long ans = f[n - m];     vector<int> vec;     for (int i = 0; i < m; i++) {       scanf( %d , &arr[i]);     }     sort(arr, arr + m);     if (!m)       vec.push_back(n);     else {       vec.push_back(arr[0] - 1);       for (int i = 1; i < m; i++) vec.push_back(arr[i] - arr[i - 1] - 1);       vec.push_back(n - arr[m - 1]);     }     long long sum = 1;     for (int i = 0; i < vec.size(); i++) sum = (sum * f[vec[i]]) % mod;     ans = (ans * pw(sum, mod - 2)) % mod;     for (int i = 1; i < vec.size() - 1; i++)       if (vec[i] - 1 && vec[i]) ans = (ans * pw(2, vec[i] - 1)) % mod;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e6 + 5;   const int inf = 1e9 + 5;   const double pi = acos(-1);   const int dx[] = {1, -1, 0, 0};   const int dy[] = {0, 0, 1, -1};   const int mod = 1e9 + 7;   int p[N], cnt[N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     ;     string s;     cin >> s;     int n = (int)(s).size();     memset(p, 0, sizeof p);     for (int i = 1; i < n; i++) {       int prev = p[i - 1];       while (prev > 0 && s[prev] != s[i]) prev = p[prev - 1];       if (s[prev] == s[i]) prev++;       p[i] = prev;     }     if (p[n - 1] == 0) {       if (p[p[n - 1] - 1] == 0) {         cout <<  Just a legend ;       } else {         cout << s.substr(0, p[p[n - 1] - 1]);       }     } else {       int cnt = 0;       for (int i = 0; i < n; i++) {         if (p[i] == p[n - 1]) {           ++cnt;         }       }       if (cnt >= 2) {         cout << s.substr(0, p[n - 1]);       } else {         if (p[p[n - 1] - 1] == 0) {           cout <<  Just a legend ;         } else {           cout << s.substr(0, p[p[n - 1] - 1]);         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s[10100];   string sep;   bool u[10100] = {false};   vector<string> str;   string make(pair<string, string> p) {     return ((p.first + sep + p.second) < (p.second + sep + p.first))                ? (p.first + sep + p.second)                : (p.second + sep + p.first);   }   int main() {     int n = 0, sumLeng = 0, len = 0;     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> s[i];       sumLeng += s[i].length();     }     cin >> sep;     len = sumLeng / (n / 2);     sort(s, s + n);     for (int i = 0; i < n; ++i) {       if (u[i]) continue;       int leng = s[i].length();       for (int j = 0; j < n; ++j)         if (!u[j] && leng + s[j].length() == len && i != j) {           str.push_back(make(make_pair(s[i], s[j])));           u[i] = true;           u[j] = true;           break;         }     }     sort(str.begin(), str.end());     for (int i = 0; i < n / 2; ++i) cout << str[i] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   using minpq = priority_queue<T, vector<T>, greater<T>>;   int n, m, k;   int arr[70][70];   int dp[71][71][36][71];   int func(int s, int e, int cnd, int rem) {     if (cnd >= m / 2) {       return -1e9;     }     if (s == n) {       if (rem == 0) {         return 0;       }       return -1e9;     }     if (e == m) {       return -1e9;     }     if (dp[s][e][cnd][rem] != -1) {       return dp[s][e][cnd][rem];     }     int ans = -1e9;     int nc = (rem + arr[s][e]) % k;     ans =         max({func(s, e + 1, cnd, rem), arr[s][e] + func(s, e + 1, cnd + 1, nc)});     ans = max({ans, func(s + 1, 0, 0, rem), arr[s][e] + func(s + 1, 0, 0, nc)});     return dp[s][e][cnd][rem] = ans;   }   void solve() {     memset(dp, -1, sizeof(dp));     cin >> n >> m >> k;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> arr[i][j];       }     }     int ans = func(0, 0, 0, 0);     if (ans < 0) {       ans = 0;     }     cout << ans << endl;   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int x, y;   char a[1001][1001];   int n, c[1000000], ni[5001][5001];   bool vis[1001][1001], b[1000000];   int e[] = {1, -1, 0, 0};   int r[] = {0, 0, -1, 1};   void dfs(int i, int j, int n) {     vis[i][j] = true;     ni[i][j] = n;     c[n]++;     for (int g = 0; g < 4; g++) {       int z = i + e[g], k = j + r[g];       if (a[z][k] ==  .  && z >= 0 && z < x && k >= 0 && k < y &&           vis[z][k] == false)         dfs(z, k, n);     }   }   int main() {     scanf( %d%d , &x, &y);     for (int i = 0; i < x; i++) scanf( %s , &a[i]);     int g = 1;     for (int i = 0; i < x; i++) {       for (int j = 0; j < y; j++) {         if (a[i][j] ==  .  && vis[i][j] == false) {           dfs(i, j, g);           g++;         }       }     }     for (int i = 0; i < x; i++) {       for (int j = 0; j < y; j++) {         if (a[i][j] ==  * ) {           int sum = 1;           for (int k = 0; k < 4; k++) {             int z = i + e[k], d = j + r[k];             if (a[z][d] ==  .  && b[ni[z][d]] == false && z >= 0 && z < x &&                 d >= 0 && d < y) {               sum += c[ni[z][d]];               b[ni[z][d]] = true;             }           }           a[i][j] = sum % 10 + 48;           for (int k = 0; k < 4; k++) {             int z = i + e[k], d = j + r[k];             if (z >= 0 && z < x && d >= 0 && d < y && a[z][d] ==  . ) {               b[ni[z][d]] = false;             }           }         }       }     }     for (int i = 0; i < x; i++) {       for (int j = 0; j < y; j++) {         printf( %c , a[i][j]);       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long x = 0, f = 1;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) {       x = (x << 3) + (x << 1) + (c ^ 48);       c = getchar();     }     return f == -1 ? ~x + 1 : x;   }   long long n;   vector<long long> ve[11];   long long sum[11];   const long long N = 1e6, mod1 = 998244353, mod2 = 1e9 + 7;   long long cnt, tmp, ans;   long long m1(long long x) { return (x % mod1 + mod1) % mod1; }   void dfs1(long long x, long long v) {     if (v > n) return;     if (x > 6) return;     ++cnt;     ve[x].push_back(m1(cnt - v));     sum[x] += m1(cnt - v);     for (long long i = 0; i < 10; ++i) dfs1(x + 1, v * 10 + i);   }   void dfs2(long long x, long long v) {     if (v > n) return;     if (x >= 1) {       if (v * N * 10 > n && v * N + N - 1 <= n) {         for (long long i = 0, t = 1; i <= 6; ++i, t *= 10) {           long long val = m1(cnt - v * t);           long long pos =               lower_bound(ve[i].begin(), ve[i].end(), mod1 - val) - ve[i].begin();           (ans += val * ve[i].size() + sum[i] - mod1 * (ve[i].size() - pos)) %=               mod2;         }         cnt += tmp;         return;       }       ++cnt;       (ans += m1(cnt - v)) %= mod2;     }     for (long long i = (x == 0 ? 1 : 0); i <= 9; ++i) dfs2(x + 1, v * 10 + i);   }   signed main() {     n = read();     dfs1(0, 0);     tmp = cnt;     cnt = 0;     for (long long i = 0; i <= 6; ++i) sort(ve[i].begin(), ve[i].end());     dfs2(0, 0);     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 10;   const int inf = 2000000000;   int f(int first, int second, int t[N]) {     int a[N], b[N];     for (int i = 0; i < N; i++) {       a[i] = b[i] = t[i];     }     a[first]--;     b[second]--;     if (a[first] < 0 || b[second] < 0) {       return -1;     }     if ((first + second) != 10) {       return 0;     }     int cur = 1;     for (int i = 0; i < N; i++) {       cur += min(a[i], b[N - i - 1]);     }     return cur;   }   pair<string, string> get(int a[N], pair<pair<int, int>, int> code) {     int q[N], w[N];     for (int i = 0; i < N; i++) {       q[i] = w[i] = a[i];     }     string s, t;     for (int i = 0; i < code.second; i++) {       s +=  0 ;       t +=  0 ;       q[0]--;       w[0]--;     }     int first = code.first.first;     int second = code.first.second;     s += char(first +  0 );     t += char(second +  0 );     q[first]--;     w[second]--;     for (int i = 0; i < N; i++) {       int val = min(q[i], w[N - i - 1]);       for (int j = 0; j < val; j++) {         s += char(i +  0 );         t += char(N - i - 1 +  0 );       }       q[i] -= val;       w[N - i - 1] -= val;     }     for (int i = 0; i < N; i++) {       for (int j = 0; j < q[i]; j++) {         s += char(i +  0 );       }       for (int j = 0; j < w[i]; j++) {         t += char(i +  0 );       }     }     reverse((s).begin(), (s).end());     reverse((t).begin(), (t).end());     return {s, t};   }   int main() {     cin.tie(0);     ios_base::sync_with_stdio(0);     string s;     cin >> s;     int a[N];     memset(a, 0, sizeof(a));     int n = s.length();     for (int i = 0; i < n; i++) {       a[s[i] -  0 ]++;     }     int best = -1;     pair<pair<int, int>, int> code;     for (int i = 0; i <= a[0]; i++) {       int b[N];       for (int j = 0; j < N; j++) {         b[j] = a[j];       }       b[0] -= i;       for (int first = 0; first < N; first++) {         for (int second = 0; second < N; second++) {           int cur = f(first, second, b);           if (cur + i > best) {             best = cur + i;             code = {{first, second}, i};           }         }       }     }     pair<string, string> ans = get(a, code);     cout << ans.first <<   n  << ans.second;   }
#include <bits/stdc++.h>   using namespace std;   const string nameFile =  test ;   ifstream in(nameFile +  .in );   ofstream out(nameFile +  .out );   const int nmax = 4e3;   int n, nrGond;   char ch;   int a[nmax + 2][nmax + 2];   int dp[802][nmax + 2];   char buffer[10000];   inline int getCost(int i, int j) {     return (a[j][j] + a[i - 1][i - 1] - a[j][i - 1] - a[i - 1][j]) / 2;   }   void divideDp(int ll, int rr, int limLeftSrc, int limRightSrc, int layer) {     if (ll > rr) return;     int mij = (ll + rr) / 2;     pair<int, int> ob = {1e9, 0};     for (int i = limLeftSrc; i <= min(mij, limRightSrc); i++)       ob = min(ob, {getCost(i, mij) + dp[layer - 1][i - 1], i});     dp[layer][mij] = ob.first;     divideDp(ll, mij - 1, limLeftSrc, ob.second, layer);     divideDp(mij + 1, rr, ob.second, limRightSrc, layer);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     scanf( %d%d n , &n, &nrGond);     for (int i = 1; i <= n; i++) {       gets(buffer);       for (int j = 1; j <= n; j++)         a[i][j] = buffer[2 * (j - 1)] -  0  + a[i - 1][j] + a[i][j - 1] -                   a[i - 1][j - 1];     }     for (int i = 1; i <= n; i++) dp[0][i] = 1e9;     for (int i = 1; i <= nrGond; i++) divideDp(i, n, i, n, i);     cout << dp[nrGond][n];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, ta;   long double x[1005][1005], tb, tc, td;   vector<int> y;   vector<long double> z;   bool used[1005];   int main() {     scanf( %d , &n);     for (int a = 0; a < n; a++)       for (int b = 0; b < n; b++) {         scanf( %d , &ta);         x[a][b] = ta;         x[a][b] /= 100;       }     y.push_back(n - 1);     z.push_back(0);     used[n - 1] = 1;     while (y.back() != 0) {       ta = -1;       for (int a = 0; a < n; a++)         if (!used[a]) {           tb = 0;           tc = 1;           for (int b = 0; b < y.size(); b++) {             tb += (z[b] + 1) * tc * x[a][y[b]];             tc *= 1 - x[a][y[b]];           }           if (abs(tc - 1) < 1e-11) continue;           tb = (tb + tc) / (1 - tc);           if (ta == -1 || tb < td) {             ta = a;             td = tb;           }         }       y.push_back(ta);       z.push_back(td);       for (int a = z.size() - 1; a >= 1; a--) {         if (z[a] >= z[a - 1]) break;         swap(z[a], z[a - 1]);         swap(y[a], y[a - 1]);       }       used[ta] = 1;     }     printf( %.15lf n , (double)z.back());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int i, j, n, m, a, b, tmp;   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   int main() {     cin >> n >> m >> a >> b;     tmp = n * m / gcd(n, m);     cout << b / tmp - (a - 1) / tmp;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 10005;   vector<int> gr[N];   int ans = 0;   void dfs(int v, int p = -1) {     for (int to : gr[v])       if (to != p) {         dfs(to, v);         ans += (gr[to].size() - 1);       }     ans += ((gr[v].size() - (v != 1)) * (gr[v].size() - 1 - (v != 1))) / 2;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i < n; ++i) {       int a, b;       scanf( %d%d , &a, &b);       gr[a].push_back(b);       gr[b].push_back(a);     }     dfs(1);     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = int64_t;   using u64 = uint64_t;   using u32 = uint32_t;   struct Node {     int idx;     Node *left = nullptr, *right = nullptr;   };   int depth(Node* v) {     if (!v) return 0;     return max(depth(v->left), depth(v->right)) + 1;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n;     vector<int> a(n);     for (auto& ai : a) cin >> ai;     auto it = min_element(begin(a), end(a));     int orig_shift = (n - (it - begin(a))) % n;     rotate(begin(a), it, end(a));     int left = 0, right = n;     vector<int> b(n);     vector<Node> nodes(n);     for (int i = 0; i < n; ++i) nodes[i].idx = i;     vector<Node*> stack;     int mind = n;     while (right - left > 1) {       for (auto& node : nodes) node.left = node.right = nullptr;       stack.clear();       int mid = (left + right) / 2;       int start = (n - mid) % n;       for (int i = start; i < n + start; ++i) {         Node* left = nullptr;         while (!stack.empty() && a[stack.back()->idx] > a[i % n]) {           left = stack.back();           stack.pop_back();         }         if (!stack.empty()) stack.back()->right = &nodes[i % n];         if (right) nodes[i % n].left = left;         stack.push_back(&nodes[i % n]);       }       Node* root = stack.front();       auto ldepth = depth(root->left);       auto rdepth = depth(root->right);       mind = min(mind, max(ldepth, rdepth) + 1);       if (ldepth == rdepth) {         cout << (ldepth + 1) <<     << ((n - mid - orig_shift + n) % n) <<   n ;         return 0;       } else if (ldepth > rdepth) {         right = mid;       } else {         left = mid;       }     }     cout << mind <<     << ((n - left - orig_shift + n) % n) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   typedef long long ll;   #define fastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);   int main()   {          fastIO       int t;       cin>>t;       while(t--)       {           int x,y;           cin>>x>>y;              if (x==y)                cout<<x+y<<  n ;           else                 cout<<max(x,y)*2-1<<  n ;          }                                                }