#K9711. Form a Rectangle or Square

    ID: 39091 Type: Default 1000ms 256MiB

Form a Rectangle or Square

Form a Rectangle or Square

Given a set of sticks with various lengths, determine whether it is possible to form a rectangle or a square using them.

A rectangle can be constructed if there exist at least two pairs of sticks with equal lengths, and a square can be formed if there exist four sticks with the same length.

In mathematical notation, let \( n \) be the total number of sticks and let \( L = \{l_1, l_2, \dots, l_n\} \) be the multiset of stick lengths. A rectangle or square can be formed if \[ \text{Number of pairs} \ge 2 \] or, equivalently, if there exists a stick length \( k \) such that its frequency \( \ge 4 \).

inputFormat

The input is provided via standard input and consists of two lines:

  • First line: an integer \( n \) representing the number of sticks.
  • Second line: \( n \) space-separated integers, where each integer denotes the length of a stick.

outputFormat

Output a single line via standard output: YES if it is possible to form a rectangle or a square, or NO otherwise.

## sample
4
1 1 2 2
YES