#P7291. Maximum Function Value in Array

    ID: 20490 Type: Default 1000ms 256MiB

Maximum Function Value in Array

Maximum Function Value in Array

Given an array k of size n with indices from 1 to n, define the function:

\( f(x,y)= \begin{cases} \min(k_x,k_y) \times (x+y) &\text{if } x \ne y \\ k_x\times x &\text{if } x=y \end{cases} \)

Your task is to determine the maximum value of \( f(x,y) \) for all \( 1 \leq x,y \leq n \).

inputFormat

The first line contains a single integer \( n \) representing the size of the array.

The second line contains \( n \) space-separated integers denoting the array elements.

outputFormat

Output a single integer representing the maximum value of \( f(x,y) \) over all valid pairs \( x,y \).

sample

1
5
5