#include<stdio.h>
#define NIL -1
#define MAX 500000

void insert(int);
int find(int);
void print();
void pO(int);
void iO(int);

int Root = NIL;
int l[MAX],r[MAX],key[MAX],p[MAX];

int main(){
  
  int i,j,k=0;
  int N;
  char in[15];
  
  scanf("%d",&N);
  for(i=0;i<MAX;i++) key[i]=l[i]=r[i]=p[i]=NIL;
  for(i=0;i<N;i++){
    scanf("%s",in);
    if(in[0]=='i'){
      scanf("%d",&j);
      key[k]=j;
      insert(k++);
    }
    else if(in[0]=='p')print();
    else if(in[0]=='f'){
       scanf("%d",&j);
       if(find(j)==1)printf("yes\n");
       else printf("no\n");
    }
  }
  
  return 0;
}

void insert(int a){
  int x=NIL;
  int y=Root;
  while(y!=NIL){
    x=y;
    if(key[a]<key[y]) y=l[x];
    else y=r[y];
  }
  p[a]=y;
  if(x==NIL) Root=a;
  else if(key[a]<key[x]) l[x]=a;
  else r[x]=a;  
}

int find(int b){
  int i=0;
  int x=NIL,y=Root;
   while(y!=NIL){
     if(key[y]==b)return 1;
    x = y;
    if(b<key[y]) y=l[y];
    else y=r[y];
  }
   return 0;
}

void print(){
  iO(Root);
  printf("\n");
  pO(Root);
  printf("\n");
}

void pO(int c){
  if(c==NIL)return;
  printf(" %d",key[c]);
  pO(l[c]);
  pO(r[c]);
}

void iO(int d){
  if(d==NIL)return;
  iO(l[d]);
  printf(" %d",key[d]);
  iO(r[d]);
}



