import collections N = int(input()) S= input() U = [] M = [] G = collections.defaultdict(int) for i in range(N): if S[i]=='U': U.append(i) elif S[i]=='M': M.append(i) else: G[i]=1 ans = 0 for u in U: for m in M: if u