~/algor $ cat problems/saralash-eng-katta-uchburchak
Triangle with the largest perimeter
Medium
1000 ms
128 MB
49%
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$.
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