// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstring>

#include<cstdlib>

#include<ctime>

#define MAXN 500000

struct node

{

	int key;

	node *ch[2];

};

node tree[MAXN+5];

node *Root,*NIL,*ncnt;

//bool first=true;

void Init()

{

	NIL=&tree[0];

	ncnt=&tree[1];

	Root=NIL;

}

inline node *NewNode(int val)

{

	node *p=++ncnt;

	p->key=val;

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

	return p;

}

void Insert(node *&rt,int val)

{

	if(rt==NIL)

	{

		rt=NewNode(val);

		return;

	}

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

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

}

void PreOrder(node *&rt)

{

	if(rt==NIL)

		return;

//	if(first==true)

//		printf("%d",rt->key),first=false;

//	else

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

	PreOrder(rt->ch[0]);

	PreOrder(rt->ch[1]);

}

void InOrder(node *&rt)

{

	if(rt==NIL)

		return;

	InOrder(rt->ch[0]);

//	if(first==true)

//		printf("%d",rt->key),first=false;

//	else

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

	InOrder(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()

{

	Init();

	int n,x;

	char op[100];

	scanf("%d",&n);

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

	{

		scanf("%s",op);

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

			scanf("%d",&x),Insert(Root,x);

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

		{

			InOrder(Root);

			printf("\n");

			PreOrder(Root);

			printf("\n");

		}

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

		{

			scanf("%d",&x);

			if(Find(Root,x)==NIL)

				printf("no\n");

			else

				printf("yes\n");

		}

	}

	return 0;

}

// Fastest known solution for this problem: