class BinarySearchTree
	class Node
		attr_accessor :key, :left, :right
		def initialize(key)
			@key = key
		end
	end

	attr_accessor :root

	def insert(key)
		parent  = nil
		current = @root
		while current
			parent = current
			if key < current.key
				current = current.left
			else
				current = current.right
			end
		end

		new_node = Node.new(key)
		if !parent
			@root = new_node
		elsif key < parent.key
			parent.left = new_node
		else
			parent.right = new_node
		end
	end

	def find(key)
		current = @root
		while current
			return true if key == current.key
			if key < current.key
				current = current.left
			else
				current = current.right
			end
		end
		false
	end

	def keys_inorder
		inorder_helper(@root)
	end

	def keys_preorder
		preorder_helper(@root)
	end

	private
	def inorder_helper(node)
		return [] unless node
		result = []
		result.concat(inorder_helper(node.left))
		result << node.key
		result.concat(inorder_helper(node.right))
	end

	def preorder_helper(node)
		return [] unless node
		result = [node.key]
		result.concat(preorder_helper(node.left))
		result.concat(preorder_helper(node.right))
	end

end

tree = BinarySearchTree.new
n = STDIN.gets.to_i
n.times do
	command, param = STDIN.gets.split[0..1]
	if command == "insert"
		tree.insert(param.to_i)
	elsif command == "find"
		puts (tree.find(param.to_i) ? "yes" : "no")
	elsif command == "print"
		puts " #{tree.keys_inorder.join(" ")}"
		puts " #{tree.keys_preorder.join(" ")}"
	else
		raise "Unexpected input #{command}, #{param}"
	end
end