There is a function f(x), which is initially a constant function f(x) = 0.
We will ask you to process Q queries in order. There are two kinds of queries, update queries and evaluation queries, as follows:
 - An update query 1 a b: Given two integers a and b, let g(x) = f(x) + |x - a| + b and replace f(x) with g(x).
 - An evaluation query 2: Print x that minimizes f(x), and the minimum value of f(x). If there are multiple such values of x, choose the minimum such value.
We can show that the values to be output in an evaluation query are always integers, so we ask you to print those values as integers without decimal points.

-----Constraints-----
 - All values in input are integers.
 - 1 \leq Q \leq 2 \times 10^5
 - -10^9 \leq a, b \leq 10^9
 - The first query is an update query.

-----Input-----
Input is given from Standard Input in the following format:
Q
Query_1
:
Query_Q

See Sample Input 1 for an example.

-----Output-----
For each evaluation query, print a line containing the response, in the order in which the queries are given.
The response to each evaluation query should be the minimum value of x that minimizes f(x), and the minimum value of f(x), in this order, with space in between.

-----Sample Input-----
4
1 4 2
2
1 1 -8
2

-----Sample Output-----
4 2
1 -3

In the first evaluation query, f(x) = |x - 4| + 2, which attains the minimum value of 2 at x = 4.
In the second evaluation query, f(x) = |x - 1| + |x - 4| - 6, which attains the minimum value of -3 when 1 \leq x \leq 4. Among the multiple values of x that minimize f(x), we ask you to print the minimum, that is, 1.

Difficulty: interview

Starter code:

Solutions:
Q = int(input())
qs = [input().split() for i in range(Q)]

import heapq
class Heapq:
    def __init__(self, arr, desc=False):
        if desc:
            arr = [-a for a in arr]
        self.sign = -1 if desc else 1
        self.hq = arr
        heapq.heapify(self.hq)

    def pop(self):
        return heapq.heappop(self.hq) * self.sign

    def push(self, a):
        heapq.heappush(self.hq, a * self.sign)

    def top(self):
        return self.hq[0] * self.sign

    def size(self):
        return len(self.hq)

lq = Heapq([], True)
rq = Heapq([], False)

ofs = 0
for q in qs:
    if q[0] == '2':
        print(lq.top(), ofs)
        continue
    _,a,b, = q
    a,b = int(a),int(b)
    ofs += b
    lq.push(a)
    rq.push(a)
    if lq.top() > rq.top():
        l,r = lq.pop(), rq.pop()
        ofs += abs(l-r)
        lq.push(r)
        rq.push(l)

from heapq import *
l = list()
r = list()
q = int(input())
sb = 0
sr = 0
sl = 0
f = 0
for _ in range(q):
  t = list(map(int, input().split()))
  if t[0] == 1:
    f ^= 1
    _, a, b = t
    sb += b
    if f:
      c = heappushpop(r, a)
      sr += a - c
      heappush(l, -c)
      sl += c
    else:
      c = -heappushpop(l, -a)
      sl += a - c
      heappush(r, c)
      sr += c   
  else:
    print(-l[0], l[0]*(len(r)-len(l)) + sr - sl + sb)

import heapq


def main():
    Q = int(input())
    query_list = [list(map(int, input().split(' '))) for _ in range(Q)]
    # fの最小を与えるxの計算用
    que_left, que_right = [], []  # 最大ヒープと最小ヒープ
    # fの最小値の計算用
    sum_a_cost = 0
    sum_b = 0
    for query in query_list:
        if query[0] == 1:
            a, b = query[1], query[2]
            # fの更新
            if len(que_right) - len(que_left) == 1:
                sum_a_cost += abs(a - que_right[0])
            elif 0 < len(que_left) == len(que_right):
                if a > que_right[0]:
                    sum_a_cost += a - que_right[0]
                elif a < - que_left[0]:
                    sum_a_cost += - que_left[0] - a
            sum_b += b
            # xの更新
            if len(que_right) == 0 or a >= que_right[0]:
                heapq.heappush(que_right, a)
            else:
                # 最大ヒープにするため符号反転
                heapq.heappush(que_left, - a)
            # ヒープのサイズ差が0 or 1になるよう調整
            if len(que_right) - len(que_left) == - 1:
                heapq.heappush(que_right, - heapq.heappop(que_left))
            elif len(que_right) - len(que_left) == 2:
                heapq.heappush(que_left, - heapq.heappop(que_right))
        else:
            x = que_right[0] if len(que_right) - len(que_left) == 1 else (- que_left[0])
            f = sum_a_cost + sum_b
            print('{} {}'.format(x, f))


def __starting_point():
    main()
__starting_point()

from heapq import heappop,heappush
l,r=[],[]
ans=0
for _ in range(int(input())):
	a=list(map(int,input().split()))
	if a[0]==1:
		_,ia,ib=a
		heappush(l,-ia)
		heappush(r,ia)
		ll=heappop(l)
		rr=heappop(r)
		heappush(l,-rr)
		heappush(r,-ll)
		ans+=ib+abs(ll+rr)
	else:print(-l[0],ans)

from heapq import heappop, heappush
Q = int(input())
maxh = []
minh = []
sum1 = sum2 = b = med = 0
for i in range(Q):
  q = list(map(int, input().split()))
  if q[0]==1:
    b += q[2]
    if len(maxh)==0 or q[1]<-maxh[0]:
      heappush(maxh, -q[1])
      sum1 += q[1]
      if len(maxh)>len(minh)+1:
        t = -heappop(maxh)
        heappush(minh, t)
        sum1 -= t
        sum2 += t
    else:
      heappush(minh, q[1])
      sum2 += q[1]
      if len(maxh)<len(minh):
        t = heappop(minh)
        heappush(maxh, -t)
        sum1 += t
        sum2 -= t
    med = -maxh[0]
  else:
    ans = len(maxh)*med-sum1+sum2-len(minh)*med+b
    print(med, ans)

import heapq

q = int(input())

nchange = 0
ming, maxg = [], []
heapq.heapify(ming)
heapq.heapify(maxg)
a = 0
b = 0
for i in range(q):
    qi = input()
    if qi[0] == '1':
        _, ai, bi = map(int, qi.split())
        b += bi
        nchange += 1
        if nchange % 2 == 1:
            if nchange == 1:
                x = ai
                continue
            Smax = -heapq.heappop(ming)
            Dmin = heapq.heappop(maxg)
            if Smax <= ai and ai <= Dmin:
                heapq.heappush(ming, -Smax)
                heapq.heappush(maxg, Dmin)
                x = ai
            elif ai < Smax:
                heapq.heappush(ming, -ai)
                heapq.heappush(maxg, Dmin)
                x = Smax
                a += Smax - ai
            else:
                heapq.heappush(ming, -Smax)
                heapq.heappush(maxg, ai)
                x = Dmin
                a += ai - Dmin
        else:
            heapq.heappush(ming, -min(x, ai))
            heapq.heappush(maxg, max(x, ai))
            a += abs(x - ai)
            x = -heapq.heappop(ming)
            heapq.heappush(ming, -x)
    else:
        print(x, a+b)

from heapq import *
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]
dij=[(1,0),(-1,0),(0,1),(0,-1)]

def main():
    sa = sb = 0
    hp1 = []
    hp2 = []
    m = None
    for _ in range(II()):
        ab=input().split()
        if ab[0]=="1":
            a,b=int(ab[1]),int(ab[2])
            sb+=b
            heappush(hp1,-a)
            heappush(hp2,a)
            while -hp1[0]>hp2[0]:
                heappush(hp1,-heappop(hp2))
                heappush(hp2,-heappop(hp1))
            if m==None:
                m=a
                continue
            if -hp1[0]>m:
                d=-hp1[0]-m
                sa+=(len(hp1)-1)//2*d-(len(hp2)+1)//2*d
            if -hp1[0]<m:
                d=hp1[0]+m
                sa+=-(len(hp1))//2*d+(len(hp2))//2*d
            sa += abs(m - a)
            m=-hp1[0]
        else:
            print(m,sa+sb)

main()

from heapq import*
L,R=[],[]
B=t=0
Q,*E=open(0)
for e in E:
  if' 'in e:_,a,b=map(int,e.split());t^=1;a*=2*t-1;c=heappushpop([L,R][t],a);heappush([R,L][t],-c);B+=b+a-c-c
  else:print(-L[0],B-L[0]*t)

import heapq

class heap():
    def __init__(self):
        self.heap = []
        self.asum = 0

class solve():
    def __init__(self):
        self.lower = heap()
        self.upper = heap()
        self.bsum = 0
        self.amed = 0
    
    def update(self,a,b):
        self.bsum += b
        if a > self.amed:
            self.__add(self.upper, a)
        else:
            self.__add(self.lower,-a)
            
        if len(self.upper.heap)>len(self.lower.heap):
            a = self.__del(self.upper)
            self.__add(self.lower, -a)
        elif len(self.lower.heap) > len(self.upper.heap) + 1:
            a = self.__del(self.lower)
            self.__add(self.upper, -a)
        
        self.amed = -self.lower.heap[0]
        
    def get_min(self):
        x = self.amed
        fx = (x * len(self.lower.heap) + self.lower.asum) + (self.upper.asum - x*len(self.upper.heap))
        fx += self.bsum
        print(x,fx)
            
    def __add(self,heap, a):
        heapq.heappush(heap.heap,a)
        heap.asum += a
    
    def __del(self, heap):
        a = heapq.heappop(heap.heap)
        heap.asum -= a
        return a

fx = solve()
    
Q = int(input())
for _ in range(Q):
    q = input()
    if q[0]=="2":
        fx.get_min()
    else:
        _,a,b = map(int,q.split())
        fx.update(a,b)

from heapq import heapify, heappush, heappop
import sys
input = sys.stdin.readline

Q = int(input())
querys = [tuple(map(int, input().split())) for _ in range(Q)]

anss = []
PQL, PQR = [], []
sumL = sumR = 0
numL = numR = 0
sumB = 0
for query in querys:
    if query[0] == 1:  # 更新
        a, b = query[1:]
        sumB += b
        if numL == 0:
            heappush(PQL, -a)
            sumL += a
            numL += 1
        elif numL == numR:
            if a <= -PQL[0]:
                heappush(PQL, -a)
                sumL += a
                numL += 1
            else:
                heappush(PQR, a)
                c = heappop(PQR)
                sumR += a-c
                heappush(PQL, -c)
                sumL += c
                numL += 1
        else:
            if a < -PQL[0]:
                heappush(PQL, -a)
                c = -heappop(PQL)
                sumL += a-c
                heappush(PQR, c)
                sumR += c
                numR += 1
            else:
                heappush(PQR, a)
                sumR += a
                numR += 1

    else:  # 求値
        x = -PQL[0]
        fx = numL*x - sumL + sumR - numR*x + sumB
        anss.append((x, fx))

print(('\n'.join([str(x[0])+' '+str(x[1]) for x in anss])))


from heapq import*
L,R=[],[]
B=t=0
Q,*E=open(0)
for e in E:
	if' 'in e:_,a,b=map(int,e.split());t=1-t;a*=2*t-1;c=heappushpop([L,R][t],a);heappush([R,L][t],-c);B+=b+a-c-c
	else:print(-L[0],B-L[0]*t)

from heapq import*
L,R=[],[]
B=t=0
Q,*E=open(0)
for e in E:
  if' 'in e:_,a,b=map(int,e.split());t^=1;a*=2*t-1;c=heappushpop([L,R][t],a);heappush([R,L][t],-c);B+=b+a-c-c
  else:print(-L[0],B-L[0]*t)

import heapq

q = int(input())
inf = 10000000000
left = [inf]
right = [inf]
minval = 0
for _ in range(q):
    query = list(map(int, input().split()))
    if query[0] == 1:
        _, a, b = query
        if a < -left[0]:
            v = -heapq.heappop(left)
            heapq.heappush(right, v)
            heapq.heappush(left, -a)
            heapq.heappush(left, -a)
            minval += abs(v - a) + b
        elif a > right[0]:
            v = heapq.heappop(right)
            heapq.heappush(left, -v)
            heapq.heappush(right, a)
            heapq.heappush(right, a)
            minval += abs(v - a) + b
        else:
            heapq.heappush(left, -a)
            heapq.heappush(right, a)
            minval += b
    else:
        print(-left[0], minval)

import heapq
Q = int(input())

# 中央値の左側の値、右側の値を管理する
# heapqとする。rightは最小が興味あるが、leftは最大なので、-1をかけて扱う
left, right = [], []
# 両方のSUMも管理する必要がある。毎回SUMしてたら間に合わん
Lsum, Rsum = 0,0
Lcnt, Rcnt = 0,0
B = 0
for _ in range(Q):
  q = list(map(int, input().split()))
  if len(q) == 1:
    # 2
    # heapqってPeakできないの・・・？
    l = (-1) * heapq.heappop(left)
    heapq.heappush(left,(-1)*l)
    # (l-l1) + (l-l2) + ... + (l-l) + (r-l) + ... + (r1 - l)
    print(l, Rsum//2 - Lsum//2 + B)
    #print(left,right, Lsum, Rsum)
  else:
    # 1
    _,a,b = q
    B += b
    # まず双方にaを突っ込む
    heapq.heappush(left,(-1)*a)
    heapq.heappush(right,a)
    Lsum += a
    Lcnt += 1
    Rsum += a
    Rcnt += 1
    # leftの最大値と、rightの最小値の関係が崩れていたら、交換する
    l = (-1) * heapq.heappop(left)
    r = heapq.heappop(right)
    if l>=r:
      Lsum = Lsum - l + r
      Rsum = Rsum - r + l
      l,r = r,l
    heapq.heappush(left,(-1)*l)
    heapq.heappush(right,r)

import heapq
Q = int(input())

A_left, A_right = [], []
A_left_sum, A_right_sum = 0, 0
heapq.heapify(A_left)
heapq.heapify(A_right)

B_sum = 0
for _ in range(Q):
    query = list(map(int,input().split()))

    if query[0] == 1:
        now = query[1]
        B_sum += query[2]

        l, r = len(A_left), len(A_right)
        if l <= r:
            heapq.heappush(A_right, now)
            A_right_sum += now

            out = heapq.heappop(A_right)
            A_right_sum -= out

            heapq.heappush(A_left, -out)
            A_left_sum += out
        else:
            heapq.heappush(A_left, -now)
            A_left_sum += now

            out = -heapq.heappop(A_left)
            A_left_sum -= out

            heapq.heappush(A_right, out)
            A_right_sum += out
    else:
        m = -A_left[0]
        ans = len(A_left) * m - A_left_sum - len(A_right) * m + A_right_sum + B_sum
        print(("{0} {1}".format(m,ans)))


# -*- coding: utf-8 -*-
"""
Created on Tue May 28 22:22:21 2019

@author: Yamazaki Kenichi
"""
import heapq

Q = int(input())
Q2 = [input() for i in range(Q)]

ans = []
Al,Ar = [-(-(10**9+1))],[10**9+1]
d, a, b = list(map(int,Q2[0].split()))
heapq.heappush(Al,-a)
B = b

for i in range(1,Q):
    if Q2[i][0] == '1':
#        intput
        d, a, b = list(map(int,Q2[i].split()))
        if len(Al) == len(Ar):
            if a < Ar[0]:
                heapq.heappush(Al,-a)
            else:
                heapq.heappush(Ar,a)
                heapq.heappush(Al,-(heapq.heappop(Ar)))
            C = abs(a - (-Al[0]))
        else:
            C = abs(a - (-Al[0]))
            if a < Ar[0]:
                heapq.heappush(Al,-a)
                heapq.heappush(Ar,-(heapq.heappop(Al)))
            else:
                heapq.heappush(Ar,a)
        B += (b + C)
#        print(Al,Ar,a,B,b)
    else:
#        output
        ans.append([(-Al[0]),B])

for c in ans:
    print((' '.join(map(str,c))))



import heapq

q = int(input())

minheap = [] # right
maxheap = [] # left
heapq.heapify(minheap)
heapq.heapify(maxheap)

s = 0
m = 0

for _ in range(0, q):
    token = input().split()
    if len(token) > 1:
        a = int(token[1])
        b = int(token[2])
        s += b
        heapq.heappush(minheap, a)
        heapq.heappush(maxheap, -a)
        if -maxheap[0] > minheap[0]:
            maxv = -heapq.heappop(maxheap)
            minv = heapq.heappop(minheap)
            m += abs(maxv - minv)
            heapq.heappush(minheap, maxv)
            heapq.heappush(maxheap, -minv)
    else:
        print(('{} {}'.format(-maxheap[0], s + m)))


from heapq import heappop,heappush
import sys
input=sys.stdin.readline

q=int(input())
query=[list(map(int,input().split())) for _ in range(q)]
inf=10**12
left=[inf]
left_sum=0
right=[inf]
right_sum=0

cnt=0
b=0
for i in range(q):
    if query[i][0]==1:
        a=query[i][1]
        b+=query[i][2]
        if cnt==0:
            d=right[0]
            if a>d:
                heappush(left,-heappop(right))
                heappush(right,a)
                right_sum+=a-d
                left_sum-=d
            else:
                heappush(left,-a)
                left_sum-=a
            cnt=1
        else:
            c=-left[0]
            if a<c:
                heappush(right,-heappop(left))
                heappush(left,-a)
                right_sum+=c
                left_sum+=c-a
            else:
                heappush(right,a)
                right_sum+=a
            cnt=0
    else:
        x=-left[0]
        if cnt==0:
            print(x,b+right_sum+left_sum)
        else:
            print(x,b+x+right_sum+left_sum)

# python 3.4.3
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# library
# -------------------------------------------------------------



# -------------------------------------------------------------
# main
# -------------------------------------------------------------
import heapq

L,R = [10**15],[10**15]
lenL,lenR = 1,1
sumL,sumR = 0,0
y = 0

Q = int(input())
for i in range(Q):
    query = list(map(int,input().split()))
    if len(query) == 1:
        x = -L[0]
        f = sumR - sumL + y
        if lenL != lenR:
            f += x
        print(("{} {}".format(x, f)))
    else:
        q,a,b = query
        y += b
        if lenL > lenR:
            sumL += a
            a = -heapq.heappushpop(L, -a)
            sumL -= a
            heapq.heappush(R, a)
            sumR += a
            lenR += 1
        else:
            sumR += a
            a = heapq.heappushpop(R, a)
            sumR -= a
            heapq.heappush(L, -a)
            sumL += a
            lenL += 1




from heapq import*
L,R=[],[]
B=t=0
Q,*E=open(0)
for e in E:
	if' 'in e:_,a,b=map(int,e.split());t^=1;a*=2*t-1;c=heappushpop([L,R][t],a);heappush([R,L][t],-c);B+=b+a-c-c
	else:print(-L[0],B-L[0]*t)

import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from heapq import heappop, heappush

bigger = []
smaller = []

def modify(bigger, smaller, a: int, b: int, mid: int, ans: int):
    if not bigger and not smaller:
        heappush(smaller, -a)
        mid = a
    elif not bigger:
        if a < -smaller[0]:
            heappush(bigger, -heappop(smaller))
            heappush(smaller, -a)

            ans += abs(-smaller[0] - mid)

        else:
            heappush(bigger, a)
    else:
        if a < -smaller[0]:
            tmp = -heappop(smaller)
            heappush(smaller, -a)
            if (len(smaller) + len(bigger)) % 2:
                ans += abs(-smaller[0] - mid)
        elif a > bigger[0]:
            tmp = heappop(bigger)
            heappush(bigger, a)
        else:
            tmp = a

        if len(smaller) == len(bigger):
            heappush(smaller, -tmp)
        else:
            heappush(bigger, tmp)

    ans += (abs(-smaller[0] - a) + b)
    mid = -smaller[0]

    return mid, ans

q = ni()
mid = ans = 0

for _ in range(q):
    # judge process
    query = ns()
    if query.startswith("1"):
        _, a, b = map(int, query.split())
        mid, ans = modify(bigger, smaller, a, b, mid, ans)

    else:
        print(mid, ans)

import heapq

q = int(input())
l = []
r = []
ans = 0

for i in range(q):
    a = list(map(int,input().split()))
    if a[0] == 1:
        ans += a[2]
        if l == []:
            heapq.heappush(r,a[1])
            heapq.heappush(l,-a[1])
        else: 
            ll = -heapq.heappop(l)
            rr = heapq.heappop(r)
            if ll <= a[1] <= rr:
                heapq.heappush(r,rr)
                heapq.heappush(l,-ll) 
                heapq.heappush(r,a[1])
                heapq.heappush(l,-a[1]) 

            elif ll > a[1]:
                ans += ll-a[1]
                heapq.heappush(r,rr)
                heapq.heappush(r,ll) 
                heapq.heappush(l,-a[1])
                heapq.heappush(l,-a[1]) 
            else:
                ans += a[1] -rr
                heapq.heappush(l,-rr)
                heapq.heappush(l,-ll) 
                heapq.heappush(r,a[1])
                heapq.heappush(r,a[1]) 
        
    else:
        a = heapq.heappop(l)
        print(-a,ans)
        heapq.heappush(l,a)

import heapq

q = int(input())
ans = []
mini = 0
left, right = [], []
cnt = 0
mid = None
for _ in range(q):
    qi = input()
    if qi == '2':
        if cnt%2 == 0:
            ans.append([-left[0], mini])
        else:
            ans.append([mid, mini])
    else:
        kind, a, b = map(int, qi.split())
        if cnt%2 == 1:
            mini += abs(mid-a) + b
            heapq.heappush(left, -min(mid, a))
            heapq.heappush(right, max(mid, a))
            mid = None
        else:
            if cnt == 0:
                mid = a
                mini = b
                cnt += 1
                continue
            l = -heapq.heappop(left)
            r = heapq.heappop(right)
            if a <= l:
                mini += l-a + b
                heapq.heappush(left, -a)
                heapq.heappush(right, r)
                mid = l
            elif a <= r:
                mini += b
                heapq.heappush(left, -l)
                heapq.heappush(right, r)
                mid = a
            else:
                mini += a-r + b
                heapq.heappush(left, -l)
                heapq.heappush(right, a)
                mid = r
        cnt += 1

for i, j in ans:
    print(i, j)

from heapq import heapify, heappush, heappop
import sys
input = sys.stdin.readline

Q = int(input())
ss = input()
t, A, B = list(map(int, ss.split()))
PQ1, PQ2 = [-A], [A]
fr = to = A
minF = 0
accB = B
anss = []
for _ in range(Q-1):
    ss = input()
    if ss[0] == '1':
        t, A, B = list(map(int, ss.split()))
        if fr <= A <= to:
            heappush(PQ1, -A)
            heappush(PQ2, A)
        elif A < fr:
            p = -heappop(PQ1)
            heappush(PQ2, p)
            heappush(PQ1, -A)
            heappush(PQ1, -A)
            minF += fr-A
        else:
            p = heappop(PQ2)
            heappush(PQ1, -p)
            heappush(PQ2, A)
            heappush(PQ2, A)
            minF += A-to
        fr = -heappop(PQ1)
        to = heappop(PQ2)
        heappush(PQ1, -fr)
        heappush(PQ2, to)
        accB += B
    else:
        anss.append((fr, minF+accB))

print(('\n'.join([str(x[0])+' '+str(x[1]) for x in anss])))


from heapq import heappop,heappush
q=int(input())
queries=[list(map(int,input().split()))for _ in range(q)]
l=[]
r=[]
ans=0
queonecount=0
mid=-1
for query in queries:
  if query[0]==1:
    queonecount+=1
    _,a,b=query
    ans+=b
    heappush(l,-a)
    heappush(r,a)
    midl=-heappop(l)
    midr=heappop(r)
    ans+=abs(midl-midr)
    heappush(l,-midr)
    heappush(r,midl)
  if query[0]==2:
    minind=-heappop(l)
    print(minind,ans)
    heappush(l,-minind)

import heapq as hq
Q = int(input())
minval = 0
argminval = -(10**9)
#aを大きい方と小さい方に分けて最小ヒープで管理(Lは最大が欲しいので-1掛けておく)
L, R = [10**9], [10**9]
lenL, lenR = 0, 0

for _ in range(Q):
    qi = list(map(int, input().split()))
    if qi[0] == 1:
        ai, bi = qi[1], qi[2]
        LC, RC = -1*L[0], R[0] #左右それぞれで中央に一番近いもの
        if lenL == lenR:
            if ai < RC:
                #Lにaiを追加
                hq.heappush(L, -1*ai)
            else:
                #RCをLに移動, Rにaiを追加
                hq.heappop(R)
                hq.heappush(L, -1*RC)
                hq.heappush(R, ai)
            lenL += 1
            #新しいargminで最小値更新
            argminval = -1*L[0]
            minval += abs(argminval - ai) + bi
        else:
            if ai < LC:
                #LCをRに移動, Lにaiを追加
                hq.heappop(L)
                hq.heappush(L, -1*ai)
                hq.heappush(R, LC)
            else:
                #Rにaiを追加
                hq.heappush(R, ai)
            lenR += 1
            #古いargminで最小値更新
            minval += abs(argminval - ai) + bi
            argminval = -1*L[0]
    else:
        print("{} {}".format(argminval, minval))

import heapq as h
q_num=int(input())
bsum=0
high=[]
low=[]
asum=0
for iii in range(q_num):
  q=[int(_) for _ in input().split()]
  if q[0]==1:
    bsum+=q[2]
    if len(low)==0:
      h.heappush(low,-q[1])
    else:
      asum+=abs(q[1]+low[0])
      if -low[0]>=q[1]:
        h.heappush(low,-q[1])
      else:
        h.heappush(high,q[1])
      
    if len(low)>=len(high)+2:
      ltoh=h.heappop(low)
      h.heappush(high, -ltoh)
    elif len(high)>=len(low)+1:
      ltoh=h.heappop(high)
      asum+=-low[0]-ltoh
      h.heappush(low, -ltoh)
  else:
    print(-low[0],asum+bsum)

import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

from heapq import heapify,heappop,heappush
def main():
    Q = int(input())
    total_b = 0
    total_a = 0
    less_than_middle = 0
    left = []
    right = []
    cnt = 0
    for _ in range(Q):
        query = tuple(map(int,input().split()))
        if query[0] == 1:
            a,b = query[1:]
            total_b += b
            total_a += a
            cnt += 1
            heappush(right,a)
            while left and right and (-left[0] > right[0]):
                p = -heappop(left)
                q = heappop(right)
                heappush(left,-q)
                heappush(right,p)
                less_than_middle += -p + q
            if cnt%2 == 0:
                p = heappop(right)
                heappush(left,-p)
                less_than_middle += p
        else:
            if cnt%2 == 0:
                x = -left[0]
                ans = total_a - 2*less_than_middle + total_b
                print(x,ans)
            else:
                x = right[0]
                ans = total_a - 2*less_than_middle - x + total_b
                print(x,ans)
def __starting_point():
    main()
__starting_point()

import heapq

q = int(input())
big, small = [], []
heapq.heapify(big)
heapq.heapify(small)
sumb = 0
sumdist = 0
i = 0
for _ in range(q):
    query = list(map(int, input().split()))
    if query[0] == 1:
        i += 1
        a, b = query[1], query[2]
        sumb += b
        if i % 2 == 1:
            if i == 1:
                median = a
            else:
                if big[0] <= a:
                    median = heapq.heappushpop(big, a)
                    sumdist += abs(a - median)
                elif a <= -small[0]:
                    median = -heapq.heappushpop(small, -a)
                    sumdist += abs(a - median)
                else:
                    median = a
        else:
            sumdist += abs(a - median)
            heapq.heappush(big, max(a, median))
            heapq.heappush(small, -min(a, median))
            median = -small[0]
    else:
        print(median, sumdist + sumb)

import numpy as np
import heapq
Q = int(input())
Qinit = list(map(int,input().split()))
Qlist = [list(map(int,input().split())) for i in range(Q-1)]

#coef_list = []
intercept = Qinit[2]
left_list = []
cent_list = [Qinit[1]]
right_list = []
left_sum = 0
right_sum = 0

median = Qinit[1]
count = 0

for query in Qlist:
    if query[0] == 1:
        source = query[1]
        intercept += query[2]

        if cent_list == []:
            if median > source:
                heapq.heappush(left_list, -source)
                left_sum += source #
                tmp = -heapq.heappop(left_list)
                left_sum -= tmp #
                cent_list.append(tmp)
            elif right_list[0] > source:
                cent_list.append(source)
            else:
                heapq.heappush(right_list, source)
                tmp = heapq.heappop(right_list)
                right_sum += source - tmp
                cent_list.append(tmp)
            median = cent_list[0]
        else:
            if cent_list[0] < source:
                heapq.heappush(left_list, -cent_list[0])
                left_sum += cent_list[0]
                median = cent_list[0]
                heapq.heappush(right_list, source)
                right_sum += source
                cent_list.remove(cent_list[0])
            else:
                heapq.heappush(left_list, -source)
                left_sum += source
                median = -left_list[0]
                heapq.heappush(right_list, cent_list[0])
                right_sum += cent_list[0]
                cent_list.remove(cent_list[0])
            count += 1

    else:
        minval = np.abs(left_sum-count*median) + np.abs(right_sum-count*median) + intercept
        #print(str(median) + " " + str(minval))
        print(("{} {}".format(median, minval)))


import heapq

Q = int(input())
m = L = R = 0
l, r = [], []
n = 0
b = 0

for i in range(Q):
  query = list(map(int, input().split()))
  if len(query) == 3: # 更新クエリ
    b += query[2]
    new = query[1]
    if  n == 0:
      m = new
    elif n == 1:
      if new <= m:
        heapq.heappush(l, -new)
        heapq.heappush(r, m)
        L, R = new, m
        m = new
      else:
        heapq.heappush(l, -m)
        heapq.heappush(r, new)
        L, R = m, new
    elif n == 2:
      if new < m:
        m = -heapq.heappop(l)
        heapq.heappush(l, -new)
        L = new
      else:
        _r = heapq.heappop(r)
        if new < _r:
          m = new
          heapq.heappush(r, _r)
        else:
          m = _r
          heapq.heappush(r, new)
          R = new
    else:
      _l = - l[0]
      _r = r[0]
      if n%2:
        if new <= _l:
          _ = heapq.heappop(l)
          heapq.heappush(l, -new)
          heapq.heappush(r, m)
          m, L, R = _l, L+new, R+m
        elif new <= m:
          heapq.heappush(r, m)
          m, L, R = new, L+new, R+m
        else:
          heapq.heappush(r, new)
          L, R = L+m, R+new
      else:
        if new <= m:
          heapq.heappush(l, -new)
          L += new - m
        elif new <= _r:
          heapq.heappush(l, -m)
          m = new
        else:
          _ = heapq.heappop(r)
          heapq.heappush(l, -m)
          heapq.heappush(r, new)
          m, R = _r, R+new-_r
    n += 1
  else: # 求値クエリ
    print(m, R-L+b)

import heapq
Q = int(input())
ans = 0
L = []
R = []
for _ in range(Q):
    q = input()
    if q[0] == '1':
        _, a, b = map(int, q.split())
        ans += b
        if len(L) > 0 and not -L[0] <= a <= R[0]:
            ans += min(abs(a + L[0]), abs(a - R[0]))
        l = heapq.heappushpop(L, -a)
        r = heapq.heappushpop(R, a)
        heapq.heappush(L, -r)
        heapq.heappush(R, -l)
    else:
        print(-L[0], ans)

import heapq
import collections

cnt=1
cnts=collections.defaultdict(int)
median=0
left_cnt=0
right_cnt=0
left_sum=0
right_sum=0
left_pos=[]
right_pos=[]
b=0
q=int(input())
initial=list(map(int,input().split()))
median=initial[1]
b+=initial[2]
cnts[median]=1
for _ in range(q-1):
  query=list(map(int,input().split()))
  if query[0]==1:
    cnt+=1
    b+=query[2]
    if query[1]==median:
      cnts[median]+=1
    elif query[1]<median:
      left_cnt+=1
      left_sum+=query[1]
      cnts[query[1]]+=1
      if cnts[query[1]]==1:
        heapq.heappush(left_pos,-query[1])
    elif query[1]>median:
      right_cnt+=1
      right_sum+=query[1]
      cnts[query[1]]+=1
      if cnts[query[1]]==1:
        heapq.heappush(right_pos,query[1])
    if left_cnt+1<=(cnt+1)//2<=left_cnt+cnts[median]:
      continue
    elif left_cnt+1>(cnt+1)//2:
      heapq.heappush(right_pos,median)
      right_cnt+=cnts[median]
      right_sum+=median*cnts[median]
      median=-heapq.heappop(left_pos)
      left_cnt-=cnts[median]
      left_sum-=median*cnts[median]
    elif (cnt+1)//2>left_cnt+cnts[median]:
      heapq.heappush(left_pos,-median)
      left_cnt+=cnts[median]
      left_sum+=median*cnts[median]
      median=heapq.heappop(right_pos)
      right_cnt-=cnts[median]
      right_sum-=median*cnts[median]
  elif query[0]==2:
    value=b
    if left_cnt!=0:
      value+=abs(left_sum-median*left_cnt)
    if right_cnt!=0:
      value+=abs(right_sum-median*right_cnt)
    print(median,value)

Q = int(input())
qs = [tuple(map(int,input().split())) for i in range(Q)]

import heapq
class Heapq:
    def __init__(self, arr, desc=False):
        if desc:
            arr = [-a for a in arr]
        self.sign = -1 if desc else 1
        self.hq = arr
        heapq.heapify(self.hq)

    def pop(self):
        return heapq.heappop(self.hq) * self.sign

    def push(self, a):
        heapq.heappush(self.hq, a * self.sign)

    def top(self):
        return self.hq[0] * self.sign

lq = Heapq([],True)
rq = Heapq([])
ans = 0

for q in qs:
    if q[0] == 2:
        print(lq.top(), ans)
        continue
    _,a,b = q
    ans += b
    lq.push(a)
    rq.push(a)
    if lq.top() > rq.top():
        l = lq.pop()
        r = rq.pop()
        ans += abs(l-r)
        lq.push(r)
        rq.push(l)

def main():
	def Technique_often_used():    
		# enumerate: for i, a in enumerate(a_list):
		# q, mod = divmod(a, b)
		# Functional Programming: filter, map, reduce
		pass
	def naming_conventions():
		# [s_1, s_2, s_3, ..., s_k] is named s_k
		# [[s_11, s_12, ..., s_1k], ..,[s_j1, s_j2, ..., s_jk] is named s_jk
		# [[b1,c1],[b2,c2],..,[bm,cm]] is named bc
		# if there is something strange in a list then I add _ to the list's name (ex:s_jk_)
		pass
	def visual_studio_code_shortcut():    
		# visual studio code shortcut https://qiita.com/TakahiRoyte/items/cdab6fca64da386a690b
		# delete line: Ctrl+Shift+k
		# choose same words: Ctrl+Shift+l
		pass
	import sys
	from itertools import combinations, permutations # https://docs.python.org/ja/3/library/itertools.html
	from collections import deque, Counter # https://docs.python.org/ja/3/library/collections.html#collections.deque
	from heapq import heapify, heappop, heappush, heappushpop, heapreplace,nlargest,nsmallest # https://docs.python.org/ja/3/library/heapq.html
	from copy import deepcopy, copy # https://docs.python.org/ja/3/library/copy.html
	from functools import reduce
	from fractions import gcd # Deprecated since version 3.5: Use math.gcd() instead.
	def gcds(numbers):
		return reduce(gcd, numbers)
	def lcm(x, y):
		return (x * y) // gcd(x, y)
	def lcms(numbers): #
		return reduce(lcm, numbers, 1)

	# set the inputs
		# open(0).read() is a convenient method: 
		# ex) n, m, *x = map(int, open(0).read().split())
		#     min(x[::2]) - max(x[1::2])
		# ex2) *x, = map(int, open(0).read().split())
		#     don't forget to add comma after *x if only one variable is used
		# ex1) n, k = R()
		# ex2) v = list(R())
		# ex3) bc = [list(R()) for i in range(m)]

	R = lambda: map(int, input().split())
	q = int(input())
	queries = [list(R()) for i in range(q)]

	# q = 4
	# queries=[[1,4,2],[1,5,3],[1,-9,5],[1,1,-8],[2]]

	l = []
	r = []
	ans = 0
	for query in queries:
		if query[0] == 1:
			a = heappushpop(l,-query[1])
			b = heappushpop(r, query[1])
			heappush(l,-b)
			heappush(r,-a)
			ans += abs(b+a) + query[2]
		else:
			print(-l[0],ans)

def __starting_point():
    main()
__starting_point()

import heapq

Q = int(input())
m = L = R = 0
l, r = [], []
n = 0
b = 0

for i in range(Q):
  query = list(map(int, input().split()))
  if len(query) == 3: # 更新クエリ
    b += query[2]
    new = query[1]
    if  n == 0:
      m = new
    elif n == 1:
      if new <= m:
        heapq.heappush(l, -new)
        heapq.heappush(r, m)
        L, R = new, m
        m = new
      else:
        heapq.heappush(l, -m)
        heapq.heappush(r, new)
        L, R = m, new
    elif n == 2:
      if new < m:
        m = -heapq.heappop(l)
        heapq.heappush(l, -new)
        L = new
      else:
        _r = heapq.heappop(r)
        if new < _r:
          m = new
          heapq.heappush(r, _r)
        else:
          m = _r
          heapq.heappush(r, new)
          R = new
    else:
      _l = - heapq.heappop(l)
      _r = heapq.heappop(r)
      if n%2:
        if new <= _l:
          heapq.heappush(l, -new)
          heapq.heappush(r, _r)
          heapq.heappush(r, m)
          m, L, R = _l, L+new, R+m
        elif new <= m:
          heapq.heappush(l, -_l)
          heapq.heappush(r, _r)
          heapq.heappush(r, m)
          m, L, R = new, L+new, R+m
        else:
          heapq.heappush(l, -_l)
          heapq.heappush(r, _r)
          heapq.heappush(r, new)
          L, R = L+m, R+new
      else:
        if new <= m:
          heapq.heappush(l, -_l)
          heapq.heappush(l, -new)
          heapq.heappush(r, _r)
          L += new - m
        elif new <= _r:
          heapq.heappush(l, -_l)
          heapq.heappush(l, -m)
          heapq.heappush(r, _r)
          m = new
        else:
          heapq.heappush(l, -_l)
          heapq.heappush(l, -m)
          heapq.heappush(r, new)
          m, R = _r, R+new-_r
    n += 1
  else: # 求値クエリ
    print(m, R-L+b)

from heapq import heappush,heappop
def main():
    Q=int(input())

    ab_list=[]
    query_type=[]

    for i in range(Q):
        query=list(map(int,input().split()))
        query_type.append(query[0])
        if query[0]==1:
            ab_list.append((query[1],query[2]))

    #query_type->[1,1,2,1,2]
    #ab_list->[(a,b),(a,b),(a,b)]

    L=[]
    R=[]

    ini=0

    counter=0
    ab_pointer=0
    minF=0
    for i in query_type:
        if i==1:
            a_new=ab_list[ab_pointer][0]
            b_new=ab_list[ab_pointer][1]
            heappush(L,-1*a_new)
            heappush(R,a_new)
            Lmax=-1*heappop(L)
            Rmin=heappop(R)
            if Lmax<=Rmin:
                heappush(L,-1*Lmax)
                heappush(R,Rmin)
            else:
                heappush(L,-1*Rmin)
                heappush(R,Lmax)
            delta=abs(Lmax-Rmin)
            minF+=delta+b_new
            ab_pointer+=1
        else:
            minX=-1*heappop(L)
            print((str(minX)+" "+str(minF)))
            heappush(L,-1*minX)



def __starting_point():
    main()




__starting_point()

import heapq
Q = int(input())
qs = [tuple(map(int,input().split())) for i in range(Q)]

lq = []
rq = []
heapq.heapify(lq)
heapq.heapify(rq)
ans = 0

for q in qs:
    if q[0] == 2:
        print(-lq[0], ans)
        continue
    _,a,b = q
    ans += b
    heapq.heappush(lq, -a)
    heapq.heappush(rq, a)
    if -lq[0] > rq[0]:
        l = -heapq.heappop(lq)
        r = heapq.heappop(rq)
        ans += abs(l-r)
        heapq.heappush(lq,-r)
        heapq.heappush(rq,l)

from heapq import*
L,R=[],[]
n=int(input())
B=0
cnt=0
l,r=0,0
for i in range(n):
    I=input()
    if I[0]=="1":
        a,b,c=map(int,I.split())
        B+=c
        cnt+=1
        
        if cnt%2:
            x=heappushpop(R,b)
            r+=b-x
            heappush(L,-x)
            l+=-x
        else:
            x=heappushpop(L,-b)
            l+=-b-x
            heappush(R,-x)
            r+=-x
        #print(L,R,l,r)
        #print(b,x)
    else:
        med=-L[0]
#        print(L,R)
#        print(l,r)
        print(med,cnt%2*med+B+l+r)

from heapq import heappop,heappush
l = []
r = []
Q = int(input())
ans = 0
l_s = 0
r_s = 0
_,m,b = map(int,input().split())
ans += b
n = 0
for i in range(1,Q):
    s = input()
    if s != '2':
        _,a,b = map(int,s.split())
        ans += b
        if n == 0:
            c,d = sorted([m,a])
            heappush(l,-c)
            heappush(r,d)
            l_s += c
            r_s += d
            m1 = c
        else:
            c,d = heappop(l),heappop(r)
            l_s += c
            r_s -= d
            c = -c
            if n%2 == 1:
                c,m,d = sorted([a,c,d])
                heappush(l,-c)
                heappush(r,d)
                l_s += c
                r_s += d
            else:
                c,m1,m2,d = sorted([m,a,c,d])
                heappush(l,-c)
                heappush(l,-m1)
                heappush(r,d)
                heappush(r,m2)
                l_s += c
                r_s += d
                l_s += m1
                r_s += m2
        n += 1
    else:
        if n == 0:
            print('{} {}'.format(m,ans))
        elif n == 1:
            print('{} {}'.format(m1,r_s-l_s+ans))
        elif n%2 == 0:
            print('{} {}'.format(m,r_s-l_s+ans))
        else:
            print('{} {}'.format(m1,r_s-l_s+ans))

from itertools import zip_longest
from heapq import heappush, heappop

# 入力
Q = int(input())

q, a, b = (
    zip_longest(*(list(map(int, input().split())) for _ in range(Q))) if Q else
    ((), ())
)

INF = 10**18
L = []
R = []
heappush(L, INF)
heappush(R, INF)
S = 0
res = []

for i, A, B in zip(q, a, b):
    if i == 1:
        S += B
        if len(L) == len(R):
            if A < -L[0]:
                S += -L[0] - A
                heappush(L, -A)
            elif A <= R[0]:
                heappush(L, -A)
            else:
                S += A - R[0]
                t = heappop(R)
                heappush(L, -t)
                heappush(R, A)
        else:
            if A < -L[0]:
                S += -L[0] - A
                t = -heappop(L)
                heappush(R, t)
                heappush(L, -A)
            else:
                S += A - (-L[0])
                heappush(R, A)
    else:
        res.append((-L[0], S))

ans = '\n'.join(
    ' '.join(map(str, r))
    for r in res
)

# 出力
print(ans)


# -*- coding: utf-8 -*-
"""
Created on Tue May 28 22:22:21 2019

@author: Yamazaki Kenichi
"""
import heapq

Q = int(input())
Q2 = [input() for i in range(Q)]

ans = []
Al,Ar = [-(-(10**9+1))],[10**9+1]
B = 0
flg = False
for q in Q2:
    if q[0] == '1':
#        input
        d, a, b = list(map(int,q.split()))
        if not flg:
            heapq.heappush(Al,-a)
            B += b
            flg = True
            continue
        
#        C = abs(a - (-Al[0]))
        if len(Al) == len(Ar):
            if a < Ar[0]:
#                C = abs(a - (-Al[0]))
                heapq.heappush(Al,-a)
#                C = abs(a - (-Al[0]))
#            elif a < Ar[0]:
#                heapq.heappush(Al,-(heapq.heappop(Ar)))
#                heapq.heappush(Ar,a)
                C = abs(a - (-Al[0]))
            else:
                heapq.heappush(Ar,a)
                heapq.heappush(Al,-(heapq.heappop(Ar)))
                C = abs(a - (-Al[0]))
        else:
            if a < Ar[0]:
                C = abs(a - (-Al[0]))
                heapq.heappush(Al,-a)
                heapq.heappush(Ar,-(heapq.heappop(Al)))
#                C = abs(a - (-Al[0]))
#            elif a < A[]
            else:
                C = abs(a - (-Al[0]))
                heapq.heappush(Ar,a)
#                C = abs(a - (-Al[0]))
        B += (b + C)
#        print(Al,Ar,a,B,b)
    else:
#        output
        ans.append([(-Al[0]),B])
        
for c in ans:
    print((' '.join(map(str,c))))



import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    k=int(input())
    score=0
    B=0

    from heapq import heappush,heappop
    q=[] # 小さいほうの最大をとる→マイナスにして入れる
    Q=[] # 大きいほうの最小をとる

    for _ in range(k):
        s=input()
        if(s[0]=='1'):
            s,a,b=map(int,s.split())
            heappush(q,-a)
            heappush(Q,a)
            B+=b
            # 大小関係が逆転しているかを判断する
            t=-q[0]; T=Q[0]
            if(t>T):
                score+=t-T
                heappop(q); heappop(Q)
                heappush(q,-T); heappush(Q,t)
        else:
            print(-q[0],score+B)
resolve()

import heapq
Q=int(input())

alist=[]
hq_left,hq_right=[],[]
dummy,a1,b1=map(int,input().split())
heapq.heappush(hq_left,-a1)
heapq.heappush(hq_right,a1)
b=b1

min_arg=-hq_left[0]
min_diff=0
#min_value=b      
for _ in range(Q-1):
  query=list(map(int,input().split()))
  if len(query)==3:    
    dummy,ai,bi=query
    b+=bi
    
    max_left=-hq_left[0]
    min_right=hq_right[0]
    if ai<max_left:
      heapq.heappush(hq_left,-ai)
      heapq.heappush(hq_left,-ai)
      heapq.heappop(hq_left)
      heapq.heappush(hq_right,max_left)      
      min_diff+=max_left-ai
    elif min_right<ai:
      heapq.heappush(hq_right,ai)
      heapq.heappush(hq_right,ai)
      heapq.heappop(hq_right)
      heapq.heappush(hq_left,-min_right)      
      min_diff+=ai-min_right
    else:
      heapq.heappush(hq_left,-ai)
      heapq.heappush(hq_right,ai)      
  else:    
    min_arg=-hq_left[0]
    min_value=min_diff+b
    print(min_arg,min_value)

from heapq import heappop,heappush
q=int(input())
queries=[list(map(int,input().split()))for _ in range(q)]
l=[]
r=[]
ans=0
quecount=0
for query in queries:
  if query[0]==1:
    quecount+=1
    _,a,b=query
    ans+=b
    if quecount==1:
      mid=a
    elif quecount%2==1:
      if a<-l[0]:
        mid=-heappop(l)
        heappush(l,-a)
      elif r[0]<a:
        mid=heappop(r)
        heappush(r,a)
      else:
        mid=a
      ans+=abs(a-mid)
    else:
      ans+=abs(a-mid)
      heappush(l,-min(a,mid))
      heappush(r,max(a,mid))
  if query[0]==2:
    if quecount%2==1:
      ansind=mid
    else:
      ansind=-l[0]
    print(ansind,ans)

import sys
input = sys.stdin.readline
import heapq

def main():
  less = []
  greater = []
  s = 0
  sum_ = 0
  q = int(input())
  def query(n):
    nonlocal s, sum_
    if n[0] == "1":
      c, a, b = map(int, n.split())
      s += b
      if len(less) == len(greater):
        if not greater or a <= greater[0]:
          heapq.heappush(less, -a)
          sum_ -= a
        else:
          r = heapq.heappushpop(greater, a)
          heapq.heappush(less, -r)
          sum_ += a - 2*r
      else:
        if a >= -less[0]:
          heapq.heappush(greater, a)
          sum_ += a
        else:
          r = -heapq.heappushpop(less, -a)
          heapq.heappush(greater, r)
          sum_ += 2*r - a
    else:
      res = sum_
      if len(less) > len(greater):
        res -= less[0]
      res += s
      print(-less[0], res)

  for _ in range(q):
    k = input()
    query(k)
    
def __starting_point():
  main()
__starting_point()

"""
言い換えると次のことをすればよい
初期値をl = [], s = 0 として
'1 a b': lにaを追加、sにbを足す
'2': 中央値のインデックスより大きい要素の和-～～より小さい要素の和+sを出力
(要素が仮に昇順にソートされているなら、要素数をkとして、
sum(l[(k+1)//2:]) - sum(l[:k//2]) + s　を出力、xとしてはl[(k-1)//2]を出力
"""
import heapq

less = []
greater = []
s = 0
sum_ = 0
q = int(input())
def query(n):
  nonlocal s, sum_
  if n[0] == "1":
    c, a, b = map(int, n.split())
    s += b
    if len(less) == len(greater):
      if not greater or a <= greater[0]:
        heapq.heappush(less, -a)
        sum_ -= a
      else:
        r = heapq.heappushpop(greater, a)
        heapq.heappush(less, -r)
        sum_ += a - 2*r
    else:
      if a >= -less[0]:
        heapq.heappush(greater, a)
        sum_ += a
      else:
        r = -heapq.heappushpop(less, -a)
        heapq.heappush(greater, r)
        sum_ += 2*r - a
  else:
    res = sum_
    if len(less) > len(greater):
      res -= less[0]
    res += s
    print(-less[0], res)
    
for _ in range(q):
  k = input()
  query(k)

import heapq
q=int(input())
L=[]
R=[]
heapq.heapify(L)
heapq.heapify(R)
fx=0
for i in range(q):
  Q=list(map(int,input().split()))
  if Q[0]==1:
    a,b=Q[1],Q[2]
    heapq.heappush(L,-a)
    heapq.heappush(R,a)
    l=-heapq.heappop(L)
    r=heapq.heappop(R)
    if l==a and r==a:
      heapq.heappush(L,-l)
      heapq.heappush(R,r)
    else:
      fx+=abs(r-l)
      heapq.heappush(L,-r)
      heapq.heappush(R,l)
    x=-L[0]
    fx+=b
  else:
    print(x,fx)