malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > g;   vector<int> lista;   vector<int> posicion;   vector<set<int> > s;   void genera(int u, int p, int lis, int pos) {     lista[u] = lis;     posicion[u] = pos;     vector<int> &ar = g[u];     for (int i = 0; i < int(ar.size()); i++)       if (ar[i] != p) genera(ar[i], u, lis, pos + 1);   }   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     g = vector<vector<int> >(n);     vector<pair<int, int> > arista;     for (int i = 0; i < n - 1; i++) {       int u, v;       cin >> u >> v;       u--;       v--;       g[u].push_back(v);       g[v].push_back(u);       arista.push_back(pair<int, int>(u, v));     }     int umax = 0;     lista = posicion = vector<int>(n);     for (int u = 1; u < n; u++)       if (int(g[u].size()) > int(g[umax].size())) umax = u;     {       lista[umax] = posicion[umax] = -1;       vector<int> &ar = g[umax];       for (int i = 0; i < int(ar.size()); i++) genera(ar[i], umax, i, 1);       s = vector<set<int> >(int(ar.size()));     }     int m;     cin >> m;     for (int i = 0; i < m; i++) {       int tipo;       cin >> tipo;       if (tipo == 1) {         int indar;         cin >> indar;         indar--;         int u;         if (posicion[arista[indar].first] < posicion[arista[indar].second])           u = arista[indar].second;         else           u = arista[indar].first;         s[lista[u]].erase(posicion[u]);       } else if (tipo == 2) {         int indar;         cin >> indar;         indar--;         int u;         if (posicion[arista[indar].first] < posicion[arista[indar].second])           u = arista[indar].second;         else           u = arista[indar].first;         s[lista[u]].insert(posicion[u]);       } else {         int u, v;         cin >> u >> v;         u--;         v--;         if (posicion[u] > posicion[v]) swap(u, v);         if (u == umax) {           if (v == umax) {             cout << 0 << endl;           } else {             set<int>::iterator it = s[lista[v]].upper_bound(posicion[v]);             if (it == s[lista[v]].begin())               cout << posicion[v] << endl;             else               cout << -1 << endl;           }         } else {           set<int>::iterator itu = s[lista[u]].upper_bound(posicion[u]);           set<int>::iterator itv = s[lista[v]].upper_bound(posicion[v]);           if (lista[u] == lista[v]) {             if (itu == itv)               cout << posicion[v] - posicion[u] << endl;             else               cout << -1 << endl;           } else {             int du;             if (itu == s[lista[u]].begin())               du = posicion[u];             else               du = -1;             int dv;             if (itv == s[lista[v]].begin())               dv = posicion[v];             else               dv = -1;             if (du != -1 and dv != -1)               cout << du + dv << endl;             else               cout << -1 << endl;           }         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   struct ac {     int x, y;   } t[202400];   bool cmp(const ac &a, const ac &b) {     if (a.x != b.x) {       return a.x < b.x;     } else {       return a.y < b.y;     }   }   bool wfHas(int x, int y) {     int l = 0, r = m - 1, mid;     while (l < r) {       mid = (l + r) / 2;       if (t[mid].x == x && t[mid].y == y) {         return true;       }       if (x < t[mid].x || x == t[mid].x && y < t[mid].y) {         r = mid;       } else {         l = mid + 1;       }     }     return (t[l].x == x && t[l].y == y);   }   bool wf(int k) {     int i, x, y;     for (i = 0; i < m; i++) {       x = t[i].x + k;       y = t[i].y + k;       if (x > n) x -= n;       if (y > n) y -= n;       if (x > y) {         x ^= y;         y ^= x;         x ^= y;       }       if (!wfHas(x, y)) {         return false;       }     }     return true;   }   void solve() {     int i, k;     int x, y;     for (i = 0; i < m; i++) {       scanf( %d %d , &x, &y);       if (x > y) {         k = x;         x = y;         y = k;       }       t[i].x = x;       t[i].y = y;     }     sort(t, t + m, cmp);     if (wf(1)) {       printf( Yes n );       return;     }     for (i = 2; i * i <= n; i++) {       if (n % i == 0) {         if (wf(i) || wf(n / i)) {           printf( Yes n );           return;         }       }     }     printf( No n );   }   int main() {     while (scanf( %d %d , &n, &m) != EOF) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long fen[2][2][1010][1010];   int n, m;   void updateFen(int a, int b, int x, int y, long long t) {     for (int i = x; i <= n / 2 + 5; i += i & (-i))       for (int j = y; j <= n / 2 + 5; j += j & (-j)) fen[a][b][i][j] ^= t;   }   long long getFen(int a, int b, int x, int y) {     long long res = 0;     for (int i = x; i > 0; i -= (i & (-i)))       for (int j = y; j > 0; j -= (j & (-j))) res ^= fen[a][b][i][j];     return res;   }   void update(int x, int y, long long t) {     updateFen(x % 2, y % 2, x / 2 + 1, y / 2 + 1, t);   }   long long get(int x, int y) {     return getFen(x % 2, y % 2, x / 2 + 1, y / 2 + 1);   }   int main() {     cin >> n >> m;     for (int i = 0; i < m; i++) {       int t;       cin >> t;       if (t == 1) {         int x1, y1, x2, y2;         long long res = 0;         cin >> x1 >> y1 >> x2 >> y2;         res ^= get(x2, y2);         res ^= get(x1 - 1, y2);         res ^= get(x2, y1 - 1);         res ^= get(x1 - 1, y1 - 1);         cout << res << endl;       } else {         int x1, y1, x2, y2;         long long v;         cin >> x1 >> y1 >> x2 >> y2 >> v;         update(x1, y1, v);         update(x2 + 1, y1, v);         update(x1, y2 + 1, v);         update(x2 + 1, y2 + 1, v);       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000004;   int a[N];   int spf[N], prime[N];   int cntp[N];   void sieve() {     int i, j;     for (i = 2; i < N; i++) {       if (!prime[i]) {         for (j = 1; 1LL * i * j < N; j++) {           prime[i * j] = 1;           if (!spf[i * j]) spf[i * j] = i;         }       }     }   }   int main() {     int n, k;     scanf( %d %d , &n, &k);     int i;     sieve();     for (i = 1; i <= n; i++) scanf( %d , &a[i]);     for (i = 1; i <= n; i++) {       int val = a[i];       while (val > 1) {         int sf = spf[val], cnt = 0;         while (val % sf == 0) {           val = val / sf;           cnt++;         }         cntp[sf] = max(cntp[sf], cnt);       }     }     while (k > 1) {       int sf = spf[k], cnt = 0;       while (k % sf == 0) {         k = k / sf;         cnt++;       }       if (cnt > cntp[sf]) {         printf( No n );         return 0;       }     }     printf( Yes n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int sum = 0;     cin >> n;     char a[n + 5];     int c[n + 5];     for (int i = 1; i <= n; i++) {       cin >> a[i];       if (a[i] ==  R )         c[i] = 0;       else if (a[i] ==  G )         c[i] = 1;       else if (a[i] ==  B )         c[i] = 2;     }     for (int i = 1; i <= n; i++) {       if (a[i] == a[i + 1]) {         sum++;         ++i;       }     }     cout << sum << endl;     for (int i = 2; i <= n; i++) {       if (c[i] == c[i - 1]) {         if (c[i - 1] != 0 && c[i + 1] != 0)           c[i] = 0;         else if (c[i - 1] != 1 && c[i + 1] != 1)           c[i] = 1;         else if (c[i - 1] != 2 && c[i + 1] != 2)           c[i] = 2;       }     }     for (int i = 1; i <= n; i++) {       if (c[i] == 0)         cout <<  R ;       else if (c[i] == 1)         cout <<  G ;       else if (c[i] == 2)         cout <<  B ;     }     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1024000000,1024000000 )   using namespace std;   void output(long long x) {     if (x < 0) putchar( - ), x = -x;     if (x == 0) {       putchar( 0 );       return;     }     int a[20], num = 0;     while (x) a[++num] = x % 10, x /= 10;     while (num > 0) putchar( 0  + a[num--]);   }   inline long long myInt() {     char c = getchar();     while (!isdigit(c) && c !=  - ) c = getchar();     int flag = 1;     if (c ==  - ) flag = -1, c = getchar();     long long x = 0;     while (isdigit(c)) {       x = (x * 10) + (c -  0 );       c = getchar();     }     if (-1 == flag) return -x;     return x;   }   const long long mod = 1000000007;   const int N = 2005;   int h, w, n;   struct node {     int x, y;   };   node a[N];   long long f[N];   long long p[200005];   long long myPow(long long x, long long y) {     long long ans = 1;     while (y) {       if (y & 1) ans = ans * x % mod;       x = x * x % mod;       y >>= 1;     }     return ans;   }   long long reverse(long long x) { return myPow(x, mod - 2); }   long long C(long long x, long long y) {     if (x < y) return 0;     if (x == y || y == 0) return 1;     return p[x] * reverse(p[y] * p[x - y] % mod) % mod;   }   long long cal(node from, node to) {     int xx = ((from.x - to.x) >= 0 ? (from.x - to.x) : -(from.x - to.x));     int yy = ((from.y - to.y) >= 0 ? (from.y - to.y) : -(from.y - to.y));     return C(xx + yy, xx);   }   int cmp(node a, node b) {     if (a.x != b.x) return a.x < b.x;     return a.y < b.y;   }   int main() {     h = myInt();     w = myInt();     n = myInt();     for (int i = 1; i <= n; i++) {       a[i].x = myInt();       a[i].y = myInt();     }     p[0] = 1;     for (int i = 1; i <= 200000; i++) {       p[i] = p[i - 1] * i % mod;     }     sort(a + 1, a + n + 1, cmp);     node E;     E.x = h;     E.y = w;     for (int i = n; i >= 1; i--) {       for (int j = i + 1; j <= n; j++) {         if (a[i].x <= a[j].x && a[i].y <= a[j].y) {           f[i] -= cal(a[i], a[j]) * f[j];           f[i] %= mod;         }       }       f[i] += cal(a[i], E);       f[i] %= mod;     }     node S;     S.x = 1;     S.y = 1;     long long ans = 0;     for (int i = 1; i <= n; i++) {       ans += f[i] * cal(S, a[i]);       ans %= mod;     }     if (ans < 0) ans += mod;     ans = cal(S, E) - ans;     ans %= mod;     if (ans < 0) ans += mod;     printf( %d n , (int)ans);   }
#include <bits/stdc++.h>   using namespace std;   int n, t, r, x, A[2000], B[2000], CODE = 0, ans = 0, z, j;   void Init() {     cin >> n >> t >> r;     if (r > t)       CODE = 1;     else       for (int i = 0; i < 1000; i++) {         A[i] = 0;         B[i] = 0;       }   }   int main() {     Init();     if (CODE == 1) {       for (int i = 0; i < n; i++) cin >> x;       cout << -1;     } else {       for (int i = 0; i < n; i++) {         cin >> x;         x += 500;         if (B[x] < r) {           j = x - 1;           z = r - B[x];           while (z != 0) {             if (A[j] == 0) {               A[j] = 1;               for (int q = j + 1; q < j + t + 1; q++) B[q]++;               ans++;               z--;             }             j--;           }         }       }       cout << ans;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, K;   int CtoI(int x) {     if (x ==  R ) return 1;     if (x ==  Y ) return 2;     if (x ==  B ) return 3;     if (x ==  W ) return 0;   }   int ItoC(int x) {     if (x == 1) return  R ;     if (x == 2) return  Y ;     if (x == 3) return  B ;     if (x == 0) return  . ;   }   int ar[2005], mt[2005][2][2];   bitset<2005> a[2005];   void ins(bitset<2005>& x) {     for (int i = 0; i < 2 * n; i++)       if (x[i]) {         if (!a[i].none())           x = x ^ a[i];         else {           a[i] = x;           return;         }       }     if (x[2 * n]) {       puts( NO );       exit(0);     }   }   int main() {     scanf( %d%d , &n, &K);     for (int i = (0), LIM = (n - 1); i <= LIM; i++) mt[i][0][0] = mt[i][1][1] = 1;     for (int i = (0), LIM = (K - 1); i <= LIM; i++) {       int m, x, cl;       char ch[10], col[2];       scanf( %s , ch);       scanf( %d , &m);       for (int j = (1), LIM = (m); j <= LIM; j++) scanf( %d , &ar[j]), ar[j]--;       if (ch[0] ==  m ) {         scanf( %s , col);         cl = CtoI(col[0]);         bitset<2005> A, B;         for (int j = (1), LIM = (m); j <= LIM; j++) {           if (mt[ar[j]][0][0]) A[ar[j] << 1] = A[ar[j] << 1] ^ 1;           if (mt[ar[j]][0][1]) B[ar[j] << 1] = B[ar[j] << 1] ^ 1;           if (mt[ar[j]][1][0]) A[ar[j] << 1 | 1] = A[ar[j] << 1 | 1] ^ 1;           if (mt[ar[j]][1][1]) B[ar[j] << 1 | 1] = B[ar[j] << 1 | 1] ^ 1;         }         A[n << 1] = cl & 1;         B[n << 1] = cl & 2;         ins(A), ins(B);       } else {         int b[2][2] = {};         if (ch[0] ==  R  && ch[1] ==  Y ) {           b[1][0] = b[0][1] = 1;         }         if (ch[0] ==  R  && ch[1] ==  B ) {           b[0][0] = b[1][1] = b[0][1] = 1;         }         if (ch[0] ==  Y ) {           b[0][0] = b[1][1] = b[1][0] = 1;         }         for (int j = (1), LIM = (m); j <= LIM; j++) {           static int c[2][2];           memset(c, 0, sizeof c);           int v = ar[j];           for (int i = (0), LIM = (1); i <= LIM; i++)             for (int j = (0), LIM = (1); j <= LIM; j++)               for (int k = (0), LIM = (1); k <= LIM; k++)                 c[i][k] ^= mt[v][i][j] * b[j][k];           for (int i = (0), LIM = (1); i <= LIM; i++)             for (int j = (0), LIM = (1); j <= LIM; j++) mt[v][i][j] = c[i][j];         }       }     }     for (int i = (2 * n - 1), LIM = (0); i >= LIM; i--) {       for (int j = (i + 1), LIM = (2 * n - 1); j <= LIM; j++)         if (a[i][j]) a[i][n << 1] = a[i][n << 1] ^ a[j][n << 1];     }     puts( YES );     for (int i = (0), LIM = (n - 1); i <= LIM; i++) {       int cl = a[i << 1][n << 1] | (a[i << 1 | 1][n << 1] << 1);       putchar(ItoC(cl));     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int q, l1, r1, l2, r2;     cin >> q;     while (q--) {       cin >> l1 >> r1 >> l2 >> r2;       if (l1 == l2 && r1 == r2)         cout << l1 <<     << r1 << endl;       else if (l1 == l2 && r1 != r2)         cout << r1 <<     << r2 << endl;       else if (l1 != l2 && r1 == r2)         cout << l1 <<     << l2 << endl;       else if (l1 != l2 && r1 != r2)         cout << l1 <<     << l2 << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   void input(vector<int>& v, int n) {     int i, io;     for (i = 0; i < n; i++) {       cin >> io;       v.push_back(io);     }   }   void output(vector<long long> v) {     long long i;     for (i = 0; i < v.size(); i++) cout << v.at(i) <<    ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     vector<int> v;     int i;     long long sum = 0;     input(v, 4);     string str;     cin >> str;     int n = str.length();     for (i = 0; i < n; i++) sum += v[str[i] -  0  - 1];     cout << sum << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long n, k;   priority_queue<long long, vector<long long>, greater<long long> > q;   signed main() {     scanf( %lld%lld , &n, &k);     while (n--) {       long long s, m;       scanf( %lld%lld , &s, &m);       if (q.size() >= k)         s = max(s, q.top()), q.pop();       else         s;       printf( %lld n , s + m);       q.push(s + m);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long a, b;     cin >> a >> b;     long long sum = 0;     long long notes = 0;     while (sum + notes + 1 <= a + b) {       ++notes;       sum += notes;     }     set<int> possible;     for (int i = 1; i <= notes; ++i) possible.insert(i);     vector<int> read_a;     while (a && possible.size()) {       if (*possible.rbegin() < a) {         int take = *possible.rbegin();         a -= take;         possible.erase(take);         read_a.push_back(take);       } else {         possible.erase(a);         read_a.push_back(a);         a = 0;       }     }     cout << read_a.size() <<   n ;     for (int x : read_a) cout << x <<    ;     cout <<   n ;     cout << possible.size() <<   n ;     for (int x : possible) cout << x <<    ;     cout <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   map<int, long long> mp;   const int maxn = 1e6 + 10;   char str[maxn];   int num[30];   int main() {     int n;     scanf( %d , &n);     while (n--) {       scanf( %s , str);       memset(num, 0, sizeof num);       int len = strlen(str);       for (int i = 0; i < len; i++) {         num[str[i] -  a ]++;       }       int state = 0;       for (int i = 0; i < 26; i++) {         if (num[i] & 1) {           state |= (1 << i);         }       }       mp[state]++;     }     long long ans = 0;     for (map<int, long long>::iterator it = mp.begin(); it != mp.end(); it++) {       ans += (it->second) * ((it->second) - 1) / 2;       int state = it->first;       for (int i = 0; i < 26; i++) {         if ((state >> i) & 1) {           int tmp = (1 << i) ^ (state);           ans += mp[tmp] * mp[state];         }       }     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 3452;   vector<int> G[maxn];   pair<int, int> snd[maxn][maxn];   int size[maxn][maxn];   long long f[maxn][maxn];   int n, cur, nxt;   void dfs(int p, int fl = -1) {     if (fl == cur) {       nxt = p;     }     size[cur][p] = 1;     snd[cur][p] = make_pair(nxt, fl);     for (auto t : G[p]) {       if (t == fl) {         continue;       }       dfs(t, p);       size[cur][p] += size[cur][t];     }   }   long long dp(int x, int y) {     if (x == y) {       return 0;     }     pair<int, int> path = snd[x][y];     long long sum = (long long)size[x][y] * size[y][x];     long long &v = f[x][y];     if (v != -1) {       return v;     }     long long l = dp(path.first, y) + sum;     long long r = dp(x, path.second) + sum;     return v = max(l, r);   }   int main() {     cin >> n;     for (int i = 1; i < (n); i++) {       int x, y;       cin >> x >> y;       G[x].push_back(y);       G[y].push_back(x);     }     for (int i = 1; i <= (n); i++) {       cur = i;       nxt = -1;       dfs(i);     }     memset(f, -1, sizeof(f));     long long ans = 0;     for (int i = 1; i <= (n); i++) {       for (int j = 1; j < (i); j++) {         ans = max(ans, dp(i, j));       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t, n;     cin >> t;     while (t--) {       cin >> n;       if (n >= 2)         cout << n - 2 <<   n ;       else         cout << n - 1 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 1e9 + 7;   const int N = 100;   long long bit[60];   int n, m;   int a[N][N];   int main() {     bit[0] = 1;     for (int i = 1; i < 60; i++) bit[i] = bit[i - 1] << 1;     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         scanf( %d , &a[i][j]);       }     }     long long ans = -n * m;     for (int col = 0; col < 2; col++) {       for (int i = 0; i < n; i++) {         int cnt = 0;         for (int j = 0; j < m; j++)           if (col == a[i][j]) cnt++;         ans += bit[cnt] - 1;       }       for (int j = 0; j < m; j++) {         int cnt = 0;         for (int i = 0; i < n; i++)           if (col == a[i][j]) cnt++;         ans += bit[cnt] - 1;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int l[305];   int c[305];   map<pair<int, int>, long long int> m;   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   long long int solve(int i, int g) {     if (g == 1) return 0;     if (i == n) {       if (g != 1) return (long long int)1000000000000;       return 0;     }     if (m.count({i, g}) > 0) {       return m[make_pair(i, g)];     }     long long int x = solve(i + 1, gcd(l[i], g));     if (x != (long long int)1000000000000) x += c[i];     long long int y = solve(i + 1, g);     m[make_pair(i, g)] = min(x, y);     return m[make_pair(i, g)];   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d , &l[i]);     }     for (int i = 0; i < n; ++i) {       scanf( %d , &c[i]);     }     m.clear();     long long int x = solve(0, 0);     if (x == (long long int)1000000000000)       printf( -1 );     else       cout << x;   }
#include <bits/stdc++.h>   using namespace std;   using ii = pair<int, int>;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int tc;     cin >> tc;     while (tc--) {       int n, mx = 0, mn;       cin >> n;       vector<int> v(n);       for (int &vi : v) {         cin >> vi;         mx = max(mx, vi);       }       set<ii> ans;       mn = n - mx;       vector<bool> sL(mn + 1, false), sR(mx + 1, false);       bool can = true;       for (int i = 0; i < n; ++i) {         if (i < mn) {           if (v[i] > mn) {             can = false;             break;           } else if (sL[v[i]]) {             can = false;             break;           }           sL[v[i]] = true;         } else {           if (sR[v[i]]) {             can = false;             break;           }           sR[v[i]] = true;         }       }       if (can && mn) ans.insert({mn, mx});       vector<bool> SL(mx + 1, false), SR(mn + 1, false);       can = true;       for (int i = 0; i < n; ++i) {         if (i >= mx) {           if (v[i] > mn) {             can = false;             break;           } else if (SR[v[i]]) {             can = false;             break;           }           SR[v[i]] = true;         } else {           if (SL[v[i]]) {             can = false;             break;           }           SL[v[i]] = true;         }       }       if (can && mn) ans.insert({mx, mn});       cout << ans.size() <<   n ;       for (const auto &x : ans) cout << x.first <<     << x.second <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int N, M;     scanf( %d%d , &N, &M);     long long ans = 0;     for (int b = M + 1; b <= (N + 1) / 2; b++) {       for (int a = M + 1; a <= N - M; a++) {         int coe = (b * 2 - 1 == N ? 3 : 6);         int num = (2 * b - a) * (N + 1 - b);         int den = b + a;         int x = (num - 1) / den;         if (x <= M) break;         x = min(x, N - M);         int tmp = max(x - M, 0);         ans += tmp * coe;       }     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int mxn = 2e5 + 10;   int sp[mxn], arr[mxn];   vector<int> required[mxn], bit[mxn];   int ask(int p, int x) {     int idx = lower_bound(required[p].begin(), required[p].end(), x) -               required[p].begin();     int ret = 0;     while (idx > 0) ret = max(ret, bit[p][idx]), idx -= idx & -idx;     return ret;   }   void update(int p, int x, int v) {     int idx = lower_bound(required[p].begin(), required[p].end(), x) -               required[p].begin() + 1;     while (idx <= required[p].size())       bit[p][idx] = max(v, bit[p][idx]), idx += idx & -idx;   }   int main() {     sp[1] = 1;     for (int i = 2; i < mxn; i++) {       if (sp[i]) continue;       for (int j = i; j < mxn; j += i) sp[j] = sp[j] == 0 ? i : sp[j];     }     int n, x, ret = 1;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &arr[i]), x = arr[i];       while (x != 1) {         int p = sp[x];         while (p == sp[x]) x /= p;         required[p].push_back(arr[i]);       }     }     for (int i = 1; i < mxn; i++) {       sort(required[i].begin(), required[i].end());       required[i].erase(unique(required[i].begin(), required[i].end()),                         required[i].end());       bit[i] = vector<int>(required[i].size() + 1, 0);     }     for (int i = 1; i <= n; i++) {       x = arr[i];       int curr = 0;       while (x != 1) {         int p = sp[x];         while (p == sp[x]) x /= p;         curr = max(curr, 1 + ask(p, arr[i]));       }       ret = max(ret, curr);       x = arr[i];       while (x != 1) {         int p = sp[x];         while (p == sp[x]) x /= p;         update(p, arr[i], curr);       }     }     printf( %d n , ret);   }