def min(a, b): return a if a <= b else b n = int(input()) s = input() s_list = list(s) num_M = s_list.count('M') checked_M = 0 count = 0 while checked_M != num_M: M_index = s_list.index('M') distance = min(M_index - 0, (n - 1) - M_index) ss_list = s_list[M_index - distance : M_index + distance + 1] # print('ss_list before: {}'.format(ss_list)) num_U = ss_list.count('U') M_index_ss = ss_list.index('M') for i in range(num_U): U_index = ss_list.index('U') if U_index > M_index_ss: break else: ss_list[U_index] = 'x' distance_ss = M_index_ss - U_index # print('M_index_ss: {}'.format(M_index_ss)) # print('U_index: {}'.format(U_index)) # print('distance_ss: {}'.format(distance_ss)) if ss_list[M_index_ss + distance_ss] == 'G': count += 1 # print('ss_list after: {}'.format(ss_list)) # print('count: {}'.format(count)) # after founding 'umg' s_list[M_index] = 'x' checked_M += 1 print(count)