#include "bits/stdc++.h" using namespace std; void solve() { int n, ans = 0; string s; cin >> n >> s; for (int x = 1; x <= n/2; x++) { for (int i = 0; i < n; i++) { int j = i + x, k = j + x; if (j < n && k && n) { bool ok = 1; ok &= s[i] == 'U'; ok &= s[j] == 'M'; ok &= s[k] == 'G'; ans += ok; } } } cout << ans << endl; } int main(void) { solve(); //cout << "yui(*-v・)yui" << endl; return 0; }