#!/usr/bin/ruby s=gets.chomp.chars.map(&:to_i) f=true (s.size-1).downto(0){|i| if f&&[2,3,4].include?(i) if i==0 puts :No exit end s[i-1]-=1 elsif [6,7].include?(i) f=false else puts :No exit end } puts :Yes