N = int(input()) S = input() cnt = 0 for i in range(N-1): for k in range(i+1,N): if (i + k)%2 == 0: j = (i+k)//2 if S[i] == 'U' and S[j] == 'M' and S[k] == 'G': cnt += 1 print(cnt)