#K78377. Mountain Hike Rearrangement

    ID: 35073 Type: Default 1000ms 256MiB

Mountain Hike Rearrangement

Mountain Hike Rearrangement

You are given an integer n and a sequence of n integers representing the identifiers of mountain peaks. The goal is to determine whether it is possible to rearrange the sequence so that no two adjacent days have the same mountain peak.

This can be determined by checking if the maximum frequency fmax of any peak satisfies the inequality $$f_{max} \le \left\lceil \frac{n+1}{2} \right\rceil,$$ where n is the total number of peaks. If the condition is met, output POSSIBLE; otherwise, output NO.

For example, for the sequence [1, 2, 3, 4, 5] with n = 5, the output is POSSIBLE since each peak is unique. Conversely, for the sequence [1, 1, 1] with n = 3, the output is NO because one peak appears too frequently.

inputFormat

Input is given via standard input. The first line contains a single integer n (the number of mountain peaks). The second line contains n space-separated integers, each representing an identifier of a mountain peak.

outputFormat

Output a single line to standard output containing either "POSSIBLE" if a valid rearrangement exists or "NO" if it does not.## sample

5
1 2 3 4 5
POSSIBLE