Union of segments#4424

Union of segments

1 saniye
128 megabayt
Çok kolay

Vasya solved a problem in a math test and obtained the answer as a union of segments [l_i, r_i] on the number line. However, some of these segments may overlap, which Vasya does not like.

Your task is to represent Vasya's answer as a union of the minimum number of segments.

Giriş

The first line contains the integer (1 \leq n \leq 50000).

Each of the next lines contains two integers l_i and r_i (|l_i|, |r_i| \leq 50000), separated by one or more spaces. Each pair is given on a separate line.

Çıktı

On the first line, print the integer — the number of segments in the required union. In the next lines, print these segments in the same format as in the input. The list of segments must be sorted in ascending order of their left endpoints.

Örnekler

Örnek 1

Loading
Loading