#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

struct Tree {
    struct Node {
        int value;
        Node *left;
        Node *right;
    };

    vector<Node> nodes;
    int size;

    vector<int> order;

    Tree() : size(0), nodes(500000) {
    }

    Node CreateNode(int value) {
        Node me;
        me.value = value;
        me.left = nullptr;
        me.right = nullptr;
        return me;
    }

    void Insert(int value) {
        if(size == 0) {
            nodes[size++] = CreateNode(value);
        }
        else {
            nodes[size] = CreateNode(value);
            Node *me  = &nodes[size];
            ++size;

            Node *cur = &nodes[0];
            while(true) {
                if(value < cur->value) {
                    if(cur->left == nullptr) {
                        cur->left = me;
                        break;
                    }
                    else {
                        cur = cur->left;
                    }
                }
                else if (value > cur->value) {
                    if(cur->right == nullptr) {
                        cur->right = me;
                        break;
                    }
                    else {
                        cur = cur->right;
                    }
                }
                else {
                    cerr << "conflict occured" << endl;
                    abort();
                }
            }
        }
    }  // void Insert(int value)

    void ShowWithInorderWalk() {
        if(size == 0) return;
        order.clear();
        ShowWithInorderWalkInner(&nodes[0]);
    }

    void ShowWithInorderWalkInner(const Node *cur) {
        if(cur->left != nullptr) ShowWithInorderWalkInner(cur->left);
        order.push_back(cur->value);
        if(cur->right != nullptr) ShowWithInorderWalkInner(cur->right);
    }

    void ShowWithPreorderWalk() {
        if(size == 0) return;
        order.clear();
        ShowWithPreorderWalkInner(&nodes[0]);
    }

    void ShowWithPreorderWalkInner(const Node *cur) {
        order.push_back(cur->value);
        if(cur->left != nullptr) ShowWithPreorderWalkInner(cur->left);
        if(cur->right != nullptr) ShowWithPreorderWalkInner(cur->right);
    }

    bool HasKey(int value) {
        if(size == 0) return false;
        Node *cur = &nodes[0];
        while(true) {
            if(cur->value == value) return true;
            if(cur->left != nullptr && value < cur->value) {
                cur = cur->left;
            }
            else if(cur->right != nullptr && value > cur->value) {
                cur = cur->right;
            }
            else {
                return false;
            }
        }
        return false;
    }
};

int main() {
    Tree tree;
    int N; cin >> N;
    while(N--) {
        string cmd;
        cin >> cmd;
        if(cmd == "print") {
            tree.ShowWithInorderWalk();
            for(int item : tree.order) {
                cout << ' ' << item;
            }
            cout << endl;
            tree.ShowWithPreorderWalk();
            for(int item : tree.order) {
                cout << ' ' << item;
            }
            cout << endl;
        }
        else if(cmd == "find") {
            int value; cin >> value;
            cout << (tree.HasKey(value) ? "yes" : "no") << endl;
        }
        else {
            int value; cin >> value;
            tree.Insert(value);
        }
    }
}

Measured memory_bytes: 14884