malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long Mxn = 1e6 + 7;   const long long Mod = 1e9 + 7;   const long long Inf = 1e16 + 7;   const long long Module = 998244353;   int N;   long long Ans, A[Mxn], B[Mxn], Val[Mxn];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> N;     for (int i = 1; i <= N; i++) {       cin >> A[i];     }     for (int i = 1; i <= N; i++) {       cin >> B[i];     }     sort(B + 1, B + N + 1);     for (int i = 1; i <= N; i++) {       Val[i] = (1LL * A[i] * i * (N - i + 1));     }     sort(Val + 1, Val + N + 1);     reverse(Val + 1, Val + N + 1);     for (int i = 1; i <= N; i++) {       Ans = (Ans + (1LL * B[i] * (Val[i] % Module)) % Module) % Module;     }     cout << Ans;     return false;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k;     cin >> n >> k;     vector<long long> v, v1;     map<long long, long long> m;     for (long long i = 0; i < n; i++) {       long long a;       cin >> a;       v.push_back(a);     }     long long a, c = 0;     cin >> a;     for (long long i = 0; i < n; i++)       if (v[i] > ((i + 1) * a + k)) c = -1;     long long val = k;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       v1.push_back(a);     }     long long sum = 0;     if (c == 0) {       for (long long i = 0; i < n; i++) {         m[v1[i]]++;         auto itr = m.begin();         while (v[i] > val && itr != m.end()) {           if (itr->second == 0 && itr != m.end()) {             auto itr1 = itr;             itr1++;             m.erase(itr->first);             itr = m.find(itr1->first);           } else {             val += a;             sum += itr->first;             (itr->second)--;           }         }       }       cout << sum <<   n ;     } else       cout <<  -1             <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int n, nc, a[111], b[111];   string c[111];   struct Node {     int lab;     Node *left, *right;     Node(int x) {       lab = x;       left = NULL;       right = NULL;     }   };   void printfalse() {     cout <<  IMPOSSIBLE ;     exit(0);   }   Node *solve(int x, int y) {     if (x > y) return NULL;     if (x == y) return new Node(x);     int l = -1, r = n + 1;     for (int i = (1); i <= (nc); i++) {       int u = a[i], v = b[i];       if (u == x) {         if (c[i][0] ==  L ) {           l = max(l, v);         } else {           r = min(r, v);         }       }     }     for (int s = (max(x, l)); s <= (min(y, r - 1)); s++) {       bool ok = true;       for (int i = (1); i <= (nc); i++) {         int u = a[i], v = b[i];         if (x < min(u, v) && min(u, v) <= s && s < max(u, v)) {           ok = false;         }       }       if (!ok) continue;       Node *r = new Node(x);       r->left = solve(x + 1, s);       r->right = solve(s + 1, y);       return r;     }     printfalse();   }   void print(Node *r) {     if (r == NULL) return;     print(r->left);     cout << r->lab <<    ;     print(r->right);   }   bool find(Node *u, int v) {     if (u == NULL) return false;     if (u->lab == v) return true;     return find(u->left, v) || find(u->right, v);   }   void visit(Node *u) {     if (u == NULL) return;     for (int i = (1); i <= (nc); i++)       if (a[i] == u->lab) {         if (c[i][0] ==  L ) {           if (!find(u->left, b[i])) printfalse();         } else {           if (!find(u->right, b[i])) printfalse();         }       }     visit(u->left);     visit(u->right);   }   int main() {     cin >> n >> nc;     for (int i = (1); i <= (nc); i++) {       cin >> a[i] >> b[i] >> c[i];     }     Node *r = solve(1, n);     visit(r);     print(r);   }
#include <bits/stdc++.h>   using namespace std;   int a[300000], b[300000];   int tree[1 << 21], lazy[1 << 21];   int prop(int s, int e, int i) {     tree[i] += lazy[i];     if (s != e) lazy[2 * i + 1] += lazy[i], lazy[2 * i + 2] += lazy[i];     lazy[i] = 0;     return 0;   }   int update(int s, int e, int as, int ae, int i, int num) {     prop(s, e, i);     if ((s > ae) || (e < as))       return tree[i];     else if ((s >= as) && (e <= ae)) {       lazy[i] += num;       prop(s, e, i);       return tree[i];     }     int mid = (s + e) / 2;     update(s, mid, as, ae, 2 * i + 1, num),         update(mid + 1, e, as, ae, 2 * i + 2, num);     tree[i] = min(tree[2 * i + 1], tree[2 * i + 2]);     return tree[i];   }   int query(int s, int e, int i) {     prop(s, e, i);     if (s == e) return s;     int mid = (s + e) / 2;     prop(mid + 1, e, 2 * i + 2);     if (tree[2 * i + 2] < 0)       return query(mid + 1, e, 2 * i + 2);     else       return query(s, mid, 2 * i + 1);   }   int main() {     int i;     int n, m, q;     int t, j, x;     scanf( %d %d , &n, &m);     for (i = 0; i < n; i++) scanf( %d , &a[i]);     for (i = 0; i < m; i++) scanf( %d , &b[i]);     for (i = 0; i < n; i++) update(0, 1000000, 1, a[i], 0, -1);     for (i = 0; i < m; i++) update(0, 1000000, 1, b[i], 0, 1);     scanf( %d , &q);     for (i = 0; i < q; i++) {       scanf( %d %d %d , &t, &j, &x), j--;       if (t == 1) {         update(0, 1000000, 1, a[j], 0, 1);         a[j] = x;         update(0, 1000000, 1, a[j], 0, -1);       } else {         update(0, 1000000, 1, b[j], 0, -1);         b[j] = x;         update(0, 1000000, 1, b[j], 0, 1);       }       int ans = query(0, 1000000, 0);       if (ans == 0)         printf( -1 n );       else         printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const string problemName =   ;   const string inputFile = problemName +  .in ;   const string outputFile = problemName +  .out ;   const int INF = (1LL << 31) - 1;   const long long int LINF = (1LL << 62) - 1;   const int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};   const int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};   const int MOD = (int)(1e9) + 7;   const int NMAX = 100000 + 5;   const int MMAX = 100000 + 5;   const int KMAX = 100000 + 5;   const int PMAX = 100000 + 5;   const int LMAX = 100000 + 5;   const int VMAX = 100000 + 5;   long long int t, a, b, n, i, tt, q, sol = 0;   long long int A[NMAX];   int putere(long long int b, long long int a) {     if (a == 1 && b != 1) return 0;     if (a != 1 && b == 1) return 0;     while (b != 1 && b % a == 0) b /= a;     return b == 1;   }   int main() {     scanf( %lld%lld%lld , &t, &a, &b);     if (t != 1 || (t == 1 && !putere(b, a))) {       if (a == b) sol++;       for (n = 0; b && a > 1; n++) {         A[n] = b % a;         b /= a;       }       for (i = q = 0, tt = 1; i < n; i++) {         q += A[i] * tt;         tt *= t;         if (q < 0 || q > a) break;       }       if (q == a) sol++;       printf( %lld , sol);     } else {       if (a == 1 && b == 1)         printf( inf );       else         printf( %d , putere(b, a));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   ostream& operator<<(ostream& os, vector<T> V) {     os <<  [  ;     for (auto v : V) os << v <<    ;     return os <<  ] ;   }   template <class L, class R>   ostream& operator<<(ostream& os, pair<L, R> P) {     return os <<  (  << P.first <<  ,  << P.second <<  ) ;   }   const long long Mod = 1e9 + 7;   const long long pre = 1e10;   const double inv = pow(10, -10);   double y, y2, yw, xb, yb, r;   int check(long long xp) {     double p = (double)xp * inv;     double slope = (yw - r - yb) / (xb - p);     double c = (yw - r) - slope * p;     if (c >= y2) return 1;     if (c <= y) return -1;     bool a = (c >= y + r);     bool b = (abs(y2 - c) >= r * (sqrt(1 + slope * slope)));     if (a && b)       return 0;     else if (!a && !b)       return -1;     else if (!a)       return -1;     else       return 1;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> y >> y2 >> yw >> xb >> yb >> r;     long long left = 0, right = xb * pre - 1, mid;     while (left <= right) {       mid = (left + right) / 2;       int t = check(mid);       if (t == 0) {         printf( %0.10lf n , (double)mid * inv);         return 0;       } else if (t == 1)         left = mid + 1;       else if (t == -1)         right = mid - 1;       else {         cout << -1 << endl;         return 0;       }     }     cout << -1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double L, R;   int n, i;   int a[10000];   double jami;   long long ans1, ans2, ans;   int main() {     L = 10.0;     R = 1000000000;     cin >> n;     for (i = 1; i <= n; i++) cin >> a[i];     for (i = 1; i <= n; i++) {       L = max(L, (double)((double)a[i] / i) * 10.0);       R = min(R, (double)((double)(a[i] + 1) / i) * 10.0);     }     R -= 0.000000001;     jami = (n + 1) * L;     jami -= 10 * a[n];     jami = floor(jami);     ans1 = jami / 10;     jami = (n + 1) * R;     jami -= 10 * a[n];     jami = floor(jami);     ans2 = jami / 10;     if (ans1 == ans2) {       cout <<  unique  << endl;       cout << a[n] + ans1 << endl;       return 0;     }     cout <<  not unique  << endl;   }
#include <bits/stdc++.h>   using namespace std;   struct query {     long long l, r, x;   };   int n, a[109];   long long m;   int main() {     cin >> n >> m;     vector<query> v;     vector<long long> cp = {1LL << 60};     for (int i = 0; i < n; i++) {       cin >> a[i];       int pr = sqrt(a[i]);       for (int j = 1; j < pr; j++) {         v.push_back(query{j, j + 1, (a[i] + j - 1) / j});         cp.push_back(j);       }       cp.push_back(pr);       int r = (a[i] + pr - 1) / pr, ptr = pr;       for (int j = r; j > 1; j--) {         v.push_back(query{ptr, (a[i] + j - 2) / (j - 1), j});         ptr = v.back().r;         cp.push_back(ptr);       }       v.push_back(query{ptr, 1LL << 60, 1});     }     sort(cp.begin(), cp.end());     cp.erase(unique(cp.begin(), cp.end()), cp.end());     vector<long long> sum(cp.size());     for (query i : v) {       int pl = lower_bound(cp.begin(), cp.end(), i.l) - cp.begin();       int pr = lower_bound(cp.begin(), cp.end(), i.r) - cp.begin();       sum[pl] += i.x;       sum[pr] -= i.x;     }     for (int i = 1; i < cp.size(); i++) sum[i] += sum[i - 1];     long long ret = 0;     for (int i = 0; i < cp.size() - 1; i++) {       long long r = min(cp[i + 1] - 1, (m + sum[0]) / sum[i]);       if (cp[i] <= r) ret = max(ret, r);     }     cout << ret << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long maxs = 1e6 + 5;   long long root[maxs];   class cmp {     bool operator()(const long long &a, const long long &b) { return a < b; }   };   void init() { iota(root, root + maxs, 0); }   long long find(long long u) {     long long f;     if (root[u] == u)       return u;     else {       long long f = find(root[u]);       root[u] = f;       return f;     }   }   void Union(long long x, long long y) {     long long u = find(x);     long long v = find(y);     root[v] = u;   }   long long power(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   void update(vector<long long> &BIT, long long ind, long long val) {     while (ind < BIT.size()) {       BIT[ind] += val;       ind += (ind & (-ind));     }   }   long long query(vector<long long> &BIT, long long ind) {     long long sum = 0;     while (ind > 0) {       sum += BIT[ind];       ind -= (ind & (-ind));     }     return sum;   }   void count_factors() {     long long i, j;     long long numOfDivisors[maxs] = {0};     long long ans[maxs] = {0};     for (i = 1; i < maxs; i++)       for (j = i; j < maxs; j += i) {         numOfDivisors[j]++;         ans[j]++;       }     for (i = 1; i < maxs; i++)       for (j = i; j < maxs; j += i)         if (numOfDivisors[j / i] == 4) ans[j] = min(ans[j], ans[i]);   }   long long get(long long x, long long y) {     if (x == 0) return 1;     long long cnt = 0;     while (x % y == 0) {       cnt++;       x /= y;     }     return cnt;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t, n, i, k, y, x, j, m, r, l;     cin >> t;     while (t--) {       cin >> n >> k;       vector<long long> arr(n + 1);       for (i = 1; i <= n; i++) {         cin >> arr[i];       }       vector<vector<long long>> dp(n + 1, vector<long long>(n + 1, 0));       for (i = 1; i <= n; i++) {         for (j = 1; j <= i; j++) {           dp[i][j] = dp[i - 1][j];           dp[i][j] = max(dp[i - 1][j - 1] + (arr[i] == j), dp[i][j]);         }       }       long long ans = 0;       for (i = 1; i <= n; i++) {         if (dp[n][i] >= k) ans = i;       }       if (ans == 0)         cout << -1 <<   n ;       else         cout << n - ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, i, sz, j;   map<char, int> m;   vector<long long> v;   vector<string> v2;   string s, ss;   int main() {     cin >> n >> s;     for (int i = 0; i < s.length(); i++) {       m[s[i]]++;       if (m[s[i]] == 1) {         v.push_back(i);       }     }     if (v.size() < n) {       cout <<  NO  << endl;       return 0;     }     vector<string> v2;     for (int i = 0; i < n; i++) {       string ss;       if (i != n - 1) {         for (int j = v[i]; j < v[i + 1]; j++) {           ss += s[j];         }       } else {         for (int j = v[i]; j < s.size(); j++) {           ss += s[j];         }       }       v2.push_back(ss);     }     cout <<  YES  << endl;     for (int i = 0; i < v2.size(); i++) {       cout << v2[i] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void checkmax(T& a, T b) {     if (a < b) a = b;   }   bool judge_taxi(string name) {     vector<char> vc;     for (int i = 0; i < (name.size()); i++)       if (isdigit(name[i])) vc.push_back(name[i]);     sort(vc.begin(), vc.end());     vc.erase(unique(vc.begin(), vc.end()), vc.end());     return vc.size() == 1;   }   bool judge_pizza(string name) {     char pre =  a ;     for (int i = 0; i < (name.size()); i++) {       if (isdigit(name[i])) {         if (name[i] < pre)           pre = name[i];         else           return false;       }     }     return true;     vector<char> vc;     for (int i = 0; i < (name.size()); i++)       if (isdigit(name[i])) vc.push_back(name[i]);     sort(vc.begin(), vc.end());     vc.erase(unique(vc.begin(), vc.end()), vc.end());     return vc.size() == 6;   }   int main(int argc, char* argv[]) {     int T;     while (cin >> T) {       vector<int> VT, VP, VG;       vector<string> VN;       int mtaxi = 0, mpizza = 0, mgirl = 0;       for (int i = 0; i < (T); i++) {         int si;         string name;         cin >> si >> name;         VN.push_back(name);         int taxi = 0, pizza = 0;         string phone;         for (int j = 0; j < (si); j++) {           cin >> phone;           if (judge_taxi(phone))             taxi++;           else if (judge_pizza(phone))             pizza++;         }         VT.push_back(taxi);         VP.push_back(pizza);         VG.push_back(si - taxi - pizza);         checkmax(mtaxi, taxi);         checkmax(mpizza, pizza);         checkmax(mgirl, si - taxi - pizza);       }       bool f = false;       cout <<  If you want to call a taxi, you should call:  ;       for (int i = 0; i < (VT.size()); i++)         if (VT[i] == mtaxi) {           if (f)             cout <<  ,  ;           else             f = true;           cout << VN[i];         }       cout <<  .  << endl;       f = false;       cout <<  If you want to order a pizza, you should call:  ;       for (int i = 0; i < (VT.size()); i++)         if (VP[i] == mpizza) {           if (f)             cout <<  ,  ;           else             f = true;           cout << VN[i];         }       cout <<  .  << endl;       cout <<  If you want to go to a cafe with a wonderful girl, you should                  call:  ;       f = false;       for (int i = 0; i < (VT.size()); i++)         if (VG[i] == mgirl) {           if (f)             cout <<  ,  ;           else             f = true;           cout << VN[i];         }       cout <<  .  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     vector<int> w;     cin >> n;     for (int i = 0; i < 2 * n; i++) {       int x;       cin >> x;       w.push_back(x);     }     long long int m = INT_MAX;     for (int i = 0; i < w.size(); i++) {       for (int j = i + 1; j < w.size(); j++) {         vector<int> temp;         for (int k = 0; k < w.size(); k++) {           if (k != i and k != j) {             temp.push_back(w[k]);           }         }         sort(temp.begin(), temp.end());         long long int sum = 0;         for (int k = 1; k < temp.size(); k += 2) {           sum += (temp[k] - temp[k - 1]);         }         m = min(m, sum);       }     }     cout << m << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5;   const int P = 1e9 + 7;   char s[N + 10];   int dp[N + 10][4];   int main() {     int n;     cin >> n >> (s + 1);     dp[0][0] = 1;     for (int i = 1; i <= n; i++) {       if (s[i] !=  ? ) {         memcpy(dp[i], dp[i - 1], sizeof(dp[i]));         (dp[i][s[i] -  a  + 1] += dp[i - 1][s[i] -  a ]) %= P;       } else {         memcpy(dp[i], dp[i - 1], sizeof(dp[i]));         dp[i][0] = 3ll * dp[i][0] % P;         for (int j = 1; j <= 3; j++) {           dp[i][j] = (3ll * dp[i][j] + dp[i - 1][j - 1]) % P;         }       }     }     cout << dp[n][3];   }
#include <bits/stdc++.h>   using namespace std;   long long d[25];   int main() {     long long t;     cin >> t;     while (t--) {       long long n, s;       cin >> n >> s;       long long len = 0, sum = 0, num = n;       fill(d, d + 25, 0);       while (num > 0) {         d[++len] = num % 10;         sum += d[len];         num /= 10;       }       if (sum <= s) {         cout << 0 << endl;         continue;       }       long long cur = 0;       for (int i = len; i >= 1; i--) {         cur += d[i];         if (cur >= s) {           d[i + 1]++;           for (int j = i; j >= 1; j--) d[j] = 0;           break;         }       }       long long ans = 0;       cur = 1;       for (int i = 1; i <= len + 1; i++) {         d[i + 1] += d[i] / 10;         d[i] = d[i] % 10;         ans += d[i] * cur;         cur *= 10;       }       cout << ans - n << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int w[int(1e5) + 10], id[int(1e5) + 10];   int m;   bitset<1010> primes, aux;   struct segtree {     bitset<1010> values;     int start, end, mid, lazy;     segtree *left, *right;     segtree(int start, int end) : start(start), end(end) {       lazy = 0;       if (start != end) {         mid = (start + end) / 2;         left = new segtree(start, mid);         right = new segtree(mid + 1, end);         values = left->values | right->values;       } else {         left = right = NULL;         values.reset();         values[w[id[start]]] = 1;       }     }     void rotate_mask(int x) {       values = values << x | values >> (m - x);       values &= aux;     }     void propagate() {       lazy %= m;       if (lazy) {         rotate_mask(lazy);         if (left != right) {           left->lazy += lazy;           left->lazy %= m;           right->lazy += lazy;           right->lazy %= m;         }         lazy = 0;       }     }     void update(int x, int y, int sum) {       propagate();       if (x == start && y == end) {         lazy += sum;         propagate();       } else {         if (y <= mid)           left->update(x, y, sum);         else if (x > mid)           right->update(x, y, sum);         else           left->update(x, mid, sum), right->update(mid + 1, y, sum);         left->propagate();         right->propagate();         values = left->values | right->values;       }     }     bitset<1010> query(int x, int y) {       propagate();       if (x == start && y == end) return values;       if (y <= mid)         return left->query(x, y);       else if (x > mid)         return right->query(x, y);       else         return left->query(x, mid) | right->query(mid + 1, y);     }   };   vector<vector<int> > G;   int start[int(1e5) + 10], fin[int(1e5) + 10], n;   void preorder(int u, int p, int &t) {     id[t] = u;     start[u] = t++;     for (int i = 0; i < G[u].size(); i++) {       int v = G[u][i];       if (v != p) preorder(v, u, t);     }     fin[u] = t - 1;   }   void sieve() {     primes.set();     primes[0] = primes[1] = 0;     for (int i = 2; i <= 1000; i++)       if (primes[i])         for (int j = i + i; j <= 1000; j += i) primes[j] = 0;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> w[i], w[i] %= m;     G = vector<vector<int> >(n);     int a, b;     for (int i = 0; i < n - 1; i++) {       cin >> a >> b;       a--;       b--;       G[a].push_back(b);       G[b].push_back(a);     }     int t = 0;     preorder(0, -1, t);     sieve();     for (int i = m - 1; i >= 0; i--) aux[i] = 1;     segtree st(0, n - 1);     int q, op;     cin >> q;     while (q--) {       cin >> op;       if (op == 1) {         cin >> a >> b;         b %= m;         a--;         st.update(start[a], fin[a], b);       } else {         cin >> a;         a--;         cout << int((st.query(start[a], fin[a]) & primes).count()) <<   n ;       }     }   }
#include <bits/stdc++.h>   int main() {     int n, i, j;     scanf( %d , &n);     long long int a[n][2], x, y, max1, max2, min1, min2;     for (i = 0; i < n; i++)       for (j = 0; j < 2; j++) scanf( %I64d , &a[i][j]);     min1 = max1 = a[0][0];     min2 = max2 = a[0][1];     for (i = 0; i < n; i++) {       if (min1 > a[i][0]) min1 = a[i][0];       if (max1 < a[i][0]) max1 = a[i][0];       if (min2 > a[i][1]) min2 = a[i][1];       if (max2 < a[i][1]) max2 = a[i][1];     }     x = max1 - min1;     y = max2 - min2;     if (x > y)       printf( %I64d , x * x);     else       printf( %I64d , y * y);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 150000;   int b[maxn];   long long a[maxn];   int main(void) {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &b[i]);     b[0] = b[n];     int id = 0;     for (int i = 1; i <= n; i++)       if (b[i] > b[i - 1]) {         id = i;         break;       }     if (id == 0) {       if (b[1] == 0) {         printf( YES n );         for (int i = 1; i <= n; i++) printf( 1%c ,    n [i == n]);       } else         printf( NO n );       return 0;     }     a[id] = max(b[id], 1);     for (int i = 0; i < n - 1; i++) {       int nid = id - 1;       if (nid == 0) nid = n;       int nnid = nid - 1;       if (nnid == 0) nnid = n;       a[nid] = b[nid];       if (b[nnid] >= b[nid]) a[nid] += ((b[nnid] - b[nid]) / a[id] + 1) * a[id];       if (a[nid] == 0) a[nid] = a[id];       id = nid;     }     a[n + 1] = a[1];     printf( YES n );     for (int i = 1; i <= n; i++) printf( %I64d%c , a[i],    n [i == n]);     return 0;   }