macro_rules! read_line_to_tuple { ( $( $t:ty ),* ) => {{ let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); let mut iter = input.split_whitespace(); ( $( iter.next().unwrap().parse::<$t>().unwrap() ),* ) }}; } macro_rules! read_line_to_collection { ( $t:ty ) => {{ let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); let iter = input.split_whitespace(); iter.map(|x| x.parse().unwrap()).collect::<$t>() }}; } const MOD: i64 = 1_000_000_007; fn main() { let n = read_line_to_tuple!(usize); let a = read_line_to_collection!(Vec); let min = *a.iter().min().unwrap(); if min == 0 { return println!("-1"); } let max = *a.iter().max().unwrap(); if max >= 4 { return println!("{}", MOD); } let pow = |mut a: i64, mut n: usize| -> i64 { let mut res = 1; while n > 0 { if n & 1 > 0 { res = res * a % MOD; } a = a * a % MOD; n >>= 1; } res }; let mut ans = 1; for i in 0..n { let k = (1..=a[i]).fold(1, |acc, x| acc * x); ans = ans * pow(a[i], k as usize); if ans > MOD { return println!("{}", MOD); } } println!("{}", MOD % ans); }