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

#include <cstring>

#include <iostream>

#include <algorithm>

#include <vector>

#include <stack>

#include <queue>

#include <set>

#include <map>

#include <string>

#include <cmath>

#include <cstdlib>

using namespace std;





struct Node {

    int v;

    Node* l;

    Node* r;

};



Node* root = NULL;



bool find(int v) {

    Node* x = root;

    while (x && x->v != v) {

        if (v < x->v) {

            x = x -> l;

        } else if (v > x-> v) {

            x = x -> r;

        } 

    }

    if (x && x->v == v) return true;

    return false;

}



void insert(int v) {

    if (!root) {

        root = new Node;

        root -> v = v;

        root -> l = NULL;

        root -> r = NULL;

        return;

    }



    Node* par = NULL;

    Node* x = root;

    while (x) {

        par = x;

        if (v < x -> v) {

            x = x -> l;

        } else {

            x = x -> r;

        }

    }

    if (v < par->v) {

        par -> l = new Node;

        Node* p = par -> l;

        p -> v = v;

        p -> l = NULL;

        p -> r = NULL;

    } else {

        par -> r = new Node;

        Node* p = par -> r;

        p -> v = v;

        p -> l = NULL;

        p -> r = NULL;

    }

}



void preOrder(Node* root) {

    if (root == NULL) return ;

    printf(" %d", root -> v);

    preOrder(root -> l);

    preOrder(root -> r);

}



void inOrder(Node* root) {

    if (root == NULL) return ;

    inOrder(root -> l);

    printf(" %d", root -> v);

    inOrder(root -> r);

}





int main() {

    //freopen("in.txt", "r", stdin);

    //freopen("out.txt", "w", stdout);

    int n;

    int num;

    char s[10];

    scanf("%d", &n);

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

        scanf("%s", s);

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

            scanf("%d", &num);

            insert(num);

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

            inOrder(root);

            printf("\n");

            preOrder(root);

            printf("\n");

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

            scanf("%d", &num);

            if (find(num)) printf("yes\n");

            else printf("no\n");

        }

    }

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.020144640537254x):
#include<cstdio>

#define MAXN 500000

struct node{

	int key;

	node *ch[2],*fa;

};

node tree[MAXN+5];

node *Root,*NIL,*ncnt;

void Init(){

	NIL=&tree[0];

	NIL->fa=NIL->ch[0]=NIL->ch[1]=NIL;

	ncnt=&tree[1];

	Root=NIL;

}

inline node * NewNode(int val){

	node *p=++ncnt;

	p->key=val;

	p->fa=p->ch[0]=p->ch[1]=NIL;

	return p;

}

void Insert(node *&rt,node *fa,int val){

	if(rt==NIL){

		rt=NewNode(val);

		rt->fa=fa;

		return ;

	}

	int d=(val>=rt->key);

	Insert(rt->ch[d],rt,val);

}

void InOrder(node *rt){

	if(rt==NIL)return ;

	InOrder(rt->ch[0]);

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

	InOrder(rt->ch[1]);

}

void PreOrder(node *rt){

	if(rt==NIL)return ;

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

	PreOrder(rt->ch[0]);

	PreOrder(rt->ch[1]);

}

node *Find(node *rt,int val){

	if(rt==NIL)return NIL;

	if(rt->key==val)return rt;

	int d=(val>=rt->key);

	return Find(rt->ch[d],val);

}

int main(){

	int n,x;

	char op[100];

	Init();

	scanf("%d",&n);

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

	{

		scanf("%s",op);

		if(op[0]=='p')

		{

			InOrder(Root);puts("");

			PreOrder(Root);puts("");

		}

		if(op[0]=='i')

		{

			scanf("%d",&x);

			Insert(Root,NIL,x);

		}

		if(op[0]=='f')

		{

			scanf("%d",&x);

			node *p=Find(Root,x);

			if(p==NIL)puts("no");

			else puts("yes");

		}

		if(op[0]=='d')

		{

			

		}

	}

	return 0;

}