import sys input=lambda: sys.stdin.readline().rstrip() n=int(input()) S=input() U=[] ans=0 for i in range(n): if S[i]=="U": U.append(i) elif S[i]=="M": for u in U: if 2*i-u