malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 3;   struct tree {     long long sum;     int tag;     int lc;     int rc;   } a[N << 1];   long long s[N];   int n, m, t = 1;   long long ans;   long long win;   vector<pair<long long, long long> > other, change;   inline int read() {     int v = 0, c = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) c = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       v = v * 10 + ch - 48;       ch = getchar();     }     return v * c;   }   inline void pushup(int u) { a[u].sum = a[a[u].lc].sum + a[a[u].rc].sum; }   inline void pushdown(int u, int l, int r) {     if (a[u].tag) {       int mid = (l + r) >> 1;       a[a[u].lc].sum = mid - l + 1 - a[a[u].lc].sum;       a[a[u].lc].tag ^= 1;       a[a[u].rc].sum = r - mid - a[a[u].rc].sum;       a[a[u].rc].tag ^= 1;     }     a[u].tag = 0;   }   void build(int u, int l, int r) {     if (l == r) return;     int mid = (l + r) >> 1;     a[u].lc = ++t;     build(a[u].lc, l, mid);     a[u].rc = ++t;     build(a[u].rc, mid + 1, r);     pushup(u);   }   long long query(int u, int l, int r, int ll, int rr, int w) {     if (l == ll && r == rr) {       if (w == 1) return a[u].sum;       return r - l + 1 - a[u].sum;     }     pushdown(u, l, r);     int mid = (l + r) >> 1;     if (rr <= mid)       return query(a[u].lc, l, mid, ll, rr, w);     else if (ll > mid)       return query(a[u].rc, mid + 1, r, ll, rr, w);     else       return query(a[u].lc, l, mid, ll, mid, w) +              query(a[u].rc, mid + 1, r, mid + 1, rr, w);   }   void updata(int u, int l, int r, int ll, int rr) {     if (l == ll && r == rr) {       a[u].sum = r - l + 1 - a[u].sum;       a[u].tag ^= 1;       return;     }     pushdown(u, l, r);     int mid = (l + r) >> 1;     if (rr <= mid)       updata(a[u].lc, l, mid, ll, rr);     else if (ll > mid)       updata(a[u].rc, mid + 1, r, ll, rr);     else {       updata(a[u].lc, l, mid, ll, mid);       updata(a[u].rc, mid + 1, r, mid + 1, rr);     }     pushup(u);   }   int main() {     n = read(), m = read();     for (int i = 1; i <= n; ++i) s[i] = (long long)read();     sort(s + 1, s + n + 1);     for (int i = 1; i <= m; ++i) {       int l = read(), r = read();       l = lower_bound(s + 1, s + n + 1, l) - s;       r = upper_bound(s + 1, s + n + 1, r) - s - 1;       if (l > r) continue;       change.push_back(make_pair(l, r));       other.push_back(make_pair(r, l));     }     build(1, 1, n);     sort(change.begin(), change.end());     sort(other.begin(), other.end());     ans = (long long)(n - 2) * (n - 1) * n / 6;     for (int i = 1, r = 0, l = 0; i <= n; ++i) {       while (l < change.size() && change[l].first == i) {         updata(1, 1, n, change[l].first, change[l].second);         l++;       }       win = 0;       if (i != 1) win += query(1, 1, n, 1, i - 1, 0);       if (i != n) win += query(1, 1, n, i + 1, n, 1);       ans -= win * (win - 1) / 2;       while (r < other.size() && other[r].first == i) {         updata(1, 1, n, other[r].second, other[r].first);         r++;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   const double PI = acos(-1);   template <class A, class B>   std::ostream& operator<<(std::ostream& st, const std::pair<A, B> p) {     st <<  (  << p.first <<  ,   << p.second <<  ) ;     return st;   }   using namespace std;   const int mod = 998244353;   int add(int a, int b) {     a += b;     if (a >= mod) a -= mod;     if (a < 0) a += mod;     return a;   }   int mul(int a, int b) { return (a * (long long)b) % mod; }   const int MAX = 500 * 1000 + 10;   int n, K, m;   int L[MAX], R[MAX], X[MAX];   int cnt[MAX];   int val[MAX];   int tail[MAX];   int p2[MAX];   int dp[MAX], sum[MAX];   int prv[MAX], nxt[MAX];   int solve(int b) {     static std::vector<std::pair<int, int> > V;     for (int i = 0; i < (n + 1); i++) cnt[i] = 0;     V.clear();     for (int i = 0; i < (m); i++) {       int x = (X[i] >> b) & 1;       if (x) {         cnt[L[i]]++;         cnt[R[i] + 1]--;       } else {         V.emplace_back(L[i], R[i]);       }     }     for (int i = 1; i <= n; i++) {       cnt[i] += cnt[i - 1];       val[i] = (cnt[i] > 0) + val[i - 1];     }     for (int i = 1, v = -1; i <= n; i++) {       if (!cnt[i]) v = i;       prv[i] = v;     }     for (int i = n, v = -1; i >= 1; i--) {       if (!cnt[i]) v = i;       nxt[i] = v;     }     for (int i = 1; i <= n; i++) tail[i] = -1;     for (auto p : V) {       int l = p.first, r = p.second;       int ctr = val[r] - val[l - 1];       if (ctr == r - l + 1) return 0;       l = nxt[l];       r = prv[r];       l = l - val[l];       r = r - val[r];       tail[r] = max(tail[r], l);     }     int m = n - val[n];     if (!m) return 1;     dp[0] = 1;     sum[0] = 1;     int L = 0;     for (int i = 1; i <= m; i++) {       dp[i] = add(sum[i - 1], L ? -sum[L - 1] : 0);       sum[i] = add(dp[i], sum[i - 1]);       L = max(L, tail[i]);     }     int ret = add(sum[m], L ? -sum[L - 1] : 0);     return ret;   }   int main() {     p2[0] = 1;     for (int i = 1; i < MAX; i++) p2[i] = mul(2, p2[i - 1]);     scanf( %d %d %d , &n, &K, &m);     for (int i = 0; i < (m); i++) scanf( %d %d %d , L + i, R + i, X + i);     int ans = 1;     for (int b = 0; b < (K); b++) {       ans = mul(ans, solve(b));       if (!ans) break;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   const int dx[] = {1, 0, -1, 0};   const int dy[] = {0, 1, 0, -1};   using namespace std;   const long long MOD = 1000000009;   const int MAXM = 100010;   int m;   long long pow_mod[MAXM];   int X[MAXM], Y[MAXM];   map<pair<int, int>, int> ma;   set<int> S;   set<int> up[MAXM], down[MAXM];   void init() {     pow_mod[0] = 1;     for (int i = 1; i < m; i++) {       pow_mod[i] = (pow_mod[i - 1] * m) % MOD;     }   }   bool ok(int k) {     for (auto el : up[k]) {       if (down[el].size() <= 1) return false;     }     return true;   }   int main() {     cin >> m;     init();     for (int i = 0; i < m; i++) {       cin >> X[i] >> Y[i];       ma.insert(make_pair(pair<int, int>(X[i], Y[i]), i));     }     for (auto el : ma) {       int y = el.first.second;       int x = el.first.first;       for (int d = -1; d <= 1; d++) {         pair<int, int> tmp = pair<int, int>(x + d, y + 1);         if (ma.count(tmp)) {           up[el.second].insert(ma[tmp]);           down[ma[tmp]].insert(el.second);         }       }     }     for (int i = 0; i < m; i++)       if (ok(i)) S.insert(i);     long long ret = 0;     for (int i = 0; i < m; i++) {       int er;       if (i % 2 == 0) {         er = *S.rbegin();       } else {         er = *S.begin();       }       ret += pow_mod[m - i - 1] * (long long)er % MOD;       ret %= MOD;       S.erase(er);       for (auto el : up[er]) {         down[el].erase(er);         if (ok(el))           S.insert(el);         else           S.erase(el);         for (auto ell : down[el]) {           if (ok(ell))             S.insert(ell);           else             S.erase(ell);         }       }       for (auto el : down[er]) {         up[el].erase(er);         if (ok(el))           S.insert(el);         else           S.erase(el);       }     }     cout << ret << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5 * 10000;   const long long mod = 1000000007;   void solve() {     int n;     cin >> n;     vector<int> a(n), b(n), c(n), d(n), e(n);     string str;     for (int i = 0; i < n; i++) {       cin >> str;       int qtd[] = {0, 0, 0, 0, 0};       for (char c : str) {         qtd[c -  a ]++;       }       a[i] = 2 * qtd[0] - str.length();       b[i] = 2 * qtd[1] - str.length();       c[i] = 2 * qtd[2] - str.length();       d[i] = 2 * qtd[3] - str.length();       e[i] = 2 * qtd[4] - str.length();     }     sort(a.rbegin(), a.rend());     sort(b.rbegin(), b.rend());     sort(c.rbegin(), c.rend());     sort(d.rbegin(), d.rend());     sort(e.rbegin(), e.rend());     int ans = 0;     int sum = 0, i = 0;     while (i < n && sum + a[i] > 0) {       sum += a[i];       i++;     }     ans = max(ans, i);     sum = 0, i = 0;     while (i < n && sum + b[i] > 0) {       sum += b[i];       i++;     }     ans = max(ans, i);     sum = 0, i = 0;     while (i < n && sum + c[i] > 0) {       sum += c[i];       i++;     }     ans = max(ans, i);     sum = 0, i = 0;     while (i < n && sum + d[i] > 0) {       sum += d[i];       i++;     }     ans = max(ans, i);     sum = 0, i = 0;     while (i < n && sum + e[i] > 0) {       sum += e[i];       i++;     }     ans = max(ans, i);     cout << ans <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int tt = 1;     cin >> tt;     while (tt--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     char ch1, ch2, ch;     int i, j, k, tc, res, total, temp, mx, num, num1, num2;     int n, a, b;     {       scanf( %d %d %d , &n, &a, &b);       if (b == 0)         printf( %d n , a);       else if (b > 0) {         while (b--) {           if (a == n)             a = 1;           else             a++;         }         printf( %d n , a);       } else {         b = (-1 * b);         while (b--) {           if (a == 1)             a = n;           else             a--;         }         printf( %d n , a);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, aa, bb;     cin >> a >> b;     a += 100;     b += 100;     cin >> aa >> bb;     aa += 100;     bb += 100;     if (aa != a && bb != b) {       int tmp = (abs(a - aa));       int tmp2 = (abs(b - bb));       cout << 2 * abs(tmp2 + tmp) + 4;     } else       cout << max(8, (6 + (abs(a - aa) + abs(b - bb)) * 2));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     vector<int> a(n);     for (auto &i : a) scanf( %d , &i);     map<int, int> dp;     int ans = 0;     int last = 0;     for (int i = 0; i < n; i++) {       int x = a[i];       dp[x] = dp[x - 1] + 1;       if (ans < dp[x]) {         ans = dp[x];         last = x;       }     }     vector<int> res;     for (int i = n - 1; i >= 0; i--) {       if (a[i] == last) {         res.push_back(i);         last--;       }     }     reverse(res.begin(), res.end());     printf( %d n , ans);     for (auto &i : res) printf( %d  , i + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int id = 0;   vector<int> group(2e5 + 5, -1);   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int N;     cin >> N;     vector<int> A(N);     for (int i = 0; i < N; i++) cin >> A[i];     string S;     cin >> S;     for (int i = 0; i < N; i++) {       if (group[A[i]] != -1) continue;       group[A[i]] = id;       int j = i;       while (j + 1 < N && S[j] ==  1 ) group[A[++j]] = id;       id++;     }     for (int i = 0; i < N; i++) {       if (A[i] == i + 1) continue;       if (group[i + 1] != group[A[i]]) {         cout <<  NO n ;         return 0;       }     }     cout <<  YES n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[200005];   int alph[26];   int main() {     scanf( %s , &s);     for (int i = 0; s[i]; i++) alph[s[i] -  a ]++;     for (int i = 0; i < 26; i++)       for (int j = 26 - 1; j > i; j--)         if (alph[i] & 1)           if (alph[j] & 1) alph[i]++, alph[j]--;     int odd = -1;     for (int i = 0; i < 26; i++)       if (alph[i] & 1) odd = i;     for (int i = 0; i < 26; i++)       for (int j = 1; j <= alph[i] / 2; j++) printf( %c , i +  a );     if (odd != -1) printf( %c , odd +  a );     for (int i = 26 - 1; i >= 0; i--)       for (int j = 1; j <= alph[i] / 2; j++) printf( %c , i +  a );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t;     cin >> n >> t;     if (n == 1 && t == 10)       cout << -1 << endl;     else {       cout << t;       if (t == 10) n--;       for (int i = 0; i < n - 1; i++) cout << 0;       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char tbl[209][209];   int vid[209][209];   int hid[209][209];   int n, m;   vector<int> G[100009];   int pr[100009];   int was[100009];   int wcnt;   bool vert(int x, int y) { return vid[x][y] > 0; }   bool improve(int x) {     was[x] = wcnt;     for (int nb : G[x]) {       if (was[nb] < wcnt) {         if (pr[nb] == nb) {           pr[nb] = x;           pr[x] = nb;           return true;         }         was[nb] = wcnt;         if (improve(pr[nb])) {           pr[nb] = x;           pr[x] = nb;           return true;         }       }     }     return false;   }   int h2 = 0;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> tbl[i][j];         if (tbl[i][j] ==  # ) h2++;       }     }     int cnt = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j < m; j++) {         if (tbl[i][j] ==  #  && tbl[i][j + 1] ==  # ) {           cnt++;           vid[i][j] = cnt;         }       }     }     int rows = cnt;     for (int i = 1; i < n; i++) {       for (int j = 1; j <= m; j++) {         if (tbl[i][j] ==  #  && tbl[i + 1][j] ==  # ) {           cnt++;           hid[i][j] = cnt;         }       }     }     for (int i = 1; i < n; i++) {       for (int j = 1; j <= m; j++) {         if (tbl[i][j] ==  #  && tbl[i + 1][j] ==  # ) {           if (vert(i, j - 1)) {             G[hid[i][j]].push_back(vid[i][j - 1]);             G[vid[i][j - 1]].push_back(hid[i][j]);           }           if (vert(i, j)) {             G[hid[i][j]].push_back(vid[i][j]);             G[vid[i][j]].push_back(hid[i][j]);           }           if (vert(i + 1, j - 1)) {             G[hid[i][j]].push_back(vid[i + 1][j - 1]);             G[vid[i + 1][j - 1]].push_back(hid[i][j]);           }           if (vert(i + 1, j)) {             G[hid[i][j]].push_back(vid[i + 1][j]);             G[vid[i + 1][j]].push_back(hid[i][j]);           }         }       }     }     for (int i = 1; i <= cnt; i++) {       pr[i] = i;     }     int ans = 0;     for (int i = 1; i <= rows; i++) {       if (pr[i] == i) {         wcnt++;         if (improve(i)) ans++;       }     }     cout << h2 - (cnt - ans) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const unsigned int MOD = 1000000007;   void solve() {     string s;     cin >> s;     string t;     cin >> t;     vector<char> v;     bool check1 = false;     bool check2 = false;     bool check3 = false;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  a ) {         check1 = true;       }       if (s[i] ==  b ) {         check2 = true;       }       if (s[i] ==  c ) {         check3 = true;       }     }     if (t[0] ==  a  && t[1] ==  b  && t[2] ==  c  && check1 && check2 && check3) {       for (int j = 0; j < s.length(); j++) {         if (s[j] ==  a ) {           v.push_back(s[j]);         }       }       for (int j = 0; j < s.length(); j++) {         if (s[j] ==  c ) {           v.push_back(s[j]);         }       }       for (int j = 0; j < s.length(); j++) {         if (s[j] ==  b ) {           v.push_back(s[j]);         }       }     } else {       for (int j = 0; j < s.length(); j++) {         if (s[j] ==  a ) {           v.push_back(s[j]);         }       }       for (int j = 0; j < s.length(); j++) {         if (s[j] ==  b ) {           v.push_back(s[j]);         }       }       for (int j = 0; j < s.length(); j++) {         if (s[j] ==  c ) {           v.push_back(s[j]);         }       }     }     sort(s.begin(), s.end());     for (int i = 0; i < s.length(); i++) {       if (s[i] !=  a  && s[i] !=  b  && s[i] !=  c ) {         v.push_back(s[i]);       }     }     for (auto it : v) {       cout << it;     }     cout << endl;   }   signed main() {     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 220, maxm = 220 * 220;   struct edge {     int s, t, next;   } e[maxm];   struct vtx {     int dfn, low, belong, leave;     bool instack;   } ver[maxn];   int hd[maxn], cnt, ind, sta[maxn], top, bcnt;   void insert(int a, int b) {     e[cnt].next = hd[a];     hd[a] = cnt;     e[cnt].t = b;     e[cnt].s = a;     cnt++;   }   vector<int> bcc[maxn];   void tarjanSCC(int u) {     ver[u].dfn = ver[u].low = ind++;     ver[u].instack = true;     sta[top++] = u;     for (int i = hd[u]; i != -1; i = e[i].next) {       int v = e[i].t;       if (!ver[v].dfn) {         tarjanSCC(v);         ver[u].low = min(ver[u].low, ver[v].low);       }       if (ver[v].instack) ver[u].low = min(ver[u].low, ver[v].dfn);     }     if (ver[u].dfn == ver[u].low) {       bcnt++;       int j = -1;       do {         j = sta[--top];         ver[j].belong = bcnt;         bcc[bcnt].push_back(j);         ver[j].instack = false;       } while (j != u);     }     ver[u].leave = ind;   }   void tarjanInit() {     memset(hd, -1, sizeof hd);     memset(ver, 0, sizeof ver);     ind = top = 1;     cnt = 0;   }   int ord[maxn];   bool cmp(int i, int j) { return ver[i].leave < ver[j].leave; }   bool twoSat(int n, int *sel) {     for (int i = 0; i < 2 * n; i++) bcc[i].clear();     for (int i = 0; i < 2 * n; i++)       if (!ver[i].dfn) tarjanSCC(i);     for (int i = 0; i < n; i++)       if (ver[i * 2].belong == ver[i * 2 + 1].belong) return false;     for (int i = 0; i < 2 * n; i++) ord[i] = i;     sort(ord, ord + 2 * n, cmp);     memset(sel, -1, n * sizeof(int));     for (int i = 0; i < 2 * n; i++) {       if (sel[ord[i] >> 1] != -1)         continue;       else {         int c = ver[ord[i]].belong;         for (int j = 0; j < (int)bcc[c].size(); j++)           sel[bcc[c][j] >> 1] = (bcc[c][j] & 1);       }     }     return true;   }   bool intersect(int a1, int a2, int b1, int b2) {     if (a1 > a2) swap(a1, a2);     if (b1 > b2) swap(b1, b2);     return a1 == b1 ? 0                     : (a1 < b1 ? (a2 - b1) * (a2 - b2) < 0                                : (b2 - a1) * (b2 - a2) < 0);   }   int ans[110];   int main() {     int n, m, p[110][2];     scanf( %d%d , &n, &m);     tarjanInit();     for (int i = 0; i < m; i++) {       scanf( %d%d , &p[i][0], &p[i][1]);     }     for (int i = 0; i < m; i++) {       for (int j = 0; j < i; j++) {         if (intersect(p[i][0], p[i][1], p[j][0], p[j][1])) {           insert(i * 2, j * 2 + 1);           insert(i * 2 + 1, j * 2);           insert(j * 2, i * 2 + 1);           insert(j * 2 + 1, i * 2);         }       }     }     if (twoSat(m, ans)) {       for (int i = 0; i < m; i++) {         if (ans[i])           printf( i );         else           printf( o );       }     } else       printf( Impossible );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ull = unsigned long long;   using vi = vector<int>;   using ii = pair<int, int>;   using vii = vector<pair<int, int>>;   void solve() {     int n;     cin >> n;     int r = 0;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         int x;         cin >> x;         if (i == j) r += x;       }     }     r %= 2;     string res;     int q;     cin >> q;     while (q--) {       int t;       cin >> t;       if (t == 3)         res += to_string(r);       else if (t == 1 || t == 2) {         int waste;         cin >> waste;         r ^= 1;       }     }     cout << res <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int tc = 1;     while (tc--) solve();   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   void solve() {     int n;     cin >> n;     vector<set<int>> v(n + 1);     for (int i = 0; i < n - 2; i++) {       int x, y, z;       cin >> x >> y >> z;       v[x].insert(y);       v[x].insert(z);       v[y].insert(x);       v[y].insert(z);       v[z].insert(x);       v[z].insert(y);     }     vector<int> res(n);     for (int i = 1; i < n + 1; i++) {       if (((int)(v[i]).size()) == 2) {         res[0] = i;         break;       }     }     vector<bool> been(n + 1);     int num1 = res[0], num2;     int can1 = *v[num1].begin(), can2 = *v[num1].rbegin();     if (((int)(v[can1]).size()) == 3)       num2 = can1;     else       num2 = can2;     res[1] = num2;     been[num1] = been[num2] = 1;     for (int i = 2; i < n - 2; i++) {       vector<int> can;       for (auto& j : v[num1]) {         if (been[j]) continue;         can.push_back(j);       }       for (auto& j : v[num2]) {         if (been[j]) continue;         can.push_back(j);       }       sort(can.begin(), can.end());       int num = 0;       for (int j = 0; j < ((int)(can).size()) - 1; j++) {         if (can[j] == can[j + 1]) {           num = can[j];           break;         }       }       been[num] = 1;       res[i] = num;       num1 = num2;       num2 = num;     }     for (int i = 1; i < n + 1; i++) {       if (((int)(v[i]).size()) == 3 && !been[i]) {         res[n - 2] = i;       } else if (((int)(v[i]).size()) == 2 && !been[i]) {         res[n - 1] = i;       }     }     for (auto& i : res) cout << i <<    ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int _ = 5e5 + 7;   int n, m, a[_], b[_];   bool check(int mid) {     memset(b, -1, sizeof(b));     b[0] = 0;     for (int i = 1; i <= n; ++i) {       int L = a[i], R = (a[i] + mid) % m;       if (L <= R) {         if (b[i - 1] <= R)           b[i] = max(b[i - 1], L);         else           return 0;       } else {         if (R < b[i - 1] && b[i - 1] < L)           b[i] = L;         else           b[i] = b[i - 1];       }       if (b[i] < b[i - 1]) return 0;     }     return 1;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     int l = 0, r = m - 1, ans = 0;     while (l <= r) {       int mid = (l + r) >> 1;       if (check(mid))         ans = mid, r = mid - 1;       else         l = mid + 1;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>      using namespace std;      int main(){       //freopen( input.inp , r ,stdin);       //freopen( output.out , w ,stdout);       ios::sync_with_stdio(0);       cin.tie(0);       int t;       cin >> t;       while (t--){           int a,b;           cin >> a >> b;           int ans = 0;           for (int i = 0; i < min(a,b);i++) ans+=2;            if (a != b){               for (int i = min(a,b); i < max(a,b);i++){                   ans+=2;               }               ans--;           }           cout << ans << endl;       }       return 0;   }