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: Accepted)

#![allow(unused_imports)]
#![allow(unused_macros)]
use std::cmp::{ min, max };

macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

#[allow(dead_code)]
const M: i64 = 1_000_000_007;
use std::collections::BinaryHeap;

fn add(x: i64,
       head: &mut BinaryHeap<i64>,
       tail: &mut BinaryHeap<i64>,
       ) -> (i64, i64) {
    let mut head_diff = 0;
    let mut tail_diff = 0;
    match (head.peek(), tail.peek()) {
        (None, None) => {
            head.push(x);
            tail.push(-x);
            head_diff += x;
            tail_diff += x;
        },
        (Some(&a), Some(&b)) => {
            if x < a {
                head.push(x);
                head.push(x);
                head_diff += x;
                head_diff += x;
            } else if -b < x {
                tail.push(-x);
                tail.push(-x);
                tail_diff += x;
                tail_diff += x;
            } else {
                head.push(x);
                tail.push(-x);
                head_diff += x;
                tail_diff += x;
            }
        },
        _ => {}
    }
    while head.len() > tail.len() {
        let x = -head.pop().unwrap();
        tail.push(x);
        head_diff += x;
        tail_diff -= x;
    }
    while tail.len() > head.len() {
        let x = -tail.pop().unwrap();
        head.push(x);
        head_diff += x;
        tail_diff -= x;
    }
    (head_diff, tail_diff)
}

fn main() {

    let mut sc = Scanner::new();
    let n: usize = sc.cin();

    let mut head = BinaryHeap::new();
    let mut tail = BinaryHeap::new();
    let mut head_sum = 0;
    let mut tail_sum = 0;
    let mut offset = 0;

    for _ in 0..n {
        let t: usize = sc.cin();
        if t == 1 {
            let a: i64 = sc.cin();
            let b: i64 = sc.cin();
            let (hd, td) = add(a, &mut head, &mut tail);
            head_sum += hd;
            tail_sum += td;
            // trace!(head_sum, &head);
            // trace!(tail_sum, &tail);
            offset += b;
        } else {
            let x = head.peek().unwrap();
            let y = (tail_sum - head_sum) / 2 + offset;
            println!("{} {}", x, y);
        }
    }

}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}