#K92562. Three Sum Zero Triplets

    ID: 38225 Type: Default 1000ms 256MiB

Three Sum Zero Triplets

Three Sum Zero Triplets

You are given an array of integers of length between 1 and 1000, where each integer is in the range \(-1000\) to \(1000\). Your task is to determine the number of unique triplets \((a, b, c)\) such that \(a+b+c=0\). Two triplets are considered the same if they consist of the same three numbers, regardless of their order.

Note: The array may contain duplicate numbers. Only count unique triplets.

Example:

Input: [-1, 0, 1, 2, -1, -4]
Output: 2

inputFormat

The input is read from standard input (stdin) and has the following format:

  • The first line contains an integer \(T\), the number of test cases.
  • For each test case, the first line contains an integer \(n\) representing the number of elements in the array.
  • The next line contains \(n\) space-separated integers.

outputFormat

For each test case, output a single line containing the number of unique triplets whose sum is \(0\).

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

1 2 0 1 2

</p>