#K80292. Largest Perimeter of Triangle

    ID: 35498 Type: Default 1000ms 256MiB

Largest Perimeter of Triangle

Largest Perimeter of Triangle

You are given an array of positive integers representing the lengths of line segments. Your task is to find the largest possible perimeter of a non-degenerate triangle that can be formed by selecting any three of these segments.

A triangle is non-degenerate if it has a non-zero area. In terms of side lengths, for three sides \( a, b, c \) (where \( a \) is the largest), this is equivalent to the condition:

\( a < b + c \)

If no valid triangle can be formed, output 0.

The input is read from standard input and the result should be printed to standard output.

inputFormat

The first line contains a single integer \( n \) denoting the number of elements in the array.

The second line contains \( n \) space-separated integers representing the side lengths.

outputFormat

Output a single integer representing the largest perimeter of a non-degenerate triangle. If no valid triangle exists, output 0.

## sample
3
2 1 2
5