class Node
  attr_accessor :key, :left, :right
  def initialize key
    @key = key
  end
  
  def inorder
    left.inorder if left
    print " ", key
    right.inorder if right
  end
  
  def preorder
    print " ", key
    left.preorder if left
    right.preorder if right
  end
end
  
def insert
  z = Node.new $key.to_i
  x = $root
  while x
    y = x
    x = z.key < x.key ? x.left : x.right
  end
  
  unless y
    $root = z
  else
    z.key < y.key ? y.left = z : y.right = z
  end
end

def find(x)
  y = $root
  while y
    if y.key == x
      puts "yes"
      return
    end
    z = y
    y = x < y.key ? y.left : y.right
  end
  puts "no"
end

n = gets.to_i
n.times do
  command, $key = gets.split
  if command == "insert"
    insert
  elsif command == "find"
    find($key.to_i)
  else
    $root.inorder
    puts
    $root.preorder
    puts
  end
end