#K80997. Unique Pair Sums

    ID: 35654 Type: Default 1000ms 256MiB

Unique Pair Sums

Unique Pair Sums

You are given a list of integers and a target integer. Your task is to find all unique pairs of numbers from the list that add up to the target. Each pair must be in the form \((a, b)\) where \(a \leq b\). The resulting list of pairs must be sorted in lexicographical order (i.e. first by \(a\), then by \(b\)).

Note: The input is given via standard input and the output must be printed via standard output. If no pairs exist, output nothing.

Examples:

  • Input: 7 then 1 2 3 4 3 2 1 then 4
    Output:
    1 3
    2 2
  • Input: 5 then 1 5 2 4 3 then 6
    Output:
    1 5
    2 4
  • Input: 5 then 1 2 2 3 4 then 8
    Output:
    
      

inputFormat

The input is read from standard input in the following format:

n
num1 num2 ... numN
target

Where:

  • n is the number of elements in the list (an integer).
  • The second line contains n integers separated by spaces.
  • The third line contains the target integer.

outputFormat

Print the unique pairs that sum to the target. Each pair is printed on a separate line with the two numbers separated by a space. The pairs must be sorted in lexicographical order. If there is no valid pair, do not print anything.

Note: Use standard output for printing the result.

## sample
7
1 2 3 4 3 2 1
4
1 3

2 2

</p>