#C3328. Product Except Self

    ID: 46743 Type: Default 1000ms 256MiB

Product Except Self

Product Except Self

Given a list of integers, compute an output list such that, for each index \(i\), the corresponding output element is the product of all the elements in the input list except the one at index \(i\). Note that you are not allowed to use division.

For example, if the input list is [1, 2, 3, 4], then the output should be [24, 12, 8, 6] because:

  • \(24 = 2 \times 3 \times 4\)
  • \(12 = 1 \times 3 \times 4\)
  • \(8 = 1 \times 2 \times 4\)
  • \(6 = 1 \times 2 \times 3\)

If the input list is empty, output an empty list.

inputFormat

The input is given via standard input (stdin). The first line contains an integer \(n\) representing the number of elements in the list. The second line contains \(n\) space-separated integers.

outputFormat

Output to standard output (stdout) a single line containing \(n\) space-separated integers representing the product of all elements except the current one for each position. If \(n = 0\), print nothing.

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