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

using namespace std;

struct Node{

	int data;

	Node *left;

	Node *right;

	Node(int val=0){

		data=val;

		left=NULL;

		right=NULL;

	}

};

Node *root;

void insert(Node *&root,int x){

	if(root==NULL){

		root=new Node(x);

		return;

	}

	else{

		if(x==root->data) return;

		else if(x<root->data) insert(root->left,x);

		else insert(root->right,x);

	}

	return;

}

void Inorder(Node *node){

	if(node==NULL) return;

	Inorder(node->left);

	cout<<' '<<node->data;

	Inorder(node->right);

}

void Preorder(Node *node){

	if(node==NULL) return;

	cout<<' '<<node->data;

	Preorder(node->left);

	Preorder(node->right);

}

bool find(Node *&root,int x){

	if(root==NULL) return false;

	if(root->data==x) return true;

	else if(root->data<x){

		return find(root->right,x);

	}

	else{

		return find(root->left,x);

	}

}

int main(){

	root=NULL;

	int m;

	cin>>m;

	while(m--){

		string str;

		cin>>str;

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

			int data;

			cin>>data;

			insert(root,data);

		}

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

			int data;

			cin>>data;

			if(find(root,data)) cout<<"yes"<<endl;

			else cout<<"no"<<endl;

		}

		else{

			Inorder(root);

			cout<<endl;

			Preorder(root);

			cout<<endl;

		}

	}

} 

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

}