#include #include int main() { int n; std::string s; std::cin >> n >> s; int ans=0; for (int i=1;i<=n;i++) { if (s[i-1]=='U') { for (int j=i+1;j<=(n-i)/2+i;j++) { ans=((s[j-1]=='M')&&(s[2*j-i-1]=='G'))?ans+1:ans; } } } std::cout << ans << std::endl; }