You are given a function f(x), initially f(x) = 0. Process Q queries in order: update queries and evaluation queries. An update query 1 a b: g(x) = f(x) + |x - a| + b, replace f(x) with g(x). An evaluation query 2: Print x that minimizes f(x) and the minimum value of f(x). All input values are integers. 1 ≤ Q ≤ 2 × 10^5, -10^9 ≤ a, b ≤ 10^9. Input format: Q, Query_1, ..., Query_Q. Output: For each evaluation query, print the minimum value of x that minimizes f(x) and the minimum value of f(x).

# Buggy version:
q = int(input())
ans = [0, 0]
import heapq
p1 = []
p2 = []
heapq.heapify(p1)
heapq.heapify(p2)
sum_b = 0
sum_p1 = 0
sum_p2 = 0
for _ in range(q):
    ql = list(map(int,input().split()))
    if ql[0] == 2:
        print(p1[0], sum_p1 - len(p1) * p1[0] + len(p2) * p1[0] - sum_p2 + sum_b)
    else:
        sum_b += ql[2]
        if len(p1) == 0:
            heapq.heappush(p1, ql[1])
            sum_p1 += ql[1]
        elif p1[0] <= ql[1]:
            heapq.heappush(p1, ql[1])
            sum_p1 += ql[1]
        else:
            heapq.heappush(p2, -ql[1])
            sum_p2 += ql[1]
        if len(p1) < len(p2):
            k = heapq.heappop(p2)
            heapq.heappush(p1, -k)
            sum_p2 -= k
            sum_p1 += k
        if len(p1) - 1 > len(p2):
            k = heapq.heappop(p1)
            heapq.heappush(p2, -k)
            sum_p1 -= k
            sum_p2 += k



# Fixed version:
q = int(input())
ans = [0, 0]
import heapq
p1 = []
p2 = []
heapq.heapify(p1)
heapq.heapify(p2)
sum_b = 0
sum_p1 = 0
sum_p2 = 0
for _ in range(q):
    ql = list(map(int,input().split()))
    if ql[0] == 2:
        if len(p1) == len(p2):
            print(-p2[0], sum_p1 - len(p1) * -p2[0] + len(p2) * -p2[0] - sum_p2 + sum_b)
        else:
            print(p1[0], sum_p1 - len(p1) * p1[0] + len(p2) * p1[0] - sum_p2 + sum_b)
    else:
        sum_b += ql[2]
        if len(p1) == 0:
            heapq.heappush(p1, ql[1])
            sum_p1 += ql[1]
        elif p1[0] <= ql[1]:
            heapq.heappush(p1, ql[1])
            sum_p1 += ql[1]
        else:
            heapq.heappush(p2, -ql[1])
            sum_p2 += ql[1]
        if len(p1) < len(p2):
            k = heapq.heappop(p2)
            heapq.heappush(p1, -k)
            sum_p2 += k
            sum_p1 -= k
        if len(p1) - 1 > len(p2):
            k = heapq.heappop(p1)
            heapq.heappush(p2, -k)
            sum_p1 -= k
            sum_p2 += k

# Buggy version:
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(roght)
            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(right[0], minval)

# Fixed version:
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)

# Buggy version:
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])
        print(a, b)
        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))


# Fixed version:
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))

# Buggy version:
from heapq import heappush, heappushpop

Q = int(input())

b = 0
la = []
sl = 0
ra = []
sr = 0

cnt = 0
for _ in range(Q):
    q = map(int, input().split())
    # print(la, ra)
    if q[0] == 2:
        # 求値
        x = -la[0]
        cl = (cnt + 1) // 2
        cr = cnt - cl
        print(x, (cl * x - sl) + (sr - cr * x) + b)
    else:
        # 更新
        b += q[2]
        cnt += 1
        if cnt % 2 == 1:
            sr += q[1]
            x = heappushpop(ra, q[1])
            sr -= x
            sl += x
            heappush(la, -x)
        else:
            sl += q[1]
            x = heappushpop(la, -q[1])
            x *= -1
            sl -= x
            sr += x
            heappush(ra, x)


# Fixed version:
from heapq import heappop, heappush, heappushpop

Q = int(input())

b = 0
la = []
sl = 0
ra = []
sr = 0

cnt = 0
for _ in range(Q):
    q = input().split()
    # print(la, ra)
    if q[0] == '2':
        # 求値
        x = -la[0]
        print(x, ((cnt + 1) // 2 * x - sl) + (sr - cnt // 2 * x) + b)
    else:
        # 更新
        x, y = map(int, q[1:])
        b += y
        cnt += 1
        if cnt % 2 == 1:
            sr += x
            x = heappushpop(ra, x)
            sr -= x
            sl += x
            heappush(la, -x)
        else:
            sl += x
            x = heappushpop(la, -x)
            x *= -1
            sl -= x
            sr += x
            heappush(ra, x)

# Buggy version:
import heapq

Q = int(input())
B = 0

q, a, b = map(int, input().split())
L, R = [-a], [a]
L_sum, R_sum = a, a
B = b

for i in range(Q - 1):
    q = list(map(int, input().split()))
    if len(q) == 3:
        print(L, R)
        A = q[1]
        B += q[2]

        if A <= -L[0]:
            heapq.heappush(L, -A)
            M = -heapq.heappushpop(L, -A)
            heapq.heappush(R, M)

            L_sum += (2 * A - M)
            R_sum += M
        else:
            heapq.heappush(R, A)
            M = heapq.heappushpop(R, A)
            heapq.heappush(L, -A)

            R_sum += (2 * A - M)
            L_sum += M
    else:
        N = len(L)
        X = -L[0]
        print(X, (abs(L_sum - X * N) + abs(R_sum - X * N)) // 2 + B)


# Fixed version:
import heapq
import sys

inp = sys.stdin.readline

Q = int(input())
B = 0

q, a, b = map(int, inp().split())
L, R = [-a], [a]
L_sum, R_sum = a, a
B = b

for i in range(Q - 1):
    q = list(map(int, inp().split()))
    if len(q) == 3:
        A = q[1]
        B += q[2]

        if A <= -L[0]:
            heapq.heappush(L, -A)
            M = -heapq.heappushpop(L, -A)
            heapq.heappush(R, M)

            L_sum += (2 * A - M)
            R_sum += M
        else:
            heapq.heappush(R, A)
            M = heapq.heappushpop(R, A)
            heapq.heappush(L, -M)

            R_sum += (2 * A - M)
            L_sum += M
    else:
        N = len(L)
        X = -L[0]
        print(X, (abs(L_sum - X * N) + abs(R_sum - X * N)) // 2 + B)

# Buggy version:

import heapq as hq

Q = int(input())



low = []
high = []

_,mid,val = map(int,input().split())

for _ in range(Q-1):
    s = input()
    if s[0] == '1':
        _,a,b = map(int,s.split())
        if mid is None:
            if a < -low[0]:
                mid = hq.heapreplace(low, -a)
            elif a > high[0]:
                mid = hq.heapreplace(high, a)
            else:
                mid = a
            val += abs(mid-a)+b
        else:
            val += abs(mid-a)+b
            x,y = sorted((a,mid))
            hq.heappush(high, y)
            hq.heappush(low, -x)
            mid = None

    else:
        print(high[0] if mid is None else mid, val)

# Fixed version:

import heapq as hq

Q = int(input())



low = []
high = []

_,mid,val = map(int,input().split())

for _ in range(Q-1):
    s = input()
    if s[0] == '1':
        _,a,b = map(int,s.split())
        if mid is None:
            if a < -low[0]:
                mid = -hq.heapreplace(low, -a)
            elif a > high[0]:
                mid = hq.heapreplace(high, a)
            else:
                mid = a
            val += abs(mid-a)+b
        else:
            val += abs(mid-a)+b
            x,y = sorted((a,mid))
            hq.heappush(high, y)
            hq.heappush(low, -x)
            mid = None

    else:
        print(-low[0] if mid is None else mid, val)

# Buggy version:
# -*- coding: utf-8 -*-
from heapq import heappush, heappop

qn = int(input())

low = []
high = []
ans = 0
num = 0

for i in range(qn):
    q = [int(i) for i in input().split()]
    if q[0] == 1:
        ans += q[2]
        a = q[1]
        # lowは降順に並べたいので-aを入れる
        heappush(low, -a)
        heappush(high, a)
        if -low[0] > high[0]:
            low0 = heappop(low)
            high0 = heappop(high)
            # lowとhighで正負が逆なので注意する
            heappush(low, -high0)
            heappush(high, -low0)
            ans += high[0] + low[0]
    if q[0] == 2:
        print(high[0], ans)

print(high)


# Fixed version:
# -*- coding: utf-8 -*-
from heapq import heappush, heappop

qn = int(input())

low = []
high = []
ans = 0

for i in range(qn):
    q = [int(i) for i in input().split()]
    if q[0] == 1:
        ans += q[2]
        a = q[1]

        if len(low) >= 1:
            if a < -low[0]:
                ans += -low[0] - a
            elif a > high[0]:
                ans += a - high[0]

        # lowは降順に並べたいので-aを入れる
        heappush(low, -a)
        heappush(high, a)
        if -low[0] > high[0]:
            low0 = heappop(low)
            high0 = heappop(high)
            # lowとhighで正負が逆なので注意する
            heappush(low, -high0)
            heappush(high, -low0)

    elif q[0] == 2:
        print(-low[0], ans)

# Buggy version:
from heapq import heappush, heappop, heappushpop
def inpl(): return list(map(int, input().split()))

Q = int(input())
L = []
R = []

B = 0
M = 0

for _ in range(Q):
    q = inpl()
    if len(q) == 3:
        B += q[2]
        if len(R) == 0:
            L.append(-q[1])
            R.append(q[1])
            continue

        M += min(abs(-L[0] - q[1]), abs(R[0] - q[1])) * (not (-L[0] <= q[1] <= R[0]))
        if q[1] < R[0]:
            heappush(L, -q[1])
            heappush(R, -heappushpop(L, -q[1]))
        else:
            heappush(R, q[1])
            heappush(L, -heappushpop(R, Q[1]))
    else:
        print(-L[0], B+M)

# Fixed version:
from heapq import heappush, heappop
def inpl(): return list(map(int, input().split()))

Q = int(input())
L = []
R = []

B = 0
M = 0

for _ in range(Q):
    q = inpl()
    if len(q) == 3:
        B += q[2]
        if len(R) == 0:
            L.append(-q[1])
            R.append(q[1])
            continue

        M += min(abs(-L[0] - q[1]), abs(R[0] - q[1])) * (not (-L[0] <= q[1] <= R[0]))
        if q[1] < R[0]:
            heappush(L, -q[1])
            heappush(L, -q[1])
            heappush(R, -heappop(L))
        else:
            heappush(R, q[1])
            heappush(R, q[1])
            heappush(L, -heappop(R))
    else:
        print(-L[0], B+M)

# Buggy version:
import bisect
import heapq

Q=int(input())

que=list(map(int,input().split()))
b=que[2]
a=[que[1]]
l,r=[-que[1]],[que[1]]
min=0
j=1
tmp=que[1]
for i in range(Q-1):
    que=list(map(int,input().split()))
    if que[0]==1:
        j+=1
        b+=que[2]
        tmp=-l[0]
        if j%2==0:
            if que[1]<=-l[0]:
                heapq.heappushpop(l,-que[1])
            else:
                heapq.heappushpop(l,que[1])

        else:
            if que[1]<=-l[0]:
                heapq.heappush(r, -heapq.heappushpop(l,-que[1]))
            else:
                heapq.heappush(l, -heapq.heappushpop(r,que[1]))
        
        if -l[0]!=r[0]: min+=abs(tmp-que[1])
        else: min+=abs(tmp-que[1])-abs(l[0]-tmp)
        tmp=-l[0]

    elif que[0]==2:
        print(tmp,min+b)

# Fixed version:
import bisect
import heapq 

Q=int(input())

que=list(map(int,input().split()))
b=que[2]
l,r=[-que[1]],[que[1]]
heapq.heapify(l)
heapq.heapify(r)
a=0
tmp=que[1]
j=1
for i in range(Q-1):
    que=list(map(int,input().split()))
    if que[0]==1:
        j+=1
        b+=que[2]
        q1=que[1]
        if j%2==0:
            if q1<-l[0]:
                heapq.heappushpop(l,-q1)
            else:
                heapq.heappushpop(r,q1)

        else:
            if q1<-l[0]:
                heapq.heappush(l,-q1)
                heapq.heappush(r,-l[0])
            else:
                heapq.heappush(r,q1)
                heapq.heappush(l,-r[0])
        

        if -l[0]!=r[0]: a+=abs(tmp-q1)
        else: a+=abs(tmp-q1)-abs(-l[0]-tmp)
        tmp=-l[0]

    elif que[0]==2:
        print(tmp,a+b)

# Buggy version:
from heapq import*
L,R=[]*2
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)

# Fixed version:
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:w=-L[0];print(w,B+w*t)

# Buggy version:
from heapq import *

Q = int(input())

lows = []
highs = []

a = []
b = 0
r = 0

for i in range(Q):
    vs = [int(_) for _ in input().split()]
    if vs[0] == 1:
        b = +vs[2]
        if not lows:
            heappush(lows, -vs[1])
        else:
            r += abs(vs[1] + lows[0])
            if vs[1] <= -lows[0]:
                heappush(lows, -vs[1])
            else:
                heappush(highs, vs[1])
        
        if len(lows) < len(highs):
            x = heappop(highs)
            y = -lows[0]
            r += y - x
            heappush(lows, -x)
            
        elif len(lows) > len(highs) + 1:
            x = -heappush(lows)
            if len(highs):
                y = highs[0]
            else:
                y = 0
            heappush(highs,x)
    else:
        print(-lows[0], r+b)

# Fixed version:
Q = int(input())

from heapq import *

lows = []
highs = []

a = []
b = 0
r = 0

for i in range(Q):
    vs = [int(_) for _ in input().split()]
    if vs[0] == 1:
        b += vs[2]
        if not lows:
            x = vs[1]
            heappush(lows, -x)
        else:
            r += abs(vs[1] + lows[0])
            if vs[1] <= -lows[0]:
                heappush(lows, -vs[1])
            else:
                heappush(highs, vs[1])

        if len(lows) < len(highs):
            x = heappop(highs)
            y = -lows[0]
            r += y - x
            heappush(lows, -x)
        elif len(lows) > len(highs) + 1:
            x = -heappop(lows)
            y = highs[0] if len(highs) else 0
            heappush(highs, x)
            # r += x - y

        # print("center", -lows[0], r, lows, highs)

    else:
        print(-lows[0], r + b)

# Buggy version:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

q = ni()

lh = []
hh = []
ln = 0
hn = 0
ls = 0
hs = 0
off = 0
for z in range(q):
    line = na()
    if line[0] == 1:
        _, a, b = line
        off += b

        if len(lh) > 0:
            mid = -lh[0]
            if a <= mid:
                heapq.heappush(lh, -a)
                ls += a
                ln += 1
            else:
                heapq.heappush(hh, a)
                hs += a
                hn += 1
        else:
            heapq.heappush(lh, -a)
            ls += a
            ln += 1

        while ln < hn:
            mx = heapq.heappop(hh)
            hs -= mx
            hn -= 1
            ls += mx
            ln += 1
            heapq.heappush(lh, -mx)

        while ln > hn + (ln+hn)%2:
            mx = -heapq.heappop(lh)
            ls -= mx
            ln -= 1
            heapq.heappush(hh, mx)
            hs += mx
            hn += 1
    else:
        lls = -lh[0]*ln - ls
        hhs = hs - (-lh[0]*hn)
        print(-lh[0], lls+hhs+off)

# Fixed version:
import sys
import heapq

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

q = ni()

lh = []
hh = []
ln = 0
hn = 0
ls = 0
hs = 0
off = 0
for z in range(q):
    line = na()
    if line[0] == 1:
        _, a, b = line
        off += b

        if len(lh) > 0:
            mid = -lh[0]
            if a <= mid:
                heapq.heappush(lh, -a)
                ls += a
                ln += 1
            else:
                heapq.heappush(hh, a)
                hs += a
                hn += 1
        else:
            heapq.heappush(lh, -a)
            ls += a
            ln += 1

        while ln < hn:
            mx = heapq.heappop(hh)
            hs -= mx
            hn -= 1
            ls += mx
            ln += 1
            heapq.heappush(lh, -mx)

        while ln > hn + (ln+hn)%2:
            mx = -heapq.heappop(lh)
            ls -= mx
            ln -= 1
            heapq.heappush(hh, mx)
            hs += mx
            hn += 1
    else:
        lls = -lh[0]*ln - ls
        hhs = hs - (-lh[0]*hn)
        print(-lh[0], lls+hhs+off)