malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int T, n, i, j, k;     cin >> T;     while (T--) {       cin >> n;       string str[51];       for (i = 0; i < n; i++) {         cin >> str[i];       }       if (n == 1) {         cout <<  YES  << endl;         continue;       }       for (i = n - 1; i >= 0; i--) {         for (j = n - 1; j >= 0; j--) {           if (str[i][j] ==  1 ) {             if (i == n - 1 || j == n - 1) str[i][j] =  * ;             k = n - 1;             int c = 0;             while (k >= 0) {               if (str[k][j] ==  * ) {                 c = 1;               } else if (str[k][j] ==  1  && c == 1) {                 str[k][j] =  * ;               } else if (str[k][j] ==  0 )                 c = 0;               k--;             }             k = n - 1;             c = 0;             while (k >= 0) {               if (str[i][k] ==  * ) {                 c = 1;               } else if (str[i][k] ==  1  && c == 1) {                 str[i][k] =  * ;               } else if (str[i][k] ==  0 )                 c = 0;               k--;             }           }         }       }       for (i = n - 1; i >= 0; i--) {         for (j = n - 1; j >= 0; j--) {           if (str[i][j] ==  1 ) {             if (i == n - 1 || j == n - 1) str[i][j] =  * ;             k = n - 1;             int c = 0;             while (k >= 0) {               if (str[i][k] ==  * ) {                 c = 1;               } else if (str[i][k] ==  1  && c == 1) {                 str[i][k] =  * ;               } else if (str[i][k] ==  0 )                 c = 0;               k--;             }             k = n - 1;             c = 0;             while (k >= 0) {               if (str[k][j] ==  * ) {                 c = 1;               } else if (str[k][j] ==  1  && c == 1) {                 str[k][j] =  * ;               } else if (str[k][j] ==  0 )                 c = 0;               k--;             }           }         }       }       int cnt = 0;       for (i = 0; i < n; i++) {         for (j = 0; j < n; j++) {           if (str[i][j] ==  1 ) {             cnt++;           }         }       }       if (cnt == 0)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int a;     int b;     int idx;     int k;     int actor;     node() {}     node(int a, int b, int idx, int k, int actor)         : a(a), b(b), idx(idx), k(k), actor(actor) {}   };   const int MAXN = (int)1e5 + 5;   set<node> s;   vector<node> v;   int res[MAXN];   bool operator<(const node &x, const node &y) {     return x.b < y.b || (x.b == y.b && x.idx < y.idx);   }   bool comp(const node &x, const node &y) {     return x.a < y.a || (x.a == y.a && x.actor > y.actor);   }   int main(void) {     int n, m;     int a, b;     int c, d, k;     scanf(  %d , &n);     for (int i = 0; i < n; i++) {       scanf(  %d %d , &a, &b);       v.push_back(node(a, b, i, 0, 0));     }     scanf(  %d , &m);     for (int i = 1; i <= m; i++) {       scanf(  %d %d %d , &c, &d, &k);       v.push_back(node(c, d, i, k, 1));     }     sort(v.begin(), v.end(), comp);     int ok = 1;     for (int i = 0; i < (int)v.size(); i++) {       a = v[i].a;       b = v[i].b;       k = v[i].k;       int idx = v[i].idx;       int actor = v[i].actor;       if (actor) {         s.insert(v[i]);       } else {         v[i].idx = 0;         set<node>::iterator it = s.lower_bound(v[i]);         if (it == s.end()) {           ok = 0;         } else {           node aux = *it;           res[idx] = aux.idx;           s.erase(it);           aux.k--;           if (aux.k > 0) {             s.insert(aux);           }         }       }     }     if (ok) {       printf( YES n );       for (int i = 0; i < n; i++) {         if (i != 0) {           printf(   );         }         printf( %d , res[i]);       }     } else {       printf( NO n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000005;   int a[N], sum[N], f[N], ans[N];   int n, r, c;   char ch[N * 6];   int main() {     scanf( %d%d%d , &n, &r, &c);     for (int i = 1; i <= n; i++) {       scanf( %s , ch + sum[i - 1] + 2);       a[i] = strlen(ch + sum[i - 1] + 2);       sum[i] = sum[i - 1] + 1 + a[i];     }     for (int i = 1; i <= n; i++)       for (f[i] = max(f[i - 1], i); f[i] <= n && sum[f[i]] - sum[i - 1] - 1 <= c;            f[i]++)         ;     f[n + 1] = n + 1;     for (int i = 1; i <= n; i++) ans[i] = i;     for (; r; r >>= 1)       for (int i = 1; i <= n; i++) {         if (r & 1) ans[i] = f[ans[i]];         f[i] = f[f[i]];       }     int pos = 1;     for (int i = 2; i <= n; i++)       if (ans[i] - i > ans[pos] - pos) pos = i;     int last = 0;     for (int i = pos; i <= ans[pos] - 1; i++) {       if (last + a[i] > c) {         last = 0;         puts(  );       }       if (last) putchar(   );       last += a[i] + 1;       printf( %s , ch + sum[i - 1] + 2);     }     return 0;   }
#include <bits/stdc++.h>   inline void in(int &MAGNUS) { scanf( %d , &MAGNUS); }   inline void out(int MAGNUS) { printf( %d n , MAGNUS); }   inline void in(int &MAGNUS, int &CLAR) { scanf( %d%d , &MAGNUS, &CLAR); }   inline void out(int MAGNUS, int CLAR) { printf( %d %d n , MAGNUS, CLAR); }   inline void inl(long long &LIV) { scanf( %lld , &LIV); }   inline void inl(long long &LIV, long long &MART) {     scanf( %lld%lld , &LIV, &MART);   }   inline void outl(long long LIV) { printf( %lld n , LIV); }   inline void outl(long long LIV, long long MART) {     printf( %lld %lld n , LIV, MART);   }   using namespace std;   int R;   string s, res;   vector<string> kata;   bool ok(int C) {     int r = 1, c = 0;     for (int i = 0; i <= (int)kata.size() - 1; i++) {       if (kata[i].size() > C) return 0;       if (c + (int)kata[i].size() <= C) {         c += (int)kata[i].size();       } else {         r++;         c = 0;         c += (int)kata[i].size();       }     }     return r <= R;   }   int main() {     in(R);     getchar();     getline(cin, s);     res =   ;     for (int i = 0; i <= (int)s.size() - 1; i++) {       if (s[i] ==    ) s[i] =  . ;       res += (char)s[i];       if (!isalpha(s[i])) {         kata.push_back(res);         res =   ;       }     }     kata.push_back(res);     int lo = 1, hi = (int)s.size(), ans = 1 << 30;     while (lo <= hi) {       int mid = (lo + hi) / 2;       if (ok(mid)) {         hi = mid - 1;         ans = mid;       } else         lo = mid + 1;     }     out(ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     long long int mn, mx, noob;     cin >> t;     while (t--) {       long long int flag = 0;       cin >> mn >> mx >> noob;       if (mn > mx) swap(mx, mn);       if (noob >= mn) {         cout << mn << endl;         flag = 1;         continue;       }       long long int ans = 0;       ans = noob;       mn -= noob;       mx -= noob;       long long int p = (mx - mn);       if (p > mn)         ans += mn;       else {         ans += p;         mx -= p * 2;         mn -= p;         ans += (mn + mx) / 3;       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 15;   const int maxt = 235;   const int MOD = 1e9 + 7;   inline void upd(int &a, int b) {     a += b;     if (a >= MOD) a -= MOD;   }   int n, T;   int dp[maxt][1 << maxn][3], t[maxn], g[maxn];   int main() {     scanf( %d%d , &n, &T);     for (int(i) = (0); (i) <= ((n)-1); (i)++) {       scanf( %d%d , t + i, g + i);       g[i]--;     }     for (int(i) = (0); (i) <= ((n)-1); (i)++) dp[t[i]][1 << i][g[i]] = 1;     for (int(i) = (1); (i) <= (T - 1); (i)++)       for (int(mask) = (0); (mask) <= ((1 << n) - 1); (mask)++)         for (int(k) = (0); (k) <= ((n)-1); (k)++)           if ((mask & (1 << k)) == 0 && t[k] + i <= T)             for (int(j) = (0); (j) <= ((3) - 1); (j)++)               if (j != g[k])                 upd(dp[i + t[k]][mask | (1 << k)][g[k]], dp[i][mask][j]);     int ans = 0;     for (int(mask) = (0); (mask) <= ((1 << n) - 1); (mask)++)       for (int(i) = (0); (i) <= ((3) - 1); (i)++) upd(ans, dp[T][mask][i]);     printf( %d , ans);   }
#include <bits/stdc++.h>   using namespace std;   long long DP[100005][25];   long long arr[100005];   long long l = 1, r, ans;   long long freq[100005];   void alter_range(long long l1, long long r1) {     while (l1 < l) {       ans += freq[arr[l - 1]];       freq[arr[l - 1]]++;       l--;     }     while (r < r1) {       ans += freq[arr[r + 1]];       freq[arr[r + 1]]++;       r++;     }     while (l < l1) {       ans -= freq[arr[l]] - 1;       freq[arr[l]]--;       l++;     }     while (r1 < r) {       ans -= freq[arr[r]] - 1;       freq[arr[r]]--;       r--;     }   }   void make_layer(long long layer, long long l1, long long r1, long long a,                   long long b) {     if (l1 > r1) return;     long long i, j, mid = (l1 + r1) >> 1, &curr = DP[mid][layer], best = mid;     for (i = a; i <= min(b, mid); i++) {       alter_range(i, mid);       if (curr > DP[i - 1][layer - 1] + ans) {         curr = DP[i - 1][layer - 1] + ans;         best = i;       }     }     make_layer(layer, l1, mid - 1, a, best);     make_layer(layer, mid + 1, r1, best, b);   }   int main() {     long long i, j, n, k;     scanf( %lld %lld , &n, &k);     for (i = 1; i <= n; i++) scanf( %lld , &arr[i]);     for (i = 0; i <= n; i++)       for (j = 0; j <= k; j++) DP[i][j] = 1e18;     DP[0][0] = 0;     for (i = 1; i <= k; i++) {       make_layer(i, 1, n, 1, n);     }     printf( %lld n , DP[n][k]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5;   long long aa[N + 2], bb[N + 2];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long k1, k2, k3;     cin >> k1 >> k2 >> k3;     long long t1, t2, t3;     cin >> t1 >> t2 >> t3;     long long n;     cin >> n;     for (long long i = 1; i <= n; i++) cin >> aa[i], bb[i] = aa[i];     multiset<long long> st;     vector<long long> v;     for (long long i = 1; i <= n; i++) {       while (true) {         if (st.size() == 0) break;         long long x = *st.begin();         if (x < aa[i])           st.erase(st.find(x));         else           break;       }       if (st.size() < k1) {         st.insert(aa[i] + t1 - 1);         v.push_back(aa[i] + t1);       } else {         long long x = *st.begin();         st.erase(st.find(x));         st.insert(x + t1);         v.push_back(x + t1 + 1);       }     }     for (long long i = 1; i <= n; i++) aa[i] = v[i - 1];     v.clear();     st.clear();     for (long long i = 1; i <= n; i++) {       while (true) {         if (st.size() == 0) break;         long long x = *st.begin();         if (x < aa[i])           st.erase(st.find(x));         else           break;       }       if (st.size() < k2) {         st.insert(aa[i] + t2 - 1);         v.push_back(aa[i] + t2);       } else {         long long x = *st.begin();         st.erase(st.find(x));         st.insert(x + t2);         v.push_back(x + t2 + 1);       }     }     for (long long i = 1; i <= n; i++) aa[i] = v[i - 1];     v.clear();     st.clear();     for (long long i = 1; i <= n; i++) {       while (true) {         if (st.size() == 0) break;         long long x = *st.begin();         if (x < aa[i])           st.erase(st.find(x));         else           break;       }       if (st.size() < k3) {         st.insert(aa[i] + t3 - 1);         v.push_back(aa[i] + t3);       } else {         long long x = *st.begin();         st.erase(st.find(x));         st.insert(x + t3);         v.push_back(x + t3 + 1);       }     }     for (long long i = 1; i <= n; i++) aa[i] = v[i - 1];     v.clear();     st.clear();     long long mx = 0;     for (long long i = 1; i <= n; i++) mx = max(mx, aa[n] - bb[n]);     cout << mx << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   int main() {     int n;     scanf( %d , &n);     int q = n / 3;     int r = n % 3;     if (r > 0) {       printf( %d , 2 * q + 1);     } else {       printf( %d , 2 * q);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int a[31] = {4,   22,  27,  58,  85,  94,  121, 166, 202, 265,                274, 319, 346, 355, 378, 382, 391, 438, 454, 483,                517, 526, 535, 562, 576, 588, 627, 634, 636, 645};   int main() {     scanf( %d , &n);     printf( %d , a[n - 1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long T, n;   long long getFirst(long long n) {     long long cur = 4;     while (n > cur) {       n -= cur;       cur *= 4;     }     return cur + n - 1;   }   long long getSecond(long long n) {     long long cur = 4;     while (n > cur) {       n -= cur;       cur *= 4;     }     n--;     vector<long long> d;     while (n) {       d.push_back(n % 4);       n /= 4;     }     long long f[4] = {0, 2, 3, 1};     reverse(d.begin(), d.end());     for (auto i : d) n = n * 4ll + f[i];     return 2ll * cur + n;   }   long long getThird(long long n) { return getFirst(n) ^ getSecond(n); }   int init() {     scanf( %lld , &n);     if (n <= 3) return printf( %lld n , n), 0;     if (n % 3 == 1) return printf( %lld n , getFirst(n / 3));     if (n % 3 == 2) return printf( %lld n , getSecond(n / 3));     return printf( %lld n , getThird(n / 3 - 1));   }   int main() {     scanf( %lld , &T);     while (T--) init();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long k, a[1200000];   int n;   int main() {     cin >> a[0] >> k;     n = 0;     while ((a[n] >= k) || (a[n] < 0)) {       if (a[n] >= k) {         long long x = a[n] / k;         a[n] -= k * x;         a[++n] = -x;       } else {         long long x = (-a[n] + k - 1) / k;         a[n] += k * x;         a[++n] = x;       }     }     cout << n + 1 << endl;     for (int i = 0; i <= n; i++) cout << a[i] <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, ans = 0, ans1 = 0, ans2 = 0, tar;     cin >> n;     tar = n / 3;     string s;     cin >> s;     for (int i = 0; i < n; i++) {       int val = s[i] -  0 ;       if (val == 0)         ans++;       else if (val == 1)         ans1++;       else         ans2++;     }     for (int i = 0; tar > ans; i++) {       if (i == n) break;       if (s[i] ==  1  and tar < ans1) {         s[i] =  0 ;         ans++;         ans1--;         continue;       }       if (s[i] ==  2  and tar < ans2) {         s[i] =  0 ;         ans++;         ans2--;         continue;       }     }     for (int i = n - 1; (tar < ans1) and ans2 < tar; i--) {       if (i < 0) break;       if (s[i] ==  1 ) {         s[i] =  2 ;         ans2++;         ans1--;       }     }     for (int i = n - 1; (tar < ans) and ans2 < tar; i--) {       if (i < 0) break;       if (s[i] ==  0 ) {         s[i] =  2 ;         ans2++;         ans--;       }     }     for (int i = 0; (tar < ans2) and ans1 < tar; i++) {       if (i == n) break;       if (s[i] ==  2 ) {         s[i] =  1 ;         ans1++;         ans2--;       }     }     for (int i = n - 1; (tar < ans) and ans1 < tar; i--) {       if (i < 0) break;       if (s[i] ==  0 ) {         s[i] =  1 ;         ans1++;         ans--;       }     }     cout << s << endl;   }
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const double eps = 1e-8;   inline int sign(double x) {     if (x < -eps) return -1;     return x > eps;   }   struct Tpoint {     double x, y;     Tpoint() {}     Tpoint(double x, double y) : x(x), y(y) {}     inline double norm() { return sqrt(x * x + y * y); }     inline void rotate(double ang) {       double co = cos(ang), si = sin(ang);       double tx = x, ty = y;       x = tx * co - ty * si;       y = tx * si + ty * co;     }   };   inline Tpoint operator+(const Tpoint &a, const Tpoint &b) {     return Tpoint(a.x + b.x, a.y + b.y);   }   inline Tpoint operator-(const Tpoint &a, const Tpoint &b) {     return Tpoint(a.x - b.x, a.y - b.y);   }   inline Tpoint operator*(const Tpoint &a, const double &b) {     return Tpoint(a.x * b, a.y * b);   }   inline Tpoint operator/(const Tpoint &a, const double &b) {     return Tpoint(a.x / b, a.y / b);   }   inline double det(const Tpoint &a, const Tpoint &b) {     return a.x * b.y - a.y * b.x;   }   inline double dot(const Tpoint &a, const Tpoint &b) {     return a.x * b.x + a.y * b.y;   }   const int dx[] = {-1, -1, 1, 1};   const int dy[] = {-1, 1, -1, 1};   int main() {     int n, m, x, y;     scanf( %d%d , &n, &m);     char sdir[100];     scanf( %d%d%s , &x, &y, sdir);     int dir = 0;     if (sdir[0] ==  D ) {       dir |= 2;     }     if (sdir[1] ==  R ) {       dir |= 1;     }     int target = 0;     for (int i = 1; i <= n; ++i) {       if ((i + 1) % 2 == (x + y) % 2) {         ++target;       }       if ((i + m) % 2 == (x + y) % 2) {         ++target;       }     }     for (int i = 2; i < m; ++i) {       if ((i + 1) % 2 == (x + y) % 2) {         ++target;       }       if ((i + n) % 2 == (x + y) % 2) {         ++target;       }     }     set<pair<int, int> > visit;     long long total_time = 1;     for (int t = 0; t < (n + m) * 4; ++t) {       visit.insert(make_pair(x, y));       if ((int)visit.size() == target) {         printf( %I64d n , total_time);         return 0;       }       int l = 0, r = max(n, m) + 1;       while (l + 1 < r) {         int mid = (l + r) / 2;         int xx = x + dx[dir] * mid;         int yy = y + dy[dir] * mid;         if (xx >= 1 && xx <= n && yy >= 1 && yy <= m) {           l = mid;         } else {           r = mid;         }       }       total_time += l;       x += dx[dir] * l;       y += dy[dir] * l;       if (x == 1 || x == n) {         dir ^= 2;       }       if (y == 1 || y == m) {         dir ^= 1;       }       if (x == 1 && y == 1) {         dir = 3;       } else if (x == 1 && y == m) {         dir = 2;       } else if (x == n && y == 1) {         dir = 1;       } else if (x == n && y == m) {         dir = 0;       }     }     puts( -1 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int fs[43][2], d[20], dp[20][10], r[20][10], from[20][10];   vector<int> pos;   int main() {     memset((fs), -1, sizeof((fs)));     for (int i = 0; i <= 6; i++)       for (int j = 0; i + j <= 6; j++) {         fs[i * 7 + j * 4][0] = i;         fs[i * 7 + j * 4][1] = j;       }     for (int i = 0; i <= 42; i++) {       if (fs[i][0] != -1) pos.push_back(i);     }     int ___T, case_n = 1;     scanf( %d  , &___T);     while (___T-- > 0) {       long long n;       cin >> n;       for (int i = 0; i < 20; i++) {         d[i] = n % 10;         n /= 10;       }       memset((dp), -1, sizeof((dp)));       memset((r), 0, sizeof((r)));       dp[0][0] = 0;       for (int i = 0; i < 19; i++) {         for (int j = 0; j < 10; j++) {           if (dp[i][j] != -1) {             for (int k = 0; k < ((int)(pos).size()); k++) {               if (pos[k] % 10 == (d[i] - j + 100) % 10) {                 dp[i + 1][(j + pos[k]) / 10] = k;                 from[i + 1][(j + pos[k]) / 10] = j;               }             }           }         }       }       if (dp[19][0] != -1) {         int x = 19, y = 0;         while (x) {           int v = pos[dp[x][y]];           int cnt = 0;           for (int i = 0; i < fs[v][0]; i++) r[x - 1][cnt++] = 7;           for (int i = 0; i < fs[v][1]; i++) r[x - 1][cnt++] = 4;           y = from[x][y];           x--;         }         for (int i = 0; i < 6; i++) {           long long tmp = 0;           for (int j = 18; j >= 0; j--) tmp = tmp * 10 + r[j][i];           if (i) printf(   );           cout << tmp;         }         puts(  );       } else         puts( -1 );     }     return 0;   }
#include <bits/stdc++.h>   int main(void) {     int i, j, n, k, c = 0;     int a[100];     scanf( %d%d , &n, &k);     for (i = 0; i < n; i++) scanf( %d , &a[i]);     for (i = 0; i < n; i++) {       if (a[i] <= k) {         c++;       } else         break;     }     for (i = n - 1; i >= 0; i--) {       if (a[i] <= k) {         c++;       } else         break;     }     if (c > n) c = n;     printf( %d n , c);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long b;     while (cin >> b) {       long long ans = 0;       long long i;       for (i = 1; i * i < b; i++) {         if (b % i == 0) ans += 2;       }       if (i * i == b) ans++;       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, ans = 0, sum = 0, sum2 = 0;       cin >> n;       int a[n + 1];       a[0] = 0;       for (int i = 1; i <= n; i++) cin >> a[i];       sort(a, a + (n + 1));       for (int i = 1; i <= n; i++) {         sum = (sum, a[i]);         sum2++;         if ((ans + sum2) >= sum) {           ans += sum2;           sum2 = 0;         }       }       cout << ans + 1 << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int a[100000];   int n, k;   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     int l = 0, r = n;     while (r - l > 1) {       int m = (l + r) / 2;       if ((long long)k > (long long)m * (m + 1) / 2)         l = m;       else         r = m;     }     printf( %d , a[k - l * (l + 1) / 2 - 1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k, i, j, v, bor[100005][27], a[100005], b[100005];   string s;   void dfs(int v) {     int q = 0;     int u = 0;     int t = 0;     for (int i = 1; i < 27; i++) {       if (bor[v][i] > 0) {         q = 1;         dfs(bor[v][i]);         if (a[bor[v][i]] == 0) u = 1;         if (b[bor[v][i]] == 0) t = 1;       }     }     if (q == 0) {       a[v] = 0;       b[v] = 1;     }     if (u == 1) a[v] = 1;     if (t == 1) b[v] = 1;   }   int main() {     cin >> n >> m;     k = 1;     for (i = 1; i <= n; i++) {       cin >> s;       v = 1;       for (j = 0; j < s.length(); j++) {         int to = s[j] - 96;         if (bor[v][to] > 0)           v = bor[v][to];         else {           k++;           bor[v][to] = k;           v = k;         }       }     }     dfs(1);     if (a[1] == 1 && b[1] == 1)       cout <<  First ;     else if (a[1] == 1 && b[1] == 0 && (m % 2 == 1))       cout <<  First ;     else       cout <<  Second ;   }