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 9.2.1) (judge verdict: Wrong Answer)

///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#pragma warning(disable:4786)
#pragma warning(disable:4996)

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e12;
const int mod=1e9+7;
const int M=500005;
int q;
set<int>s;
set<int>::iterator it;
int bsum=0;
int cur=0;
unordered_map<int,int>id;
struct BIT
{
	int N;
	vector<int> bit;

	void init(int n)
	{
		N = n;
		bit.assign(n + 1, 0);
	}
        //Update always 1 based index e hobe
	void update(int idx, int val)
	{
		while(idx <= N)
		{
			bit[idx] += val;
			idx += idx & -idx;
		}
	}

	void updateMax(int idx, int val)
	{
		while(idx <= N)
		{
			bit[idx] = max(bit[idx], val);
			idx += idx & -idx;
		}
	}

	int pref(int idx)
	{
		int ans = 0;
		while(idx > 0)
		{
			ans += bit[idx];
			idx -= idx & -idx;
		}
		return ans;
	}

	int rsum(int l, int r)
	{
		return pref(r) - pref(l - 1);
	}

	int prefMax(int idx)
	{
		int ans = -2e9;
		while(idx > 0)
		{
			ans = max(ans, bit[idx]);
			idx -= idx & -idx;
		}
		return ans;
	}
};

BIT yo,cnt;

int chk(int x)
{
    int ret=0;
    it=s.upper_bound(x);
    int idx=0;
    if(it!=s.begin())
    {
        it--;
        idx=*it;
        idx=id[idx];
    }
    if(idx==0)
    {
        ret=yo.pref(cur)-(x*cnt.pref(cur));
        return ret;
    }
    int sum1=(x*cnt.pref(idx))-yo.pref(idx);
    int sum2=yo.rsum(idx+1,cur)-(x*cnt.rsum(idx+1,cur));
    ret=sum1+sum2;
    return ret;
}

void work()
{
    int lo=-inf;
    int hi=inf;
    while(hi-lo>=5)
    {
        int m1=lo+(hi-lo)/3;
        int m2=hi-(hi-lo)/3;
        int u=chk(m1);
        int v=chk(m2);
        if(u<=v)
        {
            hi=m2;
        }
        else
        {
            lo=m1;
        }
    }
    int fx=inf;
    int idx;
    f(i,lo,hi)
    {
        int x=chk(i);
        if(x<fx)
        {
            fx=x;
            idx=i;
        }

    }
    fx+=bsum;
    cout<<idx<<" "<<fx<<"\n";
}
int t[M];
int ta[M],tb[M];
vector<int>p;
 main()

{
    fast
    yo.init(M);
    cnt.init(M);
    cin>>q;
    f(i,1,q)
    {
        cin>>t[i];
        if(t[i]==1)
        {
           cin>>ta[i]>>tb[i];
           p.pb(ta[i]);
        }
    }
    sort(p.begin(),p.end());
    for(auto x:p)
    {
        id[x]=++cur;
    }
    f(i,1,q)
    {
        int typ;
        typ=t[i];
        if(typ==1)
        {
           int a,b;
           a=ta[i];
           b=tb[i];
           s.insert(a);
           yo.update(id[a],a);
           cnt.update(id[a],1);
           bsum+=b;
        }
        else
        {
           work();
        }
    }
    return 0;
}