N = gets.to_i S = gets $x = 0 $u, $m, $g = "" * 3 N.times do |i| N.times do |j| #p i, j $u = S[j] $m = S[i+j] $g = S[2*i+j] break if $g.nil? #p $u+$m+$g $x+=1 if $u+$m+$g == "UMG" end #break if $g.nil? end p $x