#include <bits/stdc++.h>
int main() {
  int n;
  scanf("%d", &n);
  int64_t total_damage = 0;
  int to_double = 0;
  int fire_doubled = 0;
  std::set<std::pair<int, int>> doubled;
  std::set<std::pair<int, int>> pend;
  for (int i = 1; i <= n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (y > 0) {
      if (x == 1) to_double++;
      total_damage += y;
      pend.insert({y, x});
    } else {
      y = -y;
      total_damage -= y;
      auto it = pend.find({y, x});
      if (it != pend.end()) {
        pend.erase(it);
      } else {
        it = doubled.find({y, x});
        doubled.erase(it);
        if (x == 0) fire_doubled--;
        total_damage -= y;
      }
      if (x == 1) {
        to_double--;
        if (doubled.size() > 0) {
          auto it_pend = doubled.begin();
          std::pair<int, int> max = *it_pend;
          if (max.second == 0) fire_doubled--;
          doubled.erase(it_pend);
          total_damage -= max.first;
          pend.insert(max);
        }
      }
    }
    if (doubled.size() < to_double && pend.size() > 0) {
      auto it = --pend.end();
      std::pair<int, int> max = *it;
      doubled.insert(max);
      pend.erase(it);
      if (max.second == 0) fire_doubled++;
      total_damage += max.first;
    } else if (doubled.size() > 0 && pend.size() > 0 &&
               doubled.size() == to_double) {
      auto it_doubled = doubled.begin();
      auto it_pend = --pend.end();
      std::pair<int, int> min = *it_doubled;
      std::pair<int, int> max = *it_pend;
      if (max.first > min.first) {
        if (max.second == 0) fire_doubled++;
        if (min.second == 0) fire_doubled--;
        doubled.erase(it_doubled);
        pend.erase(it_pend);
        doubled.insert(max);
        pend.insert(min);
        total_damage += max.first - min.first;
      }
    }
    if (doubled.size() > 0 && fire_doubled == 0 &&
        doubled.size() == to_double) {
      auto it_doubled = doubled.begin();
      doubled.erase(it_doubled);
      std::pair<int, int> min = *it_doubled;
      total_damage -= min.first;
      if (pend.size() > 0) {
        auto it_pend = --pend.end();
        std::pair<int, int> max = *it_pend;
        pend.erase(it_pend);
        doubled.insert(max);
        fire_doubled++;
        total_damage += max.first;
      }
      pend.insert(min);
    }
    printf("%lld\n", total_damage);
  }
  return 0;
}
