#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int tp[N], d[N];
pair<int, long long> penwick[2][N];
void update(pair<int, long long> *pen, int ind, pair<int, long long> g) {
  while (ind < N) {
    pen[ind].first += g.first;
    pen[ind].second += g.second;
    ind += ind & (-ind);
  }
}
long long get(int bit, int k) {
  long long ret = 0;
  int ind = 0, cur = 0;
  for (int i = 20; i >= 0; --i) {
    int nind = ind + (1 << i);
    if (nind < N) {
      if (cur + penwick[bit][nind].first <= k) {
        ind = nind;
        cur += penwick[bit][nind].first;
        ret += penwick[bit][nind].second;
      }
    }
  }
  return ret;
}
void solve() {
  int n;
  scanf("%d", &n);
  map<int, int> H;
  for (int i = 0; i < n; ++i) {
    scanf("%d %d ", &tp[i], &d[i]);
    H[abs(d[i])];
  }
  int pos = 0;
  for (map<int, int>::iterator it = H.begin(); it != H.end(); ++it) {
    it->second = ++pos;
  }
  int cc[2] = {0, 0};
  long long sum[2] = {0LL, 0LL};
  int num = 0;
  for (int i = 0; i < n; ++i) {
    int ind = H[abs(d[i])];
    if (d[i] < 0) {
      ++num;
      pair<int, long long> val = {-1, d[i]};
      update(penwick[tp[i]], ind, val);
      --cc[tp[i]];
    } else {
      pair<int, long long> val = {1, d[i]};
      update(penwick[tp[i]], ind, val);
      ++cc[tp[i]];
    }
    sum[tp[i]] += d[i];
    if (cc[0] > 0 && cc[1] > 0) {
      int l = 1, r = min(cc[0], cc[1]), mid;
      while (l < r) {
        mid = (l + r + 1) / 2;
        if (get(0, cc[0] - mid + 1) - get(0, cc[0] - mid) <=
            get(1, mid) - get(1, mid - 1)) {
          r = mid - 1;
        } else {
          l = mid;
        }
      }
      printf("%lld\n", 2 * sum[0] + sum[1] * 2 - get(0, cc[0] - l) - get(1, l));
    } else if (cc[0] > 0) {
      printf("%lld\n", sum[0]);
    } else if (cc[1] > 0) {
      printf("%lld\n", sum[1] * 2 - get(1, 1));
    } else {
      printf("0\n");
    }
  }
}
int main() {
  solve();
  return 0;
}
