#include "bits/stdc++.h" #define in std::cin #define out std::cout #define rep(i,N) for(LL i=0;i> N >> S; LL ans = 0; rep(i, N) { for (LL j = i + 1; j < N; ++j) { LL k = j + (j - i); if (k >= N) continue; if (S[i] == 'U'&&S[j] == 'M'&&S[k] == 'G') ++ans; } } out << ans << std::endl; }