fn main(){ let n: usize = read(); let s: String = read(); let sv: Vec = s.chars().collect(); let mut ans: usize = 0; for j in 1 .. n - 1 { if sv[j] == 'M' { let mut i = j - 1; let mut k = j + 1; loop { if sv[i] == 'U' && sv[k] == 'G' { ans += 1; } if i == 0 || k == n-1 { break; } i -= 1; k += 1; } } } println!("{}", ans); } fn read() -> T where T: std::str::FromStr, T::Err: std::fmt::Debug { let mut buf = String::new(); std::io::stdin().read_line(&mut buf).expect("failed to read"); buf.trim().parse().unwrap() }