# frozen_string_literal: true N = gets.to_i S = gets.chars count = 0 (0..N - 3).each do |i| next unless S[i] == 'U' (i + 1..N - 2).each do |j| next unless S[j] == 'M' count += 1 if S[2 * j - i] == 'G' end end puts count