malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   mt19937 rng(       (unsigned int)chrono::steady_clock::now().time_since_epoch().count());   const int MAGIC = 239;   const int N = 100010;   vector<int> g[N];   bool in_st[N];   bool was[N];   bool dfs(int v) {     was[v] = true;     in_st[v] = true;     for (int u : g[v]) {       if (was[u]) {         if (!in_st[u]) {           in_st[v] = false;           return false;         }       } else {         if (!dfs(u)) {           in_st[v] = false;           return false;         }       }     }     in_st[v] = false;     return true;   }   vector<int> vis;   int depth[N];   int md[N];   int md2[N];   int mver[N];   int mver2[N];   void Update(int v, int x, int y) {     if (x < md[v]) {       md2[v] = md[v];       mver2[v] = mver[v];       md[v] = x;       mver[v] = y;     } else {       if (x < md2[v]) {         md2[v] = x;         mver2[v] = y;       }     }   }   void solve(int v) {     vis.push_back(v);     was[v] = true;     md[v] = md2[v] = depth[v];     mver[v] = mver2[v] = v;     for (int u : g[v]) {       if (was[u]) {         assert(depth[u] < depth[v]);         Update(v, depth[u], u);       } else {         depth[u] = depth[v] + 1;         solve(u);         Update(v, md[u], mver[u]);         Update(v, md2[u], mver2[u]);       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int tt;     cin >> tt;     while (tt--) {       int n, m;       cin >> n >> m;       for (int i = 0; i < n; i++) {         g[i].clear();       }       for (int i = 0; i < m; i++) {         int x, y;         cin >> x >> y;         --x;         --y;         g[x].push_back(y);       }       vector<int> order(n);       iota(order.begin(), order.end(), 0);       shuffle(order.begin(), order.end(), rng);       int root = -1;       for (int iter = 0; iter < min(n, MAGIC); iter++) {         for (int i = 0; i < n; i++) {           was[i] = in_st[i] = false;         }         if (dfs(order[iter])) {           root = order[iter];           break;         }       }       if (root == -1) {         cout << -1 <<   n ;         continue;       }       for (int i = 0; i < n; i++) {         was[i] = false;       }       vis.clear();       depth[root] = 0;       solve(root);       vector<bool> is_good(n);       for (int i : vis) {         if (i == root) {           is_good[i] = true;         } else {           if (md[i] < depth[i] && md2[i] >= depth[i]) {             is_good[i] = is_good[mver[i]];           } else {             is_good[i] = false;           }         }       }       vector<int> res;       for (int i = 0; i < n; i++) {         if (is_good[i]) {           res.push_back(i);         }       }       if ((int)res.size() * 5 < n) {         cout << -1 <<   n ;         continue;       }       for (int i = 0; i < (int)res.size(); i++) {         if (i > 0) {           cout <<    ;         }         cout << res[i] + 1;       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gems[30050], maxi = INT_MIN;   int dp[30005][600], kood;   int solve(int i, int d) {     int change = 300 + (d - kood);     if (i > maxi) return 0;     if (dp[i][change] != -1) return dp[i][change];     if (d == 1) {       return dp[i][change] =                  gems[i] + max(solve(i + d, d), solve(i + d + 1, d + 1));     }     return dp[i][change] =                gems[i] + max(solve(i + d - 1, d - 1),                              max(solve(i + d, d), solve(i + d + 1, d + 1)));   }   int main() {     int n, d, x;     cin >> n >> d;     kood = d;     memset(dp, -1, sizeof(dp));     for (int i = 0; i < n; i++) {       cin >> x;       gems[x]++;       maxi = max(maxi, x);     }     cout << solve(d, d) << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   struct node {     int a, b, id;     bool operator<(const node& tem) const { return a > tem.a; }   } vec[maxn];   bool used[maxn];   int n;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &vec[i].a);     for (int i = 1; i <= n; i++) scanf( %d , &vec[i].b);     for (int i = 1; i <= n; i++) vec[i].id = i;     sort(vec + 1, vec + 1 + n);     priority_queue<pair<int, int> > q;     int pcou = 1, cnt = 0;     for (int i = 1; i <= n / 2 + 1; i++) {       while (pcou <= n && pcou <= 2 * i - 1) {         q.push(pair<int, int>(vec[pcou].b, vec[pcou].id));         ++pcou;       }       if (!q.empty()) {         ++cnt;         int id = q.top().second;         q.pop();         used[id] = 1;       }     }     printf( %d n , cnt);     for (int i = 1; i <= n; i++)       if (used[i]) printf( %d  , i);     return 0;   }
#include <bits/stdc++.h>   const int long long N = 10e8 + 7;   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int arr[n];       vector<int> odd, even;       for (int i = 0; i < n; i++) {         cin >> arr[i];         if (arr[i] % 2 == 0)           even.push_back(arr[i]);         else           odd.push_back(arr[i]);       }       int p = int(odd.size()), q = even.size();       if (p % 2 == 0 && q % 2 == 0) {         cout <<  YES  <<   n ;         continue;       }       bool flag = 0;       for (int i = 0; i < p; i++) {         for (int j = 0; j < q; j++) {           if (int(abs(even[j] - odd[i])) == 1) flag = 1;         }         if (flag) break;       }       if (flag)         cout <<  YES  <<   n ;       else         cout <<  NO  <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   set<int> st;   set<int>::iterator it;   int n, m, used[N], hmm[N];   vector<int> graph[N], vec, b[N];   void lmao() {     if (st.size() == 0) {       return;     }     it = st.begin();     int u = *it;     for (int i = 0; i < graph[u].size(); i++) {       int v = graph[u][i];       st.erase(v);     }     st.erase(u);     lmao();     for (int i = 0; i < b[u].size(); i++) {       int v = b[u][i];       if (hmm[v]) return;     }     hmm[u] = 1;     vec.push_back(u);   }   int main() {     cin.tie(0), ios::sync_with_stdio(0);     cin >> n >> m;     for (int i = 1; i <= n; i++) st.insert(i);     for (int i = 1; i <= m; i++) {       int u, v;       cin >> u >> v;       graph[u].push_back(v);       b[v].push_back(u);     }     lmao();     cout << vec.size() <<   n ;     for (int i = 0; i < vec.size(); i++) cout << vec[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   void sort_vec(vector<int> x, vector<int> b, int cnt) {     int index;     int max = 101;     for (; cnt > 0; cnt--) {       for (int j = 0; j < x.size(); j++) {         if (x[j] < max) {           index = j;           max = x[j];         }       }       cout << x[index] <<     << b[index] << endl;       x[index] = 101;       b[index] = 101;     }   }   int main() {     int x, y, a, b;     cin >> x >> y >> a >> b;     vector<int> va;     vector<int> vb;     int cnt = 0;     for (int i = b; i <= y; i++) {       for (int j = a; j <= x; j++) {         if (j <= i) continue;         cnt++;         va.push_back(j);         vb.push_back(i);       }     }     cout << cnt << endl;     int index, tmp = 101;     while (cnt > 0) {       tmp = 101;       for (int i = 0; i < va.size(); i++) {         if (va[i] < tmp) {           tmp = va[i];           index = i;         }       }       cout << va[index] <<     << vb[index] << endl;       va.erase(va.begin() + index, va.begin() + index + 1);       vb.erase(vb.begin() + index, vb.begin() + index + 1);       cnt--;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 410;   int cl[maxn * maxn];   int po[maxn * maxn];   int pre[maxn * maxn * 2];   int cnt[maxn * maxn * 2];   short cc[maxn * maxn * 2];   short F[maxn][maxn];   short g[maxn][maxn];   int a[maxn][maxn];   int b[maxn][maxn];   int pos[maxn][maxn];   int n, m;   int find(int x) { return cnt[x] ? x : pre[x] = find(pre[x]); }   inline void init(int x, short f[][maxn], int a[][maxn]) {     int tot = maxn * maxn;     for (int i = x; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cl[a[i][j]] = 0, po[a[i][j]] = a[i][j] + 1;         cc[a[i][j] + 1] = 0;         cnt[a[i][j] + 1] = 1;       }     }     for (int i = 0; i <= m; i++) f[x - 1][i] = 0;     for (int j = 1; j <= m; j++) {       for (int i = x; i <= n; i++) {         if (cl[a[i][j]] != j) {           pos[i][j] = tot;           cnt[tot] = 1;           cc[tot] = j;           pre[tot] = po[a[i][j]];           po[a[i][j]] = tot;           tot++;         } else {           pos[i][j] = po[a[i][j]];           cnt[pos[i][j]]++;         }         cl[a[i][j]] = j;       }     }     for (int i = n; i >= x; i--) {       for (int j = m; j > 0; j--) {         int p = pos[i][j];         cnt[p]--;         f[i][j] = cc[find(p)];       }     }     for (int i = x; i <= n; i++) {       for (int j = 1; j <= m; j++) {         f[i][j] = max(f[i][j], max(f[i - 1][j], f[i][j - 1]));       }     }   }   int main() {     int w = 0;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         scanf( %d , &a[i][j]);         b[i][m - j + 1] = a[i][j];       }     }     int ans = 0;     for (int i = 1; i <= n; i++) {       init(i, F, a);       init(i, g, b);       for (int j = i; j <= n; j++) {         int r = 1;         for (int k = 1; k <= m; k++) {           for (int len = m - g[j][m - k + 1]; r <= len; r++) {             if (F[j][r] >= k) break;           }           ans = max(ans, (j - i + 1) * (r - k));         }       }     }     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int N;   int mov[2][4] = {{-1, 0, 0, 1}, {0, -1, 1, 0}};   long long X[31], Y[31];   vector<int> graph[31];   void BuildTree(int node, int parent, int dir, long long dist) {     if (graph[node].size() > 4) {       cout <<  NO n ;       exit(0);     }     for (int i = 0, j = 0; i < graph[node].size(); i++)       if (graph[node][i] != parent) {         if (dir == 3 - j) j = (j + 1) % 4;         X[graph[node][i]] = X[node] + dist * mov[0][j];         Y[graph[node][i]] = Y[node] + dist * mov[1][j];         BuildTree(graph[node][i], node, j, dist / 2);         j = (j + 1) % 4;       }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie();     cin >> N;     for (int i = 0; i < N - 1; i++) {       int u, v;       cin >> u >> v;       graph[u].push_back(v);       graph[v].push_back(u);     }     BuildTree(1, 1, -1, 1ll << 30);     cout <<  YES n ;     for (int i = 1; i <= N; i++) cout << X[i] <<     << Y[i] <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   pair<int, int> a[2 * (int)(1e5 + 51)], b[2 * (int)(1e5 + 51)];   bool visited[2 * (int)(1e5 + 51)];   vector<int> g[2 * (int)(1e5 + 51)];   void dfs(int x) {     visited[x] = 1;     for (auto v : g[x]) {       if (!visited[v]) dfs(v);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       for (int i = 1; i <= n; i++) {         int x;         cin >> x;         a[i] = {x, i};       }       for (int i = 1; i <= n; i++) {         int x;         cin >> x;         b[i] = {x, i};       }       sort(a + 1, a + 1 + n);       reverse(a + 1, a + 1 + n);       sort(b + 1, b + 1 + n);       reverse(b + 1, b + 1 + n);       for (int i = 1; i < n; i++) g[a[i + 1].second].push_back({a[i].second});       for (int i = 1; i < n; i++)         if (((int)g[b[i + 1].second].size() &&              g[b[i + 1].second][0] != b[i].second) ||             !(int)g[b[i + 1].second].size())           g[b[i + 1].second].push_back(b[i].second);       dfs(b[1].second);       dfs(a[1].second);       string ans =   ;       for (int i = 1; i <= n; i++) {         if (visited[i])           ans +=  1 ;         else           ans +=  0 ;         visited[i] = 0;         g[i].clear();       }       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   long long po(long long x, long long y) {     if (y == 0)       return 1;     else       return x * po(x, y - 1);   }   vector<long long> a[7], b[7];   void solve(long long l, long long r, long long d) {     if (l == r) return;     long long m = (l + r) >> 1;     for (long long i = l; i <= m; i++) a[d].push_back(i);     for (long long i = m + 1; i <= r; i++) b[d].push_back(i);     solve(l, m, d + 1);     solve(m + 1, r, d + 1);   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       for (long long i = 0; i < 7; i++) {         a[i].clear();         b[i].clear();       }       solve(1, n, 0);       long long ans = 0;       for (long long i = 0; i < 7; i++) {         if (a[i].empty() || b[i].empty()) break;         cout << a[i].size() <<     << b[i].size() <<    ;         for (auto it : a[i]) cout << it <<    ;         for (auto it : b[i]) cout << it <<    ;         cout << endl;         long long x;         cin >> x;         ans = max(ans, x);       }       cout <<  -1   << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long x, y, n;     cin >> x >> y >> n;     long long a = -1, b = -1;     for (int i = 1; i <= n; i++) {       int t = x * i * 1.0 / y;       if (abs(t * y - i * x) > abs((t + 1) * y - i * x)) t++;       if (a == -1 || (abs(t * y - i * x) * b < abs(a * y - b * x) * i))         a = t, b = i;     }     cout << a <<  /  << b;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, i;   void input() {     cin >> n;     return;   }   void output() { return; }   void lolicon() {     n = abs(n);     while (!(i * (i + 1) / 2 >= n && (i * (i + 1) / 2 - n) % 2 == 0)) i++;     cout << i;   }   int main() {     ios_base::sync_with_stdio(false);     input();     lolicon();     output();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long M = 1e9 + 7;   const long long INF = LLONG_MAX / 2;   const long long N = 1e4;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       long long n, k;       cin >> n >> k;       string s;       cin >> s;       sort(s.begin(), s.end());       char last = s[n - 1];       vector<string> a(k);       for (long long i = 0; i < k; i++) a[i].append(1, s[i]);       long long i = k, j = 0;       if (count(a.begin(), a.end(), a[0]) == k && s[i] == last)         while (i < n) {           a[j % k].append(1, s[i]);           i++;           j++;         }       else         a[j].append(s.substr(k, n - k));       cout << *max_element(a.begin(), a.end()) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long double PI = acosl(-1);   bool compare_int(int a, int b) { return (a > b); }   bool compare_string(string a, string b) { return a.size() < b.size(); }   bool compare_pair(const pair<int, int> &a, const pair<int, int> &b) {     if (a.second == b.second)       return a.first > b.first;     else       return (a.second > b.second);   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int r, c;     cin >> r >> c;     if (r == 1 and c == 1) {       cout << 0 << endl;       return 0;     }     if (r == 1) {       for (int i = 1; i <= c; i++) cout << i + 1 <<    ;       return 0;     }     if (c == 1) {       for (int i = 1; i <= r; i++) cout << i + 1 << endl;       return 0;     }     for (int i = 1; i <= r; i++) {       for (int j = 1; j <= c; j++) {         cout << i * (r + j);         j == c ? cout << endl : cout <<    ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int n, n1, n2, mn, mx;   int A[100001];   int main() {     cin >> n >> n1 >> n2;     for (int i = 0; i < n; i++) {       cin >> A[i];     }     sort(A, A + n);     mn = min(n1, n2);     mx = max(n1, n2);     double s1 = 0;     double s2 = 0;     int nr = 0;     int k = 0;     for (int i = n - 1; k < mn; i--, k++) {       s1 = s1 + A[i];       nr = i;     }     k = 0;     for (int i = nr - 1; k < mx; i--, k++) {       s2 = s2 + A[i];     }     cout << fixed << s1 / mn + s2 / mx << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double res;   long long n, m, k, i, j, x = 1, y, t, a[1000001], b[1000001];   int main() {     cin >> n;     for (i = 1; i <= n; i++) {       cin >> t;       if (t == 1) {         cin >> k >> m;         a[k] += m;         y += k * m;         printf( %.10f , (double)y / x);         cout << endl;       }       if (t == 2) {         cin >> k;         y += k;         x++;         b[x] = k;         printf( %.10f , (double)y / x);         cout << endl;       }       if (t == 3) {         a[x - 1] += a[x];         y -= a[x] + b[x];         a[x] = 0;         x--;         printf( %.10f , (double)y / x);         cout << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const signed long long int INF = 1e9;   int main() {     int n;     cin >> n;     vector<signed long long int> a(n);     for (int i(0); i < n; i++) {       scanf( %lld , &a[i]);     }     int s, f;     scanf( %d %d , &s, &f);     vector<signed long long int> d(n + 1);     d[0] = a[0];     for (int i(1); i < n; i++) {       d[i] = d[i - 1] + a[i];     }     signed long long int ans = 0;     signed long long int tp = INF;     for (int i(0); i < n; i++) {       int l = (i + s - 1 + n) % n;       int r = (i + f - 2 + n) % n;       signed long long int tmp = 0;       if (l <= r) {         tmp += d[r];         if (l - 1 >= 0) tmp -= d[l - 1];       } else {         tmp += d[r];         tmp += d[n - 1];         if (l - 1 >= 0) tmp -= d[l - 1];       }       if (ans <= tmp) {         signed long long int ti;         if (i == 0)           ti = 1;         else           ti = n - 1 - i + 2;         if (ans == tmp) {           tp = min(tp, ti);         } else {           ans = tmp;           tp = ti;         }       }     }     cout << tp;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x;     cin >> n;     if (n % 2 == 0) {       x = n / 2;       cout << x * (x + 1);     } else {       x = (n + 1) / 2;       cout << (x - 1) * x + x;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[200009];   int s1[200009];   int s2[200009];   int id1[200009];   int id2[200009];   int main() {     int n;     cin >> n;     for (int i = 1; i <= 2 * n; ++i) id1[i] = -1;     for (int i = 1; i <= 2 * n; ++i) id2[i] = -1;     for (int i = 0; i < n; ++i) {       cin >> a[i];       if (i > 0) {         s1[i] += s1[i - 1];         s2[i] += s2[i - 1];       }       if (a[i] == 1)         s1[i]++;       else         s2[i]++;       if (id1[s1[i]] == -1) id1[s1[i]] = i;       if (id2[s2[i]] == -1) id2[s2[i]] = i;     }     vector<pair<int, int> > ans;     for (int t = 1; t <= max(s1[n - 1], s2[n - 1]); ++t) {       int ans1 = 0, ans2 = 0;       int i = 0;       bool f = false;       while (i < n) {         int i1, i2;         if (s1[i] + t - (a[i] == 1) > s1[n - 1])           i1 = n;         else {           if (a[i] == 1)             i1 = id1[s1[i] + t - 1];           else             i1 = id1[s1[i] + t];         }         if (s2[i] + t - (a[i] == 2) > s2[n - 1])           i2 = n;         else {           if (a[i] == 2)             i2 = id2[s2[i] + t - 1];           else             i2 = id2[s2[i] + t];         }         if (i1 == n && i2 == n) {           f = false;           break;         }         f = false;         if (i1 < i2) {           ++ans1;           if (ans1 > ans2) f = true;         } else {           ++ans2;           if (ans2 > ans1) f = true;         }         i = min(i1, i2) + 1;       }       if (f && ans1 != ans2) {         ans.push_back(make_pair(max(ans1, ans2), t));       }     }     sort(ans.begin(), ans.end());     cout << (int)ans.size() << endl;     for (int i = 0; i < (int)ans.size(); ++i)       cout << ans[i].first <<     << ans[i].second <<   n ;   }
#include<bits/stdc++.h>   #include<algorithm>   #define ll long long   using namespace std;   int main(){    ios_base::sync_with_stdio(false);       cin.tie(NULL);       int testcases;       cin>>testcases;       while(testcases--){        int n,k;        cin>>n>>k;        unsigned ll sum = 0 ;        cin>>sum;        unsigned ll diff = 0;        for (int i = 0; i < n-1; ++i)        {         ll current;         cin>>current;         double thiscase = (1.00*sum) / current ;         if(thiscase < (100.00/k)){          ll currentdiff = ceil((100.00*current) / k) - sum;          diff += currentdiff;          sum += currentdiff;         }           sum+= current;        }        cout<<diff<<  n ;       }   return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = pow(10, 9) + 7;   int main() {     ios_base::sync_with_stdio(false);     int k;     cin >> k;     string s;     cin >> s;     int n = s.length();     int l = 0, r = 0;     long long ans = 0LL;     long long count1 = 0;     while (l < n && k != 0) {       long long countL = 0, countr = 0;       bool found = false;       while (r < n) {         if (s[r] ==  1 ) count1++;         r++;         if (count1 == k) {           found = true;           break;         }       }       while (r < n && s[r] !=  1 ) {         countr++;         r++;       }       while (l < n && s[l] !=  1 ) {         countL++;         l++;       }       if (found) ans += (countL + 1) * (countr + 1);       count1--;       l++;     }     long long z = 0LL;     if (k == 0) {       for (int i = 0; i < n; i++) {         if (s[i] ==  0 )           z++;         else {           ans += (z * (z + 1)) / 2;           z = 0;         }       }     }     cout << (ans + (z * (z + 1)) / 2);     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, k, i, j, t;     vector<int> b, a;     vector<bool> v;     cin >> n >> k;     v.resize(n, false);     for (i = 0; i < n; i++) {       cin >> x;       b.push_back(x);       if (x == 0) {         v[i] = true;         a.push_back(i + 1);       }     }     for (i = n - 1; i >= 0; i--) {       if (!v[i]) {         t = 0;         for (j = 0; j < (int)a.size(); j++) {           if (a[j] >= i + 1 + k) {             t++;           }           if (t == b[i]) {             break;           }         }         a.insert(a.begin() + j + 1, i + 1);       }     }     for (i = 0; i < n; i++) {       cout << a[i] <<    ;     }     cout << endl;   }