malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ll n, a, b;     cin >> n >> a >> b;     ll tot = 6 * n;     ll ans = 1e18;     if (a * b >= tot) {       cout << a * b <<   n  << a <<     << b <<   n ;     } else {       bool swp = false;       if (a > b) {         swp = true;         swap(a, b);       }       ll na = a, nb = b;       for (ll i = 1; i * i <= tot; i++) {         ll j = tot / i;         if (i * j < tot) j++;         if (i >= a && j >= b) {           if (i * j >= tot && i * j <= ans) {             ans = i * j;             na = i;             nb = j;           }         }       }       if (swp) swap(na, nb);       cout << na * nb <<   n  << na <<     << nb <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   namespace IO {   char buf[1 << 23], *p1 = buf, *p2 = buf;   template <typename T>   inline void read(T &x) {     x = 0;     register char ch =         (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)              ? EOF              : *p1++);     while (!(ch >= 48 && ch <= 57))       ch =           (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)                ? EOF                : *p1++);     while ((ch >= 48 && ch <= 57)) {       x = (x << 1) + (x << 3) + (ch ^ 48);       ch =           (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)                ? EOF                : *p1++);     }   }   template <typename T, typename... Args>   inline void read(T &t, Args &...args) {     read(t);     read(args...);   }   }  // namespace IO   using namespace IO;   const int N = 1e5 + 10, inf = 0x3f3f3f3f;   struct ALTXDY {     int tp, t, x, y, id;     bool operator<(ALTXDY const &a) const {       return x == a.x ? tp < a.tp : x < a.x;     }   };   ALTXDY q[N << 1];   int n, m, k, tot, rt, bus[N], ans[N], c[N << 1], dat[N << 2], ls[N << 2],       rs[N << 2];   void update(int &i, int l, int r, int x, int k) {     if (!i) i = ++tot;     if (bus[dat[i]] < bus[k]) dat[i] = k;     if (l == r) return;     int mid = (l + r) >> 1;     if (x <= mid)       update(ls[i], l, mid, x, k);     else       update(rs[i], mid + 1, r, x, k);   }   int query(int i, int l, int r, int x, int y, int val) {     if (l == r) return dat[i];     int mid = (l + r) >> 1, t = -1;     if (x <= mid && ls[i] && bus[dat[ls[i]]] >= val)       t = query(ls[i], l, mid, x, y, val);     if (t == -1 && y >= mid + 1 && rs[i] && bus[dat[rs[i]]] >= val)       t = query(rs[i], mid + 1, r, x, y, val);     return t;   }   int main() {     read(n, m);     for (int i = 1; i <= n; i++) {       int s, f, t;       read(s, f, t);       q[i] = (ALTXDY){0, t, s, f, i};       c[++k] = t;       bus[i] = f;     }     for (int i = 1; i <= m; i++) {       int b, l, r;       read(l, r, b);       q[i + n] = (ALTXDY){1, b, l, r, i};       c[++k] = b;     }     sort(c + 1, c + 1 + k);     k = unique(c + 1, c + 1 + k) - c - 1;     for (int i = 1; i <= n + m; i++)       q[i].t = lower_bound(c + 1, c + 1 + k, q[i].t) - c;     sort(q + 1, q + 1 + n + m);     for (int i = 1; i <= n + m; i++)       if (q[i].tp == 0)         update(rt, 1, k, q[i].t, q[i].id);       else         ans[q[i].id] = query(rt, 1, k, q[i].t, k, q[i].y);     for (int i = 1; i <= m; i++) printf( %d  , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, i;   double am, vm2, d, tant, ti, vm, t, s, daux, tfin;   int main() {     scanf( %d %lf %lf , &n, &am, &d);     tant = 0;     for (i = 0; i < n; i++) {       scanf( %lf %lf , &ti, &vm);       t = (vm / am);       s = 0.5 * (vm * vm / am);       daux = d - s;       if (daux < 0) {         vm2 = sqrt(2 * d * am);         tfin = vm2 / am;         tfin += ti;       } else {         tfin = daux / vm;         tfin += (ti + t);       }       if (tfin > tant) {         tant = tfin;       }       printf( %.10lf n , tant);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   namespace io {   const int L = (1 << 20) + 1;   char buf[L], *S, *T, c;   char getchar() {     if (__builtin_expect(S == T, 0)) {       T = (S = buf) + fread(buf, 1, L, stdin);       return (S == T ? EOF : *S++);     }     return *S++;   }   int inp() {     int x = 0, f = 1;     char ch;     for (ch = getchar(); !isdigit(ch); ch = getchar())       if (ch ==  - ) f = -1;     for (; isdigit(ch); x = x * 10 + ch -  0 , ch = getchar())       ;     return x * f;   }   unsigned inpu() {     unsigned x = 0;     char ch;     for (ch = getchar(); !isdigit(ch); ch = getchar())       ;     for (; isdigit(ch); x = x * 10 + ch -  0 , ch = getchar())       ;     return x;   }   long long inp_ll() {     long long x = 0;     int f = 1;     char ch;     for (ch = getchar(); !isdigit(ch); ch = getchar())       if (ch ==  - ) f = -1;     for (; isdigit(ch); x = x * 10 + ch -  0 , ch = getchar())       ;     return x * f;   }   char B[25], *outs = B + 20, *outr = B + 20;   template <class T>   inline void print(register T a, register char x = 0) {     if (x) *--outs = x, x = 0;     if (!a)       *--outs =  0 ;     else       while (a) *--outs = (a % 10) + 48, a /= 10;     if (x) *--outs = x;     fwrite(outs, outr - outs, 1, stdout);     outs = outr;   }   };  // namespace io   using io ::inp;   using io ::inp_ll;   using io ::inpu;   using io ::print;   using i32 = int;   using i64 = long long;   using u8 = unsigned char;   using u32 = unsigned;   using u64 = unsigned long long;   using f64 = double;   using f80 = long double;   long long power(long long a, long long b, long long p) {     if (!b) return 1;     long long t = power(a, b / 2, p);     t = t * t % p;     if (b & 1) t = t * a % p;     return t;   }   template <class T>   inline void freshmin(T &a, const T &b) {     if (a > b) a = b;   }   template <class T>   inline void freshmax(T &a, const T &b) {     if (a < b) a = b;   }   const int MAXN = 510;   const int MAXP = 10000000;   const u64 MOD = 1000000007;   const f80 MI = f80(1) / MOD;   const long long INF = 10000000000000000LL;   const long long inf = 5000000000000LL;   int n;   struct node {     long long a, b, k;     void init() { scanf( %lld%lld%lld , &a, &b, &k); }     bool operator<(const node &A) const { return b > A.b; }   } p[MAXN];   long long F[MAXN][MAXN];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) p[i].init();     sort(p + 1, p + n + 1);     for (int i = 1; i <= n; ++i)       for (int j = 0; j <= i; ++j) {         F[i][j] = F[i - 1][j] + max(p[i].a - p[i].b * p[i].k, 0LL);         if (j) freshmax(F[i][j], F[i - 1][j - 1] + p[i].a - p[i].b * (j - 1));       }     cout << *max_element(F[n], F[n] + n + 1) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long N = 2e5 + 5;   long long gcd(long long n, long long m) {     if (n == 0)       return m;     else       return gcd(m % n, n);   }   long long a[105], b[105];   vector<pair<long long, long long> > v1, v2;   long long dp[103][60000];   long long go(long long pos, long long r) {     if (r < 0) return -MOD;     if (pos == v2.size()) {       return 0;     }     long long &ans = dp[pos][r];     if (ans != -1) return ans;     ans = go(pos + 1, r);     if (r >= a[v2[pos].second]) {       ans = max(ans, go(pos + 1, r + b[v2[pos].second]) + 1);     }     return ans;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long n, r;     cin >> n >> r;     for (long long i = 1; i <= n; i++) {       cin >> a[i] >> b[i];       if (b[i] >= 0) {         v1.push_back({a[i], b[i]});       } else {         v2.push_back({-(a[i] + b[i]), i});       }     }     memset(dp, -1, sizeof(dp));     if (v1.size() > 0) {       sort(v1.begin(), v1.end());       long long ans = 0;       for (long long i = 0; i < v1.size(); i++) {         if (r >= v1[i].first) {           r += v1[i].second;           ans++;         }       }       if (v2.size() == 0) {         cout << ans << endl;         return 0;       }       sort(v2.begin(), v2.end());       long long k = go(0, r);       cout << ans + k << endl;     } else {       sort(v2.begin(), v2.end());       cout << go(0, r) << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   int n;   long long f[N][2], down[N], g[N], h[N], a[N];   vector<int> e[N];   template <typename T>   inline void chkmax(T &x, T y) {     x = max(x, y);   }   template <typename T>   inline void chkmin(T &x, T y) {     x = min(x, y);   }   template <typename T>   inline void read(T &x) {     T f = 1;     x = 0;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -f;     for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c -  0 ;     x *= f;   }   inline void DFS(int u, int par) {     f[u][0] = f[u][1] = down[u] = g[u] = a[u];     for (unsigned i = 0; i < e[u].size(); ++i) {       int v = e[u][i];       if (v == par) continue;       DFS(v, u);       chkmax(f[u][0], f[v][0]);       chkmax(f[u][0], f[u][1] + f[v][1]);       chkmax(f[u][0], down[u] + g[v]);       chkmax(f[u][0], down[v] + g[u]);       chkmax(f[u][1], f[v][1]);       chkmax(f[u][1], down[u] + down[v]);       chkmax(g[u], g[v] + a[u]);       chkmax(g[u], down[u] + f[v][1]);       chkmax(g[u], down[v] + a[u] + h[u]);       chkmax(h[u], f[v][1]);       chkmax(down[u], a[u] + down[v]);     }   }   int main() {     read(n);     for (int i = 1; i <= n; ++i) read(a[i]);     for (int i = 1; i < n; ++i) {       int u, v;       read(u);       read(v);       e[u].push_back(v);       e[v].push_back(u);     }     DFS(1, 0);     printf( %lld n , f[1][0]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, x, y, i, j, a1 = 0, a2 = 0, b1 = 0, b2 = 0;     cin >> n >> m;     int a[n], b[m];     for (i = 0; i < n; i++) cin >> a[i];     for (i = 0; i < m; i++) cin >> b[i];     for (i = 0; i < n; i++) {       if (a[i] % 2 == 1)         a1++;       else         a2++;     }     for (i = 0; i < m; i++) {       if (b[i] % 2 == 1)         b1++;       else         b2++;     }     x = a1;     if (b2 < x) x = b2;     y = a2;     if (b1 < y) y = b1;     cout << x + y;   }
#include <bits/stdc++.h>   using namespace std;   int n, s, i, j, k, l, x, y;   int a[200010];   struct node {     int i;   };   bool operator<(node x, node y) { return a[x.i] < a[y.i]; }   multiset<node> S;   multiset<node>::iterator p, p2;   int li[200010];   vector<pair<int, int> > v;   int main() {     scanf( %d%d , &n, &s);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++) S.insert((node){i});     while (!S.empty()) {       if (a[(*S.begin()).i] == 0) {         S.erase(S.begin());         continue;       }       p = --S.end();       x = (*p).i;       S.erase(p);       for (li[0] = 0; a[x]; a[x]--)         if (S.empty())           return puts( No ), 0;         else {           p2 = --S.end();           y = (*p2).i;           S.erase(p2);           li[++li[0]] = y;           a[y]--;           v.push_back(make_pair(x, y));         }       for (; li[0]; li[0]--) S.insert((node){li[li[0]]});     }     if (S.empty()) {       printf( Yes n );       printf( %d n , s / 2);       for (int k = 0; k < v.size(); k++)         printf( %d %d n , v[k].first, v[k].second);     } else       printf( No n );     scanf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int read() {     char ch =    ;     int x = 0;     bool flag = false;     while (!isdigit(ch)) {       if (ch ==  - ) flag = true;       ch = getchar();     }     while (isdigit(ch)) {       x = (x << 3) + (x << 1) + ch -  0 ;       ch = getchar();     }     return flag ? -x : x;   }   struct heap {     vector<pair<int, int> > v;     int loc[N];     heap() {       v.push_back(make_pair(-1, -1));       memset(loc, -1, sizeof loc);     }     void push(pair<int, int> p) {       int cur;       cur = v.size();       loc[p.second] = cur;       v.push_back(p);       while (v[cur] < v[cur >> 1]) {         swap(v[cur], v[cur >> 1]);         swap(loc[v[cur].second], loc[v[cur >> 1].second]);         cur >>= 1;       }     }     void pop() {       if (empty()) return;       swap(v[1], v.back());       loc[v[1].second] = 1;       loc[v.back().second] = -1;       v.pop_back();       int cur = 1;       while ((cur << 1) < v.size()) {         if ((cur << 1) + 1 == v.size()) {           if (v[cur] > v[cur << 1])             swap(v[cur], v[cur << 1]),                 swap(loc[v[cur].second], loc[v[cur << 1].second]);           break;         }         if (v[cur] < min(v[cur << 1], v[(cur << 1) + 1])) break;         if (v[cur << 1] < v[(cur << 1) + 1]) {           swap(v[cur], v[cur << 1]);           swap(loc[v[cur].second], loc[v[cur << 1].second]);           cur <<= 1;         } else {           swap(v[cur], v[(cur << 1) + 1]);           swap(loc[v[cur].second], loc[v[(cur << 1) + 1].second]);           cur = (cur << 1) + 1;         }       }     }     pair<int, int> top() { return v[1]; }     bool empty() { return v.size() == 1; }   };   int n, m;   vector<int> bad[N];   vector<pair<int, int> > v[N];   int d[N];   heap pq;   int main() {     n = read(), m = read();     for (int i = 0; i < m; i++) {       int a = read(), b = read(), c = read();       --a, --b;       v[a].push_back(make_pair(b, c));       v[b].push_back(make_pair(a, c));     }     for (int i = 0; i < n; i++) {       int num = read();       while (num--) {         bad[i].push_back(read());       }     }     for (int i = 0; i < n; i++) d[i] = 0x3f3f3f3f;     d[0] = 0;     pq.push(make_pair(0, 0));     while (!pq.empty()) {       pair<int, int> tp = pq.top();       pq.pop();       int t = tp.first;       int cur = tp.second;       if (t != d[cur]) continue;       int j = 0;       while (j < bad[cur].size() && bad[cur][j] < t) j++;       while (j < bad[cur].size() && bad[cur][j] == t) t++, j++;       for (int i = 0; i < v[cur].size(); i++) {         int to = v[cur][i].first, cost = v[cur][i].second;         if (t + cost < d[to]) {           d[to] = t + cost;           pq.push(make_pair(d[to], to));         }       }     }     if (d[n - 1] >= 0x3f3f3f3f)       puts( -1 );     else       cout << d[n - 1] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int atoi(string s) {     int sol = 0, st = 1;     for (int i = 0; i < int(s.size()); i++) {       sol += (s[i] - 48) * st;       st *= 10;     }     return sol;   }   int main() {     string a, b;     cin >> a >> b;     reverse(a.begin(), a.end());     cout << atoi(a) + atoi(b) << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int oo = 0x3f3f3f3f;   const long long ooo = 9223372036854775807ll;   const int _cnt = 1000 * 1000 + 7;   const int _p = 1000 * 1000 * 1000 + 7;   const int N = 1001005;   const double PI = acos(-1.0);   const double eps = 1e-9;   int o(int x) { return x % _p; }   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int lcm(int a, int b) { return a / gcd(a, b) * b; }   void file_put() {     freopen( filename.in ,  r , stdin);     freopen( filename.out ,  w , stdout);   }   int p[N], prime[N], phi[N], top, T, X, P, K, pp[N];   long long l, r, mid, ans;   void init_prime(int N) {     top = 0, phi[1] = 1;     for (int i = 2; i <= N; ++i) {       if (!p[i]) prime[++top] = i, phi[i] = i - 1;       for (int j = 1; j <= top; ++j) {         if ((long long)i * prime[j] > N) break;         p[i * prime[j]] = 1;         if (i % prime[j] == 0) {           phi[i * prime[j]] = phi[i] * prime[j];           break;         }         phi[i * prime[j]] = phi[i] * phi[prime[j]];       }     }   }   void init(int x) {     pp[0] = 0;     for (int i = 1; i <= top && (long long)prime[i] * prime[i] <= x; i++)       if (x % prime[i] == 0) {         pp[++pp[0]] = prime[i];         while (x % prime[i] == 0) x /= prime[i];         if (x == 1) return;         if (!p[x]) {           pp[++pp[0]] = x;           return;         }       }     if (x > 1) pp[++pp[0]] = x;   }   void dfs(int k, int op, long long s, long long n, long long &ans) {     if (k > pp[0]) {       ans += n / s * op;       return;     }     dfs(k + 1, op, s, n, ans);     if (s * pp[k] <= n) dfs(k + 1, -op, s * pp[k], n, ans);   }   long long Count(long long x) {     long long ans = 0;     dfs(1, 1, 1, x % P, ans);     return x / P * phi[P] + ans;   }   int main() {     scanf( %d , &T);     init_prime(N - 5);     while (T--) {       scanf( %d%d%d , &X, &P, &K), init(P);       K += Count(X), l = 1, r = 1e8;       while (l <= r) {         mid = (l + r) >> 1;         if (Count(mid) >= K)           ans = mid, r = mid - 1;         else           l = mid + 1;       }       printf( %I64d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool cmp(long long x, long long y) { return x > y; }   int main() {     long long n;     cin >> n;     string S;     cin >> S;     vector<long long> C;     for (long long i = 0; i < n; i++) {       long long x = S[i] -  0 ;       if (x == 0 || x == 1)         continue;       else if (x == 2)         C.push_back(2);       else if (x == 3)         C.push_back(3);       else if (x == 4)         C.push_back(2), C.push_back(2), C.push_back(3);       else if (x == 5)         C.push_back(5);       else if (x == 6)         C.push_back(5), C.push_back(3);       else if (x == 7)         C.push_back(7);       else if (x == 8)         C.push_back(7), C.push_back(2), C.push_back(2), C.push_back(2);       else if (x == 9)         C.push_back(7), C.push_back(3), C.push_back(3), C.push_back(2);     }     sort(C.begin(), C.end(), cmp);     for (auto it : C) cout << it;   }
#include <bits/stdc++.h>   using namespace std;   int read() {     int x = 0;     char c = getchar();     while (c <  0  ||  9  < c) c = getchar();     while ( 0  <= c && c <=  9 )       x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();     return x;   }   int p[200000 + 5];   int tp, stk[200000 + 5];   int U[200000 + 5], V[200000 + 5];   map<pair<int, int>, bool> Map;   int main() {     int n = read(), m = read();     for (int i = 1; i <= m; i++) {       U[i] = read(), V[i] = read();       Map[make_pair(U[i], V[i])] = 1;       Map[make_pair(V[i], U[i])] = 1;     }     for (int i = 1; i <= n; i++) p[i] = i;     for (int t = 100; t >= 0; t--) {       random_shuffle(p + 1, p + n + 1);       p[n + 1] = p[1];       tp = 0;       for (int i = 1; i <= n && tp < m; i++)         if (!Map.count(make_pair(p[i], p[i + 1]))) stk[++tp] = i;       if (tp == m) {         for (int i = 1; i <= m; i++) printf( %d %d n , p[stk[i]], p[stk[i] + 1]);         return 0;       }     }     puts( -1 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( Ofast )   #pragma GCC optimize( no-stack-protector )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native )   #pragma GCC optimize( fast-math )   #pragma GCC optimize  -O3    long long INF = (long long)1e20;   int iINF = (int)1e20;   long long mod = 1e9 + 7;   long long mult(long long a, long long b) {     if (a == 0) return 0;     if (a == 1) return (b % mod);     if (a % 2) {       long long kek = mult(a / 2, b) % mod;       kek *= 2;       kek %= mod;       kek += b;       kek %= mod;       return kek;     } else {       long long kek = mult(a / 2, b) % mod;       kek *= 2;       kek %= mod;       return kek;     }   }   long long f(long long r) {     long long odd = 0, even = 0;     long long now = 1;     bool chet = false;     while (r > 0) {       long long num = min(r, now);       if (chet)         even += num;       else         odd += num;       r -= now;       now *= 2;       chet = !chet;     }     return (mult(odd, odd) + mult(even, even) + even) % mod;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long l, r;     cin >> l >> r;     cout << (f(r) - f(l - 1) + mod) % mod;   }
#include <bits/stdc++.h>   int in[301];   int c[301];   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int main() {     int n, i, j;     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d , in + i);     for (i = 1; i <= n; i++) scanf( %d , c + i);     for (i = 1; i <= n; i++) {       for (j = 2; j * j <= in[i]; j++) {         if (in[i] % j == 0) {           while (in[i] % j == 0) in[i] /= j;           in[i] *= j;         }       }     }     std::map<int, int> dp, dt;     dp[0] = 0;     for (i = 1; i <= n; i++) {       for (auto t : dp) {         int xx = gcd(t.first, in[i]);         int xy = t.second + c[i];         if (dp.count(xx) == 0 || dp[xx] > xy) {           if (dt.count(xx) == 0 || dt[xx] > xy) dt[xx] = xy;         }       }       for (auto t : dt) {         dp[t.first] = t.second;       }       dt.clear();     }     if (dp.count(1) == 0)       printf( -1 );     else       printf( %d , dp[1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     char c = getchar();     int n = 0;     bool f = 0;     while (c <  0  || c >  9 ) {       if (c ==  - ) f = 1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       n = (n << 1) + (n << 3) + (c ^ 48);       c = getchar();     }     return f ? -n : n;   }   int r, c, n, t, x, y, ans, res;   bool m[101][101];   int main() {     r = read(), c = read(), n = read(), t = read();     for (int i = 1; i <= n; i++) {       x = read(), y = read();       m[x][y] = 1;     }     for (int i = 1; i <= r; i++)       for (int j = 1; j <= c; j++)         for (int k = i; k <= r; k++)           for (int h = j; h <= c; h++) {             res = 0;             for (int a = i; a <= k; a++)               for (int b = j; b <= h; b++)                 if (m[a][b]) res++;             if (res >= t) ans++;           }     printf( %d n , ans);     return 0;   }