#include #define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1)) using namespace std; using ll = long long; using pii = pair; constexpr int MOD = int(1e9 + 7); constexpr int INF = int(1e9 + 1); constexpr ll LLINF = ll(4 * 1e18 + 1); // constexpr int INF = 2147483647; // 2 * 1e9 // constexpr ll LLINF = 9223372036854775807; // 9 * 1e18 const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1, 0}; const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1, 0}; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(10); int n; string s; cin >> n >> s; ll ans = 0; for(int i = 0; i < n; ++i){ for(int j = 1; i - j >= 0 && i + j < n; ++j){ if(s[i - j] == 'U' && s[i] == 'M' && s[i + j] == 'G') ++ans; } } cout << ans << "\n"; return 0; }