#K55957. Product Except Self

    ID: 30090 Type: Default 1000ms 256MiB

Product Except Self

Product Except Self

Given an array (a = [a_0, a_1, \dots, a_{n-1}]) of integers, your task is to construct a new array (P) such that each element (P_i) is equal to the product of all the elements in (a) except (a_i). In other words: [ P_i = \prod_{\substack{0 \leq j < n \ j \neq i}} a_j ]

Note that when the array contains only one element, the output should be 0. This problem requires you to compute the result without using division.

You will be given the input via standard input (stdin) and your final answer should be printed to standard output (stdout).

inputFormat

The input consists of two lines:

  • The first line contains a single integer n representing the number of elements in the array.
  • The second line contains n space-separated integers.

outputFormat

Output a single line with n space-separated integers where the i-th integer is the product of all the elements of the array except the one at index i.

## sample
4
1 2 3 4
24 12 8 6