#include <stdio.h>
#define MAX 500000
 
int root = -1;
int key[MAX];
int left[MAX];
int right[MAX];
int k[MAX];
 
void insert(int n){
  int a = -1;
  int b = root;
  while(b!=-1){
    a = b;
    if(key[n]<key[b]){
      b = left[b];
    }
    else{
 b = right[b];
}
  }
 
  p[n] = a;
  if(a==-1){
 root = n;
}
  else if(key[z]<key[a]){
 left[a] = n;
}
  else{
 right[a] = n;
}
}
 
void preorder(int n){
  if(n == -1) return;
  printf(" %d",key[n]);
  preorder(left[n]);
  preorder(right[n]);
}
 
void inorder(int n){
  if(n == -1){
 return;
}
  inorder(left[n]);
  printf(" %d",key[n]);
  inorder(right[n]);
}
 
void print(){
  inorder(root);
  printf("\n");
  preorder(root);
  printf("\n");
}
 
int find(int n){
  int i = 0,b = root;
  int y = -1;
  while(b!=-1){
    if(key[b] == t) return 1;
    y = b;
    if(t<key[b]) b = left[b];
    else b = right[b];
  }
  return 0;
}
 
int main(){
  int i,n,x;
  int z =0;
  char A[10];
  scanf("%d",&n);
  for(i=0;i<MAX;i++){
    key[i] = -1;
    left[i] = -1;
    right[i] = -1;
    p[i] = -1;
  }
 
  for(i=0;i<n;i++){
    scanf("%s",A);
    if(A[0]=='i'){
      scanf("%d",&x);
      key[z] = x;
      insert(z);
      z++;
    }
    else if(A[0]=='p'){
 print();
}
    else if(A[0]== 'f'){
      scanf("%d",&x);
      if(find(x)==1){
 printf("yes\n");
}
      else{
 printf("no\n");
}
    }
  }
  return 0;
}