#include <bits/stdc++.h>
using namespace std;
const long long N = 810000;
inline long long read() {
  long long s = 0, w = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
  return s * w;
}
long long n;
struct segg {
  long long son[N][2], siz[N], cnt = 0, val[N], rd[N], root, x, y, z, sum[N];
  inline long long New_Node(long long x) {
    cnt++;
    val[cnt] = sum[cnt] = x;
    siz[cnt] = 1;
    rd[cnt] = rand();
    return cnt;
  }
  inline void UpDate(long long x) {
    siz[x] = siz[son[x][0]] + siz[son[x][1]] + 1;
    sum[x] = sum[son[x][0]] + sum[son[x][1]] + val[x];
  }
  void Split(long long root, long long k, long long &x, long long &y) {
    if (!root)
      x = y = 0;
    else {
      if (val[root] > k) {
        y = root;
        Split(son[root][0], k, x, son[root][0]);
      } else {
        x = root;
        Split(son[root][1], k, son[root][1], y);
      }
      UpDate(root);
    }
  }
  long long Merge(long long x, long long y) {
    if (!x || !y) return x + y;
    if (rd[x] < rd[y]) {
      son[x][1] = Merge(son[x][1], y);
      UpDate(x);
      return x;
    } else {
      son[y][0] = Merge(x, son[y][0]);
      UpDate(y);
      return y;
    }
  }
  void Insert(long long s) {
    Split(root, s, x, y);
    root = Merge(Merge(x, New_Node(s)), y);
  }
  void Delete(long long s) {
    Split(root, s, x, z);
    Split(x, s - 1, x, y);
    y = Merge(son[y][0], son[y][1]);
    root = Merge(Merge(x, y), z);
  }
  void Rankdx(long long s) {
    Split(root, s - 1, x, y);
    printf("%lld\n", siz[x] + 1);
    root = Merge(x, y);
  }
  long long dk(long long root, long long k) {
    while (1) {
      if (siz[son[root][0]] >= k)
        root = son[root][0];
      else if (siz[son[root][0]] == k - 1)
        return val[root];
      else
        k -= siz[son[root][0]] + 1, root = son[root][1];
    }
  }
  void Findkx(long long s) { printf("%lld\n", val[dk(root, s)]); }
  void Findqq(long long s) {
    Split(root, s - 1, x, y);
    printf("%lld\n", val[dk(x, siz[x])]);
    root = Merge(x, y);
  }
  void Findhz(long long s) {
    Split(root, s, x, y);
    printf("%lld\n", val[dk(y, 1)]);
    root = Merge(x, y);
  }
  long long FindS(long long x, long long p) {
    if (!p) return 0;
    long long qwq = 0;
    while (1) {
      if (p == siz[son[x][0]] + 1) return qwq + sum[son[x][0]] + val[x];
      if (p <= siz[son[x][0]])
        x = son[x][0];
      else
        qwq += sum[son[x][0]] + val[x], p = p - siz[son[x][0]] - 1,
                                        x = son[x][1];
    }
  }
} A, B;
signed main() {
  srand((unsigned)time(NULL));
  n = read();
  for (register long long i = 1; i <= n; i++) {
    long long opt = read(), x = read();
    if (!opt) {
      if (x > 0)
        A.Insert(-x);
      else
        A.Delete(x);
    }
    if (x > 0)
      B.Insert(-x);
    else
      B.Delete(x);
    long long qwq = B.sum[B.root];
    long long res = B.siz[B.root] - A.siz[A.root];
    if (!res) {
      printf("%lld\n", -qwq);
      continue;
    }
    if (B.dk(B.root, res) < A.dk(A.root, 1))
      printf("%lld\n", -qwq - A.dk(A.root, 1) - B.FindS(B.root, res - 1));
    else
      printf("%lld\n", -qwq - B.FindS(B.root, res));
  }
  return 0;
}
