n = int(input()) s = input() ans = 0 for i in range(n): if s[i] == 'M': for j in range(i): if s[j] == 'U': if 2*i - j < n and s[2*i - j] == 'G': ans += 1 print(ans)