#include <bits/stdc++.h>
using namespace std;
int n;
int t, x;
set<int, greater<int> > s[2];
set<int> sLight;
int cntLight;
int cntBigLight;
long long sum[2];
void print_set(int id) {
  printf("printing s[%d]...\n", id);
  for (auto x : s[id]) printf("%d ", x);
  printf("\n");
}
int main() {
  scanf("%d", &n);
  for (int(i) = (0); (i) < (n); ++i) {
    scanf("%d%d", &t, &x);
    if (x > 0) {
      s[0].insert(x);
      sum[0] += x;
      if (t) {
        ++cntLight, ++cntBigLight;
        sLight.insert(x);
      }
    } else {
      x = -x;
      if (s[0].count(x)) {
        sum[0] -= x;
        if (sLight.count(x)) {
          --cntLight, --cntBigLight;
          sLight.erase(x);
        }
        s[0].erase(x);
      } else {
        sum[1] -= x;
        if (sLight.count(x)) {
          --cntLight;
          sLight.erase(x);
        }
        s[1].erase(x);
      }
    }
    while (s[0].size() > cntLight) {
      x = *s[0].rbegin();
      if (sLight.count(x)) --cntBigLight;
      sum[0] -= x, sum[1] += x;
      s[0].erase(x);
      s[1].insert(x);
    }
    while (s[0].size() < cntLight) {
      x = *s[1].begin();
      if (sLight.count(x)) ++cntBigLight;
      sum[1] -= x, sum[0] += x;
      s[1].erase(x);
      s[0].insert(x);
    }
    while (!s[0].empty() && !s[1].empty() &&
           (*s[0].rbegin()) < (*s[1].begin())) {
      x = *s[0].rbegin();
      if (sLight.count(x)) --cntBigLight;
      sum[0] -= x, sum[1] += x;
      s[0].erase(x);
      s[1].insert(x);
      x = *s[1].begin();
      if (sLight.count(x)) ++cntBigLight;
      sum[1] -= x, sum[0] += x;
      s[1].erase(x);
      s[0].insert(x);
    }
    long long out = (long long)sum[1] + 2LL * sum[0];
    if (!s[0].empty() && cntBigLight == s[0].size()) {
      out -= *s[0].rbegin();
      if (!s[1].empty()) out += *s[1].begin();
    }
    printf("%lld\n", out);
  }
  return 0;
}
