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 C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 200000 + 5;
ll tot, t, k; // 1 ~ tot
ll ch[maxn][2], key[maxn], pri[maxn], sz[maxn], h[maxn];
void update(ll u) {
	sz[u] = sz[ch[u][0]] + sz[ch[u][1]] + 1;
	h[u] = h[ch[u][0]]+h[ch[u][1]]+key[u];
}
void rotate(ll &u, ll d /* 0 or 1 */) {
	ll v = ch[u][d^1];
	ch[u][d^1] = ch[v][d];
	ch[v][d] = u;
	update(u);
	update(v);
	u = v;
}
void insert(ll &u, ll k) {
	if (u == 0) {
		u = ++tot;
		key[u] = k, pri[u] = rand(), sz[u]=1, h[u]=k;
		return;
	}
	int d = (k > key[u]);
	insert(ch[u][d], k);
	update(u); 
	if (pri[ch[u][d]] < pri[u]) rotate(u, d ^ 1);
}
/*void erase(ll &u,ll x) {
	if (u == 0) return;
	if (key[u] == x) {
		if (!ch[u][0]) u = ch[u][1];
		else if (!ch[u][1]) u = ch[u][0];
		else {
			int d = (pri[ch[u][0]] < pri[ch[u][1]]);
			rotate(u, d);
			erase(ch[u][d], x);
		}
	} else {
		int d = (x > key[u]);
		erase(ch[u][d], x);
	}
	if (u) update(u);
}*/
ll Rank(ll u,ll x) {
	if(!u) return 0;
	if(x <= key[u]) return Rank(ch[u][0],x);
	else return sz[ch[u][0]] + 1 + Rank(ch[u][1],x);
}
ll zhui(ll u, ll x){
	if(!u) return 0;
	if (x == sz[u]) return h[u];
	else if (x <= sz[ch[u][0]]) return zhui(ch[u][0], x);
	else return h[ch[u][0]]+zhui(ch[u][1], x - sz[ch[u][0]] - 1)+key[u];
}
ll select(ll u,ll x) {
	if (x == sz[ch[u][0]] + 1) return key[u];
	else if (x <= sz[ch[u][0]]) return select(ch[u][0], x);
	else return select(ch[u][1], x - sz[ch[u][0]] - 1);
}
/*void dfs(ll u) {
	if (ch[u][0]) dfs(ch[u][0]);
	//cout << key[u] << " ";
	if (ch[u][1]) dfs(ch[u][1]);
}*/
ll f, a, b, chang, sum, num;
int main() {
	srand(233);
	ll root = 0;
	cin>>t;
	for(int i=1;i<=t;i++){
		scanf("%lld", &f);
		if(f==1) {
			scanf("%lld%lld", &a, &b);
			sum+=a, num++;
			insert(root, a);
			chang+=b;
		}
		if(f==2) {
			ll p=select(root, (num+1)/2);
			ll q=chang+p*Rank(root, p)-zhui(root, Rank(root, p))+sum-zhui(root,Rank(root, p))-p*(num-Rank(root, p));
			printf("%lld %lld\n", p, q);
		}
		/*if(k==1) insert(root, x);
		if(k==2) erase(root, x);
		if(k==3) cout<<Rank(root, x)+1<<endl;
		if(k==4) cout<<select(root, x)<<endl;
		if(k==5) cout<<select(root, Rank(root, x))<<endl;
		if(k==6) cout<<select(root, Rank(root, x+1)+1)<<endl;*/
 	}
	return 0;
}