#B4277. Determining the Majority Chemical Component

    ID: 11934 Type: Default 1000ms 256MiB

Determining the Majority Chemical Component

Determining the Majority Chemical Component

A Venus probe has transmitted a sequence of measurement data, which is an integer array of length (N) (with (1 \leq N \leq 1,000,000)). Each integer represents a specific chemical component (identical integers indicate the same component).

A majority chemical component is defined as one that appears more than (\lfloor\frac{N}{2}\rfloor) times in the sequence.

For example:

  • When \(N=7\) and the sequence is 1 2 3 2 2 1 2, component 2 appears 4 times which is more than \(\lfloor7/2\rfloor=3\), so the majority component is 2.
  • When \(N=6\) and the sequence is 1 102 31 31 1 102, no component appears more than \(\lfloor6/2\rfloor=3\) times, hence there is no majority component.
Your task is to determine whether a majority chemical component exists, and if it does, output its value; otherwise, output "NO MAJOR".

inputFormat

The input consists of two lines. The first line contains a single integer (N) ( (1 \leq N \leq 1,000,000)). The second line contains (N) space-separated integers representing the chemical components.

outputFormat

Output the majority chemical component if it exists. Otherwise, output "NO MAJOR".

sample

7
1 2 3 2 2 1 2
2