#include <iostream>
#include <string>
using namespace std;
string inp;
char bString[1000];
char nString[9];
char rString[1000];
int indexSize;
string gen[100];
bool dontContinue;
string res;
string build(string start, string insert, string end) {
return start + insert + end;
}
string doCycle(string input) {
dontContinue = true;
cout << "Doing cycle for: " << input << endl;
for (int index = 0; index < input.size(); index++)
{
memset(bString, 0, sizeof bString);
memset(nString, 0, sizeof nString);
memset(rString, 0, sizeof rString);
if (isdigit(input[index])) {
dontContinue = 0;
for (int x = 0; x < index; x++) {
bString[x] = input[x];
}
indexSize = input[index] - 48;
cout << "number" << indexSize << "found at " << index;
for (int j = 1; j <= indexSize; j++)
{
nString[j - 1] = input[index + j]; //nstring = we insert into middle
}
for (int k = 1; (k + index) < input.size(); k++) {
rString[k - 1] = input[index + k]; //rstring we add to the end
}
cout << endl << " Start of string: " << bString << endl;
cout << endl << " Insert into middle: " << nString << endl;
cout << endl << " Insert into end: " << rString << endl;
return build(bString, nString, rString);
}
}
return input;
}
int main() {
getline(cin, inp);
gen[0] = doCycle(inp);
for (int i = 1; i < 100; i++) {
gen[i] = doCycle(gen[i-1]);
cout << "curgen: " << gen[i - 1];
if (dontContinue == true) {
res = doCycle(gen[i]);
break;
}
}
cout << "Final: " << res;
}