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>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;

#define MAX_N (1<<18)

struct segtree{
    ll n, dat[2*MAX_N-1]; //(1<<17) = 130000
    int cnt[2*MAX_N-1];

    void init(int n_){
        n = 1;
        while(n < n_) n *= 2;
        for(int i = 0; i < 2*n-1; i++) dat[i] = 0;
        for(int i = 0; i < 2*n-1; i++) cnt[i] = 0;
    }

    void update(int k, ll a){
        k += n-1;
        dat[k] = a;
        cnt[k]++;
        while(k > 0){
            k = (k-1)/2;
            dat[k] = dat[k*2+1] + dat[k*2+2];
            cnt[k] = cnt[k*2+1] + cnt[k*2+2];
        }
    }

    //(a,b,0,0,seg.n)で呼ぶ
    ll query(int a, int b, int k, int l, int r){
        if(r <= a || b <= l) return 0;
        if(a <= l && r <= b) return dat[k];
        else{
            ll vl = query(a,b,k*2+1,l,(l+r)/2);
            ll vr = query(a,b,k*2+2,(l+r)/2,r);
            return vl + vr;
        }
    }
    ll bin(int k, int mid){
        if (k >= n-1) {
            return k-(n-1);
        }
        if (cnt[k*2+1] >= mid) bin(k*2+1, mid);
        else bin(k*2+2, mid - cnt[k*2+1]);
    }
} seg;

int q;
int q1 = 0;
ll a[200000], b[200000];
int o[200000];
set<pl> s;
map<pl, int> pos;
int rpos[200000];

int main() {
    cin >> q;
    seg.init(q);
    rep(i,q) {
        cin >> o[i];
        if (o[i] == 1) {
            cin >> a[q1] >> b[q1];
            s.insert(pl(a[q1],i)); q1++;
        }
    }
    {
        int i = 0;
        for (auto it = s.begin(); it != s.end(); it++) {
            rpos[i] = (*it).first;
            pos[*it] = i++;
        }
    }
    q1 = 0;
    ll B = 0;
    rep(i,q) {
        if (o[i] == 1) {
            //cerr << pos[a[q1]] << " " << a[q1] << endl;
            seg.update(pos[pl(a[q1],i)], a[q1]);
            B += b[q1];
            q1++;
        } else {
            int pos = seg.bin(0, (q1+1)/2);
            cout << rpos[pos] << " ";
            if (q1%2) {
                cout << B + -1 * seg.query(0, pos, 0, 0, seg.n) + seg.query(pos+1, seg.n, 0, 0, seg.n) << endl;;
            } else {
                cout << B + -1 * seg.query(0, pos+1, 0, 0, seg.n) + seg.query(pos+1, seg.n, 0, 0, seg.n) << endl;;
            }
            //cout << seg.bin()+B << endl;
        }
    }
}