#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
void buff() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
}
constexpr ll MOD = 1e9 + 7;
inline ll pow_mod(ll a, ll b, ll mod = MOD) {
  ll res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
  }
  return res;
}
template <typename T>
inline void remin(T& x, const T& y) {
  x = min(x, y);
}
template <typename T>
inline void remax(T& x, const T& y) {
  x = max(x, y);
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  os << "{";
  string sep;
  for (const auto& x : v) os << sep << x, sep = ", ";
  return os << "}";
}
template <typename T, size_t size>
ostream& operator<<(ostream& os, const array<T, size>& arr) {
  os << "{";
  string sep;
  for (const auto& x : arr) os << sep << x, sep = ", ";
  return os << "}";
}
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}
set<pair<int, int> > lightning, fire;
set<pair<int, int> > large_k;
int count_top_L = 0;
long long sum_top = 0;
long long sum_top_L = 0;
long long total_sum = 0;
inline pii maior(const pii& a, const pii& b) {
  if (a.first > b.first) return a;
  return b;
}
int main() {
  buff();
  int n;
  cin >> n;
  int K = 0;
  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    if (y < 0) y = -y;
    if (x == 1) {
      if (large_k.find(make_pair(y, x)) != large_k.end()) {
        sum_top -= y;
        sum_top_L -= y;
        total_sum -= y;
        count_top_L--;
        large_k.erase(make_pair(y, x));
        --K;
      } else if (lightning.count(make_pair(y, x)) == 1) {
        lightning.erase(make_pair(y, x));
        --K;
        auto B = *(large_k.begin());
        if (B.second == 1) {
          lightning.insert(B);
          sum_top -= B.first;
          sum_top_L -= B.first;
          count_top_L--;
        } else {
          fire.emplace(B);
          sum_top -= B.first;
        }
        large_k.erase(large_k.begin());
        total_sum -= y;
      } else {
        ++K;
        lightning.emplace(y, x);
        total_sum += y;
        if (fire.empty()) {
          auto L = *(lightning.rbegin());
          sum_top += L.first;
          sum_top_L += L.first;
          count_top_L++;
          lightning.erase(L);
          large_k.insert(L);
        } else {
          auto F = *(fire.rbegin());
          auto L = *(lightning.rbegin());
          if (L.first > F.first) {
            sum_top += L.first;
            sum_top_L += L.first;
            count_top_L++;
            lightning.erase(L);
            large_k.insert(L);
          } else {
            large_k.insert(F);
            sum_top += F.first;
            fire.erase(F);
          }
        }
      }
    } else {
      if (large_k.count(make_pair(y, x)) == 1) {
        sum_top -= y;
        total_sum -= y;
        large_k.erase(make_pair(y, x));
        pii best = make_pair(-1, 13);
        if (!fire.empty()) best = maior(best, *(fire.rbegin()));
        if (!lightning.empty()) best = maior(best, *(lightning.rbegin()));
        if (best.second == 0) {
          large_k.insert(best);
          sum_top += best.first;
          fire.erase(best);
        } else if (best.second == 1) {
          large_k.insert(best);
          sum_top += best.first;
          sum_top_L += best.first;
          count_top_L++;
          lightning.erase(best);
        }
      } else if (fire.count(make_pair(y, x)) == 1) {
        total_sum -= y;
        fire.erase(make_pair(y, x));
      } else {
        fire.emplace(y, x);
        total_sum += y;
        if (K > 0) {
          auto SMALL = *(large_k.begin());
          if (y > SMALL.first) {
            sum_top += y;
            sum_top -= SMALL.first;
            if (SMALL.second == 1) {
              sum_top_L -= SMALL.first;
              count_top_L--;
            }
            large_k.erase(SMALL);
            if (SMALL.second == 1)
              lightning.insert(SMALL);
            else
              fire.insert(SMALL);
            large_k.emplace(y, x);
            fire.erase(make_pair(y, x));
          }
        }
      }
    }
    long long resp = total_sum;
    long long inc = 0ll;
    ;
    ;
    ;
    if (K > 0) {
      ;
      ;
      if (count_top_L == K) {
        inc += sum_top;
        inc -= large_k.begin()->first;
        auto PAR = make_pair(-1, 13);
        if (!fire.empty()) PAR = maior(PAR, *(fire.rbegin()));
        if (!lightning.empty()) PAR = maior(PAR, *(lightning.rbegin()));
        if (PAR.first != -1) inc += PAR.first;
      } else {
        inc += sum_top;
      }
    };
    ;
    cout << resp + inc << endl;
  }
  return 0;
}
