malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   const char nl =   n ;   using vi = vector<int>;   using vll = vector<ll>;   mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());   template <typename... Args, template <typename...> typename T>   string to_string(T<Args...> const &);   string to_string(string const &s) { return     + s +    ; }   string to_string(char const &c) { return to_string(string(1, c)); }   string to_string(char const *c) { return to_string(string(c)); }   string to_string(bool const &b) { return (b ?  T  :  F ); }   template <typename... Args>   string to_string(pair<Args...> const &p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename... Args, template <typename...> typename T>   string to_string(T<Args...> const &S) {     string s =  { ;     for (auto const &e : S) s +=     + to_string(e);     s +=   } ;     return s;   }   template <typename Tail>   void debug_out(Tail t) {     cerr <<  [   << to_string(t) <<   ]  << endl;   }   template <typename Head, typename... Tail>   void debug_out(Head h, Tail... t) {     cerr <<     << to_string(h) <<  , ;     debug_out(t...);   }   template <typename T>   void dbr(T lb, T ub) {     cerr <<  { ;     for (auto it = lb; it != ub; it++) cerr <<     << to_string(*it);     cerr <<   }  << endl;   }   template <typename T, typename Comp = less<T>>   bool smin(T &mem, T const &v, Comp const &cmp = Comp()) {     return cmp(v, mem) ? mem = v, true : false;   }   template <typename T, typename Comp = less<T>>   bool smax(T &mem, T const &v, Comp const &cmp = Comp()) {     return cmp(mem, v) ? mem = v, true : false;   }   const string getEnvVar(string const &key) {     char *val = getenv(key.c_str());     return val == NULL ? string(  ) : string(val);   }   vector<string> splitString(const string &str, const string &delim =    ) {     vector<string> tokens;     size_t prev = 0, pos = 0;     do {       pos = str.find(delim, prev);       if (pos == string::npos) pos = str.length();       string token = str.substr(prev, pos - prev);       if (!token.empty()) tokens.push_back(token);       prev = pos + delim.length();     } while (pos < str.length() && prev < str.length());     return tokens;   }   void header() {     ios::sync_with_stdio(false);     cin.tie(nullptr);   }   int main() {     header();     string enc, dec =   ;     cin >> enc;     for (int i = 0; i < enc.length(); i++) {       if (enc[i] ==  . ) {         dec +=  0 ;       } else {         if (enc[i + 1] ==  . )           dec +=  1 ;         else           dec +=  2 ;         i++;       }     }     cout << dec << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long n, a[1231231];   long long mark[1231231];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     mark[1] = 1;     for (int i = 2; i <= n; i++) {       mark[i] = mark[i - 1];       mark[i] = max(mark[i], a[i] + 1);     }     for (int i = n - 1; i >= 1; i--) {       mark[i] = max(mark[i], mark[i + 1] - 1);     }     long long ans = 0;     for (int i = 1; i <= n; i++) {       ans += max(0ll, (mark[i] - 1 - a[i]));     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int a[1000000], n;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     sort(a + 1, a + n + 1);     int i = 1, j = n / 2 + 1;     int ans = n;     while (true) {       if (i > n / 2) break;       if (j > n) break;       if (2 * a[i] <= a[j]) {         i++;         j++;         ans--;       } else         j++;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int sum = 0;     char c = getchar();     bool f = 0;     while (c <  0  || c >  9 ) {       if (c ==  - ) f = 1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       sum = sum * 10 + c -  0 ;       c = getchar();     }     if (f) return -sum;     return sum;   }   const int N = 200005;   const int orz = 2000000;   const int otz = 1000000005;   int n, K, d, a[N], b[N], c[N];   namespace Seg {   int lazy[N * 4], t[N * 4], v, rch;   inline void push(int p) {     if (!lazy[p]) return;     int x = lazy[p], l = p << 1, r = (l | 1);     t[l] += x;     t[r] += x;     lazy[l] += x;     lazy[r] += x;     lazy[p] = 0;   }   inline void ch(int p, int l, int r, int L, int R) {     if (l == L && r == R) {       lazy[p] += v;       t[p] += v;       return;     }     int mid = (l + r) >> 1;     push(p);     if (R <= mid)       ch(p << 1, l, mid, L, R);     else if (L > mid)       ch(p << 1 | 1, mid + 1, r, L, R);     else       ch(p << 1, l, mid, L, mid), ch(p << 1 | 1, mid + 1, r, mid + 1, R);     t[p] = min(t[p << 1], t[p << 1 | 1]);   }   inline void ask(int p, int l, int r) {     if (l == r) {       rch = l;       return;     }     int mid = (l + r) >> 1;     push(p);     if (t[p << 1] < K)       ask(p << 1, l, mid);     else       ask(p << 1 | 1, mid + 1, r);   }   }  // namespace Seg   using namespace Seg;   int s1[N], s2[N], t1, t2;   map<int, int> H;   int main() {     int i, r, st = 1, ed = 1, ans = 1, ino = 0;     n = read();     K = read();     d = read();     for (i = 1; i <= n; i++) a[i] = read() + otz;     if (!d) {       for (i = 1; i <= n; i = r) {         r = i;         while (r <= n && a[r] == a[i]) r++;         if (r - i > ans) ans = r - i, st = i, ed = r - 1;       }       printf( %d %d , st, ed);       return 0;     }     for (i = 1; i <= n; i++) b[i] = a[i] % d, c[i] = a[i] / d;     a[0] = a[1];     b[0] = b[1];     v = orz;     ch(1, 1, n, 1, n);     for (i = 1; i <= n; i++) {       if (b[i] != b[i - 1]) v = orz, ch(1, 1, n, ino + 1, i - 1), ino = i - 1;       if (H[a[i]] > ino) v = orz, ch(1, 1, n, ino + 1, H[a[i]]), ino = H[a[i]];       while (t1 && a[i] > a[s1[t1]])         v = c[i] - c[s1[t1]], ch(1, 1, n, s1[t1 - 1] + 1, s1[t1]), t1--;       while (t2 && a[i] < a[s2[t2]])         v = c[s2[t2]] - c[i], ch(1, 1, n, s2[t2 - 1] + 1, s2[t2]), t2--;       H[a[i]] = i;       s1[++t1] = i;       s2[++t2] = i;       v = -1;       ch(1, 1, n, 1, i);       v = -orz;       ch(1, 1, n, i, i);       ask(1, 1, n);       if (i - rch + 1 > ans) ans = i - rch + 1, st = rch, ed = i;     }     printf( %d %d , st, ed);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int lowbit(int x) { return x & (-x); }   int n, K, a[16], sum[1 << 16], mp[1 << 16], b[16], fac[2001], vl[2001];   bitset<2001> f[1 << 16];   vector<int> v[16];   void construct(int cur, int sum) {     if (!cur) return;     if (sum * K <= 2000 && f[cur][sum * K]) {       for (int j = 0; j < n; j++)         if ((cur >> j) & 1) b[j]++;       construct(cur, sum * K);     } else {       for (int j = 0; j < n; j++) {         if (((cur >> j) & 1) && sum >= a[j] && f[cur ^ (1 << j)][sum - a[j]]) {           construct(cur ^ (1 << j), sum - a[j]);           return;         }       }     }   }   int main() {     scanf( %d%d , &n, &K);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     for (int i = 1; i * K <= 2000; i++) fac[i * K] = fac[i] + 1;     for (int i = 1; i <= 2000; i++) {       vl[i] = i;       for (int j = 0; j < fac[i]; j++) vl[i] /= K;     }     for (int i = 0; i < n; i++) mp[1 << i] = i;     for (int i = 1; i < (1 << n); i++) {       int t = lowbit(i);       sum[i] = sum[i ^ t] + a[mp[t]];     }     f[0][0] = 1;     for (int i = 0; i < (1 << n); i++) {       for (int j = sum[i] / K * K; j >= 0; j -= K)         f[i][j / K] = f[i][j / K] | f[i][j];       for (int j = 0; j < n; j++)         if (!((i >> j) & 1)) f[i | (1 << j)] |= f[i] << a[j];     }     if (f[(1 << n) - 1][1]) {       puts( YES );       construct((1 << n) - 1, 1);       int bpos = 0;       for (int i = 0; i < n; i++) bpos = max(bpos, b[i]), v[b[i]].push_back(a[i]);       for (int i = 1; i < n; i++) {         while (v[bpos].empty()) bpos--;         int x = v[bpos].size();         printf( %d %d n , v[bpos][x - 1], v[bpos][x - 2]);         int cur = v[bpos][x - 1] + v[bpos][x - 2];         v[bpos].pop_back();         v[bpos].pop_back();         v[bpos - fac[cur]].push_back(vl[cur]);       }     } else       puts( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   pair<int, int> d[3] = {{0, 1}, {1, 0}, {1, 1}};   int b[550][550];   void rec(int k) {     if (k == 1) {       b[0][0] = 1;       return;     }     rec(k /= 2);     for (int c = 0; c < 3; c++) {       for (int i = 0; i < k; i++) {         for (int j = 0; j < k; j++) {           b[i + d[c].first * k][j + d[c].second * k] = !b[i][j];         }       }     }   }   int main() {     cin >> k;     n = pow(2, k);     rec(n);     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) cout << (b[i][j] ?  +  :  * );       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x7FFFFFFF;   template <class T>   T gcd(T a, T b) {     return b == 0 ? a : gcd(b, a % b);   }   template <typename T>   T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   template <class T>   T big_mod(T n, T p, T m) {     if (p == 0) return (T)1;     T x = big_mod(n, p / 2, m);     x = (x * x) % m;     if (p & 1) x = (x * n) % m;     return x;   }   template <class T>   T my_pow(T n, T p) {     if (p == 0) return 1;     T x = my_pow(n, p / 2);     x = (x * x);     if (p & 1) x = (x * n);     return x;   }   template <class T>   inline T Mod(T n, T m) {     return (n % m + m) % m;   }   template <class T>   T MIN(T a, T b, T c) {     return min(a, min(b, c));   }   template <class T>   T MAX(T a, T b, T c) {     return max(a, max(b, c));   }   int n, m, segment[10000];   int main() {     cin >> n >> m;     for (int i = 1; i <= m; i++) {       int x, y;       cin >> x >> y;       for (int j = x; j <= y; j++) {         segment[j]++;       }     }     for (int i = 1; i <= n; i++) {       if (segment[i] != 1) {         printf( %d %d n , i, segment[i]);         return 0;       }     }     printf( OK n );     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   long long cp[200010];   long long find(long long x) { return cp[x] = cp[x] == x ? x : find(cp[x]); }   void union_(long long x, long long y) { cp[find(x)] = find(y); }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     for (long long j = 0; j < 200010; ++j) cp[j] = j;     long long m, n;     cin >> m >> n;     vector<long long> A(m);     vector<long long> B(n);     for (long long i = 0; i < m; ++i) cin >> A[i];     for (long long i = 0; i < n; ++i) cin >> B[i];     vector<pair<long long, pair<long long, long long>>> edg;     for (long long u = 0; u < m; ++u) {       long long s;       cin >> s;       for (long long i = 0; i < s; ++i) {         long long v;         cin >> v;         edg.push_back({B[v - 1] + A[u], {u, v - 1ll}});       }     }     sort((edg).begin(), (edg).end());     reverse((edg).begin(), (edg).end());     long long ans = 0;     for (long long k = 0; k < edg.size(); ++k) {       long long u = edg[k].second.first, v = edg[k].second.second + m;       if (find(u) == find(v)) {         ans += edg[k].first;       } else {         union_(u, v);       }     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int DIM = 1e5 + 5;   int szt[DIM], ans[DIM];   vector<int> edg[DIM];   map<int, int> son, par, out;   void dfs1(int x, int sz) {     szt[x] = 1;     for (int y : edg[x]) {       dfs1(y, sz);       szt[x] += szt[y];     }     out[szt[x]]++;     ans[x] = sz - 1;     return;   }   void add(map<int, int> &mmp, int x, int val) {     mmp[x] += val;     out[x] -= val;     if (!mmp[x]) mmp.erase(x);     if (!out[x]) out.erase(x);     return;   }   void bns(map<int, int> &mmp, int x, int le, int ri, int mnm, int aux) {     int val = ri, sol = ri;     while (le <= ri) {       int md = (le + ri) >> 1;       map<int, int>::iterator it = mmp.lower_bound(val - md + aux);       if (it == mmp.end() || it->first + mnm > md + aux)         le = md + 1;       else         ri = md - 1, sol = min(sol, md);     }     ans[x] = min(ans[x], sol);     return;   }   void dfs3(int x, int val, int pos) {     add(son, szt[x], val);     for (int y : edg[x])       if (y != pos) dfs3(y, val, pos);     return;   }   void dfs2(int x, int sz, bool oki) {     int mxm1(-1), mxm2(-1), pos(-1), mnm(sz - 1);     add(par, szt[x], 1);     for (int y : edg[x]) {       mnm = min(mnm, szt[y]);       if (mxm1 < szt[y])         mxm2 = mxm1, mxm1 = szt[y], pos = y;       else         mxm2 = max(mxm2, szt[y]);     }     if (szt[x] != sz) mnm = min(mnm, sz - szt[x]);     for (int y : edg[x])       if (y != pos) dfs2(y, sz, false);     if (pos != -1) dfs2(pos, sz, true);     if (mxm1 >= sz - szt[x]) {       mxm2 = max(mxm2, sz - szt[x]);       if (mnm != sz - 1) bns(son, x, mxm2, mxm1, mnm, 0);     }     dfs3(x, 1, pos);     add(par, szt[x], -1);     if (mxm1 <= sz - szt[x] && mnm != sz - 1) {       bns(par, x, mxm1, sz - szt[x], mnm, szt[x]);       bns(out, x, mxm1, sz - szt[x], mnm, 0);     }     if (!oki) dfs3(x, -1, -1);     return;   }   int main(void) {     int n, r(-1);     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       int x, y;       scanf( %d %d , &x, &y);       if (x == 0)         r = y;       else         edg[x].push_back(y);     }     dfs1(r, n);     dfs2(r, n, true);     for (int i = 1; i <= n; ++i) printf( %d n , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long n;     while (cin >> n) {       string s;       cin >> s;       long a[10010] = {0}, x = 0, c = 0, l;       l = s.size();       for (int i = 0; i < l; i++) {         if (i % 2 == 0) {           a[s[i]]++;         } else {           x = s[i] + 32;           if (a[x] > 0) {             a[x]--;           } else             c++;         }       }       cout << c <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long maxN = 1e6 + 5;   const long long inf = 1e10;   const long long mod = 1e9 + 7;   long long n;   long long x[maxN];   long long a, b;   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (long long i = 1; i <= n; i++) cin >> x[i];     cin >> a >> b;     sort(x + 1, x + 1 + n);     n = unique(x + 1, x + 1 + n) - (x + 1);     long long res = 0;     while (a > b) {       long long next = a - 1;       for (long long i = 1; i <= n; i++) {         long long tmp = a - a % x[i];         if (tmp < b) {           x[i--] = x[--n];         } else if (tmp < next)           next = tmp;       }       a = next;       res++;     }     cout << res;     return 0;   }
/// By: CooloTran   #include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ull = unsigned long long;   using str = string;   #define st first   #define nd second   #define pb push_back   #define pf push_front   #define lb lower_bound   #define ub upper_bound   #define er equal_range   #define file  TEST    ll gcd(ll a, ll b) {    if (b == 0) return a;    return gcd(b, a % b);   }   ll lcm(ll a, ll b) {    return a / gcd(a, b) * b;   }   ll MULMOD(ll a, ll b, ll n) {    if (b == 0) return 0;    ll tmp = MULMOD(a, b >> 1, n);    if (b & 1)    return (tmp * 2 % n + a) % n;    return tmp * 2 % n;   }   int n;   ll a[200005], cur = 0;   signed main() {    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);    // freopen(file .INP ,  r , stdin);    // freopen(file .OUT ,  w , stdout);    cin >> n;    for (int i = 1; i <= n; ++i)    cin >> a[i];    priority_queue<int, vector<int>, greater<int> > pq;    for (int i = 1; i <= n; ++i) {     if (cur + a[i] >= 0) {      cur += a[i];      pq.push(a[i]);     }     else {      if (pq.empty())      continue;      ll tmp = pq.top();      pq.pop();      if (tmp < a[i]) {       pq.push(a[i]);       cur += a[i] - tmp;      }      else pq.push(tmp);     }    }    cout << pq.size() <<   n ;    return 0;   }
#include <bits/stdc++.h>   int cmp(const void* a, const void* b);   int main() {     long long t = 1;     while (t--) {       long long n, n1, n2;       scanf( %lld%lld%lld , &n, &n1, &n2);       long long arr[n];       for (long long i = 0; i < n; i++) {         scanf( %lld , &arr[i]);       }       qsort(arr, n, sizeof(arr[0]), cmp);       double s1 = 0, s2 = 0;       if (n2 < n1) {         long long x = n2;         n2 = n1;         n1 = x;       }       if (1) {         for (long long i = 0; i < n1; i++) s1 += arr[i];         for (long long i = n1; i < n1 + n2; i++) s2 += arr[i];       }       printf( %f n , s1 / n1 + s2 / n2);     }     return 0;   }   int cmp(const void* a, const void* b) { return (*(int*)b - *(int*)a); }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k;     cin >> n >> k;     long long a[k + 1];     for (long long i = 0; i < k; i++) {       cin >> a[i];     }     long long c4 = n, c2 = 2 * n;     long long o1 = 0;     for (long long i = 0; i < k; i++) {       while (c4 > 0 && a[i] > 3) {         c4 -= 1;         a[i] -= 4;       }       while (c2 >= 2 && a[i] > 3) {         c2 -= 2;         a[i] -= 4;       }       if (a[i] >= 3) {         while (c4 > 0 && a[i] > 0) {           c4 -= 1;           a[i] -= 3;         }         while (c2 >= 2 && a[i] > 0) {           c2 -= 2;           a[i] -= 3;         }       }       if (a[i] >= 2) {         while (c2 > 0 && a[i] > 0) {           c2 -= 1;           a[i] -= 2;         }         while (c4 > 0 && a[i] > 0) {           c4 -= 1;           o1++;           a[i] -= 2;         }       }       if (a[i] > 0) {         while (o1 > 0 && a[i] > 0) {           o1--;           a[i]--;         }         while (c4 > 0 && a[i] > 0) {           c4 -= 1;           a[i] -= 1;           c2++;         }         while (a[i] > 0 && c2 > 0) {           c2 -= 1;           a[i] -= 1;         }       }       if (a[i] > 0) {         cout <<  NO  << endl;         return 0;       }     }     cout <<  YES  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int i, num = 0;     for (i = 1; i <= 5; i++) {       int temp;       scanf( %d , &temp);       num += temp;     }     if (num % 5 || num == 0) {       printf( -1 n );     } else {       printf( %d n , num / 5);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s;   int main() {     ios_base::sync_with_stdio(false);     cin >> s;     bool f = false;     for (int i = 0; i < s.size() / 2; i++)       if (s[0] != s[i] or s[0] != s[s.size() - i - 1]) {         f = true;         break;       }     if (!f) {       cout <<  Impossible  << endl;       return 0;     }     for (int i = 1; i < s.size() - 1; i++) {       string v = s.substr(i, s.size() - i) + s.substr(0, i);       string w = v;       reverse(w.begin(), w.end());       if (v == w and v != s) {         cout << 1 << endl;         return 0;       }     }     cout << 2 << endl;     return 0;   }
#include <bits/stdc++.h>   static const int MaxSize = 1e5;   int tree[4 * MaxSize][2];   static void build(std::vector<int> &v, int vertex, int tl, int tr) {     if (tl == tr)       tree[vertex][0] = v[tl];     else {       int tm = (tl + tr) / 2;       build(v, 2 * vertex + 1, tl, tm + 0);       build(v, 2 * vertex + 2, tm + 1, tr);       tree[vertex][0] =           std::min(tree[2 * vertex + 1][0], tree[2 * vertex + 2][0]);     }   }   static void update(int vertex, int tl, int tr, int l, int r, int x) {     if (l > r) return;     if (l == tl && tr == r)       tree[vertex][1] += x;     else {       int tm = (tl + tr) / 2;       update(2 * vertex + 1, tl, tm + 0, l, std::min(r, tm + 0), x);       update(2 * vertex + 2, tm + 1, tr, std::max(l, tm + 1), r, x);       tree[vertex][0] =           std::min(tree[2 * vertex + 1][0] + tree[2 * vertex + 1][1],                    tree[2 * vertex + 2][0] + tree[2 * vertex + 2][1]);     }   }   static int get(int vertex, int tl, int tr, int l, int r, int x) {     if (l == tl && tr == r) return tree[vertex][0] + tree[vertex][1];     x += tree[vertex][1];     int tm = (tl + tr) / 2;     return std::min(         x + get(2 * vertex + 1, tl, tm + 0, l, std::min(r, tm + 0), x),         x + get(2 * vertex + 2, tm + 1, tr, std::max(l, tm + 1), r, x));   }   static void build(std::vector<int> &v, int n) { build(v, 0, 0, n - 1); }   static void update(int n, int l, int r, int x) { update(0, 0, n - 1, l, r, x); }   static int get(int n, int l, int r) { return get(0, 0, n - 1, l, r, 0); }   int main(int argc, const char *argv[]) {     std::ios_base::sync_with_stdio(false);     std::cin.tie(NULL);     int n, m;     std::cin >> n >> m;     std::vector<int> v(n), tree(4 * n);     for (int i = 0; i < n; i++) std::cin >> v[i];     std::vector<std::pair<int, int>> p(m);     for (int i = 0; i < m; i++) {       std::cin >> p[i].first >> p[i].second;       p[i].first--;       p[i].second--;     }     build(v, n);     std::vector<bool> used(m);     std::vector<int> t(4 * n), r;     int result = 0;     for (int i = 0; i < n; i++) {       std::vector<int> intervals;       for (int j = 0; j < m; j++) {         if (p[j].first <= i && i <= p[j].second) {           if (used[j]) {             used[j] = false;             update(n, p[j].first, p[j].second, 1);           }         } else {           if (!used[j]) update(n, p[j].first, p[j].second, -1);           intervals.push_back(j + 1);           used[j] = true;         }       }       int curr = v[i] - get(n, 0, n - 1);       if (result < curr) {         result = curr;         std::swap(r, intervals);       }     }     std::cout << result << std::endl;     std::cout << r.size() << std::endl;     if (r.size() > 0) {       for (int number : r) std::cout << number <<    ;       std::cout << std::endl;     }     return 0;   }