# 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]]

loop do
  data = gets.chomp
  break if data == '#'
  current_city = 0
  goal = 5
  data.chars.map(&:to_i).each do |i|
    current_city = graph[current_city][i]
    if current_city == -1
      break
    end
  end

  if current_city == goal
    puts "YES"
  else
    puts "NO"
  end
end