#C13295. Product Except Self

    ID: 42817 Type: Default 1000ms 256MiB

Product Except Self

Product Except Self

Given a list of non-negative integers, compute a new list where the i-th element is equal to the product of all numbers in the original list except the number at index i. In other words, if the original list is represented as \(a_1,a_2,\dots,a_n\), then the output list \(b_1,b_2,\dots,b_n\) should satisfy

\[ b_i = \prod_{\substack{j=1 \\ j \neq i}}^{n} a_j \]

This must be done without using division. Handle special cases such as when the list contains zeros or is empty.

inputFormat

The first line of input contains a single integer \(n\) representing the number of elements in the list. The second line contains \(n\) space-separated non-negative integers.

If \(n = 0\), there will be no second line and the output should be an empty list.

outputFormat

Output a single line that contains \(n\) space-separated integers representing the product of all elements except the current one for each position in the input list. For \(n = 0\), output an empty line.

## sample
4
1 2 3 4
24 12 8 6