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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cctype>
#include <queue>
#define ll long long 
#define ri register int 
using namespace std;
template <class T>inline void read(T &x){
    x=0;int ne=0;char c;
    while(!isdigit(c=getchar()))ne=c=='-';
    x=c-48;
    while(isdigit(c=getchar()))x=(x<<3)+(x<<1)+c-48;
    x=ne?-x:x;return ;
}
const int maxn=200005;
const int inf=0x7fffffff;
struct S_Heap{
	int n,heap[maxn];
	inline void up(int fa){
		while(fa>1){
			if(heap[fa]<heap[fa>>1]){
				swap(heap[fa],heap[fa>>1]);
				fa=fa>>1;
			}
			else break;
		}
	}
	inline void push(int v){
		heap[++n]=v;
		up(n);
	}
	inline void down(int fa){
		int s=fa<<1;
		while(s<=n){
			if(s<n&&heap[s]>heap[s+1])s++;
			if(heap[s]<heap[fa]){
				swap(heap[s],heap[fa]);
				fa=s;s=fa<<1;
			}
			else break;
		}
	}
	inline void pop(){
		heap[1]=heap[n--];
		down(1);
	}
	inline int size(){
		return n;
	}
	inline int top(){
		return heap[1];
	}
}q_1;
struct B_Heap{
	int n,heap[maxn];
	inline void up(int fa){
		while(fa>1){
			if(heap[fa]>heap[fa>>1]){
				swap(heap[fa],heap[fa>>1]);
				fa=fa>>1;
			}
			else break;
		}
	}
	inline void push(int v){
		heap[++n]=v;
		up(n);
	}
	inline void down(int fa){
		int s=fa<<1;
		while(s<=n){
			if(s<n&&heap[s]<heap[s+1])s++;
			if(heap[s]>heap[fa]){
				swap(heap[s],heap[fa]);
				fa=s;s=fa<<1;
			}
			else break;
		}
	}
	inline void pop(){
		heap[1]=heap[n--];
		down(1);
	}
	inline int size(){
		return n;
	}
	inline int top(){
		return heap[1];
	}
}q_2;
int Q;
int cnt=0;
ll ans=0;
int opt;
int mi=inf,mx=-inf;
int main(){
	int x,y,lst=0;
	read(Q);
	while(Q--){
		read(opt);
		if(opt==1){
			read(x),read(y);
			/*if(!q_1.n||x>q_1.top())q_1.push(x);
			else q_2.push(x);
			if(q_1.size()>q_2.size()+1){q_2.push(q_1.top());q_1.pop();}
			if(q_2.size()>q_1.size()+1){q_1.push(q_2.top());q_2.pop();}*/
			if(cnt%2==0){
				if(q_2.top()>=x){
					q_2.push(x),lst=q_2.top();
					ans+=abs(q_2.top()-x);
				}
				else{
					q_1.push(x),lst=q_1.top();
					ans+=abs(x-q_1.top());
				}
			}
			else{
				ans+=abs(lst-x);
				if(q_2.top()>=x){
					q_2.push(x);
				}
				else q_1.push(x);
				if(q_1.size()>q_2.size()+1){q_2.push(q_1.top());q_1.pop();}
				if(q_2.size()>q_1.size()+1){q_1.push(q_2.top());q_2.pop();}
				lst=0;
			}
			cnt++,ans+=y;
			/*cnt++;
			q.push(x);
			b+=y;
			if(x>mx)mx=x;
			if(x<mi)mi=x;*/
		}
		else{
			if(cnt==1)printf("%d %lld\n",lst,ans);
			else if(cnt==0)puts("0 0");
			else{
				/*if(cnt%2==1){
					lst=q.top();
					q.pop();
					printf("%d %lld\n",q.top(),b+1ll*(cnt/2)*(mx-mi));
					q.push(lst);
				}
				else{
					printf("%d %lld\n",q.top(),b+1ll*(cnt/2)*(mx-mi));
				}*/
				if(cnt%2==0){
					printf("%d %lld\n",q_2.top(),ans);
				}
				else {
					printf("%d %lld\n",lst,ans);
				}
			}
		}	
	}
	return 0;
}