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