def solve() : 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) solve()