n = int(input()) s = input() ans = 0 for i in range(1, n - 1): for j in range(1, i + 1): if i + j >= n: continue if s[i - j] + s[i] + s[i + j] == 'UMG': ans += 1 print(ans)