N = int(input()) S = input() c = 0 for i in range(N): for k in range(i, N, 2): j = (i+k)//2 if S[i] + S[j] + S[k] == 'UMG': c += 1 print(c)