import scala.io.StdIn.{readInt, readLine}
object Main {
    def main(args: Array[String]): Unit = {
        val cnt = readInt;
        val binTree = new BinaryTree[Long,Boolean]((k1, k2) => if (k1 < k2) -1 else if (k1 > k2) 1 else 0);
        (0 until cnt).foreach { i =>
            readLine.split(" ") match {
                case Array("insert", key) => binTree.insert(key.toLong, true);
                case Array("find", key) => {
                    if (binTree.find(key.toLong) != None) println("yes") else println("no");
                }
                case Array("print") => {
                    println(" " + binTree.fetchInorder.map(_._1).mkString(" "));
                    println(" " + binTree.fetchPreoder.map(_._1).mkString(" "));
                }
            }
        }
    }
}
class BinaryTree[A,B](val compare: (A,A) => Int) {
    case class RootNode(var child: TreeNode);
    case class TreeNode(key: A, value: B, var left: TreeNode, var right: TreeNode);
    var tree: RootNode = RootNode(null);
    
    def isEmpty(): Boolean = if (tree.child == null) true else false;
    
    // 要素を登録する
    def insert(key: A, value: B): Unit = {
        def _insert(curr: TreeNode): Unit = {
            if (compare(key, curr.key) < 0) { // 追加対象ノードのほうが小さい
                if (curr.left == null) curr.left = TreeNode(key, value, null, null) else _insert(curr.left);
            } else if (compare(key, curr.key) > 0) { // 追加対象ノードのほうが大きい
                if (curr.right == null) curr.right = TreeNode(key, value, null, null) else _insert(curr.right);
            }
        }
        if (isEmpty) tree.child = TreeNode(key, value, null, null) else _insert(tree.child);
    }
    
    // key を探索する
    def find(key: A): Option[B] = {
        def _find(curr: TreeNode): Option[B] = {
            if (compare(key, curr.key) == 0) {
                Some(curr.value);
            } else if (compare(key, curr.key) < 0) {
                if (curr.left == null) None else _find(curr.left);
            } else {
                if (curr.right == null) None else _find(curr.right);
            }
        }
        if (isEmpty) None else _find(tree.child);
    }

    // 先行巡回で要素を返す
    def fetchPreoder(): List[(A, B)] = {
        def _fetchPreoder(curr: TreeNode, ret: List[(A, B)]): List[(A, B)] = {
            if (curr == null) {
                ret;
            } else {
                val ret1 = (curr.key, curr.value) :: ret;
                val ret2 = _fetchPreoder(curr.left, ret1);
                val ret3 = _fetchPreoder(curr.right, ret2);
                ret3;
            }
        }
        _fetchPreoder(tree.child, Nil).reverse;
    }
    
    // 中間巡回で要素を返す
    def fetchInorder(): List[(A, B)] = {
        def _fetchInorder(curr: TreeNode, ret: List[(A, B)]): List[(A, B)] = {
            if (curr == null) {
                ret;
            } else {
                val ret1 = _fetchInorder(curr.left, ret);
                val ret2 = (curr.key, curr.value) :: ret1;
                val ret3 = _fetchInorder(curr.right, ret2);
                ret3;
            }
        }
        _fetchInorder(tree.child, Nil).reverse;
    }
}
