#include #define INF 2147483647 #define INF_LL 9223372036854775807 #define MOD 1000000007 using namespace std; typedef long long int ll; typedef unsigned long long int ull; int main() { int N; string S; cin >> N >> S; int ans = 0; for (int i = 0; i < N; i++) { for (int j = 1; j <= (N / 3 + (int)(N / 2 != 1)); j++) { if (i + j * 2 >= S.size())continue; if (S[i] == 'U' && S[i + j] == 'M' && S[i + j * 2] == 'G')ans++; } } cout << ans << endl; }