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

#define NIL NULL/*??????????????§???????????§NULL????????¨?????¨??????*/
struct node{
  int key;
  struct node *parent;
  struct node *left;
  struct node *right;
};

typedef struct node * Node;/*?§???????node?????????????????¨????????£?¨?*/


void insert(Node,int);
Node Find(Node,int);
void PrintInorder(Node );
void PrintPreorder(Node );
Node root,newnode;
main()
{
  int number,k,i;
  char str[20];
  
  scanf("%d",&number);
  root = malloc(sizeof(struct node));
  for(i=0;i<number;i++)
    {
      scanf("%s",str);
      if(str[0]=='i')
	{
	  scanf("%d",&k);
	  if(i !=0) {
	    
	    insert(root,k);}/*??????Tree????????£????????????????????¢??°????????????*/	
	  else root->key = k;
	 
	  
	}
      else if(str[0] == 'p'){
      PrintInorder(root);
      printf("\n");
      PrintPreorder(root);
      printf("\n"); 
    }	
      else{
	scanf("%d",&k);
	if(Find(root,k)==NIL)printf("no\n");
	else printf("yes\n"); 
      }
    }
return 0;
}

void insert(Node t,int k)
{
  Node y,x,z;
  /*??????????????§????????????????????§malloc?????????????????£??\??§?????????*/
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = z->right = NIL;
 
  

  y = NIL;/*????????§????????????????????? y???x??????????????????*/
  x = t;/*T=root*/ 
  
  while(1)
    {
      y = x;/*??????????????????*/
      
      if(z->key < x->key) x = x->left;
      else x = x->right;
      
      if(x == NIL)break;
    }

   z->parent = y;
   if(y == NIL)t = z;/*??????????¨???????????????¨??§??????root?????£??\??§?????????*/

   else if(z->key < y->key) y->left = z;
   else y->right = z;


}

void PrintInorder(Node T)
{
  if(T != NIL){
     PrintInorder(T->left);
  
  
  printf(" %d",T->key);
 
 
   PrintInorder(T->right);
  }
  else return;
  
}

void PrintPreorder(Node T)
{
  if(T != NIL){
    printf(" %d",T->key);

    PrintPreorder(T->left);
    PrintPreorder(T->right);

  }
  else return ;
 
}


Node Find(Node T,int k)
{
  if(T == NIL || k == T->key)return T;
  if(k < T->key)return Find(T->left,k);
  else return Find(T->right,k);

}