#C8637. Triplets Summing to Zero

    ID: 52641 Type: Default 1000ms 256MiB

Triplets Summing to Zero

Triplets Summing to Zero

Given an array of integers, find all unique triplets (a, b, c) such that \(a + b + c = 0\). Each triplet must be printed in non-decreasing order and the overall list of triplets should be sorted in lexicographical order. Duplicates in the array may exist, but the returned triplets should be unique.

Example:

Input: 6
-1 0 1 2 -1 -4
Output:
-1 -1 2
-1 0 1

Note: If no valid triplets are found, produce no output.

inputFormat

The first line contains an integer \(n\) (\(n \ge 0\)), representing the number of elements in the array. The second line contains \(n\) space-separated integers.

outputFormat

For each valid triplet, print exactly one line containing the three space-separated integers in non-decreasing order. The output lines themselves should be sorted in lexicographical order. If no valid triplet exists, output nothing.

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

-1 0 1

</p>