#K15781. Zero-Sum Triplets

    ID: 24433 Type: Default 1000ms 256MiB

Zero-Sum Triplets

Zero-Sum Triplets

Given a list of integers, your task is to find all unique triplets \( (a, b, c) \) such that \( a+b+c=0 \). Two triplets are considered unique if they differ in at least one element. Each triplet must be output in non-decreasing order, and the overall list of triplets should be sorted in lexicographical order.

Note: Use an efficient algorithm (better than \( O(n^3) \)) to handle large inputs. If no such triplets exist, simply output nothing.

Example:

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

Output: -1 -1 2 -1 0 1

</p>

inputFormat

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

outputFormat

For each unique triplet whose sum equals zero, output a line with the three integers in non-decreasing order separated by a single space. If there are no such triplets, output nothing.

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

-1 0 1

</p>