#include <stdio.h>
#include <stdlib.h>
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node *NODE;
#define NIL NULL
NODE root;
NODE min(NODE);
NODE max(NODE);
int search(NODE,int);
NODE successor(NODE);
void delete(int);
void insert(int);
void inorder(NODE);
void preorder(NODE);
int main(){
  int n,i,x,t;
  char com[20];
  scanf("%d", &n);

  for (i=0;i<n;i++){
    scanf("%s", com);
    if (com[0]=='f'){
      scanf("%d", &x);
      t = search(root, x);
      if (t==1) printf("yes\n");
      else printf("yes\n");
    } else if (com[0]=='i'){
      scanf("%d", &x);
      insert(x);
    } else if (com[0]=='p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if (com[0]=='d'){
      scanf("%d", &x);
      delete(search(root, x));
    }
  }
  free(root);
  return 0;
}
NODE min(NODE x){
}
NODE max(NODE x){
}
int search(NODE x,int k){
  if(x->key==k)return 1;
  else if(x->key < k) search(x->right,k);
  else if(x->key > k) search(x->left,k);
  else return -1;
}
NODE successor(NODE x){
}
void delete(int x){
}
void insert(int k){
  NODE y = NIL;
  NODE x = root;
  NODE z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x!=NIL){
    y=x;
    if(z->key < x->key)x=x->left;
    else x=x->right;
  }
    z->parent=y;
    if(y==NIL)root=z;
    else if(z->key < y->key)y->left=z;
    else y->right=z;
}
void inorder(NODE x){
if(x->left!=NIL && x->right!=NIL){
    inorder(x->left);
    printf(" %d",x->key);
    inorder(x->right);
  
  }
  if(x->left!=NIL && x->right==NIL){
   inorder(x->left);
     printf(" %d",x->key);  
  }
  
  if(x->right!=NIL && x->left==NIL){
  printf(" %d",x->key);
  inorder(x->right); 
  
  }
  if(x->left==NIL && x->right==NIL)printf(" %d",x->key);
}
void preorder(NODE x){
printf(" %d",x->key);
  if(x->left!=NIL){
    preorder(x->left);
  }
  if(x->right!=NIL){
    preorder(x->right);
  }
}

