N = gets.to_i S = gets.chomp count = 0 (N - 2).times do |i| (1..(N - 3) / 2 + 1).each do |j| count += 1 if "#{S[i]}#{S[i + j]}#{S[i + 2 * j]}" == 'UMG' end end puts count