#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << "{" << p.first << "," << p.second << "}";
  return os;
}
const int N = 3e5 + 5;
const int oo = 1e9 + 7;
int tot[2];
int ache[2][2];
set<int> st[2];
long long sum[2];
map<int, int> type;
inline void add_single(int i, int d, int typ) {
  sum[i] += d;
  ache[i][typ]++;
  st[i].insert(d);
}
inline void rem_single(int i, int d, int typ) {
  sum[i] -= d;
  ache[i][typ]--;
  st[i].erase(d);
}
inline void swap_(int l, int r) {
  int lt = type[l];
  int rt = type[r];
  rem_single(0, l, lt);
  rem_single(1, r, rt);
  add_single(0, r, rt);
  add_single(1, l, lt);
}
inline void equalize() {
  while (tot[1] > st[1].size()) {
    assert(!st[0].empty());
    int l = *st[0].rbegin();
    int lt = type[l];
    rem_single(0, l, lt);
    add_single(1, l, lt);
  }
  while (tot[1] < st[1].size()) {
    assert(!st[1].empty());
    int r = *st[1].begin();
    int rt = type[r];
    rem_single(1, r, rt);
    add_single(0, r, rt);
  }
  int l, r;
  while (!st[0].empty() and !st[1].empty() and
         (l = *st[0].rbegin()) > (r = *st[1].begin())) {
    swap_(l, r);
  }
  assert(tot[1] == st[1].size());
}
inline void add(int d, int typ) {
  tot[typ]++;
  type[d] = typ;
  ache[0][typ]++;
  st[0].insert(d);
  sum[0] += d;
  equalize();
}
inline void rem(int d, int typ) {
  tot[typ]--;
  type.erase(d);
  for (int i = 0; i < 2; i++)
    if (st[i].find(d) != st[i].end()) {
      st[i].erase(d);
      ache[i][typ]--;
      sum[i] -= d;
    }
  equalize();
}
void pr() {
  cerr << "line " << 90 << " : "
       << "tot[0]"
       << " --> " << (tot[0]) << endl;
  cerr << "line " << 91 << " : "
       << "tot[1]"
       << " --> " << (tot[1]) << endl;
  for (int i = 0; i < 2; i++) {
    cerr << "line " << 93 << " : "
         << "i"
         << " --> " << (i) << endl;
    cerr << "line " << 94 << " : "
         << "sum[i]"
         << " --> " << (sum[i]) << endl;
    cerr << "line " << 95 << " : "
         << "ache[i][0]"
         << " --> " << (ache[i][0]) << endl;
    cerr << "line " << 96 << " : "
         << "ache[i][1]"
         << " --> " << (ache[i][1]) << endl;
    cerr << "line " << 97 << " : "
         << "&st[i]"
         << " --> " << (&st[i]) << endl;
    for (int j : st[i]) cout << j << " ";
    cout << endl;
    cout << endl;
  }
  cout << endl;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  while (n--) {
    int tp, d;
    cin >> tp >> d;
    if (d > 0) {
      add(d, tp);
    } else
      rem(-d, tp);
    long long ans = sum[0] + sum[1] * 2;
    if (tot[1] == ache[1][1]) {
      if (tot[1]) {
        ans -= *st[1].begin();
        if (!st[0].empty()) ans += *st[0].rbegin();
      }
    }
    cout << ans << "\n";
  }
}
