#C7041. Maximum Beauty of Sequence
Maximum Beauty of Sequence
Maximum Beauty of Sequence
You are given an integer n representing the length of a sequence and a sequence of n integers. You are allowed to reverse any subsequence arbitrarily to arrange the sequence in a desired order. The beauty of a sequence is defined in this problem as follows:
\[ B = \begin{cases} 2 \times M, & \text{if the maximum element } M \text{ appears at least twice}\\ M, & \text{if the maximum element } M \text{ appears only once} \end{cases} \]
Your task is to compute the maximum possible beauty according to the rule above.
inputFormat
The input is read from standard input (stdin) and consists of two lines:
- The first line contains a single integer n (1 ≤ n ≤ 105), the number of elements in the sequence.
- The second line contains n space-separated integers, representing the sequence.
outputFormat
Output a single integer to standard output (stdout), which is the maximum beauty of the sequence as defined.
## sample1
5
5
</p>