use proconio::input; use proconio::fastout; use proconio::marker::Chars; #[fastout] #[allow(non_snake_case)] fn main() { input! { S: Chars, } assert!(1 <= S.len() && S.len() <= 500_000); let mut T = Vec::new(); let mut cnt = 0; for i in 0..S.len() { assert!(S[i] == '<' || S[i] == '>' || S[i] == '='); if S[i] == '=' { cnt += 1; } else { if cnt > 0 { T.push(('=', cnt)); cnt = 0; } T.push((S[i], 1)); } } if cnt > 0 { T.push(('=', cnt)); } let mut stc = Vec::new(); for i in 0..T.len() { stc.push(T[i]); if stc.len() < 3 { continue; } let n = stc.len(); if stc[n-3].0 == '<' && stc[n-2].0 == '=' && stc[n-1].0 == '>' { for _ in 0..3 { stc.pop(); } } } println!("{}", stc.iter().map(|&x| x.1).sum::()); }