#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9;
struct node {
  int x, y, size, t, cnt, min, max;
  long long sum;
  node *left, *right;
  node(int val, int type) {
    size = 1;
    cnt = t = type;
    sum = x = min = max = val;
    y = (rand() << 15) + rand();
    left = right = nullptr;
  }
  ~node() {
    if (left) delete left;
    if (right) delete right;
  }
};
int get_size(node *root) {
  if (!root)
    return 0;
  else
    return root->size;
}
int get_cnt(node *root) {
  if (!root)
    return 0;
  else
    return root->cnt;
}
long long get_sum(node *root) {
  if (!root)
    return 0;
  else
    return root->sum;
}
int get_min(node *root) {
  if (!root)
    return INF;
  else
    return root->min;
}
int get_max(node *root) {
  if (!root)
    return 0;
  else
    return root->max;
}
void update(node *root) {
  root->min = min({root->x, get_min(root->left), get_min(root->right)});
  root->max = max({root->x, get_max(root->left), get_max(root->right)});
  root->size = get_size(root->left) + get_size(root->right) + 1;
  root->cnt = get_cnt(root->left) + get_cnt(root->right) + root->t;
  root->sum = get_sum(root->left) + get_sum(root->right) + root->x;
}
pair<node *, node *> split(node *root, int val) {
  if (!root) return {nullptr, nullptr};
  if (root->x < val) {
    auto [res1, res2] = split(root->right, val);
    root->right = res1;
    update(root);
    return {root, res2};
  } else {
    auto [res1, res2] = split(root->left, val);
    root->left = res2;
    update(root);
    return {res1, root};
  }
}
pair<node *, node *> split_kth(node *root, int k) {
  if (!root) return {nullptr, nullptr};
  if (get_size(root->left) == k) {
    auto res = root->left;
    root->left = nullptr;
    update(root);
    return {res, root};
  } else if (get_size(root->left) > k) {
    auto [res1, res2] = split_kth(root->left, k);
    root->left = res2;
    update(root);
    return {res1, root};
  } else {
    auto [res1, res2] = split_kth(root->right, k - get_size(root->left) - 1);
    root->right = res1;
    update(root);
    return {root, res2};
  }
}
node *merge(node *root1, node *root2) {
  if (!root1) return root2;
  if (!root2) return root1;
  if (root1->y < root2->y) {
    root1->right = merge(root1->right, root2);
    update(root1);
    return root1;
  } else {
    root2->left = merge(root1, root2->left);
    update(root2);
    return root2;
  }
}
void insert(node *&root, int val, int t) {
  auto [res1, res3] = split(root, val);
  node *res2 = new node(val, t);
  root = merge(merge(res1, res2), res3);
}
void erase(node *&root, int val) {
  auto res1 = split(root, val), res2 = split(res1.second, val + 1);
  delete res2.first;
  root = merge(res1.first, res2.second);
}
int main() {
  int n, t, x;
  cin >> n;
  node *root = nullptr;
  while (n--) {
    cin >> t >> x;
    if (x > 0)
      insert(root, x, t);
    else
      erase(root, -x);
    auto [root1, root2] = split_kth(root, get_size(root) - get_cnt(root));
    long long ans = get_sum(root1) + 2 * get_sum(root2);
    if (root2 && root2->cnt == root2->size)
      ans += get_max(root1) - get_min(root2);
    cout << ans << endl;
    root = merge(root1, root2);
  }
  return 0;
}
