#include using namespace std; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; string s; cin >> s; int ans = 0; for(int i = 0; i < n; i++){ if(s[i] == 'U'){ for(int j = i + 1; j < n; j++){ //cout << i << ' ' << j << ' ' << j + j - i << endl; if(j + j - i >= n) continue; if(s[j] == 'M' and s[j + j - i] == 'G') ans++; } } } cout << ans << endl; return 0; }