#include <bits/stdc++.h>
using namespace std;
int tp[212345], d[212345];
vector<int> ds;
int bit_cnt[212345];
long long int bit_sum[212345];
inline int get_id(int x) {
  return upper_bound(ds.begin(), ds.end(), x) - ds.begin();
}
inline int get_cnt(int x) {
  int ret = 0;
  while (x > 0) {
    ret += bit_cnt[x];
    x -= (x & -x);
  }
  return ret;
}
inline long long int get_sum(int x) {
  long long int ret = 0;
  while (x > 0) {
    ret += bit_sum[x];
    x -= (x & -x);
  }
  return ret;
}
inline void update_cnt(int x, int v) {
  while (x < 212345) {
    bit_cnt[x] += v;
    x += (x & -x);
  }
}
inline void update_sum(int x, int v) {
  while (x < 212345) {
    bit_sum[x] += v;
    x += (x & -x);
  }
}
set<int> lightning, fire;
long long int sum = 0;
inline int get_lightning_min() { return *(lightning.begin()); }
inline int get_fire_max() {
  set<int>::iterator it = fire.end();
  it--;
  return *(it);
}
inline void update(int i) {
  int id = get_id(d[i] > 0 ? d[i] : -d[i]);
  update_cnt(id, (d[i] > 0 ? 1 : -1));
  update_sum(id, d[i]);
  if (tp[i] == 0) {
    if (d[i] > 0) {
      fire.insert(d[i]);
    } else {
      fire.erase(-d[i]);
    }
  } else {
    if (d[i] > 0) {
      lightning.insert(d[i]);
    } else {
      lightning.erase(-d[i]);
    }
  }
  sum += d[i];
}
inline long long int get_top_k(int k) {
  int tot_cnt = get_cnt(212345 - 1);
  long long int tot_sum = get_sum(212345 - 1);
  int l = 1;
  int r = 212345 - 1;
  while (l < r) {
    int md = (l + r) / 2;
    if (get_cnt(md) >= tot_cnt - k) {
      r = md;
    } else {
      l = md + 1;
    }
  }
  return tot_sum - get_sum(r);
}
inline long long int query(int i) {
  if (lightning.size() == 0) {
    return sum;
  }
  if (fire.size() == 0) {
    int x = get_lightning_min();
    return sum + sum - x;
  }
  int lightning_min = get_lightning_min();
  int fire_max = get_fire_max();
  long long int ans = get_top_k(lightning.size()) + sum;
  if (fire_max < lightning_min) {
    ans += fire_max - lightning_min;
  }
  return ans;
}
inline void solve() {
  int n;
  cin >> n;
  for (long long int i = 0; i < n; ++i) {
    cin >> tp[i] >> d[i];
    if (d[i] > 0) ds.push_back(d[i]);
  }
  sort(ds.begin(), ds.end());
  ds.erase(unique(ds.begin(), ds.end()), ds.end());
  for (long long int i = 0; i < n; ++i) {
    update(i);
    cout << query(i) << "\n";
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
