N = int(input()) S = input() cnt=0 for i in range(len(S)-2): if S[i]=='U': for j in range(i+1, len(S)-1): if S[j]=='M': if j+j-i