#K42872. Find Unique Pairs with Given Sum

    ID: 27184 Type: Default 1000ms 256MiB

Find Unique Pairs with Given Sum

Find Unique Pairs with Given Sum

Given a list of integers and a target sum \( T \), find all unique pairs \((a, b)\) such that \(a + b = T\). Each pair should be ordered so that \(a \le b\), and the list of pairs should be sorted in ascending order by the first element of each pair.

Note: Each pair should be printed only once even if multiple occurrences appear in the list. If no such pair exists, output nothing.

Example:

Input:
7
2 4 3 5 7 8 9
7

Output: 2 5 3 4

</p>

inputFormat

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

outputFormat

Print each unique pair on a separate line with the two integers separated by a single space. The pairs must be ordered such that the first element is less than or equal to the second, and overall sorted by the first element of each pair in ascending order. If no pair exists, output nothing.

## sample
7
2 4 3 5 7 8 9
7
2 5

3 4

</p>