#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n, dfcnt, lcnt;
struct spell {
  int pow, type;
};
bool operator<(const spell& s1, const spell& s2) { return s1.pow > s2.pow; }
set<spell> doub, sing;
ll dsum, ssum;
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int t, p;
    cin >> t >> p;
    if (t == 0 && p < 0) {
      p = -p;
      if (doub.count({p, 0})) {
        dsum -= p;
        --dfcnt;
        doub.erase({p, 0});
        if (sing.size() > 0) {
          ssum -= sing.begin()->pow;
          dsum += sing.begin()->pow;
          dfcnt += (sing.begin()->type == 0);
          doub.insert(*sing.begin());
          sing.erase(sing.begin());
        }
      } else {
        ssum -= p;
        sing.erase({p, 0});
      }
    } else if (t == 1 && p < 0) {
      p = -p;
      --lcnt;
      if (doub.count({p, 1})) {
        dsum -= p;
        doub.erase({p, 1});
      } else {
        ssum -= p;
        sing.erase({p, 0});
        spell mov = *doub.rbegin();
        dfcnt -= (mov.type == 0);
        dsum -= mov.pow;
        ssum += mov.pow;
        doub.erase(mov);
        sing.insert(mov);
      }
    } else if (t == 0 && p > 0) {
      dsum += p;
      ++dfcnt;
      doub.insert({p, 0});
      if (doub.size() > lcnt ||
          (doub.size() == lcnt && doub.rbegin()->pow < sing.begin()->pow)) {
        spell mov = *doub.rbegin();
        dfcnt -= (mov.type == 0);
        dsum -= mov.pow;
        ssum += mov.pow;
        sing.insert(mov);
        doub.erase(mov);
        if (doub.size() < lcnt) {
          mov = *sing.begin();
          dfcnt += (mov.type == 0);
          dsum += mov.pow;
          ssum -= mov.pow;
          doub.insert(mov);
          sing.erase(mov);
        }
      }
    } else {
      ++lcnt;
      dsum += p;
      doub.insert({p, 1});
      if (doub.size() == lcnt && doub.rbegin()->pow < sing.begin()->pow) {
        spell mov = *doub.rbegin();
        dfcnt -= (mov.type == 0);
        dsum -= mov.pow;
        ssum += mov.pow;
        sing.insert(mov);
        doub.erase(mov);
        mov = *sing.begin();
        dfcnt += (mov.type == 0);
        dsum += mov.pow;
        ssum -= mov.pow;
        doub.insert(mov);
        sing.erase(mov);
      }
    }
    if (dfcnt > 0)
      cout << (dsum << 1) + ssum << endl;
    else if (lcnt == 0)
      cout << ssum << endl;
    else {
      ll ans = dsum - (doub.rbegin()->pow) +
               (sing.size() > 0 ? sing.begin()->pow : 0);
      ans <<= 1;
      ans += ssum + (doub.rbegin()->pow) -
             (sing.size() > 0 ? sing.begin()->pow : 0);
      cout << ans << endl;
    }
  }
  return 0;
}
