#C14814. Most Frequent Integer in a List

    ID: 44505 Type: Default 1000ms 256MiB

Most Frequent Integer in a List

Most Frequent Integer in a List

You are given a list of integers. Your task is to determine the integer that appears most frequently in the list. In case multiple integers have the same maximum frequency, you should return the smallest one among them.

If the list is empty, output None.

Explanation:

  • Let \(n\) be the number of integers in the list and \(A = [a_1, a_2, \dots, a_n]\) the list of integers.
  • Define the frequency \(f(x)\) as the number of times an integer \(x\) appears in \(A\).
  • You need to find the integer \(x\) such that \(f(x)\) is maximized. If there exists another integer with the same frequency, choose the one with the smallest value.

The solution should read input from standard input and write the result to standard output.

inputFormat

The input consists of two lines:

  • The first line contains a single integer \(n\) (the number of elements in the list). \(n\) can be zero.
  • If \(n > 0\), the second line contains \(n\) space-separated integers representing the list \(A\).

outputFormat

Print a single line with the most frequent integer. If the list is empty (i.e., \(n = 0\)), print None. The output should be written to standard output.

## sample
8
4 1 2 2 3 4 4 1
4