n = int(input()) S = list(input()) cnt = 0 for i in range(n): if S[i] == "M": for j in range(i): if 2 * i - j < n and (S[j], S[2 * i - j]) == ("U", "G"): cnt += 1 print(cnt)