typedef long long ll; #include using namespace std; template void Fill(A (&array)[N], const T &val){ std::fill( (T*)array, (T*)(array+N), val ); } int main() { ll n; string s; std::cin >> n; ll result = 0; std::cin >> s; for (int i =1; i <= n/2; i++) { for (int j = 0; j < n; j++) { ll c1,c2,c3; c1 = j; c2 = j+i; c3 = j+2*i; if(j+2*i>n-1)break; if( s[c1] == 'U' && s[c2] == 'M' && s[c3] == 'G'){ result++; } } } std::cout << result << std::endl; }