// 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)
{ //  < x into .first,  >= x into .second
	if (t == nullptr)
	{
		return {nullptr, nullptr};
	}
	if (t -> x < x)
	{
		auto 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)
{
	PNode v = new Node (x);
	auto temp = tSplit (t, x);
	// temp.first | x | temp.second
	auto half = tMerge (temp.first, v);
	return tMerge (half, temp.second);
}

void tEraseRecur (PNode t)
{
	if (t != nullptr)
	{
		tEraseRecur (t -> left);
		tEraseRecur (t -> right);
		delete t;
	}
}

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

PNode tErase (PNode t, int x)
{
	auto temp = tSplit (t, x); // <x | >=x
	auto half = tSplit (temp.second, x + 1); // =x | >x
	tEraseRecur (half.first);
	return tMerge (temp.first, half.second);
}

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 == "erase")
		{
			cin >> x;
			root = tErase (root, x);
		}
		else if (cmd == "find")
		{
			cin >> x;
			cout << tFind (root, x) << "\n";
		}
		else
		{
			break;
		}
/*
		tOutput (root);
		cout << "\n";
*/
	}
	tOutput (root);
	cout << "\n";
	return 0;
}
