#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n;
  cin >> n;
  set<long long int> s1, s2, l;
  long long int t1 = 0, t2 = 0;
  s1.insert(0);
  for (int i = 0; i < n; ++i) {
    long long int tp, d;
    cin >> tp >> d;
    if (d > 0) {
      t1 += d;
      s1.insert(d);
    } else {
      d *= -1;
      if (s1.find(d) != s1.end()) {
        t1 -= d;
        s1.erase(d);
      } else {
        s2.erase(d);
        long long int temp = *(--s1.end());
        s1.erase(temp);
        s2.insert(temp);
        t1 -= temp;
        t2 += temp - d;
      }
      d *= -1;
    }
    if (s2.size() > 0 && s1.size() > 0 && *(--s1.end()) > *s2.begin()) {
      long long int te1, te2;
      te1 = *(--s1.end());
      te2 = *s2.begin();
      s1.erase(te1);
      s2.erase(te2);
      s1.insert(te2);
      s2.insert(te1);
      t1 += te2 - te1;
      t2 += te1 - te2;
    }
    if (tp) {
      if (d > 0) {
        long long int temp = *(--s1.end());
        s1.erase(temp);
        s2.insert(temp);
        t1 -= temp;
        t2 += temp;
        l.insert(d);
      } else {
        long long int temp = *(s2.begin());
        s2.erase(temp);
        s1.insert(temp);
        t1 += temp;
        t2 -= temp;
        l.erase(-d);
      }
    }
    int fl = 0;
    if (s2.find(*(l.begin())) != s2.end()) {
      long long int temp = *(--s1.end());
      t1 -= temp;
      t2 += temp;
      long long int te = *(l.begin());
      t1 += te;
      t2 -= te;
      fl = 1;
    }
    cout << 2 * t2 + t1 << "\n";
    if (fl) {
      long long int temp = *(--s1.end());
      t1 += temp;
      t2 -= temp;
      long long int te = *(l.begin());
      t1 -= te;
      t2 += te;
    }
  }
}
