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
  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 root
  if root == nil
    puts 'no'
  elsif $key == root.key
    puts 'yes'
  elsif $key < root.key
    find root.left
  else
    find root.right
  end
end

gets.to_i.times {
    command, $key = gets.split
    $key=$key.to_i
    if command == 'insert'
      insert
    elsif command == 'find'
      find $root
    else
      $root.inorder
      puts
      $root.preorder
      puts
    end
}