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