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