// treap as set, k-th order statistic
#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 size;
	PNode left;
	PNode right;

	Node (int x_)
	{
		x = x_;
		size = 1;
		left = nullptr;
		right = nullptr;
	}

	void recalc ()
	{
		size = 1;
		if (left != nullptr)
		{
			size += left -> size;
		}
		if (right != nullptr)
		{
			size += right -> size;
		}
	}
};

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;
		t -> recalc ();
		return {t, temp.second};
	}
	else
	{
		auto temp = tSplit (t -> left, x);
		t -> left = temp.second;
		t -> recalc ();
		return {temp.first, t};
	}
}

pair <PNode, PNode> tSplitK (PNode t, int k)
{ //  k left vertices into .first,  others into .second
	if (t == nullptr)
	{
		return {nullptr, nullptr};
	}
	int leftSize = (t -> left == nullptr) ? 0 : t -> left -> size;
	if (leftSize + 1 <= k)
	{
		auto temp = tSplitK (t -> right, k - leftSize - 1);
		t -> right = temp.first;
		t -> recalc ();
		return {t, temp.second};
	}
	else
	{
		auto temp = tSplitK (t -> left, k);
		t -> left = temp.second;
		t -> recalc ();
		return {temp.first, t};
	}
}

PNode tMerge (PNode l, PNode r)
{
	if (l == nullptr)
	{
		return r;
	}
	if (r == nullptr)
	{
		return l;
	}
	if (uniform (0, l -> size + r -> size - 1) (gen) < l -> size)
	{
		l -> right = tMerge (l -> right, r);
		l -> recalc ();
		return l;
	}
	else
	{
		r -> left = tMerge (l, r -> left);
		r -> recalc ();
		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 << "|" << t -> size;
		tOutput (t -> right);
		cout << ")";
	}
}

int main ()
{
	PNode root = nullptr;
	while (true)
	{
		string cmd;
		int x, k;
		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 if (cmd == "kth")
		{
			cin >> k;
			auto temp = tSplitK (root, k);
			auto half = tSplitK (temp.second, 1);
			cout << half.first -> x << "\n";
			temp.second = tMerge (half.first, half.second);
			root = tMerge (temp.first, temp.second);
		}
		else
		{
			break;
		}
		tOutput (root);
		cout << "\n";
	}
	tOutput (root);
	cout << "\n";
	return 0;
}
