malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     long long arr[4];     for (int i = 0; i < 4; i++) cin >> arr[i];     sort(arr, arr + 4);     long long w, x, y, z;     w = arr[0];     x = arr[1];     y = arr[2];     long long a, b, c, d;     b = (w - x + y) / 2;     a = w - b;     c = x - a;     cout << a <<     << b <<     << c;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n % 2 == 0) {       cout << n / 2 << endl;       for (int i = 0; i < n / 2; i++) cout <<  2  ;       return 0;     } else {       cout << (n / 2) << endl;       for (int i = 0; i < (n / 2) - 1; i++) cout <<  2  ;       cout <<  3 ;       return 0;     }   }
#include <bits/stdc++.h>   using namespace std;   int a[10000];   int n, m, mn, mn1;   multiset<int> s;   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> a[i];       s.insert(a[i]);     }     int q = *s.rbegin() + m;     while (m--) {       int t = *s.begin();       s.erase(s.begin());       s.insert(t + 1);     }     cout << *s.rbegin() <<     << q;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int div_floor(const long long int &a, const long long int &b) {     return a / b - (((a ^ b) < 0) and a % b);   }   long long int div_ceil(const long long int &a, const long long int &b) {     return a / b + (((a ^ b) >= 0) and a % b);   }   long long int modpow(long long int a, long long int b,                        long long int m = 998244353) {     a %= m;     long long int res = 1;     while (b) {       if (b & 1) res = (res * a) % m;       a = (a * a) % m;       b >>= 1;     }     return res;   }   long long int modinv(long long int a, long long int m = 998244353) {     return modpow(a, m - 2, m);   }   vector<long long int> f;   vector<long long int> invf;   const int MAXVAL = 2e5 + 7;   void init() {     f.resize(MAXVAL, 1);     invf.resize(MAXVAL, 1);     for (int i = 1; i < MAXVAL; i++) f[i] = (f[i - 1] * i) % 998244353;     for (int i = 1; i < MAXVAL; i++) invf[i] = modinv(f[i]);   }   long long int ncr(long long int n, long long int r) {     if (r > n) return 0;     return invf[n - r] * (f[n] * invf[r] % 998244353) % 998244353;   }   void solve() {     int n, k;     cin >> n >> k;     vector<int> a(n);     for (auto &e : a) cin >> e;     int x = -1, cnt = 0;     for (auto &e : a)       if (e != x) x = e, cnt++;     if (a.back() == a[0]) cnt = max(1, cnt - 1);     if (k == 1 || cnt == 1) {       cout << 0 <<   n ;       return;     }     long long int ans = 0;     for (long long int i = 0; i < cnt; i++) {       long long int add = (modpow(k - 2, i) * ncr(cnt, i)) % 998244353;       long long int rem = cnt - i;       if (rem % 2)         add = (add * modpow(2, rem - 1)) % 998244353;       else         add = (add * (modpow(2, rem) - ncr(rem, rem / 2))) % 998244353,         add = (add + 998244353) % 998244353, add = (add * modinv(2)) % 998244353;       ans += add;     }     ans %= 998244353;     ans = (ans * modpow(k, n - cnt)) % 998244353;     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     init();     int t = 1;     while (t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long n;     cin >> n;     long long ar[n + 1];     for (long long i = 0; i < n; i++) {       cin >> ar[i];     }     ar[n] = n + 1;     long long ans = 0;     for (long long i = 0; i < n; i++) {       long long x = ar[i];       long long y = ar[i + 1];       if (x > y) {         ans += (x - y) * (n - x + 1);       }       if (x < y) {         ans += x * (y - x);       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     multiset<long long> v;     vector<pair<string, long long>> ans;     for (int i = 0; i < n; ++i) {       string s;       cin >> s;       if (s ==  insert ) {         long long x;         cin >> x;         ans.push_back({ insert , x});         v.insert(x);       }       if (s ==  removeMin ) {         if (v.size() == 0) {           ans.push_back({ insert , 1});           v.insert(1);         }         ans.push_back({ removeMin , 0});         v.erase(v.begin());       }       if (s ==  getMin ) {         long long x;         cin >> x;         if (v.find(x) == v.end()) {           ans.push_back({ insert , x});           v.insert(x);         }         while (*(v.begin()) != x) {           ans.push_back({ removeMin , 0});           v.erase(v.begin());         }         ans.push_back({ getMin , x});       }     }     cout << ans.size() <<   n ;     for (auto i : ans) {       cout << i.first <<    ;       if (i.first !=  removeMin ) {         cout << i.second;       }       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   using INT = long long;   const int NN = 111;   string tar;   string s[NN];   int n;   void dfs(int len) {     if (!len) {       for (int i = 1; i <= n; i++) {         for (int j = 0; j < s[i].length(); j++) {           int f = 1;           for (int k = j; k < s[i].length(); k++) {             if (k - j == tar.length()) {               puts( YES );               exit(0);             }             if (tar[k - j] != s[i][k]) {               f = 0;               break;             }           }           if (f) dfs(s[i].length() - j);         }       }       return;     }     for (int i = 1; i <= n; i++) {       int j = 0;       for (; j < s[i].length(); j++) {         if (tar[len + j] != s[i][j]) break;       }       if (len + j == tar.length()) {         puts( YES );         exit(0);       }       if (j == s[i].length()) dfs(len + j);     }   }   int main() {     cin >> tar;     cin >> n;     for (int i = 1; i <= n; i++) cin >> s[i];     dfs(0);     puts( NO );   }
#include <bits/stdc++.h>   const long long N = 2e5 + 7;   const long long M = 2e4 + 5;   const double eps = 1e-8;   const long long mod = 1e9 + 7;   const long long inf = 0x7fffffff;   const double pi = 3.1415926;   using namespace std;   vector<long long> v[N], num;   long long n;   long long dfs(long long x, long long fa) {     long long sum = 1;     for (long long i = 0; i < v[x].size(); i++) {       if (v[x][i] == fa) continue;       sum += dfs(v[x][i], x);     }     if (x != 1) num.push_back((n - sum) * sum);     return sum;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long t;     cin >> t;     while (t--) {       cin >> n;       for (long long i = 0; i <= n; i++) v[i].clear();       num.clear();       for (long long i = 1; i < n; i++) {         long long x, y;         cin >> x >> y;         v[x].push_back(y);         v[y].push_back(x);       }       long long m;       cin >> m;       vector<long long> p;       for (long long i = 0; i < m; i++) {         long long c;         cin >> c;         p.push_back(c);       }       dfs(1, -1);       if (m < n - 1) {         for (long long i = 0; i < n - 1 - m; i++) p.push_back(1);       }       sort(num.begin(), num.end());       sort(p.begin(), p.end());       long long ans = 0;       if (m <= n - 1) {         for (long long i = 0; i < n - 1; i++) {           ans += (num[i] * p[i]) % mod;           ans %= mod;         }       } else {         for (long long i = 0; i < n - 2; i++) {           ans += (num[i] * p[i]) % mod;           ans %= mod;         }         long long add = 1;         for (long long i = n - 2; i < m; i++) {           add = (add * p[i]) % mod;         }         ans += (add * num[n - 2]) % mod;         ans %= mod;       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long nums[100005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     long long potL = 1000000000;     long long total = 0;     for (int i = 0; i < n; i++) {       long long num;       cin >> num;       if (num % 2 == 1 && num < potL) potL = num;       total += num;       nums[i] = num;     }     if (total % 2 == 1) total -= potL;     cout << total << endl;     return 0;   }
#include <bits/stdc++.h>   const int N = 1e4 + 5;   int ans, n;   double f[2][N];   signed main() {     scanf( %d%lf , &n, &f[1][1]);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= i; j++) {         if (f[i & 1][j] >= 1.0) {           f[i & 1 ^ 1][j] += (f[i & 1][j] - 1.0) / 2.0;           f[i & 1 ^ 1][j + 1] += (f[i & 1][j] - 1.0) / 2.0;           ans++;         }         f[i & 1][j] = 0;       }     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int i, n, x[110], y[110], f[110], j, ans;   bool b[110];   int find(int x) {     if (f[x] == x)       return x;     else       return f[x] = find(f[x]);   }   void Union(int x, int y) { f[find(x)] = find(y); }   int main() {     scanf( %d , &n);     for (i = 1; i <= n; i++) f[i] = i;     for (i = 1; i <= n; i++) {       scanf( %d%d , &x[i], &y[i]);     }     for (i = 1; i <= n; i++)       for (j = 1; j <= n; j++)         if (find(i) != find(j))           if (x[i] == x[j] || y[i] == y[j]) Union(i, j);     memset(b, 0, sizeof(b));     for (i = 1; i <= n; i++)       if (!b[find(i)]) b[find(i)] = 1, ans++;     printf( %d n , ans - 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxN = 2e5 + 7;   int N, M, head[maxN], cnt;   struct Eddge {     int nex, to, id;     Eddge(int a = -1, int b = 0, int c = 0) : nex(a), to(b), id(c) {}   } edge[maxN << 1];   inline void addEddge(int u, int v, int id) {     edge[cnt] = Eddge(head[u], v, id);     head[u] = cnt++;   }   inline void _add(int u, int v, int id) {     addEddge(u, v, id);     addEddge(v, u, id);   }   inline void init() {     cnt = 0;     for (int i = 1; i <= N; i++) head[i] = -1;   }   struct node {     int u, v, op;     node(int a = 0, int b = 0, int c = -1) : u(a), v(b), op(c) {}   } t[maxN];   struct Point {     int id, op;     Point(int a = 0, int b = 0) : id(a), op(b) {}   };   queue<Point> Q;   bool bfs() {     t[1].op = 1;     Q.push(Point(t[1].u, 1));     while (!Q.empty()) {       Point now = Q.front();       Q.pop();       int u = now.id;       for (int i = head[u], v, id; ~i; i = edge[i].nex) {         id = edge[i].id;         if (~t[id].op) {           if (t[id].u == u) {             if (t[id].op == 0 && now.op == 1) return false;             if (t[id].op == 1 && now.op == -1) return false;           } else {             if (t[id].op == 0 && now.op == -1) return false;             if (t[id].op == 1 && now.op == 1) return false;           }           continue;         }         v = edge[i].to;         if (now.op == 1) {           Q.push(Point(v, -1));           if (t[id].u == u)             t[id].op = 1;           else             t[id].op = 0;         } else {           Q.push(Point(v, 1));           if (t[id].u == u)             t[id].op = 0;           else             t[id].op = 1;         }       }     }     Q.push(Point(t[1].v, -1));     while (!Q.empty()) {       Point now = Q.front();       Q.pop();       int u = now.id;       for (int i = head[u], v, id; ~i; i = edge[i].nex) {         id = edge[i].id;         if (~t[id].op) {           if (t[id].u == u) {             if (t[id].op == 0 && now.op == 1) return false;             if (t[id].op == 1 && now.op == -1) return false;           } else {             if (t[id].op == 0 && now.op == -1) return false;             if (t[id].op == 1 && now.op == 1) return false;           }           continue;         }         v = edge[i].to;         if (now.op == 1) {           Q.push(Point(v, -1));           if (t[id].u == u)             t[id].op = 1;           else             t[id].op = 0;         } else {           Q.push(Point(v, 1));           if (t[id].u == u)             t[id].op = 0;           else             t[id].op = 1;         }       }     }     return true;   }   int main() {     scanf( %d%d , &N, &M);     init();     for (int i = 1, u, v; i <= M; i++) {       scanf( %d%d , &u, &v);       t[i] = node(u, v, -1);       _add(u, v, i);     }     if (bfs()) {       printf( YES n );       for (int i = 1; i <= M; i++) printf( %d , t[i].op);       printf(  n );     } else       printf( NO n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   map<string, int> mid, pid;   std::vector<string> hostname;   vector<int> a[100000];   char s[1000];   int m_total = 0, p_total = 0;   int b[100000];   std::vector<std::vector<int> > ans;   bool cmp(int i, int j) { return a[i] < a[j]; }   int main(int argc, char const *argv[]) {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %s , s);       int j = 7;       for (; s[j]; ++j)         if (s[j] ==  / ) break;       string host =   , path =   ;       for (int k = 0; k < j; ++k) host += s[k];       for (int k = j; s[k]; ++k) path += s[k];       if (mid.count(host) == 0) {         mid[host] = m_total++;         hostname.push_back(host);       }       if (pid.count(path) == 0) {         pid[path] = p_total++;       }       a[mid[host]].push_back(pid[path]);     }     for (int i = 0; i < m_total; ++i) {       sort(a[i].begin(), a[i].end());       a[i].erase(unique(a[i].begin(), a[i].end()), a[i].end());       b[i] = i;     }     sort(b, b + m_total, cmp);     int l = 0;     for (int i = 1; i < m_total; ++i) {       if (a[b[i]] != a[b[l]]) {         if (i - l > 1) {           std::vector<int> v;           v.clear();           for (int j = l; j < i; ++j) v.push_back(b[j]);           ans.push_back(v);         }         l = i;       }     }     if (m_total - l > 1) {       std::vector<int> v;       v.clear();       for (int j = l; j < m_total; ++j) v.push_back(b[j]);       ans.push_back(v);     }     printf( %d n , ans.size());     for (int i = 0; i < ans.size(); ++i) {       for (int j = 0; j < ans[i].size(); ++j) {         printf( %s%c , hostname[ans[i][j]].c_str(),                j < ans[i].size() - 1 ?     :   n );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7;   const int maxn = 1e4 + 5;   int n, b, q;   int a[maxn], c[maxn];   inline int f(int x, int j) { return (x / 5) + (x % 5 >= j); }   inline int calc(int j, int l, int r) { return f(r, j) - f(l - 1, j); }   int main() {     scanf( %d%d%d , &n, &b, &q);     memset(a, -1, sizeof(a));     for (int i = (0); i < (q); ++i) {       int x, k;       scanf( %d%d , &x, &k);       if (~a[x] && a[x] != k) {         puts( unfair );         return 0;       }       a[x] = k;     }     if (~a[b] && a[b] != n) {       puts( unfair );       return 0;     }     a[b] = n;     a[0] = 0;     for (int msk = (0); msk < (1 << 5); ++msk) {       int x, g = 0, lst = 0;       for (int i = (1); i <= (b); ++i)         if (~a[i]) {           int sub = 0, nin = 0;           if (a[i] < a[lst]) {             puts( unfair );             return 0;           }           for (int j = (0); j < (5); ++j) {             if (msk >> j & 1)               sub += calc(j, lst + 1, i);             else               nin += calc(j, lst + 1, i);           }           g += min(a[i] - a[lst], sub);           if (a[i] - a[lst] > i - lst) {             puts( unfair );             return 0;           }           lst = i;         }       x = __builtin_popcount(msk) * n / 5;       if (x > g) {         puts( unfair );         return 0;       }     }     puts( fair );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ins[300];   struct Rec {     int n, p;     int a[10];   } st[1000000];   void Print(int now) {     int i, j, x, pre, ret;     if (now == 0) return;     pre = st[now].p;     ret = st[now].a[st[now].n - 1];     for (i = 0; i < st[pre].n; i++)       for (x = 2; x <= 8; x <<= 1)         if (st[pre].a[i] * x == ret) {           Print(pre);           printf( lea e%cx, [%d*e%cx] n , st[now].n +  a  - 1, x,  a  + i);           return;         }     for (i = 0; i < st[pre].n; i++)       for (j = 0; j < st[pre].n; j++)         for (x = 1; x <= 8; x <<= 1)           if (st[pre].a[i] + st[pre].a[j] * x == ret) {             Print(pre);             printf( lea e%cx, [e%cx + %d*e%cx] n , st[now].n +  a  - 1, i +  a ,                    x, j +  a );             return;           }   }   int main() {     int i, j, n, x, low, top, lim, ret;     scanf( %d , &n);     if (n == 1) {       puts( 0 );       return 0;     }     st[0].n = 1;     st[0].a[0] = 1;     for (low = top = 0; low <= top; low++) {       memset(ins, 0, sizeof(ins));       lim = st[low].a[st[low].n - 1];       for (i = 0; i < st[low].n; i++)         for (x = 2; x <= 8; x <<= 1) {           ret = st[low].a[i] * x;           if (ret <= lim || ret > n) continue;           ins[ret] = 1;         }       for (i = 0; i < st[low].n; i++)         for (j = 0; j < st[low].n; j++)           for (x = 1; x <= 8; x <<= 1) {             ret = st[low].a[i] + st[low].a[j] * x;             if (ret <= lim || ret > n) continue;             ins[ret] = 1;           }       for (i = lim + 1; i <= n; i++)         if (ins[i]) {           st[++top].n = st[low].n;           for (j = 0; j < st[low].n; j++) st[top].a[j] = st[low].a[j];           st[top].a[st[top].n++] = i;           st[top].p = low;           if (i == n) {             printf( %d n , st[top].n - 1);             Print(top);             return 0;           }         }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   queue<long long> q1;   long long a[20005];   long long l, r;   int main(void) {     int i = 0;     int j;     cin >> l >> r;     q1.push(0);     while (1) {       a[i] = q1.front() * 10 + 4;       i++;       if (a[i - 1] >= r) break;       q1.push(a[i - 1]);       a[i] = q1.front() * 10 + 7;       i++;       if (a[i - 1] >= r) break;       q1.push(a[i - 1]);       q1.pop();     }     long long sum = 0;     for (j = 0; j < i; j++) {       if (l <= a[j] && r > a[j]) {         sum += a[j] * (a[j] + 1 - l);         l = a[j] + 1;       } else if (l <= a[j] && r <= a[j]) {         sum += a[j] * (r + 1 - l);         break;       }     }     cout << sum << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = (long long)1e9 + 7;   const long double PI = 3.141592653589793238462643383279502884197;   long long fac[1] = {1}, inv[1] = {1};   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long mp(long long a, long long b) {     long long ret = 1;     while (b) {       if (b & 1) ret = ret * a % MOD;       a = a * a % MOD;       b >>= 1;     }     return ret;   }   long long cmb(long long r, long long c) {     return fac[r] * inv[c] % MOD * inv[r - c] % MOD;   }   vector<int> v[1000000], rv[1000000];   char visit[1000000], mark[1000000];   int main() {     int n, m;     scanf( %d %d , &n, &m);     while (m--) {       int a, b;       scanf( %d %d , &a, &b);       a--;       b--;       v[a].push_back(b);       rv[b].push_back(a);     }     for (int i = 0; i < n; i++) {       if (visit[i] == 0) {         visit[i] = 1;         mark[i] = 1;         for (int j : v[i]) visit[j] = 1;       }     }     int cnt = 0;     for (int i = n - 1; i >= 0; i--) {       if (mark[i]) {         for (int j : rv[i])           if (mark[j]) mark[i] = 0;         cnt += mark[i];       }     }     printf( %d n , cnt);     for (int i = 0; i < n; i++)       if (mark[i]) printf( %d  , i + 1);   }
#include <bits/stdc++.h>   using namespace std;   char s[105], pos[105], p[105], cmp[105];   int main() {     int n = 0, k = 0;     scanf( %d%d , &n, &k);     scanf( %s , p);     scanf( %s , pos);     for (int i = 0; i < n; ++i) {       s[i] =  * ;     }     int lenp = strlen(p);     for (int i = 0; i < n - lenp + 1; ++i) {       if (pos[i] ==  1 ) {         for (int j = 0; j < lenp; ++j) {           s[i + j] = p[j];         }       }     }     for (int i = 0; i < n; ++i) {       bool isSame = true;       for (int j = 0; j < lenp && i + j < n; ++j) {         if (s[i + j] ==  * ) {           s[i + j] = p[j] ==  a  ?  b  :  a ;           isSame = false;           break;         } else if (s[i + j] != p[j]) {           if (pos[i] ==  1 ) {             printf( No solution );             return 0;           } else {             isSame = false;             break;           }         }       }       if (isSame && pos[i] ==  0 ) {         printf( No solution );         return 0;       }     }     for (int i = 0; i < n; ++i) {       printf( %c , s[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using namespace std::chrono;   template <typename A>   ostream &operator<<(ostream &cout, vector<A> const &v);   template <typename A, typename B>   ostream &operator<<(ostream &cout, pair<A, B> const &p) {     return cout <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <typename A>   ostream &operator<<(ostream &cout, vector<A> const &v) {     cout <<  [ ;     for (int i = 0; i < v.size(); i++) {       if (i) cout <<  ,  ;       cout << v[i];     }     return cout <<  ] ;   }   template <typename A, typename B>   istream &operator>>(istream &cin, pair<A, B> &p) {     cin >> p.first;     return cin >> p.second;   }   mt19937 rng(steady_clock::now().time_since_epoch().count());   void usaco(string filename) {     freopen((filename +  .in ).c_str(),  r , stdin);     freopen((filename +  .out ).c_str(),  w , stdout);   }   const long double pi = 3.14159265358979323846;   const long long mod = 1000000007;   long long n, m, k, q, Q, T, l, r, x, y, z;   long long a[1000005];   long long b[1000005];   long double c[1000005];   string second, t;   long long ans = 0;   double shoelace(double X[], double Y[], int n) {     double area = 0.0;     int j = n - 1;     for (int i = 0; i < n; i++) {       area += (X[j] + X[i]) * (Y[j] - Y[i]);       j = i;     }     return abs(area / 2.0);   }   int main() {     {       ios_base::sync_with_stdio(false);       cin.tie(NULL);       cout.tie(NULL);     };     for (int ele = 0; ele < 6; ele++) cin >> a[ele];     ;     double X[6], Y[6];     double ang = 0;     double x = 0, y = 0;     for (long long i = 0; i < (6); i++) {       X[i] = x;       Y[i] = y;       x += a[i] * cos(ang);       y += a[i] * sin(ang);       ang += pi / 3;     }     cout << (long long)(2 * shoelace(X, Y, 6) / 0.86602540378 + 0.5) << endl;   }