#K4111. Unique Quadruplets

    ID: 26793 Type: Default 1000ms 256MiB

Unique Quadruplets

Unique Quadruplets

Given an array of integers and a target integer \(T\), count the number of unique quadruplets \((a, b, c, d)\) such that \(a + b + c + d = T\). The quadruplets must be formed by four distinct indices, and duplicate quadruplets (consisting of the same numbers) should be counted only once.

Note: If the array has fewer than four elements, the answer is \(0\). The array may contain positive, negative, and duplicate numbers.

inputFormat

The input is read from standard input and consists of three lines:

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

outputFormat

Output a single integer to standard output representing the number of unique quadruplets that sum to \(T\).

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