#C13713. Product Except Self

    ID: 43282 Type: Default 1000ms 256MiB

Product Except Self

Product Except Self

Given an array of integers, compute a new array such that each element at index (i) is the product of all the numbers in the original array except the one at (i). In other words, for an input array (A) of length (n), you need to produce an output array (B) where (B[i] = \prod_{j \neq i} A[j]). The solution should work in (O(n)) time and must not use division.

Special cases to consider include empty arrays (which should return an empty array), single-element arrays (where the output should be [1]), and arrays containing zero or negative numbers.

inputFormat

The input is read from standard input. The first line contains a single integer (n) representing the number of elements in the array. The second line contains (n) space-separated integers, representing the elements of the array.

outputFormat

Output a single line containing (n) space-separated integers representing the product-except-self array.## sample

4
1 2 3 4
24 12 8 6