#include <bits/stdc++.h>
using namespace std;
vector<pair<pair<long long, int>, int> > qs, v;
int t[200009], a[200009], id[200009], n;
long long seg[800009];
int f[800009];
int num[800009];
long long rid[200009];
void add(int x, int l, int r, int w, int tp) {
  if (l == r) {
    w = rid[w];
    if (tp) {
      seg[x] = a[w];
      f[x] = t[w];
      num[x] = 1;
    } else {
      seg[x] = 0;
      f[x] = 0;
      num[x] = 0;
    }
    return;
  }
  if ((l + r) / 2 >= w)
    add(2 * x + 1, l, (l + r) / 2, w, tp);
  else
    add(2 * x + 2, (l + r) / 2 + 1, r, w, tp);
  seg[x] = seg[2 * x + 1] + seg[2 * x + 2];
  f[x] = f[2 * x + 1] + f[2 * x + 2];
  num[x] = num[2 * x + 1] + num[2 * x + 2];
}
int bb = 0;
long long qu(int x, int l, int r, int s) {
  if (s <= 0) return 0;
  if (num[x] <= s) {
    bb = max(bb, f[x]);
    return seg[x];
  }
  long long sum = 0;
  if (num[2 * x + 2] >= s)
    return qu(2 * x + 2, (l + r) / 2 + 1, r, s);
  else
    return qu(2 * x + 2, (l + r) / 2 + 1, r, num[2 * x + 2]) +
           qu(2 * x + 1, l, (l + r) / 2, s - num[2 * x + 2]);
}
multiset<long long> fi;
long long m2;
bool proc(int i) {
  if (a[i] < 0) {
    if (t[i])
      fi.erase(-a[i]);
    else
      m2--;
    return 0;
  }
  if (t[i])
    fi.insert(a[i]);
  else
    m2++;
  return 1;
}
long long sum;
int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(0);
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> t[i] >> a[i];
    t[i] = 1 - t[i];
    if (a[i] > 0)
      v.push_back({{a[i], t[i]}, i});
    else
      qs.push_back({{-a[i], t[i]}, i});
  }
  sort(v.begin(), v.end());
  sort(qs.begin(), qs.end());
  for (int i = 0; i < v.size(); i++) {
    id[v[i].second] = i;
    rid[i] = v[i].second;
  }
  int cnt = 0;
  for (int i = 0; i < qs.size(); i++) {
    while (v[cnt].first != qs[i].first) cnt++;
    id[qs[i].second] = id[v[cnt].second];
    cnt++;
  }
  fi.insert(0);
  for (int i = 0; i < n; i++) {
    sum += a[i];
    add(0, 0, n - 1, id[i], proc(i));
    long long ot = sum;
    bb = 0;
    ot += qu(0, 0, n - 1, m2 - 1);
    if (m2) {
      if (bb) {
        ot = sum + qu(0, 0, n - 1, m2);
      } else {
        ot += (*fi.rbegin());
      }
    }
    cout << ot << "\n";
  }
}
