Cutting a rectangle | 프로그래밍의 벗 PivotOJ
PivotOJ

Cutting a rectangle

시간 제한: 1000ms메모리 제한: 1024MB출처: LMIO 2017-2018BOJ 7263

문제

Irus had a rectangle. Irus cut the rectangle and obtained two rectangles. He then put one aside and cut the other one, and continued cutting the same way (never cutting rectangles that were put aside) until he had K rectangles. The edges of all the rectangles have integer lengths.

After he sorted the rectangles by the lengths of their longer edges, Irus realized that these lengths are all distinct (however the lengths of the shorter edges need not be distinct).

Irus forgot the dimensions of the initial rectangle. Help Irus remember them.

입력

The first line contains the number of rectangles K. The remaining K lines contain two natural numbers each, ai and bi, which are the edge lengths of the i-th rectangle, and these numbers are ordered so that ai ≥ bi, and a1 < · · · < aK.

출력

In the first line, output P – the total number of possible dimensions of the initial rectangle.

In the next P lines, output the lengths of the shorter edges of all possible initial rectangles, from smallest to largest (note that we count a rectangle of certain dimensions at most once, even if there are several ways to cut it into the K given rectangles).

예제

예제 1

입력
3
2 1
3 2
4 2
출력
2
2
4
코드를 제출하려면 로그인하세요.