#include <bits/stdc++.h>
using namespace std;
multiset<pair<long long, long long>> smin;
multiset<pair<long long, long long>, greater<pair<long long, long long>>> smax;
long long cur_light;
long long cur_fir;
long long light;
long long fire;
long long ans_dbl;
long long ans;
void fun() {
  while (smin.size() > light) {
    auto p = smin.begin();
    smax.insert(*p);
    ans_dbl -= (*p).first;
    ans += (*p).first;
    if ((*p).second == 1)
      cur_light--;
    else
      cur_fir--;
    smin.erase(p);
  }
  if (cur_light == light && light > 0) {
    pair<long long, long long> p = *smin.begin();
    smax.insert(p);
    smin.erase(p);
    cur_light--;
    ans += p.first;
    ans_dbl -= p.first;
  }
  vector<pair<long long, long long>> v;
  for (auto i : smax) {
    if (i.second == 1 && cur_fir == 0 && smin.size() == light - 1) continue;
    if (smin.size() == light) break;
    smin.insert(i);
    ans_dbl += i.first;
    ans -= i.first;
    v.push_back(i);
    if (i.second == 1)
      cur_light++;
    else
      cur_fir++;
  }
  for (auto i : v) smax.erase(i);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  while (n--) {
    long long tp, d;
    cin >> tp >> d;
    if (tp == 0) {
      if (d > 0) {
        fire++;
        smin.insert({d, 0});
        ans_dbl += d;
        fun();
        cur_fir++;
      } else {
        d = abs(d);
        auto p = smax.find({d, 0});
        fire--;
        if (p != smax.end())
          smax.erase(p), ans -= d;
        else {
          smin.erase({d, 0});
          ans_dbl -= d;
          cur_fir--;
        }
        fun();
      }
    } else {
      if (d > 0) {
        light++;
        smax.insert({d, 1});
        ans += d;
        fun();
      } else {
        light--;
        d = abs(d);
        auto p = smax.find({d, 1});
        if (p != smax.end())
          smax.erase(p), ans -= d;
        else {
          smin.erase({d, 1});
          ans_dbl -= d;
          cur_light--;
        }
        fun();
      }
    }
    cout << ans + 2 * ans_dbl << "\n";
  }
}
