#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
int tp[200100], d[200100], cnt[2];
struct info {
  long long int noe, sum, fire, light;
  info() {}
  info(long long int _noe, long long int _sum, long long int _fire,
       long long int _light) {
    noe = _noe;
    sum = _sum;
    fire = _fire;
    light = _light;
  }
};
info tree[4 * 200100];
void Clean() {
  for (int i = 0; i < 4 * 200100; i++) {
    tree[i].noe = 0LL;
    tree[i].sum = 0LL;
    tree[i].fire = 0LL;
    tree[i].light = 0LL;
  }
}
info combine(info p1, info p2) {
  info ret;
  ret = info(p1.noe + p2.noe, p1.sum + p2.sum, p1.fire + p2.fire,
             p1.light + p2.light);
}
void Update(long long int node, long long int b, long long int e,
            long long int i, long long int val, long long int type) {
  if (i > e || i < b) return;
  if (i == b && i == e) {
    if (val > 0LL)
      tree[node] = info(1LL, val, (long long int)(type == 0),
                        (long long int)(type == 1));
    else
      tree[node] = info(0LL, 0LL, 0LL, 0LL);
    return;
  }
  long long int lft = node << 1LL;
  long long int rgt = 1LL + lft;
  long long int mid = (b + e) >> 1LL;
  Update(lft, b, mid, i, val, type);
  Update(rgt, mid + 1, e, i, val, type);
  tree[node] =
      info(tree[lft].noe + tree[rgt].noe, tree[lft].sum + tree[rgt].sum,
           tree[lft].fire + tree[rgt].fire, tree[lft].light + tree[rgt].light);
}
int qryBS(int node, int b, int e, int tote) {
  if (b == e) return b;
  int lft = node << 1;
  int rgt = 1 + lft;
  int mid = (b + e) >> 1;
  if (tree[lft].noe >= tote)
    return qryBS(lft, b, mid, tote);
  else
    return qryBS(rgt, mid + 1, e, tote - tree[lft].noe);
}
pair<long long int, long long int> Query(int node, int b, int e, int i, int j) {
  if (i > e || j < b) return make_pair(0LL, 0LL);
  if (b >= i && e <= j) {
    return make_pair(tree[node].sum, tree[node].light);
  }
  int lft = node << 1;
  int rgt = 1 + lft;
  int mid = (b + e) >> 1;
  pair<long long int, long long int> ret1 = Query(lft, b, mid, i, j);
  pair<long long int, long long int> ret2 = Query(rgt, mid + 1, e, i, j);
  return make_pair(ret1.first + ret2.first, ret1.second + ret2.second);
}
map<long long int, long long int> idx;
vector<int> v;
set<int> st[2];
void Solve(int t) {
  Clean();
  long long int i, j, k, n, tot = 0, co = 0;
  scanf("%lld", &(n));
  for (i = 1; i <= n; i++) {
    scanf("%d %d", &(tp[i]), &(d[i]));
    v.push_back(fabs(d[i]));
  }
  (sort(v.begin(), v.end()),
   v.resize(distance(v.begin(), unique(v.begin(), v.end()))));
  reverse(v.begin(), v.end());
  for (auto x : v) {
    idx[x] = ++co;
  }
  for (i = 1; i <= n; i++) {
    if (d[i] > 0) {
      tot += d[i];
      cnt[tp[i]]++;
      Update(1, 1, n, idx[d[i]], d[i], tp[i]);
      st[tp[i]].insert(d[i]);
    } else {
      tot += d[i];
      cnt[tp[i]]--;
      Update(1, 1, n, idx[fabs(d[i])], d[i], tp[i]);
      st[tp[i]].erase(fabs(d[i]));
    }
    long long int lightning = cnt[1];
    long long int part1 = 0, part2 = 0;
    if (lightning) {
      int id = qryBS(1, 1, n, lightning);
      pair<long long int, long long int> pr = Query(1, 1, n, 1, id);
      part1 = pr.first;
      if (pr.second == lightning) {
        long long int mnlight = 0, mxfire = 0;
        if (!st[1].empty()) mnlight = *st[1].begin();
        if (!st[0].empty()) mxfire = *st[0].rbegin();
        part1 = part1 - mnlight + mxfire;
      }
    }
    part2 = tot - part1;
    long long int ans = (2 * part1) + part2;
    cout << ans << endl;
  }
}
int main() {
  int t, T;
  T = 1;
  for (__typeof(t) t = 1; t <= T; t++) {
    Solve(t);
  }
  return 0;
}
