#include using namespace std; int solve(int N, string S){ int count = 0; for (int i = 0; i < N; ++i){ if (S[i] != 'U') continue; for (int s = 1; i + s + s < N; ++s){ int j = i + s; int k = j + s; if (S[j] == 'M' and S[k] == 'G') count++; } } return count; } int main() { cin.tie(0); ios::sync_with_stdio(false); int N; string S; cin >> N >> S; cout << solve(N, S) << endl; return 0; }