# Original solution

import queue

que_small=queue.PriorityQueue()
small_sum=0
que_s_size=0
que_b_size=0
que_big=queue.PriorityQueue()
big_sum=0

Q=int(eval(input()))
ans = []
b_sum=0
for i in range(Q):
    q=input().split()    
    if len(q)>1:
        a=int(q[1])
        if que_s_size==0:
            que_small.put(-a)
            small_sum+=a
            que_s_size+=1
        elif que_s_size>que_b_size:
            c=-que_small.get()
            small_sum-=c
            if c>a:
                que_big.put(c)
                big_sum+=c
                que_small.put(-a)
                small_sum+=a
            else:
                que_big.put(a)
                big_sum+=a
                que_small.put(-c)
                small_sum+=c
            que_b_size+=1
        else:
            c=-que_small.get()
            small_sum-=c
            d=que_big.get()
            big_sum-=d
            if a>d:
                que_big.put(a)
                big_sum+=a
                que_small.put(-c)
                que_small.put(-d)
                small_sum+=c+d
            else:
                que_big.put(d)
                big_sum+=d
                que_small.put(-a)
                que_small.put(-c)               
                small_sum+=a+c
            que_s_size+=1

        b_sum+=int(q[2])
    else:
        if que_s_size>que_b_size:
            c=-que_small.get()
            S = b_sum+big_sum-small_sum+c
            ans.append(str(c)+" "+str(S))
            que_small.put(-c)
        else:
            c=-que_small.get()
            S = b_sum+big_sum-small_sum
            ans.append(str(c)+" "+str(S))
            que_small.put(-c)
            

for a in ans:
    print(a)
    

# Optimized solution
import heapq
spq = []
bpq = []
#que_small=queue.PriorityQueue()
small_sum=0
que_s_size=0
que_b_size=0
#que_big=queue.PriorityQueue()
big_sum=0

Q=int(eval(input()))
ans = []
b_sum=0
for i in range(Q):
    q=input().split()    
    if len(q)>1:
        a=int(q[1])
        if que_s_size==0:
            heapq.heappush(spq,-a)
            small_sum+=a
            que_s_size+=1
        elif que_s_size>que_b_size:
            c=-heapq.heappop(spq)
            small_sum-=c
            if c>a:
                #que_big.put(c)
                heapq.heappush(bpq,c)
                big_sum+=c
                heapq.heappush(spq,-a)
                #que_small.put(-a)
                small_sum+=a
            else:
                #que_big.put(a)
                heapq.heappush(bpq,a)
                big_sum+=a
                #que_small.put(-c)
                heapq.heappush(spq,-c)
                small_sum+=c
            que_b_size+=1
        else:
            c=-heapq.heappop(spq)
            small_sum-=c
            d=heapq.heappop(bpq)
            big_sum-=d
            if a>d:
                #que_big.put(a)
                heapq.heappush(bpq,a)
                big_sum+=a
                #que_small.put(-c)
                #que_small.put(-d)
                heapq.heappush(spq,-c)
                heapq.heappush(spq,-d)
                small_sum+=c+d
            else:
                #que_big.put(d)
                heapq.heappush(bpq,d)
                big_sum+=d
                #que_small.put(-a)
                #que_small.put(-c)               
                heapq.heappush(spq,-a)
                heapq.heappush(spq,-c)
                small_sum+=a+c
            que_s_size+=1

        b_sum+=int(q[2])
    else:
        if que_s_size>que_b_size:
            c=-heapq.heappop(spq)
            S = b_sum+big_sum-small_sum+c
            ans.append(str(c)+" "+str(S))
            #que_small.put(-c)
            heapq.heappush(spq,-c)
        else:
            c=-heapq.heappop(spq)
            S = b_sum+big_sum-small_sum
            ans.append(str(c)+" "+str(S))
            #que_small.put(-c)
            heapq.heappush(spq,-c)
            

for a in ans:
    print(a)