#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::string;
using std::vector;
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int64_t n, ans = 0, dbcnt = 0;
  std::set<int> tp0, db, undb;
  for (cin >> n; n--;) {
    int tp, x;
    cin >> tp >> x;
    ans += x;
    if (x > 0) {
      if (tp)
        dbcnt++;
      else
        tp0.insert(x);
      if (!undb.empty() && x <= *undb.rbegin())
        undb.insert(x);
      else
        db.insert(x), ans += x;
    } else {
      x = -x;
      if (tp)
        dbcnt--;
      else
        tp0.erase(x);
      if (!undb.empty() && x <= *undb.rbegin())
        undb.erase(x);
      else
        db.erase(x), ans -= x;
    }
    while (db.size() < dbcnt) {
      int tmp = *undb.rbegin();
      ans += tmp;
      db.insert(tmp);
      undb.erase(tmp);
    }
    while (db.size() > dbcnt) {
      int tmp = *db.begin();
      ans -= tmp;
      db.erase(tmp);
      undb.insert(tmp);
    }
    cout << ans + std::min(db.size()
                               ? (tp0.size() ? *tp0.rbegin() : 0) - *db.begin()
                               : 0,
                           0)
         << '\n';
  }
}
