malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   ostream &operator<<(ostream &out, string str) {     for (char c : str) out << c;     return out;   }   template <class L, class R>   ostream &operator<<(ostream &out, pair<L, R> p) {     return out <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <class T>   auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) {     out <<  { ;     for (auto it = a.begin(); it != a.end(); it = next(it))       out << (it != a.begin() ?  ,   :   ) << *it;     return out <<  } ;   }   void dump() { cerr <<   n ; }   template <class T, class... Ts>   void dump(T a, Ts... x) {     cerr << a <<  ,  ;     dump(x...);   }   template <class T>   int size(T &&a) {     return a.size();   }   using LL = long long;   using PII = pair<int, int>;   mt19937 _gen(chrono::system_clock::now().time_since_epoch().count());   int rd(int a, int b) { return uniform_int_distribution<int>(a, b)(_gen); }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     for (int _t = 0; _t < t; _t++) {       int n, m;       cin >> n >> m;       vector<vector<int>> v(n, vector<int>(m));       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++) cin >> v[i][j];       vector<int> ord(m);       vector<int> mx(m);       for (int j = 0; j < m; j++) {         ord[j] = j;         for (int i = 0; i < n; i++) mx[j] = max(mx[j], v[i][j]);       }       sort(ord.begin(), ord.end(), [&](int a, int b) { return mx[a] > mx[b]; });       vector<int> rev;       for (int i = 0; i < min(n, m); i++) rev.emplace_back(ord[i]);       vector<vector<int>> t(n, vector<int>(size(rev)));       for (int i = 0; i < n; i++)         for (int j = 0; j < size(rev); j++) t[i][j] = v[i][rev[j]];       m = size(rev);       int p = (1 << n);       vector<vector<int>> dp(m, vector<int>(p));       vector<vector<int>> sum(m, vector<int>(p));       auto mymod = [&](int val) {         if (val >= n) return val - n;         return val;       };       for (int j = 0; j < m; j++) {         for (int k = 0; k < p; k++) {           for (int r = 0; r < n; r++) {             int sumka = 0;             for (int i = 0; i < n; i++) {               if (k & (1 << mymod(i + r))) sumka += t[i][j];             }             sum[j][k] = max(sum[j][k], sumka);           }           false;         }       }       for (int j = 0; j < m; j++) {         if (j != 0) dp[j] = dp[j - 1];         for (int k = 0; k < p; k++) {           if (j == 0)             dp[j][k] = sum[j][k];           else {             for (int l = k; l > 0; l = (l - 1) & k) {               dp[j][k] = max(dp[j][k], dp[j - 1][k ^ l] + sum[j][l]);             }           }         }         false;       }       cout << dp[m - 1][p - 1] <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       string s;       cin >> s;       vector<int> v(m);       for (int i = 0; i < m; i++) {         cin >> v[i];       }       sort(v.begin(), v.end());       vector<int> ans(26);       for (int i = 0; i < n; i++) {         int k = v.end() - upper_bound(v.begin(), v.end(), i);         ans[s[i] -  a ] += (k + 1);       }       for (auto x : ans) cout << x <<    ;       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > g[100000];   vector<pair<int, int> > t[100000];   int n, k;   int dp[100000][2];   bool cmp(pair<int, int> f, pair<int, int> s) {     if (dp[f.first][0] + f.second != dp[s.first][0] + s.second)       return dp[f.first][0] + f.second > dp[s.first][0] + s.second;     else       return f.first < s.first;   }   void dfs(int cur, int par = -1) {     for (int i = 0; i < g[cur].size(); i++) {       if (g[cur][i].first == par) continue;       dfs(g[cur][i].first, cur);       t[cur].push_back(g[cur][i]);     }     sort(t[cur].begin(), t[cur].end(), cmp);     for (int i = 0; i < min(k - 1, (int)t[cur].size()); i++) {       dp[cur][0] += dp[t[cur][i].first][0] + t[cur][i].second;     }     int add = 0;     if (t[cur].size() >= k) {       add = dp[t[cur][k - 1].first][0] + t[cur][k - 1].second;     }     for (int i = 0; i < t[cur].size(); i++) {       if (i < k) {         dp[cur][1] = max(dp[cur][1], dp[cur][0] + dp[t[cur][i].first][1] -                                          dp[t[cur][i].first][0] + add);       } else {         dp[cur][1] = max(dp[cur][1],                          dp[cur][0] + dp[t[cur][i].first][1] + t[cur][i].second);       }     }   }   int main() {     scanf( %d %d , &n, &k);     for (int i = 0; i < n - 1; i++) {       int a, b, c;       scanf( %d %d %d , &a, &b, &c);       g[a].push_back(make_pair(b, c));       g[b].push_back(make_pair(a, c));     }     dfs(0);     cout << max(dp[0][0], dp[0][1]) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k, h;   int m[100001];   int v[100001];   int id[100001];   int match[100001];   int res[100001];   double eps = 1e-9;   void qsort1(int, int);   void qsort2(int, int);   bool ok(double);   int main() {     cin >> n >> k >> h;     for (int i = 1; i <= n; i++) {       cin >> m[i];       id[i] = i;     }     for (int i = 1; i <= n; i++) cin >> v[i];     qsort1(1, n);     int first = 1;     for (int i = 2; i <= n; i++)       if (m[i] != m[i - 1]) {         qsort2(first, i - 1);         first = i;       }     if (m[n] == m[n - 1]) qsort2(first, n);     double hi, lo;     lo = 0;     hi = 1e9;     for (int j = 1; j <= 100; j++) {       double mid = (hi + lo) / 2;       if (ok(mid)) {         hi = mid;         for (int i = 1; i <= k; i++) res[i] = match[i];       } else         lo = mid;     }     for (int i = 1; i <= k; i++) cout << res[i] <<    ;     cout << endl;     return 0;   }   bool ok(double mid) {     int j = 1;     for (int i = 1; i <= k; i++) {       while (j <= n && double(i * h) / double(v[j]) > mid + eps) j++;       if (j > n) return false;       match[i] = id[j];       j++;     }     return true;   }   void qsort1(int l, int r) {     if (l >= r) return;     int i = l;     int j = r;     int mid = m[(l + r) / 2];     while (i < j) {       while (m[i] < mid) i++;       while (mid < m[j]) j--;       if (i <= j) {         swap(m[i], m[j]);         swap(v[i], v[j]);         swap(id[i], id[j]);         i++;         j--;       }     }     qsort1(i, r);     qsort1(l, j);   }   void qsort2(int l, int r) {     if (l >= r) return;     int i = l;     int j = r;     int mid = v[(l + r) / 2];     while (i < j) {       while (v[i] < mid) i++;       while (mid < v[j]) j--;       if (i <= j) {         swap(v[i], v[j]);         swap(m[i], m[j]);         swap(id[i], id[j]);         i++;         j--;       }     }     qsort2(i, r);     qsort2(l, j);   }
#include <bits/stdc++.h>   using namespace std;   long long x, x2, y, y2, n, m, k, a, b, rep, koliko, koliko2, p;   long long hi, lo, mid;   bool t;   char c;   string s;   int main() {     vector<long long> V;     cin >> n >> k;     k = n - k;     for (int i = 0; i < n; i++) {       cin >> x;       V.push_back(x);     }     lo = 1;     hi = 1000000010;     while (lo < hi) {       mid = (lo + hi) / 2;       koliko = 0;       p = 0;       while (p < V.size()) {         if (V[p] > mid) {           koliko++;           p++;         } else {           p += 2;         }       }       koliko2 = 0;       p = 1;       while (p < V.size()) {         if (V[p] > mid) {           koliko2++;           p++;         } else {           p += 2;         }       }       if (min(koliko, koliko2) <= k) {         hi = mid;       } else {         lo = mid + 1;       }     }     cout << lo <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int a[26];   int b[26];   bool ok;   inline void go(int v, int rem, int cur, int last) {     if (v == n) {       ok = 1;       for (int i = 1; i <= n && ok; ++i)         if (b[i]) ok = 0;       if (ok) {         puts( YES );         exit(0);       }     }     if (rem == 1) {       if (cur == 1) return;       if (v + 1 != n) ++b[a[v]];       go(v + 1, a[v + 1], 0, n);       if (v + 1 != n) --b[a[v]];       return;     }     if (!cur) {       for (int i = rem - 2; i >= 1; --i) {         if (!b[i]) continue;         --b[i];         go(v, rem - i, cur + 1, i);         ++b[i];       }     } else {       for (int i = min(rem - 1, last); i >= 1; --i) {         if (!b[i]) continue;         --b[i];         go(v, rem - i, cur + 1, i);         ++b[i];       }     }   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d , &a[i]);     sort(a, a + n);     ok = 1;     for (int i = 0; i < n; ++i)       if (a[i] == 2) ok = 0;     if (a[n - 1] != n || !ok) {       puts( NO );       return 0;     }     go(0, a[0], 0, n);     puts( NO );     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:66777216 )   using namespace std;   inline pair<int, int> operator-(const pair<int, int> &a,                                   const pair<int, int> &b) {     return make_pair(a.first - b.first, a.second - b.second);   }   inline int vec(const pair<int, int> &a, const pair<int, int> &b) {     return a.first * b.second - b.first * a.second;   }   int a, b, c, d, n, m, k;   pair<int, int> mas[3005], tmp[3005], res[3005], hull[3005];   inline int dist(const pair<int, int> &a, const pair<int, int> &b) {     return (a.first - b.first) * (a.first - b.first) +            (a.second - b.second) * (a.second - b.second);   }   inline bool cool(pair<int, int> *mas, int n, long double xx) {     if (n < 2) return 0;     int k = 0;     for (int _n((2) - 1), iter(0); iter <= _n; iter++) {       int h = 0;       for (int _n((n)-1), i(0); i <= _n; i++) {         while (h >= 2 &&                vec(mas[i] - hull[h - 1], hull[h - 1] - hull[h - 2]) <= 0)           --h;         hull[h++] = mas[i];       }       --h;       for (int _n((h)-1), i(0); i <= _n; i++) res[k++] = hull[i];       reverse(mas, mas + n);     }     if (k == 2) {       if (dist(res[0], res[1]) >= xx)         return 1;       else         return 0;     }     int a = 0;     for (int _n((k)-1), i(0); i <= _n; i++) {       if (a == i) {         a = i + 1;         if (a == k) a = 0;       }       while (1) {         int t = a + 1;         if (t >= k) t = 0;         if (t == i) break;         int s1 = dist(res[i], res[a]);         int s2 = dist(res[i], res[t]);         if (s2 >= s1)           a = t;         else           break;       }       if (dist(res[i], res[a]) >= xx) return 1;     }     return 0;   }   inline bool check(long double xx) {     for (int _n((n)-1), v(0); v <= _n; v++) {       int k = 0;       for (int _n(n - 1), i(v + 1); i <= _n; i++) {         int s = (mas[v].first - mas[i].first) * (mas[v].first - mas[i].first) +                 (mas[v].second - mas[i].second) * (mas[v].second - mas[i].second);         if (s >= xx) {           tmp[k++] = mas[i];         }       }       if (cool(tmp, k, xx)) return 1;     }     return 0;   }   int main() {     scanf( %d , &n);     for (int _n((n)-1), i(0); i <= _n; i++) {       scanf( %d%d , &mas[i].first, &mas[i].second);     }     sort(mas, mas + n);     long double l = 0.0, r = 4.1e9;     for (int _n((55) - 1), hhod(0); hhod <= _n; hhod++) {       long double xx = (r + l) / 2.0;       if (check(xx))         l = xx;       else         r = xx;     }     double ans = (double)(sqrt(l / 4));     printf( %.12lf n , (double)(sqrt(l / 4)));   }
#include <bits/stdc++.h>   #pragma GCC optimize(2)   #pragma GCC optimize(3)   #pragma GCC optimize( Ofast )   #pragma GCC optimize( inline )   #pragma GCC optimize( -fgcse )   #pragma GCC optimize( -fgcse-lm )   #pragma GCC optimize( -fipa-sra )   #pragma GCC optimize( -ftree-pre )   #pragma GCC optimize( -ftree-vrp )   #pragma GCC optimize( -fpeephole2 )   #pragma GCC optimize( -ffast-math )   #pragma GCC optimize( -fsched-spec )   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( -falign-jumps )   #pragma GCC optimize( -falign-loops )   #pragma GCC optimize( -falign-labels )   #pragma GCC optimize( -fdevirtualize )   #pragma GCC optimize( -fcaller-saves )   #pragma GCC optimize( -fcrossjumping )   #pragma GCC optimize( -fthread-jumps )   #pragma GCC optimize( -funroll-loops )   #pragma GCC optimize( -fwhole-program )   #pragma GCC optimize( -freorder-blocks )   #pragma GCC optimize( -fschedule-insns )   #pragma GCC optimize( inline-functions )   #pragma GCC optimize( -ftree-tail-merge )   #pragma GCC optimize( -fschedule-insns2 )   #pragma GCC optimize( -fstrict-aliasing )   #pragma GCC optimize( -fstrict-overflow )   #pragma GCC optimize( -falign-functions )   #pragma GCC optimize( -fcse-skip-blocks )   #pragma GCC optimize( -fcse-follow-jumps )   #pragma GCC optimize( -fsched-interblock )   #pragma GCC optimize( -fpartial-inlining )   #pragma GCC optimize( no-stack-protector )   #pragma GCC optimize( -freorder-functions )   #pragma GCC optimize( -findirect-inlining )   #pragma GCC optimize( -fhoist-adjacent-loads )   #pragma GCC optimize( -frerun-cse-after-loop )   #pragma GCC optimize( inline-small-functions )   #pragma GCC optimize( -finline-small-functions )   #pragma GCC optimize( -ftree-switch-conversion )   #pragma GCC optimize( -foptimize-sibling-calls )   #pragma GCC optimize( -fexpensive-optimizations )   #pragma GCC optimize( -funsafe-loop-optimizations )   #pragma GCC optimize( inline-functions-called-once )   #pragma GCC optimize( -fdelete-null-pointer-checks )   using namespace std;   inline int read() {     int s = 0, w = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) s = s * 10 + ch -  0 , ch = getchar();     return s * w;   }   inline void write(int x) {     if (x < 0) {       putchar( - );       x = -x;     }     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );   }   int a[25];   int main() {     ios::sync_with_stdio(false);     int n, k, l = 0, i = 1;     n = read();     k = read();     if (k == 1) {       write(n);       puts(  );     } else {       while (i++) {         while (n % i == 0) {           n /= i;           a[++l] = i;           if (k == l + 1) {             if (n == 1) {               puts( -1 );               break;             }             for (register int j = 1; j <= l; j++) {               write(a[j]);               putchar(   );             }             write(n);             break;           }         }         if (k == l + 1) break;         if (i > n) {           puts( -1 );           break;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7, N = 1e5 + 5;   int n, c[N], x;   long long dp[N][2];   vector<int> g[N];   void dfs(int v) {     dp[v][0] = 1LL;     for (int u : g[v]) {       dfs(u);       (dp[u][0] += dp[u][1]) %= mod;       dp[v][1] = (dp[v][1] * dp[u][0] + dp[v][0] * dp[u][1]) % mod;       dp[v][0] = (dp[v][0] * dp[u][0]) % mod;     }     if (c[v]) {       dp[v][1] = dp[v][0];       dp[v][0] = 0;     }   }   int main() {     ios::sync_with_stdio(0), cin.tie(0);     cin >> n;     for (int i = 1; i < n; i++) {       cin >> x;       g[x].push_back(i);     }     for (int i = 0; i < n; i++) cin >> c[i];     dfs(0);     cout << dp[0][1];   }
#include <bits/stdc++.h>   using namespace std;   const long double eps = 1e-13;   const long double PI = acos(-1);   const int INF = (int)1e9;   const long long INFF = (long long)1e18;   const int mod = (int)1e9 + 7;   const int MXN = (int)1e6 + 7;   int n, k;   vector<int> edge[MXN];   vector<int> re_edge[MXN];   int prt[MXN];   int dp[21][MXN];   void init() {     scanf( %d %d , &n, &k);     for (int i = 2; i < n + 1; i++) {       scanf( %d , prt + i);       edge[prt[i]].push_back(i);       re_edge[i].push_back(prt[i]);       dp[0][i] = prt[i];     }     return;   }   bool leaf[MXN];   struct Scc {     int re[MXN], cntp;     int in[MXN];     int siz[MXN], gp[MXN];     int num[MXN];     int val[MXN];     int fd(int u) { return gp[u] == u ? u : gp[u] = fd(gp[u]); }     void uni(int u, int v) {       u = fd(u), v = fd(v);       if (u == v) return;       if (siz[u] > siz[v]) swap(u, v);       gp[u] = v;       siz[u] += siz[v];       return;     }     void dfs(int u) {       in[u] = 1;       for (int v : edge[u]) {         if (!in[v]) dfs(v);       }       re[++cntp] = u;       return;     }     void dfs2(int u, int la) {       in[u] = 1;       uni(u, la);       for (int v : re_edge[u]) {         if (!in[v]) dfs2(v, la);       }     }     void pre() {       for (int i = 1; i < n + 1; i++) siz[i] = 1, gp[i] = i;       for (int i = 1; i < n + 1; i++)         if (!in[i]) dfs(i);       memset(in, 0, sizeof(in));       ;       for (int i = n; i >= 1; i--)         if (!in[re[i]]) dfs2(re[i], re[i]);       for (int i = 1; i < n + 1; i++)         if (leaf[i]) {           num[fd(i)]++;           val[fd(i)]++;         }       return;     }     int solve() {       pre();       int ans = 0;       for (int i = 1; i < n + 1; i++) {         ans = max(ans, val[fd(i)]);         for (int v : edge[re[i]]) {           int p1 = fd(v);           int p2 = fd(re[i]);           if (p1 == p2) continue;           val[p2] = max(val[p2], num[p2] + val[p1]);           ans = max(ans, val[p2]);         }       }       return ans;     }   } scc;   int dep[MXN];   void dfs(int u, int dpt) {     dep[u] = dpt;     for (int v : edge[u]) dfs(v, dpt + 1);     return;   }   int up(int u, int d) {     for (int i = 0; i < 21; i++) {       if (d & (1 << i)) {         u = dp[i][u];       }     }     return u;   }   void sol() {     dfs(1, 1);     for (int i = 1; i < 21; i++)       for (int j = 1; j < n + 1; j++) {         dp[i][j] = dp[i - 1][dp[i - 1][j]];       }     for (int i = 1; i < n + 1; i++)       if (edge[i].empty()) {         leaf[i] = 1;         int p = 0;         if (dep[i] <= k)           p = 1;         else           p = up(i, k);         edge[i].push_back(p);         re_edge[p].push_back(i);       }     int ans = scc.solve();     printf( %d n , ans);     return;   }   int main(void) {     init();     sol();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXL = 2000005;   string pat[100005];   int beg[2000005];   int bel[2000005];   int id[4200000];   int L = 0;   inline void modify(int a, int b, int val, int v = 1, int l = 1, int r = MAXL) {     if (b < l || a > r) return;     if (a <= l && r <= b) {       id[v] = val;       return;     }     int m = l + r >> 1;     if (id[v]) id[v << 1] = id[v << 1 | 1] = id[v];     id[v] = 0;     modify(a, b, val, v << 1, l, m);     modify(a, b, val, v << 1 | 1, m + 1, r);     return;   }   inline int query(int p, int v = 1, int l = 1, int r = MAXL) {     if (p < l || p > r) return 0;     if (id[v]) return id[v];     if (l == r) return 0;     int m = l + r >> 1;     return max(query(p, v << 1, l, m), query(p, v << 1 | 1, m + 1, r));   }   int cnt = 0;   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> pat[i];       int len = pat[i].size();       int m;       cin >> m;       while (m--) {         cin >> beg[++cnt];         bel[cnt] = i;         modify(beg[cnt], beg[cnt] + len - 1, cnt);         L = max(L, beg[cnt] + len - 1);       }     }     for (int i = 1; i <= L; ++i) {       int q = query(i);       if (!q)         cout <<  a ;       else {         cout << pat[bel[q]][i - beg[q]];       }     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void optimizeIO() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   int32_t main() {     optimizeIO();     long long tt = 1;     cin >> tt;     while (tt--) {       long long n;       cin >> n;       vector<bool> v(65, 0);       while (n) {         long long temp = 1;         long long ind = 0;         while (temp < n) {           temp *= 3;           ind++;         }         if (temp != n) {           temp /= 3;           ind--;         }         if (!v[ind])           v[ind] = true;         else {           for (long long i = ind; i < 65; i++) {             if (v[i])               v[i] = !v[i];             else {               v[i] = true;               break;             }           }           break;         }         n -= temp;       }       long long res = 0;       for (long long i = (long long)(0); i < (long long)(65); i++) {         if (v[i]) {           long long temp = 1;           for (long long j = (long long)(0); j < (long long)(i); j++) {             temp *= 3;           }           res += temp;         }       }       cout << res << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string str[51];   bool visited[51][51], flag = false;   int arrx[] = {1, -1, 0, 0}, arry[] = {0, 0, 1, -1}, n, m;   void dfs(int x, int y, int oldX, int oldY, char renk) {     if (x < 0 || x >= n || y < 0 || y >= m) return;     if (str[x][y] != renk) return;     if (visited[x][y] == true) {       flag = true;       return;     }     visited[x][y] = true;     for (int i = 0; i < 4; i++) {       int newX = x + arrx[i], newY = y + arry[i];       if (newX == oldX && newY == oldY) continue;       dfs(newX, newY, x, y, renk);     }   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> str[i];     memset(visited, 0, sizeof(visited));     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (!visited[i][j]) dfs(i, j, -1, -1, str[i][j]);       }     }     cout << (flag ?  Yes  :  No ) << endl;     return 0;   }