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