/*
* Programming By: linwebs
* UVA 245
*/
#include<iostream>
#include<string>
using namespace std;
struct element {
string data;
element *last;
};
class stack {
private:
element *sp;
public:
stack();
void push(string, bool);
string get(int);
};
stack::stack() {
sp = nullptr;
}
void stack::push(string s, bool i) {
if(sp == nullptr) {
sp = new element;
sp->data = s;
sp->last = nullptr;
} else {
element *t = sp;
t = new element;
t->data = s;
t->last = sp;
sp = t;
if(i) {
element *l;
l=t;
t=t->last;
while(t != nullptr) {
if(t->data == s) {
l->last = t->last;
break;
} else {
l = t;
t = t->last;
}
}
}
}
}
string stack::get(int i) {
element *t = sp;
while(--i && t->last != nullptr) {
t = t->last;
}
return t->data;
}
int main () {
stack st;
char c;
int nn=0, cn=0;
string ss = "";
st.push("", false);
while(cin.get(c)) {
if(c=='0') {
if(nn!=0) {
nn=nn*10+(c-'0');
st.push(st.get(nn), true);
cout<<st.get(1);
nn=0;
} else {
if(ss!="") {
st.push(ss, false);
cout<<ss;
ss="";
}
break;
}
} else if(c>'0' && c<='9') {
if(ss!="") {
st.push(ss, false);
cout<<ss;
ss="";
}
nn=nn*10+(c-'0');
} else if((c>='A'&&c<='Z')||(c>='a'&&c<='z')) {
if(nn!=0) {
st.push(st.get(nn), true);
cout<<st.get(1);
nn=0;
}
ss.append(1u, c);
} else {
if(nn!=0) {
st.push(st.get(nn), true);
cout<<st.get(1);
nn=0;
}
if(ss!="") {
st.push(ss, false);
cout<<ss;
ss="";
}
cout<<c;
}
}
return 0;
}