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: Runtime Error)

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+7;
typedef long long ll;
ll A[maxn],B[maxn];int T[maxn];
template <typename T>
struct BIT{
	int n;
	vector<T> v;
	
	BIT(int n=0)
	{
		init(n);
	}
	void init(int nin)
	{
		n=nin;
		v.resize(n+1);
		for(int i=1;i<=n;i++) v[i]=0;
	}
	void add(int i,T a)
	{
		while(i<=n)
		{
			v[i]+=a;
			i+=(i&(-i));
		}
	}
	T sum(int i)
	{
		T s=0;
		if(i<=0) return 0;
		while(i>0)
		{
			s+=v[i];i-=(i&(-i));
		}
		return s;
	}
	T sum(int i,int j)
	{
		return sum(j)-sum(i-1);
	}
	//a[1]+a[2]+...a[ret]>=x
	int low_bound(T x)
	{
		T tmp=0;int ret=0,k=1;
		while(2*k<n) k<<=1;
		for(;k>=1;k>>=1)
		{
			if(ret+k <= n && v[ret+k]<x)
			{
				x-=v[ret+k];ret+=k;
			}
		}
		return ret+1;
	}
};
int main()
{
	int q;scanf("%d",&q);vector<ll> as;//as的作用的给数下标 
	for(int i=1;i<=q;i++)
	{
		scanf("%d",&T[i]);
		if(T[i]==1)
		{
			scanf("%lld%lld",&A[i],&B[i]);
			as.push_back(A[i]);
		}
	}
	sort(as.begin(),as.end());
	as.erase(unique(as.begin(),as.end()),as.end());
	int sz=as.size();map<ll,int> mp;
	for(int i=1;i<=sz;i++)
	{
		mp[as[i-1]]=i;
		//cout<<i<<" "<<as[i-1]<<endl;
	}
	BIT<ll> bitsum(sz);
	BIT<ll> bitnum(sz);
	int allv=0;ll tmp=0;
	for(int i=1;i<=q;i++)
	{
		if(T[i]==1)
		{
			int id=mp[A[i]];
			bitsum.add(id,A[i]);
			bitnum.add(id,1);
			tmp+=B[i];//cout<<i<<" "<<B[i]<<endl;
			allv++;
		}
		else
		{
			int id=bitnum.low_bound((allv+1)/2);//cout<<" "<<as[id-1]<<endl;
			ll ans=0;
			ans-=bitsum.sum(1,id-1);
			//cout<<ans<<endl;
			ans+=as[id-1]*bitnum.sum(1,id-1);
			//cout<<ans<<endl;
			ans+=bitsum.sum(id+1,sz);
			//cout<<ans<<endl;
			ans-=as[id-1]*bitnum.sum(id+1,sz);
			//cout<<ans<<endl;
			cout<<as[id-1]<<" "<<ans+tmp<<endl;
		}
	}
 }