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# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.CodeDom;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;

namespace AtCoder
{

    class C : IComparer<S>
    {
        public int Compare(S x, S y)
        {
            if (x.L == y.L)
            {
                return x.Index.CompareTo(y.Index);
            }

            return x.L.CompareTo(y.L);
        }
    }
    struct S
    {
        public long L;
        public int Index;

        public S(long l, int index)
        {
            L = l;
            Index = index;
        }
    }
    class Program
    {

        static void Main(string[] args)
        {
            new Program().Solve();
        }

        public void Solve()
        {
            var sc = new Scanner();
            var sb = new StringBuilder();
            long bSum = 0;
            int Q = sc.NextInt();
            var ss = new SortedSet<S>(new C());
            long l = int.MinValue, r = int.MaxValue;
            long min = 0;
            for (int i = 0; i < Q; i++)
            {
                int type = sc.NextInt();
                if (type == 1)
                {
                    int a = sc.NextInt();
                    int b = sc.NextInt();
                    bSum += b;
                    ss.Add(new S(a, i));
                    if (l <= a && a <= r)
                    {
                        min += 0;
                        l = a;
                        r = a;
                    }
                    else
                    {
                        if (r < a)
                        {
                            min += a - r;
                        }

                        if (a < l)
                        {
                            min += l - a;
                        }

                        var ar = ss.ToArray();

                        if (ar.Length % 2 == 0)
                        {
                            l = ar[ar.Length / 2 - 1].L;
                            r = ar[ar.Length / 2].L;
                        }
                        else
                        {
                            l = r = ar[ar.Length - 1].L;
                        }
                    }
                    
                }
                else if (type == 2)
                {

                    sb.AppendLine($"{l} {min + bSum}");
                }
            }
            Console.Write(sb.ToString());
        }
    }
}




class Scanner
{
    public Scanner()
    {
        _stream = new StreamReader(Console.OpenStandardInput());
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private readonly StreamReader _stream;
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = _stream.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = _stream.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}