#C13181. Unique Pair Sum
Unique Pair Sum
Unique Pair Sum
You are given an array of integers and a target sum \(T\). Your task is to find the number of unique unordered pairs \((a, b)\) in the array such that \(a + b = T\). Each pair is counted only once, regardless of the order of the elements. Note that the array may contain duplicates and negative numbers. Efficiently compute the answer using appropriate data structures.
Constraints:
- The first input line contains an integer \(n\) (\(0 \leq n \leq 10^5\)), representing the number of elements in the array.
- The second line contains \(n\) space-separated integers.
- The third line contains an integer \(T\), the target sum.
inputFormat
The input is given in three lines:
- The first line contains a single integer \(n\), the number of elements in the array.
- The second line contains \(n\) space-separated integers representing the array elements. If \(n = 0\), this line will be empty.
- The third line contains the target integer \(T\).
outputFormat
Output a single integer \(k\), the number of unique pairs \((a, b)\) that add up to the target sum \(T\). The output should be printed to stdout.
## sample7
1 2 3 4 3 2 1
5
2