#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5;
const int P = 998244353;
const int inf = 0x3f3f3f3f;
int n, pos[maxn], tot;
long long ans = 0;
pair<int, int> q[maxn];
inline int read() {
  char ch = getchar();
  int u = 0, f = 1;
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    u = u * 10 + ch - 48;
    ch = getchar();
  }
  return u * f;
}
struct BIT {
  long long C[maxn];
  inline void update(int x, int y) {
    for (int i = x; i <= tot; i += (i & -i)) C[i] += y;
  }
  inline long long sum(int x, long long rnt = 0) {
    for (int i = x; i; i -= (i & -i)) rnt += C[i];
    return rnt;
  }
} A, B, C;
int main() {
  n = read();
  for (int i = 1; i <= n; ++i) q[i].first = read(), q[i].second = read();
  for (int i = 1; i <= n; ++i) pos[++tot] = abs(q[i].second);
  sort(pos + 1, pos + 1 + tot);
  tot = unique(pos + 1, pos + 1 + tot) - pos - 1;
  for (int i = 1; i <= n; ++i) {
    int x = lower_bound(pos + 1, pos + 1 + tot, abs(q[i].second)) - pos;
    if (q[i].second < 0) {
      A.update(x, q[i].second);
      B.update(x, -1);
      if (q[i].first) C.update(x, -1);
    } else {
      A.update(x, q[i].second);
      B.update(x, 1);
      if (q[i].first) C.update(x, 1);
    }
    int cnt = C.sum(tot), cnt1 = B.sum(tot);
    int l = 1, r = tot, ans = 0;
    if (cnt == 0) {
      printf("%lld\n", A.sum(tot));
      continue;
    }
    while (l <= r) {
      int mid = (l + r >> 1);
      if (cnt1 - B.sum(mid - 1) >= cnt)
        l = mid + 1, ans = mid;
      else
        r = mid - 1;
    }
    if (cnt1 - B.sum(ans - 1) == cnt) {
      long long ANS = A.sum(tot) * 2 - A.sum(ans - 1);
      if (C.sum(ans - 1) == 0) {
        ANS -= pos[ans];
        if (cnt != cnt1) {
          l = 1;
          r = tot;
          while (l <= r) {
            int mid = (l + r >> 1);
            if (cnt1 - B.sum(mid - 1) >= cnt + 1)
              l = mid + 1, ans = mid;
            else
              r = mid - 1;
          }
          ANS += pos[ans];
        }
      }
      printf("%lld\n", ANS);
    } else {
      printf("%lld\n", A.sum(tot) + A.sum(tot) - A.sum(ans) +
                           (cnt - cnt1 + B.sum(ans) * pos[ans]));
    }
  }
  return 0;
}
