#include<stdio.h>
#include<stdlib.h>
#define NIL NULL
struct node{
  struct node *r,*l,*parent;
  int point;
};
typedef struct node * Node;

Node root;

Node tree(Node t, int k){
  while((t != NIL) && (k != t->point)){
    if (k < t->point){
    t = t->l;
    } 
    else t = t->r;
  }
  return t;
}
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
  
  z = malloc(sizeof(struct node));
  z->point = k;
  z->l = z->r =NIL;
 
  while(x != NIL){
    y = x;
    if (z->point < x->point)x = x->l;
    else x = x->r;
  }
  z->parent = y;
  if (y == NIL)root = z;
  else if(z->point < y->point) y->l = z;
  else y->r = z;
}
void treeDelete(Node z){
  Node y,x; 
}
void in(Node t){
  if(t != NIL) {
    if(t->l != NIL) in(t->l);
    printf(" %d",t->point);
    if(t->r != NIL) in(t->r);
  }
}
void pre(Node u){ 
  if(u != NIL) {
    printf(" %d",u->point);
    if(u->l!= NIL) pre(u->l);
    if(u->r != NIL) pre(u->r);
  }
}
int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for(i=0;i<n;i++){
    scanf("%s", com);
    switch(com[0]){
        case 'f':
            scanf("%d", &x);
            Node t = tree(root, x);
            ( t != NIL ) ? printf("yes\n") : printf("no\n");
            break;
        case 'i':
            scanf("%d", &x);
            insert(x);
            break;
        case 'p':
            in(root);
            printf("\n");
            pre(root);
            printf("\n");
            break;
        case 'd':
            scanf("%d", &x);
            treeDelete(tree(root, x));
            break;
    }
  }
  return 0;
}
