malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   vector<long long> v;   vector<pair<long long, long long> > ans;   long long sz, n, m, pos;   long long p2(long long x) {     long long y = sqrt(x);     for (long long i = y - 1; i <= y + 1; i++)       if (i * i == x) return y;     return false;   }   bool fnd(long long x) {     long long p = pos, i;     for (i = pos; i <= sz; i++) {       long long j = p2(i * i + x);       if (j) {         pos = j;         ans.push_back({i, j});         return true;       }     }     return false;   }   int32_t main() {     cin >> n;     for (long long i = 1; i <= n / 2; i++) {       long long x;       scanf( %lld , &x);       v.push_back(x);     }     sz = 1e7;     pos = 1;     for (auto x : v)       if (!fnd(x)) return cout <<  No  << endl, 0;     long long bef = 0;     cout <<  Yes  << endl;     for (auto p : ans) {       printf( %lld %lld  , p.first * p.first - bef * bef,              p.second * p.second - p.first * p.first);       bef = p.second;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m, h;     cin >> n >> m >> h;     long long r[n], c[m], a[n][m];     for (long long i = 0; i < m; i++) {       cin >> c[i];     }     for (int i = 0; i < n; i++) {       cin >> r[i];     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> a[i][j];       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (r[i] == c[j] && a[i][j] == 1) {           a[i][j] = r[i];         }       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i][j] == 1) {           a[i][j] = min(r[i], c[j]);         }       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cout << a[i][j] <<    ;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = -1;   struct dot {     long long x, y;     dot(long long x = 0, long long y = 0) : x(x), y(y) {}   };   bool operator<(dot a, dot b) {     return ((a.x + a.y) == (b.x + b.y) ? a.x < b.x : (a.x + a.y) < (b.x + b.y));   }   bool Amber(dot a, dot b) { return (a.x - a.y) < (b.x - b.y); }   multiset<dot> L, R;   long long getans(long long st, vector<dot> &V) {     L.clear();     R.clear();     for (int i = (0); i < (int)(V.size()); i++) R.insert(V[i]);     long long ans = 0;     int p = 0;     for (long long lim = -st; lim < st; lim += 2) {       while (p < V.size() && (V[p].x - V[p].y < lim)) {         L.insert(V[p]);         R.erase(V[p]);         p++;       }       if (L.empty() || R.empty()) {         continue;       }       dot A = max(*L.begin(), *R.begin());       long long l = A.x + A.y;       dot B = min(*L.rbegin(), *R.rbegin());       long long r = B.x + B.y;       if (r < l) continue;       ans += (r - l) / 2;     }     return ans;   }   int n;   vector<dot> B, W;   int main() {     while (scanf( %d , &n) == 1) {       B.clear();       W.clear();       for (int i = (0); i < (int)(n); i++) {         dot T;         scanf( %lld %lld , &T.x, &T.y);         if ((T.x + T.y) % 2)           B.push_back(T);         else           W.push_back(T);       }       sort(B.begin(), B.end(), Amber);       sort(W.begin(), W.end(), Amber);       long long ans = getans(200004, B) + getans(200005, W);       printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 9;   int n, u, v, w, t, p, sub[N], par[N], mark[N];   vector<pair<int, int> > g[N];   vector<pair<int, pair<int, int> > > edge[N];   pair<pair<int, int>, pair<int, int> > ed[N];   long long mx, ans[N];   set<int> s;   int Get_par(int u) {     if (par[u] < 0) return u;     return par[u] = Get_par(par[u]);   }   void merge(int u, int v) {     u = Get_par(u), v = Get_par(v);     if (par[v] < par[u]) swap(u, v);     par[u] += par[v];     par[v] = u;   }   void dfs1(int x) {     sub[x] = par[x] * -1, mark[x] = 1;     for (int i = 0; i < g[x].size(); i++)       if (!mark[g[x][i].first]) dfs1(g[x][i].first), sub[x] += sub[g[x][i].first];   }   void dfs2(int x, int rt, int e) {     mark[x] = 2;     ans[e] = 1ll * sub[x] * (sub[rt] - sub[x]);     for (int i = 0; i < g[x].size(); i++)       if (mark[g[x][i].first] < 2) dfs2(g[x][i].first, rt, g[x][i].second);   }   int main() {     fill(par, par + N, -1);     cin >> n;     for (int i = 1; i < n; i++) {       scanf( %d%d , &ed[i].second.first, &ed[i].second.second);       ;       scanf( %d , &ed[i].first.first);       ;       ed[i].first.second = i;     }     sort(ed + 1, ed + n);     for (int i = 1; i < n; i++) {       if (i != 1 && ed[i].first.first != ed[i - 1].first.first) p++;       edge[p].push_back(           make_pair(ed[i].first.second,                     make_pair(ed[i].second.first, ed[i].second.second)));     }     for (int k = 0; k < N; k++) {       for (int i = 0; i < edge[k].size(); i++) {         edge[k][i].second.first = Get_par(edge[k][i].second.first),         edge[k][i].second.second = Get_par(edge[k][i].second.second);         g[edge[k][i].second.first].clear(), g[edge[k][i].second.second].clear();       }       for (int i = 0; i < edge[k].size(); i++)         g[edge[k][i].second.first].push_back(             make_pair(edge[k][i].second.second, edge[k][i].first)),             g[edge[k][i].second.second].push_back(                 make_pair(edge[k][i].second.first, edge[k][i].first)),             mark[edge[k][i].second.first] = mark[edge[k][i].second.second] = 0;       for (int i = 0; i < edge[k].size(); i++)         if (!mark[edge[k][i].second.first]) dfs1(edge[k][i].second.first);       for (int i = 0; i < edge[k].size(); i++) {         merge(edge[k][i].second.first, edge[k][i].second.second);         if (mark[edge[k][i].second.first] < 2)           dfs2(edge[k][i].second.first, edge[k][i].second.first, 0);       }     }     for (int i = 1; i < n; i++) mx = max(mx, ans[i]);     ;     for (int i = 1; i < n; i++) t += (ans[i] == mx);     cout << mx * 2 <<     << t << endl;     for (int i = 1; i < n; i++)       if (ans[i] == mx) cout << i <<    ;   }
#include <bits/stdc++.h>      #define optimize ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);   #define S second   #define F first   #define ENDL   n    #define fori(i, n) for(int i=0; i<n; ++i)   #define foreach(n) for(int i=0; i<n; ++i)   #define read_v(v) for(int i=0; i<v.size(); ++i) cin >> v[i]   #define all(v) v.begin(), v.end()   #define asc_sort(v) sort(v.begin(), v.end())   #define desc_sort(v) sort(v.rbegin(), v.rend())   #define print_all(v) for(int i=0; i<(int)v.size(); ++i) cout << v[i] << (i<(int)v.size()-1 ?     :   n )   #define pb push_back   #define sz(v) v.size()   #define ceil_div(a, b) (a+b-1) / b   #define tcs(foo)  {                                        int tc;                                  cin >> tc;                               while(tc--) foo();                       }      using namespace std;      typedef string str;   typedef unsigned int ui;   typedef long long ll;   typedef unsigned long long ull;   typedef vector<int> vi;   typedef vector<bool> vbool;   typedef vector<long long> vll;   typedef vector<unsigned long long> vull;   typedef vector<string> vstr;   typedef vector<pair<int, int>> vpii;   typedef set<int> s_int;   typedef pair<int, int> pii;   typedef priority_queue<int, vector<int>, greater<int>> min_heap;   typedef priority_queue<int> max_heap;      string to_string(string s) { return     + s +    ; }      string to_string(const char* s) { return to_string((string) s); }      string to_string(bool b) { return (b ?  true  :  false ); }      template <typename A, typename B>   string to_string(pair<A, B> p) { return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ; }      template <typename A>   string to_string(A v) {     bool first = true;     string res =  { ;     for (const auto &x : v) {       if (!first) res +=  ,  ;       first = false;       res += to_string(x);     }     res +=  } ;     return res;   }      void debug_out() { cerr << endl; }      template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << to_string(H);     debug_out(T...);   }      #ifdef LOCAL   #define debug(...) cerr <<  [  << #__VA_ARGS__ <<  ]: , debug_out(__VA_ARGS__)   #else   #define debug(...) 42   #endif      /********************       END TEMPLATE   *********************/   ll n, m, ans, sm, suma, sumb;      void solve(){     cin >> n >> m;     vi A, B, tmp(n);     int aux, i, j;     suma = sumb = sm  = 0;     ans = INT_MAX;        read_v(tmp);        for(auto &a : tmp){       cin >>  aux;       sm += a;       if(aux==1) {         A.pb(a);       }else {         sumb += a;         B.pb(a);       }     }        if(sm < m){       cout << -1 << endl;       return;     }        desc_sort(A);     desc_sort(B);        i = 0;     j = sz(B)-1;        for(i=0; i<=sz(A); ++i){       while(j >= 0 && suma+sumb-B[j] >= m)         sumb -= B[j--];          if(sumb+suma >= m) ans = min(ans, (ll)(j+1)*2+i);       if(i < sz(A)) suma += A[i];     }     cout << ans << endl;   }         int main(){     tcs(solve)     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int t, a, b, c, ans, t1;   int main() {     scanf( %d , &t);     while (t--) {       scanf( %d%d%d , &a, &b, &c);       ans = 0;       t1 = c / 2;       t1 = min(t1, b);       ans += t1 * 3;       b -= t1;       t1 = b / 2;       t1 = min(t1, a);       ans += t1 * 3;       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     string s;     cin >> s;     vector<int> st;     st.push_back(s[0]);     for (int i = 1; i < s.size(); i++) {       if (st.empty())         st.push_back(s[i]);       else {         if (st.back() == s[i])           st.pop_back();         else           st.push_back(s[i]);       }     }     int turns = (s.size() - st.size()) / 2;     cout << (turns % 2 ?  Yes  :  No );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int A[55], ctos, lleno;   long long D[52][52][52][52];   double res = 0, suma;   int main() {     scanf( %d , &ctos);     for (int i = 1; i <= ctos; i++) {       scanf( %d , &A[i]);       suma += A[i];     }     scanf( %d , &lleno);     for (int quien = 1; quien <= ctos; quien++) {       for (int dnde = ctos + 1; dnde > 0; dnde--) {         for (int lleva = 0; lleva <= 50; lleva++) {           for (int lugares = 0; lugares <= ctos; lugares++) {             if (dnde == quien) {               D[dnde][lleva][lugares][quien] = D[dnde + 1][lleva][lugares][quien];             } else if (dnde > ctos) {               if (lleva == 0 and lugares == 0) {                 D[dnde][lleva][lugares][quien] = 1;               } else {                 D[dnde][lleva][lugares][quien] = 0;               }             } else if (lleva == 0 or lugares == 0) {               if (lleva == 0 and lugares == 0) {                 D[dnde][lleva][lugares][quien] = 1;               } else {                 D[dnde][lleva][lugares][quien] = 0;               }             } else {               D[dnde][lleva][lugares][quien] = D[dnde + 1][lleva][lugares][quien];               if (lleva >= A[dnde]) {                 D[dnde][lleva][lugares][quien] +=                     D[dnde + 1][lleva - A[dnde]][lugares - 1][quien];               }             }           }         }       }     }     if (suma <= lleno) {       res = ctos;     } else {       for (int i = ctos - 1; i > 0; i--) {         for (int eleg = 1; eleg <= ctos; eleg++) {           suma = 0;           for (int es = lleno - A[eleg] + 1; es <= lleno; es++) {             suma += D[1][es][i][eleg];           }           suma *= i;           for (double e = ctos; e > i; e--) {             suma /= e;           }           for (int e = 2; e <= ctos - i - 1; e++) {             suma *= e;           }           res += suma;         }       }     }     cout << res <<   n ;     return 0;   }
#include <bits/stdc++.h>   int main() {     long a, b;     while (scanf( %ld%ld , &a, &b) != EOF) {       if (a == b) {         if (a % 2 == 0)           printf( 2 n );         else if (a % 3 == 0)           printf( 3 n );         else if (a % 5 == 0)           printf( 5 n );         else if (a % 7 == 0)           printf( 7 n );         else           printf( %ld , a);       } else         printf( 2 n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const double eps = 1e-8;   char ans[1024];   int K, X, N, M;   char st[64], ed[64];   long long num[64];   void printAns(char from, char to, int all, int len) {     int pos = 1;     if (from ==  A ) pos = 0;     for (int i = 0; i < len; i++) ans[i] =  B ;     for (int i = 0; i < all; i++)       ans[pos + 2 * i] =  A , ans[pos + 2 * i + 1] =  C ;     ans[0] = from;     ans[len - 1] = to;     ans[len] =   0 ;     printf( %s n , ans);   }   int main() {     scanf( %d%d%d%d , &K, &X, &N, &M);     for (char s1 =  A ; s1 <=  C ; s1++) {       for (char e1 =  A ; e1 <=  C ; e1++) {         if (N == 1 && s1 != e1) continue;         for (char s2 =  A ; s2 <=  C ; s2++) {           for (char e2 =  A ; e2 <=  C ; e2++) {             if (M == 1 && s2 != e2) continue;             long long tn = N - (s1 !=  A ) - (e1 !=  C );             long long tm = M - (s2 !=  A ) - (e2 !=  C );             long long inN = tn / 2;             long long inM = tm / 2;             st[1] = s1, ed[1] = e1;             st[2] = s2, ed[2] = e2;             for (long long i = 0; i <= inN; i++) {               for (long long k = 0; k <= inM; k++) {                 if (N == 2 && s1 ==  A  && e1 ==  C  && i == 0) continue;                 if (M == 2 && s2 ==  A  && e2 ==  C  && k == 0) continue;                 num[1] = i;                 num[2] = k;                 for (int g = 3; g <= K; g++) {                   st[g] = st[g - 2], ed[g] = ed[g - 1];                   num[g] = num[g - 1] + num[g - 2] +                            (ed[g - 2] ==  A  && st[g - 1] ==  C );                 }                 if (num[K] == X) {                   printAns(s1, e1, i, N);                   printAns(s2, e2, k, M);                   return 0;                 }               }             }           }         }       }     }     printf( Happy new year! n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string last_w =   ;   set<string> reserved;   void change_last_w() {     do {       int j(last_w.size() - 1);       while (j >= 0 && last_w[j] ==  z ) --j;       if (j == -1)         last_w.assign(last_w.size() + 1,  a );       else {         ++last_w[j];         for (int i(j + 1); i < last_w.size(); ++i) last_w[i] =  a ;       }     } while (reserved.count(last_w));   }   bool valid_char(char c) {     return isdigit(c) || isalpha(c) || c ==  _  || c ==  $ ;   }   int parse_word(const string& s) {     if (s.empty()) return 0;     if (isdigit(s[0])) return false;     int ans(0);     while (ans < s.size() && valid_char(s[ans])) ++ans;     return ans;   }   int parse_num(const string& s) {     if (s.empty()) return 0;     int ans(0);     while (ans < s.size() && isdigit(s[ans])) ++ans;     return ans;   }   int parse_reserved(const string& s) {     if (s.empty()) return 0;     int best(0);     string t;     for (int i(0); i < min<size_t>(20UL, s.size()) && s[i] !=  # ; ++i) {       t += s[i];       if (reserved.count(t)) best = i + 1;     }     return best;   }   int parse_all(const string& s) {     return max({parse_num(s), parse_reserved(s), parse_word(s)});   }   vector<string> parse(string s) {     vector<string> ans;     while (!s.empty() && s[0] !=  # ) {       int cnt(0);       while (cnt < s.size() && s[cnt] ==    ) ++cnt;       if (cnt) {         s = s.substr(cnt, s.size() - cnt);         continue;       }       int cur(parse_all(s));       ans.push_back(s.substr(0, cur));       s = s.substr(cur, s.size() - cur);     }     return ans;   }   vector<int> parse_len(string s) {     vector<int> ans;     while (!s.empty()) {       int cnt(0);       while (cnt < s.size() && s[cnt] ==    ) ++cnt;       if (cnt) {         s = s.substr(cnt, s.size() - cnt);         continue;       }       int cur(parse_all(s));       ans.push_back(cur);       s = s.substr(cur, s.size() - cur);     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     string s__;     for (int i(0); i < n; ++i) {       cin >> s__;       reserved.insert(s__);     }     cin >> n;     getline(cin, s__);     vector<string> tokens;     while (n--) {       getline(cin, s__);       auto add = parse(s__);       copy(begin(add), end(add), back_inserter(tokens));     }     map<string, string> was;     for (string& s : tokens)       if (!reserved.count(s) && !isdigit(s[0])) {         if (!was.count(s)) {           change_last_w();           was[s] = last_w;         }         s = was[s];       }     string ans;     int next_space(tokens.size());     for (int i(0); i < tokens.size(); ++i) {       string s(tokens[i]);       int j(i + 1);       while (true) {         if (j == tokens.size()) break;         s += tokens[j];         if (parse_all(s) != tokens[i].size()) {           next_space = min(next_space, j - 1);           break;         }         if (s.size() > 20) break;         ++j;       }       ans += tokens[i];       if (next_space == i) {         next_space = tokens.size();         ans +=    ;       }     }     cout << ans;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK: 1024000000,1024000000 )   using namespace std;   inline int getint() {     int _x = 0;     char _tc = getchar();     while (_tc <  0  || _tc >  9 ) _tc = getchar();     while (_tc >=  0  && _tc <=  9 ) _x *= 10, _x += (_tc -  0 ), _tc = getchar();     return _x;   }   const int N = 1010, M = 1e5 + 15, INF = 1e7;   bool vis[N];   int dis[N];   struct Edge {     int u, v, c, w;     int nxt;     Edge() {}     Edge(int t2, int t3, int t4, int t5, int t6)         : u(t2), v(t3), c(t4), w(t5), nxt(t6) {}   };   Edge e[M];   int h[N], ect;   int mom[N], id[N];   int n, m, A[N], D[N], X[N], ca, cd;   char s[10];   int S, T;   void init() {     memset(vis, false, sizeof(vis));     ect = 0;     memset(h, -1, sizeof(h));     ca = cd = 0;   }   void _add(int u, int v, int c, int w) {     e[ect] = Edge(u, v, c, w, h[u]);     h[u] = ect++;     e[ect] = Edge(v, u, 0, -w, h[v]);     h[v] = ect++;   }   int spfa() {     queue<int> Q;     for (int i = S + 1; i <= T; i++) dis[i] = 10 * INF;     Q.push(S);     vis[S] = true;     while (!Q.empty()) {       int u = Q.front();       Q.pop();       vis[u] = false;       for (int i = h[u]; i + 1; i = e[i].nxt) {         int v = e[i].v;         if (e[i].c && dis[v] > dis[u] + e[i].w) {           dis[v] = dis[u] + e[i].w;           if (!vis[v]) vis[v] = true, Q.push(v);           id[v] = i;         }       }     }     return dis[T];   }   void aug() {     int p = T;     while (p != S) {       e[id[p]].c -= 1;       e[id[p] ^ 1].c += 1;       p = e[id[p] ^ 1].v;     }   }   int MFMC() {     int ret = 0, d, tmp = 0;     for (int i = 1; i <= n; i++) {       d = spfa();       if (d == 10 * INF) return -ret;       tmp += d, ret = min(ret, tmp), aug();     }     for (int i = n + 1; i <= m; i++) {       d = spfa();       if (d == 10 * INF) return -ret;       tmp += d - 2 * INF, ret = min(ret, tmp), aug();     }     return -ret;   }   int main() {     init();     scanf( %d%d , &n, &m);     S = 0, T = n + m + 1;     dis[S] = 0;     for (int i = 1, x; i <= n; i++) {       scanf( %s %d , s, &x);       if (s[0] ==  A )         A[++ca] = x;       else         D[++cd] = x;     }     for (int i = 1; i <= n; i++) _add(i + m, T, 1, 0);     for (int i = 1; i <= m; i++) {       scanf( %d , &X[i]);       _add(S, i, 1, 0);       _add(i, T, 1, 2 * INF - X[i]);       for (int j = 1; j <= ca; j++)         if (X[i] >= A[j]) _add(i, j + m, 1, A[j] - X[i]);       for (int j = 1; j <= cd; j++)         if (X[i] > D[j]) _add(i, j + m + ca, 1, 0);     }     printf( %d n , MFMC());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n;     cin >> n;     long long a[n];     for (long long i = 0; i < n; i++) cin >> a[i];     long long ans = 0;     for (long long i = n - 1; i >= 0; i--) {       if (i == n - 1)         ans += a[i];       else if (a[i] < a[i + 1])         ans += a[i];       else if (a[i] >= a[i + 1]) {         if (a[i + 1] == 0)           a[i] = 0;         else {           ans += a[i + 1] - 1;           a[i] = a[i + 1] - 1;         }       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   long long mod = 1000000007;   long long mod2 = 998244353;   long long OO = 1e18;   long long david_villa_pow(long long x, long long n) {     if (n == 0) return 1;     long long u = david_villa_pow(x, n / 2);     u = ((u) * (u));     if (n % 2 == 1) u = ((u) * (x));     return u;   }   long long up(long long x, long long y) {     if (x % y == 0) return x / y;     return x / y + 1;   }   using namespace std;   long long a[200200];   int main() {     long long i, j;     ;     long long T;     cin >> T;     while (T--) {       long long n, k, mn = OO;       cin >> n >> k;       for (i = 0; i < n; i++) {         cin >> a[i];         mn = min(mn, a[i]);       }       long long indx = 0;       for (i = 0; i < n; i++) {         if (a[i] == mn) {           indx = i;           break;         }       }       long long res = 0;       for (i = 0; i < n; i++) {         if (i != indx) {           res += (k - a[i]) / mn;         }       }       cout << res << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = (1 << 30) - 1;   const long long linf = (1ll << 62) - 1;   int main() {     int n;     cin >> n;     vector<int> is_prime(n + 1, true), primes;     is_prime[0] = is_prime[1] = 0;     for (int i = 2; i * i <= n; i++) {       if (is_prime[i]) {         for (int j = i * i; j <= n; j += i) {           is_prime[j] = false;         }       }     }     vector<int> ans;     for (int i = 1; i <= n; i++) {       if (is_prime[i]) {         int q = i;         while (q <= n) {           ans.push_back(q);           q *= i;         }       }     }     cout << ((int)(ans).size()) << endl;     for (int i : ans) {       printf( %d  , i);     }     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int i, n, k, r;     cin >> n >> k;     long long int a[n];     for (i = 0; i < n; i++) {       cin >> a[i];     }     long long int *m = min_element(a, a + n);     r = 0;     for (i = 0; i < n; i++) {       if ((a[i] - *m) % k == 0) {         r += (a[i] - *m) / k;       } else {         cout << -1;         return 0;       }     }     cout << r;   }