#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-6;
const int PRECISION = 20;
const int MOD = 1e9 + 7;
struct node {
  long long val;
  vector<long long> formula;
  node() { val = -1; }
};
struct group {
  long long mul, last, gcd;
  group(long long m, long long l, long long lm) {
    mul = m;
    last = l;
    gcd = lm;
  }
};
bool comp(pair<int, int> p1, pair<int, int> p2) {
  return p1.second < p2.second;
}
int bs(vector<int> vc, int target) {
  int low = 0, high = vc.size() - 1;
  while (high > low) {
    int mid = ((high - low + 1) / 2) + low;
    if (vc[mid] <= target)
      low = mid;
    else
      high = mid - 1;
  }
  return low;
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long fastPow(long long a, long long n, long long m) {
  if (n == 0) return 1;
  if (n == 1) return a;
  long long x = fastPow(a, n / 2, m) % m;
  x = (x * x) % m;
  return (n % 2 == 0 ? x : (x * a) % m);
}
int char2index(char a) { return a >= 'a' ? a - 'a' : a - 'A' + 26; }
int flipCase(char a) {
  return a >= 'a' ? char2index(a - ('a' - 'A')) : char2index(a + ('a' - 'A'));
}
void prefix(vector<long long> &arr) {
  for (int i = 1; i < arr.size(); i++) arr[i] += arr[i - 1];
}
long long eval(vector<long long> &coeffs, long long x) {
  long long ans = 0;
  long long xs = 1;
  for (long long i = coeffs.size() - 1; i >= 0; i--) {
    ans += (coeffs[i] * xs);
    xs *= x;
  }
  return ans;
}
int bracketToInt(char a) {
  switch (a) {
    case '(':
      return 1;
    case ')':
      return -1;
    case '{':
      return 2;
    case '}':
      return -2;
    case '[':
      return 3;
    case ']':
      return -3;
    case '<':
      return 4;
    case '>':
      return -4;
    default:
      return -1;
  }
}
long long findOpposite(long long x, long long y, long long n) {
  long long ans = 0;
  if (x - 2 >= 1) {
    if (y - 1 >= 1) ans++;
    if (y + 1 < n) ans++;
  }
  if (x + 2 <= n) {
    if (y - 1 >= 1) ans++;
    if (y + 1 <= n) ans++;
  }
  if (y - 2 >= 1) {
    if (x + 1 <= n) ans++;
    if (x - 1 >= 1) ans++;
  }
  if (y + 2 < n) {
    if (x + 1 <= n) ans++;
    if (x - 1 >= 1) ans++;
  }
  return ans;
}
vector<bool> taken;
long long solve(long long remain, const vector<long long> &nums,
                long long ind) {
  if (ind == 1) {
    for (long long i = 0; i < 5; i++) {
      if (!taken[i]) return remain == nums[i];
    }
  }
  for (long long i = 0; i < 5; i++) {
    if (taken[i]) continue;
    taken[i] = true;
    if (solve(remain - nums[i], nums, ind - 1)) return 1;
    if (solve(remain + nums[i], nums, ind - 1)) return 1;
    if (remain % nums[i] == 0 && solve(remain / nums[i], nums, ind - 1))
      return 1;
    taken[i] = false;
  }
  return 0;
}
bool customComp(pair<long long, long long> p1, pair<long long, long long> p2) {
  return p1.second < p2.second;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  set<long long> sets[2][2];
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    long long t, x;
    cin >> t >> x;
    if (x < 0) {
      x = -x;
      if (sets[t][0].find(x) != sets[t][0].end()) {
        sum -= x;
        sets[t][0].erase(x);
      } else {
        sum -= (2 * x);
        sets[t][1].erase(x);
      }
    } else {
      sets[t][0].insert(x);
      sum += x;
    }
    if (!sets[0][1].empty()) {
      auto f = sets[0][1].begin();
      sum -= *f;
      sets[0][0].insert(*f);
      sets[0][1].erase(f);
    }
    if (!sets[1][1].empty()) {
      auto l = sets[1][1].begin();
      sum -= *l;
      sets[1][0].insert(*l);
      sets[1][1].erase(l);
    }
    long long req = (sets[1][0].size() + sets[1][1].size()) -
                    (sets[1][1].size() + sets[0][1].size());
    while (req > 0 && (!sets[0][0].empty() || sets[1][0].size() > 1)) {
      long long target;
      if (sets[0][0].empty())
        target = 1;
      else if (sets[1][0].size() <= 1)
        target = 0;
      else {
        if (*sets[0][0].rbegin() > *sets[1][0].rbegin()) {
          target = 0;
        } else
          target = 1;
      }
      auto t = sets[target][0].rbegin();
      sum += *t;
      sets[target][1].insert(*t);
      sets[target][0].erase(*t);
      req--;
    }
    cout << sum << '\n';
  }
  return 0;
}
