#C12286. Product Except Self

    ID: 41696 Type: Default 1000ms 256MiB

Product Except Self

Product Except Self

Given an array of integers of length n where n ≥ 2, compute a new array such that each element at index i is equal to the product of all the numbers in the original array except the one at i. In other words, for each index i, you need to calculate

\( output[i] = \prod_{\substack{j=0 \\ j \neq i}}^{n-1} nums[j] \)

This must be done without using division. You can assume that the input is valid and contains at least two integers.

inputFormat

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

  • The first line contains a single integer n (number of elements, n ≥ 2).
  • The second line contains n space-separated integers.

outputFormat

Output a single line to standard output (stdout) containing n space-separated integers. The i-th integer is the product of all input numbers except the one at index i.

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