#K83407. Product of Array Except Self

    ID: 36190 Type: Default 1000ms 256MiB

Product of Array Except Self

Product of Array Except Self

Given an array \(nums\) of \(n\) integers, calculate an output array such that each element output[i] is equal to the product of all the numbers in the original array except \(nums[i]\). In other words, for each valid index \(i\),

[ output[i] = \prod_{\substack{0 \leq j < n \ j \neq i}} nums[j] ]

Your program must read the input from stdin and write the result to stdout.

If the input list is empty (i.e. \(n = 0\)), print an empty line.

inputFormat

The first line contains an integer (n) denoting the number of elements. If (n > 0), the second line contains (n) space-separated integers representing the array (nums).

outputFormat

Output a single line containing (n) space-separated integers, where each integer is the product of all the array elements except the one at the corresponding position.## sample

4
1 2 3 4
24 12 8 6