#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(i, n) for (int i = 0; i < (int)(n); ++i) //#define cerr if(false) cerr #define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__); using namespace std; using ll = long long; using pii = pair; template ostream &operator<<(ostream &os, pair a){ os << '(' << a.first << ',' << a.second << ')'; return os; } template ostream &operator<<(ostream &os, vector v){ for(auto x:v)os << x << ' '; return os; } void debug(){cerr << '\n';} template void debug(H a, T... b){ cerr << a; if(sizeof...(b))cerr << ", "; debug(b...); } int main(){ int n; string s; cin >> n >> s; ll ans = 0; for(int i = 0; i < n; i++){ if(s[i] == 'M'){ for(int j = 0; j < i; j++){ if(s[j] == 'U' and s[i+i-j] == 'G')ans++; } } } cout << ans << endl; }