#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) { cerr << endl; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int fx[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
const int fxx[8][2] = {{0, 1}, {0, -1}, {1, 0},  {-1, 0},
                       {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
int n;
set<int> sdouble;
long long sum[2];
set<int> s[2];
int cntdouble[2];
void upd(int id) {
  int x = *s[id].rbegin();
  if (id == 1) x = *s[id].begin();
  bool d = sdouble.count(x);
  sum[id] -= x, sum[!id] += x;
  s[id].erase(x), s[!id].insert(x);
  cntdouble[id] -= d, cntdouble[!id] += d;
}
int main() {
  scanf("%d", &n);
  for (int i = int(0); i < int(n); i++) {
    int tp, x;
    scanf("%d%d", &tp, &x);
    if (x > 0) {
      sum[0] += x;
      s[0].insert(x);
      cntdouble[0] += tp;
      if (tp) sdouble.insert(x);
    } else {
      x = -x;
      int id = 0;
      if (s[1].count(x)) id = 1;
      sum[id] -= x;
      s[id].erase(x);
      cntdouble[id] -= tp;
      if (tp) {
        sdouble.erase(x);
      }
    }
    int sumd = cntdouble[0] + cntdouble[1];
    while (s[1].size() < sumd) upd(0);
    while (s[1].size() > sumd) upd(1);
    while (s[1].size() > 0 && s[0].size() > 0 &&
           *s[0].rbegin() > *s[1].begin()) {
      upd(0);
      upd(1);
    }
    long long ans = sum[0] + sum[1] * 2;
    if (cntdouble[1] == sumd && sumd > 0) {
      ans -= *s[1].begin();
      if (s[0].size() > 0) ans += *s[0].rbegin();
    }
    printf("%lld\n", ans);
  }
  return 0;
}
