use std::io::*; use std::str::FromStr; fn fact(x: i64) -> i64 { let mut ret = 1; for i in 1..=x { ret *= i; } ret } fn calc(n: i64, v: Vec) -> i64 { let mut ret = 1; for i in 0..n { let x = v[i as usize]; if x == 0 { return -1; } if x >= 4 { return 1000_000_007_i64; } let mut p = 1; for _ in 0..fact(x) { p *= x; } ret *= p; } 1000_000_007_i64 % ret } fn main() { let mut s = String::new(); stdin().read_line(&mut s).ok(); let mut itr = s.split_whitespace().map(|x| i64::from_str(x).unwrap()); let n = itr.next().unwrap(); s.clear(); stdin().read_line(&mut s).ok(); let mut itr = s.split_whitespace().map(|x| i64::from_str(x).unwrap()); let mut v = Vec::new(); for _i in 0..n { v.push(itr.next().unwrap()); } println!("{}", calc(n, v)); }