n = io.read("*n", "*l") s = io.read() cnt = 0 for i = 1, n-2 do u = string.sub(s, i, i) if(u == "U") then diffmax = (n - i) / 2 for d = 1, diffmax do if(string.sub(s, i + d, i + d) == "M" and string.sub(s, i + 2 * d, i + 2 * d) == "G") then cnt = cnt + 1 end end end end print(cnt)