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

~/algor $ cat problems/ochkoz-tayoqchalar-uchburchak

Triangle from sticks

Easy 1000 ms 128 MB 33%
Share

$n$ sticks are given, the length of the $i$-th one is $a_{i}$. Choose three of them and form a triangle of positive area (the sticks cannot be broken). Among all such triangles, print the largest perimeter. If no triangle can be formed, print $0$.

Sticks by length; the three chosen ones and the triangle made from them

Input

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

Output

One integer — the largest perimeter or $0$.

Note

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

Examples

Input #1
6
2 3 9 4 15 5
Output #1
12
Input #2
4
1 2 3 6
Output #2
0

Sign in to submit a solution

Signing up is free and takes a minute.