Polycarp plays a computer game (yet again). In this game, he fights monsters using magic spells.

There are two types of spells: fire spell of power $x$ deals $x$ damage to the monster, and lightning spell of power $y$ deals $y$ damage to the monster and doubles the damage of the next spell Polycarp casts. Each spell can be cast only once per battle, but Polycarp can cast them in any order.

For example, suppose that Polycarp knows three spells: a fire spell of power $5$, a lightning spell of power $1$, and a lightning spell of power $8$. There are $6$ ways to choose the order in which he casts the spells:

  first, second, third. This order deals $5 + 1 + 2 \cdot 8 = 22$ damage;  first, third, second. This order deals $5 + 8 + 2 \cdot 1 = 15$ damage;  second, first, third. This order deals $1 + 2 \cdot 5 + 8 = 19$ damage;  second, third, first. This order deals $1 + 2 \cdot 8 + 2 \cdot 5 = 27$ damage;  third, first, second. This order deals $8 + 2 \cdot 5 + 1 = 19$ damage;  third, second, first. This order deals $8 + 2 \cdot 1 + 2 \cdot 5 = 20$ damage. 

Initially, Polycarp knows $0$ spells. His spell set changes $n$ times, each time he either learns a new spell or forgets an already known one. After each change, calculate the maximum possible damage Polycarp may deal using the spells he knows.


-----Input-----

The first line contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of changes to the spell set.

Each of the next $n$ lines contains two integers $tp$ and $d$ ($0 \le tp_i \le 1$; $-10^9 \le d \le 10^9$; $d_i \neq 0$) — the description of the change. If $tp_i$ if equal to $0$, then Polycarp learns (or forgets) a fire spell, otherwise he learns (or forgets) a lightning spell.

If $d_i > 0$, then Polycarp learns a spell of power $d_i$. Otherwise, Polycarp forgets a spell with power $-d_i$, and it is guaranteed that he knew that spell before the change.

It is guaranteed that the powers of all spells Polycarp knows after each change are different (Polycarp never knows two spells with the same power).


-----Output-----

After each change, print the maximum damage Polycarp can deal with his current set of spells.


-----Example-----
Input
6
1 5
0 10
1 -5
0 5
1 11
0 -10

Output
5
25
10
15
36
21

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = 'class BIT():\n    def __init__(self,n):\n        self.BIT=[0]*(n+1)\n        self.num=n\n\n    def query(self,idx):\n        res_sum = 0\n        while idx > 0:\n            res_sum += self.BIT[idx]\n            idx -= idx&(-idx)\n        return res_sum\n\n    #Ai += x O(logN)\n    def update(self,idx,x):\n        while idx <= self.num:\n            self.BIT[idx] += x\n            idx += idx&(-idx)\n        return\n\nimport sys,heapq,random\n\ninput=sys.stdin.readline\n\nn=int(input())\nspell=[tuple(map(int,input().split())) for i in range(n)]\n\n\nS=set([])\nfor i in range(n):\n    S.add(abs(spell[i][1]))\nS=list(S)\nS.sort(reverse=True)\ncomp={i:e+1 for e,i in enumerate(S)}\nN=len(S)\n\nx_exist=BIT(N)\ny_exist=BIT(N)\npower=BIT(N)\n\nX,Y,S=0,0,0\nXmax=[]\nYmin=[]\nx_data=[0]*(N+1)\ny_data=[0]*(N+1)\n\nfor i in range(n):\n    t,d=spell[i]\n    S+=d\n    if d<0:\n        id=comp[-d]\n        if t==0:\n            X-=1\n            x_exist.update(id,-1)\n            power.update(id,d)\n            x_data[id]-=1\n        else:\n            Y-=1\n            y_exist.update(id,-1)\n            power.update(id,d)\n            y_data[id]-=1\n    else:\n        id=comp[d]\n        if t==0:\n            X+=1\n            x_exist.update(id,1)\n            power.update(id,d)\n            heapq.heappush(Xmax,-d)\n            x_data[id]+=1\n        else:\n            Y+=1\n            y_exist.update(id,1)\n            power.update(id,d)\n            heapq.heappush(Ymin,d)\n            y_data[id]+=1\n    if X==0:\n        if Y==0:\n            print(0)\n        else:\n            while not y_data[comp[Ymin[0]]]:\n                heapq.heappop(Ymin)\n            print(2*S-Ymin[0])\n    else:\n        if Y==0:\n            print(S)\n        else:\n            start=0\n            end=N\n            while end-start>1:\n                test=(end+start)//2\n                if x_exist.query(test)+y_exist.query(test)<=Y:\n                    start=test\n                else:\n                    end=test\n            if y_exist.query(start)!=Y:\n                print(S+power.query(start))\n            else:\n                while not y_data[comp[Ymin[0]]]:\n                    heapq.heappop(Ymin)\n                while not x_data[comp[-Xmax[0]]]:\n                    heapq.heappop(Xmax)\n                print(S+power.query(start)-Ymin[0]-Xmax[0])\n'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 18093