Problem:
Insertion Sort Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: for i = 1 to A.length-1
    key = A[i]
    /* insert A[i] into the sorted sequence A[0,...,j-1] */
    j = i - 1
    while j >= 0 and A[j] > key
        A[j+1] = A[j]
        j--
    A[j+1] = key Note that, indices for array elements are based on 0-origin. To illustrate the algorithms, your program should trace intermediate result for each step. Input The first line of the input includes an integer N, the number of elements in the sequence. In the second line, N elements of the sequence are given separated by a single space. Output The output consists of N lines. Please output the intermediate sequence in a line for each step. Elements of the sequence should be separated by single space. Constraints 1 ≤ N ≤ 100 Sample Input 1 6
5 2 4 6 1 3 Sample Output 1 5 2 4 6 1 3
2 5 4 6 1 3
2 4 5 6 1 3
2 4 5 6 1 3
1 2 4 5 6 3
1 2 3 4 5 6 Sample Input 2 3
1 2 3 Sample Output 2 1 2 3
1 2 3
1 2 3 Hint Template in C

Solution (Python):
def show(lst):
    length = len(lst)
    for i in range(length-1):
        print(lst[i], end=" ")
    print(lst[-1])
        
    

n = int(input())
lst = list(map(int, input().split()))
def insertion_sort(lst, n):
    for i in range(n):
        v = lst[i]
        j = i - 1
        while j >= 0 and lst[j] > v:
            lst[j+1] = lst[j]
            j -= 1
        lst[j+1] = v
        show(lst)
insertion_sort(lst, n)

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
for i in range(n):
    v = A[i]
    j = i-1
    while j >= 0 and  A[j] > v:
        A[j+1] = A[j]
        j -= 1
        A[j+1] = v
    print(" ".join(map(str,A)))

Solution (Python):
n = int(input())

A = [int(x) for x in input().split()]
print(*A)

for i in range(1,n):
    v = A[i]
    j = i-1
    while j>=0 and A[j]>v:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = v
    print(*A)

Solution (Python):
N = int(input())
a = [int(i) for i in input().split() ]
for j in range(len(a)):
  if j == len(a) -1:
    print(a[j],end = "")
  else:
    print(a[j],end = " ")    
print()
for i in range(1,len(a)):
  tmp = a[i]
  j = i- 1
  while j >= 0 and a[j] > tmp:
    a[j+1] = a[j]
    j -= 1
  a[j+1] = tmp
  for j in range(len(a)):
      if  j == len(a)-1 :
        print(a[j],end = "")
      else:
        print(a[j],end = " ")
  print()

Solution (Python):

def show (seqs):
    for i in range(len(seqs)):
        if i!=len(seqs)-1:
            print(seqs[i],end=' ')
        else :
            print(seqs[i])

num = int(input())
seqs = list(map(int,input().split()))

show(seqs) 

for i in range(1,num):
    element = seqs[i] 
    j = i-1 
    while (j>=0 and seqs[j]>element): 
        seqs[j+1] = seqs[j] 
        j -=1
    
    seqs[j+1]=element
    show(seqs)

Solution (Python):
n = int(input())
s = list(map(int, input().split()))

for i in range(n):
    v = s[i]
    j = i - 1
    while j >= 0 and s[j] > v:
        s[j+1] = s[j]
        j -= 1
    s[j+1] = v

    print(*s)

Solution (Python):
n = int(input())
data = list(map(int, input().split()))

for i in range(1,n):
	print(" ".join(map(str, data)))
	v = data[i]
	j = i-1
	while j >= 0 and data[j] > v:
		data[j+1] = data[j]
		j -= 1
	data[j+1] = v
print(" ".join(map(str, data)))

Solution (Python):

import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read
inp = sys.stdin.buffer.readline
def inpS(): return inp().rstrip().decode()
readlines = sys.stdin.buffer.readlines
MOD = 10 ** 9 + 7
INF = 1 << 60





def resolve():
    N = int(inp())
    A = list(map(int, inp().split()))
    print(*A)

    for i in range(1, N):
        v = A[i]
        j = i-1
        while j>=0 and A[j] > v:
            A[j+1] = A[j]
            j -= 1
        A[j+1] = v
        print(*A)


if __name__ == '__main__':
    resolve()

Solution (Python):
def insertsort(N_list):
    sort_list = list(N_list)
    ans = [str(i) for i in sort_list]
    print(" ".join(ans))
    for i in range(1,len(N_list)):
        target = sort_list[i]
        j = i-1
        while j >= 0 and sort_list[j] > target:
            sort_list[j], sort_list[j+1] = target, sort_list[j]
            j -= 1
        ans = [str(i) for i in sort_list]
        print(" ".join(ans))
            
    
N = int(input())
N_list = list(map(int,input().split()))
insertsort(N_list)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

def insertion_sort(A):
    for idx, target in enumerate(A[1:]):
        j = idx
        while j >= 0 and A[j] > target:
            A[j+1] = A[j]
            j -= 1
        A[j+1] = target
        disp(A)

def disp(A):
    for i in A[:-1]:
        print(i, end=" ")
    print(A[-1])

disp(A)
insertion_sort(A)

Solution (Python):
def insertionSort(A,N):
    print(*A)
    for i in range(1,N):
        v = A[i]
        j = i-1
        while j >= 0 and A[j] > v:
            A[j+1],A[j] = A[j],A[j+1]
            
            j -= 1
        print(*A)


N = int(input())
A = list(map(int,input().split()))
insertionSort(A,N)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

for i in range(n):
    v = a[i]
    j = i - 1
    while j >= 0 and a[j] > v:
        a[j+1] = a[j]
        j -= 1
    a[j+1] = v
    print(*a)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
for k in range(N-1):
    print(f"{A[k]} ",end="")
print(f"{A[N-1]}")
for i in range(1,N):
    v = A[i]
    j = i-1
    while (j>=0)*(A[j]>v):
        A[j+1]=A[j]
        j-=1
        A[j+1]=v
    for k in range(N-1):
        print(f"{A[k]} ",end="")
    print(f"{A[N-1]}")

Solution (Python):
def insert_sort(n:int, s:list):
    print(' '.join(map(str, s)))
    for i in range(1, len(s)):
        j = i - 1
        v = s[i]
        while (j >= 0 and s[j] > v):
            s[j + 1] = s[j]
            j -= 1
            s[j + 1] = v
        print(" ".join(map(str, s)))

insert_sort(int(input()),list(map(int,input().split(' '))))

Solution (Python):
def insertionSort(A, N):
    for i in range(N):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j+1] = A[j]
            j -= 1
        A[j+1] = v
        print(*A)
    return A


N = int(input())
A = list(map(int, input().split()))

insertionSort(A, N)

Solution (Python):
def Insertion_Sort(a,n):
  for i in range(1,n+1):
    print(' '.join(map(str,a)))
    if n > i:
      temp = a[i]
      j = i - 1
      while j >= 0 and a[j] > temp:
        a[j+1] = a[j]
        j -= 1
      a[j+1] = temp


num = int(input())
s = list(map(int,input().split()))
Insertion_Sort(s,num)

Solution (Python):
import sys
import math
import itertools

def insertionSort(A, N):
  for i in range(N):
    v = A[i]
    j = i - 1
    while j >= 0 and A[j] > v:
      A[j+1] = A[j]
      j -= 1
    A[j+1] = v
    print(*A)

def main():
  N = int(input())
  numbers = list(map(int, input().split()))

  insertionSort(numbers, N)

if __name__ == '__main__':
  main()

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

for i in range(1, N+1):
    for j in reversed(range(1, i)):
        if A[j] < A[j-1]:
            tmp = A[j]
            A[j] = A[j-1]
            A[j-1] = tmp
        else:
            break

    result = [str(k) for k in A]
    print(' '.join(result))

Solution (Python):
from sys import stdin

N = int(stdin.readline())
A = list(map(int, stdin.readline().split()))

print(*A)
for i in range(1,N):
    v = A[i]
    j = i - 1
    while j >= 0 and A[j] > v:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = v
    print(*A)

Solution (Python):
def show (seqs):
    for i in range(len(seqs)):
        if i != len(seqs)-1:
            print(seqs[i], end = ' ')
        else :
            print(seqs[i])

num = int(input())
seqs = list(map(int,input().split()))

show(seqs)
for i in range(1,num):
    element = seqs[i]
    j = i-1
    while (j>=0 and seqs[j]>element):
        seqs[j+1] = seqs[j]
        j -=1
    seqs[j+1] = element
    show(seqs)

Solution (Python):
n = int(input())
*A, = map(int, input().split())
for i in range(n):
    v = A[i]
    j = i - 1
    while j >= 0 and A[j] > v:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = v
    print(*A)

Solution (Python):
n = int(input())  
a = list(map(int, input().split()))  
print(' '.join([str(n) for n in a]))

for i in range(1, len(a)):
	j = a[i]
	for k in range(i - 1, -1, -1):
		if a[k] > j:
			a[k + 1] = a[k]
			a[k] = j
	print(' '.join([str(n) for n in a]))

Solution (Python):
def insertionSort(A, N):
    for i in range(N):
        v = A[i]
        j = i -1
        while j >= 0 and A[j] > v:
             A[j+1] = A[j]
             j -= 1
        A[j+1] = v
        b = 0
        for i in A:
            b +=1
            if b == N:
                print(i, end ="")
            else:
                print(i, end =" ")
        print()
n = int(input())
a = [int(i) for i in input().split()]
insertionSort(a,n)

Solution (Python):
n = int(input())
a_str = input().split()
a = [int(i) for i in a_str]

c = 1
for s in a:
    if c != n:
        print("{} ".format(s), end="")
    elif c == n:
        print(s)
    c += 1

i = 1
while n-1 >= i:
    v = a[i]
    j = i - 1
    while j >= 0 and a[j] > v:
        a[j+1] = a[j]
        j -= 1
    a[j+1] = v

    c = 1
    for s in a:
        if c != n:
            print("{} ".format(s), end="")
        elif c == n:
            print(s)
        c += 1

    i += 1

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
l = [str(a) for a in A]
print(" ".join(l))

for i in range(1,n):
    v = A[i]
    j = i - 1
    while j>=0 and A[j] > v:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = v
    l = [str(a) for a in A]
    print(" ".join(l))

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
s = [str(a) for a in A]
s = ' '.join(s)
print(s)

for i in range(1, N):
    v = A[i]
    j = i - 1
    while j >= 0 and A[j] > v:
        A[j + 1] = A[j]
        j -= 1
    A[j + 1] = v
    s = [str(a) for a in A]
    s = ' '.join(s)
    print(s)

Solution (Python):
n = int(input())
l = list(map(int,input().split()))
for j in range(n):
    a = l[j]
    v = j-1
    while v>=0 and l[v]>a:
        l[v+1]=l[v]
        l[v]=a
        v -=1
    print(*l)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
[print(A[x],'',end='') for x in range(N-1)]
print(A[N-1])
for i in range(1,N):
    v=A[i]
    j=i-1
    while j>=0 and A[j]>v:
        A[j+1] = A[j]
        j-=1
    A[j+1]=v
    [print(A[x],'',end='') for x in range(N-1)]
    print(A[N-1])

Solution (Python):
def insort(n,A):
    for i in range(n):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j+1] = A[j]
            j -= 1
        A[j+1] = v
        L=[str(a) for a in A]
        L=" ".join(L)
        print(L)

n = int(input())
A = list(map(int,input().split()))

insort(n,A)

Solution (Python):
def insertion_sort(N, A):
    print(*A)
    for i in range(1, N):
        key = A[i]
        j = i - 1
        while j >= 0 and A[j] > key:
            A[j+1] = A[j]
            j -= 1
        A[j + 1] = key
        print(*A)  

def main():
    N = int(input())
    A = list(map(int, input().split()))
    insertion_sort(N, A)


main()

Solution (Python):
N = int(input())
aa = list(map(int, input().split()))
for i in range(N):
    tmpl = sorted(aa[:i+1]) + aa[i+1:]
    print(" ".join(map(str,tmpl)))

Solution (Python):

import sys
from functools import reduce


def to_str(x, y):
    return str(x) + ' ' + str(y)


input()
A = list(map(int, input().split()))

print(reduce(to_str, A))
for i in range(1, len(A)):
    v = A[i]
    j = i - 1
    while j >= 0 and A[j] > v:
        A[j + 1] = A[j]
        j -= 1
    A[j + 1] = v
    print(reduce(to_str, A))

Solution (Python):

n = int(input())
L = list(map(int,input().split()))
print(' '.join(map(str, L)))

for i in range(1, n):
    v = L[i]
    j = i - 1
    while j >= 0 and L[j] > v:
        L[j + 1] = L[j]
        j -= 1
    L[j + 1] = v
    print(' '.join(map(str,L)))

Solution (Python):
n = int(input())


a = list(map(int,input().split()))

print(' '.join(map(str,a)))

for i in range(1, n):
    v = a[i]
    j = i - 1
    while (j>=0 and a[j] > v):
        a[j+1] = a[j]
        j -= 1
    a[j+1] = v
    print(' '.join(map(str,a)))

Solution (Python):
def insertionSort(A, N):
    for i in range(N):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j+1] = A[j]
            j += -1
        A[j+1] = v
        print(" ".join(map(str, A)))

n = int(input())
A = list(map(int, input().split()))
insertionSort(A, n)

Solution (Python):
n = int(input())
A = list(map(int,input().split()))

print(' '.join(map(str, A)))
for i in range(1,n):
    v = A[i]
    j = i-1
    while j >= 0 and A[j] > v:
        A[j+1] = A[j]
        j = j-1
    A[j+1] = v
    print(' '.join(map(str, A)))

Solution (Python):
n = int(input())
A = [int(i) for i in input().split()]

for i in range(n):
    v = A[i]
    j = i-1
    while j >= 0 and A[j] > v:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = v
    print(*A)

Solution (Python):
def printArray(A):
  strA = [str(i) for i in A]
  print(" ".join(strA))

def insertion(A,N):
  for i in range(1,N):
    printArray(A)
    v = A[i]
    j = i - 1
    
    while j >= 0 and A[j] > v:
      A[j+1] = A[j]
      j -= 1
    
    A[j + 1] = v
  printArray(A)
    
N = int(input())
A = list(map(int,input().split()))

insertion(A,N)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))

for i in range(N):
    v=A[i]
    j=i-1
    while j>=0 and A[j]>v:
        A[j+1]=A[j]
        j -= 1
    A[j+1]=v
    print(" ".join(map(str,A)))

Solution (Python):
n = int(input())
num_list = list(map(int, input().split()))
def insertion_sort(lst):
    n = len(lst)
    for i in range(n):
        current = lst[i]
        j = i - 1
        while j >= 0 and lst[j] > current:
            lst[j + 1] = lst[j]
            j -= 1
        lst[j + 1] = current
        map_lst = map(str, lst)
        print(" ".join(map_lst))
insertion_sort(num_list)

Solution (Python):
num = int(input())
sort_list = list(map(int,input().split()))

for i in range(1,num):
    for n, sl in enumerate(sort_list):
        if n != num - 1:
            print('{} '.format(sl),end='')
        else:
            print('{}'.format(sl))

    tmp = sort_list[i]
    j = i -1
    while j >= 0 and sort_list[j] >= tmp:
        buf = sort_list[j]
        del sort_list[j]
        sort_list.insert(j + 1, buf)
        j -= 1

for n, sl in enumerate(sort_list):
    if n != num - 1:
        print('{} '.format(sl),end='')
    else:
        print('{}'.format(sl))

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
print(*a)
for i in range(1,n):
    v=a[i]
    j=i-1
    while j >=0 and a[j] > v:
        a[j+1] = a[j]
        j-=1
    a[j+1] = v
    print(*a)

Solution (Python):
n = int(input())
*A, = map(int, input().split())
for i in range(n):
    v = A[i]
    j = i - 1
    while j >= 0 and A[j] > v:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = v
    print(*A)

Solution (Python):
n = int(input())
l = []
l = input().split()
l = list(map(int,l))
print(*l)
for i in range(1,n):
    v = l[i]
    j = i - 1
    while j >= 0 and l[j] > v:
        l[j+1] = l[j]
        j = j - 1
    l[j+1] = v
    print(*l)

Solution (Python):
def insertSort(input_list):
    print(' '.join([str(i) for i in input_list]))
    for i in range(1, len(input_list)):
        tmp = input_list[i]
        j = i - 1

        while j >= 0 and input_list[j] > tmp:
            input_list[j + 1] = input_list[j]
            j -= 1
            input_list[j + 1] = tmp

        print(' '.join([str(i) for i in input_list]))


if __name__ == '__main__':
    N = int(input())

    L = input()
    input_list = [int(i) for i in L.split()]
    insertSort(input_list)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

for i in range(N):
    v = A[i]
    j = i-1
    
    while j >= 0 and A[j] > v:
        A[j+1] = A[j]
        j -= 1
    
    A[j+1] = v
    print(' '.join([str(n) for n in A]))

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

for i in range(1, N):
    print(" ".join(map(str, A)))
    for j in range(i-1, -1, -1):
        if A[j] < A[j+1]:
            break
        A[j], A[j+1] = A[j+1], A[j]
print(" ".join(map(str, A)))

Solution (Python):
def InsertionSort(A, N):
    for i in range(N):
        v = A[i]       
        j = i - 1
        while j >= 0 and A[j] > v: 
            A[j+1] = A[j]  
            j -= 1     
        A[j+1] = v     
        print(*A)

N = int(input())
A = list(map(int, input().split()))

InsertionSort(A, N)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
print(*a)
for i in range(1, n):
    v = a[i]
    j = i - 1
    while j >= 0 and a[j] > v:
        a[j + 1] = a[j]
        j -= 1
    a[j + 1] = v
    print(*a)

Solution (Python):
N = int(input())
list_cards = [0]*N
list_cards = list(map(int,input().split()))

def insertionsort(A, N):
    for i in range(N):
        v = A[i]
        j = i-1
        while j >= 0 and A[j] > v:
            A[j+1] = A[j]
            j -= 1
        A[j+1] = v        

        A_str = list(map(str, A))
        print(" ".join(A_str))

    return(A)

result_cards = insertionsort(list_cards, N)

Solution (Python):
def insertion_sort(A):
    n = len(A)
    for i in range(1, n):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j+1] = A[j]
            j -= 1
        A[j+1] = v
        print(' '.join(map(str, A)))
    return A

n = int(input())
A = list(map(int, input().split()))
print(' '.join(map(str, A)))
insertion_sort(A)

Solution (Python):


n = int(input())
A = list(map(int, input().split()))

def insertSort(A):
	print(*A)
	n = len(A)
	for i in range(1, n):
		v = A[i]
		j = i - 1
		while j >= 0 and A[j] > v:
			A[j + 1] = A[j]
			j -= 1
		A[j + 1] = v
		print(*A)
	return 0

insertSort(A)

Solution (Python):
def show(nums):
    for i in range(len(nums)):
        if i!=len(nums)-1:
            print(nums[i],end=' ')

        else:
            print(nums[i])
            

n=int(input())
nums=list(map(int,input().split()))
show(nums)

for i in range(1,n):
    v=nums[i]
    j=i-1

    while (j>=0 and nums[j]>v):
        nums[j+1]=nums[j]
        j-=1

    nums[j+1]=v
    show(nums)

Solution (Python):
N = int(input())
A = [int(a) for a in input().split()]
print(*A)

for i in range(1, N):
    v = A[i]
    j = i - 1
    while 0 <= j and v < A[j]:
        A[j + 1] = A[j]
        j -= 1
    A[j + 1] = v
    print(*A)

Solution (Python):
N=int(input())
R=list(map(int,input().split()))

print(*R)

for n in range(1,N):
    if R[n-1]<=R[n]:
        pass
    elif R[n-1]>R[n]:
        v=R[n]
        for i in R[:n]:
            if i>v:
                j=R.index(i)
                break
        R[j+1:n+1]=R[j:n]
        R[j]=v
    print(*R)

Solution (Python):
N=int(input())
A=list(map(int, input().split()))
print(*A)
for i in range(1,N):
    v=A[i]
    j=i-1
    while j>=0 and A[j]>v:
        A[j+1]=A[j]
        j-=1
    A[j+1]=v
    print(*A)

Solution (Python):
def printData(data):
    for d in data:
        val = f'{d}'
        if data[-1] != d:
            end = " "
        else:
            end = "\n"
        print(f'{d}',end=end)

num = int(input())
data = list(map(int,input().split()))

printData(data)

for i in range(1,num):
    v = data[i]
    j = i -1 
    while j >= 0 and data[j] > v:
        data[j+1] = data[j]
        j -= 1
    data[j+1] = v
    printData(data)

Solution (Python):

n = int(input())
a = list(map(int,input().split()))
for i in range(n):
        v = a[i]
        j = i - 1
        while j >= 0 and a[j] > v:
            a[j+1] = a[j]
            j -= 1
        a[j+1] = v
        print(*a)

Solution (Python):
n = int(input())
arr = list(map(int, input().split()))
print(*arr)
for i in range(1, n):
    key = arr[i]
    j = i - 1
    while j >= 0 and arr[j] > key:
        arr[j + 1] = arr[j]
        j -= 1
    arr[j + 1] = key
    print(*arr)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

print(*a)
for i in range(1, n):
    v = a[i]
    while i-1 >= 0 and a[i-1]>v:
        a[i]=a[i-1]
        i -= 1
    a[i] = v
    print (*a)

Solution (Python):
n=int(input())

li=[int(x) for x in input().split()]


for i in range(n):
    v = li[i]
    j = i-1
    while j >= 0 and li[j] > v:
        li[j+1] = li[j]
        j-=1
    li[j+1] = v
    l=[str(a) for a in li]
    l=" ".join(l)
    print(l)

Solution (Python):
def insertionSort(At, Nt):
	for i in range(Nt):
		v = At[i]
		j = i - 1
		while j >= 0 and At[j] > v:
			A[j + 1] = A[j]
			j = j - 1
		A[j + 1] = v
		print(" ".join(map(str,At)))
	return At

if __name__ == '__main__':

    N = int(input())
    A = list(map(int,input().split()))
    A = insertionSort(A,N)

Solution (Python):
n = int(input())
A = list(map(int, input().split()))

def trace():
    for i in range(len(A)):
        if i != len(A) - 1:
            print(A[i],end=' ')
        else:
            print(A[i])
        


for i in range(len(A)):
    v = A[i]
    j = i - 1
    while j >= 0 and A[j] > v:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = v

    trace()

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
for i in range(len(a)):
    v = a[i]
    j = i-1
    while j >= 0 and a[j] > v:
        a[j+1] = a[j]
        j -= 1
    a[j+1] = v
    for k in range(n):
        if k != n-1:
            print(a[k], end=' ')
        else:
           print(a[k], end='') 
    print()

Solution (Python):
def insertSort(a,n):
    L=[str(ai) for ai in a]
    L=" ".join(L)
    print(L)
    for i in range(1,n):
        v = a[i]
        j = i-1
        while(j>=0 and a[j]>v):
            a[j+1] = a[j]
            j -= 1
        a[j+1] = v;
        L=[str(ai) for ai in a]
        L=" ".join(L)
        print(L)
        
n = int(input())
a = list(map(int,input().split()))
insertSort(a,n)

Solution (Python):
n = int(input())
A = list(map(int, input().split(' ')))

print(*A)
for i in range(1, n):
    t = A[i]
    k = i - 1
    while k >= 0 and t < A[k]:
        A[k + 1] = A[k]
        k -= 1
    A[k + 1] = t
    print(*A)

Solution (Python):
def insertionSort(A, N) :
    for i in range(N) :
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v :
            A[j+1]  = A[j]
            j -= 1
        A[j+1]  = v
        for j in range(N-1) :
            print(A[j],  end=" ")
        print(A[N-1])
    


N = int(input())
A = list(map(int, input().split()))

insertionSort(A, N)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

print(' '.join([str(x) for x in a]))

for i in range(1, n):

    v = a[i]
    j = i - 1
    while (j >= 0) and (a[j] > v):
        a[j+1] = a[j]
        j -= 1

    a[j+1] = v

    print(' '.join([str(x) for x in a]))

Solution (Python):
N = input()
l = [int(i) for i in input().split()]
mapped_l = map(str, l)
print(" ".join(mapped_l))
for i in range(1, len(l)):
  key = l[i]
  j = i-1
  while j >= 0 and l[j] > key:
    l[j+1] = l[j]
    j -= 1
  l[j+1] = key
  mapped_l = " ".join(map(str, l))
  print(mapped_l)

Solution (Python):
from sys import stdin
input = stdin.readline

N = int(input())
A = list(map(int, input().split()))


def p(N):
    for i in range(len(N)):
        if i == len(N) - 1:
            print(N[i])
        else:
            print(N[i], end=" ")


p(A)

for i in range(1, N):
    s = A[i]
    j = i - 1

    while j >= 0 and A[j] > s:
        A[j + 1] = A[j]
        j -= 1

    A[j + 1] = s

    p(A)

Solution (Python):
N=int(input())
lst=list(map(int,input().split()))
print(' '.join(map(str,lst)))

for i in range(1,len(lst)):
    j = i-1
    ele = lst[i]
    while j>=0 and lst[j] > ele:
        lst[j+1] = lst[j]
        j-=1
    lst[j+1] = ele
    print(' '.join(map(str,lst)))

Solution (Python):
n = int(input())
A = [int(_) for _ in input().split()]

for i in range(n):
    v = A[i]
    j = i - 1
    while j >= 0 and A[j] > v:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = v
    print(' '.join(map(str, A)))

Solution (Python):
def print_list(l):
    print(' '.join(map(str, l)))


n = int(input())
l = list(map(int, input().split()))

print_list(l)

for i in range(1, n):
    v = l[i]
    j = i - 1
    while j >= 0 and l[j] > v:
        l[j + 1] = l[j]
        j -= 1
    l[j + 1] = v
    print_list(l)

Solution (Python):
n = int(input())
A = list(map(int,input().split()))

for i in range(n):
    v = A[i]
    j = i -1
    while j>=0 and A[j]>v:
        A[j+1]=A[j]
        j -=1
        A[j+1]=v
    print(*A)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))

for i in range(N):
    j=i-1
    insertion_A=A[i]
    while j >= 0:
        if A[j] > insertion_A: 
            A[j+1] = A[j] 
        else:
            break
        j -= 1
    A[j+1]=insertion_A
    print(*A)

Solution (Python):
n = int(input())
*lst, = map(int, input().split())

for i in range(1, n):
    print(*lst)
    v = lst[i]
    j = i - 1

    while j>=0 and lst[j]>v:
        lst[j+1] = lst[j]
        j -= 1

    lst[j+1] = v
    
print(*lst)

Solution (Python):
N = int(input())
As = [int(x) for x in input().split()]

print(" ".join(map(str,As)))
for i in range(1,N):
    v = As[i]
    j = i - 1
    while j >= 0 and As[j] > v:
        As[j+1] = As[j]
        j -= 1
    As[j+1] = v
    print(" ".join(map(str,As)))

Solution (Python):







def insertionSort(a: list, n: int):
    a_string_list = map(str, a)
    output = ' '.join(a_string_list)
    print(output)
    for i in range(1, n):
        v = a[i]
        j = i - 1
        while j >= 0 and a[j] > v:
            a[j + 1] = a[j]
            j -= 1
        a[j + 1] = v
        a_string_list = map(str, a)
        output = ' '.join(a_string_list)
        print(output)


n = int(input())
a = list(map(int, input().split()))

insertionSort(a, n)

Solution (Python):


n = int(input())
l = list(map(int, input().split()))
for i in range(n):
    v = l[i]
    j = i - 1
    while j >= 0 and l[j] > v:
        l[j+1] = l[j]
        l[j] = v
        j -= 1
    print(' '.join(map(str, l)))

Solution (Python):


N = int(input())
A = list(map(int, input().split()))


def insertionSort(A, N):
    print(' '.join([str(i) for i in A]))
    for i in range(1, N):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j + 1] = A[j]
            j -= 1
        A[j+1] = v
        print(' '.join([str(i) for i in A]))


insertionSort(A, N)

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
print(' '.join(map(str, A)))
'''
for i in range(n):
    print(A[i], end=' ')
print('')
'''
for i in range(1, n):
    v = A[i]
    j = i - 1
    while j >=0 and A[j] > v:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = v
    '''
    for i in range(n):
        print(A[i], end=' ')
    print('')
    '''
    print(' '.join(map(str, A)))

Solution (Python):
def insertionSort(A):
    for i in range(len(A)):
        v = A[i]
        j = i-1
        while j >= 0 and A[j] > v:
            A[j+1] = A[j]
            j -= 1
        A[j+1] = v
        for i in range(len(A)):
            if i == len(A)-1:
                print(A[i],end="\n")
            else:
                print(A[i],end=" ")

def main():
    N = int(input())
    A = list(map(int,input().split()))
    insertionSort(A)


if __name__ == "__main__":
    main()

Solution (Python):
n = input()
A = list(map(int, input().split()))
for index in range(len(A)):
    if index != len(A) - 1:
        print(A[index], end=" ")
    else:
        print(A[index])

for i in range(1, len(A)):
    key = A[i]
    j = i - 1
    while j >= 0 and A[j] > key:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = key
    for index in range(len(A)):
        if index == len(A) - 1:
            print(A[index])
        else:
            print(A[index], end=" ")

Solution (Python):
def insertion_sort(lst):
    for i in range(1, len(lst)):
        v = lst[i]
        j = i - 1
        while j >= 0 and lst[j] > v:
            lst[j+1] = lst[j]
            j -= 1
        lst[j+1] = v
        print(*lst)

n = int(input())
lst = list(map(int, input().split()))
print(*lst)
insertion_sort(lst)

Solution (Python):
n = int(input())

L = [int(i) for i in input().split()]

def InsertionSort(A,N):
	for i in range(1,N):
		key = A[i]
		j = i - 1
		while j>=0 and A[j] > key:
			A[j+1] = A[j]
			j -= 1
		A[j+1]  = key

		for item in range(len(A)):
			if item == len(A)-1:
				print(A[item])
			else:
				print(A[item],end=" ")

for item in range(len(L)):
	if item == len(L)-1:
		print(L[item])
	else:
		print(L[item],end=" ")

InsertionSort(L,n)






"""
for i in range(len(A)):
	if i == len(A)-1:
		print(A[i])
	else:
		print(A[i],end=" ")
"""

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

print(" ".join(map(str, A)))

for i in range(1, N):
  v = A[i]
  j = i - 1
  while j >= 0 and A[j] > v:
    A[j + 1] = A[j]
    j -= 1
  A[j+1] = v
  print(" ".join(map(str, A)))

Solution (Python):
def insert_sort(A, N):
    print(*A, sep=' ')
    for i in range(1, N):
        tmp = A[i]
        j = i-1
        while j>=0 and A[j]>tmp:
            A[j+1] = A[j]
            j -= 1
            A[j+1] = tmp
        print(*A, sep=' ')

N = int(input())
A = list(map(int, input().split()))

insert_sort(A, N)

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
for i in range(1,n):
    print(" ".join(map(str,A)))
    v = A[i]
    j = i-1
    while j >= 0 and A[j] > v:
        
        A[j+1] = A[j]
        j -= 1
    A[j+1] = v
        
print(" ".join(map(str,A)))

Solution (Python):
n = int(input())
original_list = list(map(int,input().split()))
maped_list = map(str, original_list)
print(' '.join(maped_list))
for i in range(1,n):
    v = original_list[i]
    j = i - 1
    while j >= 0 and original_list[j] > v:
        original_list[j+1] = original_list[j]
        j = j - 1
    original_list[j+1] = v
    maped_list = map(str,original_list)
    print(' '.join(maped_list))

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
for i in range(n):
    v=A[i]
    j=i-1
    while j >= 0 and A[j] > v:
        A[j+1] = A[j]
        j-=1
    A[j+1] = v
    for k in range(len(A)):
        if k != len(A)-1:
            print(A[k],end=' ')
        else:
            print(A[k])

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

print(*a)
for i in range(1, n):
    v = a[i]
    j = i - 1
    while j >= 0 and a[j] > v:
        a[j + 1] = a[j]
        j -= 1
    a[j + 1] = v
    print(*a)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
s=" ".join(map(str,A))
print(s)
for i in range(1,N):
    
    v=A[i]
    j=i-1
    while(j>=0 and v<A[j]):
        A[j+1]=A[j]
        j-=1
    A[j+1]=v
    s=" ".join(map(str,A))
    print(s)

Solution (Python):
N = int(input())
a = [int(i) for i in input().split()]

for i in range(N):
    key = a[i]
    j = i-1
    while j>=0 and a[j] > key:
        a[j+1] = a[j]
        j -= 1
    a[j+1] = key
    for k in range(N):
        arra = ' '.join([str(n) for n in a])

    print(arra)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))



for i in range(N):
    v=A[i]
    j=i-1
    while(j>=0 and A[j]>v):
        A[j+1]=A[j]
        j-=1
    A[j+1]=v
    for i in range(N):print(A[i],end=' \n'[i+1==N])

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
def printA():
    for i in range(0, N-1):
            print(A[i], '', end='')
    print(A[N-1])

for i in range(0,N):
    v = A[i]
    for j in range(i,-1,-1):
        if A[j-1] <= v or j == 0:
            A[j+1:i+1] = A[j:i]
            A[j] = v
            break
    printA()