malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     getline(cin, s);     int i = s.size() - 1;     while (s[i] ==  ? ) {       i--;     }     while (s[i] == 32) {       i--;     }     if (s[i] ==  y  || s[i] ==  u  || s[i] ==  o  || s[i] ==  i  || s[i] ==  e  ||         s[i] ==  a ) {       cout <<  YES ;       return 0;     }     if (s[i] ==  Y  || s[i] ==  U  || s[i] ==  O  || s[i] ==  I  || s[i] ==  E  ||         s[i] ==  A ) {       cout <<  YES ;       return 0;     }     cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const double eps = 1e-6;   const int INF = 0x3f3f3f3f;   const int MAXN = 1e5 + 10;   int cnt, head[MAXN], tot;   int n, tim, a[MAXN], root[MAXN];   struct Poi {     int w, dfn, dep, col;   } poi[MAXN];   bool cmp(int a, int b) { return poi[a].dep < poi[b].dep; }   struct Edge {     int v, nex;   } edge[MAXN * 2];   struct Node {     int l, r, m;   } node[MAXN * 20];   void add(int u, int v) {     edge[cnt] = {v, head[u]};     head[u] = cnt++;   }   void dfs(int u, int fa) {     poi[u].dep = poi[fa].dep + 1;     poi[u].dfn = ++tim;     for (int i = head[u]; ~i; i = edge[i].nex) {       int v = edge[i].v;       if (v == fa) continue;       dfs(v, u);     }     poi[u].col = tim;   }   void up(int rt) { node[rt].m = min(node[node[rt].l].m, node[node[rt].r].m); }   void update(int &rt, int l, int r, int k, int x) {     node[++tot] = node[rt];     rt = tot;     if (l == r) {       node[rt].m = x;       return;     }     int mid = ((l + r) >> 1);     if (k <= mid)       update(node[rt].l, l, mid, k, x);     else       update(node[rt].r, mid + 1, r, k, x);     up(rt);   }   int bin(int x) {     int l = 1, r = n;     while (l <= r) {       int mid = ((l + r) >> 1);       if (poi[a[mid]].dep <= x)         l = mid + 1;       else         r = mid - 1;     }     return r;   }   int query(int rt, int l, int r, int L, int R) {     if (l == L && r == R) return node[rt].m;     int mid = ((l + r) >> 1);     if (R <= mid)       return query(node[rt].l, l, mid, L, R);     else if (L > mid)       return query(node[rt].r, mid + 1, r, L, R);     else {       int a = query(node[rt].l, l, mid, L, mid);       int b = query(node[rt].r, mid + 1, r, mid + 1, R);       return min(a, b);     }   }   inline int read() {     int k = 0;     char f = 1;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -1;     for (; isdigit(c); c = getchar()) k = k * 10 + c -  0 ;     return k * f;   }   int main() {     int s;     memset(head, -1, sizeof head);     cin >> n >> s;     for (int i = 1; i <= n; i++) poi[i].w = read(), a[i] = i;     for (int i = 1; i < n; i++) {       int u, v;       u = read(), v = read();       add(u, v);       add(v, u);     }     dfs(s, 0);     sort(a + 1, a + 1 + n, cmp);     node[0].m = INF;     for (int i = 1; i <= n; i++) {       root[i] = root[i - 1];       int idx = a[i];       int p = poi[idx].dfn;       int w = poi[idx].w;       update(root[i], 1, n, p, w);     }     int m;     cin >> m;     int ans = 0;     while (m--) {       int x, k;       x = read(), k = read();       x = (x + ans) % n + 1;       k = (k + ans) % n;       int dep = poi[x].dep + k;       int l = poi[x].dfn, r = poi[x].col;       int p = bin(dep);       ans = query(root[p], 1, n, l, r);       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     for (int row = -n; row <= n; row++) {       int top = n - abs(row);       for (int i = 0; i < abs(row); i++) {         cout <<     ;       }       for (int i = 0; i < top; ++i) {         cout << i <<    ;       }       for (int i = top; i > 0; --i) {         cout << i <<    ;       }       cout << 0 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int n, d = 0;     n = s.size();     for (int i = 0; i < n; i++) {       if (s[i] ==  o ) d++;     }     if (d == 0) {       cout <<  YES ;       return 0;     }     if ((n - d) % d == 0) {       cout <<  YES ;       return 0;     }     cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 10002;   const int maxm = 15000002;   int f[maxm], p[maxn];   bool v[maxn];   int a[maxn];   int n, m, s;   int main() {     int i, j;     for (i = 2; i < 12; i++) {       if (!v[i]) p[s++] = i;       for (j = 0; j < s && i * p[j] < 12; j++) {         v[i * p[j]] = 1;         if (i % p[j] == 0) break;       }     }     for (i = 2; i < maxm; i++)       if (!f[i])         for (j = i; j < maxm; j += i) f[j] = i;     scanf( %d , &n);     m = 1;     for (j = 0; j < s; ++j) {       m *= p[j];       if (m > n) break;     }     --j;     m = 0;     for (i = 2; i <= 2 * n * n && i < maxm; ++i)       if (f[i] <= p[j]) {         a[m++] = i;       }     sort(a, a + m);     reverse(a, a + m);     for (i = 0; i < n; ++i) printf( %d  , a[i]);     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool debug = false;   int n, m, k;   int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};   long long ln, lk, lm;   int gg(int x, int y) {     int z = y;     while (x % y != 0) {       z = x % y;       x = y;       y = z;     }     return z;   }   map<int, vector<int>> X[2];   map<pair<pair<int, int>, pair<int, int>>, vector<int>> mp[2];   int cx[20005], cy[20005], cr[20005], ans;   int dis(int i, int j) {     return (cx[i] - cx[j]) * (cx[i] - cx[j]) + (cy[i] - cy[j]) * (cy[i] - cy[j]);   }   pair<int, int> gett(int x, int y) {     if (y == 0) return {0, 1};     int tmp = gg(abs(x), abs(y));     pair<int, int> tt = {abs(y / tmp), abs(x / tmp)};     if ((y < 0 && x > 0) || (y > 0 && x < 0)) tt.second *= -1;     return tt;   }   void cal(int i, int j) {     if (cy[i] == cy[j]) {       int x = cx[i] + cx[j];       if (x % 2 != 0) return;       x /= 2;       auto p = X[0][x];       int sz = p.size();       if (sz == 0) return;       int tar = cy[i];       int c = p.end() - upper_bound(p.begin(), p.end(), tar);       p = X[1][x];       c += sz - (p.end() - lower_bound(p.begin(), p.end(), tar));       ans += sz - c;       return;     }     int x = cx[i] - cx[j], y = cy[i] - cy[j];     int zx = (cx[i] + cx[j]), zy = (cy[i] + cy[j]);     pair<int, int> kk = gett(y * -1, x);     pair<int, int> bb = gett(kk.second * 2, kk.second * zy - kk.first * zx);     if (mp[0].find({kk, bb}) == mp[0].end()) return;     auto p = mp[0][{kk, bb}];     int sz = p.size();     int tar = zx / 2;     int c = p.end() - upper_bound(p.begin(), p.end(), tar);     p = mp[1][{kk, bb}];     c += sz - (p.end() - lower_bound(p.begin(), p.end(), tar));     ans += sz - c;   }   int main() {     scanf( %d%d , &n, &m);     int a, b, c, d;     for (int(i) = 0; (i) < (int)(n); (i)++) {       scanf( %d%d%d%d , &a, &b, &c, &d);       if (a == c) {         X[0][a].push_back({min(b, d)});         X[1][a].push_back({max(b, d)});       } else {         int x = a - c, y = b - d;         pair<int, int> tt = gett(x, y);         y = d * a - c * b;         pair<int, int> bb = gett(x, y);         mp[0][{tt, bb}].push_back(min(a, c));         mp[1][{tt, bb}].push_back(max(a, c));       }     }     for (int(i) = 0; (i) < (int)(2); (i)++) {       for (auto &p : X[i]) sort(p.second.begin(), p.second.end());       for (auto &p : mp[i]) sort(p.second.begin(), p.second.end());     }     for (int(i) = 0; (i) < (int)(m); (i)++)       scanf( %d%d%d , cx + i, cy + i, cr + i);     for (int(i) = 0; (i) < (int)(m); (i)++)       for (int j = i + 1; j < m; j++)         if (cr[i] == cr[j]) {           int D = cr[i] + cr[j];           D *= D;           if (dis(i, j) > D) {             cal(i, j);           }         }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MN = 200010;   int a[MN], b[MN], p[MN], q[MN];   char ans[MN];   int main() {     int t, m, k;     for (scanf( %d , &t); t--;) {       scanf( %d%d , &m, &k);       int pos = 0, pos1;       for (int i = 1; i <= k; i++) {         scanf( %d , &a[i]);       }       bool flag = false;       for (int i = 1; i < m; i++) {         scanf( %d%d , &p[i], &q[i]);         if (q[i] == 1 && !flag) {           flag = true;           for (int j = 1; j <= k; j++) {             b[j] = a[j];           }           pos1 = pos;         }         if (p[i] != 0) {           a[p[i]]--;         } else {           pos++;         }       }       int minA = MN;       if (flag) {         for (int i = 1; i <= k; i++) {           if (a[i] == b[i]) {             minA = min(minA, a[i]);           }         }         pos -= minA;       }       for (int i = 1; i <= k; i++) {         if (flag && a[i] == b[i] && a[i] <= pos1) {           printf( Y );         } else {           printf( %c , (a[i] > pos ?  N  :  Y ));         }       }       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     char a[10][10];     char b[10][10];     vector<char> v, l;     long long int i, count = 0, j;     for (i = 0; i < 2; i++) {       for (j = 0; j < 2; j++) {         cin >> a[i][j];       }     }     v.push_back(a[0][0]);     v.push_back(a[0][1]);     v.push_back(a[1][1]);     v.push_back(a[1][0]);     for (i = 0; i < 2; i++) {       for (j = 0; j < 2; j++) {         cin >> b[i][j];       }     }     l.push_back(b[0][0]);     l.push_back(b[0][1]);     l.push_back(b[1][1]);     l.push_back(b[1][0]);     int flag = 0;     v.erase(remove(v.begin(), v.end(),  X ), v.end());     l.erase(remove(l.begin(), l.end(),  X ), l.end());     for (i = 0; i < 3; i++) {       if (equal(v.begin(), v.end(), l.begin())) {         flag = 1;         break;       } else {         vector<char>::iterator k = v.begin() + 2;         char la = *k;         v.insert(v.begin(), *k);         v.erase(v.begin() + 3);       }     }     if (flag)       cout <<  YES n ;     else       cout <<  NO n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     vector<int> a(n);     int sum = 0, maxi = -1;     for (int i = 0; i < n; i++) {       cin >> a[i];       sum += a[i];       maxi = max(a[i], maxi);     }     if (maxi > (sum / 2))       cout <<  T             <<   n ;     else {       if (sum % 2 == 0)         cout <<  HL               <<   n ;       else         cout <<  T               <<   n ;     }   }   int main() {     int t;     cin >> t;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   int main() {     int k, d, i, n, x;     scanf( %d%d , &k, &d);     n = k;     x = d;     if ((k > 1) && (d == 0)) {       printf( No solution );     } else {       for (i = 1; ((i < n) && (x > 0)); i++) {         printf( 1 );         x--;       }       while (i < n) {         printf( 0 );         i++;       }       if (x == 0) {         printf( 0 );       } else {         printf( %d , (d - i + 1));       }     }   }
#include <bits/stdc++.h>   int main() {     int n, o, i, k, m;     scanf( %d%d , &n, &o);     scanf( %d%d , &k, &m);     int a[n], b[o];     for (i = 0; i < n; i++) scanf( %d , &a[i]);     for (i = 0; i < o; i++) scanf( %d , &b[i]);     if (a[k - 1] < b[o - m])       printf( YES );     else       printf( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool dp[10005][3];   int main() {     int n, i;     string s;     set<string> ans;     cin >> s;     n = s.length();     for (i = n - 1; i >= 5; i--) {       if (i + 2 <= n) {         if (i + 2 == n || dp[i + 2][1] ||             (dp[i + 2][0] && s.substr(i + 2, 2) != s.substr(i, 2))) {           dp[i][0] = true;           ans.insert(s.substr(i, 2));         }       }       if (i + 3 <= n) {         if (i + 3 == n || dp[i + 3][0] ||             (dp[i + 3][1] && s.substr(i + 3, 3) != s.substr(i, 3))) {           dp[i][1] = true;           ans.insert(s.substr(i, 3));         }       }     }     cout << ans.size() << endl;     while (!ans.empty()) {       cout << *ans.begin() << endl;       ans.erase(ans.begin());     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 345;   int ai[maxn];   int bi[maxn];   bool used[maxn];   int m, r, t;   void init() {     for (int i = 1; i <= m; i++) {       scanf( %d , &ai[i]);       ai[i]++;     }   }   vector<int> V;   void play() {     memset(bi, 0, sizeof(bi));     memset(used, 0, sizeof(used));     V.clear();     if (t < r) {       printf( -1 n );       return;     }     long long sum = 0;     for (int i = 1; i <= m; i++) {       int st = 0;       while (bi[ai[i]] < r) {         for (int j = ai[i] - st; j <= ai[i] - st + t - 1; j++) {           if (j <= 0 || j > 320) continue;           bi[j]++;         }         sum++;         st++;       }     }     printf( %I64d n , sum);   }   int main() {     while (scanf( %d%d%d , &m, &t, &r) != EOF) {       init();       play();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7, N = 1e5 + 5;   int main() {     std::ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     long long a[n + 5], ans = 0, maxx = 0, sum = 0;     vector<long long> e, o;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] & 1)         e.push_back(a[i]);       else         o.push_back(a[i]);       maxx = max(a[i], maxx);       sum += a[i];     }     sort(e.begin(), e.end()), sort(o.begin(), o.end());     long long es = (long long)e.size(), os = (long long)o.size();     if (abs(es - os) <= 1) {       cout << 0;       return 0;     }     if (es == 0 || os == 0) {       cout << sum - maxx;       return 0;     }     if (es > os) {       for (int i = 0; i < (es - os - 1); i++) {         ans += e[i];       }     } else {       for (int i = 0; i < (os - es - 1); i++) {         ans += o[i];       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, k, x, y;     scanf( %d%d%d , &n, &m, &k);     bool f = false;     while (k--) {       scanf( %d%d , &x, &y);       int mn = (1 << 20);       for (int i = 1; i <= n; ++i)         for (int j = 1; j <= m; ++j)           if (i == 1 || j == 1 || i == n || j == m)             mn = min(mn, abs(i - x) + abs(j - y));       if (mn <= 4) f = true;     }     if (f)       cout <<  YES  << endl;     else       cout <<  NO  << endl;   }
#include<bits/stdc++.h>   using namespace std;       #define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);   #define int long long   #define rep(i,a,b)    for(int i=a;i<b;i++)   #define repn(i,a,b)   for(int i=a;i>=b;i--)   #define ff first   #define ss second   #define lb lower_bound   #define ub upper_bound   #define pii pair<int,int>   #define vi vector<int>   #define vs vector<string>   #define vii vector<pii>   #define vvi vector<vector<int>>   #define vvii vector<vector<pii>>   #define pb push_back   #define ppb pop_back   #define pf push_front   #define ppf pop_front   #define sz(x) (int)x.size()   #define all(v) (v).begin(), (v).end()      #define ret(x) return cout<<x,0;   #define rety return cout<< YES ,0;   #define retn return cout<< NO ,0;   #define fl fflush(stdout)      #define hell 1000000007   #define hell2 998244353    #define pi 3.14159265358979323846      int solve(){       int n,m;       cin >> n >> m;       string s,a;       cin >> s;       a = s;       for(int i = 0; i < min(m,n); i++){           int x{};           for(int j = 0; j < n; j++){               if(j == 0){                   if(s[1] ==  1  && s[0] ==  0 )                       a[0] =  1 ;                   x++;                   }               else if(j == n-1){                   if(s[n-1] ==  0  && s[n-2] ==  1 )                       a[n-1] =  1 ;                   x++;               }               else{                   if((s[j-1] ==  1  && s[j+1] ==  0  && s[j] ==  0 ) || (s[j-1] ==  0  && s[j+1] ==  1  && s[j] ==  0 ))                       a[j] =  1 ;                   x++;                   }           }           s = a;           if(x == 0)               break;       }       cout << s << endl;              return 0;   }          signed main(){       IOS;       int tp=1;    cin>>tp;       while(tp--){           solve();       }              return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     int ans = 0;     int inp;     for (int i = 0; i < n; i++) {       cin >> inp;       int temp = (inp + k - 1) / k;       ans += temp;     }     cout << (ans + 1) / 2 << endl;   }
#include <bits/stdc++.h>   using namespace std;   map<char, int> m;   char letters[30];   int numbers[30];   int mystring[30];   int ceiling(int top, int bottom) { return (top + bottom - 1) / bottom; }   int main() {     string s;     int n;     cin >> s >> n;     for (int i = 0; i < (int)s.length(); i++) m[s[i]]++;     int numChar = 0;     for (map<char, int>::iterator it = m.begin(); it != m.end(); ++it) {       letters[numChar] = it->first;       numbers[numChar] = it->second;       numChar++;     }     if (numChar > n) {       cout << -1 << endl;       return 0;     }     for (int i = 0; i < numChar; i++) mystring[i] = 1;     for (int i = numChar; i < n; i++) {       int needMost = -1, needMostIndex = -1;       for (int j = 0; j < numChar; j++) {         if (ceiling(numbers[j], mystring[j]) > needMost) {           needMost = ceiling(numbers[j], mystring[j]);           needMostIndex = j;         }       }       mystring[needMostIndex]++;     }     int needMost = -1;     for (int j = 0; j < numChar; j++) {       if (ceiling(numbers[j], mystring[j]) > needMost) {         needMost = ceiling(numbers[j], mystring[j]);       }     }     cout << needMost << endl;     for (int i = 0; i < numChar; i++)       for (int j = 0; j < mystring[i]; j++) cout << letters[i];     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long Size = 501;   const long long mod = 1e9 + 7;   long long a[Size], num[Size];   bool vis[Size];   long long f[Size], d[Size];   long long dp[Size][Size];   inline long long min(long long a, long long b) { return a < b ? a : b; }   inline long long max(long long a, long long b) { return a > b ? a : b; }   long long fastpow(long long b, long long p, long long k) {     long long ans = 1;     while (p) {       if (p & 1) ans = ans * b % k;       b = b * b % k;       p >>= 1;     }     return ans;   }   void init() {     f[0] = 1;     for (long long i = 1; i <= 300; i++) f[i] = f[i - 1] * i % mod;     d[300] = fastpow(f[300], mod - 2, mod);     for (long long i = 299; i >= 0; i--) d[i] = d[i + 1] * (i + 1) % mod;   }   long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = 10 * x + ch -  0 ;       ch = getchar();     }     return x * f;   }   long long C(long long a, long long b) {     if (a < 0 || b < 0 || a < b) return 0;     if (!b || a == b) return 1;     return (f[a] * d[b] % mod) * d[a - b] % mod;   }   int main() {     init();     C(2, 1);     long long n = read(), size = 0;     for (long long i = 1; i <= n; i++) a[i] = read();     for (long long i = 1; i <= n; i++) {       if (!vis[i]) {         size++;         for (long long j = i; j <= n; j++) {           if (sqrt(a[i] * a[j]) == (long long)sqrt(a[i] * a[j])) {             vis[j] = true;             num[size]++;           }         }       }     }     long long sum = num[1] - 1;     dp[1][sum] = 1;     for (long long i = 2; i <= size; sum += num[i++]) {       for (long long j = 0; j <= sum; j++) {         if (!dp[i - 1][j]) continue;         for (long long k = 0; k <= num[i]; k++) {           long long tmp = min(j, k + 1), temp;           for (long long l = 0; l <= tmp; l++) {             temp = dp[i - 1][j] * C(num[i] - 1, k) % mod * C(j, l) % mod *                    C(sum + 2 - j, k - l + 1) % mod;             dp[i][j + num[i] - 1 - k - l] += temp;             dp[i][j + num[i] - 1 - k - l] %= mod;           }         }       }     }     long long ans = dp[size][0];     for (long long i = 1; i <= size; i++) ans = ans * f[num[i]] % mod;     printf( %I64d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   using v2d = vector<vector<T> >;   template <class T>   bool uin(T &a, T b) {     return a > b ? (a = b, true) : false;   }   template <class T>   bool uax(T &a, T b) {     return a < b ? (a = b, true) : false;   }   mt19937 rng(chrono::system_clock::now().time_since_epoch().count());   const int maxN = 2e5 + 10;   const int maxM = 5e5 + 10;   int n, m, a, b;   vector<int> adj[maxN];   int fa[maxN], fb[maxN];   long long ca = 0, cb = 0;   void DFSa(int u) {     if (u == b) {       return;     }     fa[u] = 1;     for (auto &v : adj[u]) {       if (!fa[v]) {         DFSa(v);       }     }   }   void DFSb(int u) {     if (u == a) {       return;     }     fb[u] = 1;     for (auto &v : adj[u]) {       if (!fb[v]) {         DFSb(v);       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int T;     cin >> T;     while (T--) {       cin >> n >> m >> a >> b;       for (int i = 1; i <= (int)(n); ++i) {         adj[i].clear();         fa[i] = fb[i] = 0;       }       while (m--) {         int u, v;         cin >> u >> v;         adj[u].emplace_back(v);         adj[v].emplace_back(u);       }       DFSa(a);       DFSb(b);       ca = cb = 0;       for (int i = 1; i <= (int)(n); ++i) {         if (fa[i]) {           ca += !fb[i];         }         if (fb[i]) {           cb += !fa[i];         }       }       cout << (ca - 1) * (cb - 1) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       unsigned int n;       cin >> n;       unsigned long k;       cin >> k;       if (n & 1) {         for (int i = 2; i <= (n); i++) {           if (n % i == 0) {             n += i;             break;           }         }         n += 2 * (k - 1);       } else         n += 2 * k;       cout << n <<   n ;     }     return 0;   }