AtCoder Beginner Contest 127 - Absolute Minima

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: MEDIUM_HARD

Starter code:

Solutions:
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]))


import heapq as hq
Q = int(input())
minval = 0
argminval = -10 ** 9
(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:
				hq.heappush(L, -1 * ai)
			else:
				hq.heappop(R)
				hq.heappush(L, -1 * RC)
				hq.heappush(R, ai)
			lenL += 1
			argminval = -1 * L[0]
			minval += abs(argminval - ai) + bi
		else:
			if ai < LC:
				hq.heappop(L)
				hq.heappush(L, -1 * ai)
				hq.heappush(R, LC)
			else:
				hq.heappush(R, ai)
			lenR += 1
			minval += abs(argminval - ai) + bi
			argminval = -1 * L[0]
	else:
		print('{} {}'.format(argminval, minval))


import heapq
Q = int(input())

def update(ans, a, b):
	heapq.heappush(lq, -a)
	heapq.heappush(rq, a)
	(lmax, rmin) = (-lq[0], rq[0])
	ans += b
	if lmax > rmin:
		(lmax, rmin) = (rmin, lmax)
		ans += rmin - lmax
		heapq.heappop(lq)
		heapq.heappop(rq)
		heapq.heappush(lq, -lmax)
		heapq.heappush(rq, rmin)
	return ans

def query():
	return str(-lq[0]) + ' ' + str(ans)
lq = []
rq = []
ans = 0
for i in range(Q):
	q = list(map(str, input().split()))
	if len(q) == 1:
		print(query())
	else:
		(one, a, b) = q
		ans = update(ans, int(a), int(b))


import heapq
import sys
sys.setrecursionlimit(10000)
INF = float('inf')
Q = int(next(sys.stdin))
smalls = []
larges = []
fmin = 0
prev_x = None
for _ in range(Q):
	q = list(map(int, next(sys.stdin).split()))
	if q[0] == 1:
		(a, b) = (q[1], q[2])
		if not larges or a > larges[0]:
			heapq.heappush(larges, a)
		else:
			heapq.heappush(smalls, -a)
		if len(larges) > len(smalls) + 1:
			heapq.heappush(smalls, -heapq.heappop(larges))
		elif len(smalls) > len(larges) + 1:
			heapq.heappush(larges, -heapq.heappop(smalls))
		if len(smalls) >= len(larges):
			x = -smalls[0]
		else:
			x = larges[0]
		fmin += abs(x - a) + b
		if x != prev_x:
			if prev_x is not None and len(smalls) == len(larges):
				fmin += abs(x - prev_x)
			prev_x = x
	else:
		if len(smalls) >= len(larges):
			x = -smalls[0]
		else:
			x = larges[0]
		print(x, fmin)


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
	elif 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))


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)


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]))
	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)
main()


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)


import sys
input = sys.stdin.readline
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


import sys, math, collections, heapq, itertools
from bisect import bisect_left
F = sys.stdin

def single_input():
	return F.readline().strip('\n')

def line_input():
	return F.readline().strip('\n').split()

def gcd(a, b):
	(a, b) = (max(a, b), min(a, b))
	while a % b > 0:
		(a, b) = (b, a % b)
	return b

def solve():
	Q = int(single_input())
	(n, a, b) = map(int, line_input())
	(left, right) = ([-a], [a])
	heapq.heapify(left)
	heapq.heapify(right)
	minans = b
	for i in range(1, Q):
		queri = [int(i) for i in line_input()]
		if queri[0] == 1:
			(a, b) = queri[1:]
			minans += b
			left_upper = -1 * heapq.heappop(left)
			right_lower = heapq.heappop(right)
			if left_upper <= a <= right_lower:
				heapq.heappush(left, -a)
				heapq.heappush(left, -1 * left_upper)
				heapq.heappush(right, a)
				heapq.heappush(right, right_lower)
			elif a < left_upper:
				minans += left_upper - a
				heapq.heappush(left, -a)
				heapq.heappush(left, -a)
				heapq.heappush(right, left_upper)
				heapq.heappush(right, right_lower)
			else:
				minans += a - right_lower
				heapq.heappush(left, -1 * left_upper)
				heapq.heappush(left, -1 * right_lower)
				heapq.heappush(right, a)
				heapq.heappush(right, a)
		else:
			left_lower = -1 * heapq.heappop(left)
			print(left_lower, minans)
			heapq.heappush(left, -1 * left_lower)
	return 0
solve()


import heapq
r = []
l = []
lsum = 0
rsum = 0
y = 0
cnt = 0
Q = int(input())
for _ in range(Q):
	row = input()
	if row == '2':
		x = -heapq.heappop(l)
		print(x, y + rsum - lsum + cnt % 2 * x)
		heapq.heappush(l, -x)
	else:
		row = list(map(int, row.split()))
		a = row[1]
		y += row[2]
		if cnt % 2 == 0:
			heapq.heappush(r, a)
			rsum += a
			_a = heapq.heappop(r)
			rsum -= _a
			heapq.heappush(l, -_a)
			lsum += _a
		else:
			heapq.heappush(l, -a)
			lsum += a
			_a = -heapq.heappop(l)
			lsum -= _a
			heapq.heappush(r, _a)
			rsum += _a
		cnt += 1


import heapq
Q = int(input())
(heapL, heapR) = ([], [])
s = 0
x = None
for i in range(Q):
	q = list(map(int, input().split()))
	if len(q) == 1:
		print(x, s)
	else:
		(_, a, b) = q
		s += b
		if not heapL:
			heapq.heappush(heapL, -a)
		elif not heapR:
			s += abs(a + heapL[0])
			heapq.heappush(heapR, -heapq.heappushpop(heapL, -a))
		elif len(heapL) > len(heapR):
			s += abs(a + heapL[0])
			heapq.heappush(heapR, -heapq.heappushpop(heapL, -a))
		else:
			heapq.heappush(heapL, -heapq.heappushpop(heapR, a))
			s += abs(a + heapL[0])
		x = -heapL[0]


q = int(input())
query = [input() for _ in range(q)]
from bisect import bisect_left
ary = [-float('inf')]
for qq in query:
	if qq[0] == '1':
		(_, a, _) = map(int, qq.split())
		ary.append(a)
ary.sort()
ary.append(float('inf'))

class BIT:

	def __init__(self, n):
		self.n = n
		self.data = [0] * (n + 1)
		self.el = [0] * (n + 1)

	def sum(self, i):
		s = 0
		while i > 0:
			s += self.data[i]
			i -= i & -i
		return s

	def add(self, i, x):
		self.el[i] += x
		while i <= self.n:
			self.data[i] += x
			i += i & -i

	def get(self, i, j=None):
		if j is None:
			return self.el[i]
		return self.sum(j) - self.sum(i)
(ml, mr) = (0, len(ary) + 1)
mv = 0
bit = BIT(len(ary) + 1)
for qq in query:
	if qq[0] == '2':
		print(ary[ml], mv)
	else:
		(_, a, b) = map(int, qq.split())
		a = bisect_left(ary, a)
		bit.add(1, -1)
		bit.add(a + 1, 2)
		if ml <= a < mr:
			mv += b
			(ml, mr) = (a, a + 1)
		else:
			(l, r) = (1, len(ary) + 2)
			while r - l > 1:
				x = (r + l) // 2
				if bit.sum(x) >= 0:
					(l, r) = (l, x)
				else:
					(l, r) = (x, r)
			mv += b
			mv += min(abs(ary[l] - ary[ml]), abs(ary[l] - ary[mr])) + abs(ary[l] - ary[a])
			ml = l
			(l, r) = (1, len(ary) + 2)
			while r - l > 1:
				x = (r + l) // 2
				if bit.sum(x) > 0:
					(l, r) = (l, x)
				else:
					(l, r) = (x, r)
			mr = l


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

def int_raw():
	return int(input())

def ss_raw():
	return input().split()

def ints_raw():
	return tuple(map(int, ss_raw()))

def main():
	Q = int(input())
	sb = 0
	lupper = []
	rlower = []
	s = 0
	for _ in range(Q):
		cmds = tuple(map(int, input().split()))
		if cmds[0] == 1:
			(_, a, b) = cmds
			sb += b
			if len(lupper) == 0 or a <= -lupper[0]:
				heappush(lupper, -a)
				s += -lupper[0] - a
				if len(lupper) - len(rlower) >= 2:
					heappush(rlower, -heappop(lupper))
			else:
				heappush(rlower, a)
				s += a + lupper[0]
				if len(rlower) > len(lupper):
					s += -lupper[0] - rlower[0]
					heappush(lupper, -heappop(rlower))
		else:
			print(-lupper[0], s + sb)
main()


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)]
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('{} {}'.format(median, minval))


import heapq
q = int(input())
l = []
r = []
ai = 0
bs = 0
for i in range(q):
	ipt = list(map(int, input().split()))
	if ipt[0] == 1:
		al = heapq.heappushpop(l, -ipt[1])
		ar = heapq.heappushpop(r, ipt[1])
		ai -= al + ar
		heapq.heappush(l, -ar)
		heapq.heappush(r, -al)
		bs += ipt[2]
	else:
		an = heapq.heappop(l)
		print(-an, bs + ai)
		heapq.heappush(l, an)


import heapq
q = int(input())
minheap = []
maxheap = []
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))


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 heappush, heappop
upper_asc = []
lower_dsc = []
q = ni()
ans = 0
for i in range(q):
	query = list(map(int, ns().split()))
	if query[0] == 1:
		(a, b) = (query[1], query[2])
		heappush(upper_asc, a)
		heappush(lower_dsc, -a)
		if i == 0:
			ans += b
			continue
		(x, y) = (heappop(upper_asc), -heappop(lower_dsc))
		ans += y - x + b
		heappush(upper_asc, y)
		heappush(lower_dsc, -x)
	else:
		print(-lower_dsc[0], ans)


import heapq
import sys
input = sys.stdin.readline

def main():
	q = int(input())
	res = 0
	x = list(map(int, input().split()))
	a = x[1]
	res += x[2]
	asmall = [a * -1]
	alarge = [a]
	heapq.heapify(asmall)
	heapq.heapify(alarge)
	r1 = a
	r2 = a
	for _ in range(q - 1):
		x = list(map(int, input().split()))
		if x[0] == 1:
			a = x[1]
			res += x[2]
			if r1 <= a and a <= r2:
				pass
			else:
				res += min(abs(a - r1), abs(a - r2))
			mid1 = asmall[0] * -1
			if mid1 > a:
				heapq.heappush(alarge, heapq.heappop(asmall) * -1)
				heapq.heappush(asmall, -a)
				heapq.heappush(asmall, -a)
			else:
				mid2 = alarge[0]
				if mid2 >= a:
					heapq.heappush(asmall, -a)
					heapq.heappush(alarge, a)
				else:
					heapq.heappush(asmall, heapq.heappop(alarge) * -1)
					heapq.heappush(alarge, a)
					heapq.heappush(alarge, a)
			r1 = asmall[0] * -1
			r2 = alarge[0]
		if x[0] == 2:
			print(str(r1) + ' ' + str(res))
main()


from heapq import *

class median_tree(object):

	def __init__(self):
		self.lower_than_med = []
		self.higher_than_med = []
		self.count = 0
		self.low = 0
		self.high = 0
		self.median = 0

	def push(self, x):
		self.count = 1 - self.count
		if self.count:
			y = heappushpop(self.higher_than_med, x)
			heappush(self.lower_than_med, -y)
			self.low += -y
			self.high += x - y
		else:
			y = heappushpop(self.lower_than_med, -x)
			heappush(self.higher_than_med, -y)
			self.low -= x + y
			self.high -= y
		self.median = -self.lower_than_med[0]
from heapq import *
n = int(input())
m = median_tree()
B = 0
for i in range(n):
	I = input()
	if I[0] == '1':
		(a, b, c) = map(int, I.split())
		B += c
		m.push(b)
	else:
		print(m.median, m.count % 2 * m.median + B + m.low + m.high)


import heapq

class PriorityQueue:

	def __init__(self):
		self.__heap = []
		self.__count = 0

	def empty(self) -> bool:
		return self.__count == 0

	def dequeue(self):
		if self.empty():
			raise Exception('empty')
		self.__count -= 1
		return heapq.heappop(self.__heap)

	def enqueue(self, v):
		self.__count += 1
		heapq.heappush(self.__heap, v)

	def __len__(self):
		return self.__count

def absolute_minima():
	Q = int(input())
	(L, R) = (PriorityQueue(), PriorityQueue())
	(sL, sR) = (0, 0)
	M = None
	B = 0
	N = 0
	for _ in range(Q):
		query = [int(s) for s in input().split()]
		if query[0] == 1:
			(_, a, b) = query
			B += b
			N += 1
			if M is None:
				M = a
			elif M < a:
				R.enqueue(a)
				sR += a
			else:
				L.enqueue(-a)
				sL += a
			while len(R) - len(L) > 1:
				L.enqueue(-M)
				sL += M
				M = R.dequeue()
				sR -= M
			while len(L) > len(R):
				R.enqueue(M)
				sR += M
				M = -L.dequeue()
				sL -= M
		else:
			s = -sL + sR + B
			if N % 2 == 0:
				s -= M
			print(M, s)
absolute_minima()


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
		elif 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)
main()


import sys
input = sys.stdin.readline
Q = int(input())
Y = []
D = []
S = [0] * Q
s = 0
for i in range(Q):
	a = list(map(int, input().split()))
	Y.append(a)
	if a[0] == 1:
		D.append(a[1])
		s += a[2]
	S[i] = s
D = sorted(list(set(D)))
INV = {}
for i in range(len(D)):
	INV[D[i]] = i
N = 17
X = [0] * (2 ** (N + 1) - 1)
C = [0] * (2 ** (N + 1) - 1)

def add(j, x):
	i = 2 ** N + j - 1
	while i >= 0:
		X[i] += x
		C[i] += 1
		i = (i - 1) // 2

def rangeof(i):
	s = len(bin(i + 1)) - 3
	l = (i + 1 - (1 << s)) * (1 << N - s)
	r = l + (1 << N - s)
	return (l, r)

def rangesum(a, b):
	l = a + (1 << N)
	r = b + (1 << N)
	s = 0
	while l < r:
		if l % 2:
			s += X[l - 1]
			l += 1
		if r % 2:
			r -= 1
			s += X[r - 1]
		l >>= 1
		r >>= 1
	return s

def rangecnt(a, b):
	l = a + (1 << N)
	r = b + (1 << N)
	s = 0
	while l < r:
		if l % 2:
			s += C[l - 1]
			l += 1
		if r % 2:
			r -= 1
			s += C[r - 1]
		l >>= 1
		r >>= 1
	return s
c = 0
su = 0
CC = [0] * 2 ** N
for i in range(Q):
	y = Y[i]
	if y[0] == 1:
		add(INV[y[1]], y[1])
		CC[INV[y[1]]] += 1
		c += 1
		su += y[1]
	else:
		(l, r) = (0, 2 ** N)
		while True:
			m = (l + r) // 2
			rc = rangecnt(0, m)
			if rc >= (c + 1) // 2:
				r = m
			elif rc + CC[m] <= (c - 1) // 2:
				l = m
			else:
				break
		rs = rangesum(0, m)
		print(D[m], D[m] * rc - rs + (su - rs) - (c - rc) * D[m] + S[i])


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
			elif 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)


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

def main():
	Q = int(input())
	y = 0
	lheap = []
	rheap = []
	lsum = 0
	rsum = 0
	for _ in range(Q):
		q = input()
		if q[0] == '1':
			(_, a, b) = map(int, q.split())
			y += b
			if len(lheap) == 0 or -lheap[0] <= a <= rheap[0]:
				heappush(lheap, -a)
				heappush(rheap, a)
				lsum += a
				rsum += a
			elif a < -lheap[0]:
				mov = -heappop(lheap)
				heappush(rheap, mov)
				heappush(lheap, -a)
				heappush(lheap, -a)
				lsum += a * 2 - mov
				rsum += mov
			elif rheap[0] < a:
				mov = heappop(rheap)
				heappush(lheap, -mov)
				heappush(rheap, a)
				heappush(rheap, a)
				lsum += mov
				rsum += a * 2 - mov
		else:
			x = -lheap[0]
			minimum = abs(x * len(lheap) - lsum) // 2 + abs(x * len(rheap) - rsum) // 2 + y
			print(x, minimum)
main()


import heapq
numQ = int(input())
bsum = 0
Lheap = []
Rheap = []
for loop in range(numQ):
	query = input()
	if query == '2':
		print(nx, fx + bsum)
	else:
		(query, newa, newb) = query.split()
		newa = int(newa)
		newb = int(newb)
		bsum += newb
		if loop == 0:
			nx = newa
			fx = 0
			heapq.heappush(Lheap, -1 * newa)
		else:
			fx += abs(nx - newa)
			if -1 * Lheap[0] > newa:
				heapq.heappush(Lheap, -1 * newa)
			else:
				heapq.heappush(Rheap, newa)
			while len(Lheap) > len(Rheap) + 1:
				temp = heapq.heappop(Lheap)
				heapq.heappush(Rheap, -1 * temp)
			while len(Rheap) > len(Lheap):
				temp = heapq.heappop(Rheap)
				heapq.heappush(Lheap, -1 * temp)
			ox = nx
			nx = -1 * Lheap[0]
			if nx < ox:
				fx += (ox - nx) * (len(Rheap) - len(Lheap))
			elif nx > ox:
				fx += (nx - ox) * (len(Lheap) - 1 - (len(Rheap) + 1))


class Bit:

	def __init__(self, n):
		self.size = n
		self.tree = [0] * (n + 1)

	def sum(self, i):
		s = 0
		while i > 0:
			s += self.tree[i]
			i -= i & -i
		return s

	def add(self, i, x):
		while i <= self.size:
			self.tree[i] += x
			i += i & -i

def bsearch(mn, mx, func):
	idx = (mx + mn) // 2
	while mx - mn > 1:
		if func(idx):
			(idx, mn) = ((idx + mx) // 2, idx)
			continue
		(idx, mx) = ((idx + mn) // 2, idx)
	return idx
import sys
input = sys.stdin.readline
(Q,) = map(int, input().split())
qs = []
c = 0
j = 0
for _ in range(Q):
	q = input().split()
	if len(q) == 1:
		c += 1
	else:
		(a, b) = (int(q[1]), int(q[2]))
		qs.append((a, b, c, j))
		c = 0
		j += 1
if c:
	qs.append((a, b, c, j))
m = j
qqs = sorted(qs, key=lambda x: x[0])
j2i = dict()
i2a = dict()
for (i, (a, b, c, j)) in enumerate(qqs):
	j2i[j] = i + 1
	i2a[i + 1] = a
m = len(j2i)
st = Bit(m)
st_sum = Bit(m)
asum = bsum = 0
for (a, b, c, i) in qs:
	if c:
		j = bsearch(0, m + 1, lambda x: st.sum(x) < ci)
		for _ in range(c):
			if not i % 2:
				print(i2a[j + 1], -2 * st_sum.sum(j + 1) + asum + bsum)
			else:
				print(i2a[j + 1], -st_sum.sum(j) + (asum - st_sum.sum(j + 1)) + bsum)
	asum += a
	bsum += b
	st.add(j2i[i], 1)
	st_sum.add(j2i[i], a)
	ci = -(-(i + 1) // 2)


from heapq import heappush, heappop
INF = 10 ** 18
sum_B = 0
(L, R) = ([INF], [INF])
sum_L = sum_R = 0
L_size = R_size = 0
A = map(int, open(0).read().split())
Q = next(A)
for _ in range(Q):
	q = next(A)
	if q == 1:
		(a, b) = (next(A), next(A))
		sum_B += b
		max_L = -heappop(L)
		min_R = heappop(R)
		sum_L -= max_L
		sum_R -= min_R
		(l, m, r) = sorted((max_L, a, min_R))
		heappush(L, -l)
		heappush(R, r)
		sum_L += l
		sum_R += r
		if L_size == R_size:
			heappush(L, -m)
			L_size += 1
			sum_L += m
		else:
			heappush(R, m)
			R_size += 1
			sum_R += m
	else:
		median = -L[0]
		min_value = sum_B + sum_R - sum_L
		if L_size != R_size:
			min_value += median
		print(median, min_value)


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
		elif 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]))


import heapq
import sys
buff_readline = sys.stdin.buffer.readline
readline = sys.stdin.readline
INF = 2 ** 62 - 1

def read_int():
	return int(buff_readline())

def read_int_n():
	return list(map(int, buff_readline().split()))

def read_float():
	return float(buff_readline())

def read_float_n():
	return list(map(float, buff_readline().split()))

def read_str():
	return readline().strip()

def read_str_n():
	return readline().strip().split()

def error_print(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time

	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		error_print(e - s, 'sec')
		return ret
	return wrap

def slv(Q):
	sb = 0
	l = []
	r = []
	sl = 0
	sr = 0
	for q in Q:
		if q[0] == 1:
			(_, a, b) = q
			heapq.heappush(l, -a)
			sl += a
			if len(l) > len(r) + 1:
				a = -heapq.heappop(l)
				heapq.heappush(r, a)
				sl -= a
				sr += a
			while l and r and (-l[0] > r[0]):
				a = -heapq.heappop(l)
				heapq.heappush(r, a)
				sl -= a
				sr += a
				a = heapq.heappop(r)
				heapq.heappush(l, -a)
				sl += a
				sr -= a
			sb += b
		else:
			x = -l[0]
			print(x, abs(sl - len(l) * x) + abs(sr - len(r) * x) + sb)

def main():
	N = read_int()
	Q = [read_int_n() for _ in range(N)]
	slv(Q)
main()


q = int(input())
query = [input() for _ in range(q)]
from bisect import bisect_left
ary = [-float('inf')]
for qq in query:
	if qq[0] == '1':
		(_, a, _) = map(int, qq.split())
		ary.append(a)
ary.sort()
ary.append(float('inf'))

class SegmentTree:

	def __init__(self, size, f=lambda x, y: x + y, default=0):
		self.size = pow(2, (size - 1).bit_length())
		self.f = f
		self.default = default
		self.data = [default] * (self.size * 2)

	def update(self, i, x):
		i += self.size
		self.data[i] = x
		while i:
			i >>= 1
			self.data[i] = self.f(self.data[i * 2], self.data[i * 2 + 1])

	def query(self, l, r):
		(l, r) = (l + self.size, r + self.size)
		(lret, rret) = (self.default, self.default)
		while l < r:
			if l & 1:
				lret = self.f(self.data[l], lret)
				l += 1
			if r & 1:
				r -= 1
				rret = self.f(self.data[r], rret)
			l >>= 1
			r >>= 1
		return self.f(lret, rret)

	def get(self, i):
		return self.data[self.size + i]

	def add(self, i, x):
		self.update(i, self.get(i) + x)
(ml, mr) = (0, len(ary) + 1)
mv = 0
st = SegmentTree(len(ary))
for qq in query:
	if qq[0] == '2':
		print(ary[ml], mv)
	else:
		(_, a, b) = map(int, qq.split())
		a = bisect_left(ary, a)
		st.add(0, -1)
		st.add(a, 2)
		if ml <= a < mr:
			mv += b
			(ml, mr) = (a, a + 1)
		else:
			(l, r) = (0, len(ary) + 1)
			while r - l > 1:
				x = (r + l) // 2
				if st.query(0, x) >= 0:
					(l, r) = (l, x)
				else:
					(l, r) = (x, r)
			mv += b
			mv += min(abs(ary[l] - ary[ml]), abs(ary[l] - ary[mr])) + abs(ary[l] - ary[a])
			ml = l
			(l, r) = (0, len(ary) + 1)
			while r - l > 1:
				x = (r + l) // 2
				if st.query(0, x) > 0:
					(l, r) = (l, x)
				else:
					(l, r) = (x, r)
			mr = l


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 sys
input = sys.stdin.buffer.readline
q = int(input())
from heapq import heapify, heappop, heappush
L = []
R = []
s = 0
ans = 0
c = 0
(l, r) = (-10 ** 10, 10 ** 10)
for i in range(q):
	j = tuple(map(int, input().split()))
	if j[0] == 1:
		(x, y) = (j[1], j[2])
		s += 1
		ans += y
		if not l <= x <= r:
			ans += min(abs(l - x), abs(r - x))
		if s == 1:
			heappush(L, -x)
			(l, r) = (x, x)
		elif s % 2:
			if -L[0] >= x:
				heappush(L, -x)
				(l, r) = (-L[0], -L[0])
			else:
				heappush(R, x)
				l = heappop(R)
				r = l
				heappush(L, -l)
		else:
			if -L[0] <= x:
				heappush(R, x)
			else:
				heappush(L, -x)
				heappush(R, -heappop(L))
			(l, r) = (-L[0], R[0])
	else:
		print(l, ans)


import sys
input = sys.stdin.readline
import heapq
Q = int(input())
ans = 0
INF = 10 ** 18
L_pque = []
R_pque = []
heapq.heappush(L_pque, +INF)
heapq.heappush(R_pque, +INF)
for _ in range(Q):
	tmp = tuple(map(str, input().split()))
	if len(tmp) == 1:
		print(-L_pque[0], ans)
	else:
		a = int(tmp[1])
		b = int(tmp[2])
		ans += b
		tmpA = -L_pque[0]
		tmpB = +R_pque[0]
		if a < tmpA:
			ans += abs(tmpA - a)
		elif tmpB < a:
			ans += abs(a - tmpB)
		heapq.heappush(L_pque, -a)
		heapq.heappush(R_pque, +a)
		tmpA = -heapq.heappop(L_pque)
		tmpB = +heapq.heappop(R_pque)
		if tmpA <= tmpB:
			heapq.heappush(L_pque, -tmpA)
			heapq.heappush(R_pque, +tmpB)
		else:
			(tmpA, tmpB) = (tmpB, tmpA)
			heapq.heappush(L_pque, -tmpA)
			heapq.heappush(R_pque, +tmpB)


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))


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
		elif 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)


from heapq import heappush, heappop
Q = int(input())
update_count = 0
al = []
sl = 0
ar = []
sr = 0
b = 0
for _ in range(Q):
	s = tuple(map(int, input().split()))
	if s[0] == 1:
		b += s[2]
		if update_count % 2 == 0:
			heappush(ar, s[1])
			sr += s[1]
			x = heappop(ar)
			sr -= x
			heappush(al, -x)
			sl += x
		else:
			heappush(al, -s[1])
			sl += s[1]
			x = heappop(al)
			sl -= -x
			heappush(ar, -x)
			sr += -x
		update_count += 1
	else:
		x = heappop(al)
		heappush(al, x)
		x *= -1
		cnt_l = (update_count + 1) // 2
		cnt_r = update_count - cnt_l
		print(x, cnt_l * x - sl + (sr - cnt_r * x) + b)


from heapq import heappop, heappush
Q = int(input())
M = [input() for i in range(Q)]
A = []
B = []
a = 0
b = 0
sumb = 0
n = 0
for q in M:
	if q[0] == '1':
		(num, x, y) = map(int, q.split())
		sumb += y
		n += 1
		m = (n + 1) // 2
		if n == 1:
			heappush(A, -x)
			a += x
			continue
		if -A[0] >= x:
			heappush(A, -x)
			a += x
			if len(A) > m:
				z = heappop(A)
				a += z
				heappush(B, -z)
				b += -z
		else:
			heappush(B, x)
			b += x
			if len(B) > n - m:
				z = heappop(B)
				b -= z
				heappush(A, -z)
				a += z
	elif n % 2 == 0:
		print(-A[0], sumb + b - a)
	else:
		print(-A[0], sumb + b - a - A[0])


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)


import heapq
import sys
input = sys.stdin.readline
Q = int(input())
Query = [[int(_) for _ in input().split()] for _ in range(Q)]
H1 = []
H2 = []
a = b = sum1 = sum2 = 0
for query in Query:
	if query[0] == 1:
		m0 = query[1]
		if len(H1) == len(H2):
			if len(H2):
				m1 = heapq.heappop(H2)
				sum2 -= m1
				(m0, m1) = sorted([m0, m1])
				heapq.heappush(H1, -m0)
				heapq.heappush(H2, m1)
				sum1 -= m0
				sum2 += m1
			else:
				heapq.heappush(H1, -m0)
				sum1 -= m0
		else:
			m1 = -heapq.heappop(H1)
			sum1 += m1
			(m0, m1) = sorted([m0, m1])
			heapq.heappush(H1, -m0)
			heapq.heappush(H2, m1)
			sum1 -= m0
			sum2 += m1
		b += query[2]
	else:
		x = -H1[0]
		print(x, x * len(H1) + sum1 + sum2 - x * len(H2) + b)


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)


import sys
from heapq import heappush, heappop

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
Q = INT()
(_, a, b) = MAP()
mid = a
asm = 0
bsm = b
ln = 1
(que1, que2) = ([-a], [INF])
for _ in range(Q - 1):
	li = LIST()
	if li[0] == 1:
		(a, b) = li[1:]
		bsm += b
		l = -que1[0]
		r = que2[0]
		if ln % 2 == 1:
			asm += abs(a - l)
			if a < mid:
				heappush(que1, -a)
				heappush(que2, -que1[0])
				heappop(que1)
			else:
				heappush(que2, a)
		else:
			if a < l:
				asm += abs(a - l)
			elif a > r:
				asm += abs(a - r)
			if a > mid:
				heappush(que2, a)
				heappush(que1, -que2[0])
				heappop(que2)
			else:
				heappush(que1, -a)
		ln += 1
		mid = -que1[0]
	else:
		print(mid, asm + bsm)


import sys
import heapq
stdin = sys.stdin
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
ns = lambda : stdin.readline().rstrip()
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)


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)


from heapq import heappush, heappushpop

def main():
	INF = 10 ** 18
	sum_B = 0
	(L, R) = ([INF], [INF])
	sum_L = sum_R = 0
	A = map(int, open(0).read().split())
	Q = next(A)
	for _ in range(Q):
		q = next(A)
		if q == 1:
			(a, b) = (next(A), next(A))
			sum_B += b
			if len(L) > len(R):
				l = -L[0]
				if a >= l:
					heappush(R, a)
					sum_R += a
				else:
					heappushpop(L, -a)
					sum_L += a - l
					heappush(R, l)
					sum_R += l
			elif len(L) == 0:
				heappush(R, a)
				sum_L += a
			else:
				r = R[0]
				if a <= r:
					heappush(L, -a)
					sum_L += a
				else:
					heappushpop(R, a)
					sum_R += a - r
					heappush(L, -r)
					sum_L += r
		else:
			median = -L[0]
			res = median * len(L) - sum_L + (sum_R - median * len(R)) + sum_B
			print(median, res)
main()


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)


class BITree:

	def __init__(self, n):
		self.size = n
		self.tree = [0] * (n + 1)

	def calc(self, i):
		s = 0
		while i > 0:
			s += self.tree[i]
			i -= i & -i
		return s

	def add(self, i, x):
		while i <= self.size:
			self.tree[i] += x
			i += i & -i
Q = int(input())
query = [list(map(int, input().split())) for i in range(Q)]
tmp = []
for i in range(Q):
	seq = query[i]
	if len(seq) == 1:
		continue
	else:
		tmp.append((seq[1], i))
tmp.sort()
X = [(-1, -1) for i in range(Q)]
for (i, sq) in enumerate(tmp):
	X[sq[1]] = (i + 1, sq[0])
N = len(tmp)
Idx = BITree(N)
Clc = BITree(N)
Btm = 0
nowindex = 0
for i in range(Q):
	if X[i] == (-1, -1):
		left = 1
		right = N
		mid = (left + right) // 2
		while left <= right:
			mid = (left + right) // 2
			if Idx.calc(mid) < (nowindex + 1) // 2:
				left = mid + 1
			else:
				right = mid - 1
		k = left
		x = Clc.calc(k) - Clc.calc(k - 1)
		ans = Clc.calc(N) - 2 * Clc.calc(k) - x * (Idx.calc(N) - 2 * Idx.calc(k)) + Btm
		print(x, ans)
	else:
		Idx.add(X[i][0], 1)
		Clc.add(X[i][0], X[i][1])
		Btm += query[i][2]
		nowindex += 1


from heapq import heappop, heappush
Q = int(input())
(n, a, b) = map(int, input().split())
mi = b
L = [-a]
R = [a]
num = 1
for i in range(Q - 1):
	q = list(map(int, input().split()))
	if len(q) == 3:
		if num % 2 != 0:
			l = -heappop(L)
			r = heappop(R)
			l1 = min(l, q[1])
			r1 = max(r, q[1])
			heappush(L, -l1)
			heappush(R, r1)
			mi += abs(l - q[1])
		elif q[1] < -L[0]:
			heappush(L, -q[1])
			heappush(R, -L[0])
			mi -= q[1] + L[0]
		elif q[1] > R[0]:
			heappush(L, -R[0])
			heappush(R, q[1])
			mi += q[1] - R[0]
		else:
			heappush(L, -q[1])
			heappush(R, q[1])
		mi += q[2]
		num += 1
	else:
		print(-L[0], mi)


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]
		heappush(low, -a)
		heappush(high, a)
		if -low[0] > high[0]:
			low0 = heappop(low)
			high0 = heappop(high)
			heappush(low, -high0)
			heappush(high, -low0)
			ans += -low0 - high0
	if q[0] == 2:
		print(-low[0], ans)


import heapq

def main():
	Q = int(input())
	query_list = [list(map(int, input().split(' '))) for _ in range(Q)]
	(que_left, que_right) = ([], [])
	sum_a_cost = 0
	sum_b = 0
	for query in query_list:
		if query[0] == 1:
			(a, b) = (query[1], query[2])
			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
			if len(que_right) == 0 or a >= que_right[0]:
				heapq.heappush(que_right, a)
			else:
				heapq.heappush(que_left, -a)
			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 *
import sys
input = sys.stdin.readline
(Q,) = map(int, input().split())
qs = []
c = 0
for i in range(Q):
	q = input().split()
	if len(q) == 1:
		c += 1
	else:
		(a, b) = (int(q[1]), int(q[2]))
		qs.append((a, b, c))
		c = 0
if c:
	qs.append((a, b, c))
R = [10 ** 18]
L = [10 ** 18]
ss = 0
for (a, b, c) in qs:
	xs = []
	if c:
		x = heappop(L)
		for _ in range(c):
			print(-x, ss)
		heappush(L, x)
	x = heappop(R)
	y = -heappop(L)
	if x < a:
		heappush(R, a)
		heappush(R, a)
		heappush(L, -x)
		heappush(L, -y)
		ss += a - x
	elif y > a:
		heappush(L, -a)
		heappush(L, -a)
		heappush(R, x)
		heappush(R, y)
		ss += y - a
	else:
		heappush(L, -a)
		heappush(R, a)
		heappush(L, -y)
		heappush(R, x)
	ss += b


import sys
from heapq import heappop, heappush

def main():
	input = sys.stdin.readline
	INF = 10 ** 9 + 1
	Q = int(input())
	left = []
	right = []
	min_val = 0
	for _ in range(Q):
		q = list(map(int, input().split()))
		if q[0] == 1:
			(a, b) = (q[1], q[2])
			heappush(left, -a)
			heappush(right, a)
			left_max = -heappop(left)
			right_min = heappop(right)
			median_left = min(left_max, right_min)
			median_right = max(left_max, right_min)
			heappush(left, -median_left)
			heappush(right, median_right)
			min_val += abs(median_right - median_left)
			min_val += b
		else:
			median = -heappop(left)
			print('{} {}'.format(median, min_val))
			heappush(left, -median)
main()


import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from heapq import heappush, heappop, heappushpop
Q = int(readline())
query = (tuple(map(int, line.split())) for line in readlines())
INF = 10 ** 12
L = [INF]
R = [INF]
sumL = 0
sumR = 0
lenL = 0
lenR = 0
add = 0
answer = []
for q in query:
	if len(q) == 1:
		x = -L[0]
		f = sumR - sumL + x * (lenL - lenR)
		answer.append('{} {}'.format(x, f + add))
		continue
	(a, b) = q[1:]
	add += b
	if lenL > lenR:
		sumL += a
		a = -heappushpop(L, -a)
		sumL -= a
		heappush(R, a)
		sumR += a
		lenR += 1
	else:
		sumR += a
		a = heappushpop(R, a)
		sumR -= a
		heappush(L, -a)
		sumL += a
		lenL += 1
print('\n'.join(answer))


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

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def II():
	return int(sys.stdin.readline())

def SI():
	return input()
from heapq import heappush, heappop

def main():
	q = II()
	Q = []
	for _ in range(q):
		Q.append(LI())
	(lows, highs) = ([], [])
	(slow, shigh) = (0, 0)
	bias = 0
	for q in Q:
		if q[0] == 2:
			odd = -lows[0] if len(highs) != len(lows) else 0
			ans = (-lows[0], bias + shigh - slow + odd)
			print(*ans)
		else:
			(_, a, b) = q
			bias += b
			if not lows:
				lows = [-a]
				slow = a
			elif a <= -lows[0]:
				heappush(lows, -a)
				slow += a
				if len(lows) > len(highs) + 1:
					x = -heappop(lows)
					heappush(highs, x)
					slow -= x
					shigh += x
			else:
				heappush(highs, a)
				shigh += a
				if len(highs) > len(lows):
					x = heappop(highs)
					heappush(lows, -x)
					shigh -= x
					slow += x
	return
main()


from heapq import heappush, heappop
N = int(input())
s = list(map(int, input().split()))
(a, b) = (s[1], s[2])
L = []
R = []
heappush(L, -a)
heappush(R, a)
bsum = b
t = 0
for k in range(N - 1):
	s = input()
	if s[0] == '1':
		s = list(map(int, s.split()))
		a = s[1]
		b = s[2]
		bsum += b
		if -L[0] <= a <= R[0]:
			pass
		else:
			t += min(abs(a + L[0]), abs(a - R[0]))
		heappush(L, -a)
		heappush(R, a)
		if -L[0] > R[0]:
			c = heappop(L)
			d = heappop(R)
			heappush(R, -c)
			heappush(L, -d)
	else:
		print(-L[0], t + bsum)


Q = int(input())
INF = 10 ** 9
queries = []
for _ in range(Q):
	queries.append(input())
from bisect import insort_left
from heapq import heappush, heappop
(absum, bsum, c) = (0, 0, 0)
(lefts, rights) = ([INF], [INF])
for query in queries:
	if query[0] == '2':
		print(-lefts[0], absum + bsum)
	else:
		(_, a, b) = map(int, query.split())
		if c % 2 == 0:
			if -lefts[0] <= a <= rights[0]:
				heappush(lefts, -a)
				heappush(rights, a)
				absum += 0
			elif a < -lefts[0]:
				heappush(lefts, -a)
				heappush(rights, -lefts[0])
				absum += -lefts[0] - a
			else:
				heappush(rights, a)
				heappush(lefts, -rights[0])
				absum += a - rights[0]
		elif a < -lefts[0]:
			absum += -lefts[0] - a
			heappop(lefts)
			heappush(lefts, -a)
		else:
			absum += a - rights[0]
			heappop(rights)
			heappush(rights, a)
		bsum += b
		c += 1


import heapq
q = int(input())
large = []
small = []
l_s = 0
s_s = 0
c = 0
ll = 0
ls = 0
cc = 0
for i in range(q):
	s = input()
	if s[0] == '1':
		cc = (cc + 1) % 2
		(_, a, b) = map(int, s.split())
		c += b
		if large == [] and small == []:
			heapq.heappush(small, -1 * a)
			s_s += a
			ls += 1
		elif a > small[0] * -1:
			heapq.heappush(large, a)
			l_s -= a
			ll += 1
		else:
			x = heapq.heappop(small)
			heapq.heappush(small, -1 * a)
			heapq.heappush(large, -1 * x)
			s_s = s_s + a + x
			l_s += x
			ll += 1
		if not ll <= ls <= ll + 1:
			x = heapq.heappop(large)
			heapq.heappush(small, -1 * x)
			s_s = s_s + x
			l_s += x
			ll -= 1
			ls += 1
	else:
		print(small[0] * -1, c - s_s - l_s - small[0] * cc)


import heapq
N = int(input())
st = input()
(n, a, b) = map(int, st.split())
minvalue = b
left = [-a]
right = [a]
ptnum = 1
for i in range(N - 1):
	st = input()
	if st[0] == '1':
		(n, a, b) = map(int, st.split())
		if ptnum % 2 == 1:
			l = -heapq.heappop(left)
			r = heapq.heappop(right)
			le = min(l, a)
			ri = max(a, r)
			heapq.heappush(left, -le)
			heapq.heappush(right, ri)
			minvalue += abs(l - a)
		elif a < -left[0]:
			heapq.heappush(left, -a)
			heapq.heappush(right, -left[0])
			minvalue -= a + left[0]
		elif a > right[0]:
			heapq.heappush(left, -right[0])
			heapq.heappush(right, a)
			minvalue += a - right[0]
		else:
			heapq.heappush(left, -a)
			heapq.heappush(right, a)
		minvalue += b
		ptnum += 1
	else:
		print(-left[0], minvalue)


import heapq

def main():
	n = int(input())
	s = list(map(int, input().split()))
	l = []
	r = []
	heapq.heapify(l)
	heapq.heapify(r)
	lenl = 0
	lenr = 0
	x = s[1]
	ans = s[2]
	for i in range(n - 1):
		q = list(map(int, input().split()))
		if q[0] == 1:
			ans += q[2]
			if (lenl + lenr) % 2 == 0:
				lenr += 1
				ans += abs(x - q[1])
				if x <= q[1]:
					heapq.heappush(r, q[1])
				else:
					heapq.heappush(l, -q[1])
					heapq.heappush(r, x)
					x = -heapq.heappop(l)
			else:
				lenl += 1
				if x < q[1]:
					heapq.heappush(l, -x)
					heapq.heappush(r, q[1])
					x = heapq.heappop(r)
				else:
					heapq.heappush(l, -q[1])
				ans += abs(x - q[1])
		if q[0] == 2:
			print(x, ans)
main()


q0 = int(input())
from heapq import *
low = []
high = []
ans = 0
num = 0
for _ in range(q0):
	q = [int(i) for i in input().split()]
	if q[0] == 1:
		ans += q[2]
		num += 1
		a = q[1]
		if num == 1:
			heappush(low, -a)
			df = 0
		elif num % 2 == 1:
			centold = -low[0]
			centold2 = high[0]
			if -low[0] >= a:
				heappush(low, -a)
			else:
				c = heappushpop(high, a)
				heappush(low, -c)
			centnew = -low[0]
			if centnew < centold:
				df = 2 * (centold - centnew)
			elif centnew <= centold2:
				df = 0
			else:
				df = 2 * (centnew - centold2)
		else:
			centold = -low[0]
			if -low[0] > a:
				c = heappushpop(low, -a)
				heappush(high, -c)
			else:
				heappush(high, a)
			centnew = -low[0]
			if centnew < centold:
				df = centold - centnew
			else:
				df = centnew - centold
		df += abs(-low[0] - a)
		ans += df
	if q[0] == 2:
		print(-low[0], ans)


import sys
from heapq import heappush, heappop
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007

def main():
	Q = int(readline())
	hi = []
	lo = []
	hi_sum = lo_sum = 0
	b_sum = 0
	ans = []
	for _ in range(Q):
		A = list(map(int, readline().split()))
		if len(A) == 3:
			(a, b) = (A[1], A[2])
			b_sum += b
			if not lo:
				lo.append(-a)
				lo_sum += a
			elif a <= -lo[0]:
				heappush(lo, -a)
				lo_sum += a
			else:
				heappush(hi, a)
				hi_sum += a
			if len(hi) > len(lo):
				x = heappop(hi)
				hi_sum -= x
				heappush(lo, -x)
				lo_sum += x
			elif len(hi) + 1 < len(lo):
				x = -heappop(lo)
				lo_sum -= x
				heappush(hi, x)
				hi_sum += x
		else:
			x = -lo[0]
			val = x * (len(lo) - len(hi)) - lo_sum + hi_sum + b_sum
			ans.append((x, val))
	for (x, val) in ans:
		print(x, val)
	return
main()


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
	else:
		med = -L[0]
		print(med, cnt % 2 * med + B + l + r)


def main():
	import sys
	input = sys.stdin.readline
	sys.setrecursionlimit(10 ** 7)
	from collections import Counter, deque
	from itertools import combinations, permutations, accumulate, groupby, product
	from bisect import bisect_left, bisect_right
	from heapq import heapify, heappop, heappush
	import math
	q = int(input())
	b = 0
	(hq_l, hq_r) = ([], [])
	(sum_l, sum_r) = (0, 0)
	for _ in range(q):
		a = list(map(int, input().split()))
		if a[0] == 1:
			b += a[2]
			if len(hq_l) == 0 or a[1] <= -hq_l[0]:
				heappush(hq_l, -a[1])
				sum_l += a[1]
			else:
				heappush(hq_r, a[1])
				sum_r += a[1]
		else:
			while len(hq_l) - 1 > len(hq_r):
				sum_l -= -hq_l[0]
				sum_r += -hq_l[0]
				m = -heappop(hq_l)
				heappush(hq_r, m)
			while len(hq_l) < len(hq_r):
				sum_l += hq_r[0]
				sum_r -= hq_r[0]
				m = -heappop(hq_r)
				heappush(hq_l, m)
			print(-hq_l[0], -hq_l[0] * len(hq_l) - sum_l + sum_r - -hq_l[0] * len(hq_r) + b)
main()


import heapq
Q = int(input())
b = 0
mid = None
lq = []
ls = 0
rq = []
rs = 0
n = 0
for _ in range(Q):
	q = input()
	if q[0] == '1':
		(x, y, z) = map(int, q.split())
		if n == 0:
			mid = y
		elif mid is None:
			l = -lq[0]
			r = rq[0]
			if y < l:
				mid = -heapq.heappop(lq)
				heapq.heappush(lq, -y)
				ls = ls - mid + y
			elif y < r:
				mid = y
			else:
				mid = heapq.heappop(rq)
				heapq.heappush(rq, y)
				rs = rs - mid + y
		else:
			heapq.heappush(lq, -min(y, mid))
			heapq.heappush(rq, max(y, mid))
			ls = ls + min(y, mid)
			rs = rs + max(y, mid)
			mid = None
		n += 1
		b += z
	elif mid is None:
		print(-lq[0], b - ls + rs)
	else:
		print(mid, b - ls + rs)


def main():

	def Technique_often_used():
		pass

	def naming_conventions():
		pass

	def visual_studio_code_shortcut():
		pass
	import sys
	from itertools import combinations, permutations
	from collections import deque, Counter
	from heapq import heapify, heappop, heappush, heappushpop, heapreplace, nlargest, nsmallest
	from copy import deepcopy, copy
	from functools import reduce
	from fractions import gcd

	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)
	R = lambda : map(int, input().split())
	q = int(input())
	queries = [list(R()) for i in range(q)]
	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 sys
from collections import deque, defaultdict
import copy
import bisect
input = sys.stdin.readline
import math
import heapq
Q = int(input())
q = []
for i in range(Q):
	q.append(list(map(int, input().split())))
a_list = []
a_list2 = []
b_sum = 0
a_sum = 0
a_sum_half = 0
length = 0
for i in range(Q):
	if len(q[i]) == 3:
		if len(a_list2) == 0:
			D = True
		else:
			x = heapq.heappop(a_list2)
			heapq.heappush(a_list2, x)
			D = x <= q[i][1]
		length += 1
		if length % 2 == 0 and (not D):
			a_sum_half += q[i][1]
			heapq.heappush(a_list, -q[i][1])
		elif length % 2 == 0 and D:
			heapq.heappush(a_list2, q[i][1])
			x = heapq.heappop(a_list2)
			heapq.heappush(a_list, -x)
			a_sum_half += x
		elif length % 2 == 1 and (not D):
			a_sum_half += q[i][1]
			heapq.heappush(a_list, -q[i][1])
			x = heapq.heappop(a_list)
			a_sum_half += x
			heapq.heappush(a_list2, -x)
		else:
			heapq.heappush(a_list2, q[i][1])
		a_sum += q[i][1]
		b_sum += q[i][2]
	else:
		if length % 2 == 0:
			argmin_x = -heapq.heappop(a_list)
			heapq.heappush(a_list, -argmin_x)
		else:
			argmin_x = heapq.heappop(a_list2)
			heapq.heappush(a_list2, argmin_x)
		min_x = argmin_x * (length // 2) - a_sum_half
		min_x += a_sum - a_sum_half - argmin_x * (length - length // 2)
		min_x += b_sum
		print('{0} {1}'.format(argmin_x, min_x))


import sys
input = sys.stdin.readline
from heapq import heappush, heappop
q = int(input())
(L, R) = ([], [])
(s, c) = (0, 0)
for _ in range(q):
	query = tuple(map(int, input().split()))
	if query[0] == 1:
		(_, a, b) = query
		c += b
		if len(L) == 0 or a <= -L[0]:
			heappush(L, -a)
			s += -L[0] - a
		else:
			heappush(R, a)
			s += a + L[0]
		if len(R) > len(L):
			s += -R[0] - L[0]
			heappush(L, -heappop(R))
		if len(L) - len(R) == 2:
			heappush(R, -heappop(L))
	else:
		print(-L[0], s + c)


import sys
input = sys.stdin.readline
from heapq import heappush, heappop
q = int(input())
(_, a, b) = map(int, input().split())
Small = [-a]
Large = []
cnt = 1
med = a
c = b
s = 0
for i in range(q - 1):
	query = tuple(map(int, input().split()))
	if query[0] == 1:
		(_, a, b) = query
		c += b
		if cnt % 2:
			s += abs(a - med)
			if a < -Small[0]:
				heappush(Small, -a)
				heappush(Large, -heappop(Small))
			else:
				heappush(Large, a)
		elif a <= -Small[0]:
			heappush(Small, -a)
			med = -Small[0]
			s += med - a
		elif a <= Large[0]:
			heappush(Small, -a)
		else:
			heappush(Large, a)
			med = heappop(Large)
			s += a - med
			heappush(Small, -med)
		cnt += 1
		med = -Small[0]
	else:
		print(med, s + c)


q = int(input())
a = 0
b = 0
(g, l, ans) = map(int, input().split())
r = l
now = 1
from heapq import heappop, heappush
(le, ri) = ([], [])
for i in range(q - 1):
	cin = tuple(map(int, input().split()))
	if cin[0] == 2:
		print(l, ans)
	else:
		x = cin[1]
		ans += cin[2]
		if not l <= x <= r:
			ans += min(abs(x - l), abs(r - x))
		now += 1
		if now % 2:
			heappush(le, -min(l, r, x))
			heappush(ri, max(l, r, x))
			l = l + r + x - max(l, r, x) - min(l, r, x)
			r = l
		elif l <= x:
			heappush(ri, x)
			r = heappop(ri)
		else:
			heappush(le, -x)
			(l, r) = (-heappop(le), l)


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)
			elif 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)


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)


from heapq import heappop, heappush
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)


import sys
import math
import collections
import heapq
INF = 10 ** 10
(Q,) = map(int, sys.stdin.readline().rstrip().split(' '))
b_all = 0
sum_value = 0
k_value = 0
tree = None
qs = [list(map(int, sys.stdin.readline().rstrip().split(' '))) for _ in range(Q)]
left = []
right = []
a_s = []
current_median = None
heapq.heappush(left, INF)
heapq.heappush(right, INF)
a_current = 0
for query in qs:
	if query[0] == 1:
		(_, a, b) = query
		a_s.append(a)
		b_all += b
		(last_left, last_right) = (-left[0], right[0])
		heapq.heappush(left, -a)
		heapq.heappush(right, a)
		heapq.heappush(left, -heapq.heappop(right))
		heapq.heappush(right, -heapq.heappop(left))
		current_median = -left[0]
		if last_left <= a and a <= last_right:
			pass
		else:
			a_current += min(abs(last_right - a), abs(last_left - a))
	else:
		print(current_median, a_current + b_all)
exit(0)


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())
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)


from heapq import heappush, heappushpop
import sys
input = sys.stdin.readline
Q = int(input())
small = []
large = []
const = 0
total = 0
s = 0
n = 0
m = 0
for _ in range(Q):
	(q, *nums) = map(int, input().split())
	if q == 1:
		n += 1
		(a, b) = nums
		total += a
		const += b
		if n % 2 == 0:
			if a > large[0]:
				a = heappushpop(large, a)
			heappush(small, -a)
			m = -small[0]
			s += a
		else:
			if small and a < -small[0]:
				s += a
				a = -heappushpop(small, -a)
				s -= a
			heappush(large, a)
			m = large[0]
	else:
		ans = const + total - 2 * s
		if n % 2 == 1:
			ans -= m
		print(m, ans)


from heapq import *
Q = int(input())
(L, R) = ([], [])
ans = 0
for _ in range(Q):
	a = [int(a) for a in input().split()]
	if a[0] == 1:
		t1 = heappushpop(L, -a[1])
		t2 = heappushpop(R, a[1])
		heappush(L, -t2)
		heappush(R, -t1)
		ans += a[2] + abs(t2 + t1)
	else:
		print(-L[0], ans)


Q = int(input())
Queries = [list(map(int, input().split())) for _ in range(Q)]
import heapq as hp
L = [--(10 ** 9 + 1)]
R = [10 ** 9 + 1]
hp.heapify(L)
hp.heapify(R)
odd = False
sum_b = 0
sum_l = 0
sum_r = 0
for q in Queries:
	if len(q) == 1 and q[0] == 2:
		print(*(-L[0], sum_b + abs(sum_l - sum_r)))
	else:
		(_, a, b) = q
		sum_b += b
		l = -hp.heappop(L)
		r = hp.heappop(R)
		X = sorted([l, r, a])
		if odd == False:
			sum_l -= l
			sum_r -= r
			hp.heappush(L, -X[0])
			hp.heappush(L, -X[1])
			hp.heappush(R, X[2])
			sum_l += X[0]
			sum_r += X[2]
			odd = True
		elif odd == True:
			sum_r -= r
			hp.heappush(L, -X[0])
			hp.heappush(R, X[1])
			hp.heappush(R, X[2])
			sum_l += X[0]
			sum_r += X[1] + X[2]
			odd = False


import bisect
from heapq import heappush as hpush
from heapq import heappushpop as hpushpop
Q = int(input())
que = list(map(int, input().split()))
b = que[2]
(l, r) = ([-que[1]], [que[1]])
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]:
				hpushpop(l, -q1)
			else:
				hpushpop(r, q1)
		elif q1 < -l[0]:
			hpush(l, -q1)
			hpush(r, -l[0])
		else:
			hpush(r, q1)
			hpush(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)


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)
	else:
		print(-lows[0], r + b)


import heapq
qq = int(input())
ans = 0
hq1 = []
hq2 = []
x = 10 ** 10
c = 0
(p, q) = (0, 0)
for _ in range(qq):
	que = list(map(int, input().split()))
	if que[0] == 1:
		(a, b) = que[1:]
		ans += b
		if c % 2 == 0:
			if a <= x:
				heapq.heappush(hq1, -a)
				p += a
			else:
				heapq.heappush(hq2, a)
				q += a
				y = heapq.heappop(hq2)
				q -= y
				heapq.heappush(hq1, -y)
				p += y
		elif a <= x:
			heapq.heappush(hq1, -a)
			p += a
			y = -heapq.heappop(hq1)
			p -= y
			heapq.heappush(hq2, y)
			q += y
		else:
			heapq.heappush(hq2, a)
			q += a
		x = -hq1[0]
		c += 1
	else:
		print(x, q - len(hq2) * x + len(hq1) * x - p + 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())
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':
		(d, a, b) = map(int, q.split())
		if not flg:
			heapq.heappush(Al, -a)
			B += b
			flg = True
			continue
		if len(Al) == len(Ar):
			if a < Ar[0]:
				heapq.heappush(Al, -a)
				C = abs(a - -Al[0])
			else:
				heapq.heappush(Ar, a)
				heapq.heappush(Al, -heapq.heappop(Ar))
				C = abs(a - -Al[0])
		elif a < Ar[0]:
			C = abs(a - -Al[0])
			heapq.heappush(Al, -a)
			heapq.heappush(Ar, -heapq.heappop(Al))
		else:
			C = abs(a - -Al[0])
			heapq.heappush(Ar, a)
		B += b + C
	else:
		ans.append([-Al[0], B])
for c in ans:
	print(' '.join(map(str, c)))


def f_absolute_minima(Q, Queries, INF=float('inf')):
	import heapq
	(left, right) = ([], [])
	(current_ans, current_median) = (0, 0)
	bias_total = 0
	heapq.heappush(left, INF)
	heapq.heappush(right, INF)
	ans = []
	for query in Queries:
		if query[0] == 1:
			(_, a, b) = query
			bias_total += b
			(last_left, last_right) = (-left[0], right[0])
			heapq.heappush(left, -a)
			heapq.heappush(right, a)
			heapq.heappush(left, -heapq.heappop(right))
			heapq.heappush(right, -heapq.heappop(left))
			current_median = -left[0]
			if a < last_left or last_right < a:
				current_ans += min(abs(last_right - a), abs(last_left - a))
		else:
			ans.append((current_median, current_ans + bias_total))
	return '\n'.join((' '.join(map(str, row)) for row in ans))
Q = int(input())
Queries = [[int(i) for i in input().split()] for j in range(Q)]
print(f_absolute_minima(Q, Queries))


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

def resolve():
	N = int(input())
	b = 0
	left = []
	right = []
	sumleft = sumright = mid = 0
	for _ in range(N):
		q = list(map(int, input().split()))
		if q[0] == 1:
			a = q[1]
			b = b + q[2]
			if not left or -left[0] > a:
				heappush(left, -a)
				sumleft = sumleft + a
				if len(left) - len(right) >= 2:
					move = -heappop(left)
					heappush(right, move)
					sumleft = sumleft - move
					sumright = sumright + move
			else:
				heappush(right, a)
				sumright = sumright + a
				if len(left) < len(right):
					move = heappop(right)
					heappush(left, -move)
					sumright = sumright - move
					sumleft = sumleft + move
			mid = -left[0]
		else:
			ans = (len(left) - len(right)) * mid - sumleft + sumright + b
			print(mid, ans)
resolve()


def main():
	import sys
	from heapq import heappop, heappush, heappushpop
	input = sys.stdin.readline
	Q = int(input())
	R = [10 ** 9 + 1]
	L = [10 ** 9 + 1]
	Rsum = 0
	Lsum = 0
	NL = 0
	NR = 0
	B = 0
	for _ in range(Q):
		query = input().rstrip('\n')
		if query == '2':
			Lmax = -L[0]
			print(Lmax, Lmax * NL - Lsum + Rsum - Lmax * NR + B)
		else:
			(_, a, b) = query.split()
			a = int(a)
			b = int(b)
			B += b
			if NL != NR:
				Lmax = -L[0]
				Rmin = R[0]
				if a >= Lmax:
					heappush(R, a)
					Rsum += a
					NR += 1
				else:
					newR = -heappushpop(L, -a)
					heappush(R, newR)
					Rsum += newR
					Lsum += a - newR
					NR += 1
					Lmax = -L[0]
			else:
				Rmin = R[0]
				if a <= Rmin:
					heappush(L, -a)
					Lsum += a
					NL += 1
				else:
					newL = heappushpop(R, a)
					heappush(L, -newL)
					Lsum += newL
					Rsum += a - newL
					NL += 1
main()


import sys
from heapq import heappush, heappushpop
Q = int(input())
high = []
low = []
(sum_dh, sum_dl) = (0, 0)
sum_b = 0
MIN_X = -10 ** 9
buf = []
for (qi, line) in enumerate(sys.stdin):
	q = list(map(int, line.split()))
	if len(q) == 1:
		x = -low[0]
		dx = x - MIN_X
		ans_l = dx * len(low) - sum_dl
		ans_h = sum_dh - dx * len(high)
		buf.append('{} {}\n'.format(x, ans_l + ans_h + sum_b))
	else:
		(_, a, b) = q
		da = a - MIN_X
		sum_b += b
		if len(low) == len(high):
			h = heappushpop(high, a)
			heappush(low, -h)
			dh = h - MIN_X
			sum_dh += da - dh
			sum_dl += dh
		else:
			l = -heappushpop(low, -a)
			heappush(high, l)
			dl = l - MIN_X
			sum_dl += da - dl
			sum_dh += dl
print(''.join(buf))


import heapq
Q = int(input())
b_sum = 0
a_list = []
left = []
right = []
res = 0
for i in range(Q):
	query = list(map(int, input().split()))
	if query[0] == 1:
		b_sum += query[2]
		if not left:
			a = query[1]
			heapq.heappush(left, -a)
		else:
			res += abs(query[1] + left[0])
			if query[1] <= -left[0]:
				heapq.heappush(left, -query[1])
			else:
				heapq.heappush(right, query[1])
		if len(left) < len(right):
			x = heapq.heappop(right)
			y = -left[0]
			res += y - x
			heapq.heappush(left, -x)
		elif len(left) > len(right) + 1:
			x = -heapq.heappop(left)
			if len(right) != 0:
				y = right[0]
			else:
				y = 0
			heapq.heappush(right, x)
	else:
		print(-left[0], res + b_sum)


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


import heapq
q = int(input())
l = []
r = []
lsum = 0
rsum = 0
cnt = 0
b = 0
for i in range(q):
	(*que,) = map(int, input().split())
	if que[0] == 1:
		b += que[2]
		a = que[1]
		ax = None
		if cnt % 2 == 0:
			rsum += a
			heapq.heappush(r, a)
			ax = heapq.heappop(r)
			rsum -= ax
			heapq.heappush(l, -ax)
			lsum += ax
		else:
			lsum += a
			heapq.heappush(l, -a)
			ax = -heapq.heappop(l)
			lsum -= ax
			heapq.heappush(r, ax)
			rsum += ax
		cnt += 1
	else:
		x = -heapq.heappop(l)
		print(x, b + rsum - lsum + (len(l) + 1 - len(r)) * x)
		heapq.heappush(l, -x)


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 itertools import zip_longest
from heapq import heappush, heappop
Q = int(input())
(q, a, b) = zip_longest(*(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)
		elif 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)


import heapq
Q = int(input())
Query = [input() for _ in range(Q)]
ans = 0
lq = []
rq = []
for q in Query:
	if q[0] == '1':
		(a, b) = map(int, q[2:].split())
		heapq.heappush(lq, -a)
		heapq.heappush(rq, a)
		(lmax, rmin) = (-lq[0], rq[0])
		if lmax > rmin:
			(lmax, rmin) = (rmin, lmax)
			ans += rmin - lmax
			heapq.heappop(lq)
			heapq.heappop(rq)
			heapq.heappush(lq, -lmax)
			heapq.heappush(rq, rmin)
		ans += b
	else:
		print(-lq[0], ans)


from heapq import heappush, heappop
n = int(input())
INF = 10 ** 10
left = [INF]
right = [INF]
left_sm = 0
right_sm = 0
cnt = 0
b_sm = 0
for _ in range(n):
	q = input()
	if q[0] == '1':
		(_, a, b) = map(int, q.split())
		if cnt % 2:
			if a < -left[0]:
				l2r = -heappop(left)
				left_sm -= l2r
				heappush(left, -a)
				left_sm += a
				heappush(right, l2r)
				right_sm += l2r
			else:
				heappush(right, a)
				right_sm += a
		elif a > right[0]:
			r2l = heappop(right)
			right_sm -= r2l
			heappush(left, -r2l)
			left_sm += r2l
			heappush(right, a)
			right_sm += a
		else:
			heappush(left, -a)
			left_sm += a
		b_sm += b
		cnt += 1
	else:
		x = -left[0]
		fx = -left_sm + right_sm + b_sm
		if cnt % 2:
			fx += x
		print(x, fx)


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)


Q = int(input())
import heapq
import sys
input = sys.stdin.readline
INF = 10 ** 18
L = []
R = []
heapq.heappush(L, INF)
heapq.heappush(R, INF)
L_size = 0
R_size = 0
sum_b = 0
sum_L = 0
sum_R = 0

def f1(a, b):
	global sum_b, L_size, R_size, sum_L, sum_R
	sum_b += b
	L_max = -heapq.heappop(L)
	R_min = heapq.heappop(R)
	sum_L -= L_max
	sum_R -= R_min
	X = sorted([L_max, a, R_min])
	if L_size == R_size:
		heapq.heappush(L, -X[0])
		heapq.heappush(L, -X[1])
		heapq.heappush(R, X[2])
		L_size += 1
		sum_L += X[0] + X[1]
		sum_R += X[2]
	else:
		heapq.heappush(L, -X[0])
		heapq.heappush(R, X[1])
		heapq.heappush(R, X[2])
		R_size += 1
		sum_L += X[0]
		sum_R += X[1] + X[2]
	return

def f2():
	min_value = sum_b
	min_x = -L[0]
	if L_size == R_size:
		min_value += sum_R - sum_L
	else:
		min_value += sum_R - sum_L + min_x
	print(min_x, min_value)
QUERY = [[int(x) for x in input().split()] for _ in range(Q)]
for q in QUERY:
	if q[0] & 1:
		f1(q[1], q[2])
	else:
		f2()


from heapq import heappush, heappushpop
Q = int(input())
b = 0
la = []
sl = 0
ra = []
sr = 0
cnt = 0
for _ in range(Q):
	q = tuple(map(int, input().split()))
	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)


import heapq

class DynamicMedian:

	def __init__(self):
		self.l_q = []
		self.r_q = []
		self.l_sum = 0
		self.r_sum = 0

	def add(self, val):
		if len(self.l_q) == len(self.r_q):
			self.l_sum += val
			val = -heapq.heappushpop(self.l_q, -val)
			self.l_sum -= val
			heapq.heappush(self.r_q, val)
			self.r_sum += val
		else:
			self.r_sum += val
			val = heapq.heappushpop(self.r_q, val)
			self.r_sum -= val
			heapq.heappush(self.l_q, -val)
			self.l_sum += val

	def median_low(self):
		if len(self.l_q) + 1 == len(self.r_q):
			return self.r_q[0]
		else:
			return -self.l_q[0]

	def median_high(self):
		return self.r_q[0]

	def minimum_query(self):
		res1 = len(self.l_q) * self.median_high() - self.l_sum
		res2 = self.r_sum - len(self.r_q) * self.median_high()
		return res1 + res2
q = int(input())
info = [list(map(int, input().split())) for i in range(q)]
dm = DynamicMedian()
b = 0
for i in range(q):
	if info[i][0] == 1:
		(_, tmp_a, tmp_b) = info[i]
		dm.add(tmp_a)
		b += tmp_b
	else:
		print(dm.median_low(), dm.minimum_query() + b)


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
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 *
Q = int(input())
(L, R) = ([], [])
ans = 0
for _ in range(Q):
	a = [int(a) for a in input().split()]
	if a[0] == 1:
		ans += a[2]
		if len(L) == 0 or a[1] <= -L[0]:
			heappush(L, -a[1])
			ans += -L[0] - a[1]
		else:
			heappush(R, a[1])
			ans += a[1] + L[0]
		if len(R) > len(L):
			ans -= R[0] + L[0]
			heappush(L, -heappop(R))
		elif len(L) - len(R) >= 2:
			heappush(R, -heappop(L))
	else:
		print(-L[0], ans)


import heapq
inn = lambda : int(input())
inl = lambda : list(map(int, input().split()))
DBG = True and False
q = inn()
x = inl()
root = x[1]
b = x[2]
tl = []
tr = []
nl = nr = suml = sumr = 0
for i in range(1, q):
	x = inl()
	if len(x) == 1:
		z = sumr - suml - (root if nr > nl else 0) + b
		print('{} {}'.format(root, z))
	else:
		a = x[1]
		b += x[2]
		if nl == nr:
			aa = -heapq.heappushpop(tl, -a)
			suml += a - aa
			if aa < root:
				(aa, root) = (root, aa)
			heapq.heappush(tr, aa)
			sumr += aa
			nr += 1
		else:
			aa = heapq.heappushpop(tr, a)
			sumr += a - aa
			if aa > root:
				(aa, root) = (root, aa)
			heapq.heappush(tl, -aa)
			suml += aa
			nl += 1


from bisect import bisect
Q = int(input())
xs = [-10 ** 10, 10 ** 10]
min_index = 0
minimum = 0
for _ in range(Q):
	s = input()
	if s[0] == '1':
		(a, b) = map(int, s[2:].split())
		index = bisect(xs, a)
		xs.insert(index, a)
		if min_index >= index:
			min_index += 1
		minimum += abs(xs[min_index] - a) + b
		if min_index < (len(xs) - 1) // 2:
			minimum += (len(xs) % 2 - 2) * (xs[min_index + 1] - xs[min_index])
			min_index += 1
		elif min_index > (len(xs) - 1) // 2:
			minimum += len(xs) % 2 * (xs[min_index - 1] - xs[min_index])
			min_index -= 1
	else:
		print(xs[min_index], minimum)


import sys
import heapq
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
N = int(input())
inf = 10 ** 18
L = [--inf]
R = [inf]
Lsum = 0
Rsum = 0
const = 0
xmed = None
for _ in range(N):
	(f, *arg) = map(int, input().split())
	if f == 1:
		(a, b) = arg
		const += b
		if xmed is None:
			xmed = a
			while -L[0] > xmed or xmed > R[0]:
				while xmed < -L[0]:
					Lsum += xmed
					xmed = -heapq.heappushpop(L, -xmed)
					Lsum -= xmed
				while xmed > R[0]:
					Rsum += xmed
					xmed = heapq.heappushpop(R, xmed)
					Rsum -= xmed
		else:
			if a < xmed:
				(a, xmed) = (xmed, a)
			heapq.heappush(L, -xmed)
			heapq.heappush(R, a)
			Lsum += xmed
			Rsum += a
			xmed = None
			while -L[0] > R[0]:
				lx = -heapq.heappop(L)
				rx = heapq.heappop(R)
				heapq.heappush(L, -rx)
				heapq.heappush(R, lx)
				Lsum += rx - lx
				Rsum += lx - rx
	else:
		if xmed is None:
			xres = -L[0]
		else:
			xres = xmed
		F = const
		F += Rsum - xres * (len(R) - 1)
		F += xres * (len(L) - 1) - Lsum
		print(xres, F)


import heapq
import sys
input = sys.stdin.readline
INF = 10 ** 18
Q = int(input())
count = 0
s = 0
upper = [INF]
lower = [INF]
heapq.heapify(upper)
heapq.heapify(lower)
for _ in range(Q):
	q = list(map(int, input().split()))
	if q[0] == 1:
		count += 1
		s += q[2]
		a = q[1]
		u = heapq.heappop(upper)
		l = -heapq.heappop(lower)
		if count % 2 == 0:
			if a < l:
				heapq.heappush(lower, -a)
				heapq.heappush(upper, l)
				heapq.heappush(upper, u)
				s += l - a
			else:
				heapq.heappush(lower, -l)
				heapq.heappush(upper, a)
				heapq.heappush(upper, u)
				s += a - l
		elif a <= u:
			heapq.heappush(lower, -l)
			heapq.heappush(lower, -a)
			heapq.heappush(upper, u)
			s += max(0, l - a)
		else:
			heapq.heappush(lower, -l)
			heapq.heappush(lower, -u)
			heapq.heappush(upper, a)
			s += a - u
	else:
		x = -heapq.heappop(lower)
		print(x, s)
		heapq.heappush(lower, -x)


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()
	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)


import heapq
Q = int(input())
Q2 = [input() for i in range(Q)]
ans = []
(Al, Ar) = ([--(10 ** 9 + 1)], [10 ** 9 + 1])
(d, a, b) = map(int, Q2[0].split())
heapq.heappush(Al, -a)
B = b
for i in range(1, Q):
	if Q2[i][0] == '1':
		(d, a, b) = 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
	else:
		ans.append([-Al[0], B])
for c in ans:
	print(' '.join(map(str, c)))


import bisect
import heapq
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)

class v:

	def __init__(self, f):
		self.f = f
		self.v = None

	def __str__(self):
		return str(self.v)

	def ud(self, n):
		if self.v is None:
			self.v = n
		else:
			self.v = self.f(self.v, n)

def read_values():
	return map(int, input().split())

def read_list():
	return list(read_values())

def update(S, L, M):
	(_, a, b) = S
	M[0] += b
	if len(L[0]) == 0:
		L[0].append(-a)
		L[1].append(a)
	else:
		r0 = -1 * L[0][0]
		r1 = L[1][0]
		if a < r0:
			M[1] += r0 - a
		elif r1 < a:
			M[1] += a - r1
		if -1 * L[0][0] >= a:
			heapq.heappush(L[0], -a)
			t = -1 * heapq.heappushpop(L[0], -a)
			heapq.heappush(L[1], t)
		elif L[1][0] < a:
			heapq.heappush(L[1], a)
			t = heapq.heappushpop(L[1], a)
			heapq.heappush(L[0], -t)
		else:
			heapq.heappush(L[0], -a)
			heapq.heappush(L[1], a)

def print_min(L, M):
	print(-1 * L[0][0], sum(M))

def main():
	Q = int(input())
	L = [[], []]
	M = [0, 0]
	for q in range(Q):
		S = read_list()
		if S[0] == 1:
			update(S, L, M)
		else:
			print_min(L, M)
main()


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
q = int(input())
queries = [tuple(map(int, input().split())) for i in range(q)]
INF = 10 ** 12
small = Heapq([-INF], desc=True)
large = Heapq([INF])
fx_min = queries[0][2]
median = queries[0][1]
k = 0
for query in queries[1:]:
	if query[0] == 1:
		k += 1
		(a, b) = (query[1], query[2])
		fx_min += abs(median - a) + b
		(small_max, large_min) = (small.top(), large.top())
		if k % 2:
			if a <= median:
				small.push(a)
				large.push(median)
				median = small.top()
			else:
				small.push(median)
				large.push(a)
		elif a <= small_max:
			small.pop()
			small.push(a)
		elif small_max < a <= large_min:
			fx_min -= abs(median - a)
			median = a
		else:
			large.push(a)
			newmed = large.pop()
			fx_min -= abs(median - newmed)
			median = newmed
	else:
		print(median, fx_min)


import heapq
Q = int(input())
L = []
R = []
B = 0
n = 0
res = 0
for _ in range(1, Q + 1):
	q = input()
	if q == '2':
		print(-L[0], res + B)
	else:
		n += 1
		(t, a, b) = map(int, q.split())
		B += b
		if len(L) == 0 or a <= -L[0]:
			heapq.heappush(L, -a)
			res += -L[0] - a
		else:
			heapq.heappush(R, a)
			res += a + L[0]
		if len(R) > len(L):
			res -= R[0] + L[0]
			heapq.heappush(L, -heapq.heappop(R))
		elif len(L) - len(R) >= 2:
			heapq.heappush(R, -heapq.heappop(L))


import heapq
Q = int(input())
ans = 0
L = []
R = []
for _ in range(Q):
	q = list(map(int, input().split()))
	if q[0] == 1:
		l = heapq.heappushpop(L, -q[1])
		r = heapq.heappushpop(R, q[1])
		heapq.heappush(L, -r)
		heapq.heappush(R, -l)
		ans += abs(l + r) + q[2]
	else:
		print(-L[0], ans)


from heapq import heappush as hp, heappushpop as hppp
import sys
Q = int(input())
sumis = 0
sumib = 0
S = []
B = []
geta = 0
k = 0
med = 0
for _ in range(Q):
	q = sys.stdin.readline().split()
	if q[0] == '1':
		k += 1
		m = int(q[1])
		geta += int(q[2])
		if k % 2 == 1:
			if med < m:
				x = hppp(B, m)
				sumib += m - x
				hp(S, -x)
				sumis += x
			else:
				hp(S, -m)
				sumis += m
		elif med < m:
			hp(B, m)
			sumib += m
		else:
			x = -hppp(S, -m)
			sumis += m - x
			hp(B, x)
			sumib += x
		med = -S[0]
	else:
		print(med, geta + med * (k % 2) - sumis + sumib)


from heapq import *
q = int(input())
b_cur = 0
diff = 0
(lefts, rights) = ([], [])
for i in range(q):
	query = input()
	if len(query) > 1:
		(_, a, b) = map(int, query.split())
		b_cur += b
		if len(lefts) == 0:
			heappush(lefts, -a)
		else:
			diff += abs(a + lefts[0])
			if a <= -lefts[0]:
				heappush(lefts, -a)
			else:
				heappush(rights, a)
		if len(lefts) < len(rights):
			med_r = heappop(rights)
			med_l = -lefts[0]
			diff += med_l - med_r
			heappush(lefts, -med_r)
		elif len(lefts) > len(rights) + 1:
			med_l = -heappop(lefts)
			med_r = rights[0] if len(rights) > 0 else 0
			heappush(rights, med_l)
	else:
		print(-lefts[0], b_cur + diff)


from heapq import heappush, heappop
num_q = int(input())
x = 0
f = 0
low = []
high = []
odd = False
num_a = 0
for _ in range(num_q):
	q = input()
	if q[0] == '2':
		print(x, f)
	else:
		(_, n, m) = map(int, q.split(' '))
		if odd:
			if n >= -low[0]:
				f += m + n + low[0]
				heappush(high, n)
			else:
				f += m - n - low[0]
				heappush(low, -n)
				heappush(high, -heappop(low))
		else:
			f += m
			if num_a == 0:
				heappush(low, -n)
			elif n > -low[0]:
				if n > high[0]:
					f += n - high[0]
				heappush(high, n)
				heappush(low, -heappop(high))
			else:
				f += -n - low[0]
				heappush(low, -n)
		odd = ~odd
		x = -low[0]
		num_a += 1


Q = int(input())
Query = [list(map(int, input().split())) for _ in range(Q)]
import heapq
L = []
R = []
pop = heapq.heappop
push = heapq.heappush
(A, B, C) = (0, 0, 0)

def nasu(a):
	global A
	global C
	if len(R) == 0:
		push(R, a)
		C = a
		return
	if len(L) == 0:
		r = pop(R)
		push(L, -min(a, r))
		push(R, max(a, r))
		A += abs(a - r)
		C = min(a, r)
		return
	if len(L) < len(R):
		r = pop(R)
		l = -pop(L)
		push(L, -l)
		push(L, -min(a, r))
		push(R, max(a, r))
		A += abs(a - r)
		if a < l:
			C = l
		elif a < r:
			C = a
		return
	l = -pop(L)
	r = pop(R)
	if l <= a and a <= r:
		push(L, -l)
		push(R, r)
		push(R, a)
		C = a
	elif a < l:
		push(L, -a)
		push(R, r)
		push(R, l)
		A += abs(a - l)
		C = l
	else:
		push(L, -l)
		push(R, a)
		push(R, r)
		A += abs(a - r)
		C = r
for q in Query:
	if q[0] == 1:
		nasu(q[1])
		B += q[2]
	if q[0] == 2:
		print(C, A + B)


import heapq
n = int(input())
hq1 = []
hq2 = []
ans = 0
for _ in range(n):
	q = list(map(int, input().split()))
	if q[0] == 1:
		heapq.heappush(hq1, q[1] * -1)
		heapq.heappush(hq2, q[1])
		hq1max = heapq.heappop(hq1) * -1
		hq2min = heapq.heappop(hq2)
		heapq.heappush(hq1, hq2min * -1)
		heapq.heappush(hq2, hq1max)
		ans += abs(hq1max - hq2min) + q[2]
	if q[0] == 2:
		hq1max = heapq.heappop(hq1) * -1
		heapq.heappush(hq1, hq1max * -1)
		print(hq1max, ans)


from heapq import heappop, heappush, heappushpop
n = int(input())
q = [tuple((int(x) for x in input().split())) for _ in range(n)]
L = []
R = []
a = 1
b = q[0][2]
ans = 0
heappush(L, -q[0][1])
for i in range(1, n):
	temp = q[i]
	if temp[0] == 1:
		a += 1
		if a % 2 == 0:
			ans += abs(temp[1] + L[0])
			p = heappushpop(L, -temp[1])
			heappush(R, -p)
		else:
			ans += abs(temp[1] + L[0])
			tl = L[0]
			p = heappushpop(R, temp[1])
			heappush(L, -p)
			if tl != L[0]:
				ans -= abs(tl - L[0])
		b += temp[2]
	else:
		m = -L[0]
		print(m, ans + b)


import heapq
n = int(input())
l = [10 ** 10]
r = [10 ** 10]
heapq.heapify(l)
heapq.heapify(r)
lenl = 0
lenr = 0
ans = 0
for i in range(n):
	q = list(map(int, input().split()))
	if q[0] == 1:
		ans += q[2]
		if lenl > lenr:
			lenr += 1
			x = -l[0]
			ans += abs(x - q[1])
			if x <= q[1]:
				heapq.heappush(r, q[1])
			else:
				heapq.heappush(r, x)
				heapq.heapreplace(l, -q[1])
		else:
			lenl += 1
			x = r[0]
			if x < q[1]:
				heapq.heappush(l, -x)
				heapq.heapreplace(r, q[1])
			else:
				heapq.heappush(l, -q[1])
			ans += abs(-l[0] - q[1])
	if q[0] == 2:
		print(-l[0], ans)


q = int(input())
import sys
input = sys.stdin.readline
from heapq import heappop, heappush
left = []
right = []
lsum = 0
rsum = 0
q1_num = 0
b = 0
for _ in range(q):
	qs = tuple(map(int, input().split()))
	if qs[0] == 1:
		b += qs[2]
		if q1_num == 0:
			heappush(left, qs[1] * -1)
			lsum += qs[1]
			q1_num += 1
			continue
		elif q1_num % 2 == 1:
			tmp = heappop(left) * -1
			lsum -= tmp
		else:
			tmp = heappop(right)
			rsum -= tmp
		less = min(tmp, qs[1])
		more = max(tmp, qs[1])
		heappush(left, less * -1)
		heappush(right, more)
		lsum += less
		rsum += more
		q1_num += 1
	else:
		num = rsum - lsum + b
		tmp = heappop(left) * -1
		if q1_num % 2 == 1:
			num += tmp
		heappush(left, tmp * -1)
		print(' '.join(map(str, [tmp, num])))


def main():
	from heapq import heappop, heappush
	import sys
	input = sys.stdin.readline
	Q = int(input())
	left = []
	right = []
	sum_l = 0
	sum_r = 0
	cnt = 0
	b = 0
	for _ in range(Q):
		query = map(int, input().split())
		t = next(query)
		if t == 1:
			(x, b_) = query
			b += b_
			cnt += 1
			if cnt % 2 == 0:
				heappush(left, -x)
				sum_l += x
				x = -heappop(left)
				sum_l -= x
				heappush(right, x)
				sum_r += x
			else:
				heappush(right, x)
				sum_r += x
				x = heappop(right)
				sum_r -= x
				heappush(left, -x)
				sum_l += x
		else:
			x = -left[0]
			ans = b + sum_r - sum_l + x * (cnt % 2)
			print(x, ans)
main()


from heapq import heappop
from heapq import heappush
q = int(input())
(L, R) = ([], [])
b_sum = 0
(l_sum, r_sum) = (0, 0)
count = 0
mid = 0
for _ in range(q):
	Q = list(map(int, input().split()))
	if Q[0] == 1:
		(a, b) = (Q[1], Q[2])
		count += 1
		b_sum += b
		if count == 1:
			mid = a
		elif count % 2 == 0:
			if a <= mid:
				heappush(L, -a)
				l_sum += a
				heappush(R, mid)
				r_sum += mid
			else:
				heappush(L, -mid)
				l_sum += mid
				heappush(R, a)
				r_sum += a
		else:
			(l, r) = (-heappop(L), heappop(R))
			if a < l:
				heappush(L, -a)
				l_sum += a - l
				mid = l
				heappush(R, r)
			elif r < a:
				heappush(L, -l)
				mid = r
				heappush(R, a)
				r_sum += a - r
			else:
				heappush(L, -l)
				mid = a
				heappush(R, r)
	elif count % 2 == 1:
		print(mid, r_sum - l_sum + b_sum)
	else:
		l = -heappop(L)
		print(l, r_sum - l_sum + b_sum)
		heappush(L, -l)


import sys
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
q = int(input())
import heapq
L = []
R = []
heapq.heapify(L)
heapq.heapify(R)
B = 0
for i in range(q):
	query = list(map(int, input().split()))
	if query[0] == 1:
		(a, b) = (query[1], query[2])
		B += b
		heapq.heappush(L, -a)
		heapq.heappush(R, a)
		if -L[0] > R[0]:
			l = -heapq.heappop(L)
			r = heapq.heappop(R)
			B += l - r
			heapq.heappush(L, -r)
			heapq.heappush(R, l)
	else:
		print(-L[0], B)


from heapq import heappush, heappop
import sys
input = sys.stdin.readline
q = int(input())
a_sum = b_sum = 0
INF = 10 ** 10
queue_l = [INF]
queue_r = [INF]
for i in range(q):
	s = input()
	if s[0] == '1':
		(_, a, b) = map(int, s.split())
		ql_max = -queue_l[0]
		qr_min = queue_r[0]
		if a < ql_max:
			heappop(queue_l)
			heappush(queue_l, -a)
			heappush(queue_l, -a)
			heappush(queue_r, ql_max)
			a_sum += ql_max - a
		elif a > qr_min:
			heappop(queue_r)
			heappush(queue_r, a)
			heappush(queue_r, a)
			heappush(queue_l, -qr_min)
			a_sum += a - qr_min
		else:
			heappush(queue_l, -a)
			heappush(queue_r, a)
		b_sum += b
	else:
		ql_max = -queue_l[0]
		print(ql_max, a_sum + b_sum)


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 sys, heapq
input = sys.stdin.readline

def main():
	q = int(input())
	big = [10 ** 10]
	sma = [10 ** 10]
	sb = 0
	ss = 0
	rr = 0
	for _ in [None] * q:
		m = tuple(map(int, input().split()))
		if m[0] == 1:
			a = m[1]
			rr += m[2]
			if big[0] <= a:
				heapq.heappush(big, a)
				sb += a
			elif -sma[0] >= a:
				heapq.heappush(sma, -a)
				ss += a
			elif len(sma) >= len(big):
				heapq.heappush(sma, -a)
				ss += a
			else:
				heapq.heappush(big, a)
				sb += a
			while len(big) > len(sma) + 1:
				p = heapq.heappop(big)
				heapq.heappush(sma, -p)
				ss += p
				sb -= p
			while len(sma) > len(big) + 1:
				p = -heapq.heappop(sma)
				heapq.heappush(big, p)
				sb += p
				ss -= p
		else:
			if len(big) > len(sma):
				mid = big[0]
			else:
				mid = -sma[0]
			print(mid, sb - mid * (len(big) - 1) + mid * (len(sma) - 1) - ss + rr)
main()


import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from heapq import heappush, heappop
Q = int(readline())
query = (tuple(map(int, line.split())) for line in readlines())
INF = 10 ** 12
L = [INF]
R = [INF]
SL = 0
SR = 0

def pushL(x):
	global SL
	heappush(L, -x)
	SL += x

def popL():
	global SL
	x = -heappop(L)
	SL -= x
	return x

def pushR(x):
	global SR
	heappush(R, x)
	SR += x

def popR():
	global SR
	x = heappop(R)
	SR -= x
	return x
add = 0
answer = []
for q in query:
	if len(q) == 1:
		x = -L[0]
		f = SR - SL + x * (len(L) - len(R))
		answer.append('{} {}'.format(x, f + add))
		continue
	(a, b) = q[1:]
	add += b
	b = popL()
	c = popR()
	(a, b, c) = sorted([a, b, c])
	pushL(a)
	pushR(c)
	if len(L) > len(R):
		pushR(b)
	else:
		pushL(b)
print('\n'.join(answer))


from heapq import heappush, heappop
Q = int(input())
X = [list(map(int, input().split())) for _ in range(Q)]
left_q = []
right_q = []
q_sum = 0
const = 0
for (q, *w) in X:
	if q == 1:
		(x, y) = w
		const += y
		if len(left_q) == 0 or x <= -left_q[0]:
			heappush(left_q, -x)
			q_sum += -left_q[0] - x
		else:
			heappush(right_q, x)
			q_sum += left_q[0] + x
		if len(right_q) > len(left_q):
			q_sum += -right_q[0] - left_q[0]
			heappush(left_q, -heappop(right_q))
		if len(left_q) - len(right_q) == 2:
			heappush(right_q, -heappop(left_q))
	else:
		print(-left_q[0], q_sum + const)


import heapq
Q = int(input())
(left, right) = ([], [])
(Lsum, Rsum) = (0, 0)
(Lcnt, Rcnt) = (0, 0)
B = 0
for _ in range(Q):
	q = list(map(int, input().split()))
	if len(q) == 1:
		l = -1 * heapq.heappop(left)
		heapq.heappush(left, -1 * l)
		print(l, Rsum // 2 - Lsum // 2 + B)
	else:
		(_, a, b) = q
		B += b
		heapq.heappush(left, -1 * a)
		heapq.heappush(right, a)
		Lsum += a
		Lcnt += 1
		Rsum += a
		Rcnt += 1
		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 sys

def main():
	input = sys.stdin.readline
	q = int(input())
	Q = [tuple(map(int, input().split())) for _ in range(q)]
	asum = bsum = 0
	from heapq import heappop, heappush
	(s, l) = ([], [])
	mn = 0
	for query in Q:
		if query[0] == 1:
			(a, b) = (query[1], query[2])
			bsum += b
			E = [a, a]
			(smx, lmn) = (a, a)
			if s:
				smx = -heappop(s)
				E.append(smx)
			if l:
				lmn = heappop(l)
				E.append(lmn)
			if a < smx:
				mn += smx - a
			elif lmn < a:
				mn += a - lmn
			E.sort()
			for i in range(len(E) // 2):
				heappush(s, -E[i])
				heappush(l, E[-1 - i])
		else:
			print(-s[0], mn + bsum)
main()


import heapq

def main():
	Q = int(input())
	(hs, hl) = ([], [])
	(ss, sl) = (0, 0)
	B = 0
	for _ in range(Q):
		q = input()
		if q == '2':
			x = -hs[0]
			print(x, x * (len(hs) - len(hl)) + sl - ss + B)
			continue
		(_, a, b) = map(int, q.split())
		B += b
		if hl and a >= hl[0]:
			heapq.heappush(hl, a)
			sl += a
		else:
			heapq.heappush(hs, -a)
			ss += a
		if len(hl) > len(hs):
			while len(hl) > len(hs):
				a = heapq.heappop(hl)
				sl -= a
				heapq.heappush(hs, -a)
				ss += a
		else:
			while len(hs) - len(hl) > 1:
				a = -heapq.heappop(hs)
				ss -= a
				heapq.heappush(hl, a)
				sl += a
main()


import sys
input = sys.stdin.readline
import heapq
MIN = []
MAX = []
ANS = 0
SCORE = 0
Queries = int(input())
for i in range(Queries):
	Q = list(map(int, input().split()))
	if Q[0] == 1:
		ANS += Q[2]
		heapq.heappush(MIN, Q[1])
		heapq.heappush(MAX, -Q[1])
		if MIN[0] < -MAX[0]:
			x = heapq.heappop(MIN)
			y = -heapq.heappop(MAX)
			SCORE += y - x
			heapq.heappush(MIN, y)
			heapq.heappush(MAX, -x)
	else:
		print(-MAX[0], ANS + SCORE)


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):
	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 sys, heapq
F = sys.stdin

def single_input():
	return F.readline().strip('\n')

def line_input():
	return F.readline().strip('\n').split()

def solve():
	Q = int(single_input())
	(n, a, b) = map(int, line_input())
	(left, right) = ([-a], [a])
	heapq.heapify(left)
	heapq.heapify(right)
	minans = b
	ans = ''
	for i in range(1, Q):
		queri = [int(i) for i in line_input()]
		if queri[0] == 1:
			(a, b) = queri[1:]
			minans += b
			if -1 * left[0] <= a <= right[0]:
				heapq.heappush(left, -a)
				heapq.heappush(right, a)
			elif a < -1 * left[0]:
				minans += -1 * left[0] - a
				heapq.heappush(left, -a)
				heapq.heappush(left, -a)
				heapq.heappush(right, -1 * heapq.heappop(left))
			else:
				minans += a - right[0]
				heapq.heappush(left, -1 * heapq.heappop(right))
				heapq.heappush(right, a)
				heapq.heappush(right, a)
		else:
			ans += str(-1 * left[0]) + ' ' + str(minans) + '\n'
	print(ans)
	return 0
solve()


from heapq import heappop, heappush

class Medians:

	def __init__(self):
		self.left = []
		self.right = []
		self.size_l = 0
		self.size_r = 0
		self.sum_l = 0
		self.sum_r = 0

	def add(self, n):
		if self.size_l > self.size_r:
			t = -self.left[0]
			if n >= t:
				heappush(self.right, n)
				self.sum_r += n
			else:
				heappop(self.left)
				self.sum_l -= t
				heappush(self.left, -n)
				self.sum_l += n
				heappush(self.right, t)
				self.sum_r += t
			self.size_r += 1
		else:
			if not self.size_l:
				heappush(self.left, -n)
				self.sum_l += n
			else:
				t = self.right[0]
				if n <= t:
					heappush(self.left, -n)
					self.sum_l += n
				else:
					heappop(self.right)
					self.sum_r -= t
					heappush(self.right, n)
					self.sum_r += n
					heappush(self.left, -t)
					self.sum_l += t
			self.size_l += 1

	def get(self):
		return -self.left[0]

def solve():
	Q = int(input())
	s = 0
	med = Medians()
	for _ in range(Q):
		(q, *l) = map(int, input().split())
		if q == 1:
			(a, b) = l
			s += b
			med.add(a)
		else:
			m = med.get()
			d1 = med.size_l - med.size_r
			d2 = med.sum_r - med.sum_l
			print(m, m * d1 + d2 + s)
solve()


from heapq import heapify, heappush, heappop
import sys
input = sys.stdin.readline
Q = int(input())
query = []
(sumL, sumR) = ([], [])
ans = 0
for _ in range(Q):
	a = list(map(int, input().split()))
	if a[0] == 1:
		ans += a[2]
		if len(sumL) == 0 or a[1] <= -sumL[0]:
			heappush(sumL, -a[1])
			ans += -sumL[0] - a[1]
		else:
			heappush(sumR, a[1])
			ans += sumL[0] + a[1]
		if len(sumR) > len(sumL):
			ans -= sumR[0] + sumL[0]
			heappush(sumL, -heappop(sumR))
		elif len(sumL) - len(sumR) >= 2:
			heappush(sumR, -heappop(sumL))
	else:
		print(-sumL[0], ans)


import sys
input = sys.stdin.readline
from collections import defaultdict

def compress(l):
	l = list(set(l))
	l.sort()
	d1 = defaultdict(int)
	d2 = defaultdict(int)
	for i in range(len(l)):
		d1[l[i]] = i
		d2[i] = l[i]
	return (d1, d2)

class BIT:

	def __init__(self, n):
		self.n = n
		self.bit = [0] * (n + 1)

	def acc(self, i):
		i += 1
		s = 0
		while i > 0:
			s += self.bit[i]
			i -= i & -i
		return s

	def add(self, i, x):
		i += 1
		while i <= self.n:
			self.bit[i] += x
			i += i & -i

def binary_search(c):
	(l, r) = (0, L - 1)
	while l <= r:
		m = (l + r) // 2
		if bit.acc(m) >= (c + 1) // 2:
			r = m - 1
		else:
			l = m + 1
	return l
Q = int(input())
que = []
l = []
for _ in range(Q):
	que_i = tuple(map(int, input().split()))
	if len(que_i) == 3:
		l.append(que_i[1])
	que.append(que_i)
(d1, d2) = compress(l)
L = len(list(d1.keys()))
bit = BIT(L)
bit2 = BIT(L)
cnt = 0
b_acc = 0
for que_i in que:
	if len(que_i) == 3:
		(a, b) = (que_i[1], que_i[2])
		bit.add(d1[a], 1)
		bit2.add(d1[a], a)
		b_acc += b
		cnt += 1
	else:
		med_idx = binary_search(cnt)
		med = d2[med_idx]
		s = bit.acc(med_idx) * med - bit2.acc(med_idx) + (bit2.acc(L - 1) - bit2.acc(med_idx)) - (bit.acc(L - 1) - bit.acc(med_idx)) * med
		s += b_acc
		print(med, s)


from heapq import *
q = int(input())
sum_a = 0
sum_b = 0
L = []
R = []
for _ in range(q):
	qi = list(map(int, input().split()))
	if qi[0] == 1:
		a = qi[1]
		heappush(L, -a)
		heappush(R, a)
		if -L[0] > R[0]:
			LtoR = -heappop(L)
			RtoL = heappop(R)
			sum_a += LtoR - RtoL
			heappush(L, -RtoL)
			heappush(R, LtoR)
		sum_b += qi[2]
	else:
		print(-L[0], sum_a + sum_b)


import heapq
Q = int(input())
INF = 2 * 10 ** 9
(a1, a2) = ([INF], [INF])
asum1 = 0
asum2 = 0
bsum = 0
for i in range(Q):
	query = list(map(int, input().split()))
	if query[0] == 3:
		break
	if query[0] == 1:
		(a, b) = query[1:]
		bsum += b
		if len(a1) == len(a2):
			if -a1[0] > a:
				asum1 += a
				heapq.heappush(a1, -a)
			else:
				asum2 += a
				heapq.heappush(a2, a)
				asum1 += a2[0]
				asum2 -= a2[0]
				heapq.heappush(a1, -heapq.heappop(a2))
		elif a2[0] < a:
			asum2 += a
			heapq.heappush(a2, a)
		else:
			asum1 += a
			heapq.heappush(a1, -a)
			asum2 += -a1[0]
			asum1 -= -a1[0]
			heapq.heappush(a2, -heapq.heappop(a1))
	else:
		m = -a1[0]
		print(m, m * (len(a1) - 1) - asum1 + asum2 - m * (len(a2) - 1) + bsum)


import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

class Bit:

	def __init__(self, n):
		self.size = n
		self.tree = [0] * (n + 1)
		self.depth = n.bit_length()

	def sum(self, i):
		s = 0
		while i > 0:
			s += self.tree[i]
			i -= i & -i
		return s

	def add(self, i, x):
		while i <= self.size:
			self.tree[i] += x
			i += i & -i

	def lower_bound(self, x):
		sum_ = 0
		pos = 0
		for i in range(self.depth, -1, -1):
			k = pos + (1 << i)
			if k <= self.size and sum_ + self.tree[k] < x:
				sum_ += self.tree[k]
				pos += 1 << i
		return pos + 1

def compress(list1):
	list2 = sorted(set(list1))
	memo = {value: index for (index, value) in enumerate(list2)}
	return (memo, len(list2))
q = int(readline())
L = [list(map(int, readline().split())) for i in range(q)]
chk = []
for i in range(q):
	if L[i][0] == 1:
		chk.append(L[i][1])
(memo, len_memo) = compress(chk)
memo_inv = dict([(v, k) for (k, v) in memo.items()])
bit = Bit(len_memo)
num = Bit(len_memo)
s = 0
cnt = 0
for i in range(q):
	que = L[i]
	if que[0] == 1:
		(a, b, c) = que
		s += c
		cnt += 1
		bit.add(memo[b] + 1, b)
		num.add(memo[b] + 1, 1)
	else:
		d = num.lower_bound((cnt + 1) // 2)
		m = memo_inv[d - 1]
		sum1 = bit.sum(d)
		num1 = num.sum(d)
		sum2 = bit.sum(len_memo) - bit.sum(d)
		num2 = num.sum(len_memo) - num.sum(d)
		print(m, abs(num1 * m - sum1) + abs(num2 * m - sum2) + s)


import heapq

class DynamicMedian:

	def __init__(self):
		self.left_q = []
		self.right_q = []
		self.left_sum = 0
		self.right_sum = 0

	def add(self, val):
		if len(self.left_q) == len(self.right_q):
			self.left_sum += val
			val = -heapq.heappushpop(self.left_q, -val)
			self.left_sum -= val
			heapq.heappush(self.right_q, val)
			self.right_sum += val
		else:
			self.right_sum += val
			val = heapq.heappushpop(self.right_q, val)
			self.right_sum -= val
			heapq.heappush(self.left_q, -val)
			self.left_sum += val

	def median_low(self):
		if len(self.left_q) + 1 == len(self.right_q):
			return self.right_q[0]
		else:
			return -self.left_q[0]

	def median_high(self):
		return self.right_q[0]
q = int(input())
info = [list(map(int, input().split())) for i in range(q)]
dm = DynamicMedian()
b = 0
for i in range(q):
	if info[i][0] == 1:
		(_, tmp_a, tmp_b) = info[i]
		dm.add(tmp_a)
		b += tmp_b
	else:
		med = dm.median_high()
		lsum = dm.left_sum
		rsum = dm.right_sum
		lnum = len(dm.left_q)
		rnum = len(dm.right_q)
		tmp = lnum * med - lsum + (rsum - rnum * med)
		print(dm.median_low(), tmp + b)


from heapq import heappush, heappop
import sys
readline = sys.stdin.readline
ans = []
Q = int(readline())
QL = [10 ** 10]
QR = [10 ** 10]
R = 0
for i in range(Q):
	(t, *A) = map(int, input().split())
	if t == 1:
		(a, b) = A
		R += b
		if -QL[0] <= a <= QR[0]:
			heappush(QL, -a)
			heappush(QR, a)
		elif a <= -QL[0]:
			heappush(QL, -a)
			heappush(QL, -a)
			c = heappop(QL)
			R -= c + a
			heappush(QR, -c)
		elif QR[0] <= a:
			heappush(QR, a)
			heappush(QR, a)
			c = heappop(QR)
			R += a - c
			heappush(QL, -c)
	else:
		ans.append('%d %d\n' % (-QL[0], R))
sys.stdout.writelines(ans)


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()


def main():
	import heapq
	left = [10 ** 20]
	right = [10 ** 20]
	heapq.heapify(left)
	heapq.heapify(right)
	q = int(input())
	ans = 0
	cnt = 0
	left_sum = 0
	right_sum = 0
	for _ in range(q):
		temp = input()
		if temp[0] == '1':
			cnt += 1
			(x, a, b) = map(int, temp.split())
			l = -heapq.heappop(left)
			r = heapq.heappop(right)
			left_sum -= l
			right_sum -= r
			ans += b
			(ll, aa, rr) = sorted([l, a, r])
			heapq.heappush(right, rr)
			right_sum += rr
			heapq.heappush(left, -ll)
			left_sum += ll
			if len(left) == len(right):
				heapq.heappush(left, -aa)
				left_sum += aa
			else:
				heapq.heappush(right, aa)
				right_sum += aa
		else:
			i = -heapq.heappop(left)
			left_sum -= i
			print(i, ans + (right_sum - (len(right) - 1) * i) + ((len(left) - 1) * i - left_sum))
			heapq.heappush(left, -i)
			left_sum += i
main()


from heapq import heappop, heappush
n = int(input())
(_, a, b) = map(int, input().split())
l = []
r = []
med_val = a
sum_l = 0
sum_r = 0
sum_b = b
for _ in range(n - 1):
	query = input().split()
	if query[0] == '1':
		(_, a, b) = map(int, query)
		if len(l) < len(r):
			if a <= med_val:
				heappush(l, -a)
				sum_l += a
			else:
				heappush(l, -med_val)
				sum_l += med_val
				heappush(r, a)
				sum_r += a
				med_val = heappop(r)
				sum_r -= med_val
		elif med_val < a:
			heappush(r, a)
			sum_r += a
		else:
			heappush(r, med_val)
			sum_r += med_val
			heappush(l, -a)
			sum_l += a
			med_val = -heappop(l)
			sum_l -= med_val
		sum_b += b
	else:
		f = len(l) * med_val - sum_l + sum_r - len(r) * med_val + sum_b
		print('{} {}'.format(med_val, f))


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

class Binary_Indexed_Tree:

	def __init__(self, n):
		self.n = n
		self.data = [0] * (n + 1)

	def add(self, i, x):
		i += 1
		while i <= self.n:
			self.data[i] += x
			i += i & -i

	def sum(self, i):
		i += 1
		ret = 0
		while i:
			ret += self.data[i]
			i &= i - 1
		return ret

	def sum_range(self, l, r):
		return self.sum(r) - self.sum(l - 1)

	def lower_bound(self, w):
		if w <= 0:
			return 0
		i = 0
		k = 1 << self.n.bit_length()
		while k:
			if i + k <= self.n and self.data[i + k] < w:
				w -= self.data[i + k]
				i += k
			k >>= 1
		return i
q = int(input())
query = [list(map(int, input().split())) for i in range(q)]
a_set = sorted(set((i[1] for i in query if len(i) > 1)))
n = len(a_set)
dd = {j: i + 1 for (i, j) in enumerate(a_set)}
cnt_bit = Binary_Indexed_Tree(n + 2)
sum_bit = Binary_Indexed_Tree(n + 2)
offset = 0
cnt = 0
for i in query:
	if len(i) == 1:
		left = cnt // 2 + cnt % 2
		right = cnt - left
		j = cnt_bit.lower_bound(left)
		x = a_set[j - 1]
		ans = offset
		left_cnt = cnt_bit.sum_range(0, j - 1)
		ans -= sum_bit.sum_range(0, j - 1)
		ans += left_cnt * x
		right_cnt = cnt_bit.sum_range(j + 1, n + 1)
		ans += sum_bit.sum_range(j + 1, n + 1)
		ans -= right_cnt * x
		print(x, ans)
	else:
		(_, a, b) = i
		cnt_bit.add(dd[a], 1)
		sum_bit.add(dd[a], a)
		offset += b
		cnt += 1


import heapq
Q = int(input())
L = []
R = []
ans = []
min = 0
for _ in range(Q):
	(q, *c) = map(int, input().split())
	if q == 1:
		(a, b) = c
		min += b
		heapq.heappush(L, -a)
		heapq.heappush(R, a)
		if -L[0] > R[0]:
			x = -heapq.heappop(L)
			y = heapq.heappop(R)
			heapq.heappush(L, -y)
			heapq.heappush(R, x)
			min += abs(x - y)
	else:
		ans.append((-L[0], min))
for x in ans:
	print(*x)


import heapq
Q = int(input())
A_left_sum = 0
A_left = []
A_right_sum = 0
A_right = []
A_med = None
query_size = 0
b_sum = 0
for i in range(Q):
	query = list(map(int, input().split()))
	if query[0] == 1:
		a = query[1]
		if A_med is None:
			A_med = a
		elif query_size % 2 == 0:
			left_max = -A_left[0]
			right_min = A_right[0]
			if a < left_max:
				heapq.heappushpop(A_left, -a)
				A_left_sum += a - left_max
				A_med = left_max
			elif a > right_min:
				heapq.heappushpop(A_right, a)
				A_right_sum += a - right_min
				A_med = right_min
			else:
				A_med = a
		elif A_med <= a:
			heapq.heappush(A_left, -A_med)
			heapq.heappush(A_right, a)
			A_left_sum += A_med
			A_right_sum += a
		else:
			heapq.heappush(A_left, -a)
			heapq.heappush(A_right, A_med)
			A_right_sum += A_med
			A_left_sum += a
		query_size += 1
		b_sum += query[2]
	elif query_size % 2 == 0:
		print(-A_left[0], A_right_sum - A_left_sum + b_sum)
	else:
		print(A_med, A_right_sum - A_left_sum + b_sum)


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)


def main():
	from heapq import heappush, heappop, heappushpop
	import sys
	input = sys.stdin.readline

	class Median:

		def __init__(self):
			self.b = 0
			self.l = []
			self.sum_l = 0
			self.r = []
			self.sum_r = 0

		def update(self, a: int, b: int) -> None:
			self.b += b
			size = len(self.l) + len(self.r)
			if size % 2 == 0:
				x = heappushpop(self.r, a)
				self.sum_r += a - x
				heappush(self.l, -x)
				self.sum_l += x
			else:
				x = heappushpop(self.l, -a)
				self.sum_l += a + x
				heappush(self.r, -x)
				self.sum_r -= x

		def query(self):
			median = -self.l[0]
			ret = abs(len(self.l) * median - self.sum_l) + abs(self.sum_r - len(self.r) * median) + self.b
			return (median, ret)
	med = Median()
	n = int(input())
	for _ in range(n):
		q = iter(input().rstrip().split())
		if next(q) == '1':
			med.update(*map(int, q))
		else:
			print(*med.query())
main()


Q = int(input())
ans = 0
from heapq import heappush, heappop
left = []
right = []
L = -1 * float('inf')
R = float('inf')
for i in range(Q):
	q = input()
	if q == '2':
		print(' '.join([str(L), str(ans)]))
	else:
		(s, a, b) = map(int, q.split())
		ans += b
		if L <= a <= R:
			heappush(left, -1 * a)
			heappush(right, a)
			L = a
			R = a
		elif a < L:
			ans += L - a
			x = heappop(left)
			heappush(right, -1 * x)
			heappush(left, -1 * a)
			heappush(left, -1 * a)
		elif R < a:
			ans += a - R
			x = heappop(right)
			heappush(left, -1 * x)
			heappush(right, a)
			heappush(right, a)
		R = right[0]
		L = -1 * left[0]


import sys
from heapq import heappush, heappop, heapify
INF = float('inf')

def main():
	Q = int(input())
	bottom = [INF]
	top = [INF]
	bottom_total = 0
	top_total = 0
	btot = 0
	for i in range(Q):
		q = input()
		if q[0] == '1':
			(_, a, b) = map(int, q.split())
			btot += b
			if top[0] < a:
				heappush(top, a)
				top_total += a
			elif -bottom[0] < a:
				heappush(bottom, -a)
				bottom_total += a
			else:
				heappush(bottom, -a)
				bottom_total += a
			while len(top) - len(bottom) > 0:
				heappush(bottom, -top[0])
				bottom_total += top[0]
				top_total -= heappop(top)
			while len(bottom) - len(top) > 1:
				heappush(top, -bottom[0])
				top_total += -bottom[0]
				bottom_total -= -heappop(bottom)
		else:
			tot = btot
			tot += len(bottom) * -bottom[0] - bottom_total
			tot += top_total - len(top) * -bottom[0]
			print(-bottom[0], tot)
	return
main()


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)


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)


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()


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 heappop, heappush
import sys
input = sys.stdin.readline

class median_o1:

	def __init__(self):
		self.count = 0
		self.al = []
		self.ar = []
		self.sl = 0
		self.sr = 0
		self.b = 0

	def update_b(self, b):
		self.b += b

	def insert(self, x):
		if self.count % 2 == 0:
			if self.count == 0:
				heappush(self.al, -x)
				self.sl += x
			else:
				t = heappop(self.ar)
				self.sr -= t
				(tl, tr) = (min(x, t), max(x, t))
				heappush(self.al, -tl)
				self.sl += tl
				heappush(self.ar, tr)
				self.sr += tr
		else:
			t = heappop(self.al)
			t *= -1
			self.sl -= t
			(tl, tr) = (min(x, t), max(x, t))
			heappush(self.ar, tr)
			self.sr += tr
			heappush(self.al, -tl)
			self.sl += tl
		self.count += 1

	def get_median(self):
		return -self.al[0]

	def calc_min_value(self):
		m = self.get_median()
		return m * ((self.count + 1) // 2) - self.sl + (self.sr - m * (self.count // 2)) + self.b
q = int(input())
m = median_o1()
for _ in range(q):
	(q_typ, *x) = map(int, input().split())
	if q_typ == 1:
		m.update_b(x[1])
		m.insert(x[0])
	else:
		print(m.get_median(), m.calc_min_value())


import sys
input = sys.stdin.readline
from collections import *

def compress(l):
	l = list(set(l))
	l.sort()
	idx = defaultdict(int)
	for i in range(len(l)):
		idx[l[i]] = i
	return idx

class BIT:

	def __init__(self, n):
		self.n = n
		self.bit = [0] * (n + 1)

	def add(self, i, x):
		i += 1
		while i <= self.n:
			self.bit[i] += x
			i += i & -i

	def acc(self, i):
		s = 0
		while i > 0:
			s += self.bit[i]
			i -= i & -i
		return s
Q = int(input())
que = []
vals = []
for _ in range(Q):
	l = list(map(int, input().split()))
	que.append(l)
	if len(l) == 3:
		vals.append(l[1])
idx = compress(vals)
rev_idx = defaultdict(int)
for (k, v) in idx.items():
	rev_idx[v] = k
N = len(list(idx.keys()))
bit1 = BIT(N)
bit2 = BIT(N)
b_acc = 0
cnt = 0
for i in range(Q):
	if len(que[i]) == 3:
		(a, b) = (que[i][1], que[i][2])
		b_acc += b
		bit1.add(idx[a], 1)
		bit2.add(idx[a], a)
		cnt += 1
	else:
		(l, r) = (0, N - 1)
		while l <= r:
			m = (l + r) // 2
			if bit1.acc(m + 1) >= (cnt + 1) // 2:
				r = m - 1
			else:
				l = m + 1
		x = l
		lsum = bit1.acc(x) * rev_idx[x] - bit2.acc(x)
		rsum = bit2.acc(N) - bit2.acc(x) - (bit1.acc(N) - bit1.acc(x)) * rev_idx[x]
		print(rev_idx[x], lsum + rsum + b_acc)


import heapq
Q = int(input())
(lefts, rights) = ([], [])
diff = 0
bsum = 0
for i in range(Q):
	query = list(map(int, input().split()))
	if query[0] == 1:
		a = query[1]
		bsum += query[2]
		if len(lefts) == 0:
			heapq.heappush(lefts, -a)
		elif a <= -lefts[0]:
			heapq.heappush(lefts, -a)
			diff -= a + lefts[0]
		else:
			heapq.heappush(rights, a)
			diff += a + lefts[0]
		if len(lefts) < len(rights):
			med = heapq.heappop(rights)
			diff -= med + lefts[0]
			heapq.heappush(lefts, -med)
		elif len(lefts) > len(rights) + 1:
			med = -heapq.heappop(lefts)
			heapq.heappush(rights, med)
	else:
		x = -lefts[0]
		fx = diff + bsum
		print(x, fx)


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 *
(L, R) = ([], [])
B = 0
(Q, *E) = open(0)
for e in E:
	if e[0] > '1':
		w = -L[0]
		print(w, B + w * (len(L) > len(R)))
	else:
		(_, a, b) = map(int, e.split())
		B += b
		if len(L) > len(R):
			B -= a
			a = -heappushpop(L, -a)
			B += a + a
			heappush(R, a)
		else:
			B += a
			a = heappushpop(R, a)
			B -= a + a
			heappush(L, -a)


import heapq
const = 0
left = []
right = []
q = int(input())
cnt = 0
left_sum = 0
right_sum = 0
for _ in range(q):
	t = list(map(int, input().split()))
	if t[0] == 1:
		(a, b) = t[1:]
		const += b
		if cnt % 2 == 0:
			if not right:
				heapq.heappush(left, -a)
				left_sum += a
				cnt += 1
				continue
			c = heapq.heappop(right)
			right_sum -= c
			if a <= c:
				heapq.heappush(left, -a)
				heapq.heappush(right, c)
				left_sum += a
				right_sum += c
			else:
				heapq.heappush(left, -c)
				heapq.heappush(right, a)
				left_sum += c
				right_sum += a
		else:
			c = heapq.heappop(left)
			left_sum += c
			if a <= -c:
				heapq.heappush(left, -a)
				heapq.heappush(right, -c)
				left_sum += a
				right_sum -= c
			else:
				heapq.heappush(left, c)
				heapq.heappush(right, a)
				left_sum -= c
				right_sum += a
		cnt += 1
	else:
		tmp = -left[0]
		print(tmp, const - left_sum + right_sum + tmp * (cnt % 2))


import sys
input = sys.stdin.readline
import heapq

def main():
	Q = int(input())
	ans = 0
	l = []
	r = []
	for _ in range(Q):
		query = list(map(int, input().split()))
		if query[0] == 1:
			ans += query[2]
			heapq.heappush(l, -query[1])
			heapq.heappush(r, query[1])
			if -l[0] > r[0]:
				l_max = -1 * heapq.heappop(l)
				r_min = heapq.heappop(r)
				ans += abs(l_max - r_min)
				heapq.heappush(l, -r_min)
				heapq.heappush(r, l_max)
		else:
			print(-l[0], ans)
main()


q = int(input())
from heapq import heappush, heappop, heapify
l = []
r = []
sl = 0
sr = 0
sb = 0
for i in range(q):
	Q = input().split()
	if len(Q) == 1:
		x = -l[0]
		print(x, x * len(l) - sl + sr - len(r) * x + sb)
		continue
	(a, b) = (int(Q[1]), int(Q[2]))
	sb += b
	if len(l) > len(r):
		heappush(r, a)
		sr += a
	else:
		heappush(l, -a)
		sl += a
	try:
		if r[0] < -l[0]:
			(x, y) = (heappop(r), -heappop(l))
			heappush(r, y)
			sr += y - x
			heappush(l, -x)
			sl += x - y
	except:
		pass


import heapq
q = int(input())
(_, a, b) = map(int, input().split())
a_large = []
a_small = [-a]
cnt_large = 0
cnt_small = 1
mean = 0
cons = b
total = 0
for i in range(q - 1):
	query = input()
	if query[0] == '1':
		(_, a, b) = map(int, query.split())
		cons = cons + b
		if a < -a_small[0]:
			heapq.heappush(a_small, -a)
			total += -(a - -a_small[0])
			cnt_small += 1
			if cnt_small > cnt_large + 1:
				old_mean = -a_small[0]
				heapq.heappush(a_large, -heapq.heappop(a_small))
				cnt_small -= 1
				cnt_large += 1
				new_mean = -a_small[0]
				total += (new_mean - old_mean) * (cnt_large - cnt_small)
		else:
			heapq.heappush(a_large, a)
			total += a - -a_small[0]
			cnt_large += 1
			if cnt_large > cnt_small:
				old_mean = -a_small[0]
				heapq.heappush(a_small, -heapq.heappop(a_large))
				cnt_small += 1
				cnt_large -= 1
				new_mean = -a_small[0]
				total += (new_mean - old_mean) * (cnt_large - cnt_small)
	else:
		x = -a_small[0]
		print(x, total + cons)


import sys
from heapq import heapify, heappop, heappush

def I():
	return int(sys.stdin.readline().rstrip())

def LI():
	return list(map(int, sys.stdin.readline().rstrip().split()))
ans = 0
(left, right) = ([], [])
heapify(left)
heapify(right)
r = 0
Q = I()
for _ in range(Q):
	q = LI()
	if q[0] == 1:
		(a, b) = q[1:]
		ans += b
		if r == 0:
			heappush(left, -a)
		elif r == 1:
			x1 = -heappop(left)
			ans += abs(a - x1)
			if x1 < a:
				(x1, a) = (a, x1)
			heappush(left, -a)
			heappush(right, x1)
		else:
			x1 = -heappop(left)
			x2 = heappop(right)
			if r % 2 == 0:
				ans += max(0, x1 - a, a - x2, 0)
				heappush(left, -x1)
				if a <= x2:
					heappush(left, -a)
					heappush(right, x2)
				else:
					heappush(left, -x2)
					heappush(right, a)
			else:
				ans += abs(x1 - a)
				heappush(right, x2)
				if a <= x1:
					heappush(left, -a)
					heappush(right, x1)
				else:
					heappush(left, -x1)
					heappush(right, a)
		r += 1
	else:
		x = -heappop(left)
		print(x, ans)
		heappush(left, -x)


import heapq
Q = int(input())
A_left = []
A_right = []
A_middle = 0
A_size = 0
MIN_SCORE = 0
for i in range(Q):
	q = input()
	if q[0] == '1':
		(dummy, a, b) = map(int, q.split())
		A_size += 1
		sabun = 0
		if A_size == 1:
			A_middle = a
			sabun = 0
		elif A_size % 2 == 0:
			if a <= A_middle:
				sabun = A_middle - a
				heapq.heappush(A_left, a * -1)
				heapq.heappush(A_right, A_middle)
			else:
				sabun = a - A_middle
				heapq.heappush(A_left, A_middle * -1)
				heapq.heappush(A_right, a)
			A_middle = 0
		elif a < A_left[0] * -1:
			sabun = A_left[0] * -1 - a
			A_middle = heapq.heappop(A_left) * -1
			heapq.heappush(A_left, a * -1)
		elif a > A_right[0]:
			sabun = a - A_right[0]
			A_middle = heapq.heappop(A_right)
			heapq.heappush(A_right, a)
		else:
			sabun = 0
			A_middle = a
		MIN_SCORE += sabun + b if A_size > 1 else b
	elif q[0] == '2':
		if A_size % 2 == 0:
			print(A_left[0] * -1, MIN_SCORE)
		else:
			print(A_middle, MIN_SCORE)


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)


from heapq import heappushpop, heappush
(left, right) = ([], [])
q = int(input())
ans = 0
for _ in range(q):
	a = list(map(int, input().split()))
	if a[0] == 1:
		left_out = heappushpop(left, -a[1])
		right_out = heappushpop(right, a[1])
		ans += a[2] + abs(left_out + right_out)
		heappush(left, -right_out)
		heappush(right, -left_out)
	else:
		print(-left[0], ans)