malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e4 + 10, mod = 1e9 + 9, maxa = 1e6 + 100;   long long sta = 0;   const long long inf = 2e18 + 13;   long long max(long long x, long long y) { return (x > y ? x : y); }   long long min(long long x, long long y) { return (x < y ? x : y); }   long long pw(long long x, long long y) {     if (!y) {       return 1;     }     long long res = pw(x, y / 2);     res *= res;     res %= mod;     if (y & 1) {       res *= x;     }     return res % mod;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, m;     cin >> n >> m;     long long ans = 1;     for (int i = 1; i <= n; i++) {       ans = ans * (pw(2, m) - i);       ans += mod;       ans %= mod;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long K, B, N, T;   int main() {     cin >> K >> B >> N >> T;     if (K == 1 && 1 + N * B >= T) {       cout << (int)ceil((1 + N * B - T) / (1.0 * B)) << endl;       return 0;     }     if (K == 1) {       cout << 0 << endl;       return 0;     }     long long C = 1, counter = N + 1;     double thres = 1.0 * (T * (K - 1) + B) / (K - 1 + B);     for (int i = 1; i <= N; i++) {       C *= K;       if (C > thres) {         counter = i;         break;       }     }     counter--;     cout << N - counter << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char buff[100000], *pb;   int readInt() {     int num = 0;     while (*pb && isdigit(*pb)) {       num = num * 10 + (*pb -  0 );       ++pb;     }     return num;   }   int nextChar() {     int c =   0 ;     if (*pb) {       c = *pb;       pb++;     }     return c;   }   int hasNext() { return *pb ? 1 : 0; }   int main(void) {     int n;     scanf( %i n , &n);     int nextId = 1;     map<vector<int>, int> SId;     vector<int> deg(n + 1);     vector<vector<vector<int>>> S(n + 1);     vector<vector<int>> H(n + 1);     for (int i = 1; i <= n; i++) {       scanf( %s , buff);       pb = buff;       while (hasNext()) {         int k = readInt();         assert(nextChar() ==  : );         vector<int> s;         while (hasNext()) {           s.push_back(readInt());           if (nextChar() ==  - ) {             break;           }         }         assert(s.size() == k);         sort(begin(s), end(s));         S[i].push_back(s);         deg[i]++;         if (!SId.count(s)) {           SId[s] = nextId++;         }         H[i].push_back(SId[s]);       }     }     vector<vector<int>> sh = H;     for (vector<int> &s : sh) {       sort(s.begin(), s.end());     }     vector<int> from, to;     vector<int> proc(n + 1);     queue<int> Q;     for (int i = 1; i <= n; i++) {       if (deg[i] == 1) {         proc[i] = 1;         Q.push(i);       }     }     vector<int> tree_deg(n + 1);     map<int, int> root;     set<int> seen;     while (!Q.empty()) {       int u = Q.front();       Q.pop();       vector<int> sub = {u};       for (int j = 0; j < H[u].size(); j++) {         int id = H[u][j];         if (seen.count(id)) {           from.push_back(u);           to.push_back(root[id]);           tree_deg[root[id]]++;           for (auto e : S[u][j]) {             sub.push_back(e);           }         }       }       sort(begin(sub), end(sub));       int id = SId[sub];       seen.insert(id);       root[id] = u;       for (int i = 1; i <= n; i++)         if (!proc[i]) {           if (binary_search(begin(sh[i]), end(sh[i]), id)) {             deg[i]--;             if (deg[i] <= 1) {               proc[i] = 1;               Q.push(i);             }           }         }     }     bool ok = true;     for (int d : tree_deg) {       if (d > 1) {         ok = false;       }     }     if (ok && int(from.size()) == n - 1) {       printf( %i n , n - 1);       for (int i = 0; i < n - 1; i++) {         printf( %i %i n , from[i], to[i]);       }     } else {       puts( -1 );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int a, b, c, d;       cin >> a >> b >> c >> d;       if (min(a, b) + min(c, d) == max(a, b) && max(a, b) == max(c, d)) {         cout <<  YES n ;       } else {         cout <<  NO n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     ;     long long int t;     cin >> t;     while (t--) {       string s;       cin >> s;       long long int a[26] = {0};       long long int cnt = 0;       char c;       int i = 0;       while (i < s.length()) {         cnt = 0;         c = s[i];         while (s[i] == c && i < s.length()) {           cnt++;           i++;         }         if (cnt % 2 != 0) {           a[c -  a ] = 1;         }       }       string ans =   ;       for (i = 0; i < 26; i++) {         if (a[i] == 1) {           ans += (i +  a );         }       }       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int check(string st) {     int s1 = 0, s2 = 0;     for (int i = 1; i < st.length(); i++) {       if (st[i] ==  1  && i % 2 == 1) s1++;       if (st[i] ==  1  && i % 2 == 0) s2++;       if (s1 - s2 > 5 - i / 2 || (i % 2 == 1 && s2 - s1 >= 5 - i / 2) ||           (i % 2 == 0 && s2 - s1 > 5 - i / 2))         return i;     }     return 10;   };   int main() {     int t;     cin >> t;     while (t--) {       string st;       cin >> st;       st =     + st;       string sts = st;       for (int i = 1; i < st.length(); i++)         if (st[i] ==  ? )           if (i % 2 == 1)             st[i] =  1 ;           else             st[i] =  0 ;       for (int i = 1; i < sts.length(); i++)         if (sts[i] ==  ? )           if (i % 2 == 0)             sts[i] =  1 ;           else             sts[i] =  0 ;       cout << min(check(st), check(sts)) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using pii = pair<int, int>;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m, k, t;     cin >> n >> m >> k >> t;     vector<pii> waste(k);     for (int i = 0; i < k; ++i) {       cin >> waste[i].first >> waste[i].second;       --waste[i].first;       --waste[i].second;     }     sort(begin(waste), end(waste));     vector<pair<pii, int>> queries(t);     for (int i = 0; i < t; ++i) {       cin >> queries[i].first.first >> queries[i].first.second;       --queries[i].first.first;       --queries[i].first.second;       queries[i].second = i;     }     sort(begin(queries), end(queries));     vector<int> ans(t);     int ptr = 0;     for (auto& p : queries) {       pii pos = p.first;       int idx = p.second;       while (ptr < k and waste[ptr] < pos) {         ++ptr;       }       if (ptr < k and waste[ptr] == pos) {         ans[idx] = 3;       } else {         int tot = m * pos.first + pos.second;         tot -= ptr;         ans[idx] = tot % 3;       }     }     vector<string> res = { Carrots ,  Kiwis ,  Grapes ,  Waste };     for (int x : ans) cout << res[x] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     int nums[n];     for (int i = 0; i < n; i++) {       cin >> nums[i];     }     for (int i = 0; i < n - 1; i++) {       if (nums[i] < 0) {         cout <<  NO ;         return 0;       }       if (nums[i] % 2 == 1) {         nums[i + 1] -= 1;       }     }     if (nums[n - 1] >= 0 && nums[n - 1] % 2 == 0) {       cout <<  YES ;     } else {       cout <<  NO ;     }     return 0;   }
#include <bits/stdc++.h>   void rd(int &x) {     x = 0;     int f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch <=  9  && ch >=  0 ) x = x * 10 + ch -  0 , ch = getchar();     x *= f;   }   void lrd(long long &x) {     x = 0;     int f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch <=  9  && ch >=  0 ) x = x * 10 + ch -  0 , ch = getchar();     x *= f;   }   const int INF = 1e9;   const long long LINF = 1e18;   const int mod = 998244353;   const int N = 3e5 + 10;   using namespace std;   int n;   int fi[N], nxt[N << 1], to[N << 1], tot;   void link(int x, int y) {     nxt[++tot] = fi[x];     fi[x] = tot;     to[tot] = y;   }   int f[N][3];   void dfs(int x) {     f[x][0] = f[x][1] = f[x][2] = 1;     int cnt = 1;     int ghb = 1;     for (int i = fi[x]; i; i = nxt[i]) {       if (f[to[i]][0]) continue;       dfs(to[i]);       cnt = cnt * 2 % mod;       int tmp;       tmp = (1ll * f[to[i]][0] * 2 + f[to[i]][1] + f[to[i]][2]) % mod;       f[x][0] = 1ll * f[x][0] * tmp % mod;       f[x][1] = 1ll * f[x][1] * (1ll * 2 * f[to[i]][0] + f[to[i]][1]) % mod;       ghb = 1ll * ghb * (f[to[i]][0] + f[to[i]][1]) % mod;       f[x][2] = 1ll * f[x][2] * (1ll * f[to[i]][0] * 2 + f[to[i]][1]) % mod;     }     f[x][1] = (f[x][1] - ghb + mod) % mod;   }   int main() {     rd(n);     for (int i = 1; i < n; i++) {       int x, y;       rd(x);       rd(y);       link(x, y);       link(y, x);     }     dfs(1);     printf( %d n , (f[1][0] + f[1][1] - 1) % mod);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   int dr8[] = {0, 0, 1, -1, 1, 1, -1, -1};   int dc8[] = {1, -1, 0, 0, -1, 1, -1, 1};   int dr4[] = {0, 1, -1, 0};   int dc4[] = {1, 0, 0, -1};   int n;   int a[N];   set<pair<int, int> > s;   set<int> end_idx;   int sz[N];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i + 1];     }     int c = 1;     for (int i = 2; i <= n; i++) {       if (a[i] != a[i - 1]) {         s.insert({-c, i - 1});         end_idx.insert(i - 1);         sz[i - 1] = c;         c = 1;       } else         c++;     }     s.insert({-c, n});     end_idx.insert(n);     sz[n] = c;     int ans = 0;     while (!s.empty()) {       auto it = *s.begin();       s.erase(s.begin());       end_idx.erase(it.second);       ans++;       auto idx = end_idx.lower_bound(it.second);       if (idx != end_idx.begin() && idx != end_idx.end()) {         int rgt = *idx;         idx--;         int lft = *idx;         if (a[lft] == a[rgt]) {           s.erase(s.find({-sz[lft], lft}));           s.erase(s.find({-sz[rgt], rgt}));           end_idx.erase(lft);           sz[rgt] += sz[lft];           s.insert({-sz[rgt], rgt});         }       }     }     cout << ans;   }
#include <bits/stdc++.h>   char s[100][100];   int main() {     int n, m, ans = 0;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %s , s[i] + 1);     for (int i = 1; i < n; i++) {       for (int j = i + 1; j <= n; j++) {         int f = 0, g = 0;         for (int k = 1; k <= m; k++)           if (s[i][k] !=  .  || s[j][k] !=  . ) {             if (s[i][k] == s[j][k])               f = 1;             else               g = 1;           }         if (f == g && f) {           printf( No );           return 0;         }       }     }     printf( Yes );   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long n, d;       cin >> n >> d;       if (n >= d)         cout <<  YES  << endl;       else {         double i = 1, cnt = 0;         while (i <= n) {           int y = ceil(d / (i + 1)) + i;           if (y <= n) {             cout <<  YES  << endl;             ++cnt;             break;           }           ++i;         }         if (cnt == 0) cout <<  NO  << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int arr[n];       for (int i = 0; i < n; i++) cin >> arr[i];       sort(arr, arr + n);       bool flag = 1;       for (int i = 1; i < n; i++) {         if (arr[i] - arr[i - 1] > 1) {           flag = 0;         }       }       if (flag)         cout <<  Yes  << endl;       else         cout <<  No  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 100, PI = 3.14159265359, M = 1e9 + 7;   long long a[N], ans = 1;   int main() {     long long n;     cin >> n;     long long x = 0, y = 0;     for (int i = 0; i < n; i++) {       long long a, b;       cin >> a >> b;       long long t1 = a - x, t2 = b - x;       if (x == y) {         ans += min(a, b) - x;       } else if (x < y) {         if (y <= a) {           x = y;           ans += min(a, b) - x + 1;         }       } else if (x > y) {         if (x <= b) {           y = x;           ans += min(a, b) - x + 1;         }       }       x = a, y = b;     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const int maxN = 40;   int a[maxN][maxN];   int b[maxN][maxN];   int flips[maxN][maxN];   int n, x;   int check(int mask) {     memset(flips, 0, sizeof(flips));     for (int i = 0; i < x; ++i) {       if (mask & (1 << i)) {         flips[x - 1][i] = 1;       }     }     for (int i = 0; i + 1 < x; ++i) {       for (int j = 0; j < x; ++j) {         flips[i + x][j] = flips[i][j] ^ flips[x - 1][j];       }     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j + 1 < x; ++j) {         flips[i][j + x] = flips[i][j] ^ flips[i][x - 1];       }     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         b[i][j] = a[i][j];         if (flips[i][j]) {           b[i][j] = -b[i][j];         }       }     }     int res = 0;     for (int i = 0; i < n; ++i) {       res += b[x - 1][i];     }     for (int i = 0; i + 1 < x; ++i) {       for (int j = 0; j < n; ++j) {         b[i][j] += b[i + x][j];       }     }     for (int i = 0; i + 1 < x; ++i) {       int cres1 = 0, cres2 = 0;       for (int j = 0; j + 1 < x; ++j) {         cres1 += abs(b[i][j] + b[i][j + x]);         cres2 += abs(b[i][j] - b[i][j + x]);       }       res += max(cres1 + b[i][x - 1], cres2 - b[i][x - 1]);     }     return res;   }   int solve(vector<vector<int> > a) {     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         ::a[i][j] = a[i][j];       }     }     x = (n + 1) / 2;     int res = -1000000000LL;     for (int i = 0; i < (1 << x); ++i) {       res = max(res, check(i));     }     return res;   }   int main() {     scanf( %d , &n);     vector<vector<int> > a(n, vector<int>(n));     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         scanf( %d , &a[i][j]);       }     }     cout << solve(a) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long int str, in, ex, z;       cin >> str >> in >> ex;       if (str + ex - in <= 0) {         cout << 0 << endl;       } else {         if (ex + in < str) {           z = ex + 1;         } else {           z = ex;         }         if ((str + ex - in) % 2 == 0) {           cout << min(((str + ex - in) / 2), z) << endl;         } else {           cout << min((((str + ex - in) / 2) + 1), z) << endl;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, k;   long long S[1000000] = {};   int main() {     cin >> n >> k;     for (long long i = 0; i < n; i++) {       string s;       cin >> s;       S[s.size()]++;     }     string s;     cin >> s;     long long pass = s.size();     long long sum1 = 1, sum2 = 0;     for (long long i = 0; i < pass; i++) {       sum1 += S[i];       sum2 += S[i];     }     sum2 += S[pass];     cout << sum1 + ((sum1 - 1) / k) * 5 <<     << sum2 + ((sum2 - 1) / k) * 5          << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long exp(long long x, long long y, long long p) {     long long res = 1;     while (y) {       if (y % 2) res = (res * x % p) % p;       x = (x * x) % p;       y /= 2;     }     return res;   }   long long exp(long long x, long long y) {     long long res = 1;     while (y) {       if (y % 2) res = (res * x);       x = (x * x);       y /= 2;     }     return res;   }   long long a[100];   int main() {     long long n, m;     cin >> n >> m;     long long a[n];     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     if (n > m)       cout << 0 << endl;     else {       long long sum = 1;       for (long long i = 0; i < n; i++) {         for (long long j = i + 1; j < n; j++) {           sum = sum * abs(a[i] - a[j]);           sum = sum % m;         }       }       cout << sum % m;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 500010;   int A[N];   const int S = 250;   int sum[S][S];   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int Q;     cin >> Q;     while (Q--) {       int t, x, y;       cin >> t >> x >> y;       if (t == 1) {         A[x] += y;         for (int m = 1; m < S; m++) {           sum[m][x % m] += y;         }       } else {         int ans = 0;         if (x < S) {           ans = sum[x][y];         } else {           for (int i = y; i < N; i += x) {             ans += A[i];           }         }         cout << ans <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Point {    public:     int x, y;     bool operator<(const Point &a) const {       if (x != a.x) return x < a.x;       return y < a.y;     }   } tem;   set<Point> p;   set<int> xSet;   set<int> ySet;   bool f() {     if (xSet.size() != 3 || ySet.size() != 3 || p.size() != 8) return false;     set<int>::iterator p1;     set<int>::iterator p2;     int cn = 0;     for (p1 = xSet.begin(); p1 != xSet.end(); p1++) {       for (p2 = ySet.begin(); p2 != ySet.end(); p2++) {         cn++;         if (cn == 5) continue;         tem.x = *p1;         tem.y = *p2;         if (p.find(tem) == p.end()) return false;       }     }     return true;   }   int main(int argc, char **argv) {     int i, a, b;     for (i = 0; i < 8; i++) {       scanf( %d%d , &a, &b);       tem.x = a;       tem.y = b;       xSet.insert(a);       ySet.insert(b);       p.insert(tem);     }     printf( %s n , (f() ?  respectable  :  ugly ));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> a(n);     vector<int> b(n);     string aans = string(n / 2,  1 ) + string((n + 1) / 2,  0 );     string bans = string(n / 2,  1 ) + string((n + 1) / 2,  0 );     for (int i = 0; i < n; i++) {       cin >> a[i];       cin >> b[i];     }     if (n % 2) {       if (a[n / 2] < b[n / 2])         aans[n / 2] =  1 ;       else         bans[n / 2] =  1 ;     }     int bpoint = 0;     int apoint = 0;     for (int i = 0; i < n; i++) {       if (a[apoint] < b[bpoint]) {         aans[apoint] =  1 ;         apoint++;       } else {         bans[bpoint] =  1 ;         bpoint++;       }     }     cout << aans <<   n  << bans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string str;     int c1, c2, c3;     c1 = c2 = c3 = 0;     cin >> str;     for (int i = 0; i < str.length(); i++) {       if (str[i] ==  + ) {         str.erase(i, 1);         i--;       }     }     for (int i = 0; i < str.length(); i++) {       if (str[i] ==  1 )         c1++;       else if (str[i] ==  2 )         c2++;       else         c3++;     }     if (c1 == 0) {       if (c2 == 0) {         if (c3 == 0)           cout <<   ;         else {           cout <<  3 ;           for (int i = 0; i < c3 - 1; i++) {             cout <<  +3 ;           }         }       } else {         if (c3 == 0) {           cout <<  2 ;           for (int i = 0; i < c2 - 1; i++) {             cout <<  +2 ;           }         } else {           cout <<  2 ;           for (int i = 0; i < c2 - 1; i++) {             cout <<  +2 ;           }           for (int i = 0; i < c3; i++) {             cout <<  +3 ;           }         }       }     } else {       cout <<  1 ;       for (int i = 0; i < c1 - 1; i++) {         cout <<  +1 ;       }       if (c2 == 0) {         if (c3 == 0)           cout <<   ;         else {           for (int i = 0; i < c3; i++) {             cout <<  +3 ;           }         }       } else {         if (c3 == 0) {           for (int i = 0; i < c2; i++) {             cout <<  +2 ;           }         } else {           for (int i = 0; i < c2; i++) {             cout <<  +2 ;           }           for (int i = 0; i < c3; i++) {             cout <<  +3 ;           }         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const int dx[8] = {0, -1, 0, 1, -1, -1, 1, 1},             dy[8] = {1, 0, -1, 0, -1, 1, -1, 1};   int a[100005];   int cnt = 0;   int n, m, k;   vector<int> vt[100005], vt2[2];   stack<int> st;   int dfn[100005], color[100005];   void dfs(int x, int fa) {     st.push(x);     dfn[x] = st.size();     for (int i = 0; i < vt[x].size(); i++) {       int v = vt[x][i];       if (v == fa) continue;       if (!dfn[v]) {         dfs(v, x);       } else if (dfn[x] - dfn[v] + 1 <= k && dfn[x] > dfn[v]) {         cout << 2 << endl;         cout << dfn[x] - dfn[v] + 1 << endl;         while (1) {           cout << st.top() <<    ;           if (st.top() == v) {             exit(0);           }           st.pop();         }       }     }     st.pop();   }   void dfs2(int x, int fa, int co) {     vt2[co].push_back(x);     color[x] = co;     if (vt2[co].size() == k) {       for (int i = 0; i < vt2[co].size(); i++) {         cout << vt2[co][i] <<    ;       }       exit(0);     }     for (int i = 0; i < vt[x].size(); i++) {       int v = vt[x][i];       if (v == fa || color[v] != -1) continue;       dfs2(v, x, co ^ 1);     }   }   void solve() {     memset(color, -1, sizeof color);     cin >> n >> m >> k;     for (int i = 1; i <= m; i++) {       int x, y;       cin >> x >> y;       vt[x].push_back(y);       vt[y].push_back(x);     }     dfs(1, 0);     k = (k + 1) / 2;     cout << 1 << endl;     dfs2(1, 0, 0);   }   int main() {     ios::sync_with_stdio(0);     ;     solve();     return 0;   }