malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, size = 1e6 + 1;     cin >> n;     vector<int> prime(1e6 + 1, 1);     prime[0] = 0;     prime[1] = 0;     for (int ri = 2; ri <= sqrt(size); ri++) {       if (prime[ri]) {         for (int pi = ri * ri; pi <= size; pi += ri)           if (prime[pi]) prime[pi] = 0;       }     }     vector<long long int> tprime;     for (long long int ri = 0; ri < size; ri++) {       if (prime[ri]) {         tprime.push_back(ri * ri);       }     }     long long int arr[n];     for (int ri = 0; ri < n; ri++) scanf( %lld , &arr[ri]);     for (int ri = 0; ri < n; ri++) {       bool val = binary_search(tprime.begin(), tprime.end(), arr[ri]);       if (val)         cout <<  YES n ;       else         cout <<  NO n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200010;   int a[maxn];   int main() {     int t;     cin >> t;     while (t--) {       string s;       cin >> s;       int m = s.length();       int fa = 0, fb = 0, fc = 0;       for (int i = 0; i < m; i++) {         if (s[i] ==  1  && fa == 0) fa = i + 1;         if (s[i] ==  2  && fb == 0) fb = i + 1;         if (s[i] ==  3  && fc == 0) fc = i + 1;       }       if (fa == 0 || fb == 0 || fc == 0) {         cout <<  0  << endl;         continue;       }       int x = max(fa, max(fb, fc));       int ans = x - min(fa, min(fb, fc)) + 1;       int sum = ans;       for (int i = 0; i < m; i++) {         if (s[i] ==  1 ) {           int u = min(fb, fc);           int v = max(fb, fc);           if (i + 1 >= v)             sum = i + 1 - u + 1;           else if (i + 1 <= u)             sum = v - i;           else             sum = v - u + 1;           ans = min(ans, sum);           fa = i + 1;         }         if (s[i] ==  2 ) {           int u = min(fa, fc);           int v = max(fa, fc);           if (i + 1 >= v)             sum = i + 1 - u + 1;           else if (i + 1 <= u)             sum = v - i;           else             sum = v - u + 1;           ans = min(ans, sum);           fb = i + 1;         }         if (s[i] ==  3 ) {           int u = min(fb, fa);           int v = max(fb, fa);           if (i + 1 >= v)             sum = i + 1 - u + 1;           else if (i + 1 <= u)             sum = v - i;           else             sum = v - u + 1;           ans = min(ans, sum);           fc = i + 1;         }       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MaxLg = 25, inf = 1e9 + 100;   int n;   bool flag;   vector<int> out, mins[2][MaxLg];   void output() {     if (flag)       cout << -1 <<   n ;     else       cout << out.size() <<   n ;     for (auto i : out) cout << i <<    ;     cout << endl;   }   void input(int a, int b) {     int tmp;     for (int i = 0; i < n; ++i) {       cin >> tmp;       mins[a][b].push_back(tmp);     }   }   void solve() {     for (int i = 0; i < n; ++i) out.push_back(inf);     for (int i = 0; (1 << i) <= n; ++i)       for (int j = 1; j <= n; ++j)         out[j - 1] = min(out[j - 1], mins[!(j & (1 << i))][i][j - 1]);     flag = true;   }   int main() {     cin >> n;     for (int k = 0; k < 2; ++k)       for (int i = 0; (1 << i) <= n; ++i) {         for (int j = 1; j <= n; ++j)           if ((j & (1 << i)) == k * (1 << i)) out.push_back(j);         output();         input(k, i);         out.clear();       }     solve();     output();     return 0;   }
#include <bits/stdc++.h>   const bool debugging = 1;   const long long mod = 1e9 + 7;   using namespace std;   template <class T>   ostream &operator<<(ostream &os, vector<T> V) {     for (auto v : V) {       os << v <<    ;     }     return os <<   ;   }   template <class T>   ostream &operator<<(ostream &os, vector<vector<T>> V) {     for (long long i = 0; i < V.size(); i++) {       for (long long j = 0; j < V[i].size(); j++) {         os << V[i][j] <<    ;       }       os <<   n ;     }     return os <<   ;   }   template <class T>   ostream &operator<<(ostream &os, set<T> S) {     for (auto s : S) {       os << s <<    ;     }     return os <<   ;   }   template <class L, class R>   ostream &operator<<(ostream &os, pair<L, R> P) {     return os << P.first <<     << P.second;   }   template <class L, class R>   ostream &operator<<(ostream &os, map<L, R> M) {     os <<   n ;     for (auto m : M) {       os << m <<   n ;     }     return os <<   ;   }   void solve() {     long long N;     cin >> N;     vector<long long> elements(N);     for (long long i = 0; i < N; i++) {       cin >> elements[i];     }     vector<long long> max_val(N);     long long contri_front = elements[0];     long long contri_end = 0;     long long index = N;     bool single = 1;     for (long long i = 0; i < N; i++) {       if (contri_front >= elements[i] && single) {         contri_front = elements[i];         elements[i] = 0;       } else {         single = 0;         long long need_from_end = elements[i] - contri_front;         if (need_from_end > elements[N - 1]) {           cout <<  NO                 <<   n ;           return;         }         if (need_from_end < contri_end) {           contri_front = elements[i] - contri_end;           if (contri_front < 0) {             cout <<  NO                   <<   n ;             return;           }         } else {           contri_end = need_from_end;         }       }     }     cout <<  YES           <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long no_of_testcases;     cin >> no_of_testcases;     while (no_of_testcases-- > 0) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   const double PI =       3.141592653589793238462643383279502884197169399375105820974944;   using namespace std;   const int MOD = 1e9 + 7;   double gcd(double a, double b) { return a < 0.01 ? b : gcd(fmod(b, a), a); }   template <typename T>   T mymax(T a, T b) {     return (a > b) ? a : b;   }   template <typename T>   T mymax(T a, T b, T c) {     return mymax(a, mymax(b, c));   }   template <typename T>   T mymin(T a, T b) {     return (a < b) ? a : b;   }   template <typename T>   T mymin(T a, T b, T c) {     return mymin(a, mymin(b, c));   }   template <typename T>   T power(T x, T y) {     T res = 1;     x = x % MOD;     while (y > 0) {       if (y & 1) res = (res * x) % MOD;       y = y >> 1;       x = (x * x) % MOD;     }     return res;   }   template <typename T>   void swap(T *x, T *y) {     T temp;     temp = *y;     *y = *x;     *x = temp;   }   template <typename T>   T mod(T a) {     if (a > 0)       return a;     else       return -a;   }   template <typename T>   T logg(T a) {     T x = 0;     while (a > 1) {       x++;       a /= 2;     }     return x;   }   typedef struct trie {     int a, b, c;     trie(int p1, int p2, int p3) { a = p1, b = p2, c = p3; }   } tri;   bool operator<(tri p, tri q) {     if (p.a < q.a) {       return 1;     } else if (p.a > q.a)       return 0;     else {       return (p.b < q.b);     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int n, k1;     cin >> n >> k1;     multiset<pair<int, int>> k;     vector<int> l(n), r(n);     vector<tri> p;     for (int i = 1; i <= n; i++) {       cin >> l[i - 1] >> r[i - 1];       p.push_back({l[i - 1], -1, i - 1});       p.push_back({r[i - 1], 1, i - 1});     }     int c = 0;     sort(p.begin(), p.end());     vector<int> ans;     for (tri p1 : p) {       int a1 = p1.a, b1 = p1.b, c1 = p1.c;       if (b1 == -1) {         k.insert({r[c1], c1});         c++;         if (c > k1) {           pair<int, int> pk = *k.rbegin();           k.erase(k.find(pk));           ans.push_back(pk.second);           c--;         }       } else {         if (k.count({r[c1], c1})) {           c--;           k.erase(k.find({r[c1], c1}));         }       }     }     cout << ans.size() <<   n ;     for (int pk : ans) {       cout << pk + 1 <<    ;     }     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x[5], y[5], i;     cin >> n;     for (i = 1; i <= n; i++) cin >> x[i] >> y[i];     if (n == 1)       cout << -1;     else if (n == 2) {       if (x[1] != x[2] && y[1] != y[2])         cout << abs(x[1] - x[2]) * abs(y[1] - y[2]);       else         cout << -1;     } else if (n == 3) {       if (x[1] == x[2] && y[1] == y[3])         cout << abs(y[2] - y[1]) * abs(x[3] - x[1]);       else if (x[1] == x[2] && y[2] == y[3])         cout << abs(y[2] - y[1]) * abs(x[3] - x[2]);       else if (x[2] == x[3] && y[2] == y[1])         cout << abs(y[2] - y[3]) * abs(x[2] - x[1]);       else if (x[2] == x[3] && y[3] == y[1])         cout << abs(y[2] - y[3]) * abs(x[3] - x[1]);       else if (x[1] == x[3] && y[2] == y[1])         cout << abs(y[1] - y[3]) * abs(x[2] - x[1]);       else if (x[1] == x[3] && y[3] == y[2])         cout << abs(y[1] - y[3]) * abs(x[3] - x[2]);     } else if (n == 4) {       int x1 = 10000, x2 = -10000, y1 = 10000, y2 = -10000;       for (i = 1; i <= 4; i++) {         if (x[i] < x1) x1 = x[i];         if (x[i] > x2) x2 = x[i];         if (y[i] < y1) y1 = y[i];         if (y[i] > y2) y2 = y[i];       }       cout << (x2 - x1) * (y2 - y1);     }   }
#include<iostream>   using namespace std;   int main()   {       int t;       cin>>t;       while(t--)       {         int Xa,Ya,Xb,Yb,Xf,Yf,sum;        cin>>Xa>>Ya>>Xb>>Yb>>Xf>>Yf;        sum=abs(Xa-Xb)+abs(Ya-Yb);        if(Xa==Xb&&Xb==Xf)           {             if(Ya<Yf&&Yb>Yf||Ya>Yf&&Yb<Yf)               sum+=2;           }       if(Ya==Yb&&Yb==Yf)       {           if(Xa<Xf&&Xb>Xf||Xa>Xf&&Xb<Xf)           sum+=2;       }        cout<<sum<<endl;       }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, i, teo = 0, s = 0, a[100001], t[100001];     cin >> n >> k;     for (i = 1; i <= n; i++) cin >> a[i];     for (i = 1; i <= n; i++) {       cin >> t[i];       if (t[i] == 1) {         teo = teo + a[i];         a[i] = 0;       }       a[i] = a[i] + a[i - 1];     }     for (i = k; i <= n; i++) s = max(s, a[i] - a[i - k]);     cout << teo + s;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /stack:640000000 )   using namespace std;   const double EPS = 1e-9;   const int INF = 0x7f7f7f7f;   const double PI = acos(-1.0);   template <class T>   inline T gcd(T a, T b) {     return (b) == 0 ? (a) : gcd((b), ((a) % (b)));   }   template <class T>   inline T lcm(T a, T b) {     return ((a) / gcd((a), (b)) * (b));   }   template <typename T>   string NumberToString(T Number) {     ostringstream second;     second << Number;     return second.str();   }   struct debugger {     template <typename T>     debugger& operator,(const T& v) {       cerr << v <<    ;       return *this;     }   } dbg;   int t, n, m;   string s;   int main() {     while (~scanf( %d%d , &n, &m)) {       long long k;       scanf( %lld , &k);       if (k < n) {         printf( %lld 1 n , k + 1);         continue;       }       k -= (n - 1);       int row = k / (m - 1);       if (k % (m - 1) == 0) row--;       int col = k % (m - 1);       if (k % (m - 1) == 0) col = m - 1;       int odd = row % 2;       row = n - row;       if (odd)         col = m - col + 1;       else         col = col + 1;       printf( %d %d n , row, col);     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int n, k, i;     scanf( %d , &n);     int a[n][2];     for (i = 0; i < n; i++) {       scanf( %d%d , &a[i][0], &a[i][1]);     }     scanf( %d , &k);     for (i = 0; i < n; i++) {       if (k >= a[i][0] && k <= a[i][1]) {         printf( %d , n - i);         break;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int read() {     int X = 0, w = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) w = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) X = X * 10 + c -  0 , c = getchar();     return X * w;   }   const int N = 1500 + 10, K = 100000 + 10;   const int mod = 1e9 + 7;   int qpow(int a, int b) {     int c = 1;     for (; b; b >>= 1, a = 1ll * a * a % mod)       if (b & 1) c = 1ll * c * a % mod;     return c;   }   int n, m, a, b, k, p;   int fac[K], ifac[K], d[K], sd[N], fr[N][N], sr[N][N], ss[N][N];   int C(int n, int m) { return 1ll * fac[n] * ifac[m] % mod * ifac[n - m] % mod; }   int main() {     n = read(), m = read(), a = read(), b = read(), k = read();     p = 1ll * a * qpow(b, mod - 2) % mod;     fac[0] = 1;     for (int i = 1; i <= k; ++i) fac[i] = 1ll * fac[i - 1] * i % mod;     ifac[k] = qpow(fac[k], mod - 2);     for (int i = k; i; --i) ifac[i - 1] = 1ll * ifac[i] * i % mod;     for (int i = 0; i <= k; ++i)       d[i] = 1ll * C(k, i) * qpow(p, i) % mod * qpow(1 - p + mod, k - i) % mod;     for (int i = 1; i <= m; ++i) sd[i] = (sd[i - 1] + d[i - 1]) % mod;     fr[0][m] = sr[0][m] = 1;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) {         fr[i][j] = (1ll * (sr[i - 1][m] - sr[i - 1][m - j] + mod) * sd[j] -                     ss[i - 1][j] + mod) %                    mod * d[m - j] % mod;         sr[i][j] = (sr[i][j - 1] + fr[i][j]) % mod;         ss[i][j] = (ss[i][j - 1] + 1ll * d[j - 1] * sr[i][j - 1]) % mod;       }     printf( %d n , sr[n][m]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   enum { MAXN = 4010, MAXC = 26 };   int dp[MAXN][MAXN];   char sa[MAXN], sb[MAXN];   int pra[MAXN][MAXC], prb[MAXN][MAXC];   int main() {     int ci, cd, cr, cs;     scanf( %d%d%d%d , &ci, &cd, &cr, &cs);     scanf( %s , sa + 1);     scanf( %s , sb + 1);     int la = strlen(sa + 1);     fill(pra[0], pra[0] + MAXC, 0);     for (int i = 1; i <= la; i++) {       sa[i] -=  a ;       copy(pra[i - 1], pra[i - 1] + MAXC, pra[i]);       pra[i][sa[i]] = i;     }     int lb = strlen(sb + 1);     fill(prb[0], prb[0] + MAXC, 0);     for (int i = 1; i <= lb; i++) {       sb[i] -=  a ;       copy(prb[i - 1], prb[i - 1] + MAXC, prb[i]);       prb[i][sb[i]] = i;     }     for (int i = 0; i <= la; i++) dp[i][0] = cd * i;     for (int i = 0; i <= lb; i++) dp[0][i] = ci * i;     for (int i = 1; i <= la; i++)       for (int j = 1; j <= lb; j++) {         dp[i][j] = min(min(dp[i - 1][j] + cd, dp[i][j - 1] + ci),                        dp[i - 1][j - 1] + (sa[i] == sb[j] ? 0 : cr));         if (sa[i] != sb[j] && pra[i][sb[j]] && prb[j][sa[i]]) {           dp[i][j] = min(dp[i][j], dp[pra[i][sb[j]] - 1][prb[j][sa[i]] - 1] +                                        (i - pra[i][sb[j]] - 1) * cd + cs +                                        (j - prb[j][sa[i]] - 1) * ci);         }       }     printf( %d n , dp[la][lb]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long int n;     cin >> n;     long long int a[n];     long long int sum = 0;     for (long long int i = 0; i < n; i++) {       cin >> a[i];       sum += a[i];     }     sort(a, a + n);     long long int req = ceil(sum / (long double)(n - 1));     cout << max(req, a[n - 1]);   }
#include <bits/stdc++.h>   using namespace std;   int w, m;   long long x = 1;   bool f = 1;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> w >> m;     while (m && f) {       if ((m - 1) % w == 0 || m % w == 0 || (m + 1) % w == 0) {         if ((m - 1) % w == 0 || m % w == 0)           m /= w;         else           m = (m + 1) / w;       } else         f = 0;     }     if (f)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long nax = 1e5 + 10;   vector<long long> g[nax];   signed main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     ;     long long n;     cin >> n;     long long f = 0;     vector<pair<pair<long long, long long>, long long> > a(n - 2);     for (long long i = 0; i < n - 2; i++) {       long long x, y, z;       cin >> x >> y >> z;       a[i].first.first = x;       a[i].first.second = y;       a[i].second = z;       g[x].push_back(i);       g[y].push_back(i);       g[z].push_back(i);     }     for (long long i = 1; i <= n; i++) {       if (g[i].size() == 1) {         f = i;         break;       }     }     vector<long long> ans;     long long id = g[f][0];     long long cur1 = -1, cur2 = -1;     if (a[id].first.first != f) {       cur1 = a[id].first.first;       if (a[id].second != f)         cur2 = a[id].second;       else         cur2 = a[id].first.second;     } else {       cur1 = a[id].first.second, cur2 = a[id].second;     }     ans.push_back(f);     ans.push_back(cur1);     ans.push_back(cur2);     long long cd = cur1;     long long dc = cur2;     set<long long> yy;     yy.insert(id);     while (ans.size() < n) {       for (auto &i : g[cur1])         if (yy.find(i) == yy.end()) id = i;       yy.insert(id);       if (a[id].first.first != cur1 && a[id].first.first != cur2)         ans.push_back(a[id].first.first);       else if (a[id].first.second != cur1 && a[id].first.second != cur2)         ans.push_back(a[id].first.second);       else         ans.push_back(a[id].second);       cur1 = ans[ans.size() - 2];       cur2 = ans.back();     }     vector<long long> ans1;     id = g[f][0];     cur1 = dc;     cur2 = cd;     ans1.push_back(f);     ans1.push_back(cur1);     ans1.push_back(cur2);     set<long long> xx;     xx.insert(id);     while (ans1.size() < n) {       for (auto &i : g[cur1])         if (xx.find(i) == xx.end()) id = i;       xx.insert(id);       if (a[id].first.first != cur1 && a[id].first.first != cur2)         ans1.push_back(a[id].first.first);       else if (a[id].first.second != cur1 && a[id].first.second != cur2)         ans1.push_back(a[id].first.second);       else         ans1.push_back(a[id].second);       cur1 = ans1[ans1.size() - 2];       cur2 = ans1.back();     }     set<long long> s1, s2;     for (auto &i : ans) s1.insert(i);     for (auto &i : ans1) s2.insert(i);     if (s1.size() == n)       for (auto &i : ans) cout << i <<    ;     else       for (long long i = 0; i < n; i++) cout << ans1[i] <<    ;   }
#include <bits/stdc++.h>   int main() {     int n, i, j, k;     scanf( %d , &n);     int a[1000];     int b[1000];     int c[6] = {0};     int d[6] = {0};     int sum = 0;     for (i = 0; i < n; i++) {       scanf( %d , &a[i]);       c[a[i]]++;     }     for (i = 0; i < n; i++) {       scanf( %d , &b[i]);       d[b[i]]++;     }     for (i = 1; i <= 5; i++) {       if ((c[i] - d[i]) % 2 == 0) {         if (c[i] > d[i])           sum = sum + (c[i] - d[i]) / 2;         else           sum = sum + (d[i] - c[i]) / 2;       } else {         sum = -1;         break;       }     }     if (sum == -1)       printf( -1 n );     else       printf( %d n , sum / 2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[20005];   struct SuffixArray {     int wa[20005], wb[20005], cnt[20005], wv[20005];     int rk[20005], height[20005];     int sa[20005];     bool cmp(int r[], int a, int b, int l) {       return r[a] == r[b] && r[a + l] == r[b + l];     }     void calcSA(char r[], int n, int m) {       int i, j, p, *x = wa, *y = wb;       for (i = 0; i < m; ++i) cnt[i] = 0;       for (i = 0; i < n; ++i) cnt[x[i] = r[i]]++;       for (i = 1; i < m; ++i) cnt[i] += cnt[i - 1];       for (i = n - 1; i >= 0; --i) sa[--cnt[x[i]]] = i;       for (j = 1, p = 1; p < n; j *= 2, m = p) {         for (p = 0, i = n - j; i < n; ++i) y[p++] = i;         for (i = 0; i < n; ++i)           if (sa[i] >= j) y[p++] = sa[i] - j;         for (i = 0; i < n; ++i) wv[i] = x[y[i]];         for (i = 0; i < m; ++i) cnt[i] = 0;         for (i = 0; i < n; ++i) cnt[wv[i]]++;         for (i = 1; i < m; ++i) cnt[i] += cnt[i - 1];         for (i = n - 1; i >= 0; --i) sa[--cnt[wv[i]]] = y[i];         for (swap(x, y), p = 1, x[sa[0]] = 0, i = 1; i < n; ++i)           x[sa[i]] = cmp(y, sa[i - 1], sa[i], j) ? p - 1 : p++;       }     }     void calcHeight(char r[], int n) {       int i, j, k = 0;       for (i = 0; i <= n; ++i) rk[sa[i]] = i;       for (i = 0; i < n; height[rk[i++]] = k)         for (k ? k-- : 0, j = sa[rk[i] - 1]; r[i + k] == r[j + k]; k++)           ;     }     bool solve(int k, int n, int div) {       int ca = 0, cb = 0;       for (int i = 1; i <= n; i++) {         if (height[i] < k) {           if (ca == 1 && cb == 1) return true;           ca = 0;           cb = 0;           if (sa[i] < div)             ca++;           else if (sa[i] > div)             cb++;           continue;         }         if (sa[i] < div)           ca++;         else if (sa[i] > div)           cb++;       }       return ca == 1 && cb == 1;     }   } suf;   char a[20005], b[20005];   int main() {     scanf( %s %s , a, b);     int n = strlen(a), m = strlen(b);     strcpy(s, a);     s[n] =  # ;     strcpy(s + n + 1, b);     int tot = n + m + 1;     suf.calcSA(s, tot + 1, 128);     suf.calcHeight(s, tot);     int ret = -1;     for (int i = 1; i <= n; i++) {       if (suf.solve(i, tot, n)) {         ret = i;         break;       }     }     printf( %d n , ret);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   const int inf = 1 << 30;   const long long INF = 1ll << 61;   const double oo = 1 << 30;   const long long zqc = 1e9 + 7;   int n, k;   int t, x;   vector<int> a;   int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }   int main() {     scanf( %d%d , &n, &k);     t = n / 2;     --t;     x = k - t;     if (k == 0 && n == 1) return 0 * printf( 1 );     if (x <= 0) return 0 * printf( -1 );     if (n == 1) return 0 * printf( -1 );     a.push_back(x);     a.push_back(2 * x);     for (int i = 1; i <= 1e9; ++i) {       if (a.size() == n) break;       if (x == i || 2 * x == i) continue;       if (a.size() % 2 == 1 && gcd(a[a.size() - 1], i) != 1) continue;       a.push_back(i);     }     for (auto p : a) printf( %d  , p);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, d, cot = 0;     cin >> n >> m >> d;     int arr[10004] = {0};     int rn = n * m;     for (int j = 1; j <= rn; j++) cin >> arr[j];     sort(arr, arr + rn);     int ind = arr[rn / 2];     if (n * m == 1) {       cout << 0;       return 0;     }     for (int i = 1; i <= rn; i++) {       if (abs(ind - arr[i]) % d != 0) {         cout << -1;         return 0;       } else {         cot += abs(ind - arr[i]) / d;       }     }     cout << cot << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 2e3;   vector<int> e[MAX_N], d;   vector<char> flag;   void dfs(int v) {     if (d[v] != -1) return;     d[v] = 1;     for (int to : e[v]) {       dfs(to);       d[v] = max(d[v], d[to] + 1);     }   }   int main() {     int n;     scanf( %d , &n);     d.assign(n, -1);     for (int i = 0; i < n; i++) {       int x;       scanf( %d , &x);       if (x != -1) e[x - 1].push_back(i);     }     for (int i = 0; i < n; i++)       if (d[i] == -1) dfs(i);     int ans = 1;     for (int i : d) ans = max(ans, i);     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a[100], n, temp, m, ans;     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     for (int i = 0; i < (n - 1); i++) {       for (int j = 0; j < n - i - 1; j++) {         if (a[j] < a[j + 1]) {           temp = a[j];           a[j] = a[j + 1];           a[j + 1] = temp;         }       }     }     for (int i = 0; i < n; i++) {       if (m % a[i] == 0) {         ans = max(0, m / a[i]);         cout << ans << endl;         return 0;       }     }     return 0;   }