#C11962. Arrange Students Without Adjacent Equal Heights

    ID: 41336 Type: Default 1000ms 256MiB

Arrange Students Without Adjacent Equal Heights

Arrange Students Without Adjacent Equal Heights

You are given n students with their respective heights. Your task is to determine whether it is possible to arrange these students in a row such that no two adjacent students have the same height.

More formally, let \(n\) be the number of students and let the heights be given in an array \(h[1..n]\). It is possible to arrange the students if and only if the maximum frequency \(f_{max}\) of any height satisfies:

\( f_{max} \le \frac{n+1}{2} \)

If the condition holds, output YES; otherwise, output NO.

inputFormat

The input is provided from stdin and consists of two lines:

  1. The first line contains an integer \(n\) representing the number of students.
  2. The second line contains \(n\) space-separated integers representing the heights of the students.

outputFormat

Output a single line to stdout with YES if it is possible to arrange the students according to the given condition, or NO otherwise.

Note that the output should contain no extra spaces or newline characters.

## sample
5
1 2 2 3 4
YES