malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int euclid(int m, int n) {     int amari;     if ((amari = m % n) == 0) {       return n;     } else {       return euclid(n, amari);     }   }   int main() {     int N;     int A[101];     cin >> N;     for (int i = 1; i <= N; i++) {       cin >> A[i];     }     vector<int> v;     bool used[101] = {};     bool flag = true;     for (int i = 1; i <= N; i++) {       if (!used[i]) {         used[i] = true;         int x = 1;         int now = i;         while (A[now] != i) {           now = A[now];           if (used[now]) {             flag = false;             break;           }           used[now] = true;           x++;         }         v.push_back(x);       }     }     if (!flag) {       cout << -1 << endl;       return 0;     }     int res = 1;     for (int i = 0; i < v.size(); i++) {       int z;       if (v[i] % 2 == 0) {         z = v[i] / 2;       } else {         z = v[i];       }       if (res > z) {         res = res * z / euclid(res, z);       } else {         res = res * z / euclid(z, res);       }     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   const int N = 100010;   const int inf = 0x3f3f3f3f;   using namespace std;   int a[N], b[N], c[N], d[N];   int main() {     int n, m, k;     scanf( %d%d%d , &n, &m, &k);     for (int i = 0; i < m; i++) scanf( %d%d%d , a + i, b + i, c + i);     long long ret = 0;     for (int i = 0; i < k; i++) {       scanf( %d , d + i);       for (int j = 0; j < m; j++) {         if (a[j] <= d[i] && d[i] <= b[j]) ret += c[j] + d[i] - a[j];       }     }     cout << ret << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 5;   int su[N], lst[N], n, i, a, lim;   long long ans;   pair<int, int> b[N];   int xb;   inline int calc(int k) {     int i, j;     long long s = 0, ans = -1, x, y, z;     xb = 0;     for (i = 0; i * k < N; ++i) {       s += 1ll * i * (su[min(N - 1, (i + 1) * k - 1)] - (i ? su[i * k - 1] : 0));       x = lst[min(N - 1, (i + 1) * k)];       if (x && x >= i * k) {         y = su[x] - su[x - 1] > 1 ? x : lst[x];         if (y >= i * k) b[++xb] = make_pair(i, y - i * k);         b[++xb] = make_pair(i, x - i * k);       }     }     for (i = 1; i <= xb; ++i) {       z = 2 * s - b[i].second;       x = z <= 0 ? 0 : (z - 1) / (k + 2) + 1;       if (x <= b[i].first) ans = max(ans, s - x);     }     y = -1;     if (k == 7) {       ++k, --k;     }     for (i = xb; i; --i) {       if (y >= 0) {         z = s - min(1ll * b[i].second, y);         x = z <= 0 ? 0 : (z - 1) / (k + 2) + 1;         if (x <= b[i].first) ans = max(ans, s - x * 2);       }       y = max(y, 1ll * b[i].second);     }     y = -1;     for (i = xb; i; --i) {       if (b[i].first < b[xb].first) {         z = s - 1 - b[i].second;         x = z <= 0 ? 0 : (z - 1) / (k + 2) + 1;         if (x <= b[i].first) ans = max(ans, s - x * 2 - 1);       }       if (y >= 0) {         z = s + 1 + k - y;         x = z <= 0 ? 0 : (z - 1) / (k + 2) + 1;         if (x <= b[i].first) ans = max(ans, s - x * 2 + 1);       }       y = max(y, 1ll * b[i].second);     }     return ans == -1 ? lim : (ans < 2 ? 0 : ans);   }   int main() {     scanf( %d , &n);     for (i = 0; i < n; ++i) scanf( %d , &a), ++su[a];     for (i = 1; i < N; ++i) lst[i] = su[i - 1] ? i - 1 : lst[i - 1];     a = lst[N - 1];     lim = max(a / 2, su[a] > 1 ? a : lst[a]);     for (i = 1; i < N; ++i) su[i] += su[i - 1];     for (i = 2; i < N; ++i) ans = max(ans, 1ll * i * calc(i));     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> s[200050 * 4];   pair<int, int> li[200050];   int n, m, st, qu[200050][3], fa[200050], sg[200050];   inline int Read() {     int x = 0;     char y;     bool z = 0;     do y = getchar(), z |= y ==  - ;     while (y <  0  || y >  9 );     do x = x * 10 + y -  0 , y = getchar();     while (y >=  0  && y <=  9 );     return z ? -x : x;   }   void Pretreat() {     int now = 0;     for (int i = 1; i <= n; i++)       if (qu[i][0] == 1)         li[++now].first = qu[i][1], li[now].second = i,         li[++now].first = qu[i][2], li[now].second = -i;     sort(li + 1, li + now + 1);     li[0].first = int(1e9);     for (int i = 1; i <= now; i++) {       st += li[i].first != li[i - 1].first;       if (li[i].second < 0)         qu[-li[i].second][2] = st;       else         qu[li[i].second][1] = st;     }     return;   }   int Find(int x) { return fa[x] == x ? x : (fa[x] = Find(fa[x])); }   inline void Update(int x, int y) {     qu[0][1] = min(qu[0][1], x);     qu[0][2] = max(qu[0][2], y);   }   void Merge(int x, int y, int z, int o) {     int i = x + y >> 1, j = z << 1;     while (!s[z].empty()) {       int k = Find(s[z].back());       s[z].pop_back();       if (k == m) continue;       Update(qu[sg[k]][1], qu[sg[k]][2]);       fa[k] = m;     }     if (x == y) return;     if (o <= i)       Merge(x, i, j, o);     else       Merge(i + 1, y, j + 1, o);   }   void Modify(int x, int y, int z, int o, int p) {     int i = x + y >> 1, j = z << 1;     if (x == o && y == p) {       s[z].push_back(m);       return;     }     if (p <= i)       Modify(x, i, j, o, p);     else if (o > i)       Modify(i + 1, y, j + 1, o, p);     else       Modify(x, i, j, o, i), Modify(i + 1, y, j + 1, i + 1, p);   }   int main() {     n = Read();     for (int i = 1; i <= n; i++)       qu[i][0] = Read(), qu[i][1] = Read(), qu[i][2] = Read();     Pretreat();     for (int i = 1; i <= n; i++)       if (qu[i][0] == 1) {         m++;         sg[fa[m] = m] = i;         qu[0][1] = qu[i][1];         qu[0][2] = qu[i][2];         Merge(1, st, 1, qu[i][1]);         Merge(1, st, 1, qu[i][2]);         qu[i][1] = qu[0][1];         qu[i][2] = qu[0][2];         if (qu[i][1] < qu[i][2] - 1) Modify(1, st, 1, qu[i][1] + 1, qu[i][2] - 1);       } else {         int k = sg[Find(qu[i][1])], l = sg[Find(qu[i][2])];         if (k == l || (qu[k][1] > qu[l][1] && qu[k][1] < qu[l][2]) ||             (qu[k][2] > qu[l][1] && qu[k][2] < qu[l][2]))           puts( YES );         else           puts( NO );       }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int tu(int val) { return (1 << val); }   bool iset(int mask, int id) {     if ((mask & tu(id)) != 0) return true;     return false;   }   void doset(int &mask, int id) { mask |= tu(id); }   void dounset(int &mask, int id) { mask = mask & (~tu(id)); }   template <typename T>   string tos(T a) {     stringstream ss;     string ret;     ss << a;     ss >> ret;     return ret;   }   const int LM = (1 << 19);   int AR[3 * LM], N;   inline void add(int pos, int val) {     pos += LM - 1;     AR[pos] += val;     while (pos /= 2) AR[pos] = AR[pos + pos] + AR[pos + pos + 1];   }   inline int get(int l, int r, int L = 1, int R = LM, int v = 1) {     if (r < L || l > R) return 0;     if (l <= L && R <= r) return AR[v];     const int mid = (L + R) / 2;     return get(l, r, L, mid, v + v) + get(l, r, mid + 1, R, v + v + 1);   }   int main() {     int q;     while (cin >> N >> q) {       memset(AR, 0, sizeof AR);       ;       int opt, oa, ob, l, r, lf, rt, dir;       l = 1, r = N;       dir = 1;       for (int i = 1; i <= N; i++) add(i, 1);       for (int(qq) = (0); (qq) < (q); (qq)++) {         scanf( %d , &opt);         if (opt == 1) {           scanf( %d , &oa);           int len = abs(l - r) + 1;           lf = l + (dir * oa) - dir;           rt = lf + dir;           if (2 * oa <= len) {             for (int(loop) = (0); (loop) < (oa); (loop)++) {               int v = get(lf, lf);               add(rt, v);               lf -= dir;               rt += dir;             }             l += oa * dir;           } else {             oa = len - oa;             for (int(loop) = (0); (loop) < (oa); (loop)++) {               int v = get(rt, rt);               add(lf, v);               lf -= dir;               rt += dir;             }             r -= oa * dir;             swap(l, r);             dir *= -1;           }         } else {           scanf( %d %d , &oa, &ob);           ob--;           int ra = l + oa * dir, rb = l + ob * dir;           if (ra > rb) swap(ra, rb);           printf( %d n , get(ra, rb));         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, k;     cin >> n >> k;     set<pair<int, int>> s;     map<int, int> m;     int temp;     for (int i = 0; i < n; i++) {       cin >> temp;       if (s.size() < k && (!m.count(temp))) {         s.insert({i + 1, temp});         m[temp] = i + 1;       }       if (!m.count(temp) || (!s.count({m[temp], temp}))) {         s.insert({i + 1, temp});         m[temp] = i + 1;         s.erase(*s.begin());       }     }     int ar[k + 10];     int c = 0;     for (auto u : s) {       ar[c] = u.second;       c++;     }     cout << c <<   n ;     for (int i = c - 1; i >= 0; i--) {       cout << ar[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int a, b;     cin >> a >> b;     a--;     string l = to_string(a);     string r = to_string(b);     long long int ans1;     if (l.length() == 1) {       ans1 = a;     } else {       if (l[0] <= l[(l.length() - 1)]) {         ans1 = (a / 10) + 9;       } else {         ans1 = (a / 10) + 8;       }     }     long long int ans2;     if (r.length() == 1) {       ans2 = b;     } else {       if (r[0] <= r[(r.length() - 1)]) {         ans2 = (b / 10) + 9;       } else {         ans2 = (b / 10) + 8;       }     }     cout << ans2 - ans1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200001;   const int mod = 998244353;   int n, m;   int sum[maxn << 2];   int y[maxn], x;   int vis[maxn];   int fac[maxn << 1], rfac[maxn << 1];   int mul(int a, int b) { return 1LL * a * b % mod; }   int qpow(int a, int q) {     int res = 1;     while (q) {       if (q & 1) res = mul(res, a);       q >>= 1;       a = mul(a, a);     }     return res;   }   void init() {     fac[0] = 1;     int n = maxn * 2;     for (int i = 1; i < n; ++i) {       fac[i] = mul(fac[i - 1], i);     }     rfac[n - 1] = qpow(fac[n - 1], mod - 2);     for (int i = n - 2; i >= 0; --i) {       rfac[i] = mul(rfac[i + 1], i + 1);     }   }   void pushup(int rt) { sum[rt] = sum[(rt << 1)] + sum[(rt << 1 | 1)]; }   void build(int rt, int l, int r) {     if (l == r) {       sum[rt] = 1;       return;     }     int mid = (l + r) / 2;     build((rt << 1), l, mid);     build((rt << 1 | 1), mid + 1, r);     pushup(rt);   }   int query(int rt, int l, int r, int val) {     if (l == r) {       return l;     }     int mid = (l + r) >> 1;     if (val <= sum[(rt << 1)]) return query((rt << 1), l, mid, val);     return query((rt << 1 | 1), mid + 1, r, val - sum[(rt << 1)]);   }   void update(int rt, int l, int r, int pos, int val) {     if (l == r) {       sum[rt] = val;       return;     }     int mid = (l + r) >> 1;     if (pos <= mid)       update((rt << 1), l, mid, pos, val);     else       update((rt << 1 | 1), mid + 1, r, pos, val);     pushup(rt);   }   int C(int a, int b) { return mul(mul(fac[a], rfac[b]), rfac[a - b]); }   int main() {     int t;     scanf( %d , &t);     init();     int len = maxn - 1;     build(1, 1, len);     while (t--) {       scanf( %d%d , &n, &m);       for (int i = 0; i < m; ++i) {         scanf( %d%d , &x, &y[i]);       }       memset(vis, 0, sizeof(vis));       int c = 0;       vector<int> ve;       for (int i = m - 1; i >= 0; --i) {         int p = query(1, 1, len, y[i]);         int q = query(1, 1, len, y[i] + 1);         update(1, 1, len, p, 0);         if (!vis[q]) {           vis[q] = 1;           ++c;         }         ve.push_back(p);       }       printf( %d n , C(2 * n - c - 1, n));       for (auto u : ve) {         update(1, 1, len, u, 1);       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   const int M = 1e9 + 7;   long long a[N];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long d;     cin >> a[0] >> a[1] >> a[2] >> d;     sort(a, a + 3);     cout << max(0ll, a[0] - a[1] + d) + max(0ll, a[1] + d - a[2]);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long n, k;       cin >> n >> k;       if (k == n) {         cout <<  Alice n ;         continue;       }       if (k > n || k % 3 != 0) {         if (n % 3 == 0) {           cout <<  Bob n ;         } else {           cout <<  Alice n ;         }         continue;       }       long long z = n % (k + 1);       if (z % 3 == 0 && z != k) {         cout <<  Bob n ;       } else {         cout <<  Alice n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long i, j, k, m, n, p, s, t, x, a[100005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     for (cin >> t; t--;) {       cin >> n >> x;       for (i = p = 0; i < n; i++) {         cin >> a[i];         if (a[i] == x) p = 1;       }       sort(a, a + n);       if (p)         cout << 1 << endl;       else if (a[n - 1] > x)         cout << 2 << endl;       else         cout << (x - 1) / a[n - 1] + 1 << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 2000000000LL;   int main() {     int m1, m2, m3, m4, m5;     int w1, w2, w3, w4, w5;     int hs, hu;     int sum;     cin >> m1 >> m2 >> m3 >> m4 >> m5;     cin >> w1 >> w2 >> w3 >> w4 >> w5;     cin >> hs >> hu;     sum = max(150, 500 - 2 * m1 - 50 * w1);     sum = sum + max(300, 1000 - 4 * m2 - 50 * w2);     sum = sum + max(450, 1500 - 6 * m3 - 50 * w3);     sum = sum + max(600, 2000 - 8 * m4 - 50 * w4);     sum = sum + max(750, 2500 - 10 * m5 - 50 * w5);     cout << sum + hs * 100 - hu * 50;     return 0;   }
/*       @uthor: Amit Kumar       user -->GitHub: drviruses ; CodeChef: dr_virus_ ; Codeforces: dr_virus_ ;AtCoder,Hackerearth,Hakerrank: dr_virus;   */   #include <bits/stdc++.h>   #include <chrono>   using namespace std;   using namespace std::chrono;   //#include <boost/multiprecision/cpp_int.hpp>   //namespace mp = boost::multiprecision;   //#define ln mp::cpp_int;   #define int      long long   #define double   long double   #define uint     unsigned long long   #define endl   n    #define all(vec) vec.begin(),vec.end()   int google_itr = 1;   #define google(x) cout<< Case # <<x<< :     #define pi 3.14159265358979323846264338327950L      vector<string> vec_splitter(string s) {           s +=  , ;           vector<string> res;           while(!s.empty()) {                   res.push_back(s.substr(0, s.find( , )));                   s = s.substr(s.find( , ) + 1);           }           return res;   }   void debug_out(   vector<string> __attribute__ ((unused)) args,   __attribute__ ((unused)) int idx,    __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }    template <typename Head, typename... Tail>   void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {           if(idx > 0) cerr <<  ,  ; else cerr <<  Line(  << LINE_NUM <<  )  ;           stringstream ss; ss << H;           cerr << args[idx] <<   =   << ss.str();           debug_out(args, idx + 1, LINE_NUM, T...);   }      #define XOX   #ifdef XOX       #define deb(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)   #else       #define deb(...) 42   #endif         const int mod = 1e9+7;   const int inf = 1e18;         void virus(){           int n;           cin >> n;              vector <int> arr(n), seq(n);           for(auto &i:arr) cin >> i;           iota(all(seq), 0);              partial_sum(all(arr), arr.begin());           partial_sum(all(seq), seq.begin());              for(auto i=0; i<n; i++) {               if(arr[i] < seq[i]) {                   cout <<  NO n ; return;               }           }              cout <<  YES n ;   }         int32_t main(){       ios_base::sync_with_stdio(false);       cin.tie(0);       cout.tie(0);            /*#ifndef ONLINE_JUDGE       freopen( input.txt , r ,stdin);       freopen( output.txt , w ,stdout);       #endif*/          int t;       cin >> t;       while(t--){              auto start = system_clock::now();              virus();              auto stop = system_clock::now();              duration<double> duration = (stop - start);              //cerr <<   nTime:  << fixed << setprecision(10) << (double)duration.count() << sec << endl;              //your code goes here       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     vector<int> a(5);     string s;     long long q = 0;     for (int i = 1; i < 5; ++i) {       cin >> a[i];     }     cin >> s;     for (int i = 0; i < (int)s.size(); ++i) {       q += a[s[i] -  0 ];     }     cout << q;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7;   const int maxn = 2e6 + 5;   int n, m, k;   int last[30], dp[maxn];   char s[maxn];   int main() {     scanf( %d%d%s , &n, &k, s + 1);     m = strlen(s + 1);     n += m;     memset(last, -1, sizeof(last));     dp[0] = 1;     for (int i = (1); i <= (n); ++i) {       if (i <= m)         if (~last[s[i] -  a ])           dp[i] = (dp[i - 1] * 2 % INF + INF - dp[last[s[i] -  a ] - 1]) % INF;         else           dp[i] = dp[i - 1] * 2 % INF;       else {         int mn = 0;         for (int j = (0); j < (k); ++j)           if (last[mn] > last[j]) mn = j;         if (~last[mn])           dp[i] = (dp[i - 1] * 2 % INF + INF - dp[last[mn] - 1]) % INF;         else           dp[i] = dp[i - 1] * 2 % INF;         s[i] = mn +  a ;       }       last[s[i] -  a ] = i;     }     printf( %d n , dp[n]);     return 0;   }
#include <bits/stdc++.h>   using std::cin;   using std::cout;   using std::deque;   using std::endl;   using std::map;   using std::max;   using std::min;   using std::pair;   using std::queue;   using std::sort;   using std::string;   using std::vector;   int main() {     char last =  b ;     char x =  b ;     while ((x = getchar()) != EOF) {       if (x >=  a  && x <=  z ) {         last = x -  a  +  A ;       } else if (x >=  A  && x <=  Z ) {         last = x;       }     }     if (last ==  A  || last ==  E  || last ==  I  || last ==  O  || last ==  U  ||         last ==  Y ) {       cout <<  YES ;     } else {       cout <<  NO ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     queue<int> q;     set<int> vals;     for (int i = 0; i < n; ++i) {       int id;       cin >> id;       if (!vals.count(id)) {         if (int(q.size()) >= k) {           int cur = q.front();           q.pop();           vals.erase(cur);         }         vals.insert(id);         q.push(id);       }     }     vector<int> res;     while (!q.empty()) {       res.push_back(q.front());       q.pop();     }     reverse(res.begin(), res.end());     cout << res.size() << endl;     for (auto it : res) cout << it <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, l[605], r[605];   string str, tmp;   stack<string> S;   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> l[i] >> r[i];     for (int i = n - 1; i >= 0; i--) {       if (l[i] == 1) {         S.push( () );         continue;       } else {         int lenth = 1;         tmp =   ;         while (!S.empty() && lenth < l[i]) {           tmp = tmp + S.top();           lenth += S.top().length();           S.pop();         }         tmp =  (  + tmp +  ) ;         S.push(tmp);         if (lenth > r[i] || lenth < l[i]) {           cout <<  IMPOSSIBLE  << endl;           return 0;         }       }     }     while (!S.empty()) {       cout << S.top();       S.pop();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100005], b[100005];   int n;   int main() {     scanf( %d n , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     b[0] = -1000000;     for (int i = 1; i <= n; i++) {       b[i] = 1000000;     }     for (int i = 0; i < n; i++) {       int j = upper_bound(b, b + n, a[i]) - b;       if (b[j - 1] < a[i] && b[j] > a[i]) {         b[j] = a[i];       }     }     for (int i = n; i >= 1; i--) {       if (b[i] < 1000000) {         printf( %d n , i);         return 0;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int t, n;   } a[200005];   int cmp(const void* a, const void* b) {     node* aa = (node*)a;     node* bb = (node*)b;     if (aa->n > bb->n) {       return 1;     } else if (aa->n == bb->n) {       return bb->t - aa->t;     } else {       return -1;     }   }   int main() {     int n, k;     while (~scanf( %d%d , &n, &k)) {       int i;       for (i = 0; i < n; i++) {         scanf( %d , &a[i].n);         a[i].t = 1;       }       for (i = 0; i < n; i++) {         scanf( %d , &a[i + n].n);         a[i + n].n = k - a[i + n].n;         a[i + n].t = 2;       }       int s1 = 0, s2 = 0;       qsort(a, 2 * n, sizeof(a[0]), cmp);       for (i = 0; i < 2 * n; i++) {         if (a[i].t == 2) {           s2++;         } else {           if (s2) {             s2--;             s1++;           }         }       }       printf( 1 %d n , s1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct tree {     int l, r, c, p;   };   int n, K, m, r;   long long res, a[10000011], b[10000011];   bool cmp1(tree a, tree b) { return a.l < b.l; }   bool cmp2(tree a, tree b) { return a.r < b.r; }   void update(int x, int l, int r, int c, int p) {     if (l == r) {       a[x] += c, b[x] += 1ll * l * c;       return;     }     int mid = (l + r) >> 1;     if (p <= mid)       update(x << 1, l, mid, c, p);     else       update(x << 1 | 1, mid + 1, r, c, p);     a[x] = a[x << 1] + a[x << 1 | 1], b[x] = b[x << 1] + b[x << 1 | 1];     return;   }   long long query(int x, int l, int r, int p) {     if (l == r) {       if (p <= a[x]) return 1ll * l * p;       return b[x];     }     int mid = (l + r) >> 1;     if (a[x << 1] >= p) return query(x << 1, l, mid, p);     return query(x << 1 | 1, mid + 1, r, p - a[x << 1]) + b[x << 1];   }   int main() {     scanf( %d%d%d , &n, &K, &m);     tree a[m + 1], b[m + 1];     for (int i = 1; i <= m; i++)       scanf( %d%d%d%d , &a[i].l, &a[i].r, &a[i].c, &a[i].p), b[i] = a[i];     for (int i = 1; i <= m; i++) r = max(r, a[i].p);     sort(a + 1, a + m + 1, cmp1);     sort(b + 1, b + m + 1, cmp2);     for (int i = 1, j = 1, k = 1; i <= n; i++) {       while (j <= m && a[j].l == i) update(1, 1, r, a[j].c, a[j].p), j++;       res += query(1, 1, r, K);       while (k <= m && b[k].r == i) update(1, 1, r, -b[k].c, b[k].p), k++;     }     printf( %lld , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, char* argv[]) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int k;     string str;     cin >> str;     cin >> k;     int temp[50];     memset(temp, 0, sizeof(temp));     int count = 0;     for (int i = 0; i < str.size(); ++i) {       if (temp[(int)(str[i] -  a )] == 0) {         count++;         temp[str[i] -  a ] = 1;       }     }     if (count >= k) {       cout <<  0  << endl;     } else if (k > (int)str.size()) {       cout <<  impossible  << endl;     } else {       cout << k - count << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long inf = 2e18;   long long mod = 1e6;   const long long M = 1e5;   string s;   long long a[M];   long long bmm(long long a, long long b) {     if (b == 0) return a;     return bmm(b, a % b);   }   int main() {     long long n;     cin >> n;     string s =   ;     for (long long i = 0; i < n; i++) {       cin >> a[i];       s +=  ? ;     }     long long su = 0;     for (long long i = n - 1; i > -1; i--) {       if (su > 0) {         s[i] =  - ;         su -= a[i];       } else {         s[i] =  + ;         su += a[i];       }     }     if (su < 0)       for (long long i = 0; i < n; i++)         if (s[i] ==  + )           s[i] =  - ;         else           s[i] =  + ;     cout << s;   }