#C5325. Product Except Self

    ID: 48962 Type: Default 1000ms 256MiB

Product Except Self

Product Except Self

Given an integer array, return an output array such that each element at index i is equal to the product of all the numbers in the array except the one at i. You must solve the problem without using division and in O(n) time complexity.

Formally, for an array \(A\) with \(n\) elements, compute an array \(B\) where:

$$B_i = \prod_{\substack{0 \leq j < n \\ j \neq i}} A_j$$

Note that when \(n = 1\), the returned array should be [1].

inputFormat

The first line of input contains a single integer n, representing the number of elements in the array.

The second line contains n space-separated integers, representing the elements of the array.

outputFormat

Output a single line containing n space-separated integers where the i-th integer is the product of all array elements except the one at position i.

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