malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   void read(int &sum) {     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) sum = -sum;   }   void read(long long &sum) {     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) sum = -sum;   }   void readvec(vector<int> &a, int n) {     for (int i = 0; i < n; i++) read(a[i]);   }   void readvec(vector<long long> &a, long long n) {     for (int i = 0; i < n; i++) read(a[i]);   }   const int MOD = 1e9 + 7;   const int INF = (int)2e9 + 7;   const long long LINF = (long long)1e18;   const long double PI = 3.1415926535897932384626433832795;   mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());   void solve() {     int n;     read(n);     vector<int> v(n);     readvec(v, n);     if (n == 1) {       cout << -1;       return;     }     if (n == 2 && v[0] == v[1]) {       cout << -1;       return;     }     int ind, mn = 1001;     for (int i = 0; i < n; i++) {       if (v[i] < mn) {         mn = v[i];         ind = i;       }     }     cout << 1 <<   n ;     cout << ind + 1 <<   n ;   }   int32_t main() {     int t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int MAXN = 1000010;   int prime[5005];   long long f[MAXN][22];   void getPrime() {     for (int i = 2; i <= 5000; i++) {       if (!prime[i]) prime[++prime[0]] = i;       for (int j = 1; j <= prime[0] && prime[j] <= 5000 / i; j++) {         prime[prime[j] * i] = 1;         if (i % prime[j] == 0) break;       }     }   }   void init() {     f[0][0] = 1;     for (int i = 1; i <= 20; ++i) {       f[0][i] = 2;     }     for (int i = 1; i <= 1000000; ++i) {       f[i][0] = 1;       for (int j = 1; j <= 20; ++j) {         f[i][j] = (f[i][j - 1] + f[i - 1][j]) % MOD;       }     }   }   int q, r, n;   int main() {     init();     getPrime();     scanf( %d , &q);     while (q--) {       scanf( %d%d , &r, &n);       long long ans = 1;       int cnt = 0;       for (int i = 1, tmp; prime[i] * prime[i] <= n && i <= prime[0]; ++i) {         tmp = prime[i];         if (n == 1) break;         if (n % tmp == 0) {           while (n % tmp == 0) {             n /= tmp;             cnt++;           }         }         ans = ans * f[r][cnt] % MOD;         cnt = 0;       }       if (n > 1) {         ans = ans * (long long)f[r][1] % MOD;       }       printf( %I64d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       int n, i;       int d = 0, c = 0;       cin >> n;       string s;       cin >> s;       for (i = n - 1; i >= 0; i--) {         if (s[i] ==  P )           c++;         else {           d = max(d, c);           c = 0;         }       }       cout << d << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const long long inf = 1e18;   const int maxn = 2e5 + 10;   const double eps = 1e-7;   const double pi = 3.14159265359;   long long n, m, a[maxn], par[maxn];   bool check(int x) {     long long now = 0;     long long cnt = 0;     long long cal = 0;     for (int i = 0; i < n; i++) {       if (cal >= x) {         cal = 0;         cnt++;       }       if (a[i] - cnt > 0) {         now += a[i] - cnt;         cal++;       }     }     if (now >= m) {       return 1;     }     return 0;   }   int main() {     std::ios::sync_with_stdio(0);     ;     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     reverse(a, a + n);     par[0] = a[0];     for (int i = 1; i < n; i++) {       par[i] = par[i - 1] + a[i];     }     int ans = -1;     long long l = 1, r = n + 5, mid;     while (l <= r) {       mid = (l + r) / 2;       if (check(mid)) {         ans = mid;         r = mid - 1;       } else {         l = mid + 1;       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   char c[100005];   int cut[100005], num[100005];   int f[100005], h[2][100005];   int main() {     int n, m;     cin >> n >> c + 1 >> m;     for (int i = 1; i <= n; i++) {       num[i] = num[i - 1];       if (c[i] ==  a )         h[0][i] = h[1][i - 1] + 1;       else if (c[i] ==  b )         h[1][i] = h[0][i - 1] + 1;       else {         h[0][i] = h[1][i - 1] + 1;         h[1][i] = h[0][i - 1] + 1;         num[i]++;       }       f[i] = f[i - 1], cut[i] = cut[i - 1];       if (h[(m + 1) & 1][i] >= m) {         if (f[i] < f[i - m] + 1) {           f[i] = f[i - m] + 1, cut[i] = cut[i - m] + num[i] - num[i - m];         }         if (f[i] == f[i - m] + 1) {           cut[i] = min(cut[i], cut[i - m] + num[i] - num[i - m]);         }       }     }     cout << cut[n] << endl;   }
#include <bits/stdc++.h>   using namespace std;   struct str {     long long num;     long long id;   } st[666666];   long long arr[666666];   bool cmp(str a, str b) { return a.num < b.num; }   signed main() {     long long n;     cin >> n;     for (long long i = 1; i <= n; i++) {       cin >> arr[i];     }     long long ans = min(arr[1], arr[n]) / (n - 1);     for (long long i = 2; i < n; i++) {       long long t1 = min(arr[i], arr[1]) * 1ll / (i - 1) * 1ll;       long long t2 = min(arr[i], arr[n]) / (n - i) * 1ll;       ans = min(ans, min(t1, t2));     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, q;   int a[100005];   long long tree[2 * 100005], tree2[2 * 100005];   vector<long long> mapa;   int mp(double val) {     return upper_bound(mapa.begin(), mapa.end(), val) - mapa.begin();   }   void update(int pos, int val) {     for (int i = pos; i < 2 * 100005; i += i & -i) tree[i] += val;   }   void update2(int pos, int val) {     for (int i = pos; i < 2 * 100005; i += i & -i) tree2[i] += val;   }   void upd(int pos, int val) {     int posi = mp(a[pos - 1]);     update(posi, -a[pos - 1]);     update2(posi, -1);     a[pos - 1] = val;     posi = mp(val);     update(posi, val);     update2(posi, 1);   }   long long query(int pos) {     long long res = 0;     for (int i = pos; i > 0; i -= i & -i) res += tree[i];     return res;   }   long long query2(int pos) {     long long res = 0;     for (int i = pos; i > 0; i -= i & -i) res += tree2[i];     return res;   }   long double f(long double x) {     double res;     int pos = mp(x);     res = x * query2(pos) - query(pos);     return res;   }   struct quer {     int t, p;     long long v;     quer(){};     quer(int t, int p, long long v) : t(t), p(p), v(v){};   } qry[100005];   int main() {     scanf( %d%d , &n, &q);     for (int i = 0; i < n; i++) scanf( %d , a + i), mapa.push_back(a[i]);     for (int i = 0, t, p = 0; i < q; i++) {       long long v;       cin >> t;       if (t == 1)         cin >> p >> v, mapa.push_back(v);       else         cin >> v;       qry[i] = quer(t, p, v);     }     sort(mapa.begin(), mapa.end());     mapa.resize(unique(mapa.begin(), mapa.end()) - mapa.begin());     for (int i = 0; i < n; i++) {       int posi = mp(a[i]);       update(posi, a[i]);       update2(posi, 1);     }     for (int i = 0; i < q; i++) {       quer Q = qry[i];       if (Q.t == 1) {         upd(Q.p, Q.v);       } else {         double l = 0, r = 1000000001;         while (l + 1e-5 <= r) {           double m = l + (r - l) / 2;           if (f(m) < Q.v)             l = m + 1e-5;           else             r = m;         }         if (abs(l - 1000000001) <= 1e-5 && abs(f(l) - Q.v) > 1e-5) {           l = 1.0 * (Q.v + query(2 * 100005 - 1)) / n;         }         printf( %.5lf n , l);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   void solve() {     scanf( %d , &n);     int tmp, tot;     if (n == 0) {       printf( O-|-OOOO n );       return;     }     while (n) {       tmp = n % 10;       if (tmp >= 5) {         tot = tmp - 5;         printf( -O| );       } else {         tot = tmp;         printf( O-| );       }       for (int i = 1; i <= tot; i++) printf( O );       printf( - );       for (int i = 1; i <= 4 - tot; i++) printf( O );       printf(  n );       n /= 10;     }   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void getint(int &v) {     char ch, fu = 0;     for (ch =  * ; (ch <  0  || ch >  9 ) && ch !=  - ; ch = getchar())       ;     if (ch ==  - ) fu = 1, ch = getchar();     for (v = 0; ch >=  0  && ch <=  9 ; ch = getchar()) v = v * 10 + ch -  0 ;     if (fu) v = -v;   }   int n, m, ans, a[444][444], f[444][444], p[401][160001];   int main() {     cin >> n >> m;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) getint(a[i][j]);     for (int i = 1; i <= n; ++i) {       for (int len = 1; len <= m; ++len)         for (int l = 1; l <= m - len + 1; ++l) {           int r = l + len - 1;           if (len > 1) {             f[l][r] = max(f[l][r], max(f[l + 1][r], f[l][r - 1]));             f[l][r] = max(f[l][r], p[r][a[i][l]]);             f[l][r] = max(f[l][r], p[l][a[i][r]]);             if (a[i][l] == a[i][r]) f[l][r] = i;           } else {             f[l][r] = max(f[l][r], p[l][a[i][l]]);           }           ans = max(ans, (i - f[l][r]) * (r - l + 1));         }       for (int j = 1; j <= m; ++j) p[j][a[i][j]] = i;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int b[m];     for (int i = 0; i < m; cin >> b[i++])       ;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (b[j] <= i + 1) {           cout << b[j] <<    ;           break;         }       }     }     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e3 + 10;   int n, m, c = 0, ans = 0;   vector<int> adj[maxn], bkadj[maxn], components, nodes[maxn], sink;   bool mark[maxn];   int cmp[maxn], d[maxn], o[maxn];   stack<int> st;   queue<int> q;   void input() {     cin >> n >> m;     for (int i = 0; i < m; i++) {       int fi, se;       cin >> fi >> se;       adj[fi].push_back(se);       bkadj[se].push_back(fi);     }   }   void dfs1(int x) {     mark[x]++;     for (int i = 0; i < adj[x].size(); i++) {       int child = adj[x][i];       if (!mark[child]) dfs1(child);     }     st.push(x);   }   void dfs2(int x) {     mark[x]++;     nodes[cmp[x]].push_back(x);     for (int i = 0; i < bkadj[x].size(); i++) {       int child = bkadj[x][i];       if (!mark[child]) {         cmp[child] = cmp[x];         dfs2(child);       } else if (cmp[child] != cmp[x])         o[cmp[child]]++;     }   }   int bfs(int x) {     memset(mark, 0, sizeof mark);     q.push(x);     d[x] = 1;     mark[x]++;     int mi = 1e8;     while (!q.empty()) {       int cur = q.front();       q.pop();       for (int i = 0; i < adj[cur].size(); i++) {         int child = adj[cur][i];         if (!mark[child]) {           mark[child]++;           d[child] = d[cur] + 1;           q.push(child);         } else if (child == x)           mi = min(mi, d[cur]);       }     }     return mi;   }   void task() {     for (int i = 1; i <= n; i++)       if (!mark[i]) dfs1(i);     memset(mark, 0, sizeof mark);     while (!st.empty()) {       int x = st.top();       st.pop();       if (!mark[x]) cmp[x] = x, components.push_back(x), dfs2(x);     }     for (int i = 0; i < components.size(); i++)       if (o[components[i]] == 0) sink.push_back(components[i]);     for (int i = 0; i < sink.size(); i++) {       int cm = sink[i];       if (nodes[cm].size() != 1) {         c++;         int mi = 1e8;         for (int i = 0; i < nodes[cm].size(); i++) {           int cur = nodes[cm][i];           mi = min(mi, bfs(cur));         }         ans += mi;       }     }   }   void debug() {     for (int i = 1; i <= n; i++) cerr << i <<  :  << cmp[i] << endl;   }   int main() {     input();     task();     cout << n + (ans * 998) + c << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[150000], b[510000], arr[226660];   int main() {     int n, x, k;     cin >> n >> k >> x;     int cnt = 1;     int l = 0;     cin >> arr[0];     for (int i = 1; i < n; i++) {       cin >> arr[i];       if (arr[i] == arr[i - 1]) {         cnt++;       } else {         a[l] = arr[i - 1];         b[l++] = cnt;         cnt = 1;       }     }     a[l] = arr[n - 1];     b[l++] = cnt;     int sum = 0;     for (int i = 0; i < l; i++) {       int ans = 0;       if (a[i] == x) {         if (b[i] + 1 >= 3) {           ans += b[i];           int u = i - 1;           int v = i + 1;           while (a[u] == a[v] && b[u] + b[v] >= 3 && u >= 0 && v < n) {             ans += b[u] + b[v];             u--;             v++;           }           sum = max(sum, ans);         }       }     }     printf( %d n , sum);   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     long long n;     cin >> n;     n /= 2;     vector<long long> x(n);     for (long long i = 0; i < n; ++i) {       cin >> x[i];     }     vector<vector<pair<long long, long long>>> as(n);     for (long long i = 0; i < n; ++i) {       for (long long a = 1; a * a < x[i]; ++a) {         if (x[i] % a) {           continue;         }         long long b = x[i] / a;         if ((b + a) % 2) {           continue;         }         as[i].emplace_back((b - a) / 2, (b + a) / 2);       }       reverse(as[i].begin(), as[i].end());     }     vector<long long> y(n);     long long last = 0;     for (long long i = 0; i < n; ++i) {       pair<long long, long long> tf = {last, 0};       long long j = lower_bound(as[i].begin(), as[i].end(), tf) - as[i].begin();       if (j >= as[i].size()) {         cout <<  No ;         return 0;       }       tf = as[i][j];       y[i] = tf.first * tf.first - last * last;       last = tf.second;     }     for (long long i = 0; i < n; ++i) {       if (y[i] < 1) {         cout <<  No ;         return 0;       }     }     cout <<  Yes  <<   n ;     for (long long i = 0; i < n; ++i) {       cout << y[i] <<     << x[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(void) {     long long int t, a, b, a1, b1;     cin >> t;     while (t--) {       cin >> a >> b;       a1 = max(a, b);       b1 = min(a, b);       if (a1 >= (2 * b1)) {         cout << b1 << endl;       } else {         cout << (a1 - b1) + (2 * ((b1 - (a1 - b1)) / 3)) +                     (((b1 - (a1 - b1)) % 3) == 2 ? 1 : 0)              << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   unsigned char a[200042];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %hhu , &a[i]);     int q;     scanf( %d , &q);     while (q--) {       int l, r;       unsigned char x, y;       scanf( %d%d%hhu%hhu , &l, &r, &x, &y);       for (int i = l - 1; i < r; i++) a[i] = a[i] == x ? y : a[i];     }     for (int i = 0; i < n; ++i) printf( %hhu  , a[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = (int)1e5 + 12;   int a[maxn], n;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     sort(a + 1, a + n + 1);     int cnt = 0;     for (int i = 2; i < n; i++) {       if (a[1] < a[i] && a[i] < a[n]) cnt++;     }     cout << cnt;   }
#include <bits/stdc++.h>   int in() {     int r = 0, c;     for (c = getchar(); c <= 32; c = getchar())       ;     if (c ==  - ) return -in();     for (; c > 32; r = (r << 1) + (r << 3) + c -  0 , c = getchar())       ;     return r;   }   using namespace std;   const int INF = int(1e9 + 7);   long long v[100010];   int main() {     long long n, u;     double ans = -1;     cin >> n >> u;     for (int i = 0; i < n; i++) cin >> v[i];     for (int i = 0; i < n - 2; i++) {       long long a = v[i], b = v[i + 1];       long long lo = i + 2, hi = n - 1, mid;       double res = -1;       while (lo <= hi) {         mid = (lo + hi) / 2;         if (v[mid] - a <= u) {           res = (double)(v[mid] - b) / (double)(v[mid] - a);           lo = mid + 1;         } else           hi = mid - 1;       }       ans = max(ans, res);     }     if (ans >= 0)       cout << fixed << setprecision(10) << ans << endl;     else       cout << -1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, K = 0;   int ans[1005];   int main() {     scanf( %d , &N);     int i, j, tmp = 0;     for (i = 1; i * 2 < N; i++) {       ++K;       ans[K] = i;       N -= i;     }     printf( %d n , K + 1);     for (i = 1; i <= K; i++) printf( %d  , ans[i]);     printf( %d n , N);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int w[1010000], n, Res[1010000], Mod = 1000000007;   long long S[1010000], K;   vector<int> E[1010000], G[1010000], d;   void DFS(int a) {     S[a] = w[a];     for (auto &x : E[a]) {       DFS(x);       S[a] += S[x];     }   }   void Go(int a) {     int i, c = 0;     for (i = 1; i * i < a; i++) {       if (a % i == 0) {         c += G[i].size();         c += G[a / i].size();       }     }     if (i * i == a) c += G[i].size();     if (c == a) {       Res[a] = 1;       for (auto &x : d) {         if (x % a == 0) Res[a] = (Res[a] + Res[x]) % Mod;       }       d.push_back(a);     }   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   int main() {     int i, a, b;     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d , &w[i]);     for (i = 2; i <= n; i++) {       scanf( %d , &a);       E[a].push_back(i);     }     DFS(1);     for (i = 1; i <= n; i++) {       long long g = gcd(S[1], S[i]);       if (S[1] / g <= n) {         G[S[1] / g].push_back(i);       }     }     for (i = n; i >= 1; i--) {       if (S[1] % i == 0) Go(i);     }     printf( %d n , Res[1]);   }
#include <bits/stdc++.h>   using namespace std;   string s, dum;   int idx = 0;   int A[5000];   stack<int> S;   int main() {     while (cin >> dum) {       s += dum;     }     for (int i = 0; i < s.length(); i++) {       dum =   ;       while (s[i] !=  > ) {         dum += s[i];         i++;       }       dum +=  > ;       if (dum ==  <table> ) {         S.push(idx);         idx++;       } else if (dum ==  </table> ) {         S.pop();       } else if (dum ==  <td> ) {         A[S.top()]++;       }     }     sort(A, A + idx);     for (int i = 0; i < idx; i++) {       if (i > 0) printf(   );       printf( %d , A[i]);     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double PI = 3.141592653589793;   const long long MOD = 1000000007;   const long double EPS = 1e-9;   const long long MAX = LLONG_MAX;   const long long MIN = LLONG_MIN;   const int N = 2e5 + 7;   long long power(long long base, unsigned long long exp, const long long MOD) {     long long res = 1;     base %= MOD;     while (exp) {       if (exp & 1) {         res = (res * base) % MOD;       }       exp >>= 1;       base = (base * base) % MOD;     }     return res;   }   inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   bool palin(const string& s) {     long long i = 0, j = s.length() - 1;     while (i <= j) {       if (s[i] != s[j]) return false;       ++i;       --j;     }     return true;   }   long long modinv(long long a, const long long MOD) {     if (MOD == 1) {       return 0;     }     long long x = 1, y = 0, m = MOD;     while (a > 1) {       long long q = a / m, t = m;       m = a % m;       a = t;       t = y;       y = x - q * y;       x = t;     }     if (x < 0) {       x += MOD;     }     return x;   }   template <typename T>   void input(vector<T>& v) {     for (int i = 0; i < v.size(); ++i) {       cin >> v[i];     }   }   template <typename T>   void printarr(vector<T>& v) {     for (int x : v) {       cout << x <<    ;     }     cout << endl;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, x, ans = 0, next = 1;     bool queue = false;     string s;     stack<int> st;     cin >> n;     for (int i = 0; i < 2 * n; ++i) {       cin >> s;       if (s ==  add ) {         cin >> x;         st.push(x);       } else {         if (!st.empty()) {           if (st.top() == next) {             st.pop();           } else {             ++ans;             st = stack<int>();           }         }         ++next;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int sum[101000 << 2], lsum[101000 << 2], rsum[101000 << 2], lazy[101000 << 2];   int L[105];   int ans[105];   int max(int a, int b) { return a > b ? a : b; }   void pushup(int rt, int len) {     sum[rt] = max(sum[rt << 1], sum[rt << 1 | 1]);     sum[rt] = max(sum[rt], rsum[rt << 1] + lsum[rt << 1 | 1]);     lsum[rt] = lsum[rt << 1];     if (lsum[rt] == len - (len >> 1)) lsum[rt] += lsum[rt << 1 | 1];     rsum[rt] = rsum[rt << 1 | 1];     if (rsum[rt] == (len >> 1)) rsum[rt] += rsum[rt << 1];   }   void pushdown(int rt, int len) {     lazy[rt << 1] = lazy[rt << 1 | 1] = lazy[rt];     if (lazy[rt] == 0) {       sum[rt << 1] = sum[rt << 1 | 1] = 0;       lsum[rt << 1] = lsum[rt << 1 | 1] = 0;       rsum[rt << 1] = rsum[rt << 1 | 1] = 0;     } else {       sum[rt << 1] = lsum[rt << 1] = rsum[rt << 1] = len - (len >> 1);       sum[rt << 1 | 1] = lsum[rt << 1 | 1] = rsum[rt << 1 | 1] = len >> 1;     }     lazy[rt] = -1;   }   void update(int l, int r, int rt, int L, int R, int val) {     if (l >= L && r <= R) {       sum[rt] = val * (r - l + 1);       lsum[rt] = val * (r - l + 1);       rsum[rt] = val * (r - l + 1);       lazy[rt] = val;       return;     }     if (lazy[rt] != -1) {       pushdown(rt, r - l + 1);     }     int m = (l + r) >> 1;     if (L <= m) update(l, m, rt << 1, L, R, val);     if (R > m) update(m + 1, r, rt << 1 | 1, L, R, val);     pushup(rt, r - l + 1);   }   int query(int l, int r, int rt, int L) {     if (sum[rt] < L) return -1;     if (lazy[rt] != -1) {       pushdown(rt, r - l + 1);     }     int m = (l + r) >> 1;     if (sum[rt << 1] >= L) {       return query(l, m, rt << 1, L);     } else if (rsum[rt << 1] + lsum[rt << 1 | 1] >= L) {       return m - rsum[rt << 1] + 1;     }     return query(m + 1, r, rt << 1 | 1, L);   }   void print(int l, int r, int rt) {     printf(           l = %d r = %d sum[rt] = %d , lsum[rt] = %d , rsum[rt] = %d lazy[rt] =            %d  n ,         l, r, sum[rt], lsum[rt], rsum[rt], lazy[rt]);     if (l == r) return;     int m = (l + r) >> 1;     print(l, m, rt << 1);     print(m + 1, r, rt << 1 | 1);   }   int main() {     int n, b, f;     while (scanf( %d%d%d , &n, &b, &f) != EOF) {       memset(lazy, -1, sizeof(lazy));       n += b + f;       update(1, n, 1, 1, n, 1);       int k, i;       scanf( %d , &k);       for (i = 1; i <= k; i++) {         int t;         scanf( %d%d , &t, &L[i]);         if (t == 1) {           int pos = query(1, n, 1, L[i] + b + f);           if (pos == -1) {             printf( -1 n );             ans[i] = -1;           } else {             printf( %d n , pos - 1);             update(1, n, 1, pos + b, pos + b + L[i] - 1, 0);             ans[i] = pos + b;           }         } else {           if (ans[L[i]] == -1) continue;           update(1, n, 1, ans[L[i]], ans[L[i]] + L[L[i]] - 1, 1);         }       }     }     return 0;   }