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):
n = int(input())
A = list(map(int, input().split()))
for i in range(1, n):
    print(' '.join(map(str, A)))
    temp = A[i]
    j = i - 1
    while A[j] > temp and j >= 0:
        A[j + 1] = A[j]
        j -= 1
    A[j + 1] = temp
print(' '.join(map(str, A)))

Solution (Python):
def insertion_sort(A, N):
  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)

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

print(*A)
insertion_sort(A,N)

Solution (Python):

import sys
input=sys.stdin.readline

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

if __name__=="__main__":
    main()

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

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

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):
import sys, os, math, bisect, itertools, collections, heapq, queue

from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def insertion_sort(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():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = il()
    insertion_sort(A, N)


if __name__ == '__main__':
    main()

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

print(' '.join(str(a) for a 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(a) for a in A))

Solution (Python):
n = int(input())
num = list(map(int, input().split()))
cnt = 1
print(" ".join(map(str,num)))
while cnt < len(num):
    for i in range(cnt, 0, -1):
        if num[i] < num[i-1]:
            num[i], num[i-1] = num[i-1], num[i]
    print(" ".join(map(str,num)))
    cnt+=1

Solution (Python):


def insert_sort(A:list) -> list:
    for i in range(1, len(A)):
        print(" ".join(list(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
    return A


if __name__ == '__main__':
    n = int(input())
    A = list(map(int, input().rstrip().split()))
    print(" ".join(list(map(str,insert_sort(A)))))

Solution (Python):
def insertionSort(A, N):
    for i in range(1, N):
        pri_lst(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

def pri_lst(A):
    print(" ".join(map(str,A)))

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

insertionSort(A, N)
pri_lst(A)

Solution (Python):
def Insert_sort(array,N):
    for i in range(1,N):
        temp = array[i]
        j = i - 1
        print(*array)
        while(j >= 0 ) and (array[j] >= temp):
            array[j+1] = array[j]
            
            j -= 1
        array[j+1] = temp
    print(*array)      
            
    
    
    
try:
    N = int(input())
    array = list(map(int,input().split()))
except ValueError as N:
    print('数値以外が入力されました')

Insert_sort(array,N)

Solution (Python):

n = int(input())
elements = [int(n) for n in input().split()]
print(' '.join(map(str, elements)))


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

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

for i in xrange(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):
_ = input()

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

for i in range(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
    print(' '.join(map(str,a)))

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


_N = int(input())
_A = list(input().split())
_A = [int(x) for x in _A]
insertion_sort(_A, _N)

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


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
        print(" ".join([str(a) for a in A]))


def main():
    _ = int(input().strip())
    A = [int(i) for i in input().strip().split()]
    insertionSort(A)


if __name__ == "__main__":
    main()

Solution (Python):
n, *aa = map(int, open(0).read().split())

for i in range(n):
    j = i
    while j-1 >= 0:
        if aa[j-1] > aa[j]:
            aa[j-1], aa[j] = aa[j], aa[j-1]
        j -= 1
    print(*aa)

Solution (Python):

N = int(input())
list_num = list(map(int, input().split(" ")))
print(" ".join(map(str, list_num)))

for i_incert in range(1, N):
    num_incert = list_num[i_incert]
    i_cmpr = i_incert - 1
    
    while i_cmpr >= 0 and list_num[i_cmpr] > num_incert:
        list_num[i_cmpr + 1] = list_num[i_cmpr]  
        i_cmpr -= 1
    list_num[i_cmpr + 1] = num_incert
    print(" ".join(map(str, list_num)))

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 l[j] > v and j >= 0:
        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()))

for i in range(N):
    v = A[i]
    if v >= A[0]:
        j = 0
        while v >= A[j] and j < i:
            j = j + 1
        if j < i:
            for k in reversed(range(j, i)):
                A[k + 1] = A[k]
            A[j] = v
            print(' '.join([str(a) for a in A]))
        else:
            print(' '.join([str(a) for a in A]))

    else:
        for l in reversed(range(i)):
            A[l+1]=A[l]
        A[0]=v
        print(' '.join([str(a) for a in A]))

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

for idx1 in range(len(nums)):
    num  = nums[idx1]
    idx2 = idx1 - 1
    while idx2 >= 0 and nums[idx2] > num:
        nums[idx2 + 1] = nums[idx2]
        idx2 -= 1
    nums[idx2+1] = num
    print(" ".join(map(str, nums)))

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

if __name__ == '__main__':
    n = int(input())
    l = list(map(int, input().split()))
    print(' '.join(list(map(str,l))))
    insertion_sort(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,sep=' ')

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

for i in range(n):
    b = sorted(a[:i+1])
    b.extend(a[i+1:])
    print(' '.join([str(i) for i in b]))

Solution (Python):
def insertionSort(arr): 
  
    
    for i in range(1, len(arr)): 
  
        key = arr[i] 
        j = i - 1
        
        while j >=0 and key < arr[j] : 
                arr[j+1] = arr[j] 
                j -= 1
        arr[j+1] = key
        
        print(' '.join(map(str, numbers)))

_ = input()
numbers = list(map(int, input().split()))
print(' '.join(map(str, numbers)))
insertionSort(numbers)

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()))

for i in range(1, n):
    for m in range(n-1):
        print(A[m], end=' ')
    print(A[n-1])
    
    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 m in range(n-1):
    print(A[m], end=' ')
print(A[n-1])

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 main():
    card_num = int(input())
    cards = list(map(int, input().split()))
    
    res = " ".join([str(n) for n in cards])
    print(res)
    
    for i in range(1, card_num):
        v = cards[i]
        j = i - 1
        while j >= 0 and cards[j] > v:
            cards[j + 1] = cards[j]
            j -= 1
        cards[j + 1] = v
        
        res = " ".join([str(n) for n in cards])
        print(res)

if __name__ == '__main__':
    main()

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

for i in range(1, n + 1):
    print(*A)
    if i >= n: break

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

Solution (Python):
def insertionSort(A, N):
    for i in range(1, N):
        print(" ".join([str(a) for a in 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([str(a) for a in A]))    
    

N = int(input().rstrip())
A = [int(a) for a in input().rstrip().split(" ")]
insertionSort(A, N)

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

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

def insertionSort(A, N):
    for i in range(1, N):
        show(A)
        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

    show(A)

def show(lst):
    print(*lst)


insertionSort(nums, N)

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

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

print(" ".join(list(map(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(" ".join(list(map(str, A))))

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

def insertionSort(a, n):
    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)))

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

Solution (Python):
def InsertionSort(A, N=1):
    N = min(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
    return A


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

for i in range(len(a)):
    print(' '.join(map(str, InsertionSort(a, i+1))))

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

ans=str(num_list[0])
for k in range(1,len(num_list)):
    ans+=" "+str(num_list[k])
print(ans)

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

    ans=str(num_list[0])
    for k in range(1,len(num_list)):
        ans+=" "+str(num_list[k])
    print(ans)

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
    A_=' '.join(map(str,A))
    print(A_)

Solution (Python):

test_case_1_num = int(input())
test_case_1 = list(map(int,input().split()))

print(" ".join(map(str, test_case_1)))
for i in range(1, test_case_1_num):
    t = test_case_1[i]
    p = i
    for j in range(0, i):
        if t > test_case_1[j]:
            continue
        else:
            for k in reversed(range(j,i)):
                test_case_1[k + 1] = test_case_1[k]
                p -= 1
            break

    test_case_1[p] = t

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

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

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

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

main()

Solution (Python):
def show(a):
    ans=""
    for c in a:
        if c==a[-1]:
            ans+=str(c)
        else:    
            ans+=str(c)+" "
    print(ans)

def insertionsort(a,n):
    show(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
        show(a)

n=int(input())
line=list(map(int,input().split()))
insertionsort(line,n)

Solution (Python):
from sys import stdin


def insertion_sort(A, N):
    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 j in range(N-1):
            print(A[j], end=" ", sep=" ")
        print(A[N-1])
            

def main():
    read = stdin.readline
    N = int(read())
    data = list(map(int, read().split(" ")))
    for j in range(N-1):
        print(data[j], end=" ", sep=" ")
    print(data[N-1])
    insertion_sort(data, N)
    
if __name__ == "__main__":
    main()

Solution (Python):
import sys

input = sys.stdin.readline


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

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


if __name__ == "__main__":
    main()

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

for i in range(1,n):
  print(*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(*A)

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()))

for x in a:
    if x == a[n-1]:
        print(x)
    else:
        print(x, end=' ')

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 x in a:
        if x == a[n-1]:
            print(x)
        else:
            print(x, end=' ')

Solution (Python):
N=int(input())
A=list(map(int,input().split(" ")))
print(" ".join(list(map(str,A))))
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(" ".join(list(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)


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


if __name__ == '__main__':
    main()

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

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


def insertionSort(table):
    for i in range(1, len(table)):
        min = table[i]
        j = i - 1
        while j >= 0 and min < table[j]:
            table[j + 1] = table[j]
            table[j] = min
            j += -1
        printTable(table)


number = int(input())
table = list(map(int, input().split()))
printTable(table)
insertionSort(table)

Solution (Python):

from sys import stdin

def insertionSort(A, N):  
  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)))

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

insertionSort(A, N)

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

Solution (Python):



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

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

        
ans = insertionSort(N,arr)

Solution (Python):
n = input()
A = list(map(int, input().split()))
print(*A)
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
    print(*A)

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

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

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
for i in range(1,N):
  print(*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(*A)

Solution (Python):








def insertionSort(A, N):
    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)

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

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(" ".join(map(str, A)))

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


if __name__ == '__main__':
    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(0,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,sep=" ")

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())
cards = list(map(int,input().split()))
print(" ".join(map(str,cards)))

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

Solution (Python):
N = int(input())
array = list(map(int,input().split()))
for dt in array:
    if dt==array[-1]:
        print(dt)
    else:print(dt,end=" ")
for n in range(1,N):
    for m in range(n-1,-1,-1):
        if array[m]>array[m+1]:
            tmp=array[m]
            array[m]=array[m+1]
            array[m+1]=tmp
    for dt in array:
        if dt==array[-1]:
            print(dt)
        else:print(dt,end=" ")

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()))

def print_space(li):
    for i in range(len(li)-1):
        print(li[i], end=' ')
    else:
        print(li[-1])

def InsertionSort(li):
    print_space(li)
    for i in range(1, n):
        v = li[i]
        j = i - 1
        while j >= 0 and li[j] > v:
            li[j+1] = li[j]
            j -= 1
        else:
            li[j+1] = v
        print_space(li)
            

InsertionSort(a)

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

def insertion_sort(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
        print(' '.join(map(str,a)))
    return a
    
if __name__ == "__main__":
    n = int(input())
    a = list(map(int,input().split()))
    insertion_sort(n,a)

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
    Z=[str(a) for a in S]
    Z=" ".join(Z)
    print(Z)

Solution (Python):
def show(A):
    output = ""
    for i in range(len(A)):
        output += str(A[i]) + " "
    print(output[:-1])

def insertionsort(A, N):
    for i in range(1, N):
        show(A)
        A[:i+1] = sorted(A[:i+1])
    show(A)
    
N = int(input())
A = list(map(int, input().split())) 

insertionsort(A, N)

Solution (Python):
def insertionSort(N,A):
    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)))

insertionSort(int(input()),list(map(int,input().split())))

Solution (Python):
def print_list(A):
    for x in range(len(A) - 1):
        print(A[x],end = " ")
    print(A[len(A) - 1])

def insertionsort(A,n):
    count = 0
    for i in range(1,n):
        print_list(A)
        right = i
        left = i - 1
        while A[left] > A[right] and left >= 0:
            A[left],A[right] = A[right],A[left]
            right = left
            left -= 1
            count += 1
    print_list(A)
    return A

if __name__ == '__main__':
    n = int(input())
    A = [int(i) for i in input().split()]
    A = insertionsort(A,n)

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

N = int(input())
input_list = input().split(' ')
A = []
for i in input_list:
    A.append(int(i))
if len(input_list) != N:
    raise ValueError('N個の整数を入力してください。')

for i in range(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
    show_nums(A)

Solution (Python):


from sys import stdin
input = lambda: stdin.readline().rstrip()

N = int(input())

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

join = lambda a : ' '.join(map(str, a))
print(join(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(A))

Solution (Python):
def insertion_sort(A,N):
    sorted_A = A.copy()
    print(*sorted_A)
    for i in range(1,N):
        v = sorted_A[i]
        j = i-1
        while (j>=0)&(sorted_A[j]>v):
            sorted_A[j+1] = sorted_A[j]
            j -= 1
        sorted_A[j+1] = v
        print(*sorted_A)
        

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

insertion_sort(A,N)

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([str(_) for _ in a]))
N = int(input())
A = list(map(int,input().split()))
insertionSort(A,N)

Solution (Python):
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import bisect
import functools

def InsertionSort(A):
    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
        print(*A)
n = int(input())
A = list(map(int,input().split()))
print(*A)
InsertionSort(A)

Solution (Python):
def insertionSort(A, N):
    for i in range(1, N):
        print(*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(*A)


def resolve():
    N = int(input())
    A = [int(i) for i in input().split()]
    insertionSort(A, N)


resolve()

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 j in range(n):
        if j == n - 1 :
            print(A[j])
        else:
            print(str(A[j]) + " ", end="")

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

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

Solution (Python):
size = int(input())
l = []
for i in map(int, input().split()):
    l.append(i)
print(' '.join(map(str,l)))

for i in range(1,size):
    tmp = l[i]
    j = i - 1

    while l[j] > tmp and j >= 0:
        l[j + 1] = l[j]
        j = j - 1
    l[j + 1] = tmp
    
    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 insertion_sort(A: list, N: int):
    print(*A, sep=" ")
    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, sep=" ")


if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    insertion_sort(A, N)

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**10
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    A = LI()

    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 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())
numlist = [int(x) for x in input().split()]

insertionSort(numlist,n)

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

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

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

Solution (Python):
def insertion_sort(seq):
    n = len(seq)
    for i in range(n):
        v = seq[i]
        j = i-1
        while j >= 0 and seq[j] > v:
            seq[j+1] = seq[j] 
            j -= 1
        seq[j+1] = v
        print(seq[0], end='')
        for k in range(1, n):
            print(' '+str(seq[k]), end='')
        print()

n = int(input())
seq = list(map(int, input().split()))
insertion_sort(seq)

Solution (Python):
n = int(input())
l = list(map(int, input().split()))
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 -= 1
    l[j+1] = v
    print(*l)