N=int(input()) S=input() res=0 for le in range(1,N//2+1): for st in range(N-le*2): #print(st,le,S[st],S[st+le],S[st+le*2]) if S[st]=='U' and S[st+le]=='M' and S[st+le*2]=='G': res+=1 print(res)