#include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double lld; #define rep(i,n) for(int i = 0; i < (n); i++) #define pb push_back #define eb emplace_back #define fi first #define se second #define all(x) x.begin() , x.end() #define vi vector #define vll vector #define vb vector #define vs vector #define mp make_pair const static int INF = 1001001001; const static ll LINF = 1001001001001001001LL; const static lld PI = 3.1415926535897932384626L; const static int MOD = 1000000009; //const static int MOD = 998244353; template < typename T > bool chmin (T &a , T b) { if (a > b) { a = b; return true; } else { return false; } } template < typename T > bool chmax (T &a , T b) { if (a < b) { a = b; return true; } else { return false; } } ll gcd (ll a , ll b) { if (a < b) swap(a , b); if (a % b == 0) return b; else return gcd (b , a % b); } ll lcm (ll a , ll b) { return (a / gcd (a , b) * b); } int keta (ll x) { int ret = 0; while(x) { ret++; x /= 10; } return ret; } inline int in () { int x; scanf("%d" , &x); return x; } inline ll lin () { ll x; scanf("%lld" , &x); return x; } inline string sin () { string s; cin >> s; return s; } void io_setup () { cout << fixed << setprecision(15); //cin.tie(0); //ios::sync_with_stdio(false); } bool is_prime (ll x) { if (x == 2 || x == 3 || x == 5 || x == 7) { return true; } for (ll i = 3; i * i <= x; i++) { if (x % i == 0) { return false; } } return true; } /* vb prime_table(2020202 , true); void prime () { prime_table[0] = false; prime_table[1] = false; for (int i = 2; i < 2020202; i++) { for(int j = i + i; j < 2020202; j += i) { prime_table[j] = false; } } } */ //nCr ll modpow (ll x , ll p) { ll ret = 1; while (p > 0) { if (p & 1) { ret *= x; ret %= MOD; } x *= x; x %= MOD; p >>= 1; } return ret; } vector fact(1 << 20 , 0); vector factinv(1 << 20 , 0); void pre_calc_fact () { fact[0] = 1; for (int i = 1; i < (1 << 20); i++) { fact[i] = 1LL * i * fact[i - 1] % MOD; } for (int i = 0; i < (1 << 20); i++) { factinv[i] = modpow(fact[i], MOD - 2); } } ll nCk (ll n , ll k) { return fact[n] * factinv[k] % MOD * factinv[n - k] % MOD; } /* //memo v.erase(unique(all(v)), v.end()); */ void solve() { int n = in(); string s; cin >> s; int ans = 0; for (int i = 0; i < n - 2; i++) { for (int j = i + 1; j < n - 1; j++) { if (s[i] == 'U' && s[j] == 'M') { int k = j + j - i; if (k < n && s[k] == 'G') ans++; } } } cout << ans << endl; return; } int main () { io_setup(); //prime(); //pre_calc_fact(); solve(); return 0; }