#include <bits/stdc++.h>
using namespace std;
struct IO {
  char buf[(1 << 20)], *p1, *p2;
  char pbuf[(1 << 20)], *pp;
  IO() : p1(buf), p2(buf), pp(pbuf) {}
  inline char gc() {
    return getchar();
    if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, (1 << 20), stdin);
    return p1 == p2 ? ' ' : *p1++;
  }
  inline bool blank(char ch) {
    return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
  }
  template <class T>
  inline void read(T &x) {
    register double tmp = 1;
    register bool sign = 0;
    x = 0;
    register char ch = gc();
    for (; !(ch >= '0' && ch <= '9'); ch = gc())
      if (ch == '-') sign = 1;
    for (; (ch >= '0' && ch <= '9'); ch = gc()) x = x * 10 + (ch - '0');
    if (ch == '.')
      for (ch = gc(); (ch >= '0' && ch <= '9'); ch = gc())
        tmp /= 10.0, x += tmp * (ch - '0');
    if (sign) x = -x;
  }
  inline void read(char *s) {
    register char ch = gc();
    for (; blank(ch); ch = gc())
      ;
    for (; !blank(ch); ch = gc()) *s++ = ch;
    *s = 0;
  }
  inline void read(char &c) {
    for (c = gc(); blank(c); c = gc())
      ;
  }
  template <class t>
  inline void write(t x) {
    if (x < 0)
      putchar('-'), write(-x);
    else {
      if (x > 9) write(x / 10);
      putchar('0' + x % 10);
    }
  }
} io;
const long long mod = 1e9 + 7;
const long long mo = 998244353;
const long long N = 2e6 + 5;
long long n, m, noden, tot;
struct node {
  long long lc, rc, rnd, val, sz;
} a[N];
struct fhq {
  long long rt;
  void pushup(long long x) { a[x].sz = a[a[x].lc].sz + a[a[x].rc].sz + 1; }
  long long NEW(long long val) {
    a[++noden] = (node){0, 0, rand(), val, 1};
    return noden;
  }
  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 merge(long long x, long long y) {
    if (!x || !y) return x | y;
    if (a[x].rnd < a[y].rnd) {
      a[x].rc = merge(a[x].rc, y);
      pushup(x);
      return x;
    } else {
      a[y].lc = merge(x, a[y].lc);
      pushup(y);
      return y;
    }
  }
  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;
      }
    }
  }
  void insert(long long val) {
    long long x, y;
    split(rt, val, x, y);
    rt = merge(merge(x, NEW(val)), y);
  }
  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);
  }
  long long Find(long long val) {
    long long res, x, y;
    split(rt, val + 1, x, y);
    res = a[x].sz + 1;
    rt = merge(x, y);
    return res;
  }
  long long Kth(long long rank) { return a[getk(rt, rank)].val; }
} T;
set<long long> S;
long long sum, pre1, pre2, ans;
signed main() {
  io.read(n);
  long long cnt = 0;
  for (long long i = (1); i <= (n); i++) {
    long long op, v, rk;
    io.read(op), io.read(v);
    sum += v;
    rk = T.Find(abs(v));
    if (v > 0) {
      if (rk <= cnt) pre1 += v - T.Kth(cnt);
      if (rk <= cnt + 1) pre2 += v - T.Kth(cnt + 1);
      T.insert(v);
      if (op) {
        cnt++;
        pre1 += T.Kth(cnt);
        pre2 += T.Kth(cnt + 1);
        S.insert(v);
      }
      if (cnt && T.Find(*S.begin()) <= cnt)
        ans = sum + pre2 - *S.begin();
      else
        ans = sum + pre1;
    } else {
      v = -1 * v;
      if (rk <= cnt) pre1 -= v - T.Kth(cnt + 1);
      if (rk <= cnt + 1) pre2 -= v - T.Kth(cnt + 2);
      T.Del(v);
      if (op) {
        pre1 -= T.Kth(cnt), pre2 -= T.Kth(cnt + 1);
        cnt--;
        S.erase(v);
      }
      if (cnt && T.Find(*S.begin()) <= cnt)
        ans = sum + pre2 - *S.begin();
      else
        ans = sum + pre1;
    }
    io.write(ans);
    puts("");
  }
  return 0;
}
