#C10075. Second Highest Number

    ID: 39240 Type: Default 1000ms 256MiB

Second Highest Number

Second Highest Number

You are given a list of integers. Your task is to find and print the second highest number among the distinct values in the list. In case there are fewer than two distinct numbers in the list, output the highest number.

In mathematical terms, if the list of numbers is given by \( A = [a_1, a_2, \dots, a_n] \), then let \( U \) be the set of unique numbers in \( A \). If \(|U| \ge 2\), output the second largest number in \( U \); otherwise, output \( \max(U) \).

The input is provided via standard input (stdin) and the output should be printed to standard output (stdout).

inputFormat

The first line contains an integer \( n \) which indicates the number of elements in the list. The second line contains \( n \) space-separated integers.

Input format:

n
a1 a2 ... an

outputFormat

Output the second highest distinct number from the list. If there is no second distinct number, output the highest number.

## sample
4
10 5 8 10
8