malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int a[1005], b[1005];   int x[1005], y[1005];   int main() {     int n;     while (scanf( %d , &n) != EOF) {       memset(x, 0, sizeof(x));       memset(y, 0, sizeof(y));       for (int i = 0; i < n; ++i) {         scanf( %d%d , &a[i], &b[i]);         x[a[i]]++;         y[b[i]]++;       }       int sum = 0;       for (int i = 0; i < n; ++i) {         if (x[b[i]]) {           if (a[i] != b[i]) {             sum += x[b[i]];             x[b[i]] = 0;           } else if (y[a[i]] > 1) {             sum += x[b[i]];             x[b[i]] = 0;           } else if (x[b[i]] > 1) {             sum += x[b[i]] - 1;             x[b[i]] = 1;           }         }       }       printf( %d n , n - sum);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-9;   const int INF = 0x3f3f3f3f;   int sgn(double a) { return ((a > EPS) ? (1) : ((a < -EPS) ? (-1) : (0))); }   int cmp(double a, double b = 0.0) { return sgn(a - b); }   struct node {     int x, y;     node(int x = 0, int y = 0) : x(x), y(y) {}   };   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     bool rated = false;     vector<int> rating;     for (int i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       if (x != y)         rated = true;       else         rating.push_back(y);     }     if (rated)       cout <<  rated n ;     else {       for (int i = 0; i < n - 1; i++)         if (rating[i] < rating[i + 1]) {           cout <<  unrated n ;           return 0;         }       cout <<  maybe n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 5;   const long long mod = 998244353;   vector<long long> adj[N];   long long dp[N][4], f[N][3];   void dfs(long long x) {     if (adj[x].size() == 0) {       dp[x][2] = 1;       return;     } else {       dp[x][0] = 1;     }     for (long long i : adj[x]) {       dfs(i);       dp[x][2] = (dp[x][2] * (dp[i][0] + dp[i][2]) +                   (dp[x][1] + dp[x][2]) * (dp[i][1] + dp[i][2])) %                  mod;       dp[x][1] =           (dp[x][1] * (dp[i][0] + dp[i][2]) + dp[x][0] * (dp[i][1] + dp[i][2])) %           mod;       dp[x][0] = (dp[x][0] * (dp[i][0] + dp[i][2])) % mod;     }   }   signed main() {     long long n, i, j, k;     cin >> n;     for (i = 2; i <= n; i++) {       cin >> j;       adj[j].push_back(i);     }     dfs(1);     cout << (dp[1][0] + dp[1][2]) % mod;   }
#include <bits/stdc++.h>   int main() {     int x;     scanf( %d , &x);     if (x == 3)       printf( 5 n );     else {       for (int i = 1; i <= 100; i += 2) {         if (i * i - (i * i) / 2 >= x) {           printf( %d n , i);           break;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   pair<int, int> a[111111], b[111111];   int n;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i].first);       a[i].second = i;     }     for (int i = 1; i <= n; i++) {       scanf( %d , &b[i].first);       b[i].second = i;     }     int m;     scanf( %d , &m);     sort(a + 1, a + 1 + n);     sort(b + 1, b + 1 + n);     long long ret = 1;     for (int i = 1, j = 1; i <= n || j <= n;) {       int val;       if (i <= n && (j > n || a[i].first <= b[j].first))         val = a[i].first;       else         val = b[j].first;       int cnt = 0, l2 = 0;       map<int, bool> f;       f.clear();       for (; i <= n && a[i].first == val; i++) {         cnt++;         f[a[i].second] = 1;       }       for (; j <= n && b[j].first == val; j++) {         cnt++;         if (f[b[j].second]) l2++;       }       for (int k = 2; k <= cnt; k++) {         int now = k;         while (now % 2 == 0 && l2) {           now /= 2;           l2--;         }         ret = (ret * now) % m;       }     }     printf( %I64d , ret);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int fact[300001];   int invfact[300001];   int pw(int a, int e) {     if (e == 0) return 1;     int tmp = pw(a, e / 2);     tmp = (tmp * ((long long)tmp)) % 1000000007;     if (e & 1) tmp = (tmp * ((long long)a)) % 1000000007;     return tmp;   }   void computeFactorials() {     fact[0] = invfact[0] = 1;     for (int i = 1; i <= 300000; i++) {       fact[i] = (fact[i - 1] * ((long long)i)) % 1000000007;       invfact[i] = pw(fact[i], 1000000007 - 2);     }   }   void mult(int &a, int b) { a = (a * ((long long)b)) % 1000000007; }   void add(int &a, int b) {     a = a + b;     if (a >= 1000000007) a -= 1000000007;   }   void sub(int &a, int b) {     a = a + 1000000007 - b;     if (a >= 1000000007) a -= 1000000007;   }   int chs(int n, int k) {     if (k > n) return 0;     int tmp = (fact[n] * ((long long)invfact[k])) % 1000000007;     tmp = (tmp * ((long long)invfact[n - k])) % 1000000007;     return tmp;   }   vector<int> pcs[300001];   int A[300000];   int occ[20];   int ps[20];   int N, C;   int tmp[300001];   int computePrime(int p) {     for (int i = 0; i < 20; i++) occ[i] = 0;     for (int j = 0; j < pcs[p].size(); j++) {       int l = 0;       while (pcs[p][j] % p == 0) {         l++;         pcs[p][j] /= p;       }       occ[l]++;     }     occ[0] = N - pcs[p].size();     int numLess = 0;     int numMore;     int ans = 0;     for (int k = 0; k < 19; k++) {       numLess += occ[k];       numMore = N - numLess;       tmp[0] = 0;       for (int i = 1; i < numMore; i++) {         tmp[i] = i;         mult(tmp[i], chs(numLess, i));         add(tmp[i], tmp[i - 1]);         int cur = tmp[i];         mult(cur, chs(numMore, i + 1));         add(ans, cur);       }       tmp[0] = pw(2, numLess);       for (int i = 1; i <= numMore; i++) {         tmp[i] = tmp[i - 1];         sub(tmp[i], chs(numLess, i - 1));         int cur = tmp[i];         mult(cur, chs(numMore, i));         mult(cur, i);         add(ans, cur);       }     }     return ans;   }   int main() {     cin >> N;     computeFactorials();     for (int i = 0; i < N; i++) {       cin >> A[i];       int c = A[i];       for (int j = 2; j * j <= A[i]; j++) {         if (c % j == 0) {           pcs[j].push_back(A[i]);           while (c % j == 0) c /= j;         }       }       if (c > 1) {         pcs[c].push_back(A[i]);       }     }     int ans = 0;     for (int i = 1; i <= 300000; i++)       if (pcs[i].size() > 0) add(ans, computePrime(i));     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = (1e9) + 7;   const long double EPS = 0.0000001;   int main(void) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     int pa;     cin >> pa;     deque<int> arr;     int ans = 0;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       if (i == pa - 1) {         if (x != 0) {           x = 0;           ans++;         }       }       arr.push_back(x);     }     sort(arr.begin(), arr.end());     arr.pop_front();     int cur = 0;     while (arr.front() == 0) {       arr.pop_front();       arr.push_back(INT_MAX);     }     while (arr.size()) {       cur++;       int x = arr.front();       if (x == cur) {         while (arr.size() && arr.front() == cur) arr.pop_front();         continue;       }       while (arr.size()) {         x = arr.front();         if (cur == x) {           cur--;           break;         }         arr.pop_back();         cur++;         ans++;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int t, n, m;   int a[10][10];   int main() {     cin >> t;     while (t--) {       cin >> n >> m;       int ok = 0;       for (int i = 1; i <= n; i++) {         cin >> a[1][1] >> a[1][2] >> a[2][1] >> a[2][2];         if (a[1][2] == a[2][1]) {           ok = 1;         }       }       if (m % 2) ok = 0;       if (ok)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     int n;     cin >> t;     for (int u = 0; u < t; u++) {       cin >> n;       int arr[n];       for (int i = 0; i < n; i++) cin >> arr[i];       vector<int> v;       int mini = arr[n - 1];       for (int i = (n - 2); i >= 0; i--) {         if (mini < arr[i])           v.push_back(arr[i]);         else           mini = arr[i];       }       cout << v.size() <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000000 + 7;   const int N = 100000 + 50;   vector<int> a;   int val[N];   int p[N];   int rp[N];   int avl[N];   pair<int, int> dp[N];   int curn;   pair<int, int> bit[N];   vector<vector<int> > fa;   void clear_bit(int n) {     for (int i = 0; i < n + 2; i++) {       bit[i] = {0, -1};     }   }   void upd(int i, int x, int y) {     while (i < curn) {       if (x > bit[i].first) {         bit[i] = {x, y};       }       i += i & (-i);     }   }   pair<int, int> get(int i) {     pair<int, int> ans = {0, 0};     while (i > 0) {       if (bit[i].first > ans.first) {         ans = bit[i];       }       i -= i & (-i);     }     return ans;   }   void build() {     int n = a.size();     if (n == 0) return;     clear_bit(n + 3);     curn = n + 2;     pair<int, int> vl = {0, 0};     for (int i = 1; i <= n; i++) {       avl[i] = 1;       auto an = get(a[i - 1]);       dp[i] = {an.first + 1, an.second};       if (dp[i].first > vl.first) {         vl = {dp[i].first, i};       }       upd(a[i - 1], dp[i].first, i);     }     if (val[n - vl.first] < val[n]) {       vector<int> ans;       int cur = vl.second;       while (cur > 0) {         avl[a[cur - 1]] = 0;         ans.push_back(p[a[cur - 1]]);         cur = dp[cur].second;       }       reverse(ans.begin(), ans.end());       fa.push_back(ans);       int c = 0;       for (int i = 1; i <= n; i++) {         c += avl[i];         if (avl[i] == 1) {           p[c] = p[i];           rp[i] = c;         }       }       vector<int> temp;       for (int i = 1; i <= n; i++) {         if (avl[a[i - 1]]) {           temp.push_back(rp[a[i - 1]]);         }       }       a = temp;       build();       return;     } else {       vector<int> v[n + 5];       for (int i = 1; i <= n; i++) {         v[dp[i].first].push_back(p[a[i - 1]]);       }       for (int i = 0; i <= n; i++) {         if (v[i].size()) fa.push_back(v[i]);       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int cur = 2;     for (int i = 1; i < N; i++) {       for (int j = 0; j < cur && i + j < N; j++) {         val[i + j] = cur - 1;       }       i += cur - 1;       cur++;     }     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       a.clear();       for (int i = 1; i <= n; i++) {         p[i] = i;         int x;         cin >> x;         a.push_back(x);       }       fa.clear();       build();       cout << fa.size() << endl;       for (auto& it : fa) {         cout << it.size() <<    ;         for (auto it1 : it) cout << it1 <<    ;         cout << endl;       }     }   }
#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   template <typename T>   T gcd(T a, T b) {     return b == 0 ? a : gcd(b, a % b);   }   const int maxn = 1e5 + 5;   const long long mod = 1e9 + 7;   int Case = 1;   int n, m;   struct node {     int x, y, xx, yy;   } a, b, c;   vector<int> A, B;   int getid(int x, int id) {     if (id == 1)       return lower_bound(((A).begin()), ((A).end()), x) - A.begin() + 1;     else       return lower_bound(((B).begin()), ((B).end()), x) - B.begin() + 1;   }   int maze[20][20];   void solve() {     cin >> a.x >> a.y >> a.xx >> a.yy;     cin >> b.x >> b.y >> b.xx >> b.yy;     cin >> c.x >> c.y >> c.xx >> c.yy;     A.push_back(a.x * 2);     A.push_back(a.xx * 2);     A.push_back(a.x * 2 + 1);     A.push_back(a.xx * 2 + 1);     B.push_back(a.y * 2);     B.push_back(a.yy * 2);     B.push_back(a.y * 2 + 1);     B.push_back(a.yy * 2 + 1);     A.push_back(b.x * 2);     A.push_back(b.xx * 2);     A.push_back(b.x * 2 + 1);     A.push_back(b.xx * 2 + 1);     B.push_back(b.y * 2);     B.push_back(b.yy * 2);     B.push_back(b.y * 2 + 1);     B.push_back(b.yy * 2 + 1);     A.push_back(c.x * 2);     A.push_back(c.xx * 2);     A.push_back(c.x * 2 + 1);     A.push_back(c.xx * 2 + 1);     B.push_back(c.y * 2);     B.push_back(c.yy * 2);     B.push_back(c.y * 2 + 1);     B.push_back(c.yy * 2 + 1);     sort(((A).begin()), ((A).end()));     A.erase(unique(((A).begin()), ((A).end())), A.end());     sort(((B).begin()), ((B).end()));     B.erase(unique(((B).begin()), ((B).end())), B.end());     int x = getid(b.x * 2, 1), xx = getid(b.xx * 2, 1);     int y = getid(b.y * 2, 2), yy = getid(b.yy * 2, 2);     for (int i = x; i <= xx; i++) {       for (int j = y; j <= yy; j++) {         maze[i][j] = 1;       }     }     x = getid(c.x * 2, 1), xx = getid(c.xx * 2, 1);     y = getid(c.y * 2, 2), yy = getid(c.yy * 2, 2);     for (int i = x; i <= xx; i++) {       for (int j = y; j <= yy; j++) {         maze[i][j] = 1;       }     }     x = getid(a.x * 2, 1), xx = getid(a.xx * 2, 1);     y = getid(a.y * 2, 2), yy = getid(a.yy * 2, 2);     for (int i = x; i <= xx; i++) {       for (int j = y; j <= yy; j++) {         if (maze[i][j] == 0) {           cout <<  YES n ;           return;         }       }     }     cout <<  NO n ;     return;   }   int main() {     while (Case--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void calc() {     long long n, m;     cin >> n >> m;     vector<pair<long long, long long> > v;     vector<long long> a;     for (long long i = 0; i < m; i++) {       long long ai, bi;       cin >> ai >> bi;       v.push_back(make_pair(ai, bi));       a.push_back(ai);     }     sort(a.begin(), a.end());     reverse(a.begin(), a.end());     vector<long long> acc(m + 2);     for (long long i = 1; i <= m; i++) {       acc[i] = acc[i - 1] + a[i - 1];     }     long long ans = -1;     for (long long i = 0; i < m; i++) {       long long ai = v[i].first;       long long bi = v[i].second;       long long lo, hi;       lo = 0;       hi = m;       while (lo + 1 != hi) {         long long mid = (lo + hi) / 2;         if (a[mid] > bi)           lo = mid;         else           hi = mid;       }       long long curr, rem;       if (a[lo] > bi) {         curr = ai;         rem = n - 1;         if (rem > 0) {           long long used = min(lo + 1, rem);           curr += acc[used];           if (a[used - 1] <= ai) {             curr -= ai;             rem -= used;             rem++;             if (used + 1 <= m && a[used] > bi) {               rem--;               curr += a[used];             }           } else {             rem -= used;           }           if (rem > 0) curr += rem * bi;         }       } else {         curr = ai;         rem = n - 1;         if (rem > 0) curr += rem * bi;       }       ans = max(ans, curr);     }     cout << ans <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) calc();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 7;   const int inf = INT_MAX;   const long long inff = 5e18;   const long long mod = 1e9 + 7;   long long f[7];   long long dp[maxn], dp2[maxn];   vector<long long> value = {0, 0, 0, 1, 0, 0, 2, 0, 0, 3};   void update(long long x, long long dd) {     for (long long i = 999999; i >= 0; i--)       if (i >= x) dp[i] = max(dp[i], dp[i - x] + dd);   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long k;     cin >> k;     for (long long i = 0; i < 6; i++) cin >> f[i];     for (long long i = 1; i <= 999999; i++) dp[i] = -inff;     long long now = 3;     for (long long i = 0; i < 6; i++) {       long long cnt = 3 * (k - 1);       for (long long j = 1;; j <<= 1) {         if (j >= cnt) {           update(now * cnt, f[i] * cnt);           break;         } else           update(now * j, f[i] * j), cnt -= j;       }       now = now * 10;     }     now = 1;     for (long long i = 0; i < 6; i++) {       for (long long k = 0; k <= 999999; k++) dp2[k] = dp[k];       for (long long j = 0; j < 10; j++) {         for (long long k = 1; k <= 999999; k++)           if (k >= now * j)             dp2[k] = max(dp2[k], dp[k - j * now] + value[j] * f[i]);       }       for (long long k = 0; k <= 999999; k++) dp[k] = max(dp2[k], dp[k]);       now = now * 10;     }     long long q;     cin >> q;     while (q--) {       long long x;       cin >> x;       cout << dp[x] << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, m, a[2000000 + 100];   int main() {     cin >> n >> m;     if ((m < n - 1) || (m > 2 * (n + 1))) {       cout << -1 << endl;       return 0;     }     for (int i = 1; i <= n; i++) a[2 * i] = 0;     for (int i = 2; i <= n; i++) a[2 * i - 1] = 1;     m = m - (n - 1);     for (int i = 2; i <= n; i++) {       if (m == 0) break;       a[2 * i - 1] = 11, m--;     }     if (m == 1) cout << 1;     if (m == 2) cout << 11;     if (m == 3) cout << 11;     if (m == 4) cout << 11;     for (int i = 2; i <= 2 * n; i++) cout << a[i];     if (m == 3) cout << 1;     if (m == 4) cout << 11;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, i;   const int maxn = 1e5 + 20;   int arr[maxn];   int main() {     cin >> n >> m;     int x = m;     if (m <= n * 2) {       for (int i = 1; i <= m; i++) {         cout << i <<    ;       }     } else {       for (i = 1; i <= (m - n * 2); i++) {         cout << i + (n * 2) <<     << i <<    ;         arr[i + (n * 2)]++, arr[i]++;       }       for (int i = 1; i <= m; i++) {         if (arr[i] == 0) cout << i <<    ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e18;   long long dp[10000005], sol = 0;   int main() {     int n, i;     long long x, y;     scanf( %d%I64d%I64d , &n, &x, &y);     for (i = 1; i <= 10000005; i++) dp[i] = inf;     dp[1] = x;     for (i = 2; i <= n; i++) {       dp[i] = min(dp[i], dp[i - 1] + x);       if (i % 2 == 0) dp[i] = min(dp[i], dp[i / 2] + y);       if (i % 2 == 1) {         dp[i] = min(dp[i], dp[(i - 1) / 2] + y + x);         dp[i] = min(dp[i], dp[(i + 1) / 2] + y + x);       }     }     printf( %I64d n , dp[n]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int pen[2000005];   void update(int ind, int add) {     while (ind < 2000005) {       pen[ind] += add;       ind += ind & (-ind);     }   }   int query(int ind) {     int ret = 0;     while (ind > 0) {       ret = ret + pen[ind];       ind = ind & (ind - 1);     }     return ret;   }   pair<int, int> r[2000005];   bool vis[2000005];   int getIndex(int y) {     int sum = 0;     int ind = 0;     for (int i = 20; i >= 0; --i) {       int nind = ind + (1 << i);       if (nind < 2000005) {         int nsum = sum + pen[nind];         if (nsum < y) {           sum = nsum;           ind = nind;         }       }     }     return ind + 1;   }   int out[2000005];   int mapping[2000005];   void solve() {     int n, m;     scanf(  %d %d  , &n, &m);     int pos = m + 1;     for (int i = 1; i <= n; ++i) {       r[pos + i] = {-1, i};       update(pos + i, 1);     }     for (int i = 0; i < m; ++i) {       int x, y;       scanf( %d %d  , &x, &y);       int ind = getIndex(y);       if (vis[x]) {         if (r[ind].first != x) {           printf( -1 n );           return;         }       } else {         if (r[ind].first != -1) {           printf( -1 n );           return;         }       }       update(ind, -1);       update(pos, 1);       r[pos] = r[ind];       r[pos].first = x;       vis[x] = true;       --pos;     }     int p = 1;     for (int i = 1; i <= n; ++i) {       int ind = getIndex(i);       if (r[ind].first == -1) {         while (p <= n) {           if (vis[p]) {             ++p;           } else {             break;           }         }         r[ind].first = p++;       }       out[r[ind].second] = r[ind].first;     }     for (int i = 1; i <= n; ++i) {       printf( %d  , out[i]);     }   }   int main() {     solve();     return 0;   }
#include<bits/stdc++.h>   #define For(i,x,y) for (register int i=(x);i<=(y);i++)   #define FOR(i,x,y) for (register int i=(x);i<(y);i++)   #define Dow(i,x,y) for (register int i=(x);i>=(y);i--)   #define Debug(v) for (auto i:v) cout<<i<<   ;puts(  )   #define mp make_pair   #define fi first   #define se second   #define pb push_back   #define ep emplace_back   #define siz(x) ((int)(x).size())   #define all(x) (x).begin(),(x).end()   #define fil(a,b) memset((a),(b),sizeof(a))   using namespace std;   typedef long long ll;   typedef unsigned long long ull;   typedef pair<int,int> pa;   typedef pair<ll,ll> PA;   typedef vector<int> poly;   inline ll read(){    ll x=0,f=1;char c=getchar();    while ((c< 0 ||c> 9 )&&(c!= - )) c=getchar();    if (c== - ) f=-1,c=getchar();    while (c>= 0 &&c<= 9 ) x=x*10+c- 0 ,c=getchar();    return x*f;   }      const int N = 5010;   int n,p[N];   pa a[N];      inline pa operator - (pa a,pa b){    return mp(a.fi-b.fi,a.se-b.se);   }   inline bool check(pa a,pa b,pa c){    pa A=a-b,B=c-b;    return (1ll*A.fi*B.fi+1ll*A.se*B.se)>0;   }      int main(){    n=read();    For(i,1,n) a[i].fi=read(),a[i].se=read(),p[i]=i;    For(i,3,n){     Dow(j,i,3) if (!check(a[p[j-2]],a[p[j-1]],a[p[j]])){      swap(p[j],p[j-1]);     }    }    For(i,1,n) printf( %d  ,p[i]);   }
#include <bits/stdc++.h>   using namespace std;   bool compare(const pair<int, int> &i, const pair<int, int> &j) {     return i.second > j.second;   }   int n, d;   vector<pair<long long, long long>> a;   long long p(long long a, long long b) {     long long x = 1, y = a;     while (b > 0) {       if (b % 2 == 1) {         x = (x * y) % 998244353;       }       y = (y * y) % 998244353;       b /= 2;     }     return x % 998244353;   }   long long inv(long long a) { return p(a, 998244353 - 2); }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     string s;     cin >> s;     map<char, int> m;     vector<char> v;     for (int i = 0; i < s.length(); i++) {       m[s[i]]++;     }     for (auto x : m)       if (x.second % 2) v.push_back(x.first);     for (int i = v.size() - 1, j = 0; i > j; i--, j++) {       if (i <= j) break;       m[v[j]]++, m[v[i]]--;     }     string str =   ;     char flag =  0 ;     for (auto x : m) {       if (!x.second) continue;       if (x.second % 2) flag = x.first;       for (int i = 0; i < (x.second) / 2; i++) {         str += x.first;       }     }     string ans = str;     if (flag !=  0 ) {       ans += flag;     }     reverse(str.begin(), str.end());     ans += str;     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<long long int> g[100005];   long long int vis[100005];   vector<double> ans;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t = 1;     cin >> t;     while (t--) {       long long int a, b, c, d;       cin >> a >> b >> c >> d;       if ((b - a) % (c + d) == 0)         cout << (b - a) / (c + d);       else         cout << -1;       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0), cin.tie(0);     long long n, k;     cin >> n >> k;     long long a[k];     map<long long, bool> m;     for (long long i = 0; i < k; i++) {       cin >> a[i];       m[a[i]] = true;     }     long long cnt = 1;     for (long long i = 0; i < k; i++) {       cout << a[i];       for (long long i = 0; i < n - 1; i++) {         if (!m[cnt])           cout <<     << cnt;         else           i--;         cnt++;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   const int mx = 1e6 + 5;   const int inf = 0x3f3f3f3f;   using namespace std;   vector<int> ans;   int dfs(long long int a, long long int b) {     if (a > b) return 0;     if (a == b) return 1;     if (dfs(a * 2, b)) {       ans.push_back(2 * a);       return 1;     }     if (dfs(a * 10 + 1, b)) {       ans.push_back(a * 10 + 1);       return 1;     }     return 0;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int a, b;     cin >> a >> b;     if (dfs(a, b)) {       printf( YES n%d n%d  , int(1 + ans.size()), a);       for (int i = ans.size() - 1; i >= 0; --i) printf( %d  , ans[i]);       puts(  );     } else       puts( NO );     return 0;   }