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>() }}; } use std::cmp::max; fn main() { let _n = read_line_to_tuple!(usize); let a = read_line_to_collection!(Vec); let mut old = vec![std::i32::MIN; 10]; old[0] = 0; for x in a.iter().map(|x| x % 10) { let mut new = old.clone(); for i in 0..10 { let j = (i + x as usize) % 10; new[j] = max(new[j], old[i] + 1); } old = new; } println!("{}", old[0]); }