#C8290. Product of Array Except Self

    ID: 52256 Type: Default 1000ms 256MiB

Product of Array Except Self

Product of Array Except Self

You are given an array of N integers. Your task is to compute a new array such that the element at each index i is equal to the product of all the numbers in the original array except the one at index i.

In other words, for an array arr, you need to compute:

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

Note that division is not allowed, so you must solve the problem without dividing.

Example:

Input:  5
        1 2 3 4 5
Output: 120 60 40 30 24

The first element is 120 because 2×3×4×5 = 120, and so on.

inputFormat

The input is read from standard input (stdin) and has the following format:

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

outputFormat

Output a single line to standard output (stdout) with N space-separated integers. The i-th integer should be the product of all array elements except the one at index i.

## sample
5
1 2 3 4 5
120 60 40 30 24