#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5;
vector<pair<int, int>> all;
set<int> ugly;
int getidx(int tp, int d) {
  int l = -1, r = all.size();
  while (r - l > 1) {
    int c = (l + r) / 2;
    if (all[c].first != d) {
      if (all[c].first < d)
        l = c;
      else
        r = c;
    } else {
      if (all[c].second < tp)
        l = c;
      else
        r = c;
    }
  }
  return r;
}
int F[MAXN][2];
long long G[MAXN][2];
void update(int pos, int delta) {
  int tp = all[pos].second;
  int inf = all[pos].first * delta;
  for (; pos < all.size(); pos = (pos | (pos + 1))) {
    F[pos][tp] += delta;
    G[pos][tp] += inf;
  }
}
pair<int, int> get(int pos) {
  pair<int, int> res(0, 0);
  for (; pos >= 0; pos = (pos & (pos + 1)) - 1) {
    res.first += F[pos][0];
    res.second += F[pos][1];
  }
  return res;
}
pair<long long, long long> getsum(int pos) {
  pair<long long, long long> res(0, 0);
  for (; pos >= 0; pos = (pos & (pos + 1)) - 1) {
    res.first += G[pos][0];
    res.second += G[pos][1];
  }
  return res;
}
void solve() {
  int n;
  scanf("%d", &n);
  vector<pair<int, int>> q;
  for (int i = 0; i < n; ++i) {
    int tp, d;
    scanf("%d%d", &tp, &d);
    q.push_back(pair<int, int>(tp, d));
    all.push_back(pair<int, int>(abs(d), tp));
  }
  sort(all.begin(), all.end());
  {
    vector<pair<int, int>>::iterator z = unique(all.begin(), all.end());
    all.resize(z - all.begin());
  }
  for (int i = 0; i < n; ++i) {
    int tp = q[i].first;
    int d = q[i].second;
    int idx = getidx(tp, abs(d));
    if (all[idx].first != abs(d) || all[idx].second != tp) {
      printf("wut\n");
      fflush(stdout);
      throw "qwe";
    }
    if (d > 0)
      update(idx, 1);
    else
      update(idx, -1);
    if (tp == 1) {
      if (d > 0)
        ugly.insert(idx);
      else
        ugly.erase(idx);
    }
    pair<long long, long long> sum = getsum(all.size() - 1);
    pair<int, int> total_pair = get(all.size() - 1);
    if (total_pair.second == 0) {
      printf("%I64d\n", sum.first);
    } else if (total_pair.first == 0) {
      printf("%I64d\n", sum.second * 2 - all[*ugly.begin()].first);
    } else {
      int u = *ugly.begin();
      update(u, -1);
      int total = total_pair.first + total_pair.second - 1;
      int want = total - total_pair.second;
      int l = -2, r = all.size();
      while (r - l > 1) {
        int c = (l + r) / 2;
        pair<int, int> cnt = get(c);
        if (cnt.first + cnt.second < want)
          l = c;
        else
          r = c;
      }
      pair<int, int> cnt = get(r);
      pair<long long, long long> sum1 = getsum(r);
      printf("%I64d\n", (sum.first + sum.second) * 2 - sum1.first -
                            sum1.second - all[u].first);
      update(u, 1);
    }
  }
}
int main() {
  solve();
  return 0;
}
