use std::io::Read; fn main() { const DIVIDER: u128 = 1_000_000_000_000_000_000; let mut all_data = String::new(); std::io::stdin().read_to_string(&mut all_data).ok(); let all_data: Vec<&str> = all_data.trim().split('\n').map(|a| a.trim()).collect(); let n: usize = all_data.iter().next().unwrap().parse::().unwrap(); let p: Vec = all_data.iter().skip(1).next().unwrap().split_whitespace().map(|a| a.parse::().unwrap()).collect(); let mut result: Vec = vec![p[0]]; p.iter().skip(1).for_each(|a| { let old = result.clone().to_owned(); result.clear(); let mut carry_over = 0; old.iter().for_each(|r| { let rest = (r * *a + carry_over) % DIVIDER; carry_over = (r * *a + carry_over) / DIVIDER; result.push(rest); }); if carry_over > 0 { result.push(carry_over); } }); let mut p: u128 = result.iter().map(|a| a.to_string().chars().map(|b| b.to_string().parse::().unwrap()).sum::()).sum(); while p >= 10 { let p_str: String = p.to_string(); p = p_str.chars().map(|a| a.to_string().parse::().unwrap()).sum(); } println!("{}", p); }