#include <algorithm>
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <memory>
#include <stdexcept>
#include <utility>

template <class T> class persistent_vector {
public:
	using value_type = T;
	using reference = value_type &;
	using const_reference = const value_type &;
	using size_type = std::size_t;

protected:
	using rank_type = std::uint_least8_t;
	struct node_t {
		using pointer = std::shared_ptr<const node_t>;
		using cp_cr = const pointer &;
		value_type value;
		size_type size;
		rank_type rank;
		const pointer left, right;

		template <class... Args>
		explicit node_t(cp_cr l, cp_cr r, Args &&... args)
			: value(std::forward<Args>(args)...), size(nsize(l) + nsize(r) + 1),
			rank(std::max(nrank(l), nrank(r)) + 1), left(l), right(r) {}

		static size_type nsize(cp_cr c) { return c ? c->size : 0; }
		static rank_type nrank(cp_cr c) { return c ? c->rank : 0; }

		const_reference access(const size_type i) const {
			const size_type s = nsize(left);
			if (s == i)
				return value;
			if (s < i)
				return right->access(i - s - 1);
			else
				return left->access(i);
		}
		const_reference front() const { return left ? left->front() : value; }
		const_reference back() const { return right ? right->back() : value; }

		static pointer make_l(const value_type &value, cp_cr l, cp_cr r) {
			if (nrank(l) != nrank(r) + 2)
				return std::make_shared<const node_t>(l, r, value);
			if (nrank(l->left) + 1 == nrank(l->right)) {
				return std::make_shared<const node_t>(
					std::make_shared<const node_t>(l->left, l->right->left, l->value),
					std::make_shared<const node_t>(l->right->right, r, value),
					l->right->value);
			}
			else {
				return std::make_shared<const node_t>(
					l->left, std::make_shared<const node_t>(l->right, r, value),
					l->value);
			}
		}
		static pointer make_r(const value_type &value, cp_cr l, cp_cr r) {
			if (nrank(l) + 2 != nrank(r))
				return std::make_shared<const node_t>(l, r, value);
			if (nrank(r->left) == nrank(r->right) + 1) {
				return std::make_shared<const node_t>(
					std::make_shared<const node_t>(l, r->left->left, value),
					std::make_shared<const node_t>(r->left->right, r->right, r->value),
					r->left->value);
			}
			else {
				return std::make_shared<const node_t>(
					std::make_shared<const node_t>(l, r->left, value), r->right,
					r->value);
			}
		}
		pointer insert(const size_type i, cp_cr e) const {
			if (nsize(left) < i)
				return make_r(value, left,
				(right ? right->insert(i - nsize(left) - 1, e) : e));
			else
				return make_l(value, (left ? left->insert(i, e) : e), right);
		}
		pointer erase(const size_type i) const {
			if (nsize(left) < i)
				return make_l(value, left, right->erase(i - nsize(left) - 1));
			if (nsize(left) > i)
				return make_r(value, left->erase(i), right);
			if (right)
				return make_l(right->front(), left, right->erase_front());
			else
				return left;
		}
		pointer insert_back(cp_cr e) const {
			return make_r(value, left, right ? right->insert_back(e) : e);
		}
		pointer erase_back() const {
			return right ? make_l(value, left, right->erase_back()) : left;
		}
		pointer insert_front(cp_cr e) const {
			return make_l(value, left ? left->insert_front(e) : e, right);
		}
		pointer erase_front() const {
			return left ? make_r(value, left->erase_front(), right) : right;
		}
	};
	using pointer = std::shared_ptr<const node_t>;
	using cp_cr = const pointer &;

	pointer root;

	explicit persistent_vector(cp_cr r) : root(r) {}

public:
	persistent_vector() : root() {}

	bool empty() const noexcept { return !root; }
	size_type size() const noexcept { return node_t::nsize(root); }

	const_reference operator[](const size_type i) const {
		assert(i < size());
		return root->access(i);
	}
	const_reference at(const size_type i) const {
		if (i < size())
			return root->access(i);
		else
			throw std::out_of_range("out of range");
	}
	const_reference front() const {
		assert(!empty());
		return root->front();
	}
	const_reference back() const {
		assert(!empty());
		return root->back();
	}

	persistent_vector insert(const size_type position,
		const value_type &value) const {
		assert(position <= size());
		if (empty())
			return persistent_vector(
				std::make_shared<const node_t>(nullptr, nullptr, value));
		else
			return persistent_vector(root->insert(
				position, std::make_shared<const node_t>(nullptr, nullptr, value)));
	}
	template <class... Args>
	persistent_vector emplace(const size_type position, Args &&... args) const {
		assert(position <= size());
		if (empty())
			return persistent_vector(std::make_shared<const node_t>(
				nullptr, nullptr, std::forward<Args>(args)...));
		else
			return persistent_vector(root->insert(
				position, std::make_shared<const node_t>(
					nullptr, nullptr, std::forward<Args>(args)...)));
	}
	persistent_vector erase(const size_type position) {
		assert(position < size());
		return persistent_vector(root->erase(position));
	}
	persistent_vector push_back(const value_type &value) const {
		cp_cr e = std::make_shared<const node_t>(nullptr, nullptr, value);
		return persistent_vector(empty() ? e : root->insert_back(e));
	}
	template <class... Args>
	persistent_vector emplace_back(Args &&... args) const {
		cp_cr e = std::make_shared<const node_t>(nullptr, nullptr,
			std::forward<Args>(args)...);
		return persistent_vector(empty() ? e : root->insert_back(e));
	}
	persistent_vector pop_back() const {
		assert(!empty());
		return persistent_vector(root->erase_back());
	}
	persistent_vector push_front(const value_type &value) const {
		cp_cr e = std::make_shared<const node_t>(nullptr, nullptr, value);
		return persistent_vector(empty() ? e : root->insert_front(e));
	}
	template <class... Args>
	persistent_vector emplace_front(Args &&... args) const {
		cp_cr e = std::make_shared<const node_t>(nullptr, nullptr,
			std::forward<Args>(args)...);
		return persistent_vector(empty() ? e : root->insert_front(e));
	}
	persistent_vector pop_front() const {
		assert(!empty());
		return persistent_vector(root->erase_front());
	}

	persistent_vector &merge(persistent_vector &other) {}
	persistent_vector &operator+=(persistent_vector &other) {}
	persistent_vector split(size_type position) {}
};



#include<iostream>
#include<cstdio>

int main() {
	persistent_vector<char> s,t;
	char c;
	while (1) {
		c = fgetc(stdin);
		if (c == '\n') break;
		s = s.emplace_back(c);
	}
	for (int i = 0; i < s.size();++i) {
		if (s[i] != 'B')
			t = t.push_back(s[i]);
		else if (!t.empty())
			t=t.pop_back();
	}
	while (!t.empty())
		std::cout << t.front(), t = t.pop_front();
	return 0;
}

Measured memory_bytes: 256