#C5577. Unique Subsets

    ID: 49241 Type: Default 1000ms 256MiB

Unique Subsets

Unique Subsets

Given a list of integers (possibly containing duplicates), find all unique subsets of the list. A subset is defined as any combination of the elements, and duplicate subsets (i.e. subsets containing the same multiset of elements) must not be repeated.

The task is to generate all subsets using a backtracking strategy while skipping over duplicates. Mathematically, if the input list is sorted as \(a_1 \le a_2 \le \cdots \le a_n\), then the solution should generate each subset \(S \subseteq \{a_1, a_2, \ldots, a_n\}\) exactly once.

Note: The empty subset is considered a valid subset.

inputFormat

The first line contains an integer n representing the number of elements in the list. The second line contains n space-separated integers.

outputFormat

Output all unique subsets, one per line. For each subset, print its elements in non-decreasing order separated by a single space. If a subset is empty, output an empty line.

## sample
3
1 2 2

1 1 2 1 2 2 2 2 2

</p>