malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base ::sync_with_stdio(false);     ;     cin.tie(NULL);     ;     long long int t = 1;     while (t--) {       long long int n;       cin >> n;       pair<long long int, long long int> tree[n];       long long int i, j, k;       map<pair<long long int, long long int>, long long int> mp;       for (i = 0; i < n; i++) {         cin >> j >> k;         tree[i].first = j;         tree[i].second = k;       }       list<long long int> l;       for (i = 0; i < n; i++) {         if (tree[i].first == 1) l.push_back(i);       }       vector<pair<long long int, long long int> > edges;       while (!l.empty()) {         long long int node = l.front();         l.pop_front();         if (tree[node].first == 0) continue;         long long int xors = tree[node].second;         tree[xors].first--;         tree[xors].second ^= node;         edges.push_back({node, xors});         if (tree[xors].first == 1) l.push_back(xors);       }       cout << edges.size() << endl;       for (auto x : edges) cout << x.first <<     << x.second << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-5;   const int p = 131;   const int inf = 0x3f3f3f3f;   const long long mod = 1e9 + 7;   const int N = 1e6 + 10;   long long Hash[N], fac[N];   char s[N], ss[N];   long long get(int l, int r) {     return (Hash[r] - Hash[l - 1] * fac[r - l + 1] % mod + mod) % mod;   }   void run() {     scanf( %s %s , s + 1, ss + 1);     int len1 = strlen(s + 1);     int len2 = strlen(ss + 1);     fac[0] = 1;     int n0 = 0, n1 = 0;     for (int i = 1; i <= len1; i++) {       n0 += (s[i] ==  0 );       n1 += (s[i] ==  1 );     }     for (int i = 1; i <= len2; i++) {       Hash[i] = (Hash[i - 1] * p % mod + ss[i] -  a  + 1) % mod;       fac[i] = fac[i - 1] * p % mod;     }     int res = 0;     for (int l0 = 1, l1; l0 < len2; l0++) {       if (l0 * n0 >= len2) break;       if ((len2 - l0 * n0) % n1) continue;       l1 = (len2 - l0 * n0) / n1;       long long hash0 = -1, hash1 = -1;       int idx = 1;       int flag = 1;       for (int j = 1; j <= len1; j++) {         if (s[j] ==  1 ) {           if (hash1 == -1) {             hash1 = get(idx, idx + l1 - 1);           } else if (hash1 != get(idx, idx + l1 - 1)) {             flag = 0;             break;           }           idx += l1;         } else {           if (hash0 == -1) {             hash0 = get(idx, idx + l0 - 1);           } else if (hash0 != get(idx, idx + l0 - 1)) {             flag = 0;             break;           }           idx += l0;         }         if (~hash0 && ~hash1 && hash0 == hash1) {           flag = 0;           break;         }       }       if (flag) res++;     }     printf( %d n , res);   }   int main() {     run();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   int vis[maxn], son[maxn], f[maxn], sum, root, ans[maxn];   vector<int> g[maxn];   void getroot(int x, int fa) {     son[x] = 1;     f[x] = 0;     for (int i = 0; i < g[x].size(); i++) {       int v = g[x][i];       if (v == fa || vis[v]) continue;       getroot(v, x);       son[x] += son[v];       f[x] = max(f[x], son[v]);     }     f[x] = max(f[x], sum - son[x]);     if (f[x] < f[root]) root = x;   }   void work(int x, int fa, int dep) {     ans[x] = dep;     vis[x] = 1;     for (int i = 0; i < g[x].size(); i++) {       int v = g[x][i];       if (vis[v]) continue;       sum = son[v], root = 0;       getroot(v, x);       work(root, x, dep + 1);     }   }   int main(void) {     int n;     while (~scanf( %d , &n) && n) {       for (int i = 1; i <= n; i++) g[i].clear();       int a, b;       for (int i = 0; i < n - 1; i++) {         scanf( %d %d , &a, &b);         g[a].push_back(b);         g[b].push_back(a);       }       f[0] = sum = n;       getroot(1, 0);       work(root, 0, 0);       for (int i = 1; i <= n; i++) {         printf( %c  , ans[i] +  A );       }       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   using vi = vector<int>;   struct ele {     int value, jj, index;   };   bool ordena(ele a, ele b) { return a.value < b.value; }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int k, n;     cin >> k;     vector<ele> arr;     for (int i = 0; i < k; i++) {       int v[200010], sum = 0;       cin >> n;       for (int j = 0; j < n; j++) {         cin >> v[j];         sum += v[j];       }       for (int j = 0; j < n; j++) {         ele myele;         myele.value = sum - v[j];         myele.jj = j;         myele.index = i;         arr.push_back(myele);       }     }     sort(arr.begin(), arr.end(), ordena);     for (int i = 0; i < arr.size() - 1; i++) {       if (arr[i].value == arr[i + 1].value && arr[i].index != arr[i + 1].index) {         cout <<  YES  <<   n ;         cout << arr[i].index + 1 <<     << arr[i].jj + 1 <<   n ;         cout << arr[i + 1].index + 1 <<     << arr[i + 1].jj + 1 <<   n ;         return 0;       }     }     cout <<  NO  <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     int n, a, b;     cin >> n >> a >> b;     string s;     cin >> s;     vector<int> dp(n + 1, INT_MAX);     vector<vector<int> > lcp(n, vector<int>(n));     for (int i = n - 1; i >= 0; --i) {       for (int j = n - 1; j >= 0; --j) {         if (s[i] == s[j]) {           if (i == n - 1 || j == n - 1) {             lcp[i][j] = 1;           } else {             lcp[i][j] = 1 + lcp[i + 1][j + 1];           }         }       }     }     dp[0] = 0;     for (int i = 0; i < n; ++i) {       dp[i + 1] = min(dp[i + 1], dp[i] + a);       for (int j = 0; j < i; ++j) {         int k = min(lcp[i][j], i - j);         dp[i + k] = min(dp[i + k], dp[i] + b);       }     }     cout << dp[n];   }
#include <bits/stdc++.h>   using namespace std;   bool vis[100001];   int pi[100001];   int level[100001];   list<int> adj[100001];   void dfs(int s) {     vis[s] = 1;     bool flag = 1;     for (list<int>::iterator it = adj[s].begin(); it != adj[s].end(); ++it)       if (!vis[*it]) {         level[*it] = level[s] + 1;         pi[*it] = s;         dfs(*it);         flag = 0;       }     if (flag) {       int least = s;       stack<int> stk;       for (list<int>::iterator it = adj[s].begin(); it != adj[s].end(); ++it)         if (level[least] > level[(*it)]) least = *it;       while (s != least) {         stk.push(s);         s = pi[s];       }       stk.push(s);       cout << stk.size() <<   n ;       while (!stk.empty()) {         cout << stk.top() <<    ;         stk.pop();       }       exit(0);     }   }   int main() {     int n, m, k, i, l, r;     cin >> n >> m >> k;     for (i = 1; i <= m; ++i) {       cin >> l >> r;       adj[l].push_back(r);       adj[r].push_back(l);     }     pi[1] = -1;     dfs(1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename tn>   void read(tn &a) {     tn x = 0, f = 1;     char c =    ;     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -1;     for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;     a = x * f;   }   const int N = 101000;   long long lim[8], lm[8];   int n;   struct point {     long long x, y, z;     long long getval(int k) {       return x * (k & 1 ? -1 : 1) + y * (k >> 1 & 1 ? -1 : 1) +              z * (k >> 2 & 1 ? -1 : 1);     }   } p[N], ans;   bool chk(int tag, long long *lim) {     long long l[4] = {(-lim[7] + 1 - 3 * tag) >> 1, (-lim[6] + 1 - tag) >> 1,                       (-lim[5] + 1 - tag) >> 1, (-lim[3] + 1 - tag) >> 1};     long long r[4] = {(lim[0] - 3 * tag) >> 1, (lim[1] - tag) >> 1,                       (lim[2] - tag) >> 1, (lim[4] - tag) >> 1};     long long a = l[1], b = l[2], c = l[3];     for (int i = 0; i < 4; i++)       if (r[i] < l[i]) return 0;     if (a + b + c > r[0]) return 0;     if (a + b + c < l[0]) {       a = min(r[1], l[0] - b - c);       b = min(r[2], l[0] - a - c);       c = min(r[3], l[0] - a - b);     }     if (a + b + c < l[0]) return 0;     ans = {b + c + tag, a + c + tag, a + b + tag};     return 1;   }   bool check(long long len) {     memcpy(lm, lim, sizeof(lm));     for (int i = 0; i < 8; i++) lm[i] += len;     if (chk(0, lm)) return 1;     if (chk(1, lm)) return 1;     return 0;   }   int main() {     int T;     read(T);     while (T--) {       read(n);       for (int i = 1; i <= n; i++) read(p[i].x), read(p[i].y), read(p[i].z);       memset(lim, 63, sizeof(lim));       for (int i = 1; i <= n; i++)         for (int j = 0; j < 8; j++) lim[j] = min(lim[j], p[i].getval(j));       long long l = -1, r = 4e18l + 1;       while (l + 1 < r) {         long long mid = l + r >> 1;         if (check(mid))           r = mid;         else           l = mid;       }       check(r);       cout << ans.x <<     << ans.y <<     << ans.z <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 7;   long long arr[maxn];   int vis[maxn];   int main() {     int T;     scanf( %d , &T);     while (T--) {       int n;       if (n == 1) {         printf( YES n );         continue;       }       scanf( %d , &n);       n *= 4;       for (int i = 1; i <= n; i++) {         scanf( %lld , &arr[i]);       }       sort(arr + 1, arr + n + 1);       long long aver;       int mark = 1;       for (int i = 1, j = n - 1; i <= j; i += 2, j -= 2) {         if (arr[i] != arr[i + 1] || arr[j] != arr[j + 1]) {           mark = 0;           break;         }         if (i == 1) {           aver = arr[i] * arr[j];         } else if (arr[i] * arr[j] != aver) {           mark = 0;           break;         }       }       if (mark) {         printf( YES n );       } else {         printf( NO n );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, cnt = 0, sum = 1;     vector<int> v;     cin >> n >> k;     if (k == 1) {       cout << n << endl;       return 0;     }     for (int i = 2; i <= n / 2; i++) {       while (n % i == 0 && cnt < k - 1) {         cnt++;         n /= i;         v.push_back(i);       }       if (cnt == k - 1 && n > 1) {         v.push_back(n);         cnt++;         break;       }     }     if (cnt == k) {       for (int i = 0; i < v.size(); i++) cout << v[i] <<    ;       cout << endl;     } else       cout << -1 << endl;     return 0;   }
#include <bits/stdc++.h>   const int N = 12;   using namespace std;   int n, x, y, a[N][N];   pair<pair<int, int>, pair<int, int> > b[N] = {       {{0, 0}, {0, 0}}, {{1, 1}, {3, 3}}, {{1, 4}, {3, 6}}, {{1, 7}, {3, 9}},       {{4, 1}, {6, 3}}, {{4, 4}, {6, 6}}, {{4, 7}, {6, 9}}, {{7, 1}, {9, 3}},       {{7, 4}, {9, 6}}, {{7, 7}, {9, 9}}};   int main() {     ios_base::sync_with_stdio(0);     n = 9;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j) {         char c;         cin >> c;         a[i][j] = (int)c;       }     cin >> x >> y;     x %= 3;     y %= 3;     if (x == 0) x = 3;     if (y == 0) y = 3;     int flag = 0;     for (int i = b[(x - 1) * 3 + y].first.first;          i <= b[(x - 1) * 3 + y].second.first; ++i)       for (int j = b[(x - 1) * 3 + y].first.second;            j <= b[(x - 1) * 3 + y].second.second; ++j)         if (a[i][j] == 46) flag = 1, a[i][j] = 33;     if (flag == 0) {       for (int i = 1; i <= n; ++i)         for (int j = 1; j <= n; ++j)           if (a[i][j] == 46) a[i][j] = 33;     }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j) {         cout << char(a[i][j]);         if (j % 3 == 0 && j != n) cout <<    ;       }       cout <<   n ;       if (i % 3 == 0) cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   long long dp[N][2];   struct segment {     int l, r;   };   auto cmp = [](segment& s1, segment& s2) {     if (s1.r != s2.r)       return s1.r < s2.r;     else       return s1.l > s2.l;   };   void solve() {     int n, m;     cin >> n >> m;     long long p[n + 2];     for (int i = 1; i <= n; i++) cin >> p[i];     p[0] = -1e10;     p[n + 1] = 1e10;     sort(p, p + n + 2);     vector<segment> s;     for (int i = 1; i <= m; i++) {       int l, r;       cin >> l >> r;       if (lower_bound(p, p + n + 2, l) != upper_bound(p, p + n + 2, r)) continue;       s.push_back((segment){l, r});     }     sort(s.begin(), s.end(), cmp);     for (int i = 1; i < s.size(); i++) {       if (s[i - 1].l >= s[i].l || s[i - 1].r == s[i].r)         s.erase(s.begin() + i), i--;     }     long long dp[n + 2][2];     for (int i = 1; i <= n + 1; i++) dp[i][0] = dp[i][1] = 1e15;     dp[0][0] = dp[0][1] = 0;     int now = 0;     for (int i = 1; i < n + 2; i++) {       vector<long long> l, r;       l.push_back(p[i - 1]);       while (now < s.size() && s[now].r < p[i]) {         l.push_back(s[now].l);         r.push_back(s[now].r);         now++;       }       r.push_back(p[i]);       for (int j = 0; j < l.size(); j++) {         dp[i][0] =             min(dp[i][0], dp[i - 1][0] + (l[j] - p[i - 1]) + 2 * (p[i] - r[j]));         dp[i][1] =             min(dp[i][1], dp[i - 1][0] + (l[j] - p[i - 1]) + (p[i] - r[j]));         dp[i][0] = min(dp[i][0],                        dp[i - 1][1] + 2 * (l[j] - p[i - 1]) + 2 * (p[i] - r[j]));         dp[i][1] =             min(dp[i][1], dp[i - 1][1] + 2 * (l[j] - p[i - 1]) + (p[i] - r[j]));       }     }     cout << min(dp[n + 1][0], dp[n + 1][1]) << endl;   }   int main() {     int T;     cin >> T;     while (T--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   inline long long int rand(long long int x, long long int y) {     ++y;     return (rng() % (y - x)) + x;   }   string to_string(char c) {     string second(1, c);     return second;   }   string to_string(bool b) { return (b ?  true  :  false ); }   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 first = true;     string res =  { ;     for (const auto &x : v) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(x);     }     res +=  } ;     return res;   }   void degug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void degug_out(Head H, Tail... T) {     cerr <<     << to_string(H);     degug_out(T...);   }   long long int n, fac[(300006)], dp[(300006)];   const long long int MOD = 998244353;   vector<long long int> v[(300006)];   void fact() {     fac[0] = fac[1] = 1;     for (long long int i = 2; i <= n; ++i) {       fac[i] = (i * fac[i - 1]) % MOD;     }     return;   }   void dfs(long long int x, long long int p) {     long long int ans = 1;     long long int child = 1;     for (auto i : v[x])       if (i != p) {         child++;         dfs(i, x);         ans *= dp[i];         ans %= MOD;       }     ans *= fac[child - 1];     ans %= MOD;     if (x != 1) ans *= child;     ans %= MOD;     return void(dp[x] = ans);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     fact();     for (long long int i = 0; i < (long long int)n - 1; ++i) {       long long int a, b;       cin >> a >> b;       v[a].push_back(b);       v[b].push_back(a);     }     dfs(1, 1);     cout << (dp[1] * n) % MOD;   }
#include <bits/stdc++.h>   const int maxn = 2e5 + 10;   int N;   int A[maxn];   long long Q[maxn];   long long sum1[maxn];   long long sum2[maxn];   double X(int i) { return i; }   double Y(int i) { return i * sum1[i] - sum2[i]; };   double slope(int i, int j) { return (Y(i) - Y(j)) / (X(i) - X(j)); }   long long Calc(int i, int j) {     return sum2[j] - sum2[i] - 1ll * i * (sum1[j] - sum1[i]);   }   int main() {     scanf( %d , &N);     for (register int i = 1; i <= N; i++) {       scanf( %d , &A[i]);       sum1[i] = sum1[i - 1] + A[i];       sum2[i] = sum2[i - 1] + 1ll * A[i] * i;     }     int tail = 0;     long long Ans = 0;     for (register int j = 1; j <= N; j++) {       long long k = sum1[j];       int l = 0, r = tail;       while (l < r) {         int mid = l + r >> 1;         if (slope(Q[mid], Q[mid + 1]) > k)           l = mid + 1;         else           r = mid;       }       int i = Q[r];       Ans = std::max(Ans, Calc(i, j));       while (tail >= 1 && slope(Q[tail], Q[tail - 1]) < slope(Q[tail], j)) tail--;       Q[++tail] = j;     }     printf( %I64d n , Ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a, b, res;   int check(int a, int b) { return a < b; }   int main() {     scanf( %d%d , &a, &b);     if (a == b) {       printf( infinity );       return 0;     }     res = 0;     a -= b;     if (a < 0) {       printf( 0 );       return 0;     }     for (int i = 1; i * i <= a; i++)       if (!(a % i)) {         res += check(b, i);         if (i * i != a) res += check(b, a / i);       }     printf( %d , res);   }
#include <bits/stdc++.h>   using namespace std;   int n, m, c, l, r, cp, cm;   string s;   int main() {     cin >> n >> s;     for (int i = 0; i < n; i++) {       l = i - 1;       r = i;       cp = 1;       cm = 1;       while (l >= 0 && s[l] !=  L ) {         cp += (s[l] ==  R );         l--;       }       while (r < n - 1 && s[r] !=  R ) {         cm += (s[r] ==  L );         r++;       }       cout << max(cp, cm) << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   struct node;   struct node {     node* arr[26];     int val;     node();     void insert(char ch[], int l, int pos);     void win();     void lose();   };   node::node() {     val = 0;     for (int i = 0; i < 26; i++) arr[i] = 0;   }   void node::insert(char ch[], int l, int pos) {     if (pos == l)       return;     else {       int index = ch[pos] -  a ;       if (arr[index] == 0) {         arr[index] = new node();         arr[index]->insert(ch, l, pos + 1);       } else {         arr[index]->insert(ch, l, pos + 1);       }     }   }   void node::win() {     int ind = 0;     for (int i = 0; i < 26; i++) {       if (arr[i] != 0) {         arr[i]->win();         ind = ind | arr[i]->val;       }     }     val = !ind;   }   void node::lose() {     int ind = 1;     int leaf = 1;     for (int i = 0; i < 26; i++) {       if (arr[i] != 0) {         leaf = 0;         arr[i]->lose();         ind = ind & arr[i]->val;       }     }     if (leaf)       val = leaf;     else       val = !ind;   }   int main() {     int n, k;     scanf( %d %d , &n, &k);     node* root = new node();     char ch[100000];     for (int i = 0; i < n; i++) {       scanf( %s , ch);       int l = strlen(ch);       root->insert(ch, l, 0);     }     int ind = 0;     for (int i = 0; i < 26; i++) {       if (root->arr[i] != 0) {         root->arr[i]->win();         ind = ind | root->arr[i]->val;       }     }     int w = ind;     ind = 0;     for (int i = 0; i < 26; i++) {       if (root->arr[i] != 0) {         root->arr[i]->lose();         ind = ind | !root->arr[i]->val;       }     }     int l = ind;     if (w & l) {       printf( First n );     } else if (w & !l) {       if (k & 1)         printf( First n );       else         printf( Second n );     } else       printf( Second n );   }
#include <bits/stdc++.h>   using namespace std;   int main() {     char a, b;     cin >> a >> b;     int n;     cin >> n;     n = n % 4;     if (n == 0) {       cout <<  undefined ;       return 0;     }     int arr[] = {118, 60, 94, 62};     int arr2[] = {118, 62, 94, 60};     int i = 0;     for (i = 0; i < 4; i++) {       if (a == arr[i]) break;     }     char c = arr[i];     for (int j = 1; j <= n; j++) {       i = (i + 1) % 4;       c = arr[i];     }     int k = 0;     for (k = 0; k < 4; k++) {       if (a == arr2[k]) break;     }     char d = arr[k];     for (int j = 1; j <= n; j++) {       k = (k + 1) % 4;       d = arr2[k];     }     if (c == b && d == b)       cout <<  undefined ;     else if (c == b)       cout <<  cw ;     else       cout <<  ccw ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7;   const long long INFL = 1e18 + 123;   const double PI = atan2(0, -1);   mt19937 tw(960172);   long long rnd(long long x, long long y) {     static uniform_int_distribution<long long> d;     return d(tw) % (y - x + 1) + x;   }   int cross(int x1, int y1, int x2, int y2) { return x1 * y2 - y1 * x2; }   bool inside(int x, int y, vector<pair<int, int> > poly) {     int s1 = 0, s2 = 0;     for (int i = 0; i < ((int)(poly).size()); ++i) {       int next = (i + 1) % ((int)(poly).size());       int tmp = cross(poly[i].first - x, poly[i].second - y, poly[next].first - x,                       poly[next].second - y);       s1 += tmp;       s2 += abs(tmp);     }     return abs(s1) == s2;   }   void solve() {     vector<pair<int, int> > poly[2];     for (int i = 0; i < 2; ++i) {       for (int j = 0; j < 4; ++j) {         int x, y;         cin >> x >> y;         poly[i].push_back({x, y});       }     }     for (int x = -150; x <= 150; ++x) {       for (int y = -150; y <= 150; ++y) {         if (inside(x, y, poly[0]) && inside(x, y, poly[1])) {           cout <<  YES n ;           return;         }       }     }     cout <<  NO n ;   }   int main() {     cerr << fixed << setprecision(15);     cout << fixed << setprecision(15);     ios::sync_with_stdio(false);     int tests = 1;     for (int it = 1; it <= tests; ++it) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s;   int n, i, k = 0;   int main() {     cin >> s;     for (i = 0; i < s.size(); i++) {       while (s[i] == s[i + 1] && s.size()) {         s.erase(i, 2);         i--;         k++;       }     }     if (k % 2 != 0)       cout <<  YES  << endl;     else if (k % 2 == 0)       cout <<  No  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 2e5 + 100;   vector<int> ans;   set<pair<int, int>> add[MAX], rem[MAX], cur;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, k;     cin >> n >> k;     for (int i = 1; i <= n; i++) {       int x, y;       cin >> x >> y;       add[x].insert({y, i});       rem[y + 1].insert({y, i});     }     for (int i = 1; i < MAX; i++) {       for (auto p : rem[i]) {         cur.erase(p);       }       for (auto p : add[i]) {         cur.insert(p);       }       while (cur.size() > k) {         set<pair<int, int>>::iterator it;         it = prev(cur.end());         ans.push_back((*it).second);         cur.erase(it);       }     }     cout << ans.size() << endl;     for (int x : ans) {       cout << x <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int a[n], b[n], min, count = 0;       for (int i = 0; i < n; i++) {         cin >> a[i];         b[i] = a[i];       }       sort(b, b + n);       min = b[0];       for (int i = 0; i < n; i++) {         if (a[i] % min == 0 || a[i] == b[i]) {           count++;         } else           break;       }       if (count == n)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     long long n;     cin >> n;     long long ans = 0;     for (long long i = 1; i < n; i++) {       if (n % i == 0) {         ans++;       }     }     cout << ans <<   n ;   }