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