class MyNode
  attr_accessor :v, :parent, :left_child, :right_child

  def initialize v, parent, left_child, right_child
    @v = v
    @parent = parent
    @left_child = left_child
    @right_child = right_child
  end
end

def insert(root_node, v)
  p = nil
  x = root_node
  while x
    p = x
    if v < x.v
      x = x.left_child
    else
      x = x.right_child
    end
  end
  node = MyNode.new(v, p, nil, nil)
  if p
    if node.v < p.v
      p.left_child = node
    else
      p.right_child = node
    end
  else
    root_node = node
  end

  return root_node
end

def find(root_node, v)
  return true if root_node.v == v
  if v < root_node.v && root_node.left_child
    return find(root_node.left_child, v)
  end
  if v > root_node.v && root_node.right_child
    return find(root_node.right_child, v)
  end
  return false
end

def make_pre node, vs
  vs << node.v
  make_pre node.left_child, vs if node.left_child
  make_pre node.right_child, vs if node.right_child
  vs
end

def make_in node, vs
  make_in node.left_child, vs if node.left_child
  vs << node.v
  make_in node.right_child, vs if node.right_child
  vs
end

_ = gets
root = nil
while l = gets
  command, val = l.chomp.split(' ')
  if command == 'insert'
    root = insert(root, val.to_i)
  elsif command == 'print'
    puts ' ' + make_in(root, []).join(' ')
    puts ' ' + make_pre(root, []).join(' ')
  elsif command == 'find'
    puts find(root, val.to_i) ? 'yes' : 'no'
  end
end
