#!/usr/bin/env python3 n = int(input()) s = input() ans = 0 for i in range(1, (n - 1) // 2 + 1): for j in range(n - i * 2): if s[j] == "U" and s[j + i] == "M" and s[j + i + i] == "G": ans += 1 print(ans)