Product of Array Except Self

MediumArrays
Next
ArrayPrefix Sum

For each position, compute the product of every other element in the array. Do it without using division.

Input

Line 1: n. Line 2: n integers.

Output

Print n values: the i-th is the product of all elements except a[i].

Constraints

2 <= n <= 20 -10 <= each value <= 10 All results fit in a signed 64-bit integer.

Example 1
Input
4
1 2 3 4
Output
24 12 8 6

For index 0: 2 * 3 * 4 = 24, and so on.

Example 2
Input
5
-1 1 0 -3 3
Output
0 0 9 0 0

A zero makes every product zero except the zero's own position.

Hints

Product of Array Except Self - Medium Arrays Problem | Skill Shiksha