#K79647. Unique Pair Sum Finder

    ID: 35355 Type: Default 1000ms 256MiB

Unique Pair Sum Finder

Unique Pair Sum Finder

You are given a target integer n and a list of integers. Your task is to find all unique pairs of integers from the list such that they sum up to $$a+b=n$$. In each pair, the two numbers must be distinct (i.e. you cannot use the same element twice to form a pair). If there are no such pairs, output an empty list. If the input is not valid – meaning the first line is not an integer or the second line does not consist solely of integers – then output the exact error message: "Please enter a valid list of integers and a valid integer."

The unique pairs should be output in sorted order (first by the first number in the pair, then by the second). Each pair is represented in the format (a, b) where a < b.

inputFormat

The input is given via standard input (stdin) and consists of two lines:

  • The first line contains a single integer n, the target sum.
  • The second line contains a sequence of space-separated integers representing the list. This line may be empty, in which case the list is considered empty.

outputFormat

The output, printed to standard output (stdout), is either:

  • A string representation of a list of tuples containing the unique pairs that sum to n. For example: [(1, 9), (2, 8), (3, 7)].
  • An empty list: [], if no valid pairs exist.
  • The exact error message: Please enter a valid list of integers and a valid integer. if the input is invalid.
## sample
10
2 4 3 5 7 8 9 1
[(1, 9), (2, 8), (3, 7)]