72. Space Colony Decision

Time Limit: 1 seconds

Memory Limit: 1024 MB

Rating: 800

Problem Statement

The Galactic Council is planning to establish a new space colony on one of the potential planets in the Alpha Centauri system. The council members have each provided their preferred planet from a set of candidate planets. However, due to the large number of candidates and council members, it is important to determine which planet has the majority vote to proceed with. You are given a list of $N$ council members' votes, where each vote is represented by an integer corresponding to the planet number. Your task is to determine which planet received the majority of the votes. A planet is considered to have a majority if it appears more than $\frac{N}{2}$ times in the list. If no majority exists, return $-1$

Input

The first line contains an integer $N$, the number of council members. The second line contains $N$ integers, where each integer $p_i$ represents the planet number voted by the $i$-th council member. $1 \le N \le 5000$ $1 \le p_i \le 10^9$

Output

Output the planet number that has the majority of the votes

Sample Cases
Sample Input 0:
7
100
100
1
2
3
100
100

Sample Output 0:
100


Sample Input 1:
20
8
9
0
18
7
15
20
20
11
14
15
2
19
0
9
14
7
15
18
21

Sample Output 1:
-1
Explanation

Not available for this problem.

Sources

KL Coding Cup October 2024 > Problem 10

Submit | Back