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

#include <cstdio>

#include <cstring>

using namespace std;



const int maxn = 500000 + 5;



struct Node{

	int value;

	Node *Left_Child,*Right_Child;

}pool[maxn],*tail = pool;



Node *root,*NUL;



void Insert(int key){

	Node *x = tail++;

	Node *fa = NUL;

	Node *cur = root;

	

	x->value = key;

	x->Left_Child = NUL;

	x->Right_Child = NUL;

	

	while(cur != NUL){

		fa = cur;

		if(cur->value > x->value)cur = cur->Left_Child;

		else cur = cur->Right_Child;

	}

	

	if(fa == NUL)root = x;

	else {

		if(fa->value > x->value)fa->Left_Child = x;

		else fa->Right_Child = x;

	}

}



void Preorder(Node *cur){

	if(cur == NUL)return;

	printf(" %d",cur->value);

	Preorder(cur->Left_Child);

	Preorder(cur->Right_Child);

}



void Inorder(Node *cur){

	if(cur == NUL)return;

	Inorder(cur->Left_Child);

	printf(" %d",cur->value);

	Inorder(cur->Right_Child);

}



bool find(int key){

	Node *cur = root;

	while(cur != NUL){

		if(cur->value > key)cur = cur->Left_Child;

		else if(cur->value < key)cur = cur->Right_Child;

		else return true;

	}

	return false;

}



int main(){

	int n;

	scanf("%d",&n);

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

		char s[15];

		scanf("%s",s);

		if(strcmp(s,"insert") == 0){

			int key;

			scanf("%d",&key);

			Insert(key);

		}

		else if(strcmp(s,"print") == 0){

			Inorder(root);

			printf("\n");

			Preorder(root);

			printf("\n");

		}

		else {

			int key;

			scanf("%d",&key);

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

			else printf("no\n");

		}

	}

}

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

}