malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int Maxn = 4e5;   int n, m, q;   int head[Maxn], tot, father[Maxn], cnt[Maxn];   int vis[Maxn];   struct Edge {     int to, next;   } edge[Maxn * 10];   void init() {     memset(head, -1, sizeof(head));     tot = 0;     for (int i = 0; i < Maxn; i++) father[i] = i;   }   int Find(int x) {     int y = x;     while (y != father[y]) {       y = father[y];     }     while (x != father[x]) {       int temp = father[x];       father[x] = y;       x = temp;     }     return y;   }   void Union(int a, int b) {     int ra = Find(a), rb = Find(b);     if (ra == rb) return;     father[ra] = rb;     cnt[rb] =         max((cnt[ra] + 1) / 2 + (cnt[rb] + 1) / 2 + 1, max(cnt[ra], cnt[rb]));     cnt[ra] = 0;   }   void add_edge(int u, int v) {     edge[tot].to = v;     edge[tot].next = head[u];     head[u] = tot++;   }   int pos, len;   void dfs(int u, int deep, int tar) {     if (vis[u] == tar) return;     vis[u] = tar;     if (deep > len) {       len = deep;       pos = u;     }     for (int i = head[u]; ~i; i = edge[i].next) {       int v = edge[i].to;       dfs(v, deep + 1, tar);       Union(u, v);     }   }   int process(int u) {     pos = len = -1;     dfs(u, 0, 1);     dfs(pos, 0, 2);     return len;   }   int main() {     init();     scanf( %d %d %d , &n, &m, &q);     while (m--) {       int u, v;       scanf( %d %d , &u, &v);       add_edge(u, v);       add_edge(v, u);     }     for (int i = 1; i <= n; i++) {       if (vis[i]) continue;       int Root = Find(i);       cnt[Root] = process(i);     }     while (q--) {       int op;       scanf( %d , &op);       if (op == 1) {         int u;         scanf( %d , &u);         printf( %d n , cnt[Find(u)]);       } else {         int u, v;         scanf( %d %d , &u, &v);         Union(u, v);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string pad(string x, int lngth) {     reverse(x.begin(), x.end());     for (int i = 0; i < lngth; i++) x +=  0 ;     reverse(x.begin(), x.end());     return x;   }   string add(string x, string y) {     string res =   ;     int mx = max(x.length(), y.length());     x = pad(x, mx - x.length());     y = pad(y, mx - y.length());     reverse(x.begin(), x.end());     reverse(y.begin(), y.end());     int carry = 0, tmp;     for (int i = 0; i < x.length(); i++) {       tmp = (x[i] -  0 ) + (y[i] -  0 ) + carry;       res += ((tmp % 10) +  0 );       carry = tmp / 10;     }     if (carry != 0) res += (carry +  0 );     reverse(res.begin(), res.end());     if (res[0] ==  0 ) {       int i = 0;       while (res[i] ==  0 ) i++;       res = res.substr(i, res.length());     }     return res;   }   string smaller(string x, string y) {     int i, mx = max(x.length(), y.length());     string x_ = pad(x, mx - x.length());     string y_ = pad(y, mx - y.length());     for (i = 0; i < x_.length(); i++) {       if (x_[i] > y_[i])         return y;       else if (x_[i] < y_[i])         return x;     }     return x;   }   int main() {     ios::sync_with_stdio(0);     int i, n;     string s, x, y;     cin >> n >> s;     int m = n / 2;     string p1, p2, res, ans =   ;     bool zero_found = false;     for (i = 0; i < m; i++) {       if (s[m + i] !=  0 )         break;       else         zero_found = true;     }     if (!zero_found) {       ans = add(s.substr(0, m), s.substr(m, n));       ans = smaller(ans, add(s.substr(0, m + 1), s.substr(m + 1, n)));     } else       ans = add(s.substr(0, m + i), s.substr(m + i, n));     zero_found = false;     for (i = 0; i < m; i++) {       if (s[m - i] !=  0 )         break;       else         zero_found = true;     }     if (!zero_found)       ans = smaller(ans, add(s.substr(0, m - 1), s.substr(m - 1, n)));     else       ans = smaller(ans, add(s.substr(0, m - i), s.substr(m - i, n)));     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = 4 * atan(1);   template <int p>   struct FF {     long long val;     FF(long long x = 0) { val = (x % p + p) % p; }     bool operator==(const FF<p> other) { return val == other.val; }     bool operator!=(const FF<p> other) { return val != other.val; }     FF operator+() const { return val; }     FF operator-() const { return -val; }     FF& operator+=(const FF<p> other) {       val = (val + other.val) % p;       return *this;     }     FF& operator-=(const FF<p> other) {       *this += -other;       return *this;     }     FF& operator*=(const FF<p> other) {       val = (val * other.val) % p;       return *this;     }     FF& operator/=(const FF<p> other) {       *this *= other.inv();       return *this;     }     FF operator+(const FF<p> other) const { return FF(*this) += other; }     FF operator-(const FF<p> other) const { return FF(*this) -= other; }     FF operator*(const FF<p> other) const { return FF(*this) *= other; }     FF operator/(const FF<p> other) const { return FF(*this) /= other; }     static FF<p> pow(const FF<p> a, long long b) {       if (!b) return 1;       return pow(a * a, b >> 1) * (b & 1 ? a : 1);     }     FF<p> pow(long long b) const { return pow(*this, b); }     FF<p> inv() const { return pow(p - 2); }   };   template <int p>   FF<p> operator+(long long lhs, const FF<p> rhs) {     return FF<p>(lhs) += rhs;   }   template <int p>   FF<p> operator-(long long lhs, const FF<p> rhs) {     return FF<p>(lhs) -= rhs;   }   template <int p>   FF<p> operator*(long long lhs, const FF<p> rhs) {     return FF<p>(lhs) *= rhs;   }   template <int p>   FF<p> operator/(long long lhs, const FF<p> rhs) {     return FF<p>(lhs) /= rhs;   }   int N;   vector<int> adj[500013];   FF<998244353> dp[500013];   FF<998244353> ans;   void dfs(int n, int par = -1) {     dp[n] = 1;     for (int v : adj[n])       if (v != par) {         dfs(v, n);         dp[n] *= 1 - dp[v] / 2;       }     ans += 1 - dp[n];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> N;     for (int i = 0; i < N - 1; i++) {       int u, v;       cin >> u >> v;       --u;       --v;       adj[u].push_back(v);       adj[v].push_back(u);     }     dfs(0);     for (int i = 0; i < N; i++) ans = ans * 2;     cout << ans.val << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k, dx, dy, x, y;   char c[5];   bool f;   long long ans;   struct blk {     int x, y;     blk(int xx = 0, int yy = 0) {       x = xx;       y = yy;     }     bool operator<(const blk& b) const {       return x < b.x || (x == b.x && y < b.y);     }   };   vector<blk> data[2];   void ins(int x, int y) {     data[0].push_back(blk(x - y, x));     data[1].push_back(blk(x + y, x));   }   void beam() {     int ff = (dx != dy);     blk p = ff ? blk(x + y, x) : blk(x - y, x);     vector<blk>::iterator it = upper_bound(data[ff].begin(), data[ff].end(), p);     for (; it->x != p.x; it--)       ;     if (dx < 0)       for (; it->y >= x; it--)         ;     ans += abs(x - it->y) - 1;     x = it->y, y = ff ? it->x - x : x - it->x;     bool u =         binary_search(data[0].begin(), data[0].end(), blk(x - y - dx, x - dx));     bool v = binary_search(data[0].begin(), data[0].end(), blk(x - y + dy, x));     if (u == v) {       f = 1;       dx *= -1;       dy *= -1;     } else if (u) {       x -= dx;       dy *= -1;     } else if (v) {       y -= dy;       dx *= -1;     }   }   int main() {     cin >> n >> m >> k;     for (int i = 1; i <= m; i++) {       ins(0, i);       ins(n + 1, i);     }     for (int i = 0; i <= n + 1; i++) {       ins(i, 0);       ins(i, m + 1);     }     for (int i = 1; i <= k; i++) {       scanf( %d%d , &x, &y);       ins(x, y);     }     scanf( %d%d%s , &x, &y, c);     dx = (c[0] ==  N ) ? -1 : 1, dy = (c[1] ==  W ) ? -1 : 1;     sort(data[0].begin(), data[0].end());     sort(data[1].begin(), data[1].end());     beam();     int sx = x, sy = y, sdx = dx, sdy = dy;     ans = 0;     do beam();     while (!(x == sx && y == sy && dx == sdx && dy == sdy));     cout << ((f) ? (ans / 2) : ans) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long inf = 1e18;   const long double eps = 1e-8;   const double pi = acos(-1);   const long long hashh = 247;   char s[203040];   long long p[203040], cnt[203040], hs[203040][2];   long long get(long long l, long long r) {     return (hs[r][l & 1] - hs[l - 1][l & 1] * p[cnt[r] - cnt[l - 1]] % mod +             mod) %            mod;   }   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     int n, q;     cin >> n >> s + 1 >> q;     p[0] = 1;     for (int i = 1; i < n + 1; i++) {       p[i] = p[i - 1] * hashh % mod;       cnt[i] = cnt[i - 1];       hs[i][0] = hs[i - 1][0];       hs[i][1] = hs[i - 1][1];       if (s[i] ==  0 ) {         cnt[i]++;         hs[i][0] = (hs[i - 1][0] * hashh + (i & 1) + 1) % mod;         hs[i][1] = (hs[i - 1][1] * hashh + (i & 1 ^ 1) + 1) % mod;       }     }     for (int i = 0; i < q; i++) {       long long l1, l2, len;       cin >> l1 >> l2 >> len;       if (get(l1, l1 + len - 1) == get(l2, l2 + len - 1))         cout <<  Yes n ;       else         cout <<  No n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int m, n, cnt = 0;   vector<vector<int> > g;   vector<int> outgroup;   int main() {     cin >> n >> m;     vector<int> emptyg;     g.push_back(emptyg);     for (int i = 1; i <= n; i++) {       vector<int> subg;       g.push_back(subg);     }     for (int i = 0; i < m; i++) {       int fr, to;       cin >> fr >> to;       g[fr].push_back(to);       g[to].push_back(fr);     }     while (true) {       outgroup.clear();       cerr <<  cnt ==   << cnt << endl;       for (int i = 1; i <= n; i++) {         int deg = g[i].size();         cerr <<  node   << i <<   has degree   << deg <<   n ;         if (deg == 1) {           outgroup.push_back(i);         }         cerr.flush();       }       if (outgroup.empty()) {         cout << cnt << endl;         return 0;       }       vector<int>::iterator it = outgroup.begin();       for (; it != outgroup.end(); it++) {         int nodetodelete = *it;         cerr <<  deleting node   << nodetodelete <<  ...  << endl;         int onlyconnectednode;         if (!g[nodetodelete].empty()) {           onlyconnectednode = g[nodetodelete][0];         } else {           continue;         }         vector<int>::iterator adjit = g[onlyconnectednode].begin();         for (; adjit != g[onlyconnectednode].end(); adjit++) {           if (*adjit == nodetodelete) {             g[onlyconnectednode].erase(adjit);             break;           }         }         g[nodetodelete].clear();       }       cnt = cnt + 1;       cerr <<  has the thread reached here?  << endl;       bool isEnd = true;       vector<vector<int> >::iterator ggit = g.begin();       for (; ggit != g.end(); ggit++) {         vector<int> thissubg = *ggit;         isEnd = thissubg.size() == 1 ? false : isEnd;       }       if (isEnd) {         break;       }     }     cout << cnt << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, q, a[210000], b[210000];   int tree[210000];   char Getchar() {     static char now[1 << 20], *S, *T;     if (T == S) {       T = (S = now) + fread(now, 1, 1 << 20, stdin);       if (T == S) return EOF;     }     return *S++;   }   int read() {     int x = 0, f = 1;     char ch = Getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = Getchar();     }     while (ch <=  9  && ch >=  0 ) x = x * 10 + ch -  0 , ch = Getchar();     return x * f;   }   void update(int x, int y) {     for (; x <= n; x += x & -x) tree[x] ^= y;   }   int getnum(int x) {     int res = 0;     for (; x; x -= x & -x) res ^= tree[x];     return res;   }   struct Linear_Basis {     int cnt, v[30];     void clr() {       cnt = 0;       memset(v, 0, sizeof(v));     }     void ins(int x, int lim = 29) {       if (cnt == 30) return;       for (int i = lim; i >= 0 && x; i--)         if (x & (1 << i)) {           if (v[i])             x ^= v[i];           else {             v[i] = x;             cnt++;             break;           }         }     }     void merge(const Linear_Basis &a) {       for (int i = 29; i >= 0; i--)         if (a.v[i]) ins(a.v[i], i);     }   } tmp, t[810000];   void pushup(int now) {     t[now] = t[now << 1];     t[now].merge(t[now << 1 | 1]);   }   void build(int now, int l, int r) {     if (l == r) {       t[now].clr();       t[now].ins(b[l]);       return;     }     int mid = (l + r) >> 1;     build(now << 1, l, mid);     build(now << 1 | 1, mid + 1, r);     pushup(now);   }   void change(int now, int l, int r, int x) {     if (l == r) {       t[now].clr();       t[now].ins(b[l]);       return;     }     int mid = (l + r) >> 1;     if (x <= mid)       change(now << 1, l, mid, x);     else       change(now << 1 | 1, mid + 1, r, x);     pushup(now);   }   void query(int now, int l, int r, int x, int y) {     if (l == x && r == y) {       tmp.merge(t[now]);       return;     }     int mid = (l + r) >> 1;     if (y <= mid)       query(now << 1, l, mid, x, y);     else if (x > mid)       query(now << 1 | 1, mid + 1, r, x, y);     else {       query(now << 1, l, mid, x, mid);       query(now << 1 | 1, mid + 1, r, mid + 1, y);     }   }   int main() {     n = read();     q = read();     for (int i = 1; i <= n; i++) {       a[i] = read();       b[i] = a[i - 1] ^ a[i];       update(i, b[i]);     }     build(1, 1, n);     int op, l, r, x;     while (q--) {       op = read();       l = read();       r = read();       if (op == 1) {         x = read();         update(l, x);         update(r + 1, x);         b[l] ^= x;         b[r + 1] ^= x;         change(1, 1, n, l);         if (r < n) change(1, 1, n, r + 1);       } else {         tmp.clr();         tmp.ins(getnum(l));         if (l < r) query(1, 1, n, l + 1, r);         printf( %d n , 1 << tmp.cnt);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int x, y, a[3000], n, m, sum;   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < m; i++) {       cin >> x >> y;       sum += min(a[--x], a[--y]);     }     cout << sum;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   void init_ios() {     ios_base::sync_with_stdio(0);     cin.tie(0);   }   const int N = (1 << 19);   int n, m, jump[N][20];   pair<int, int> a[N], drz[2 * N];   void add(int v, int val, int ind) {     v += N;     if (val < drz[v].first) return;     drz[v] = {val, ind};     while (v > 1) {       v /= 2;       if (drz[2 * v].first > drz[2 * v + 1].first)         drz[v] = drz[2 * v];       else         drz[v] = drz[2 * v + 1];     }   }   pair<int, int> get(int p, int q) {     p += N;     q += N;     pair<int, int> res;     if (drz[p].first > drz[q].first)       res = drz[p];     else       res = drz[q];     while (p / 2 != q / 2) {       if (p % 2 == 0 && drz[p + 1].first > res.first) res = drz[p + 1];       if (q % 2 == 1 && drz[q - 1].first > res.first) res = drz[q - 1];       p /= 2;       q /= 2;     }     return res;   }   int get_id(int id, int hm) {     for (int i = 0; i < 20; ++i)       if (hm & (1 << i)) id = jump[id][i];     return id;   }   int query(int x, int y) {     int id = get(0, x).second;     if (id == 0) return -1;     if (a[id].second >= y) return 1;     int x1 = 1, x2 = n - 1, x3;     while (x2 - x1 > 1) {       x3 = (x1 + x2) / 2;       int id2 = get_id(id, x3);       if (id2 == 0 || a[id2].second >= y)         x2 = x3;       else         x1 = x3;     }     int id2 = get_id(id, x1);     if (id2 != 0 && a[id2].second >= y) return 1 + x1;     id2 = get_id(id, x2);     if (id2 != 0 && a[id2].second >= y) return 1 + x2;     return -1;   }   int main() {     init_ios();     cin >> n >> m;     for (int i = 1; i <= n; ++i) {       cin >> a[i].first >> a[i].second;       add(a[i].first, a[i].second, i);     }     for (int l = 0; l < 20; ++l) {       for (int i = 1; i <= n; ++i) {         if (l == 0) {           pair<int, int> p = get(a[i].first, a[i].second);           jump[i][l] = p.second;         } else {           jump[i][l] = jump[jump[i][l - 1]][l - 1];         }       }     }     while (m--) {       int x, y;       cin >> x >> y;       cout << query(x, y) <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, a[2001][2001], s1[2001], s2[2001], res = 0, d[2001];   string s;   int main() {     scanf( %d n , &n);     for (int i = 0; i < n; ++i) {       cin >> s;       for (int j = 0; j < n; ++j)         if (s[j] ==  0 )           a[i][j] = 0;         else           a[i][j] = 1;     }     memset(s1, 0, sizeof s1);     memset(s2, 0, sizeof s2);     memset(d, 0, sizeof d);     for (int J = n - 1; J > 0; --J) {       int i = 0, j = J;       while (j < n) {         if ((a[i][j] + s1[i] + s2[j]) % 2 == 1) {           s1[i] = (s1[i] + 1) % 2;           s2[j] = (s2[j] + 1) % 2;           d[i] = (d[i] + 1) % 2;           d[j] = (d[j] + 1) % 2;           a[i][j] = (a[i][j] + 1) % 2;           ++res;         }         ++i;         ++j;       }     }     memset(s1, 0, sizeof s1);     memset(s2, 0, sizeof s2);     for (int I = n - 1; I > 0; --I) {       int i = I, j = 0;       while (i < n) {         if ((a[i][j] + s1[i] + s2[j]) % 2 == 1) {           s1[i] = (s1[i] + 1) % 2;           s2[j] = (s2[j] + 1) % 2;           d[i] = (d[i] + 1) % 2;           d[j] = (d[j] + 1) % 2;           a[i][j] = (a[i][j] + 1) % 2;           ++res;         }         ++i;         ++j;       }     }     for (int i = 0; i < n; ++i)       if ((a[i][i] + d[i]) % 2) ++res;     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string s;     cin >> n >> s;     int ans = -1;     for (int i = 0; i < n - 1; i++) {       if (s[i + 1] < s[i]) {         ans = i;         break;       }     }     if (ans == -1)       cout <<  NO ;     else {       cout <<  YES  << endl;       cout << ans + 1 <<     << ans + 2 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int x, i;     int a[100];     while (cin >> x && x) {       if (x == 1) {         cout << x << endl;       } else {         cout << x <<    ;         for (i = 1; i < x; i++) cout << i <<    ;         cout << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve(int cnum) {     int di[] = {-1, 0, 0, 1};     int dj[] = {0, -1, 1, 0};     int n, m;     cin >> n >> m;     vector<vector<int>> arr(n, vector<int>(m));     vector<vector<int>> ans(n, vector<int>(m));     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) cin >> arr[i][j];     auto isvalid = [&](int i, int j) {       if (i < 0 || j < 0) return false;       if (i >= n || j >= m) return false;       return true;     };     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         int neicnt = 0;         for (int k = 0; k < 4; ++k) {           if (isvalid(i + di[k], j + dj[k])) neicnt++;         }         if (neicnt < arr[i][j]) {           cout <<  NO n ;           return;         }         ans[i][j] = neicnt;       }     }     cout <<  YES n ;     for (auto a : ans) {       for (auto b : a) cout << b <<    ;       cout <<   n ;     }   }   int main() {     int t;     int count = 1;     for (cin >> t; t--; solve(count), count++)       ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int n, k;   pair<int, int> a[N];   long long b, s;   int main() {     cin >> n >> k;     cin >> b;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i].first);       a[i].second = i;     }     sort(a + 1, a + n, greater<pair<int, int> >());     for (int i = 1; i <= k; i++) s += a[i].first;     long long res = n;     if (s > b)       for (int i = 1; i <= k; i++) res = min(res, (long long)a[i].second);     for (int i = k + 1; i < n; i++)       if (s - a[k].first + a[i].first > b) res = min(res, (long long)a[i].second);     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxm = 200000 + 5;   const int maxn = 200000 + 5;   struct Edge {     int from, to, w, id;   };   vector<Edge> edges;   vector<int> G[maxn];   int ans[maxm];   int n, m;   int win[maxn], wall[maxn];   inline void solve() {     memset(ans, -1, sizeof ans);     queue<int> Q;     Q.push(1);     while (!Q.empty()) {       int now = Q.front();       Q.pop();       vector<int> tocheck;       for (const int& i : G[now]) {         Edge& e = edges[i];         if (ans[e.id] != -1) continue;         int to;         if (now == e.from)           to = e.to, ans[e.id] = 0;         else           to = e.from, ans[e.id] = 1;         win[to] += e.w;         wall[to] -= e.w;         if (to != n) tocheck.push_back(to);       }       for (const int& nx : tocheck)         if (win[nx] == wall[nx]) Q.push(nx);     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0, a, b, c; i < m; i++) {       scanf( %d%d%d , &a, &b, &c);       edges.push_back((Edge){a, b, c, i});       G[a].push_back((int)edges.size() - 1);       G[b].push_back((int)edges.size() - 1);       wall[a] += c;       wall[b] += c;     }     solve();     for (int i = 0; i < m; i++) printf( %d n , ans[i]);   }
#include <bits/stdc++.h>   using namespace std;   queue<int> Q;   vector<int> edges[11000];   int num[11000];   int ans;   int n;   int bfs(int s) {     int cnt = 0;     for (int i = 0; i < edges[s].size(); i++) {       cnt += edges[edges[s][i]].size() - 1;     }     return cnt;   }   int main(void) {     int i;     scanf( %d , &n);     for (i = 1; i <= n - 1; i++) {       int u, v;       scanf( %d %d , &u, &v);       edges[u].push_back(v);       edges[v].push_back(u);     }     for (i = 1; i <= n; i++) {       num[i] = bfs(i);       ans += num[i];     }     printf( %d , ans / 2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int a, b;     cin >> a >> b;     if (a == b) {       cout <<  infinity ;       return 0;     }     if (a < b) {       cout << 0;       return 0;     }     long long int x, i, k, j;     x = a - b;     long long int sq;     sq = sqrt((a - b) * 1.0);     long long int cnt = 0;     for (i = 1; i <= sq; i++) {       if (x % i == 0) {         j = i, k = x / i;         if (j == k && j > b)           cnt++;         else if (j != k) {           if (j > b) cnt++;           if (k > b) cnt++;         }       }     }     cout << cnt;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ans[120000], fa[120000], i, j, k, l, n, m, n2;   int get(int x) { return fa[x] == x ? x : (fa[x] = get(fa[x])); }   int main() {     scanf( %d , &n);     if (n & 1) return puts( -1 ), 0;     for (i = 0; i < n; ++i) fa[i] = i;     n2 = n / 2;     for (i = 0; i < n2; ++i) {       ans[i] = i * 2;       ans[i + n2] = i * 2 + 1;       fa[get(i)] = get(i * 2);       fa[get(i + n2)] = get(i * 2 + 1);     }     for (i = 0; i < n2; ++i)       if (get(i) != get(i + n2)) {         swap(ans[i], ans[i + n2]);         fa[get(i)] = get(i + n2);       }     for (i = 0;;) {       printf( %d  , i);       i = ans[i];       if (!i) break;     }     printf( 0 n );   }
#include <bits/stdc++.h>   using namespace std;   int k;   int main() {     cin >> k;     for (int i = 1; i < k; i++) {       cout << i;       for (int j = 2; j < k; j++) {         if (i * j < k)           cout <<      << i * j % k;         else           cout << setw(2) << i * j / k << i * j % k;       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main(void) {     int t;     cin >> t;     while (t--) {       long long n, x, sum = 0, ans = 0, cur;       cin >> n >> x;       priority_queue<long long> nums;       for (int i = 0; i < n; ++i) {         cin >> cur;         nums.push(cur - x);       }       for (int i = 0; i < n && sum >= 0; ++i) {         sum += nums.top();         nums.pop();         if (sum < 0) break;         ++ans;       }       cout << ans << endl;     }   }