#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200000 + 11;
const int INF = 0x3f3f3f3f;
multiset<int> S1, S2, F;
multiset<int>::iterator it1, it2;
long long sum1, sum2;
int L;
int a, b, n;
void maintain() {
  if (S1.empty() || S2.empty()) return;
  it1 = S1.end();
  it1--;
  it2 = S2.begin();
  while (*it1 > *it2) {
    a = *it1;
    b = *it2;
    S1.erase(a);
    S1.insert(b);
    S2.erase(b);
    S2.insert(a);
    sum1 += a - b;
    sum2 += b - a;
    it1 = S1.end();
    it1--;
    it2 = S2.begin();
  }
}
void check() {
  cout << "///////////////////////////////" << endl;
  cout << sum1 << " " << sum2 << endl;
  cout << L << endl;
  for (it1 = S1.begin(); it1 != S1.end(); it1++) {
    cout << -*it1 << " ";
  }
  cout << endl;
  for (it1 = S2.begin(); it1 != S2.end(); it1++) {
    cout << -*it1 << " ";
  }
  cout << endl;
  cout << "///////////////////////////////" << endl;
}
int main() {
  sum1 = sum2 = 0;
  L = 0;
  scanf("%d", &n);
  while (n--) {
    int opt, d;
    scanf("%d%d", &opt, &d);
    if (opt == 1) {
      if (d > 0) {
        L++;
        S1.insert(-d);
        sum1 += d;
        maintain();
      } else {
        L--;
        if (S1.count(d)) {
          S1.erase(d);
          sum1 += d;
        } else {
          S2.erase(d);
          sum2 += d;
          it1 = S1.end();
          it1--;
          a = *it1;
          S1.erase(a);
          S2.insert(a);
          sum1 += a;
          sum2 -= a;
        }
      }
    } else {
      if (d > 0) {
        F.insert(-d);
        S2.insert(-d);
        sum2 += d;
        maintain();
      } else {
        F.erase(d);
        if (S2.count(d)) {
          S2.erase(d);
          sum2 += d;
        } else {
          S1.erase(d);
          sum1 += d;
          a = *(S2.begin());
          S2.erase(a);
          S1.insert(a);
          sum2 += a;
          sum1 -= a;
        }
      }
    }
    if (L == 0) {
      printf("%lld\n", sum1 + sum2);
      continue;
    }
    if (S2.empty()) {
      it1 = S1.end();
      it1--;
      printf("%lld\n", sum1 * 2 + *it1);
      continue;
    }
    it1 = S1.end();
    it1--;
    it2 = F.begin();
    if (*it2 <= *it1) {
      printf("%lld\n", sum1 * 2 + sum2);
    } else {
      printf("%lld\n", sum1 * 2 + sum2 + *it1 - *it2);
    }
  }
  return 0;
}
