import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); char[] arr = sc.next().toCharArray(); TreeSet uSet = new TreeSet<>(); TreeSet mSet = new TreeSet<>(); TreeSet gSet = new TreeSet<>(); for (int i = 0; i < n; i++) { if (arr[i] == 'U') { uSet.add(i); } else if (arr[i] == 'M') { mSet.add(i); } else { gSet.add(i); } } long ans = 0; for (int m : mSet) { for (int u : uSet) { if (m < u) { break; } if (gSet.contains(m * 2 - u)) { ans++; } } } System.out.println(ans); } }