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