malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main(int argc, char const *argv[]) {     int cases;     cin >> cases;     while (cases--) {       int length, target;       cin >> length >> target;       vector<vector<int>> BGR(3, vector<int>(length, 0));       string inp;       cin >> inp;       for (size_t i = 0, tok; i < inp.length(); ++i) {         if (inp[i] ==  B )           tok = 0;         else if (inp[i] ==  G )           tok = 1;         else           tok = 2;         BGR[(tok + i) % 3][i] = 1;       }       int ans = target;       for (auto x : BGR) {         size_t j = 0;         int init = target;         for (; j < target; ++j) init -= x[j];         ans = init < ans ? init : ans;         for (size_t i = 0; j < x.size(); ++i, ++j) {           init += x[i] - x[j];           ans = init < ans ? init : ans;         }       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INFint = 2147483647;   const long long INF = 9223372036854775807ll;   const long long MOD = 1000000007ll;   char f[2020][2020];   int n, m;   bool c(int x, int y, int d, int cnt) {     int cur = 0;     cerr << x <<     << y << endl;     if (x > 0 && y > 0 && x + d - 1 <= n && y + d - 1 <= m) {       for (int i = x; i < x + d; i++) {         cur += (f[i][y] ==  w );         cur += (f[i][y + d - 1] ==  w );       }       for (int i = y + 1; i < y + d - 1; i++) {         cur += (f[x][i] ==  w );         cur += (f[x + d - 1][i] ==  w );       }       return (cur == cnt);     }     return 0;   }   int main() {     ios_base::sync_with_stdio(0);     int minx = INFint, miny = INFint, maxx = -INFint, maxy = -INFint;     cin >> n >> m;     int cnt = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> f[i][j];         if (f[i][j] ==  w ) {           minx = min(minx, i);           miny = min(miny, j);           maxx = max(maxx, i);           maxy = max(maxy, j);           cnt++;         }       }     }     int d = max(maxx - minx + 1, maxy - miny + 1);     cerr << d << endl;     if (d == 1) {       for (int it = 1; it <= n; it++) {         for (int l = 1; l <= m; l++) cout << f[it][l];         cout << endl;       }       return 0;     }     int x[3] = {minx, maxx - d + 1, 1};     int y[3] = {miny, maxy - d + 1, 1};     for (int i = 0; i < 3; i++) cerr << x[i] <<    ;     cerr << endl;     for (int i = 0; i < 3; i++) cerr << y[i] <<    ;     cerr << endl;     for (int i = 0; i < 3; i++)       for (int j = 0; j < 3; j++) {         if (c(x[i], y[j], d, cnt)) {           for (int it = x[i]; it < x[i] + d; it++) {             if (f[it][y[j]] !=  w ) f[it][y[j]] =  + ;             if (f[it][y[j] + d - 1] !=  w ) f[it][y[j] + d - 1] =  + ;           }           for (int it = y[j]; it < y[j] + d; it++) {             if (f[x[i]][it] !=  w ) f[x[i]][it] =  + ;             if (f[x[i] + d - 1][it] !=  w ) f[x[i] + d - 1][it] =  + ;           }           for (int it = 1; it <= n; it++) {             for (int l = 1; l <= m; l++) cout << f[it][l];             cout << endl;           }           return 0;         }       }     cout << -1 << endl;     fprintf(stderr,   nTIME = %lf n , 1.0 * clock() / CLOCKS_PER_SEC);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     int count1 = 0;     for (int i = 0; i < n; i++) {       int sum = 0;       for (int j = 0; j < n; j++) {         if (i == j) {           continue;         } else {           sum += a[j];         }       }       if (sum % 2 == 0) {         count1++;       }     }     cout << count1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int sgn(double x) { return (x > 1e-8) - (x < -1e-8); }   int count_bit(int x) { return x == 0 ? 0 : count_bit(x >> 1) + (x & 1); }   template <class T>   inline void ckmin(T& a, const T b) {     if (b < a) a = b;   }   template <class T>   inline void ckmax(T& a, const T b) {     if (b > a) a = b;   }   const int MAXN = 100000 + 10;   struct binary_indexed_tree {     int a[MAXN], val[MAXN];     void clear() {       memset(a, 0, sizeof(a));       memset(val, 0, sizeof(val));     }     void update(int x, int y) {       val[x] += y;       for (; x < MAXN; x += ((x) & (-(x)))) {         a[x] += y;       }     }     int getsum(int x) {       int ret = 0;       for (; x; x -= ((x) & (-(x)))) {         ret += a[x];       }       return ret;     }     int getsum(int l, int r) {       int ret = 0;       while (l <= r) {         if (r - ((r) & (-(r))) + 1 >= l) {           ret += a[r];           r -= ((r) & (-(r)));         } else {           ret += val[r--];         }       }       return ret;     }   } bit;   void filp_left(int& l, int& r, int len) {     for (int i = (1); i <= (len); ++i) {       bit.update(l + len + len - i, bit.val[l + i - 1]);     }     l += len;   }   void filp_right(int& l, int& r, int len) {     for (int i = (1); i <= (len); ++i) {       bit.update(r - len - len + i, bit.val[r - i + 1]);     }     r -= len;   }   int main() {     int n, q;     while (scanf( %d%d , &n, &q) != EOF) {       bit.clear();       for (int i = 0; i < (n); ++i) {         bit.update(i + 1, 1);       }       int off = 0;       int l = 1, r = n;       bool rev = false;       for (int i = 0; i < (q); ++i) {         int optype, flen, cl, cr;         scanf( %d , &optype);         if (optype == 1) {           scanf( %d , &flen);           int clen = r - l + 1;           if (2 * flen > clen) {             if (!rev) {               filp_right(l, r, clen - flen);             } else {               filp_left(l, r, clen - flen);             }             rev = !rev;           } else {             if (!rev) {               filp_left(l, r, flen);             } else {               filp_right(l, r, flen);             }           }         } else {           scanf( %d%d , &cl, &cr);           int ret;           if (!rev) {             ret = bit.getsum(l + cl, l + cr - 1);           } else {             ret = bit.getsum(r - cr + 1, r - cl);           }           printf( %d n , ret);         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     int c1 = 0, c2 = 0;     for (int i = 0; i < n; ++i) {       int aux;       cin >> aux;       c1 += aux == 1;       c2 += aux == -1;     }     for (int i = 0; i < m; ++i) {       int a, b;       cin >> a >> b;       if ((b - a + 1) % 2 == 0) {         if (c1 >= (b - a + 1) / 2 && c2 >= (b - a + 1) / 2)           cout <<  1 n ;         else           cout <<  0 n ;       } else         cout <<  0 n ;     }     return 0;   }
#include <bits/stdc++.h>   int main() {     char s[15];     char a;     int len;     scanf( %s , s);     len = strlen(s);     a =  a  - 1;     for (int i = 0; i < len; i++) {       if (a <= s[i]) {         a = s[i];       }     }     for (int i = 0; i < len; i++) {       if (s[i] == a) printf( %c , s[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000000 + 239;   const int inf = (int)1e9 + 1;   const long long big = (long long)1e18 + 1;   const int P = 31;   const int MOD = (int)1e9 + 7;   const int MOD1 = (int)1e9 + 9;   const double eps = 1e-9;   const double pi = atan2(0, -1);   int a[N];   vector<int> g[N];   int d[N];   void dfs(int u) {     for (int v : g[u]) {       dfs(v);       d[u] = max(d[u], d[v] + 1);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.precision(20);     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 1; i < n; i++) {       int p;       cin >> p;       p--;       g[p].push_back(i);     }     dfs(0);     int res = 0;     for (int i = 0; i < n; i++)       if (d[i] % 2 == 0) res ^= a[i];     map<int, int> cnt;     for (int i = 0; i < n; i++)       if (d[i] % 2 == 1) cnt[a[i]]++;     long long ans = 0;     for (int i = 0; i < n; i++)       if (d[i] % 2 == 0) ans += cnt[res ^ a[i]];     if (res == 0) {       int cnt0 = 0, cnt1 = 0;       for (int i = 0; i < n; i++)         if (d[i] % 2 == 0)           cnt0++;         else           cnt1++;       ans += (long long)cnt0 * (cnt0 - 1) / 2;       ans += (long long)cnt1 * (cnt1 - 1) / 2;     }     cout << ans << endl;     return 0;   }
//#pragma GCC target ( avx2 )   //#pragma GCC optimization ( O3 )   //#pragma GCC optimization ( unroll-loops )   #include<bits/stdc++.h>   //#include <ext/pb_ds/assoc_container.hpp>   //#include <ext/pb_ds/tree_policy.hpp>   //using namespace __gnu_pbds;   #define eps 1e-8   #define eq(x,y) (fabs((x)-(y)) < eps)   using namespace std;   typedef long long ll;   typedef long double ld;   typedef pair<int,int>pii;   const ll mod= 998244353;   long double PI = acosl(-1);   const ll infl = 1e17+100;   const int inf = 1e9+100;   const int nmax = 3e5+5;   //const int MAXLG = log2(nmax)+1;   //mt19937 rng(chrono::system_clock::now().time_since_epoch().count());   //typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ost;      bool vis[nmax];   vector<int>g[nmax];      void dfs(int u){       vis[u] = true;       for(int v : g[u]) if(!vis[v])           dfs(v);   }         int main(){          ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);          int tc;       cin>>tc;       while(tc--){           int n,m;           cin>>n>>m;           for(int i=0; i<m; i++){               int u,v;               cin>>u>>v;               g[u].push_back(v);               g[v].push_back(u);           }           bool hoise = false;           bool unposibol = false;           for(int i=1; i<=n; i++){               if(!vis[i]){                   if(!hoise){                       dfs(i);                       hoise = true;                   }                   else unposibol = true;               }           }           if(unposibol) cout<< NO n ;           else{               cout<< YES n ;               for(int i=1; i<=n; i++) vis[i] = false;               vector<int>ans;               set<int>st; st.insert(1);               while(st.size()){                   int u = *st.begin();                   st.erase(u);                   if(vis[u]) continue;                   vis[u] = true;                   ans.push_back(u);                   vector<int>tmp;                   for(int v : g[u]) if(!vis[v]){                       vis[v] = true;                       tmp.push_back(v);                   }                   for(int v : tmp){                       for(int z : g[v]) if(!vis[z]){                           st.insert(z);                       }                   }               }               cout<<ans.size()<<  n ;               for(int x : ans) cout<<x<<   ;               cout<<  n ;           }           for(int i=1; i<=n; i++) vis[i] = false, g[i].clear();       }         }   /*      */
#include <bits/stdc++.h>   using namespace std;   long long mysqrt(long long x) {     long long l = 0;     long long r = 1;     while (r * r <= x) r *= 2;     while (r - l > 1) {       long long m = (l + r) / 2;       if (m * m <= x)         l = m;       else         r = m;     }     return l;   }   int main() {     long long n;     cin >> n;     long long a[n + 2][n + 2];     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++) {       int j = (i + 1) % n;       int k = (j + 1) % n;       cout << mysqrt(1ll * a[i][j] * a[i][k] / a[j][k]) <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, mx = 0, i, j, value;     cin >> n;     vector<int> v(n + 1, 0);     for (i = 1; i <= n; i++) {       cin >> v[i];       v[i] += v[i - 1];     }     for (i = 1; i <= n; i++) {       for (j = 0; j < i; j++) {         if ((v[i] - v[j]) > (100 * (i - j))) {           mx = max(mx, i - j);           break;         }       }     }     cout << mx << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve();   string conc(long long int a, long long int b) {     return to_string(a) +  |  + to_string(b);   }   long long int rev(long long int x) {     long long int ans = 0;     while (x != 0) {       ans = ans * 10 + (x % 10);       x /= 10;     }     return ans;   }   long long int numdig(long long int x) {     long long int ans = 0;     while (x != 0) {       ans++;       x /= 10;     }     return ans;   }   void printvec(vector<long long int> &v) {     for (long long int i = 0; i < v.size(); i++) cout << v[i] <<    ;     cout <<   n ;   }   void printmat(vector<vector<long long int>> &mat) {     for (long long int i = 0; i < mat.size(); i++) {       for (long long int j = 0; j < mat[0].size(); j++) cout << mat[i][j] <<    ;       cout <<   n ;     }   }   void solve() {     long long int n, k;     cin >> n >> k;     string s;     cin >> s;     vector<long long int> f(26, 0);     vector<pair<char, long long int>> v;     long long int vsize = 0;     for (auto c : s) f[c -  a ]++;     for (long long int i = 0; i < 26; i++) {       if (f[i] > 0) {         v.push_back({ a  + i, f[i]});         vsize++;       }     }     if (v[0].second < k) {       long long int count = 0;       for (long long int i = 0; i < vsize; i++) {         count += v[i].second;         if (count >= k) {           cout << v[i].first <<   n ;           return;         }       }       return;     }     string init =   ;     init = init + v[0].first;     vector<string> words(k, init);     v[0].second -= k;     for (long long int i = 0; i < vsize; i++) {       if (i == vsize - 1) {         long long int j = 0;         long long int c = 0;         while (j < k && words[j] == words[0]) j++;         while (v[i].second--) {           words[c] += v[i].first;           c = (c + 1) % j;         }       } else {         while (v[i].second--) {           words[0] += v[i].first;         }       }     }     sort(words.begin(), words.end());     cout << words[k - 1] <<   n ;   }   int main(void) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     t = 1;     cin >> t;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 998244353;   pair<int, int> calc(int a, int b) {     if (a <= b) return {a, 0};     int r = a / b;     if (a % b == 0) return {b, r - 1};     return {a / (r + 1), r};   }   vector<pair<int, int>> compact(const vector<pair<int, int>>& V) {     vector<pair<int, int>> R;     int p = -1, c = 0;     for (auto [a, b] : V) {       if (a != p && p != -1) {         R.emplace_back(p, c);         c = 0;       }       p = a;       c += b;     }     R.emplace_back(p, c);     return R;   }   int main() {     ios_base::sync_with_stdio(false);     int tn;     cin >> tn;     for (int ti = 0; ti < tn; ++ti) {       int n;       cin >> n;       vector<int> A(n);       for (int& a : A) cin >> a;       vector<pair<int, int>> B;       uint64_t r = 0;       for (int i = n - 1; i > 0; --i) {         B.emplace_back(A[i], 1);         vector<pair<int, int>> C;         for (auto [x, y] : B) {           auto [z, t] = calc(A[i - 1], x);           C.emplace_back(z, y);           r = (r + 1ull * t * i * y) % MOD;         }         sort(C.begin(), C.end());         B = compact(C);       }       cout << r << endl;     }     return 0;   }
#include<bits/stdc++.h>   #define maxn 1000005   #define inf 9999999999999999   #define mod 100003   typedef long long LL;   using namespace std;   LL a[maxn];   int main()   {       ios::sync_with_stdio(false);       //freopen( bwxnQAQin.txt , r ,stdin);       LL T;       cin>>T;       while(T--)       {           LL n;           cin>>n;           if(n&1)           {               LL zong=n-1,fuyi=zong/2;               for(LL i=zong;i>=1;i--)               {                   for(LL j=1;j<=i-fuyi;j++)cout<< 1  ;                   for(LL j=1;j<=fuyi;j++)cout<< -1  ;                   if(fuyi)fuyi--;               }               cout<<endl;           }           else           {               LL zong=n-1,ban=zong/2;               for(LL i=1;i<=zong;i++)               {                   for(LL j=i;j<=zong;j++)                   {                       if(j<i+ban)cout<< 1  ;                       else if(j==i+ban)cout<< 0  ;                       else cout<< -1  ;                   }               }               cout<<endl;           }       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline 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;   }   double p[200010];   int n, cnt;   double ans;   inline void solve(int a, int b) {     ans += (double)(a - b) / 2;     p[++cnt] = (double)(a + b) / 2;   }   int main() {     n = read();     for (int i = 1; i <= n; i++) {       long long a = read(), b = read(), c = read(), d = read();       if (a + b >= c + d) {         solve(a, b);         solve(c, d);       } else {         if (a >= d) solve(a - d, d - a);         if (b >= c) solve(c - b, b - c);       }     }     sort(p + 1, p + cnt + 1, greater<double>());     for (int i = 1; i <= cnt; i++) {       if (i & 1)         ans += p[i];       else         ans -= p[i];     }     printf( %.0f n , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000010;   int f[N];   void init() {     for (int i = 1; i <= N; i++) {       f[i] = f[i - 1] + i * 2 + (i - 1);       if (f[i] >= 1e9) {         break;       }     }   }   int Find(int x) {     int l = 0, r = 25820;     while (l < r) {       int mid = (l + r + 1) / 2;       if (f[mid] <= x)         l = mid;       else         r = mid - 1;     }     return l;   }   int main() {     int T;     scanf( %d , &T);     init();     while (T--) {       int x;       scanf( %d , &x);       int ans = 0;       while (true) {         int t = Find(x);         if (f[t] <= 0) break;         x -= f[t];         ans++;       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = ~0ull / 2;   const int maxn = 100100;   int seen[maxn];   int ind[maxn];   int par[maxn][22];   int bd[maxn];   int h[maxn];   vector<int> adj[maxn];   vector<int> adlist[maxn];   vector<int> tree[maxn];   vector<pair<int, int> > edges;   void dfs1(int root, int dad = -1) {     seen[root] = 1;     bd[root] = h[root];     for (auto v : adj[root]) {       if (!seen[v]) {         h[v] = h[root] + 1;         dfs1(v, root);         bd[root] = min(bd[v], bd[root]);         if (!(bd[v] > h[root])) {           adlist[root].push_back(v);           adlist[v].push_back(root);         } else {           edges.push_back(make_pair(root, v));         }       } else {         if (v != dad) {           adlist[root].push_back(v);           adlist[v].push_back(root);           bd[root] = min(bd[root], h[v]);         }       }     }   }   void dfs2(int root, int t) {     seen[root] = 2;     ind[root] = t;     for (auto v : adlist[root]) {       if (seen[v] == 1) {         dfs2(v, t);       }     }   }   void dfs3(int root, int dad) {     par[root][0] = dad;     for (auto v : tree[root]) {       if (v != dad) {         h[v] = h[root] + 1;         dfs3(v, root);       }     }   }   int dis(int x, int y) {     x = ind[x];     y = ind[y];     if (h[x] < h[y]) swap(x, y);     int X = x;     int Y = y;     int t = 20;     while (h[x] != h[y]) {       if (h[par[x][t]] >= h[y]) x = par[x][t];       t--;     }     if (x == y) return h[X] - h[x];     int A;     t = 20;     while (par[x][0] != par[y][0] and t >= 0) {       if (par[x][t] != par[y][t]) {         x = par[x][t];         y = par[y][t];       }       t--;     }     A = par[x][0];     return (h[X] + h[Y] - 2 * h[A]);   }   int main() {     ios::sync_with_stdio(false), cin.tie(0);     int n, m, k;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       a--, b--;       adj[a].push_back(b);       adj[b].push_back(a);     }     dfs1(0);     int t = 1;     for (int i = 0; i < n; i++) {       if (seen[i] == 1) {         dfs2(i, t);         t++;       }     }     for (auto e : edges) {       int x = e.first;       int y = e.second;       x = ind[x];       y = ind[y];       tree[x].push_back(y);       tree[y].push_back(x);     }     h[0] = 0;     h[1] = 1;     dfs3(1, 0);     fill(par[0], par[0] + 22, 0);     for (int i = 1; i < 22; i++)       for (int j = 1; j < t; j++) par[j][i] = par[par[j][i - 1]][i - 1];     cin >> k;     for (int i = 0; i < k; i++) {       int s, l;       cin >> s >> l;       s--, l--;       cout << dis(s, l) <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   double dp[maxn], p[maxn];   int main() {     int n;     scanf( %d , &n);     double ans = 0, d;     for (int i = 1; i <= n; i++) {       scanf( %lf , &p[i]);       ans += p[i];     }     for (int i = 2; i <= n; i++) {       dp[i] = (dp[i - 1] + p[i - 1]) * p[i];       ans += 2 * dp[i];     }     printf( %.10f n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0;     char c = getchar();     bool p = 1;     for (; !isdigit(c); c = getchar())       if (c ==  - ) p = 0;     for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);     return p ? x : -x;   }   const int N = 1000105;   struct edge {     int to, nt;   } e[N * 2];   int n, k, x, y, ans, cnt, head[N], rt = 1, du[N];   void add(int u, int v) {     e[++cnt] = (edge){v, head[u]};     head[u] = cnt;   }   int dfs(int u, int fa) {     vector<int> v;     int i;     for (i = head[u]; i; i = e[i].nt)       if (e[i].to != fa) v.push_back(dfs(e[i].to, u) + 1);     sort(v.begin(), v.end());     for (i = v.size() - 1; i > 0; i--)       if (v[i] + v[i - 1] > k)         ans++;       else         break;     return v.size() == 0 ? 0 : v[i];   }   int main() {     n = read();     k = read();     for (int i = 1; i < n; i++) {       x = read();       y = read();       add(x, y);       add(y, x);       du[x]++;       du[y]++;       if (du[x] > 1) rt = x;       if (du[y] > 1) rt = y;     }     dfs(rt, 0);     cout << ans + 1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, m;     cin >> n >> m;     long long a[n + 1];     for (int i = 1; i <= n; i++) cin >> a[i];     long long v, x, add = 0, y, q;     int t;     while (m--) {       cin >> t;       if (t == 1) {         cin >> v >> x;         a[v] = x - add;       } else if (t == 2) {         cin >> y;         add += y;       } else {         cin >> q;         cout << a[q] + add <<   n ;       }     }     return 0;   }