malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   const double eps = (1e-10);   using namespace std;   int dcmp(long double a, long double b) {     return fabsl(a - b) <= eps ? 0 : (a > b) ? 1 : -1;   }   int getBit(int num, int idx) { return ((num >> idx) & 1) == 1; }   int setBit1(int num, int idx) { return num | (1 << idx); }   long long setBit0(long long num, int idx) { return num & ~(1ll << idx); }   long long flipBit(long long num, int idx) { return num ^ (1ll << idx); }   void M() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int countNumBit1(int mask) {     int ret = 0;     while (mask) {       mask &= (mask - 1);       ++ret;     }     return ret;   }   long long X, Y, x, y, fl;   string st;   long long sx, sy, GX, GY;   int getquad(long long GX, long long GY) {     int fl;     if (GX >= 0 && GY >= 0)       fl = 1;     else if (GX <= 0 && GY >= 0)       fl = 2;     else if (GX <= 0 && GY <= 0)       fl = 3;     else       fl = 4;     return fl;   }   int main() {     cin >> x >> y >> st;     if (x == 0 && y == 0) {       cout <<  Yes n ;       return 0;     }     GX = 0, GY = 0;     for (int i = 0; i < ((int)(st).size()); i++) {       if (st[i] ==  U ) GY += 1;       if (st[i] ==  R ) GX += 1;       if (st[i] ==  L ) GX -= 1;       if (st[i] ==  D ) GY -= 1;     }     if (GX >= 0 && GY >= 0)       fl = 1;     else if (GX <= 0 && GY >= 0)       fl = 2;     else if (GX <= 0 && GY <= 0)       fl = 3;     else       fl = 4;     X = 0, Y = 0;     for (int i = 0; i < ((int)(st).size()); i++) {       if (st[i] ==  U ) Y += 1;       if (st[i] ==  R ) X += 1;       if (st[i] ==  L ) X -= 1;       if (st[i] ==  D ) Y -= 1;       sx = x - X;       sy = y - Y;       if (sx == 0 && sy == 0) {         cout <<  Yes n ;         return 0;       }       if (getquad(sx, sy) != fl) continue;       bool ok1 = (GX == 0 ? sx == 0 : sx % GX == 0);       bool ok2 = (GY == 0 ? sy == 0 : sy % GY == 0);       if (ok1 && ok2 && sx * GY == GX * sy) {         cout <<  Yes n ;         return 0;       }     }     cout <<  No n ;   }
#include <bits/stdc++.h>   using namespace std;   int s[100], n, r[100], h[100], c[100], mni = -1;   bool bad;   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> s[i] >> r[i] >> h[i] >> c[i];     for (int i = 0; i < n; i++) {       bad = false;       for (int j = 0; j < n; j++) {         if (s[i] < s[j] && r[i] < r[j] && h[i] < h[j]) bad = true;       }       if (!bad) {         if (mni == -1 || c[i] < c[mni]) mni = i;       }     }     cout << mni + 1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool sorts(pair<long long, long long> a, pair<long long, long long> b) {     return a.second < b.second;   }   int main() {     long long n, m, k, t;     cin >> n >> m >> k >> t;     string s[3] = { Carrots ,  Kiwis ,  Grapes };     vector<pair<long long, long long>> vec;     for (long long i = 0; i < k; i++) {       long long a, b;       cin >> a >> b;       a--;       b--;       vec.push_back(make_pair((m * a + b), 1));     }     sort(vec.begin(), vec.end());     long long sum = 0;     for (long long i = 0; i < k; i++) {       vec[i].second += sum;       sum = vec[i].second;     }     for (int i = 0; i < t; i++) {       long long a, b;       cin >> a >> b;       a--;       b--;       long long num = m * a + b;       for (int j = 0; j < vec.size(); j++) {         if (vec[j].first == num) {           cout <<  Waste  << endl;           break;         } else {           if (num < vec[0].first) {             cout << s[num % 3] << endl;             break;           } else if (num < vec[j].first) {             cout << s[(num - vec[j - 1].second) % 3] << endl;             break;           } else {             if (num > vec[vec.size() - 1].first) {               cout << s[(num - vec[vec.size() - 1].second) % 3] << endl;               break;             }           }         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3e5 + 5;   const int INF = 1e9;   vector<int> adj[MAXN], ts;   int tin[MAXN], en[MAXN], curt;   bool dag;   void dfs(int s, int p = -1) {     tin[s] = ++curt;     for (auto v : adj[s]) {       if (tin[v] && !en[v]) {         dag = false;         return;       }       if (!tin[v]) dfs(v, s);     }     en[s] = 1;     ts.push_back(s);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, m;     cin >> n >> m;     vector<int> v;     vector<vector<int>> g(n, vector<int>(m));     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> g[i][j];         if (g[i][j] > -1) v.push_back(g[i][j]);       }     }     map<int, int> to;     sort(v.begin(), v.end());     v.erase(unique(v.begin(), v.end()), v.end());     for (int i = 0; i < v.size(); i++) {       to[v[i]] = i;     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (g[i][j] > -1)           g[i][j] = to[g[i][j]];         else           g[i][j] = INF;       }     }     int cur = 0;     for (int i = 0; i < n; i++) {       vector<pair<int, int>> nums;       for (int j = 0; j < m; j++) nums.push_back({g[i][j], j});       sort(nums.begin(), nums.end());       cur += 2;       for (int j = 0; j < m; j++) {         auto p = nums[j];         if (p.first == INF) break;         if (j > 0 && nums[j].first != nums[j - 1].first) cur++;         adj[p.second].push_back(m + cur);         adj[m + cur - 1].push_back(p.second);       }     }     dag = true;     for (int i = 0; i < MAXN; i++)       if (!tin[i]) dfs(i);     if (!dag) {       cout <<  -1 n ;       return 0;     }     reverse(ts.begin(), ts.end());     for (auto x : ts)       if (x < m) cout << x + 1 <<    ;     cout <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 2147000000;   const int maxn = 4e5 + 10;   const int mod = 998244353;   int n, I;   int a[maxn];   int sum[maxn];   int main() {     scanf( %d%d , &n, &I);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     sort(a + 1, a + 1 + n);     for (int i = 1; i <= n; i++) {       sum[i] = sum[i - 1];       if (a[i] != a[i - 1]) sum[i]++;     }     int z = 8 * I / n;     int ans = 0;     if (z <= 20) {       int K = 1 << z;       if (sum[n] > K) {         int l = 1, r = 1;         ans = INF;         int num = 1;         while (l <= r && r <= n) {           while (r <= n && num <= K) {             ans = min(ans, l - 1 + n - r);             r++;             if (a[r] != a[r - 1]) num++;           }           while (l <= r && num > K) {             l++;             if (a[l] != a[l - 1]) num--;           }         }       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   using namespace std;   int dist[501][501];   int INF = 1000000000;   int s[501][501];   int c[501][501];   int main() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) {         dist[i][j] = INF;         c[i][j] = INF;       }     memset(s, 0, sizeof(s));     for (int i = 1; i <= n; i++) {       dist[i][i] = 0;     }     for (int i = 1; i <= m; i++) {       int x, y, l;       cin >> x >> y >> l;       dist[x][y] = l;       dist[y][x] = l;       c[x][y] = l;       c[y][x] = l;     }     for (int k = 1; k <= n; k++)       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++) {           if (dist[i][k] + dist[k][j] < dist[i][j]) {             dist[i][j] = dist[i][k] + dist[k][j];           }         }     memset(s, 0, sizeof(s));     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         for (int k = 1; k <= n; k++)           if (c[k][j] && dist[i][k] + c[k][j] == dist[i][j]) s[i][j]++;     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++) {         int ans = 0;         for (int k = 1; k <= n; k++)           if (dist[i][k] < INF && dist[k][j] < INF)             if (dist[i][k] + dist[k][j] == dist[i][j]) ans += s[i][k];         cout << ans <<    ;       }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     char ch = getchar();     int nega = 1;     while (!isdigit(ch)) {       if (ch ==  - ) nega = -1;       ch = getchar();     }     int ans = 0;     while (isdigit(ch)) {       ans = ans * 10 + ch - 48;       ch = getchar();     }     if (nega == -1) return -ans;     return ans;   }   int add(int x, int y) {     return x + y >= 1000000007 ? x + y - 1000000007 : x + y;   }   int sub(int x, int y) { return x - y < 0 ? x - y + 1000000007 : x - y; }   int mul(int x, int y) { return 1LL * x * y % 1000000007; }   int qpow(int x, int y) {     int ans = 1;     while (y) {       if (y & 1) ans = mul(ans, x);       x = mul(x, x);       y >>= 1;     }     return ans;   }   int inv(int x) { return qpow(x, 1000000007 - 2); }   int pw[600005], ipw[600005], i2 = 500000004;   int p[600005], pos[600005], val[600005], n, Q, cnt;   pair<int, int> v[600005];   struct Node {     int pw, l, r, val;   };   Node merge(Node x, Node y) {     Node ans;     ans.pw = mul(x.pw, y.pw);     ans.l = add(x.l, mul(x.pw, y.l));     ans.r = add(y.r, mul(y.pw, x.r));     ans.val = add(add(mul(x.pw, y.val), mul(x.val, y.pw)), mul(x.l, y.r));     return ans;   }   Node t[600005 * 4];   int d[600005];   void build(int u, int l, int r) {     if (l == r) {       t[u].pw = 1;       return;     }     int mid = (l + r) / 2;     build((u << 1), l, mid);     build((u << 1 | 1), mid + 1, r);     t[u] = merge(t[(u << 1)], t[(u << 1 | 1)]);   }   void update(int u, int l, int r, int p, int opt) {     if (l == r) {       if (opt == 1)         t[u] = (Node){2, d[l], d[l], 0};       else         t[u] = (Node){1, 0, 0, 0};       return;     }     int mid = (l + r) / 2;     if (p <= mid)       update((u << 1), l, mid, p, opt);     else       update((u << 1 | 1), mid + 1, r, p, opt);     t[u] = merge(t[(u << 1)], t[(u << 1 | 1)]);   }   void print() { printf( %d n , mul(t[1].val, ipw[n])); }   signed main() {     pw[0] = 1;     for (int i = 1; i < 600005; i++) pw[i] = add(pw[i - 1], pw[i - 1]);     ipw[0] = 1;     for (int i = 1; i < 600005; i++) ipw[i] = mul(ipw[i - 1], i2);     cin >> n;     for (int i = 1; i <= n; i++) p[i] = read(), v[++cnt] = make_pair(p[i], i);     cin >> Q;     for (int i = 1; i <= Q; i++) {       pos[i] = read(), val[i] = read();       v[++cnt] = make_pair(val[i], i + n);     }     sort(v + 1, v + cnt + 1);     for (int i = 1; i <= n; i++)       p[i] = lower_bound(v + 1, v + cnt + 1, make_pair(p[i], i)) - v;     for (int i = 1; i <= Q; i++)       val[i] = lower_bound(v + 1, v + cnt + 1, make_pair(val[i], i + n)) - v;     for (int i = 1; i <= cnt; i++) d[i] = v[i].first;     build(1, 1, cnt);     for (int i = 1; i <= n; i++) update(1, 1, cnt, p[i], 1);     print();     for (int i = 1; i <= Q; i++) {       update(1, 1, cnt, p[pos[i]], 0);       p[pos[i]] = val[i];       update(1, 1, cnt, p[pos[i]], 1);       print();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int MAXN = 1e5 + 5;   const int MAXM = 1e5 + 5;   int T, N, M, K, cas;   struct Edge {     int u, v, w;     Edge() {}     Edge(int u, int v, int w) : u(u), v(v), w(w) {}     bool operator<(const Edge& e) const { return w < e.w; }   } edges[MAXM];   int tot;   bool F[MAXN];   void init() {     tot = 0;     memset(F, false, sizeof(F));   }   void add_edge(int u, int v, int w) { edges[tot++] = Edge(u, v, w); }   int main() {     int u, v, w;     while (~scanf( %d %d %d , &N, &M, &K)) {       init();       for (int i = 0; i < M; i++) {         scanf( %d %d %d , &u, &v, &w);         add_edge(u, v, w);       }       for (int i = 0; i < K; i++) {         scanf( %d , &u);         F[u] = true;       }       int res = INF;       for (int i = 0; i < M; i++) {         u = edges[i].u, v = edges[i].v, w = edges[i].w;         if (F[u] == F[v]) continue;         res = min(res, w);       }       if (res == INF)         printf( -1 );       else         printf( %d n , res);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 10005;   int n, a[N];   int cnt[N];   int main() {     int T;     srand(time(0));     scanf( %d , &(T));     while (T--) {       memset(cnt, 0, sizeof(cnt));       double ex = 0;       for (int i = 1; i <= 250; i++)         scanf( %d , &(a[i])), cnt[a[i]]++, ex += a[i];       ex /= 250;       int tot = 0;       for (int i = 1; i <= ex / 3; i++) tot += cnt[i];       if (tot < 250 / 6 - 25) {       } else {         double dx = 0;         dx = 0;         for (int i = 1; i <= 250; i++) dx = max(dx, (double)a[i]);         dx /= 2.0;         ex = dx;       }       printf( %.0lf n , ex);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int NV = 105;   const int LNV = 11;   const int NE = 5015;   const int NQ = 1000005;   const int intmax = 0x7fffffff;   int f[2005];   int a[2005];   int n, m;   struct Edge {     int ne, y, v;   };   struct Edge2 {     int x, y, v;   };   bool cmp(Edge2 a, Edge2 b) { return a.v < b.v; }   struct DisSet {     int fa[NV], nv;     void init(int n) {       nv = n;       for (int i = 0; i < n; i++) fa[i] = i;     }     int find(int x) {       if (fa[x] == x) return x;       return fa[x] = find(fa[x]);     }     void uni(int x, int y) { fa[find(x)] = find(y); }   };   struct Graph {     Edge e[NE];     int ep, h[NV], nv, ne;     void init(int n, int m = NE) {       ne = m;       nv = n;       ep = 2;       memset(h, 0, 4 * nv);     }     void add(int a, int b, int v = 1) {       e[ep].ne = h[a];       e[ep].y = b;       e[ep].v = v;       h[a] = ep;       ep++;     }     bool dfs(int now, int d, int t) {       if (t == m + 1) {         if (d) return 1;         return 0;       }       int ans = intmax;       vector<pair<int, int> > p;       for (int i = h[now]; i; i = e[i].ne) {         if (!d)           if (e[i].y < f[t]) continue;         if (e[i].v) continue;         p.push_back(make_pair(e[i].y, i));       }       sort(p.begin(), p.end());       for (int i = 0; i < p.size(); i++) {         int key = p[i].second;         e[key].v = 1;         e[key ^ 1].v = 1;         if (dfs(e[key].y, (e[key].y > f[t]) | d, t + 1)) {           a[t] = e[key].y;           return 1;         }         e[key].v = 0;         e[key ^ 1].v = 0;       }       return 0;     }   };   Graph g;   int main() {     scanf( %d%d , &n, &m);     g.init(n, m);     int la;     scanf( %d , &la);     f[0] = la;     for (int i = 1; i <= m; i++) {       int a;       scanf( %d , &a);       g.add(la, a, 0);       g.add(a, la, 0);       la = a;       f[i] = a;     }     if (g.dfs(f[0], 0, 1)) {       printf( %d , f[0]);       for (int i = 1; i <= m; i++) printf(  %d , a[i]);       puts(  );     } else       puts( No solution );   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long loop = 0, t, n, a, b, c, d;     scanf( %lld , &t);     while (t--) {       loop++;       scanf( %lld%lld%lld%lld%lld , &n, &a, &b, &c, &d);       if (n * (a - b) > c + d || n * (a + b) < c - d)         printf( No n );       else         printf( Yes n );     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200000;   int n;   bool p[N];   int tot, ans[N][2];   int tmp[N], tmptot;   int rem[N], remtot;   int main() {     scanf( %d , &n);     for (int i = 3; i <= n / 2; ++i)       if (!p[i] && i % 2) {         tmptot = 0;         p[i * 2] = 1;         for (int j = i * 3; j <= n; j += i) {           if (p[j]) continue;           p[j] = 1;           tmp[tmptot++] = j;         }         for (int j = 0; j + 1 < tmptot; j += 2) {           ans[tot][0] = tmp[j];           ans[tot][1] = tmp[j + 1];           ++tot;         }         if (tmptot % 2) {           ans[tot][0] = i;           ans[tot][1] = tmp[tmptot - 1];           ++tot;           rem[remtot++] = i * 2;         } else {           ans[tot][0] = i;           ans[tot][1] = i * 2;           ++tot;         }       }     for (int i = 2; i <= n; ++i)       if (!p[i] && !(i % 2)) {         rem[remtot++] = i;       }     for (int i = 0; i + 1 < remtot; i += 2) {       ans[tot][0] = rem[i];       ans[tot][1] = rem[i + 1];       ++tot;     }     printf( %d n , tot);     for (int i = 0; i < tot; ++i) {       printf( %d %d n , ans[i][0], ans[i][1]);     }   }
#include <bits/stdc++.h>   using namespace std;   int z[100005], cnt[100005];   char s[100005];   void solve() {     int n, t, L, R;     n = strlen(s), L = R = 0;     z[0] = n;     for (int i = 1; i < n; i++) {       if (R < i) {         L = R = i;         while (R < n && s[R - L] == s[R]) R++;         z[i] = R - L, R--;       } else {         t = i - L;         if (z[t] + i - 1 < R)           z[i] = z[t];         else {           L = i;           while (R < n && s[R - L] == s[R]) R++;           z[i] = R - L, R--;         }       }     }     int ret = 0;     for (int i = (n)-1; i >= (0); i--) {       if (z[i] + i >= n) ++ret;       ++cnt[z[i]];     }     for (int i = (n)-1; i >= (0); i--) cnt[i] += cnt[i + 1];     printf( %d n , ret);     for (int i = (n)-1; i >= (0); i--)       if (z[i] + i >= n) printf( %d %d n , n - i, cnt[n - i]);   }   int main() {     scanf( %s , s);     solve();     return 0;   }
#include <bits/stdc++.h>   const double eps = 1e-8;   const int oo = 0x3f3f3f3f;   using namespace std;   long long a, b, c, d;   bool read() {     if (!(cin >> a >> b >> c >> d)) return false;     return true;   }   void process() { cout << b <<     << c <<     << c << endl; }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t = -1;     cin >> t;     while (t-- && read()) {       process();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void calcula(long long int n, long long int m, long long int r[10000],                long long int sumar[10000], long long int k, long long int p) {     priority_queue<long long int> q;     for (int i = 0; i < n; i++) q.push(r[i]);     for (int paso = 1; paso <= k; paso++) {       long long int x = q.top();       q.pop();       sumar[paso] = sumar[paso - 1] + x;       q.push(x - m * p);     }   }   long long int n, m, k, p;   long long int c[10000], r[10000];   long long int sumac[2000000], sumar[2000000];   int main() {     cin >> n >> m >> k >> p;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         int a;         cin >> a;         r[i] += a;         c[j] += a;       }     }     calcula(n, m, r, sumar, k, p);     calcula(m, n, c, sumac, k, p);     long long int maximo = -1000000000000000000LL;     for (long long int kc = 0; kc <= k; kc++) {       long long int kr = k - kc;       maximo = max(maximo, sumar[kr] + sumac[kc] - p * kc * kr);     }     cout << maximo << endl;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline bool chkmin(T &a, const T &b) {     return a > b ? a = b, 1 : 0;   }   template <typename T>   inline bool chkmax(T &a, const T &b) {     return a < b ? a = b, 1 : 0;   }   const int oo = 0x3f3f3f3f;   const int Mod = 1e9 + 7;   const int maxn = 500000;   struct edge {     int id, nxt;     edge() {}     edge(int _id, int _nxt) : id(_id), nxt(_nxt) {}   };   edge e[(maxn << 1) + 5];   int st[maxn + 5], en = 0;   inline void add_edge(int first, int second) {     e[en] = edge(second, st[first]), st[first] = en++;   }   int n;   set<pair<int, int> > all[maxn + 5];   int id[maxn + 5];   int sz[maxn + 5];   int dep[maxn + 5];   int ans = 0;   void dfs(int first, int f = -1) {     id[first] = first;     for (int i = st[first]; i != -1; i = e[i].nxt) {       int second = e[i].id;       if (second == f) continue;       dep[second] = dep[first] + 1;       dfs(second, first);       if (f == -1) {         chkmax(ans, (--all[id[second]].end())->first - 1);         continue;       }       if (sz[first] < sz[second]) swap(id[first], id[second]);       sz[first] += sz[second];       for (auto u : all[id[second]]) {         for (int v = (u.second), _end_ = (u.first); v < _end_; ++v) {           auto t = all[id[first]].lower_bound(make_pair(v, oo));           if (t == all[id[first]].end() || t->second > v)             all[id[first]].insert(make_pair(v + 1, v));           else {             auto t0 = t;             int from = t->second, to = t->first;             while (1) {               auto pre = t0++;               if (t0 == all[id[first]].end()) break;               if (pre->first < t0->second) break;               to = t0->first;             }             all[id[first]].erase(t, t0);             all[id[first]].insert(make_pair(to + 1, from));           }         }       }     }     if (!(int((all[id[first]]).size())))       all[id[first]].insert(make_pair(dep[first] + 1, dep[first])), sz[first] = 1;   }   int main() {     memset(st, -1, sizeof st), en = 0;     scanf( %d , &n);     for (int i = (0), _end_ = (n - 1); i < _end_; ++i) {       int first, second;       scanf( %d%d , &first, &second), --first, --second;       add_edge(first, second), add_edge(second, first);     }     dfs(0);     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int lft[26];   char s[111111], t[111111];   int n, m;   int main() {     gets(s);     n = (int)strlen(s);     for (int i = 0; i < n; ++i) lft[s[i] -  a ]++;     gets(t);     m = (int)strlen(t);     for (int i = 0; i < n; ++i) {       bool fnd = 0;       for (int let = 0; let < 26; ++let) {         if (!lft[let]) continue;         s[i] =  a  + let;         lft[let]--;         int pos = i + 1;         for (int j = 25; j >= 0; --j) {           for (int k = 0; k < lft[j]; ++k) s[pos++] =  a  + j;         }         s[n] = 0;         if (strcmp(s, t) == 1) {           fnd = 1;           break;         }         lft[let]++;       }       if (!fnd) {         cout <<  -1 n ;         return 0;       }     }     puts(s);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int size = 100010;   const int bound = 100;   int n, m, qq;   int res[size], arr[size], father[size];   vector<pair<int, int> > edge[size];   pair<int, int> q[size];   map<int, int> ans[size];   int find(int x) { return father[x] == -1 ? x : father[x] = find(father[x]); }   void merge(int x, int y) {     int xx = find(x), yy = find(y);     if (xx != yy) {       father[xx] = yy;     }   }   void solve() {     for (int c = 1; c <= m; c++) {       for (auto i : edge[c]) {         merge(i.first, i.second);       }       if (edge[c].size() > bound) {         for (int j = 0; j < qq; j++) {           if (find(q[j].first) == find(q[j].second)) {             ++res[j];           }         }       } else {         int num = 0;         for (auto i : edge[c]) {           arr[num++] = i.first;           arr[num++] = i.second;         }         sort(arr, arr + num);         num = unique(arr, arr + num) - arr;         for (int u = 0; u < num; u++) {           for (int v = u + 1; v < num; v++) {             if (find(arr[u]) == find(arr[v])) {               ++ans[arr[u]][arr[v]];             }           }         }       }       for (auto i : edge[c]) {         father[i.first] = father[i.second] = -1;       }     }   }   int main() {     int a, b, c;     memset(father, -1, sizeof(father));     memset(res, 0, sizeof(res));     cin >> n >> m;     for (int i = 0; i < m; i++) {       cin >> a >> b >> c;       edge[c].push_back(make_pair(a, b));     }     cin >> qq;     for (int i = 0; i < qq; i++) {       cin >> q[i].first >> q[i].second;     }     solve();     for (int i = 0; i < qq; i++) {       cout << res[i] +                   max(ans[q[i].first][q[i].second], ans[q[i].second][q[i].first])            << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int h, g, c, n, m, k, l, a[140] = {};     string s;     cin >> s;     n = s.length();     for (int i = 0; i < s.length(); i++) a[s[i]]++;     int res = 0;     for (int i = 0; i <= 139; i++)       if (a[i] > 0) {         res++;       }     if ((res < 2) || (n < 4) || (res > 4)) {       printf( No );       return 0;     }     int kol = res;     if (res == 4) {       printf( Yes );       return 0;     }     res = 0;     for (int i = 0; i <= 139; i++)       if (a[i] > 1) {         res++;       }     if ((kol == 3) && (res > 0)) {       printf( Yes );       return 0;     }     if ((kol == 2) && (res > 1)) {       printf( Yes );       return 0;     }     printf( No );   }