#include <algorithm>
#include <iostream>
#include <stack>
using namespace std;

struct Node{
    Node *right;
    Node *left;
    Node *parent;
    int key;
    Node(Node *r, Node *l, Node *p, int k) : right(r), left(l), parent(p), key(k){};
};

class Tree{
    Node* root;
public:
    Tree(){root = 0; }
    void insert(int v){
        Node *z = new Node(0, 0, 0, v);
        Node *y = 0;
        Node *x = root;
        while(x != 0){
            y = x;
            if (z->key < x-> key){
                x = x->left;
            } else {
                x = x->right;
            }
        }
        z->parent = y;
        if (y==0){
            root = z;
        } else if (z->key <  y->key){
            y->left = z;
        } else {
            y->right = z;
        }
    }
    
    void mainoutput(){
        outputInorder();
        outputPreorder();
    }
    
    void outputPreorder(){
        stack<Node*> pre;
        pre.push(root);
        while(!pre.empty()){
            Node *buf = pre.top(); pre.pop();
            cout << " " << buf->key;
            if (buf->right != 0) pre.push(buf->right);
            if (buf->left != 0) pre.push(buf->left);
        }
        cout << endl;
    }
    
    void outputInorder(){
        if (root == 0) return;
        Node* cur = root;
        Node* prev = cur->parent;
        while(cur!=0){
            if (cur->parent == prev){
                if (cur->left != 0){
                    prev = cur;
                    cur = cur->left;
                    continue;
                } else {
                    prev = cur->left;
                }
            }
            if (prev == cur->left){
                cout << " " << cur->key;
                if (cur->right != 0){
                    prev = cur;
                    cur = cur->right;
                    continue;
                } else {
                    prev = cur->right;
                }
            }
            
            if (prev == cur->right){
                prev = cur;
                cur = cur->parent;
            }
        }
        cout << endl;
    }
    
    void find(int num){
        find_under(num, root);
    }
    
    void find_under(int num, Node* v){
        if (v == 0){
            cout << "no" << endl;
        } else {
            if (num == v->key){
                cout << "yes" << endl;
            } else if (num > v->key){
                if (v->right == 0){
                    cout << "no" << endl;
                } else {
                    find_under(num, v->right);
                }
            } else if (num < v->key){
                if (v->left == 0){
                    cout << "no" << endl;
                } else {
                    find_under(num, v->left);
                }
            }
        }
    }
};

int main(){
    Tree tree;
    int n;
    cin >> n;
    for(int i=0; i<n; ++i){
        string str;
        int num;
        cin >> str;
        if (str == "insert"){
            cin >> num;
            tree.insert(num);
        } else if (str == "print"){
            tree.mainoutput();
        } else if (str == "find"){
            cin >> num;
            tree.find(num);
        } 
    }
    return 0;
}

Measured memory_bytes: 19964