use std::cmp; use std::io::*; use std::str::FromStr; fn calc(n: usize, v: Vec) -> i32 { let mut dp = vec![vec![-1; n + 1]; 10]; dp[0][0] = 0; for i in 0..n { for j in 0..10 { if dp[j][i] < 0 { continue; } dp[j][i + 1] = cmp::max(dp[j][i + 1], dp[j][i]); let val = (v[i] % 10) as usize; dp[(j + val) % 10][i + 1] = cmp::max(dp[(j + val) % 10][i + 1], dp[j][i] + 1); } } /* for i in 0..10 { for j in 0..n + 1 { print!("{} ", dp[i][j]); } println!(""); } */ dp[0][n] } fn main() { let mut s = String::new(); stdin().read_line(&mut s).ok(); let mut it = s.split_whitespace().map(|x| i32::from_str(x).unwrap()); let n = it.next().unwrap(); let mut s = String::new(); stdin().read_line(&mut s).ok(); let v: Vec = s .split_whitespace() .map(|x| i32::from_str(x).unwrap()) .collect(); println!("{}", calc(n as usize, v)); }