malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   map<int, int> mp;   vector<int> object, ans;   map<int, int> counter;   int gcd(int a, int b) { return a == 0 ? b : gcd(b % a, a); }   int main() {     int n, num;     scanf( %d , &n);     for (int i = 0; i < n * n; i++) {       scanf( %d , &num);       object.push_back(num);     }     sort(object.begin(), object.end());     for (int i = object.size() - 1; i >= 0; i--) {       if (counter[object[i]]) {         counter[object[i]]--;         continue;       }       for (int j = 0; j < ans.size(); j++) {         int temp = gcd(ans[j], object[i]);         counter[temp] += 2;       }       ans.push_back(object[i]);     }     for (int i = 0; i < n; i++) {       if (i) printf(   );       printf( %d , ans[i]);     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100005;   vector<long long> g[100005];   long long vis[MAXN], s[MAXN], gc[MAXN];   long long n;   void dfs(long long v) {     vis[v] = 1;     s[v] = 1;     for (auto i : g[v]) {       if (!vis[i]) {         dfs(i);         s[v] += s[i];         gc[v] = max(gc[v], s[i]);       }     }     gc[v] = max(gc[v], n - s[v]);   }   int pa[MAXN], sz[MAXN];   long long find_pa(long long pos) {     if (pa[pos] != pos) pa[pos] = find_pa(pa[pos]);     return pa[pos];   }   void join(int a, int b) {     int x = find_pa(a), y = find_pa(b);     if (x != y) {       if (sz[x] >= sz[y])         sz[x] += sz[y], pa[y] = x;       else         sz[y] += sz[x], pa[x] = y;     }   }   void dsu_init(long long n) {     for (long long i = 0, ggdem = n; i < ggdem; ++i) pa[i] = i, sz[i] = 1;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       cin >> n;       for (long long i = 0, ggdem = n - 1; i < ggdem; ++i) {         long long u, v;         cin >> u >> v;         u--;         v--;         g[u].push_back(v);         g[v].push_back(u);       }       dfs(0);       long long mini = n;       for (long long i = 0, ggdem = n; i < ggdem; ++i) {         mini = min(mini, gc[i]);       }       vector<long long> v;       for (long long i = 0, ggdem = n; i < ggdem; ++i) {         if (gc[i] == mini) v.push_back(i);       }       assert(((int)v.size()) <= 2);       sort(v.begin(), v.end());       if (((int)v.size()) == 1) {         for (long long k = 0, ggdem = 2; k < ggdem; ++k)           cout << 1 <<     << g[0][0] + 1 <<   n ;       } else {         assert(mini == n / 2 && n % 2 == 0);         dsu_init(n);         for (long long i = 0, ggdem = n; i < ggdem; ++i) {           for (auto j : g[i]) {             if (min(i, j) != v[0] || max(i, j) != v[1]) {               join(i, j);             }           }         }         long long br = 0;         for (long long i = 0, ggdem = n; i < ggdem; ++i) {           if (((int)g[i].size()) == 1 && i != v[0] &&               find_pa(i) != find_pa(v[1])) {             cout << i + 1 <<     << g[i][0] + 1 <<   n ;             cout << i + 1 <<     << v[1] + 1 <<   n ;             br++;             break;           }         }         assert(br);       }       for (long long i = 0, ggdem = n; i < ggdem; ++i) g[i].clear();       for (long long i = 0, ggdem = n; i < ggdem; ++i)         vis[i] = 0, s[i] = 0, gc[i] = 0;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[1000005];   queue<long long int> q;   vector<long long int> v;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int i, j, k, n, m, mid;     cin >> k;     string s;     cin >> s;     n = s.size();     int co = 0;     long long int sum = 0;     if (k == 0) {       for (i = 0; i < n; i++) {         if (s[i] ==  0 ) {           co++;         } else           co = 0;         sum += (co);       }       cout << sum;       return 0;     }     for (i = 0; i < n; i++) {       if (s[i] ==  1 ) {         a[i] = co;         co = 0;         v.push_back(i);       } else         co++;     }     long long int first = 0;     long long int l = v.size();     for (i = k - 1; i < l; i++) {       long long int temp1 = a[v[first]] + 1;       long long int temp2;       if (i + 1 < l)         temp2 = v[i + 1] - v[i];       else         temp2 = n - v[i];       sum += temp1 * temp2;       first++;     }     cout << sum;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m;   long long a[100000], b[100000];   long long val(long long p) {     long long ret = 0;     for (long long i = 0; i < n; ++i) ret += max((long long)0, p - a[i]);     for (long long i = m - 1; i >= 0; --i) ret += max((long long)0, b[i] - p);     return ret;   }   int32_t main() {     cin >> n >> m;     for (long long i = 0; i < n; ++i) cin >> a[i];     for (long long i = 0; i < m; ++i) cin >> b[i];     sort(a, a + n), sort(b, b + m);     long long l = 0, r = 1e9 + 1, m1, m2, v1, v2;     long long ans = LLONG_MAX;     while (l <= r) {       m1 = l + (r - l) / 3;       m2 = l + 2 * (r - l) / 3;       v1 = val(m1), v2 = val(m2);       if (v1 <= v2) {         ans = min(v1, ans);         r = m2 - 1;       } else {         ans = min(v2, ans);         l = m1 + 1;       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int v[112345];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &v[i]);     sort(v, v + n);     int res = 1;     for (int i = 0; i < n; i++) {       if (v[i] >= res) {         v[i] = res;         res++;       }     }     printf( %d n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   long long a[maxn], b[maxn];   int main() {     int m, n;     long long sum1 = 0, sum2 = 0, max1 = 0, max2 = 0, t1, t2;     scanf( %d%d , &m, &n);     for (int i = 1; i <= m; i++) {       scanf( %lld , &a[i]);       sum1 += a[i];       if (a[i] > max1) {         t1 = i;         max1 = a[i];       }     }     for (int i = 1; i <= n; i++) {       scanf( %lld , &b[i]);       sum2 += b[i];       if (b[i] > max2) {         t2 = i;         max2 = b[i];       }     }     long long ans1 = sum1 * n, ans2 = sum2 * m;     for (int i = 1; i <= m; i++) {       if (i != t1 && a[i] < sum2) ans2 = ans2 - sum2 + a[i];     }     for (int i = 1; i <= n; i++) {       if (i != t2 && b[i] < sum1) ans1 = ans1 - sum1 + b[i];     }     printf( %lld n , min(ans1, ans2));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   string st;   int call() {     int s = 0, r = -1, neg = 0;     for (int i = 0; st[i]; i++) {       if (st[i] ==  ( )         s++;       else         s--;       if (s <= 1) r = i;       if (s < 0) neg = 1;     }     int ans = 0;     if (s == 2 && !neg) {       s = 0;       for (int i = 0; st[i]; i++) {         if (st[i] ==  ( )           s++;         else           s--;         if (i > r) {           if (st[i] ==  ( ) {             if (s - 2 >= 0) ans++;           }         }       }     }     return ans;   }   int main() {     cin >> n >> st;     int ans = call();     string y;     for (int i = st.size() - 1; i >= 0; i--) {       if (st[i] ==  ) )         y +=  ( ;       else         y +=  ) ;     }     st = y;     ans += call();     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100005;   int n, m, far[MAXN], a[MAXN];   struct LCT {     int fa[MAXN], ch[MAXN][2];     int s[MAXN], xs[MAXN];     long long xs2[MAXN], sum[MAXN], ans[MAXN], xans[MAXN];     bool isroot(int x) { return ch[fa[x]][0] != x && ch[fa[x]][1] != x; }     int get(int x) { return ch[fa[x]][1] == x; }     void up(int x) {       s[x] = s[ch[x][0]] + s[ch[x][1]] + xs[x] + 1;       sum[x] = sum[ch[x][0]] + sum[ch[x][1]] + 1ll * a[x] * (xs[x] + 1);       ans[x] = ans[ch[x][0]] + ans[ch[x][1]] + xans[x] +                a[x] * (1ll * (xs[x] + 1) * (xs[x] + 1) - xs2[x]) +                2ll * a[x] * (xs[x] + 1) * s[ch[x][1]] +                2ll * sum[ch[x][0]] * (s[x] - s[ch[x][0]]);     }     void rotate(int x) {       int f1 = fa[x], f2 = fa[f1], id = get(x);       ch[f1][id] = ch[x][id ^ 1];       fa[ch[f1][id]] = f1;       if (!isroot(f1)) ch[f2][get(f1)] = x;       fa[x] = f2;       ch[x][id ^ 1] = f1;       fa[f1] = x;       up(f1);     }     void splay(int x) {       while (!isroot(x)) {         int f1 = fa[x];         if (!isroot(f1)) {           if (get(x) == get(f1))             rotate(f1);           else             rotate(x);         }         rotate(x);       }       up(x);     }     void access(int x) {       for (int y = 0; x; y = x, x = fa[x]) {         splay(x);         xs[x] += s[ch[x][1]] - s[y];         xs2[x] += 1ll * s[ch[x][1]] * s[ch[x][1]] - 1ll * s[y] * s[y];         xans[x] += ans[ch[x][1]] - ans[y];         ch[x][1] = y;         up(x);       }     }     void link(int x, int y) {       access(x), splay(x);       access(y), splay(y);       fa[x] = y;       xs[y] += s[x];       xans[y] += ans[x];       xs2[y] += 1ll * s[x] * s[x];       up(y);     }     void cut(int x, int y) {       access(y), splay(y);       splay(x);       fa[x] = 0;       xs[y] -= s[x];       xans[y] -= ans[x];       xs2[y] -= 1ll * s[x] * s[x];       up(y);     }     bool is_anc(int x, int y) {       access(y);       splay(y), splay(x);       return !isroot(y);     }     long long ask() {       splay(1);       return ans[1];     }     void modify(int x, int v) {       access(x), splay(x);       a[x] = v, up(x);     }   } tr;   char op[2];   int main() {     scanf( %d , &n);     for (int i = 2; i <= n; i++) scanf( %d , &far[i]);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++) tr.s[i] = 1;     for (int i = 2; i <= n; i++) tr.link(i, far[i]);     printf( %.10lf n , (double)tr.ask() / n / n);     scanf( %d , &m);     while (m--) {       int x, y;       scanf( %s%d%d , op, &x, &y);       if (op[0] ==  P ) {         if (tr.is_anc(x, y)) swap(x, y);         tr.cut(x, far[x]);         far[x] = y;         tr.link(x, far[x]);       } else         tr.modify(x, y);       printf( %.10lf n , (double)tr.ask() / n / n);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[200010], b[200010];   int n, m;   inline bool isprime(int x) {     for (int i = 2; i * i <= x; i++)       if (x % i == 0) return 0;     return 1;   }   unsigned long long hashseed;   unsigned long long h1[200010], h2[200010], t[200010];   inline void prehash() {     for (int i = 1; i < n; i++)       h1[i] = h1[i - 1] * hashseed + (unsigned long long)b[i];     for (int i = n - 1; i; i--)       h2[i] = h2[i + 1] * hashseed + (unsigned long long)b[i];     t[0] = 1;     for (int i = 1; i <= n; i++) t[i] = t[i - 1] * hashseed;   }   inline unsigned long long q1(int l, int r) {     return h1[r] - h1[l - 1] * t[r - l + 1];   }   inline unsigned long long q2(int l, int r) {     return h2[l] - h2[r + 1] * t[r - l + 1];   }   inline bool check(int l, int r) { return q1(l, r) == q2(l, r); }   set<int> ans;   int main() {     srand(time(NULL));     hashseed = rand() * rand();     while (!isprime(hashseed)) hashseed++;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , a + i);     for (int i = 1; i < n; i++) b[i] = a[i + 1] - a[i];     prehash();     bool flag;     for (int i = 1; i <= n; i++) {       flag = 1;       if (i != 1 && !check(1, i - 1)) flag = 0;       if (i != n) {         if (a[1] + a[i] + m != a[i + 1] + a[n]) flag = 0;         if (i != n - 1 && !check(i + 1, n - 1)) flag = 0;       }       if (flag) ans.insert((a[1] + a[i]) % m);     }     cout << ans.size() << endl;     for (set<int>::iterator it = ans.begin(); it != ans.end(); it++)       printf( %d  , *it);   }
#include <bits/stdc++.h>   using namespace std;   long long int T, n;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> T;     while (T--) {       cin >> n;       set<long long int> chk_div;       vector<long long int> g;       for (long long int i = 0, u; i < n; i++) cin >> u, g.push_back(u);       sort(g.begin(), g.end());       long long int p = (g[0] * g[n - 1]);       for (long long int i = 2; i * i <= p; i++)         if (!(p % i)) chk_div.insert(i), chk_div.insert(p / i);       set<long long int> div(g.begin(), g.end());       (chk_div == div) ? (cout << p <<   n ) : (cout <<  -1 n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1 << 15 + 5;   int deg[MAXN], s[MAXN];   queue<int> q;   int main() {     int n, sum = 0, u, v;     cin >> n;     while (!q.empty()) q.pop();     for (int i = 0; i < n; i++) {       cin >> deg[i] >> s[i];       if (deg[i] == 1) q.push(i);       sum += deg[i];     }     cout << sum / 2 << endl;     while (!q.empty()) {       u = q.front();       q.pop();       if (deg[u] == 0) continue;       deg[u] = 0;       v = s[u];       s[v] ^= u;       deg[v]--;       if (deg[v] == 1) q.push(v);       cout << u <<     << v << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       vector<long> vt;       long i = 0, n, temp, count = 1;       cin >> n;       for (int i = 0; i < n; i++) {         cin >> temp;         vt.push_back(temp);       }       sort(vt.begin(), vt.end());       while (i < n) {         if (vt[i] <= count) {           count++;         } else {           temp = count;           bool check = true;           for (int j = i; j < n; j++) {             if (vt[j] <= temp) {               check = true;               temp++;               i = j;               break;             } else {               check = false;               temp++;             }           }           if (check == false)             break;           else             count = temp;         }         i++;       }       cout << count << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long h[1000005];   long long dp[1000005][2];   const int mod = 1e9 + 7;   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %I64d , &h[i]), h[i]--;     for (int i = 1; i <= n; i++) {       dp[i][0] = (dp[i - 1][0] + dp[i - 1][1] * min(h[i], h[i - 1]) + h[i]) % mod;       dp[i][1] = ((min(h[i + 1], h[i])) +                   min(h[i + 1], min(h[i], h[i - 1])) * dp[i - 1][1]) %                  mod;     }     printf( %I64d n , dp[n][0]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool cmp(pair<int, int> p1, pair<int, int> p2) {     return (p1.first < p2.first) ||            (p1.first == p2.first && p1.second > p2.second);   }   int main() {     bool b[200000];     int t[200000];     int n;     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> t[i];       b[i] = true;     }     int answer = 1;     for (int i = 2; i <= n; ++i) {       if (t[i] == 0) {         ++answer;         continue;       }       if (b[t[i]])         b[t[i]] = false;       else         ++answer;     }     cout << answer;   }
#include <bits/stdc++.h>   using namespace std;   FILE* stream;   const long long P = 998244353;   long long mpow(long long n, int deg) {     if (deg == 0) {       return 1;     }     if (deg % 2 == 0) {       return mpow((n * n) % P, deg / 2) % P;     }     return (mpow(n, deg - 1) * n) % P;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long w, h;     cin >> w >> h;     cout << mpow(2, w + h) % P << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n;   map<int, int> a;   bool found;   int b[5][5], sum, cols[5];   void backTrack(int x, int y, int sumRow, int sumDia1, int sumDia2) {     if (x == n) {       if (sumDia1 != sum || sumDia2 != sum) return;       for (int i = 0; i < n; i++)         if (cols[i] != sum) return;       found = true;       return;     }     for (typeof(a.begin()) it = a.begin(); it != a.end(); it++)       if (it->second > 0) {         it->second--;         sumRow += it->first;         if (x == y) sumDia1 += it->first;         if (x + y == n - 1) sumDia2 += it->first;         cols[y] += it->first;         int xx = x, yy = y + 1;         if (yy == n) yy = 0, xx++;         b[x][y] = it->first;         if (yy == 0) {           if (sumRow == sum) backTrack(xx, yy, 0, sumDia1, sumDia2);         } else           backTrack(xx, yy, sumRow, sumDia1, sumDia2);         it->second++;         sumRow -= it->first;         if (x == y) sumDia1 -= it->first;         if (x + y == n - 1) sumDia2 -= it->first;         cols[y] -= it->first;         if (found) return;       }   }   int main() {     sum = 0;     scanf( %d , &n);     for (int i = 0, val; i < n * n; i++) {       scanf( %d , &val);       a[val]++;       sum += val;     }     sum /= n;     found = false;     memset(cols, 0, sizeof(cols));     backTrack(0, 0, 0, 0, 0);     printf( %d n , sum);     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (j) putchar(   );         printf( %d , b[i][j]);       }       putchar(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double PI = 3.141592653589793;   const double EPS = 1e-9;   const int N = 1e6 + 5;   const long long mod = 1e9 + 7;   const int oo = 1e9 + 9;   int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};   int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};   int n, m;   long long row[1005], col[1005];   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i <= n - 1; i++) {       for (int j = 0; j <= m - 1; j++) {         int x;         scanf( %d , &x);         row[i] += x;         col[j] += x;       }     }     long long min_row = 1e18;     int ans_row;     for (int i = 0; i <= n; i++) {       long long curr = 0;       for (int j = i, x = 2; j < n; j++, x += 4) {         curr += x * x * row[j];       }       for (int j = i - 1, x = 2; j >= 0; j--, x += 4) {         curr += x * x * row[j];       }       if (curr < min_row) {         ans_row = i;         min_row = curr;       }     }     long long min_col = 1e18;     int ans_col;     for (int i = 0; i <= m; i++) {       long long curr = 0;       for (int j = i, y = 2; j < m; j++, y += 4) {         curr += (long long)y * y * col[j];       }       for (int j = i - 1, y = 2; j >= 0; j--, y += 4) {         curr += (long long)y * y * col[j];       }       if (curr < min_col) {         ans_col = i;         min_col = curr;       }     }     printf( %lld n%d %d , min_col + min_row, ans_row, ans_col);   }
#include <bits/stdc++.h>   using namespace std;   long long input() {     long long x = 0, f = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) f |= ch ==  - , ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return f ? -x : x;   }   const int N = 107;   string s[N];   map<string, int> p;   int vis[N];   string res;   int main() {     int n = input(), m = input();     for (int i = 1; i <= n; i++) {       cin >> s[i];       if (p[s[i]])         res += s[i], vis[i] = vis[p[s[i]]] = 1;       else         reverse(s[i].begin(), s[i].end()), p[s[i]] = i;     }     string ser = res;     reverse(ser.begin(), ser.end());     for (int i = 1; i <= n; i++) {       if (vis[i]) continue;       int flag = 1;       for (int j = 0; j < m / 2; j++) {         if (s[i][j] != s[i][m - j - 1]) {           flag = 0;           break;         }       }       if (flag == 1) {         res += s[i];         break;       }     }     res += ser;     cout << res.length() << endl;     cout << res << endl;   }
#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long sum = 0, f = 1;     char ch = getchar();     while (ch !=  -  && (ch <  0  || ch >  9 )) ch = getchar();     if (ch ==  - ) ch = getchar(), f = -1;     while (ch <=  9  && ch >=  0 ) sum = sum * 10 + ch -  0 , ch = getchar();     return sum * f;   }   int n;   long long w[22];   bool used[(1 << 20) + 10];   int st[22], num, end_, maxn;   bool col[22];   long long A[(1 << 20) + 10], B[(1 << 20) + 10], cntA, cntB;   long long AA, BB, AA_, BB_;   void dfs(int a, long long cha, int ty, int allodd, int alleven) {     if (a == end_) {       if (!ty)         A[++cntA] = cha;       else         B[++cntB] = cha;       if (!ty) {         if (allodd) AA = cha;         if (alleven) AA_ = cha;       } else {         if (allodd) BB = cha;         if (alleven) BB_ = cha;       }       return;     }     col[a] = 0, dfs(a + 1, cha - w[st[a]], ty, 0, alleven);     col[a] = 1, dfs(a + 1, cha + w[st[a]], ty, allodd, 0);   }   bool chk(int sta) {     num = 0;     long long sum = 0;     for (int i = 1; i <= n; i++)       if (sta & (1 << (i - 1))) st[++num] = i, sum += w[i];     if (num == 1 || (sum & 1) != ((num - 1) & 1)) return 0;     int mid = num >> 1;     cntA = cntB = 0;     AA = AA_ = BB = BB_ = 2e18;     end_ = mid + 1, dfs(1, 0, 0, 1, 1);     end_ = num + 1, dfs(mid + 1, 0, 1, 1, 1);     sort(A + 1, A + 1 + cntA);     sort(B + 1, B + 1 + cntB);     int pB = cntB, pA = cntA;     if (abs(AA + BB_) <= num - 1 || abs(AA_ + BB) <= num - 1) return 1;     for (int i = 1; i <= cntA; i++) {       if (A[i] == AA_ || A[i] == AA) continue;       long long l = 1 - num - A[i], r = num - 1 - A[i];       while (pB && B[pB] > r) pB--;       if (!pB) return 0;       if (B[pB] >= l) return 1;     }     for (int i = 1; i <= cntB; i++) {       if (B[i] == BB_ || B[i] == BB) continue;       long long l = 1 - num - B[i], r = num - 1 - B[i];       while (pA && A[pA] > r) pA--;       if (!pA) return 0;       if (A[pA] >= l) return 1;     }     return 0;   }   int f[(1 << 20) + 10 + 10];   int s[22];   int main() {     n = read();     int q = 0;     for (int i = 1; i <= n; i++) {       w[i] = read();       if (w[i]) w[++q] = w[i];     }     n = q;     maxn = (1 << n) - 1;     for (int i = 1; i <= maxn; i++) {       used[i] = chk(i);       if (used[i]) f[i] = 1;     }     for (int i = 1; i <= maxn; i++)       if (used[i]) {         int g = maxn ^ i;         for (int j = g; j; j = (j - 1) & g) {           f[i + j] = max(f[i + j], f[j] + f[i]);         }       }     cout << n - f[maxn];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9 + 7;   string to_string(string s) { return     + s +    ; }   string to_string(char s) { return string(1, s); }   string to_string(const char* s) { return to_string((string)s); }   string to_string(bool b) { return (b ?  true  :  false ); }   template <typename A>   string to_string(A);   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename A>   string to_string(A v) {     bool f = 1;     string r =  { ;     for (const auto& x : v) {       if (!f) r +=  ,  ;       f = 0;       r += to_string(x);     }     return r +  } ;   }   void debug_out() { cout << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cout <<     << to_string(H);     debug_out(T...);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int v;     cin >> v;     while (v--) {       int n = 250;       vector<int> a(n);       double m = 0;       for (auto i = (0); i <= (n - 1); ++i) cin >> a[i], m += a[i];       m /= n;       double var = 0;       for (auto i = (0); i <= (n - 1); ++i) var += (a[i] - m) * (a[i] - m);       var /= n;       if (abs(var - m) > abs(var - (m * m + m) / 3)) {         int mx = *max_element((a).begin(), (a).end());         cout << mx / 2 <<   n ;       } else {         cout << (int)round(m) <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int find(int u[], int i) {     if (u[i] == i) {       return i;     }     return (u[i] = find(u, u[i]));   }   int main() {     int n, m;     cin >> n >> m;     if (n != m + 1) {       cout <<  no  << endl;       return 0;     }     int ufs[n];     for (int i = 0; i < n; i++) {       ufs[i] = i;     }     int a, b;     for (int i = 0; i < m; i++) {       cin >> a >> b;       int c = find(ufs, a - 1);       int d = find(ufs, b - 1);       if (c == d) {         cout <<  no  << endl;         return 0;       }       int m = min(c, d);       ufs[c] = m;       ufs[d] = m;     }     for (int i = 0; i < n; i++) {       if (find(ufs, i) != 0) {         cout <<  no  << endl;         return 0;       }     }     cout <<  yes  << endl;   }