use std::io::*; use std::str::FromStr; use utils::*; pub fn main() { let i = stdin(); let mut o = Vec::new(); run(i.lock(), &mut o); stdout().write_all(&o).unwrap(); } fn run(i: R, o: &mut W) { let mut i = CpReader::new(i); let _n = i.read::(); let s = i.read_line().as_bytes(); writeln!(o, "{}", solve(s)).unwrap(); } fn solve(s: &[u8]) -> usize { let mut count = 0; for i in 0..s.len() - 2 { if s[i] != b'U' { continue; } for l in 0..(s.len() - i - 1) / 2 { let l = l + 1; if s[i + l] == b'M' && s[i + l * 2] == b'G' { count += 1; } } } count } mod utils { use super::*; pub struct CpReader { r: R, s: String, } macro_rules! fn_read { { $f:ident($($t:ident),*) } => { #[allow(dead_code)] pub fn $f<$($t: FromStr),*>(&mut self) -> ($($t),*) { let i = &mut self.read_line().split(' '); ($(read_next::<$t,_>(i)),*) } }; } impl CpReader { pub fn new(r: R) -> Self { CpReader { r: r, s: String::new(), } } pub fn read_line(&mut self) -> &str { self.s.clear(); self.r.read_line(&mut self.s).unwrap(); self.s.trim() } pub fn read(&mut self) -> T { self.read_line().parse().ok().unwrap() } fn_read! { read2(T1, T2) } fn_read! { read3(T1, T2, T3) } fn_read! { read4(T1, T2, T3, T4) } fn_read! { read5(T1, T2, T3, T4, T5) } } fn read_next<'a, T: FromStr, I: Iterator>(i: &mut I) -> T { i.next().unwrap().parse().ok().unwrap() } }