eolymp
bolt
Try our new interface for solving problems
Problems

Cut frame

Cut frame

Rectangular frame was divided into \textbf{N} pieces. Each piece can be either a line segment, or "corner" - two segments, joined at right angles. According to the lengths required to restore the original frame, or determine that it is impossible. The pieces can be rotated, but can not reflect. You have to use all the pieces. \includegraphics{http://imcs.dvgu.ru/cats/download/img/img_rxmG9k9xkXUcoCPghJX86fBaTy9jQMUz_pic1.png} \InputFile \includegraphics{http://imcs.dvgu.ru/cats/download/img/img_rxmG9k9xkXUcoCPghJX86fBaTy9jQMUz_pic2.png} The input file contains the number of pieces \textbf{N}, followed by \textbf{N}pairs of integers \textbf{a_i} \textbf{b_i}, describing the length of two segments of "corner" \textbf{i}-th piece. If a piece is a segment, then \textbf{a_i} = \textbf{0} or \textbf{b_i} = \textbf{0}. \OutputFile Output file must contain two positive integers \textbf{W} \textbf{H} --- the width and height of the frame, with \textbf{W }≥\textbf{ H}. If the solution does not exist, it should give the number of \textbf{−1}. ЕIf making a few, must issue a decision with the maximum value of \textbf{W}.
Time limit 1 second
Memory limit 64 MiB
Input example #1
1
0 5
Output example #1
-1