PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FT0000046. Giá trị tuyệt đối nhỏ nhất (Absolute Minima)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Giá trị tuyệt đối nhỏ nhất (Absolute Minima)

Absolute Minima

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

A real-valued function f(x)f(x) is initially zero for every real xx. Process QQ operations:

  • 1 a b: replace the current function by f(x)+∣x−a∣+bf(x)+|x-a|+b, adding this expression for every xx.
  • 2: find an xx minimizing f(x)f(x) and print that xx together with the minimum value f(x)f(x). If multiple xx values minimize the function, choose the smallest xx.

The first operation is guaranteed to be type 1, so at least one absolute-value term exists before any evaluation. The required output values are integers.

Input

  • Line 1: integer QQ, the operation count.
  • Next QQ lines: a type-1 operation has three integers 1 a b; a type-2 operation contains only the integer 2.

Output

For each type-2 operation, print two integers x,f(x)x,f(x) on one line, where xx is the smallest minimizer and f(x)f(x) is the minimum value.

Subtasks

Subtask 1 (20 points):

  • 1≤Q≤301\le Q\le 30; −109≤a,b≤109-10^9\le a,b\le 10^9 in every 1 a b operation; every operation is type 1 or 2; the first operation is type 1; all input values are integers.

Subtask 2 (30 points):

  • 1≤Q≤30001\le Q\le 3000; −109≤a,b≤109-10^9\le a,b\le 10^9 in every 1 a b operation; every operation is type 1 or 2; the first operation is type 1; all input values are integers.

Subtask 3 (50 points):

  • 1≤Q≤2000001\le Q\le 200000; −109≤a,b≤109-10^9\le a,b\le 10^9 in every 1 a b operation; every operation is type 1 or 2; the first operation is type 1; all input values are integers.

Examples

Examples 1

Input

4
1 4 2
2
1 1 -8
2

Output

4 2
1 -3

Explanation

After 1 4 2, f(x)=∣x−4∣+2f(x)=|x-4|+2 has minimum 22 at x=4x=4. After 1 1 -8, f(x)=∣x−4∣+∣x−1∣−6f(x)=|x-4|+|x-1|-6. For every xx in [1,4][1,4], the absolute-value sum is 33, so the minimum is −3-3. The smallest minimizing xx is 11.

Examples 2

Input

4
1 -1000000000 1000000000
1 -1000000000 1000000000
1 -1000000000 1000000000
2

Output

-1000000000 3000000000

Explanation

All three absolute-value terms vanish at x=−109x=-10^9. The three constants each contribute 10910^9, making the minimum 3⋅109=30000000003\cdot10^9=3000000000, which requires a 64-bit integer.