#K64762. Find the Second Largest Number

    ID: 32048 Type: Default 1000ms 256MiB

Find the Second Largest Number

Find the Second Largest Number

You are given a list of integers. Your task is to find the second largest distinct number in the list. More formally, if the list is represented as \(A = [a_1, a_2, \dots, a_n]\), you should find the second highest value among the distinct elements of \(A\).

If there are fewer than two distinct values in the list, print Error.

Input/Output Requirements: The program reads the input from stdin and writes the output to stdout. The input consists of an integer indicating the number of elements, followed by the list of integers on the next line (space-separated). The output should be a single line containing either the second largest number, or the string Error if the condition is not met.

inputFormat

The first line of the input contains a single integer \(n\) that denotes the number of elements in the list. The second line contains \(n\) integers separated by spaces.

For example:

5
3 5 1 4 2

outputFormat

Output a single line. If the list contains at least two distinct values, print the second largest distinct number; otherwise, print Error.

For example, for the above input the correct output is:

4
## sample
5
3 5 1 4 2
4

</p>