#include <iostream>
#include <deque>
#include <string>
using namespace std;
string processKeys(const string& keys) {
deque<char> text;
auto cursor = text.begin();
for (char key : keys) {
if (key == '[') {
cursor = text.begin();
} else if (key == ']') {
cursor = text.end();
} else {
text.insert(cursor, key);
}
}
return string(text.begin(), text.end());
}
int main() {
string keys;
getline(cin, keys);
cout << processKeys(keys) << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8ZGVxdWU+CiNpbmNsdWRlIDxzdHJpbmc+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKc3RyaW5nIHByb2Nlc3NLZXlzKGNvbnN0IHN0cmluZyYga2V5cykgewogICAgZGVxdWU8Y2hhcj4gdGV4dDsKICAgIGF1dG8gY3Vyc29yID0gdGV4dC5iZWdpbigpOwoKICAgIGZvciAoY2hhciBrZXkgOiBrZXlzKSB7CiAgICAgICAgaWYgKGtleSA9PSAnWycpIHsKICAgICAgICAgICAgY3Vyc29yID0gdGV4dC5iZWdpbigpOwogICAgICAgIH0gZWxzZSBpZiAoa2V5ID09ICddJykgewogICAgICAgICAgICBjdXJzb3IgPSB0ZXh0LmVuZCgpOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHRleHQuaW5zZXJ0KGN1cnNvciwga2V5KTsKICAgICAgICB9CiAgICB9CgogICAgcmV0dXJuIHN0cmluZyh0ZXh0LmJlZ2luKCksIHRleHQuZW5kKCkpOwp9CgppbnQgbWFpbigpIHsKICAgIAoJCXN0cmluZyBrZXlzOwogICAgICAgIGdldGxpbmUoY2luLCBrZXlzKTsKICAgICAgICBjb3V0IDw8IHByb2Nlc3NLZXlzKGtleXMpIDw8IGVuZGw7CiAgICByZXR1cm4gMDsKfQ==