ws = 0 gs = 0 gets.to_i.times do possible = true gets.chomp.chars.each do |c| case c when "W" ws += 1 when "G" if ws <= 0 possible = false break end ws -= 1 gs += 1 when "R" if gs <= 0 possible = false break end gs -= 1 end end if possible && gs.zero? puts "possible" else puts "impossible" end end