#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long n, ar[500050];
set<long long> fi, li;
set<long long> on, tw;
long long son, stw;
void chupd() {
  if (tw.empty() || li.empty()) return;
  if ((long long)li.size() > (long long)tw.size()) return;
  if (fi.empty()) {
    if ((long long)li.size() == (long long)tw.size()) {
      long long f = *tw.begin();
      stw -= f;
      son += f;
      tw.erase(tw.begin());
      on.insert(f);
    }
    return;
  }
  set<long long>::iterator it = fi.end();
  it--;
  long long g = *it;
  long long f = *tw.begin();
  if (f > g) {
    stw -= f;
    son += f;
    tw.erase(tw.begin());
    it = on.end();
    it--;
    long long d = *it;
    son -= d;
    stw += d;
    on.erase(d);
    tw.insert(d);
    on.insert(f);
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  while (n--) {
    long long t, d;
    cin >> t >> d;
    if (t == 0) {
      if (d < 0) {
        d = -d;
        fi.erase(d);
        if (tw.find(d) != tw.end()) {
          tw.erase(d);
          stw -= d;
          set<long long>::iterator it = on.end();
          if (it != on.begin()) {
            it--;
            long long g = *it;
            on.erase(g);
            son -= g;
            stw += g;
            tw.insert(g);
          }
        }
        if (on.find(d) != on.end()) {
          on.erase(d);
          son -= d;
        }
      } else {
        fi.insert(d);
        if (!li.empty()) {
          if ((long long)tw.size() < (long long)li.size()) {
            tw.insert(d);
            stw += d;
          } else {
            long long f = *tw.begin();
            if (f > d) {
              on.insert(d);
              son += d;
            } else {
              tw.insert(d);
              stw += d;
              if ((long long)tw.size() > (long long)li.size()) {
                tw.erase(f);
                stw -= f;
                on.insert(f);
                son += f;
              }
            }
          }
        } else {
          on.insert(d);
          son += d;
        }
      }
    } else {
      if (d < 0) {
        d = -d;
        li.erase(d);
        if (on.find(d) != on.end()) {
          on.erase(d);
          son -= d;
          if (!tw.empty()) {
            long long g = *tw.begin();
            tw.erase(g);
            stw -= g;
            on.insert(g);
            son += g;
          }
        } else {
          tw.erase(d);
          stw -= d;
        }
      } else {
        li.insert(d);
        on.insert(d);
        son += d;
        set<long long>::iterator it = on.end();
        it--;
        long long c = *it;
        tw.insert(c);
        stw += c;
        on.erase(c);
        son -= c;
      }
    }
    chupd();
    cout << son + stw + stw << "\n";
  }
  return 0;
}
