malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T min(T a, T b, T c) {     return min(min(a, b), c);   }   template <class T>   inline T min(T a, T b, T c, T d) {     return min(min(a, b), min(c, d));   }   template <class T>   inline T max(T a, T b, T c) {     return max(max(a, b), c);   }   template <class T>   inline T max(T a, T b, T c, T d) {     return max(max(a, b), max(c, d));   }   const int INF = 1e9;   const long long INF_LL = 4e18;   const double pi = acos(-1.0);   int dx[] = {-1, 1, 0, 0};   int dy[] = {0, 0, -1, 1};   int n;   vector<long long> odd;   int main() {     scanf( %d , &n);     long long ans = 0;     for (int i = 0; i < n; i++) {       long long x;       cin >> x;       if (x % 2L)         odd.push_back(x);       else         ans += x;     }     sort((odd).begin(), (odd).end());     for (int i = int((odd).size()) % 2; i < int((odd).size()); i++) ans += odd[i];     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long double nb;     cin >> nb;     if (nb <= 127)       cout <<  byte ;     else if (nb <= 32767)       cout <<  short ;     else if (nb <= 2147483647)       cout <<  int ;     else if (nb <= 9223372036854775807LL)       cout <<  long ;     else       cout <<  BigInteger ;   }
#include <bits/stdc++.h>   using namespace std;   long long a1, a2, b1, b2, c1, c2;   int main() {     ios_base::sync_with_stdio(0);     cin.tie();     cout.tie();     cin >> a1 >> b1 >> c1 >> a2 >> b2 >> c2;     if (!a1 && !b1 && c1 || !a2 && !b2 && c2) {       cout <<  0 ;       return 0;     }     if (a1 * b2 != a2 * b1) {       cout << 1;       return 0;     }     if (c1 * b2 == c2 * b1 && c1 * a2 == c2 * a1) {       cout <<  -1 ;       return 0;     }     cout << 0;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 1e5 + 5;   int A[M];   char B[M];   int main() {     int n;     scanf( %d , &n);     for (int j = 0; j < n; j++) scanf( %d , &A[j]);     scanf( %s , B);     int cnt = 0;     for (int j = 0; j < n; j++)       if (B[j] ==  1 ) cnt += A[j];     int ans = cnt, sum = 0, sum1 = 0;     for (int j = 0; j < n; j++) {       if (B[j] ==  1 ) {         ans = max(ans, cnt - A[j] + sum1 - sum);         sum += A[j];       }       sum1 += A[j];     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000010;   string s;   long long ans;   long long mem[N][5];   int n;   long long dp(int i, int last) {     if (i == n) {       if (last == 2 || last == 4) return 0;       return 1;     }     if (mem[i][last] != -1) return mem[i][last];     long long p = 0;     if (last == 0) {       if (s[i] ==  2  || s[i] ==  * ) return 0;       if (s[i] ==  1 )         p += dp(i + 1, 4);       else if (s[i] ==  0 )         p += dp(i + 1, 0);       else {         p += dp(i + 1, 4);         p += dp(i + 1, 0);       }     } else if (last == 1) {       if (s[i] ==  2  || s[i] ==  * ) return 0;       if (s[i] ==  1 )         p += dp(i + 1, 4);       else if (s[i] ==  0 )         p += dp(i + 1, 0);       else {         p += dp(i + 1, 4);         p += dp(i + 1, 0);       }     } else if (last == 4) {       if (s[i] ==  *  || s[i] ==  ? )         p += dp(i + 1, 3);       else         return 0;     } else if (last == 3) {       if (s[i] ==  0 )         return 0;       else if (s[i] ==  * )         p += dp(i + 1, 3);       else if (s[i] ==  1 )         p += dp(i + 1, 1);       else if (s[i] ==  2 )         p += dp(i + 1, 2);       else {         p += dp(i + 1, 3);         p += dp(i + 1, 1);         p += dp(i + 1, 2);       }     } else {       if (s[i] ==  *  || s[i] ==  ? )         p += dp(i + 1, 3);       else         return 0;     }     return mem[i][last] = p % 1000000007;   }   int main() {     cin >> s;     n = s.length();     memset(mem, -1, sizeof mem);     if (s[0] ==  ? ) {       ans += dp(1, 0);       ans += dp(1, 4);       ans += dp(1, 3);     } else {       if (s[0] ==  1 )         ans += dp(1, 4);       else if (s[0] ==  0 )         ans += dp(1, 0);       else if (s[0] ==  * )         ans += dp(1, 3);       else         ans = 0;     }     cout << ans % 1000000007;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n;     cin >> n;     long long a[n];     for (long long i = 0; i < n; i++) cin >> a[i];     long long f[n - 1];     long long s[n - 1];     for (long long i = 0; i < n - 1; i++) {       f[i] = abs((a[i] - a[i + 1])) * pow(-1, i);       s[i] = abs((a[i] - a[i + 1])) * (pow(-1, i + 1));     }     long long curr = f[0];     long long max_sofar = f[0];     for (long long i = 1; i <= n - 2; i++) {       curr = max(f[i], curr + f[i]);       max_sofar = max(max_sofar, curr);     }     if (n > 2) curr = s[1];     max_sofar = max(max_sofar, curr);     for (long long i = 2; i <= n - 2; i++) {       curr = max(s[i], curr + s[i]);       max_sofar = max(max_sofar, curr);     }     cout << max_sofar;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       while (n--) {         if (n == 0) {           cout <<  1  <<   n ;         } else {           cout <<  1  ;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   int a[4];   int cur[100005];   void work(int x, int y, int z, int w, int tp) {     if (x + z < y + w) return;     if (x + z >= y + w + 2) return;     int nlen = x + y + z + w;     for (int pl = 1; pl <= nlen; pl += 2) {       if (x)         cur[pl] = 0, x--;       else         cur[pl] = 2, z--;     }     for (int pl = 2; pl <= nlen; pl += 2) {       if (y)         cur[pl] = 1, y--;       else         cur[pl] = 3, w--;     }     for (int pl = 1; pl < nlen; pl++)       if (abs(cur[pl] - cur[pl + 1]) != 1) return;     printf( YES n );     for (int i = 1; i <= nlen; i++) {       if (tp)         printf( %d  , 3 - cur[i]);       else         printf( %d  , cur[i]);     }     exit(0);   }   int main() {     cin >> a[0] >> a[1] >> a[2] >> a[3];     work(a[0], a[1], a[2], a[3], 0);     work(a[3], a[2], a[1], a[0], 1);     printf( NO n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct rec {     int x, p;   } a[101];   vector<rec> ans;   int n;   bool was[101];   bool cmp(rec a, rec b) { return a.x > b.x; }   void dfs(int v) {     was[v] = true;     for (int i = v + 1; i < n; ++i) {       if (a[v].x == 0) break;       if (!was[i]) {         a[v].x--;         rec r;         r.x = a[v].p;         r.p = a[i].p;         ans.push_back(r);         dfs(i);       }     }   }   int main() {     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> a[i].x;       a[i].p = i;     }     sort(a + 1, a + n, cmp);     dfs(0);     for (int i = 0; i < n; ++i)       if (!was[i]) {         cout << -1;         return 0;       }     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); ++i) {       cout << ans[i].x + 1 <<     << ans[i].p + 1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[1000100];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int x;       scanf( %i , &x);       a[x]++;     }     int res = 0;     for (int i = 0; i < 1000100 - 1; i++) {       a[i + 1] += a[i] / 2;       a[i] %= 2;       res += a[i];     }     printf( %i n , res);   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void DBGpair(T a, string s =   ) {     cerr << s << (s ==    ?    :  :  ) << a.first <<  ,   << a.second <<   n ;   }   template <class T>   void DBGvec(vector<T> a) {     for (T i : a) cerr << i <<    ;     cerr <<   n ;   }   int dx[] = {0, 0, 1, -1};   int dy[] = {1, -1, 0, 0};   char dir[] = { R ,  L ,  D ,  U };   const int MOD = 1e9 + 7;   const long long INF = 1e9;   void setIO(string filename) {     if (fopen((filename +  .in ).c_str(),  r )) {       freopen((filename +  .in ).c_str(),  r , stdin);       freopen((filename +  .out ).c_str(),  w , stdout);     }   }   struct bit {     vector<long long> tree;     bit(int n) { tree = vector<long long>(n + 5, 0); }     long long rsq(int idx) {       long long sum = 0;       while (idx > 0) {         sum += tree[idx];         idx -= idx & -idx;       }       return sum;     }     long long rsq(int a, int b) {       a++;       b++;       return rsq(b) - (a == 1 ? 0 : rsq(a - 1));     }     void upd(int idx, int val) {       idx++;       while (idx < tree.size() - 1) {         tree[idx] += val;         idx += idx & -idx;       }     }   };   void solve() {     int n;     cin >> n;     vector<long long> a(n);     for (auto &i : a) cin >> i;     vector<long long> t(n);     for (auto &i : t) cin >> i;     vector<long long> psums(n + 1);     for (int i = 1; i <= n; i++) psums[i] = psums[i - 1] + t[i - 1];     bit tree(n);     vector<long long> pos(n + 1);     for (int i = 0; i < n; i++) tree.upd(i, 1);     for (int i = 0; i < n; i++) {       int idx = upper_bound((psums).begin(), (psums).end(), a[i] + psums[i]) -                 psums.begin();       if (idx == psums.size()) continue;       idx--;       pos[idx] += a[i] + psums[i] - psums[idx];       tree.upd(idx, -1);     }     for (int i = 0; i < n; i++) {       long long ans = tree.rsq(0, i) * t[i] + pos[i];       cout << ans <<    ;     }     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t = 1;     for (int i = 1; i <= t; i++) solve();   }
#include <bits/stdc++.h>   const int MAXN = 50 + 10;   bool row[MAXN];   bool column[MAXN];   int main() {     int n, x, y;     std::cin >> n;     for (int i = 0; i <= n * n; i++) {       std::cin >> x >> y;       if (row[x - 1] == false && column[y - 1] == false) {         row[x - 1] = true;         column[y - 1] = true;         std::cout << i + 1 <<    ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> vec[200005];   queue<int> Q;   int n, m;   int cvp[200005];   int top[200005], in[200005];   int a[200005], b[200005], c[200005];   void oku() {     int f, s, cost, i;     scanf( %d %d , &n, &m);     for (i = 1; i <= m; i++) {       scanf( %d %d %d , &f, &s, &cost);       vec[f].push_back(i);       vec[s].push_back(i);       a[i] = f;       b[i] = s;       c[i] = cost;       top[f] += cost;       top[s] += cost;     }     return;   }   void coz() {     int nod, s;     vector<int>::iterator it;     memset(cvp, -1, sizeof cvp);     Q.push(1);     while (!Q.empty()) {       nod = Q.front();       Q.pop();       for (it = vec[nod].begin(); it != vec[nod].end(); it++)         if (cvp[*it] == -1) {           if (nod == b[*it])             s = a[*it];           else             s = b[*it];           cvp[*it] = (nod == b[*it]);           in[s] += c[*it];           if (s != n && top[s] == 2 * in[s]) Q.push(s);         }     }     for (int i = 1; i <= m; i++) printf( %d n , cvp[i]);     return;   }   int main() {     oku();     coz();     return 0;   }
#include <bits/stdc++.h>   namespace IO {   char buf[1000000], *p1, *p2;   inline char getc() {     if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);     return p1 == p2 ? EOF : *(p1++);   }   template <typename tp>   inline void r(tp &n) {     n = 0;     char c = getc();     while (!isdigit(c)) c = getc();     while (isdigit(c)) n = n * 10 + c - 48, c = getc();   }   template <typename tp, typename... Args>   inline void r(tp &n, Args &...args) {     r(n);     r(args...);   }   template <typename tp>   inline void write(tp n) {     if (n / 10) write(n / 10);     putchar(n % 10 + 48);   }   template <typename tp>   inline void w(tp n, char c =   n ) {     write(n);     putchar(c);   }   };  // namespace IO   using namespace IO;   const int N = 1e6 + 2333;   using namespace std;   int m;   int dep[N], f[N][25];   int LCA(int x, int y) {     if (dep[x] < dep[y]) x ^= y ^= x ^= y;     for (int i = 20; i >= 0; --i)       if (dep[f[x][i]] >= dep[y]) x = f[x][i];     if (x == y) return x;     for (int i = 20; i >= 0; --i)       if (f[x][i] != f[y][i]) x = f[x][i], y = f[y][i];     return f[x][0];   }   int dis(int a, int b) { return dep[a] + dep[b] - dep[LCA(a, b)] * 2; }   int main() {     r(m);     int n = 4, u = 2, v = 3, nowdis = 2;     for (int i = 2; i <= 4; ++i) f[i][0] = 1, dep[i] = 1;     while (m--) {       int x;       r(x);       dep[n + 1] = dep[x] + 1, f[n + 1][0] = x;       dep[n + 2] = dep[x] + 1, f[n + 2][0] = x;       for (int i = 0; f[n + 1][i]; ++i) f[n + 1][i + 1] = f[f[n + 1][i]][i];       for (int i = 0; f[n + 2][i]; ++i) f[n + 2][i + 1] = f[f[n + 2][i]][i];       n += 2;       int a = dis(u, n), b = dis(v, n), c = nowdis;       nowdis = max(max(a, b), c);       if (nowdis == a)         v = n;       else if (nowdis == b)         u = n;       w(nowdis);     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 ,  unroll-loops )   using namespace std;   template <class T>   inline void sort(T &a) {     sort((a).begin(), (a).end());   }   template <class T>   inline void rsort(T &a) {     sort((a).rbegin(), (a).rend());   }   template <class T>   inline void reverse(T &a) {     reverse((a).begin(), (a).end());   }   template <class T, class U>   inline void checkmin(T &x, U y) {     if (x > y) x = y;   }   template <class T, class U>   inline void checkmax(T &x, U y) {     if (x < y) x = y;   }   vector<vector<int>> rev, G;   void dfs(int v, int p = -1) {     for (auto &i : G[v])       if (i != p) {         rev[i].push_back(v);         dfs(i, v);       }   }   void solve() {     int n;     cin >> n;     G = vector<vector<int>>(n);     for (int i = 1; i < n; ++i) {       int u, v;       cin >> u >> v;       --u, --v;       G[u].push_back(v);       G[v].push_back(u);     }     int k1, k2;     cin >> k1;     vector<int> arr(k1);     for (auto &i : arr) cin >> i, --i;     cin >> k2;     vector<int> brr(k2);     for (auto &i : brr) cin >> i, --i;     vector<bool> used(n);     for (auto &i : arr) used[i] = true;     cout <<  B   << brr[0] + 1 << endl;     int y;     cin >> y;     --y;     rev = vector<vector<int>>(n);     dfs(y);     y = arr[0];     while (int(rev[y].size())) {       if (!used[rev[y][0]]) break;       y = rev[y][0];     }     int start = y;     cout <<  A   << y + 1 << endl;     cin >> y;     --y;     for (auto i : brr)       if (i == y) {         cout <<  C   << start + 1 << endl;         return;       }     cout <<  C   << -1 << endl;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout << fixed << setprecision(20);     srand(time(nullptr));     int q;     cin >> q;     while (q--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     size_t n;     string s, t;     cin >> n >> s >> t;     int base = ( z  -  a ) + 1;     vector<int> l(n + 1), r(n + 1);     for (int i = 0; i < int(n); ++i) {       l[i + 1] = s[i] -  a ;     }     for (int i = 0; i < int(n); ++i) {       r[i + 1] = t[i] -  a ;     }     for (int i = n; i >= 0; --i) {       l[i] += r[i];       if (i > 0) {         l[i - 1] += l[i] / 26;         l[i] %= 26;       }     }     vector<int> res(n + 1);     for (int i = 0; i <= n; ++i) {       int rem = l[i] % 2;       l[i] /= 2;       if (i < n) {         l[i + 1] += rem * 26;       }     }     for (int i = 1; i <= n; ++i) {       cout << char(l[i] +  a );     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long n, m, a, b, c;   vector<pair<long, long> > g[220000];   long cap[220000];   map<pair<long, long>, long> mapp;   set<pair<long, long> > done;   long ans[220000];   void solve(long v) {     for (int i = 0; i < g[v].size(); i++) {       long q = g[v][i].first;       long val = g[v][i].second;       if (done.find(make_pair(v, q)) != done.end()) continue;       done.insert(make_pair(v, q));       done.insert(make_pair(q, v));       ans[mapp[make_pair(v, q)]] = 1;       cap[q] -= val;       if (cap[q] == 0 && q < n) solve(q);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> m;     for (int i = 1; i <= m; i++) {       cin >> a >> b >> c;       mapp[make_pair(b, a)] = i;       g[a].push_back(make_pair(b, c));       g[b].push_back(make_pair(a, c));       cap[a] += c;       cap[b] += c;     }     for (int i = 1; i <= n; i++) cap[i] /= 2;     cap[n] = 0;     cap[1] = 0;     solve(1);     for (int i = 1; i <= m; i++) cout << ans[i] << endl;     cin.get();     cin.get();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f, mod = 998244353;   const long long INF = 0x3f3f3f3f3f3f3f3fLL;   const double pi = acosl(-1.), eps = 1e-9;   inline void sum(int &a, int b) {     a += b;     if (a >= mod) a -= mod;   }   inline int power(int a, int b, int m = mod, int ans = 1) {     for (; b; b >>= 1, a = 1LL * a * a % m)       if (b & 1) ans = 1LL * ans * a % m;     return ans;   }   const int NN = 10010;   int ch[NN], rch[NN];   int c(int n, int m) {     if (n < m) return 0;     if (!m) return 1;     return (long long)ch[n] * rch[n - m] % mod * rch[m] % mod;   }   int dp[111][5555];   int s[111][5555];   int main() {     ch[0] = 1;     for (int i = 1; i < NN; i++) ch[i] = (long long)ch[i - 1] * i % mod;     rch[NN - 1] = power(ch[NN - 1], mod - 2);     for (int i = NN - 1; i; i--) {       rch[i - 1] = (long long)rch[i] * i % mod;     }     int N, S, R;     cin >> N >> S >> R;     if (N == 1) {       puts( 1 );       return 0;     }     int tmp;     if (R == 0) {       tmp = c(N + S - 1, N - 1);     } else {       dp[0][0] = 1;       for (int i = 0; i <= S; i++) s[0][i] = 1;       for (int i = 1; i <= N; i++) {         for (int j = 0; j <= S; j++) {           dp[i][j] = s[i - 1][j];           if (j >= R) dp[i][j] -= s[i - 1][j - R];           if (dp[i][j] < 0) dp[i][j] += mod;         }         s[i][0] = 1;         for (int j = 1; j <= S; j++) {           s[i][j] = s[i][j - 1] + dp[i][j];           if (s[i][j] >= mod) s[i][j] -= mod;         }       }       tmp = c(S + N - 1, N - 1) - dp[N][S];       if (tmp < 0) tmp += mod;     }     tmp = (long long)tmp * power(N, mod - 2) % mod;     int tot = 0;     for (int i = R; i <= S; i++) {       sum(tot, c(S - i + N - 1 - 1, N - 2));     }     tot = power(tot, mod - 2);     cout << (long long)tmp * tot % mod << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   pair<pair<int, int>, int> e[100010];   int parent[100010];   int Rank[100010];   int sz[100010];   vector<int> v[100010];   bool mark[100010];   bool mark1[100010];   int color[100010];   vector<int> out[2];   bool success[2];   int cnt[2];   int n, m;   int find(int cur) {     if (parent[cur] == cur) return cur;     return parent[cur] = find(parent[cur]);   }   void Union(int x, int y) {     int xroot = find(x);     int yroot = find(y);     if (xroot == yroot) return;     if (Rank[xroot] < Rank[yroot])       parent[xroot] = yroot;     else if (Rank[xroot] > Rank[yroot])       parent[yroot] = xroot;     else {       Rank[xroot]++;       parent[yroot] = xroot;     }   }   void init(int n) {     int i;     for (i = 0; i <= n; ++i) {       Rank[i] = 0;       parent[i] = i;       sz[i] = 0;     }   }   bool dfs(int cur, int c) {     mark[cur] = 1;     color[cur] = c;     cnt[c] += sz[cur];     for (int i = 0; i < v[cur].size(); ++i) {       if (mark[v[cur][i]]) {         if (color[v[cur][i]] == c) return 0;         continue;       }       if (!dfs(v[cur][i], 1 - c)) return 0;     }     return 1;   }   void dfs1(int cur) {     mark1[cur] = 1;     color[cur] = 1 - color[cur];     for (int i = 0; i < v[cur].size(); ++i)       if (!mark1[v[cur][i]]) dfs1(v[cur][i]);   }   void solve(int f) {     int i;     init(n);     success[f] = 0;     for (i = 1; i <= n; ++i) v[i].clear();     for (i = 0; i < m; ++i)       if (e[i].second == f) Union(e[i].first.first, e[i].first.second);     for (i = 0; i < m; ++i)       if (e[i].second != f) {         int x = find(e[i].first.first), y = find(e[i].first.second);         if (x == y) return;         v[x].push_back(y);         v[y].push_back(x);       }     for (i = 1; i <= n; ++i) sz[find(i)]++;     memset(mark, 0, sizeof(mark));     memset(mark1, 0, sizeof(mark1));     for (i = 1; i <= n; ++i) {       cnt[0] = cnt[1] = 0;       if (mark[find(i)]) continue;       if (!dfs(find(i), 0)) return;       if (cnt[0] > cnt[1]) dfs1(find(i));     }     success[f] = 1;     for (i = 1; i <= n; ++i)       if (color[find(i)] == 0) out[f].push_back(i);   }   int main() {     int i, x, y, c;     string s;     scanf( %d , &n);     scanf( %d , &m);     for (i = 0; i < m; ++i) {       scanf( %d , &x);       scanf( %d , &y);       cin >> s;       if (s[0] ==  R )         c = 0;       else         c = 1;       e[i] = make_pair(make_pair(x, y), c);     }     solve(0);     solve(1);     int minn = 1000000, minpos;     for (i = 0; i < 2; ++i)       if (success[i])         if ((int)out[i].size() < minn) {           minn = (int)out[i].size();           minpos = i;         }     if (minn == 1000000)       printf( %d n , -1);     else {       printf( %d n , minn);       for (auto it : out[minpos]) printf( %d  , it);       printf(  n );     }   }