def main(): n = int(input()) s = list(input()) a = 0 for j in range(1,n): if s[j] != 'M': continue else: for i in range(j): if s[i] != 'U': continue else: if 2 * j - i >= n: continue else: a += 1 if s[2 * j - i] == 'G' else 0 print(a) if __name__ == '__main__': main()