malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cerr.tie(0);     string a;     cin >> a;     vector<int> res[2];     for (char e : a) {       vector<int> ne[2];       if (e ==  a ) {         ne[0] = res[1];         ne[0].push_back(1);         ne[1] = res[1];         ne[1].push_back(0);       } else {         ne[0] = res[0];         ne[0].push_back(0);         ne[1] = res[0];         ne[1].push_back(1);       }       res[0] = ne[0];       res[1] = ne[1];     }     for (int e : res[0]) {       cout << e <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   int v, m, d, f;   int main() {     int n, a, b, c;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a >> b >> c;       if (a == 1) {         v += b;         m += c;       } else {         d += b;         f += c;       }     }     if (v >= m)       cout <<  LIVE  <<   n ;     else       cout <<  DEAD  <<   n ;     if (d >= f)       cout <<  LIVE  <<   n ;     else       cout <<  DEAD  <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dx[] = {0, 0, 1, -1, -1, -1, 1, 1};   int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};   template <class T>   inline T biton(T n, T pos) {     return n | ((T)1 << pos);   }   template <class T>   inline T bitoff(T n, T pos) {     return n & ~((T)1 << pos);   }   template <class T>   inline T ison(T n, T pos) {     return (bool)(n & ((T)1 << pos));   }   template <class T>   inline T gcd(T a, T b) {     while (b) {       a %= b;       swap(a, b);     }     return a;   }   template <typename T>   string NumberToString(T Number) {     ostringstream second;     second << Number;     return second.str();   }   inline int nxt() {     int aaa;     scanf( %d , &aaa);     return aaa;   }   inline long long int lxt() {     long long int aaa;     scanf( %lld , &aaa);     return aaa;   }   inline double dxt() {     double aaa;     scanf( %lf , &aaa);     return aaa;   }   template <class T>   inline T bigmod(T p, T e, T m) {     T ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p) % m;       p = (p * p) % m;     }     return (T)ret;   }   int ar[200010];   vector<int> v;   map<int, int> mp;   int main() {     int c = 0;     int i = 1;     while (1) {       if (c > 100000) break;       c += i;       v.push_back(c);       mp[c] = i;       i++;     }     int n = nxt();     if (n == 0) {       cout <<  a  << endl;       return 0;     }     vector<int> ans;     while (n) {       for (int i = v.size() - 1; i >= 0; i--) {         if (v[i] <= n) {           ans.push_back(v[i]);           n -= v[i];         }       }     }     int t = 0;     for (int i = 0; i < ans.size(); i++) {       int x = ans[i];       int lagbe = mp[x];       for (int j = 0; j <= lagbe; j++) {         printf( %c , t +  a );       }       t++;     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 0x3f3f3f3f;   const long long MOD = 1e9 + 7;   const long double EPS = 1e-9;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string grid[3][3][3];     for (int i = 0; i < 3; i++) {       for (int j = 0; j < 3; j++) {         for (int k = 0; k < 3; k++) {           cin >> grid[i][k][j];         }       }     }     int a, b;     cin >> a >> b;     int gi = (a - 1) % 3;     int gj = (b - 1) % 3;     bool shit = true;     for (int i = 0; i < 3; i++) {       for (int j = 0; j < 3; j++) {         if (grid[gi][gj][i][j] ==  . ) shit = false;       }     }     for (int i = 0; i < 3; i++) {       for (int j = 0; j < 3; j++) {         for (int k = 0; k < 3; k++) {           if (shit || i == gi && k == gj) {             for (int l = 0; l < 3; l++) {               if (grid[i][k][j][l] ==  . )                 cout <<  ! ;               else                 cout << grid[i][k][j][l];             }             cout <<    ;           } else {             cout << grid[i][k][j] <<    ;           }         }         cout <<   n ;       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);     long long n, m;     cin >> n >> m;     map<long long, set<long long>> adj;     for (long long i = 0; i < m; i++) {       long long a, b;       cin >> a >> b;       adj[a].insert(b);       adj[b].insert(a);     }     long long mx = INT_MIN, v = 0;     map<long long, long long> deg;     for (auto i : adj) {       deg[i.first] = i.second.size();       if (mx < i.second.size()) {         mx = i.second.size();         v = i.first;       }     }     deg[v] = 0;     for (auto i : adj[v]) {       deg[i]--;     }     long long f = 0;     for (long long i = 1; i <= n; i++) {       if (deg[i] > 0) {         f = 1;         break;       }     }     if (!f) {       cout <<  YES n ;       return 0;     }     mx = INT_MIN, v = 0;     for (long long i = 1; i <= n; i++) {       if (mx < deg[i]) {         mx = deg[i];         v = i;       }     }     deg[v] = 0;     for (auto i : adj[v]) {       deg[i]--;     }     f = 0;     for (long long i = 1; i <= n; i++) {       if (deg[i] > 0) {         f = 1;         break;       }     }     if (!f) {       cout <<  YES n ;       return 0;     }     cout <<  NO n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1);   inline double cross(double x1, double y1010101010101, double x2, double y2) {     return x1 * x2 + y1010101010101 * y2;   }   inline double len(double x, double y) { return sqrt(x * x + y * y); }   inline double angle(double x1, double y1010101010101, double x2, double y2) {     if (x1 == 0 && y1010101010101 == 0) return pi;     if (x2 == 0 && y2 == 0) return pi;     return acos(cross(x1, y1010101010101, x2, y2) / len(x1, y1010101010101) /                 len(x2, y2));   }   int n, x[100005], y[100005], cur = 0;   struct data {     double tx, ty;     int fx, fy;     int cx, cy;     data operator~() {       data ans = *this;       ans.tx = -ans.tx;       ans.ty = -ans.ty;       ans.cx = -ans.cx;       ans.cy = -ans.cy;       return ans;     }   } d[100005 << 5];   inline data add(int x, int y, int cx, int cy) {     data ans;     ans.tx = d[x].tx * cx + d[y].tx * cy;     ans.ty = d[x].ty * cx + d[y].ty * cy;     ans.cx = cx;     ans.cy = cy;     ans.fx = x;     ans.fy = y;     return ans;   }   int neg[100005 << 5];   inline void dump(int x) {     if (x <= n) return;     neg[d[x].fx] = neg[x] * d[x].cx;     neg[d[x].fy] = neg[x] * d[x].cy;     dump(d[x].fx);     dump(d[x].fy);   }   inline void dfs(int x, int y, int z, int w) {     if (z == n + 1) {       d[++cur] = ~d[x];       d[++cur] = ~d[y];       vector<int> t;       t.push_back(x);       t.push_back(y);       t.push_back(cur - 1);       t.push_back(cur);       for (int i = 0; i < 4; i += 2)         for (int j = 1; j < 4; j += 2) {           int u = t[i], v = t[j];           if (len(d[u].tx + d[v].tx, d[u].ty + d[v].ty) <= 1500000.0) {             if (i == 2)               neg[x] = -1;             else               neg[x] = 1;             if (j == 3)               neg[y] = -1;             else               neg[y] = 1;             dump(x);             dump(y);             return;           }         }     }     d[++cur] = ~d[x];     d[++cur] = ~d[y];     d[++cur] = ~d[z];     vector<int> t;     t.push_back(x);     t.push_back(y);     t.push_back(z);     t.push_back(cur - 2);     t.push_back(cur - 1);     t.push_back(cur);     for (int i = 0; i < 6; i++)       for (int j = 0; j < i; j++) {         if ((i % 3) == (j % 3)) continue;         int a = t[i], b = t[j];         if (angle(d[a].tx, d[a].ty, d[b].tx, d[b].ty) >= 2.0 * pi / 3) {           d[++cur] = add(a, b, 1, 1);           int nxt = 3 - (i % 3) - (j % 3);           if (nxt == 0) dfs(cur, x, w, w + 1);           if (nxt == 1) dfs(cur, y, w, w + 1);           if (nxt == 2) dfs(cur, z, w, w + 1);           return;         }       }   }   int main() {     scanf( %d , &n);     if (n == 1) return puts( 1 ), 0;     for (int i = 1; i <= n; i++) scanf( %d%d , &x[i], &y[i]);     for (int i = 1; i <= n; i++) {       d[i].tx = x[i];       d[i].ty = y[i];       d[i].fx = i;       d[i].fy = 0;       d[i].cx = 1;       d[i].cy = 0;     }     cur = n;     dfs(1, 2, 3, 4);     for (int i = 1; i <= n; i++) printf( %d  , neg[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   const int mod = 1e9 + 7;   const long long inf = 1e17;   char a[maxn], b[maxn], s[maxn];   int v[200];   int main() {     int q;     scanf( %s%s , a, b);     int n = strlen(a);     for (int i = 0; i < n; ++i) v[a[i]] = 1;     n = strlen(b);     scanf( %d , &q);     while (q--) {       scanf( %s , s);       int len = strlen(s);       int o = len - n + 1;       if (o < 0) {         puts( NO );         continue;       }       int i = 0, j = 0, k;       while (i < n) {         if (b[i] == s[j]) {           i++;           j++;         } else if (b[i] ==  ?  && v[s[j]]) {           i++;           j++;         } else if (b[i] ==  * ) {           for (k = 0; k < o && j < len; ++k, ++j)             if (v[s[j]]) break;           if (k < o) break;           i++;         } else {           break;         }       }       if (i < n || j < len)         puts( NO );       else         puts( YES );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct hehe {     unsigned long long l, r;     mutable bool z;     inline bool operator<(hehe y) const { return l < y.l; }   };   set<hehe> s;   inline set<hehe>::iterator split(unsigned long long pos) {     hehe qaq;     qaq.l = pos;     qaq.r = 0;     qaq.z = 0;     set<hehe>::iterator itp = s.lower_bound(qaq);     if (itp->l == pos && itp != s.end()) return itp;     itp--;     unsigned long long l = itp->l, r = itp->r;     bool val = itp->z;     s.erase(itp);     qaq.l = l;     qaq.r = pos - 1;     qaq.z = val;     s.insert(qaq);     qaq.l = pos;     qaq.r = r;     qaq.z = val;     set<hehe>::iterator ret = s.insert(qaq).first;     return ret;   }   inline unsigned long long read() {     unsigned long long s = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) ch = getchar();     while (ch >=  0  && ch <=  9 ) s = s * 10 + ch -  0 , ch = getchar();     return s;   }   inline void rev(unsigned long long l, unsigned long long r) {     set<hehe>::iterator itr, itl;     itr = split(r + 1);     itl = split(l);     for (set<hehe>::iterator it = itl; it != itr; ++it) it->z ^= 1;   }   inline void fz(unsigned long long l, unsigned long long r,                  unsigned long long val) {     set<hehe>::iterator itl, itr;     itr = split(r + 1);     itl = split(l);     s.erase(itl, itr);     hehe qwq;     qwq.l = l;     qwq.r = r;     qwq.z = val;     s.insert(qwq);   }   inline unsigned long long que() {     for (set<hehe>::iterator it = s.begin(); it != s.end(); ++it) {       if (it->z == 0) return it->l;     }     return 1000000000000000001llu;   }   signed main() {     unsigned long long n;     n = read();     hehe qwq;     qwq.l = 1;     qwq.r = 1000000000000000000llu;     qwq.z = 0;     s.insert(qwq);     while (n--) {       unsigned long long opt, l, r;       opt = read();       l = read();       r = read();       if (opt == 1)         fz(l, r, 1);       else if (opt == 2)         fz(l, r, 0);       else if (opt == 3)         rev(l, r);       printf( %lld n , que());     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   multiset<int> st;   multiset<int>::iterator it;   int arr[200000];   int main() {     int n, i, a, b, c, ans = 0, temp[3];     scanf( %d , &n);     scanf( %d , &temp[0]);     scanf( %d , &temp[1]);     scanf( %d , &temp[2]);     sort(temp, temp + 3);     a = temp[0];     b = temp[1];     c = temp[2];     for (i = 0; i < n; i++) {       scanf( %d , &arr[i]);       st.insert(-arr[i]);     }     for (i = 0; i < n; i++)       if (arr[i] > a + b + c) {         printf( -1 n );         return 0;       }     while (!st.empty()) {       it = st.lower_bound(-1 * (a + b + c));       if (it == st.end() or -1 * (*it) <= (b + c)) break;       st.erase(it);       ans++;     }     while (!st.empty()) {       it = st.lower_bound(-1 * (b + c));       if (it == st.end() or -1 * (*it) <= (a + c)) break;       st.erase(it);       it = st.lower_bound(-1 * (a));       if (it != st.end()) st.erase(it);       ans++;     }     while (!st.empty()) {       it = st.lower_bound(-1 * (a + c));       if (it == st.end() or -1 * (*it) <= (max(a + b, c))) break;       st.erase(it);       it = st.lower_bound(-1 * (b));       if (it != st.end()) st.erase(it);       ans++;     }     if ((a + b) > c) {       while (!st.empty()) {         it = st.lower_bound(-1 * (a + b));         if (it == st.end() or -1 * (*it) <= c) break;         st.erase(it);         it = st.lower_bound(-1 * (c));         if (it != st.end()) st.erase(it);         ans++;       }     }     while (!st.empty()) {       it = st.lower_bound(-1 * (c));       if (it == st.end()) break;       st.erase(it);       it = st.lower_bound(-1 * (b));       if (it != st.end()) {         st.erase(it);         it = st.lower_bound(-1 * (a));         if (it != st.end()) st.erase(it);       } else {         it = st.lower_bound(-1 * (a + b));         if (it != st.end()) st.erase(it);       }       ans++;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, m, k;     cin >> n >> m >> k;     int best = 1e9;     for (int i = 0; i < k; i++) {       int x, y;       cin >> x >> y;       best = min(best, x - 1);       best = min(best, n - x);       best = min(best, y - 1);       best = min(best, m - y);     }     if (best > 4)       cout <<  NO n ;     else       cout <<  YES n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> ans1;     vector<char> ans2;     int n1, n2;     cin >> n1;     vector<int> a1(n1);     for (int i = 0; i < n1; i++) {       cin >> a1[i];     }     cin >> n2;     vector<int> a2(n2);     for (int i = 0; i < n2; i++) {       cin >> a2[i];     }     int now1 = 0, now2 = 0;     for (int i = 0; i < n2; i++) {       int s = 0;       while (now2 < n1 && s < a2[i]) {         s += a1[now2];         now2++;       }       if (now2 > n1 || s != a2[i] || now1 == now2) {         cout <<  NO ;         return 0;       }       int temp = now1;       for (int j = now1; j < now2; j++) {         if (a1[temp] <= a1[j] && (j - 1 >= now1 && a1[j - 1] < a1[j] ||                                   j + 1 < now2 && a1[j + 1] < a1[j])) {           temp = j;         }       }       if (temp == now1 && temp + 1 < now2 && a1[temp + 1] == a1[temp]) {         cout <<  NO ;         return 0;       }       if (temp - 1 >= now1 && a1[temp] > a1[temp - 1]) {         int him = a1[temp];         int j = temp - 1;         while (j >= now1 && him > a1[j]) {           him += a1[j];           ans1.push_back(i + j - now1 + 2);           ans2.push_back( L );           j--;         }         j = temp + 1;         while (j < now2 && him > a1[j]) {           him += a1[j];           ans1.push_back(i + 1);           ans2.push_back( R );           j++;         }       } else {         if (temp + 1 < now2 && a1[temp] > a1[temp + 1]) {           int him = a1[temp];           int j = temp + 1;           while (j < now2 && him > a1[j]) {             him += a1[j];             ans1.push_back(i + temp - now1 + 1);             ans2.push_back( R );             j++;           }           j = temp - 1;           while (j >= now1 && him > a1[j]) {             him += a1[j];             ans1.push_back(i + j - now1 + 2);             ans2.push_back( L );             j--;           }         }       }       now1 = now2;       now2 = now1;     }     if (now2 != a1.size()) {       cout <<  NO ;       return 0;     }     cout <<  YES  << endl;     for (int i = 0; i < ans1.size(); i++) {       cout << ans1[i] <<     << ans2[i] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   int t;   int n;   long long dp[500010][2];   long long x;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     cin >> t;     while (t--) {       cin >> n;       for (int i = 1; i <= n + 1; i++) {         dp[i][0] = 0;         dp[i][1] = 0;       }       dp[0][0] = 1;       long long ans = 0;       for (int i = 1; i <= n; i++) {         cin >> x;         x++;         dp[x][0] = (dp[x][0] + dp[x][0]) % mod;         dp[x][0] = (dp[x][0] + dp[x - 1][0]) % mod;         dp[x][1] = (dp[x][1] + dp[x][1]) % mod;         dp[x + 2][1] = (dp[x + 2][1] + dp[x + 2][1]) % mod;         if (x > 1) {           dp[x][1] = (dp[x][1] + dp[x - 2][0]) % mod;         }       }       for (int i = 1; i <= n + 1; i++) {         ans = (ans + dp[i][0]) % mod;         ans = (ans + dp[i][1]) % mod;       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long t, n;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> t;     while (t--) {       cin >> n;       long long k = 0, l = 0;       for (int i = 0; i < (n); i++) {         long long a;         cin >> a;         if (a % 2 != i % 2)           if (a % 2)             k++;           else             l++;       }       if (k != l)         cout <<  -1 n ;       else         cout << k <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000010;   int tot;   struct node {     node *ch[26], *fail;     int len, id;     node* init(int tlen) {       memset(ch, 0, sizeof(ch));       fail = NULL;       len = tlen;       return this;     }   } * root, spT[N];   vector<int> g[N];   void addin(char* c) {     node* tmp = root;     while (*c !=   0 ) {       int t = *c -  a ;       if (tmp->ch[t] == NULL) tmp->ch[t] = spT[++tot].init(tmp->len + 1);       tmp = tmp->ch[t];       c++;     }   }   queue<node*> q;   int en, st;   void getfail() {     q.push(root);     while (!q.empty()) {       node* tmp = q.front();       q.pop();       for (int t = 0; t < 26; t++)         if (tmp->ch[t] != NULL) {           if (tmp == root)             tmp->ch[t]->fail = root;           else {             node* p = tmp->fail;             while (p != root && p->ch[t] == NULL) p = p->fail;             if (p->ch[t] != NULL)               tmp->ch[t]->fail = p->ch[t];             else               tmp->ch[t]->fail = root;           }           q.push(tmp->ch[t]);         }     }   }   char S[N];   int f[N][2];   int dfs(int x) {     f[x][0] = 0;     f[x][1] = 1;     for (auto p : g[x]) {       dfs(p);       f[x][1] += f[p][0];       f[x][0] += max(f[p][0], f[p][1]);     }     return max(f[x][0], f[x][1]);   }   bool v[N];   int main() {     int T, n;     for (int i = (1); i <= (N - 1); i++) spT[i].id = i;     cin >> T;     while (T--) {       root = spT[tot = 1].init(0);       cin >> n;       for (int i = (1); i <= (n); i++) {         scanf( %s , S);         addin(S);       }       getfail();       for (int i = (1); i <= (tot); i++) g[i].clear(), v[i] = 0;       for (int i = (1); i <= (tot); i++) {         node* tmp = &spT[i];         if (tmp->fail && tmp->fail != root && tmp->fail->len + 1 == tmp->len) {           g[tmp->fail->id].push_back(tmp->id);           v[tmp->id] = 1;         }       }       int ans = 0;       for (int i = (2); i <= (tot); i++)         if (!v[i]) ans += dfs(i);       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     string cad;     cin >> cad;     map<char, int> M;     for (int i = 0; i < cad.size(); i++) M[cad[i]]++;     int xx = M[ x ];     int yy = M[ y ];     int ans = max(xx, yy) - min(xx, yy);     if (max(xx, yy) == M[ x ])       cout << string(ans,  x ) << endl;     else       cout << string(ans,  y ) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200 * 1000 + 85;   int n, m;   int a[N];   vector<int> vec[N];   pair<pair<int, int>, int> b[N];   int mapp[N];   int ans[N];   int seg[N << 2];   inline void add(int, int, int = 1, int = 0, int = N);   inline int get(int, int = 1, int = 0, int = N);   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> a[i];       mapp[a[i]] = i;     }     for (int i = 1; i <= n; i++) {       int j = 1;       while (j * i <= n) {         if (mapp[j * i] >= mapp[i]) vec[mapp[j * i]].push_back(mapp[i]);         if (mapp[i] > mapp[j * i]) vec[mapp[i]].push_back(mapp[j * i]);         j++;       }     }     for (int i = 0; i < m; i++) {       cin >> b[i].first.second >> b[i].first.first;       b[i].first.second--;       b[i].first.first--;       b[i].second = i;     }     sort(b, b + m);     int k = 0;     for (int t = 0; t < m; t++) {       while (k <= b[t].first.first) {         for (int i = 0; i < vec[k].size(); i++) add(0, vec[k][i] + 1);         k++;       }       ans[b[t].second] = get(b[t].first.second);     }     for (int i = 0; i < m; i++) cout << ans[i] <<   n ;   }   inline void add(int st, int en, int id, int l, int r) {     if (en <= l or r <= st) return;     if (st <= l and r <= en) {       seg[id]++;       return;     }     int mid = (l + r) >> 1, lc = id << 1, rc = lc | 1;     add(st, en, lc, l, mid);     add(st, en, rc, mid, r);   }   inline int get(int idx, int id, int l, int r) {     if (idx < l or r <= idx) return 0;     if (l + 1 == r) return seg[id];     int mid = (l + r) >> 1, lc = id << 1, rc = lc | 1;     return get(idx, lc, l, mid) + get(idx, rc, mid, r) + seg[id];   }
#include <bits/stdc++.h>   using namespace std;   int n, m, cnt;   vector<int> e[105];   bool f[105];   void dfs(int x) {     f[x] = 1, ++cnt;     for (int i = 0; i < e[x].size(); ++i)       if (!f[e[x][i]]) dfs(e[x][i]);   }   void work() {     int i, x, y;     scanf( %d%d , &n, &m);     if (n != m) {       puts( NO );       return;     }     for (i = 1; i <= m; ++i) {       scanf( %d%d , &x, &y);       e[x].push_back(y);       e[y].push_back(x);     }     dfs(1);     if (cnt == n)       puts( FHTAGN! );     else       puts( NO );   }   int main() {     work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9 + 7;   const int N = 2e2 + 10;   int main() {     int n, m;     cin >> n >> m;     int l = 1, r = INF;     int ans = 0;     while (l <= r) {       int mid = (r + l) / 2;       int z = mid / 6;       int x = mid / 2 - z;       int y = mid / 3 - z;       if (z >= max(0, n - x) + max(0, m - y))         ans = mid, r = mid - 1;       else         l = mid + 1;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int cnta[10], cntb[10];   int a[15][2], b[15][2];   int one_common(int x, int y) {     if (a[x][0] == b[y][0] && a[x][1] != b[y][1]) return a[x][0];     if (a[x][1] == b[y][0] && a[x][0] != b[y][1]) return a[x][1];     if (a[x][0] == b[y][1] && a[x][1] != b[y][0]) return a[x][0];     if (a[x][1] == b[y][1] && a[x][0] != b[y][0]) return a[x][1];     return 0;   }   int main() {     scanf( %d%d , &n, &m);     int x, y;     for (int i = 0; i < n; i++) {       scanf( %d%d , &x, &y);       cnta[x]++;       cnta[y]++;       a[i][0] = x;       a[i][1] = y;     }     for (int i = 0; i < m; i++) {       scanf( %d%d , &x, &y);       cntb[x]++;       cntb[y]++;       b[i][0] = x;       b[i][1] = y;     }     set<int> num;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (one_common(i, j)) num.insert(one_common(i, j));       }     }     if (num.size() == 1) {       printf( %d n , *num.begin());       return 0;     }     for (int i = 0; i < n; i++) {       set<int> num;       for (int j = 0; j < m; j++)         if (one_common(i, j)) num.insert(one_common(i, j));       if (num.size() > 1) {         printf( -1 n );         return 0;       }     }     for (int i = 0; i < m; i++) {       set<int> num;       for (int j = 0; j < n; j++)         if (one_common(j, i)) num.insert(one_common(j, i));       if (num.size() > 1) {         printf( -1 n );         return 0;       }     }     printf( 0 n );     return 0;   }