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 int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

template<typename T>
struct BIT {
  int n;
  vector<T> bit;
  BIT() {}
  BIT(int n, T e = 0) : n(n), bit(n+1,e){}
  T sum(int i) {
    T s = bit[0];
    for(int x = i;x > 0; x -= (x & -x))
      s += bit[x];
    return s;
  }
  void add(int i, T a){
    if(i == 0) return;
    for(int x = i; x <= n; x += (x & -x))
      bit[x] += a;
  }
  int lower_bound(T w){
    if(w <= 0) return 0;
    int x = 0,r = 1;
    while(r < n) r <<= 1;
    for(int k = r; k > 0; k >>= 1){
      if(x+k <= n && bit[x+k] < w){
        w -= bit[x+k];
        x += k;
      }
    }
    return x+1;
  }
};

int Q;
int a[200010],b[200010],c[200010];
map<int,int> mp;
int imp[200010];

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  BIT<int> cnt(200010),cum(200010);
  cin >> Q;
  REP(i,Q) {
    cin >> c[i];
    if (c[i] == 1) {
      cin >> a[i] >> b[i];
      mp[a[i]]++;
    }
  }
  int id = 1;
  for (auto p : mp) {
    mp[p.first] = id;
    imp[id++] = p.first;
  }
  int suma = 0, sumb = 0;
  int num = 0;
  REP(i,Q) {
    if (c[i] == 1) {
      cnt.add(mp[a[i]],1);
      cum.add(mp[a[i]],a[i]);
      suma += a[i];
      sumb += b[i];
      num++;
    } else {
      int pos = cnt.lower_bound((num+1)/2);
      int ans = sumb;
      ans += cnt.sum(pos)*imp[pos]-cum.sum(pos);
      ans += (suma-cum.sum(pos))-(num-cnt.sum(pos))*imp[pos];
      cout << imp[pos] << " " << ans << endl;
    }
  }

  return 0;
}