malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, m, q;   int arr[26];   string s;   long long dp[1001][1001];   int mn = 1 << 20, mx = 0;   long long solve(int idx, int sz, int mn) {     if (sz > mn) return 0;     mx = max(mx, sz);     if (idx == n) return 1;     if (dp[idx][sz] != -1) return dp[idx][sz] % 1000000007;     if (sz < mn) {       long long a = solve(idx + 1, 1, arr[s[idx] -  a ]);       return dp[idx][sz] =                  (a + solve(idx + 1, sz + 1, min(mn, arr[s[idx] -  a ]))) %                  1000000007;     } else       return dp[idx][sz] = solve(idx + 1, 1, arr[s[idx] -  a ]) % 1000000007;   }   long long solve2(int idx, int sz, int mn) {     if (sz > mn) return 1 << 20;     if (idx == n) {       return 0;     }     if (dp[idx][sz] != -1) return dp[idx][sz];     if (sz < mn) {       long long a = solve2(idx + 1, 1, arr[s[idx] -  a ]) + 1;       return dp[idx][sz] =                  min(a, solve2(idx + 1, sz + 1, min(mn, arr[s[idx] -  a ])));     } else       return dp[idx][sz] = solve2(idx + 1, 1, arr[s[idx] -  a ]) + 1;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     memset(dp, -1, sizeof dp);     cin >> n;     cin >> s;     for (int i = 0; i < 26; i++) {       cin >> arr[i];     }     cout << solve(1, 1, arr[s[0] -  a ]) % 1000000007 << endl;     ;     cout << mx << endl;     memset(dp, -1, sizeof dp);     cout << solve2(1, 1, arr[s[0] -  a ]) + 1 << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k;   string a[12];   int b[12], vis[40];   vector<string> v;   void solve(int i, int rem) {     if (i == k + 1) {       if (rem == 0) {         string s =   ;         for (int j = 1; j <= k; j++) {           if (vis[j])             s += a[0][j];           else             s += (a[0][j] ==  0  ?  1  :  0 );         }         v.push_back(s);       }       return;     }     if (rem > 0) {       vis[i] = 1;       solve(i + 1, rem - 1);       vis[i] = 0;     }     if (k - i + 1 > rem) solve(i + 1, rem);   }   bool ok(string s) {     for (int i = 0; i < m; i++) {       int k = 0;       for (int j = 0; j < n; j++) {         if (s[j] == a[i][j]) k++;       }       if (k != b[i]) {         return 0;       }     }     return 1;   }   int main() {     cin >> n >> m;     for (int i = 0; i < m; i++) cin >> a[i] >> b[i];     k = b[0];     string g = a[0];     a[0] =  x  + a[0];     swap(k, n);     solve(1, n);     swap(k, n);     int ans = 0;     a[0] = g;     for (auto s : v) {       if (ok(s)) ans++;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = (int)1e9 + 7;   void MAIN();   int main() {     MAIN();     return 0;   }   const int N = (int)1e5 + 32;   char s[N];   int n;   void MAIN() {     scanf( %d , &n);     scanf( %s , s);     vector<int> cnt(26, 0);     for (int i = 0; i < int(n); i++) cnt[s[i] -  A ]++;     int ma = 0, nma = 0;     for (int i = 0; i < int(26); i++) {       if (cnt[i] > ma) {         ma = cnt[i];         nma = 1;       } else if (cnt[i] == ma)         nma++;     }     int res = 1;     for (int i = 0; i < int(n); i++) res = 1LL * res * nma % MOD;     printf( %d n , res);   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int n, x, i, j;     cin >> n >> x;     long long int mm = 0;     long long int mx = 0;     for (i = 0; i < n; i++) {       long long int a, b;       cin >> a >> b;       mm = max(mm, a - b);       mx = max(mx, a);     }     if (x <= mx) {       cout <<  1 n ;       return;     }     if (mm <= 0) {       cout <<  -1 n ;       return;     }     long long int p = x - mx;     long long int q = p / mm;     if (p % mm != 0) {       q++;     }     x -= (q * mm);     if (x > 0) {       q++;     }     cout << q <<   n ;   }   int main() {     ios_base ::sync_with_stdio(0);     cin.tie(NULL);     int t;     cin >> t;     while (t > 0) {       t--;       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5010 + 10;   const int mod = 1e9 + 7;   char s[N];   char t[N];   int d[N][N];   int main() {     int n, m;     cin >> n >> m;     scanf( %s%s , s + 1, t + 1);     int ans = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         d[i][j] = max(d[i - 1][j], d[i][j - 1]) - 1;         if (s[i] == t[j]) {           d[i][j] = d[i - 1][j - 1] + 2;           d[i][j] = max(d[i][j], 2);         }         ans = max(ans, d[i][j]);       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long n, k;     cin >> n >> k;     long long ans[6][3] = {0, 1, 2, 1, 0, 2, 1, 2, 0, 2, 1, 0, 2, 0, 1, 0, 2, 1};     cout << ans[n % 6][k] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char str[10000 + 1];   int M;   char tmp[10000 + 1];   int main() {     scanf( %s , str);     scanf( %d , &M);     for (int t = 0; t < M; t++) {       int l, r, k;       scanf( %d %d %d , &l, &r, &k);       int s_len = (r - l + 1);       k = k % s_len;       --l, --r;       for (int i = s_len - 1; i >= 0; i--) {         int d = (i - k);         if (d < 0) {           tmp[i] = str[l + d + s_len];         } else {           tmp[i] = str[l + d];         }       }       for (int i = l; i <= r; i++) {         str[i] = tmp[i - l];       }     }     printf( %s n , str);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, h, t, r, x, y, dis[210][210], h1[210], t1[210], h2[210], t2[210],       bfs[210 * 210][2], L, R;   void renew(int x, int y, int v) {     if (x + y > r) return;     if (dis[x][y] == -1) {       dis[x][y] = v;       bfs[++R][0] = x;       bfs[R][1] = y;     }   }   int dfs(int x, int y) {     if (x + y > r) return 0;     int i, p = 1;     if (dis[x][y] == -1) {       printf( Draw n );       exit(0);     }     if (dis[x][y]) return dis[x][y];     dis[x][y] = -1;     for (i = 1; i <= n && i <= x; ++i)       p = max(p, dfs(x - i + h1[i], y + t1[i]) + 1);     for (i = 1; i <= m && i <= y; ++i)       p = max(p, dfs(x + h2[i], y - i + t2[i]) + 1);     dis[x][y] = p;     return p;   }   int main() {     int i;     scanf( %d%d%d , &h, &t, &r);     scanf( %d , &n);     for (i = 1; i <= n; ++i) scanf( %d%d , &h1[i], &t1[i]);     scanf( %d , &m);     for (i = 1; i <= m; ++i) scanf( %d%d , &h2[i], &t2[i]);     memset(dis, -1, sizeof(dis));     dis[h][t] = 0;     bfs[L = R = 1][0] = h;     bfs[1][1] = t;     while (L <= R) {       x = bfs[L][0];       y = bfs[L++][1];       for (i = 1; i <= n && i <= x; ++i)         renew(x - i + h1[i], y + t1[i], dis[x][y] + 1);       for (i = 1; i <= m && i <= y; ++i)         renew(x + h2[i], y - i + t2[i], dis[x][y] + 1);     }     if (dis[0][0] != -1) return printf( Ivan n%d n , dis[0][0]), 0;     memset(dis, 0, sizeof(dis));     printf( Zmey n%d n , dfs(h, t));   }
#include <bits/stdc++.h>   using namespace std;   const int maxN = 200011;   long long n, i, j, cntx, cnty, x, y, z;   long long vx[maxN];   map<long long, long long> Mx, My;   map<pair<long long, long long>, long long> M;   pair<long long, pair<long long, long long> > low;   vector<vector<long long> > data;   vector<long long> le, ri;   vector<long long> vals;   long long gcd(long long a, long long b) {     if (a < b) swap(a, b);     while (b > 0) {       a %= b;       swap(a, b);     }     return a;   }   bool check_rat() {     int i, j;     for (i = 1; i + 1 <= cntx; i++) {       for (j = 1; j + 1 <= cnty; j++) {         if (data[i][j] * data[i + 1][j + 1] != data[i + 1][j] * data[i][j + 1])           return false;       }     }     return true;   }   void check(long long d) {     long long i, j;     le[low.second.first] = d;     for (i = 1; i <= cnty; i++) {       if (data[low.second.first][i] % d) return;       ri[i] = data[low.second.first][i] / d;     }     for (i = 1; i <= cntx; i++) {       if (data[i][1] % ri[1]) return;       le[i] = data[i][1] / ri[1];     }     long long aux = 0;     for (i = 1; i <= cntx; i++) aux += le[i] * vx[i];     vals.push_back(aux);   }   int main() {     low = make_pair(1LL << 60, make_pair(0, 0));     scanf( %lld , &n);     for (i = 1; i <= n; i++) {       scanf( %lld%lld%lld , &x, &y, &z);       if (Mx[x] == 0) Mx[x] = ++cntx, vx[cntx] = x;       if (My[y] == 0) My[y] = ++cnty;       M[make_pair(Mx[x], My[y])] = z;       low = min(low, make_pair(z, make_pair(Mx[x], My[y])));     }     if (cntx * cnty != n) {       printf( 0 );       return 0;     }     le.resize(cntx + 1);     ri.resize(cnty + 1);     data = vector<vector<long long> >(cntx + 1, vector<long long>(cnty + 1, 0));     for (i = 1; i <= cntx; i++)       for (j = 1; j <= cnty; j++) data[i][j] = M[make_pair(i, j)];     if (!check_rat()) {       printf( 0 );       return 0;     }     for (i = 1; i <= cnty; i++)       low.first = gcd(low.first, data[low.second.first][i]);     for (long long d = 1; d * d <= low.first; d++) {       if (low.first % d) continue;       check(d);       if (d * d != low.first) check(low.first / d);     }     sort(vals.begin(), vals.end());     vals.resize(unique(vals.begin(), vals.end()) - vals.begin());     printf( %d , vals.size());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k, mod = 1000000007;   bool ok[1005];   char a[1005], b[1005];   int cnt[2][1005], tp, tn;   int solve() {     scanf( %s , a);     scanf( %s , b);     n = strlen(a);     scanf( %d , &k);     int cg = 0;     for (int i = 0; i < n; i++) {       ok[i] = true;       for (int j = 0; j < n && ok[i]; j++)         if (a[j] != b[(i + j) % n]) ok[i] = false;       cg += ok[i];     }     if (!cg) return 0;     cnt[1][0] = 1;     tp = 1;     for (int s = 0; s < k; s++) {       tn = 0;       int p = (s + 1) % 2, c = s % 2;       for (int i = 0; i < n; i++) {         cnt[c][i] = (tp + mod - cnt[p][i]) % mod;         tn = (tn + cnt[c][i]) % mod;       }       tp = tn;     }     int re = 0;     for (int i = 0; i < n; i++)       if (ok[i]) {         re = (re + cnt[(k + 1) % 2][i]) % mod;       }     return re;   }   int main() { printf( %d n , solve()); }
#include <bits/stdc++.h>   using namespace std;   const int NMAX = 1e5;   int v[NMAX + 5], ans[NMAX + 5];   inline void GenerateAnswer(int n) {     int i, state = 1, st = 1, dr = n, dim = 0;     sort(v + 1, v + n + 1);     while (st <= dr) {       if (st != dr) {         if (state == 1)           ans[++dim] = v[st], ans[++dim] = v[dr];         else           ans[++dim] = v[dr], ans[++dim] = v[st];       } else         ans[++dim] = v[st];       ++st;       --dr;     }   }   int main() {     int t, n, i, j;     scanf( %d , &t);     for (j = 1; j <= t; ++j) {       scanf( %d , &n);       for (i = 1; i <= n; ++i) scanf( %d , &v[i]);       GenerateAnswer(n);       for (i = n; i >= 1; --i) printf( %d  , ans[i]);       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     string s;     cin >> s;     if (s[0] ==  @  || s.back() ==  @  || (s.find( @ ) == -1)) {       cout <<  No solution ;       return 0;     }     vector<int> v;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  @ ) v.push_back(i);     }     for (int i = 1; i < v.size(); i++) {       if (v[i] - v[i - 1] < 3) {         cout <<  No solution ;         return 0;       }     }     int pre = 0;     for (int i = 0; i < v.size(); i++) {       for (int j = pre; j <= v[i] + 1; j++) {         cout << s[j];       }       if (i + 1 != v.size()) cout <<  , ;       pre = v[i] + 2;     }     for (int i = pre; i < s.size(); i++) cout << s[i];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 4010;   int N;   long long V[MAXN], D[MAXN], P[MAXN];   set<int> st;   int main() {     if (fopen( input.txt ,  r )) {       freopen( input.txt ,  r , stdin);     }     ios::sync_with_stdio(false);     cin >> N;     for (int i = 1; i <= N; i++) {       cin >> V[i] >> D[i] >> P[i];       st.insert(i);     }     vector<int> ans;     while (!st.empty()) {       int b = *st.begin();       ans.push_back(b);       st.erase(st.begin());       long long val = V[b];       for (int i : st) {         P[i] -= val;         val--;         if (val == 0) {           break;         }       }       for (auto it = st.begin(); it != st.end();) {         int i = *it;         if (P[i] >= 0) {           it++;           continue;         }         st.erase(it++);         for (auto jt = it; jt != st.end(); jt++) {           P[*jt] -= D[i];         }       }     }     cout << ans.size() << endl;     for (int i : ans) {       cout << i <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e7 + 10;   const int INF = 0x3f3f3f3f;   const double EPS = 1e-10;   inline int read() {     int ret = 0, f = 0;     char ch = getchar();     while (ch >  9  || ch <  0 ) f ^= ch ==  - , ch = getchar();     while (ch <=  9  && ch >=  0 ) ret = ret * 10 + ch -  0 , ch = getchar();     return f ? -ret : ret;   }   int n, m;   char s[1005];   int main() {     scanf( %d%d , &n, &m);     int x = 0, y = 0;     int cnt = 0;     for (int i = 1; i <= n; i++) {       scanf( %s , s + 1);       for (int j = 1; j <= m; j++)         if (s[j] ==  B ) cnt++, x += i, y += j;     }     x /= cnt;     y /= cnt;     printf( %d %d n , x, y);     return 0;   }
#include <bits/stdc++.h>   const int N = 1000001;   using namespace std;   vector<int> a[N];   bool st[N], vis1[N];   void f(int u) {     st[u] = true;     vis1[u] = true;     for (int v : a[u]) {       if (st[v]) {         cout <<  Draw ;         exit(0);       }       if (!vis1[v]) {         f(v);       }     }     st[u] = false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, m;     cin >> n >> m;     for (int i = 1; i < n + 1; i++) {       int x, v;       cin >> x;       while (x--) {         cin >> v;         a[i].push_back(v);       }     }     int x;     cin >> x;     queue<pair<int, int>> q;     bool vis[n + 1][2];     int par[n + 1][2];     memset(vis, false, sizeof vis);     q.push(make_pair(x, 0));     vis[x][0] = true;     while (!q.empty()) {       auto f = q.front();       q.pop();       if (a[f.first].empty() && f.second) {         cout <<  Win n ;         vector<int> ans;         int v = f.first, typ = f.second;         while (v != x || typ) {           ans.push_back(v);           v = par[v][typ];           typ = 1 - typ;         }         cout << x <<    ;         for (int i = (int)ans.size() - 1; i >= 0; i--) cout << ans[i] <<    ;         return 0;       }       for (int v : a[f.first]) {         if (!vis[v][1 - f.second]) {           vis[v][1 - f.second] = true;           q.push(make_pair(v, 1 - f.second));           par[v][1 - f.second] = f.first;         }       }     }     memset(st, false, sizeof st);     memset(vis1, false, sizeof vis1);     f(x);     cout <<  Lose ;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k;   bool a[2501][2501];   int sum[2501][2501];   long long ans = 0;   int get(int x1, int x2, int y1, int y2) {     return sum[x2][y2] - sum[x1 - 1][y2] - sum[x2][y1 - 1] + sum[x1 - 1][y1 - 1];   }   void solve(int x1, int y1, int x2, int y2) {     if (x1 == x2 && y1 == y2) {       ans += a[x1][y1] == k;       return;     }     if (y2 - y1 > x2 - x1) {       int yy = (y2 + y1) >> 1;       for (int c = 0; c <= k; c++) {         int c1 = c, c2 = k - c;         for (int i = x1; i <= x2; i++) {           int l1 = y1, r1 = y1;           int l2 = y2, r2 = y2;           for (int j = i; j <= x2; j++) {             while (l1 <= yy && get(i, j, l1, yy) >= c1) l1++;             while (r1 <= yy && get(i, j, r1, yy) > c1) r1++;             if (r1 > yy) break;             while (l2 > yy && get(i, j, yy + 1, l2) >= c2) l2--;             while (r2 > yy && get(i, j, yy + 1, r2) > c2) r2--;             if (r2 <= yy) break;             long long w1 = 0, w2 = 0;             if (get(i, j, r1, yy) == c1) w1 = l1 - r1;             if (get(i, j, yy + 1, r2) == c2) w2 = r2 - l2;             ans += w1 * w2;           }         }       }       solve(x1, y1, x2, yy);       solve(x1, yy + 1, x2, y2);     } else {       int xx = (x1 + x2) >> 1;       for (int c = 0; c <= k; c++) {         int c1 = c, c2 = k - c;         for (int i = y1; i <= y2; i++) {           int l1 = x1, r1 = x1;           int l2 = x2, r2 = x2;           for (int j = i; j <= y2; j++) {             while (l1 <= xx && get(l1, xx, i, j) >= c1) l1++;             while (r1 <= xx && get(r1, xx, i, j) > c1) r1++;             if (r1 > xx) break;             while (l2 > xx && get(xx + 1, l2, i, j) >= c2) l2--;             while (r2 > xx && get(xx + 1, r2, i, j) > c2) r2--;             if (r2 <= xx) break;             long long w1 = 0, w2 = 0;             if (get(r1, xx, i, j) == c1) w1 = l1 - r1;             if (get(xx + 1, r2, i, j) == c2) w2 = r2 - l2;             ans += w1 * w2;           }         }       }       solve(x1, y1, xx, y2);       solve(xx + 1, y1, x2, y2);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         char c;         cin >> c;         a[i][j] = c -  0 ;         sum[i][j] = a[i][j] + sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];       }     }     solve(1, 1, n, m);     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   int mod(int x, int m) {     if (x < 0) x += m;     return x % m;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> v(n);       int mx = -1;       for (int i = 0; i < n; ++i) {         cin >> v[i];         mx = max(v[i], mx);       }       int ans = -1;       for (int i = 0; i < n; ++i) {         if (v[i] == mx) {           if (i != 0 && v[i - 1] < v[i]) {             ans = i;             break;           } else if (i != (n - 1) && v[i] > v[i + 1]) {             ans = i;             break;           }         }       }       cout << ans + (ans != -1) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline char gc() {     static char now[1 << 16], *S, *T;     if (T == S) {       T = (S = now) + fread(now, 1, 1 << 16, stdin);       if (T == S) return EOF;     }     return *S++;   }   inline long long read() {     register long long x = 0, f = 1;     char ch = gc();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = gc();     }     while (isdigit(ch)) {       x = (x << 3) + (x << 1) + ch -  0 ;       ch = gc();     }     return (f == 1) ? x : -x;   }   long long a[1010101], b[1010101], m, n, ida[1010101], idb[1010101];   long long A[1010101], B[1010101], ans[1010101];   inline bool cmpa(long long i, long long j) { return a[i] < a[j]; }   inline bool cmpb(long long i, long long j) { return b[i] < b[j]; }   signed main() {     m = read(), n = read();     for (int i = 1; i <= n; i++) a[i] = read(), ida[i] = i;     for (int i = 1; i <= n; i++) b[i] = read(), idb[i] = i;     sort(ida + 1, ida + 1 + n, cmpa);     sort(idb + 1, idb + 1 + n, cmpb);     sort(a + 1, a + 1 + n);     sort(b + 1, b + 1 + n);     for (int i = 1; i <= n; i++) {       b[i + n] = b[i];       b[i + 2 * n] = b[i] + m;       b[i] -= m;     }     for (int i = 1, j = 0; i <= n; i++) {       for (; b[j + 1] <= a[i] && j + 1 <= 3 * n; j++)         ;       if (j - i + 1 >= 1) A[1] += a[i], A[j - i + 2] -= a[i];       if (j - i + 2 <= 2 * n + 1)         A[max(1, j - i + 2)] -= a[i], A[2 * n + 2] += a[i];     }     for (int j = 1, i = 0; j <= 3 * n; j++) {       for (; b[j] > a[i + 1] && i + 1 <= n; i++)         ;       if (j - i + 1 <= j) B[max(1, j - i + 1)] += b[j], B[j + 1] -= b[j];       if (max(1ll, j - n + 1) <= j - i + 1 && j - i + 1 > 0)         B[max(1ll, j - n + 1)] -= b[j], B[j - i + 1] += b[j];     }     for (int i = 1; i <= 2 * n + 1; i++) {       A[i] += A[i - 1];       B[i] += B[i - 1];     }     long long ansid = 0;     A[ansid] = B[ansid] = 99999999999999;     for (int i = 1; i <= 2 * n + 1; i++) {       if (A[ansid] + B[ansid] > A[i] + B[i]) ansid = i;     }     cout << A[ansid] + B[ansid] <<   n ;     for (int i = 1; i <= n; i++) {       ans[ida[i]] = idb[(ansid + i - 2) % n + 1];     }     for (int i = 1; i <= n; i++) {       printf( %lld  , ans[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     long long a[n];     for (int i = 0, ggdem = n; i < ggdem; ++i) cin >> a[i];     long long yo = -1;     for (int i = 0, ggdem = n; i < ggdem; ++i) {       if (a[i] == -1) {         yo = i;       }     }     for (int i = 0, ggdem = yo + 1; i < ggdem; ++i) {       a[i] = 0;     }     long long res = 0;     for (long long i = 20; i >= 0; i--) {       if ((1 << i) > n) continue;       long long mini = 1e18, minid = -1;       for (int j = (1 << i) - 1, ggdem = n; j < ggdem; ++j) {         if (a[j] <= mini) {           mini = a[j];           minid = j;         }       }       res += mini;       a[minid] = 1e18;     }     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve();   int main() {     int t = 1;     cin >> t;     while (t--) solve();     return 0;   }   int gcd(int a, int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   void solve() {     int n;     cin >> n;     vector<int> a(n);     int maxEle = -1;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] > maxEle) maxEle = a[i];     }     int gcdTillNow = maxEle;     for (int i = 0; i < n; i++) {       int currMaxGcd = -1, maxGcdPos = -1;       for (int j = i; j < n; j++) {         if (gcd(a[j], gcdTillNow) > currMaxGcd) {           currMaxGcd = gcd(a[j], gcdTillNow);           maxGcdPos = j;         }       }       swap(a[i], a[maxGcdPos]);       cout << a[i] <<    ;       gcdTillNow = currMaxGcd;     }     cout <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int sum = 0;     char c = getchar();     while (!isdigit(c)) c = getchar();     while (isdigit(c)) {       sum = (sum << 1) + (sum << 3) + (c ^ 48);       c = getchar();     }     return sum;   }   int n, k, a, m;   set<int> s;   set<int>::iterator it;   int main() {     n = read(), k = read(), a = read();     s.insert(0), s.insert(n + 1);     m = read();     int rest = (n + 1) / (a + 1);     if (rest < k) {       printf( 0 n );       return 0;     }     for (int i = 1; i <= m; i++) {       int x = read();       it = s.lower_bound(x);       int a1 = *it;       it--;       int a2 = *it;       int dist = a1 - a2 - 1, dist1 = x - a2 - 1, dist2 = a1 - x - 1;       int b = (dist + 1) / (a + 1), b1 = (dist1 + 1) / (a + 1),           b2 = (dist2 + 1) / (a + 1);       rest -= (b - (b1 + b2));       if (rest < k) {         printf( %d n , i);         return 0;       }       s.insert(x);     }     printf( -1 n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long int n;     cin >> n;     int flag = 0;     while (flag == 0 && n != 0) {       if ((n % 10) == 1)         n = n / 10;       else if ((n % 10) == 4) {         if (((n / 10) % 10) == 1)           n = n / 100;         else if (((n / 10) % 10) == 4) {           if (((n / 100) % 10) == 1)             n = n / 1000;           else             flag = 1;         } else           flag = 1;       } else         flag = 1;     }     if (flag == 1)       cout <<  NO ;     else       cout <<  YES ;     return 0;   }