#K43477. Three Sum: Find Unique Triplets

    ID: 27318 Type: Default 1000ms 256MiB

Three Sum: Find Unique Triplets

Three Sum: Find Unique Triplets

Given an array of integers, find all unique triplets \( (a, b, c) \) such that \( a + b + c = 0 \). Each triplet must be in non-decreasing order (i.e. \( a \le b \le c \)) and the list of triplets should be printed in lexicographical order. If no such triplet exists, print a message as described in the output section.

Note: The same element from the array can not be reused in the same triplet more than once. However, the array may contain duplicate numbers, and the solution should not include duplicate triplets.

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

Output:
-1 -1 2
-1 0 1

inputFormat

The first line contains a single integer \( N \) which represents the number of elements in the array. The second line contains \( N \) space-separated integers denoting the array elements.

outputFormat

For each unique triplet that sums to zero, print the three integers in non-decreasing order (separated by a space) on a separate line. The triplets must be printed in lexicographical order. If no such triplet exists, output the line "No triplets".

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

-1 0 1

</p>