#include <bits/stdc++.h>
using namespace std;
int n, tp, d;
set<int> fire, light, small, big;
long long sum, bigsum;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < (n); ++i) {
    cin >> tp >> d;
    if (tp) {
      if (d > 0)
        light.insert(d);
      else
        light.erase(light.find(-d));
    } else {
      if (d > 0)
        fire.insert(d);
      else
        fire.erase(fire.find(-d));
    }
    if (d > 0) {
      if (!big.empty() && d >= *big.begin())
        big.insert(d), bigsum += d;
      else
        small.insert(d);
      sum += d;
    } else {
      if (!big.empty() && -d >= *big.begin())
        big.erase(big.find(-d)), bigsum += d;
      else
        small.erase(small.find(-d));
      sum += d;
    }
    int num_light = light.size();
    while (big.size() < num_light) {
      big.insert(*small.rbegin());
      bigsum += *small.rbegin();
      small.erase(--small.end());
    }
    while (big.size() > num_light) {
      small.insert(*big.begin());
      bigsum -= *big.begin();
      big.erase(big.begin());
    }
    if (fire.empty() && light.empty()) {
      cout << 0 << endl;
    } else if (fire.empty()) {
      cout << sum + bigsum - *light.begin() << endl;
    } else if (*fire.rbegin() < *light.begin()) {
      cout << sum + bigsum - *light.begin() + *fire.rbegin() << endl;
    } else {
      cout << sum + bigsum << endl;
    }
  }
}
