#K56582. Distinct Subset Products
Distinct Subset Products
Distinct Subset Products
You are given a list of integers. Your task is to compute all distinct products obtained by multiplying elements from any subset of the list. Note that a subset can be any selection of elements (including a subset with a single element) and the empty subset is allowed.
Important: The product of the empty subset is defined as \(0\). For example, for a list \([1,2]\), the possible subsets and their products are:
- Empty subset: product = 0
- \([1]\): product = 1
- \([2]\): product = 2
- \([1,2]\): product = 1 \(\times\) 2 = 2
The result should be the sorted list (in ascending order) of all distinct products.
inputFormat
The input is read from standard input. The first line contains an integer \(n\), the number of elements in the list. The second line contains \(n\) space-separated integers. If \(n = 0\), the second line will be absent and the list is considered empty.
outputFormat
Print to standard output the distinct subset products in ascending order, separated by a space.
## sample2
1 2
0 1 2