n=int(input()) s=input() ans=0 for kankaku in range(len(s)): if 3 + 2*kankaku > len(s): break for i in range(len(s)): j=i+1+kankaku k=j+1+kankaku if k >= len(s): break if s[i] == 'U' and s[j] == 'M' and s[k] == 'G': ans+=1 print(ans)