Cut frame#483

Cut frame

1 second
64 megabytes
Hard

A rectangular frame was divided into pieces. Each piece can be either a line segment or a corner—two segments joined at a right angle.

Based on the given segment lengths, restore the original frame or determine that it is impossible. The pieces can be rotated but cannot be reflected. All pieces must be used.

Input

The input file contains the number of pieces , followed by pairs of integers a_i b_i, describing the lengths of the two segments of the -th corner piece. If a piece is a segment, then a_i = 0 or b_i = 0.

Output

The output file must contain two positive integers —the width and height of the frame, with W \geq H. If a solution does not exist, output . If there are multiple solutions, output the one with the maximum .

Examples

Example 1

Loading
Loading