malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long double eps = 1e-10;   int n, q, t;   double plc[500005], ans[500005];   struct Point {     long double x, y;     Point() {}     Point(long double _x, long double _y) { x = _x, y = _y; }     Point operator+(Point p) { return Point(x + p.x, y + p.y); }   } P[500005], Q[500005];   struct Node {     long double x, m, c;     int d;     Node() {}     Node(long double _x, long double _m, long double _c, int _d) {       x = _x, m = _m, c = _c, d = _d;     }     bool operator<(const Node &p) const { return x < p.x; }   } V[500005];   void Add(Point a, Point b, int v) {     if (abs(b.x - a.x) < eps) return;     if (a.x > b.x) {       swap(a, b);       v *= -1;     }     long double m = (b.y - a.y) / (b.x - a.x), c = a.y - a.x * m;     V[++t] = Node(a.x, v * m, v * c, 0);     V[++t] = Node(b.x, -v * m, -v * c, 0);     return;   }   Point Calc(Point a, Point b, Point p) {     return Point((b.x - a.x) * (p.y - a.y) / (b.y - a.y) + a.x, p.y);   }   int main() {     scanf( %d%d , &n, &q);     int p = 0;     for (int i = 0; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       P[i] = Point(x, y);       if (P[i].y < P[p].y) p = i;     }     for (int i = 1; i <= q; i++) {       double x;       scanf( %lf , &x);       plc[i] = x;       V[i] = Node(x, -1, -1, i);     }     t = q;     long double all = 0;     for (int i = 0; i < n; i++) {       all += P[i].x * P[(i + 1) % n].y - P[(i + 1) % n].x * P[i].y;       if (P[i].y < P[(i + 1) % n].y)         Add(P[i], P[(i + 1) % n], -1);       else         Add(P[(i + 1) % n], P[i], -1);     }     all = abs(all / 2);     int s = 0;     for (int i = p; i < n; i++) Q[s++] = P[i];     for (int i = 0; i < p; i++) Q[s++] = P[i];     for (int i = 0; i < n; i++) P[i] = Q[i];     int lf = 0, rg = 0;     Point lst = P[0];     for (int i = 0; i < n - 1; i++) {       int L = (lf + 1) % n, R = (rg + n - 1) % n;       Point now;       if (P[L].y < P[R].y) {         Point tmp = Calc(P[rg], P[R], P[L]) + P[L];         now.x = tmp.x * 0.5, now.y = tmp.y * 0.5;         lf = L;       } else {         Point tmp = Calc(P[lf], P[L], P[R]) + P[R];         now.x = tmp.x * 0.5;         now.y = tmp.y * 0.5;         rg = R;       }       Add(lst, now, 2);       lst = now;     }     sort(V + 1, V + t + 1);     long double a = 0.0, b = 0.0;     for (int i = 1; i <= t; i++) {       long double x = V[i].x, m = V[i].m, c = V[i].c;       if (V[i].d > 0)         ans[V[i].d] = all + (0.5 * a * x * x + b * x);       else {         all -= 0.5 * m * x * x + c * x;         a += m, b += c;       }     }     for (int i = 1; i <= q; i++) printf( %.10lf n , (double)ans[i]);   }
#include <bits/stdc++.h>   using namespace std;   int const N = 22, M = 1 << 22;   inline int nextInt() {     char c;     c = getchar();     while (c !=  -  && (c <  0  || c >  9 )) c = getchar();     int n = 0, s = 1;     if (c ==  - ) s = -1, c = getchar();     while (c >=  0  && c <=  9 ) n *= 10, n += c -  0 , c = getchar();     return n * s;   }   int mx;   int parents[M];   int Find(int a) { return parents[a] < 0 ? a : parents[a] = Find(parents[a]); }   void Union(int a, int b) {     a = Find(a), b = Find(b);     if (a == b) return;     if (parents[a] < parents[b])       parents[a] += parents[b], parents[b] = a;     else       parents[b] += parents[a], parents[a] = b;   }   void init() { memset(parents, (0xff), sizeof parents); }   int q[M];   bool ck[M];   int vis[M];   int n, m;   queue<int> que;   void upd(int t) {     if (vis[t] != -1) return;     while (!que.empty()) que.pop();     que.push(t);     vis[t] = t;     while (!que.empty()) {       int x = que.front();       que.pop();       if (ck[x]) Union(t, ((1 << n) - 1) ^ x);       for (int j = 0; j < (n); ++j)         if ((x >> j & 1) == 0) {           int u = x ^ (1 << j);           if (ck[u]) Union(t, ((1 << n) - 1) ^ u);           if (vis[u] == -1) {             vis[u] = t;             que.push(u);           }         }     }   }   int main() {     n = nextInt();     m = nextInt();     for (int i = 0; i < (m); ++i) q[i] = nextInt();     init();     int mask = (1 << n) - 1;     memset(vis, (0xff), sizeof vis);     for (int i = 0; i < (m); ++i) {       int t = q[i];       if (vis[mask ^ t] != -1) {         Union(t, vis[mask ^ t]);       }       upd(t);       ck[mask ^ t] = 1;     }     int ans = 0;     for (int i = 0; i < (m); ++i)       if (q[i] == Find(q[i])) ++ans;     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     char ar[100];     int len, count = 0, i, j;     gets(ar);     len = strlen(ar);     if (isupper(ar[0]) && islower(ar[1])) {       cout << ar;     } else {       for (i = 0; ar[i] !=   0 ; i++) {         if (isupper(ar[i])) {           count++;         }       }       if (len == 1) {         if (islower(ar[0])) {           ar[0] = toupper(ar[0]);         } else if (isupper(ar[0])) {           ar[0] = tolower(ar[0]);         }       } else if (count == len) {         for (i = 0; ar[i] !=   0 ; i++) {           ar[i] = tolower(ar[i]);         }       } else if (count == len - 1) {         if (islower(ar[0])) {           for (i = 1; ar[i] !=   0 ; i++) {             ar[i] = tolower(ar[i]);             ar[0] = toupper(ar[0]);           }         }       }       cout << ar;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     stack<int> s1;     int ans = 0;     int x = 1;     for (int i = 0; i < (2 * n); i++) {       char s[10];       scanf( %s , s);       if (strlen(s) == 3) {         int a;         scanf( %d , &a);         s1.push(a);       } else {         if (strlen(s) == 6 && !s1.empty() && s1.top() != x) {           while (!s1.empty()) s1.pop();           ans++;         } else {           if (!s1.empty()) s1.pop();         }         x++;       }     }     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int data[(int)2e5];   int dp[5001][5001];   int used[5001][5001];   string s;   int magic(int l, int r) {     if (l > r) return 1;     if (used[l][r] != -1) return used[l][r];     if (l == r) {       data[1]++;       return used[l][r] = 1;     }     int lk, rk, k, flag = 1, middle = (l + r) / 2;     lk = magic(l, (r - l) % 2 == 0 ? (middle - 1) : middle);     rk = magic(middle + 1, r);     k = min(lk, rk) + 1;     if (s[l] == s[r] and magic(l + 1, r - 1)) {       for (int i = 1; i <= k; i++) data[i]++;       return used[l][r] = k;     }     return used[l][r] = 0;   }   int main() {     memset(used, -1, sizeof(used));     cin >> s;     int n = s.size() - 1;     for (int i = 0; i <= n; i++) {       for (int j = i; j <= n; j++) magic(i, j);     }     for (int i = 1; i <= s.size(); i++) cout << data[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int x, y, a, b, r, m, t, pr;   int poc, kraj, uk;   int drvo[2000], sveca[2000];   void apdejt(int a, int b) {     while (a <= 2000) {       drvo[a] += b;       a += (a & -a);     }   }   int koliko(int a) {     int zbir = 0;     while (a > 0) {       zbir += drvo[a];       a -= (a & -a);     }     return zbir;   }   void solve() {     cin >> m >> t >> r;     uk = 0;     for (int i = 0; i < m; i++) {       cin >> a;       a += 500;       if (koliko(a) >= r) continue;       kraj = r - koliko(a);       for (int j = 0; j < kraj; j++) {         x = -1;         for (int z = a - 1; z >= a - t; z--) {           if (sveca[z] == 0) {             sveca[z] = 1;             uk++;             apdejt(z, 1);             apdejt(z + t + 1, -1);             x = 1;             break;           }         }         if (x == -1) {           cout <<  -1  << endl;           return;         }       }     }     cout << (uk) << endl;   }   int main() {     ios_base::sync_with_stdio(false);     int t;     t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 5;   struct edge {     int u, v, w, num;   } e[N], c[N];   map<long long, int> mp;   int n, m, q, s, siz[N], fa[N];   long long L[N], R[N];   bool vis[N];   int find(int x) { return fa[x] ? fa[x] = find(fa[x]) : x; }   bool comp(edge x, edge y) { return x.w < y.w; }   int main() {     int i, j, k, x, num;     scanf( %d%d , &n, &m);     for (i = 1; i <= m; i++) {       scanf( %d%d%d , &c[i].u, &c[i].v, &c[i].w);       c[i].num = i;     }     sort(c + 1, c + 1 + m, comp);     for (i = 1; i <= m; i++) siz[c[i].num] = i;     for (i = 1; i <= m; i = j + 1) {       for (j = i; j < m && c[j + 1].w == c[i].w; j++)         ;       for (k = i; k <= j; k++)         L[c[k].num] = 1LL * c[k].w * m + find(c[k].u),         R[c[k].num] = 1LL * c[k].w * m + find(c[k].v);       for (k = i; k <= j; k++)         if (find(c[k].u) != find(c[k].v)) fa[find(c[k].u)] = find(c[k].v);     }     memset(fa, 0, sizeof(fa));     scanf( %d , &q);     for (i = 1; i <= q; i++) {       scanf( %d , &s);       mp.clear();       bool flag = true;       num = 0;       for (j = 1; j <= s; j++) {         scanf( %d , &x);         if (!mp[L[x]]) fa[mp[L[x]] = ++num] = 0;         if (!mp[R[x]]) fa[mp[R[x]] = ++num] = 0;         if (find(mp[L[x]]) == find(mp[R[x]]))           flag = 0;         else           fa[find(mp[L[x]])] = find(mp[R[x]]);       }       puts(flag ?  YES  :  NO );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 2e9;   const int sz = 3;   const double eps = 1e-9;   const int maxn = 1e3 + 500, base = 1e9 + 7, maxm = 10;   string second[maxn];   int main() {     ios_base::sync_with_stdio(0);     ;     cin.tie(0);     int n;     cin >> n;     if (n == 1) {       cout << 6 << endl;       return 0;     }     int k = inf;     for (int i = 0; i < n; i++) cin >> second[i];     for (int i = 0; i < n; i++)       for (int j = i + 1; j < n; j++) {         int eq = 0;         for (int b = 0; b < 6; b++)           if (second[i][b] == second[j][b]) eq++;         if (eq == 0 || eq == 1) k = min(k, 2);         if (eq == 3 || eq == 2) k = min(k, 1);         if (eq >= 4) k = min(k, 0);       }     cout << k;   }
#include <bits/stdc++.h>   const long base = 151;   const long long MM = 1ll * 1000000007 * 1000000007;   using namespace std;   int BIT(int i, long long x) { return (x & (1 << i)); }   long long ONBIT(int i, long long x) { return (x | (1 << i)); }   long long OFFBIT(int i, long long x) { return (x & ~(1 << i)); }   long long FLIPBIT(int i, long long x) { return (x ^ (1 << i)); }   long long NUMBIT(long long x) { return __builtin_popcount(x); }   template <class T>   T GCD(T a, T b) {     T r;     while (b != 0) {       r = a % b;       a = b;       b = r;     }     return a;   }   template <class T>   T LCM(T a, T b) {     return a / GCD(a, b) * b;   }   void read() {     int x, y, u, v;     long long ans = 1;     cin >> x >> y >> u >> v;     int s1 = u - x;     int s2 = v - y;     long long tmp = min(s1, s2) - 1;     ans += (tmp + 1) * (abs(s2 - s1) + 1);     ans += (tmp + 1) * tmp;     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long te;     cin >> te;     while (te--) read();   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-9;   const double pi = 3.1415926535897932384626;   const double e = exp(1.0);   int main() {     int t;     double a, b, c;     double x, y, z;     double s;     while (~scanf( %lf , &s)) {       scanf( %lf%lf%lf , &a, &b, &c);       double tt = a + b + c;       if (tt == 0) {         x = y = 0;         z = s;       } else {         x = s * (a * 1.0 / tt);         y = s * (b * 1.0 / tt);         z = s * (c * 1.0 / tt);       }       printf( %.10lf %.10lf %.10lf n , x, y, z);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T gcd(T a, T b) {     while (b) {       a %= b;       swap(a, b);     }     return a;   }   template <class T>   inline T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   inline int nxt() {     int wow;     scanf( %d , &wow);     return wow;   }   inline long long int lxt() {     long long int wow;     scanf( %lld , &wow);     return wow;   }   inline double dxt() {     double wow;     scanf( %lf , &wow);     return wow;   }   int main() {     int n = nxt(), a[100];     for (int i = 1; i <= n; i++) a[i] = nxt();     if (a[n] == 15) {       puts( DOWN );       return 0;     }     if (a[n] == 0) {       puts( UP );       return 0;     }     if (n == 1) {       puts( -1 );       return 0;     }     if (a[n] > a[n - 1])       puts( UP );     else       puts( DOWN );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int d, n;     cin >> d >> n;     vector<int> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     int day = 0, res = 0;     for (int i = 0; i < n; i++) {       day = (day + a[i] - 1) % d + 1;       if (day != a[i]) {         if (day < a[i])           res += a[i] - day;         else           res += d - day + a[i];         day = a[i];       }     }     cout << res;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void umax(T &a, T b) {     if (a < b) a = b;   }   template <class T>   inline void umin(T &a, T b) {     if (a > b) a = b;   }   template <class T>   inline T abs(T a) {     return a > 0 ? a : -a;   }   template <class T>   inline T gcd(T a, T b) {     return __gcd(a, b);   }   template <class T>   inline T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   const int inf = 1e9 + 143;   const long long longinf = 1e18 + 143;   inline int read() {     int x;     scanf(  %d , &x);     return x;   }   const int N = 1e6 + 100;   int p[N], sz[N];   int get(int x) {     if (x == p[x]) return x;     return p[x] = get(p[x]);   }   int main() {     int n = read();     int m = read();     int mod = read();     for (int i = 1; i <= n; i++) p[i] = i;     for (int i = 1; i <= m; i++) {       int a = read();       int b = read();       a = get(a);       b = get(b);       if (a != b) {         p[a] = b;       }     }     vector<int> trees;     for (int i = 1; i <= n; i++) {       sz[get(i)] += 1;     }     for (int i = 1; i <= n; i++) {       if (i == get(i)) {         trees.push_back(sz[i]);       }     }     if (trees.size() == 1) {       printf( %d n , 1 % mod);       return 0;     }     int res = 1;     for (int i = 1; i <= (int)trees.size() - 2; i++)       res = (long long)res * n % mod;     for (int i = 0; i < trees.size(); i++) res = (long long)res * trees[i] % mod;     printf( %d n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int modular(long long int n, long long int pow, long long int N) {     long long int res = 1;     while (pow) {       if (pow & 1) res = (res % N * n % N) % N;       n = (n % N * n % N) % N;       pow = pow / 2;     }     return res;   }   long long int d, x, y;   void extendedEuclid(long long int A, long long int B) {     if (B == 0) {       d = A;       x = 1;       y = 0;     } else {       extendedEuclid(B, A % B);       long long int temp = x;       x = y;       y = temp - (A / B) * y;     }   }   long long int modInverse(long long int A, long long int N) {     extendedEuclid(A, N);     return (x % N + N) % N;   }   int main() {     long long int n, i;     cin >> n;     vector<pair<long long int, long long int>> v;     for (i = 0; i < n; i++) {       long long int x, y;       cin >> x >> y;       v.push_back({x, y});     }     long long int ans = min(v[n - 1].first, v[n - 1].second);     long long int flag = 0;     for (i = n - 2; i >= 0; i--) {       if (v[i].second >= ans && v[i].first >= ans)         ans = min(v[i].second, v[i].first);       else if (v[i].second >= ans)         ans = v[i].second;       else if (v[i].first >= ans)         ans = ans = v[i].first;       else {         flag = 1;         break;       }     }     if (flag == 1)       cout <<  NO  << endl;     else       cout <<  YES  << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int n, m;   int head[N], nxt[N * 2], to[N * 2], tot;   int vis[N], stp[N];   int dp[N][20];   int dfn[N], low[N], dep = 0;   int stk[N * 5], top = 0;   int belong[N], block = 0;   int odd[N], col[N];   void init() {     memset(head, -1, sizeof(head));     tot = 0;   }   void add(int x, int y) {     to[tot] = y;     nxt[tot] = head[x];     head[x] = tot++;   }   void DFS_st(int u, int fa) {     vis[u] = 1;     stp[u] = stp[fa] + 1;     dp[u][0] = fa;     for (int i = 1; i < 20; i++) dp[u][i] = dp[dp[u][i - 1]][i - 1];     for (int i = head[u]; ~i; i = nxt[i]) {       int v = to[i];       if (!vis[v]) DFS_st(v, u);     }   }   void tarjan(int u, int fa) {     dfn[u] = low[u] = ++dep;     stk[top++] = u;     vis[u] = 1;     for (int i = head[u]; ~i; i = nxt[i]) {       int v = to[i];       if (v == fa) continue;       if (!dfn[v]) {         tarjan(v, u);         low[u] = min(low[u], low[v]);       } else if (vis[v])         low[u] = min(low[u], dfn[v]);     }     if (low[u] == dfn[u]) {       block++;       do {         top--;         belong[stk[top]] = block;         vis[stk[top]] = 0;       } while (stk[top] != u);     }   }   void DFS(int u, int fa) {     vis[u] = 1;     for (int i = head[u]; ~i; i = nxt[i]) {       int v = to[i];       if (!vis[v]) {         col[v] += col[u];         DFS(v, u);       }     }   }   int LCA(int x, int y) {     if (stp[x] < stp[y]) swap(x, y);     int delta = stp[x] - stp[y];     for (int i = 0; i < 20; i++)       if (delta & (1 << i)) x = dp[x][i];     if (x == y) return x;     for (int i = 19; i >= 0; i--)       if (dp[x][i] != dp[y][i]) x = dp[x][i], y = dp[y][i];     return dp[x][0];   }   int main() {     init();     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       int x, y;       scanf( %d%d , &x, &y);       add(x, y);       add(y, x);     }     for (int u = 1; u <= n; u++)       if (!vis[u]) DFS_st(u, 0);     memset(vis, 0, sizeof(vis));     for (int u = 1; u <= n; u++)       if (!dfn[u]) tarjan(u, 0);     for (int u = 1; u <= n; u++) {       if (!odd[belong[u]]) {         for (int i = head[u]; ~i; i = nxt[i]) {           int v = to[i];           if ((stp[u] + stp[v]) % 2 == 0 && belong[v] == belong[u]) {             odd[belong[u]] = 1;             break;           }         }       }     }     for (int u = 1; u <= n; u++)       if (belong[u] == belong[dp[u][0]] && dp[u][0] != 0 && odd[belong[u]])         col[u]++;     memset(vis, 0, sizeof(vis));     for (int u = 1; u <= n; u++)       if (!vis[u]) DFS(u, 0);     int q;     scanf( %d , &q);     while (q--) {       int u, v;       scanf( %d%d , &u, &v);       int lca = LCA(u, v);       if (lca == 0) {         printf( No n );       } else if ((stp[u] + stp[v] - stp[lca] * 2) % 2 == 1)         printf( Yes n );       else {         if (col[u] + col[v] != col[lca] * 2)           printf( Yes n );         else           printf( No n );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double p[8][10020];   int main() {     int n;     int l[8], r[8];     scanf( %d , &n);     double ex = 0;     double all = 1.0;     for (int i = 0; i < n; i++) {       scanf( %d %d , &l[i], &r[i]);       all *= (r[i] - l[i] + 1);     }     for (int i = 1; i <= 10000; ++i) {       double cr = 0;       for (int j = 0; j < n; ++j) {         if (r[j] < i || l[j] > i) continue;         for (int k = 0; k < n; ++k) {           if (k == j) continue;           double t = 1.0;           if (k < j) {             if (r[k] < i) continue;             t *= (r[k] - max(i, l[k]) + 1);           } else {             if (r[k] <= i) continue;             t *= (r[k] - max(i + 1, l[k]) + 1);           }           for (int s = 0; s < n; ++s) {             if (s == j || s == k) continue;             if (s < j) {               if (l[s] >= i) {                 t = 0;                 break;               }               t *= (min(r[s], i - 1) - l[s] + 1);             } else {               if (l[s] > i) {                 t = 0;                 break;               }               t *= (min(r[s], i) - l[s] + 1);             }           }           if (t != 0) {           }           cr += t;         }       }       ex += cr / all * i;     }     printf( %.15lf n , ex);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (a < b) swap(a, b);     if (b == 0) return a;     return gcd(b, a % b);   }   int main() {     int n, m;     cin >> n >> m;     int a0, b0, x;     for (int i = 0; i < n + 1; i++) {       cin >> x;       if (!i) a0 = x;     }     for (int i = 0; i < m + 1; i++) {       cin >> x;       if (!i) b0 = x;     }     if (n > m) {       int sign;       if (a0 < 0 && b0 > 0 || a0 > 0 && b0 < 0) cout <<  - ;       cout <<  Infinity n ;     } else if (n < m) {       cout <<  0/1 n ;     } else {       int sign;       if (a0 < 0 && b0 < 0 || a0 > 0 && b0 > 0)         sign = 1;       else         sign = -1;       a0 = abs(a0);       b0 = abs(b0);       int g = gcd(a0, b0);       a0 /= g;       b0 /= g;       a0 *= sign;       cout << a0 <<  /  << b0 <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   long long dp[200000][3];   string s;   signed main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(false);     cin >> s;     long long l = s.size();     vector<vector<bool> > in(l, vector<bool>(3));     dp[0][0] = dp[0][1] = dp[0][2] = 10000000000;     if ((s[0] -  0 ) % 3 == 0) {       dp[0][0] = 0;       in[0][0] = 1;     } else {       long long d = (s[0] -  0 ) % 3;       dp[0][d] = 0;       in[0][d] = 1;       dp[0][0] = 1;     }     for (long long i = 1; i < l; i++) {       long long d = (s[i] -  0 ) % 3;       for (long long j = 0; j < 3; j++) {         if (s[i] !=  0 )           dp[i][j] = min(dp[i - 1][(j + 3 - d) % 3], dp[i - 1][j] + 1),           in[i][j] = (dp[i][j] != dp[i - 1][j] + 1);         else {           dp[i][j] = dp[i - 1][j] + (dp[i - 1][j] == i);           in[i][j] = (dp[i - 1][j] != i);         }       }     }     if (dp[l - 1][0] == l) {       for (long long i = 0; i < l; i++) {         if (s[i] ==  0 ) return cout <<  0 n , 0;       }       return cout << -1, 0;     }     string ans =   ;     long long sm = 0;     for (long long i = l - 1; i >= 0; i--) {       if (in[i][sm]) {         ans += s[i];         sm += 3 - (s[i] -  0 ) % 3;         sm %= 3;       }     }     reverse(ans.begin(), ans.end());     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int MX = 2e5 + 1;   bool sieve[MX], in_graph[MX], vstd[MX];   vector<int> pos[MX], adj[MX];   int mu[MX];   ll res[MX];   void init() {     vector<int> primes;     mu[1] = 1;     for (int i = 2; i < MX; ++i) {       if (!sieve[i]) {         mu[i] = -1;         primes.push_back(i);       }       for (auto j : primes) {         if (i * j >= MX) break;         sieve[i * j] = true;         if (i % j == 0) {           mu[i * j] = 0;           break;         }         mu[i * j] = -mu[i];       }     }   }   int dfs(int u, int p) {     int res = 1;     vstd[u] = true;     for (auto c : adj[u]) {       if (c == p || !in_graph[c]) continue;       res += dfs(c, u);     }     return res;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     init();     int n;     cin >> n;     for (int i = 1; i <= n; ++i) {       int a;       cin >> a;       pos[a].push_back(i);     }     for (int i = 0; i < n - 1; ++i) {       int u, v;       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     for (int i = 1; i < MX; ++i) {       for (int j = i; j < MX; j += i) {         for (auto k : pos[j]) {           in_graph[k] = true;         }       }       for (int j = i; j < MX; j += i) {         for (auto k : pos[j]) {           if (!vstd[k]) {             ll cnt = dfs(k, 0);             res[i] += cnt * (cnt + 1) / 2;           }         }       }       for (int j = i; j < MX; j += i) {         for (auto k : pos[j]) {           in_graph[k] = false;           vstd[k] = false;         }       }     }     for (int i = 1; i < MX; ++i) {       ll ans = 0;       for (int j = 1; j * i < MX; ++j) {         ans += mu[j] * res[j * i];       }       if (ans) {         cout << i <<     << ans <<   n ;       }     }   }