#K2996. Product Except Self

    ID: 24860 Type: Default 1000ms 256MiB

Product Except Self

Product Except Self

Given an array of integers nums of size \(n\), your task is to return an array result such that each element at index \(i\) is the product of all the elements in the input array except the element at \(i\). This means:

[ result[i] = \prod_{j=0}^{i-1} nums[j] \times \prod_{j=i+1}^{n-1} nums[j] ]

Note: You are not allowed to use division in your solution. The expected time complexity is \(O(n)\) and you are allowed to use extra space to achieve this.

inputFormat

The input is given via standard input (stdin). 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 elements of the array nums. If \(n=0\), then the array is empty.

outputFormat

Output the resulting array via standard output (stdout) as \(n\) space-separated integers in a single line. If the input array is empty, output nothing.

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