9244 - Mode   

Description

Mode means the most frequent value in a data set. Given a sequence of integers, find out their mode.

Input

There are several numbers of test cases. Each case begins with an integer N. The next line contains N integers separated by a blank space. Each number is less than 1000 and greater than 0. The input is terminated if N = 0.

Problem size for the four testcases
1 <= N <= 1000 (1 second)
1 <= N <= 10000 (1 second)
1 <= N <= 1000000 (1 second)
1 <= N <= 10000000 (3 seconds)

Output

For each test case, print the mode of the sequence. If the mode is not unique, print the smallest one.

Sample Input  Download

Sample Output  Download

Tags




Discuss