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

use std::io::*;


mod rand {
    static mut SEED: u64 = 88172645463325252;

    pub fn next() -> u64 {
        unsafe {
            SEED ^= SEED<<13; SEED ^= SEED>>7; SEED ^= SEED<<17;
            SEED
        }
    }
}


mod treap {
    use rand;

    #[derive(Debug, Clone)]
    pub struct Node {
        pub v: i64,
        pri: u64,
        lch: Option<Box<Node>>,
        rch: Option<Box<Node>>,
        cnt: usize,
        sum: i64,
    }


    pub type Tree = Option<Box<Node>>;


    fn tree(n:Node) -> Tree {
        Some(Box::new(n))
    }


    pub fn leaf(v:i64) -> Tree {
        tree(Node {
            v:v,
            pri: rand::next(),
            lch: None.into(),
            rch: None.into(),
            cnt: 1,
            sum: v,
        })
    }


    pub fn count(t: &Tree) -> usize {
        match *t {
            None => 0,
            Some(ref n) => n.cnt,
        }
    }


    pub fn sum(t: &Tree) -> i64 {
        match *t {
            None => 0,
            Some(ref n) => n.sum,
        }
    }


    pub fn update(t: Tree) -> Tree {
        match t {
            None => t,
            Some(mut n) => {
                n.cnt = count(&n.lch) + count(&n.rch) + 1;
                n.sum = sum(&n.lch) + sum(&n.rch) + n.v;
                Some(n)
            }
        }
    }


    pub fn merge(tl: Tree, tr: Tree) -> Tree {
        match (tl, tr) {
            (None, None) => None,
            (l, None) => l,
            (None, r) => r,
            (Some(mut l), Some(mut r)) => {
                if l.pri > r.pri {
                    l.rch = merge(l.rch.take(), Some(r));
                    update(Some(l))
                }
                else {
                    r.lch = merge(Some(l), r.lch.take());
                    update(Some(r))
                }
            }
        }
    }


    pub fn split(t: Tree, k: usize) -> (Tree, Tree) {
        match t {
            None => (None, None),
            Some(mut n) => {
                let cnt = count(&n.lch);
                if k <= cnt {
                    let (l,r) = split(n.lch.take(), k);
                    n.lch = r;
                    (l, update(Some(n)))
                }
                else {
                    let (l,r) = split(n.rch.take(), k - cnt - 1);
                    n.rch = l;
                    (update(Some(n)), r)
                }
            }
        }
    }


    pub fn insert(t: Tree, k: usize, v: i64) -> Tree {
        let (l,r) = split(t, k);
        merge(l, merge(leaf(v), r))
    }


    pub fn slice(t: Tree, l: usize, r: usize) -> Tree {
        let (_,t) = split(t, l);
        let (t,_) = split(t, r-l);
        t
    }


    pub fn get(t: &Tree, k: usize) -> Option<i64> {
        match *t {
            None => None,
            Some(ref n) => {
                let cnt = count(&n.lch);
                if k == cnt {
                    Some(n.v)
                }
                else if  k < cnt {
                    get(&n.lch, k)
                }
                else {
                    get(&n.rch, k - cnt - 1)
                }
            }
        }
    }
}


struct Treap {
    t: treap::Tree
}


impl Treap {
    fn new() -> Treap {
        Treap { t: None }
    }


    fn insert(&mut self, k:usize, v:i64) {
        self.t = treap::insert(self.t.take(), k, v);
    }


    fn ordered_insert(&mut self, v:i64) {
        let mut l = 0;
        let mut r = treap::count(&self.t);
        while r - l > 1 {
            let m = (l+r)/2;
            if v <= self.get(m) {
                r = m;
            }
            else {
                l = m + 1;
            }
        }
        self.insert(l, v);
    }


    fn get(&self, k:usize) -> i64 {
        treap::get(&self.t, k).unwrap_or_else(|| panic!("idx: {}", k))
    }


    fn sum(&self, l:usize, r:usize) -> i64 {
        treap::sum(&treap::slice(self.t.clone(), l, r))
    }


    fn len(&self) -> usize {
        treap::count(&self.t)
    }
}


use std::fmt::Write;
fn solve(buf: String) -> String {
    let mut it = buf.trim().split_whitespace();
    let q = it.next().unwrap().parse::<usize>().unwrap();

    let mut ans = String::new();
    let mut sum_b = 0;
    let mut A = Treap::new();
    for _ in 0..q {
        let kind = it.next().unwrap().parse::<usize>().unwrap();
        match kind {
            1 => {
                let a = it.next().unwrap().parse::<i64>().unwrap();
                let b = it.next().unwrap().parse::<i64>().unwrap();
                A.ordered_insert(a);
                sum_b += b;
            },
            2 => {
                let n = A.len();
                let mid = (n-1)/2;
                let x = A.get(mid);
                let mut sum_abs = 0;
                sum_abs += x*(mid as i64) - A.sum(0,mid);
                sum_abs += A.sum(mid+1,n) - x*(n as i64 - 1 - mid as i64);
                write!(ans, "{} {}\n", x, sum_abs+sum_b).unwrap();
            },
            _ => {
                unreachable!()
            }
        }
    }
    ans
}


fn main() {
    let mut buf = String::new();
    stdin().read_to_string(&mut buf).unwrap();
    print!("{}", solve(buf));
}