import java.io.*; import java.util.Scanner; public class Main_yukicoder805 { private static Scanner sc; private static Printer pr; private static void solve() { int n = sc.nextInt(); char[] s = sc.next().toCharArray(); int ans = 0; for (int i = 0; i < n; i++) { for (int j = 1; i + j + j < n; j++) { if (s[i] == 'U' && s[i + j] == 'M' && s[i + j + j] == 'G') { ans++; } } } pr.println(ans); } // --------------------------------------------------- public static void main(String[] args) { sc = new Scanner(System.in); pr = new Printer(System.out); solve(); pr.close(); sc.close(); } static class Printer extends PrintWriter { Printer(OutputStream out) { super(out); } } }