#include <iostream>
#include <memory>
#include <vector>

class BinaryTree
{
private:
  struct Node
  {
    // Member variables of 'Node'
    int key;
    std::shared_ptr<Node> parent_ptr;
    std::shared_ptr<Node> left_ptr;
    std::shared_ptr<Node> right_ptr;

    // Default constructor
    Node():
      key(0),
      parent_ptr(nullptr),
      left_ptr(nullptr),
      right_ptr(nullptr)
    {}

    // Construcotr
    explicit Node(int k, std::shared_ptr<Node> p, std::shared_ptr<Node> l, std::shared_ptr<Node> r):
      key(k),
      parent_ptr(p),
      left_ptr(l),
      right_ptr(r)
    {}
  };

  // Member variables of 'BinaryTree'
  std::shared_ptr<Node> root_ptr;

public:
  // Default constructor
  BinaryTree():
    root_ptr(nullptr)
  {}

  // Specify 'key' then insert into the tree
  void insert(int key)
  {
    std::shared_ptr<Node> temp_parent_ptr = nullptr;
    std::shared_ptr<Node> temp_child_ptr = root_ptr;

    while (temp_child_ptr != nullptr)
    {
      temp_parent_ptr = temp_child_ptr;
      if (key < temp_child_ptr->key)
        temp_child_ptr = temp_child_ptr->left_ptr;
      else
        temp_child_ptr = temp_child_ptr->right_ptr;
    }

    std::shared_ptr<Node> new_node_ptr = std::make_shared<Node>(key, temp_parent_ptr, nullptr, nullptr);

    // If this is the first element,
    // then new_node is the root
    if (temp_parent_ptr == nullptr)
      root_ptr = new_node_ptr;
    // If new_node's key is smaller than parent's,
    // then insert into left
    else if (key < temp_parent_ptr->key)
      temp_parent_ptr->left_ptr = new_node_ptr;
    // If new_node's key is larger than parent's,
    // then insert into left
    else
      temp_parent_ptr->right_ptr = new_node_ptr;
  }

  // Print keys as preorder tour
  void printPreorder(std::shared_ptr<Node> node_ptr)
  {
    // Escape condition of the recursive function
    if (node_ptr == nullptr)
      return;

    // Recursively output the key value.
    std::cout << ' ' << node_ptr->key;
    printPreorder(node_ptr->left_ptr);
    printPreorder(node_ptr->right_ptr);
  }

  // Print keys as inorder tour
  void printInorder(std::shared_ptr<Node> node_ptr)
  {
    // Escape condition of the recursive function
    if (node_ptr == nullptr)
      return;

    // Recursively output the key value.
    printInorder(node_ptr->left_ptr);
    std::cout << ' ' << node_ptr->key;
    printInorder(node_ptr->right_ptr);
  }

  // Print keys as both preorder and inorder
  void print()
  {
    printInorder(root_ptr);
    std::cout << std::endl;
    printPreorder(root_ptr);
    std::cout << std::endl;
  }

private:
  bool find_sub(std::shared_ptr<Node> node_ptr, int key)
  {
    if (node_ptr == nullptr)
      return false;

    if (key < node_ptr->key)
      return find_sub(node_ptr->left_ptr, key);
    else if (key > node_ptr->key)
      return find_sub(node_ptr->right_ptr, key);
    else
      return true;
  }

public:
  // Judge if the tree has the 'key'
  bool find(int key)
  {
    return find_sub(root_ptr, key);
  }
};

int main()
{
  int m;
  std::cin >> m;

  BinaryTree tree;
  for (int i = 0; i < m; ++i)
  {
    std::string command;
    int key;

    std::cin >> command;
    if (command == "insert")
    {
      std::cin >> key;
      tree.insert(key);
    }
    else if (command == "find")
    {
      std::cin >> key;
      if (tree.find(key))
        std::cout << "yes" << std::endl;
      else
        std::cout << "no" << std::endl;
    }
    else
      tree.print();
  }

  return 0;
}


Measured memory_bytes: 34428