#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'M') {
            for (int j = 1; j <= i; j++) {
                if (i - j < 0 || i + j >= n) break;
                if (s[i - j] == 'U' && s[i + j] == 'G') ans++;
            }
        }
    }
    cout << ans << endl;
}