#C6623. Product of Array Except Self

    ID: 50404 Type: Default 1000ms 256MiB

Product of Array Except Self

Product of Array Except Self

Given an array of integers, compute a new array such that the i-th element is the product of all the elements of the input array except the element at index i. More formally, for an input array \( arr \) of length \( n \), you are to produce an output array \( result \) where

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

The input array can be empty. In this case, output an empty array. Note that you must solve the problem without using division.

inputFormat

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

  • The first line contains an integer \( n \) (\( 0 \le n \le 10^5 \)), which represents the number of elements in the array.
  • The second line contains \( n \) space-separated integers representing the elements of the array.

outputFormat

Output the resulting array to stdout as \( n \) space-separated integers. If the array is empty, output nothing.

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