# /usr/bin/python # -*- coding: utf-8 -*- # import sys N = int(input()) S = "A" + str(input()) ans=0 for i in range(1,N-1): if S[i] != 'U': continue for j in range(1,(N-i)//2+1): if (S[i+j]=='M') and (S[i+2*j]=='G'): ans += 1 print(ans)