mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.readline N = int(input()) S = input().rstrip('\n') ans = 0 for i in range(N): for k in range(i+1, N): if i%2 == k%2: j = (i+k) // 2 if S[i] == "U" and S[j] == "M" and S[k] == "G": ans += 1 print(ans) if __name__ == '__main__': main()