#C11817. Product of Array Except Self

    ID: 41175 Type: Default 1000ms 256MiB

Product of Array Except Self

Product of Array Except Self

Given an array of integers, your task is to compute a new array where each element at index i is the product of all the elements of the original array except the one at index i. You must solve this problem without using division.

For each index \( i \), the answer is:

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

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

inputFormat

The input is read from stdin and consists of two lines.

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

outputFormat

The output is written to stdout and should be a single line containing n space-separated integers, where the i-th integer is the product of all the numbers in the input array except the one at index i.

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

</p>