import collections import itertools def main(): _ = input() s = input() d = collections.defaultdict(list) for i, c in enumerate(s): d[c].append(i) ans = 0 for i, j in itertools.product(d['U'], d['M']): if 2 * j - i in d['G']: ans += 1 print(ans) if __name__ == "__main__": main()