malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <iostream>   #include <cstdio>   #include <cmath>   #include <cstring>   #include <vector>   #include <map>      #include <set>   #include <cmath>   #include <queue>   #include <algorithm>   #include <numeric>   using namespace std;   typedef long long ll;   const int N=1e6+5;   const int M=1e3+5;   const int mod=1e9+7;   int n,m;   int T,a[N];   std::vector<int> ans;   int rns;   bool cal(vector<int> v,std::vector<int> v1){       for(int i=0;i<n*2;i++){           if(v[i]!=v1[i])return 0;       }       return 1;   }   map<std::vector<int>,int>mp;   void bfs(){       queue<vector<int> >q;       std::vector<int>G;       for(int i=1;i<=n*2;i++)G.push_back(i);           rns=-1;       q.push(G);       mp[G]=0;       while(!q.empty()){           std::vector<int> now=q.front();           q.pop();           if(cal(now,ans)==1){               rns=mp[now];               return ;           }           std::vector<int> v1=now;           for(int i=0;i+1<n*2;i+=2){               swap(v1[i],v1[i+1]);           }           std::vector<int> v2=now;           for(int i=0;i+n<n*2;i++){               swap(v2[i],v2[i+n]);           }           if(!mp.count(v1)){               q.push(v1);               mp[v1]=mp[now]+1;           }           if(!mp.count(v2)){               q.push(v2);               mp[v2]=mp[now]+1;           }       }               }   int main() {       scanf( %d ,&n);       for(int i=1;i<=n*2;i++)scanf( %d ,&a[i]),ans.push_back(a[i]);       bfs();   cout<<rns<<endl;                                     }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t, c, i, a, m, l, r;     cin >> t >> i >> m >> a >> l;     r = i;     c = 1;     t = t - r;     while (t > 0) {       c++;       r = r + a;       if (r > m) r = m;       t = t + l - r;       if (t < 0) t = 0;     }     cout << c;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int q, n, m, u1, d1, l1, r1, u2, d2, l2, r2, u3, d3, l3, r3;   long long count(int a, int b) { return (1ll * a * b + 1) / 2; }   long long count(int u, int d, int l, int r) {     return count(d, r) + count(u - 1, l - 1) - count(d, l - 1) - count(u - 1, r);   }   int main() {     scanf( %d , &q);     while (q--) {       scanf( %d %d , &m, &n);       scanf( %d %d %d %d , &u1, &l1, &d1, &r1);       scanf( %d %d %d %d , &u2, &l2, &d2, &r2);       long long ans = count(n, m);       u3 = max(u1, u2), l3 = max(l1, l2);       d3 = min(d1, d2), r3 = min(r1, r2);       ans -= count(u2, d2, l2, r2);       ans += 1ll * (d1 - u1 + 1) * (r1 - l1 + 1) - count(u1, d1, l1, r1);       if (d3 >= u3 && r3 >= l3)         ans -= 1ll * (d3 - u3 + 1) * (r3 - l3 + 1) - count(u3, d3, l3, r3);       printf( %I64d %I64d n , ans, 1ll * n * m - ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   string in[1003];   int a[1003][1003];   int X[] = {-1, 0, 0, 1};   int Y[] = {0, -1, 1, 0};   bool d[1003][1003];   int getSm(int i, int j, int u, int v) {     return a[u][v] - a[i - 1][v] - a[u][j - 1] + a[i - 1][j - 1];   }   bool check() {     for (int i = 1; i <= n; i++) {       bool ok = 0;       int cnt = 0;       for (int j = 1; j <= m; j++) {         if (in[i][j] ==  # ) {           if (!ok) {             cnt++;             ok = 1;           }         } else {           ok = 0;         }       }       if (cnt > 1) {         return 0;       }       if (cnt == 0) {         ok = 0;         for (int j = 1; j <= m; j++) {           if (getSm(1, j, n, j) == 0) {             ok = 1;             continue;           }         }         if (!ok) {           return 0;         }       }     }     for (int j = 1; j <= m; j++) {       bool ok = 0;       int cnt = 0;       for (int i = 1; i <= n; i++) {         if (in[i][j] ==  # ) {           if (!ok) {             cnt++;             ok = 1;           }         } else {           ok = 0;         }       }       if (cnt > 1) {         return 0;       }       if (cnt == 0) {         ok = 0;         for (int i = 1; i <= n; i++) {           if (getSm(i, 1, i, m) == 0) {             ok = 1;             continue;           }         }         if (!ok) {           return 0;         }       }     }     return 1;   }   bool canC(int u, int v) {     return (1 <= u) && (u <= n) && (1 <= v) && (v <= m) && (in[u][v] ==  # ) &&            (d[u][v] == 0);   }   void DFS(int u, int v) {     d[u][v] = 1;     for (int k = 0; k < 4; k++) {       int nu = u + X[k];       int nv = v + Y[k];       if (canC(nu, nv)) {         DFS(nu, nv);       }     }   }   int main() {     ios::sync_with_stdio(0);     cin >> n >> m;     for (int i = 1; i <= n; i++) {       cin >> in[i];       in[i].insert(0,    );       for (int j = 1; j <= m; j++)         a[i][j] = (in[i][j] ==  # ) + a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1];     }     if (a[n][m] == 0) {       cout << 0;       return 0;     }     if (n == 1) {       int cnt = 0;       for (int j = 1; j <= m; j++) {         cnt += (in[1][j] ==  # );       }       if ((0 < cnt) && (cnt < m)) {         cout << -1;         return 0;       }     }     if (m == 1) {       int cnt = 0;       for (int i = 1; i <= n; i++) {         cnt += (in[i][1] ==  # );       }       if ((0 < cnt) && (cnt < n)) {         cout << -1;         return 0;       }     }     if (!check()) {       cout << -1;       return 0;     }     memset(d, 0, sizeof d);     int res = 0;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         if ((in[i][j] ==  # ) && (d[i][j] == 0)) {           res++;           DFS(i, j);         }       }     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e3 + 5;   const int mod = 998244353;   char s[maxn], t[maxn];   int m, n, dp[maxn][maxn];   int main() {     scanf( %s%s , s + 1, t + 1);     n = strlen(s + 1);     m = strlen(t + 1);     for (int i = 1; i <= n; i++) {       if (i > m || t[i] == s[1]) dp[i][i] = 2;     }     for (int len = 2; len <= n; len++) {       char ch = s[len];       for (int l = 1; l + len - 1 <= n; l++) {         int r = l + len - 1;         if (l > m || ch == t[l]) dp[l][r] = (dp[l][r] + dp[l + 1][r]) % mod;         if (r > m || ch == t[r]) dp[l][r] = (dp[l][r] + dp[l][r - 1]) % mod;       }     }     int ans = 0;     for (int i = m; i <= n; i++) ans = (ans + dp[1][i]) % mod;     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   const int N = 1e5 + 5;   vector<pair<int, int> > aa, bb;   bool valid(pair<int, int> p1, pair<int, int> p2) {     if (p1.first == p2.first || p1.second == p2.second || p1.first == 0 ||         p1.second == 0 || p2.first == 0 || p2.second == 0)       return 0;     if (p1.first * p2.first + p1.second * p2.second != 0) return 0;     return 1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     int a, b;     cin >> a >> b;     for (int i = 1; i <= a; i++) {       for (int j = 1; j <= a; j++) {         if (i * i + j * j == a * a) aa.push_back({i, j});       }     }     for (int i = 1; i <= b; i++) {       for (int j = 1; j <= b; j++) {         if (i * i + j * j == b * b) bb.push_back({-i, j});       }     }     for (auto p1 : aa) {       for (auto p2 : bb) {         if (valid(p1, p2)) {           cout <<  YES n ;           cout <<  0 0 n ;           cout << p1.first <<     << p1.second <<   n ;           cout << p2.first <<     << p2.second <<   n ;           return 0;         }       }     }     cout <<  NO n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int k = 0, t = 0, l = 0, q = 0, z = 0;     string s, s1, s2;     cin >> s;     if (s[0] ==  - ) {       q = -1;       s.erase(0, 1);     }     k = s.size();     for (int i = 0; i < s.size(); i++)       if (s[i] ==  . ) {         t = i;         break;       }     if (t == 0) s +=  .00 , t = k;     if (s.size() - t == 2) s +=  0 ;     l = t;     if (q == -1) cout <<  ( ;     cout <<  $ ;     if (l % 3 != 0)       z = l % 3;     else       z = 3;     for (int i = 0; i < l + 3; i++) {       if (i == z && z < l) {         cout <<  , ;         z += 3;       }       if (s[i] !=  - ) cout << s[i];     }     if (q == -1) cout <<  ) ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   long long a3, b3;   bool check1(long long a1, long long b1, long long a2, long long b2) {     if ((a2 * a3 + b2 * b3 + a1 * b3 - a3 * b1) % (a3 * a3 + b3 * b3))       return false;     if ((a2 * b3 - b2 * a3 - a1 * a3 - b1 * b3) % (a3 * a3 + b3 * b3))       return false;     return true;   }   bool check2(long long a1, long long b1, long long a2, long long b2) {     if ((a2 * a3 + b2 * b3 - a1 * a3 - b1 * b3) % (a3 * a3 + b3 * b3))       return false;     if ((a1 * b3 - b1 * a3 - a2 * b3 + b2 * a3) % (a3 * a3 + b3 * b3))       return false;     return true;   }   bool check(long long a1, long long b1, long long a2, long long b2) {     if (a1 == a2 && b1 == b2) return true;     if (b1 == a2 && -a1 == b2) return true;     if (-a1 == a2 && -b1 == b2) return true;     if (-b1 == a2 && a1 == b2) return true;     return false;   }   int main() {     long long a1, a2, b1, b2;     while (~scanf( %lld%lld%lld%lld%lld%lld , &a1, &b1, &a2, &b2, &a3, &b3)) {       if (a3 == b3 && a3 == 0) {         puts(check(a1, b1, a2, b2) ?  YES  :  NO );       } else {         int ok = 0;         ok += check(a1, b1, a2, b2);         ok += check1(a1, b1, a2, b2);         ok += check1(a1, b1, b2, -a2);         ok += check1(a1, b1, -a2, -b2);         ok += check1(a1, b1, -b2, a2);         ok += check2(a1, b1, a2, b2);         ok += check2(a1, b1, b2, -a2);         ok += check2(a1, b1, -a2, -b2);         ok += check2(a1, b1, -b2, a2);         puts(ok ?  YES  :  NO );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3fll;   template <bool directed>   struct Euler {     int N;     vector<vector<pair<int, int>>> adj;     vector<vector<pair<int, int>>::iterator> its;     vector<bool> used;     Euler(int N_) : N(N_), adj(N), its(N) {}     void ae(int a, int b) {       int M = used.size();       used.push_back(0);       adj[a].emplace_back(b, M);       if (!directed) adj[b].emplace_back(a, M);     }     vector<pair<int, int>> solve(int src = 0) {       while (!adj[src].size()) src++;       for (int i = 0; i < N; i++) its[i] = begin(adj[i]);       vector<pair<pair<int, int>, int>> ret, second = {{{src, -1}, -1}};       while (second.size()) {         int x = second.back().first.first;         auto &it = its[x], en = end(adj[x]);         while (it != en && used[it->second]) it++;         if (it == en) {           if (ret.size() && ret.back().first.second != x) return {};           ret.push_back(second.back()), second.pop_back();         } else {           second.push_back({{it->first, x}, it->second});           used[it->second] = 1;         }       }       if (ret.size() != used.size() + 1) return {};       vector<pair<int, int>> ans;       for (auto& t : ret) ans.push_back({t.first.first, t.second});       reverse(ans.begin(), ans.end());       return ans;     }   };   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int N;     cin >> N;     vector<pair<int, int>> v(N);     for (auto& i : v) cin >> i.first >> i.second;     for (int i = 20; i >= 0; i--) {       Euler<false> E(1 << i);       for (auto [l, r] : v) E.ae(l & ((1 << i) - 1), r & ((1 << i) - 1));       auto ans = E.solve();       if (!ans.size()) continue;       if (ans[0].first != ans.back().first) continue;       ans.erase(ans.begin());       cout << i <<   n ;       for (auto [j, id] : ans) {         int a = 2 * id + 1, b = 2 * id + 2;         if ((v[id].first & ((1 << i) - 1)) == j) swap(a, b);         cout << a <<     << b <<    ;       }       cout <<   n ;       break;     }     exit(0);   }
#include <bits/stdc++.h>   using namespace std;   const int mxN = 1e3 + 1;   int n, d[mxN], k;   vector<int> adj[mxN];   vector<string> a[mxN];   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> k;     for (int i = 0, c; i < n; i++) {       cin >> c;       string s1;       for (int j = 0; j < k; j++) {         cin >> s1;         a[c].push_back(s1);       }     }     vector<string> s;     for (int i = 0; i < n; i++)       for (int j = 0; j < k; j++) s.push_back(a[i][j]);     n *= k;     vector<bool> ok(26);     int al = 0;     for (string x : s)       for (char c : x) {         if (!ok[c -  a ]) ++al, ok[c -  a ] = 1;       }     for (int i = 1; i < n; i++) {       int n1 = s[i - 1].size(), n2 = s[i].size(), i1 = 0;       for (; i1 < n1 || i1 < n2; i1++) {         if (i1 >= n2 && i1 < n1) {           cout <<  IMPOSSIBLE ;           return 0;         } else if (i1 >= n1 || i1 >= n2)           break;         if (s[i - 1][i1] == s[i][i1]) continue;         adj[s[i - 1][i1] -  a ].push_back(s[i][i1] -  a );         d[s[i][i1] -  a ]++;         break;       }     }     queue<int> qu;     string ans;     for (int i = 0; i < 26; i++)       if (!d[i] && ok[i]) qu.push(i);     while (qu.size()) {       int u = qu.front();       qu.pop();       for (int x : adj[u]) {         --d[x];         if (!d[x]) qu.push(x);       }       ans += (u +  a );     }     cout << (ans.size() == al ? ans :  IMPOSSIBLE );   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   clock_t clk = clock();   long long int i, j, k;   void solve(void);   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     int t = 1;     while (t--) solve();     return 0;   }   void solve() {     long long int n, m;     cin >> n >> m;     bool rev = 0;     for (i = 1; i <= (n + 1) / 2; ++i) {       for (j = 1; j <= m; ++j)         if (!rev) {           if (n + 1 != 2 * i) {             cout << i <<     << j <<   n ;             cout << n + 1 - i <<     << m + 1 - j <<   n ;           } else if (j & 1)             cout << i <<     << (j - 1) / 2 + 1 <<   n ;           else             cout << i <<     << m - j / 2 + 1 <<   n ;         } else {           if (n + 1 != 2 * i) {             cout << i <<     << m + 1 - j <<   n ;             cout << n + 1 - i <<     << j <<   n ;           } else if (j & 1)             cout << i <<     << m - (j - 1) / 2 <<   n ;           else             cout << i <<     << j / 2 <<   n ;         }       rev ^= 1;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     vector<set<string> > N, F;     vector<pair<string, string> > ans;     set<string> p;     for (int i = 0; i < 26; ++i) {       N.push_back(p);       F.push_back(p);     }     int n, k, c;     cin >> n;     c = (int) A ;     string s;     for (int i = 0; i < n; ++i) {       cin >> s;       k = (int)s[0];       N[k - c].insert(s);     }     for (int i = 0; i < n; ++i) {       cin >> s;       k = (int)s[0];       F[k - c].insert(s);     }     queue<string> qN, qF;     set<string>::iterator el, el1;     for (int i = 0; i < 26; ++i) {       if (N[i].size() <= F[i].size()) {         while (N[i].size() < F[i].size() && !qN.empty()) {           el = F[i].begin();           ans.push_back(make_pair(qN.front(), *el));           F[i].erase(el);           qN.pop();         }         while (!N[i].empty()) {           el = F[i].begin();           el1 = N[i].begin();           ans.push_back(make_pair(*el1, *el));           F[i].erase(el);           N[i].erase(el1);         }         while (!F[i].empty()) {           el = F[i].begin();           qF.push(*el);           F[i].erase(el);         }       } else {         while (F[i].size() < N[i].size() && !qF.empty()) {           el = N[i].begin();           ans.push_back(make_pair(*el, qF.front()));           N[i].erase(el);           qF.pop();         }         while (!F[i].empty()) {           el = F[i].begin();           el1 = N[i].begin();           ans.push_back(make_pair(*el1, *el));           F[i].erase(el);           N[i].erase(el1);         }         while (!N[i].empty()) {           el = N[i].begin();           qN.push(*el);           N[i].erase(el);         }       }     }     sort(ans.begin(), ans.end());     int i;     for (i = 0; i < ans.size() - 1; ++i)       cout << ans[i].first <<     << ans[i].second <<  ,  ;     cout << ans[i].first <<     << ans[i].second;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long double PI = 4 * atan((long double)1);   const long long INF = 1e18;   const long long NINF = -1e18;   long long get_hash(string s) {     long long N = 1000001;     long long base[N], A = 11, MD = 1110111110111;     base[0] = 1;     for (long long i = (1); i < (N); ++i) base[i] = (base[i - 1] * A) % MD;     long long hs = 0;     for (long long i = (0); i < (s.size()); ++i) {       hs += (s[i] * base[i]);       hs %= MD;     }     return hs;   }   long long power(long long a, long long n) {     long long res = 1;     while (n) {       if (n % 2) res *= a;       a *= a;       n /= 2;     }     return res;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n;     cin >> n;     long long k = 1, m = 2;     while (k != n + 1) {       long long p = (k + 1) * k;       long long u = k + 1;       long long v = (k + 1) * (k + 1) * k;       cout << v - (m) / k <<   n ;       m = p;       k++;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 505;   char g[N][N];   int id[N][N];   int cnt = 1;   int dx[] = {0, 0, 1, -1};   int dy[] = {1, -1, 0, 0};   int amt[N * N];   int sz[N * N];   int sum;   int n, k;   void dfs(int i, int j, int idx) {     if (g[i][j] ==  X  or id[i][j]) return;     id[i][j] = idx;     sz[idx]++;     for (int k = 0; k < 4; k++) dfs(i + dx[k], j + dy[k], idx);   }   void add(int c, int l, int r, bool row, bool in, bool rem = false) {     for (int i = l; i <= r; i++) {       int idx;       if (row)         idx = id[c][i];       else         idx = id[i][c];       if (idx == 0) {         if (in) sum = sum + !rem - rem;       } else {         amt[idx] = amt[idx] + !rem - rem;         if (amt[idx] == 1 and !rem) sum += sz[idx];         if (amt[idx] == 0 and rem) sum -= sz[idx];       }     }   }   void addEnv(int i, int j, bool rem = false) {     add(i - 1, j, j + k - 1, true, false, rem);     add(i + k, j, j + k - 1, true, false, rem);     add(j - 1, i, i + k - 1, false, false, rem);     add(j + k, i, i + k - 1, false, false, rem);   }   int main() {     cin >> n >> k;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) cin >> g[i][j];     for (int i = 0; i <= n + 1; i++)       g[i][0] =  X , g[i][n + 1] =  X , g[0][i] =  X , g[n + 1][i] =  X ;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         if (!id[i][j] and g[i][j] !=  X ) dfs(i, j, cnt++);     add(0, 1, k, true, false, false);     add(k + 1, 1, k, true, false, false);     add(0, 1, k, false, false, false);     add(k + 1, 1, k, false, false, false);     for (int i = 1; i <= k; i++) add(i, 1, k, true, true, false);     int ans = sum;     int dir = 1;     for (int i = 1; i <= n - k + 1;) {       int lim = n - k + 1, bg = 1;       int j;       if (dir == -1) swap(lim, bg);       for (j = bg; j != lim;) {         addEnv(i, j, true);         if (dir == 1)           add(j, i, i + k - 1, false, true, true),               add(j + k, i, i + k - 1, false, true, false);         else           add(j + k - 1, i, i + k - 1, false, true, true),               add(j - 1, i, i + k - 1, false, true, false);         j += dir;         addEnv(i, j, false);         ans = max(ans, sum);       }       if (i == n - k + 1) break;       addEnv(i, j, true);       add(i, j, j + k - 1, true, true, true),           add(i + k, j, j + k - 1, true, true, false);       i++;       dir = -dir;       addEnv(i, j, false);       ans = max(ans, sum);     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   struct pair_hash {     template <class T1, class T2>     size_t operator()(pair<T1, T2> const &pair) const {       size_t h1 = std::hash<T1>()(pair.first);       size_t h2 = std::hash<T2>()(pair.second);       return h1 ^ h2;     }   };   unordered_set<pair<int, int>, pair_hash> segmentos;   int main() {     int n, m;     scanf( %d %d , &n, &m);     vector<pair<int, int> > a(m);     for (int i = 0; i < m; i++) {       cin >> a[i].first >> a[i].second;       segmentos.insert({a[i].first, a[i].second});     }     for (int i = 1; i < n; i++) {       if (n % i) continue;       bool solved = true;       for (int j = 0; j < m && solved; j++) {         int optA = a[j].first;         int optB = a[j].second;         optA = (a[j].first + i > n ? 1 : 0) + (a[j].first + i) % (n + 1);         optB = (a[j].second + i > n ? 1 : 0) + (a[j].second + i) % (n + 1);         if (segmentos.find({optA, optB}) == segmentos.end() &&             segmentos.find({optB, optA}) == segmentos.end()) {           solved = false;         }       }       if (solved) {         printf( Yes );         exit(0);       }     }     printf( No );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int p, first, cnts, cntw, S, W;   int solve(long long picked) {     int cap1 = p, cap2 = first, cnt1 = cnts, cnt2 = cntw;     long long temp = picked;     cap1 -= (picked * S);     cnt1 -= picked;     if (cap1 >= W) {       temp += min(cap1 / W, cnt2);       cnt2 -= min(cap1 / W, cnt2);     }     if (S <= W) {       temp += min(cap2 / S, cnt1);       cap2 -= (min(cap2 / S, cnt1) * S);       temp += min(cap2 / W, cnt2);     } else {       temp += min(cap2 / W, cnt2);       cap2 -= (min(cap2 / W, cnt2) * W);       temp += min(cap2 / S, cnt1);     }     return temp;   }   int main() {     int t;     scanf( %d , &t);     while (t--) {       scanf( %d %d , &p, &first);       scanf( %d %d , &cnts, &cntw);       scanf( %d %d , &S, &W);       long long ans = 0, temp;       for (int pickedS = 0; pickedS <= min(cnts, p / S); pickedS++) {         temp = solve(pickedS);         ans = max(ans, temp);       }       printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     long long a, b, x, y, i, k, j, t, n, s;     cin >> t;     while (t--) {       cin >> n >> k;       if (n % 2 == 0) {         s = n + (k * 2);         cout << s << endl;       } else {         s = (k - 1) * 2;         a = 0;         for (i = 3; i * i <= n; i += 2) {           if (n % i == 0) {             a = i;             break;           }         }         if (a == 0) a = n;         s = a + n + s;         cout << s << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long p, k;     cin >> p >> k;     long long d = (k - p) / k;     if ((((k - p) % k) + k) % k == 0 || (d <= 0 && p > k)) d--;     vector<long long> res;     res.push_back(d);     if (k > p) return cout <<  1 n  << p, 0;     while (1) {       long long r = res.back();       d = (k - r) / k;       if ((((k - r) % k) + k) % k == 0 || d <= 0) d--;       res.push_back(d);       if (d < k && d >= 0) break;     }     cout << res.size() + 1 << endl;     long long last = p;     for (int i = 0; i < res.size(); i++) {       cout << k * res[i] + last <<    ;       last = res[i];     }     cout << d;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int x = 1;     while (n > 0) {       if (n == 3) {         cout << x <<     << x <<     << 3 * x <<    ;         break;       } else {         for (int i = 0; i < (n + 1) / 2; i++) {           cout << x <<    ;         }         x *= 2;         n = n - (n + 1) / 2;       }     }     cout << endl;     return 0;   }