#include <iostream>
#include <string>
using namespace std;
string inp;
char bString[1000];
char nString[9];
char rString[1000];
int indexSize;
string gen1, gen2, gen3;
string build(string start, string insert, string end) {
return start + insert + end;
}
string doCycle(string input) {
cout << "Doing cycle for: " << input << endl;
for (int index = 0; index < input.size(); index++)
{
memset(bString, 0, 255);
memset(nString, 0, 255);
memset(rString, 0, 255);
if (isdigit(input[index])) {
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);
gen1 = doCycle(inp);
gen2 = doCycle(gen1);
gen3 = doCycle(gen2);
cout << "Final: " << gen3;
}