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