malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   void solve() {     string s;     cin >> s;     vector<vector<ll>> cnt(2, vector<ll>(2, 0));     ll e = 0, o = 0;     for (int i = 0; i < s.size(); i++) {       o++;       if (i % 2 == 0) {         o += cnt[s[i] -  a ][0];         e += cnt[s[i] -  a ][1];         cnt[s[i] -  a ][0]++;       } else {         e += cnt[s[i] -  a ][0];         o += cnt[s[i] -  a ][1];         cnt[s[i] -  a ][1]++;       }     }     cout << e <<     << o <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int t = 1;     for (int i = 1; i <= t; i++) {       solve();     }     return EXIT_SUCCESS;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     for (int tt = 0; tt < int(t); tt++) {       int a, b, c, r;       cin >> a >> b >> c >> r;       int L = max(min(a, b), c - r);       int R = min(max(a, b), c + r);       cout << max(a, b) - min(a, b) - max(0, R - L) << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e3 + 5;   int a[maxn][maxn];   int col[maxn];   int deg[maxn];   bool vis[maxn];   int n;   void recurse() {     int piv = -1;     for (int i = 1; i <= n; i++) {       if (vis[i]) continue;       if (deg[i] % 2 == 1) {         piv = i;         break;       }     }     if (piv == -1) {       for (int i = 1; i <= n; i++) {         if (vis[i]) continue;         col[i] = 0;       }       return;     }     vis[piv] = true;     vector<int> adj;     for (int i = 1; i <= n; i++) {       if (vis[i]) continue;       if (a[piv][i] == 1) {         a[piv][i] = a[i][piv] = 0;         adj.push_back(i);         deg[i] -= 1;       }     }     for (auto i : adj) {       for (auto j : adj) {         if (i == j) continue;         if (a[i][j] == 1) {           a[i][j] = 0;           deg[i] -= 1;         } else {           a[i][j] = 1;           deg[i] += 1;         }       }     }     recurse();     int cnt[] = {0, 0};     for (int i : adj) {       cnt[col[i]] += 1;     }     col[piv] = cnt[0] % 2 == 0 ? 0 : 1;   }   void solve() {     int m;     cin >> n >> m;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) a[i][j] = 0;     memset(deg, 0, sizeof deg);     memset(vis, false, sizeof vis);     for (int i = 1; i <= m; i++) {       int p, q;       cin >> p >> q;       a[p][q] = a[q][p] = 1;       deg[p] += 1;       deg[q] += 1;     }     recurse();     cout << *max_element(col + 1, col + n + 1) + 1 << endl;     for (int i = 1; i <= n; i++) cout << 1 + col[i] <<    ;     cout << endl;   }   int main() {     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     cin >> q;     while (q--) {       int n, h;       cin >> h >> n;       int a[n];       for (int i = 0; i < n; ++i) cin >> a[i];       int cnt = 1;       vector<int> v;       for (int i = 1; i < n; ++i) {         if (a[i] == a[i - 1] - 1) {           ++cnt;         } else {           v.push_back(cnt);           cnt = 1;         }       }       v.push_back(cnt);       int sm = 0;       if (v.size() == 1) {         if (a[n - 1] < 2)           sm = 0;         else {           if (v[0] % 2 == 0)             sm = 1;           else             sm = 0;         }       } else {         for (int i = 0; i < v.size(); ++i) {           if (i == 0) {             if (v[i] % 2 == 0) ++sm;           } else if (i == v.size() - 1) {             ++v[i];             if (a[n - 1] >= 2 && v[i] % 2 == 0) ++sm;           } else {             ++v[i];             if (v[i] % 2 == 0) ++sm;           }         }       }       cout << sm << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   string a, ans;   int b;   string c;   int main() {     while (cin >> a >> b) {       for (int i = 0; i < a.size(); i++)         if (a[i] >=  A  && a[i] <=  Z ) a[i] = a[i] -  A  +  a ;       for (int i = 0; i < a.size(); i++) {         if ((int)a[i] < b + 97) {           a[i] = a[i] -  a  +  A ;         }       }       cout << a << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double eps = 1e-9;   const int inf = (1 << 30) - 1;   const long long inf64 = ((long long)1 << 62) - 1;   const long double pi = 3.1415926535897932384626433832795;   template <class T>   T sqr(T x) {     return x * x;   }   template <class T>   T abs(T x) {     return x < 0 ? -x : x;   }   const int MAXN = 310000;   int a[MAXN], ind[MAXN], ind_cut[MAXN];   long long sum[MAXN];   bool comp(int ind1, int ind2) {     return ((a[ind1] < a[ind2]) || (a[ind1] == a[ind2] && ind1 < ind2));   }   int main() {     int n;     cin >> n;     sum[0] = 0;     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);       sum[i + 1] = (a[i] > 0 ? sum[i] + a[i] : sum[i]);       ind[i] = i;     }     sort(ind, ind + n, comp);     int i = 0;     int ind_l, ind_r;     long long max_sum = -2 * inf;     ind[n] = n;     a[n] = inf;     while (i < n) {       int j = i;       while (a[ind[j + 1]] == a[ind[i]]) j++;       long long temp = sum[ind[j]] - sum[ind[i] + 1] + 2 * a[ind[i]];       if (j > i && temp > max_sum) {         max_sum = temp;         ind_l = ind[i];         ind_r = ind[j];       }       i = j + 1;     }     int num = 0;     for (int i = 0; i < ind_l; ++i) {       ind_cut[num] = i + 1;       num++;     }     for (int i = ind_l + 1; i < ind_r; ++i) {       if (a[i] < 0) {         ind_cut[num] = i + 1;         num++;       }     }     for (int i = ind_r + 1; i < n; ++i) {       ind_cut[num] = i + 1;       num++;     }     cout << max_sum <<     << num << endl;     for (int i = 0; i < num; ++i) {       cout << ind_cut[i] <<    ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[1005];   long long int p[1005], f[1005], d;   long long int power(long long int a, long long int b) {     if (b == 0) return 1;     if (b == 1) return a % 998244353;     long long int c = power(a, b / 2);     if (b & 1)       return (((c * c) % 998244353) * a) % 998244353;     else       return (c * c) % 998244353;   }   long long int ret(int a, int b) {     long long int c = f[a];     c *= power(f[b], 998244353 - 2);     c %= 998244353;     c *= power(f[a - b], 998244353 - 2);     return c % 998244353;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     f[0] = 1;     for (int i = 1; i < 1005; i++) {       f[i] = i * f[i - 1];       f[i] %= 998244353;     }     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     p[n + 1] = 1;     for (int i = n; i > 0; i--) {       p[i] = p[i + 1];       for (int j = i + a[i]; j <= n && a[i] > 0; j++) {         d = ret(j - i - 1, a[i] - 1);         p[i] += d * p[j + 1];         p[i] %= 998244353;       }     }     cout << ((p[1] + 998244353 - 1) % 998244353);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int c, hr, hb, wr, wb;     cin >> c >> hr >> hb >> wr >> wb;     long long int ret = 0, ret1 = 0;     int cnt = 0;     for (long long int i = 0; i <= (c / wr); i++) {       long long int r = i * wr;       long long int l = c - r;       long long int b = l / wb;       ret1 = i * hr + b * hb;       ret = max(ret, ret1);       cnt++;       if (cnt > 1e7) break;     }     cnt = 0;     for (long long int i = 0; i <= (c / wb); i++) {       long long int r = i * wb;       long long int l = c - r;       long long int b = l / wr;       ret1 = i * hb + b * hr;       ret = max(ret, ret1);       cnt++;       if (cnt > 1e7) break;     }     cout << ret << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   set<int> st;   int n;   long long w[4] = {1, 5, 10, 50};   bool vis[1280][105000];   void doit(int i, int s) {     if (i == n) {       st.insert(s);       return;     }     if (vis[i][s]) return;     vis[i][s] = 1;     for (int j = 0; j < 4; j++) doit(i + 1, w[j] + s);   }   long long ans[12] = {0, 4, 10, 20, 35, 56, 83, 116, 155, 198, 244, 292};   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     if (n <= 11)       cout << ans[n] << endl;     else       cout << ans[11] + (n - 11) * 49LL << endl;     ;   }
#include <bits/stdc++.h>   using namespace std;   long long mi, ma, n, d, k, l, r, mid, a[500007], b[500007], cnt[500007];   inline long long read() {     long long s = 0, w = 1;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) w = -1;     for (; isdigit(c); c = getchar()) s = (s << 3) + (s << 1) + (c ^ 48);     return (s * w);   }   inline bool check() {     long long num = 0, sum = 0;     for (int i = 1; i <= n; i++) {       long long delta = mid - cnt[i] - b[i] - sum;       if (delta <= 0) {         sum = sum + b[i];         continue;       }       num = num + delta;       if (num > k) {         for (int j = min(i + 2 * d, n); j; j--) b[j] = 0;         return false;       }       b[i] = b[i] + delta;       if (i + 2 * d < n) b[i + 2 * d + 1] = b[i + 2 * d + 1] - delta;       sum = sum + b[i];     }     for (int i = 1; i <= n; i++) b[i] = 0;     return true;   }   int main() {     n = read(), d = read(), k = read();     mi = LLONG_MAX;     for (int i = 1; i <= n; i++) {       long long x = read();       a[max(1LL, i - d)] = a[max(1LL, i - d)] + x;       if (i + d < n) a[i + d + 1] = a[i + d + 1] - x;     }     for (int i = 1; i <= n; i++)       cnt[i] = cnt[i - 1] + a[i], ma = max(ma, cnt[i]), mi = min(mi, cnt[i]);     l = mi, r = ma + k;     while (l < r) {       mid = (l + r + 1) >> 1;       if (check())         l = mid;       else         r = mid - 1;     }     printf( %lld n , l);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[100005];   long long dp[100005];   int main() {     int n;     memset(a, 0, sizeof(a));     memset(dp, 0, sizeof(dp));     cin >> n;     int x;     for (int i = 0; i < n; i++) {       cin >> x;       a[x]++;     }     dp[1] = a[1];     dp[0] = 0LL;     for (int i = 2; i <= 100002; i++) {       dp[i] = max(dp[i - 1], dp[i - 2] + i * a[i]);     }     cout << dp[100002] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long i, j, m, n, p, q, r, s, a, b;   string aa, bb;   int main() {     cin >> n;     scanf( %ld:%ld , &a, &b);     if (n == 12) {       if (a == 0)         aa =  01 ;       else if (a >= 13) {         p = a % 10;         if (p == 0) {           aa =  10 ;         } else           aa +=  0 , aa += (a % 10 + 48);       } else {         p = a % 10;         a /= 10;         q = a % 10;         aa += (q + 48), aa += (p + 48);       }       if (b == 60)         bb =  00 ;       else if (b > 60) {         bb +=  0 , bb += (b % 10 + 48);       } else {         p = b % 10;         b /= 10;         q = b % 10;         bb += (q + 48), bb += (p + 48);       }       cout << aa <<  :  << bb;     } else {       if (a >= 24) {         aa +=  0 , aa += (a % 10 + 48);       } else {         p = a % 10;         a /= 10;         q = a % 10;         aa += (q + 48), aa += (p + 48);       }       if (b == 60)         bb =  00 ;       else if (b > 60) {         bb +=  0 , bb += (b % 10 + 48);       } else {         p = b % 10;         b /= 10;         q = b % 10;         bb += (q + 48), bb += (p + 48);       }       cout << aa <<  :  << bb;     }   }
#include <bits/stdc++.h>   using namespace std;   int solve(bool can_be_equal, const string &sa, vector<int> num_digits) {     int received = 0;     int given = 0;     int offset = can_be_equal ? 0 : 1;     for (char c : sa) {       int d = c -  0 ;       bool found = false;       for (int search = d + offset; search < 10; ++search) {         if (num_digits[search] != 0) {           num_digits[search]--;           found = true;           given++;           break;         }       }       if (!found) {         received++;         for (int search = 0; search < d + offset; ++search) {           if (num_digits[search] != 0) {             num_digits[search]--;             found = true;             break;           }         }       }     }     return can_be_equal ? received : given;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n;     string sa, sb;     cin >> sa;     cin >> sb;     vector<int> num_digits(10);     for (char c : sb) {       num_digits[c -  0 ]++;     }     cout << solve(true, sa, num_digits) << endl;     cout << solve(false, sa, num_digits) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long bigmod(long long a, int p, long long int m) {     if (p == 0) return 1;     if (p & 1) {       return ((a % m) * (bigmod(a, p - 1, m))) % m;     } else {       long long tmp = bigmod(a, p / 2, m);       return (tmp * tmp) % m;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int chu;     cin >> chu;     while (chu--) {       long long int n;       cin >> n;       long long int x;       cin >> x;       long long int a[n];       for (long long int i = 0; i < n; i++) cin >> a[i];       sort(a, a + n);       reverse(a, a + n);       long long int ans = 0;       long long int i = 0;       long long int y = 1;       for (i = 0; i < n; i++) {         if (a[i] * y >= x)           ans++, y = 1;         else           y++;       }       cout << ans;       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   int main() {     int k;     string s, st;     cin >> k >> s;     map<char, int> m;     set<char> s1;     if (s.length() % k) {       cout << -1;       return 0;     }     for (auto i = 0; i < s.length(); i++) {       if (m.find(s[i]) == m.end())         m.insert({s[i], 1});       else         m[s[i]]++;       s1.insert(s[i]);     }     for (auto i = m.begin(); i != m.end(); ++i) {       if (i->second % k) {         cout << -1;         return 0;       }     }     for (auto i = s1.begin(); i != s1.end(); ++i) {       while (m[*i] != 0) {         st += *i;         m[*i] -= k;       }     }     for (auto i = 0; i < k; i++) cout << st;   }
#include <bits/stdc++.h>   using namespace std;   template <typename _T>   inline void read(_T &f) {     f = 0;     _T fu = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) {         fu = -1;       }       c = getchar();     }     while (c >=  0  && c <=  9 ) {       f = (f << 3) + (f << 1) + (c & 15);       c = getchar();     }     f *= fu;   }   template <typename T>   void print(T x) {     if (x < 0) putchar( - ), x = -x;     if (x < 10)       putchar(x + 48);     else       print(x / 10), putchar(x % 10 + 48);   }   template <typename T>   void print(T x, char t) {     print(x);     putchar(t);   }   const int N = 105, md = 1e9 + 7;   inline int add(int x, int y) {     x += y;     if (x >= md) x -= md;     return x;   }   inline void addx(int &x, int y) {     x += y;     if (x >= md) x -= md;   }   inline int sub(int x, int y) {     x -= y;     if (x < 0) x += md;     return x;   }   inline void subx(int &x, int y) {     x -= y;     if (x < 0) x += md;   }   inline int mul(int x, int y) { return 1ll * x * y % md; }   inline int fpow(int x, int y) {     int ans = 1;     while (y) {       if (y & 1) ans = mul(ans, x);       y >>= 1;       x = mul(x, x);     }     return ans;   }   vector<int> adj[N];   int f[N][N][N], ans[N], siz[N], c[N][N], tmp[N][N];   int n;   void conv(int a[N][N], int b[N][N], int &lena, int lenb) {     for (int i = 0; i <= lena + lenb; i++) {       for (int j = 0; j <= lena + lenb; j++) tmp[i][j] = 0;     }     for (int i = 0; i <= lena; i++) {       for (int j = 0; j <= lena; j++) {         if (a[i][j] == 0) continue;         for (int x = 0; x <= lenb; x++) {           for (int y = 0; y <= lenb; y++) {             if (b[x][y] == 0) continue;             addx(tmp[i + x + 1][j], mul(mul(a[i][j], b[x][y]), y));             addx(tmp[i + x][j + y], mul(a[i][j], b[x][y]));           }         }       }     }     lena += lenb;     for (int i = 0; i <= lena; i++) {       for (int j = 0; j <= lena; j++) a[i][j] = tmp[i][j];     }   }   void dfs1(int u, int fa) {     siz[u] = 1;     f[u][0][1] = 1;     for (auto v : adj[u]) {       if (v == fa) continue;       dfs1(v, u);       conv(f[u], f[v], siz[u], siz[v]);     }   }   int main() {     read(n);     c[0][0] = 1;     for (int i = 1; i <= n; i++) {       c[i][0] = 1;       for (int j = 1; j <= i; j++) c[i][j] = add(c[i - 1][j - 1], c[i - 1][j]);     }     for (int i = 1; i < n; i++) {       int u, v;       read(u);       read(v);       adj[u].push_back(v);       adj[v].push_back(u);     }     dfs1(1, 0);     for (int i = 0; i <= n; i++) {       for (int j = 0; j <= n; j++) {         if (f[1][i][j] == 0) continue;         addx(ans[n - i - 1], mul(f[1][i][j], j));       }     }     for (int i = n - 1; i >= 0; i--) {       if (i != n - 1)         ans[i] = mul(ans[i], fpow(n, n - i - 2));       else         ans[i] = 1;       for (int j = i + 1; j <= n - 1; j++) subx(ans[i], mul(ans[j], c[j][i]));     }     for (int i = 0; i <= n - 1; i++) print(ans[i],    );     putchar(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve(int test_number);   int main() {     cout.setf(ios::fixed);     cout.precision(9);     cerr.setf(ios::fixed);     cerr.precision(3);     int n = 1;     for (int i = 0; i < n; i++) {       solve(i + 1);     }     return 0;   }   const int MAXN = 200100;   const int BUBEN = 800;   int n;   int a[MAXN];   int d[MAXN];   int nd;   bool used[BUBEN][MAXN];   int sum[BUBEN];   vector<int> q[MAXN];   int st[MAXN];   inline int gcd(int a, int b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   void solve(int test_number) {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 1; i * i <= n; i++) {       if (n % i == 0) {         d[nd++] = i;         int j = n / i;         if (i != j && j != n) d[nd++] = j;       }     }     sort(d, d + nd);     for (int j = 0; j < nd; j++) {       int step = d[j];       for (int from = 0; from < step; from++) {         int mx = a[from];         for (int i = from; i < n; i += step) {           mx = max(mx, a[i]);         }         for (int i = from; i < n; i += step) {           if (mx == a[i]) {             used[j][i] = true;           }         }       }       int last = -1;       int pref = 0;       for (int i = 0; i < n; i++)         if (used[j][i]) {           if (last == -1) last = i;         } else if (last != -1) {           if (last == 0) {             pref = i - last;           } else {             q[j].push_back(i - last);             sum[j] += i - last;           }           last = -1;         }       if (last != -1) {         pref += n - last;       }       q[j].push_back(pref);       sum[j] += pref;       sort(q[j].begin(), q[j].end());     }     long long res = 0;     for (int len = 1; len < n; len++) {       int step = gcd(len, n);       long long j = lower_bound(d, d + nd, step) - d;       while ((int)q[j].size() != st[j] && q[j][st[j]] < len) {         sum[j] -= q[j][st[j]];         st[j]++;       }       if (sum[j] == n) {         res += (long long)n;       } else {         res += (long long)sum[j] -                (long long)(len - 1) * (long long)(q[j].size() - st[j]);       }     }     cout << res << endl;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int a, b, c;       cin >> a >> b >> c;       int ans = -1;       for (int x = 0; x < a + 1; x++) {         for (int y = 0; y <= c; y += 2) {           if (y / 2 + 2 * x <= b) {             ans = max(ans, 3 * x + y + y / 2);           }         }       }       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int N, K;   int A[300005];   int DP[300005];   bool chk(int d) {     int mxp = 0;     for (int i = K; i <= N; i++) {       if (A[i] - A[DP[i - K] + 1] <= d) mxp = i;       DP[i] = mxp;     }     return mxp == N;   }   int main() {     cin >> N >> K;     for (int i = 1; i <= N; i++) cin >> A[i];     sort(A + 1, A + 1 + N);     int l = -1, r = 1e9;     while (l + 1 < r) {       int md = (l + r) / 2;       if (chk(md))         r = md;       else         l = md;     }     cout << r <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 119;   int n, F[N], T[N];   long double D[N];   vector<pair<int, int> > Adj[N];   void DFS(int v, int p) {     long double d = 2.0 / Adj[v].size(), t = 1.0;     for (auto X : Adj[v])       if (X.first == p) t += D[X.second], t -= (t > 2.0) ? 2.0 : 0;     for (auto X : Adj[v])       if (X.first != p) {         F[X.second] = v;         T[X.second] = X.first;         t += d;         t -= (t > 2.0) ? 2 : 0;         D[X.second] = t;         DFS(X.first, v);       }   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++)       scanf( %d%d , &F[i], &T[i]), Adj[F[i]].push_back({T[i], i}),           Adj[T[i]].push_back({F[i], i});     DFS(1, 0);     printf( %d n , n - 1);     for (int i = 1; i < n; i++) {       if (D[i] > 1) swap(F[i], T[i]), D[i] -= 1;       printf( 1 %d %d %d %.12f n , i, F[i], T[i], (double)D[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int a[200013];   int type[200013], len[200013];   int high[200013];   int res[200013];   multiset<int> has;   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= m; i++) scanf( %d%d , &type[i], &len[i]);     for (int i = m; i > 0; i--) high[i] = max(high[i + 1], len[i]);     for (int i = high[1] + 1; i <= n; i++) res[i] = a[i];     for (int i = 1; i <= high[1]; i++) has.insert(a[i]);     int dir = 1;     int last = high[1];     for (int i = 1; i <= m + 1; i++) {       if (len[i] == high[i]) {         while (last > len[i]) {           if (dir == 1) {             res[last--] = *has.rbegin();             has.erase(--has.end());           } else {             res[last--] = *has.begin();             has.erase(has.begin());           }         }         dir = type[i];       }     }     for (int i = 1; i <= n; i++) printf( %d  , res[i]);     printf(  n );     return 0;   }