#include <stdio.h>
#define MAX 500000

int root = -1;
int key[MAX];
int left[MAX];
int right[MAX];
int p[MAX];

void insert(int z){
  int a = -1;
  int b = root;
  while(b!=-1){
    a = b;
    if(key[z]<key[b]){
      b = left[b];
    }
    else b = right[b];
  }

  p[z] = a;
  if(a==-1) root = z;
  else if(key[z]<key[a]) left[a] = z;
  else right[a] = z;
}

void preorder(int t){
  if(t == -1) return;
  printf(" %d",key[t]);
  preorder(left[t]);
  preorder(right[t]);
}

void inorder(int t){
  if(t == -1) return;
  inorder(left[t]);
  printf(" %d",key[t]);
  inorder(right[t]);
}

void print(){
  inorder(root);
  printf("\n");
  preorder(root);
  printf("\n");
}

int find(int t){
  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;
}