use std::io::Read; fn main() { let mut s = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let mut l = s.lines(); let n: usize = l.next().unwrap().parse().unwrap(); let c: Vec<_> = l.last().unwrap().chars().collect(); let mut a = 0; for i in 0..n { if c[i] == 'U' { for j in 1..n { if i + j + j < n && c[i + j] == 'M' && c[i + j + j] == 'G' { a += 1; } } } } println!("{}", a) }