#include <bits/stdc++.h>
const int maxn = 200000 + 5;
std::multiset<int> S;
const int INF = 0x3f3f3f3f;
int type[maxn], d[maxn], x[maxn], c;
long long sum[maxn * 4];
int cnt[maxn * 4];
void update(int o, int L, int R, int p, int d = 1) {
  if (L == R) {
    cnt[o] += d;
    sum[o] += x[p - 1] * d;
    return;
  }
  int M = L + (R - L) / 2;
  if (p <= M)
    update((o << 1), L, M, p, d);
  else
    update((o << 1 | 1), M + 1, R, p, d);
  sum[o] = sum[(o << 1)] + sum[(o << 1 | 1)];
  cnt[o] = cnt[(o << 1)] + cnt[(o << 1 | 1)];
}
long long query_k(int o, int L, int R, int k) {
  if (cnt[o] <= k) return sum[o];
  if (L == R) {
    return static_cast<long long>(x[L - 1]) * k;
  }
  int M = L + (R - L) / 2;
  if (cnt[(o << 1 | 1)] < k)
    return sum[(o << 1 | 1)] + query_k((o << 1), L, M, k - cnt[(o << 1 | 1)]);
  return query_k((o << 1 | 1), M + 1, R, k);
}
inline int locate(int v) { return std::lower_bound(x, x + c, v) - x + 1; }
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", type + i, d + i);
    if (d[i] > 0) x[c++] = d[i];
  }
  std::sort(x, x + c);
  c = std::unique(x, x + c) - x;
  long long total = 0;
  for (int i = 0; i < n; i++) {
    int sign = 1, v = d[i];
    if (d[i] < 0) {
      sign = -1;
      v = -d[i];
    }
    total += d[i];
    int idx = locate(v);
    if (type[i]) {
      if (sign > 0) {
        if (S.empty()) {
          S.insert(idx);
        } else {
          int min = *S.begin();
          S.insert(idx);
          if (idx < min)
            update(1, 1, c, min);
          else
            update(1, 1, c, idx);
        }
      } else {
        S.erase(idx);
        if (!S.empty()) {
          int min = *S.begin();
          if (idx < min)
            update(1, 1, c, min, -1);
          else
            update(1, 1, c, idx, -1);
        }
      }
    } else {
      update(1, 1, c, idx, sign);
    }
    long long doubled = query_k(1, 1, c, static_cast<int>(S.size()));
    printf("%lld\n", total + doubled);
  }
  return 0;
}
