use std::cmp::min; //{{{ #[allow(unused_macros)] macro_rules! getl { ( $( $t:ty ),* ) => { { let mut s = String::new(); std::io::stdin().read_line(&mut s).unwrap(); let s = s.trim_right(); let mut ws = s.split_whitespace(); ($(ws.next().unwrap().parse::<$t>().unwrap()),*) } }; } #[allow(unused_macros)] macro_rules! getl_vec { ( $t:ty ) => {{ let mut s = String::new(); std::io::stdin().read_line(&mut s).unwrap(); let s = s.trim_right(); s.split_whitespace() .map(|x| x.parse().unwrap()) .collect::>() }}; } //}}} fn main() { let n = getl!(usize); let a = getl_vec!(usize); let mut cnt = vec![0usize; 10]; for ai in a.iter().copied() { cnt[ai % 10] += 1; } let mut s = 0; for ai in a.iter().copied() { s += ai; s = s % 10; } let r = dfs(1, 0, 0, s, &cnt); println!("{}", n - r); } fn dfs(m: usize, c: usize, now: usize, t: usize, cnt: &Vec) -> usize { if m > 9 { return 100; } let mut ret = 100; for i in 0..=9 { if i > cnt[m] || c + i > 10 { break; } let now = (now + m * i) % 10; if now == t { ret = std::cmp::min(ret, c + i); } else { ret = std::cmp::min(ret, dfs(m + 1, c + i, now, t, cnt)); } } ret }