1. Majority vote winner
mediumIn a class representative election, each of the n students writes one candidate ID on a slip. A candidate wins outright only with more than half of all the votes.
Print the winner's ID. If no candidate has more than half the votes, print -1. Try to use only a few variables besides the list of votes.
Input: The first line has one integer n. The second line has n integers: the candidate ID on each slip.
Output: One integer: the winning candidate ID, or -1.
Limits: 1 ≤ n ≤ 10^5 · 1 ≤ candidate ID ≤ 10^9
Example 1
Input
7 2 2 1 1 2 2 3
Output
2
Candidate 2 has 4 of the 7 votes, which is more than half.
Example 2
Input
4 5 5 6 6
Output
-1
Candidate 5 has 2 of 4 votes. Exactly half is not enough.