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



Sample input:
6
5 2 4 6 1 3


Sample output:
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

Submission status: Accepted

Solution code:
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=j-1
        A[j+1]=v
        print(*A,sep=" ")
N=int(input())
A=list(map(int,input().split()))

insertion_sort(A,N)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():
    def insertSort(A):
        N = len(A)
        for i in range(1,N):
            print(*A)
            val = A[i]
            j = i - 1
            while j >= 0 and A[j] > val:
                A[j+1] = A[j]
                j -= 1
            A[j+1] = val
        else:
            print(*A)

    N = int(input())
    A = [int(i) for i in input().split()]
    insertSort(A)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def insertion_sort(array):
    n = len(array)
    for i in range(1, n):
        tmp = array[i] # 挿入する値を退避
        if tmp < array[i-1]:
            # 挿入する位置までずらしていく
            j = i
            while True:
                array[j] = array[j-1]
                j -= 1
                if j == 0 or tmp >= array[j-1]:
                    break
            array[j] = tmp 
        print_list(array)

def print_list(array):
    list_s = [str(x) for x in array]
    print(" ".join(list_s))


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

Submission status: Accepted

Solution code:
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)))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
n = int(input())
nums = list(map(int, input().split()))
print(" ".join(list(map(str, nums))))
for i in range(1, n):
    for j in range(i):
        if nums[j] > nums[i]:
            nums.insert(j, nums.pop(i))
    print(" ".join(list(map(str, nums))))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:

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

  else:
    A[j + 1] = v
    for b in range(n):
      print(A[b], end=" \n"[b + 1 == n])

Submission status: Accepted

Solution code:
def insert_sort(nums, n):
    for i in range(1, n):
        nums_str = map(str, nums)
        print(" ".join(nums_str))
        v = nums[i]
        j = i - 1
        while j >= 0 and nums[j] > v:
            nums[j+1] = nums[j]
            j-=1

        nums[j+1] = v

    nums_str = map(str, nums)
    print(" ".join(nums_str))


if __name__=="__main__":
    n = int(input())
    nums = list(map(int, input().split()))
    insert_sort(nums, n)

Submission status: Accepted

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


def insertionSort(li: list, n: int):
    for i in range(n):
        v = li[i]
        j = i - 1
        while 0 <= j and v < li[j]:
            li[j+1] = li[j]
            j -= 1
        li[j+1] = v
        print(*li)


insertionSort(A, N)

Submission status: Accepted

Solution code:
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)))

Submission status: Accepted

Solution code:
N = int(input())
S = list(map(int, input().strip().split()))

for i in range(1, N+1):
    tmp = S[:i]
    tmp.sort()
    sroted_list = tmp + S[i:]
    str_list =[str(j) for j in sroted_list]
    print(' '.join(str_list))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline


def main():
    N = int(input())
    P = list(map(int, input().split()))
    print(' '.join(map(str, P)))
    insertionSort(N, P)


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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
#print(" ".join(list(map(str,a))))
for i in range(n):
    x=a[i]
    for j in range(i):
        if a[i-j-1]>a[i-j]:
            a[i-j-1],a[i-j]=a[i-j],a[i-j-1]
        else:
            break
    print(" ".join(list(map(str,a))))

Submission status: Accepted

Solution code:
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 v<A[j]:
        A[j+1]=A[j]
        j-=1
    A[j+1]=v
    print(*A)

Submission status: Accepted

Solution code:
n=int(input())
A = list(map(int,input().split()))
sA=[str(i) for i in A]
pA = ' '.join(sA)
print(pA)
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(A)
    sA=[str(i) for i in A]
    pA = ' '.join(sA)
    print(pA)

Submission status: Accepted

Solution code:

def insertion_sort(arr, num):
    for i in range(1, num):
        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(c) for c in a]))


if __name__ == '__main__':
    n = int(input())
    a_str: str = input()
    a = a_str.split(' ')
    a = [int(c) for c in a]
    print(' '.join([str(c) for c in a]))
    insertion_sort(a, n)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x 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
    for _ in range(N):
        if _ == N-1:
            print(A[_],sep='',end='')
        else:
            print(A[_], sep='',end=' ')
    print()

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split())
for i in range(1,n+1):a[:i]=sorted(a[:i]);print(*a)

Submission status: Accepted

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

li2 = []
for i in range(len(li)):
    s = li.pop(0)
    li2.append(s)
    li2.sort()
    ans = li2+li
    print(' '.join(map(str, ans)))

Submission status: Accepted

Solution code:
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)))

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]

for k in range(N):
    if k == N - 1:
        print(A[k])
    else:
        print(A[k], 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 k in range(N):
        if k == N - 1:
            print(A[k])
        else:
            print(A[k], end=" ")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

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

Submission status: Accepted

Solution code:
def insertion_sort(a, n):   # N個の要素を含む0-オリジンの配列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
        output(a)
    return a


def main():
    n = int(input())
    a = [int(x) for x in input().split()]
    insertion_sort(a, n)


def output(int_arr):
    print(" ".join([str(x) for x in int_arr]))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
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(list(map(str,A))))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
#coding: utf-8

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

def view():
    print(str(a[0]), end = '')
    for k in range(1, n):
        print(' {}'.format(a[k]), end = '')
    print('')
    
for i in range(1, n):
    view()
    v = a[i]
    j = i - 1
    while j >= 0 and a[j] > v:
        a[j + 1] = a[j]
        j -= 1
    a[j + 1] = v
view()

Submission status: Accepted

Solution code:
N = int(input())
s = list(map(int, input().split()))
for k in range(N):
    if k>0:
        print(" ",sep='',end='')
    print(s[k],sep='',end='')
print()



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=j-1

        A[j+1]=v

        
        for k in range(N):
            if k>0:
                print(" ",sep='',end='')
            print(A[k],sep='',end='')

        print()

insertionSort(s,N)

Submission status: Accepted

Solution code:
def main(n):
	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)))
	return

main(int(input()))

Submission status: Accepted

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

if __name__ == "__main__":
    N = int(input())
    A = [int(i) for i in input().strip().split()]
    insertionSort(A, N)

Submission status: Accepted

Solution code:
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 = j - 1
        A[j+1] = v
        print(*A)

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

Submission status: Accepted

Solution code:
n=int(input())
box=list(map(int,input().split()))
print(*box)
for i in range(1,n):
    while 1:
        if i==0:break
        elif box[i]<box[i-1]:
            box[i],box[i-1]=box[i-1],box[i]
            i -=1
        else:break
    print(*box)

Submission status: Accepted

Solution code:
# 1_1_A_InsertionSort.py

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

print(' '.join([str(x) for x in a]))
for i in range(1, len(a)):
    for j in range(i, 0, -1):
        if a[j] < a[j-1]:
            a[j], a[j-1] = a[j-1], a[j]
    print(' '.join([str(x) for x in a]))

Submission status: Accepted

Solution code:
def show(A):
    for i in range(N):
        if i<N-1:
            print(A[i],end=' ')
        else:
            print(A[i])

N=int(input())
A=list(map(int,input().split()))
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)

Submission status: Accepted

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
print(' '.join(map(str, a)))
for i in range(1, N):
    v = a[i]
    j = i - 1
    while j >= 0:
        if a[j] > v:
            a[j + 1], a[j] = a[j], a[j - 1]
            j -= 1
        else:
            break
    a[j + 1] = v
    print(' '.join(map(str, a)))

Submission status: Accepted

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

for i in range(1, N):
    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
    
print(' '.join(list(map(str, A))))

Submission status: Accepted

Solution code:
def insertSort(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)

f = insertSort(a, n)

Submission status: Accepted

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


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

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

Submission status: Accepted

Solution code:

def print_result(A, n):
    for i in range(n):
        if i > 0:
            print(' ', end='')
        print(A[i], end='')
    print('\n', end='')


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_result(arr, n)


n = eval(input())

arr = [eval(x) for x in input().split()]
print_result(arr, n)
insertion_sort(arr, n)

Submission status: Accepted

Solution code:
i=int(input())
n=list(map(int,input().split()))
print(' '.join(map(str, n)))
for k in range(1,i):
	target=n[k]
	hh=k-1
	while hh>=0 and n[hh]>target:
		n[hh+1]=n[hh]
		hh-=1
	n[hh+1]=target
	print(' '.join(map(str, n)))

Submission status: Accepted

Solution code:
def prList(A):
    n = len(A)
    for i in range(n):
        if i:
            print(" ", end="")
        print(A[i], end="")
    print("")


def insertSort(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
        prList(A)


n = int(input())
A = [int(i) for i in input().split()]
prList(A)
insertSort(A)

Submission status: Accepted

Solution code:
# ALDS1_1_A - Insertion Sort
def main():
    N, *A = map(int, open(0).read().split())
    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)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    print(*A)
    for i in range(1, N):
        while(i >= 1 and A[i-1] > A[i]):
            A[i], A[i-1] = A[i-1], A[i]
            i -= 1
        print(*A)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
A =list(map(int,input().split()))
L = [str(a) for a in A]
B = " ".join(L)
print(B)
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]
	B = " ".join(L)
	print(B)

Submission status: Accepted

Solution code:
num = int(input())

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

def plist(a):
    for i in range(len(a)):
        print(a[i],end="")
        if i < len(a)-1:
            print(" ",end="")
    print()
    
plist(a)
for i in range(1,num):
    tmp = a[i]
    j = i - 1
    while (j >= 0 and a[j] > tmp):
        a[j+1] = a[j]
        j -= 1
    a[j+1] = tmp
    plist(a)

Submission status: Accepted

Solution code:
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(' '.join(map(str,A)))
    
    
n = int(input())
test = list(map(int,input().split()))

print(' '.join(map(str,test)))
insertion_sort(test,n)

Submission status: Accepted

Solution code:
N=int(input())
nums=list(map(int,input().split()))

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

Submission status: Accepted

Solution code:
def test():

	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):
		
		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-1):
			print(f"{A[k]} ",end = '')
		print(f"{A[n-1]}")

if __name__ == "__main__":
	test()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)))

Submission status: Accepted

Solution code:
N = input()
A = map(int, raw_input().split())
for i in range(N):
  print " ".join(map(str, sorted(A[:i+1])+A[i+1:]))

Submission status: Accepted

Solution code:
def display(l):
    for item in l:
        if not item == l[-1]:
            print(f"{item}", end=' ')
        else:
            print(item)


n = int(input())
lst = list(map(int, input().split()))
display(lst)

for i in range(1, len(lst)):
    key = lst[i]
    j = i - 1
    while j >= 0 and lst[j] > key:
        lst[j+1] = lst[j]
        j -= 1
    lst[j+1] = key
    display(lst)

Submission status: Accepted

Solution code:

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())
m = list(map(int, input().split()))
print(*m)
insertion_sort(m,n)

Submission status: Accepted

Solution code:
#! /usr/bin/python
# -*- coding: utf-8 -*-

n=int(input()) # 数列の長さ
A=list(map(int, input().split())) # 空白を区切文字として配列に格納
print(*A)

for i in range(1, n):
    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 -= 1
    A[j+1] = key
    print(*A)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def FUNC00(ARG00):
    for VAR00 in range(1, len(ARG00)):
        VAR01 = ARG00[VAR00]
        VAR02 = VAR00 - 1
        while VAR02 >= 0 and ARG00[VAR02] > VAR01:
            ARG00[VAR02 + 1] = ARG00[VAR02]
            VAR02 -= 1
        ARG00[VAR02 + 1] = VAR01
        print(' '.join([str(VAR03) for VAR03 in ARG00]))
VAR04 = int(input())
VAR05 = [int(VAR06) for VAR06 in input().split()]
print(' '.join([str(VAR06) for VAR06 in VAR05]))
FUNC00(VAR05)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

    string=[str(a) for a in A]
    out=' '.join(string)
    print(out)

Submission status: Accepted

Solution code:

N = int(input())

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


for i in range(N-1):

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

    i += 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


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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]

def pr(A):
    N = len(A)
    for i in range(N):
        if i != 0:
            print(" ",end = "")
        print(A[i], end = "")
    print("")

def insertionSort(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
        pr(A)

pr(A)
insertionSort(A)

Submission status: Accepted

Solution code:
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 = j-1
        A[j+1] = v
    for k in range(n-1):
        print(str(A[k]) + " ", end = "")
    print(str(A[n-1]))

Submission status: Accepted

Solution code:
r = int(input())
A = list(map(int, input().split()))

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

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

Submission status: Accepted

Solution code:
#insertion sort
def printout(array,n):
    output = ""
    for i in range(n-1):
        output += str(array[i]) + " "
    output += str(array[N-1])
    print(output)

N = int(input())
array = [int(i) for i in input().split()]
printout(array,N)

for i in range(1,N):
    a = array[i]
    for j in reversed(range(0,i)):
        if (a < array[j]):
            array[j+1] = array[j]
            array[j] = a
        else:
            break;
    printout(array, N)

Submission status: Accepted

Solution code:
valuenum = int(input())

Input = input()
print(Input)
values = [int(value) for value in Input.split()]

for i in range(1,valuenum):
  for j in range(0,i):
    if values[i] < values[j]:
      values.insert(j, values[i])
      values.pop(i + 1)
      break

  ans = map(lambda value:str(value), values)
  print(' '.join(ans).strip())

Submission status: Accepted

Solution code:
def insertion_sort(a, n):
    for i in range(n):
        v = a[i]
        j = i-1
        while((j>=0)&(v<a[j])):
            a[j+1] = a[j]
            j -= 1
        a[j+1] = v
        print(" ".join([str(i) for i in a]))
    return
    
n = int(input())
a = [int(i) for i in input().split()]
insertion_sort(a, n)

Submission status: Accepted

Solution code:

def InsertionSort(data):
    show(data)
    for i in range(1, len(data)):
        temp = data[i]
        for j in reversed(range(0, i)):
            if data[j] > temp:
                data[j+1] = data[j]
            else:
                data[j+1] = temp
                break
            if j == 0:
                data[0] = temp
        show(data)
    return data

def Input():
    input()
    data = [int(e) for e in input().split()]
    return data

def show(data):
    string = str(data[0])
    for i in range(1, len(data)):
        string = string + " " + str(data[i])
    print(string)

InsertionSort(Input())

Submission status: Accepted

Solution code:
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 = j - 1
  a[j+1] = v
  print(*a)

Submission status: Accepted

Solution code:
num = int(input())
num_list = input().split(" ")

nums = []

for n in num_list:
    nums.append(int(n))
    
for m in range(num):
    i = nums[m]
    j = m - 1
    while j >= 0 and nums[j] > i:
        nums[j+1] = nums[j]
        j -= 1
    nums[j+1] = i
    
    for n in range(num):
        if n == len(nums)-1:
            print(int(nums[n]), end = "")
            print("")
        else:
            print(int(nums[n]), end = " ")

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def insertion_sort(A):
    for i in range(1,len(A)):
        print(*A)
        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-=1
        A[j+1] = key
 
if __name__=='__main__':
   n=int(input()) 
   A=list(map(int,input().split()))
   insertion_sort(A)
   print(*A)

Submission status: Accepted

Solution code:
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)))

Submission status: Accepted

Solution code:
num_inputs = int(input())
input_array = input().split(' ')

for i in range(1, num_inputs):
    print(' '.join(input_array))
    current_value = input_array[i]
    j = i - 1
    while j >= 0 and int(input_array[j]) > int(current_value):
        input_array[j + 1] = input_array[j]
        j -= 1
    input_array[j + 1] = current_value
    
print(' '.join(input_array))

Submission status: Accepted

Solution code:
n=int(input())
A=list(map(int,input().split()))
def convert(list):
    s=[str(i) for i in list]
    res = " ".join(s)
    return res
print(convert(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(convert(A))

Submission status: Accepted

Solution code:
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(" ".join(map(str,a)))

Submission status: Accepted

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


def fun(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(["{0["+ str(i) + "]}" for i in range(n)]).format(A))

fun(n,A)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
n = int(input())
nums = list(map(int, input().split()))
print(' '.join(map(str, nums)))

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

Submission status: Accepted

Solution code:
n = int(input())

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

for i in range(1, n):
    key = A[i]
    j = i - 1
    while j >= 0 and A[j] > key:
        j -= 1
    A.insert(j+1, key)
    del A[i+1]

    print(*A)

Submission status: Accepted

Solution code:
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], A[j+1] = A[j+1], A[j]
    j -= 1
  print(' '.join(map(str, A)))

Submission status: Accepted

Solution code:
def sort(a, n):
	print(" ".join(map(str, 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(" ".join(map(str, a)))

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

sort(A, N)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
for j in range(n):
  print(a[j], end="")
  if j < n-1:
    print(" ", end="")
  else:
    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 = j - 1
  a[j+1] = v

  for j in range(n):
    print(a[j], end="")
    if j < n-1:
      print(" ", end="")
    else:
      print("")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def insertitionSort(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 = j -1
        A[j+1] = v
        map_result = map(str, A)
        print(' '.join(map_result))                  ### 出力形式を変換

##from IPython.core.debugger import Pdb; Pdb().set_trace()        
N = int(input())
A = list(map(int, input().split()))   ###　　1行の複数の入力を整数型で

insertitionSort(A,N)