#include int main() { int N; char S[5000+1]; scanf("%d %s", &N, S); int n = 0; for (int i = 0; i < N; i++) if (S[i] == 'U') for (int d = 1; i+2*d < N; d++) if (S[i+d] == 'M' && S[i+2*d] == 'G') n++; printf("%d\n", n); return 0; }