malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   inline long long read() {     char ch = getchar();     long long s = 0, w = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       s = s * 10 + ch -  0 ;       ch = getchar();     }     return s * w;   }   int d[1000010], t[1000010], prime[1000010], tot, vis[1000010];   int n, fa[1000010], a[1000010], m;   long long c[1000010];   inline void prepare(int Maxn) {     d[1] = 1;     for (register int i = 2; i <= Maxn; i++) {       if (!vis[i]) {         prime[++tot] = i;         t[i] = d[i] = 2;       }       for (register int j = 1; 1LL * prime[j] * i <= Maxn; j++) {         vis[i * prime[j]] = 1;         if (i % prime[j]) {           d[i * prime[j]] = d[i] * 2;           t[i * prime[j]] = 2;         } else {           d[i * prime[j]] = d[i] / t[i] * (t[i] + 1);           t[i * prime[j]] = t[i] + 1;           break;         }       }     }   }   inline void add(int x, int v) {     for (; x <= n; x += x & (-x)) c[x] += v;   }   inline long long query(int x) {     long long sum = 0;     for (; x; x -= x & (-x)) sum += c[x];     return sum;   }   int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }   int main() {     prepare(1000010 - 10);     n = read(), m = read();     for (register int i = 1; i <= n; i++) a[i] = read(), fa[i] = i;     fa[n + 1] = n + 1;     for (register int i = 1; i <= n; i++) add(i, a[i]);     while (m--) {       int opt = read(), l = read(), r = read();       if (opt == 1) {         for (register int i = l; i <= r; i = find(i + 1)) {           add(i, d[a[i]] - a[i]);           a[i] = d[a[i]];           if (a[i] == 2 || a[i] == 1) fa[find(i)] = find(i + 1);         }       } else {         printf( %lld n , query(r) - query(l - 1));       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char str[100050];   char a[5000], b[5000];   int len1, len2, len3;   bool pp(int s1, int s2) {     while (s2 <= len2) {       if (str[s1] != a[s2]) return false;       s1++, s2++;     }     return true;   }   bool pp2(int s1, int s2) {     while (s2 <= len3) {       if (str[s1] != b[s2]) return false;       s1++, s2++;     }     return true;   }   bool rp(int s1, int s2) {     while (s2 <= len2) {       if (str[s1] != a[s2]) return false;       s1--, s2++;     }     return true;   }   bool rp2(int s1, int s2) {     while (s2 <= len3) {       if (str[s1] != b[s2]) return false;       s1--, s2++;     }     return true;   }   int main() { printf( Even n ); }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long num, tmp, sum, mx, l, r, mid;     cin >> num;     mx = sum = 0;     for (int i = 0; i < num; i++) {       cin >> tmp;       sum += tmp;       mx = max(mx, tmp);     }     l = mx;     r = sum;     while (l < r) {       mid = (l + r) / 2;       if (mid * num - sum >= mid)         r = mid;       else         l = mid + 1;     }     cout << l;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 505;   const int maxm = 1e4 + 5;   struct node {     int pre[maxn];     void init() {       for (int i = 0; i < maxn; ++i) {         pre[i] = i;       }     }     int Find(int x) {       if (x != pre[x]) pre[x] = Find(pre[x]);       return pre[x];     }     void v(int x, int y) {       int fx = Find(x), fy = Find(y);       if (fx != fy) pre[fy] = fx;     }   };   struct node q[maxm], h[maxm];   int u[maxm], v[maxm];   int n, m;   int solve(node a, node b) {     int ans = 0;     for (int i = 1; i <= n; ++i) {       a.v(i, b.Find(i));     }     for (int i = 1; i <= n; ++i) {       if (a.Find(i) == i) ans++;     }     return ans;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; ++i) scanf( %d%d , &u[i], &v[i]);     q[0].init();     h[m + 1].init();     for (int i = 1; i <= m; ++i) {       q[i] = q[i - 1];       q[i].v(u[i], v[i]);     }     for (int i = m; i >= 1; --i) {       h[i] = h[i + 1];       h[i].v(u[i], v[i]);     }     int tt;     scanf( %d , &tt);     while (tt--) {       int x, y;       scanf( %d%d , &x, &y);       printf( %d n , solve(q[x - 1], h[y + 1]));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<long long int> v, t;     v.push_back(0), t.push_back(0);     long long int sum = 0, tt = 1, x = 0;     double result = 0;     long long int ix, a, b;     for (int i = 0; i < n; ++i) {       cin >> ix;       if (ix == 1) {         cin >> a >> b;         t[a - 1] += b;         sum += a * b;       } else if (ix == 2) {         cin >> a;         v.push_back(a), t.push_back(0);         sum += a;         ++tt;       } else {         t[t.size() - 2] += t.back();         sum -= (v.back() + t.back());         --tt;         v.pop_back(), t.pop_back();       }       result = (double)sum / (double)tt;       cout << fixed << setprecision(6) << result <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e9 + 5;   long long n, k;   bool valid(long long x) {     long long maxi = (x)*k - ((x - 1) * ((x + 2) / 2.0));     if (maxi >= n)       return true;     else       return false;   }   long long binary() {     long long lo = 0, mid, hi = k;     while (hi - lo > 0) {       mid = (hi + lo) / 2;       if (valid(mid))         hi = mid;       else         lo = mid + 1;     }     if (hi == lo)       return lo;     else       return -1;   }   int main() {     scanf( %I64d %I64d , &n, &k);     long long ans = binary();     long long maxi = k;     maxi += (ans - 1) * k - ((ans - 1) * ((ans + 2) / 2));     if (ans & 1 && ans != 1) maxi--;     if (maxi >= n)       printf( %I64d , ans);     else       printf( -1 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int cnt[3600];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int h, m;       scanf(  n%d:%d , &h, &m);       cnt[h * 60 + m]++;     }     int ans = 0;     for (int i = 0; i < 1440; i++) {       if (cnt[i] == 0) {         int cur = 1, j = (i + 1) % 1440;         while (j != i && cnt[j] == 0) {           j = (j + 1) % 1440;           cur++;         }         ans = max(ans, cur);       }     }     cout << (ans / 60) / 10 << (ans / 60) % 10 <<  :  << (ans % 60) / 10          << ans % 10;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e6 + 10;   int a[N], b[N];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     vector<int> ans;     for (int i = 1; i <= n; i++) {       b[i] = a[i] - a[i - 1];     }     for (int i = 1; i <= n; i++) {       int flag = 0;       for (int j = 1; i + j <= n; j++) {         if (b[j] != b[i + j]) {           flag++;           break;         }       }       if (!flag) {         ans.push_back(i);       }     }     cout << ans.size() << endl;     for (auto i : ans) cout << i <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 6;   bool flag = true;   vector<int> v[N];   int a[N], p[N], h[N], g[N];   void dfs(int u, int temp = -1) {     a[u] = p[u];     int sum = 0;     for (auto x : v[u]) {       if (x == temp) continue;       dfs(x, u);       sum += g[x];       a[u] += a[x];     }     if ((a[u] + h[u]) % 2 != 0) flag = false;     g[u] = (a[u] + h[u]) / 2;     if (g[u] >= 0 and g[u] <= a[u]) {     } else       flag = false;     if (sum > g[u]) flag = false;   }   int main() {     long long int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       for (int i = 0; i < n; i++) cin >> p[i];       ;       for (int i = 0; i < n; i++) cin >> h[i];       ;       for (int i = 0; i < n - 1; i++) {         int a, b;         cin >> a >> b;         a--;         b--;         v[a].push_back(b);         v[b].push_back(a);       }       dfs(0);       cout << (flag ?  YES  :  NO ) << endl;       flag = true;       for (int i = 0; i < n; i++) v[i].clear();     }   }
#include <bits/stdc++.h>   using namespace std;   char inp[1005], ans[1005];   int n, p;   bool possible(int pos, int ok) {     if (pos == n) return ok;     int start = ok ? 0 : inp[pos] -  a ;     int i;     for (i = start; i < p; i++) {       ans[pos] = i +  a ;       if (pos > 0 && ans[pos - 1] == ans[pos]) continue;       if (pos > 1 && ans[pos - 2] == ans[pos]) continue;       if (possible(pos + 1, ok | (i > start))) return true;     }     return false;   }   int main() {     scanf( %d%d , &n, &p);     scanf( %s , inp);     bool ok = 0;     int i;     if (possible(0, 0)) {       ans[n] =   0 ;       printf( %s n , ans);     } else       printf( NO n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k;   long long C[1005][2005];   int main() {     scanf( %d %d %d , &n, &m, &k);     int M = max(n, m);     for (int n = 0; n <= M; n++)       for (int r = 0; r <= 2 * k; r++) {         if (r == 0)           C[n][r] = 1;         else if (n == 0)           C[n][r] = 0;         else           C[n][r] = (C[n - 1][r - 1] + C[n - 1][r]) % 1000000007;       }     printf( %d n , (int)((C[n - 1][2 * k] * C[m - 1][2 * k]) % 1000000007));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long lca(long long a, long long b) {     while (a != b) {       if (a < b)         b /= 2;       else         a /= 2;     }     return a;   }   long long inf = 1000LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL;   int main() {     ios_base::sync_with_stdio(0);     int t;     cin >> t;     map<long long, long long> M;     while (t-- > 0) {       int x;       cin >> x;       long long u, v, w;       cin >> u >> v;       if (x == 1) {         cin >> w;         long long y = lca(u, v);         while (u != y) {           M[u] += w;           u /= 2;         }         while (v != y) {           M[v] += w;           v /= 2;         }       } else {         long long y = lca(u, v);         long long ans = 0;         while (u != y) {           ans += M[u];           u /= 2;         }         while (v != y) {           ans += M[v];           v /= 2;         }         cout << ans <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int a[100];   int main() {     int x = 1;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       if (a[i] < a[x]) x = i;     }     if (n == 1 || (n == 2 && a[1] == a[2])) {       puts( -1 );     } else {       printf( 1 n%d n , x);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char comp[200005];   vector<pair<int, int> > edge[200005];   vector<int> father[200005];   vector<string> ans;   int dis[200005], n, k;   queue<pair<int, int> > q;   void dfs(int u) {     if (ans.size() >= k) return;     if (u == n + 1) {       ans.push_back(comp + 1);       return;     }     for (int i = 0; i < father[u].size(); i++) {       comp[father[u][i]] =  1 ;       dfs(u + 1);       comp[father[u][i]] =  0 ;     }   }   int main() {     char a[10];     int m;     cin >> n >> m >> k;     for (int i = 1; i <= m; i++) {       int u, v;       scanf( %d %d , &u, &v);       edge[u].push_back(make_pair(v, i));       edge[v].push_back(make_pair(u, i));     }     memset(dis, -1, sizeof(dis));     for (int i = 1; i <= m; i++) comp[i] =  0 ;     q.push(make_pair(1, 0));     dis[1] = 0;     while (!q.empty()) {       pair<int, int> pa = q.front();       q.pop();       int u = pa.first, d = pa.second;       for (int i = 0; i < edge[u].size(); i++) {         int v = edge[u][i].first;         if (dis[v] == -1) {           dis[v] = d + 1;           q.push(make_pair(v, d + 1));         }       }     }     for (int i = 2; i <= n; i++) {       for (int j = 0; j < edge[i].size(); j++) {         if (dis[i] == dis[edge[i][j].first] + 1)           father[i].push_back(edge[i][j].second);       }     }     dfs(2);     if (ans.size() >= k) {       cout << k << endl;       for (int i = 0; i < k; i++) cout << ans[i] << endl;     } else {       cout << ans.size() << endl;       for (int i = 0; i < ans.size(); i++) cout << ans[i] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) {       int s, f, t;       cin >> s >> f >> t;       int x = t % (2 * (m - 1));       int y = t - x;       int ans = 0;       if (s == f) {         ans = t;       } else if (s < f) {         if (x <= s - 1) {           ans = y + f - 1;         } else {           ans = y + 2 * (m - 1) + f - 1;         }       } else {         if (x <= (m - 1) + (m - s)) {           ans = y + (m - 1) + m - f;         } else {           ans = y + 3 * (m - 1) + m - f;         }       }       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   int n, m, t;   vector<int> e[maxn];   vector<int> ans;   stack<int> s;   bool vis[maxn];   int dep[maxn];   int N;   bool v[maxn];   int dfs(int x, int fr) {     vis[x] = true;     s.push(x);     for (auto y : e[x]) {       if (y == fr) continue;       if (!vis[y]) {         dep[y] = dep[x] + 1;         dfs(y, x);         dep[y] = 0;       } else if (dep[y]) {         if (dep[x] - dep[y] + 1 >= N) {           printf( 2 n );           printf( %d n , dep[x] - dep[y] + 1);           while (s.top() != y) {             printf( %d  , s.top());             s.pop();           }           printf( %d n , s.top());           exit(0);         }       }     }     if (!v[x]) {       for (auto y : e[x]) {         v[y] = true;       }       ans.push_back(x);     }     s.pop();     return 0;   }   int read() {     int x;     scanf( %d , &x);     return x;   }   int main() {     int i, j;     int x, y;     n = read();     m = read();     N = sqrt(n);     while (N * N < n) N++;     for (i = 1; i <= m; i++) {       x = read();       y = read();       e[x].push_back(y);       e[y].push_back(x);     }     for (i = 1; i <= n; i++) {       if (!vis[i]) {         dep[i] = 1;         dfs(i, -1);         dep[i] = 0;       }     }     printf( 1 n );     for (i = 1; i <= n; i++) {       if (v[i]) continue;       N--;       printf( %d  , i);       if (!N) break;     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[110], mx;   const int N = 30;   map<int, int> mem;   int Penu(int now) {     if (!now || mem.find(now) != mem.end()) return mem[now];     register int ans = 0;     register set<int> mex;     for (register int i = 1; i < 31; i++)       if (now >> i) mex.insert(Penu(now & ((1 << i) - 1) | (now >> i)));     while (mex.count(ans)) ans++;     return mem[now] = ans;   }   int ans;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cin >> n;     mem[0] = 0;     map<int, int> ma;     for (register int i = 1, j; i <= n; i++) {       cin >> j;       for (register int r = 2, c = 0; r * r <= j; r++, c = 0) {         while (!(j % r)) {           c++;           j /= r;         }         if (c) ma[r] |= (1 << c);       }       if (j > 1) ma[j] |= 2;     }     for (auto u : ma) ans ^= Penu(u.second);     cout << (!ans ?  Arpa n  :  Mojtaba n );     return 0;   }
#include<bits/stdc++.h>      #define ll long long int   #define ld long double   #define pb push_back   #define fi first   #define se second   #define all(x) x.begin(),x.end()   #define mem(x,y) memset(x,y,sizeof(x))   #define pii pair<int,int>   #define pll pair<ll,ll>   #define INF 1e9+10   #define INFL 1e18   #define mod 1000000007   //#define mod 998244353   #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);   using namespace std;               ll power(ll x,ll n){ll res =1;while(n>0){if(n%2==1){res=res*x;}x=x*x;n=n/2;}return res;}   ll powm(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}      //cout<< fixed << setprecision(10)   //__builtin_popcountll();   //|_2.4_|=2     int vis[500005];   vector<int>g[500005];      int lev[500005];   int ans[500005];      void bfs(int s)   {    queue<int>q;    q.push(s);    vis[s]=1;    lev[s]=0;        while(!q.empty())    {     int x=q.front();     q.pop();     for(int i=0;i<g[x].size();i++)     {            if(vis[g[x][i]]==0)      {       lev[g[x][i]]=lev[x]+1;       vis[g[x][i]]=1;       q.push(g[x][i]);      }           }         }   }   void dfs(int s)   {    vis[s]=1;    for(auto x:g[s])    {     if(lev[s]>=lev[x])      continue;          dfs(x);        ans[s]=min(ans[s],ans[x]);    }   }         int main(){        fast;    int T=1;    cin>>T;    while(T--)    {     int n,i,j,m;     cin>>n>>m;     vector<pii>v;     for(i=0;i<m;i++)     {      int r,c;      cin>>r>>c;      v.pb({c,r});     }     sort(all(v));     int l=0,r;     if(m%2==1)     {      cout<< NO n ;      continue;     }     for(i=0;i+1<m;i+=2)     {      if(v[i].fi==v[i+1].fi)      {       continue;         }      else      {       if(i+2<m&&v[i+1].fi==v[i+2].fi)       {        l=1;        break;       }       if((v[i].se==v[i+1].se&&(v[i+1].fi-v[i].fi-1)%2==0)||(v[i].se!=v[i+1].se&&(v[i+1].fi-v[i].fi-1)%2==1))       {        continue;             }       else       {        l=1;        break;       }         }     }     if(l)     {      cout<< NO n ;     }     else     {      cout<< YES n ;     }                       }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     string s, t;     cin >> n >> s >> t;     string ss = s, tt = t;     sort(ss.begin(), ss.end());     sort(tt.begin(), tt.end());     if (ss != tt)       cout << -1 <<   n ;     else {       vector<int> ans;       for (int j = (int)(n - 1); j >= int(0); j--) {         char target = t[j];         ;         int pos = n - j - 1;         ;         while (target != s[pos]) pos++;         ;         ;         ans.push_back(n);         reverse(s.begin(), s.end());         ;         ans.push_back(pos);         string temp(s.begin() + n - pos, s.end());         reverse(temp.begin(), temp.end());         s.erase(s.begin() + n - pos, s.end());         s.insert(s.begin(), temp.begin(), temp.end());         ;         ans.push_back(1);         char c = s[n - 1];         s.erase(s.begin() + n - 1);         s.insert(s.begin(), c);         ;       }       cout << int((ans).size()) <<   n ;       for (int i = 0; i < int(int((ans).size())); i++) {         if (i) cout <<    ;         cout << ans[i];       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int MOD = 1000000000 + 7;   long long int arr[200005];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long int t;     cin >> t;     while (t--) {       long long int n, sum = 0;       cin >> n;       for (long long int i = 0; i < n; i++) cin >> arr[i];       long long int i = 0;       vector<long long int> vec;       while (1) {         long long int maxp = INT_MIN;         long long int maxn = INT_MIN;         for (; i < n; i++) {           if (arr[i] < 0)             break;           else {             maxp = max(maxp, arr[i]);           }         }         if (maxp != INT_MIN) vec.push_back(maxp);         if (i == n) break;         for (; i < n; i++) {           if (arr[i] >= 0)             break;           else {             maxn = max(maxn, arr[i]);           }         }         if (maxn != INT_MIN) vec.push_back(maxn);         if (i == n) break;       }       for (long long int i = 0; i < vec.size(); i++) sum += vec[i];       cout << sum << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long maxn = 2e5 + 5;   int n, k, a[maxn], ans[maxn], pos[maxn];   class Node {    public:     int l, r;   };   Node lis[maxn];   int main() {     scanf( %d%d , &n, &k);     for (int(i) = 0; (i) < (n); (i)++) {       cin >> a[i + 1];       pos[a[i + 1]] = i + 1;       lis[i + 1].l = i;       lis[i + 1].r = i + 2;     }     int team = 1;     for (int i = n; i >= 1; i--) {       int p = pos[i];       if (ans[p] != 0) continue;       ans[p] = team;       for (int(j) = 0; (j) < (k); (j)++) {         int el = lis[p].r;         if (el != n + 1) {           ans[el] = team;           lis[lis[el].l].r = lis[el].r;           lis[lis[el].r].l = lis[el].l;         } else           break;       }       for (int(j) = 0; (j) < (k); (j)++) {         int el = lis[p].l;         if (el != 0) {           ans[el] = team;           lis[lis[el].l].r = lis[el].r;           lis[lis[el].r].l = lis[el].l;         } else           break;       }       lis[lis[p].l].r = lis[p].r;       lis[lis[p].r].l = lis[p].l;       if (team == 1)         team = 2;       else         team = 1;     }     for (int(i) = 0; (i) < (n); (i)++) cout << ans[i + 1];     cout << endl;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   template <class T>   using V = vector<T>;   template <typename T>   using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;   long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; }   long long LCM(long long a, long long b) { return a / GCD(a, b) * b; }   long long int pom(long long int a, long long int n, int m) {     long long int x = 1;     for (a %= m; n; n /= 2) n& 1 ? x = x * a % m : 0, a = a * a % m;     return x;   }   int dx[4] = {-1, 0, 1, 0};   int dy[4] = {0, -1, 0, 1};   int ddx[8] = {-1, 0, 1, 0, 1, 1, -1, -1};   int ddy[8] = {0, -1, 0, 1, 1, -1, 1, -1};   long long int cmp1(pair<pair<long long int, long long int>, long long int> a,                      pair<pair<long long int, long long int>, long long int> b) {     return a.first.second > b.first.second;   }   long long int cmp2(pair<long long int, long long int> a,                      pair<long long int, long long int> b) {     if (a.second != b.second)       return a.second < b.second;     else       return a.first > b.first;   }   int main(int argc, char* argv[]) {     cin.tie(0);     ios::sync_with_stdio(false);     long long int T;     cin >> T;     while (T--) {       long long int n;       cin >> n;       V<long long int> a(n + 1);       for (long long int i = 0; i < n; i++) {         cin >> a[i];       }       long long int ans = 0;       bool abc = 0;       long long int cnt = 0;       for (long long int i = 1; i < n; i++) {         if (a[i - 1] == 1 && a[i] == 0) {           abc = 1;           cnt = 1;         } else if (abc == 1 && a[i] == 0) {           cnt++;         }         if (abc == 1 && (a[i] == 0 && a[i + 1] == 1 && i < n - 1)) {           ans += cnt;           cnt = 0;           abc = 0;         }       }       cout << ans << endl;     }     return 0;   }