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

~/algor $ cat problems/saralash-eng-katta-uchburchak

Triangle with the largest perimeter

Medium 1000 ms 128 MB 49%
Share

There are $n$ sticks, the $i$-th stick has length $a_{i}$. Choose three of them and form a triangle of positive area (the longest side must be strictly less than the sum of the other two). Find the largest perimeter of such a triangle. If no triangle can be formed, print $0$.

Sticks sorted by length; the three longest that form a triangle are highlighted

Input

The first line contains a positive integer $n$. The second line contains $n$ positive integers $a_{i}$.

Output

One integer — the largest perimeter, or $0$.

Note

$3 \le n \le 2 \cdot 10^{5}$
$1 \le a_{i} \le 10^{9}$

Examples

Input #1
6
2 10 3 4 20 6
Output #1
13
Input #2
3
1 2 3
Output #2
0

Sign in to submit a solution

Signing up is free and takes a minute.