malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long mod(long long x, long long MOD) {     if (x > MOD) x -= MOD;     return x;   }   long long _ceil(long long x, long long y) { return x / y + (x % y != 0); }   void wrt() {     cout <<   n ;     return;   }   template <typename T1, typename... T2>   void wrt(T1 x, T2... args) {     ((cout << x <<    ), wrt(args...));   }   template <typename T>   ostream& operator<<(ostream& os, const vector<T>& v) {     for (auto& i : v) os << i <<    ;     return os;   }   template <typename T>   istream& operator>>(istream& in, vector<T>& v) {     for (auto& e : v) in >> e;     return in;   }   const long long MOD = 998244353;   const long long N = 1e6 + 5, inf = 1e18 + 2;   long long n, m, x, u, v, k, p, q, i, j;   string s, t;   long long ans;   long long a[N];   vector<long long> arr(7, 0);   bool f(long long i, long long j, long long k) {     long long x;     vector<long long> res;     res.push_back(arr[i]);     res.push_back(arr[j]);     res.push_back(arr[k]);     res.push_back(arr[i] + arr[j]);     res.push_back(arr[j] + arr[k]);     res.push_back(arr[i] + arr[k]);     res.push_back(arr[i] + arr[j] + arr[k]);     sort((res).begin(), (res).end());     for (long long i = 0; i < (((long long)(res).size())); ++i) {       if (res[i] != arr[i]) return false;     }     return true;   }   void solve() {     for (long long i = 0; i < (7); ++i) arr[i] = 0;     cin >> arr;     sort((arr).begin(), (arr).end());     for (long long i = 0; i < (7); ++i) {       for (long long j = (i + 1); j < (7); ++j) {         for (long long k = (j + 1); k < (7); ++k) {           if (f(i, j, k)) {             wrt(arr[i], arr[j], arr[k]);             return;           }         }       }     }   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T INT_LEN(T v) {     int len = 1;     while (v /= 10) ++len;     return len;   }   int t1, t2, x1, x2, t0;   int less_than(double va, double vb) { return va <= vb + 1e-10; }   int binary_found(int lt, int rt, int y2, double &pre) {     int y1;     bool flag = false;     double t;     while (lt <= rt) {       y1 = (lt + rt) >> 1;       t = ((double)t1 * y1 + (double)t2 * y2) / (y1 + y2);       if (t >= t0)         lt = -~y1;       else         rt = ~-y1;     }     t = ((double)t1 * rt + (double)t2 * y2) / (rt + y2);     if (less_than(fabs(t - t0), fabs(pre - t0))) {       flag = true;       pre = t;     }     return flag ? rt : -1;   }   void solve() {     int i, j, mx = 0;     int y1, y2;     if (t1 == t2)       printf( %d %d n , x1, x2);     else if (t0 == t1)       printf( %d %d n , x1, 0);     else if (t0 == t2)       printf( %d %d n , 0, x2);     else {       double pre = t2;       y2 = 0;       for (i = 1; i <= x2; i++) {         j = binary_found(0, x1, i, pre);         if (~j && i + j > mx) {           mx = i + j;           y1 = j;           y2 = i;         }       }       printf( %d %d n , y1, y2);     }   }   int main(void) {     while (5 == scanf( %d%d%d%d%d , &t1, &t2, &x1, &x2, &t0)) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   inline void smin(T &a, U b) {     if (a > b) a = b;   }   template <typename T, typename U>   inline void smax(T &a, U b) {     if (a < b) a = b;   }   inline void gn(long long &first) {     int sg = 1;     char c;     while (((c = getchar()) <  0  || c >  9 ) && c !=  - )       ;     c ==  -  ? (sg = -1, first = 0) : (first = c -  0 );     while ((c = getchar()) >=  0  && c <=  9 ) first = first * 10 + c -  0 ;     first *= sg;   }   inline void gn(int &first) {     long long t;     gn(t);     first = t;   }   inline void gn(unsigned long long &first) {     long long t;     gn(t);     first = t;   }   inline void gn(double &first) {     double t;     scanf( %lf , &t);     first = t;   }   inline void gn(long double &first) {     double t;     scanf( %lf , &t);     first = t;   }   int power(int a, int b, int m, int ans = 1) {     for (; b; b >>= 1, a = 1LL * a * a % m)       if (b & 1) ans = 1LL * ans * a % m;     return ans;   }   int main() {     long long k, b, n, t, m;     scanf( %I64d%I64d%I64d%I64d , &k, &b, &n, &t);     if (k == 1) {       m = n - (t - 1) / b;       if (m < 0) m = 0;       cout << m << endl;       return 0;     }     double u = 1.0 * (t - t * k - b) / (1 - k - b);     double v = log(u) / log(1.0 * k);     m = n - floor(v);     if (m < 0) m = 0;     printf( %I64d n , m);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 5;   const long long MOD = 998244353;   int n, k;   vector<int> a, b;   long long ans[MAXN][3][5];   bool found[MAXN][3][5];   long long mul(long long a, long long b) { return (a * b) % MOD; }   long long dp(int pos, int last, int var) {     if (pos == 1) return (last == 1) ? 1LL : 0LL;     if (found[pos][last][var]) return ans[pos][last][var];     found[pos][last][var] = true;     ans[pos][last][var] = 0LL;     for (int i = 0; i < var; ++i)       if (last == 0 || i != last) {         long long koef = 1;         if (i == 0) koef = k - var + 1;         if (last == 0 && i == 0) koef--;         koef = max(koef, 0LL);         ans[pos][last][var] =             (ans[pos][last][var] + mul(dp(pos - 1, i, var), koef)) % MOD;       }     return ans[pos][last][var];   }   long long calc(const vector<int> &A) {     vector<pair<int, int> > fixed;     fixed.push_back(pair<int, int>(0, -1));     for (int i = 0; i < A.size(); ++i) {       if (A[i] != -1) {         fixed.push_back(pair<int, int>(A[i], i));       }     }     fixed.push_back(pair<int, int>(0, A.size()));     long long tmpAns = 1LL;     for (int i = 0; i < fixed.size() - 1; ++i) {       int l = fixed[i].second, r = fixed[i + 1].second;       if (fixed[i].first == 0 && fixed[i + 1].first == 0) {         tmpAns = mul(tmpAns, k);         for (int j = l + 2; j < r; ++j) tmpAns = mul(tmpAns, k - 1);       } else if (fixed[i].first == 0 || fixed[i + 1].first == 0) {         for (int j = l + 1; j < r; ++j) tmpAns = mul(tmpAns, k - 1);       } else {         if (A[l] == A[r]) {           tmpAns = mul(tmpAns, dp(r - l + 1, 1, 2));         } else {           tmpAns = mul(tmpAns, dp(r - l + 1, 2, 3));         }       }     }     return tmpAns;   }   int main() {     scanf( %d %d , &n, &k);     for (int i = 0; i < n; ++i) {       int tmp;       scanf( %d , &tmp);       if (i % 2)         a.push_back(tmp);       else         b.push_back(tmp);     }     printf( %lld n , mul(calc(a), calc(b)));   }
#include <bits/stdc++.h>   using namespace std;   void FastIO() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);   }   stack<pair<int, int> > stk;   string ip;   int length;   int main() {     FastIO();     cin >> ip;     length = ip.length();     int prev[length + 10], open[length + 10];     pair<int, int> ppp;     memset(open, 0, sizeof(open));     if (ip[0] ==  [ ) open[0]++;     for (int i = 1; i < length; i++) {       open[i] = open[i - 1];       if (ip[i] ==  [ ) open[i]++;     }     for (int i = 0; i < length; i++) {       prev[i] = -1;       if (ip[i] ==  ( )         stk.push(make_pair(1, i));       else if (ip[i] ==  [ )         stk.push(make_pair(2, i));       else if (ip[i] ==  ]  && !stk.empty()) {         ppp = stk.top();         if (ppp.first != 2) {           stk.push(make_pair(-1, -1));         }         if (ppp.first == 2) {           stk.pop();           prev[i] = ppp.second;         }       } else if (ip[i] ==  )  && !stk.empty()) {         ppp = stk.top();         if (ppp.first != 1) {           stk.push(make_pair(-1, -1));         }         if (ppp.first == 1) {           stk.pop();           prev[i] = ppp.second;         }       }     }     string anssubsr;     int ans = 0, t;     for (int i = 0; i < length; i++) {       if (prev[i] != -1) {         t = prev[i];         while (prev[t - 1] != -1 && t > 0) {           t = prev[t - 1];           if (t <= 0) break;         }         prev[i] = t;       }     }     int at, from;     for (int i = 0; i < length; i++) {       if (prev[i] != -1) {         t = prev[i];         prev[i]--;         if (prev[i] >= 0) open[i] -= open[prev[i]];         if (open[i] > ans) {           ans = open[i];           from = t;           at = i;         }       }     }     if (ans != 0) {       cout << ans << endl;       for (int k = from; k <= at; k++) cout << ip[k];       cout << endl;     } else       cout << 0 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t, i;     cin >> t;     while (t--) {       int flag = 0;       string s, t, p;       cin >> s >> t >> p;       int a[26] = {0};       if (s.length() > t.length()) {         flag = 0;       } else {         for (i = 0; i < min(t.length(), s.length()) + 1; i++) {           if (s[i] != t[i]) {             for (int j = 0; j < p.length(); j++) {               if (p[j] == t[i]) {                 string d =   ;                 d = d + p[j];                 s.insert(i, d);                 p.erase(p.begin() + j);                 flag = 0;                 break;               }             }             if (flag == 1) {               cout <<  NO n ;               break;             }           }         }       }       if (s == t && flag == 0)         cout <<  YES n ;       else if (flag == 0)         cout <<  NO n ;     }   }
#include <bits/stdc++.h>   using namespace std;   struct Maxflow {     static const int MAXV = 20010;     long long INF = 1000000000000000ll;     struct Edge {       int v, r;       long long c;       Edge(int _v, long long _c, int _r) : v(_v), c(_c), r(_r) {}     };     int s, t;     vector<Edge> G[MAXV * 2];     int iter[MAXV * 2], d[MAXV * 2], gap[MAXV * 2], tot;     void init(int x) {       tot = x + 2;       s = x + 1, t = x + 2;       for (int i = 0; i <= tot; i++) {         G[i].clear();         iter[i] = d[i] = gap[i] = 0;       }     }     void addEdge(int u, int v, long long c) {       G[u].push_back(Edge(v, c, ((int)(G[v]).size())));       G[v].push_back(Edge(u, 0, ((int)(G[u]).size()) - 1));     }     long long dfs(int p, long long flow) {       if (p == t) return flow;       for (int &i = iter[p]; i < ((int)(G[p]).size()); i++) {         Edge &e = G[p][i];         if (e.c > 0 && d[p] == d[e.v] + 1) {           long long f = dfs(e.v, min(flow, e.c));           if (f) {             e.c -= f;             G[e.v][e.r].c += f;             return f;           }         }       }       if ((--gap[d[p]]) == 0)         d[s] = tot;       else {         d[p]++;         iter[p] = 0;         ++gap[d[p]];       }       return 0;     }     long long solve() {       long long res = 0;       gap[0] = tot;       for (res = 0; d[s] < tot; res += dfs(s, INF))         ;       return res;     }   } flow;   int n, m;   int main() {     cin >> n >> m;     flow.init(n + m + 5);     for (int i = 1; i <= n; i++) {       long long f;       scanf( %lld , &f);       flow.addEdge(m + i, flow.t, f);     }     long long tot = 0;     for (int i = 1; i <= m; i++) {       int x, y;       long long f;       scanf( %d%d%lld , &x, &y, &f);       flow.addEdge(flow.s, i, f);       flow.addEdge(i, m + x, flow.INF);       flow.addEdge(i, m + y, flow.INF);       tot += f;     }     printf( %lld n , tot - flow.solve());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long M = 1e8;   int main() {     long long n, i, j;     cin >> n;     vector<long long> ara;     for (i = 0; i < n; i++) {       cin >> j;       ara.push_back(j);     }     long long pre1[n + 1];     long long pre2[n + 1];     pre1[0] = 0;     pre2[0] = 0;     for (i = 1; i <= n; i++) pre1[i] = pre1[i - 1] + ara[i - 1];     sort(ara.begin(), ara.end());     for (i = 1; i <= n; i++) pre2[i] = pre2[i - 1] + ara[i - 1];     long long t;     cin >> t;     while (t--) {       long long l, h, type, ans = 0;       cin >> type >> l >> h;       if (type == 1) {         ans = pre1[h] - pre1[l - 1];       } else         ans = pre2[h] - pre2[l - 1];       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10, mod = 1e9 + 7;   int k, n, sz, last;   char s[N];   string ret;   long long cnt[2 * N], dp[2 * N];   char inp[N];   struct state {     int link, len, next[26];   };   state st[2 * N];   bool vis[2 * N];   void sa_init() {     st[0].len = 0;     st[0].link = -1;     for (int i = 0; i < 26; i++) st[0].next[i] = -1;     sz = 1;     last = 0;   }   void sa_extend(char ch) {     int cur = sz++;     int c = ch -  a ;     st[cur].len = st[last].len + 1;     for (int i = 0; i < 26; i++) st[cur].next[i] = -1;     int p = last;     while (p != -1 && st[p].next[c] == -1) {       st[p].next[c] = cur;       p = st[p].link;     }     if (p == -1)       st[cur].link = 0;     else {       int q = st[p].next[c];       if (st[q].len == st[p].len + 1)         st[cur].link = q;       else {         int clone = sz++;         for (int i = 0; i < 26; i++) st[clone].next[i] = -1;         st[clone] = st[q];         st[clone].len = st[p].len + 1;         while (p != -1 && st[p].next[c] == q) {           st[p].next[c] = clone;           p = st[p].link;         }         st[cur].link = st[q].link = clone;       }     }     last = cur;     cnt[cur] = 1;   }   bool cmp(int x, int y) { return st[x].len > st[y].len; }   void dfs(int u) {     vis[u] = 1;     dp[u] = cnt[u];     for (int j = 0; j < 26; j++) {       int v = st[u].next[j];       if (v == -1) continue;       if (!vis[v]) dfs(v);       dp[u] += dp[v];     }   }   void solve(int u) {     for (int j = 0; j < 26; j++) {       int v = st[u].next[j];       if (v == -1) continue;       if (dp[v] >= k) {         k -= cnt[v];         ret.push_back(j +  a );         if (k > 0)           solve(v);         else           k = 0;         break;       }       k -= dp[v];     }   }   int main() {     scanf( %s%d , &s, &k);     n = strlen(s);     sa_init();     for (int i = 0; i < n; i++) sa_extend(s[i]);     vector<int> v(sz);     iota(v.begin(), v.end(), 0);     sort(v.begin(), v.end(), cmp);     for (int i = 0; i < sz; i++) {       cnt[st[v[i]].link] += cnt[v[i]];     }     dfs(0);     solve(0);     if (!k)       cout << ret <<   n ;     else       cout <<  No such line. n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100010], b[100010];   map<string, bool> mark;   bool word(char a) {     if (a >=  a  and a <=  z ) return true;     if (a >=  A  and a <=  Z ) return true;     return false;   }   int main() {     int n;     cin >> n;     string a;     cin >> a;     int ind = 0;     int inside = 0;     int ans1 = 0;     int ans2 = 0;     while (ind < n) {       if (a[ind] ==  _ ) {         ind++;         continue;       }       if (a[ind] ==  ( ) {         inside++;         ind++;         continue;       }       if (a[ind] ==  ) ) {         inside--;         ind++;         continue;       }       int leng = 0;       string cur =   ;       while (word(a[ind]) == true) {         if (ind == n - 1) {           cur += a[ind];           if (inside > 0) {             ans2++;           }           if (inside == 0) {             ans1 = max(ans1, int(cur.size()));           }           ind++;           break;         }         cur += a[ind];         ind++;       }       if (ind == n) {         break;       }       if (inside > 0) {         ans2++;       }       if (inside == 0) {         ans1 = max(ans1, int(cur.size()));       }     }     cout << ans1 <<     << ans2 << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   const long long MOD = 1e9 + 7;   template <class T>   inline void chmax(T &a, const T &b) {     if ((a) < (b)) (a) = (b);   }   template <class T>   inline void chmin(T &a, const T &b) {     if ((a) > (b)) (a) = (b);   }   template <typename T>   using PQ = priority_queue<T, vector<T>, greater<T>>;   struct Fast {     Fast() {       std::cin.tie(0);       ios::sync_with_stdio(false);     }   } fast;   long long query() {     long long n;     cin >> n;     vector<long long> x(n);     vector<long long> y(n);     vector<long long> L(n);     vector<long long> U(n);     vector<long long> R(n);     vector<long long> D(n);     long long l = -1e5;     long long r = 1e5;     long long d = -1e5;     long long u = 1e5;     for (long long i = (long long)(0); i < (long long)(n); ++i) {       cin >> x[i] >> y[i] >> L[i] >> U[i] >> R[i] >> D[i];       if (L[i] == 1 && R[i] == 1) {       }       if (L[i] == 0 && R[i] == 1) {         chmax(l, x[i]);       }       if (L[i] == 1 && R[i] == 0) {         chmin(r, x[i]);       }       if (L[i] == 0 && R[i] == 0) {         chmax(l, x[i]);         chmin(r, x[i]);       }       if (D[i] == 1 && U[i] == 1) {       }       if (D[i] == 0 && U[i] == 1) {         chmax(d, y[i]);       }       if (D[i] == 1 && U[i] == 0) {         chmin(u, y[i]);       }       if (D[i] == 0 && U[i] == 0) {         chmax(d, y[i]);         chmin(u, y[i]);       }     }     42;     42;     if (l <= r && d <= u) {       42;       printf( 1 %lld %lld n , l, d);     } else {       printf( 0 n );     }     return 0;   }   long long solve() {     long long Q;     cin >> Q;     for (long long q = (long long)(0); q < (long long)(Q); ++q) {       query();     }     return 0;   }   signed main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   inline void smin(T &a, const U &b) {     if (a > b) a = b;   }   template <typename T, typename U>   inline void smax(T &a, const U &b) {     if (a < b) a = b;   }   template <class T>   inline void gn(T &first) {     char c, sg = 0;     while (c = getchar(), (c >  9  || c <  0 ) && c !=  - )       ;     for ((c ==  -  ? sg = 1, c = getchar() : 0), first = 0; c >=  0  && c <=  9 ;          c = getchar())       first = (first << 1) + (first << 3) + c -  0 ;     if (sg) first = -first;   }   template <class T1, class T2>   inline void gn(T1 &x1, T2 &x2) {     gn(x1), gn(x2);   }   template <class T1, class T2, class T3>   inline void gn(T1 &x1, T2 &x2, T3 &x3) {     gn(x1, x2), gn(x3);   }   template <class T>   inline void print(T first) {     if (first < 0) {       putchar( - );       return print(-first);     }     if (first < 10) {       putchar( 0  + first);       return;     }     print(first / 10);     putchar(first % 10 +  0 );   }   template <class T>   inline void println(T first) {     print(first);     putchar(  n );   }   template <class T>   inline void printsp(T first) {     print(first);     putchar(   );   }   template <class T1, class T2>   inline void print(T1 x1, T2 x2) {     printsp(x1), println(x2);   }   template <class T1, class T2, class T3>   inline void print(T1 x1, T2 x2, T3 x3) {     printsp(x1), printsp(x2), println(x3);   }   int power(int a, int b, int m, int ans = 1) {     for (; b; b >>= 1, a = (long long)a * a % m)       if (b & 1) ans = (long long)ans * a % m;     return ans;   }   int size(int n) {     int ans = 0;     while (n) {       n /= 7;       ans++;     }     smax(ans, 1);     return ans;   }   int f[11], p[11];   int calc(int st, int ed) {     int ans = 0;     int nn = 0;     for (int i = ed; i >= st; i--) {       ans += p[i] * f[nn];       nn++;     }     return ans;   }   int main() {     int n, m;     gn(n, m);     int N = size(n - 1), M = size(m - 1);     if (N + M > 7) return puts( 0 );     f[0] = 1;     for (int i = 1; i < 11; i++) f[i] = f[i - 1] * 7;     for (int i = 0; i < 7; i++) p[i] = i;     int ans = 0;     do {       int a = calc(0, N - 1), b = calc(N, N + M - 1);       if (a < n && b < m) ans++;     } while (next_permutation(p, p + 7));     int num = 1;     for (int i = 2; i <= 7 - N - M; i++) num *= i;     println(ans / num);   }
#include <bits/stdc++.h>   using namespace std;   struct operacion {     string name;     int x;     operacion() {}     operacion(string name, int x) : name(name), x(x) {}   };   int n;   priority_queue<int, vector<int>, greater<int> > q;   vector<operacion> v;   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int cas = 0; cas < n; cas++) {       string name;       cin >> name;       if (name ==  insert ) {         int x;         cin >> x;         v.push_back(operacion(name, x));         q.push(x);       } else if (name ==  getMin ) {         int x;         cin >> x;         while (int(q.size()) > 0 and q.top() < x) {           v.push_back(operacion( removeMin , 0));           q.pop();         }         if (int(q.size()) == 0 or q.top() != x) {           v.push_back(operacion( insert , x));           q.push(x);         }         v.push_back(operacion( getMin , x));       } else if (name ==  removeMin ) {         if (int(q.size()) == 0) {           v.push_back(operacion( insert , 1));           q.push(1);         }         v.push_back(operacion( removeMin , 0));         q.pop();       }     }     cout << int(v.size()) << endl;     for (int i = 0; i < int(v.size()); i++) {       cout << v[i].name;       if (v[i].name !=  removeMin ) cout <<     << v[i].x;       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   #pragma GCC target( avx2 )   #pragma GCC optimization( O2 )   #pragma GCC optimization( unroll-loops )   const long double ERR = 1e-5;   const int MOD = 1e9 + 7;   bool areEqual(long double _n1, long double _n2) {     return fabs(_n1 - _n2) < ERR;   }   long long A[] = {       1,          2,          4,          8,          16,          32,       64,         128,        256,        512,        1024,        2048,       4096,       8092,       16184,      32368,      64736,       129472,       258944,     517888,     1035776,    2071552,    4143104,     8286208,       16572416,   33144832,   66289664,   132579328,  265158656,   530317312,       1060634624, 2121269248, 4242538496, 8485076992, 16970153984, 33940307968};   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int x;     cin >> x;     cout << A[x] <<   n ;   }