using System;

namespace B
{
    class Node
    {
        public int key = -1;
        public int id;
        public int left = -1;
        public int right = -1;
        public void node()
        {
            key = -1;
        }
    }

    class Tree
    {
        public Node[] node = new Node[500001];
    }

    class Output
    {
        public void insert(ref Tree tree, int key, int nowid)
        {
            if (tree.node[0].key == -1)
            {
                tree.node[0].key = key;
            }
            else
            {
                int x = 0, parent = 0;
                while (x != -1)
                {
                    parent = tree.node[x].id;
                    if (key < tree.node[x].key)
                    {
                        x = tree.node[x].left;
                    }
                    else
                    {
                        x = tree.node[x].right;
                    }
                }

                if (key < tree.node[parent].key)
                {
                    tree.node[parent].left = nowid;
                }
                else
                {
                    tree.node[parent].right = nowid;
                }
                tree.node[nowid].key = key;
            }
        }

        public void inorder(Tree tree, int key)
        {
            if (tree.node[key].left != -1)
            {
                inorder(tree, tree.node[key].left);
            }
            Console.Write(" " + tree.node[key].key);
            if (tree.node[key].right != -1)
            {
                inorder(tree, tree.node[key].right);
            }
        }

        public void preorder(Tree tree, int key)
        {
            Console.Write(" " + tree.node[key].key);
            if (tree.node[key].left != -1)
            {
                preorder(tree, tree.node[key].left);
            }
            if (tree.node[key].right != -1)
            {
                preorder(tree, tree.node[key].right);
            }
        }

        public void find(Tree tree, int key, int id)
        {
            if (id == -1)
            {
                Console.WriteLine("no");
            }
            else if (tree.node[id].key == key)
            {
                Console.WriteLine("yes");
            }
            else if (key < tree.node[id].key)
            {
                find(tree, key, tree.node[id].left);
            }
            else
            {
                find(tree, key, tree.node[id].right);
            }
        }
    }

    class B
    {
        static void Main(string[] args)
        {
            string input1 = Console.ReadLine();
            int n = int.Parse(input1), i;
            string[] input2 = new string[2];
            Output output = new Output();
            Tree tree = new Tree();
            int count = 0;
            for (i = 0; i < tree.node.Length; i++)
            {
                tree.node[i] = new Node();
                tree.node[i].id = i;
            }
            for (i = 0; i < n; i++)
            {
                input2 = Console.ReadLine().Split(' ');
                if (input2[0] == "print")
                {
                    output.inorder(tree, 0);
                    Console.WriteLine();
                    output.preorder(tree, 0);
                    Console.WriteLine();
                }
                else if(input2[0]=="find")
                {
                    output.find(tree, int.Parse(input2[1]), 0);
                }
                else
                {
                    output.insert(ref tree, int.Parse(input2[1]), count);
                    count++;
                }
            }
        }
    }
}



Measured memory_bytes: 41652