node = Struct.new(:key, :parent, :left, :right)
root = nil

insert = ->(z) {
  pa = nil
  x = root
  while x
    pa = x
    x = (z.key < x.key) ? x.left : x.right
  end
  z.parent = pa
  
  if pa.nil?
    root = z
  elsif z.key < pa.key
    pa.left  = z
  else
    pa.right = z
  end
}

inorder = ->(x) {
  a = x.left
  inorder.(a) if a
  print " " + x.key.to_s
  a = x.right
  inorder.(a) if a
}

preorder = ->(x) {
  print " " + x.key.to_s
  a = x.left
  preorder.(a) if a
  a = x.right
  preorder.(a) if a
}

find = ->(x, k) {
  f = false
  try = ->(node) {
    if node.key == k
      f = true
    else
      a = node.left
      try.(a) if a
      a = node.right
      try.(a) if a
    end
  }
  try.(x) 
  puts f ? "yes" : "no" 
}

gets.to_i.times do
  command = gets.split(" ")
  case command[0]
  when "insert"
    z = node.new
    z.key = command[1].to_i
    insert.(z)
  when "print"
    inorder .(root)
    puts
    preorder.(root)
    puts
  when "find"
    find.(root, command[1].to_i)
  end
end
