Page not loading? Try clicking here.
Placeholder

#1158

Insertion Sort 1s 32MB

Problems

Insertion sort is a method that sorts an array by taking each element in order from the front, comparing it with the already sorted portion of the array, and inserting it into its correct position.

For example, given the sequence {5, 4, 3, 7, 6}, the insertion sort process is as follows:

  • Initially, the first value 5 has nothing in front of it, so it is considered sorted.

  • From the second element 4 onward, each element is inserted into its correct position in the already sorted part.

  • Note: In the third step, 7 is larger than the previous sorted portion 3 4 5, so it remains in its place.


Input

The first line contains the length of the sequence N (4 \le N \le 100).

The second line contains N integers between 0 and 100 inclusive.


Output

Excluding the initial state, print the sequence after each step of the insertion sort.


Example

5

5 4 3 7 6
4 5 3 7 6

3 4 5 7 6
3 4 5 7 6
3 4 5 6 7


Source

JUNGOL

You must sign in to write code.