n = int(input()) s = input() x = 0 for i in range(n): if s[i] == 'U': for j in range(i, n, 2): if s[j] == 'G': if s[(i+j)//2] == 'M': x += 1 print(x)