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