malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (a > b) swap(a, b);     if (a == 0) return b;     return gcd(b % a, a);   }   long long powerMod(long long x, long long y) {     long long res = 1;     x %= 1000000007;     while (y > 0) {       if (y & 1) res = (res * x) % 1000000007;       y = y >> 1;       x = (x * x) % 1000000007;     }     return res;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     ;     long long n, i, j, k, l;     cin >> n;     long long p[n + 1], q[n + 1];     for (i = 1; i <= n; i++) {       cin >> p[i];       q[p[i]] = i;     }     long long m = 0;     vector<pair<long long, long long> > swaps;     for (i = 1; i <= n; i++) {       if (p[i] != i) {         j = q[i];         if (2 * abs(i - j) >= n) {           m++;           swaps.push_back({i, j});           p[j] = p[i];           q[p[i]] = j;           p[i] = i;           q[i] = i;         } else if (i <= n / 2 && j <= n / 2) {           k = max(i, j) + n / 2;           m += 3;           swaps.push_back({i, k});           swaps.push_back({j, k});           swaps.push_back({i, k});           p[j] = p[i];           q[p[i]] = j;           p[i] = i;           q[i] = i;         } else if (i > n / 2 && j > n / 2) {           k = min(i, j) - n / 2;           m += 3;           swaps.push_back({i, k});           swaps.push_back({j, k});           swaps.push_back({i, k});           p[j] = p[i];           q[p[i]] = j;           p[i] = i;           q[i] = i;         } else {           m += 5;           if (i <= n / 2 && j > n / 2)             k = i + n / 2, l = j - n / 2;           else             k = i - n / 2, l = j + n / 2;           swaps.push_back({j, l});           swaps.push_back({l, k});           swaps.push_back({k, i});           swaps.push_back({k, l});           swaps.push_back({l, j});           p[j] = p[i];           q[p[i]] = j;           p[i] = i;           q[i] = i;         }       }     }     cout << m << endl;     for (pair<long long, long long> p : swaps) {       cout << p.first <<     << p.second << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int c = 0;     int n;     cin >> n;     string s;     for (int i = 0; i < n; i++) {       cin >> s;       if (s ==  Cube )         c += 6;       else if (s ==  Tetrahedron )         c += 4;       else if (s ==  Octahedron )         c += 8;       else if (s ==  Icosahedron )         c += 20;       else         c += 12;     }     cout << c << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, tot, m, l, r, len;   char c;   int po[400005], ha[400005], ys[400005], fi[400005], la[400005];   int s[400005], id[400005], t[400005], sum[400005], it[400005];   struct pi {     int num, hai;   };   pi find(int li, int ri) {     int f1 = 0, f2 = 0, lp = li, rp = ri;     pi tmp;     if (it[li] == it[ri]) {       if (s[li] == 1) {         if ((ri - li + 1) % 2 == 1) {           tmp.hai = (long long)2 * po[2 * n] % 1000000007;         } else           tmp.hai = 0;         tmp.num = (ri - li + 1) / 2;       } else {         tmp.num = 0;         tmp.hai = (long long)(ha[ys[ri]] - ha[ys[li] - 1] + 1000000007) %                   1000000007 * po[2 * n - ys[ri]] % 1000000007;       }       return tmp;     }     if (s[li] == 1) lp = la[lp] + 1;     if (s[ri] == 1) rp = fi[rp] - 1;     if ((lp - li) & 1) f1 = 1;     if ((ri - rp) & 1) f2 = 1;     tmp.hai = (long long)(ha[ys[rp]] - ha[ys[lp] - 1] + 1000000007) % 1000000007 *               po[2 * n - 1 - ys[rp]] % 1000000007;     tmp.num = sum[rp] - sum[lp];     tmp.num += (lp - li) / 2;     tmp.num += (ri - rp) / 2;     if (f2 == 1)       tmp.hai = (tmp.hai + (long long)2 * po[2 * n] % 1000000007) % 1000000007;     else       tmp.hai = (long long)tmp.hai * po[1] % 1000000007;     int len = ri - li + 1 - tmp.num * 2;     if (f1 == 1)       tmp.hai = (tmp.hai + (long long)2 * po[2 * n - len + 1] % 1000000007) %                 1000000007;     return tmp;   }   int main() {     scanf( %d , &n);     s[0] = -1;     s[n + 1] = -1;     for (int i = 1; i <= n; i++) {       scanf(  %c , &c);       s[i] = c -  0 ;     }     int tit = 0;     for (int i = 1; i <= n; i++) {       if (s[i] != s[i - 1])         fi[i] = i, tit++;       else         fi[i] = fi[i - 1];       it[i] = tit;     }     for (int i = n; i >= 1; i--) {       if (s[i] != s[i + 1])         la[i] = i;       else         la[i] = la[i + 1];     }     po[0] = 1;     for (int i = 1; i <= 2 * n; i++)       po[i] = (long long)po[i - 1] * 1500007 % 1000000007;     for (int i = 1; i <= n; i++) {       t[++tot] = s[i];       id[tot] = i;       if (t[tot] == 1 && t[tot - 1] == 1) tot -= 2, sum[i]++;       ys[i] = tot;     }     for (int i = 1; i <= n; i++) sum[i] += sum[i - 1];     for (int i = 1; i <= tot; i++)       ha[i] =           (ha[i - 1] + (long long)po[i] * (t[i] + 1) % 1000000007) % 1000000007;     scanf( %d , &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d%d , &l, &r, &len);       pi t1 = find(l, l + len - 1), t2 = find(r, r + len - 1);       if (t1.hai == t2.hai && t1.num == t2.num)         puts( Yes );       else         puts( No );     }     return 0;   }
#include <bits/stdc++.h>   int n, m, a[210], f[210][210][1010], ans;   inline void up(int &x, int y) {     if ((x += y) >= 1000000007) x -= 1000000007;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     std::sort(a + 1, a + n + 1);     f[1][1][0] = f[1][0][0] = 1;     for (int i = 1; i < n; i++) {       int delta = a[i + 1] - a[i], next;       for (int j = 0; j <= n; j++) {         for (int k = 0; k <= m; k++) {           if ((next = k + j * delta) > m) continue;           if (!f[i][j][k]) continue;           if (j > 0) up(f[i + 1][j - 1][next], 1LL * f[i][j][k] * j % 1000000007);           up(f[i + 1][j][next], 1LL * f[i][j][k] * (j + 1) % 1000000007);           up(f[i + 1][j + 1][next], f[i][j][k]);         }       }     }     for (int i = 0; i <= m; i++) up(ans, f[n][0][i]);     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a, b, k, h[200010];   int main() {     scanf( %d%d%d%d , &n, &a, &b, &k);     int ans = 0, x;     for (int i = 1; i <= n; i++) {       scanf( %d , &x);       if (x % (a + b) == 0)         x -= (x / (a + b) - 1) * (a + b);       else         x -= (x / (a + b)) * (a + b);       if (x <= a)         ans++;       else {         if (x % a == 0)           x = x / a - 1;         else           x = x / a;         h[i] = x;       }     }     sort(h + 1, h + 1 + n);     for (int i = 1; i <= n; i++)       if (h[i] > 0 && k >= h[i]) k -= h[i], ans++;     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void err(istream_iterator<string> it) { cerr << endl; }   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a <<   ,  ;     err(++it, args...);   }   namespace fastIO {   bool IOerror = 0;   inline char nc() {     static char buf[100000], *p1 = buf + 100000, *pend = buf + 100000;     if (p1 == pend) {       p1 = buf;       pend = buf + fread(buf, 1, 100000, stdin);       if (pend == p1) {         IOerror = 1;         return -1;       }     }     return *p1++;   }   inline bool blank(char ch) {     return ch ==     || ch ==   n  || ch ==   r  || ch ==   t ;   }   inline void read(int &x) {     char ch;     while (blank(ch = nc()))       ;     if (IOerror) return;     for (x = ch -  0 ; (ch = nc()) >=  0  && ch <=  9 ; x = x * 10 + ch -  0 )       ;   }   }  // namespace fastIO   using namespace fastIO;   const double PI = acos(-1.0);   const double eps = 1e-8;   const int maxn = 3e5 + 7;   const int N = 5e5 + 10;   int a[N];   int main() {     int n;     cin >> n;     int mx = 0;     for (int i = 1; i <= n; ++i) cin >> a[i], mx = max(mx, a[i]);     int ans = 1;     int len = 0;     for (int i = 1; i <= n; ++i) {       if (a[i] == mx)         len++;       else         len = 0;       ans = max(ans, len);     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   long long qpow(long long x, long long y) {     long long re = 1, base = x % mod;     while (y) {       if (y & 1) re = (re * base) % mod;       base = (base * base) % mod;       y >>= 1;     }     return re;   }   struct node {     int to, w;     node(int to, int w) : to(to), w(w) {}   };   int n, k;   vector<node> e[100050];   int deep[100050], f[100050], anc[100050][25];   int up[100050], cnt[2][100050];   void init() {     for (int i = 0; i <= n; i++) e[i].clear();     memset(f, 0, sizeof(f)), memset(anc, 0, sizeof(anc)),         memset(deep, 0, sizeof(deep));     memset(up, 0, sizeof(up)), memset(cnt, 0, sizeof(cnt));     deep[1] = 1;   }   void dfs1(int x, int fa) {     anc[x][0] = f[x];     for (int i = 1; i <= 20; i++) anc[x][i] = anc[anc[x][i - 1]][i - 1];     for (int i = 0; i < e[x].size(); i++) {       int next = e[x][i].to;       if (next != fa) {         f[next] = x;         deep[next] = deep[x] + 1;         up[next] = -e[x][i].w;         dfs1(next, x);       }     }   }   int lca(int x, int y) {     if (deep[x] < deep[y]) swap(x, y);     for (int i = 20; i >= 0; i--)       if (deep[anc[x][i]] >= deep[y]) x = anc[x][i];     if (x == y) return x;     for (int i = 20; i >= 0; i--)       if (anc[x][i] != anc[y][i]) x = anc[x][i], y = anc[y][i];     return f[x];   }   void dfs2(int x) {     for (int i = 0; i < e[x].size(); i++) {       int next = e[x][i].to;       if (next == anc[x][0]) continue;       dfs2(next);       for (int j = 0; j < 2; j++) cnt[j][x] += cnt[j][next];     }   }   int main() {     scanf( %d , &n);     init();     for (int i = 1; i < n; i++) {       int u, v, w;       scanf( %d%d%d , &u, &v, &w);       if (w == 0) {         e[u].push_back(node(v, 0));         e[v].push_back(node(u, 0));       } else {         e[u].push_back(node(v, 1));         e[v].push_back(node(u, -1));       }     }     dfs1(1, 0);     scanf( %d , &k);     int pre = 1, now;     while (k--) {       scanf( %d , &now);       int x = lca(pre, now);       cnt[0][pre]++;       cnt[0][x]--;       cnt[1][now]++;       cnt[1][x]--;       pre = now;     }     dfs2(1);     int ans = 0;     for (int i = 1; i <= n; i++) {       if (!up[i]) continue;       if (up[i] == -1)         ans = (ans + qpow(2, cnt[0][i]) - 1) % mod;       else         ans = (ans + qpow(2, cnt[1][i]) - 1) % mod;     }     ans = (ans + mod) % mod;     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<int, int> p;   int a[100005];   int a1[100005], a2[100005];   int n, flag, pl = 1;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       if (p[a[i]] == 0) p[a[i]] = pl++;     }     for (int i = 1; i <= n; i++) {       a1[i] = p[a[i]];       a2[a1[i]] = a[i];     }     int l = p.size();     for (int i = 1; i <= l; i++) {       if (a1[a2[i]] != i) flag = 1;     }     if (flag)       printf( -1 n );     else {       printf( %d n , p.size());       for (int i = 1; i <= n; i++) {         if (i != 1) printf(   );         printf( %d , a1[i]);       }       printf(  n );       for (int i = 1; i <= l; i++) {         if (i != 1) printf(   );         printf( %d , a2[i]);       }       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const double PI = 3.14159265358979323846;   const int MAXN = 1000005;   int n, x[MAXN], y[MAXN], r[MAXN];   int d[MAXN];   vector<int> G[MAXN];   inline double dis(double x1, double y1, double x2, double y2) {     double d = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);     return sqrt(d);   }   int judge(int i, int j) {     if (r[i] + r[j] <= dis(x[i], y[i], x[j], y[j]))       return 0;     else if (r[i] > r[j])       return 1;     else if (r[j] > r[i])       return 2;   }   double calc(int i) { return PI * r[i] * r[i]; }   double ans = 0;   void dfs(int i, int dis) {     if (d[i] >= dis)       return;     else       d[i] = dis;     for (int v : G[i]) {       dfs(v, dis + 1);     }   }   int main() {     scanf( %d , &n);     for (int i = (1); i < (n + 1); i++) scanf( %d%d%d , x + i, y + i, r + i);     for (int i = (1); i < (n + 1); i++) {       for (int j = (i + 1); j < (n + 1); j++) {         int status = judge(i, j);         if (status == 1) {           G[i].push_back(j);         } else if (status == 2) {           G[j].push_back(i);         }       }     }     for (int i = (1); i < (n + 1); i++) {       if (!d[i]) dfs(i, 1);     }     for (int i = (1); i < (n + 1); i++) {       if (d[i] <= 2)         ans += calc(i);       else if (d[i] & 1)         ans -= calc(i);       else         ans += calc(i);     }     printf( %.11f n , ans);   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   constexpr ll mod = 1e9 + 7;   template <typename A, typename B>   string to_string(pair<A, B> p);   template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p);   template <typename A, typename B, typename C, typename D>   string to_string(tuple<A, B, C, D> p);   string to_string(const string& s) { return     + s +    ; }   string to_string(const char c) { return string(1, c); }   string to_string(const char* s) { return to_string((string)s); }   string to_string(bool b) { return (b ?  true  :  false ); }   string to_string(vector<bool> v) {     bool first = true;     string res =  { ;     for (int i = 0; i < static_cast<int>(v.size()); i++) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(v[i]);     }     res +=  } ;     return res;   }   template <size_t N>   string to_string(bitset<N> v) {     string res =   ;     for (int i = int(N) - 1; i >= 0; --i) {       res += static_cast<char>( 0  + v[i]);     }     return res;   }   template <typename A>   string to_string(A v) {     bool first = true;     string res =  { ;     for (const auto& x : v) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(x);     }     res +=  } ;     return res;   }   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ) ;   }   template <typename A, typename B, typename C, typename D>   string to_string(tuple<A, B, C, D> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ,   + to_string(get<3>(p)) +  ) ;   }   void debug_out() { cerr <<   n ; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << to_string(H);     debug_out(T...);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     ll n;     cin >> n;     string s;     cin >> s;     vector<ll> A(n);     for (auto& _a : A) cin >> _a;     vector<int> left, right;     for (int i = 0; i < n; ++i) {       if (s[i] ==  L ) {         left.push_back(A[i]);       } else {         right.push_back(A[i]);       }     }     if (0) {     };     if (0) {     };     sort(left.begin(), left.end());     sort(right.begin(), right.end());     int nl = left.size(), nr = right.size();     ll ans = INT_MAX;     for (int r = 0; r < nr; ++r) {       auto it = lower_bound(left.begin(), left.end(), right[r]);       if (it != left.end()) {         ans = min(ans, ll(*it - right[r]) / 2);       }     }     if (ans == INT_MAX) ans = -1;     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   typename T::value_type arr_sum(const T& v, int n) {     typename T::value_type sum = 0;     for (int i = 0; i < n; ++i) sum += v[i];     return sum;   }   struct Sync_stdio {     Sync_stdio() {       cin.tie(NULL);       ios_base::sync_with_stdio(false);     }   } _sync_stdio;   vector<int> t;   void build(vector<int>& a, int v, int tl, int tr) {     if (tl == tr)       t[v] = a[tl];     else {       int tm = (tl + tr) / 2;       build(a, v * 2 + 1, tl, tm);       build(a, v * 2 + 2, tm + 1, tr);       t[v] = t[v * 2 + 1] + t[v * 2 + 2];     }   }   int sum(int v, int tl, int tr, int l, int r) {     if (l > r) return 0;     if (l == tl && r == tr) return t[v];     int tm = (tl + tr) / 2;     return sum(v * 2 + 1, tl, tm, l, min(r, tm)) +            sum(v * 2 + 2, tm + 1, tr, max(l, tm + 1), r);   }   void update(int v, int tl, int tr, int pos, int new_val) {     if (tl == tr) {       t[v] = new_val;     } else {       int tm = (tl + tr) / 2;       if (pos <= tm)         update(v * 2 + 1, tl, tm, pos, new_val);       else         update(v * 2 + 2, tm + 1, tr, pos, new_val);       t[v] = t[v * 2 + 1] + t[v * 2 + 2];     }   }   void add(int v, int tl, int tr, int pos, int new_val) {     if (tl == tr) {       t[v] += new_val;     } else {       int tm = (tl + tr) / 2;       if (pos <= tm)         add(v * 2 + 1, tl, tm, pos, new_val);       else         add(v * 2 + 2, tm + 1, tr, pos, new_val);       t[v] = t[v * 2 + 1] + t[v * 2 + 2];     }   }   int main() {     int n, q;     cin >> n >> q;     t.resize(4 * n);     vector<int> v(n, 1);     int flag = 0;     build(v, 0, 0, n - 1);     int l = 0, r = v.size();     for (int k = 0; k < q; ++k) {       int tmp;       cin >> tmp;       if (tmp == 1) {         int x;         cin >> x;         if ((x <= (r - l) / 2) ^ flag) {           if (flag) {             x = r - l - x;           }           for (int i = l + x, j = l + x - 1; j >= l; ++i, --j) {             add(0, 0, n - 1, i, sum(0, 0, n - 1, j, j));           }           l += x;           flag = 0;         } else {           if (flag) {             x = r - l - x;           }           for (int i = l + x, j = l + x - 1; i < r; ++i, --j) {             add(0, 0, n - 1, j, sum(0, 0, n - 1, i, i));           }           r = l + x;           flag = 1;         }       } else {         int tl, tr;         cin >> tl >> tr;         if (!flag) {           cout << sum(0, 0, n - 1, l + tl, l + tr - 1) << endl;         } else {           cout << sum(0, 0, n - 1, r - tr, r - tl - 1) << endl;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const long long infll = 0x3f3f3f3f3f3f3f3fLL;   inline long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   set<pair<long long, int> > s;   pair<long long, long long> a[200005];   pair<pair<long long, long long>, int> brige[200005];   set<pair<long long, int> >::iterator it;   int ans[200005];   int main() {     int n = read();     int m = read();     for (int i = 1; i <= n; i++) {       cin >> a[i].first >> a[i].second;     }     for (int i = 1; i < n; i++) {       brige[i] = make_pair(           make_pair(a[i].second - a[i + 1].first, a[i].first - a[i + 1].second),           i);     }     sort(brige + 1, brige + n);     for (int i = 1; i <= m; i++) {       long long kiss;       cin >> kiss;       s.insert(make_pair(kiss, i));     }     for (int i = 1; i < n; i++) {       long long r = -brige[i].first.second;       long long l = -brige[i].first.first;       it = s.lower_bound(make_pair(r, inf));       if (it == s.begin()) {         printf( No n );         return 0;       }       it--;       if (it->first < l) {         printf( No n );         return 0;       }       ans[brige[i].second] = it->second;       s.erase(it);     }     printf( Yes n );     for (int i = 1; i < n; i++) {       printf( %d  , ans[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   ifstream fin( input.txt );   ofstream fout( output.txt );   const long long mod = 1000000000 + 7;   const int maxn = 500 + 10;   const int inf = 1000000000;   int n, m, par[maxn][maxn][2], dist[maxn][maxn][2];   vector<int> v[maxn], e[2];   queue<pair<pair<int, int>, int> > q;   bool mark[maxn][maxn][2];   void pr(int x, int y, int o) {     if (par[x][y][o] == -1) return;     if (o == 0) {       pr(x, par[x][y][o], 1 - o);       e[o].push_back(y);     } else {       pr(par[x][y][o], y, 1 - o);       e[o].push_back(x);     }   }   int main() {     for (int i = 0; i < maxn; i++)       for (int j = 0; j < maxn; j++) dist[i][j][0] = dist[i][j][1] = inf;     cin >> n >> m;     for (int i = 1; i <= m; i++) {       int x, y;       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     q.push(make_pair(make_pair(1, n), 0));     par[1][n][0] = -1;     mark[1][n][0] = 1;     dist[1][n][0] = 0;     while (!q.empty()) {       int x = q.front().first.first;       int y = q.front().first.second;       int o = q.front().second;       q.pop();       if (o == 0) {         for (int i = 0; i < v[x].size(); i++)           if (!mark[v[x][i]][y][1]) {             q.push(make_pair(make_pair(v[x][i], y), 1));             dist[v[x][i]][y][1] = dist[x][y][0] + 1;             mark[v[x][i]][y][1] = 1;             par[v[x][i]][y][1] = x;           }       } else {         for (int i = 0; i < v[y].size(); i++)           if (v[y][i] != x && !mark[x][v[y][i]][0]) {             q.push(make_pair(make_pair(x, v[y][i]), 0));             dist[x][v[y][i]][0] = dist[x][y][1] + 1;             mark[x][v[y][i]][0] = 1;             par[x][v[y][i]][0] = y;           }       }     }     if (dist[n][1][0] != inf) {       cout << dist[n][1][0] / 2 << endl;       pr(n, 1, 0);       cout << 1 <<    ;       for (int i = 0; i < e[1].size(); i++) cout << e[1][i] <<    ;       cout << endl << n <<    ;       for (int i = 0; i < e[0].size(); i++) cout << e[0][i] <<    ;       cout << endl;     } else       cout << -1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 1e7 + 1;   char used[MAXN] = {0};   int lowest_divisor[MAXN];   int numbers[2][MAXN], numbers2[2][MAXN];   void sieve() {     for (int i = 2; i < MAXN; i += 2) {       used[i] = 1;       lowest_divisor[i] = 2;     }     for (long long i = 3; i < MAXN; i += 2) {       if (!used[i]) {         used[i] = 1;         lowest_divisor[i] = i;         for (long long j = i; (j * i) < MAXN; j += 2) {           if (!used[i * j]) {             used[i * j] = 1;             lowest_divisor[i * j] = i;           }         }       }     }   }   void factor(int n, bool fl) {     while (n > 1) {       numbers[fl][lowest_divisor[n]]++;       n /= lowest_divisor[n];     }   }   int main() {     sieve();     int n, m;     scanf( %d%d , &n, &m);     vector<int> a, b;     a.resize(n);     b.resize(m);     for (int i = 0; i < n; i++) {       int t;       scanf( %d , &t);       factor(t, 0);       a[i] = t;     }     for (int i = 0; i < m; i++) {       int t;       scanf( %d , &t);       factor(t, 1);       b[i] = t;     }     for (int i = 2; i < MAXN; i++) {       numbers2[0][i] = numbers[0][i] - min(numbers[0][i], numbers[1][i]);       numbers2[1][i] = numbers[1][i] - min(numbers[0][i], numbers[1][i]);     }     cout << n <<     << m << endl;     for (int i = 0; i < n; i++) {       int t = a[i];       while (t > 1) {         if (numbers[0][lowest_divisor[t]] > numbers2[0][lowest_divisor[t]]) {           numbers[0][lowest_divisor[t]]--;           a[i] /= lowest_divisor[t];         }         t /= lowest_divisor[t];       }     }     for (int i = 0; i < m; i++) {       int t = b[i];       while (t > 1) {         if (numbers[1][lowest_divisor[t]] > numbers2[1][lowest_divisor[t]]) {           numbers[1][lowest_divisor[t]]--;           b[i] /= lowest_divisor[t];         }         t /= lowest_divisor[t];       }     }     for (auto it : a) {       printf( %d  , it);     }     cout << endl;     for (auto it : b) {       printf( %d  , it);     }     return 0;   }