#include <iostream>
#include <memory>
#include <string>

namespace BinarySearchTree{
using namespace std;
constexpr int nullNum = -1;

class Node{
public:
    Node( int k ) : 
    key( k ), parent( nullptr ), left( nullptr ), right( nullptr ) {}

    Node() : 
    key( nullNum ), parent( nullptr ), left( nullptr ), right( nullptr ) {}

    //----Getter----
    int Key(){
        return key;
    }

    int NumOfChildren(){
        return ( left? 1 : 0 ) + ( right? 1 : 0 );
    }

    shared_ptr<Node> Left(){
        return left;
    }

    shared_ptr<Node> Right(){
        return right;
    }

    //----Setter----
    void SetParent( shared_ptr<Node> p ){
        parent = p;
    }

    void SetLeft( shared_ptr<Node> l ){
        left = l;
    }

    void SetRight( shared_ptr<Node> r ){
        right = r;
    }

private:
    int key;
    shared_ptr<Node> parent;
    shared_ptr<Node> left;
    shared_ptr<Node> right;
};

shared_ptr<Node> Find( shared_ptr<Node>& root, int key ){
    shared_ptr<Node>& node( root );
    while( node ){
        if( node->Key() == key ){
            return node;
        }else if( node->Key() < key ){
            node = node->Right();
        }else{
            node = node->Left();
        }
    }
    return nullptr;
}

void FindPrint( shared_ptr<Node>& root, int key ){
    if( Find( root, key ) ){
        std::cout << "yes\n";
        return;
    }
    std::cout << "no\n";
}

void Insert( shared_ptr<Node>& root, shared_ptr<Node>& z ){
    if( root->Key() == nullNum ){
        root.reset();
        root = std::move( z );
    }else{
        shared_ptr<Node> y = nullptr;
        shared_ptr<Node> x = root;
        while( x ){
            y = x;
            if( z->Key() < x->Key() ){
                x = x->Left();
            }else{
                x = x->Right();
            }
        }

        z->SetParent( y );

        if( z->Key() < y->Key() ){
            y->SetLeft( z );
        }else{
            y->SetRight( z );
        }
    }
}

void Delete( shared_ptr<Node>& tree, int key ){
    shared_ptr<Node> node = Find( tree, key );
    if( node ){
        if( !node->NumOfChildren() ){
            //delete node.get();
        }
    }
}

void InorderTreeWalk( shared_ptr<Node> root ){
    if( root ){
        InorderTreeWalk( root->Left() );
        std::cout << " " << root->Key();
        InorderTreeWalk( root->Right() );
    }
}

void PreorderTreeWalk( shared_ptr<Node> root ){
    if( root ){
        std::cout << " " << root->Key();
        PreorderTreeWalk( root->Left() );
        PreorderTreeWalk( root->Right() );
    }
}

}

int main(){
    std::cin.tie( 0 );

    int n;
    std::string command;
    std::getline( std::cin, command );
    n = std::stoi( command );

    int key;
    std::shared_ptr<BinarySearchTree::Node> tree = std::make_shared<BinarySearchTree::Node>();

    for( int i = 0; i < n; ++i ){
        std::getline( std::cin, command );
        if( command[0] == 'i' ){
            key = std::stoi( &command[7] );
            std::shared_ptr<BinarySearchTree::Node> node = std::make_shared<BinarySearchTree::Node>( key );
            //std::cout << "[" << node->Key() << "]\n";
            BinarySearchTree::Insert( tree, node );
        }else if( command[0] == 'f' ){
            key = std::stoi( &command[5] );
            BinarySearchTree::FindPrint( tree, key );
        }else{
            BinarySearchTree::InorderTreeWalk( tree );
            std::cout << "\n";
            BinarySearchTree::PreorderTreeWalk( tree );
            std::cout << std::endl;
        }
    }
}


Measured memory_bytes: 42228