import java.io._
import scala.io.StdIn.{readInt, readLine}

object Main {
  class Node(var key:Int, var left:Node = null, var right:Node = null) { }

        def getNodeToInsert(node:Node,keyNode:Node):Node =
                if(node.key > keyNode.key) {
                        if(node.left == null) node
                        else getNodeToInsert(node.left,keyNode)
                } else {
                        if(node.right == null) node
                        else getNodeToInsert(node.right,keyNode)
                }

  def insert(tree:Node, keyNode:Node) = {
    val target = getNodeToInsert(tree,keyNode)
    if(keyNode.key < target.key) target.left = keyNode
    else target.right = keyNode
  }

  def inOrder(tree:Node):Unit =
    if(tree == null) return
    else {
      inOrder(tree.left)
      printf(" %d",tree.key)
      inOrder(tree.right)
    }

  def preOrder(tree:Node):Unit =
    if(tree == null) return
    else {
      printf(" %d",tree.key)
      preOrder(tree.left)
      preOrder(tree.right)
    }

  def find(tree:Node, key:Int) {
          def loop(node:Node):Unit = {
      if(node == null) {
        printf("no\n")
      } else if(node.key > key) {
        loop(node.left)
      } else if(node.key < key) {
        loop(node.right)
      } else {
        printf("yes\n")
      }
    }
    loop(tree)
  }

  def main(args:Array[String]) = {
    val n = readInt
    val tree = new Node(-1)

    for(i<-0 until n) {
      val s = readLine.split(" ")
      s(0) match {
        case "insert" =>
          if(tree.key == -1) tree.key = s(1).toInt
          else insert(tree, new Node(s(1).toInt))
        case "find" => find(tree, s(1).toInt)
        case _ => {
          inOrder(tree)
          printf("\n")
          preOrder(tree)
          printf("\n")
        }
      }
    }
  }
}