#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vector<T>>;
template <class T>
inline bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
int main() {
  init();
  ll N;
  cin >> N;
  ll now = 0, tn = 0, fn = 0, mt = 0;
  set<ll> A, B, T;
  for (ll _ = 0; _ < (N); _++) {
    ll tp, d;
    cin >> tp >> d;
    if (tp == 0) {
      if (d > 0) {
        fn++;
        now += d;
        if (A.size() < tn) {
          A.emplace(d);
          now += d;
          while (B.size() > 0 and A.size() < tn) {
            ll a = *B.rbegin();
            A.emplace(a), B.erase(a);
            now += a;
          }
        } else if (A.size() > 0 and d > *A.begin()) {
          ll a = *A.begin();
          A.emplace(d), A.erase(a), B.emplace(a);
          now += d - a;
          while (B.size() > 0 and A.size() < tn) {
            a = *B.rbegin();
            A.emplace(a), B.erase(a);
            now += a;
          }
        } else {
          B.emplace(d);
          while (B.size() > 0 and A.size() < tn) {
            ll a = *B.rbegin();
            A.emplace(a), B.erase(a);
            now += a;
          }
        }
      } else {
        d *= -1;
        fn--;
        now -= d;
        if (A.find(d) != A.end()) {
          A.erase(d);
          now -= d;
          while (B.size() > 0 and A.size() < tn) {
            ll a = *B.rbegin();
            A.emplace(a), B.erase(a);
            now += a;
          }
        } else {
          B.erase(d);
          while (B.size() > 0 and A.size() < tn) {
            ll a = *B.rbegin();
            A.emplace(a), B.erase(a);
            now += a;
          }
        }
      }
    } else {
      if (d > 0) {
        tn++;
        now += d;
        T.emplace(d);
        if (mt == 0) {
          mt = d;
          while (B.size() > 0 and A.size() < tn) {
            ll a = *B.rbegin();
            A.emplace(a), B.erase(a);
            now += a;
          }
        } else if (d < mt) {
          B.emplace(mt);
          mt = d;
          while (B.size() > 0 and A.size() < tn) {
            ll a = *B.rbegin();
            A.emplace(a), B.erase(a);
            now += a;
          }
        } else {
          B.emplace(d);
          while (B.size() > 0 and A.size() < tn) {
            ll a = *B.rbegin();
            A.emplace(a), B.erase(a);
            now += a;
          }
        }
      } else {
        d *= -1;
        tn--;
        now -= d;
        T.erase(d);
        if (d == mt) {
          if (tn == 0) {
            mt = 0;
            while (A.size() > 0) {
              ll a = *A.begin();
              B.emplace(a), A.erase(a);
              now -= a;
            }
          } else {
            mt = *T.begin();
            if (A.find(mt) != A.end()) {
              A.erase(mt);
              now -= mt;
              while (B.size() > 0 and A.size() < tn) {
                ll a = *B.rbegin();
                A.emplace(a), B.erase(a);
                now += a;
              }
            } else {
              B.erase(mt);
              while (A.size() > tn) {
                ll a = *A.begin();
                B.emplace(a), A.erase(a);
                now -= a;
              }
              while (B.size() > 0 and A.size() < tn) {
                ll a = *B.rbegin();
                A.emplace(a), B.erase(a);
                now += a;
              }
            }
          }
        } else {
          if (A.find(d) != A.end()) {
            A.erase(d);
            now -= d;
            while (A.size() > tn) {
              ll a = *A.begin();
              B.emplace(a), A.erase(a);
              now -= a;
            }
            while (B.size() > 0 and A.size() < tn) {
              ll a = *B.rbegin();
              A.emplace(a), B.erase(a);
              now += a;
            }
          } else {
            B.erase(d);
            while (A.size() > tn) {
              ll a = *A.begin();
              B.emplace(a), A.erase(a);
              now -= a;
            }
            while (B.size() > 0 and A.size() < tn) {
              ll a = *B.rbegin();
              A.emplace(a), B.erase(a);
              now += a;
            }
          }
        }
      }
    }
    cout << now << '\n';
  }
}
