#P22D. Segments
Segments
机翻
你得到的是 n牛轴上的线段。你可以在牛轴上的任何一个整数点上钉一个钉子,这样,所有包含这个点的线段都被认为是钉住了。如果钉子穿过某个线段的端点,这个线段也被认为是钉上了。钉子的最小数量是多少,才能钉住所有的线段?
输入的第一行包含一个整数 n(1 ≤ n ≤ 1000)--段的数量。接下来的 n行包含段的描述。每个描述都是一对整数,即端点坐标。所有坐标的绝对值都不超过10000。段落可以降级为点。
第一行应该包含一个整数--钉子的最小数量,以钉住所有的分段。第二行应该包含由空格隔开的钉子的坐标,顺序不限。如果答案不唯一,则输出任何。
Description
You are given n segments on the Ox-axis. You can drive a nail in any integer point on the Ox-axis line nail so, that all segments containing this point, are considered nailed down. If the nail passes through endpoint of some segment, this segment is considered to be nailed too. What is the smallest number of nails needed to nail all the segments down?
The first line of the input contains single integer number n (1 ≤ n ≤ 1000) — amount of segments. Following n lines contain descriptions of the segments. Each description is a pair of integer numbers — endpoints coordinates. All the coordinates don't exceed 10000 by absolute value. Segments can degenarate to points.
The first line should contain one integer number — the smallest number of nails needed to nail all the segments down. The second line should contain coordinates of driven nails separated by space in any order. If the answer is not unique, output any.
Input
The first line of the input contains single integer number n (1 ≤ n ≤ 1000) — amount of segments. Following n lines contain descriptions of the segments. Each description is a pair of integer numbers — endpoints coordinates. All the coordinates don't exceed 10000 by absolute value. Segments can degenarate to points.
Output
The first line should contain one integer number — the smallest number of nails needed to nail all the segments down. The second line should contain coordinates of driven nails separated by space in any order. If the answer is not unique, output any.
Samples
2
0 2
2 5
1
2
5
0 3
4 2
4 8
8 10
7 7
3
7 10 3