#include #include #include #include #include #define Max(a, b) ((a) > (b) ? (a) : (b)) #define Min(a, b) ((a) > (b) ? (b) : (a)) #define abs(x) ((x) > 0 ? (x) : -(x)) #define rep(i, n) for(int i = 0; i < (n); i++) #define INF 1000000000000 //10^12 #define MOD 1000000007 //10^9 + 7 #define endl printf("\n") typedef long long ll; int main(int argc, char **argv) { int n; char s[5001]; scanf("%d", &n); scanf("%s", s); int cnt = 0; for(int i = 0; i < n; i++){ for(int j = i + 1; j < n; j++){ if(s[i] == 'U' && s[j] == 'M'){ if(2 * j - i < n &&s[2 * j - i] == 'G'){ cnt++; } } } } printf("%d\n", cnt); return 0; }