malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   struct BIT {     static const int N = 200006;     long long a[N];     int n;     void init(int _n) {       n = _n;       memset(a, 0, sizeof(a));     }     void update(int pos, long long val) {       for (int i = pos; n >= i; i += i & (-i)) {         a[i] += val;       }     }     long long query(int pos) {       long long ret = 0;       for (int i = pos; i > 0; i -= i & (-i)) {         ret += a[i];       }       return ret;     }   } bit;   const int N = 200006;   const int P = 32;   set<pair<long long, long long> > st[P];   long long a[N];   void addd(long long val, int pos) {     if (!val)       st[0].insert(make_pair(pos, val));     else {       for (int i = P - 1; i >= 1; i--) {         if (val >= (1LL << (i - 1))) {           st[i].insert(make_pair(pos, val));           break;         }       }     }   }   void dell(long long val, int pos) {     if (!val)       st[0].erase(make_pair(pos, val));     else {       for (int i = P - 1; i >= 1; i--) {         if (val >= (1LL << (i - 1))) {           st[i].erase(make_pair(pos, val));           break;         }       }     }   }   int main() {     int n, q;     scanf( %d %d , &n, &q);     bit.init(n);     for (int i = 1; n >= i; i++) {       scanf( %lld , &a[i]);       bit.update(i, a[i]);       addd(a[i], i);     }     while (q--) {       int p, x;       scanf( %d %d , &p, &x);       dell(a[p], p);       bit.update(p, -a[p]);       a[p] = x;       addd(a[p], p);       bit.update(p, a[p]);       int ans = -1;       for (int i = 0; P > i; i++) {         auto iter = st[i].begin();         int cnt = 2;         while (cnt--) {           if (iter == st[i].end()) break;           pair<long long, long long> p = (*iter);           if (bit.query(p.first - 1) == p.second) {             ans = p.first;             break;           }           ++iter;         }       }       printf( %d n , ans);     }   }
#include <bits/stdc++.h>   using namespace std;   char s[200005];   bool vis[200005];   int a[200005];   int n, m;   double p;   void doit() {     memset(vis, 0, sizeof(vis));     for (int i = 1; i <= n; ++i) {       scanf( %s , s);       if (s[0] !=  ? ) {         a[i] = atoi(s);         vis[i] = 1;       }     }     for (int i = 1; i <= m; ++i) {       a[n + i] = 1001000000;       vis[n + i] = 1;     }     n += m;     long long ans = 0;     for (int i = 1; i <= m; ++i) {       int last = -1001000000, ff, t = 0;       for (int j = i; j <= n; j += m)         if (vis[j]) {           if (a[j] - last <= t) {             printf( Incorrect sequence n );             return;           }           if (!t) {             last = a[j];             continue;           }           if (last <= 0 && a[j] >= 0) {             if (last < 0 && a[j] > 0) t--;             if (!t) {               for (int k = ff; k < j; k += m) a[k] = 0;               last = a[j];               continue;             }             int k1 = max(0, last + 1), k2 = 0;             while (t) {               if (k2 + 1 < a[j]) k2++, t--;               if (!t) break;               if (k1 - 1 > last) k1--, t--;             }             last = k1 - 1;             for (int k = ff; k < j; k += m) a[k] = ++last;             last = a[j];           } else if (last > 0) {             for (int k = ff; k < j; k += m) a[k] = ++last;             last = a[j];             t = 0;           } else {             last = a[j];             for (int k = j - m; k >= ff; k -= m) a[k] = --last;             last = a[j];             t = 0;           }         } else {           t++;           if (t == 1) ff = j;         }     }     n -= m;     for (int i = 1; i <= n - 1; ++i) printf( %d  , a[i]);     printf( %d n , a[n]);   }   int main() {     while (scanf( %d%d , &n, &m) != EOF) doit();   }
#include <bits/stdc++.h>   using namespace std;   bool comp(int a, int b) { return (a < b); }   int max(int a, int b) {     if (a > b) return a;     return b;   }   int min(int a, int b) {     if (a < b) return a;     return b;   }   long long power(long long a, int x) {     while (x--) {       a *= a;     }     return a;   }   int main() {     int n, i = 0, x;     cin >> n;     string s, c;     cin >> s;     while (i < n) {       x = i;       if (s[i] ==  o )         while (s[i + 1] ==  g  && s[i + 2] ==  o ) i += 2;       if (x < i)         c +=  *** ;       else         c += s[i];       i++;     }     cout << c;   }
#include <bits/stdc++.h>   using namespace std;   long long int arr[378999];   long long int arr2[234597];   long long int ab[10];   vector<long long int> adj[22222];   map<long long int, long long int> mp, mp2;   map<long long int, long long int>::iterator it;   vector<long long int> vec;   string s;   long long int gcd(long long int a, long long int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int t, i, loss, j, diff;     cin >> t;     while (t--) {       long long int n, x, y, k, maxi = INT_MIN, mini = INT_MAX, two = 0, one1 = 0,                                 one2 = 0, zero = 0, p;       long long int cs, cw, w;       mp.clear();       mp2.clear();       string s, ans =   ;       cin >> s;       cin >> x;       long long int len = s.length();       for (i = 0; i < len; i++) {         ans +=  1 ;       }       long long int f = 0;       for (i = 0; i < len; i++) {         if (s[i] ==  1 ) {           continue;         } else if (s[i] ==  0 ) {           if (i - x >= 0) {             ans[i - x] =  0 ;           }           if (i + x < len) {             ans[i + x] =  0 ;           }         }       }       for (i = 0; i < len; i++) {         if (s[i] ==  1 ) {           if ((i - x >= 0 && ans[i - x] ==  1 ) ||               (i + x < len && ans[i + x] ==  1 ))             continue;           else {             f = 1;             break;           }         }       }       if (f == 1)         cout <<  -1 n ;       else         cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[1505];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     int ans = 0;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= i - 1; j++)         if (a[j] > a[i]) ans ^= 1;     int q;     scanf( %d , &q);     while (q--) {       int a, b;       scanf( %d%d , &a, &b);       int sz = b - a + 1;       sz = sz * (sz - 1) / 2;       if (sz % 2 == 1) ans ^= 1;       if (ans == 0)         printf( even n );       else         printf( odd n );     }   }
#include <bits/stdc++.h>   using namespace std;   int n;   string str;   int main() {     cin >> str;     n = str.length();     string str1 = str + str;     reverse(str.begin(), str.end());     string str2 = str + str;     int ans = 0;     int dp[2][2 * n];     for (int i = 0; i < 2 * n - 1; i++) {       dp[0][i] = 1;       if (i > 0 && str1[i] != str1[i - 1]) {         dp[0][i] += min(n - 1, dp[0][i - 1]);       }       ans = max(ans, dp[0][i]);     }     for (int i = 0; i < 2 * n - 1; i++) {       dp[1][i] = 1;       if (i > 0 && str2[i] != str2[i - 1]) {         dp[1][i] += min(n - 1, dp[1][i - 1]);       }       ans = max(ans, dp[1][i]);     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int a[1111111];   bool curr_state[22];   long long sum_inversions[22];   long long sum_non_inversions[22];   int tmp_array1[1111111];   int tmp_array2[1111111];   int binary_search(int i, int sz) {     if (tmp_array2[0] >= tmp_array1[i]) return -1;     int low = 0;     int high = sz - 1;     while (low < high) {       int mid = (low + high + 1) / 2;       if (tmp_array2[mid] >= tmp_array1[i])         high = mid - 1;       else         low = mid;     }     return low;   }   long long find_num_inversions(int sz) {     sort(tmp_array2, tmp_array2 + sz);     long long answer = 0;     for (int i = 0; i < sz; i++) {       int j = binary_search(i, sz);       answer += j + 1;     }     return answer;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < (1 << n); i++) scanf( %d , &a[i]);     for (int level = 1; level <= n; level++) {       sum_inversions[level - 1] = 0;       sum_non_inversions[level - 1] = 0;       for (int j = 0; j < (1 << n); j += (1 << (n - level + 1))) {         int l1 = j;         int u1 = j + (1 << (n - level)) - 1;         int l2 = j + (1 << (n - level));         int u2 = j + (1 << (n - level + 1)) - 1;         for (int i = l1; i <= u1; i++) {           tmp_array1[i - l1] = a[i];         }         for (int j = l2; j <= u2; j++) {           tmp_array2[j - l2] = a[j];         }         sum_inversions[level - 1] += find_num_inversions(u1 - l1 + 1);         for (int i = l1; i <= u1; i++) {           tmp_array2[i - l1] = a[i];         }         for (int j = l2; j <= u2; j++) {           tmp_array1[j - l2] = a[j];         }         sum_non_inversions[level - 1] += find_num_inversions(u1 - l1 + 1);       }     }     for (int i = 0; i <= n - 1; i++) {       curr_state[i] = false;     }     int m;     scanf( %d , &m);     for (int i = 1; i <= m; i++) {       int q;       scanf( %d , &q);       for (int j = n - q; j <= n - 1; j++) curr_state[j] = (!curr_state[j]);       long long answer = 0;       for (int level = 0; level <= n - 1; level++)         answer += (curr_state[level] ? sum_non_inversions[level]                                      : sum_inversions[level]);       cout << answer << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   vector<int> t;   int rec(int k, int sz, int n = 0) {     if (t[n] <= k) return k - t[n];     if (n >= sz && t[n]) return n;     int a = rec(k, sz, 2 * n + 1);     if (a >= sz)       return a;     else       return rec(a, sz, 2 * n + 2);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int n, m, q1 = 0, q2 = 0, k = 1;     cin >> n >> m;     vector<int> a(m), el;     for (int i = 0; i < m; ++i) cin >> a[i];     while (k < n) k *= 2;     k *= 2;     k--;     t.resize(k);     for (int i = 0; i < n; ++i) {       int p;       cin >> p;       if (p == 0 || p == 1) {         el.push_back(p);         int index = k / 2 + q1;         t[index] = 1;         while (index != 0) {           index = index / 2 - (index % 2 == 0);           t[index] = t[2 * index + 1] + t[2 * index + 2];         }         q1++;         q2++;       } else {         vector<int> rm;         int l = -1, r = m;         while (l + 1 < r) {           int mid = (l + r) / 2;           if (a[mid] > q2)             r = mid;           else             l = mid;         }         q2 -= l + 1;         for (int j = 0; j <= l; ++j) rm.push_back(rec(a[j] - 1, k / 2));         for (int x : rm) {           t[x] = 0;           while (x != 0) {             x = x / 2 - (x % 2 == 0);             t[x] = t[2 * x + 1] + t[2 * x + 2];           }         }       }     }     bool empty = true;     for (int i = 0; i < el.size(); ++i)       if (t[k / 2 + i]) empty = false, cout << el[i];     if (empty) cout <<  Poor stack! ;   }
#include <bits/stdc++.h>   using namespace std;   inline long long read() {     char ch = getchar();     long long nega = 1;     while (!isdigit(ch)) {       if (ch ==  - ) nega = -1;       ch = getchar();     }     long long ans = 0;     while (isdigit(ch)) {       ans = ans * 10 + ch - 48;       ch = getchar();     }     if (nega == -1) return -ans;     return ans;   }   long long a[40005], b[40005];   long long u[40005], v[40005], n, m;   signed main() {     cin >> n >> m;     for (long long i = 1; i <= n; i++) a[i] = read();     for (long long j = 1; j <= m; j++) b[j] = read();     vector<long long> s;     for (long long i = 1; i <= n; i++) {       for (long long j = 1; j <= m; j++) {         s.push_back(a[i] + b[j]);         u[a[i] + b[j] + 20000] |= (1LL << (i - 1));         v[a[i] + b[j] + 20000] |= (1LL << (j - 1));       }     }     sort(s.begin(), s.end());     s.erase(unique(s.begin(), s.end()), s.end());     long long ans = 0;     for (long long i : s) {       for (long long j : s) {         long long r = u[i + 20000] | u[j + 20000],                   s = v[i + 20000] | v[j + 20000];         ans = max(ans, 0LL + __builtin_popcountll(r) + __builtin_popcountll(s));       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline bool uin(T& a, T b) {     return a > b ? (a = b, true) : false;   }   template <class T>   inline bool uax(T& a, T b) {     return a < b ? (a = b, true) : false;   }   const int nax = 2e5 + 10;   vector<int> offer[nax];   int K[nax];   int N, M;   bool can(int day) {     vector<int> last(N, -1);     for (int i = 0; i <= min(day, nax - 1); ++i) {       for (int x : offer[i]) {         last[x] = i;       }     }     vector<int> need(K, K + N);     vector<int> temp_offer[nax];     for (int i = 0; i < N; ++i)       if (last[i] != -1) temp_offer[last[i]].push_back(i);     int money = 0;     for (int d = 0; d <= day; ++d) {       ++money;       if (d > 2e5) continue;       for (int x : temp_offer[d]) {         if (money >= need[x]) {           money -= need[x];           need[x] = 0;         } else {           need[x] -= money;           money = 0;           break;         }       }     }     for (int i = 0; i < N; ++i)       ;     ;     return money >= 2 * accumulate(need.begin(), need.end(), 0);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> N >> M;     for (int i = 0; i < N; ++i) cin >> K[i];     for (int d, t, i = 0; i < M; ++i) {       cin >> d >> t;       --d, --t;       offer[d].push_back(t);     }     for (int i = 0; i < 10; ++i)       ;     int l = 0, r = 4e5;     while (l < r) {       int m = (l + r) / 2;       ;       if (can(m))         r = m;       else         l = m + 1;     }     cout << r + 1 <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, ta;     cin >> a >> ta;     int b, tb, h = 0, m = 0, num = 0;     int totmin;     cin >> b >> tb;     string s;     cin >> s;     for (int i = 0; i < 2; i++) {       h = h * 10 + (s[i] -  0 );     }     for (int i = 3; i < 5; i++) {       m = m * 10 + (s[i] -  0 );     }     totmin = h * 60 + m;     for (int i = 5 * 60; i <= 1439; i += b) {       if ((i <= totmin && i + tb > totmin) || (i >= totmin && i < totmin + ta))         num++;     }     cout << num;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = (1ll << 32);   const int LOGN = 14;   const long long INF = (1ll << 62);   long long __gcd(long long a, long long b) {     if (b == 0) return a;     return __gcd(b, a % b);   }   bool comp(pair<int, unordered_set<int> >& a,             pair<int, unordered_set<int> >& b) {     return a.second.size() > b.second.size();   }   int main() {     std ::ios_base ::sync_with_stdio(false);     cin.tie(NULL), cout.tie(NULL);     int n, m;     cin >> n >> m;     vector<pair<int, unordered_set<int> > > a(n);     int sz;     int ct = 0;     int ct_p1 = 0;     for (int i = 0; i < n; ++i) {       cin >> sz;       ct += sz;       a[i].first = i;       int x;       for (int j = 0; j < sz; ++j) {         cin >> x;         a[i].second.insert(x);       }     }     ct_p1 = ct % n;     ct /= n;     sort(a.begin(), a.end(), comp);     int l = 0;     int r = n - 1;     vector<vector<int> > ans;     while (l < r) {       int req_l_size = ct;       int req_r_size = ct;       if (l < ct_p1) req_l_size++;       if (r < ct_p1) req_r_size++;       vector<int> temp;       for (auto it : a[l].second) {         if ((int)a[l].second.size() - (int)temp.size() == req_l_size) break;         if (a[r].second.size() == req_r_size) break;         if (a[r].second.find(it) == a[r].second.end()) {           temp.push_back(it);           a[r].second.insert(it);           vector<int> x;           x.push_back(a[l].first);           x.push_back(a[r].first);           x.push_back(it);           ans.push_back(x);         }       }       for (int i = 0; i < temp.size(); ++i) a[l].second.erase(temp[i]);       if (a[r].second.size() == req_r_size) r--;       if (a[l].second.size() == req_l_size) l++;     }     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); ++i)       cout << ans[i][0] + 1 <<     << ans[i][1] + 1 <<     << ans[i][2] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     scanf( %d , &t);     string s1, s2;     cin >> s1 >> s2;     int temp;     vector<int> index;     for (int i = 0; i < t; i++) {       temp = -1;       if (s1[i] == s2[i]) {         continue;       }       for (int j = i + 1; j < t; j++) {         if (s1[j] == s2[i]) {           temp = j;           break;         }       }       if (temp == -1) {         printf( %d , temp);         return 0;       }       for (int j = temp - 1; j >= i; j--) {         swap(s1[j], s1[j + 1]);         index.push_back(j + 1);       }     }     printf( %d n , index.size());     for (int i = 0; i < index.size(); i++) {       printf( %d  , index[i]);     }   }
#include <bits/stdc++.h>   using namespace std;   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   const long long inf = 9223372036854775807;   const long long mod = 1000000007;   const double pi = acos(-1);   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(0);     long long n, k;     cin >> n >> k;     long long val = n - (n % 2);     if (n == 1) {       if (k == 0) {         cout << 1;       } else {         cout << -1;       }       return 0;     }     if (val / 2 > k) {       cout << -1;     } else {       long long x = (val / 2 - 1);       cout << k - x <<     << (k - x) * 2 <<    ;       set<long long> s;       s.insert(k - x);       s.insert((k - x) * 2);       long long t = 2;       for (int i = 0; i < x; i++) {         if (s.find(t) == s.end() && s.find(t + 1) == s.end()) {           cout << t <<     << t + 1 <<    ;           s.insert(t);           s.insert(t + 1);           t += 2;         } else {           t += 2;           i--;         }       }       t += 2;       if (n % 2 != 0) {         while (t == (k - x) || t == (k - x) * 2) {           t++;         }         cout << t;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   bool ckmin(T& a, const T& b) {     return b < a ? a = b, 1 : 0;   }   template <class T>   bool ckmax(T& a, const T& b) {     return a < b ? a = b, 1 : 0;   }   void solve() {     int n, k;     cin >> n >> k;     vector<int> a(n);     for (int i = 0; i < (int)(n); ++i) cin >> a[i];     set<int> st;     vector<int> ans;     for (int i = 0; i < (int)(n); ++i) {       if (st.find(a[i]) == st.end()) {         ans.push_back(i + 1);       }       st.insert(a[i]);     }     if (ans.size() < k)       cout <<  NO ;     else {       cout <<  YES  <<   n ;       for (int i = 0; i < (int)(k); ++i) cout << ans[i] <<    ;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.precision(10);     int T = 1;     while (T--) {       solve();       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9 + 100;   const int MX = 200503;   int N, M, k;   int arr[MX];   int cnt[MX];   vector<int> G[MX];   int vis[MX];   vector<int> sr;   void dfs(int x) {     vis[x] = 1;     for (int i = 0; i < G[x].size(); i++) {       int ch = G[x][i];       if (vis[ch] == 1) {         sr.push_back(ch);       } else if (!vis[ch])         dfs(ch);     }     vis[x] = 2;   }   int get(int x, int p) {     int ret = arr[x];     vis[x] = 1;     for (int i = 0; i < G[x].size(); i++) {       int ch = G[x][i];       if (vis[ch]) continue;       ret = min(ret, get(ch, x));     }     return ret;   }   int main() {     scanf( %d , &N);     for (int i = 1; i <= N; i++) {       scanf( %d , &arr[i]);     }     for (int i = 1; i <= N; i++) {       int x;       scanf( %d , &x);       G[i].push_back(x);     }     long long an = 0;     for (int i = 1; i <= N; i++)       if (vis[i] == 0) dfs(i);     memset(vis, 0, sizeof vis);     for (int i = 0; i < sr.size(); i++) an += get(sr[i], -1);     cout << an <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long nChooseR(int n, int k);   long long gcd(long long a, long long b);   vector<string> split(string target, char c);   bool isPrime(long long g);   long long n, k, r, l, t, x, y, m, a[100003];   long long ans;   int main() {     string s;     cin >> s;     reverse(((s).begin()), ((s).end()));     ans = s[0] ==  1 ;     n = ((int)((s).size()));     x = 1;     for (int i = 0; i < (int)(n - 1); i++) {       x *= 4;       x %= 1000000007;       if (s[i + 1] ==  1 )         ans = ans * 2 + x;       else         ans *= 2;       ans %= 1000000007;     }     cout << ans;     return 0;   }   long long nChooseR(int n, int k) {     if (k > n) return 0;     if (k * 2 > n) k = n - k;     if (k == 0) return 1;     long long result = n;     for (int i = 2; i <= k; ++i) {       result *= (n - i + 1);       result /= i;     }     return result;   }   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   vector<string> split(string target, char c) {     string d =   ;     vector<string> arr;     for (auto n : target) {       if (n != c)         d += n;       else if (d !=   )         arr.push_back(d), d =   ;     }     if (d !=   ) arr.push_back(d), d =   ;     return arr;   }   bool isPrime(long long g) {     if ((g % 2 == 0 && g > 2) || g == 1) return 0;     for (int i = 3; i * i <= g; i += 2)       if (g % i == 0) return 0;     return 1;   }