#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int N = 5e3 + 4;
set<int> fire, elec, big, small;
long long total_sum = 0, big_sum = 0;
void add(int x) {
  total_sum += x;
  if ((int)big.size() == 0 or *big.begin() > x)
    small.insert(x);
  else
    big.insert(x), big_sum += x;
}
void rem(int x) {
  total_sum -= x;
  if (small.find(x) != small.end())
    small.erase(x);
  else
    big_sum -= x, big.erase(x);
}
long long calc() {
  if ((int)big.size() < (int)elec.size()) {
    big.insert(*small.rbegin());
    big_sum += *small.rbegin();
    small.erase(*small.rbegin());
  }
  if ((int)big.size() > (int)elec.size()) {
    big_sum -= *big.begin();
    small.insert(*big.begin());
    big.erase(*big.begin());
  }
  long long ans_here = total_sum + big_sum;
  if ((int)fire.size() == 0 or *fire.rbegin() < *elec.begin()) {
    ans_here -= *elec.begin();
    if ((int)fire.size()) ans_here += *fire.rbegin();
  }
  return ans_here;
}
int main() {
  int q;
  scanf("%d", &q);
  while (q--) {
    int type, val;
    scanf("%d", &type);
    scanf("%d", &val);
    if (type == 0) {
      if (val > 0)
        fire.insert(val), add(val);
      else
        fire.erase(-val), rem(-val);
    } else {
      if (val > 0)
        elec.insert(val), add(val);
      else
        elec.erase(-val), rem(-val);
    }
    long long ans = calc();
    printf("%lld\n", ans);
  }
  return 0;
}
