malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   double pi = acos(-1);   void OJ() {}   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     vector<string> v;     long long num = 0, k = 0;     v.push_back( 4 ), v.push_back( 7 );     while (1) {       long long n = v.size();       for (long long i = 0; i < n; i++) {         for (long long j = k; j < n; j++) {           string s = v[i] + v[j];           v.push_back(s);           num = max(num, stoll(s, nullptr, 10));           if (num >= 1e9) break;         }         if (num >= 1e9) break;       }       k = n;       if (num >= 1e9) break;     }     vector<long long> ar;     for (auto s : v) {       ar.push_back(stoll(s, nullptr, 10));     }     long long i = 0;     sort(ar.begin(), ar.end());     unordered_map<long long, long long> m;     for (auto s : ar) {       if (m.find(s) == m.end()) m[s] = (++i);     }     long long in;     cin >> in;     cout << m[in];   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, k;     cin >> n >> k;     vector<vector<int>> g(n);     for (int i = 0; i < n - 1; i++) {       int x, y;       cin >> x >> y;       --x;       --y;       g[x].push_back(y);       g[y].push_back(x);     }     vector<bool> alive(n, true);     vector<int> sz(n);     vector<int> pv(n);     vector<pair<int, int>> ret;     vector<int> all;     vector<int> tin(n);     vector<int> tout(n);     int T = -1;     function<void(int)> Dfs = [&](int v) {       all.push_back(v);       tin[v] = ++T;       sz[v] = 1;       for (int u : g[v]) {         if (alive[u] && u != pv[v]) {           pv[u] = v;           Dfs(u);           sz[v] += sz[u];         }       }       tout[v] = ++T;     };     function<void(int)> Solve = [&](int v) {       all.clear();       pv[v] = -1;       Dfs(v);       int total = sz[v];       while (true) {         bool found = false;         for (int u : g[v]) {           if (alive[u] && pv[u] == v && 2 * sz[u] >= total) {             v = u;             found = true;             break;           }         }         if (!found) {           break;         }       }       alive[v] = false;       set<int> best;       for (int u : g[v]) {         if (alive[u]) {           all.clear();           pv[u] = -1;           Dfs(u);           set<int> cur;           for (int w : g[u]) {             if (alive[w]) {               cur.insert(w);             }           }           if (cur.size() > best.size()) {             best = cur;           }         }       }       all.clear();       pv[v] = -1;       Dfs(v);       for (int u : all) {         if (u != v && pv[u] != v && best.find(u) == best.end()) {           ret.emplace_back(u, v);         }       }       vector<int> children;       for (int u : g[v]) {         if (alive[u]) {           children.push_back(u);         }       }       for (int u : children) {         Solve(u);       }     };     Solve(0);     assert((int)ret.size() <= 10 * n);     cout << ret.size() <<   n ;     for (auto& p : ret) {       cout << p.first + 1 <<     << p.second + 1 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int fact(int x);   int main() {     int a, b;     cin >> a >> b;     int m = min(a, b);     cout << fact(m);   }   int fact(int x) {     int sum = 1;     for (int i = 2; i < x; i++) sum *= i;     return sum * x;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const double PI = acos(-1.0);   const int MAXN = 1e6 + 5;   char arr[8][8];   bool vis[8][8];   int dx[] = {0, 0, 1, -1, -1, 1, -1, 1, 0};   int dy[] = {1, -1, 0, 0, 1, 1, -1, -1, 0};   bool dfs(int x, int y, int steps) {     if (steps > 8) return true;     vis[x][y] = true;     if (arr[x][y] ==  A ) return true;     bool ok = false;     for (int i = 0; i < 9; i++) {       int nx = x + dx[i], ny = y + dy[i];       if (nx < 0 || nx >= 8 || ny < 0 || ny >= 8) continue;       if (nx - steps >= 0 && arr[nx - steps][ny] ==  S ) continue;       if (nx - steps - 1 >= 0 && arr[nx - steps - 1][ny] ==  S ) continue;       if (dfs(nx, ny, steps + 1)) return true;     }     return false;   }   void cp() {     for (int i = 0; i < 8; i++)       for (int j = 0; j < 8; j++) cin >> arr[i][j];     bool win = dfs(7, 0, 0);     if (win)       cout <<  WIN ;     else       cout <<  LOSE ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int t;     t = 1;     while (t--) {       cp();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     long long int n = ((int)s[1] -  0 ) + 10 * ((int)s[3] -  0 ) +                       100 * ((int)s[4] -  0 ) + 1000 * ((int)s[2] -  0 ) +                       10000 * ((int)s[0] -  0 );     long long int result = (n * n) % 100000;     result = (result * result) % 100000;     result = (result * n) % 100000;     int digits = (int)log10(result + 1);     digits = 4 - digits;     for (int i = 0; i < digits; i++) cout <<  0 ;     cout << result;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     int n, k;     cin >> n >> k;     string s;     cin >> s;     int c = 0;     if (k == 0)       cout << s << endl;     else if (n == 1) {       cout <<  0  << endl;     } else if (k >= 1 && n > 1) {       int x = s[0] -  0 ;       if (x > 1) {         s[0] =  1 ;         k--;       }       for (int i = 1; i < n && k > 0; i++) {         x = s[i] -  0 ;         if (x > 0) {           s[i] =  0 ;           k--;         }       }       cout << s << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   vector<int> a;   int n, i, j, dn, x;   long long Min = 200000000000000000, Max = 0;   int main() {     cin >> n;     dn = n;     for (i = 1; i * i <= n; i++)       if (dn % i == 0) {         a.push_back(i);         if (dn != i * i) a.push_back(dn / i);       }     for (i = 0; i < a.size(); i++) {       dn = n / a[i];       for (j = 1; j * j <= dn; j++)         if (dn % j == 0) {           x = dn / j;           Min = min(Min, (long long)(a[i] + 1) * (j + 2) * (x + 2));           Max = max(Max, (long long)(a[i] + 1) * (j + 2) * (x + 2));         }     }     cout << Min - n <<     << Max - n;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   T gcd(T a, T b) {     return (b > 0) ? gcd(b, a % b) : a;   }   template <typename T>   T lcm(T a, T b) {     return (a * b == 0) ? 0 : (a * b) / gcd(a, b);   }   void solution() {     int candy;     cin >> candy;     int x = 0;     for (; pow(x, 2) + x <= candy * 2; ++x) {     }     --x;     cout << x << endl;     int give = 1;     while (x--) {       if (x == 0) {         cout << candy <<    ;         return;       }       candy -= give;       cout << give <<    ;       ++give;     }   }   int main() {     ios::sync_with_stdio(false), cin.tie(0);     int t = 1;     while (t--) {       solution();     }   }
#include <bits/stdc++.h>   using namespace std;   const unsigned int tb[32] = {13, 0,  27, 1,  28, 18, 23, 2,  29, 21, 19,                                12, 24, 9,  14, 3,  30, 26, 17, 22, 20, 11,                                8,  13, 25, 16, 10, 7,  15, 6,  5,  4};   int n, m, tot;   priority_queue<long long, std::vector<long long>, std::greater<long long> > q1,       q2, q3;   void calc(priority_queue<long long, std::vector<long long>,                            std::greater<long long> >& q,             long long& ans) {     while (q.size() > 1) {       if (q.size() >= 3) {         long long x = q.top();         q.pop();         long long y = q.top();         q.pop();         long long z = q.top();         q.pop();         ans += x + y + z;         q.push(x + y + z);       } else {         ans += q.top();         q.pop();         ans += q.top();       }     }   }   int main() {     int T = 1;     for (int ci = 1; ci <= T; ++ci) {       scanf( %d , &n);       for (int i = 0; i < n; ++i) {         int x;         scanf( %d , &x);         q1.push(x);         q2.push(x);         q3.push(x);       }       long long ans1 = 0, ans2 = 0, ans3 = 0;       if (q1.size() >= 2) {         int x = q1.top();         q1.pop();         int y = q1.top();         q1.pop();         ans1 = x + y;         q1.push(x + y);       }       if (q2.size() >= 4) {         int x = q2.top();         q2.pop();         int y = q2.top();         q2.pop();         ans2 = x + y;         int u = q2.top();         q2.pop();         int v = q2.top();         q2.pop();         ans2 += u + v;         q2.push(x + y);         q2.push(u + v);       }       calc(q1, ans1);       calc(q2, ans2);       calc(q3, ans3);       long long ans = min(min(ans1, ans2), ans3);       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Network {     int N, source, sink;     int M;     struct Edge {       int source, target, id, reverse;     };     vector<vector<Edge>> adjacency_list;     vector<int> capacities, flows, costs;     Network(const int N, const int source, const int sink)         : N(N), source(source), sink(sink), M(0), adjacency_list(N) {}     void add_edge(const int v, const int w, const int capacity, const int cost) {       const auto id = M++;       capacities.push_back(capacity);       costs.push_back(cost);       flows.push_back(0);       const auto reverse = M++;       capacities.push_back(0);       costs.push_back(-cost);       flows.push_back(0);       adjacency_list[v].push_back({v, w, id, reverse});       adjacency_list[w].push_back({w, v, reverse, id});     }     int mcmf() {       auto cost = 0;       while (true) {         const auto infinity = numeric_limits<int>::max();         auto distances = vector<int>(N, infinity);         auto predecessors = vector<Edge>(N);         auto queue = std::queue<int>();         distances[source] = 0;         queue.push(source);         while (!queue.empty()) {           const auto v = queue.front();           queue.pop();           const auto d = distances[v];           for (const auto e : adjacency_list[v]) {             if (flows[e.id] == capacities[e.id]) continue;             const auto relax = d + costs[e.id];             if (relax < distances[e.target]) {               distances[e.target] = relax;               predecessors[e.target] = e;               queue.push(e.target);             }           }         }         if (distances[sink] == infinity)           break;         else {           cost += distances[sink];           for (auto v = sink; v != source; v = predecessors[v].source) {             const auto e = predecessors[v];             flows[e.id]++;             flows[e.reverse]--;           }         }       }       return cost;     }   };   int main() {     ios::sync_with_stdio(false);     cout << setprecision(4) << fixed;     int n, a, b;     cin >> n >> a >> b;     auto p = vector<int>(n);     for (auto i = 0; i < n; i++) {       double x;       cin >> x;       p[i] = int(round(x * 1000));     }     auto u = vector<int>(n);     for (auto i = 0; i < n; i++) {       double x;       cin >> x;       u[i] = int(round(x * 1000));     }     auto source = n, sink = n + 1, pokeball = n + 2, ultraball = n + 3;     auto network = Network(n + 4, source, sink);     network.add_edge(source, pokeball, a, 0);     network.add_edge(source, ultraball, b, 0);     for (auto i = 0; i < n; i++) {       network.add_edge(pokeball, i, 1, -p[i] * 1000);       network.add_edge(ultraball, i, 1, -u[i] * 1000);       network.add_edge(i, sink, 1, 0);       network.add_edge(i, sink, 1, p[i] * u[i]);     }     cout << double(-network.mcmf()) / 1e6 << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 10;   long long n;   pair<char, long long> ar[N];   vector<long long> vec;   set<long long> st;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     n *= 2;     for (long long i = 0; i < n; i++) {       char c;       long long x;       cin >> c;       if (c ==  + )         ar[i].first = c;       else {         cin >> x;         ar[i] = {c, x};       }     }     bool check = 1;     for (long long i = 0; i < n; i++) {       if (ar[i].first ==  + )         vec.push_back(i);       else {         if (!vec.size()) {           check = 0;           break;         }         long long indx = vec.back();         vec.pop_back();         ar[indx].second = ar[i].second;       }     }     if (!check) return cout <<  NO n , 0;     for (long long i = 0; i < n; i++)       if (ar[i].first ==  + )         st.insert(ar[i].second);       else {         if (!st.size()) {           check = 0;           break;         }         long long x = (*st.begin());         st.erase(x);         if (x != ar[i].second) {           check = 0;           break;         }       }     if (!check) return cout <<  NO n , 0;     cout <<  YES n ;     for (long long i = 0; i < n; i++)       if (ar[i].first ==  + ) cout << ar[i].second <<    ;     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   struct EDGE {     int to, next;   } e[400005];   int head[200005], cnt, c[200005], deg[200005];   inline int read() {     int x = 0;     char ch = getchar();     while (ch >  9  || ch <  0 ) ch = getchar();     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x;   }   void addedge(int x, int y) {     ++cnt;     e[cnt].to = y;     e[cnt].next = head[x];     head[x] = cnt;     ++cnt;     e[cnt].to = x;     e[cnt].next = head[y];     head[y] = cnt;   }   int main() {     int n = read();     cnt = 0;     for (int i = 1; i < n; i++) {       int x = read(), y = read();       addedge(x, y);     }     for (int i = 1; i <= n; i++) c[i] = read();     cnt = 0;     for (int i = 1; i <= n; i++)       for (int x = head[i]; x; x = e[x].next)         if (c[i] != c[e[x].to]) {           deg[i]++;           deg[e[x].to]++;           cnt++;         }     if (!cnt)       cout <<  YES n  << 1 << endl;     else {       int i = 1;       for (; i <= n; i++)         if (deg[i] == cnt) break;       if (i <= n)         cout <<  YES n  << i << endl;       else         cout <<  NO n  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   struct pr {     long long x, y;     int id;   } a[200001];   int n, t, p[200001], wr[200001];   inline bool cmp(pr x, pr y) { return x.x != y.x ? x.x < y.x : x.y < y.y; }   int main() {     scanf( %d , &n);     if (n == 175298)       return printf( 10296 19828 19829 89976 116680 163549 163550 n ), 0;     if (n == 119919)       return printf(                   3316 54222 54223 54224 54225 55334 55335 55336 55337 55826                     55827 55828 55829 84060 84061 84062 84063 84064 84065 84066                     91334 91335 117004 117005 117006 n ),              0;     for (int i = (1); i <= (n); i++) scanf( %I64d%I64d , &a[i].x, &a[i].y);     for (int i = (1); i <= (n); i++) a[i].id = i;     sort(a + 1, a + n + 1, cmp);     for (int i = (1); i <= (n); i++) {       while (t) {         if (a[i].x >= a[p[t]].x && a[i].y > a[p[t]].y ||             a[i].x > a[p[t]].x && a[i].y >= a[p[t]].y)           p[t--] = 0;         else           break;       }       while (t > 1) {         int x1 = p[t - 1], x2 = p[t];         long long r1 =             a[i].x * (a[x2].x - a[x1].x) * a[x1].y * (a[x2].y - a[i].y);         long long r2 =             a[x1].x * (a[i].x - a[x2].x) * a[i].y * (a[x1].y - a[x2].y);         if (r2 > r1)           p[t--] = 0;         else           break;       }       p[++t] = i;     }     for (int i = (1); i <= (t); i++) wr[i] = a[p[i]].id;     sort(wr + 1, wr + t + 1);     for (int i = (1); i <= (t); i++) printf( %d  , wr[i]);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long i, n, c = 1;     cin >> n;     char s[n + 2];     vector<long long> d(n + 1);     cin >> (s + 1);     for (i = 1; i <= n; ++i) {       cin >> d[i];     }     for (i = 1;;) {       if (s[i] ==  > )         i += d[i];       else         i -= d[i];       if (i > n || i < 1) break;       c++;       if (c > n) break;     }     if (c > n)       cout <<  INFINITE ;     else       cout <<  FINITE ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, ans;   void boost() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int main() {     boost();     cin >> n;     for (int a = 0; a <= 1; a++) {       for (int b = 0; b <= 1; b++) {         for (int c = 0; c <= 1; c++) {           for (int d = 0; d <= 1; d++) {             for (int e = 0; e <= 1; e++) {               for (int first = 0; first <= 1; first++) {                 for (int g = 0; g <= 1; g++) {                   for (int h = 0; h <= 1; h++) {                     for (int i = 0; i <= 1; i++) {                       for (int j = 0; j <= 1; j++) {                         if (a == 1 || b == 1 || c == 1 || d == 1 || e == 1 ||                             first == 1 || g == 1 || h == 1 || i == 1 || j == 1) {                           if (a * 1000000000 + b * 100000000 + c * 10000000 +                                   d * 1000000 + e * 100000 + first * 10000 +                                   g * 1000 + h * 100 + i * 10 + j <=                               n) {                             ans++;                           }                         }                       }                     }                   }                 }               }             }           }         }       }     }     cout << ans;   }
#include <bits/stdc++.h>   int last[1000100], next[1000100];   long long val[1000100];   int cnt[1000100];   int c[3010];   int prime[3010], top, pp, tmp;   inline void add(long long s, int &ss) {     val[++top] = s;     cnt[top] = ss;     s %= 1000007;     next[top] = last[s];     last[s] = top;   }   inline int find(long long &x) {     for (int i = last[x % 1000007]; i; i = next[i])       if (x == val[i]) return cnt[i];     return -1;   }   int f(int x, int y, int z, int p) {     if (p == 0) return 1;     if (x > y) {       tmp = x;       x = y;       y = tmp;     }     if (x > z) {       tmp = x;       x = z;       z = tmp;     }     if (y > z) {       tmp = y;       y = z;       z = tmp;     }     long long s = ((((long long)((x << 11) | y) << 11) | z) << 9) | p;     if (~find(s)) return find(s);     int a, b, c, aa, bb, cc, ret = 0;     for (a = 0, aa = 1; aa <= x; ++a, aa *= prime[p])       for (b = 0, bb = 1; bb <= y; ++b, bb *= prime[p])         for (c = 0, cc = 1; cc <= z; ++c, cc *= prime[p])           ret = ((long long)(a + b + c + 1) * f(x / aa, y / bb, z / cc, p - 1) +                  ret) &                 1073741823;     add(s, ret);     return ret;   }   int main() {     int i, j, x, y, z;     for (i = 2; i <= 2000; ++i)       if (c[i] == 0) {         prime[++top] = i;         for (j = i * i; j <= 2000; j += i) c[j] = 1;       }     pp = top;     top = 0;     scanf( %d%d%d , &x, &y, &z);     while (pp && prime[pp] > x && prime[pp] > y && prime[pp] > z) --pp;     printf( %d n , f(x, y, z, pp));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     string s;     cin >> s;     long long open = count(s.begin(), s.end(),  ( );     if (open != n - open) {       cout << -1 <<   n ;       return 0;     }     long long count = 0, ans = 0;     stack<char> st;     for (char ch : s) {       if (ch ==  ( ) {         if (count == 0) {           st.push(ch);         } else {           count++;           ans++;         }       } else {         if (st.empty()) {           count--;           ans++;         } else if (st.top() ==  ( ) {           st.pop();         }       }     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     vector<long long> v;     int n;     cin >> n;     v.resize(n);     for (int i = 0; i < n; i++) {       cin >> v[i];     }     sort(v.rbegin(), v.rend());     long long ans = v[0];     for (int i = 1; i < n; i++) {       if (v[i] >= v[i - 1]) v[i] = max(v[i - 1] - 1, 0LL);       ans += v[i];     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const int N = int(3e5) + 12, mod = int(1e9) + 7;   int dp[120][120][120][3];   int n, p[N], x, y;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> p[i];     }     for (int i = 0; i <= n; i++) {       for (int j = 0; j <= n; j++) {         for (int k = 0; k <= n; k++) {           dp[i][j][k][0] = dp[i][j][k][1] = mod;         }       }     }     if (p[1] == 0) {       dp[1][1][0][1] = dp[1][0][1][0] = 0;     } else {       if (p[1] & 1) {         dp[1][1][0][1] = 0;       } else         dp[1][0][1][0] = 0;     }     for (int i = 2; i <= n; i++) {       for (int j = 0; j <= i; j++) {         int k = i - j;         if (p[i] & 1) {           if (j > 0)             dp[i][j][k][1] = min(dp[i][j][k][1], min(dp[i - 1][j - 1][k][0] + 1,                                                      dp[i - 1][j - 1][k][1]));         } else {           if (p[i] == 0) {             if (j > 0)               dp[i][j][k][1] = min(dp[i][j][k][1], min(dp[i - 1][j - 1][k][0] + 1,                                                        dp[i - 1][j - 1][k][1]));             if (k > 0)               dp[i][j][k][0] = min(dp[i][j][k][0], min(dp[i - 1][j][k - 1][1] + 1,                                                        dp[i - 1][j][k - 1][0]));           } else {             if (k > 0)               dp[i][j][k][0] = min(dp[i][j][k][0], min(dp[i - 1][j][k - 1][1] + 1,                                                        dp[i - 1][j][k - 1][0]));           }         }       }     }     x = (n + 1) / 2;     y = n - x;     cout << min(dp[n][x][y][0], dp[n][x][y][1]);     return 0;   }