#K72107. Taco Pair Finder

    ID: 33680 Type: Default 1000ms 256MiB

Taco Pair Finder

Taco Pair Finder

You are given multiple datasets. Each dataset consists of a list of integers and a target sum. Your task is to find all unique pairs from the list such that the sum of the two numbers equals the target. A pair is considered unique if it has not appeared before regardless of ordering, and each pair should be displayed with the smaller number first.

The output for each dataset should list the pairs in ascending order based on their first element. If no pair exists that meets the criteria, output an empty list.

The arithmetic condition can be expressed using \( a+b = T \), where \(a\) and \(b\) are elements of the list and \(T\) is the target sum.

inputFormat

The input is given via stdin and contains multiple datasets. Each dataset is formatted as follows:

  • A line with a positive integer \(n\) representing the number of elements in the list. (Note: If \(n=0\), this signifies the end of input.)
  • A line with \(n\) space-separated integers.
  • A line with an integer \(T\) representing the target sum.

Read datasets until a line with \(0\) is encountered (which should not be processed).

outputFormat

For each dataset, output a line via stdout that displays the list of unique pairs in the following format:

[(a, b), (c, d)]

If there are no pairs that sum to \(T\), output an empty list [].

## sample
4
1 2 3 4
5
0
[(1, 4), (2, 3)]

</p>