#C14186. Pair Sum to Zero

    ID: 43807 Type: Default 1000ms 256MiB

Pair Sum to Zero

Pair Sum to Zero

Given a list of integers, your task is to find all unique pairs of numbers that sum to zero. Each pair is represented in the form \((a, b)\) where \(a\) is the smaller number and \(b\) is the larger number. The resulting list of pairs must be sorted in lexicographical order, i.e., by the first element, and then by the second element.

Note:

  • Zero is not paired with itself.
  • If no such pairs exist, output an empty list [].

Input Format: The first line contains a single integer \(n\), denoting the number of integers in the list. The second line contains \(n\) space-separated integers.

Output Format: Output a list of pairs in the Python list format. For example, if the valid pairs are \((-3, 3)\), \((-2, 2)\), and \((-1, 1)\), then print:

[(-3, 3), (-2, 2), (-1, 1)]

inputFormat

The input is read from stdin and has the following format:

n
num1 num2 num3 ... numN

Where:

  • \(n\) is the number of integers in the list.
  • \(num1, num2, ..., numN\) are the space-separated integers.

outputFormat

The output should be printed on stdout as a list of tuples representing the unique pairs whose sum is zero. Each tuple should be formatted as (min, max) and the list should be in lexicographical order. If no such pairs exist, output [].

## sample
7
1 -1 2 -2 3 -3 4
[(-3, 3), (-2, 2), (-1, 1)]