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