#include <bits/stdc++.h>
using namespace std;
set<int> fire, k_big, rest;
long long sumall, sum_double;
int light, light_in_k_max;
int n;
int main() {
  scanf("%d", &n);
  while (n--) {
    int tp, value;
    scanf("%d%d", &tp, &value);
    if (value > 0) {
      sumall += value;
      rest.insert(value);
      if (tp == 1) {
        light++;
        int r = *rest.rbegin();
        k_big.insert(r);
        rest.erase(r);
        sum_double += r;
        if (!fire.count(r)) light_in_k_max++;
      } else {
        fire.insert(value);
        if (light != 0) {
          int r = *k_big.begin();
          if (value > r) {
            k_big.erase(r);
            k_big.insert(value);
            rest.erase(value);
            rest.insert(r);
            sum_double -= r;
            sum_double += value;
            if (!fire.count(r)) light_in_k_max--;
          }
        }
      }
    } else {
      value = -value;
      sumall -= value;
      if (tp == 1) {
        light--;
        if (k_big.count(value)) {
          k_big.erase(value);
          light_in_k_max--;
          sum_double -= value;
        } else {
          rest.erase(value);
          int r = *k_big.begin();
          k_big.erase(r);
          rest.insert(r);
          sum_double -= r;
          if (!fire.count(r)) light_in_k_max--;
        }
      } else {
        fire.erase(value);
        if (k_big.count(value)) {
          k_big.erase(value);
          int r = *rest.rbegin();
          rest.erase(r);
          k_big.insert(r);
          sum_double -= value;
          sum_double += r;
          if (!fire.count(r)) light_in_k_max++;
        } else
          rest.erase(value);
      }
    }
    if (light_in_k_max != light)
      printf("%lld\n", sumall + sum_double);
    else {
      if (light == 0) {
        printf("%lld\n", sumall);
      } else {
        int r = 0;
        if (!rest.empty()) r = *rest.rbegin();
        printf("%lld\n", sumall + sum_double - *k_big.begin() + r);
      }
    }
  }
  return 0;
}
