#include <bits/stdc++.h>
using namespace std;
struct _IO {
  _IO() {
    ios::sync_with_stdio(0);
    cin.tie(0);
  }
} _io;
#pragma GCC optimize(2)
using ll = long long;
using db = long double;
using pi = pair<int, int>;
using mi = map<int, int>;
using vi = vector<int>;
void prl() { cout << '\n'; }
template <class T, class... U>
void prl(T x, U... y) {
  cout << x << ' ', prl(y...);
}
template <class T, class U>
ostream &operator<<(ostream &out, pair<T, U> p) {
  return out << "(" << p.first << ", " << p.second << ")";
}
template <class T>
ostream &operator<<(ostream &out, vector<T> &v) {
  out << "{";
  for (int i = (0); i < (v.size()); ++i) {
    if (i) out << ", ";
    out << v[i];
  }
  return out << "}";
}
const int N = 3e5 + 5, M = 998244353;
inline int add(int a, int b) { return a + b >= M ? a + b - M : a + b; }
inline int sub(int a, int b) { return a - b < 0 ? a - b + M : a - b; }
inline int mul(int a, int b) { return 1LL * a * b % M; }
signed main() {
  int n;
  cin >> n;
  int op, x;
  ll suma = 0, sumb = 0;
  set<int> sa, sb, a, b;
  for (int i = (0); i < (n); ++i) {
    cin >> op >> x;
    if (x > 0) {
      if (!a.size() || x < *a.begin())
        b.insert(x), sumb += x;
      else
        a.insert(x), suma += x - (*a.begin()), sumb += *a.begin(),
            b.insert(*a.begin()), a.erase(a.begin());
      if (op == 1)
        sb.insert(x), suma += *b.rbegin(), sumb -= *b.rbegin(),
            a.insert(*b.rbegin()), b.erase(*b.rbegin());
      else
        sa.insert(x);
    } else {
      x = -x;
      if (op == 1)
        suma -= *a.begin(), sumb += *a.begin(), b.insert(*a.begin()),
            a.erase(a.begin()), sb.erase(x);
      else
        sa.erase(x);
      if (a.find(x) != a.end())
        suma += (*b.rbegin()) - x, sumb -= *b.rbegin(), a.erase(x),
            a.insert(*b.rbegin()), b.erase(*b.rbegin());
      else
        sumb -= x, b.erase(x);
    }
    ll ans = suma * 2 + sumb;
    if (a.size() && sb.size() && (*a.begin()) == (*sb.begin())) {
      if (sa.size()) ans += *sa.rbegin();
      ans -= *sb.begin();
    }
    cout << ans << '\n';
  }
}
