N = int(input()) S = input() ans = 0 K = (N-1) // 2 for delta in range(1,K+1): for i in range(N): if i + delta * 2 >= N: break if S[i] == 'U' and S[i+delta] == 'M' and S[i + 2 * delta] == 'G': ans += 1 print(ans)