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)

#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>

using namespace std;
using lint = int64_t;
using P = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (lint i = 1; i < (n); ++i)
#define repn(i, a, b) for(lint i = (a); i < (b); ++i)
#define Rep(i, n) for (lint i = (n); i >= 0; --i)
#define All(vec) vec.begin(), vec.end()
#define cend printf("\n")

//constexpr lint mod = 998'244'353LL;
constexpr lint mod = 1000'000'007LL;
constexpr lint inf = 3LL * mod * mod;
constexpr double Pi = 3.141592653589793;

template<class T> using prique     = priority_queue<T>;
template<class T> using prique_inv = priority_queue<T, vector<T>, greater<T>>;
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& rhs) { return is >> rhs.first >> rhs.second; }
template<class T, class U>inline ostream& operator<<(ostream& os, const pair<T, U>& rhs) { return os << rhs.first << " " << rhs.second; }
template<class InputIterator> void arrin(InputIterator first, InputIterator last) { for (; first != last; ++first) cin >> (*first); }
template<class InputIterator> void arrout(InputIterator first, InputIterator last) {
	for (; first != last; ++first) {
		cout << (*first) << ((first + 1) != last ? " " : "\n");
	}
}

constexpr bool pri(lint x) { for (lint i = 2; i * i <= x; ++i) if (x % i == 0) return false; return 1 < x; }

lint fact[3000000];
void fact_init(lint n, lint m = mod) {
	if (3000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (lint i = 2; i <= n; ++i) {
		fact[i] = i * fact[i - 1] % m;
	}
}

lint modpow(lint x, lint n, lint m = mod) {
	lint res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % m;
		x = x * x % m;
		n >>= 1;
	}
	return res;
}

lint intpow(lint x, lint n) {
	lint res = 1;
	while (n > 0) {
		if (n & 1) res *= x;
		x *= x;
		n >>= 1;
	}
	return res;
}

lint comb(lint n, lint r, lint m = mod) {
	if (r == 0 || r == n) return 1;
	lint res = fact[n] * modpow(fact[n - r], m - 2, m) % m * modpow(fact[r], m - 2, m) % m;
	return res < 0 ? res + m : res;
}

map<lint, lint> factring(lint n) {
	map<lint, lint> res;
	for (lint i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++res[i];
		}
	}
	if (n != 1) ++res[n];
	return res;
}

template<class T>
class binary_indexed_tree {
private:

	int m_size;
	vector<T>m_vec;

public:

	binary_indexed_tree(int size)
		:m_size(size)
	{
		m_vec.resize(m_size);
	}

	void add(int a, T w) { for (int x = a; x <= m_size; x += (x & -x)) m_vec[x] += w; }

	//[1, a]
	T sum(int a) const {
		T res = T();
		for (int x = a; x > 0; x -= (x & -x)) res += m_vec[x];
		return res;
	}

	//[a, b]
	T sum(int a, int b) const {
		return sum(b) - sum(a - 1);
	}

};

int q, n, m;
bool update[2 * 100010];
lint a[2 * 100010], b[2 * 100010], sum_b[2 * 100010];
vector<lint>compress;
int main() {
	cin >> q;
	rep(i, q) {
		int t;
		cin >> t;
		if (t == 1) {
			update[i] = true;
			cin >> a[i] >> b[i];
			compress.push_back(a[i]);
		}
		sum_b[i + 1] += sum_b[i] + b[i];
	}

	sort(compress.begin(), compress.end());
	compress.erase(unique(All(compress)), compress.end());
	m = compress.size();
	binary_indexed_tree<int> bit1(m + 10);
	binary_indexed_tree<lint> bit2(m + 10);

	rep(i, q) {
		if (update[i]) {
			n++;
			int index = lower_bound(All(compress), a[i]) - compress.begin();
			bit1.add(index + 1, 1);
			bit2.add(index + 1, a[i]);
		}
		else {
			int mid_index;
			{
				int l = 0, r = m;
				while (r - l > 1) {
					int mid = l + (r - l) / 2;
					if (bit1.sum(mid) >= (n + 1) / 2) r = mid;
					else l = mid;
				}
				mid_index = r - 1; //0-indexed
			}

			lint j = mid_index;

			lint x = compress[j];
			lint left = bit1.sum(j) * x - bit2.sum(j);
			lint right = bit2.sum(m, j + 2) - bit1.sum(m, j + 2) * x + sum_b[i + 1];
			cout << x << " " << left + right << endl;
		}
	}
}