#K51472. Find the Mode

    ID: 29095 Type: Default 1000ms 256MiB

Find the Mode

Find the Mode

You are given a list of integers. Your task is to find the mode of the list, which is the number that appears most frequently. In case multiple numbers share the highest frequency, return the smallest of these numbers.

The mode is defined as \[ \text{Mode}(A) = \min\{ x : f(x) = \max_{y \in A} f(y) \} \] for a non-empty list \(A\). If the list is empty, output None.

inputFormat

The input is provided via standard input (stdin) in the following format:

  • The first line contains a nonnegative integer \(n\) representing the number of elements.
  • If \(n > 0\), the second line contains \(n\) integers separated by spaces.

If \(n = 0\), the list is empty.

outputFormat

Output a single line to standard output (stdout) containing the mode of the list. If the list is empty, output None.

## sample
8
4 5 6 7 4 4 5 5
4