#include <bits/stdc++.h>
void solve(std::vector<std::pair<int, int>> &line) {
  std::set<std::pair<int, int>> doubled;
  std::set<std::pair<int, int>> pending;
  int to_double = 0;
  int l_doubled = 0;
  int64_t total_damage = 0;
  for (int i = 0; i < line.size(); i++) {
    int d = line[i].first;
    int t = line[i].second;
    total_damage += d;
    to_double += t * (d > 0 ? 1 : -1);
    if (d > 0) {
      pending.insert({d, t});
    } else {
      auto search = doubled.find({-d, t});
      if (search != doubled.end()) {
        doubled.erase(search);
        l_doubled -= t;
        total_damage += d;
      } else {
        pending.erase(pending.find({-d, t}));
      }
    }
    if (to_double > doubled.size()) {
      if (pending.size() > 0) {
        auto it_pending = --pending.end();
        std::pair<int, int> max = *it_pending;
        doubled.insert(max);
        pending.erase(it_pending);
        l_doubled += max.second;
        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);
        pending.insert(min);
        l_doubled -= min.second;
        total_damage -= min.first;
      }
    } else {
      if (to_double > 0 && pending.size() > 0) {
        auto it_doubled = doubled.begin();
        auto it_pending = --pending.end();
        std::pair<int, int> max = *it_pending;
        std::pair<int, int> min = *it_doubled;
        if (max > min) {
          doubled.erase(it_doubled);
          pending.erase(it_pending);
          doubled.insert(max);
          pending.insert(min);
          l_doubled += max.second - min.second;
          total_damage += max.first - min.first;
        }
      }
    }
    if (doubled.size() == to_double && l_doubled == to_double &&
        to_double > 0) {
      auto it_doubled = doubled.begin();
      std::pair<int, int> min = *it_doubled;
      doubled.erase(it_doubled);
      l_doubled--;
      total_damage -= min.first;
      if (pending.size() > 0) {
        auto it_pending = --pending.end();
        std::pair<int, int> max = *it_pending;
        pending.erase(it_pending);
        doubled.insert(max);
        total_damage += max.first;
      }
      pending.insert(min);
    }
    std::cout << total_damage << std::endl;
  }
}
int main() {
  std::ios_base::sync_with_stdio(false);
  std::vector<std::pair<int, int>> line;
  int N;
  std::cin >> N;
  line.reserve(N);
  std::pair<int, int> value;
  for (int i = 0; i < N; i++) {
    std::cin >> value.second;
    std::cin >> value.first;
    line.push_back(value);
  }
  solve(line);
  return 0;
}
