#include //#define int long long #define FOR(i, a, b) for (int i = a; i < b; ++i) #define rep(N) for (int i = 0; i < N; ++i) #define Rep(a, b) for (int i = a; i < b; ++i) #define For(i, N) for (int i = 0; i < N; ++i) #define all(v) v.begin(), v.end() #define rev(v) v.rbegin(), v.rend() #define makei(N) int N; cin >> N; #define makes(s) string s; cin >> s; #define maked(d) double d; cin >> d; #define makev(v, N) vi v(N); rep(N)cin >> v[i]; #define mod 1000000007 using namespace std; using ll = long long; using vi = vector; using vvi = vector>; using vll = vector; using vb = vector; using vvb = vector>; using vs = vector; using pii = pair; using pis = pair; using msi = map; template void say(T s) { cout << s << "\n"; } template void say(vector s) { auto itr = s.begin(); cout << *(itr++); while (itr != s.end()) { cout << " " << *(itr++); } cout << "\n"; } template void say(vector s, char r) { auto itr = s.begin(); cout << *(itr++); while (itr != s.end()) { cout << r << *(itr++); } cout << "\n"; } void yn(bool b) { if (b)say("yes"); else say("no"); } void Yn(bool b) { if (b)say("Yes"); else say("No"); } void YN(bool b) { if (b)say("YES"); else say("NO"); } template void maxi(T& a, T b) { a = max(a, b); } template void mini(T& a, T b) { a = min(a, b); } void exact_say(double x) { cout << setprecision(numeric_limits::max_digits10) << x << endl; } template vector> fill_vector(int h, int w, T val) { vector> ret; vector v(w, val); rep(h)ret.push_back(v); return ret; } signed main() { ll ans = 0; makei(n); ++n; makes(s); s.insert(0, "X"); FOR(i, 0, n) { FOR(j, i, n) { int k = 2 * j - i; if (j < k && k < n) { if (s[i] == 'U' && s[j] == 'M' && s[k] == 'G')++ans; } } } say(ans); }