import Data.Array import Data.List main :: IO () main = do n <- getLine s <- getLine let cs = array (0,length s - 1) [a | a <- zip [0..] s] print $ solve cs solve :: Array Int Char -> Int solve cs = foldl' (\acc1 ui -> if cs!ui == 'U' then acc1 + foldl' (\acc2 gi -> if cs!gi == 'M' && gi+gi-ui < length cs && cs!(gi+gi-ui) == 'G' then acc2+1 else acc2 ) 0 [ui..length cs -1] else acc1 ) 0 [0..length cs - 2]