#K74802. Three Sum
Three Sum
Three Sum
Given an array of integers, your task is to find all unique triplets in the array such that the sum of the three numbers is zero.
Each triplet \( (a, b, c) \) must satisfy \( a + b + c = 0 \). Each triplet should be output in non-decreasing order, and the overall list of triplets should be sorted in lexicographical order.
This problem requires careful handling to avoid duplicate triplets. Efficient solutions often involve sorting the array and then using a two-pointer technique.
inputFormat
The input is given via standard input (stdin). The first line contains an integer \( n \) representing the number of integers in the array. The second line contains \( n \) space-separated integers.
outputFormat
Output the number of unique triplets found on the first line. Then, for each triplet, output a separate line with three space-separated integers (in non-decreasing order). The triplets should be listed in lexicographical order.
## sample6
-1 0 1 2 -1 -4
2
-1 -1 2
-1 0 1
</p>