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