malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:200000000 )   using namespace std;   template <typename T>   inline T Abs(T x) {     return (x >= 0) ? x : -x;   }   template <typename T>   inline T sqr(T x) {     return x * x;   }   template <typename T>   string toStr(T x) {     stringstream st;     st << x;     string s;     st >> s;     return s;   }   inline int nextInt() {     int x;     if (scanf( %d , &x) != 1) throw;     return x;   }   inline long long nextInt64() {     long long x;     if (scanf( %I64d , &x) != 1) throw;     return x;   }   inline double nextDouble() {     double x;     if (scanf( %lf , &x) != 1) throw;     return x;   }   const int INF = (int)1E9;   const long long INF64 = (long long)1E18;   const long double EPS = 1E-9;   const long double PI = 3.1415926535897932384626433832795;   const int MAXN = 100100;   unsigned long long d[MAXN], ans;   vector<int> g[MAXN];   int n;   unsigned long long DFS(int v, int prev) {     if (prev != -1) g[v].erase(find((g[v]).begin(), (g[v]).end(), prev));     d[v] = 0;     long long sum2 = 0;     for (int i = 0; i < (int)(g[v].size()); i++) {       unsigned long long cur = DFS(g[v][i], v);       sum2 += 1LL * d[v] * cur;       d[v] += cur;     }     d[v]++;     ans -= sqr(sum2);     ans -= 2LL * sum2 * ((n - d[v] + 1) * d[v] - 1);     ans -= 2LL * (d[v] - 1) * ((n - d[v] + 1) * d[v] - 1) - sqr(d[v] - 1);     return d[v];   }   int main() {     n = nextInt();     for (int i = 0; i < (int)(n - 1); i++) {       int v = nextInt() - 1;       int u = nextInt() - 1;       g[v].push_back(u);       g[u].push_back(v);     }     ans = sqr(1LL * n * (n - 1) / 2);     DFS(0, -1);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, count = 0;     string s;     cin >> n >> s;     for (int i = 0; i < n; i++) {       if (s[i] ==  8 ) count++;     }     if (n < 11)       cout <<  0  << endl;     else {       cout << min(count, n / 11) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   int a[maxn], n, x, k, l;   long long ans = 0;   int main() {     cin >> n >> x;     for (int i = 1; i <= n; i++) {       cin >> k >> l;       ans += min(k, l);       a[i] = min(max(l - k, 0), k);     }     sort(a + 1, a + 1 + n);     for (int i = 1; i <= x; i++) ans += a[n - i + 1];     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 500005, M = 60;   int q, fa[N], n = 1;   double dp[N][M + 5];   int main() {     ios::sync_with_stdio(false);     cin >> q;     int opt, pos;     for (int i = 0; i <= M; i++) dp[1][i] = 1;     for (int _ = 1; _ <= q; _++) {       cin >> opt >> pos;       if (opt == 1) {         fa[++n] = pos;         for (int i = 0; i <= M; i++) dp[n][i] = 1;         double pre = 1;         int pp = n;         for (int i = 0, cur = pos; cur && i <= M; i++, cur = fa[cur]) {           double tmp = dp[cur][i];           dp[cur][i] /= 0.5 * (pre + 1);           if (i)             dp[cur][i] *= 0.5 * (1 + dp[pp][i - 1]);           else             dp[cur][i] *= 0.5;           pp = cur;           pre = tmp;         }       } else {         double ans = 0;         for (int i = 1; i <= M; i++) ans += (dp[pos][i] - dp[pos][i - 1]) * i;         printf( %.10lf n , ans);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > all;   int isable[100005], cnt[100005];   int main() {     int i, n, k;     scanf( %d , &n);     scanf( %d , &k);     long long b;     scanf( %I64d , &b);     for (i = 0; i < n; i++) {       int x;       scanf( %d , &x);       cnt[i] = x;       if (i != n - 1) all.push_back(make_pair(x, i));     }     sort(all.begin(), all.end());     i = all.size() - 1;     long long sm = 0;     int choto;     while (k) {       sm += all[i].first;       choto = all[i].first;       isable[all[i].second] = 1;       k--;       i--;     }     for (i = 0; i < n - 1; i++) {       long long temp = sm;       if (!isable[i]) {         temp -= choto;         temp += cnt[i];       }       if (temp > b) break;     }     printf( %d n , i + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string a;     string b;     cin >> a >> b;     long long int len1 = a.length();     long long int len2 = b.length();     if (a.compare(b) == 0) {       cout <<  -1 n ;     } else {       if (len1 > len2)         cout << len1 <<   n ;       else         cout << len2 <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 10;   const double eps = 1e-6;   int n, m;   int sum, res;   int f[21][1 << 21], col[MAX];   char s[MAX];   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       scanf( %s , s);       for (int j = 0; j < m; j++)         if (s[j] ==  1 ) col[j] |= (s[j] ==  1 ) << i;     }     for (int i = 0; i < m; i++) f[0][col[i]]++;     for (int i = 1; i <= n; i++) {       for (int j = 0; j < 1 << n; j++) {         sum = i < 2 ? 0 : (i - 2 - n) * f[i - 2][j];         for (int k = 0; k < n; k++) sum += f[i - 1][j ^ (1 << k)];         f[i][j] = sum / i;       }     }     res = n * m;     for (int i = 0; i < 1 << n; i++) {       sum = 0;       for (int j = 0; j <= n; j++) sum += (j < n - j ? j : n - j) * f[j][i];       res = res < sum ? res : sum;     }     printf( %d , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = int;   namespace SEG {   static const ll STAR = 1, FINI = 2e5 + 110;   struct NODE {     ll l, r, min;     NODE() : l(0), r(0), min(0) {}   } node[1000000 * 10 + 110];   ll newnode(ll pre = 0) {     static ll cnt = 0;     node[++cnt] = node[pre];     return cnt;   }   ll& lson(ll now) { return node[now].l; }   ll& rson(ll now) { return node[now].r; }   ll ins(ll pre, ll val, ll pos, ll star = STAR, ll fini = FINI) {     ll now = newnode(pre);     if (star < fini) {       if (val <= ((star + fini) / 2))         lson(now) = ins(lson(pre), val, pos, star, ((star + fini) / 2));       else         rson(now) = ins(rson(pre), val, pos, ((star + fini) / 2) + 1, fini);       node[now].min = min(node[lson(now)].min, node[rson(now)].min);     } else {       node[now].min = pos;     }     return now;   }   ll ask(ll now, ll limit, ll star = STAR, ll fini = FINI) {     if (star == fini) return star;     if (node[lson(now)].min < limit)       return ask(lson(now), limit, star, ((star + fini) / 2));     else       return ask(rson(now), limit, ((star + fini) / 2) + 1, fini);   }   void debug(ll now, ll star = STAR, ll fini = FINI) {     if (star > fini or now == 0) return;     if (star == fini) {       if (star == STAR) cout <<  SEG::debug::  << endl;       if (node[now].min != INT64_MAX)         cout << star <<     << node[now].min << endl;       if (star == FINI) cout << endl;       return;     }     debug(lson(now), star, ((star + fini) / 2));     debug(rson(now), ((star + fini) / 2) + 1, fini);   }   }  // namespace SEG   vector<ll> pos[100000 + 110];   ll date[100000 + 110];   static ll T[100000 + 110];   bool check(ll val) {     for (ll i = 1; i < pos[val].size(); i++)       if (pos[val][i - 1] < pos[val][i] - 1) {         if (SEG::ask(T[pos[val][i] - 1], pos[val][i - 1] + 1) == val) {           return 1;         }       }     return 0;   }   int main() {     ll n;     cin >> n;     for (ll i = 1; i <= n + 10; i++) pos[i].push_back(0);     for (ll i = 1; i <= n; i++) {       cin >> date[i];       pos[date[i]].push_back(i);       T[i] = SEG::ins(T[i - 1], date[i], i);     }     for (ll i = 1; i <= n + 10; i++) pos[i].push_back(n + 1);     for (ll i = 1; i <= n + 10; i++)       if (check(i) == 0) {         cout << i <<   n ;         return 0;       }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 250005;   int qr[maxn], qp[maxn], wm[maxn], loc[maxn];   int pp[maxn], pr[maxn], pm[maxn];   long long pd[maxn];   stack<int> f[maxn];   bool used[maxn];   int n, nx, ny, totm;   long long dist(int x, int y) { return (long long)x * x + (long long)y * y; };   bool cmp(int a, int b) { return pd[a] > pd[b]; };   int main() {     int i, x, y, h, t;     long long d;     scanf( %d%d%d%d%d , &nx, &ny, qp + 1, qr + 1, &n);     for (i = 1; i <= n; ++i) {       scanf( %d%d%d%d%d , &x, &y, pm + i, pp + i, pr + i);       pd[i] = dist(x - nx, y - ny);       wm[i - 1] = pm[i];       loc[i] = i;     }     sort(wm, wm + n);     totm = unique(wm, wm + n) - wm;     for (i = 1; i <= n; ++i) pm[i] = lower_bound(wm, wm + totm, pm[i]) - wm + 1;     sort(loc + 1, loc + n + 1, cmp);     for (i = 1; i <= n; ++i)       for (x = pm[loc[i]]; x <= totm; x += x & -x) f[x].push(loc[i]);     for (h = 1, t = 1; h <= t; ++h) {       x = upper_bound(wm, wm + totm, qp[h]) - wm;       d = (long long)qr[h] * qr[h];       for (; x > 0; x -= x & -x)         while (!f[x].empty() && pd[f[x].top()] <= d) {           y = f[x].top();           f[x].pop();           if (!used[y]) {             used[y] = true;             ++t;             qp[t] = pp[y];             qr[t] = pr[y];           }         }     }     printf( %d n , t - 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k, d[2][100005], q1[100005], q2[100005], x, y, st, en;   char s[2][100005];   int main() {     cin >> n >> k;     cin >> s[0];     cin >> s[1];     d[0][0] = 1;     for (en = 1; st < en;) {       x = q1[st];       y = q2[st++];       if (y >= n - k) {         cout <<  YES ;         return 0;       }       if (s[x][y - 1] ==  -  && d[x][y - 1] == 0 && y > 0 && y > d[x][y]) {         d[x][y - 1] = d[x][y] + 1;         q1[en] = x;         q2[en++] = y - 1;       }       if (s[x][y + 1] ==  -  && d[x][y + 1] == 0) {         d[x][y + 1] = d[x][y] + 1;         q1[en] = x;         q2[en++] = y + 1;       }       if (s[1 - x][y + k] ==  -  && d[1 - x][y + k] == 0) {         d[1 - x][y + k] = d[x][y] + 1;         q1[en] = 1 - x;         q2[en++] = y + k;       }     }     cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a[20];     a[0] = 2;     a[1] = 3;     a[2] = 5;     a[3] = 7;     a[4] = 11;     a[5] = 13;     a[6] = 17;     a[7] = 19;     a[8] = 23;     a[9] = 29;     a[10] = 31;     a[11] = 37;     a[12] = 41;     a[13] = 43;     a[14] = 47;     a[15] = 4;     a[16] = 9;     a[17] = 25;     a[18] = 49;     char s[10];     long int i, flag = 0;     for (i = 0; i <= 18; i++) {       printf( %ld n , a[i]);       fflush(stdout);       scanf( %s , s);       if (s[0] ==  y ) {         flag++;       }       if (flag == 2) {         printf( composite n );         fflush(stdout);         break;       }     }     if (flag < 2) printf( prime n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 5 * 100000;   vector<int> g[MAXN + 1], e[MAXN + 1];   int col[MAXN + 1], cur = 1, used[MAXN + 1];   void dfs(int v, int p) {     int num = 1;     vector<int> del;     for (auto x : g[v]) {       del.push_back(col[x]);       used[col[x]] = 1;     }     for (auto x : g[v]) {       if (col[x]) continue;       while (used[num]) num++;       used[num] = 1;       del.push_back(num);       col[x] = num;     }     for (auto x : del) used[x] = 0;     for (auto x : e[v]) {       if (x == p) continue;       dfs(x, v);     }   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     int pos = 0;     for (int i = 1; i <= n; i++) {       int sz;       scanf( %d , &sz);       for (int j = 0; j < sz; j++) {         int x;         scanf( %d , &x);         g[i].push_back(x);       }       if (g[i].size() > g[pos].size()) pos = i;       sort(g[i].begin(), g[i].end());     }     for (int i = 0; i < n - 1; i++) {       int a, b;       scanf( %d%d , &a, &b);       e[a].push_back(b);       e[b].push_back(a);     }     for (auto x : g[pos]) col[x] = cur++, used[cur] = 1;     dfs(pos, -1);     cout << max(1, *max_element(col + 1, col + 1 + m)) <<   n ;     for (int i = 1; i <= m; i++) {       if (!col[i]) col[i] = 1;       printf( %d  , col[i]);     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Person {     int a;     int id;   };   bool operator<(Person a, Person b) { return a.a < b.a; }   class TSolver {    public:     int n;     vector<Person> persons;     explicit TSolver(std::istream& in) {       in >> n;       persons.resize(n);       for (int i = 0; i < n; ++i) {         in >> persons[i].a;         persons[i].id = i;       }     }     bool ok = true;     vector<int> ans;     void Solve() {       sort((persons).begin(), (persons).end());       ans.resize(n);       int color = 1;       for (int i = 0; ok && i < n;) {         int same = n - persons[i].a;         ok = ok && i + same <= n;         for (int j = 0; ok && j < same; ++j) {           if (persons[i + j].a != persons[i].a) {             ok = false;           }           ans[persons[i + j].id] = color;         }         i += same;         ++color;       }     }     void PrintAnswer(std::ostream& out) const {       if (ok) {         out <<  Possible n ;         for (int i = 0; i < n; ++i) {           out << ans[i] <<    n [i + 1 == n];         }       } else {         out <<  Impossible n ;       }     }   };   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(nullptr);     std::cout.tie(nullptr);     {       auto solver = std::make_shared<TSolver>(std::cin);       solver->Solve();       solver->PrintAnswer(std::cout);     }     do {     } while (false);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long binpow(long long a, long long b) {     long long exp = 10e9;     long long res = 1;     while (b > 0) {       if (b & 1) res = ((res % exp) * (a % exp)) % exp;       a = ((a % exp) * (a % exp)) % exp;       b >>= 1;     }     return res;   }   bool isprime(int x) {     for (int d = 2; d * d <= x; d++) {       if (x % d == 0) return false;     }     return true;   }   unsigned int cntsb(unsigned int n) {     unsigned int count = 0;     while (n) {       count += n & 1;       n >>= 1;     }     return count;   }   void solve(int cas) {}   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int number = 0;     long long n;     cin >> n;     int last = n % 10;     if (last <= 5)       n -= last;     else       n += (10 - last);     cout << n;   }
#include <bits/stdc++.h>    using namespace std;       #define vec vector    #define PB push_back       #define MP make_pair    #define MT make_tuple    #define F first    #define S second       using ll = long long int; // watch out for overflows in your code   using pii = pair<int,int>;   //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());      void debug() { cout <<   n ; };   template <typename T, typename... Targs>    void debug(T t, Targs... args) {       cout << t <<    ;       debug(args...);   }      template <typename T1, typename T2>    inline ostream& operator << (ostream& os, const pair<T1,T2>& p) {       return os <<  (  << p.F <<  ,   << p.S <<  ) ;   }      template <typename T>    inline ostream& operator << (ostream& os, const vec<T>& v) {       for(auto& t : v) {           os << t <<    ;       }       return os;   }      template <typename T>    inline ostream& operator << (ostream& os, const vec<vec<T>>& m) {       for(auto& v : m) {           for(auto& t : v) {               os << t <<    ;           }           os <<   n ;       }       return os;   }      template <typename T>    inline ostream& operator << (ostream& os, const set<T>& v) {       for(auto& t : v) {           os << t <<    ;       }       return os;   }      template <typename K, typename V>    inline ostream& operator << (ostream& os, const map<K,V>& m) {       for(auto& p : m) {           os << p.F <<   ->   << p.S <<   n ;       }       return os;   }      const int INF = 2 * 1e9;   int T, N, M;   vec<int> A, B;      int increment(int& i, const vec<int>& v) {       int S = v.size();       if(i >= S) {           return -INF;       }       int P = v[i++];       while(i < S && P < 0) {           P += v[i];           i++;       }       while(i < S && P <= P + v[i]) {           P = P + v[i];           ++i;       }       return P;   }      int compute() {       int j = 0, i = 0;       int pa, pb;       int S = 0;       int ans = 0;          pa = increment(i, A);       pb = increment(j, B);          while(i <= N || j <= M) {           //debug( pa , pa,  pb , pb);           if(pa < 0 && pb < 0) {               break;           }           if(pa >= pb) {               S += pa;               pa = increment(i, A);           }           else {               S += pb;               pb = increment(j, B);           }           ans = max(ans, S);       }       return ans;   }      ////////////////////////////////////////////////////////////////////////      int main() {       ios::sync_with_stdio(0);       cin.tie(0);          cin >> T;       while(T--) {           cin >> N;           A.assign(N, 0);           for(int i = 0; i < N; ++i) {               cin >> A[i];           }           cin >> M;           B.assign(M, 0);           for(int j = 0; j < M; ++j) {               cin >> B[j];           }           cout << compute() <<   n ;       }      }
#include <bits/stdc++.h>   using namespace std;   const int N = 100;   const int M = 2e6 + 7;   const int inf = 1e9;   int n, m, mx, p[N], minn[N], D[M][2], sum = 0;   int a[N][N];   bool check() {     for (int t = 0, tE = (1 << mx) - 1; t <= tE; t++) {       int ds = 0, bs = 0;       for (int i = 1, iE = mx; i <= iE; i++)         if (t & (1 << (i - 1))) ds += p[i];       if (!ds) continue;       for (int i = 1, iE = mx; i <= iE; i++)         if (t & (1 << (i - 1)))           for (int j = 1, jE = mx; j <= jE; j++)             if (t & (1 << (j - 1))) bs += a[i][j];       if (bs >= ds) return 0;     }     return 1;   }   int Cnt(int x) { return x == 0 ? 0 : Cnt(x / 10) + 1; }   char sa[N], sb[N];   bool get() {     for (int x = 1, xE = mx; x <= xE; x++)       for (int i = 1, iE = mx; i <= iE; i++)         if (a[x][i]) {           a[x][i]--, p[x]--;           if (check()) return printf( %d %d n , minn[x] + p[x], minn[i]), 1;           a[x][i]++, p[x]++;           a[x][i]--, p[i]--;           if (check()) return printf( %d %d n , minn[x], minn[i] + p[i]), 1;           a[x][i]++, p[i]++;         }     return 0;   }   int main() {     scanf( %d , &n), mx = Cnt(n);     for (int i = 1, iE = n; i <= iE; i++) p[Cnt(i)]++;     minn[1] = 1;     for (int i = 2, iE = mx; i <= iE; i++) minn[i] = minn[i - 1] * 10;     for (int i = 1, iE = n - 1; i <= iE; i++)       scanf( %s%s , sa, sb), D[i][0] = strlen(sa), D[i][1] = strlen(sb),                              a[D[i][0]][D[i][1]]++;     if (!check()) return puts( -1 ), 0;     while (get()) sum++;     for (int x = 1, xE = mx; x <= xE; x++)       for (int i = 1, iE = mx; i <= iE; i++)         if (a[x][i])           printf( %d %d n , minn[x] + p[x] - 1, minn[i] + p[i] - 1), sum++;     if (sum != n - 1) assert(0);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, k, l, n, m, A[11] = {0}, count = 0, B[2000], sum1, sum2, last,                           flag = 0;     char ch;     for (i = 1; i <= 10; i++) {       scanf( %c , &ch);       if (ch ==  1 )         A[i] = 1;       else         A[i] = 0;     }     scanf( %d , &m);     for (k = 1; k <= 10; k++) {       if (A[k] == 1) {         flag = 0;         sum1 = k;         sum2 = 0;         last = k;         B[0] = k;         i = 1;         while (i < m) {           for (j = 1; j <= 10; j++) {             if (A[j] == 1) {               if (sum2 + j > sum1 && last != j) {                 sum2 += j;                 last = j;                 B[i++] = j;                 break;               }             }           }           if (j == 11) {             flag = 1;             break;           }           if (i == m) break;           for (j = 1; j <= 10; j++) {             if (A[j] == 1) {               if (sum1 + j > sum2 && last != j) {                 sum1 += j;                 last = j;                 B[i++] = j;                 break;               }             }           }           if (j == 11) {             flag = 1;             break;           }         }       }       if (i == m) break;     }     if (k == 11)       printf( NO n );     else if (i == m) {       printf( YES n );       for (i = 0; i < m; i++) {         if (i != m - 1)           printf( %d  , B[i]);         else           printf( %d n , B[i]);       }     }     return 0;   }
#include<bits/stdc++.h>   using namespace std;   typedef long long ll;      void solve()   {       int x,y;       cin>>x>>y;       string s;       cin>>s;       int cR=0,cU=0,cL=0,cD=0;       for(int i=0;i<s.size();i++)       {           if(s[i]== R )               cR++;           else if(s[i]== U )               cU++;           else if(s[i]== L )               cL++;           else               cD++;       }       //cout<<cR<<   <<cL<<   <<cU<<   <<cD<<  n ;       if(x>0&&y>0)       {           if(cR>=x&&cU>=y)               cout<< YES n ;           else               cout<< NO n ;       }       else if(x>0&&y<0)       {           if(cR>=x&&cD>=abs(y))               cout<< YES n ;           else               cout<< NO n ;       }       else if(x<0&&y>0)       {           if(cL>=abs(x)&&cU>=y)               cout<< YES n ;           else               cout<< NO n ;       }       else if(x<0&&y<0)       {           if(cL>=abs(x)&&cD>=abs(y))               cout<< YES n ;           else               cout<< NO n ;       }       else       {           if(x>0&&y==0)           {               if(cR>=x)                   cout<< YES n ;               else                   cout<< NO n ;           }           else if(x<0&&y==0)           {               if(cL>=abs(x))                   cout<< YES n ;               else                   cout<< NO n ;           }           else if(x==0&&y>0)           {               if(cU>=y)                   cout<< YES n ;               else                   cout<< NO n ;           }           else if(x==0&&y<0)           {               if(cD>=abs(y))                   cout<< YES n ;               else                   cout<< NO n ;           }           else               cout<< NO n ;       }   }   int main()   {      int t;      ios::sync_with_stdio(false);      cin>>t;      cin.tie(0);      cout.tie(0);      while(t--)       solve();      return 0;   }