Problem:
Score : 200 points

Problem Statement

Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N.

However, if the result exceeds 10^{18}, print -1 instead.

Constraints

2 \leq N \leq 10^5

0 \leq A_i \leq 10^{18}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 ... A_N

Output

Print the value A_1 \times ... \times A_N as an integer, or -1 if the value exceeds 10^{18}.

Sample Input 1

2
1000000000 1000000000

Sample Output 1

1000000000000000000

We have 1000000000 \times 1000000000 = 1000000000000000000.

Sample Input 2

3
101 9901 999999000001

Sample Output 2

-1

We have 101 \times 9901 \times 999999000001 = 1000000000000000001, which exceeds 10^{18}, so we should print -1 instead.

Sample Input 3

31
4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 0

Sample Output 3

0

Solution in Rust (1.42.0) (judge verdict: Wrong Answer)

fn main() {
    let a: Vec<i64> = read_vec();
    println!("{}", solve(&a));
}

fn read<T: std::str::FromStr>() -> T {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn solve(a: &[i64]) -> i64 {
    a.iter().fold(1, |acc, &n| {
        if n == 0 {
            return 0;
        }

        if acc <= 0 {
            return acc;
        }

        let ans = (acc as i128) * (n as i128);
        println!("{}", ans);
        if ans > 1_000_000_000_000_000_000 {
            return -1;
        }

        ans as i64
    })
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_solve_1() {
        let input = &[1_000_000_000, 1_000_000_000];
        assert_eq!(1_000_000_000_000_000_000, solve(input));
    }

    #[test]
    fn test_solve_2() {
        let input = &[101, 9901, 999_999_000_001];
        assert_eq!(-1, solve(input));
    }

    #[test]
    fn test_solve_3() {
        let input = &[
            4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4, 6, 2, 6, 4, 3, 3, 8, 3, 2, 7, 9,
            5, 0,
        ];
        assert_eq!(0, solve(input));
    }
}