malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <algorithm>     #include <iostream>     #include <sstream>     #include <string>     #include <vector>     #include <queue>     #include <set>     #include <map>     #include <cstdio>     #include <cstdlib>     #include <cctype>     #include <cmath>     #include <cstring>   #include <list>     #include <cassert>   #include <climits>   #include <bitset>   #include <chrono>   #include <random>   using namespace std;      #define PB push_back     #define MP make_pair     #define SZ(v) ((int)(v).size())     #define FOR(i,a,b) for(int i=(a);i<(b);++i)     #define REP(i,n) FOR(i,0,n)     #define FORE(i,a,b) for(int i=(a);i<=(b);++i)     #define REPE(i,n) FORE(i,0,n)     #define FORSZ(i,a,v) FOR(i,a,SZ(v))     #define REPSZ(i,v) REP(i,SZ(v))     std::mt19937 rnd((int)std::chrono::steady_clock::now().time_since_epoch().count());   typedef long long ll;   ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }      const int MAXN = 5000;   const int MAXC = 20;      int n, num, den;   char s[MAXN + 1];   vector<char> ans;      int mp[26];   char c[MAXC]; int nc;   int a[MAXN];      int fst[MAXC], lst[MAXC], cnt[MAXC];      bool ok[1 << MAXC];   bool can[1 << MAXC];      void solve() {    nc = 0; REP(i, 26) mp[i] = -1;    REP(i, n) { int x = s[i] -  a ; if (mp[x] == -1) c[nc] =  a  + x, mp[x] = nc, nc++; a[i] = mp[x]; }       REP(i, nc) fst[i] = INT_MAX, lst[i] = INT_MIN, cnt[i] = 0;    REP(i, n) fst[a[i]] = min(fst[a[i]], i), lst[a[i]] = max(lst[a[i]], i), ++cnt[a[i]];       //printf( c: ); REP(i, nc) printf(  %c , c[i]); puts(  );    FOR(mask, 1, 1 << nc) {      int maskfst = INT_MAX, masklst = INT_MIN, maskcnt = 0;     REP(i, nc) if (mask&(1 << i)) maskfst = min(maskfst, fst[i]), masklst = max(masklst, lst[i]), maskcnt += cnt[i];     ok[mask] = num*(masklst - maskfst + 1) <= maskcnt*den;     //printf( %s[%x] [%d..%d] cnt=%d n , ok[mask] ?  ok  :  fail , mask, maskfst, masklst, maskcnt);    }    can[0] = true;    FOR(mask, 1, 1 << nc) {     can[mask] = false;     if (ok[mask]) REP(i, nc) if ((mask&(1 << i)) != 0 && can[mask ^ (1 << i)]) {      can[mask] = true;     }     REP(i, nc) {      int lmask = mask&((2 << i) - 1), rmask = mask^lmask;      if (can[lmask] && can[rmask]) can[mask] = true;     }    }       ans.clear();    REP(i, nc) if (can[(1 << nc) - 1 - (1 << i)]) ans.PB(c[i]);    sort(ans.begin(), ans.end());   }      void run() {    scanf( %d%d%d , &n, &num, &den);    scanf( %s , s); assert(strlen(s) == n);    solve();    printf( %d , SZ(ans)); REPSZ(i, ans) printf(  %c , ans[i]); puts(  );   }      int main() {    //int ncase; scanf( %d , &ncase); FORE(i, 1, ncase)    run();    return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int cnt = 0, cnt1 = 0;     cin >> s;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  - )         cnt++;       else         cnt1++;     }     if (cnt1 == 0) {       cout <<  YES ;       return 0;     }     if (cnt % cnt1 == 0)       cout <<  YES ;     else       cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   inline void init() {}   string lines[1001];   int main() {     string s;     int n = 0;     int mx = 0;     while (getline(cin, lines[n])) {       mx = std::max<int>(mx, lines[n].length());       n++;     }     cout << string(mx + 2,  * ) << endl;     int sw = 0;     for (int i = 0; i < n; i++) {       cout <<  * ;       int len = lines[i].length();       if (len % 2 != mx % 2) {         if (sw) {           lines[i] =     + lines[i];         } else {           lines[i] +=    ;         }         sw = !sw;       }       int d = mx - len;       if (d) cout << string(d / 2,    );       cout << lines[i];       if (d) cout << string(d / 2,    );       cout <<  * n ;     }     cout << string(mx + 2,  * ) << endl;     return 0;   }
#include <bits/stdc++.h>   struct M {     int p, b;   };   struct F {     const int p, i;     int r;     int c;     F(int p, int t, int i) : p(p), i(i), r(p + t), c(0) {}     int t() { return r - p; }   };   void solve(std::vector<F> &fs, std::vector<M> &ms) {     std::multimap<int, int> ms_landed;     std::map<int, F *> fs_active;     {       std::vector<F *> fs_sort;       fs_sort.reserve(fs.size());       for (int i = 0; i < fs.size(); i++) fs_sort.push_back(&fs[i]);       std::sort(fs_sort.begin(), fs_sort.end(),                 [](const F *lhs, const F *rhs) { return lhs->p < rhs->p; });       fs_active.insert({fs_sort[0]->p, fs_sort[0]});       int curr = fs_sort[0]->r;       for (int i = 1; i < fs_sort.size(); i++) {         F &f = *fs_sort[i];         if (f.r > curr) {           int l = std::max(curr + 1, f.p);           curr = f.r;           fs_active.insert({l, &f});         }       }     }     auto update = [&](F &f, std::map<int, F *>::iterator &f_it, const int &b) {       f.c++;       f.r += b;       while (f_it != fs_active.end()) {         int l_succ = f_it->first;         F &f_succ = *f_it->second;         if (f.r < f_succ.r) {           if (f.r >= l_succ) {             f_it = fs_active.insert(fs_active.erase(f_it), {f.r + 1, &f_succ});           }           break;         }         f_it = fs_active.erase(f_it);       }     };     for (const M &m : ms) {       auto f_it = --fs_active.upper_bound(m.p);       if (f_it == fs_active.end()) continue;       int l = f_it->first;       F &f = *f_it->second;       if (l <= m.p && m.p <= f.r) {         update(f, ++f_it, m.b);         auto m_succ = ms_landed.lower_bound(l);         while (m_succ != ms_landed.end()) {           M m{m_succ->first, m_succ->second};           if (l <= m.p && m.p <= f.r) {             update(f, f_it, m.b);             m_succ = ms_landed.erase(m_succ);           } else {             break;           }         }       } else {         ms_landed.insert({m.p, m.b});       }     }     for (F &f : fs) {       printf( %d %d n , f.c, f.t());     }   }   int main() {     int n;     int m;     scanf( %d%d , &n, &m);     std::vector<F> fs;     fs.reserve(n);     std::vector<M> ms;     ms.reserve(m);     for (int i = 0; i < n; i++) {       int p, t;       scanf( %d%d , &p, &t);       fs.push_back({p, t, i});     }     for (int i = 0; i < m; i++) {       int p, b;       scanf( %d%d , &p, &b);       ms.push_back({p, b});     }     solve(fs, ms);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long edgestory;   long long last;   struct UnionFind {     vector<int> f;     vector<bool> special;     void init(int n) {       f.clear();       f.insert(f.begin(), n, -1);       special.clear();       special.insert(special.begin(), n, false);       edgestory = 0;     }     int comp(int x) { return (f[x] == -1 ? x : f[x] = comp(f[x])); }     bool sp(int x) { return special[comp(x)]; }     bool join1(int i, int j) {       if (i == j) return true;       edgestory++;       bool con = comp(i) == comp(j);       if (!con) {         bool spv = sp(i) || sp(j);         if (sp(i) && sp(j)) last = edgestory;         f[comp(i)] = comp(j);         special[comp(i)] = spv;       }       return con;     }     pair<int, int> join2(int i, int j) {       if (i == j) return {0, 0};       edgestory++;       if (edgestory == last) return {i, j};       bool con = comp(i) == comp(j);       if (!con) {         f[comp(i)] = comp(j);       }       return {0, 0};     }   } uf;   int main() {     ios::sync_with_stdio(0);     cin.tie(nullptr);     long long n, m, k;     cin >> n >> m >> k;     vector<long long> special(k);     for (auto &x : special) cin >> x;     vector<tuple<long long, long long, long long>> edges(m);     for (auto &x : edges) {       long long u, v, w;       cin >> u >> v >> w;       x = make_tuple(w, u - 1, v - 1);     }     sort(edges.begin(), edges.end());     uf.init(n);     for (auto &x : special) uf.special[x - 1] = true;     for (auto &[w, u, v] : edges) uf.join1(u, v);     long long lastw = 0;     uf.init(n);     for (auto &[w, u, v] : edges) {       lastw = w;       if (uf.join2(u, v) != make_pair(0, 0)) break;     }     for (int i = 0; i < k; i++) cout <<     + !i << lastw;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9 + 7;   long long a[200005], b[200005], t[200005];   long long c(long long l, long long r, long long* a) {     if (l == r - 1) return 0;     long long ans = 0, m = (l + r + 1) / 2, k = l, ct = 0;     ans += c(l, m, a) + c(m, r, a);     for (long long i = l, j = m; i < m || j < r;) {       if (j >= r || (i < m && a[i] <= a[j])) {         t[k++] = a[i++];         ct++;       } else {         t[k++] = a[j++];         ans += m - l - ct;       }     }     for (long long i = l; i < r; i++) a[i] = t[i];     return ans;   }   bool solve() {     long long n;     string s, t;     cin >> n >> s >> t;     string ss = s, tt = t;     sort((ss).begin(), (ss).end()), sort((tt).begin(), (tt).end());     if (ss != tt) {       return false;     }     for (long long i = 0; i < n - 1; i++) {       if (ss[i] == ss[i + 1]) {         return true;       }     }     for (long long i = 0; i < n; i++) {       a[i] = lower_bound((ss).begin(), (ss).end(), s[i]) - ss.begin();       b[i] = lower_bound((ss).begin(), (ss).end(), t[i]) - ss.begin();     }     long long c1 = c(0, n, a), c2 = c(0, n, b);     return (c1 & 1) == (c2 & 1);   }   signed main() {     std::ios::sync_with_stdio(0);     std::cin.tie(0);     ;     long long q;     cin >> q;     while (q--) {       if (solve())         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   ll mod = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ll t, n, m, i, j, k;     cin >> n >> k;     vector<ll> v;     i = 0;     if (n % 2 == 1) {       v.push_back(1);       n -= 1;       i++;     }     if (n > 0) {       j = log2(n);       m = pow(2, j);       while (n > 0) {         if (m <= n) {           n -= m;           v.push_back(m);           i++;         } else {           j--;           m = pow(2, j);         }       }     }     ll x = 0, y;     if (i <= k && n == 0) {       for (j = 0; j < v.size(); j++) {         if (i == k) break;         m = v[j];         if (m == 1) continue;         v.erase(v.begin() + j);         j--;         while (m != 1) {           m /= 2;           v.push_back(m);           i++;           if (i == k) break;         }         v.push_back(m);       }       if (i == k) {         sort(v.begin(), v.end());         cout <<  YES               <<   n ;         for (i = 0; i < v.size(); i++) cout << v[i] <<    ;       } else         cout <<  NO ;     } else       cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     long long V;     cin >> V;     while (V--) {       double a[250];       for (long long i = 0; i < 250; i++) cin >> a[i];       double exp = 0;       for (long long i = 0; i < 250; i++) exp += a[i];       exp /= 250;       double var = 0;       for (long long i = 0; i < 250; i++) var += (a[i] - exp) * (a[i] - exp);       var /= 250;       double k = exp / var;       double err = 0.60;       if (1.0 - err <= k && k <= 1.0 + err)         cout <<  poisson  << endl;       else         cout <<  uniform  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<int> G[100000];   int a[100000];   int b[100000];   int c[100000];   void dfs(int v) {     b[v]++;     c[v] = 1;     for (int i = 0; i < (int)(G[v].size()); i++) {       int w = G[v][i];       if (++b[w] == a[w]) dfs(w);     }   }   int main() {     cin >> n >> m;     for (int i = 0; i < (int)(m); i++) {       int a, b;       cin >> a >> b;       --a, --b;       G[a].push_back(b);       G[b].push_back(a);     }     for (int i = 0; i < (int)(n); i++) cin >> a[i];     for (int i = 0; i < (int)(n); i++) {       if (a[i] == b[i]) dfs(i);     }     cout << accumulate(c, c + n, 0) << endl;     for (int i = 0; i < (int)(n); i++)       if (c[i]) cout << i + 1 <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long sum = 0;       long long a[n];       for (long long i = 0; i < n; i++) {         cin >> a[i];         sum += a[i];       }       sort(a, a + n);       reverse(a, a + n);       if (n == 1) {         cout <<  T n ;         continue;       }       if (n == 2) {         if (a[0] == a[1]) {           cout <<  HL n ;           continue;         } else {           cout <<  T n ;           continue;         }       }       if (a[0] > sum - a[0]) {         cout <<  T n ;         continue;       }       if (sum % 2 == 0) {         cout <<  HL n ;         continue;       } else {         cout <<  T n ;         continue;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const double PI = 3.14159265358979323846264338327950288419716939937510;   const double E = 2.7182818284590452353602874713526624977572470936999596;   const double eps = 0.000000001;   const int MOD = 998244353;   inline int max(int u, int v) { return u > v ? u : v; }   inline int min(int u, int v) { return u < v ? u : v; }   inline int gcd(int u, int v) { return v ? gcd(v, u % v) : u; }   template <typename T>   inline void read(T& u) {     char id;     u = 0;     bool flag = 0;     id = getchar();     while (id >  9  || id <  0 ) {       if (id ==  - ) flag = 1;       id = getchar();     }     while ((id <=  9  && id >=  0 )) {       u = u * 10 + id -  0 ;       id = getchar();     }     if (flag) u *= -1;   }   template <typename T>   inline void read(T& u, T& v) {     read(u);     read(v);   }   template <typename T>   inline void read(T& u, T& v, T& tmp) {     read(u);     read(v);     read(tmp);   }   long long n, m, a[1500][1500], r, c, len, f[2250000];   struct node {     long long x, y, v;   } str[2250000];   bool cmp(node x, node y) { return x.v < y.v; }   long long power(long long a, long long n) {     a %= MOD;     long long res = 1;     while (n) {       if (n & 1) res = 1LL * res * a % MOD;       a = 1LL * a * a % MOD;       n >>= 1;     }     return res;   }   long long inv(long long x) { return power(x, MOD - 2) % MOD; }   long long cnt, a1, a2, b1, b2, sum;   void solve(int p) {     f[p] = (sum +             (1LL * str[p].x * str[p].x % MOD * cnt % MOD + a2 -              2LL * str[p].x % MOD * a1 % MOD) +             (1LL * str[p].y * str[p].y % MOD * cnt % MOD + b2 -              2LL * str[p].y % MOD * b1 % MOD)) %            MOD;     f[p] = (1LL * f[p] + MOD) % MOD;     f[p] = 1LL * f[p] * inv(cnt) % MOD;   }   inline void add(int p) {     cnt++;     sum += f[p];     a1 += str[p].x;     a2 += 1LL * str[p].x * str[p].x % MOD;     b1 += str[p].y;     b2 += 1LL * str[p].y * str[p].y % MOD;     a1 %= MOD;     b1 %= MOD;     a2 %= MOD;     b2 %= MOD;     sum %= MOD;   }   int main() {     read(n, m);     for (int i = (1); (i) <= (n); (i)++)       for (int j = (1); (j) <= (m); (j)++) read(a[i][j]);     for (int i = (1); (i) <= (n); (i)++)       for (int j = (1); (j) <= (m); (j)++) str[++len] = (node){i, j, a[i][j]};     sort(str + 1, str + len + 1, cmp);     for (int i = (1); (i) <= (len); (i)++) {       int j;       for (j = i; j <= len; j++)         if (str[j].v != str[i].v) break;       for (int k = (i); (k) <= (j - 1); (k)++) solve(k);       for (int k = (i); (k) <= (j - 1); (k)++) add(k);       i = j - 1;     }     long long r, c;     read(r, c);     long long res = 0;     for (int i = (1); (i) <= (len); (i)++)       if (str[i].x == r && str[i].y == c) res = f[i];     res %= MOD;     res = (res + MOD) % MOD;     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const greater<int> gt;   int A[100000];   int main() {     cout << fixed << setprecision(11);     long long n, k, m;     cin >> n >> k >> m;     for (int i = 0; i < n; ++i) cin >> A[i];     sort(A, A + n, gt);     double mx = 0, rx = 0;     for (int i = 0; i < n; ++i) {       rx += A[i];       if (n - i < m + 2) {         mx = max(mx, (min(m - n + i + 1, (i + 1) * k) + rx) / (i + 1));       }     }     cout << mx;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e3 + 5;   int n, deg[N], a[N];   bool ed[N][N];   void change(int u) {     for (int v = 0; v < n; v++) {       deg[u] -= ed[u][v], deg[u] += ed[u][v] ^= true;       deg[v] -= ed[v][u], deg[v] += ed[v][u] ^= true;     }   }   bool check() {     copy(deg, deg + n, a);     sort(a, a + n, greater<int>());     for (int i = 1, sum = a[0]; i < n; sum += a[i++])       if (sum == i * (i - 1) / 2 + i * (n - i)) return false;     return true;   }   int main() {     cin >> n;     for (int u = 0; u < n; u++)       for (int v = 0; v < n; v++) {         char c;         cin >> c;         deg[u] += ed[u][v] = c -  0 ;       }     if (check()) return cout <<  0 1 , 0;     int ted = 0;     for (int u = 0; u < n; change(u++)) change(u), ted += check();     if (ted) return cout <<  1   << ted, 0;     if (n == 6) return cout <<  2 18 , 0;     cout << -1;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 5;   long long mod = 1e9 + 7;   vector<long long> v;   long long n, s;   bool check(long long x) {     long long sum = 0;     for (long long i = 0; i < n; i++) {       sum += (v[i] - x);     }     return sum >= s;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cin >> n;     cin >> s;     long long z;     long long sum = 0;     for (long long i = 0; i < n; i++) cin >> z, v.push_back(z), sum += z;     if (sum < s) {       cout <<  -1 ;       return 0;     }     sort(v.begin(), v.end());     long long l = 0;     long long r = v[0];     while (r > l + 1) {       long long m = (l + r) / 2;       if (check(m)) {         l = m;       } else {         r = m;       }     }     if (!check(r))       cout << l <<   n ;     else       cout << r;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1 << 20;   const int inf = 2e9;   int n, q;   int h[maxn], v[maxn];   pair<pair<int, int>, int> b[maxn];   vector<int> hull[maxn];   long double inter(int id1, int id2) {     if (v[id1] == v[id2]) return -1;     return (long double)(h[id1] - h[id2]) / (v[id2] - v[id1]);   }   long double H(int idx, long double t) { return h[idx] + t * v[idx]; }   void update(int node, int x) {     while (hull[node].size() > 1) {       int sz = hull[node].size();       int id1 = hull[node][sz - 1];       int id2 = hull[node][sz - 2];       long double t = inter(id1, id2);       if (v[id1] == v[x] or H(x, t) >= H(id1, t))         hull[node].pop_back();       else         break;     }     if (hull[node].size() == 1 and h[*hull[node].begin()] < h[x])       hull[node].pop_back();     hull[node].push_back(x);   }   void add(int node, int l, int r, int idx) {     if (idx < l or r <= idx) return;     update(node, idx);     if (r - l < 2) return;     int mid = (l + r) / 2;     add((node + node + 0), l, mid, idx);     add((node + node + 1), mid, r, idx);   }   pair<long double, int> find(int node, int t) {     int l = 0, r = hull[node].size();     for (; r - l > 1;) {       int mid = (l + r) / 2;       if (inter(hull[node][mid], hull[node][mid - 1]) <= t)         l = mid;       else         r = mid;     }     return make_pair(H(hull[node][l], t), hull[node][l]);   }   pair<long double, int> ans(int node, int l, int r, int s, int e, int t) {     if (e <= l or r <= s) return make_pair(-inf, n);     if (s <= l and r <= e) return find(node, t);     int mid = (l + r) / 2;     return max(ans((node + node + 0), l, mid, s, e, t),                ans((node + node + 1), mid, r, s, e, t));   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> q;     for (int i = 0; i < n; i++) {       cin >> h[i] >> v[i];       b[i].first.second = h[i];       b[i].first.first = v[i];       b[i].second = i;     }     h[n] = -1;     v[n] = 0;     sort(b, b + n);     for (int i = 0; i < n; i++) add(1, 0, n, b[i].second);     for (int l, r, t; q--;) {       cin >> l >> r >> t;       l--, r--;       cout << ans(1, 0, n, l, r + 1, t).second + 1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k, num;     cin >> n >> k;     num = (n) * (n - 1) / 2;     if (num <= k)       cout <<  no solution  << endl;     else       for (int i = 1; i <= n; i++) cout << 1 <<     << i << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000009;   const int MOD = 1000000007;   double probMayor(pair<int, int> x, int bid) {     if (bid < x.first) {       return 1.0;     }     if (bid > x.second) {       return 0.0;     }     return double(x.second - bid) / (x.second - x.first + 1);   }   double probMenor(pair<int, int> x, int bid) {     if (bid < x.first) {       return 0.0;     }     if (bid > x.second) {       return 1.0;     }     return double(bid - x.first) / (x.second - x.first + 1);   }   double go(vector<pair<int, int> > v, int idx, int bid, int cnt) {     if (idx >= v.size()) {       if (cnt <= 0) {         return 1;       }       return 0;     }     double res = 0.0;     if (bid >= v[idx].first && bid <= v[idx].second) {       res += go(v, idx + 1, bid, cnt - 1) *              (1.0 / (v[idx].second - v[idx].first + 1));     }     res += go(v, idx + 1, bid, cnt) * probMenor(v[idx], bid);     return res;   }   int main() {     int n;     cin >> n;     vector<pair<int, int> > v;     for (int i = 0; i < n; i++) {       int l, r;       cin >> l >> r;       v.push_back(make_pair(l, r));     }     double res = 0.0;     for (int i = 0; i < n; i++) {       pair<int, int> p = v[i];       v.erase(v.begin() + i);       for (int j = 1; j <= 10000; j++) {         res += probMayor(p, j) * j * go(v, 0, j, 1);       }       v.insert(v.begin() + i, p);     }     for (int j = 1; j <= 10000; j++) {       res += j * go(v, 0, j, 2);     }     printf( %.10f n , res);     return 0;   }