#C14481. Three Sum

    ID: 44135 Type: Default 1000ms 256MiB

Three Sum

Three Sum

You are given a list of n integers. Your task is to find all unique triplets \( (a, b, c) \) in the list such that:

\( a+b+c=0 \)

Each triplet must be output in non-decreasing order, and the final list of triplets should be sorted in lexicographical order (first comparing the first element, then the second, then the third).

If no such triplets exist, output [].

Note: Each triplet should be considered unique even if the same numbers appear in different positions. Duplicate triplets must not be printed.

inputFormat

The first line of input contains an integer n representing the number of elements in the list.
The second line contains n space-separated integers.

outputFormat

If there exists at least one triplet whose sum is zero, print each triplet on a separate line with the three numbers separated by a single space. The triplets must be printed in lexicographical order (each triplet's numbers are in non-decreasing order).
If no such triplet exists, output a single line containing [].

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

-1 0 1

</p>