malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long int mod = 1e9 + 7;   long long int dx[] = {0, 0, 1, -1};   long long int dy[] = {1, -1, 0, 0};   long long int m = 0, n, res = 0, k;   string s2, ch =   , s, t, s1 =   ;   vector<pair<string, long long int> > vm;   vector<pair<pair<long long int, long long int>, long long int> > vvv;   vector<pair<long long int, long long int> > vv, vv2;   vector<long long int> v[200005], v2, v1;   long long int a[500005], vis[500005], dp[500005];   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long int i = 0, x = 0, z = 0, y = 0, j = 0, q, mx = 0, idx = 0, ok = 0,                   l = 0, r = 0, negatif = 0, positif = 0, l1, r1, p, t, d;     set<pair<long long int, long long int> >::iterator itp;     cin >> n >> k >> d;     for (i = 1; i <= n; i++) {       cin >> a[i];       dp[i] = 0;     }     sort(a + 1, a + 1 + n);     dp[0] = 1;     dp[1] = -1;     for (i = 1; i <= n; i++) {       if (!dp[i - 1]) continue;       dp[i] += dp[i - 1];       x = a[i] + d;       l = i + k - 1;       r = upper_bound(a + i, a + 1 + n, x) - a - 1;       if (r >= l) {         dp[l]++;         dp[r + 1]--;       }     }     if (dp[n])       cout <<  YES ;     else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MX = (1 << 20);   class Disjoint_Set {    public:     int sz[MX], P[MX];     int find_(int x) {       if (x != P[x]) P[x] = find_(P[x]);       return P[x];     }     int comp;     void init(int N) {       for (int j = 1; j <= N; j++) sz[j] = 1, P[j] = j;       comp = N;     }     bool same(int x, int y) { return find_(x) == find_(y); }     int compsize(int node) { return sz[find_(node)]; }     bool merge_(int x, int y) {       int px = find_(x), py = find_(y);       if (px == py) return false;       if (sz[px] < sz[py]) swap(px, py);       P[py] = px;       comp--;       sz[px] += sz[py];       return true;     }   } G;   int n, m;   int main() {     scanf( %d %d , &n, &m);     if (n != m) {       puts( NO );       return 0;     }     G.init(n);     int tt = 0;     while (m--) {       int a, b;       scanf( %d %d , &a, &b);       if (!G.merge_(a, b)) tt++;     }     if (tt == 1)       puts( FHTAGN! );     else       puts( NO );   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200007;   int n, m, q, p[N], a[N], apre[N], lst[N], ppre[N], fa[N], dep[N], w[N], b[N];   vector<int> G[N];   int max(int a, int b) { return a > b ? a : b; }   int min(int a, int b) { return a < b ? a : b; }   int read() {     int x;     scanf( %d , &x);     return x;   }   void dfs(int u) {     int i, v;     b[dep[u]] = u, w[u] = dep[u] >= n ? b[dep[u] - (n - 1)] : m + 1;     for (i = G[u].size() - 1; ~i; --i) v = G[u][i], dep[v] = dep[u] + 1, dfs(v);   }   int main() {     n = read(), m = read(), q = read();     int i, j;     for (i = 1; i <= n; ++i) p[i] = read();     p[0] = p[n];     for (i = 1; i <= n; ++i) ppre[p[i]] = p[i - 1];     for (i = 1; i <= m; ++i) {       a[i] = read(), apre[i] = lst[a[i]], lst[a[i]] = i;       for (j = lst[ppre[a[i]]]; j && !fa[j]; j = apre[j]) fa[j] = i;     }     for (i = 1; i <= m; ++i) fa[i] ? G[fa[i]].push_back(i) : G[0].push_back(i);     dfs(0);     for (i = m - 1; i; --i) w[i] = min(w[i + 1], w[i]);     while (q--) i = read(), j = read(), putchar(48 + (w[i] <= j));   }
#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 1e6;   long long a[MAXN], mod = 1e9 + 7, ans;   long long power(long long x, long long y) {     if (y == 0) return 1;     long long mid = power(x, y / 2);     if (y % 2 == 1)       return mid * mid % mod * x % mod;     else       return mid * mid % mod;   }   int main() {     int n;     cin >> n;     bool is = false, is2 = false;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] % 2 == 0) is = true;       if (a[i] != 1) is2 = true;     }     for (int i = 0; i < n; i++) {       if (i == 0)         ans = power(2, a[i]);       else         ans = power(ans, a[i]);     }     ans = ans * power(2, mod - 2) % mod;     long long ans2 = ans;     long long k = -1;     if (is) k = 1;     ans = (ans + k) * power(3, mod - 2) % mod;     cout << ans <<  /  << ans2 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, i, j = 0, c1 = 0, c0 = 0;     string a, b;     vector<long long int> v0, v1;     cin >> n;     cin >> a;     cin >> b;     for (i = 0; i < n; i++) {       if (b[i] ==  0 ) {         if (a[i] ==  1 )           v1.push_back(i);         else           v0.push_back(i);       }       if (a[i] ==  0 )         c0++;       else         c1++;     }     j = v0.size() * c1;     j += (v1.size() * c0);     j -= (v1.size() * v0.size());     cout << j << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool check(long long n, long long s) {     long long sum = 0;     while (n) {       sum += n % 10;       n /= 10;     }     return sum == s;   }   int main() {     long long n, s, rt, ans = -1;     cin >> n;     for (s = 1; s < 100; s++) {       rt = sqrt(s * s + 4 * n);       if (rt * rt == s * s + 4 * n) {         if ((rt - s) % 2 == 0) {           if (check((rt - s) / 2, s)) {             if (ans == -1)               ans = (rt - s) / 2;             else               ans = min(ans, (rt - s) / 2);           }         }       }     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> e;   double best = -1;   int main() {     int n, u;     cin >> n >> u;     for (int i = 0; i < n; i++) {       int k = 0;       cin >> k;       e.push_back(k);     }     int k = 2;     for (int j = 1; j < n; j++) {       int ej = e[j];       int ei = e[j - 1];       while (k < n && e[k] - ei <= u) {         k++;       }       k--;       if (k <= j) {         continue;       }       double value = ((double)(e[k] - ej)) / (e[k] - ei);       if (value > best) {         best = value;       }     }     cout << setprecision(12) << best;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long int;   using ui = unsigned int;   using pii = pair<int, int>;   using pll = pair<int, int>;   struct fast_ios {     fast_ios() {       ios::sync_with_stdio(false);       cin.tie(NULL);     }   } fast_ios_;   ll u, v, a;   int solve() {     cin >> u >> v;     if (u > v || (v - u) & 1) return puts( -1 ), 0;     if (u + v == 0) return puts( 0 ), 0;     if (u == v) return printf( 1 n%lld n , u), 0;     a = (v - u) / 2;     if (u & a) return printf( 3 n%lld %lld %lld n , u, a, a), 0;     return printf( 2 n%lld %lld n , u + a, a), 0;   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long t, n, m, u, v, q, k;   const int N = 3e5 + 500;   const int LN = 20;   const int SN = 331;   const long long mod = 1e9 + 7;   const long long INF = 1LL << 57;   long long arr[N], brr[N];   string str, ss;   vector<int> adj[N];   vector<int> idx[N];   int d[N];   int actuald[N];   bool can[N];   bool vis[N];   void dfs(int v, int p) {     if (d[v] == -1) d[v] = 0;     vis[v] = true;     for (int i = 0; i < adj[v].size(); ++i) {       int u = adj[v][i];       if (u == p || vis[u]) continue;       dfs(u, v);       if (actuald[u] != d[u]) {         can[idx[v][i]] = true;         actuald[v]++;         actuald[u]++;         actuald[v] %= 2;         actuald[u] %= 2;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m;     int has = -1, sum = 0;     for (int i = 1; i <= n; ++i) {       cin >> d[i];       if (d[i] == -1)         has = i;       else         sum += d[i];     }     for (int i = 1; i <= m; ++i) {       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);       idx[u].push_back(i);       idx[v].push_back(i);     }     if (sum % 2 == 1 && has == -1) {       cout << -1 <<   n ;       return 0;     }     if (sum % 2 == 1) d[has] = 1;     dfs(1, 0);     sum = 0;     for (int i = 1; i <= m; ++i) {       sum += can[i];     }     cout << sum <<   n ;     for (int i = 1; i <= m; ++i) {       if (can[i]) cout << i <<    ;     }     cout <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2000200;   bool Ch(int Ans);   int n, k;   int a[N];   int c[N];   int p[N];   int main() {     cin >> n >> k;     for (int i = 1; i <= n; i++) scanf( %d , a + i), c[a[i]]++;     for (int i = 1; i < N; i++) p[i] = c[i] + p[i - 1];     sort(a + 1, a + n + 1);     for (int Ans = a[1]; Ans >= 1; Ans--)       if (Ch(Ans)) return cout << Ans, 0;     assert(0);   }   bool Ch(int Ans) {     if (Ans <= k + 1) return true;     for (int j = Ans + Ans; j <= N; j += Ans)       if (p[j - 1] - p[j - Ans + k]) return false;     return true;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> v;   int n, m;   int f() {     int ans = 0;     for (int i = 0; i < n; i++) {       int a = 10;       for (int j = i; j < n; j++) {         for (int k = i; k <= j; k++) a = min(a, v[k]);         ans += a;       }     }     return ans;   }   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) {       v.push_back(i);     }     sort(v.begin(), v.end());     int maxx = 0;     do {       maxx = max(maxx, f());     } while (next_permutation(v.begin(), v.end()));     int k = 0;     sort(v.begin(), v.end());     int c = 0;     do {       if (f() == maxx) c++;       if (c == m) {         for (auto i : v) cout << i <<    ;         break;       }     } while (next_permutation(v.begin(), v.end()));     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long powmod(long long a, long long b, long long p) {     if (b == 0) return 1;     if (b == 1) return a;     long long temp = powmod(a, b / 2, p);     temp *= temp;     temp %= p;     if (b % 2 == 0) return temp;     temp = temp * a;     temp %= p;     return temp;   }   void solve() {     int n, x, y, d;     cin >> n >> x >> y >> d;     if (abs(x - y) % d == 0) {       cout << abs(x - y) / d << endl;       ;       return;     }     long long ans = 1e18;     if (abs(y - 1) % d == 0) {       ans = (y - 1) / d;       ans += (x - 1 + d - 1) / d;     }     if ((n - y) % d == 0) {       long long ans2 = (n - y) / d;       ans2 += (n - x + d - 1) / d;       ans = min(ans, ans2);     }     if (ans > 1e10)       cout << -1 << endl;     else       cout << ans << endl;     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long pw(long long x, long long p) {     if (p == 0) return 1;     long long t = pw(x, p / 2);     if (p % 2 == 0)       return (t * t) % 1000000007;     else       return (((t * t) % 1000000007) * x) % 1000000007;   }   const long long NN = 500007;   long long parent[NN], sizee[NN];   void make_set(long long v) {     parent[v] = v;     sizee[v] = 1;   }   long long find_set(long long v) {     if (v == parent[v]) return v;     return parent[v] = find_set(parent[v]);   }   void union_sets(long long a, long long b) {     a = find_set(a);     b = find_set(b);     if (a != b) {       if (sizee[a] < sizee[b]) swap(a, b);       parent[b] = a;       sizee[a] += sizee[b];     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     map<long long, long long> m;     long long i, n, M;     long long k;     cin >> n >> M >> k;     long long a[n + 1];     for (i = 1; i <= n; i++) cin >> a[i];     long long x, y, cur = 0, virus, pos;     vector<pair<long long, long long> > edges[M + 1];     while (M--) {       cin >> x >> y;       virus = a[x] ^ a[y];       if (m.find(virus) == m.end()) {         m.insert({virus, cur});         cur++;       }       pos = m.find(virus)->second;       edges[pos].push_back({x, y});     }     long long siz, comp;     long long unsafe = 0, temp;     for (i = 0; i < cur; i++) {       set<long long> SS;       for (auto &x : edges[i]) {         make_set(x.first), make_set(x.second);         SS.insert(x.first), SS.insert(x.second);       }       siz = SS.size();       comp = siz;       for (auto &x : edges[i]) {         if (find_set(x.first) != find_set(x.second))           comp--, union_sets(x.first, x.second);       }       temp = (pw(2, siz) - pw(2, comp) + 1000000007) % 1000000007;       unsafe = (unsafe + (temp * pw(2, n - siz)) % 1000000007) % 1000000007;     }     cout << ((pw(2, k) * pw(2, n)) % 1000000007 - unsafe + 1000000007) %                 1000000007          << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long f, n;     long double a, b, ans;     while (cin >> a >> b >> n) {       long flag = 0, i, j;       for (i = -1000; i <= 1000; i++) {         ans = 1;         f = 0;         for (j = 0; j < n; j++) {           ans *= i;           if (abs(ans) > 1000) {             f = 1;             break;           }         }         if (!f)           if (a * ans == b) {             flag = 1;             break;           }       }       if (flag)         cout << i << endl;       else         cout <<  No solution n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     vector<int> x(n);     for (int i = 0; i < n; i++) cin >> x[i];     vector<int> ans(n + 1);     for (int i = 0; i < n; i++) {       int dominant = 0;       vector<int> m(n + 1);       for (int j = i; j < n; j++) {         m[x[j]]++;         if (m[x[j]] > m[dominant] or (m[x[j]] == m[dominant] and x[j] < dominant))           dominant = x[j];         ans[dominant]++;       }     }     for (int i = 1; i < n + 1; i++) cout << ans[i] <<    ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long nax = 105;   long long a[nax];   signed main() {     long long n, cnt0 = 0, cnt1 = 0;     cin >> n;     for (long long i = 1; i <= n; i++) {       cin >> a[i];       if (a[i] == 0)         cnt0++;       else         cnt1++;     }     if (cnt0 == n) {       cout << 0 << endl;       return 0;     } else if (cnt1 == n) {       cout << 1 << endl;       return 0;     }     long long idx = 0;     long long pdt = 1;     for (long long i = 1; i <= n; i++) {       if (a[i] == 1) {         if (idx == 0)           idx = i;         else {           long long temp = idx;           pdt *= i - temp;           idx = i;         }       }     }     cout << pdt << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int y[50010] = {};   int t[50010] = {};   unordered_map<int, int> ha;   bool cmp(int x, int y) { return x > y; }   bool ff(int x) {     ha.clear();     for (int i = 1; i <= n; i++) y[i] = t[i];     for (int i = 1; i <= n; i++) {       if (y[i] <= x && ha[y[i]] == 0) {         ha[y[i]] = 1;       } else {         while (1) {           if (y[i] == 1) {             return 0;           }           if (ha.find(y[i] / 2) == ha.end() && (y[i] / 2) <= x) {             ha[y[i] / 2] = 1;             break;           } else             y[i] = y[i] / 2;         }       }     }     return 1;   }   void ans(int x) {     ha.clear();     for (int i = 1; i <= n; i++) y[i] = t[i];     for (int i = 1; i <= n; i++) {       if (y[i] <= x && ha[y[i]] == 0) {         ha[y[i]] = 1;         printf( %d  , y[i]);       } else {         while (1) {           if (ha.find(y[i] / 2) == ha.end() && (y[i] / 2) <= x) {             ha[y[i] / 2] = 1;             break;           } else             y[i] = y[i] / 2;         }         printf( %d  , y[i] / 2);       }     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &t[i]);     sort(t + 1, t + n + 1, cmp);     int l = 1;     int r = 1000000000;     while (l < r) {       int mid = (l + r) / 2;       if (ff(mid))         r = mid;       else         l = mid + 1;     }     ans(l);     return 0;   }
#include <bits/stdc++.h>   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;       int m;       cin >> n >> m;       int arr[n];       for (int i = 0; i < n; i++) {         cin >> arr[i];       }       map<int, int> freq;       freq.clear();       for (int i = 0; i < m; i++) {         int curr;         cin >> curr;         freq[curr]++;       }       for (int i = 0; i < n; i++) {         for (int j = 0; j < n; j++)           if (arr[j] > arr[j + 1] && freq[j + 1]) {             swap(arr[j], arr[j + 1]);           }       }       bool possible = true;       for (int i = 0; i < n - 1; i++) {         if (arr[i] > arr[i + 1]) {           possible = false;           break;         }       }       if (possible) {         cout <<  YES  << endl;       } else {         cout <<  NO  << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void maloosh_lazma() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   int main() {     maloosh_lazma();     int n, k;     cin >> n >> k;     string s;     cin >> s;     int l, ll;     char q, qq;     for (int i = 0; i < k; i++) {       cin >> l >> ll >> q >> qq;       --l, --ll;       for (int j = l; j <= ll; j++) {         if (s[j] == q) s[j] = qq;       }     }     cout << s;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     ;     int beauty[n];     for (int asdf = 0; asdf < n; asdf++) {       cin >> beauty[asdf];     };     map<int, long long int> occ;     long long int most = 0;     for (int i = 0; i < n; i++) {       int x = i - beauty[i];       if (!occ.count(x)) occ[x] = 0LL;       occ[x] = occ[x] + beauty[i];       if (occ[x] > most) most = occ[x];     }     cout << most;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, i, ii, c;   long long xa, xb, xc, xd, mask, a[100100], b[100100];   int main() {     scanf( %d%d , &n, &m);     for (i = 0; i < n; i++) {       scanf( %I64d.%I64d.%I64d.%I64d , &xa, &xb, &xc, &xd);       a[i] = (xa << 24) + (xb << 16) + (xc << 8) + xd;     }     sort(a, a + n);     for (ii = 31; ii > 0; ii--) {       mask |= 1LL << ii;       for (c = i = 0; i < n; i++) {         b[i] = a[i] & mask;         if (i == 0 || b[i] != b[i - 1]) c++;       }       if (c == m) {         printf( %I64d.%I64d.%I64d.%I64d n , (mask >> 24) & 255,                (mask >> 16) & 255, (mask >> 8) & 255, mask & 255);         return 0;       }     }     puts( -1 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-9;   const double PI = 3.1415926535897932384626433832795;   unsigned long long mod = 1000 * 1000 * 1000 + 7;   int INF = 1000 * 1000 * 1000;   vector<int> v;   class node {    public:     node() {       left = right = NULL;       addVal = 0;     }     int from, to;     int minVal, minPos, addVal;     node *left, *right;     void build(int i, int j) {       from = i;       to = j;       if (i == j) {         minVal = v[i];         minPos = i;       } else {         int mid = (i + j) / 2;         if (i <= mid) {           left = new node();           left->build(i, mid);         }         if (mid + 1 <= j) {           right = new node();           right->build(mid + 1, j);         }         if (left->minVal < right->minVal) {           minVal = left->minVal;           minPos = left->minPos;         } else {           minVal = right->minVal;           minPos = right->minPos;         }       }     }     pair<int, int> getMin(int i, int j) {       if (i <= from && to <= j) return make_pair(minVal + addVal, minPos);       if (i > to || j < from) return make_pair(INF, -1);       pair<int, int> r1 = left->getMin(i, j);       pair<int, int> r2 = right->getMin(i, j);       r1.first += addVal;       r2.first += addVal;       return min(r1, r2);     }     void add(int i, int j, int val) {       if (i <= from && to <= j) {         addVal += val;         return;       }       if (i > to || j < from) return;       left->add(i, j, val);       right->add(i, j, val);       return;     }   } * root;   int main() {     int n;     cin >> n;     v.resize(n);     for (int i = 0; i < n; i++) cin >> v[i];     root = new node();     root->build(0, n - 1);     queue<pair<int, int> > q;     q.push(make_pair(0, n - 1));     vector<pair<int, int> > res;     while (!q.empty()) {       pair<int, int> top = q.front();       q.pop();       pair<int, int> r = root->getMin(top.first, top.second);       for (int i = 0; i < r.first; i++)         res.push_back(make_pair(top.first, top.second));       root->add(top.first, top.second, -r.first);       if (top.first <= r.second - 1) q.push(make_pair(top.first, r.second - 1));       if (r.second + 1 <= top.second) q.push(make_pair(r.second + 1, top.second));     }     cout << res.size() << endl;     for (int i = 0; i < res.size(); i++)       cout << res[i].first + 1 <<     << res[i].second + 1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long t;     cin >> t;     while (t--) {       long long n, a, b;       cin >> n >> a >> b;       string s;       cin >> s;       for (long long i = 1; i < s.length() - 1; i++) {         if (s[i] ==  0 ) {           if (s[i + 1] ==  1  && s[i - 1] ==  1 ) s[i] =  1 ;         }       }       long long c = -1;       long long ans = 0;       vector<long long> v;       for (long long i = 0; i < s.length(); i++) {         char ch = s[i];         long long d = 0;         while (s[i] == ch && i < s.length()) {           i++;           d++;         }         i--;         ans += d * a;         if (ch ==  0 )           ans += (d + 1) * b;         else           ans += (d + 1) * 2 * b;         if (ch ==  0 ) v.push_back(d);         c++;       }       ans += c * (a - b);       long long p = v.size();       if (p > 2) {         for (long long i = 1; i < p - 1; i++) {           if (2 * a > b * (v[i] - 1)) {             ans -= 2 * a;             ans += b * (v[i] - 1);           }         }       }       cout << ans << endl;     }     return 0;   }