use proconio::{ fastout, input, marker::{Chars, Usize1}, }; const DIRS: [(isize, isize); 4] = [(0, 1), (1, 0), (0, -1), (-1, 0)]; trait OrdExt { fn chmax(&mut self, other: Self) -> bool; fn chmin(&mut self, other: Self) -> bool; } impl OrdExt for T { fn chmax(&mut self, other: Self) -> bool { if *self < other { *self = other; true } else { false } } fn chmin(&mut self, other: Self) -> bool { if *self > other { *self = other; true } else { false } } } #[fastout] fn main() { input! { N: usize, S: Chars } let mut ans = 0; let mut tmp = if S[0] == '1' { 1 } else { -1 }; for i in 1..N { if S[i] == '1' { tmp += 1; } else if tmp > 0 { tmp = -1; } else { ans += 1; tmp += 1; } } println!("{}", ans); }