n=int(input()) s=input() c=0 for i in range(n-2): if s[i]!="U": continue for d in range(1,int((n-i)/2+0.5)): if (s[i+d]=="M")and(s[i+d+d]=="G"): c+=1 print(c)