#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int max_n = 100005;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  set<pair<int, int>> upper, lower;
  long long total = 0, doub = 0;
  int fb_count = 0;
  auto ans = [&]() -> long long {
    if (fb_count) return total + doub;
    if (upper.empty()) return total;
    if (lower.empty()) {
      auto t = upper.begin()->first;
      return total + doub - t;
    }
    return total + doub - upper.begin()->first + lower.rbegin()->first;
  };
  while (n--) {
    int tp, x;
    cin >> tp >> x;
    if (x > 0) {
      total += x;
      pair<int, int> p = {x, tp};
      if (tp == 0) {
        doub += x;
        upper.insert(p);
        fb_count++;
        auto t = *upper.begin();
        upper.erase(upper.begin());
        doub -= t.first;
        if (t.second == 0) fb_count--;
        lower.insert(t);
      } else {
        if (lower.empty()) {
          doub += x;
          upper.insert(p);
        } else {
          auto t = *lower.rbegin();
          if (t.first > x) {
            doub += t.first;
            lower.erase(t);
            upper.insert(t);
            lower.insert(p);
            if (t.second == 0) fb_count++;
          } else {
            doub += x;
            upper.insert(p);
          }
        }
      }
    } else {
      x = abs(x);
      total -= x;
      pair<int, int> p = {x, tp};
      if (tp == 0) {
        if (upper.find(p) != upper.end()) {
          doub -= x;
          fb_count--;
          upper.erase(p);
          assert(!lower.empty());
          auto t = *lower.rbegin();
          lower.erase(t);
          upper.insert(t);
          doub += t.first;
          if (t.second == 0) fb_count++;
        } else {
          lower.erase(p);
        }
      } else {
        if (upper.find(p) != upper.end()) {
          doub -= x;
          upper.erase(p);
        } else {
          lower.erase(p);
          auto t = *upper.begin();
          doub -= t.first;
          if (t.second == 0) fb_count--;
          upper.erase(t);
          lower.insert(t);
        }
      }
    }
    cout << ans() << endl;
  }
  return 0;
}
