using System.Collections.Generic; using System.Linq; using System; public class Hello { static void Main() { var n = int.Parse(Console.ReadLine().Trim()); var s = Console.ReadLine().Trim(); var u = new List(); var m = new List(); var g = new bool[5010]; for (int i = 0; i < n; i++) { if (s[i] == 'U') u.Add(i + 1); else if (s[i] == 'M') m.Add(i + 1); else g[i + 1] = true; } var ans = getAns(u, m, g); Console.WriteLine(ans); } static int getAns(List u, List m, bool[] g) { var ans = 0; var uc = u.Count(); var mc = m.Count(); if (uc == 0 | mc == 0) return 0; for (int i = 0; i < uc; i++) for (int j = 0; j < mc; j++) { var t = m[j] - u[i]; if (t > 0) { var w = m[j] + t; if (w <= 5001 && g[w]) ans++; } } return ans; } }