#C10031. Product Except Self

    ID: 39192 Type: Default 1000ms 256MiB

Product Except Self

Product Except Self

Given a list of integers \(A = [a_0, a_1, \dots, a_{n-1}]\), your task is to compute a new list \(B\) of the same length such that each element \(B[i]\) is equal to the product of all the elements of \(A\) except \(a_i\). That is, \(B[i] = \prod_{j=0,\, j\neq i}^{n-1} a_j\). If the input list is empty, the output should be an empty list.

Note: The products might be computed without using division, and handling zeros correctly is essential.

inputFormat

The input is given via standard input (stdin) in the following format:

  • The first line contains a non-negative integer \(n\) representing the number of elements.
  • If \(n > 0\), the second line contains \(n\) space-separated integers.

For \(n = 0\), there will be no second line.

outputFormat

Output the resulting list on a single line via standard output (stdout). The numbers should be space-separated. For an empty list, output nothing.

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