cho.sh
Notes
Loading...

Triangle Builder

Time limit

2s

Memory limit

128 MB

Problem

Sejun has N straws, and their lengths may differ. Choose exactly 3 of them. If those 3 straws can form a triangle, find the maximum possible sum of the three side lengths.

Input

The first line contains the number of straws N. N is a natural number between 3 and 1,000,000 inclusive.

Each of the next N lines contains the length of one straw. Each length is a natural number between 1 and 1,000,000 inclusive.

Output

If a triangle can be formed, output the maximum possible sum of its three side lengths. If no choice of 3 straws can form a triangle, output -1.