#K64157. Products Except Self
Products Except Self
Products Except Self
Given a list of integers \(a_1, a_2, \dots, a_n\), your task is to compute a new list where the i-th element is the product of all elements of the original list except \(a_i\). In other words, for each index \(i\), compute
\(P_i = \prod_{\substack{j=1 \\ j \neq i}}^{n} a_j\)
You must not use division in your solution. Ensure that your program efficiently handles large lists.
Edge cases:
- If the list is empty, output nothing (an empty output).
- If the list contains a single element, output 0.
inputFormat
The input is given via standard input. The first line contains an integer (n), the number of elements in the list. The second line contains (n) space-separated integers representing the elements of the list.
outputFormat
Output the resulting list of integers as space-separated values in a single line to standard output.## sample
4
1 2 3 4
24 12 8 6