N = int(input()) S = input() c = 0 for i in range(N): for j in range(i+1,N): k = 2*j - i if k < N: if S[i] == "U" and S[j] == "M" and S[k] == "G": c += 1 print(c)