import java.util.*; public class Main { static TreeSet primes; public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); char[] arr = sc.next().toCharArray(); int count = 0; for (int i = 0; i < n; i++) { if (arr[i] != 'U') { continue; } for (int j = 1; i + j * 2 < n; j++) { if (arr[i + j] == 'M' && arr[i + j * 2] == 'G') { count++; } } } System.out.println(count); } }