#include <iostream>
using namespace std;
void print_array(int s[], int n){
int i;
for (i=0; i < n; i++){
cout << s[i] << " ";
}
cout << endl;
}
void insertion_sort(int s[], int n){
int i, j, key;
for (j = 1; j < n; j++){
//display intermediate stage
print_array(s, n);
//insert s[j] into sorted set s[0..j-1]
i = j-1;
key = s[j];
while ((i >= 0) && (key < s[i])){
s[i+1] = s[i];
i = i-1;
}
s[i+1] = key;
}
return;
}
int main() {
int n, i;
scanf("%d", &n);
int *s;
s = (int *) malloc(sizeof(int) * n);
for (i = 0; i < n; i++){
scanf("%d", &s[i]);
}
insertion_sort(s, n);
cout << "Done. Result is: " << endl;
print_array(s, n);
free(s);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnZvaWQgcHJpbnRfYXJyYXkoaW50IHNbXSwgaW50IG4pewoJaW50IGk7Cglmb3IgKGk9MDsgaSA8IG47IGkrKyl7CgkJY291dCA8PCBzW2ldIDw8ICIgIjsKCX0KCWNvdXQgPDwgZW5kbDsKfQoKdm9pZCBpbnNlcnRpb25fc29ydChpbnQgc1tdLCBpbnQgbil7CiAgaW50IGksIGosIGtleTsKICBmb3IgKGogPSAxOyBqIDwgbjsgaisrKXsKICAgIC8vZGlzcGxheSBpbnRlcm1lZGlhdGUgc3RhZ2UKICAJcHJpbnRfYXJyYXkocywgbik7CiAgCS8vaW5zZXJ0IHNbal0gaW50byBzb3J0ZWQgc2V0IHNbMC4uai0xXQogIAlpID0gai0xOwogIAlrZXkgPSBzW2pdOwogIAl3aGlsZSAoKGkgPj0gMCkgJiYgKGtleSA8IHNbaV0pKXsKICAgICAgICBzW2krMV0gPSBzW2ldOwogIAkJaSA9IGktMTsKICAJfQogIAlzW2krMV0gPSBrZXk7CiAgfQogIHJldHVybjsKfSAKCmludCBtYWluKCkgewoJaW50IG4sIGk7CglzY2FuZigiJWQiLCAmbik7CglpbnQgKnM7CglzID0gKGludCAqKSBtYWxsb2Moc2l6ZW9mKGludCkgKiBuKTsKCWZvciAoaSA9IDA7IGkgPCBuOyBpKyspewoJCXNjYW5mKCIlZCIsICZzW2ldKTsKCX0KICAgIAogICAgaW5zZXJ0aW9uX3NvcnQocywgbik7CiAgICAKICAgIGNvdXQgPDwgIkRvbmUuICBSZXN1bHQgaXM6ICIgPDwgZW5kbDsKICAgIHByaW50X2FycmF5KHMsIG4pOwogICAgCiAgICBmcmVlKHMpOwoJcmV0dXJuIDA7Cn0=