#K63377. Can Form a Rectangle?

    ID: 31740 Type: Default 1000ms 256MiB

Can Form a Rectangle?

Can Form a Rectangle?

You are given n puzzle pieces. Each piece is represented by two integers indicating its width and height. Your task is to determine whether these pieces can be arranged to form a valid rectangle.

For the pieces to form a rectangle, every unique piece (when considering that a piece of size \(a \times b\) is identical to one of size \(b \times a\)) must appear an even number of times. In other words, if we denote the frequency of each unique piece as \(f\), then a valid rectangle configuration requires that \(f \mod 2 = 0\) for every piece.

Note that if there is only one piece, or if any piece occurs an odd number of times, it is impossible to form a rectangle.

inputFormat

The input is provided via standard input (stdin). The first line contains an integer \(n\), representing the number of puzzle pieces. Each of the following \(n\) lines contains two space-separated integers, representing the width and height of a puzzle piece.

outputFormat

Output a single line to standard output (stdout): print \(YES\) if the pieces can form a valid rectangle; otherwise, print \(NO\).

Make sure to print the output without any extra spaces or newlines.

## sample
4
2 4
4 2
4 2
2 4
YES