#include <bits/stdc++.h>
int main() {
  int n;
  scanf("%d", &n);
  int64_t sum1 = 0;
  int64_t sum2 = 0;
  int to_double = 0;
  int zero = 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++;
      sum1 += y;
      pend.insert({y, x});
    } else {
      y = -y;
      sum1 -= 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) zero--;
        sum2 -= y;
      }
      if (x == 1) {
        to_double--;
        if (doubled.size() > 0) {
          auto it = doubled.begin();
          std::pair<int, int> now = *it;
          if (now.second == 0) zero--;
          doubled.erase(it);
          sum2 -= now.first;
          pend.insert(now);
        }
      }
    }
    if (doubled.size() < to_double && pend.size() > 0) {
      auto it = --pend.end();
      std::pair<int, int> max = *it;
      doubled.insert(max);
      if (max.second == 0) zero++;
      sum2 += max.first;
      pend.erase(it);
    }
    if (doubled.size() > 0 && pend.size() > 0) {
      auto it = doubled.begin();
      auto it2 = --pend.end();
      doubled.erase(it);
      pend.erase(it2);
      std::pair<int, int> now1 = *it;
      std::pair<int, int> now2 = *it2;
      if (now2.first > now1.first) {
        sum2 += now2.first - now1.first;
        if (now2.second == 0) zero++;
        if (now1.second == 0) zero--;
        doubled.insert(now2);
        pend.insert(now1);
      } else {
        doubled.insert(now1);
        pend.insert(now2);
      }
    }
    if (doubled.size() > 0 && zero == 0 && doubled.size() == to_double) {
      auto it1 = doubled.begin();
      std::pair<int, int> now = *it1;
      doubled.erase(it1);
      sum2 -= now.first;
      if (pend.size() > 0) {
        auto it2 = --pend.end();
        std::pair<int, int> now2 = *it2;
        pend.erase(it2);
        doubled.insert(now2);
        zero++;
        sum2 += now2.first;
      }
      pend.insert(now);
    }
    printf("%lld\n", sum1 + sum2);
  }
  return 0;
}
