malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   inline long long read() {     register long long x = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = (x << 1) + (x << 3) + (ch ^ 48);       ch = getchar();     }     return x * f;   }   const long long N = 1e5 + 10;   long long n, m, k, p;   long long h[N], a[N];   long long c[N];   struct node {     long long t, id;     bool operator<(const node& x) const { return t > x.t; }   };   priority_queue<node> q;   bool check(long long x) {     while (!q.empty()) q.pop();     memset(c, 0, sizeof c);     for (long long i = 1; i <= n; i++)       if (x - a[i] * m < h[i]) q.push((node){x / a[i], i});     for (long long i = 1; !q.empty() && i <= m; i++)       for (long long j = 1; !q.empty() && j <= k; j++) {         node u = q.top();         q.pop();         if (u.t < i) return 0;         ++c[u.id];         if (x + c[u.id] * p - a[u.id] * m < h[u.id])           q.push((node){(x + c[u.id] * p) / a[u.id], u.id});       }     return q.empty();   }   signed main() {     n = read(), m = read(), k = read(), p = read();     for (long long i = 1; i <= n; i++) h[i] = read(), a[i] = read();     long long l = 0, r = 1e15, ans;     while (l <= r) {       long long mid = l + r >> 1;       if (check(mid))         ans = mid, r = mid - 1;       else         l = mid + 1;     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   struct data {     int idx, val;     bool operator<(const data &a1) const {       if (a1.val == val) {         return a1.idx < idx;       }       return val > a1.val;     }     data(int t, int w) : idx(t), val(w) {}   };   set<data> coastline;   set<data>::iterator it, it2;   int main() {     int N;     scanf( %d , &N);     string ans[N];     int a;     for (int i = 0; i < N; i++) {       scanf( %d , &a);       if (a == 0) {         int sz = coastline.size();         if (sz == 0) {           ans[i] =  0 ;         } else if (sz == 1) {           ans[i] =  1 popStack ;           it = coastline.begin();           ans[it->idx] =  pushStack ;         } else if (sz == 2) {           ans[i] =  2 popStack popQueue ;           it = coastline.begin();           ans[it->idx] =  pushQueue ;           it++;           ans[it->idx] =  pushStack ;           it++;         } else {           ans[i] =  3 popStack popQueue popFront ;           it = coastline.begin();           ans[it->idx] =  pushFront ;           it++;           ans[it->idx] =  pushQueue ;           it++;           ans[it->idx] =  pushStack ;           it++;         }         coastline.clear();       } else {         coastline.insert(data(i, a));       }     }     for (int i = 0; i < N; i++) {       if (ans[i].size() == 0) {         cout <<  pushBack  << endl;       } else         cout << ans[i] << endl;     }     return 0;   }
#include <bits/stdc++.h>   #define ll long long   #define mod 1000000007   using namespace std;      ll dp[10][200001];   string s =  abcdefghijklmnopqrstuvwxyz ;   ll findgcd(ll a, ll b) {       if (b == 0) {           return a;       }       return findgcd(b, a % b);   }      bool ispalindrome(string s) {       int n = s.length();       bool flag = true;       for (int i = 0; i < n / 2; i++) {           if (s[i] != s[n - 1 - i]) {               flag = false;               break;           }       }       return flag;   }      ll factorial(ll n) {       vector<ll> v(n + 1);       for (ll i = 0; i <= n; i++) {           if (i == 0 || i == 1) {               v[i] = 1;           }           else {               v[i] = (i * v[i - 1]) % mod;           }       }       return v[n];   }      void calculatedp() {       for (ll i = 0; i <= 9; i++) {           ll temp = 10 - i;           for (ll j = 0; j <= 200000; j++) {               if (j < temp) {                   dp[i][j] = 1;               }               else if (j == temp) {                   dp[i][j] = 2;               }               else {                   break;               }           }       }       dp[1][10] = 2;       for (ll i = 11; i <= 200000; i++) {           int temp1 = i - 10;           int temp2 = i - 9;           dp[0][i] = (dp[0][temp1] + dp[1][temp1]) % mod;           dp[1][i] = (dp[0][temp2] + dp[1][temp2]) % mod;       }       for (ll i = 2; i <= 9; i++) {           ll temp = 10 - i;           for (ll j = temp + 1; j <= 200000; j++) {               dp[i][j] = (dp[0][j - temp] + dp[1][j - temp]) % mod;           }       }   }      void solve() {       // ll m;       // cin >> s;       // cin >> m;       // ll ans = 0;       // for (int i = 0; i < s.length(); i++) {       //     ans = (ans + (dp[s[i] -  0 ][m])) % mod;       // }       // cout << ans <<   n ;       int n, k;       cin >> n >> k;          string ans =   ;          for (int i = 0 ; i < k ; i++) {           ans += s[i];           for (int j = i + 1 ; j < k ; j++) {               ans += s[i];               ans += s[j];           }       }          if (n < ans.size()) {           cout << ans.substr(0, n) << endl;       }       else {           int j = ans.length();           int i = 0;           while (j < n) {               ans += ans[i];               i++;               j++;           }              cout << ans << endl;       }   }   int main() {   #ifndef ONLINE_JUDGE       //for getting input from input.txt       freopen( input.txt ,  r , stdin);       //for writing output to output.txt       freopen( output.txt ,  w , stdout);   #endif       ios_base::sync_with_stdio(0);       cin.tie(0);       cout.tie(0);       // calculatedp();       // for (int i = 0; i <= 10; i++) {       //     for (int j = 0; j <= 10; j++) {       //         cout << dp[i][j] <<    ;       //     }       //     cout <<   n ;       // }       int t;       t = 1;       // cin >> t;       while (t--) {           solve();       }   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline int popcount(T t) {     if (std::numeric_limits<T>::digits <=         std::numeric_limits<unsigned int>::digits) {       return __builtin_popcount(t);     } else {       return __builtin_popcountll(t);     }   }   const long double EPS = 1e-8;   const long double PI = acosl(0.0) * 2;   void solve() {     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < int(n); ++i) cin >> a[i];     for (int i = 30; i >= 0; --i) {       vector<int> b;       int mask = (1 << i) - 1;       for (int x : a) {         if ((x >> i) & 1) {           b.push_back(x);           mask &= x;         }       }       if (!mask) {         cout << b.size() << endl;         for (int x : b) {           cout << x <<    ;         }         cout << endl;         return;       }     }     assert(false);   }   int main() {     ios_base::sync_with_stdio(false);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n1, n2, n3, n4;     long long ans;     unordered_map<char, int> m;     string s;     while (cin >> n1 >> n2 >> n3 >> n4) {       ans = 0;       m[ 1 ] = n1;       m[ 2 ] = n2;       m[ 3 ] = n3;       m[ 4 ] = n4;       cin >> s;       for (int i = 0; i < s.size(); i++) {         ans += m[s[i]];       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool cmp(double a, double b) { return a > b; }   int n;   double a[110], x, sum, ans;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %lf , &a[i]);     sort(a, a + n, cmp);     ans = 0;     for (int i = 1; i <= n; i++) {       sum = 0;       for (int j = 0; j < i; j++) {         x = a[j];         for (int k = 0; k < i; k++) {           if (j != k) x *= 1 - a[k];         }         sum += x;       }       ans = max(sum, ans);     }     printf( %.12lf n , ans);   }
#include <bits/stdc++.h>   using namespace std;   long long int a[200][3];   int main() {     ios ::sync_with_stdio(false);     cin.tie(0);     ;     long long int i, k, l, n, j;     cin >> n;     for (i = 0; i <= n - 1; i++) cin >> a[i][0] >> a[i][1];     cin >> j;     for (i = 0; i <= n - 1; i++)       if (j >= a[i][0] && j <= a[i][1]) {         cout << n - i << endl;         return 0;       }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, K;   string S;   int vis[5050][5050];   vector<pair<int, int>> nex[26];   void dfs(int cur, int mask) {     if (vis[cur][mask] || cur + 1 + mask > N) return;     vis[cur][mask] = 1;     int i;     nex[S[cur] -  a ].push_back({cur + 1, mask});     for (i = 0; i < (K); i++)       if (mask & (1 << i)) dfs(cur + (1 << i), mask ^ (1 << i));   }   void solve() {     int i, j, k, l, r, x, y;     string s;     cin >> S;     N = S.size();     while (1 << (K + 1) <= N) K++;     vector<pair<int, int>> now;     now.push_back({0, (1 << K) - 1});     while (now.size()) {       for (i = 0; i < (26); i++) nex[i].clear();       for (auto& n : now) dfs(n.first, n.second);       char c =  z  + 1;       for (i = 25; i >= 0; i--)         if (nex[i].size()) c =  a  + i;       if (c ==  z  + 1) break;       cout << c;       swap(now, nex[c -  a ]);     }     cout << endl;   }   int main(int argc, char** argv) {     string s;     int i;     if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);     for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s +=   n ;     for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);     cout.tie(0);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   pair<double, double> get_vec_rotate(pair<double, double> nv, double fi) {     return make_pair(nv.first * cos(fi) - nv.second * sin(fi),                      nv.second * cos(fi) + nv.first * sin(fi));   }   pair<double, double> get_normal(pair<double, double> vec) {     double len = sqrt(vec.first * vec.first + vec.second * vec.second);     vec.first /= len;     vec.second /= len;     return vec;   }   pair<double, double> end_p(pair<double, double> start_p,                              pair<double, double> nv, double len) {     nv.first *= len;     nv.second *= len;     return make_pair(nv.first + start_p.first, nv.second + start_p.second);   }   double a, b, c, d;   pair<double, double> p, v, ToWrite;   pair<double, double> len_fi[7];   int main() {     cin >> p.first >> p.second >> v.first >> v.second >> a >> b >> c >> d;     v = get_normal(v);     len_fi[0].first = b;     len_fi[0].second = 0;     len_fi[1].first = a / 2;     len_fi[1].second = M_PI / 2;     len_fi[2].first = c / 2;     len_fi[2].second = M_PI / 2;     len_fi[3].first = sqrt(c * c + 4 * d * d) / 2;     len_fi[3].second = M_PI / 2 + atan(2 * d / c);     len_fi[4].first = sqrt(c * c + 4 * d * d) / 2;     len_fi[4].second = 3 * M_PI / 2 - atan(2 * d / c);     len_fi[5].first = c / 2;     len_fi[5].second = 3 * M_PI / 2;     len_fi[6].first = a / 2;     len_fi[6].second = 3 * M_PI / 2;     cout.precision(10);     for (int i = 0; i < 7; i++) {       ToWrite = end_p(p, get_vec_rotate(v, len_fi[i].second), len_fi[i].first);       cout << fixed << ToWrite.first <<     << ToWrite.second << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int active;     set<int> prev, next;     node() : active(1) {}   };   int main() {     int n, k, m, i, j;     int a, b;     cin >> n >> m;     int cnt = 1;     set<int> sh;     set<int>::iterator it;     for (i = 0; i < n; i++) sh.insert(i);     node* graf = new node[n];     for (i = 0; i < m; i++) {       cin >> a >> b;       a--, b--;       if (graf[a].active == 0) continue;       if (graf[b].prev.size() == 0) sh.erase(b);       graf[a].next.insert(b);       graf[b].prev.insert(a);       while (sh.size() == 1) {         k = *sh.begin();         cnt++;         if (cnt == n) {           cout << i + 1 << endl;           return 0;         }         for (it = graf[k].next.begin(); it != graf[k].next.end(); it++) {           j = *it;           graf[j].prev.erase(k);           if (graf[j].prev.size() == 0) sh.insert(j);         }         sh.erase(k);         graf[k].active = 0;       }     }     cout << -1 << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long long maxn = 2e5 + 7;   struct Node {     long long x, y;   } node[maxn];   bool cmp(Node a, Node b) { return a.x < b.x; }   long long n, k;   long long len[maxn];   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int t;     cin >> t;     while (t--) {       cin >> n >> k;       for (int i = 0; i < n; i++) cin >> node[i].x;       for (int i = 0; i < n; i++) cin >> node[i].y;       sort(node, node + n, cmp);       long long tarl, tarr;       for (tarr = tarl = 0; tarr < n; tarr++) {         while (node[tarl].x < node[tarr].x - k) tarl++;         len[tarr] = tarr - tarl + 1;       }       long long ans = 0, Max = 0;       for (tarr = tarl = 0; tarr < n; tarr++) {         while (node[tarl].x < node[tarr].x - k) {           Max = max(Max, len[tarl]);           tarl++;         }         ans = max(Max + len[tarr], ans);       }       cout << ans << endl;       for (int i = 0; i < n; i++) len[i] = 0;     }   }
#include <bits/stdc++.h>   using namespace std;   #pragma GCC target( avx2 )   #pragma GCC optimization( unroll-loops )   #pragma GCC optimize( O2 )   constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};   constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};   constexpr long long INF = 1999999999999999997;   constexpr int inf = INT_MAX;   constexpr int MAXSIZE = int(1e6) + 5;   constexpr auto PI = 3.14159265358979323846L;   constexpr auto oo = numeric_limits<int>::max() / 2 - 2;   constexpr auto eps = 1e-6;   constexpr auto mod = 1000000007;   constexpr auto MOD = 1000000007;   constexpr auto MOD9 = 1000000009;   constexpr auto maxn = 100006;   template <typename T, size_t N>   int SIZE(const T (&t)[N]) {     return N;   }   template <typename T>   int SIZE(const T &t) {     return t.size();   }   string to_string(string s, int x1 = 0, int x2 = 1e9) {     return     + ((x1 < s.size()) ? s.substr(x1, x2 - x1 + 1) :   ) +    ;   }   string to_string(const char *s) { return to_string((string)s); }   string to_string(bool b) { return (b ?  true  :  false ); }   string to_string(char c) { return string({c}); }   template <size_t N>   string to_string(bitset<N> &b, int x1 = 0, int x2 = 1e9) {     string t =   ;     for (int __iii__ = min(x1, SIZE(b)), __jjj__ = min(x2, SIZE(b) - 1);          __iii__ <= __jjj__; ++__iii__) {       t += b[__iii__] +  0 ;     }     return     + t +    ;   }   template <typename A, typename... C>   string to_string(A(&v), int x1 = 0, int x2 = 1e9, C... coords);   int l_v_l_v_l = 0, t_a_b_s = 0;   template <typename A, typename B>   string to_string(pair<A, B> &p) {     l_v_l_v_l++;     string res =  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;     l_v_l_v_l--;     return res;   }   template <typename A, typename... C>   string to_string(A(&v), int x1, int x2, C... coords) {     int rnk = rank<A>::value;     string tab(t_a_b_s,    );     string res =   ;     bool first = true;     if (l_v_l_v_l == 0) res +=   n ;     res += tab +  [ ;     x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v));     auto l = begin(v);     advance(l, x1);     auto r = l;     advance(r, (x2 - x1) + (x2 < SIZE(v)));     for (auto e = l; e != r; e = next(e)) {       if (!first) {         res +=  ,  ;       }       first = false;       l_v_l_v_l++;       if (e != l) {         if (rnk > 1) {           res +=   n ;           t_a_b_s = l_v_l_v_l;         };       } else {         t_a_b_s = 0;       }       res += to_string(*e, coords...);       l_v_l_v_l--;     }     res +=  ] ;     if (l_v_l_v_l == 0) res +=   n ;     return res;   }   void dbgs() { ; }   template <typename Heads, typename... Tails>   void dbgs(Heads H, Tails... T) {     cout << to_string(H) <<   |  ;     dbgs(T...);   }   int main() {     int n, d;     cin >> n >> d;     int m;     cin >> m;     while (m--) {       int x, y;       cin >> x >> y;       if (x + y - d >= 0 && y + x - 2 * n + d <= 0 && y - x - d <= 0 &&           x - y - d <= 0)         cout <<  YES               <<   n ;       else {         cout <<  NO               <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int mxN = 2e5 + 10;   vector<int> a[mxN];   int main() {     int n, k;     cin >> n >> k;     for (int i = 0; i < n; i++) {       int cnt = 0, x;       cin >> x;       while (true) {         a[x].push_back(cnt);         if (!x) break;         x >>= 1;         cnt++;       }     }     int ans = 1e9;     for (int i = 0; i < mxN; i++) {       if (a[i].size() >= k) {         sort(a[i].begin(), a[i].end());         int cnt = 0;         for (int j = 0; j < k; j++) cnt += a[i][j];         ans = min(ans, cnt);       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1LL << 28;   const long long mod = 1LL;   vector<int> adj[30];   long long b_search(int val, int indx) {     int lo, hi, mid;     long long ans = 1e12;     lo = 0;     hi = (int)adj[indx].size() - 1;     while (lo <= hi) {       mid = (lo + hi) / 2;       if (adj[indx][mid] == val) return 0;       if (adj[indx][mid] < val)         lo = mid + 1;       else         hi = mid - 1;       ans = min(ans, (long long)abs(val - adj[indx][mid]));     }     return ans;   }   int main() {     int n, k, i, j;     long long l;     string s, c;     while (scanf( %d %d , &n, &k) == 2) {       for (i = 0; i < 26; i++) adj[i].clear();       cin >> s;       for (i = 0; i < s.length(); i++) {         adj[s[i] -  a ].push_back(i);       }       while (n--) {         l = 0;         cin >> c;         for (i = 0; i < c.length(); i++) {           if ((int)adj[c[i] -  a ].size() == 0)             l += (int)c.size();           else             l += b_search(i, c[i] -  a );         }         printf( %I64d n , l);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   bool umin(T& a, T b) {     if (a > b) {       a = b;       return 1;     }     return 0;   }   template <class T>   bool umax(T& a, T b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   long long dp[200009][2], a, par[200009];   priority_queue<long long> bg;   priority_queue<long long, vector<long long>, greater<long long> > sm;   void upd(long long type, long long x) {     if (!type)       sm.push(x);     else       bg.push(x);   }   long long tap(long long type) {     if (!type) return sm.top();     return bg.top();   }   int main() {     memset(dp, -1, sizeof dp);     scanf( %lld , &a);     for (long long i = 1; i <= a; i++) {       long long x;       scanf( %lld , &x);       par[i] = par[i - 1] + x;     }     long long ans = -100000000924052357;     upd(0, -par[a]);     upd(1, par[a]);     for (long long i = a; i >= 3; i--) {       dp[i][0] = tap(1);       dp[i][1] = tap(0);       upd(0, dp[i][0] - par[i - 1]);       upd(1, dp[i][1] + par[i - 1]);       umax(ans, dp[i][1] + par[i - 1]);     }     printf( %lld n , max(ans, par[a]));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long SZ = 1e5 + 4;   const double EPS = 1e-7;   const long long mod = 1e9 + 7;   const long long hashpow = 2;   const long long inf = 2e9;   struct custom_hash {     static uint64_t splitmix64(uint64_t x) {       x += 0x9e3779b97f4a7c15;       x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;       x = (x ^ (x >> 27)) * 0x94d049bb133111eb;       return x ^ (x >> 31);     }     size_t operator()(uint64_t x) const {       static const uint64_t FIXED_RANDOM =           chrono::steady_clock::now().time_since_epoch().count();       return splitmix64(x + FIXED_RANDOM);     }   };   long long n;   void read() {     cin >> n;     --n;   }   void solve() {     long long x = 1;     long long m = n % 3;     n /= 3;     long long cnt = 0;     while (n >= x) {       n -= x;       x *= 4;       ++cnt;     }     long long a = 1;     long long b = 2;     long long c = 3;     vector<long long> y;     while (n) {       y.push_back(n % 4);       n /= 4;     }     while (y.size() < cnt) {       y.push_back(0);     }     for (long long i = (long long)(y.size()) - 1; i >= 0; --i) {       a *= 4;       b *= 4;       c *= 4;       if (y[i] == 1) {         a += 1;         b += 2;         c += 3;       } else if (y[i] == 2) {         a += 2;         b += 3;         c += 1;       } else if (y[i] == 3) {         a += 3;         b += 1;         c += 2;       }     }     if (m == 0) {       cout << a <<   n ;     } else if (m == 1) {       cout << b <<   n ;     } else {       cout << c <<   n ;     }   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long t;     cin >> t;     for (long long i = 0; i < t; ++i) {       read();       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct segTree {     long long* data;     int n;     segTree(int n) : n(n) { data = new long long[n * 2](); }     void add(int i, long long v) {       for (i += n; i; i >>= 1) data[i] += v;     }     int find(long long v) {       int i = 1;       while (i < n) {         i *= 2;         if (v >= data[i]) v -= data[i++];       }       return i - n;     }     long long sum(int i) {       long long r = data[i + n];       for (i += n; i > 1; i >>= 1) {         if (i & 1) r += data[i - 1];       }       return r;     }   };   segTree count_tree(1 << 17), sum_tree(1 << 17);   long long x[100000], t[100000];   vector<pair<int, long long>> child[100000];   map<int, int> ti_map;   int ti_list[100000];   long long dp[100000], dp2[100000];   void dfs(int p, long long T) {     if (T <= 0) return;     count_tree.add(ti_map[t[p]], x[p]);     sum_tree.add(ti_map[t[p]], x[p] * t[p]);     int i = sum_tree.find(T);     dp[p] = count_tree.sum(i - 1);     assert(sum_tree.sum(i - 1) <= T);     assert(i >= 1e5 + 10 || sum_tree.sum(i) > T);     if (i < 1e5 + 10) dp[p] += (T - sum_tree.sum(i - 1)) / ti_list[i];     vector<long long> child_vals;     for (auto e : child[p]) {       dfs(e.first, T - e.second * 2);       child_vals.push_back(dp2[e.first]);     }     sort(child_vals.rbegin(), child_vals.rend());     dp2[p] = dp[p];     if (child_vals.size() >= 2) dp2[p] = max(dp2[p], child_vals[1]);     if (p == 0) dp2[p] = max(dp2[p], child_vals[0]);     count_tree.add(ti_map[t[p]], -x[p]);     sum_tree.add(ti_map[t[p]], -x[p] * t[p]);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long n, T;     cin >> n >> T;     for (int i = 0; i < n; i++) cin >> x[i];     for (int i = 0; i < n; i++) {       cin >> t[i];       ti_map[t[i]];     }     int c = 1;     for (auto& p : ti_map) {       ti_list[c] = p.first;       p.second = c++;     }     for (int i = 1; i < n; i++) {       long long p, l;       cin >> p >> l;       child[p - 1].push_back({i, l});     }     dfs(0, T);     cout << dp2[0] << endl;   }