n=int(input()) s=input() ans=0 for i in range(n-2): for j in range(i+1,n-1): for k in range(j+1,n): if j-i==k-j and s[i]=="U" and s[j]=="M" and s[k]=="G": ans+=1 print(ans)