malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100;   char s[maxn];   int l;   long long make(int x, long long u) {     int z = l - x;     long long k = 1, u1 = 0;     for (int i = 0; i < z; i++) {       u1 += (s[l - 1 - i] -  0 ) * k;       k *= 10;     }     u1 += u / k * k;     if (u1 <= u) u1 += k;     return u1;   }   int main() {     int t;     cin >> t;     while (t--) {       scanf( %s , s);       l = strlen(s);       long long u = 1988;       for (int i = l - 1; i >= 4; i--) {         u = make(i, u);       }       cout << u << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, q, g[13][13], lca[13][13];   long long dp[1 << 13][13];   long long f(int s, int root) {     s &= ~(1 << root);     if (s == 0) return 1;     if (dp[s][root] != -1) return dp[s][root];     long long res = 0;     int must = 0;     for (int i = (0); i < (n); i++)       if (s & 1 << i) {         must = i;         break;       }     for (int x = (0); x < (1 << n); x++)       if (((x | s) == s) && (x & 1 << must)) {         int ny = s ^ x;         int y = ny | 1 << root;         bool bad = false;         for (int i = (0); i < (n); i++)           for (int j = (0); j < (n); j++)             if ((x & 1 << i) && (x & 1 << j)) {               if (lca[i][j] != -1 && (y & 1 << lca[i][j])) {                 bad = true;               }             }         for (int i = (0); i < (n); i++)           for (int j = (0); j < (n); j++)             if ((x & 1 << i) && (y & 1 << j)) {               if (lca[i][j] != -1 && lca[i][j] != root) {                 bad = true;               }             }         for (int i = (0); i < (n); i++)           for (int j = (0); j < (n); j++)             if ((x & 1 << i) && (ny & 1 << j)) {               if (g[i][j]) bad = true;             }         int c = 0, x_root = -1;         for (int i = (0); i < (n); i++)           if (x & 1 << i) {             if (g[root][i]) {               c++;               x_root = i;             }           }         if (c >= 2) bad = true;         if (bad) continue;         for (int i = (0); i < (n); i++)           if (x & 1 << i) {             if (x_root != -1 && i != x_root) continue;             res += f(x, i) * f(y, root);           }       }     return dp[s][root] = res;   }   int main() {     cin >> n >> m >> q;     for (int i = (0); i < (m); i++) {       int u, v;       cin >> u >> v;       u--;       v--;       g[u][v] = g[v][u] = 1;     }     memset(lca, -1, sizeof(lca));     for (int i = (0); i < (n); i++) lca[i][i] = i;     for (int i = (0); i < (q); i++) {       int a, b, c;       cin >> a >> b >> c;       a--;       b--;       c--;       if (lca[a][b] != -1 && lca[a][b] != c) {         cout << 0 << endl;         return 0;       }       lca[a][b] = lca[b][a] = c;     }     memset(dp, -1, sizeof(dp));     cout << f((1 << n) - 1, 0) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 510, mod = 1LL * 1000 * 1000 * 1000 + 7;   int dp[N][N], n, b[N], num[N][N];   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n;     for (int i = 0; i < n; i++) cin >> b[i];     for (int j = 1; j <= n; j++)       for (int i = j - 1; i >= 0; i--) {         if (j - i <= 2) {           dp[i][j] = num[i][j] = 1;           continue;         }         for (int k = i + 1; k + 1 < j; k++)           if (b[k] < b[j - 1])             (num[i][j] += 1LL * num[i][k + 1] * dp[k][j - 1] % mod) %= mod;         for (int k = i + 1; k < j; k++)           (dp[i][j] += 1LL * num[i][k + 1] * dp[k][j] % mod) %= mod;       }     cout << dp[0][n] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int mini;   map<char, int> M;   set<int> s;   int n;   void rec(int ind, vector<int> c, vector<int> d) {     if (ind == 10) {       int rem = n;       int X = c.size() + d.size();       int i, j;       set<int> S = s;       set<int>::iterator it;       for (i = 0; i < c.size(); i++) {         for (j = 0; j < d.size(); j++) {           if (S.find(5 * c[i] + d[j]) != S.end()) {             S.erase(5 * c[i] + d[j]);           }         }       }       for (i = 0; i < c.size(); i++) {         int count = 0, flag;         for (j = 0; j < 5; j++) {           if (S.find(5 * c[i] + j) != S.end()) {             count++;             flag = j;           }         }         if (count == 1) {           S.erase(5 * c[i] + flag);         }       }       for (i = 0; i < d.size(); i++) {         int count = 0, flag;         for (j = 0; j < 5; j++) {           if (S.find(5 * j + d[i]) != S.end()) {             count++;             flag = j;           }         }         if (count == 1) {           S.erase(5 * flag + d[i]);         }       }       if (S.size() == 1 || S.size() == 0) {         mini = min(mini, X);       }       return;     }     if (ind < 5) {       rec(ind + 1, c, d);       c.push_back(ind);       rec(ind + 1, c, d);     } else {       rec(ind + 1, c, d);       d.push_back(ind - 5);       rec(ind + 1, c, d);     }   }   int main() {     mini = 10;     M[ R ] = 0;     M[ G ] = 1;     M[ B ] = 2;     M[ Y ] = 3;     M[ W ] = 4;     cin >> n;     int i;     string st;     for (i = 0; i < n; i++) {       cin >> st;       s.insert(5 * M[st[0]] + st[1] -  1 );     }     vector<int> c;     vector<int> d;     rec(0, c, d);     cout << mini << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 110000;   const int M = 1100000;   const long long mod = 1e9 + 7;   int n, m;   vector<pair<int, int> > g[N];   int edge[N];   int col[N], dep[N];   int val[N], f[N];   void dfs(int x, int fa) {     f[x] = fa;     dep[x] = dep[fa] + 1;     for (auto p : g[x]) {       int y = p.first, id = p.second;       if (y == fa) continue;       edge[y] = id;       dfs(y, x);     }   }   struct query {     int x, y, w;     friend bool operator<(query a, query b) { return a.w < b.w; }   } a[N], b[N];   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d %d , &x, &y);       g[x].push_back(make_pair(y, i)), g[y].push_back(make_pair(x, i));     }     dfs(1, 0);     scanf( %d , &m);     for (int i = 1; i <= n; i++) val[i] = 1e6;     for (int i = 1; i <= m; i++) {       scanf( %d %d %d , &a[i].x, &a[i].y, &a[i].w);       b[i] = a[i];     }     sort(a + 1, a + 1 + m);     for (int i = 1; i <= m; i++) {       int nx = a[i].x, ny = a[i].y;       while (dep[nx] != dep[ny]) {         if (dep[nx] > dep[ny])           val[edge[nx]] = a[i].w, nx = f[nx];         else           val[edge[ny]] = a[i].w, ny = f[ny];       }       while (nx != ny) {         val[edge[nx]] = a[i].w, nx = f[nx];         val[edge[ny]] = a[i].w, ny = f[ny];       }     }     int flag = 0;     for (int i = 1; i <= m; i++) {       int nx = b[i].x, ny = b[i].y;       int mn = 1e9;       while (dep[nx] != dep[ny]) {         if (dep[nx] > dep[ny])           mn = min(mn, val[edge[nx]]), nx = f[nx];         else           mn = min(mn, val[edge[ny]]), ny = f[ny];       }       while (nx != ny) {         mn = min(mn, val[edge[nx]]), nx = f[nx];         mn = min(mn, val[edge[ny]]), ny = f[ny];       }       if (mn != b[i].w) flag = 1;     }     if (flag)       printf( -1 n );     else {       for (int i = 1; i < n; i++) printf( %d  , val[i]);     }     return 0;   }
#include<iostream>   #include<algorithm>   using namespace std;   long long cmp(long long a,long long b)   {    return a > b;   }   int main()   {    int t,n,i;    long long array[200000],alice,bob;    cin>>t;    while(t--)    {     alice=0;     bob=0;     cin>>n;     for(i=0;i<n;i++)     {      scanf( %lld ,&array[i]);     }     sort(array,array+n,cmp);     for(i=0;i<n;i++)     {      if(i%2==0)      {       if(array[i]%2==0)alice+=array[i];      }      else      {       if(array[i]%2!=0)bob+=array[i];      }     }     if(alice>bob)cout<< Alice <<endl;     else if(alice<bob)cout<< Bob <<endl;     else cout<< Tie <<endl;    }   }
#include <bits/stdc++.h>   using namespace std;   static inline void canhazfast() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);   }   template <typename T>   T gcd(T a, T b) {     return b == 0 ? a : gcd(b, a % b);   }   template <typename T>   T extgcd(T a, T b, T &x, T &y) {     T x0 = 1, y0 = 0, x1 = 0, y1 = 1;     while (b) {       T q = a / b;       a %= b;       swap(a, b);       x0 -= q * x1;       swap(x0, x1);       y0 -= q * y1;       swap(y0, y1);     }     x = x0;     y = y0;     return a;   }   static inline int ctz(unsigned x) { return __builtin_ctz(x); }   static inline int ctzll(unsigned long long x) { return __builtin_ctzll(x); }   static inline int clz(unsigned x) { return __builtin_clz(x); }   static inline int clzll(unsigned long long x) { return __builtin_clzll(x); }   static inline int popcnt(unsigned x) { return __builtin_popcount(x); }   static inline int popcntll(unsigned long long x) {     return __builtin_popcountll(x);   }   static inline int bsr(unsigned x) { return 31 ^ clz(x); }   static inline int bsrll(unsigned long long x) { return 63 ^ clzll(x); }   struct Node {     long long mx, lz;   };   Node t[1 << 19];   int a[1 << 18];   long long build(int u, int b, int e, long long s = 0) {     if (b + 1 == e) {       t[u].mx = a[b] - s;       return s + a[b];     }     int m = (b + e) / 2, lc = 2 * u, rc = 2 * u + 1;     s = build(lc, b, m, s);     s = build(rc, m, e, s);     t[u].mx = max(t[lc].mx, t[rc].mx);     return s;   }   void push(int u, int sz) {     if (!t[u].lz) return;     t[u].mx += t[u].lz;     if (sz > 1) {       t[2 * u].lz += t[u].lz;       t[2 * u + 1].lz += t[u].lz;     }     t[u].lz = 0;   }   void upd(int u, int b, int e, int pos, int d) {     int sz = e - b;     if (pos >= e) return push(u, e - b);     if (pos < b) return t[u].lz -= d, push(u, sz);     if (sz == 1) return t[u].lz += d, push(u, sz);     push(u, sz);     int m = (b + e) / 2, lc = 2 * u, rc = 2 * u + 1;     upd(lc, b, m, pos, d);     upd(rc, m, e, pos, d);     t[u].mx = max(t[lc].mx, t[rc].mx);   }   int get(int u, int b, int e) {     push(u, e - b);     if (t[u].mx < 0) return -2;     if (b + 1 == e) return t[u].mx == 0 ? b : -2;     int m = (b + e) / 2, lc = 2 * u, rc = 2 * u + 1;     int res = get(lc, b, m);     if (res < 0) res = get(rc, m, e);     return res;   }   int main() {     canhazfast();     int n, q;     cin >> n >> q;     for (int i = 0; i < n; ++i) cin >> a[i];     build(1, 0, n);     for (; q; --q) {       int p, x;       cin >> p >> x;       --p;       upd(1, 0, n, p, x - a[p]);       a[p] = x;       cout << get(1, 0, n) + 1 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     string t;     cin >> t;     int n = t.size();     int start = (n % 2) ? n / 2 : n / 2 - 1;     int j = 1;     int k = n / 2;     putchar(t[start]);     while (k--) {       if (start + j <= n - 1) {         putchar(t[start + j]);       }       if (start - j >= 0) {         putchar(t[start - j]);       }       ++j;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long n, c[long(1e7 + 50)], cnt;   void sieve() {     c[1] = 1;     for (long i = 2; i <= long(1e7); ++i)       if (!c[i])         for (long j = 2; i * j <= long(1e7); ++j) c[i * j] = 1;   }   bool Prime(long x) {     if (x < long(1e7)) {       if (c[x]) return false;       return true;     }     for (long i = 2; i <= trunc(sqrt(x)); ++i)       if (!(x % i)) return false;     return true;   }   int main() {     scanf( %ld , &n);     if (n <= 7)       printf( 1 n%ld , n);     else {       printf( 3 n );       sieve();       n -= 3;       for (long i = n; i >= 1; --i)         if (Prime(i) && Prime(n - i)) {           printf( %ld %ld %ld , i, n - i, 3);           return 0;         }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int const maxn = 1e5 + 5;   int n, m, k, p[105], second[105], mx[105];   int ans;   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; ++i) scanf( %d , &p[i]);     for (int i = 1; i <= n; ++i) {       scanf( %d , &second[i]);       if (mx[second[i]] < p[i]) mx[second[i]] = p[i];     }     for (int i = 1; i <= k; ++i) {       int v;       scanf( %d , &v);       if (mx[second[v]] > p[v]) ans++;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   const long double PI = 4 * atan((long double)1);   const long long mod = 1e9 + 7;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long tt = 1;     while ((tt)--) {       long long n, m;       cin >> n >> m;       if (min(n, m) & 1) {         cout <<  Akshat  <<   n ;       } else {         cout <<  Malvika  <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int a[205], max1, n, k, t;   int main() {     cin >> t;     while (t > 0) {       t--;       scanf( %d%d , &n, &k);       for (int i = 0; i < k; i++) scanf( %d , &a[i]);       max1 = 0;       if (k == 1)         cout << max(n - a[0] + 1, a[0]) << endl;       else {         for (int i = 1; i < k; i++) {           if ((a[i] - a[i - 1]) / 2 + 1 > max1) max1 = (a[i] - a[i - 1]) / 2 + 1;         }         int d = max(n - a[k - 1] + 1, a[0]);         if (d > max1)           cout << d << endl;         else {           cout << max1 << endl;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[500010], b[500010], l[500010], lb[39], at[39];   vector<int> v[500010];   int main() {     int n, q, p = 0, i, r, x, y;     cin >> n;     for (i = 1; i <= n; i++) scanf( %d , &a[i]);     cin >> q;     for (i = 1; i <= q; i++) {       scanf( %d%d , &l[i], &x);       v[x].push_back(i);     }     for (r = 1; r <= n; r++) {       x = a[r];       p = r;       for (i = 20; ~i; i--)         if ((1 << i) & x) {           if (!lb[i]) {             lb[i] = x;             at[i] = p;             break;           }           if (at[i] < p) swap(lb[i], x), swap(at[i], p);           x ^= lb[i];         }       for (auto x : v[r])         for (i = 20; ~i; --i)           if (at[i] >= l[x]) b[x] = max(b[x], b[x] ^ lb[i]);     }     for (i = 1; i <= q; i++) printf( %d n , b[i]);   }
#include <bits/stdc++.h>   using namespace std;   long long modpow(long long b, long long e, long long m) {     b %= m;     if (e == 0) return 1;     if (e % 2 == 1) return (b * modpow(b, e - 1, m)) % m;     return modpow((b * b) % m, e / 2, m);   }   long long powten[1005];   vector<long long> mods;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     int n, k, m;     cin >> n >> k >> m;     for (int i = 0; i < 1005; i++) {       if (i == 0)         powten[i] = 1;       else         powten[i] = (10 * powten[i - 1]) % k;     }     mods.resize(k, 0);     for (int i = 0; i < 10; i++) {       if (i % k != 0 or i == 0) mods[i % k] = (mods[i % k] + 1) % m;     }     for (int i = 1; i < n; i++) {       vector<long long> temp;       temp.resize(k, 0);       for (int j = 0; j < 10; j++) {         if (i == n - 1 and j == 0) continue;         long long del = (j * powten[i]) % k;         for (int prev = 0; prev < k; prev++)           temp[(prev + del) % k] = (temp[(prev + del) % k] + mods[prev]) % m;       }       temp[0] = ((i == n - 1) ? 0 : 1);       mods = temp;     }     if (n == 1) mods[0] = 0;     long long total = (9 * modpow(10, n - 1, m)) % m;     for (int i = 0; i < k; i++) total = (total - mods[i] + m) % m;     cout << total <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool sortin(const pair<long long int, long long int> &e,               const pair<long long int, long long int> &f) {     return (e.first < f.first);   }   bool POT(long long int x) { return x && (!(x & (x - 1))); }   long long int a, b, c, i, j, k, l, m, n, p, q, r, x, y, z, ts, mn = 10e17,                                                                  mod = 10e8 + 7;   long long int ar[1000002], br[1000002], xr[1000002];   int main() {     {       ios_base::sync_with_stdio(false);       cin.tie(0);       cout.tie(0);     };     string s;     cin >> s >> a >> b;     n = s.size();     p = 1;     for (long long int i = n - 1; i >= 0; i--) {       xr[i] = ((s[i] -  0 ) * p + xr[i + 1]) % b;       p = (p * 10) % b;     }     xr[n] = 1;     p = 0;     for (long long int i = 0; i <= n - 2; i++) {       p = (p * 10 + s[i] -  0 ) % a;       if (p == 0 and xr[i + 1] == 0 and s[i + 1] !=  0 ) {         cout <<  YES ;         cout << endl;         cout << s.substr(0, i + 1);         cout << endl;         cout << s.substr(i + 1, n - i - 1);         return 0;       }     }     cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unrolled-loops )   int n, m, b, w, color[200010], ok[200010];   vector<int> a[200010];   void dfs(int u, int c) {     color[u] = c;     ok[u] = 1;     b += (c == 0);     w += (c == 1);     for (int i = 0; i < a[u].size(); i++)       if (!ok[a[u][i]]) dfs(a[u][i], 1 - c);   }   void solve() {     cin >> n >> m;     for (int i = 1; i <= n; i++) {       a[i].clear();       color[i] = 0;       ok[i] = 0;     }     int u, v;     for (int i = 0; i < m; i++) {       cin >> u >> v;       a[u].push_back(v);       a[v].push_back(u);     }     b = 0;     w = 0;     dfs(1, 0);     cout << min(b, w) <<   n ;     if (b < w)       for (int i = 1; i <= n; i++) {         if (!color[i]) cout << i <<    ;       }     else       for (int i = 1; i <= n; i++) {         if (color[i]) cout << i <<    ;       }     cout <<   n ;   }   int main() {     int t;     cin >> t;     while (t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   inline int Get() {     int res = 0, q = 1;     char ch = getchar();     while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar();     if (ch ==  - ) q = -1, ch = getchar();     while (ch >=  0  && ch <=  9 ) res = res * 10 + ch -  0 , ch = getchar();     return res * q;   }   const double eps = 1e-12, pi = M_PI;   const int oo = (int)2e9, mod = (int)1e9 + 7;   const long long INF = (long long)1e17;   int T;   long long a, n, p, h;   long long Calc(long long a, long long n, long long p) {     long long rd = a * n / p;     if (!rd) return ((a) > (p - a * n) ? (a) : (p - a * n));     long long dt = a * n % p, st = p - p % a - a;     if (dt < st) --rd;     return Calc(min(a - p % a, p % a), rd, a);   }   int main() {     for (scanf( %d                   n ,                &T);          T--;) {       scanf(            %I64d             %I64d             %I64d             %I64d              n ,           &a, &n, &p, &h),           a %= p;       if (a * n < p)         printf( %s n , a <= h ?  YES  :  NO );       else         printf( %s n , Calc(a, n, p) <= h ?  YES  :  NO );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i;     cin >> n;     if (n & 1) {       for (i = 0; i < n; i++) cout << (i) <<    ;       cout <<   n ;       for (i = 0; i < n; i++) cout << (i) <<    ;       cout <<   n ;       for (i = 0; i < n; i++) cout << ((2 * i) % n) <<    ;       cout <<   n ;       ;     } else       cout << -1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int mex(set<int> s) {     int v = 0;     while (s.count(v) > 0) v++;     return v;   }   int g[65]{0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4,  4,  5,  5,  5,  5, 5, 5,             6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7,  7,  8,  8,  8,  8, 8, 8,             8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10};   const int MAXN = 1000007;   int s[MAXN];   map<pair<int, long long>, int> dp;   int grundy(pair<int, long long> s) {     if (dp.find(s) != dp.end()) return dp[s];     long long mask = s.second;     int &res = dp[s];     set<int> S;     for (int i = 1; i <= 60; i++) {       if (!(mask & (1ll << i)) && s.first >= i) {         S.insert(grundy(make_pair(s.first - i, (mask | (1ll << i)))));       }     }     while (S.count(res) > 0) res++;     return res;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &s[i]);     }     if (n == 1)       printf( NO n );     else {       int XOR = 0;       for (int i = 0; i < n; i++) {         XOR ^= grundy(make_pair(s[i], 0));       }       if (XOR == 0)         printf( YES n );       else         printf( NO n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long L, v, l, r;       cin >> L >> v >> l >> r;       long long tot = L / v;       long long minus = r / v;       minus -= (l - 1) / v;       cout << tot - minus <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[1000000];   int ans[1000000];   int cnt;   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       ans[a[i]]++;     }     for (int j = 1; j <= n; j++)       if (ans[j] == 0) cnt++;     cout << cnt << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct habijabi {     long int start_time, end_time;   } work[500500];   bool cmp(habijabi a, habijabi b) {     if (a.end_time == b.end_time) {       return a.start_time < b.start_time;     }     return a.end_time < b.end_time;   }   int main() {     long int t, n, i, j;     scanf( %ld , &n);     for (i = 0; i < n; i++) {       scanf( %ld %ld , &work[i].start_time, &work[i].end_time);     }     sort(work, work + n, cmp);     int ans = 0, prev_end = -1;     for (i = 0; i < n; i++) {       if (work[i].start_time > prev_end) {         ans++;         prev_end = work[i].end_time;       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   const int INF = 0x3f3f3f3f;   using namespace std;   int v[5005];   int main() {     int t1;     cin >> t1;     for (int t = 1; t <= t1; t++) {       int n, d;       cin >> n >> d;       memset(v, 0, sizeof(v));       int l = 1, nr = n - 1;       v[0] = 1;       for (; nr >= v[l - 1] * 2; l++) {         v[l] = v[l - 1] * 2;         d -= v[l] * l;         nr -= v[l];       }       if (nr == 0)         l--;       else         d -= nr * l, v[l] = nr;       if (d < 0) {         cout <<  NO n ;         continue;       }       int l2;       for (l2 = l; d > 0 && l >= 1; l--) {         if (v[l] == 1) continue;         if (l2 + 1 - l > d) {           v[l]--;           v[l + d]++;           d = 0;           break;         }         v[++l2] = 1;         d -= l2 - l;         v[l]--;         l++;       }       if (d == 0) {         cout <<  YES n ;         queue<int> p[5005];         p[0].push(1);         p[0].push(1);         for (int i = 1, node = 2; i <= l2; i++)           if (v[i] > 0) {             cout << p[i - 1].front() <<    ;             p[i - 1].pop();             p[i].push(node);             p[i].push(node);             v[i--]--;             node++;           }         cout <<   n ;       } else {         cout <<  NO n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, i, j, n, mx, p, b[1001], m;     cin >> n >> m;     for (i = 1; i <= 1000; i++) b[i] = 0;     for (i = 1; i <= m; i++) {       mx = -1;       p = -1;       for (j = 1; j <= n; j++) {         cin >> a;         if (a > mx) {           mx = a;           p = j;         }       }       b[p]++;     }     int bmax = b[1], pmax = 1;     for (i = 2; i <= 1000; i++)       if (b[i] > bmax) {         bmax = b[i];         pmax = i;       }     cout << pmax;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e6 + 5;   bool solve(int, int);   bool trySolve(int, int);   bool trySolve(int w, int m) { return (m % w == 0 && solve(w, m / w)); }   bool solve(int w, int m) {     return (w <= 3 || m == 1 || trySolve(w, m - 1) || trySolve(w, m) ||             trySolve(w, m + 1));   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int w, m;     cin >> w >> m;     if (w == 2 || w == 3)       cout <<  YES ;     else {       if (solve(w, m))         cout <<  YES ;       else         cout <<  NO ;     }     return 0;   }