// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<new>

#include<cstdlib>

#include<cstring>

using namespace std;

typedef struct node;

typedef node * tree;

int bianliang=0;

struct node

{

       int data;

       tree lchild,rchild;

};

tree root;

void build(tree &p,int n)

{

     if(p)

     {

          if(n<p->data)

          build(p->lchild,n);

          if(n>p->data)

          build(p->rchild,n);

     }

     else

     {

         p=new node;

         p->data=n;

         p->lchild=NULL;

         p->rchild=NULL;

     }

}    

void find(tree w,int x)

{

     if(w==NULL)bianliang=-1;

     else if(x==w->data)

       bianliang=1;

     else if(x<w->data)

       find(w->lchild,x);

     else if(x>w->data)

       find(w->rchild,x);

}

void beforeorder(tree q)

{

   if(q==NULL)return;

     cout<<" "<<q->data;

     beforeorder(q->lchild);

     beforeorder(q->rchild);

}

void midorder(tree q)

{

     if(q==NULL)return;

       midorder(q->lchild);

       cout<<" "<<q->data;

       midorder(q->rchild);    

}

int main()

{

    int num;

    cin>>num;

    root=NULL;

    for(int i=1;i<=num;i++)

    {  

       string order;

       cin>>order;

       if(order=="insert")

       {

            int leaf;

            cin>>leaf;

            build(root,leaf);

       }

       else if(order=="find")

       {

            int puzzle;

            cin>>puzzle;

            find(root,puzzle);

            if(bianliang==1)cout<<"yes"<<endl;

            else if(bianliang==-1)cout<<"no"<<endl;

       }

       else if(order=="print")

       {

            midorder(root);

            cout<<endl;

            beforeorder(root);

            cout<<endl;

       } 

    }

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.135930480913981x):
#include <stdio.h>

#include <stdlib.h>

typedef struct Node{

    int data;

    struct Node *parent, *left, *right;

}Node;

Node *root;

void insert(int x){

    Node *t = (Node *)malloc(sizeof(Node));

    t->data = x;

    t->left = t->right = t->parent = NULL;



    if(root == NULL){

        root = t;

    }else{

        Node *child = root;

        Node *parent = NULL;

        while(child != NULL){

            parent = child;

            if(x < child->data){

                child = child->left;

            }

            else{

                child = child->right;

            }

        }

        t->parent = parent;

        if(x < parent->data){

            parent->left = t;

        }else{

            parent->right = t;

        }

    }

}

void Preorder(Node *t){

    if(t == NULL) return ;

    printf(" %d", t->data);

    Preorder(t->left);

    Preorder(t->right);

}

void Inorder(Node *t){

    if(t == NULL) return ;

    Inorder(t->left);

    printf(" %d", t->data);

    Inorder(t->right);

}

void find(int b){

    Node *temp = root;

    while(temp != NULL){

        if(temp->data == b){

            printf("yes\n");

            return ;

        }

        if(b < temp->data){

            temp = temp->left;

        }

        else{

            temp = temp->right;

        }

    }

    printf("no\n");

}

int main(){

    root = NULL;

    int n;

    scanf("%d", &n);

    for(int i = 0; i < n; i++){

        char a[10]; int b;

        scanf("%s", a);

        if(a[0] == 'i'){

            scanf("%d", &b);

            insert(b);

        }

        else if(a[0] == 'p'){

            Inorder(root);

            printf("\n");

            Preorder(root);

            printf("\n");

        }

        else if(a[0] == 'f'){

            int c;

            scanf("%d", &c);

            find(c);

        }

    }

    return 0;

}