func_code_string: #include <bits/stdc++.h>   using namespace std;   const int maxn = 5 + 100000;   int n, m, len_behind, len_front;   struct TREE {     int fg;     int M11[3];   } T[maxn * 4];   inline int L(int &x) { return x << 1; }   inline int R(int &x) { return x << 1 | 1; }   void f_maintain(int root, int len) {     int a = L(root), b = R(root), lena = (len + 1) >> 1, lenb = len >> 1;     T[root].M11[0] = T[a].M11[0];     if (T[root].M11[0] == lena) T[root].M11[0] += T[b].M11[0];     T[root].M11[1] = T[b].M11[1];     if (T[root].M11[1] == lenb) T[root].M11[1] += T[a].M11[1];     T[root].M11[2] = max(T[a].M11[2], T[b].M11[2]);     T[root].M11[2] = max(T[root].M11[2], T[L(root)].M11[1] + T[R(root)].M11[0]);   }   void f_build(int root, int le, int ri) {     T[root].fg = -1;     T[root].M11[0] = T[root].M11[1] = T[root].M11[2] = ri - le + 1;     if (le == ri) return;     int mid = (le + ri) >> 1;     f_build(L(root), le, mid);     f_build(R(root), mid + 1, ri);   }   void f_giveson(int fg, int son, int len) {     T[son].fg = fg;     T[son].M11[0] = T[son].M11[1] = T[son].M11[2] = fg * len;   }   void f_pushdown(int root, int len) {     if (len == 1) return;     int a = L(root), b = R(root), lena = (len + 1) >> 1, lenb = len >> 1;     if (T[root].fg != -1) {       f_giveson(T[root].fg, a, lena);       f_giveson(T[root].fg, b, lenb);       T[root].fg = -1;     }   }   void f_update(int root, int le, int ri, int Mle, int Mri, int fg) {     if (Mle <= le && ri <= Mri) {       f_giveson(fg, root, ri - le + 1);       return;     }     f_pushdown(root, ri - le + 1);     int mid = (le + ri) >> 1;     if (Mle <= mid) f_update(L(root), le, mid, Mle, Mri, fg);     if (Mri > mid) f_update(R(root), mid + 1, ri, Mle, Mri, fg);     f_maintain(root, ri - le + 1);   }   int f_query(int root, int le, int ri, int x) {     if (le == ri) return le;     f_pushdown(root, ri - le + 1);     int mid = (le + ri) >> 1;     if (T[L(root)].M11[2] >= x)       return f_query(L(root), le, mid, x);     else if (T[L(root)].M11[1] + T[R(root)].M11[0] >= x)       return mid - T[L(root)].M11[1] + 1;     return f_query(R(root), mid + 1, ri, x);   }   int one[2][105];   int main() {     char ss[33];     while (scanf( %d %d %d %d , &n, &len_behind, &len_front, &m) + 1) {       f_build(1, 1, n);       memset(one, -1, sizeof one);       int e, t, newlen, leaveid;       for (e = 1; e <= m; e++) {         scanf( %d , &t);         if (t == 1) {           scanf( %d , &newlen);           if ((T[1].M11[0] == n && n >= newlen) ||               (T[1].M11[0] >= newlen + len_front)) {             puts( 0 );             f_update(1, 1, n, 1, newlen, 0);             one[0][e] = 1;             one[1][e] = newlen;             continue;           }           if (T[1].M11[2] >= newlen + len_behind + len_front) {             int x = f_query(1, 1, n, newlen + len_behind + len_front);             printf( %d n , x - 1 + len_behind);             f_update(1, 1, n, x + len_behind, x + len_behind + newlen - 1, 0);             one[0][e] = x + len_behind;             one[1][e] = x + len_behind + newlen - 1;             continue;           }           if (T[1].M11[1] >= newlen + len_behind) {             int x = n + 1 - T[1].M11[1];             printf( %d n , x - 1 + len_behind);             f_update(1, 1, n, x + len_behind, x + len_behind + newlen - 1, 0);             one[0][e] = x + len_behind;             one[1][e] = x + len_behind + newlen - 1;             continue;           }           puts( -1 );         } else {           scanf( %d , &leaveid);           if (one[0][leaveid] != -1) {             f_update(1, 1, n, one[0][leaveid], one[1][leaveid], 1);             one[0][leaveid] = one[1][leaveid] = -1;           }         }       }     }     return 0;   }   