#include <bits/stdc++.h>
using namespace std;
const long double PI = atan(1.0) * 4;
const int64_t INF = 3e18;
const int32_t LOG = 21;
const int32_t MOD = 1e9 + 7;
long long int power(long long int x, long long int y) {
  if (y == 0) return 1;
  long long int temp = power(x, y / 2);
  temp = (temp * temp) % MOD;
  if (y & 1) temp = (temp * x) % MOD;
  return temp;
}
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  long long int tests = 1;
  for (long long int ii = 0; ii < (long long int)tests; ii++) {
    long long int n;
    cin >> n;
    long long int sum = 0;
    set<pair<long long int, long long int> > open;
    set<pair<long long int, long long int> > processed;
    long long int processed_sum = 0;
    long long int cnt_fire = 0;
    for (long long int i = 1; i < (long long int)n + 1; i++) {
      long long int type, d;
      cin >> type >> d;
      if (type == 0) {
        if (d > 0) {
          if (!processed.empty()) {
            pair<long long int, long long int> p = *processed.begin();
            if (p.first <= d) {
              processed.erase(processed.begin());
              if (p.second == -1) cnt_fire--;
              open.insert(p);
              processed.insert({d, -1});
              cnt_fire++;
              processed_sum -= p.first;
              processed_sum += d;
            } else
              open.insert({d, -1});
          } else
            open.insert({d, -1});
        } else {
          pair<long long int, long long int> toRem = {-d, -1};
          if (processed.find(toRem) != processed.end()) {
            processed.erase(toRem);
            cnt_fire--;
            processed_sum += d;
            if (!open.empty()) {
              pair<long long int, long long int> p = *open.rbegin();
              open.erase(p);
              processed.insert(p);
              processed_sum += p.first;
              if (p.second == -1) cnt_fire++;
            }
          } else if (open.find(toRem) != open.end())
            open.erase(toRem);
        }
        sum += d;
      } else {
        if (d > 0) {
          pair<long long int, long long int> p = {d, -2};
          open.insert(p);
          pair<long long int, long long int> p1 = *open.rbegin();
          open.erase(p1);
          processed.insert(p1);
          processed_sum += p1.first;
          if (p1.second == -1) cnt_fire++;
        } else {
          pair<long long int, long long int> toRem = {-d, -2};
          if (processed.find(toRem) != processed.end()) {
            processed.erase(toRem);
            processed_sum += d;
          } else {
            open.erase(toRem);
            if (!processed.empty()) {
              pair<long long int, long long int> p = *processed.begin();
              processed.erase(processed.begin());
              open.insert(p);
              processed_sum -= p.first;
              if (p.second == -1) cnt_fire--;
            }
          }
        }
        sum += d;
      }
      long long int ans = 0;
      assert(cnt_fire >= 0);
      if (cnt_fire > 0)
        ans = sum + processed_sum;
      else if (processed.empty())
        ans = sum;
      else {
        long long int add = 0;
        if (!open.empty()) ans += open.rbegin()->first;
        ans -= processed.begin()->first;
        ans += processed_sum;
        ans += sum;
      }
      cout << ans << '\n';
    }
  }
  return 0;
}
