#include #include using namespace std; int main() { int N; cin >> N; string S; cin >> S; int ans = 0; for (int i = 0; 2 * (i + 1) < N; ++i) { for (int j = 0; 2 * (i + 1) + j < N; ++j) { if (S[j] == 'U' && S[i + j + 1] == 'M' && S[2 * (i + 1) + j] == 'G') ++ans; } } cout << ans; }