// 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.00789395410486x):
#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;

}