#include using namespace std; using Graph = vector>; using ll = long long; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; int main() { int N; cin >> N; string S; cin >> S; vector I; vector J; vector L; for(int i = 0;i < N; i++) { if('U' == S[i]){ I.push_back(i + 1); } if('M' == S[i]) { J.push_back(i + 1); } if('G' == S[i]) { L.push_back(i + 1); } } map a; int ans = 0; for(int i = 0;i < J.size(); i++) { a[J[i] + J[i]]++; } for(int i = 0; i < I.size(); i++) { for(int j = 0; j < L.size(); j++) { if(a[I[i] + L[j]] == 1) { int z = (I[i] + L[j]) / 2; if(I[i] < z && z < L[j]) { ans++; } } } } cout << ans << endl; }