malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long mx = 1e3 + 4;   vector<vector<long long>> dist;   vector<vector<bool>> col;   queue<pair<long long, long long>> vis;   long long n, m, t;   long long expo_pow(long long x, long long y) {     if (y == 0) return 1;     y = y % (mod - 1);     x %= mod;     if (y == 0) y = mod - 1;     long long res = 1;     while (y) {       if (y & 1) res = (res * x) % mod;       x = (x * x) % mod;       y >>= 1;     }     return res;   }   void solve() {     cin >> n >> m >> t;     col.resize(n + 1, vector<bool>(m + 1));     dist.resize(n + 1, vector<long long>(m + 1));     for (long long i = 1; i <= n; i++) {       for (long long j = 1; j <= m; j++) {         dist[i][j] = -1;         char tmp;         cin >> tmp;         col[i][j] = (tmp ==  1 );       }     }     for (long long i = 1; i <= n; i++) {       for (long long j = 1; j <= m; j++) {         if (i != 1 and col[i - 1][j] == col[i][j]) {           dist[i][j] = 0;           vis.push({i, j});         } else if (i != n and col[i + 1][j] == col[i][j]) {           dist[i][j] = 0;           vis.push({i, j});         } else if (j != 1 and col[i][j - 1] == col[i][j]) {           dist[i][j] = 0;           vis.push({i, j});         } else if (j != m and col[i][j + 1] == col[i][j]) {           dist[i][j] = 0;           vis.push({i, j});         }       }     }     while (!vis.empty()) {       auto cur = vis.front();       vis.pop();       if (cur.first != 1 and dist[cur.first - 1][cur.second] == -1) {         dist[cur.first - 1][cur.second] = dist[cur.first][cur.second] + 1;         vis.push({cur.first - 1, cur.second});       }       if (cur.first != n and dist[cur.first + 1][cur.second] == -1) {         dist[cur.first + 1][cur.second] = dist[cur.first][cur.second] + 1;         vis.push({cur.first + 1, cur.second});       }       if (cur.second != 1 and dist[cur.first][cur.second - 1] == -1) {         dist[cur.first][cur.second - 1] = dist[cur.first][cur.second] + 1;         vis.push({cur.first, cur.second - 1});       }       if (cur.second != m and dist[cur.first][cur.second + 1] == -1) {         dist[cur.first][cur.second + 1] = dist[cur.first][cur.second] + 1;         vis.push({cur.first, cur.second + 1});       }     }     while (t--) {       long long x, y, p;       cin >> x >> y >> p;       if (dist[x][y] == -1) {         cout << col[x][y] <<   n ;         continue;       }       if (p <= dist[x][y]) {         cout << col[x][y] <<   n ;         continue;       }       long long tmp = p - dist[x][y];       if (tmp % 2) {         cout << !col[x][y] <<   n ;       } else {         cout << col[x][y] <<   n ;       }     }   }   signed main() {     long long test = 1;     long long i = 1;     while (test--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0);     int n;     cin >> n;     int ats = 0;     list<int> kruv;     int kur = 1;     for (int i = 0; i < 2 * n; i++) {       string c;       cin >> c;       if (c[0] ==  a ) {         int nr;         cin >> nr;         kruv.push_front(nr);       } else {         if (kruv.size() > 0 and *kruv.begin() != kur) {           ats++;           kruv.erase(kruv.begin(), kruv.end());         } else if (kruv.size() > 0)           kruv.erase(kruv.begin());         kur++;       }     }     cout << ats;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool issub(string s, string t) {     int cur = 0;     for (char c : s) {       if (c == t[cur]) cur++;       if (cur == t.size()) return true;     }     return false;   }   int main() {     int q, i;     cin >> q;     while (q--) {       string s, t, p;       cin >> s >> t >> p;       int a[26], flag = 0;       memset(a, 0, sizeof(a));       for (char c : s) a[c -  a ]++;       for (char c : p) a[c -  a ]++;       for (char c : t) a[c -  a ]--;       for (i = 0; i < 26; i++) {         if (a[i] < 0) {           flag = 1;         }       }       if (flag == 0 && issub(t, s) == true) {         cout <<  YES  << endl;       } else {         cout <<  NO  << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   long long siv[1000006];   long long prime[1000006];   void seive() {     for (long long i = 2; i < 1000006; i++) {       prime[i] = prime[i - 1];       if (!siv[i]) {         prime[i]++;         for (long long j = i + i; j < 1000006; j += i) siv[j] = 1;       }     }   }   void solve() {     long long t;     t = 1;     cin >> t;   t:     seive();     while (t--) {       long long n;       cin >> n;       long long a = sqrt(n);       cout << prime[n] - prime[a] + 1 <<   n ;     }   }   int main() {     {       ios_base::sync_with_stdio(false);       cin.tie(NULL);     }     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long T, x, y, k;     cin >> T;     while (T--) {       cin >> x >> y >> k;       long long minSt = (y * k) + k - 1;       long long st = 1;       long long count = minSt / (x - 1);       if (minSt % (x - 1) != 0) {         cout << count + k + 1 << endl;       } else         cout << count + k << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 5;   int par[N], par1[N], T, vis[N], n, m, w[N], x[N], y[N];   bool ans[N];   vector<pair<int, int>> e[N], q[N];   int get(int u) { return u == par[u] ? u : par[u] = get(par[u]); }   int gett(int u) {     return (vis[u] != T ? vis[u] = T, par1[u] = par[u] : 0),            (u == par1[u] ? u : par1[u] = gett(par1[u]));   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) par[i] = i;     for (int i = 0, a, b, c; i < m; i++)       scanf( %d%d%d , x + i, y + i, w + i), e[w[i]].push_back({--x[i], --y[i]});     scanf( %d , &n);     for (int i = 0, a, b; i < n; i++) {       scanf( %d , &a);       while (a--) scanf( %d , &b), --b, q[w[b]].push_back({i, b});     }     for (int i = 1, last; i < N; i++) {       last = -1;       for (auto j : q[i]) {         if (last != j.first) T++, last = j.first;         int a = gett(x[j.second]), b = gett(y[j.second]);         if (a == b)           ans[last] = 1;         else           par1[a] = b;       }       for (auto j : e[i]) par[get(j.second)] = get(j.first);     }     for (int i = 0; i < n; i++) puts(ans[i] ?  NO  :  YES );   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   const double eps = 1e-9;   const int inf = 2000000000;   const long long infLL = 9000000000000000000;   inline int in() {     int x;     scanf( %d , &x);     return x;   }   inline long long inl() {     long long x;     scanf( %I64d , &x);     return x;   }   inline double ind() {     double x;     scanf( %lf , &x);     return x;   }   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   int power(int x, int n) {     if (n == 0)       return 1;     else if (n % 2 == 0) {       int y = power(x, n / 2);       return y * y;     } else       return x * power(x, n - 1);   }   char s[2];   int n, k;   long long ans;   int lastp, lastb, lastr;   int pf, rf, bf;   int c, v, g;   int main() {     n = in();     int lastb, lastp, lastr;     for (int i = 0; i < n; i++) {       scanf( %d %s , &k, s);       if (s[0] ==  P  || s[0] ==  R ) {         if (rf) {           ans += k - lastr;           c = max(c, k - lastr);         }         rf = 1;         lastr = k;       }       if (s[0] ==  P  || s[0] ==  B ) {         if (bf) {           ans += k - lastb;           v = max(v, k - lastb);         }         bf = 1;         lastb = k;       }       if (s[0] ==  P ) {         if (pf) {           ans += min(0, k - g - c - v);         }         pf = 1;         g = k;         c = v = 0;       }     }     printf( %I64d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 110;   int n, m, a, b, cnt, Newid, Size[N], id[N], nid[N], ans[N];   struct edge {     int x, y, z;     bool operator<(const edge &rhs) const { return z < rhs.z; }   } e[N << 2];   int tot = 0, head[N], to[N << 2], nxt[N << 2], len[N << 2];   void add_edge(int x, int y, int z) {     nxt[++tot] = head[x];     to[tot] = y;     len[tot] = z;     head[x] = tot;   }   int fa[N];   int getfa(int x) { return x == fa[x] ? x : fa[x] = getfa(fa[x]); }   void Krusual() {     for (int i = 1; i <= n; i++) fa[i] = i;     for (int i = 1; i <= m; i++) {       int x = getfa(e[i].x), y = getfa(e[i].y);       if (e[i].z == b || x == y) continue;       fa[y] = fa[x];     }   }   priority_queue<pair<int, pair<int, int>>> q;   int dis[1 << 18][80];   bool vis[1 << 18][80];   void Dijkstra() {     memset(dis, 0x3f, sizeof(dis));     memset(vis, 0, sizeof(vis));     q.push(make_pair(0, make_pair(0, 1)));     dis[0][1] = 0;     while (!q.empty()) {       int now = -q.top().first;       pair<int, int> u = q.top().second;       q.pop();       ans[u.second] = min(ans[u.second], now);       if (vis[u.first][u.second]) continue;       vis[u.first][u.second] = 1;       for (int i = head[u.second]; i; i = nxt[i]) {         int v = to[i];         if (id[v] == id[u.second] && len[i] == b) continue;         if (nid[v] && (u.first & (1 << nid[v]))) continue;         int S = u.first;         if (nid[u.second] && nid[v] != nid[u.second]) S |= (1 << nid[u.second]);         if (dis[u.first][u.second] + len[i] < dis[S][v]) {           dis[S][v] = dis[u.first][u.second] + len[i];           q.push(make_pair(-dis[S][v], make_pair(S, v)));         }       }     }   }   int main() {     cin >> n >> m >> a >> b;     for (int i = 1; i <= m; i++) {       scanf( %d%d%d , &e[i].x, &e[i].y, &e[i].z);       add_edge(e[i].x, e[i].y, e[i].z);       add_edge(e[i].y, e[i].x, e[i].z);     }     sort(e + 1, e + m + 1);     Krusual();     for (int i = 1; i <= n; i++) {       Size[getfa(i)]++;       if (fa[i] == i) id[i] = ++cnt;     }     for (int i = 1; i <= n; i++) id[i] = id[getfa(i)];     for (int i = 1; i <= n; i++)       if (Size[i] >= 4) nid[i] = ++Newid;     for (int i = 1; i <= n; i++) nid[i] = nid[getfa(i)];     memset(ans, 0x3f, sizeof(ans));     Dijkstra();     for (int i = 1; i <= n; i++) printf( %d  , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int k1, k2;   long long int dp[101][101][11][11];   long long int rec(long long int n1, long long int n2, long long int x,                     long long int y) {     if (n1 == 0 && n2 == 0) return 1;     if (dp[n1][n2][x][y] != -1) return dp[n1][n2][x][y];     long long int a1 = 0, a2 = 0;     if (x > 0 && n1 > 0) a1 = rec(n1 - 1, n2, x - 1, k2);     if (y > 0 && n2 > 0) a2 = rec(n1, n2 - 1, k1, y - 1);     return dp[n1][n2][x][y] = (a1 + a2) % 100000000;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     memset(dp, -1, sizeof(dp));     long long int n1, n2;     cin >> n1 >> n2 >> k1 >> k2;     cout << rec(n1, n2, k1, k2);     return 0;   }
#include <bits/stdc++.h>      #define all(v) (v).begin(), (v).end()   #define sortv(v) sort(all(v))   #define uniqv(v) (v).erase(unique(all(v)), (v).end())   #define pb push_back   #define FI first   #define SE second   #define lb lower_bound   #define ub upper_bound   #define mp make_pair   #define test 1   #define TEST if(test)       using namespace std;       typedef long long ll;   typedef pair<int, int> pii;   typedef pair<ll, ll> pll;   typedef vector<int> vi;       const int MOD = 1000000007; // 998244353   const int INF = 2e9;   const ll INFLL = 1e18;   const int MAX_N = 100;      int T;   int N, K;   int h[MAX_N+1];      int main(){    scanf( %d , &T);    while(T--){     scanf( %d%d , &N, &K);     for(int i=1; i<=N; i++){      scanf( %d , &h[i]);     }     bool tf = true;     int ans = 0;     for(int i=1; i<=K; i++){      int pos = 1;      while(pos!=N){       if(h[pos]>=h[pos+1]) pos++;       else break;      }      if(pos==N){       tf = false;       printf( -1 n );       break;      }else{       ans = pos;       h[pos]++;      }     }     if(tf){      printf( %d n , ans);     }    }    return 0;   }
#include <bits/stdc++.h>   using namespace std;   int f(int n, vector<int> &a);   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> a(n);       for (int i = 0; i <= n - 1; i++) {         cin >> a[i];       }       cout << f(n, a) <<   n ;     }     return 0;   }   int f(int n, vector<int> &a) {     sort(a.begin(), a.end());     bool flag = 0;     for (int k = 1; k <= 1023; k++) {       flag = 0;       for (int i = 0; i <= n - 1; i++) {         int x = a[i] ^ k;         if (!binary_search(a.begin(), a.end(), x)) {           flag = 1;           break;         }       }       if (flag == 0) {         return k;       }     }     return -1;   }
#include <bits/stdc++.h>   using namespace std;   int oo = (int)1e9;   int get(string str) {     int f = 0;     for (int i = 0; i < (int)str.size(); ++i) {       if (str[i] !=  - ) {         if (str[i] != str[0]) f = 1;       }     }     if (f == 0) return f;     for (int i = 1; i < (int)str.size(); ++i) {       if (str[i] !=  - ) {         if (str[i] >= str[i - 1 - (i == 3 || i == 6)]) f = 2;       }     }     return f;   }   int main() {     int n;     cin >> n;     string cn;     vector<string> vs(n);     vector<vector<int> > cnt(n, vector<int>(3, 0));     for (int i = 0; i < n; ++i) {       int s;       cin >> s >> vs[i];       for (int j = 0; j < s; ++j) {         cin >> cn;         cnt[i][get(cn)]++;       }     }     vector<vector<int> > res(3);     for (int i = 0; i < 3; ++i) {       int mx = 0;       for (int j = 0; j < n; ++j) {         mx = max(mx, cnt[j][i]);       }       for (int j = 0; j < n; ++j) {         if (cnt[j][i] == mx) {           res[i].push_back(j);         }       }     }     cout <<  If you want to call a taxi, you should call:  ;     for (int i = 0; i < (int)res[0].size(); ++i) {       if (i) cout <<  ,  ;       cout << vs[res[0][i]];     }     cout <<  . nIf you want to order a pizza, you should call:  ;     for (int i = 0; i < (int)res[1].size(); ++i) {       if (i) cout <<  ,  ;       cout << vs[res[1][i]];     }     cout <<  . nIf you want to go to a cafe with a wonderful girl, you should                call:  ;     for (int i = 0; i < (int)res[2].size(); ++i) {       if (i) cout <<  ,  ;       cout << vs[res[2][i]];     }     cout <<  .  << endl;     return 0;   }
#include <bits/stdc++.h>   int n, m, a, b, c;   int ans[110][110];   int find(int i, int j) {     for (int k = 1; k <= 10; k++) {       if (k != ans[i][j - 1] && k != ans[i - 1][j] && k != ans[i + 1][j - 1] &&           k != ans[i - 1][j + 1])         return k;     }   }   void output() {     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) printf( %c , ans[i][j] +  a  - 1);       printf(  n );     }   }   int getans(int n, int m, int a, int b, int c) {     if (b < 0) return 0;     int test = c * 4 + (a / 2) * 4 + (b / 2) * 4;     if (test < n * m) return 0;     for (int i = 1; i < n; i += 2) {       for (int j = 1; j < m; j += 2) {         if (c > 0) {           ans[i][j] = ans[i][j + 1] = ans[i + 1][j] = ans[i + 1][j + 1] =               find(i, j);           c--;         } else if (a >= 2) {           ans[i][j] = ans[i][j + 1] = find(i, j);           ans[i + 1][j] = ans[i + 1][j + 1] = find(i + 1, j);           a -= 2;         } else {           ans[i][j] = ans[i + 1][j] = find(i, j);           ans[i][j + 1] = ans[i + 1][j + 1] = find(i, j + 1);           b -= 2;         }       }     }     return 1;   }   int main() {     while (scanf( %d %d %d %d %d , &n, &m, &a, &b, &c) != EOF) {       memset(ans, 0, sizeof(ans));       if (n % 2 == 1 && m % 2 == 1)         printf( IMPOSSIBLE n );       else if (n % 2 == 0 && m % 2 == 1) {         if (b * 2 < n)           printf( IMPOSSIBLE n );         else {           int found = 1;           b -= n / 2;           found = getans(n, m - 1, a, b, c);           for (int i = 1; i < n; i += 2) ans[i][m] = ans[i + 1][m] = find(i, m);           if (found == 0)             printf( IMPOSSIBLE n );           else             output();         }       } else if (n % 2 == 1 && m % 2 == 0) {         if (a * 2 < m)           printf( IMPOSSIBLE n );         else {           int found = 1;           a -= m / 2;           found = getans(n - 1, m, a, b, c);           for (int i = 1; i < m; i += 2) ans[n][i] = ans[n][i + 1] = find(n, i);           if (found == 0)             printf( IMPOSSIBLE n );           else             output();         }       } else {         int found = getans(n, m, a, b, c);         if (found == 0)           printf( IMPOSSIBLE n );         else           output();       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string a, b;   bool ok(string s) {     if (s ==   ) return false;     if (s.length() == 1 && s[0] ==  0 ) return true;     if (s[0] ==  0 ) return false;     for (char c : s) {       if (c <  0  || c >  9 ) return false;     }     return true;   }   void cal(string s) {     if (ok(s))       a += s +  , ;     else       b += s +  , ;   }   void go(string &ret) {     if (ret ==   )       ret =  - ;     else {       ret =     + ret;       ret[ret.length() - 1] =    ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     string s, t =   ;     cin >> s;     for (char c : s) {       if (c ==  ,  || c ==  ; ) {         cal(t);         t =   ;       } else {         t += c;       }     }     cal(t);     go(a);     go(b);     cout << a <<   n  << b;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   int getRand(int l, int r) {     uniform_int_distribution<int> uid(l, r);     return uid(rng);   }   unordered_map<string, int> X;   long long get_sum(long long n) {     if (n == 1) {       return 1;     }     return get_sum(n / 2) + n;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t, num;     long long n, sum = 0, temp;     string str;     cin >> t;     while (t--) {       sum = 0;       temp = 1;       cin >> n;       while (n > 0) {         temp = 1;         while (temp <= n) {           temp *= 2;         }         sum += get_sum(temp / 2);         n = n - (temp / 2);       }       cout << sum << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6;   const long long int inf = 1e18;   vector<long long int> v, arr;   void pf() {}   long long int sqrtfun(long long int num) {     long long int lo = 0, hi = (long long int)2e9, mid;     if (num == 1) return num;     while (lo + 1 < hi) {       mid = lo + hi >> 1LL;       if (mid * mid == num)         return mid;       else if (mid * mid > num)         hi = mid;       else         lo = mid;     }     return (mid * mid > num) ? mid - 1 : mid;   }   long long int get(long long int r) {     int ans = upper_bound(arr.begin(), arr.end(), r) - arr.begin();     return ans + sqrtfun(r) - 1;   }   void solve() {     for (long long int i = 2; i <= N; i++) {       for (long long int j = i * i * i; j <= inf; j *= i) {         long long int x = sqrtfun(j);         if (x * x != j) v.push_back(j);         if (inf / i < j) break;       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long int t, l, r, ans = 0;     cin >> t;     solve();     sort(v.begin(), v.end());     for (auto i : v) {       if (arr.empty())         arr.push_back(i);       else if (arr.back() != i)         arr.push_back(i);     }     while (t--) {       cin >> r;       cout << r - get(r) - 1 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long call(long long n) {     if (n == 1)       return 1;     else       return n + call(n / 2);   }   void fun() {     long long n;     cin >> n;     cout << call(n);   }   int main() {     long long t;     cin >> t;     while (t--) {       fun();       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dx[4] = {1, -1, 0, 0};   int dy[4] = {0, 0, 1, -1};   long long gcd(long long a, long long b) {     for (; b; a %= b, swap(a, b))       ;     return a;   }   int main(void) {     ios::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     int t;     cin >> t;     while (t--) {       string n;       int k;       cin >> n;       cin >> k;       while (true) {         set<char> s;         for (int i = 0; i < n.size(); i++) s.insert(n[i]);         if (s.size() <= k) {           cout << n <<   n ;           break;         }         s.clear();         int ptr = 0;         while (true) {           s.insert(n[ptr]);           if (s.size() > k) {             while (n[ptr] ==  9 ) ptr--;             n[ptr]++;             for (int i = ptr + 1; i < n.size(); i++) n[i] =  0 ;             break;           }           ptr++;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int x, n, m;     cin >> n >> m;     if (n < m) {       cout <<  -1 n ;       return 0;     }     if (n % 2 == 0)       x = n / 2;     else       x = (n / 2) + 1;     while (x % m != 0) {       x++;     }     cout << x <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   void err(istream_iterator<string> it) {}   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a <<   n ;     err(++it, args...);   }   long long powMod(long long x, long long y) {     long long p = 1;     while (y) {       if (y % 2) {         p = (p * x) % ((long long)1e9 + 7);       }       y /= 2;       x = (x * x) % ((long long)1e9 + 7);     }     return p;   }   long long CpowMod(long long x, long long y, long long w) {     long long p = 1;     while (y) {       if (y % 2) {         p = (p * x) % w;       }       y /= 2;       x = (x * x) % w;     }     return p;   }   long long invMod(long long x) { return powMod(x, ((long long)1e9 + 7) - 2); }   long long CinvMod(long long x, long long w) { return CpowMod(x, w - 2, w); }   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long exGcd(long long a, long long b, long long &x, long long &y) {     if (b == 0) {       y = 0;       x = 1;       return a;     }     long long xtmp, ytmp;     long long g = exGcd(b, a % b, xtmp, ytmp);     x = ytmp;     y = xtmp - (a / b) * ytmp;     return g;   }   void solve() {     long long t;     cin >> t;     while (t--) {       long long n;       long long x;       cin >> n >> x;       long long cnt = 0, eve = 0;       for (long long i = 0; i <= n - 1; i++) {         long long y;         cin >> y;         if (y % 2)           cnt++;         else           eve++;       }       if (cnt == 0) {         cout <<  NO  <<   n ;         continue;       }       long long mn;       if (x % 2 == 1) {         mn = 0;       } else         mn = 1;       if (cnt % 2 == 0) {         x -= (cnt - 1);       } else         x -= cnt;       x = max(mn, x);       if (eve >= x) {         cout <<  YES  <<   n ;       } else         cout <<  NO  <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   void fastio() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   int main() {     fastio();     int n, m, temp;     cin >> n >> m;     vector<int> boys(n);     vector<int> girls(m);     int hb;     cin >> hb;     for (int i = 0; i < hb; i++) cin >> temp, boys[temp] = 1;     int hg;     cin >> hg;     for (int i = 0; i < hg; i++) cin >> temp, girls[temp] = 1;     int len = 100 * 100;     int a, b;     for (int i = 0; i < len; i++) {       a = i % n;       b = i % m;       if (boys[a] == 1 || girls[b] == 1) boys[a] = 1, girls[b] = 1;     }     for (int i = 0; i < n; i++)       if (boys[i] == 0) {         cout <<  No n ;         return 0;       }     for (int i = 0; i < m; i++)       if (girls[i] == 0) {         cout <<  No n ;         return 0;       }     cout <<  Yes n ;     return 0;   }