fn main() { std::io::stdin().read_line(&mut String::new()).ok(); let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); let s: Vec = s.trim().chars().collect(); let mut n = 0; for i in 0..s.len() { for d in 1.. { let j = i + d; let k = j + d; if k >= s.len() { break; } if s[i] == 'U' && s[j] == 'M' && s[k] == 'G' { n += 1; } } } println!("{n}"); }