malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int a[404040];   inline void solve() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , a + i);     int N = 0;     for (int i = 1, j = 1; i <= n; i = j) {       for (; j <= n && a[i] == a[j]; j++)         ;       a[++N] = j - i;     }     int s2 = 0, i2 = 2;     for (; i2 <= N && s2 <= a[1]; i2++) s2 += a[i2];     i2--;     int sum = a[1] + s2;     int s3 = 0, i3 = i2 + 1;     for (; i3 <= N && (sum + a[i3]) * 2 <= n; i3++) sum += a[i3], s3 += a[i3];     i3--;     if (a[1] < s3)       printf( %d %d %d n , a[1], s2, s3);     else       puts( 0 0 0 );   }   int main() {     int t;     scanf( %d , &t);     while (t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   long long pw(int x, int y, int z) {     if (y == 0) return 1 % z;     long long a = pw(x, y / 2, z);     if (y % 2 == 0)       return (a * a) % z;     else       return (((a * a) % z) * x % z) % z;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       long long n;       cin >> n;       vector<vector<long long>> arr(n, vector<long long>(2));       for (int i = 0; i < n; ++i) cin >> arr[i][0] >> arr[i][1];       map<long long, long long> l, r;       for (int i = 0; i < n; ++i) {         l[arr[i][0]]++;         r[arr[i][1]]++;       }       sort(arr.begin(), arr.end());       long long ans = (n * (n - 1) * (n - 2)) / 6;       sort(arr.begin(), arr.end());       for (int i = 0; i < n; ++i) {         long long curl = arr[i][0];         long long nos = l[curl];         long long othel = 0;         if (nos >= 2) {           for (int j = i; j < i + nos; ++j) {             othel += (r[arr[j][1]] - 1);           }         }         ans -= ((nos - 1) * othel);         i += nos - 1;       }       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   vector<long long int> v, primev;   int prime[2750150];   map<long long int, long long int> mp;   void FindPrime() {     long long int n = 2750140;     for (long long int i = 4; i <= n; i += 2) {       prime[i] = true;     }     prime[1] = true;     for (long long int i = 3; i * i <= n; i += 2) {       if (!prime[i]) {         for (long long int j = 2; i * j <= n; j++) {           prime[i * j] = true;         }       }     }     primev.push_back(2);     prime[2] = 2;     int c = 3;     for (long long int i = 3; i <= n; i = i + 2) {       if (!prime[i]) {         prime[i] = c;         c++;         primev.push_back(i);       }     }   }   long long int divisor(long long int a) {     long long int chk = sqrt(a + 1);     for (long long int i = 0; primev[i] <= chk; i++) {       if (a % primev[i] == 0) {         long long int res = a / primev[i];         return res;       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int a, b, c, d, e, i, j, test;     FindPrime();     cin >> a;     for (i = 0; i < a * 2; i++) {       cin >> b;       mp[b]++;       v.push_back(b);     }     sort(v.rbegin(), v.rend());     for (i = 0; i < v.size(); i++) {       if (mp[v[i]] > 0) {         if (prime[v[i]] != 1) {           long long int id = prime[v[i]];           id--;           cout << id <<    ;           mp[id]--;           mp[v[i]]--;         } else {           long long int id = divisor(v[i]);           cout << v[i] <<    ;           mp[id]--;           mp[v[i]]--;         }       }     }     return 0;   }
#include <bits/stdc++.h>   const int N = 1e6;   const int M = 2e5 + 10;   const int mod = 1e9 + 7;   long long n, a[M], cnt[N], cnt2[N], sol[N];   long long brzo_stepenovanje(long long x, long long k) {     if (k == 0) return 1;     if (k == 1) return x;     if (k % 2)       return (x * brzo_stepenovanje((x * x) % mod, k / 2)) % mod;     else       return brzo_stepenovanje((x * x) % mod, k / 2) % mod;   }   int main() {     scanf( %lld , &n);     for (int i = 1; i <= n; i++) cnt[i] = 0, cnt2[i] = 0;     for (int i = 1; i <= n; i++) {       scanf( %lld , &a[i]);       cnt2[a[i]]++;     }     for (int i = 2; i <= N; i++)       for (int j = i; j <= N; j += i) {         cnt[i] += cnt2[j];       }     for (int i = 1; i <= N; i++) sol[i] = 0;     for (int i = 2; i <= N; i++)       sol[i] = (cnt[i] * brzo_stepenovanje(2, cnt[i] - 1)) % mod;     for (int i = N / 2; i >= 2; i--)       for (int j = i + i; j <= N; j += i) {         sol[i] -= sol[j];         if (sol[i] < 0) sol[i] += mod;       }     long long ans = 0;     for (int i = 2; i <= N; i++) {       ans += (sol[i] * i) % mod;       ans %= mod;     }     printf( %lld , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     string name;     vector<struct node *> sub;   };   typedef struct node *NODE;   class cf56c {    public:     int ans = 0;     void solve(std::istream &in, std::ostream &out) {       string s;       int n;       in >> s;       n = s.length();       stack<struct node *> stk;       int p = 0;       string word;       while (s[p] >=  A  && s[p] <=  Z ) {         word += s[p];         p++;       }       NODE root = new struct node;       root->name = word;       stk.push(root);       while (p < n) {         string t;         NODE latest = stk.top();         if (s[p] ==  ,  || s[p] ==  : ) {           p++;           while (s[p] >=  A  && s[p] <=  Z  && p < n) {             t += s[p];             p++;           }           NODE child = new struct node;           child->name = t;           latest->sub.push_back(child);           stk.push(child);         }         if (s[p] ==  . ) {           stk.pop();           p++;         }       }       unordered_map<string, int> visited;       dfs(root, visited);       out << ans;     }     void dfs(NODE root, unordered_map<string, int> visited) {       string employee = root->name;       vector<NODE> children = root->sub;       ans += visited[employee];       visited[employee]++;       for (auto &i : children) {         dfs(i, visited);       }     }   };   int main() {     ios_base::sync_with_stdio(false);     cf56c solver;     std::istream &in(std::cin);     std::ostream &out(std::cout);     solver.solve(in, out);     return 0;   }
#include <bits/stdc++.h>   int main() {     int a, b, c, d;     scanf( %d%d%d%d , &a, &b, &c, &d);     int ans = 0;     if (a == b) {       ans++;     } else if (b == c) {       ans++;     } else if (b == d) {       ans++;     }     if (a == c) {       ans++;     } else if (c == d) {       ans++;     }     if (a == d) {       ans++;     }     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Node {     int l, r, x, id;   } a[1000005];   bool operator<(const Node& t1, const Node& t2) {     if (t1.l != t2.l) return t1.l < t2.l;     if (t1.x != t2.x) return t1.x > t2.x;     if (t1.r != t2.r) return t1.l < t2.r;     return t1.x > t2.x;   }   struct Node1 {     Node1(int a, int b, int c) {       r = a;       x = b;       id = c;     }     int r, x, id;   };   bool operator<(const Node1& t1, const Node1& t2) {     if (t1.r != t2.r) return t1.r < t2.r;     return t1.id < t2.id;   }   set<Node1> iset;   int ans[100005];   int main() {     int n, m;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i].l >> a[i].r;       a[i].x = -1;       a[i].id = i;     }     cin >> m;     for (int i = 0; i < m; i++) {       cin >> a[i + n].l >> a[i + n].r >> a[i + n].x;       a[n + i].id = i + 1;     }     sort(a, a + m + n);     for (int i = 0; i < m + n; i++) {       if (a[i].x != -1)         iset.insert(Node1(a[i].r, a[i].x, a[i].id));       else {         set<Node1>::iterator it = iset.lower_bound(Node1(a[i].r, 0, 0));         if (it != iset.end()) {           Node1 t = *it;           iset.erase(it);           ans[a[i].id] = t.id;           t.x--;           if (t.x != 0) iset.insert(t);         } else {           cout <<  NO  << endl;           return 0;         }       }     }     cout <<  YES  << endl;     for (int i = 0; i < n - 1; i++) cout << ans[i] <<    ;     cout << ans[n - 1] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int ntests;     cin >> ntests;     while (ntests--) {       int n, k, a, b;       cin >> k >> n >> a >> b;       if (k <= 1ll * n * b)         cout << -1 << endl;       else {         long long x = (k - 1ll * n * b - 1) / (a - b);         if (x > n) x = n;         cout << x << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   long long tree[100002] = {0};   long long findcf(long long ind) {     long long sum = 0;     while (ind > 0) {       sum += tree[ind];       ind -= (ind & (-ind));     }     return sum;   }   void update(long long ind, long long val) {     while (ind <= 100000) {       tree[ind] += val;       ind += (ind & (-ind));     }   }   void incFreqFromTo(long long a, long long b, long long delta) {     update(a, delta);     update(b + 1, -delta);   }   long long getFreqAt(long long index) { return findcf(index); }   int main() {     ios::sync_with_stdio(false);     long long t, i, j, n, m, x;     cin >> n >> m;     for (i = 1; i <= n; ++i) {       cin >> t;       incFreqFromTo(i, i, t);     }     for (i = 0; i < m; ++i) {       cin >> t;       if (t == 1) {         cin >> j >> x;         incFreqFromTo(j, j, x - getFreqAt(j));       } else if (t == 2) {         cin >> x;         incFreqFromTo(1, n, x);       } else {         cin >> j;         cout << getFreqAt(j) <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct LINE {     int start;     int end;   };   int ans = 0;   vector<int> res;   string shift(string s, int p1, int p2) {     char t;     for (int f = p2; f > p1; f--) {       ans++;       res.push_back(f);       t = s[f];       s[f] = s[f - 1];       s[f - 1] = t;     }     return s;   }   int main() {     string s, t;     int a1[27];     int a2[27];     for (int i = 0; i < 27; i++) {       a2[i] = 0;       a1[i] = 0;     }     getline(std::cin, s);     getline(std::cin, s);     getline(std::cin, t);     for (int i = 0; i < s.length(); i++) {       a1[((int)s[i]) - 97]++;     }     for (int i = 0; i < t.length(); i++) {       a2[((int)t[i]) - 97]++;     }     for (int i = 0; i < 27; i++) {       if (a1[i] != a2[i]) {         cout << -1;         return 0;       }     }     for (int i = 0; i < s.length(); i++) {       if (s[i] == t[i]) continue;       int a = s.find(t[i], i);       s = shift(s, i, a);     }     cout << ans <<   n ;     for (int i = 0; i < res.size(); i++) {       cout << res[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int i;   char s[100005];   int main() {     scanf( %s , s);     int l = strlen(s);     for (i = 0; i < l; i++) {       if (s[i] == s[l - 1 - i]) continue;       return 0 * printf( NO n );     }     for (i = 0; i < l; i++) {       if (s[i] ==  A  || s[i] ==  H  || s[i] ==  I  || s[i] ==  M  ||           s[i] ==  O  || s[i] ==  T  || s[i] ==  U  || s[i] ==  V  ||           s[i] ==  W  || s[i] ==  X  || s[i] ==  Y )         continue;       return 0 * printf( NO n );     }     printf( YES n );   }
#include <bits/stdc++.h>   using namespace std;   int n;   char in[100005];   int main() {     scanf( %d %s , &n, in);     for (int i = 1; i < n; i++) {       if (in[i] == in[i - 1]) {         for (int j = i;; j++) {           in[j] = 1 - (in[j] -  0 ) +  0 ;           if (in[j + 1] != in[j]) break;         }         break;       }     }     char prv =  2 ;     int cnt = 0;     for (int i = 0; i < n; i++)       if (in[i] != prv) {         prv = in[i];         cnt++;       }     printf( %d , cnt);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7, maxn = 1e6 + 6;   int n, m, k, x, res = 1, fact[maxn];   map<vector<int>, int> f;   vector<int> a[maxn];   int main() {     fact[0] = 1;     for (int i = 1; i < maxn; ++i) fact[i] = 1LL * fact[i - 1] * i % mod;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) {       scanf( %d , &k);       for (int j = 1; j <= k; ++j) {         scanf( %d , &x);         a[x].push_back(i);       }     }     for (int i = 1; i <= m; ++i) sort(a[i].begin(), a[i].end()), ++f[a[i]];     for (map<vector<int>, int>::iterator it = f.begin(); it != f.end(); ++it) {       res = 1LL * res * fact[it->second] % mod;     }     printf( %d , res);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t, a[100], b[100], i;     cin >> t;     string s1, s2;     while (t--) {       set<char> track;       string s3 =   , s4;       int flag = 0;       cin >> s1 >> s2;       if (s1.size() > s2.size()) {         cout <<  NO  << endl;         continue;       }       s4 = s1;       sort(s4.begin(), s4.end());       for (i = 0; s1[i]; i++) track.insert(s1[i]);       for (i = 0; i <= s2.size() - s1.size(); i++) {         int cnt = 0, k = i;         s3 =   ;         for (int j = 0; j < s1.size(); j++) {           s3 += s2[k++];         }         sort(s3.begin(), s3.end());         if (s4 == s3) {           cout <<  YES  << endl;           flag = 1;           break;         }       }       if (flag == 0) cout <<  NO  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 5, M = 5e5 + 5;   bool vis[N];   int q[N], tot, fa[N];   int n, m, k, head[N], ne[M << 1], to[M << 1], cnt, d[N];   inline int read() {     int x, f = 1;     char ch;     while (!(isdigit(ch = getchar()))) ch ==  -  ? f = -1 : f;     x = ch ^ 48;     while ((isdigit(ch = getchar()))) x = (x << 1) + (x << 3) + (ch ^ 48);     return f * x;   }   inline void ins(int x, int y) {     ne[++cnt] = head[x];     head[x] = cnt;     to[cnt] = y;   }   inline void dfs(int x) {     vis[x] = 1;     if (d[x] >= (n + k - 1) / k) {       puts( PATH );       printf( %d n , d[x]);       while (x) printf( %d  , x), x = fa[x];       exit(0);     }     bool pd = 0;     for (int i = head[x]; i; i = ne[i]) {       if (fa[x] == to[i] || vis[to[i]]) continue;       fa[to[i]] = x;       d[to[i]] = d[x] + 1;       pd = 1;       dfs(to[i]);     }     if (!pd) q[++tot] = x;   }   int main() {     n = read();     m = read();     k = read();     for (int i = 1; i <= m; i++) {       int x = read(), y = read();       ins(x, y);       ins(y, x);     }     d[1] = 1;     dfs(1);     puts( CYCLES );     for (int j = 1; j <= k; j++) {       int x = q[j], y = 0, z = 0;       for (int i = head[x]; i; i = ne[i]) {         if (fa[x] == to[i]) continue;         if (!y)           y = to[i];         else           z = to[i];       }       int res = d[x] - d[y] + 1;       if (res % 3) {         printf( %d n , res);         while (x != y) {           printf( %d  , x);           x = fa[x];         }         printf( %d n , y);         continue;       }       res = d[x] - d[z] + 1;       if (res % 3) {         printf( %d n , res);         while (x != z) {           printf( %d  , x);           x = fa[x];         }         printf( %d n , z);         continue;       }       if (d[y] < d[z]) swap(y, z);       res = d[y] - d[z] + 2;       printf( %d n , res);       while (y != z) {         printf( %d  , y);         y = fa[y];       }       printf( %d %d n , z, x);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 5;   const int INF = 2e9;   const int MOD = 1e9 + 7;   int main() {     vector<int> RES;     string S =   ;     cin >> S;     int N = S.size(), last = -1, depth = 0;     for (int i = 0; i < N; i++) {       if (S[i] ==  ( )         depth++;       else {         if (S[i] ==  # ) last = i;         depth--;       }       if (depth < 0) return printf( -1 ), 0;     }     int val = depth;     depth = 0;     for (int i = 0; i < N; i++) {       if (S[i] ==  ( )         depth++;       else {         int removeIt = (i == last && S[i] ==  #  ? val : 0) + 1;         depth -= removeIt;         if (S[i] ==  # ) RES.push_back(removeIt);       }       if (depth < 0) return printf( -1 ), 0;     }     for (int i = 0; i < RES.size(); i++) printf( %i n , RES[i]);     return 0;   }
#include <bits/stdc++.h>   void swap(long double& a, long double& b) {     long double tmp = a;     a = b, b = tmp;   }   long double solve(long double d, long double r, long double R) {     const long double EPS = 1e-9L;     if (d + EPS >= r + R) return 0;     if (r > R) swap(r, R);     if (R + EPS >= d + r) return acosl(-1.0) * r * r;     long double T = 2 * acosl((R * R + d * d - r * r) / (2 * R * d)),                 t = 2 * acosl((r * r + d * d - R * R) / (2 * r * d));     return .5 * (R * R * (T - sinl(T)) + r * r * (t - sinl(t)));   }   int main() {     long double x1, y1, r1, x2, y2, r2;     scanf( %Lf%Lf%Lf%Lf%Lf%Lf , &x1, &y1, &r1, &x2, &y2, &r2);     long double dx = x1 - x2, dy = y1 - y2;     printf( %.20Lf n , solve(sqrtl(dx * dx + dy * dy), r1, r2));   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long d, k, tc, tf, tr, res = 100 * 100 * 100 * 100LL;     scanf( %lld , &d);     ;     scanf( %lld , &k);     ;     scanf( %lld , &tc);     ;     scanf( %lld , &tf);     ;     scanf( %lld , &tr);     ;     if (k >= d) return 0 * printf( %lld , d * tc);     if (k * tc + tr >= k * tf) return 0 * printf( %lld , k * tc + (d - k) * tf);     long long chk = d / k;     long long bach_gya = d % k;     printf( %lld , tr * (chk - 1) + tc * chk * k +                        min(bach_gya * tc + tr, bach_gya * tf));   }
#include <bits/stdc++.h>   using namespace std;   int f[100001], d[40], sor[100001];   int n, kq;   bool solve(int a, int b, int &x, int &y) {     if (a % 2 != b % 2) return false;     y = (a + b) / 2;     x = (a - b) / 2;     return true;   }   int main() {     scanf( %d , &n);     kq = -1;     for (int i = 3; i < n + 1; i++) {       memset(d, false, sizeof(d));       for (int j = 2; j * j <= 2 * i; j++)         if ((2 * i) % j == 0) {           int x, y;           if (solve((2 * i) / j, j - 1, x, y)) {             d[sor[y] ^ sor[x - 1]] = true;             if (i == n && sor[y] == sor[x - 1])               if (kq == -1 || j < kq) kq = j;           }         }       for (int j = 0; j < 40; j++)         if (!d[j]) {           f[i] = j;           sor[i] = sor[i - 1] ^ j;           if (i == n && f[i] == 0) kq = -1;           break;         }     }     cout << kq << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   const long long mod = 998244353;   int mp[maxn], a[maxn];   char s[maxn];   int main() {     int T;     scanf( %d , &T);     while (T--) {       int n, x;       scanf( %d , &n);       scanf( %d , &x);       scanf( %s , s + 1);       int mn = 1e9, mx = -1e9;       for (int i = (1); i <= (n); i++) {         if (s[i] ==  0 )           a[i] = a[i - 1] + 1;         else           a[i] = a[i - 1] - 1;         mx = max(mx, a[i]), mn = min(mn, a[i]);       }       for (int i = (0); i <= (mx - mn); i++) mp[i] = 0;       for (int i = (1); i <= (n); i++) mp[a[i] - mn]++;       if (a[n] == 0) {         if (x < mn || x > mx || mp[x - mn] == 0) {           if (x != 0)             puts( 0 );           else             puts( 1 );         } else           puts( -1 );         continue;       }       if (a[n] > 0) {         int l = 0, r = 1e9, pos = -1;         while (l <= r) {           int mid = l + r >> 1;           if (x >= 1ll * mid * a[n] + mn && x <= 1ll * mid * a[n] + mx)             pos = mid, r = mid - 1;           else if (x < 1ll * mid * a[n] + mn)             r = mid - 1;           else             l = mid + 1;         }         long long ans = 0;         if (pos == -1)           ans = 0;         else {           int mpx = -1;           for (int i = pos * a[n] + mn; i <= pos * a[n] + mx; i++) {             if (i <= x)               mpx++;             else               break;           }           for (int i = mpx; i >= 0; i -= a[n]) ans += mp[i];         }         if (x == 0) ans++;         printf( %lld , ans);         puts(  );       } else {         int l = 0, r = 1e9, pos = -1;         while (l <= r) {           int mid = l + r >> 1;           if (x >= 1ll * mid * a[n] + mn && x <= 1ll * mid * a[n] + mx)             pos = mid, r = mid - 1;           else if (x < 1ll * mid * a[n] + mn)             l = mid + 1;           else             r = mid - 1;         }         long long ans = 0;         if (pos == -1)           ans = 0;         else {           int mpx = -1;           for (int i = pos * a[n] + mn; i <= pos * a[n] + mx; i++) {             if (i <= x)               mpx++;             else               break;           }           for (int i = mpx; i <= mx - mn; i += (-a[n])) ans += mp[i];         }         if (x == 0) ans++;         printf( %lld , ans);         puts(  );       }     }   }
#include<bits/stdc++.h>   using namespace std;   typedef pair<int,int> pi;   const int maxn=1e5+7;   double dp[maxn][10];   int pre[maxn][10];   int main()   {       ios::sync_with_stdio(false);       cin.tie(nullptr);       int n,d;       cin>>n>>d;       vector<int> a(n+1);       for(int i=0;i<maxn;i++) for(int j=0;j<10;j++) dp[i][j]=-1e9;       dp[0][1]=0;       for(int i=1;i<=n;i++)       {           cin>>a[i];           double val=log(a[i]);           for(int j=0;j<10;j++)           {               int nxt=j*a[i]%10;               if(dp[i-1][j]>dp[i][j])               {                   dp[i][j]=dp[i-1][j];                   pre[i][j]=j;               }               if(dp[i-1][j]+val>dp[i][nxt])               {                   dp[i][nxt]=dp[i-1][j]+val;                   pre[i][nxt]=j;               }           }       }       if(dp[n][d]<0)       {           cout<<-1<<  n ;           return 0;       }       vector<int> ans;       int cur=d;       for(int i=n;i>=1;i--)       {           int cc=a[i]%10;           if((pre[i][cur]*cc)%10==cur)           {               cur=pre[i][cur];               ans.push_back(a[i]);           }       }       if(ans.size()==0)       {           cout<<-1<<  n ;           return 0;       }       cout<<ans.size()<<  n ;       for(int i=0;i<ans.size();i++) cout<<ans[i]<<   n [i+1==ans.size()];      }