// treap as set
#include <bits/stdc++.h>
using namespace std;

mt19937 gen (123);
typedef uniform_int_distribution <int> uniform;

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

	Node (int x_)
	{
		x = x_;
		y = uniform (0, 1E9 - 1) (gen);
		left = nullptr;
		right = nullptr;
	}
};

pair <PNode, PNode> tSplit (PNode t, int x)
{
	if (t == nullptr)
	{
		return {nullptr, nullptr};
	}
	if (t -> x < x)
	{
		pair <PNode, PNode> temp = tSplit (t -> right, x);
		t -> right = temp.first;
		return {t, temp.second};
	}
	else
	{
		auto temp = tSplit (t -> left, x);
		t -> left = temp.second;
		return {temp.first, t};
	}
}

PNode tMerge (PNode l, PNode r)
{
	if (l == nullptr)
	{
		return r;
	}
	if (r == nullptr)
	{
		return l;
	}
	if (l -> y > r -> y)
	{
		l -> right = tMerge (l -> right, r);
		return l;
	}
	else
	{
		r -> left = tMerge (l, r -> left);
		return r;
	}
}

PNode tInsert (PNode t, int x)
{
	auto temp = tSplit (t, x);
	auto v = new Node (x); // temp.first | v | temp.second
	auto half = tMerge (temp.first, v);
	return tMerge (half, temp.second);
}

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

void tOutput (PNode t)
{
	if (t != nullptr)
	{
		cout << "(";
		tOutput (t -> left);
		cout << t -> x;
		tOutput (t -> right);
		cout << ")";
	}
}

int main ()
{
	PNode root = nullptr;
	while (true)
	{
		string cmd;
		int x;
		cin >> cmd;
		if (cmd == "insert")
		{
			cin >> x;
			root = tInsert (root, x);
		}
		else if (cmd == "find")
		{
			cin >> x;
			cout << tFind (root, x) << "\n";
		}
		else if (cmd == "output")
		{
			tOutput (root);
			cout << "\n";
		}
		else
		{
			break;
		}
	}
	return 0;
}
