Time limit
1s
Memory limit
256 MB
A science laboratory has many acidic and alkaline solutions. Each solution has one integer characteristic value. Acidic solutions have positive values from 1 to 1,000,000,000, and alkaline solutions have negative values from -1 to -1,000,000,000.
When three different solutions are mixed in equal amounts, the characteristic value of the mixture is the sum of the three chosen values. The laboratory wants to choose three different solutions whose mixture has a characteristic value as close to 0 as possible.
For instance, if the given values are [-2, 6, -97, -6, 98], choosing -97, -2, and 98 gives a mixture value of -1, which is closest to 0. The best three solutions may all be acidic or may all be alkaline.
Given the characteristic values of the solutions, find three different values whose sum is closest to 0.
The first line contains an integer N, the number of solutions. N is between 3 and 5,000, inclusive.
The second line contains N integers separated by spaces, the characteristic values of the solutions. Each value is between -1,000,000,000 and 1,000,000,000, inclusive. All N values are distinct. The input may contain only acidic solutions or only alkaline solutions.
Print the characteristic values of three solutions whose sum is closest to 0, in increasing order.
If there is more than one valid triple, print any one of them.