#include using namespace std; using lint = long long; template using V = vector; template using VV = V< V >; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; string s; cin >> s; int res = 0; for (int x = 1; x <= n; ++x) { for (int j = 0; j < n; ++j) { int i = j - x, k = j + x; if (i < 0 or k >= n) continue; res += s[i] == 'U' and s[j] == 'M' and s[k] == 'G'; } } cout << res << '\n'; }