#include "bits/stdc++.h" using namespace std; using ll = long long; using ld = long double; using pii = pair; using vi = vector; using vl = vector; ld EPS = 1e-12; int INF = numeric_limits::max() / 2; int MOD = 1e9 + 7; #define rep(i,n) for(int i = 0; i < n; i++) #define all(obj) (obj).begin(), (obj).end() #define debug(x) cerr << #x << ": " << x << '\n' int main(){ int n; string s; cin >> n >> s; int ans = 0; for(int i = 0; i < n; i++){ for(int dis = 0; dis <= (n-i)/3; dis++){ int temp = dis+1; if(s[i] == 'U' && s[i+temp] == 'M' && s[i+temp*2] == 'G') ans++; } } cout << ans <<'\n'; return 0; }