# a->0 x->1 y->2 z->3 w->4 b->5
$graph = [[1, 2], [-1, 3], [1, -1], [4, 5], [5, 2], [2, 1]]
$goal = 5

def wander(data)
  current_city = 0
  data.chars.map(&:to_i).each do |i|
    current_city = $graph[current_city][i]
    return false if current_city == -1
  end
  return (current_city == $goal ? true : false)
end

loop do
  data = gets.chomp
  break if data == '#'
  wander(data) ? (puts "YES") : (puts "NO")
end