#C8597. Power Set Generation

    ID: 52596 Type: Default 1000ms 256MiB

Power Set Generation

Power Set Generation

Given a list of integers, your task is to generate its power set, i.e. all possible subsets. The power set of a set with \( n \) elements contains exactly \( 2^n \) subsets. For example, if the input list is [1,2,3], then the power set is:

[
  [],
  [1],
  [2],
  [1,2],
  [3],
  [1,3],
  [2,3],
  [1,2,3]
]

Note that duplicate elements are allowed in the input, and they should be treated as distinct occurrences. The order of subsets must follow the order in which they are generated by an iterative process: starting with an empty subset and then for each number appending it to all previously generated subsets.

inputFormat

Input Format:

  • The first line contains a single integer \( n \) (where \( 0 \leq n \leq 16 \)), indicating the number of elements in the list.
  • The second line contains \( n \) space-separated integers.

If \( n = 0 \), the second line will be absent.

outputFormat

Output Format:

Print all the subsets of the given list, one subset per line. Each subset should be printed in the following format:

[elem1,elem2,...,elemk]

For an empty subset, print [] exactly. Note that there should be no extra spaces between commas and numbers.

## sample
0
[]

</p>