#include <stdio.h>
#include <stdlib.h>

typedef struct treeNode{
  int key;
  struct treeNode *p;
  struct treeNode *left;
  struct treeNode *right;
}Node;

void printPreorder(Node *);
void printInorder(Node *);
Node * insert(Node *, Node *);
int find(Node *, int);


int main(){
  Node *T = NULL;
  int m, i, j=0, l, root, k;
  int findAnswer[500000];
  Node *temp;
  char s[7];

  scanf("%d", &m);

  for(i=0; i<m; i++){
    scanf("%s", s);

    if(s[0] == 'i'){
      temp = malloc(sizeof(Node));
      scanf("%d", &(temp->key));
      temp->left = NULL;
      temp->right = NULL;
      T = insert(T, temp);
      //printf("T->key = %d\n", T->key);
    }else if(s[0] == 'p'){
      for(l=0; l < j; l++){
	if(findAnswer[l]){
	  printf("yes\n");
	}else{
	  printf("no\n");
	}
	findAnswer[l] = 0;
      }
      j = 0;
      //printf("ok\n");
      printInorder(T);
      printf("\n");
      printPreorder(T);
      printf("\n");
    }else{
      scanf("%d", &k);
      findAnswer[j] = find(T, k);
      //printf("findAnswer[%d] == %d\n", j, findAnswer[j]);
      j++;
    }
  }
  
  return 0;
}

void printPreorder(Node *N){
  printf(" %d", N->key);

  if(N->left != NULL){
    printPreorder(N->left);
  }

  if(N->right != NULL){
    printPreorder(N->right);
  }

}

void printInorder(Node *N){

  if(N->left != NULL){
    printInorder(N->left);
  }

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

  if(N->right != NULL){
    printInorder(N->right);
  }

}

Node * insert(Node *T, Node *z){
  Node *x, *y;

  y = NULL; // xの親
  x = T;

  while(x != NULL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }else{
      x = x->right;
    }
  }

  z->p = y;
  
  if( y == NULL){
    T = z;
  }else if(z->key < y->key){
    y->left = z;
  }else{
    y->right = z;
  }

  return T;

}

int find(Node *T, int k){
  while(T != NULL && k != T->key){
    if(k < T->key){
      T = T->left;
    }else{
      T = T->right;
    }
  }
  if(T == NULL) return 0;
  if(T->key == k) return 1;
}