#K40037. Product Except Self

    ID: 26553 Type: Default 1000ms 256MiB

Product Except Self

Product Except Self

Given an array of integers, compute a new array such that the element at each index i is equal to the product of all the elements in the original array except the one at index i. In other words, if the input array is \( A = [a_0, a_1, \ldots, a_{n-1}] \), then the output array \( B \) should satisfy

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

Please note that the problem must be solved with O(n) time complexity and without using division.

inputFormat

The input is provided via standard input (stdin) in 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 elements of the array.

outputFormat

Output the resulting array on a single line. The elements should be printed in order, separated by a single space. The output should be written to standard output (stdout).

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