#K42267. Product of Array Except Self

    ID: 27050 Type: Default 1000ms 256MiB

Product of Array Except Self

Product of Array Except Self

Given an array of n integers, your task is to output an array such that each element at index i is equal to the product of all the numbers in the original array except the one at i.

Note that you are not allowed to use division in your solution. The input will be provided via standard input and you are expected to output the result to standard output in the format specified below.

The mathematical formula for the output array is:

$$ res[i] = \prod_{0 \leq j < n,\;j\neq i} nums[j] $$

inputFormat

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 array elements.

Example:

5
1 2 3 4 5

outputFormat

Output a single line containing n space-separated integers, where the ith integer is the product of all the numbers in the original array except the one at index i.

Example:

120 60 40 30 24
## sample
5
1 2 3 4 5
120 60 40 30 24