#include <bits/stdc++.h>
using namespace std;
long long t;
struct Query {
  long long t;
  long long d;
};
vector<long long> pos;
Query q[200001];
long long S = 0;
long long cnt = 0;
long long Bit[301001];
long long C[300101];
long long C1[300101];
multiset<pair<long long, long long> > s;
multiset<long long, greater<long long> > f;
void update(long long pos, long long val, long long c, int c1) {
  for (long long i = pos; i <= 3e5; i += i & -i)
    Bit[i] += val, C[i] += c, C1[i] += c1;
}
pair<long long, pair<long long, long long> > Get(long long x) {
  long long ans = 0;
  long long c = 0;
  long long c1 = 0;
  for (long long i = x; i; i -= i & -i) {
    ans += Bit[i];
    c += C[i];
    c1 += C1[i];
  }
  pair<long long, pair<long long, long long> > T;
  T.first = ans;
  T.second.first = c;
  T.second.second = c1;
  return T;
}
int main() {
  cin >> t;
  for (long long i = 1; i <= t; i++) {
    cin >> q[i].t >> q[i].d;
    pos.push_back(q[i].d);
  }
  sort(pos.begin(), pos.end());
  int sz = 0;
  for (long long T = 1; T <= t; T++) {
    long long ty = q[T].t;
    long long d = q[T].d;
    S += d;
    long long x = lower_bound(pos.begin(), pos.end(), abs(d)) - pos.begin() + 1;
    long long y = 1;
    if (d < 0) y = -1;
    if (d > 0) {
      if (ty) s.insert({d, ty});
      if (!ty) f.insert(d);
    }
    if (d < 0) {
      if (ty) s.erase(s.find({-d, ty}));
      if (!ty) f.erase(f.find(-d));
    }
    x = 2e5 - x + 10;
    int z = 0;
    if (d < 0 && ty) {
      z = -1;
    }
    if (d > 0 && ty) z = 1;
    update(x, d, y, z);
    if (ty == 1) {
      if (d > 0)
        cnt++;
      else
        cnt--;
    }
    long long l = 1;
    long long r = 3e5 - 100;
    long long ans = 0;
    while (l <= r) {
      long long mid = l + r >> 1;
      pair<long long, pair<long long, long long> > K = Get(mid);
      if (K.second.first <= cnt) {
        ans = mid;
        l = mid + 1;
      } else
        r = mid - 1;
    }
    long long A = 0;
    int tt = -1;
    if (ans) A = Get(ans).first, tt = Get(ans).second.second;
    A += S;
    if (tt == cnt && tt) {
      pair<long long, long long> K = *(s.begin());
      A -= K.first;
      if (f.size()) {
        A += *f.begin();
      }
    }
    cout << A << "\n";
  }
  return 0;
}
