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