Mock CCC '23 2 S2 - Keenan Hates Triangles

View as PDF

Submit solution

Points: 7 (partial)
Time limit: 0.25s
Memory limit: 1G

Problem type

Keenan got N sticks for his birthday! As part of his birthday present, he tries to make two triangles out of them!

In order for three sticks with lengths a, b, and c to form a triangle, it must be the case that a+b>c, b+c>a, and c+a>b.

Keenan wants to maximize the sum of the perimeters of the two triangles he makes. Help him compute this! Note that a stick cannot be used in both triangles.

Constraints

1N105

1ai1015

Input Specification

The first line contains one integer, N.

Each of the next N lines contains one integer, ai.

Output Specification

Output the maximum possible sum of the perimeters of the two triangles Keenan makes. If Keenan cannot make two triangles, output 0.

Sample Input

Copy
6
1
1
1
1
1
1

Sample Output

Copy
6

Comments

There are no comments at the moment.