Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/minmax-37-uchta-eng-katta-yigindisi

Sum of the three largest numbers

Medium 1000 ms 128 MB 53%
Share

A positive integer $N$ and $N$ integers are given. Choose three elements at different positions of the sequence so that their sum is the largest. Find this sum.

Choosing three elements of the sequence with the largest sum

Input

The first line contains a positive integer $N$. The next line contains $N$ integers $A_{i}$.

Output

One integer.

Note

$3 \le N \le 10^{5}$
$-10^{9} \le A_{i} \le 10^{9}$

Examples

Input #1
6
4 9 1 7 9 3
Output #1
25
Input #2
3
-2 -5 -1
Output #2
-8

Sign in to submit a solution

Signing up is free and takes a minute.