malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int maxn = 3e5 + 5;   int n, a, b;   string s;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int q;     cin >> q;     while (q--) {       int a, b;       cin >> a >> b;       cin >> s;       n = s.size();       vector<int> sz(n, 0);       vector<int> segs;       for (int i = 0; i < n; i++) {         if (s[i] !=  . ) continue;         sz[i] = i == 0 ? 1 : sz[i - 1] + 1;         if (i == n - 1 || s[i + 1] !=  . ) segs.push_back(sz[i]);       }       int numSmall = 0;       int numBig = 0;       for (int i : segs) {         if (b <= i && i < a)           numSmall++;         else if (i >= 2 * b)           numBig++;       }       if (numSmall > 0) {         cout <<  NO n ;       } else {         if (numBig >= 2) {           cout <<  NO n ;         } else if (numBig == 0) {           int cnt = 0;           for (int i : segs) {             if (i >= a) cnt++;           }           cout << (cnt & 1 ?  YES  :  NO ) <<   n ;         } else if (numBig == 1) {           int mxSize = 0;           for (int i : segs) {             mxSize = max(mxSize, i);           }           int cnt = 0;           for (int i : segs) {             if (i == mxSize) continue;             if (i >= a) cnt++;           }           if (a > mxSize) {             cout <<  NO n ;             return 0;           }           int s1 = 0, s2 = mxSize - a;           bool canWin = false;           for (; s2 >= 0; s1++, s2--) {             if ((b <= s1 && s1 < a) || (b <= s2 && s2 < a)) continue;             if (s1 >= 2 * b || s2 >= 2 * b) continue;             int c = cnt;             if (s1 >= a) c++;             if (s2 >= a) c++;             if (c % 2 == 0) {               canWin = true;               break;             }           }           cout << (canWin ?  YES  :  NO ) <<   n ;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   int ans1[300003], ans2[300003], l[300003];   vector<int> t[2400024];   vector<int> a, q;   void build(int v, int tl, int tr) {     if (tl == tr) {       t[v].push_back(a[tl]);       return;     }     int mid = (tl + tr) / 2;     build(v * 2, tl, mid);     build(v * 2 + 1, mid + 1, tr);     int l = 0, r = 0;     t[v].reserve(t[v * 2].size() + t[v * 2 + 1].size());     while (l != t[v * 2].size() || r != t[v * 2 + 1].size()) {       if (l == t[v * 2].size()) {         t[v].push_back(t[v * 2 + 1][r++]);       } else if (r == t[v * 2 + 1].size()) {         t[v].push_back(t[v * 2][l++]);       } else if (t[v * 2][l] < t[v * 2 + 1][r]) {         t[v].push_back(t[v * 2][l++]);       } else {         t[v].push_back(t[v * 2 + 1][r++]);       }     }   }   int ask(int v, int tl, int tr, int l, int r, int x) {     if (l > r) {       return 0;     }     if (tl == l && tr == r) {       l = -1;       r = t[v].size();       while (r - l > 1) {         int mid = (r + l) / 2;         if (t[v][mid] < x) {           l = mid;         } else {           r = mid;         }       }       return r;     }     int mid = (tl + tr) / 2;     return ask(v * 2, tl, mid, l, min(r, mid), x) +            ask(v * 2 + 1, mid + 1, tr, max(l, mid + 1), r, x);   }   int main() {     int n, m;     cin >> n >> m;     a.push_back(1e9 + 7);     for (int i = n; i > 0; --i) {       ans1[i] = i;       l[i] = a.size();       a.push_back(0);     }     while (m--) {       int x;       cin >> x;       ans1[x] = 1;       q.push_back(x);       a.push_back(l[x]);       l[x] = a.size() - 1;     }     build(1, 0, a.size() - 1);     for (int i = n + 1; i < a.size(); ++i) {       ans2[q[i - n - 1]] =           max(ans2[q[i - n - 1]], ask(1, 0, a.size() - 1, a[i], i, a[i]));     }     for (int i = 1; i <= n; ++i) {       ans2[i] = max(ans2[i], ask(1, 0, a.size() - 1, l[i], a.size() - 1, l[i]));       cout << ans1[i] <<     << ans2[i] << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, a[(1 << 20)];   vector<int> odd, ev;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int s = 0, f = n - 1; s < f; s++, f--) {       if (s % 2 == 0) {         swap(a[s], a[f]);       }     }     for (int i = 0; i < n; i++) {       cout << a[i] <<    ;     }     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   vector<int> v1[maxn], v2[maxn];   int n, lazy[maxn << 2], minnode[maxn << 2], maxnode[maxn << 2];   long long sumnode[maxn << 2];   void modify(int rt, int l, int r, int c) {     lazy[rt] = c;     minnode[rt] = maxnode[rt] = c;     sumnode[rt] = (r - l + 1LL) * (n + 1 - c);   }   void pushup(int rt) {     sumnode[rt] = sumnode[rt << 1] + sumnode[rt << 1 | 1];     minnode[rt] = min(minnode[rt << 1], minnode[rt << 1 | 1]);     maxnode[rt] = max(maxnode[rt << 1], maxnode[rt << 1 | 1]);   }   void pushdown(int rt, int l, int r) {     if (lazy[rt]) {       int m = (l + r) >> 1;       modify(rt << 1, l, m, lazy[rt]);       modify(rt << 1 | 1, m + 1, r, lazy[rt]);       lazy[rt] = 0;     }   }   void build(int rt, int l, int r) {     lazy[rt] = 0;     if (l == r) {       minnode[rt] = l;       sumnode[rt] = n - l + 1;       return;     }     int m = (l + r) >> 1;     build(rt << 1, l, m), build(rt << 1 | 1, m + 1, r);     pushup(rt);   }   void update(int rt, int l, int r, int x, int y, int c) {     if (c <= minnode[rt]) return;     if (x <= l && r <= y && maxnode[rt] <= c) {       modify(rt, l, r, c);       return;     }     pushdown(rt, l, r);     int m = (l + r) >> 1;     if (x <= m) update(rt << 1, l, m, x, y, c);     if (m < y) update(rt << 1 | 1, m + 1, r, x, y, c);     pushup(rt);   }   void init() {     for (int i = 1; i < maxn; ++i) {       for (int j = i; j < maxn; j += i) v1[j].push_back(i);     }   }   int main() {     init();     scanf( %d , &n);     int mx = 0;     for (int i = 1; i <= n; ++i) {       int x;       scanf( %d , &x);       mx = max(x, mx);       for (int j = 0; j < v1[x].size(); ++j) v2[v1[x][j]].push_back(i);     }     build(1, 1, n);     long long ans = 0, cur = sumnode[1];     for (int i = mx; i; --i) {       if (v2[i].size() > 1) {         int p = v2[i][0], q = v2[i][1];         if (q < n) update(1, 1, n, q + 1, n, n + 1);         update(1, 1, n, p + 1, q, v2[i].back());         update(1, 1, n, 1, p, v2[i][v2[i].size() - 2]);         ans += i * (cur - sumnode[1]);         cur = sumnode[1];       }     }     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int t[4000005];   void update(long long int v, long long int tl, long long int tr,               long long int pos) {     if (tl == tr) {       t[v]++;       return;     }     long long int tm = (tl + tr) / 2;     if (pos <= tm)       update(2 * v, tl, tm, pos);     else       update(2 * v + 1, tm + 1, tr, pos);     t[v] = t[2 * v] + t[2 * v + 1];   }   long long int sum(long long int v, long long int tl, long long int tr,                     long long int l, long long int r) {     if (l > r) return 0;     if (l == tl && r == tr) return t[v];     long long int tm = (tl + tr) / 2;     return sum(2 * v, tl, tm, l, min(r, tm)) +            sum(2 * v + 1, tm + 1, tr, max(l, tm + 1), r);   }   void solve() {     long long int n, k;     cin >> n >> k;     if (k >= (n + 1) / 2) k = n - k;     long long int cnt = n, x = 1, cur = 1;     while (cnt) {       long long int y = x + k;       if (y > n) y -= n;       long long int s = x + 1, e = y - 1, val;       if (s == n + 1) s = 1;       if (e == 0) e = n;       if (s <= e)         val = sum(1, 1, n, s, e);       else         val = sum(1, 1, n, s, n) + sum(1, 1, n, 1, e);       cur += val + 1;       cout << cur <<    ;       update(1, 1, n, x);       update(1, 1, n, y);       x = y;       cnt--;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     clock_t z = clock();     long long int qc = 1;     for (long long int i = 1; i <= qc; i++) {       solve();     }     fprintf(stderr,  Total Time:%.4Lf n ,             (long double)(clock() - z) / CLOCKS_PER_SEC),         fflush(stderr);   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   bool chmax(T &a, const T &b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   template <class T>   bool chmin(T &a, const T &b) {     if (a > b) {       a = b;       return 1;     }     return 0;   }   template <class T>   ostream &operator<<(ostream &os, const vector<T> &t) {     os <<  [ ;     for (__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++) {       if (it != t.begin()) os <<  , ;       os << *it;     }     os <<  ] ;     return os;   }   template <class T>   ostream &operator<<(ostream &os, const set<T> &t) {     os <<  { ;     for (__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++) {       if (it != t.begin()) os <<  , ;       os << *it;     }     os <<  } ;     return os;   }   template <class S, class T>   ostream &operator<<(ostream &os, const pair<S, T> &t) {     return os <<  (  << t.first <<  ,  << t.second <<  ) ;   }   template <class S, class T>   pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) {     return pair<S, T>(s.first + t.first, s.second + t.second);   }   template <class S, class T>   pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) {     return pair<S, T>(s.first - t.first, s.second - t.second);   }   const int INF = 1 << 28;   const double EPS = 1e-8;   const int MOD = 1000000007;   int n, m, t;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     scanf( %d%d%d , &n, &m, &t);     deque<pair<int, int> > ends;     int ans = 0, accept = 0;     vector<int> idxs(n);     for (int i = 0; i < (int)(n); i++) {       int h, mm, s, x;       scanf( %d:%d:%d , &h, &mm, &s);       x = h * 3600 + mm * 60 + s;       while (!ends.empty() && ends.front().first <= x) {         idxs[ends.front().second] = 1;         ans++;         ends.pop_front();       }       ends.emplace_back(x + t, i);       if (ends.size() == m) accept = 1;       while (ends.size() > m) {         idxs[ends.back().second] = 0;         ends.pop_back();         ends.back().first = x + t;       }     }     while (!ends.empty()) {       idxs[ends.back().second] = 1;       ans++;       ends.pop_back();     }     if (!accept) {       puts( No solution );       return 0;     }     int sum = 0;     printf( %d n , ans);     for (int i = 0; i < (int)(n); i++) printf( %d n , sum += idxs[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   int tim;   int t[maxn];   int sum[maxn], sum2[maxn];   int in[maxn], ou[maxn], dfn[maxn];   vector<int> G[maxn];   void dfs(int rt, int fa) {     in[rt] = ++tim;     dfn[tim] = rt;     for (int i = 0; i < G[rt].size(); i++) {       int to = G[rt][i];       if (to == fa) continue;       dfs(to, rt);     }     ou[rt] = tim;   }   struct T {     int l, r, mid;     int add, sum;   } tree[maxn << 2];   void push_up(int rt) {     tree[rt].sum = tree[rt << 1].sum + tree[rt << 1 | 1].sum;   }   void push_down(int rt) {     if (tree[rt].add) {       tree[rt << 1].add ^= 1;       tree[rt << 1].sum =           (tree[rt << 1].r - tree[rt << 1].l + 1) - tree[rt << 1].sum;       tree[rt << 1 | 1].add ^= 1;       tree[rt << 1 | 1].sum =           (tree[rt << 1 | 1].r - tree[rt << 1 | 1].l + 1) - tree[rt << 1 | 1].sum;       tree[rt].add = 0;     }   }   void build(int rt, int l, int r) {     tree[rt].add = 0;     tree[rt].l = l;     tree[rt].r = r;     if (l == r) {       tree[rt].sum = t[dfn[l]];       return;     }     int mid = tree[rt].mid = l + r >> 1;     build(rt << 1, l, mid);     build(rt << 1 | 1, mid + 1, r);     push_up(rt);   }   void update(int rt, int l, int r) {     if (tree[rt].r < l || tree[rt].l > r) return;     if (tree[rt].l >= l && tree[rt].r <= r) {       tree[rt].sum = (tree[rt].r - tree[rt].l + 1) - tree[rt].sum;       tree[rt].add ^= 1;       return;     }     push_down(rt);     if (tree[rt].mid >= l) update(rt << 1, l, r);     if (tree[rt].mid < r) update(rt << 1 | 1, l, r);     push_up(rt);   }   int query(int rt, int l, int r) {     if (tree[rt].r < l || tree[rt].l > r) return 0;     if (tree[rt].l >= l && tree[rt].r <= r) return tree[rt].sum;     push_down(rt);     int ans = 0;     if (tree[rt].mid >= l) ans += query(rt << 1, l, r);     if (tree[rt].mid < r) ans += query(rt << 1 | 1, l, r);     push_up(rt);     return ans;   }   int main() {     int n, x;     scanf( %d , &n);     for (int i = 2; i <= n; i++) {       scanf( %d , &x);       G[x].push_back(i);       G[i].push_back(x);     }     for (int i = 1; i <= n; i++) scanf( %d , &t[i]);     dfs(1, -1);     build(1, 1, n);     int q;     scanf( %d , &q);     while (q--) {       char op[4];       int v;       scanf( %s%d , op, &v);       if (op[0] ==  p )         update(1, in[v], ou[v]);       else         printf( %d n , query(1, in[v], ou[v]));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200007;   string s;   int q, n, cnt[maxn][26];   void Solve() {     int l, r;     cin >> l >> r;     if (l == r) {       cout <<  Yes  <<   n ;       return;     }     if (s[l] != s[r]) {       cout <<  Yes  <<   n ;       return;     }     int cnt = 0;     for (int i = 0; i < 26; i++) {       if (i == s[l] -  a ) continue;       int gau = ::cnt[r][i] - ::cnt[l - 1][i];       if (gau) cnt++;     }     if (cnt >= 2)       cout <<  Yes  <<   n ;     else       cout <<  No  <<   n ;   }   int32_t main() {     auto start = chrono::steady_clock::now();     ios_base::sync_with_stdio(0);     cin.tie(0);     if (fopen( test.inp ,  r )) freopen( test.inp ,  r , stdin);     cin >> s >> q;     n = s.length();     s =     + s;     for (int i = 1; i <= n; i++) {       for (int j = 0; j < 26; j++) {         cnt[i][j] = cnt[i - 1][j];         if (j == s[i] -  a ) cnt[i][j]++;       }     }     while (q--) Solve();     auto finish = chrono::steady_clock::now();     cerr << chrono::duration_cast<chrono::milliseconds>(finish - start).count();   }
#include <bits/stdc++.h>   using namespace std;   int n;   int a[300010];   int p[300010];   struct node {     int next[2] = {};     int cnt = 0;     int par;   };   node t[31 * 300010];   int root = 1;   int E = 2;   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) cin >> p[i];     for (int i = 0; i < n; i++) {       int u = root;       for (int j = 29; j >= 0; j--) {         int c;         if (p[i] & (1 << j))           c = 1;         else           c = 0;         if (!t[u].next[c]) {           t[u].next[c] = E++;           t[E - 1].par = u;         }         u = t[u].next[c];       }       while (u != 1) {         t[u].cnt++;         u = t[u].par;       }     }     for (int i = 0; i < n; i++) {       int x = a[i];       int u = root;       int val = 0;       for (int j = 29; j >= 0; j--) {         int c;         if (a[i] & (1 << j))           c = 1;         else           c = 0;         if (t[u].next[c] && t[t[u].next[c]].cnt) {           val ^= (1 << j) * c;           u = t[u].next[c];         } else {           val ^= (1 << j) * (!c);           u = t[u].next[!c];         }       }       while (u != 0) {         t[u].cnt--;         u = t[u].par;       }       x ^= val;       cout << x <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 9;   const int mod1 = 999999937;   const int inf = 2e9;   const double eps = 1e-7;   int d[101][101];   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int a, b, c;       cin >> a >> b >> c;       d[a - 1][b - 1] = c;     }     int ans = 0;     int w = n;     while (w--) {       for (int i = 0; i < n; i++) {         for (int j = 0; j < n; j++) {           for (int k = 0; k < n; k++) {             if (d[i][j] > 0 && d[j][k] > 0) {               int q = min(d[i][j], d[j][k]);               d[i][j] -= q;               d[j][k] -= q;               d[i][k] += q;             }           }         }       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         ans += d[i][j];       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[5000010];   int f[5000010];   int main() {     scanf( %s , s);     int l = 0, r = 0, e = 1, ans = 0;     for (int i = 0; s[i]; i++) {       l = l * 103 + s[i];       r = r + s[i] * e;       e *= 103;       if (l == r) f[i + 1] = f[(i + 1) / 2] + 1;       ans += f[i + 1];     }     cout << ans << endl;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1024000000,1024000000 )   using namespace std;   const int maxn = 1e6 + 7;   const int INF = 1e9 + 7;   int n, k;   int a[maxn];   vector<int> fac[maxn];   int sum[maxn];   int L[maxn], R[maxn];   long long ans;   void ini() {     stack<int> st;     a[n + 1] = INF;     for (int i = 1; i < n + 1; i++) L[i] = 1;     for (int i = 1; i < n + 2; i++) {       int num = 0;       while (!st.empty() && a[st.top()] <= a[i]) {         int p = st.top();         st.pop();         R[p] = num;         L[i] += L[p];         num = L[p] + R[p];       }       st.push(i);     }   }   int query(int x, int l, int r) {     int a = lower_bound(fac[x].begin(), fac[x].end(), l) - fac[x].begin();     int b = upper_bound(fac[x].begin(), fac[x].end(), r) - fac[x].begin();     return b - a;   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i < n + 1; i++) scanf( %d , &a[i]);     for (int i = 1; i < n + 1; i++) sum[i] = (sum[i - 1] + a[i]) % k;     fac[0].push_back(0);     for (int i = 1; i < n + 1; i++) fac[sum[i]].push_back(i);     ini();     for (int i = 1; i < n + 1; i++) {       L[i] = i - L[i];       R[i] = i + R[i] + 1;     }     for (int i = 1; i < n + 1; i++) {       if (i - L[i] < R[i] - i) {         for (int j = L[i]; j < i; j++)           ans += query((sum[j] + a[i]) % k, i, R[i] - 1);       } else {         for (int j = i; j < R[i]; j++)           ans += query((sum[j] - a[i] % k + k) % k, L[i], i - 1);       }     }     printf( %I64d n , ans - n);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T sqr(const T& x) {     return x * x;   }   template <class T>   inline string tostr(const T& a) {     ostringstream os(  );     os << a;     return os.str();   }   const int inf = 1999999999;   const double pi = acos(-1.0);   const double eps = 1e-9;   int main(int argc, char* argv[]) {     clock_t _ = clock();     cout << fixed << setprecision(15);     string s, t;     cin >> s >> t;     bool automaton = false, array = true;     int cnt1[26], cnt2[26];     memset((cnt1), (0), sizeof(cnt1));     memset((cnt2), (0), sizeof(cnt2));     for (__typeof((s).begin()) it = (s).begin(), _it = (s).end(); it != _it;          ++it) {       cnt1[*it -  a ]++;     }     for (__typeof((t).begin()) it = (t).begin(), _it = (t).end(); it != _it;          ++it) {       cnt2[*it -  a ]++;     }     if (s.size() > t.size()) automaton = true;     for (int i = 0, _i = (26); i < _i; ++i) {       if (cnt1[i] < cnt2[i]) {         automaton = array = false;         break;       }     }     int i2 = 0;     for (int i1 = 0, _i1 = (s.size()); i1 < _i1; ++i1) {       if (s[i1] == t[i2]) i2++;     }     if (i2 == t.size()) {       automaton = true;       array = false;     }     if (automaton && array)       cout <<  both  << (  n );     else if (automaton)       cout <<  automaton  << (  n );     else if (array)       cout <<  array  << (  n );     else       cout <<  need tree  << (  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long k;     cin >> k;     getchar();     char s[1000001];     cin >> s;     int a[strlen(s)];     long long sum = 0;     for (int i = 0; i < strlen(s); i++) {       sum += s[i] - 48;       a[i] = s[i] - 48;     }     k = k - sum;     sort(a, a + strlen(s));     int c = 0;     for (int i = 0; i < strlen(s); i++) {       if (k > 0) {         k -= (9 - a[i]);         c++;       } else         break;     }     cout << c << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     long long l, a;     cin >> n >> l >> a;     long long arr[n][2];     long long ans = 0;     for (int i = 0; i < n; i++) {       cin >> arr[i][0] >> arr[i][1];       if (i == 0) {         ans += arr[i][0] / a;       }       if (i != 0) {         ans = ans + (arr[i][0] - (arr[i - 1][0] + arr[i - 1][1])) / a;       }     }     if (n != 0)       ans = ans + (l - arr[n - 1][0] - arr[n - 1][1]) / a;     else       ans = l / a;     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   bitset<50000000> arr;   int primes[100100], pr = 0;   int n;   unsigned int A, B, C, D;   int main() {     cin >> n >> A >> B >> C >> D;     for (int i = 2; i <= 18000; i++) {       arr[i] = 1;     }     for (int i = 2; i <= 18000; i++) {       if (arr[i] == 0) continue;       primes[pr++] = i;       for (int j = i * i; j <= 18000; j += i) {         arr[j] = 0;       }     }     int st = 2;     unsigned int sol = 0;     while (st <= n) {       int en = min(st + 40000000, n);       int ln = en - st + 1;       for (int i = 0; i < ln; i++) {         arr[i] = 1;       }       for (int i = 0; i < pr; i++) {         int beg = max(primes[i] * primes[i],                       ((st + primes[i] - 1) / primes[i]) * primes[i]);         for (int j = beg - st; j < ln; j += primes[i]) {           arr[j] = 0;         }       }       for (int i = 0; i < ln; i++) {         if (arr[i] == 1) {           unsigned int rep = 0;           int cur_pr = st + i;           while (cur_pr <= n) {             rep += (unsigned int)(n / cur_pr);             if (cur_pr > n / (st + i)) {               break;             } else {               cur_pr *= (st + i);             }           }           sol += rep * (A * (st + i) * (st + i) * (st + i) +                         B * (st + i) * (st + i) + C * (st + i) + D);         }       }       st = en + 1;     }     cout << sol << endl;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int l;     int r;   } a[200005], b[2000005];   int cmpl(struct node n, struct node m) { return n.l < m.l; }   int cmpr(struct node n, struct node m) { return n.r < m.r; }   int main() {     int n, m;     while (~scanf( %d , &n)) {       int sum = 0;       for (int i = 0; i < n; i++) {         scanf( %d%d , &a[i].l, &a[i].r);       }       scanf( %d , &m);       for (int i = 0; i < m; i++) {         scanf( %d%d , &b[i].l, &b[i].r);       }       sort(a, a + n, cmpl);       sort(b, b + m, cmpr);       if (a[n - 1].l > b[0].r) {         sum = max(sum, a[n - 1].l - b[0].r);       }       sort(a, a + n, cmpr);       sort(b, b + m, cmpl);       if (b[m - 1].l > a[0].r) {         sum = max(sum, b[m - 1].l - a[0].r);       }       if (!sum)         printf( 0 n );       else         printf( %d n , sum);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const string FILENAME =   ;   const bool FILE_IO = 1;   const int INF = 1000000000;   void init() {     if (!FILENAME.empty()) {       freopen((FILENAME +  .in ).c_str(),  r , stdin);       freopen((FILENAME +  .out ).c_str(),  w , stdout);     }   }   int main() {     init();     int n, m;     cin >> n;     vector<int> arr(n);     vector<long long> s(n);     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     cin >> m;     sort(arr.begin(), arr.end());     reverse(arr.begin(), arr.end());     s[0] = arr[0];     for (int i = 1; i < n; i++) {       s[i] += arr[i] + s[i - 1];     }     for (int i = 0; i < m; i++) {       int q;       long long ans = 0;       cin >> q;       ans = s[q - 2] + s[n - 1] - s[q - 1];       cout << ans << endl;     }     return 0;   }