n = int(input()) s = input() cnt = 0 for i in range(n-2): for j in range(1, (n-i+1)//2): if s[i]+s[i+j]+s[i+j*2] == 'UMG': cnt += 1 print(cnt)