#C947. Product of Array Except Self

    ID: 53566 Type: Default 1000ms 256MiB

Product of Array Except Self

Product of Array Except Self

Given an array of integers, your task is to compute an array where each element at index (i) is the product of all the numbers in the original array except the one at (i). That is, for each index (i), the result is given by (output[i] = \prod_{\substack{j=0 \ j \neq i}}^{n-1} a_j).

Note: If the array contains only one element, output 0.

inputFormat

The first line contains an integer (n), representing the number of elements in the array. The second line contains (n) space-separated integers.

outputFormat

Output a single line containing (n) space-separated integers, where the (i)-th integer is the product of all elements in the array except the element at index (i).## sample

4
1 2 3 4
24 12 8 6