malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     for (int i = 0; i < s.length(); i++)       if (s[i] >  4 ) s[i] =  9  - s[i] +  0 ;     if (s[0] ==  0 ) s[0] =  9 ;     cout << s;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int const nmax = 1000;   int const modulo = 7340033;   int dp[40][5 + nmax];   int dp2[40][5 + nmax];   int main() {     dp[0][0] = 1;     dp[1][1] = 1;     dp[1][0] = 1;     for (int i = 2; i <= 32; i++) {       dp[i][0] = 1;       for (int j = 0; j <= nmax; j++)         for (int h = 0; h <= nmax - j; h++) {           dp2[i][j + h] += 1LL * dp[i - 1][j] * dp[i - 1][h] % modulo;           if (modulo <= dp2[i][j + h]) dp2[i][j + h] -= modulo;         }       for (int j = 0; j <= nmax; j++)         for (int h = 0; h <= nmax - j; h++) {           dp[i][1 + j + h] += 1LL * dp2[i][j] * dp2[i][h] % modulo;           if (modulo <= dp[i][1 + j + h]) dp[i][1 + j + h] -= modulo;         }     }     int q;     cin >> q;     for (int testcase = 1; testcase <= q; testcase++) {       int n, k;       cin >> n >> k;       int p = 0;       while (1 < n && n % 2 == 1) {         p++;         n /= 2;       }       cout << dp[p][k] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int d = 0;     char c = getchar();     while (c <  0  || c >  9 ) c = getchar();     while (c >=  0  && c <=  9 ) {       d = (d << 3) + (d << 1) + c -  0 ;       c = getchar();     }     return d;   }   const int N = 1e5 + 5;   const long long INF = 1e14;   int n, m, k;   int from[N * 2], ver[N * 2], nxt[N * 2], edge[N * 2], head[N], cnt;   int v[N * 2], h[N], nx[N * 2], cnt1;   long long dis[N][2], ed[N * 2];   int po[N];   bool pl[N];   inline void add(int x, int y, int z) {     from[++cnt] = x, ver[cnt] = y, edge[cnt] = z, nxt[cnt] = head[x],     head[x] = cnt;   }   void spfa() {     for (int i = 1; i <= n; i++) dis[i][0] = dis[i][1] = INF;     queue<int> q;     for (int i = 1; i <= k; i++) {       q.push(po[i]);       pl[po[i]] = true;       dis[po[i]][0] = po[i];       dis[po[i]][1] = 0;     }     while (!q.empty()) {       int x = q.front();       q.pop();       pl[x] = false;       for (int i = head[x]; i; i = nxt[i]) {         int y = ver[i];         if (dis[y][1] > dis[x][1] + edge[i]) {           dis[y][1] = dis[x][1] + edge[i];           dis[y][0] = dis[x][0];           if (!pl[y]) {             q.push(y);             pl[y] = true;           }         }       }     }   }   long long prim() {     long long ans = dis[1][1], nm = dis[1][0];     int tot = 1;     priority_queue<pair<long long, int>, vector<pair<long long, int> >,                    greater<pair<long long, int> > >         q;     pl[nm] = true;     for (int i = h[nm]; i; i = nx[i]) q.push(make_pair(ed[i], v[i]));     while (tot < k) {       while (pl[q.top().second]) q.pop();       int x = q.top().second;       long long len = q.top().first;       pl[x] = true;       ans += len;       tot++;       for (int i = h[x]; i; i = nx[i]) q.push(make_pair(ed[i], v[i]));     }     return ans;   }   int main() {     n = read(), m = read();     for (int i = 1; i <= m; i++) {       int u = read(), v = read(), w = read();       add(u, v, w);       add(v, u, w);     }     k = read();     for (int i = 1; i <= k; i++) po[i] = read();     spfa();     for (int i = 1; i <= cnt; i += 2) {       int x = from[i], y = ver[i];       v[++cnt1] = dis[y][0], nx[cnt1] = h[dis[x][0]], h[dis[x][0]] = cnt1;       ed[cnt1] = dis[x][1] + edge[i] + dis[y][1];       v[++cnt1] = dis[x][0], nx[cnt1] = h[dis[y][0]], h[dis[y][0]] = cnt1;       ed[cnt1] = dis[y][1] + edge[i] + dis[x][1];     }     cout << prim();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     double sum;     int n, m, k, i;     while (scanf( %d %d %d , &n, &m, &k) == 3) {       sum = 1;       if (k + n < m) {         printf( 0 n );         continue;       } else {         for (i = 0; i <= k; i++) {           sum *= (m - i);           sum /= (n + i + 1);         }         printf( %.6lf n , 1 - sum);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int N, K, C;     int fiestas[1000];     int i, j, t;     scanf( %d%d%d , &N, &K, &C);     for (i = 0; i < C; i++) scanf( %d , &fiestas[i]);     sort(fiestas, fiestas + C);     fiestas[C] = (1 << 30);     i = 0;     t = 0;     int res = 0;     while (t <= N) {       t = min(t + K, fiestas[i]);       if (t == fiestas[i]) i++;       if (t <= N) res++;     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct vahag {     int hor, ver;   };   vahag a[25][25];   const int N = 100005;   int n, m, i, j, k, q, s, w, v, ans;   string t, p;   int bfs(int i, int j) {     int qanak = 0;     bool mark[25][25] = {0};     queue<int> xx, yy;     xx.push(i);     yy.push(j);     mark[i][j] = 1;     while (!xx.empty()) {       qanak++;       int x = xx.front();       int y = yy.front();       if (x + a[x][y].ver >= 1 && x + a[x][y].ver <= n &&           mark[x + a[x][y].ver][y] == 0) {         mark[x + a[x][y].ver][y] = 1;         xx.push(x + a[x][y].ver);         yy.push(y);       }       if (y + a[x][y].hor >= 1 && y + a[x][y].hor <= m &&           mark[x][y + a[x][y].hor] == 0) {         mark[x][y + a[x][y].hor] = 1;         xx.push(x);         yy.push(y + a[x][y].hor);       }       xx.pop();       yy.pop();     }     return qanak;   }   int main() {     cin >> n >> m;     cin >> t >> p;     for (i = 0; i < t.length(); i++) {       if (t[i] ==  < )         for (j = 0; j < p.length(); j++) a[i + 1][j + 1].hor = -1;       else         for (j = 0; j < p.length(); j++) a[i + 1][j + 1].hor = 1;     }     for (j = 0; j < p.length(); j++) {       if (p[j] ==  ^ )         for (i = 0; i < t.length(); i++) a[i + 1][j + 1].ver = -1;       else         for (i = 0; i < t.length(); i++) a[i + 1][j + 1].ver = 1;     }     for (i = 1; i <= n; i++) {       for (j = 1; j <= m; j++) {         int pop = bfs(i, j);         if (pop != n * m) {           cout <<  NO  << endl;           return 0;         }       }     }     cout <<  YES  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int containsDigit(long long int number, long long int digit) {     while (number != 0) {       int curr_digit = number % 10;       if (curr_digit == digit) return 1;       number /= 10;     }     return 0;   }   long long int soltn(long long int x, long long int n) {     if (x >= 0)       return x % n;     else       return n + x % n;   }   long long int bin_srch(long long int L[], long long int N, long long int item) {     long long int flag = -2;     int l = 0, u = N - 1, m;     while (l <= u) {       m = (l + u) / 2;       if (item == L[m]) {         flag = m - 1;         break;       } else if (item > L[m])         l = m - 1;       else         u = m + 1;     }     return flag;   }   long long int modExp(long long int b, long long int p) {     long long int res = 1;     while (p > 0) {       if (p & 1) {         res = (res * b) % 1000000007;       }       b = (b * b) % 1000000007;       p >>= 1;     }     return res;   }   long long int properdiv(long long int x, long long int y) {     if (x % y == 0)       return x / y;     else       return x / y + 1;   }   long long int coda(long long int n, long long int d) {     long long int count = 0;     while (n != 0) {       if (n % 10 == d) count++;       n /= 10;     }     return count;   }   long long int mdls(long long int x) { return max(x, -x); }   int main() {     long long int i, j, k, N;     cin >> N;     string s;     cin >> s;     long long int z = 0, e = 0, n = 0, r = 0, o = 0;     for (long long int i = 0; i < N; i++) {       if (s[i] ==  z )         z++;       else if (s[i] ==  e )         e++;       else if (s[i] ==  r )         r++;       else if (s[i] ==  o )         o++;       else if (s[i] ==  n )         n++;     }     long long int one = min(min(o, n), e);     e = e - min(min(o, n), e);     o = o - min(min(o, n), e);     n = n - min(min(o, n), e);     long long int zero = min(min(z, e), min(r, o));     for (long long int i = 0; i < one; i++) cout << 1 <<    ;     for (long long int i = 0; i < zero; i++) cout << 0 <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   multiset<long long> s[200004];   long long a[200005];   long long su[200005];   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long n, k;     cin >> n >> k;     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     long long x;     for (long long i = 0; i < n; i++) {       x = 0;       while (true) {         s[a[i]].insert(x);         su[a[i]] += x;         if (s[a[i]].size() > k) {           set<long long>::iterator pointer = s[a[i]].end();           pointer--;           su[a[i]] -= *pointer;           s[a[i]].erase(pointer);         }         if (a[i] == 0) break;         a[i] /= 2;         x++;       }     }     long long minn = 1e9;     for (long long i = 0; i < 200005; i++) {       if (s[i].size() == k) {         minn = min(minn, su[i]);       }     }     cout << minn;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long q, n, t1, t2, t[200005];   int main() {     cin >> q;     while (q--) {       cin >> n;       for (int i = 0; i < n + 1; ++i) t[i] = 0;       for (int i = 0; i < n; ++i) cin >> t1, ++t[t1];       sort(t, t + n + 1);       reverse(t, t + n + 1);       long long i = 1, tp = t[0], u = t[0];       while (tp > 0 && i < n + 1) {         tp = min(tp - 1, t[i]);         u += tp;         ++i;       }       cout << u << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int tc, cs = 1;     scanf( %lld , &tc);     while (tc--) {       long long a, b, c, d;       scanf( %lld %lld , &a, &b);       scanf( %lld %lld , &c, &d);       if ((b - a) % (c + d) == 0)         cout << (b - a) / (c + d) << endl;       else         cout << -1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> a[200100];   int cnt[200100];   vector<int> res;   int main() {     int n;     scanf( %d , &n);     int q;     for (int i = 1; i <= n; i++) {       scanf( %d , &q);       a[q].push_back(i);     }     int pos = 0;     while (true) {       if (cnt[pos] < a[pos].size()) {         res.push_back(a[pos][cnt[pos]]);         cnt[pos]++;         pos++;       } else         pos -= 3;       if (pos < 0) break;     }     if (res.size() != n) {       puts( Impossible );     } else {       puts( Possible );       for (int i = 0; i < n; i++) {         printf( %d  , res[i]);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int N = 1e9 + 7;   long long int h[200009], a[200009];   int main() {     long long int n, m, i, b, j, c, d, x, y, z, k, sum = 0, l, r = 1;     vector<long long int> v;     vector<long long int>::iterator it;     cin >> n;     cout << (n / 2) + 1;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200000 + 77, LOG = 32;   int T, n, a[N], tim = 1;   int dp[N * LOG], is[N * LOG], le[N * LOG], ri[N * LOG];   inline void Add(int x) {     int cur = 1;     is[cur] = 1;     for (int i = 29; i >= 0; --i) {       if ((x >> i) & 1) {         if (ri[cur] == 0) ri[cur] = ++tim;         cur = ri[cur];       } else {         if (le[cur] == 0) le[cur] = ++tim;         cur = le[cur];       }       is[cur] = 1;     }   }   void Solve(int v) {     if (v == 0) return;     dp[v] = is[v];     Solve(le[v]);     Solve(ri[v]);     dp[v] = max(max(dp[le[v]] + is[ri[v]], dp[ri[v]] + is[le[v]]), dp[v]);   }   inline void Test() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , a + i), Add(a[i]);     Solve(1);     printf( %d n , n - dp[1]);   }   int main() {     T = 1;     while (T--) Test();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   long long int md[500];   signed main() {     ios ::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long int n;     cin >> n;     for (long long int i = 0; i < 500; i++) md[i] = -1;     for (long long int i = 0; i <= 8; i++) {       for (long long int j = 0; j <= 48; j++) {         long long int val = 4 * i + 9 * j;         val %= 49;         if (i + j > n) continue;         md[val] = max(md[val], n - i - j);       }     }     long long int ans = 0;     for (long long int i = 0; i < 500; i++) {       ans += md[i] + 1;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200005, M = N * 4;   int n, q, a[N], t, l, r, k;   struct sgt {     long long p[M], s[M];     void B(int l, int r, int k, bool t) {       if (l == r) {         if (((l & 1) && !t) || (!(l & 1) && t))           p[k] = min(0, a[l] - a[l - 1]), s[k] = a[l] - a[l - 1];         return;       }       int mid = l + r >> 1;       B(l, mid, k << 1, t);       B(mid + 1, r, k << 1 | 1, t);       p[k] = min(p[k << 1], s[k << 1] + p[k << 1 | 1]);       s[k] = s[k << 1] + s[k << 1 | 1];     }     void C(int l, int r, int x, int y, int k) {       if (l == r) {         s[k] += y;         p[k] = min(0ll, s[k]);         return;       }       int mid = l + r >> 1;       if (x <= mid)         C(l, mid, x, y, k << 1);       else         C(mid + 1, r, x, y, k << 1 | 1);       p[k] = min(p[k << 1], s[k << 1] + p[k << 1 | 1]);       s[k] = s[k << 1] + s[k << 1 | 1];     }     pair<int, int> G(int l, int r, int x, int y, int k) {       if (l == x && y == r) return make_pair(p[k], s[k]);       int mid = l + r >> 1;       pair<int, int> L, R;       if (y <= mid) return G(l, mid, x, y, k << 1);       if (x > mid) return G(mid + 1, r, x, y, k << 1 | 1);       L = G(l, mid, x, mid, k << 1);       R = G(mid + 1, r, mid + 1, y, k << 1 | 1);       return make_pair(min(L.first, L.second + R.first), L.second + R.second);     }     void C(int x, int y) { C(1, n, x, y, 1); }     long long G(int x, int y) { return G(1, n, x, y, 1).first; }     long long sum(int x, int y) { return G(1, n, x, y, 1).second; }   };   struct s_t {     sgt p0, p1;     long long G(int x) { return p0.sum(1, x) + p1.sum(1, x); }     void B() {       p0.B(1, n, 1, 0);       p1.B(1, n, 1, 1);     }     void C(int x, int y) {       if (x > n)         return;       else if (x & 1)         p0.C(x, y);       else         p1.C(x, y);     }     bool c(int l, int r) {       long long val = G(l);       if (l == r) {         if (val > 1)           return 0;         else           return 1;       }       if (l & 1) {         long long tmp = G(r);         if (!(r & 1)) tmp = 0;         if (p1.sum(l + 1, r) != tmp) return 0;         if (p1.G(l + 1, r) < 0) return 0;         if (p0.G(l + 1, r) + val < 0) return 0;       } else {         long long tmp = G(r);         if (r & 1) tmp = 0;         if (p0.sum(l + 1, r) != tmp) return 0;         if (p0.G(l + 1, r) < 0) return 0;         if (p1.G(l + 1, r) + val < 0) return 0;       }       return 1;     }   } s;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]), a[i]--;     s.B(), scanf( %d , &q);     for (int _ = 1; _ <= q; _++) {       scanf( %d , &t);       scanf( %d , &l);       scanf( %d , &r);       l++, r++;       if (t == 1)         scanf( %d , &k), s.C(l, k), s.C(r + 1, -k);       else         printf( %d n , s.c(l, r));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct UnionFind {     vector<int> data;     UnionFind(int sz) { data.assign(sz, -1); }     bool unite(int x, int y) {       x = find(x), y = find(y);       if (x == y) return (false);       if (data[x] > data[y]) swap(x, y);       data[x] += data[y];       data[y] = x;       return (true);     }     int find(int k) {       if (data[k] < 0) return (k);       return (data[k] = find(data[k]));     }     int size(int k) { return (-data[find(k)]); }   };   int N, M, D[300000];   int A[300000], B[300000];   map<pair<int, int>, int> conv;   vector<int> tree[300000];   vector<int> ans;   bool dfs(int idx, int par = -1) {     bool ret = D[idx] == 1;     for (auto &to : tree[idx]) {       if (to == par) continue;       auto p = dfs(to, idx);       if (p) ans.push_back(conv[minmax(idx, to)]);       ret ^= p;     }     return (ret);   }   int main() {     scanf( %d %d , &N, &M);     for (int i = 0; i < N; i++) {       scanf( %d , &D[i]);     }     for (int i = 0; i < M; i++) {       scanf( %d %d , &A[i], &B[i]);       --A[i], --B[i];       conv[minmax(A[i], B[i])] = i;     }     UnionFind uf(N);     int root = 0;     bool found = false;     for (int i = 0; i < M; i++) {       if (uf.unite(A[i], B[i])) {         tree[A[i]].push_back(B[i]);         tree[B[i]].push_back(A[i]);       }     }     for (int i = 0; i < N; i++) {       if (D[i] == -1) {         root = i;         found = true;       }     }     if (!dfs(root) || found) {       sort(begin(ans), end(ans));       cout << ans.size() << endl;       for (auto &idx : ans) cout << idx + 1 << endl;     } else {       cout << -1 << endl;     }   }
#include <bits/stdc++.h>   const int INF = 0x3f3f3f3f;   using namespace std;   const int N = 1000100;   bool isp[N];   void prep() {     for (int(i) = (2); (i) < (N); ++(i)) isp[i] = true;     for (int i = 2; i * i < N; i++)       if (isp[i])         for (int j = i * i; j < N; j += i) isp[j] = false;   }   int a, b, k;   bool f(int len) {     if (len > b - a + 1) return false;     int np = 0;     for (int i = 0; i < len; i++) np += isp[a + i];     if (np < k) return false;     for (int i = a + len; i <= b; i++) {       np -= isp[i - len];       np += isp[i];       if (np < k) return false;     }     return true;   }   int main() {     ios::sync_with_stdio(false);     prep();     cin >> a >> b >> k;     int lo = 1, hi = b - a + 2;     while (lo != hi) {       int mi = (lo + hi) / 2;       if (f(mi))         hi = mi;       else         lo = mi + 1;     }     if (lo == 0 || lo > b - a + 1) lo = -1;     cout << lo <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1};   const int dc[] = {0, 1, 0, -1, 1, -1, -1, 1};   const double eps = 1e-9;   const int INF = 0x7FFFFFFF;   const long long INFLL = 0x7FFFFFFFFFFFFFFFLL;   const double pi = acos(-1);   template <class T>   T take(queue<T> &O) {     T tmp = O.front();     O.pop();     return tmp;   }   template <class T>   T take(stack<T> &O) {     T tmp = O.top();     O.pop();     return tmp;   }   template <class T>   T take(priority_queue<T> &O) {     T tmp = O.top();     O.pop();     return tmp;   }   inline void getint(int &num) { scanf( %d , &num); }   inline void getint(long long &num) { cin >> num; }   long long x[3], y[3];   long long cross() {     return (x[1] - x[0]) * (y[2] - y[0]) - (x[2] - x[0]) * (y[1] - y[0]);   }   int main() {     for (int(i) = (0), _t = (3); i < (_t); ++(i)) {       getint(x[i]);       getint(y[i]);     }     long long tmp = cross();     if (tmp == 0LL)       cout <<  TOWARDS ;     else if (tmp > 0LL)       cout <<  LEFT ;     else       cout <<  RIGHT ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char a[500000 + 10];   int n, t;   int mh;   int h, s;   int go(int mid) {     int num = mid;     int cnt = 0;     int en = mh;     int last;     if (mid < h) {       int u = 0;       for (int i = 0; i < n; i++) {         if (a[i] ==  S ) {           u++;           if (u == h - mid) {             en = max(en, i);             break;           }         }       }     }     for (int i = 0; i <= en; i++) {       cnt++;       if (a[i] ==  H ) {         num--;         if (num == -1) {           if (cnt + (en - i) * 2 <= t) return 1;           last = i;         }       } else if (a[i] ==  S ) {         num++;         if (num == 0) cnt += (i - last) * 2;       }     }     if (cnt <= t)       return 1;     else       return 0;   }   int main() {     while (scanf( %d %d , &n, &t) != EOF) {       scanf( %s , a);       for (int i = n - 1; i >= 0; i--) {         if (a[i] ==  H ) {           mh = i;           break;         }       }       if (mh + 1 > t) {         printf( -1 n );         continue;       }       for (int i = 0; i < n; i++) {         if (a[i] ==  H )           h++;         else if (a[i] ==  S )           s++;       }       int l = max(0, h - s), r = h;       int mid;       while (l < r) {         mid = (l + r) / 2;         if (go(mid))           r = mid;         else           l = mid + 1;       }       printf( %d n , l);     }   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int>> adj[1001];   int vis[1001];   int main() {     long long k, b, n, t, m = 1;     cin >> k >> b >> n >> t;     while (n >= 1 && k * m + b <= t) m = k * m + b, n--;     cout << n << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dp[160][160];   int main() {     int n;     scanf( %d , &n);     dp[1][1] = 1;     dp[0][0] = 1;     for (int i = 2; i <= n; i++) {       for (int j = 0; j <= n; j++) {         if (j == 0)           dp[i][j] = dp[i - 2][j];         else           dp[i][j] = (dp[i - 2][j] + dp[i - 1][j - 1]) % 2;       }     }     cout << n << endl;     for (int i = 0; i <= n; i++) cout << dp[n][i] <<    ;     cout << endl;     cout << n - 1 << endl;     for (int i = 0; i <= n - 1; i++) cout << dp[n - 1][i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, temp;     cin >> n;     map<int, int> a, b;     for (int i = 0; i < n; i++) {       cin >> temp;       a[temp]++;     }     for (int i = 0; i < n; i++) {       cin >> temp;       b[temp]++;     }     int ans = 0, sum = 0;     vector<int> bal(6);     for (int i = 1; i < 6; i++) {       if ((a[i] + b[i]) % 2) {         cout << -1;         return 0;       }       bal[i] = a[i] - b[i];       bal[i] /= 2;       sum += bal[i];       if (bal[i] > 0) ans += bal[i];     }     if (sum) {       cout << -1;       return 0;     }     cout << abs(ans);     return 0;   }