#include #include using namespace std; int n; string s; int main() { int i, j; int ans = 0; cin >> n >> s; for (i = 0; i < n; i++) { for (j = i + 1; j < n; j++) { int k = j + (j - i); if (k >= n) continue; if (s[i] == 'U' && s[j] == 'M' && s[k] == 'G') ans++; } } cout << ans << endl; return 0; }