#include #define rep(i, a, n) for(int i = a; i < n; i++) #define int long long using namespace std; typedef pair P; const int mod = 1000000007; const int INF = 1e18; signed main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; string s; cin >> s; int ans = 0; rep(i, 0, n){ if(s[i] != 'M') continue; for(int j = 1; i - j >= 0 && i + j < n; j++){ if(s[i - j] == 'U' && s[i + j] == 'G') ans++; } } cout << ans << endl; }