#include <iostream>
#include <stack>
#include <cstdlib>
bool isnumer(const char a){
if (a >= '1' && a <= '9'){return true;}else{return false;}
}
void test(){
using namespace std;
stack<char> de;
string str;
cout<< "Input a uncoding string:";
cin>>str;
int i = 0;
while (str[i])
{
if (isnumber(str[i]) || str[i] != ']')
{
de.push(str[i]);
}
else{
string tmp;
for (;de.top() != '[' ; de.pop())
{
tmp += de.top();
}
reverse(tmp.begin(), tmp.end());
de.pop();
string num;
while (!de.empty() && isnumber(de.top()))
{
num += de.top();
de.pop();
}
int num1 = stoi(num);
for (int i = 0; i < num1; i++)
{
for (char &x: tmp)
{
de.push(x);
}
}
}
i++;
}
stack<char> de1;
while (!de.empty())
{
de1.push(de.top());
de.pop();
}
while (!de1.empty()) {
cout<<de1.top();
de1.pop();
}
cout<<endl;
}
int main(void){
test();
return 0;
}