#include #include #define REP(i, n) for(int i = 0;i < n;i++) #define REPR(i, n) for(int i = n;i >= 0;i--) #define FOR(i, m, n) for(int i = m;i < n;i++) #define FORR(i, m, n) for(int i = m;i >= n;i--) #define SORT(v, n) sort(v, v+n); #define VSORT(v) sort(v.begin(), v.end()); #define VRSORT(v) sort(v.rbegin(), v.rend()); #define ll long long #define pb(a) push_back(a) #define INF 999999999 #define MOD (ll)(1e9+7) #define MAX (ll)(1e5*2+200) #define print(x) cout << x << endl; #define length(arr) sizeof arr / sizeof arr[0]; #define printArr(arr) REP(i, (sizeof arr / sizeof arr[0])){print(arr[i])} #define printVec(vec) REP(i, vec.size()){print(vec[i])} #define VMAX(v) max_element(v.rbegin(), v.rend()) using namespace std; int main(){ cin.tie(0); ios::sync_with_stdio(false); int N; string S; cin >> N >> S; int k, ans = 0; FOR(i, 0, N){ FOR(j, i+1, N){ k = 2*j - i; if(N > k && k > j){ if(S[i] == 'U' && S[j] == 'M' && S[k] == 'G'){ ans += 1; } } } } print(ans); return 0; }