#K15281. Majority Element Check

    ID: 24322 Type: Default 1000ms 256MiB

Majority Element Check

Majority Element Check

You are given an array of integers of length \(n\). Your task is to determine whether there exists an integer whose frequency is at least \(\frac{n}{2}\). If such an element exists, output YES; otherwise, output NO.

Note: The comparison is based on the condition that the frequency is greater than or equal to \(\frac{n}{2}\). For example, if \(n = 7\), then an element must appear at least 4 times in the array to satisfy the condition.

Input is taken from standard input (stdin) and the answer must be printed to standard output (stdout).

inputFormat

The first line contains a single integer \(n\) \((1 \le n \le 10^5)\), representing the number of elements in the array.

The second line contains \(n\) space-separated integers, which are the elements of the array.

outputFormat

Output a single line: YES if there exists an integer in the array with frequency greater than or equal to \(\frac{n}{2}\); otherwise, output NO.

## sample
7
1 2 3 1 1 2 1
YES