# coding: utf-8 # Your code here! N=int(input()) S=list(input()) ans=0 for i in range(N):#スタートの添え字 for d in range((N-i+1)//2): if S[i]=="U" and S[i+d]=="M" and S[i+2*d]=="G": ans+=1 print(ans)