defmodule Main do def is_g(s, diff) do cond do diff >= String.length(s) -> 0 String.at(s, diff) == "G" -> 1 true -> 0 end end def find_m("", _), do: 0 def find_m(s, diff) do remain = String.slice(s, 1..-1) case String.at(s, 0) do "M" -> is_g(remain, diff) + find_m(remain, diff + 1) _ -> find_m(remain, diff + 1) end end # U def find_u(""), do: 0 def find_u(s) do remain = String.slice(s, 1..-1) case String.at(s, 0) do "U" -> find_m(remain, 0) + find_u(remain) _ -> find_u(remain) end end def solve(s) do find_u(s) end def main do _ = IO.gets("") IO.gets("") |> String.trim |> solve |> IO.puts end end