#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 200005;
struct ban {
  int ty;
  int x;
};
int n;
ban a[N];
int z;
vector<int> v;
map<int, int> mp;
int rmp[N];
set<int> s[2];
pair<int, long long> t[N * 4];
pair<int, long long> mer(const pair<int, long long>& a,
                         const pair<int, long long>& b) {
  return make_pair(a.first + b.first, a.second + b.second);
}
void ubd(int tl, int tr, int x, int y, int pos) {
  if (tl == tr) {
    t[pos].first += y;
    t[pos].second += y * 1LL * rmp[x];
    return;
  }
  int m = (tl + tr) / 2;
  if (x <= m)
    ubd(tl, m, x, y, pos * 2);
  else
    ubd(m + 1, tr, x, y, pos * 2 + 1);
  t[pos] = mer(t[pos * 2], t[pos * 2 + 1]);
}
long long qry(int tl, int tr, int q, int pos) {
  if (tl == tr) {
    return min(q, t[pos].first) * 1LL * rmp[tl];
  }
  int m = (tl + tr) / 2;
  if (q > t[pos * 2 + 1].first)
    return qry(tl, m, q - t[pos * 2 + 1].first, pos * 2) +
           t[pos * 2 + 1].second;
  return qry(m + 1, tr, q, pos * 2 + 1);
}
void solv() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", &a[i].ty, &a[i].x);
  }
  for (int i = 1; i <= n; ++i) {
    if (a[i].x > 0) {
      v.push_back(a[i].x);
    }
  }
  sort((v).begin(), (v).end());
  for (int i = 0; i < ((int)(v).size()); ++i) {
    if (!i || v[i] != v[i - 1]) {
      mp[v[i]] = ++z;
      rmp[z] = v[i];
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (a[i].x < 0) {
      ubd(1, z, mp[-a[i].x], -1, 1);
      s[a[i].ty].erase(-a[i].x);
    } else {
      ubd(1, z, mp[a[i].x], 1, 1);
      s[a[i].ty].insert(a[i].x);
    }
    if (s[0].empty() && s[1].empty()) {
      printf("0\n");
      continue;
    }
    if (s[1].empty()) {
      printf("%lld\n", t[1].second);
      continue;
    }
    if (s[0].empty()) {
      printf("%lld\n", (t[1].second - *s[1].begin()) * 2 + *s[1].begin());
      continue;
    }
    long long ans = 0;
    ans += *s[1].begin();
    ubd(1, z, mp[*s[1].begin()], -1, 1);
    ans += *(--s[0].end()) * 2;
    ubd(1, z, mp[*(--s[0].end())], -1, 1);
    long long u = qry(1, z, ((int)(s[1]).size()) - 1, 1);
    ans += u * 2;
    ans += (t[1].second - u);
    printf("%lld\n", ans);
    ubd(1, z, mp[*s[1].begin()], 1, 1);
    ubd(1, z, mp[*(--s[0].end())], 1, 1);
  }
}
int main() {
  solv();
  return 0;
}
