#K88042. Product of Array Except Self

    ID: 37220 Type: Default 1000ms 256MiB

Product of Array Except Self

Product of Array Except Self

Given an array \(A\) of \(n\) integers, compute a new array \(B\) such that each element \(B[i]\) is the product of all the numbers in \(A\) except \(A[i]\). Formally, for each index \(i\) (with \(0 \le i < n\)), you need to compute:

\[ B[i] = \prod_{\substack{0 \le j < n \\ j \neq i}} A[j] \]

If \(n = 0\), simply output an empty line. Note that the array may contain zeros or negative numbers. You are not allowed to use division in your solution.

Example:

Input:
4
1 2 3 4

Output: 24 12 8 6

</p>

inputFormat

The input is read from standard input (stdin) and consists of two lines:

  1. The first line contains a single integer \(n\) indicating the number of elements in the array.
  2. If \(n > 0\), the second line contains \(n\) space-separated integers.

outputFormat

Output to standard output (stdout) a single line containing the resulting array with all elements printed as space-separated integers. If the input array is empty (i.e., \(n = 0\)), output an empty line.

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