Skip to content
UPEEC

Majority Element

Medium#arrays#boyer-moore#hashing· solved by 0 · time limit 2.0 s

Print the value that appears more than n/2n/2 times, or -1 if none does. (The Boyer–Moore voting algorithm needs only O(1)O(1) extra memory.)

Input

nn, then nn integers.

Output

The majority value or -1.

Constraints

1≤n≤1051 \le n \le 10^5

Sample 1

Input

7
2 2 1 1 1 2 2

Output

2

Sample 2

Input

2
1 2

Output

-1

Sign in or join free to run and submit your solution.