malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, m, i, pos = -1, flag;     string s1, s2;     cin >> n >> m;     cin >> s1;     cin >> s2;     for (i = 0; i < n; i++) {       if (s1[i] ==  * ) {         pos = i;         break;       }     }     if (pos == -1) {       if (s1 == s2)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     } else {       if (m < (n - 1))         cout <<  NO  << endl;       else {         flag = 0;         for (i = 0; i < n; i++) {           if (i < pos) {             if (s1[i] != s2[i]) {               cout <<  NO  << endl;               flag = 1;               break;             }           } else if (i > pos) {             if (s1[i] != s2[m - n + i]) {               cout <<  NO  << endl;               flag = 1;               break;             }           }         }         if (flag == 0) cout <<  YES  << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   int a[100005];   int maxans, maxnum;   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     sort(a, a + n);     int l = 0, r = 0;     int curk = k, curans = 0, curnum = 0;     while (r < n) {       while (r < n && curk >= (long long)curans * (a[r] - curnum)) {         curk -= curans * (a[r] - curnum);         curans++;         curnum = a[r++];       }       if (curans > maxans) {         maxans = curans;         maxnum = curnum;       }       if (l < r) {         curk += curnum - a[l++];         curans--;       }       if (curans > maxans) {         maxans = curans;         maxnum = curnum;       }     }     printf( %d %d n , maxans, maxnum);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m;     long long a[100001];     long long b[100001];     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     long long x = 0, i = 1, count = 0;     while (m > 0) {       if (a[x] != i) {         if (m - i >= 0) {           m -= i;           b[count] = i;           count++;         } else           break;       } else         x++;       i++;     }     cout << count << endl;     for (int i = 0; i < count; i++) cout << b[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   long long n, m, l, r, a[N], b[N], dp[N];   void prework() {     int k = 1;     for (int i = 2; i <= n; ++i)       if (a[i + 1] - a[i] > a[k + 1] - a[k]) k = i;     r = a[k + 1] - a[k] - 1;     for (int i = 1; i <= n; ++i) b[i] = a[i + k];     int t = b[1];     for (int i = 1; i <= n; ++i) b[i] -= t;   }   int check(long long x) {     dp[1] = 0;     for (int i = 2; i <= n; ++i) {       dp[i] = dp[i - 1];       if (dp[i - 1] >= b[i] - 1) dp[i] = max(dp[i], b[i] + x);       if (dp[i - 1] >= b[i] - x - 1) dp[i] = max(dp[i], b[i]);       if (i > 2 && dp[i - 2] >= b[i] - x - 1) dp[i] = max(dp[i], b[i - 1] + x);     }     if (dp[n] >= m - x - 1) return 1;     dp[2] = max(b[2], x);     for (int i = 3; i <= n; ++i) {       dp[i] = dp[i - 1];       if (dp[i - 1] >= b[i] - 1) dp[i] = max(dp[i], b[i] + x);       if (dp[i - 1] >= b[i] - x - 1) dp[i] = max(dp[i], b[i]);       if (dp[i - 2] >= b[i] - x - 1) dp[i] = max(dp[i], b[i - 1] + x);     }     return dp[n] >= min(m - 1, m + b[2] - x - 1);   }   int main() {     ios::sync_with_stdio(false);     cin >> m >> n;     for (int i = 1; i <= n; ++i) cin >> a[i], a[i + n] = a[i] + m;     if (n == 1) return cout << m - 1 << endl, 0;     sort(a + 1, a + n * 2 - 1);     prework();     while (l < r) {       long long mid = (l + r) >> 1;       if (check(mid))         r = mid;       else         l = mid + 1;     }     cout << l << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     long long by = (n / 2) + (n / 3) + (n / 5) + (n / 7) - (n / 6) - (n / 10) -                    (n / 14) - (n / 15) - (n / 35) - (n / 21);     by += (n / 30) + (n / 42) + (n / 70) + (n / 105);     by -= (n / 210);     cout << n - by << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool mark[100];   int main() {     int n, A[100][100];     cin >> n;     int k = n;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) cin >> A[i][j];     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) {         if (A[i][j] == 1 or A[i][j] == 3) {           mark[i] = true;           k--;           j = n;         }       }     cout << k << endl;     for (int i = 0; i < n; i++)       if (!mark[i]) cout << i + 1 <<    ;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 10;   string s[105];   int n, last_hh, last_mm, last_tme, cur_tme, cur_mm, cur_hh, ans = 1, cnt = 0;   int calch(int i) { return (s[i][1] -  0 ) * 10 + s[i][2] -  0 ; }   int calcm(int i) { return (s[i][4] -  0 ) * 10 + s[i][5] -  0 ; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n;     for (int i = 1; i <= n + 1; i++) getline(cin, s[i]);     for (int i = 2; i <= n + 1; i++) {       last_hh = calch(i - 1);       if (last_hh == 12) last_hh = 0;       last_mm = calcm(i - 1);       cur_hh = calch(i);       if (cur_hh == 12) cur_hh = 0;       cur_mm = calcm(i);       last_tme = last_hh * 60 + last_mm;       cur_tme = cur_hh * 60 + cur_mm;       if (s[i - 1][7] ==  p ) last_tme += 12 * 60;       if (s[i][7] ==  p ) cur_tme += 12 * 60;       if (last_tme > cur_tme)         ans++, cnt = 0;       else if (last_tme == cur_tme) {         cnt++;         if (cnt == 10) ans++, cnt = 0;       } else         cnt = 0;     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6;   long long int ans, n, a[N];   string s;   int main() {     cin >> n >> s;     if (n == 1) {       cout <<  Yes ;       return 0;     }     for (int i = 0; i < n; i++) {       a[s[i] -  a ]++;     }     for (int i = 0; i < 26; i++) {       if (a[i] == 1) {         ans++;       }     }     if (ans == n) {       cout <<  No ;       return 0;     }     cout <<  Yes ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string a, str, ans;   int n, m;   int G[205 * 2][205 * 2];   bool check(int x, int y) {     bool f1 = (a[ans[x] -  a ] ==  C ), f2 = (a[ans[y] -  a ] ==  C );     int ta = 2 * x + 2, tb = 2 * y + 2;     return !G[ta - f1][tb - (!f2)] && !G[tb - f2][ta - (!f1)];   }   bool DFS(int now, bool p) {     if (now == n) {       cout << ans << endl;       return true;     }     int lw = (p == true) ? 0 : str[now] -  a ;     for (int i = lw; i < a.length(); i++) {       ans[now] = i +  a ;       bool f = true;       for (int j = 0; j <= now; j++) {         if (check(j, now) == false) {           f = false;           break;         }       }       if (f == false) continue;       if (DFS(now + 1, p || (ans[now] > str[now]))) return true;     }     return false;   }   int main() {     cin >> a >> n >> m;     for (int i = 1, p1, p2; i <= m; i++) {       char t1, t2;       scanf( %d %c %d %c , &p1, &t1, &p2, &t2);       bool f1 = (t1 ==  C ), f2 = (t2 ==  C );       int x = 2 * p1, y = 2 * p2;       G[x - f1][y - f2] = G[y - (!f2)][x - (!f1)] = 1;     }     int c[2] = {0};     for (int i = 0; i < a.length(); i++) c[a[i] ==  C ] = 1;     if (c[1] == 0 || c[0] == 0) {       for (int i = 1; i <= n; i++) G[2 * i - c[0]][2 * i - (!c[0])] = 1;     }     cin >> str;     for (int t = 1; t <= 2 * n; t++) {       for (int i = 1; i <= 2 * n; i++) {         for (int j = 1; j <= 2 * n; j++)           if (G[i][t] && G[t][j]) G[i][j] = 1;       }     }     for (int i = 1; i <= n; i++) {       int x = 2 * i, y = 2 * i - 1;       if (G[x][y] && G[y][x]) {         puts( -1 );         return 0;       }       ans +=    ;     }     if (DFS(0, 0) == false) puts( -1 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename _T>   inline void _DBG(const char *s, _T x) {     cerr << s <<   =   << x <<   n ;   }   template <typename _T, typename... args>   void _DBG(const char *s, _T x, args... a) {     while (*s !=  , ) cerr << *s++;     cerr <<   =   << x <<  , ;     _DBG(s + 1, a...);   }   vector<int> A;   vector<int> modded;   int main() {     int n;     cin >> n;     A.resize(n);     modded.resize(n);     for (int i = 0; i < n; i++) {       cin >> A[i];     }     int res = 0;     for (int i = 0; i < 27; i++) {       for (int j = 0; j < n; j++) {         modded[j] = A[j] % (1 << (i + 1));       }       sort((modded).begin(), (modded).end());       int l, r, cnt = 0;       for (int j = 0; j < n; j++) {         auto beg = modded.begin() + j + 1;         auto end = modded.end();         l = lower_bound(beg, end, (1 << i) - modded[j]) - modded.begin();         r = lower_bound(beg, end, (1 << (i + 1)) - modded[j]) - modded.begin();         cnt += (r - l);         l = lower_bound(beg, end, (1 << (i + 1)) + (1 << i) - modded[j]) -             modded.begin();         r = upper_bound(beg, end, (1 << (i + 2)) - 2 - modded[j]) -             modded.begin();         cnt += (r - l);       }       if (cnt & 1) {         res |= (1 << i);       }     }     cout << res <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int TRIE[200005 * 32 * 2][2];   int isword[200005 * 32 * 2];   int nxt;   void ins(string &s) {     int v = 0;     for (int i = 0; i < s.size(); i++) {       if (TRIE[v][s[i] -  0 ] == -1) TRIE[v][s[i] -  0 ] = nxt++;       isword[v]++;       v = TRIE[v][s[i] -  0 ];     }     isword[v]++;   }   void del(string &s) {     int v = 0;     int u;     for (int i = 0; i < s.size(); i++) {       if (isword[v] > 0) isword[v]--;       if (isword[v] == 0 && i > 0) TRIE[u][s[i - 1] -  0 ] = -1;       u = v;       v = TRIE[v][s[i] -  0 ];     }     if (isword[v] > 0) isword[v]--;     if (isword[v] == 0) TRIE[u][s[31] -  0 ] = -1;   }   string bin(int a) {     string k =   ;     while (a) {       k += to_string(a % 2);       a /= 2;     }     int u = k.length();     for (int i = 0; i < 32 - u; i++) k +=  0 ;     reverse(k.begin(), k.end());     return k;   }   long long int query(string &s) {     int v = 0;     string k =   ;     for (int i = 0; i < s.size(); i++) {       if (TRIE[v][1 - (s[i] -  0 )] != -1) {         v = TRIE[v][1 - (s[i] -  0 )];         if (s[i] ==  0 )           k +=  1 ;         else           k +=  0 ;       } else {         v = TRIE[v][s[i] -  0 ];         k += s[i];       }     }     long long int val = 0, bit;     for (int i = 0; i <= 31; i++) {       bit = (s[i] == k[i]) ? 0 : 1;       val <<= 1;       val += bit;     }     return val;   }   int main() {     memset(isword, 0, sizeof(isword));     memset(TRIE, -1, sizeof(TRIE));     isword[0] = 1;     nxt = 1;     int q, a;     string s;     cin >> q;     string k = bin(0);     ins(k);     for (int i = 0; i < q; i++) {       cin >> s >> a;       string k = bin(a);       if (s ==  + )         ins(k);       else if (s ==  - )         del(k);       else         cout << query(k) << endl;     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC optimize( Ofast )   using namespace std;   int seg[800006][16], x[800006], n, m, t, p, T, ans, pc, L, R, k;   vector<int> v;   inline int gt(int a, int b) {     int k1 = (pow(10, b));     int k2 = (pow(10, b - 1));     if ((k1 % 10) == 9) k1++;     if ((k2 % 10) == 9) k2++;     return ((a % k1) / (k2));   }   inline int Build_Segtree(int h, int l, int r) {     if (l > r) return 0;     if (l > R) return seg[h][k];     if (r < L) return seg[h][k];     if (l == r) {       if (gt(x[l], k))         return seg[h][k] = l;       else         return seg[h][k] = 0;     }     int lf = Build_Segtree(h << 1, l, ((l + r) >> 1));     int rg = Build_Segtree((h << 1) + 1, ((l + r) >> 1) + 1, r);     if (x[lf] > x[rg]) return seg[h][k] = rg;     if (x[lf] <= x[rg]) return seg[h][k] = lf;   }   inline int get(int h, int l, int r) {     if (l > r) return 0;     if (l > R) return 0;     if (r < L) return 0;     if (l >= L && r <= R) return seg[h][k];     int lf = get(h << 1, l, ((l + r) >> 1));     int rg = get((h << 1) + 1, ((l + r) >> 1) + 1, r);     if (x[lf] > x[rg]) return rg;     if (x[lf] <= x[rg]) return lf;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     for (int i = 1; i <= n; i++) {       cin >> x[i];     }     x[0] = 1999999999;     for (int j = 1; j <= 9; j++) {       L = 1;       R = n;       k = j;       Build_Segtree(1, 1, n);     }     for (int i = 1; i <= m; i++) {       int q, a, b;       cin >> q >> a >> b;       if (q == 1) {         x[a] = b;         for (int j = 1; j <= 9; j++) {           L = a;           R = a;           k = j;           Build_Segtree(1, 1, n);         }       }       if (q == 2) {         ans = 1999999999;         for (int j = 1; j <= 9; j++) {           L = a;           R = b;           k = j;           t = get(1, 1, n);           p = x[t];           x[t] = 0;           L = t;           R = t;           k = j;           Build_Segtree(1, 1, n);           L = a;           R = b;           k = j;           T = get(1, 1, n);           x[t] = p;           L = t;           R = t;           k = j;           Build_Segtree(1, 1, n);           if (T) ans = min(ans, x[t] + x[T]);         }         if (ans == 1999999999) {           v.push_back(-1);         } else {           v.push_back(ans);         }       }     }     for (int i = 0; i < v.size(); i++) {       printf( %ld  n , v[i]);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int a, b, x, i, j, k, n;     cin >> a >> b >> x;     string s;     n = a + b;     if (a >= b) {       s =  0 ;       a -= 1;     } else {       s =  1 ;       b -= 1;     }     for (i = 1; i < n; i++) {       if (s[i - 1] ==  0  && x > 1) {         s +=  1 ;         b -= 1;         x -= 1;       } else if (s[i - 1] ==  1  && x > 1) {         s +=  0 ;         a -= 1;         x -= 1;       } else if (x == 1 && a != 0 && b != 0) {         if (s[i - 1] ==  0  && a != 0) {           s +=  0 ;           a -= 1;         } else if (s[i - 1] ==  1  && b != 0) {           s +=  1 ;           b -= 1;         }       } else if (a == 0) {         s +=  1 ;         b -= 1;       } else if (b == 0) {         s +=  0 ;         a -= 1;       }     }     cout << s << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma optimization_level 3   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   long double TL = 1.0;   bool is_tl = 0;   long long CALLS = 0;   inline bool IS() {     if (++CALLS == 1000) {       CALLS = 0;       is_tl |= clock() > (TL - 0.1) * CLOCKS_PER_SEC;     }     return is_tl;   }   template <typename T>   inline void amin(T &a, T b) {     if (a > b) a = b;   }   template <typename T>   inline void amax(T &a, T b) {     if (a < b) a = b;   }   template <typename T>   inline void print(T a) {     for (auto U : a) cout << U <<    ;     cout <<   n ;   }   const long long N = 1e6 + 7, NS = 1e3 + 7, lg = 18, sq = 550, inf = 1e9 + 7,                   mod = 1e9 + 7, SM = 1e2 + 7;   const long double eps = 1e-9;   mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());   struct edge {     long long to;     long long f;     long long c;     long long get() { return c - f; }   };   vector<edge> e;   vector<long long> v[N];   vector<pair<pair<long long, long long>, long long> > edges;   long long n, m, used[N];   void add_edge(long long a, long long b, long long c) {     v[a].push_back(e.size());     edge ed;     ed.to = b;     ed.f = 0;     ed.c = c;     e.push_back(ed);     v[b].push_back(e.size());     ed.to = a;     ed.c = 0;     e.push_back(ed);   }   long long dfs(long long x, long long f) {     if (x == n - 1) return f;     used[x] = 1;     for (auto u : v[x]) {       if (used[e[u].to] || e[u].get() <= 0) continue;       long long y = dfs(e[u].to, min(f, e[u].get()));       if (y) {         e[u].f += y;         e[u ^ 1].f -= y;         return y;       }     }     return 0;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long need;     cin >> n >> m >> need;     for (long long i = 1; i <= m; i++) {       long long a, b, c;       cin >> a >> b >> c;       a--, b--;       edges.push_back({{a, b}, c});     }     long double l = 0, r = inf, mid;     for (long long it = 0; it < 200; it++) {       mid = (l + r) / 2;       e.clear();       for (long long i = 0; i < n; i++) v[i].clear();       for (auto u : edges) {         long long a = u.first.first, b = u.first.second,                   c = (long long)((u.second + 0.) / mid);         add_edge(a, b, c);       }       long long ans = 0;       while (1) {         for (long long i = 0; i < n; i++) used[i] = 0;         long long y = dfs(0, inf);         if (!y) break;         ans += y;       }       if (ans >= need)         l = mid;       else         r = mid;     }     cout << fixed << setprecision(10);     cout << mid * (0. + need);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int t;     cin >> t;     while (t--) {       long long int n, i, j, k, l, sum = 0, g = 0, sum1 = 0, q, one, zero, k1;       cin >> n >> k1;       string s;       cin >> s;       for (i = 0; i < k1; i++) {         k = i;         q = 0;         zero = 0, one = 0;         while (k <= n - 1) {           if (s[k] ==  ? )             q++;           else if (s[k] ==  1 )             one++;           else             zero++;           k += k1;         }         if (one != 0 && zero != 0) {           g = 1;           break;         } else if (zero != 0) {           k = i;           while (k <= n - 1) {             s[k] =  0 ;             k += k1;           }         } else if (one != 0) {           k = i;           while (k <= n - 1) {             s[k] =  1 ;             k += k1;           }         }       }       for (i = 0; i < k1; i++) {         if (s[i] ==  1 )           sum++;         else if (s[i] ==  ? )           sum1++;       }       if (sum > k1 / 2)         g = 1;       else if (sum < (k1 / 2) && sum1 < ((k1 / 2) - sum))         g = 1;       if (g == 1)         cout <<  NO               <<   n ;       else         cout <<  YES               <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int x, y, z;     long long int x1, y1, z1;     cin >> x >> y >> z >> x1 >> y1 >> z1;     long long int a[6];     for (long long int i = 0; i < 6; i++) cin >> a[i];     long long int sum = 0;     if (y < 0) sum += a[0];     if (y > y1) sum += a[1];     if (x < 0) sum += a[4];     if (x > x1) sum += a[5];     if (z < 0) sum += a[2];     if (z > z1) sum += a[3];     cout << sum <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   char str[100010];   int main() {     int ans[] = {4, 0, 0, 0};     while (~scanf( %s , str)) {       int tmp = 0;       int len = strlen(str);       for (int i = 0; i < len; ++i) {         tmp = tmp * 10 + str[i] -  0 ;         tmp %= 4;       }       printf( %d n , ans[tmp]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100000];   int main() {     int n, h;     cin >> n >> h;     for (int i = 0; i < (int)(n); i++) cin >> a[i];     int head = min_element(a, a + n) - a;     sort(a, a + n);     int ret1 = max(a[0] + a[n - 1] + h, a[n - 1] + a[n - 2]) -                min(a[1] + a[2], a[0] + a[1] + h);     int ret2 = (a[n - 1] + a[n - 2]) - (a[0] + a[1]);     cout << min(ret1, ret2) << endl;     if (ret1 < ret2) {       for (int i = 0; i < (int)(n); i++) {         if (i == head)           cout <<  2  ;         else           cout <<  1  ;       }     } else {       for (int i = 0; i < (int)(n); i++) cout <<  1  ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const double eps = 1e-9;   const long long INF = 100000000000000000;   const int MAXN = 3 * 100000;   struct T {     int left, right, diff;     bool operator>(const T& other) {       if (diff != other.diff) return diff < other.diff;       return left < other.left;     }     bool operator<(const T& other) const {       if (diff != other.diff) return diff > other.diff;       return left > other.left;     }   };   priority_queue<T> q;   vector<pair<int, int> > ans;   char s[MAXN];   bool u[MAXN];   int a[MAXN];   int l[MAXN];   int r[MAXN];   int n;   int main() {     cin >> n;     scanf( %s , s);     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);       l[i] = i - 1;       r[i] = i + 1;       if (i + 1 == n) r[i] = -1;     }     for (int i = 0; i < n - 1; ++i)       if (s[i] != s[i + 1]) {         T t;         t.left = i;         t.right = i + 1;         t.diff = abs(a[i] - a[i + 1]);         q.push(t);       }     while (!q.empty()) {       int left = q.top().left;       int right = q.top().right;       q.pop();       if (u[left] || u[right]) continue;       u[left] = u[right] = true;       ans.push_back(pair<int, int>(left + 1, right + 1));       left = l[left];       right = r[right];       if (left != -1) r[left] = right;       if (right != -1) l[right] = left;       if (left != -1 && right != -1 && s[left] != s[right]) {         T t;         t.left = left;         t.right = right;         t.diff = abs(a[left] - a[right]);         q.push(t);       }     }     cout << ans.size() << endl;     for (int i = 0; i < (long long)(ans).size(); ++i) {       printf( %d %d n , ans[i].first, ans[i].second);     }   }