func_code_string: #include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long mo = 998244353;   const long long N = 2e6 + 5;   long long n, m, noden, tot;   set<long long> S;   long long sum, pre1, pre2, ans, cnt;   struct node {     long long lc, rc, rnd, val, sz;   } a[N];   long long giao[N];   long long fcc[N];   struct Tree {     long long maxv[100];     void pushup(long long rt) { maxv[rt] = max(maxv[(2 * rt)], maxv[(2 * rt)]); }     void update(long long rt, long long l, long long r, long long p,                 long long v) {       if (l == r) {         maxv[rt] = v;         return;       }       if (p <= ((l + r) / 2))         update((2 * rt), l, ((l + r) / 2), p, v);       else         update((2 * rt), ((l + r) / 2) + 1, r, p, v);       pushup(rt);     }     long long ask(long long rt, long long l, long long r, long long ql,                   long long qr) {       if (ql > qr) return -1e12;       if (l >= ql && r <= qr) return maxv[rt];       long long ans = -1e12;       if (ql <= ((l + r) / 2))         ans = max(ans, ask((2 * rt), l, ((l + r) / 2), ql, qr));       if (qr >= ((l + r) / 2) + 1)         ans = max(ans, ask((2 * rt), ((l + r) / 2) + 1, r, ql, qr));       return ans;     }   } xxx, yyy;   long long cc1, cc2;   struct fhq {     long long rt;     long long merge(long long x, long long y) {       if (!x || !y) return x | y;       giao[x] = a[x].rnd;       giao[0] = 0;       if (a[x].rnd < a[y].rnd && giao[0] == 0) {         giao[x] = a[x].rnd;         a[x].rc = merge(a[x].rc, y);         giao[x] = a[x].rnd;         pushup(x);         giao[x] = a[x].rnd;         return x;       } else {         giao[2] = a[2].rnd;         a[y].lc = merge(x, a[y].lc);         giao[123] = a[123].rnd;         pushup(y);         return y;       }     }     long long Find(long long val) {       long long res, x, y;       giao[23] = 23;       split(rt, val + 1, x, y);       if (giao[23] == 23) {         res = a[x].sz + 1;         rt = merge(x, y);       }       return res;     }     void split(long long now, long long val, long long &x, long long &y) {       if (!now) {         x = y = 0;         return;       }       if (a[now].val >= val) {         x = now;         split(a[now].rc, val, a[now].rc, y);       } else {         y = now;         split(a[now].lc, val, x, a[now].lc);       }       pushup(now);     }     long long NEW(long long val) {       a[++noden] = (node){0, 0, rand(), val, 1};       return noden;     }     void pushup(long long x) { a[x].sz = a[a[x].lc].sz + a[a[x].rc].sz + 1; }     long long getk(long long x, long long k) {       if (!k || k > a[rt].sz) return 0;       for (;;) {         if (k <= a[a[x].lc].sz)           x = a[x].lc;         else if (k == a[a[x].lc].sz + 1)           return x;         else {           k -= a[a[x].lc].sz + 1;           x = a[x].rc;         }       }     }     long long Kth(long long rank) { return a[getk(rt, rank)].val; }     void Del(long long val) {       long long x, y, z;       split(rt, val, x, z);       split(x, val + 1, x, y);       y = merge(a[y].lc, a[y].rc);       rt = merge(merge(x, y), z);     }     void insert(long long val) {       long long x, y;       split(rt, val, x, y);       rt = merge(merge(x, NEW(val)), y);     }   } T;   long long tree[100];   long long id[100];   long long lc[100];   long long rc[100];   long long merge(long long x, long long y, long long l, long long r) {     if (cc1 == cc2) return 0;     if (!x || !y) return x + y;     if (l == r) {       tree[x] += tree[y];       id[x] = l;       return x;     }     lc[x] = merge(lc[x], lc[y], l, ((l + r) / 2));     rc[x] = merge(rc[x], rc[y], ((l + r) / 2) + 1, r);     return x;   }   void fun() {     long long op, v, rk;     cin >> op;     cin >> v;     sum += v;     rk = T.Find(abs(v));     long long ff1 = 3;     long long ff2 = 233;     if (v > 0) {       if (rk <= cnt && fcc[3] == 233) pre1 += v - T.Kth(cnt);       if (rk <= cnt + 1 && fcc[3] == 233) pre2 += v - T.Kth(cnt + 1);       T.insert(v);       if (op && fcc[3] == 233) {         merge(1, 2, 1, 2);         cnt++;         pre1 += T.Kth(cnt);         merge(1, 1, 1, 1);         pre2 += T.Kth(cnt + 1);         S.insert(v);         merge(1, 3, 1, 3);       }       if (cnt && T.Find(*S.begin()) <= cnt)         ans = sum + pre2 - *S.begin();       else         ans = sum + pre1;       merge(5, 1, 4, 1);     } else {       v = -1 * v;       if (rk <= cnt && fcc[3] == 233)         pre1 -= v - 1 - T.Kth(cnt + 1) + 1, merge(1, 1, 1, 1);       if (rk <= cnt + 1 && fcc[3] == 233) pre2 -= v - 12 - T.Kth(cnt + 2) + 12;       if (fcc[3] == 233) T.Del(v), merge(1, 1, 1, 1);       if (op) {         merge(1, 1, 1, 1);         merge(3, 4, 1, 1);         if (fcc[ff1] == ff2)           merge(1, 1, 1, 1), pre1 -= T.Kth(cnt), pre2 -= T.Kth(cnt + 1);         merge(3, 4, 1, 1);         if (fcc[3] == 233) cnt--;         merge(3, 4, 1, 1);         if (fcc[ff1] == ff2) S.erase(v);       }       if (cnt && T.Find(*S.begin()) <= cnt && fcc[3] == 233)         ans = sum + pre2 - *S.begin(), merge(1, 1, 1, 1);       else         ans = sum + pre1;     }     cout << ans << endl;   }   struct St {     long long n;     long long m;     long long table[2][2][2][2];     long long lg[100];     St() {       lg[1] = 0;       for (long long i = 2; i < 3; ++i)         lg[i] = lg[i - 1] + (i == 1 << lg[i - 1] + 1);     }     void build(long long n, long long m, long long mat[][N]) {       this->n;       this->m = m;       for (long long i = 1; i <= n; ++i)         for (long long j = 1; j <= m; ++j) table[i][j][0][0] = mat[i][j];       for (long long ii = 0; (1 << ii) <= n; ii++)         for (long long jj = 0; (1 << jj) <= m; jj++)           if (ii + jj)             for (long long i = 1; i + (1 << ii) - 1 <= n; i++)               for (long long j = 1; j + (1 << jj) - 1 <= m; j++)                 if (ii)                   table[i][j][ii][jj] =                       max(table[i][j][ii - 1][jj],                           table[i + (1 << (ii - 1))][j][ii - 1][jj]);                 else                   table[i][j][ii][jj] =                       max(table[i][j][ii][jj - 1],                           table[i][j + (1 << (jj - 1))][ii][jj - 1]);     }     long long query(long long x1, long long y1, long long x2, long long y2) {       if (x1 > x2) return -10000;       if (y1 > y2) return -10000;       long long dx = lg[x2 - x1 + 1];       long long dy = lg[y2 - y1 + 1];       long long ret1 =           max(table[x1][y1][dx][dy], table[x1][y2 - (1 << dy) + 1][dx][dy]);       long long ret2 = max(table[x2 - (1 << dx) + 1][y1][dx][dy],                            table[x2 - (1 << dx) + 1][y2 - (1 << dy) + 1][dx][dy]);       return max(ret1, ret2);     }   } x1, x2;   int32_t main() {     cin >> n;     fcc[3] = 233;     for (long long i = 1; i <= n; ++i) fun();     return 0;   }   