#include <stdio.h>
#include <stdlib.h>
#define NIL NULL

struct node {
	struct node *r;
	struct node *l;
	struct node *p;
	int key;
};

typedef struct node * Node;

Node r;


Node treeSearch(Node , int );
void treeDelete(Node );
void preorder(Node );
void inorder(Node );
void insert(int );




int main(void) {
  int n, i, a;
  char com[20];
  scanf("%d", &n);

  for (i = 0; i < n; ++i) {
    scanf("%s", com);
    if ( com[0] == 'f' ) {
      Node t = treeSearch(r, a);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    }

    else if ( com[0] == 'i') {
      scanf("%d", &a);
      insert(a);
    }

    else if ( com[0] == 'p') {
      inorder(r);
      printf("\n");
      preorder(r);
      printf("\n");
			
    }

    else if ( com[0] == 'd') {
      scanf("%d", &a);
      treeDelete(treeSearch(r, a));
    }
  }
	
  return 0;
}

Node treeSearch(Node r, int k) {
  if (r->key = k) return r;
  if (r->key < k) {

    if (r->l != NIL) return treeSearch(r->l, k);
    else return NIL;
  }
  else {
    if (r->r != NIL) return treeSearch(r->r, k);
    else return NIL;
  }
}

void insert(int k) {
  Node y = NIL;
  Node x = r;
  Node z;
  
  z = malloc(sizeof(struct node));
  z->key = k;
  z->l = NIL;
  z->r = NIL;
  
  while (x != NIL) {
    y = x;
    if (z->key < x->key) {
      x = x->l;
    }
    
    else {
      x = x->r;
    }
  }
  
  z->p = y;
  
  if (y == NIL) {
    r = z;
  }
  else if (z->key < y->key) {
    y->l = z;
  }
  else {
    y->r = z;
  }
}

void inorder(Node u) {

  if (u == NIL){
    return;
  }
  inorder(u->l);

  printf(" %d", u->key);

  inorder(u->r);
  return;
}

void preorder(Node u) {
  if (u == NIL){
    return;
  }
  printf(" %d", u->key);
  preorder(u->l);

  preorder(u->r);

  return;
}

void treeDelete(Node z) {
  
  Node y;
  
  Node x;
  
  return;
}

