#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, m, sz1, sz2;
vector<pair<int, int> > q;
vector<int> vec;
long long sum;
set<int> st, en;
struct node {
  long long sum, cnt;
  node() { sum = cnt = 0; }
} seg[N << 2];
void compress() {
  for (int i = 0; i < n; i++) vec.push_back(abs(q[i].first));
  sort(vec.begin(), vec.end());
  vec.resize(unique(vec.begin(), vec.end()) - vec.begin());
  m = vec.size();
}
void add(int pos, int tp, int id = 1, int b = 0, int e = m) {
  if (e - b == 1) {
    if (tp)
      seg[id].sum = vec[b], seg[id].cnt = 1;
    else
      seg[id].sum = 0, seg[id].cnt = 0;
    return;
  }
  int mid = (b + e) >> 1, lc = id * 2, rc = lc | 1;
  if (pos < mid)
    add(pos, tp, lc, b, mid);
  else
    add(pos, tp, rc, mid, e);
  seg[id].sum = seg[lc].sum + seg[rc].sum;
  seg[id].cnt = seg[lc].cnt + seg[rc].cnt;
}
long long get(int l, int r, int id = 1, int b = 0, int e = m) {
  if (l >= e || b >= r) return 0;
  if (l <= b && e <= r) return seg[id].sum;
  int mid = (b + e) >> 1, lc = id * 2, rc = lc | 1;
  return get(l, r, lc, b, mid) + get(l, r, rc, mid, e);
}
long long get_k(int k, int id = 1, int b = 0, int e = m) {
  if (e - b == 1) return b;
  int mid = (b + e) >> 1, lc = id * 2, rc = lc | 1;
  if (seg[rc].cnt >= k)
    return get_k(k, rc, mid, e);
  else
    return get_k(k - seg[rc].cnt, lc, b, mid);
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    int tp, x;
    cin >> tp >> x;
    q.push_back(make_pair(x, tp));
  }
  compress();
  for (auto P : q) {
    int tp = P.second, x = P.first;
    sum += x;
    int pos = lower_bound(vec.begin(), vec.end(), abs(x)) - vec.begin();
    if (x < 0) {
      if (!tp) {
        sz2--;
        en.erase(-x);
      } else {
        sz1--;
        st.erase(-x);
      }
      add(pos, 0);
    } else {
      if (!tp) {
        sz2++;
        en.insert(x);
      } else {
        sz1++;
        st.insert(x);
      }
      add(pos, 1);
    }
    if (!sz1)
      cout << sum << "\n";
    else {
      int pos = get_k(sz1);
      int mn = (*st.begin());
      long long ans = get(pos, m) + sum;
      if (mn >= vec[pos]) {
        ans -= mn;
        auto itr = en.lower_bound(mn);
        if (itr != en.begin()) {
          itr--;
          ans += (*itr);
        }
      }
      cout << ans << "\n";
    }
  }
}
