malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int inf = (int)1.01e9;   const long long infll = (long long)1.01e18;   const long double eps = 1e-9;   const long double pi = acos((long double)-1);   mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count());   int rnd(int x) { return mrand() % x; }   void precalc() {}   const int maxn = (int)1e5 + 5;   int n, m;   vector<int> g[maxn];   bool read() {     if (scanf( %d%d , &n, &m) < 2) {       return false;     }     for (int i = 0; i < n; i++) {       g[i].clear();     }     for (int i = 0; i < m; i++) {       int v, u;       scanf( %d%d , &v, &u);       v--;       u--;       g[v].push_back(u);     }     return true;   }   int used[maxn];   int tin[maxn], tout[maxn], t;   void dfs0(int v) {     used[v] = true;     tin[v] = t++;     for (int i = 0; i < ((int)(g[v]).size()); i++) {       int u = g[v][i];       if (!used[u]) {         dfs0(u);       }     }     tout[v] = t;   }   bool anc(int v, int u) { return tin[v] <= tin[u] && tout[u] <= tout[v]; }   int incnt[maxn];   int cnt[maxn], tov[maxn];   int go[maxn];   bool dfs1(int v) {     used[v] = true;     cnt[v] = 0;     tov[v] = v;     for (int i = 0; i < ((int)(g[v]).size()); i++) {       int u = g[v][i];       if (used[u]) {         if (!anc(u, v)) {           return false;         }         incnt[u]++;         cnt[v]++;         if (anc(u, tov[v])) {           tov[v] = u;         }       } else {         if (!dfs1(u)) {           return false;         }         cnt[v] += cnt[u];         if (anc(tov[u], tov[v])) {           tov[v] = tov[u];         }       }     }     cnt[v] -= incnt[v];     go[v] = (cnt[v] == 1 ? tov[v] : -1);     return true;   }   int good[maxn];   void dfs2(int v) {     used[v] = true;     if (go[v] == v) {       good[v] = true;     } else if (go[v] == -1) {       good[v] = false;     } else {       good[v] = good[go[v]];     }     for (int i = 0; i < ((int)(g[v]).size()); i++) {       int u = g[v][i];       if (!used[u]) {         dfs2(u);       }     }   }   vector<int> ans;   bool solve1(int s) {     for (int i = 0; i < n; i++) {       used[i] = false;     }     t = 0;     dfs0(s);     for (int i = 0; i < n; i++) {       used[i] = false;       incnt[i] = 0;     }     if (!dfs1(s)) {       return false;     }     for (int i = 0; i < n; i++) {       used[i] = false;     }     go[s] = s;     dfs2(s);     ans.clear();     for (int i = 0; i < n; i++) {       if (good[i]) {         ans.push_back(i);       }     }     if (((int)(ans).size()) * 5 < n) {       printf( -1 n );     } else {       for (int i = 0; i < ((int)(ans).size()); i++) {         printf( %d  , ans[i] + 1);       }       printf(  n );     }     return true;   }   const int K = 70;   void solve() {     for (int it = 0; it < K; it++) {       int s = rnd(n);       if (solve1(s)) {         return;       }     }     printf( -1 n );   }   int main() {     precalc();     int t;     scanf( %d , &t);     while (read()) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3fll;   const long double pi = acos(-1);   const int MOD = 1e9 + 7;   int main() {     int n;     scanf( %d , &n);     set<int> tem = {1, 5, 10, 50};     vector<int> v = {1, 5, 10, 50};     if (n == 1)       printf( %d n , (int)tem.size());     else {       int last = 0;       for (int i = 2; i <= 60; i++) {         set<int> vai;         for (int x : tem)           for (int y : v) vai.insert(x + y);         last = vai.size();         if (i == n) {           printf( %d n , (int)vai.size());           return 0;         }         tem = vai;       }       cout << (((long long)n - 60) * 49 + last) << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   T abs(T x) {     return x > 0 ? x : -x;   }   int n;   int m;   string s[30];   string ans[30];   string sans[30];   vector<pair<int, int> > v[30];   int get(char c) {     if (c <=  B )       return c -  A ;     else       return c -  a  + 2;   }   char lol(int x) {     if (x < 2)       return x +  A ;     else       return (x - 2) +  a ;   }   int t;   int was[100];   int getH(int a, int b) {     if (a > b) swap(a, b);     return (a - 48) * 7 + b - 48;   }   int check() {     t++;     for (int i = 0; i < (28); i++) {       int o = getH(ans[v[i][0].first][v[i][0].second],                    ans[v[i][1].first][v[i][1].second]);       if (was[o] == t) return 0;       was[o] = t;     }     for (int i = 0; i < (n); i++) sans[i] = ans[i];     return 1;   }   int col[15];   int xx[100], yy[100];   int o[100][100];   int go(int p, int c) {     if (p == 14) {       return check();     }     int x = xx[p];     int y = yy[p];     long long aans = 0;     for (int cc = 0; cc <= c; cc++) {       if (col[cc] < 2) {         col[cc]++;         ans[x][y] = ans[x + 1][y] = ans[x][y + 1] = ans[x + 1][y + 1] =             char(cc + 48);         aans += go(p + 1, min(max(cc + 1, c), 6));         col[cc]--;       }     }     return aans;   }   int main() {     cin >> n >> m;     for (int i = 0; i < (n); i++) {       cin >> s[i];       ans[i] = s[i];     }     int pp = 0;     for (int i = 0; i < (n); i++)       for (int j = 0; j < (m); j++)         if (s[i][j] !=  . ) {           if (!o[i][j]) {             xx[pp] = i;             yy[pp] = j;             o[i][j] = o[i + 1][j] = o[i][j + 1] = o[i + 1][j + 1] = 1;             pp++;           }           v[get(s[i][j])].push_back(make_pair(i, j));         }     long long aans = go(0, 0);     cout << aans * 5040 << endl;     for (int i = 0; i < (n); i++) cout << sans[i] << endl;     return 0;   }
#include<bits/stdc++.h>   #define ll long long   using namespace std;      int main() {       ll T,N,K,i,j,k,l,ans;       string S;       cin>>T;       while (T--)       {           cin>>N>>K;           cin>>S;           ans=1;           for(i=0;S[i]!= * ;i++);           for(j=S.length()-1;S[j]!= * ;j--);           if(i!=j)           {               ans++;           }           for(k=i+1;k<=j;k++)           {               if(k-i>K)               {                   ans++;                   i=l;               }               if(S[k]== * )               {                   l=k;               }           }           cout<<ans<<endl;       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MaxN = 5010;   int N, l, r;   long long ans;   int main() {     scanf( %d%d , &N, &l);     r = l;     for (int i = 1, __end = N; i <= __end; ++i) {       int u, v;       scanf( %d%d , &u, &v);       if (max(l, u) <= min(r, v)) {         l = max(l, u);         r = min(r, v);       } else if (v < l) {         ans += l - v;         r = l;         l = v;       } else if (r < u) {         ans += u - r;         l = r;         r = u;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:100000000 )   using namespace std;   int n;   char s[2000][2001];   bool A[2000][2000];   int C[2][2000];   int Z[2][2000];   bool F(int x, int y) { return (x >= 0 && y >= 0 && x < n && y < n); }   int main() {     cin >> n;     for (int(i) = (0); (i) < (n); ++(i)) {       scanf( %s , s[i]);       for (int(j) = (0); (j) < (n); ++(j))         if (s[i][j] ==  1 ) A[i][j] = 1;     }     int res = 0;     for (int(ii) = (n)-1; (ii) >= (1); --(ii)) {       int i = ii, j = 0;       while (F(i, j)) {         int p = C[0][j] + C[1][i];         p %= 2;         if (p != A[i][j]) {           res++;           C[0][j]++;           C[1][i]++;         }         i++;         j++;       }     }     for (int(jj) = (n)-1; (jj) >= (1); --(jj)) {       int j = jj, i = 0;       while (F(i, j)) {         int p = Z[0][j] + Z[1][i];         p %= 2;         if (p != A[i][j]) {           res++;           Z[0][j]++;           Z[1][i]++;         }         i++;         j++;       }     }     for (int(i) = (0); (i) < (n); ++(i)) {       int p = C[0][i] + C[1][i] + Z[0][i] + Z[1][i];       p %= 2;       if (p != A[i][i]) res++;     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   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 = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int n, m, ans, ans1, ans2, ans3, ans4;   vector<int> e[5005];   queue<int> q;   int d[3005][3005];   int f[3005][3], g[3005][3];   void get(int x) {     q.push(x);     for (int i = 1; i <= n; i++) d[x][i] = 1000000000;     d[x][x] = 0;     while (!q.empty()) {       int t = q.front();       q.pop();       for (int i = 0; i < e[t].size(); i++)         if (d[x][e[t][i]] == 1000000000) {           d[x][e[t][i]] = d[x][t] + 1;           q.push(e[t][i]);         }     }   }   void pre(int x) {     for (int i = 1; i <= n; i++) {       int t = i;       for (int j = 0; j < 3; j++) {         int p = f[x][j];         if (d[p][x] < d[t][x] && d[t][x] != 1000000000) swap(f[x][j], t);       }       t = i;       for (int j = 0; j < 3; j++) {         int p = g[x][j];         if (d[x][p] < d[x][t] && d[x][t] != 1000000000) swap(g[x][j], t);       }     }   }   void solve(int u, int v) {     if (d[u][v] == 1000000000) return;     for (int i = 0; i < 3; i++)       for (int j = 0; j < 3; j++) {         int p1 = f[u][i], p2 = g[v][j];         if (p1 == 0 || p2 == 0) continue;         if (p1 != p2 && p1 != v && p2 != u &&             d[p1][u] + d[u][v] + d[v][p2] > ans) {           ans = d[p1][u] + d[u][v] + d[v][p2];           ans1 = p1, ans2 = u, ans3 = v, ans4 = p2;         }       }   }   int main() {     n = read();     m = read();     for (int i = 1; i <= m; i++) {       int u, v;       u = read();       v = read();       e[u].push_back(v);     }     for (int i = 1; i <= n; i++) get(i);     for (int i = 1; i <= n; i++) pre(i);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         if (i != j) solve(i, j);     cout << ans1 <<     << ans2 <<     << ans3 <<     << ans4 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100501;   struct bor {     int a[27];   };   bor q[maxn];   int free1 = 0;   void add(string &s, int pos, int i) {     if (pos == (int)s.size()) {       return;     }     if (q[i].a[s[pos] -  a  + 1] == 0) {       free1++;       q[i].a[s[pos] -  a  + 1] = free1;     }     add(s, pos + 1, q[i].a[s[pos] -  a  + 1]);     return;   }   bool u[2 * maxn];   bool was[2 * maxn];   bool dfs(int i) {     u[i] = true;     was[i] = false;     int y = 0;     int t = 0;     for (int j = 1; j < 27; j++) {       int r = q[i].a[j];       if (r != 0) {         y++;         if (dfs(r) == true) {           t++;         }         if (was[r] == false) {           was[i] = true;           if (i == 0) {           }         }       }     }     if (y == 0) {       was[i] = true;     }     if (t == y) {       u[i] = false;     }     return u[i];   }   int main() {     int n, k;     cin >> n >> k;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       add(s, 0, 0);     }     bool q = dfs(0);     if (q == false) {       cout <<  Second ;     } else {       if (was[0] == true) {         cout <<  First ;       } else if (k % 2 == 0) {         cout <<  Second ;       } else         cout <<  First ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool cmp(pair<pair<long long int, long long int>, long long int> a,            pair<pair<long long int, long long int>, long long int> b) {     if (a.first.first != b.first.first)       return a.first.first < b.first.first;     else       return a.first.second < b.first.second;   }   long long int n, m, k1;   long long int re[2 * 100000 + 2];   long long int pre[2 * 100000 + 3];   bool chec(long long int x) {     long long int s = 0;     long long int c = 0;     for (long long int i = n - (x - 1); i <= n; ++i) {       s += re[i];       if (s > k1) {         c++;         s = re[i];       }     }     if (s != 0) c++;     return c <= m;   }   void machayenge() {     cin >> n >> m >> k1;     for (long long int i = 1; i <= n; ++i) {       cin >> re[i];       pre[i] = pre[i - 1] + re[i];     }     long long int i = 0;     long long int j = n;     while (i < j) {       long long int mid = (i + j + 1) / 2;       if (chec(mid)) {         i = mid;       } else         j = mid - 1;     }     cout << i;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(0);     machayenge();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[110];   int gcd(int x, int y) {     if (!x)       return y;     else       return gcd(y % x, x);   }   int main() {     int n, mx = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       mx = max(mx, a[i]);     }     int g = a[0];     for (int i = 1; i < n; i++) g = gcd(g, a[i]);     if ((mx / g - n) % 2 == 1)       cout <<  Alice  << endl;     else       cout <<  Bob  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<long long> cnt(1e5 + 2, 0), dp(1e5 + 2, 0);     while (n--) {       long long x;       cin >> x;       cnt[x]++;     }     dp[1] = cnt[1];     for (int i = 2; i < 1e5 + 2; i++) {       dp[i] = max(dp[i - 1], dp[i - 2] + cnt[i] * i);     }     cout << dp[1e5 + 1] << endl;   }
#include <bits/stdc++.h>   using namespace std;   inline void read(int &x) {     int v = 0, f = 1;     char c = getchar();     while (!isdigit(c) && c !=  - ) c = getchar();     if (c ==  - )       f = -1;     else       v = (c & 15);     while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);     x = v * f;   }   inline void read(long long &x) {     long long v = 0ll, f = 1ll;     char c = getchar();     while (!isdigit(c) && c !=  - ) c = getchar();     if (c ==  - )       f = -1;     else       v = (c & 15);     while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);     x = v * f;   }   inline void readc(char &x) {     char c;     while (((c = getchar()) ==    ) || c ==   n )       ;     x = c;   }   int n, m, i, j, dp[18][1 << 18][2][2], w[524289];   void upd(int &x, int y) { x = max(x, y); }   int main() {     read(n);     read(m);     for (((i)) = (1); ((i)) <= ((m)); ((i))++) {       int x;       read(x);       x--;       w[x] = 1;     }     memset((dp), (-(0x16)), (sizeof((dp))));     for (((i)) = (0); ((i)) <= (((1 << (n - 1))) - 1); ((i))++) {       dp[1][i][w[i * 2]][w[i * 2 + 1]] = w[i * 2] | w[i * 2 + 1];       dp[1][i][w[i * 2 + 1]][w[i * 2]] = w[i * 2] | w[i * 2 + 1];     }     for (i = 2; i <= n; i++) {       int all = (1 << (n - i));       for (j = 0; j < all; j++) {         int a, b, c, d;         for (((a)) = (0); ((a)) <= ((2) - 1); ((a))++)           for (((b)) = (0); ((b)) <= ((2) - 1); ((b))++)             for (((c)) = (0); ((c)) <= ((2) - 1); ((c))++)               for (((d)) = (0); ((d)) <= ((2) - 1); ((d))++) {                 int t = dp[i - 1][j * 2][a][b] + dp[i - 1][j * 2 + 1][c][d];                 upd(dp[i][j][a | c][b | d], t + ((b | d) * 2 + (a | c)));                 if (a | c)                   upd(dp[i][j][a + c - 1][1], t + ((b | d) + (a | c) + 1));               }       }     }     int mx = 0;     for (((i)) = (0); ((i)) <= ((2) - 1); ((i))++)       for (((j)) = (0); ((j)) <= ((2) - 1); ((j))++) {         upd(mx, dp[n][0][i][j] + (i | j));       }     cout << mx << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int m;     cin >> s >> m;     while (m--) {       int l, r, k;       cin >> l >> r >> k;       int init = l - 1;       int len = r - l + 1;       string ns = s;       for (int i = init; i < r; i++) {         int pos = init + (i - init + k) % len;         ns[pos] = s[i];       }       s = ns;     }     cout << s << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long long maxn = 1e5 + 7;   long long n, m, a[maxn], b[maxn];   vector<long long> vt[100];   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (long long i = 1; i <= n; i++) {       cin >> b[i];       long long gau = b[i];       long long dem = 0;       while (gau > 0) {         gau >>= 1;         dem++;       }       vt[--dem].push_back(b[i]);     }     bool d = true;     long long gau = 0;     for (long long i = 1; i <= n; i++) {       if (!d) return cout <<  No , 0;       d = false;       for (long long j = 0; j <= 61; j++) {         if (((gau >> j) & 1) != 0 || vt[j].empty()) continue;         gau ^= vt[j].back();         a[i] = vt[j].back();         vt[j].pop_back();         d = true;         break;       }     }     if (!d) return cout <<  No , 0;     cout <<  Yes  <<   n ;     for (long long i = 1; i <= n; i += 1) cout << a[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   string str[N];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> str[i];     }     for (int i = 0; i < ((int)(str[0]).size()); i++) {       bool all = true;       char only = 0;       for (int j = 0; j < n; j++) {         if (str[j][i] ==  ? ) continue;         all = false;         if (only == 0)           only = str[j][i];         else if (only != 0 && str[j][i] != only)           only = -1;       }       if (all) {         printf( a );       } else if (only != -1) {         printf( %c , only);       } else {         printf( ? );       }     }     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1000 * 1000 * 1000;   const int maxn = 20;   int n, sz[maxn + maxn], ans, d[maxn + maxn][(1 << maxn)];   vector<int> g[maxn + maxn][26];   bool was[maxn + maxn][(1 << maxn)];   char a[maxn][maxn];   int calc(int v, int mask) {     if (was[v][mask]) return d[v][mask];     was[v][mask] = true;     if (v == n + n - 2) return 0;     if (v % 2)       d[v][mask] = -inf;     else       d[v][mask] = inf;     int lmask, cur;     for (int i = 0; i < 26; i++) {       lmask = 0;       for (int j = 0; j < (int)g[v + 1][i].size(); j++) {         cur = min(v + 1, n - 1) - g[v + 1][i][j];         if (v > n - 2) {           if ((mask & (1 << cur))) lmask |= (1 << cur);         } else {           if (cur && (mask & (1 << (cur - 1)))) lmask |= (1 << cur);         }         if (v > n - 2) {           if ((mask & (1 << (cur + 1)))) lmask |= (1 << cur);         } else {           if (cur != sz[v + 1] - 1 && (mask & (1 << cur))) lmask |= (1 << cur);         }       }       if (!lmask) continue;       if (v % 2)         d[v][mask] = max(d[v][mask], calc(v + 1, lmask) + (!i       ? 1                                                            : i == 1 ? -1                                                                     : 0));       else         d[v][mask] = min(d[v][mask], calc(v + 1, lmask) + (!i       ? 1                                                            : i == 1 ? -1                                                                     : 0));     }     return d[v][mask];   }   int main() {     cin >> 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 + n - 1; ++i) {       int l = min(i, n - 1), r = max(0, i - n + 1);       while (l >= 0 && r < n) {         g[i][a[l][r] -  a ].push_back(l);         l--;         r++;       }       for (int j = 0; j < 26; j++) sz[i] += (int)g[i][j].size();     }     ans = calc(0, 1) + (a[0][0] ==  a  ? 1 : a[0][0] ==  b  ? -1 : 0);     if (ans)       if (ans > 0)         cout <<  FIRST ;       else         cout <<  SECOND ;     else       cout <<  DRAW ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int head[100010], to[200010], nxt[200010], cnt, d[100010];   inline void AddEdge(int u, int v) {     ++cnt, to[cnt] = v, nxt[cnt] = head[u], head[u] = cnt;   }   int mxd, mxu, f[100010];   inline void Find(int u, int p, int d) {     if (d > mxd) mxd = d, mxu = u;     f[u] = p;     for (int e = head[u]; e; e = nxt[e]) {       int v = to[e];       if (v == p) continue;       Find(v, u, d + 1);     }   }   int depnum[100010];   inline int Checkl(int u, int p) {     if (d[u] > 2) return 0;     for (int e = head[u]; e; e = nxt[e]) {       int v = to[e];       if (v == p) continue;       return Checkl(v, u);     }     return u;   }   inline bool Dfs(int u, int p, int dep) {     if (!depnum[dep] || depnum[dep] == d[u])       depnum[dep] = d[u];     else       return false;     for (int e = head[u]; e; e = nxt[e]) {       int v = to[e];       if (v == p) continue;       if (!Dfs(v, u, dep + 1)) return false;     }     return true;   }   inline void Check(int u) {     memset(depnum, 0, sizeof(depnum));     for (int e = head[u]; e; e = nxt[e])       if (!Dfs(to[e], u, 1)) return;     printf( %d n , u);     exit(0);   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; ++i) {       int u, v;       scanf( %d%d , &u, &v);       AddEdge(u, v), AddEdge(v, u);       ++d[u], ++d[v];     }     mxd = -1, Find(1, 0, 0);     int xxu = mxu;     mxd = -1, Find(mxu, 0, 0);     if (mxd & 1) {       Check(xxu), Check(mxu), printf( -1 n );       return 0;     }     for (int i = 1; i <= mxd / 2; ++i) mxu = f[mxu];     for (int e = head[mxu]; e; e = nxt[e])       if (!Checkl(to[e], mxu) && !Dfs(to[e], mxu, 1)) {         printf( -1 n );         return 0;       }     for (int e = head[mxu], l = 0; e; e = nxt[e]) {       int u = Checkl(to[e], mxu);       if (!u) continue;       if (!Dfs(to[e], mxu, 1)) {         if (l) Check(l);         Check(u), printf( -1 n );         return 0;       }       l = u;     }     printf( %d n , mxu);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool good() {     string input;     cin >> input;     stack<int> pm;     for (int i = 0; i < input.length(); i++)       if (pm.empty() || input[i] != pm.top())         pm.push(input[i]);       else         pm.pop();     return pm.empty();   }   int main() {     cout << (good() ?  Yes  :  No ) << endl;     return 0;   }