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 JavaScript (node.js v5.12) (judge verdict: Wrong Answer)

"use strict";

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }

function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

!function () {
  var BIT =
  /*#__PURE__*/
  function () {
    function BIT(N) {
      _classCallCheck(this, BIT);

      this.N = N;
      this.data = new Array(N + 1).fill(0);
    }

    _createClass(BIT, [{
      key: "add",
      value: function add(x, v) {
        for (var i = x; i <= this.N; i += x & -x) {
          this.data[i] += v;
        }
      }
    }, {
      key: "sum",
      value: function (x) {
        var sum = 0;

        for (var i = x; i > 0; i -= x & -x) {
          sum += this.data[i];
        }

        return sum;
      }
    }]);

    return BIT;
  }();

  var Compressor =
  /*#__PURE__*/
  function () {
    function Compressor(xs) {
      _classCallCheck(this, Compressor);

      xs.sort(function (a, b) {
        return a - b;
      });
      var l = xs.length;
      this.min = xs[0];
      this.max = xs[l - 1];
      var to = new Array(l);
      var from = new Map();
      var dataNumber = 0;
      var last = null;

      for (var i = 0; i < l; i++) {
        var x = xs[i];
        if (last !== x) dataNumber++;
        to[i] = x;
        from.set(x, i);
        last = x;
      }

      this.toArray = to;
      this.fromMap = from;
      this.dataNumber = dataNumber;
    }

    _createClass(Compressor, [{
      key: "to",
      value: function to(i) {
        return this.toArray[i];
      }
    }, {
      key: "from",
      value: function from(x) {
        return this.fromMap.get(x);
      }
    }]);

    return Compressor;
  }();

  function splitNum(line) {
    return (Array.isArray(line) ? line : line.split(/\s+/)).map(function (n) {
      return parseInt(n);
    });
  }

  !function (input) {
    var lines = input.split("\n");

    var _splitNum = splitNum(lines[0]),
        _splitNum2 = _slicedToArray(_splitNum, 1),
        Q = _splitNum2[0];

    var query = lines.slice(1, Q + 1).map(function (line) {
      var _splitNum3 = splitNum(line),
          _splitNum4 = _slicedToArray(_splitNum3, 3),
          t = _splitNum4[0],
          a = _splitNum4[1],
          b = _splitNum4[2];

      return {
        t: t,
        a: a,
        b: b
      };
    });
    var xs = query.filter(function (_ref) {
      var t = _ref.t;
      return 1 === t;
    }).map(function (_ref2) {
      var a = _ref2.a;
      return a;
    });
    var c = new Compressor(xs);
    var data = new BIT(c.dataNumber);
    var minValue = 0,
        minPoint = null;
    var _iteratorNormalCompletion = true;
    var _didIteratorError = false;
    var _iteratorError = undefined;

    try {
      for (var _iterator = query[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
        var _step$value = _step.value,
            t = _step$value.t,
            a = _step$value.a,
            b = _step$value.b;

        if (1 === t) {
          var prevMin = minPoint;
          var ai = c.from(a) + 1;
          data.add(1, -1);
          data.add(ai, 2);
          minValue = null == minPoint ? b : minValue + Math.abs(a - prevMin) + b;
          minPoint = c.to(getMinPoint());
        } else console.log(`${minPoint} ${minValue}`);
      }
    } catch (err) {
      _didIteratorError = true;
      _iteratorError = err;
    } finally {
      try {
        if (!_iteratorNormalCompletion && _iterator.return != null) {
          _iterator.return();
        }
      } finally {
        if (_didIteratorError) {
          throw _iteratorError;
        }
      }
    }

    function getMinPoint() {
      var start = 1,
          end = c.dataNumber + 1;

      for (; start < end;) {
        var center = Math.floor((start + end) / 2);
        var s = data.sum(center);
        if (s > 0) end = center;else if (0 === s) {
          start = center;
          break;
        } else start = center + 1;
      }

      return start - 1;
    }
  }(require("fs").readFileSync("/dev/stdin", "utf8"));
}();