#C1220. Product of Array Except Self

    ID: 41601 Type: Default 1000ms 256MiB

Product of Array Except Self

Product of Array Except Self

Given an array of integers, compute a new array such that the element at index i is the product of all the numbers in the original array except the one at i. You are not allowed to use division in your solution.

In mathematical notation, for an array nums of length n, you need to compute:

$$output[i]=\prod_{\substack{0 \leq j < n \\ j \neq i}} nums[j]$$

Your solution should read input from stdin and write the result to stdout as space-separated integers on one line.

inputFormat

The input consists of two lines:

  • The first line contains a single integer n (n ≥ 1), representing the number of elements in the array.
  • The second line contains n space-separated integers.

outputFormat

Output a single line consisting of n space-separated integers, where the i-th integer is the product of all the input integers except the one at index i.

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