use std::io::Read; fn run() { let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); let mut it = s.trim().split_whitespace(); let _n: usize = it.next().unwrap().parse().unwrap(); let s = it.next().unwrap(); let mut a = vec![]; let mut ans = 0; for c in s.chars() { match c { '1' => { a.push(c); }, '9' => { if let Some(&'1') = a.last() { a.pop(); ans += 1; } else { a.push(c); } }, _ => ans += 1, } } let mut c9 = a.iter().filter(|c| **c == '9').count(); let mut c1 = a.iter().filter(|c| **c == '1').count(); while c9 >= 2 && c1 >= 1 { ans += 1; c9 -= 2; c1 -= 1; } while c1 >= 2 { ans += 1; c1 -= 2; } println!("{}", ans); } fn main() { run(); }