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

#include<stdio.h>
int R[2]={1,1};
int C[2]={1,1};
int H[2][400010],N[2][400010];
long long h0=0,h1=0;
//評価関数（いまはMIN）
int hyouka(int a,int b,int n){
  if(C[n]<b)return 1;
  if(C[n]<a||b==0)return 0;
  if(n==0)return N[n][H[n][a]]>N[n][H[n][b]]?1:0;
  if(n==1)return N[n][H[n][a]]<N[n][H[n][b]]?1:0;
}
//挿入関数
void hin(int a,int n){
  int i=C[n]++;
  if(n==0)h0+=2e9-a;
  else    h1+=2e9+a;
  for(N[n][H[n][0]=R[n]]=a;hyouka(0,i/2,n);i/=2)H[n][i]=H[n][i/2];
  H[n][i]=R[n]++;
}
//取り出す関数
int hout(int n){
  int rt=H[n][1],i,j=2,k=H[n][--C[n]];
  if(n==0)h0-=2e9-N[n][rt];
  else    h1-=2e9+N[n][rt];
  for(i=1;hyouka(i,C[n],n);i=j)H[n][i]=H[n][j=i*2+1-hyouka(i*2,i*2+1,n)];
  H[n][j/2]=k;
  return rt;
}
int main(){
  int n,q,a,b;
  long long s=0,x,y;
  scanf("%d",&n);
  while(n--){
    scanf("%d",&q);
    if(q==1){
      scanf("%d %d",&a,&b);
      hin(a,0);
      //h=h+a+2e9;//printf("h %lld %d %d\n",h,C[0],C[1]);
      s+=b;
      if(C[0]>C[1]+1)hin(N[0][hout(0)],1);
      while(N[0][H[0][1]]>N[1][H[1][1]]){
	hin(N[0][hout(0)],1);
	hin(N[1][hout(1)],0);
      }//printf("%d %d %d\n",C[0]-1,C[1]-1,N[0][H[0][1]]);
    }
    else {
      x=N[0][H[0][1]];
      y=h0-(2e9-x)*(C[0]-1)+h1-(2e9+x)*(C[1]-1);
      //printf("h0:%lld h1:%lld %d %d\n",h0,h1,C[0]-1,C[1]-1);
      printf("%lld %lld\n",x,y+s);
    }
  }
  return 0;
}