// naive binary search tree with find
#include <bits/stdc++.h>
using namespace std;

struct Node;
using PNode = Node *; // typedef Node * PNode;
struct Node
{
	int x;
	int y;
	PNode left;
	PNode right;

	Node (int x_, int y_)
	{
		x = x_;
		y = y_;
		left = nullptr;
		right = nullptr;
	}
};

PNode naiveInsert (PNode v, int x)
{
	if (v == nullptr)
	{
		return new Node (x, rand ());
	}
	if (v -> x < x)
	{
		v -> right = naiveInsert (v -> right, x);
		return v;
	}
	else
	{
		v -> left = naiveInsert (v -> left, x);
		return v;
	}
}

bool tFind (PNode v, int x)
{
	if (v == nullptr)
	{
		return false;
	}
	if (v -> x == x)
	{
		return true;
	}
	if (v -> x < x)
	{
		return tFind (v -> right, x);
	}
	else
	{
		return tFind (v -> left, x);
	}
}

void recurOutput (PNode v)
{
	if (v == nullptr)
	{
		return;
	}
	cout << "(";
	recurOutput (v -> left);
	cout << v -> x;
	recurOutput (v -> right);
	cout << ")";
}

void output (PNode v)
{
	recurOutput (v);
	cout << endl;
}

int main ()
{
	PNode root = nullptr;
	output (root);
	root = naiveInsert (root, 4);
	output (root);
	root = naiveInsert (root, 2);
	output (root);
	root = naiveInsert (root, 7);
	output (root);
	root = naiveInsert (root, 6);
	output (root);
	root = naiveInsert (root, 9);
	output (root);
	for (int i = 1; i <= 10; i++)
	{
		cout << tFind (root, i);
	}
	return 0;
}
