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

#include<vector>

#include<cstdlib>

#include<iostream>

using namespace std;

struct Node{

Node *parent,*left,*right;

int key;

};

Node *NIL,*root;

Node *find(Node*u,int k){

   while(u!=NIL&&k!=u->key){

    if(k<u->key)u=u->left;

    else u=u->right;

   }

   return u;

}



void prin_in(Node* node){

    if(node==NIL)return;

    prin_in(node->left);

    printf(" %d",node->key);

    prin_in(node->right);

}

void prin_pre(Node* node){

    if(node==NIL)return;

    printf(" %d",node->key);

    prin_pre(node->left);

    prin_pre(node->right);



}

void insert(int key)

{

    Node *y=NIL;

    Node *x=root;

    Node *z;

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

    z->key=key;

    z->left=NIL;

    z->right=NIL;

    while(x!=NIL){

        y=x;

        if(z->key<x->key)

           x=x->left;

        else

            x=x->right;

    }

    z->parent=y;

    if(y==NIL){

        root=z;

    } else{

            if(z->key<y->key)

                y->left=z;

            else {

                y->right=z;

            }

    }

}

int main(){

   int n,i,x;

   string s;

   scanf("%d",&n);

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

   {

       cin>>s;

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

        scanf("%d",&x);

        insert(x);

       }

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

        scanf("%d",&x);

        Node*t=find(root,x);

        if(t!=NIL)printf("yes\n");

        else printf("no\n");

       }

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

       prin_in(root);

       printf("\n");

       prin_pre(root);

       printf("\n");

       }

   }

   return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.0784538048690555x):
#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;

}