#K6781. Product Array Puzzle

    ID: 32725 Type: Default 1000ms 256MiB

Product Array Puzzle

Product Array Puzzle

Given an array of n integers, construct a new array such that the element at index i is equal to the product of all the elements in the original array except the one at index i. In mathematical notation, for each index i (where 0 ≤ i < n), the value is given by:

$$prod[i] = \prod_{\substack{0 \leq j < n \\ j \neq i}} a_j $$

Your task is to compute this new array and print it as a space separated string.

inputFormat

The input is read from standard input (stdin) and contains:

  • The first line contains an integer n, representing the number of elements in the array.
  • The second line contains n space-separated integers, which are the elements of the array.

outputFormat

Output a single line to standard output (stdout) containing n space-separated integers representing the product array, where the i-th integer is the product of all the array elements except the one at index i.

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