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