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