malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 3000000 + 11;   const int mod = 1e9 + 7;   const int MAXN = 3000000 + 5;   int n, m;   int c[MAXN];   struct Node {     int l, r;   } a[MAXN];   int lowbit(int i) { return i & (-i); }   long long sum(int x) {     long long sum = 0;     while (x) {       sum += c[x];       x -= lowbit(x);     }     return sum;   }   void add(int x, long long val) {     while (x <= n) {       c[x] += val;       x += lowbit(x);     }   }   int two_query(int x) {     int l = 1, r = n;     while (l < r) {       int mid = (l + r) >> 1;       if (sum(mid) >= x) {         r = mid;       } else         l = mid + 1;     }     return l;   }   long long p[100];   int lim;   void bz_init() {     p[0] = 1;     for (int i = 1; i < 30; i++) p[i] = p[i - 1] << 1;     lim = log(n) / log(2) + 1;   }   int bz_query(int x) {     int ans = 0, sum = 0;     for (int j = lim; j >= 0; j--) {       if (ans + p[j] <= n && sum + c[ans + p[j]] < x) {         sum += c[ans + p[j]];         ans += p[j];       }     }     return ans + 1;   }   int f[N];   char ans[N], s[N];   int main() {     scanf( %s , s + 1);     scanf( %d%d , &n, &m);     memset(c, 0, sizeof(c));     for (int i = 1; i <= n; i++) {       add(i, 1);     }     for (int i = 1; i <= m; i++) {       scanf( %d%d , &a[i].l, &a[i].r);     }     bz_init();     for (int now = n, i = m; i >= 1; i--) {       for (int x = a[i].l + 1, j = 1; a[i].r < now && j <= a[i].r - a[i].l + 1;            x += 2, j++, now--) {         if (x > a[i].r) x = a[i].l;         int pos = bz_query(a[i].r + 1);         add(pos, -1);         f[pos] = bz_query(x);       }     }     for (int i = 1, j = 0; i <= n; i++) {       if (f[i] != 0)         ans[i] = ans[f[i]];       else         ans[i] = s[++j];     }     printf( %s , ans + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     char c = getchar();     int x = 0, f = 1;     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -1;     for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;     return x * f;   }   inline void chkmax(int &x, int y) { x = x > y ? x : y; }   const int MAXN = 1e5 + 5;   const int INF = 1e9;   int ch[MAXN][26], fail[MAXN];   int N, M, cnt;   bool nd[MAXN];   char s[MAXN], t[MAXN];   vector<int> dp[MAXN];   inline void build() {     int p = 0;     for (int i = 1; i <= M; i++) {       int x = t[i] -  a ;       ch[p][x] = ++cnt;       p = ch[p][x];     }     nd[p] = true;     queue<int> Q;     for (int i = 0; i < 26; i++)       if (ch[0][i]) Q.push(ch[0][i]);     while (!Q.empty()) {       int x = Q.front();       Q.pop();       for (int i = 0; i < 26; i++)         if (!ch[x][i])           ch[x][i] = ch[fail[x]][i];         else {           int y = ch[x][i];           fail[y] = ch[fail[x]][i];           Q.push(y);         }     }   }   int main() {     scanf( %s , s + 1);     scanf( %s , t + 1);     N = strlen(s + 1);     M = strlen(t + 1);     build();     for (int i = 0; i <= N; i++) {       dp[i].resize(M + 1);       for (int j = 0; j <= M; j++) dp[i][j] = -INF;     }     dp[0][0] = 0;     for (int i = 0; i < N; i++)       if (s[i + 1] !=  ? ) {         int t = s[i + 1] -  a ;         for (int j = 0; j <= M; j++) {           int p = ch[j][t];           chkmax(dp[i + 1][p], dp[i][j] + nd[p]);         }       } else {         for (int t = 0; t < 26; t++)           for (int j = 0; j <= M; j++) {             int p = ch[j][t];             chkmax(dp[i + 1][p], dp[i][j] + nd[p]);           }       }     int ans = 0;     for (int i = 0; i <= M; i++) chkmax(ans, dp[N][i]);     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[4], i, n, x;   int main() {     for (cin >> n, i = 0; i < n; ++i)       cin >> x, --x, a[0] += !x, a[1] = max(a[0], a[1] + x),                                  a[2] = max(a[1], a[2] + !x),                                  a[3] = max(a[2], a[3] + x);     cout << a[3] << endl;   }
#include <bits/stdc++.h>   using namespace std;   int maxn, n, t, x;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       int in1, in2;       cin >> in1 >> in2;       x -= in1 - t;       if (x < 0) x = 0;       x += in2;       maxn = max(maxn, x);       t = in1;     }     cout << t + x <<     << maxn;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   pair<int, long long> operator+(const pair<int, long long> &A,                                  const pair<int, long long> &B) {     return {A.first + B.first, A.second + B.second};   }   pair<int, long long> operator-(const pair<int, long long> &A,                                  const pair<int, long long> &B) {     return {A.first - B.first, A.second - B.second};   }   struct FenwickTree {     pair<int, long long> fw[N];     void Update(int i, pair<int, long long> v) {       for (i; i < N; i += i & -i) fw[i] = fw[i] + v;     }     pair<int, long long> Query(int i) {       pair<int, long long> ans = {0, 0};       for (i; i > 0; i -= i & -i) ans = ans + fw[i];       return ans;     }     pair<int, long long> Query(int l, int r) {       if (l > r) return {0, 0};       return Query(r) - Query(l - 1);     }   } active_task;   int n, m;   int a[N], b[N];   long long t;   vector<int> val[N];   int find_index(int x, int r) {     int l = 1, f = 0;     while (l <= r) {       int m = (l + r) >> 1;       pair<int, long long> ret = active_task.Query(m);       if (ret.first <= x) {         f = m;         l = m + 1;       } else         r = m - 1;     }     return f;   }   void Solve() {     cin >> n >> m >> t;     int number = m;     pair<int, long long> ans = {t, 0};     for (int i = 1; i <= n; ++i) {       cin >> a[i];       b[i] = a[i];     }     sort(b + 1, b + n + 1);     int bSize = unique(b + 1, b + n + 1) - (b + 1);     for (int i = 1; i <= n; ++i) val[a[i]].push_back(i);     for (int i = 1; i <= bSize; ++i) {       int value = b[i];       for (int idx : val[value]) {         active_task.Update(idx, {1, a[idx]});       }       int l = 1, r = n, f = -1;       while (l <= r) {         int m = (l + r) >> 1;         pair<int, long long> ret1 = active_task.Query(m);         int idx = find_index((ret1.first - 1) / number * number, m);         pair<int, long long> ret2 = active_task.Query(idx);         long long sum = ret2.second * 2LL + active_task.Query(idx + 1, m).second;         if (sum <= t) {           l = m + 1;           f = m;         } else           r = m - 1;       }       if (f != -1) {         pair<int, long long> ret = active_task.Query(f);         if (ret.first > ans.second) ans = {value, ret.first};       }     }     cout << ans.second <<     << ans.first <<   n ;     for (int i = 1; i <= n; ++i)       active_task.Update(i, {-1, -a[i]}), val[a[i]].clear();   }   int main() {     int TC;     cin >> TC;     while (TC--) {       Solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int compareAscending(const void *a, const void *b) {     return (*(int *)a - *(int *)b);   }   int compareDecending(const void *a, const void *b) {     return (*(int *)b - *(int *)a);   }   int compareFirst(const void *a, const void *b) {     if (((pair<int, int> *)a)->first == ((pair<int, int> *)b)->first)       return ((pair<int, int> *)a)->second - ((pair<int, int> *)b)->second;     else       return ((pair<int, int> *)a)->first - ((pair<int, int> *)b)->first;   }   int compareSecond(const void *a, const void *b) {     if (((pair<int, int> *)a)->second == ((pair<int, int> *)b)->second)       return ((pair<int, int> *)a)->first - ((pair<int, int> *)b)->first;     else       return ((pair<int, int> *)a)->second - ((pair<int, int> *)b)->second;   }   bool isPrime(int a) {     if (a < 2) return false;     if (a < 4) return true;     if (a % 2 == 0) return false;     int s = (int)sqrt(a);     for (int i = 3; i <= s; i += 2) {       if (a % i == 0) return false;     }     return true;   }   int bsearch(int *a, int value, int l, int r) {     if (l == r) return l;     if (l + 1 == r) return a[l] >= value ? l : r;     int m = (l + r) / 2;     if (a[m] >= value)       return bsearch(a, value, l, m);     else       return bsearch(a, value, m + 1, r);   }   int main() {     long long a, b, res = 0, t;     scanf( %lld %lld , &a, &b);     while (a != 0 && b != 0) {       res += a / b;       t = a % b;       a = b;       b = t;     }     printf( %lld , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   multimap<long long int, long long int> par;   char en =   n ;   long long int inf = pow(10, 14);   long long int mod = 1e9 + 7;   long long int parent[2][500005];   long long int findRoot(long long int a, long long int which) {     if (parent[which][a] == a) return a;     parent[which][a] = findRoot(parent[which][a], which);     return parent[which][a];   }   void union1(long long int a, long long int b) {     long long int root1 = findRoot(a, 0);     long long int root2 = findRoot(b, 0);     if (root1 == root2) return;     long long int root11 = findRoot(a, 1);     long long int root21 = findRoot(b, 1);     if (root1 < root2) {       parent[0][root1] = root2;     } else {       parent[0][root2] = root1;     }     if (root11 > root21) {       parent[1][root11] = root21;     } else {       parent[1][root21] = root11;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n, m, p;     cin >> n >> m >> p;     string s;     cin >> s;     char arr[500005];     for (long long int i = 1; i < n + 1; i += 1) {       arr[i] = s[i - 1];       parent[0][i] = parent[1][i] = i;     }     bool visited[500005];     memset(visited, (false), sizeof(visited));     string s1;     cin >> s1;     long long int curr = p;     for (long long int i = 0; i < s1.length(); i += 1) {       if (s1[i] ==  R ) {         if (visited[curr + 1])           curr = findRoot(curr + 1, 0) + 1;         else           curr++;       } else if (s1[i] ==  L ) {         if (visited[curr - 1])           curr = findRoot(curr - 1, 1) - 1;         else           curr--;       } else {         if (arr[curr] ==  ( ) {           stack<char> st;           while (curr <= n) {             visited[curr] = true;             if (visited[curr - 1]) union1(curr - 1, curr);             if (visited[curr + 1]) union1(curr + 1, curr);             if (arr[curr] ==  ( ) {               st.push( ( );             } else {               st.pop();             }             if (st.empty()) {               long long int temp;               temp = findRoot(curr, 0) + 1;               if (temp > n) {                 temp = findRoot(curr, 1) - 1;               }               curr = temp;               break;             }             curr = findRoot(curr, 0) + 1;           }         } else {           stack<char> st;           while (curr >= 1) {             visited[curr] = true;             if (visited[curr - 1]) union1(curr - 1, curr);             if (visited[curr + 1]) union1(curr + 1, curr);             if (arr[curr] ==  ) ) {               st.push( ) );             } else {               st.pop();             }             if (st.empty()) {               long long int temp;               temp = findRoot(curr, 0) + 1;               if (temp > n) {                 temp = findRoot(curr, 1) - 1;               }               curr = temp;               break;             }             curr = findRoot(curr, 1) - 1;           }         }       }     }     for (long long int i = 1; i < n + 1; i += 1) {       if (!visited[i]) cout << arr[i];     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long t, i = 0, j, k, x, y, z, count = 0, p, flag = 0, ans = 0, sum = 0,                  l, n, m, max1, min1, pos, tmp, q;     t = 1;     while (t--) {       long long n, r;       scanf( %lld%lld , &n, &r);       long double x[1005], y[1005];       for (i = 0; i < n; i++) {         scanf( %Lf , &x[i]);       }       for (i = 0; i < n; i++) {         y[i] = -1.0 * 1000000000;         for (j = 0; j < i; j++) {           double p = abs(x[i] - x[j]);           if (p <= 2 * r) {             double q = y[j] + sqrtl(4 * r * r - p * p);             if (q > y[i]) y[i] = q;           }         }         if (y[i] == -1.0 * 1000000000) y[i] = 1.0 * r;         printf( %.15Lf  , y[i]);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2005;   const long double ep = 1e-10;   struct pnt {     long double x, y;     pnt() { x = y = 0; }     pnt(long double xx, long double yy) { x = xx, y = yy; }     pnt operator+(pnt a) { return pnt(x + a.x, y + a.y); }     void in() {       int xx, yy;       cin >> xx >> yy;       x = xx, y = yy;     }     long double operator^(const pnt &a) const { return x * a.y - y * a.x; }     bool operator<(const pnt &a) const { return x != a.x ? x < a.x : y < a.y; }     bool int_pnt(pnt &a) {       int xx = x + (x > 0 ? 0.5 : -0.5), yy = y + (y > 0 ? 0.5 : -0.5);       if (abs(x - xx) < ep && abs(y - yy) < ep) {         a = pnt(xx, yy);         return 1;       }       return 0;     }   } p[N], M, MM;   vector<pnt> P;   int n;   map<pnt, int> h;   bool opp[N];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       p[i].in();       M = M + p[i];       h[p[i]] = i;     }     M.x /= n, M.y /= n;     MM.x = M.x * 2, MM.y = M.y * 2;     for (int i = 1; i <= n; i++)       if (!opp[i]) {         pnt pp = pnt(MM.x - p[i].x, MM.y - p[i].y), qq;         if (pp.int_pnt(qq) && h.count(qq)) {           int t = h[qq];           opp[t] = 1;           opp[i] = 1;         }       }     for (int i = 1; i <= n; i++)       if (!opp[i]) P.push_back(p[i]);     if (P.empty())       puts( -1 );     else {       pnt A = P[0];       int ans = 0;       vector<pnt> D;       for (auto x : P) {         pnt AM = A + x;         AM.x /= 2, AM.y /= 2;         pnt d = pnt(M.x - AM.x, M.y - AM.y);         vector<long double> pos, neg;         for (auto y : P) {           long double l = d ^ pnt(y.x - AM.x, y.y - AM.y);           if (abs(l) < ep) continue;           if (l < 0)             neg.push_back(-l);           else             pos.push_back(l);         }         if (neg.size() != pos.size()) continue;         sort(neg.begin(), neg.end());         sort(pos.begin(), pos.end());         bool flag = 0;         for (int i = 0; i < pos.size(); i++)           if (abs(pos[i] - neg[i]) > ep) flag = 1;         if (!flag) D.push_back(d);       }       for (auto &x : D) {         if (x.y < 0) x.y = -x.y, x.x = -x.x;         if (x.y == 0 && x.x < 0) x.x = -x.x;       }       sort(D.begin(), D.end(),            [](const pnt &x, const pnt &y) { return (x ^ y) > 0; });       int sz = D.size();       for (int i = 0, j; i < sz; i = j) {         for (j = i; j < sz && (D[i] ^ D[j]) == 0; j++)           ;         ans++;       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   std::pair<long long, long long> go(long long m) {     long long cur = 1;     long long cur3 = 1;     long long cur13 = 8;     long long h = 0;     long long num = 0;     std::vector<long long> what;     while (1) {       while (h + cur3 >= cur13) {         if (cur3 > m) break;         cur++;         cur3 = cur13;         cur13 = (cur + 1) * (cur + 1) * (cur + 1);       }       if (h + cur3 > m) break;       h += cur3;       what.push_back(cur3);       num++;     }     std::vector<long long> ch(num + 1, 0);     long long sum = 0;     for (int i = 0; i < num; i++) {       sum += what[i];       ch[i + 1] = sum;     }     cur = 1;     while (cur * cur * cur <= m) cur++;     long long left = m;     long long ans = 0;     deque<long long> revans;     for (int step = num - 1; step >= 0; step--) {       cur++;       while (1) {         cur--;         if (ch[step] + cur * cur * cur > left) continue;         long long cum = ch[step] + cur * cur * cur;         bool f = false;         for (int i = 0; i < revans.size(); i++) {           cum += revans[i] * revans[i] * revans[i];           long long ra3 = (revans[i] + 1) * (revans[i] + 1) * (revans[i] + 1);           if (cum >= ra3) {             f = true;             break;           }         }         if (!f) break;       }       revans.push_front(cur);       cur3 = cur * cur * cur;       left -= cur3;       ans += cur3;     }     return make_pair(num, ans);   }   int main() {     long long m;     cin >> m;     std::pair<long long, long long> x = go(m);     cout << x.first <<     << x.second;   }
#include<bits/stdc++.h>   using namespace std;   typedef long long int ll;   typedef unsigned long long int ull;   #define pii acos(-1)   #define sc(n) scanf( %d ,&n)   #define sc2(n,x) scanf( %d%d ,&n,&x)   #define pr(n) printf( %d ,n)   #define scl(n) scanf( %I64d ,&n)   #define scl2(n,m) scanf( %I64d%I64d ,&n,&m)   #define prl(n) printf( %I64d ,n)   #define loop(x,n) for(int i=x;i<n;i++)   #define mp make_pair   #define pb push_back   #define nl printf(  n )   #define mod 998244353   #define lv -100000000   typedef pair<int,int> pi;   #define fastio           ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)   using namespace std;   int a[300005],c[300005];   int main()   {       int t,n,k;       cin>>t;       while(t--)       {           cin>>n>>k;           for(int i=0;i<n;i++)           {               cin>>a[i];           }           for(int i=0;i<k;i++)           {               cin>>c[i];           }           sort(a,a+n);           ll ans=0;           int l=0,flag=0;           for(int i=n-1;i>=0;i--)           {               if(flag==0 && c[l]<=c[a[i]-1]&&l<k)               {                   ans+=c[l];                   l++;                   //cout<< YES <<endl;               }               else               {                   flag++;                   ans+=c[a[i]-1];               }           }           cout<<ans<<endl;       }   }
#include <bits/stdc++.h>   using namespace std;   vector<long long int> v(26, 0);   long long int n, m;   bool myFun(string &a, string &s, long long int i, long long int j) {     if (i >= n && j >= m) {       return true;     }     if (j >= m) {       return false;     }     if (i >= n) {       while (j < m) {         if (s[j] !=  * ) {           return false;         }         j++;       }       return true;     }     if (a[i] == s[j]) {       return myFun(a, s, i + 1, j + 1);     }     if (s[j] ==  ? ) {       long long int temp = a[i] -  a ;       if (v[temp]) {         return myFun(a, s, i + 1, j + 1);       }       return false;     }     if (s[j] ==  * ) {       long long int temp = a[i] -  a ;       if (v[temp]) {         return myFun(a, s, i, j + 1);       } else {         return (myFun(a, s, i + 1, j + 1) || myFun(a, s, i, j + 1)) ||                myFun(a, s, i + 1, j);       }     }     return false;   }   int main() {     string s;     cin >> s;     for (long long int i = 0; i < s.length(); i++) {       long long int temp = s[i] -  a ;       v[temp] = 1;     }     cin >> s;     long long int k;     cin >> k;     for (long long int i = 0; i < k; i++) {       string a;       cin >> a;       n = a.length();       m = s.length();       if (myFun(a, s, 0, 0)) {         cout <<  YES  << endl;       } else {         cout <<  NO  << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int a, b, c, d, e, f;     scanf( %d , &a);     e = 0;     for (b = 1; b <= a; b++) {       for (c = b; c <= a; c++) {         f = b ^ c;         d = 0 ^ f;         if (b + c > d && d <= a && d >= c) {           e++;         }       }     }     printf( %d n , e);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int *xi, *di, n;     cin >> n;     xi = new int[n];     di = new int[n];     for (int i = 0; i < n; i++) cin >> xi[i] >> di[i];     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (xi[i] + di[i] == xi[j] && xi[j] + di[j] == xi[i] && j != i) {           cout <<  YES ;           return 0;         }       }     }     cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long fact[200005];   long long extgcd(long long a, long long b, long long& x, long long& y) {     long long d = a;     if (b != 0LL) {       d = extgcd(b, a % b, y, x);       y -= (a / b) * x;     } else {       x = 1;       y = 0;     }     return d;   }   long long mod_inverse(long long a, long long m) {     long long x, y;     extgcd(a, m, x, y);     return (m + x % m) % m;   }   long long mod_fact(long long n, long long p, long long& e) {     e = 0;     if (n == 0) return 1;     long long res = mod_fact(n / p, p, e);     e += n / p;     if (n / p % 2 != 0) {       return res * (p - fact[n % p]) % p;     }     return res * fact[n % p] % p;   }   long long mod_comb(long long n, long long k, long long p) {     if (n < 0 || k < 0 || n < k) return 0;     long long e1, e2, e3;     long long a1 = mod_fact(n, p, e1), a2 = mod_fact(k, p, e2),               a3 = mod_fact(n - k, p, e3);     if (e1 > e2 + e3) return 0;     return a1 * mod_inverse(a2 * a3 % p, p) % p;   }   long long mod_pow(long long x, long long n) {     long long ans = 1;     while (n > 0) {       if (n & 1) {         ans = ans * x % 998244353LL;       }       x = x * x % 998244353LL;       n >>= 1;     }     return ans;   }   int n;   long long k;   int h[200005];   int main(void) {     fact[0] = 1;     for (long long i = 1; i <= 200000; i++) {       fact[i] = fact[i - 1] * i % 998244353LL;     }     scanf( %d%lld , &n, &k);     for (int i = 0; i < n; i++) {       scanf( %d , &h[i]);     }     int cur = 0, nxt = 1;     long long po = 1;     int cnt = 0;     for (int i = 0; i < n; i++) {       int ans = h[i];       int cans = h[(i + 1) % n];       if (ans == cans) {         po = po * k % 998244353LL;       } else {         cnt++;       }     }     long long ans = 0;     long long v1 = 1;     for (int i = 0; i < cnt; i++) {       int rest = cnt - i;       long long v4 = mod_comb(cnt, i, 998244353LL);       long long sum = 0;       if (rest % 2 == 1) {         if (i == cnt) {           sum += v1 * mod_pow(2, rest - 1) % 998244353LL;           sum %= 998244353LL;         } else {           sum += v1 * mod_pow(2, rest - 1) % 998244353LL;           sum %= 998244353LL;         }       } else if (rest > 0) {         long long v3 = mod_pow(2, rest - 1);         long long v5 = mod_comb(rest - 1, rest / 2, 998244353LL);         v3 = (v3 - v5 + 998244353LL) % 998244353LL;         sum += v1 * v3 % 998244353LL;         sum %= 998244353LL;       }       sum = sum * v4 % 998244353LL;       ans += sum;       ans %= 998244353LL;       v1 = v1 * (k - 2LL) % 998244353LL;     }     ans = ans * po % 998244353LL;     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k = 0, cl[105 * 35], link[105 * 35];   vector<int> g[105 * 35];   vector<pair<int, int> > has[105];   bool dfs(int u) {     for (int i = 0; i < g[u].size(); ++i) {       int v = g[u][i];       if (!cl[v]) {         cl[v] = 1;         if (link[v] == 0 || dfs(link[v]) == true) {           link[v] = u;           return true;         }       }     }     return false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> m;     for (int i = 1; i <= n; ++i) {       int x;       cin >> x;       for (int j = 2; j <= sqrt(x); ++j) {         if (x % j == 0) {           while (x % j == 0) {             x = x / j;             has[i].push_back({j, ++k});           }         }       }       if (x > 1) has[i].push_back({x, ++k});     }     for (int i = 1; i <= m; ++i) {       int u, v;       cin >> u >> v;       if (u % 2 == 0) swap(u, v);       for (int j = 0; j < has[u].size(); ++j)         for (int q = 0; q < has[v].size(); ++q) {           if (has[u][j].first == has[v][q].first) {             g[has[u][j].second].push_back(has[v][q].second);           }         }     }     int rs = 0;     for (int j = 1; j <= k; ++j) {       for (int i = 1; i <= k; ++i) cl[i] = 0;       if (dfs(j)) ++rs;     }     cout << rs;     return 0;   }