#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string& s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (long long i = 0; i < static_cast<long long>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
const long long INF = LONG_LONG_MAX / 10;
const double PI = 3.141592653589793238;
const long long MOD = 998244353;
bool many = false;
struct Solve {
  string endl = "\n";
  long long n, sum[2], cntDouble[2];
  set<long long> sDouble, s[2];
  void upd(long long id) {
    assert((long long)s[id].size() > 0);
    long long x = *s[id].rbegin();
    if (id == 1) x = *s[id].begin();
    bool d = sDouble.count(x);
    sum[id] -= x, sum[!id] += x;
    s[id].erase(x), s[!id].insert(x);
    cntDouble[id] -= d, cntDouble[!id] += d;
  }
  Solve() {
    cin >> n;
    sum[0] = sum[1] = 0;
    cntDouble[0] = cntDouble[1] = 0;
    for (long long i = 0; i < n; i++) {
      long long tp, x;
      cin >> tp >> x;
      if (x > 0) {
        sum[0] += x;
        s[0].insert(x);
        cntDouble[0] += tp;
        if (tp) sDouble.insert(x);
      } else {
        x = -x;
        long long id = 0;
        if (s[1].count(x))
          id = 1;
        else
          assert(s[0].count(x));
        sum[id] -= x;
        s[id].erase(x);
        cntDouble[id] -= tp;
        if (tp) {
          assert(sDouble.count(x));
          sDouble.erase(x);
        }
      }
      42;
      42;
      long long sumDouble = cntDouble[0] + cntDouble[1];
      while ((long long)s[1].size() < sumDouble) upd(0);
      while ((long long)s[1].size() > sumDouble) upd(1);
      while ((long long)s[1].size() > 0 && (long long)s[0].size() > 0 &&
             *s[0].rbegin() > *s[1].begin()) {
        upd(0);
        upd(1);
      }
      assert((long long)s[1].size() == sumDouble);
      long long res = sum[0] + sum[1] * 2;
      if (cntDouble[1] == sumDouble && sumDouble > 0) {
        res -= *s[1].begin();
        if (s[0].size() > 0) res += *s[0].rbegin();
      }
      cout << res << endl;
    }
  }
};
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long CASES = 1;
  if (many) cin >> CASES;
  for (long long i = 1; i <= CASES; i++) {
    Solve me;
  }
}
