#C5876. Determine the Product of Array Elements
Determine the Product of Array Elements
Determine the Product of Array Elements
You are given an array of n integers, where each integer is either -1
, 0
, or 1
. The array is 1-indexed.
Your task is to compute the product of all the numbers in the array. If any of the numbers is 0, the overall product will be 0; otherwise, you should multiply all the numbers together.
Mathematical Formula: \( \text{Product} = a_1 \times a_2 \times \cdots \times a_n \).
Note: Although the original interactive version of this problem involves making queries to determine the values at particular indices, in this version, all the array elements are given as input via standard input (stdin), and the product should be output to standard output (stdout).
inputFormat
The first line of input contains a single integer n (1 ≤ n ≤ 105), representing the number of elements in the array.
The second line contains n space-separated integers. Each of these integers is either -1
, 0
, or 1
.
outputFormat
Output a single integer representing the product of all the array elements.
## sample4
1 -1 1 1
-1
</p>