P = gets.chomp.chars.map(&:to_i) single_flg = false its_over = false P.reverse_each.with_index do |v, idx| if idx == 0 if (2..4).cover?(v) else puts "No" exit end elsif its_over puts "No" exit else if single_flg if (6..7).cover? else puts "No" exit end else if (3..5).cover?(v) # next elsif (7..8).cover?(v) single_flg = true elsif v == 1 its_over = true else puts "No" exit end end end end puts "Yes"