#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int tp[N], d[N];
long long segment[2][N * 4];
int penwick[2][N];
void update(int *pen, int ind, int val) {
  while (ind < N) {
    pen[ind] += val;
    ind += ind & (-ind);
  }
}
void update(long long *seg, int pos, int l, int r, int ind, int val) {
  if (l == r) {
    seg[pos] += val;
    return;
  }
  int mid = (l + r) / 2;
  if (ind <= mid) {
    update(seg, pos * 2, l, mid, ind, val);
  } else {
    update(seg, pos * 2 + 1, mid + 1, r, ind, val);
  }
  seg[pos] = seg[pos * 2] + seg[pos * 2 + 1];
}
long long query(long long *seg, int pos, int l, int r, int ql, int qr) {
  if (r < ql || qr < l) {
    return 0;
  }
  if (ql <= l && r <= qr) {
    return seg[pos];
  }
  int mid = (l + r) / 2;
  return query(seg, pos * 2, l, mid, ql, qr) +
         query(seg, pos * 2 + 1, mid + 1, r, ql, qr);
}
int getIndex(int *pen, int x) {
  if (x == 0) {
    return 0;
  }
  int ind = 0, sum = 0;
  for (int i = 19; i >= 0; --i) {
    int nind = ind + (1 << i);
    if (nind < N && sum + pen[nind] < x) {
      ind = nind;
      sum += pen[nind];
    }
  }
  return ind + 1;
}
long long getValue(int *pen, long long *seg, int ind, int n) {
  int id = getIndex(pen, ind);
  return query(seg, 1, 1, n, id, id);
}
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};
  long long sum[2] = {0};
  for (int i = 0; i < n; ++i) {
    scanf("%d %d ", &tp[i], &d[i]);
    int ind = H[abs(d[i])];
    if (d[i] < 0) {
      --cc[tp[i]];
      update(segment[tp[i]], 1, 1, n, ind, d[i]);
      update(penwick[tp[i]], ind, -1);
    } else {
      update(segment[tp[i]], 1, 1, n, ind, d[i]);
      update(penwick[tp[i]], ind, 1);
      ++cc[tp[i]];
    }
    sum[tp[i]] += d[i];
    if (cc[0] > 0 && cc[1] > 0) {
      int k = min(cc[0], cc[1]);
      int l = 1, r = k, mid;
      while (l < r) {
        mid = (l + r + 1) / 2;
        if (getValue(penwick[0], segment[0], cc[0] - mid + 1, n) >=
            getValue(penwick[1], segment[1], mid, n)) {
          l = mid;
        } else {
          r = mid - 1;
        }
      }
      printf(
          "%lld\n",
          sum[0] * 2 + sum[1] * 2 -
              query(segment[1], 1, 1, n, 1, getIndex(penwick[1], l)) -
              query(segment[0], 1, 1, n, 1, getIndex(penwick[0], cc[0] - l)));
    } else if (cc[0] > 0) {
      printf("%lld\n", sum[0]);
    } else if (cc[1] > 0) {
      printf("%lld\n", sum[1] * 2 - getValue(penwick[1], segment[1], 1, n));
    } else {
      printf("0\n");
    }
  }
}
int main() {
  solve();
  return 0;
}
