#894
Gold III
POKLON
시간 제한
1s
메모리 제한
32MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Mirko got a set of intervals for his birthday. There are many games he can play with them. In one of them, Mirko must find the longest sequence of distinct intervals such that each interval in the sequence is in the set and that each interval contains the one that follows in the sequence. Write a program which finds one such longest sequence.

입력

The first line of input contains the integer N (1 ≤ N ≤ 100 000), the number of intervals in the set. Each of the following N lines contains two integers A and B describing one interval (1 ≤ A < B ≤ 1 000 000).

출력

Output the length K of the longest sequence on the first line. Each of the following K lines should contain one element of the sequence, an interval in the same format it was given in the input.

예제 입력 1

3
3 4
2 5
1 6

예제 출력 1

3
1 6
2 5
3 4

예제 입력 2

5
10 30
20 40
30 50
10 60
30 40

예제 출력 2

3
10 60
30 50
30 40

예제 입력 3

6
1 4
1 5
1 6
1 7
2 5
3 5

예제 출력 3

5
1 7
1 6
1 5
2 5
3 5
코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Gold III1명 투표· 약 1개월 전
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.