malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 20;   int a[MAXN];   int main() {     int k;     scanf( %d , &k);     for (int i = 1; i <= 12; i++) {       scanf( %d , &a[i]);     }     sort(a + 1, a + 13);     int tot = 0, ans = 0;     for (int i = 12; i >= 1; i--) {       if (tot >= k) {         break;       }       tot += a[i];       ans++;     }     if (tot < k) {       printf( -1 n );     } else {       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     switch (n) {       case 1:         cout << n * 2 << endl;         break;       case 2:         cout << n + 1 << endl;         break;       case 3:         cout << n - 2 << endl;         break;       case 4:         cout << n / 2 << endl;         break;       case 5:         cout << n / n << endl;         break;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 2e5;   int main() {     int n;     cin >> n;     int f = 0, z = 0;     for (int i = 0; i < n; i++) {       int val;       scanf( %d , &val);       if (val == 5)         f++;       else         z++;     }     int mx = 0;     for (int i = 0; i <= f; i++)       if ((5 * i) % 9 == 0) mx = i;     if (!z)       cout << -1;     else {       if (!mx)         cout << 0;       else {         for (int i = 0; i < mx; i++) cout << 5;         for (int i = 0; i < z; i++) cout << 0;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1 << 30;   long long m, r;   signed main() {     double ans = 0;     scanf( %d%d , &m, &r);     for (long long i = 1; i <= m; i++) {       double sum = 2 * r;       if (i - 1 != 0) {         sum += 2 * r + sqrt(2) * r;         if (i - 1 >= 2) {           sum += r * (i - 1) * (i - 2) + (i - 2) * 2 * sqrt(2) * r;         }       }       if (m - i != 0) {         sum += 2 * r + sqrt(2) * r;         if (m - i >= 2) {           sum += r * (m - i - 0) * (m - i - 1) + (m - i - 1) * 2 * sqrt(2) * r;         }       }       ans += sum;     }     printf( %.8f n , ans / (m * m));     return 0;   }
#include <bits/stdc++.h>   using i64 = long long;   int n;   std::vector<std::vector<int>> g;   std::vector<int> sz, d;   int dfs(int v, int p) {     return sz[v] =                std::accumulate(g[v].begin(), g[v].end(), 1, [=](int s, int c) {                  return s + (d[c] >= 0 || c == p ? 0 : dfs(c, v));                });   }   int centroid(int v, int p, int t) {     for (auto c : g[v]) {       if (d[c] >= 0 || c == p) continue;       if (2 * sz[c] > t) return centroid(c, v, t);     }     return v;   }   void rec(int v, int r) {     dfs(v, -1);     int c = centroid(v, -1, sz[v]);     d[c] = r;     for (auto e : g[c]) {       if (d[e] >= 0) continue;       rec(e, r + 1);     }   }   int main() {     scanf( %d , &n);     g.resize(n);     sz.resize(n);     d.resize(n, -1);     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d%d , &u, &v);       --u;       --v;       g[u].push_back(v);       g[v].push_back(u);     }     rec(0, 0);     for (char c : d) printf( %c  ,  A  + c);     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int read() {     int x = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while ( 0  <= c && c <=  9 ) {       x = x * 10 + c -  0 ;       c = getchar();     }     return x * f;   }   int n, m, cnt, h[200005], X[200005], Y[200005], dep[200005], du[200005], Tot,       col[200005], ans[200005];   struct Edge {     int to, next;   } a[200005 * 2];   inline void Add(int x, int y) {     cnt++;     a[cnt].to = y;     a[cnt].next = h[x];     h[x] = cnt;   }   void dfs(int x, int fa, int ban) {     dep[x] = dep[fa] + 1;     int now = 1;     if (ban == Tot)       for (int i = h[x]; i; i = a[i].next) {         int y = a[i].to;         if (y != fa) {           ans[y] = now;           dfs(y, x, now);           now = min(now + 1, Tot - 1);           if (!now) now = 1;         }       }     else       for (int i = h[x]; i; i = a[i].next) {         int y = a[i].to;         if (y != fa) {           if (now == ban) now++;           ans[y] = now;           dfs(y, x, now);           now = min(now + 1, Tot);         }       }   }   bool check(int lim) {     int sum = 0;     for (int i = 1; i <= n; ++i) sum += (du[i] > lim);     return sum <= m;   }   int main() {     n = read();     m = read();     for (int i = 1; i < n; ++i) {       int x = read(), y = read();       X[i] = x;       Y[i] = y;       Add(x, y);       Add(y, x);       du[x]++;       du[y]++;     }     int l = 1, r = n, mid;     while (l <= r) {       mid = l + r >> 1;       if (check(mid))         r = mid - 1, Tot = mid;       else         l = mid + 1;     }     dfs(1, 0, 0);     cout << Tot <<   n ;     for (int i = 1; i < n; ++i) {       if (dep[X[i]] > dep[Y[i]])         cout << ans[X[i]] <<    ;       else         cout << ans[Y[i]] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 123;   const int MINN = 1e3 + 123;   const int mod = 1e9 + 7;   const int INF = 1e9 + 1;   pair<int, int> a[MINN];   bool cmp(pair<int, int> a, pair<int, int> b) {     if (a.first < b.first) return 1;     if (a.first == b.first)       if (a.second > b.second) return 1;     return 0;   }   int main() {     int n, sum;     cin >> sum >> n;     for (int i = 1; i <= n; i++) scanf( %d%d , &a[i].first, &a[i].second);     sort(a + 1, a + n + 1, &cmp);     for (int i = 1; i <= n; i++) {       if (sum <= a[i].first) {         cout <<  NO ;         return 0;       }       sum += a[i].second;     }     cout <<  YES ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 100;   int m, n;   long long sweets[MAXN];   vector<long long> sol;   long long weightedSum;   long long sums[MAXN];   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> sweets[i];     }     sort(sweets, sweets + n);     for (int i = 0; i < n;) {       for (int j = 0; j < m && i + j < n; j++) {         sums[j] += sweets[i + j];         weightedSum += sums[j];         sol.push_back(weightedSum);       }       i += m;     }     for (int i = 0; i < sol.size(); i++) {       cout << sol[i] <<    ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct MP {     long long g[310][310];   } f[10], nil, tmp, c;   int n, m, x, y, z1, z2, ans;   void U(long long &x, long long y) { x = max(x, y); }   MP CC(MP &f1, MP &f2) {     MP res = nil;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) {         for (int k = 1; k <= n; k++) U(res.g[i][j], f1.g[i][k] + f2.g[k][j]);         U(res.g[i][j], min(f1.g[i][j], f2.g[i][j]));       }     return res;   }   bool pd(MP &t) {     for (int i = 1; i <= n; i++)       if (t.g[i][i] > 0) return 1;     return 0;   }   int main() {     scanf( %d%d , &n, &m);     memset(nil.g, -38, sizeof nil.g);     for (int i = 0; i < 10; i++) f[i] = nil;     for (; m--;) {       scanf( %d%d%d%d , &x, &y, &z1, &z2);       f[0].g[x][y] = z1;       f[0].g[y][x] = z2;     }     for (int i = 1; i < 10; i++) {       f[i] = CC(f[i - 1], f[i - 1]);       if (pd(f[i])) {         ans = 1 << i >> 1;         tmp = f[i - 1];         for (int j = i - 2; j >= 0; j--) {           c = CC(tmp, f[j]);           if (!pd(c)) {             tmp = c;             ans += 1 << j;           }         }         return 0 * printf( %d , ans + 1);       }     }     printf( 0 );   }
#include <bits/stdc++.h>   const long long oo = 2 * 1000 * 1000 * 1000;   const int _cnt = 1000 * 1000;   const int _p = 1000 * 1000 * 1000 + 7;   long long o(long long x) { return x % _p; }   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int lcm(int a, int b) { return a * b / gcd(a, b); }   using namespace std;   void file_put() {     freopen( filename.in ,  r , stdin);     freopen( filename.out ,  w , stdout);   }   struct squaretype {     int x, r;   };   string st;   int a[1000], n, m;   bool check(string st) {     for (int i = 0; i < st.length(); i++)       if (st[i] != st[0]) return false;     return true;   }   int main() {     scanf( %d%d , &n, &m);     cin.ignore();     for (int i = 1; i <= n; i++) {       getline(cin, st);       if (check(st)) {         a[i] = st[0];         continue;       }       printf( NO n );       return 0;     }     for (int i = 2; i <= n; i++)       if (a[i] == a[i - 1]) {         printf( NO n );         return 0;       }     printf( YES n );     return 0;   }
#include <bits/stdc++.h>   const int N = 1e6 + 6, mod = 1e9 + 7;   int n, sum[3];   inline int read() {     int s = 0, f = 1;     char ch;     for (; ch <  0  || ch >  9 ; ch = getchar())       if (ch ==  - ) f = -1;     for (; ch >=  0  && ch <=  9 ; ch = getchar())       s = (s << 1) + (s << 3) + ch -  0 ;     return s * f;   }   inline int add(int a, int b) { return (a += b) >= mod ? a - mod : a; }   inline int sub(int a, int b) { return (a -= b) < 0 ? a + mod : a; }   inline int mul(int a, int b) { return 1LL * a * b % mod; }   inline void Add(int &a, int b) { a = add(a, b); }   inline void Sub(int &a, int b) { a = sub(a, b); }   inline void Mul(int &a, int b) { a = mul(a, b); }   inline int quickpow(int a, int b) {     int re = 1;     while (b) {       if (b & 1) Mul(re, a);       b >>= 1;       Mul(a, a);     }     return re;   }   int fac[N + 1], inv[N + 1], f[N + 1];   inline void input() {     fac[0] = 1;     for (int i = 1; i <= N; ++i) fac[i] = mul(fac[i - 1], i);     inv[N] = quickpow(fac[N], mod - 2);     for (int i = N; i >= 1; --i) inv[i - 1] = mul(inv[i], i);     f[0] = f[1] = 1, f[2] = 2;     for (int i = 3; i <= N; ++i) f[i] = add(mul(f[i - 2], (i - 1)), f[i - 1]);   }   inline int C(int n, int m) {     if (n < m || n < 0 || m < 0) return 0;     return mul(fac[n], mul(inv[m], inv[n - m]));   }   int main() {     input();     for (int _ = 1; _; --_) {       n = read();       sum[1] = sum[2] = 0;       for (int i = 1; i <= n; ++i) ++sum[read()];       printf( %d n , mul(mul(fac[n], inv[sum[1]]), f[sum[1]]));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 200001;   long long par[N], siz[N];   long long f(long long n) {     if (n == par[n])       return n;     else       return par[n] = f(par[n]);   }   void u(long long a, long long b) {     a = f(a);     b = f(b);     if (a != b) {       if (siz[a] < siz[b]) swap(a, b);       par[b] = a;       siz[a] += siz[b];     }   }   void solve() {     long long n;     cin >> n;     string s[n + 1];     for (long long i = 1; i <= n; i++) {       cin >> s[i];       par[i] = i;       siz[i] = 1;     }     for (char c =  a ; c <=  z ; c++) {       vector<long long> v;       for (long long i = 1; i <= n; i++) {         for (long long j = 0; j < s[i].length(); j++) {           if (s[i][j] == c) v.push_back(i);         }       }       for (long long i = 1; i < v.size(); i++) u(v[i], v[i - 1]);     }     set<long long> se;     for (long long i = 1; i <= n; i++) {       long long x = f(i);       se.insert(x);     }     cout << se.size() <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void _print(long long t) { cerr << t; }   void _print(int t) { cerr << t; }   void _print(string t) { cerr << t; }   void _print(char t) { cerr << t; }   void _print(long double t) { cerr << t; }   void _print(double t) { cerr << t; }   void _print(unsigned long long t) { cerr << t; }   template <class T, class V>   void _print(pair<T, V> p);   template <class T>   void _print(vector<T> v);   template <class T>   void _print(set<T> v);   template <class T, class V>   void _print(map<T, V> v);   template <class T>   void _print(multiset<T> v);   template <class T, class V>   void _print(pair<T, V> p) {     cerr <<  { ;     _print(p.first);     cerr <<  , ;     _print(p.second);     cerr <<  } ;   }   template <class T>   void _print(vector<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T>   void _print(set<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T>   void _print(multiset<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T, class V>   void _print(map<T, V> v) {     cerr <<  [  ;     for (auto i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   int gcd(int a, int b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   bool isprime(long long a) {     if (a <= 1) return false;     if (a == 2 || a == 3) return true;     if (a % 2 == 0 || a % 3 == 0) return false;     for (int i = 5; i * i <= a; i += 6) {       if (a % i == 0 || a % (i + 2) == 0) return false;     }     return true;   }   void sieve(vector<bool> &isprimesieve) {     isprimesieve[0] = isprimesieve[1] = false;     for (int i = 2; i * i <= 1000000; i++) {       if (isprimesieve[i]) {         for (int j = i * i; j <= 1000000; j += i) {           isprimesieve[j] = false;         }       }     }   }   bool isperfectsq(long long a) { return (sqrt(a) - (int)sqrt(a) == 0); }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 0;     cin >> t;     while (t--) {       int n;       cin >> n;       string s;       cin >> s;       bool flag = false;       for (int i = 0; i < n; i++) {         if (s[i] ==  0 ) {           flag = true;           if (i >= n / 2) {             cout << 1 <<     << i + 1 <<     << 1 <<     << i <<   n ;             break;           } else {             cout << i + 1 <<     << n <<     << i + 2 <<     << n <<   n ;             break;           }         }       }       if (!flag) {         cout << 1 <<     << n - 1 <<     << 2 <<     << n <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   const double pi = acos(-1.0);   const long long INF = 0x3f3f3f3f3f3f3f3f;   const int inf = 0x3f3f3f3f;   const long long mod = 1e9 + 7;   const int N = 1e5 + 10;   struct zz {     long long x, y;   } a[N];   bool check(zz z1, zz z2, zz y1, zz y2) {     if ((z1.y - z2.y) * (y1.x - y2.x) == (z1.x - z2.x) * (y1.y - y2.y))       return true;     else       return false;   }   long long dis(zz z1, zz z2) {     return (z1.x - z2.x) * (z1.x - z2.x) + (z1.y - z2.y) * (z1.y - z2.y);   }   bool check(int n) {     while (n % 2 == 0) {       n /= 2;     }     if (n == 1)       return true;     else       return false;   }   void solve() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i].x >> a[i].y;     }     if (n & 1) {       cout <<  NO  << endl;       return;     }     int flag = 1;     for (int i = 0; i < n / 2; i++) {       if (!check(a[i], a[i + 1], a[i + n / 2], a[(i + n / 2 + 1) % n])) {         flag = 0;         break;       }     }     if (flag && n == 4) {       cout <<  YES  << endl;       return;     }     long long r = dis(a[1], a[0]);     for (int i = 0; i < n / 2; i++) {       if (dis(a[i], a[(i + 1) % n]) !=           dis(a[i + n / 2], a[(i + n / 2 + 1) % n])) {         flag = 0;         break;       }     }     if (flag)       cout <<  Yes  << endl;     else       cout <<  NO  << endl;   }   int main() {     ios::sync_with_stdio(false);     int t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   const int INF = 1 << 29;   int cmp(const void* a, const void* b);   long long maxv(long long a, long long b);   long long minv(long long a, long long b);   long long gcd(long long u, long long v);   int main() {     char s[] =  aeiou ;     long long k, n, m;     scanf( %lld , &k);     if (k <= 24) {       printf( -1 n );       return 0;     }     for (long long i = 5; i <= k; i++) {       if (k % i != 0) continue;       n = i;       m = k / i;       if (m < 5) {         printf( -1 n );         return 0;       }       break;     }     for (long long i = 0; i < (n); i++) {       for (long long j = 0; j < (m); j++) {         printf( %c , s[(i + j) % 5]);       }     }   }   int cmp(const void* a, const void* b) {     if (*(long long*)a - *(long long*)b < 0) return -1;     if (*(long long*)a - *(long long*)b > 0) return 1;     return 0;   }   long long maxv(long long a, long long b) {     if (a > b) return a;     return b;   }   long long minv(long long a, long long b) {     if (a < b) return a;     return b;   }   long long gcd(long long u, long long v) {     if (v == 0) return u;     return gcd(v, u % v);   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const double eps = 1e-9;   const int Mod = 1e9 + 7;   const int MaxN = 2e5 + 5;   char s[MaxN];   int a[MaxN];   int l[MaxN], r[MaxN];   bool cmp(int x, int y) { return x > y; }   int main() {     int n, k;     scanf( %d %d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     scanf( %s , s + 1);     int len = 0;     for (int i = 1; i <= n; i++) {       if (i == 1) {         l[++len] = 1;         continue;       }       if (s[i] == s[i - 1]) continue;       r[len] = i - 1;       l[++len] = i;     }     r[len] = n;     for (int i = 1; i <= len; i++) {       sort(a + l[i], a + r[i] + 1, cmp);     }     long long ans = 0LL, cnt = 1;     for (int i = 1; i <= n; i++) {       if (s[i] == s[i - 1])         cnt++;       else         cnt = 1;       if (cnt > k) continue;       ans += (long long)a[i];     }     printf( %lld n , ans);     return 0;   }
#include<bits/stdc++.h>   #define pb push_back   #define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)   #define ll long long   #define pii pair<int,int>   #define pll pair<ll,ll>   #define f first   #define s second   #define int long long   #define sz(x) (ll)(x.size())   using namespace std;         const int mod = 1e9+7;      int expo_pow(int x,int y){    if(y == 0) return 1;     y=y%(mod-1);     x%=mod;     if(y==0) y=mod-1;     int res=1;     while(y){       if(y&1) res=(res*x)%mod;       x=(x*x)%mod;       y>>=1;      }     return res;   }      ll add()   {       return 0;   }      template <typename T, typename... Types>   T add(T var1, Types... var2){       return (((((ll)(var1)) % mod + (ll)(add(var2...))) % mod) + mod) % mod;   }      ll mul(){       return 1;   }      template <typename T, typename... Types>   T mul(T var1, Types... var2){       return (((ll)(var1)) % mod * (ll)(mul(var2...))) % mod;   }      void solve(){     int n,x;     cin >> n >> x;     int mn = 0;     int sum = 0;     for (int i = 0; i < n; ++i) {       int tmp;       cin >> tmp;       sum += tmp;       mn += (tmp + x- 1)/x;     }        cout << (sum + x-1)/x <<     << mn <<   n ;   }         signed main(){     fast;     int test = 1;     cin>>test;     int i=1;     while(test--){       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int fastio() {     ios_base::sync_with_stdio(false);     cout << fixed << setprecision(10);     cin.tie(nullptr);     return 0;   }   int __fastio = fastio();   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cerr <<  { ;     for (auto i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   void solve() {     int n;     cin >> n;     map<int, pair<int, int>> line;     for (int i = 0; i < n; i++) {       int x, r;       cin >> x >> r;       line[x] = {r, i};     }     vector<int> res(n, -1);     int m;     cin >> m;     int x, y;     auto inCircle = [](int x, int y, int x2, int r) {       long long dx = x - x2, dy = y, r2 = 1LL * r * r;       return dx * dx + dy * dy <= r2;     };     for (int j = 1; j <= m; j++) {       cin >> x >> y;       auto it = line.lower_bound(x);       if (it != line.end()) {         auto [x1, k] = *it;         auto [r, idx] = k;         if (res[idx] == -1 && inCircle(x, y, x1, r)) res[idx] = j;       }       if (it != line.begin()) {         --it;         auto [x1, k] = *it;         auto [r, idx] = k;         if (res[idx] == -1 && inCircle(x, y, x1, r)) res[idx] = j;       }     }     int hit = n - count(res.begin(), res.end(), -1);     cout << hit <<   n ;     for (int i = 0; i < n; i++) cout << res[i] <<    n [i == n - 1];   }   int main() {     int t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   vector<int> vt;   int n;   inline bool judge(int i) {     int ans = i;     while (i) {       ans += i % 10;       i /= 10;     }     return ans == n;   }   int main(void) {     std::ios::sync_with_stdio(false);     cin.tie(0);     while (cin >> n) {       vt.clear();       for (int i = max(n - 81, 1); i <= n; ++i)         if (judge(i)) vt.push_back(i);       cout << vt.size() << endl;       for (auto it : vt) cout << it << endl;     }   }