407882: GYM102916 F Exactly One Point

Memory Limit:512 MB Time Limit:3 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

F. Exactly One Pointtime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard output

There are $$$n$$$ segments on a line. You should place some points onto this line so that:

  • every point is contained in at least one segment,
  • every segment contains exactly one point.
Input

The first line contains an integer $$$n$$$ ($$$1 \le n \le 200000$$$) — the number of segments.

Each of the next $$$n$$$ lines contains two integers $$$L_i$$$ and $$$R_i$$$ ($$$L_i < R_i$$$) — the endpoints of the $$$i$$$-th segment.

For convenience, all endpoints of all segments are even numbers from $$$0$$$ to $$$4n - 2$$$.

Output

If it's impossible to place points in a required way, output "-1".

Otherwise, in the first line output an integer $$$m$$$ — the number of points that should be placed onto the line.

In the next line, output $$$m$$$ distinct integers from $$$0$$$ to $$$4n - 2$$$ — the coordinates of the points.

You don't have to minimize the number of points. If there are several possible solutions, output any of them.

ExamplesInput
3
0 10
2 4
6 8
Output
-1
Input
2
0 6
2 4
Output
1
4
Input
3
0 2
2 4
4 6
Output
3
1 3 6

加入题单

上一题 下一题 算法标签: