#K39927. Three Sum Problem

    ID: 26529 Type: Default 1000ms 256MiB

Three Sum Problem

Three Sum Problem

Given a list of integers, find all unique triplets such that the sum of the three numbers is equal to zero. Each triplet must be in non-decreasing order and the overall list of triplets should also be sorted in ascending order. Mathematically, you need to find all triplets \( (a, b, c) \) that satisfy the equation \( a + b + c = 0 \). This problem tests your ability to use sorting and two-pointer techniques efficiently.

inputFormat

The first line of input contains an integer \( n \) representing the number of elements. The second line contains \( n \) space-separated integers.

outputFormat

Output each unique triplet on a new line with its three numbers separated by a space. If there are no valid triplets, output an empty string.

## sample
6
-1 0 1 2 -1 -4
-1 -1 2

-1 0 1

</p>