**10 人解决**，16 人已尝试。

**12 份提交通过**，共有 31 份提交。

**6.2** EMB 奖励。

**单点时限: **2.0 sec

**内存限制: **256 MB

There is given the series of $n$ closed intervals $[a_i; b_i]$, where $i=1,2,\ldots,n$. The sum of those intervals may be represented as a sum of closed pairwise non-intersecting intervals. The task is to find such representation with the minimal number of intervals. The intervals of this representation should be written in the output file in acceding order. We say that the intervals $[a; b]$ and $[c; d]$ are in ascending order if, and only if $a \le b < c \le d$.

Write a program which:

- reads the description of the series of intervals,
- computes pairwise non-intersecting intervals satisfying the conditions given above,
- writes the computed intervals in ascending order.

In the first line there is one integer $n$, $3 \le n \le 50~000$. This is the number of intervals. In the $(i+1)$-st line, $1 \le i \le n$, there is a description of the interval $[a_i; b_i]$ in the form of two integers $a_i$ and $b_i$ separated by a single space, which are respectively the beginning and the end of the interval, $1 \le ai \le bi \le 1~000~000$.

The out should contain descriptions of all computed pairwise non-intersecting intervals. In each line should be written a description of one interval. It should be composed of two integers, separated by a single space, the beginning and the end of the interval respectively. The intervals should be written into the output file in ascending order.

Input

5 5 6 1 4 10 10 6 9 8 10

Output

1 4 5 10

**10 人解决**，16 人已尝试。

**12 份提交通过**，共有 31 份提交。

**6.2** EMB 奖励。

题目标签