import heapq
Q = int(input())
b = []
heapq.heapify(b)
a = 0
for i in range(Q):
    q = input()
    if q == '3':
        print(heapq.heappop(b) + a)
    else:
        m, x = map(int, q.split())
        if m == 1:
            heapq.heappush(b, x - a)
        if m == 2:
            a += x

86542343f0387d161d175404131a5f6204fb68b7
<mask token>

<mask token>
heapq.heapify(b)
<mask token>
for i in range(Q):
    q = input()
    if q == '3':
        print(heapq.heappop(b) + a)
    else:
        m, x = map(int, q.split())
        if m == 1:
            heapq.heappush(b, x - a)
        if m == 2:
            a += x

<mask token>
Q = int(input())
b = []
heapq.heapify(b)
a = 0
for i in range(Q):
    q = input()
    if q == '3':
        print(heapq.heappop(b) + a)
    else:
        m, x = map(int, q.split())
        if m == 1:
            heapq.heappush(b, x - a)
        if m == 2:
            a += x

import heapq
Q = int(input())
b = []
heapq.heapify(b)
a = 0
for i in range(Q):
    q = input()
    if q == '3':
        print(heapq.heappop(b) + a)
    else:
        m, x = map(int, q.split())
        if m == 1:
            heapq.heappush(b, x - a)
        if m == 2:
            a += x
