N = int(input()) S = list(input()) ans = 0 for i in range(N): if S[i] != "U": continue for j in range(i + 1, N): k = 2 * j - i if k >= N: break if S[i] == "U" and S[j] == "M" and S[k] == "G": ans += 1 print(ans)