#include <bits/stdc++.h>
int main() {
  int N;
  std::cin >> N;
  std::set<std::pair<int, int>> doubled;
  std::set<std::pair<int, int>> pend;
  int to_double = 0;
  int f_doubled = 0;
  int64_t total_damage = 0;
  int t;
  int d;
  for (int i = 0; i < N; i++) {
    std::cin >> t;
    std::cin >> d;
    total_damage += d;
    to_double += t * (d > 0 ? 1 : -1);
    if (d > 0) {
      pend.insert({d, t});
    } else {
      auto search = doubled.find({-d, t});
      if (search != doubled.end()) {
        doubled.erase(search);
        if (t == 0) f_doubled--;
        total_damage += d;
      } else {
        pend.erase(pend.find({-d, t}));
      }
    }
    if (to_double > doubled.size()) {
      if (pend.size() > 0) {
        auto it_pend = --pend.end();
        std::pair<int, int> max = *it_pend;
        doubled.insert(max);
        pend.erase(it_pend);
        if (max.second == 0) f_doubled++;
        total_damage += max.first;
      }
    } else if (to_double < doubled.size()) {
      if (doubled.size() > 0) {
        auto it_doubled = doubled.begin();
        std::pair<int, int> min = *it_doubled;
        doubled.erase(it_doubled);
        pend.insert(min);
        if (min.second == 0) f_doubled--;
        total_damage -= min.first;
      }
    } else {
      if (to_double > 0 && pend.size() > 0) {
        auto it_doubled = doubled.begin();
        auto it_pend = --pend.end();
        std::pair<int, int> max = *it_pend;
        std::pair<int, int> min = *it_doubled;
        if (max > min) {
          doubled.erase(it_doubled);
          pend.erase(it_pend);
          doubled.insert(max);
          pend.insert(min);
          if (max.second == 0) f_doubled++;
          if (min.second == 0) f_doubled--;
          total_damage += max.first - min.first;
        }
      }
    }
    if (doubled.size() == to_double && f_doubled == 0 && to_double > 0) {
      auto it_doubled = doubled.begin();
      std::pair<int, int> min = *it_doubled;
      doubled.erase(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);
        f_doubled++;
        total_damage += max.first;
      }
      pend.insert(min);
    }
    std::cout << total_damage << std::endl;
  }
  return 0;
}
