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