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