#C9920. Second Largest Integer
Second Largest Integer
Second Largest Integer
You are given a list of integers. Your task is to determine the second largest distinct integer from the list. In other words, if the list contains multiple occurrences of the maximum value, they are considered as one unique value. Formally, if the list is \(a_1, a_2, \ldots, a_n\) and the maximum value is \(f=\max_{1\le i\le n}\,a_i\), you must find the value \(s=\max\{a_i\;:\; a_i<f\}\). If a valid second largest number does not exist (for example, when all the numbers are the same or the list contains fewer than 2 numbers), print ERROR
(without quotes).
Note: The input is given via standard input and the output should be printed to standard output.
inputFormat
The input consists of two lines:
- The first line contains a single integer \(N\) indicating the number of integers.
- The second line contains \(N\) space-separated integers.
outputFormat
If a valid second largest distinct integer exists, print that integer. Otherwise, print ERROR
.
6
12 35 1 10 34 1
34