Problem:
Score : 600 points

Problem Statement

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 1

4
1 4 2
2
1 1 -8
2

Sample Output 1

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.

Sample Input 2

4
1 -1000000000 1000000000
1 -1000000000 1000000000
1 -1000000000 1000000000
2

Sample Output 2

-1000000000 3000000000

Solution in Julia (0.5.0) (judge verdict: Wrong Answer)

parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function heap(a::Array{Int,1})
	h = [a[1]]
	for i in 2:length(a)
		hpush(h,a[i])
	end
	h
end

function hpush(h::Array{Int,1},x)
	push!(h,x)
	l = length(h)
	if l>1
		k = l>>1
		while h[k]>x&&k>=1
			tmp = h[k]
			h[k] = x
			h[l] = tmp
			k = max(k>>1,1)
			l = l>>1
		end
	end
end

function hpop(h::Array{Int,1})
	x = h[1]
	z = pop!(h)
	if !isempty(h)
		h[1] = z
		k = 1
		l = length(h)
		while k <= l
			if 2*k>l
				break
			elseif 2*k+1>l
				if h[2*k]>=z
					break
				else
					tmp = h[2*k]
					h[2*k] = z
					h[k] = tmp
					k = 2*k
				end
			else
				if h[2*k]>=z&&h[2*k+1]>=z
					break
				else
					t = h[2*k]<h[2*k+1]?2*k:2*k+1
					tmp = h[t]
					h[t] = z
					h[k] = tmp
					k = t
				end
			end
		end
	end
	x
end

function heapb(a::Array{Int,1})
	h = [a[1]]
	for i in 2:length(a)
		hpush(h,a[i])
	end
	h
end

function hpushb(h::Array{Int,1},x)
	push!(h,x)
	l = length(h)
	if l>1
		k = l>>1
		while h[k]<x&&k>=1
			tmp = h[k]
			h[k] = x
			h[l] = tmp
			k = max(k>>1,1)
			l = l>>1
		end
	end
end

function hpopb(h::Array{Int,1})
	x = h[1]
	z = pop!(h)
	if length(h)>0
		h[1] = z
		k = 1
		l = length(h)
		while k <= l
			if 2*k>l
				break
			elseif 2*k+1>l
				if h[2*k]<=z
					break
				else
					tmp = h[2*k]
					h[2*k] = z
					h[k] = tmp
					k = 2*k
				end
			else
				if h[2*k]<=z&&h[2*k+1]<=z
					break
				else
					t = h[2*k]<h[2*k+1]?2*k+1:2*k
					tmp = h[t]
					h[t] = z
					h[k] = tmp
					k = t
				end
			end
		end
	end
	x
end


function main()
	q = readline() |> parseInt
	l = Int[]
	ls = 0
	lt = 0
	r = Int[]
	rs = 0
	rt = 0
	y = 0
	for i in 1:q
		a = readline() |> split |> parseMap
		if a[1] == 1
			y += a[3]
			if ls == 0
				push!(l,a[2])
				ls += 1
				lt += a[2]
			elseif rs == 0
				if l[1]<a[2]
					push!(r,a[2])
				else
					push!(r,pop!(l))
					push!(l,a[2])
				end
				rs += 1
				rt += a[2]
			else
				lm = hpopb(l)
				rm = hpop(r)
				if ls==rs
					ls += 1
					if rm<a[2]
						hpush(r,a[2])
						hpushb(l,lm)
						hpushb(l,rm)
						lt += rm
						rt += a[2]-rm
					else
						hpush(r,rm)
						hpushb(l,lm)
						hpushb(l,a[2])
						lt += a[2]
					end
				else
					rs += 1
					if a[2]<lm
						hpushb(l,a[2])
						hpush(r,lm)
						hpush(r,rm)
						lt += a[2]-lm
						rt += lm
					else
						hpushb(l,lm)
						hpush(r,rm)
						hpush(r,a[2])
						rt += a[2]
					end
				end
			end
		else
			println(l[1], " ",-l[1]*ls+l[1]*rs+lt-rt+y)
		end
	end
end

main()