#include <iostream>
#include <list>
#include <string>
using namespace std;
string processKeys(const string& keys) {
list<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;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bGlzdD4KI2luY2x1ZGUgPHN0cmluZz4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpzdHJpbmcgcHJvY2Vzc0tleXMoY29uc3Qgc3RyaW5nJiBrZXlzKSB7CiAgICBsaXN0PGNoYXI+IHRleHQ7CiAgICBhdXRvIGN1cnNvciA9IHRleHQuYmVnaW4oKTsKCiAgICBmb3IgKGNoYXIga2V5IDoga2V5cykgewogICAgICAgIGlmIChrZXkgPT0gJ1snKSB7CiAgICAgICAgICAgIGN1cnNvciA9IHRleHQuYmVnaW4oKTsKICAgICAgICB9IGVsc2UgaWYgKGtleSA9PSAnXScpIHsKICAgICAgICAgICAgY3Vyc29yID0gdGV4dC5lbmQoKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB0ZXh0Lmluc2VydChjdXJzb3IsIGtleSk7CiAgICAgICAgfQogICAgfQoKICAgIHJldHVybiBzdHJpbmcodGV4dC5iZWdpbigpLCB0ZXh0LmVuZCgpKTsKfQoKaW50IG1haW4oKSB7CiAgICAgICAgc3RyaW5nIGtleXM7CiAgICAgICAgZ2V0bGluZShjaW4sIGtleXMpOwogICAgICAgIGNvdXQgPDwgcHJvY2Vzc0tleXMoa2V5cykgPDwgZW5kbDsKCiAgICByZXR1cm4gMDsKfQ==