#include <bits/stdc++.h>
using namespace std;
const int INF = 0x7fffffff;
const int N = 1e5 + 5;
int T;
set<int> s[2], all;
long long sum[2], cnt[2];
void modify(int id) {
  int x = (id ? *s[id].begin() : *s[id].rbegin()), d = all.count(x);
  sum[id] -= x, sum[id ^ 1] += x;
  s[id].erase(x), s[id ^ 1].insert(x);
  cnt[id] -= d, cnt[id ^ 1] += d;
}
int main() {
  cin >> T;
  while (T--) {
    int op, x, id;
    cin >> op >> x;
    if (x > 0) {
      s[0].insert(x), sum[0] += x, cnt[0] += op;
      if (op) all.insert(x);
    } else {
      x = abs(x), id = 0;
      if (s[1].count(x)) id = s[1].count(x);
      s[id].erase(x), sum[id] -= x, cnt[id] -= op;
      if (op) all.erase(x);
    }
    int S = cnt[0] + cnt[1];
    while (S < s[1].size()) modify(1);
    while (S > s[1].size()) modify(0);
    while (s[1].size() && s[0].size() && *s[0].rbegin() > *s[1].begin())
      modify(0), modify(1);
    long long ans = sum[1] * 2LL + sum[0];
    if (cnt[1] == S && S) {
      ans -= *s[1].begin();
      if (s[0].size()) ans += *s[0].rbegin();
    }
    cout << ans << endl;
  }
  return 0;
}
