import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int ans = 0; int n = sc.nextInt(); String s = sc.next(); for(int j = 1; j < n; j++) { if(s.charAt(j) == 'M') { for(int dist = 1; dist < n; dist++) { int i = j - dist; int k = j + dist; if(0 <= i && k < n) { if(s.charAt(i) == 'U' && s.charAt(k) == 'G') { ans++; } } } } } System.out.println(ans); } }