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