#K40732. Majority Element Finder

    ID: 26708 Type: Default 1000ms 256MiB

Majority Element Finder

Majority Element Finder

You are given an integer n and a list of integers. The task is to find the majority element that appears more than \(\lfloor n/2 \rfloor\) times in the list. If no such element exists, output -1.

Note: The value n is used as the threshold parameter for counting (i.e. the majority element must occur more than \(\lfloor n/2 \rfloor\) times). The list of integers is provided in the second line and may contain a different number of elements than n.

Example:

Input:
7
3 3 4 2 4 4 2 4

Output: 4

</p>

inputFormat

The input consists of two lines:

  1. The first line contains a single integer n, which is used to compute the threshold \(\lfloor n/2 \rfloor\).
  2. The second line contains a space-separated list of integers.

You need to determine if there exists an element in the list that occurs more than \(\lfloor n/2 \rfloor\) times.

outputFormat

Output a single integer: the majority element if it exists; otherwise, output -1.

## sample
7
3 3 4 2 4 4 2 4
4