Cutting a Rectangle
Time limit1sMemory limit1024 MB
Given K rectangles with distinct longer sides, find every possible shorter side of an original rectangle that can be cut into exactly these pieces.
Problem
Irus had a single rectangle whose sides have integer lengths. He cut the rectangle with one straight line parallel to a side, splitting it into two rectangles, set one of them aside (a rectangle that has been set aside is never cut again), and kept cutting the other one in the same way. He repeated this until he had rectangles in total; every rectangle produced this way has integer side lengths.
When Irus sorted the resulting rectangles by the length of their longer edge, he found that these longer-edge lengths were all distinct (the shorter-edge lengths, however, may coincide).
Irus has forgotten the size of the original rectangle. Help him by finding every possible size of the initial rectangle.
Input
The first line contains the number of rectangles . Each of the next lines contains two natural numbers and , the side lengths of the -th rectangle. They are given so that , and they are ordered so that .
Output
On the first line, print , the number of possible sizes of the initial rectangle.
On each of the next lines, print the length of the shorter edge of one possible initial rectangle, in increasing order (a rectangle of a given size is counted only once, even if there are several ways to cut it into the given rectangles).
Constraints
- for all