#include <bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
clock_t startTime;
double getCurrentTime() {
  return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
const int n = 202;
set<int> small, big, fire, li;
int64_t s1 = 0, s2 = 0;
void add(int d) {
  s1 += d;
  if (big.empty() || d < *big.begin())
    small.insert(d);
  else {
    big.insert(d);
    s2 += d;
  }
}
void take(int d) {
  s1 -= d;
  if (small.count(d))
    small.erase(d);
  else {
    big.erase(d);
    s2 -= d;
  }
}
int64_t solve() {
  while (big.size() > li.size()) {
    int a = *big.begin();
    s2 -= a;
    small.insert(a);
    big.erase(a);
  }
  while (big.size() < li.size()) {
    int a = *small.rbegin();
    small.erase(a);
    big.insert(a);
    s2 += a;
  }
  int64_t ans = s1 + s2;
  if (li.size() > 0 && (fire.empty() || *fire.rbegin() < *li.begin())) {
    ans -= *li.begin();
    if (!fire.empty()) ans += *fire.rbegin();
  }
  return ans;
}
int main() {
  startTime = clock();
  int n;
  cin >> n;
  while (n--) {
    int t, d;
    cin >> t >> d;
    if (d > 0) {
      if (t == 0)
        fire.insert(d);
      else
        li.insert(d);
      add(d);
    } else {
      d *= -1;
      if (t == 0)
        fire.erase(d);
      else
        li.erase(d);
      take(d);
    }
    cout << solve() << '\n';
  }
}
