#include using namespace std; #define rep(i,n) for(int i = 0;i<((int)(n));i++) #define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++) #define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--) #define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--) typedef long long ll; typedef pair mp; ll mod = 1e9+7; //LLONG_MIN /* */ ll n,ans=0; string s; int main(void){ cin>>n>>s; rep(i,n){ if(s[i]=='M'){ reg(j,1,n){ if(i-j<0 || i+j>n-1)break; if(s[i-j]=='U' && s[i+j]=='G')ans++; } } } cout<