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: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-


def insertion_sort(n, A):
    for i in xrange(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

if __name__ == "__main__":
    n = int(raw_input())
    A = raw_input().split(" ")
    insertion_sort(n, A)
    print " ".join(A)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-


def insertion_sort(n, A):
    for i in xrange(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

if __name__ == "__main__":
    n = int(raw_input())
    A = raw_input().split(" ")
    insertion_sort(n, A)
    print " ".join(A).strip()

Submission status: Wrong Answer

Solution code:
A = input().split()
N = A.pop()
# print(N)
# print(A)

# A = [5, 2, 4, 6, 1, 3]
print(' '.join(map(str, 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 = j - 1
    A[j+1] = key
    print(' '.join(map(str, A)))

Submission status: Wrong Answer

Solution code:
A = input().split()[1:]

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
A = [int(item) for item in input().split()[1:]]

print(' '.join([str(item) for item in 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 = j - 1
    A[j+1] = key
    print(' '.join(map(str, A)))

Submission status: Wrong Answer

Solution code:
A = [int(item) for item in input().split()[1:]]

print(' '.join([str(item) for item in 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 = j - 1
    A[j+1] = key
    print(' '.join([str(item) for item in A]))

Submission status: Wrong Answer

Solution code:
A = [int(item) for item in input().split()[1:]]
 
print(' '.join([str(item) for item in 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 = j - 1
    A[j+1] = key
    print(' '.join([str(item) for item in A]))

Submission status: Wrong Answer

Solution code:
A = [int(item) for item in input().split()[1:]]

print(" ".join([str(item) for item in 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 = j - 1
    A[j+1] = key
    print(" ".join([str(item) for item in A]))

Submission status: Wrong Answer

Solution code:
A = [5, 2, 4, 6, 1, 3]
 
print(' '.join([str(item) for item in 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 = j - 1
    A[j+1] = key
    print(' '.join([str(item) for item in A]))

Submission status: Wrong Answer

Solution code:
length = int(input())
targ = [int(n) for n in input().split(' ')]
for l in range(length):
    for m in range(l):
        if targ[l - m] < targ[l - m - 1]:
            disp = targ[l-m -1]
            targ[l-m-1] = targ[l-m]
            targ[l-m] = disp
    print(targ)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
_ = input()
A = [int(a) for a in input().split(" ")]
for i in range(1, len(A)):
  print(" ".join([str(a) for a in 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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

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

for i in range(1, len(num_list)):
    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
    for i in range(len(num_list)):
        print(str(num_list[i]), end="")
        if i < len(num_list)-1:
            print(" ", end="")
        else:
            print()

Submission status: Wrong Answer

Solution code:
input_num = int(input())
num_list = [int(i) for i in input().split()]

for i in range(1, len(num_list)):
    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
    for i in range(len(num_list)):
        print(str(num_list[i]), end="")
        if i < len(num_list)-1:
            print(" ", end="")
        else:
            print()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
A = map(int, raw_input().split())
for i in xrange(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 " ".join(map(str, A))

Submission status: Wrong Answer

Solution code:
print(input())

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

    string = ""
    for elem in A:
        string += str(elem) + " "

    print(string)

Submission status: Wrong Answer

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

for i in range(1, n):
    string = ""
    for elem in A:
        string += str(elem) + " "

    print(string)
    
    key = A[i]
    j = i - 1

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

    A[j+1] = key

Submission status: Wrong Answer

Solution code:
def insersionSort(A, N):
  print(" ".join(map(str,A)))
  for i in range(1,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
    print(" ".join(map(str,A)))

n = int(input())
a = [int(i) for i in input().split()]
insersionSort(a, n)

Submission status: Wrong Answer

Solution code:
n= int(input())
l= list(map(int,input().split()))
for m in range(n-1):
	j=m+1
	if(l[j-1]>l[j]):
		i=j
		while(not i==0):
			if(not(l[i-1]<l[i])):
				l[i-1],l[i]= l[i],l[i-1]
				i-=1
			else:
				break
	s= ''
	for k in l:
		s+=' '+str(k)
	print(s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
array_length = int(raw_input())
unsorted_array = list(map(int, raw_input().split()))

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

Submission status: Wrong Answer

Solution code:
from __future__ import print_function


class Solution:
    """
    @param prices: Given an integer array
    @return: Maximum profit
    """

    @staticmethod
    def insertion_sort():
        # write your code here
        array_length = int(raw_input())
        line = raw_input()
        unsorted_array = line.strip().split(" ")

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


if __name__ == '__main__':
    solution = Solution()
    solution.insertion_sort()

Submission status: Wrong Answer

Solution code:
from __future__ import print_function


class Solution:
    """
    @param prices: Given an integer array
    @return: Maximum profit
    """

    @staticmethod
    def insertion_sort():
        # write your code here
        array_length = int(raw_input())
        line = raw_input()
        unsorted_array = line.strip().split(" ")

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


if __name__ == '__main__':
    solution = Solution()
    solution.insertion_sort()

Submission status: Wrong Answer

Solution code:
array_length = int(raw_input())
line = raw_input()
unsorted_array = line.strip().split(" ")

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

Submission status: Wrong Answer

Solution code:
# encoding: utf-8

from __future__ import print_function


class Solution:
    """
    @param prices: Given an integer array
    @return: Maximum profit
    """

    @staticmethod
    def insertion_sort():
        # write your code here
        array_length = int(input())
        unsorted_array = [int(x) for x in input().split()]

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


if __name__ == '__main__':
    solution = Solution()
    solution.insertion_sort()

Submission status: Wrong Answer

Solution code:
array_length = int(input())
unsorted_array = [int(x) for x in input().split()]

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
N = raw_input()
A =raw_input().split()
print ' '.join(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 = j - 1 
    A[j+1] = v 
    print ' '.join(map(str,A))

Submission status: Wrong Answer

Solution code:
def insertionSort(length, numbers):
     for i in range(length):
          for k in range(length):
               if numbers[i] <= numbers[k]:
                    numbers.insert(k, numbers[i])
                    del numbers[i+1]
                    print numbers
                    break
          

length = int(raw_input())
numbers = map(int, raw_input().split())


insertionSort(length, numbers)

Submission status: Wrong Answer

Solution code:
leng = input()
ind = input()
indsprit = ind.split(" ")
print(indsprit)
for i in range(len(indsprit)):
	v = indsprit[i]
	j = i -1
	while j >= 0 and indsprit[j] > v:
		indsprit[j+1] = indsprit[j]
		j -= 1
	indsprit[j+1] = v
	print(indsprit)
print(indsprit)

Submission status: Wrong Answer

Solution code:
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_A&lang=jp
#?????\????????????????£?
#?¨?????????????????????????????????±?????????
def insertion_sort(target_list, n_list):
    
    for focus_index in range(1, n_list):
        print(*target_list)
        target = target_list[focus_index]
        if target < target_list[focus_index - 1]:#?????£?????°??????????????§??????
            compare_index = focus_index

            while compare_index > 0 and target_list[compare_index - 1] > target:
                target_list[compare_index] = target_list[compare_index - 1]
                compare_index -= 1;

            target_list[compare_index] = target
        
    return target_list

def main():
    n_list = int(input())
    target_list = [int(a) for a in input().split()]
    insertion_sort(target_list, n_list)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def insertion_sort(arr):
  for i in range(1, len(arr)):
    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(" ".join(map(str, arr)))

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

Submission status: Wrong Answer

Solution code:
N = int(input())
#print(N)
card = input().split()
print(card)

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

print(card)

Submission status: Wrong Answer

Solution code:
N = int(input())
#print(N)
card = input().split()
#print(card)

for i in range(N):
    v = card[i]
    j = i - 1
    while j >= 0 and card[j] > v:
        card[j+1] = card[j]
        j = j -1
    card[j+1] = v
    card_list = [int(i) for i in card]
    print(card_list)

Submission status: Wrong Answer

Solution code:
n = raw_input()

if n < 1 and n > 100:
	exit()

l = raw_input()

elements = l.split()

for i in range(1, int(n)):
	key = elements[i]
	j = i - 1
	while j >= 0 and elements[j] > key:
		elements[j + 1] = elements[j]
		j -= 1
	elements[j + 1] = key
	print elements

Submission status: Wrong Answer

Solution code:
#input number
n = raw_input()

if n < 1 and n > 100:
	exit()

# input elements
l = raw_input()

elements = l.split()

for i in range(1, int(n)):
	key = elements[i]
	j = i - 1
	while j >= 0 and elements[j] > key:
		elements[j + 1] = elements[j]
		j -= 1
	elements[j + 1] = key
	# output
	o = ''
	for e in elements:
		o += str(e) + ' '
	print o

Submission status: Wrong Answer

Solution code:
#input number
n = raw_input()

if n < 1 and n > 100:
	exit()

# input elements
l = raw_input()

elements = l.split()

print ' '.join(str(e) for e in elements)

for i in range(1, int(n)):
	key = elements[i]
	j = i - 1
	while j >= 0 and elements[j] > key:
		elements[j + 1] = elements[j]
		j -= 1
	elements[j + 1] = key
	# output
	print ' '.join(str(e) for e in elements)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-


def insertion_sort(seq, l):
    for i, v in enumerate(seq[1:], start=1):
        left = i - 1
        while left >= 0 and seq[left] > v:
            seq[left], seq[left+1] = seq[left+1], seq[left]
            left -= 1
        print(' '.join([str(n) for n in seq]))


def to_int(v):
    return int(v)


def to_seq(v):
    return [int(c) for c in v.split()]


if __name__ == '__main__':
    l = to_int(input())
    seq = to_seq(input())

    insertion_sort(seq, l)

Submission status: Wrong Answer

Solution code:
# ??\?????????
N = int(input())
list = input().split()

# ?????\?????????
for i in range(1,len(list)):
    v = list[i]
    j = i - 1
    while j >=0 and list[j] > v:
        list[j+1] = list[j]
        j -= 1
    list[j+1] = v
    print(list)

Submission status: Wrong Answer

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

# ?????\?????????
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(*A)

Submission status: Wrong Answer

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


# ?????\?????????
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)

print(*A)
print(insertion_sort(A, N))

Submission status: Wrong Answer

Solution code:

# coding:utf-8

def insert_sort(list):
    for i in range(1, n):
        temp = list[i] # ?§??????????????´?
        while i>=1 and temp<list[i-1]: list[i]=list[i-1] ; i-=1
        list[i] = temp
        print(list)


n=int(input())
buff = list(map(int,input().split()))
insert_sort(buff)

Submission status: Wrong Answer

Solution code:

# coding:utf-8

def insert_sort(list):
    for i in range(1, n):
        temp = list[i] 
        while i>=1 and temp<list[i-1]: list[i]=list[i-1] ; i-=1
        list[i] = temp
        print(list)


n=int(input())
buff = list(map(int,input().split()))
insert_sort(buff)

Submission status: Wrong Answer

Solution code:
# coding:utf-8

def insert_sort(list):
    for i in range(1, n):
        temp = list[i] # ?§??????????????´?
        while i>=1 and temp<list[i-1]: list[i]=list[i-1] ; i-=1
        list[i] = temp
        print(list)
    print(list)

n=int(input())
buff = list(map(int,input().split()))
insert_sort(buff)

Submission status: Wrong Answer

Solution code:
def insertion_sort(target_list):
    '????????????????????????????????\???????????§??????????????????????????¨?????????'
    sorted_list = list()
    for target in target_list[:]:
        for i, num in enumerate(sorted_list):
            if num > target:
                sorted_list[i:i] = [target]
                break
        else:
            sorted_list.append(target)
        target_list.pop(0)
        print(sorted_list + target_list)

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

Submission status: Wrong Answer

Solution code:
def insertion_sort(target_list):
    '????????????????????????????????\???????????§??????????????????????????¨?????????'
    sorted_list = [target_list.pop(0)]
    for target in target_list[:]:
        print(sorted_list + target_list)
        for i, num in enumerate(sorted_list):
            if num > target:
                sorted_list[i:i] = [target]
                break
        else:
            sorted_list.append(target)
        target_list.pop(0)
    print(sorted_list + target_list, end='')

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

Submission status: Wrong Answer

Solution code:
def insertion_sort(target_list):
    sorted_list = list()
    for target in target_list[:]:
        for i, num in enumerate(sorted_list):
            if num > target:
                sorted_list[i:i] = [target]
                break
        else:
            sorted_list.append(target)
        target_list.pop(0)
        print(' '.join(str(s) for s in sorted_list), end='')

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

Submission status: Wrong Answer

Solution code:
def insertionSort(lis,leng):
    for i in range(leng):
        v = lis[i]
        j = i - 1
        while j >= 0 and lis[j] > v:
            lis[j+1] = lis[j]
            j = j-1
        lis[j+1]=v

Submission status: Wrong Answer

Solution code:
leng=int(input())
lis=input().split()

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

Submission status: Wrong Answer

Solution code:
def insertionSort(lis,leng):
    for i in range(leng):
        v = lis[i]
        j = i - 1
        while j >= 0 and lis[j] > v:
            lis[j+1] = lis[j]
            j = j-1
        lis[j+1]=v
        print(lis)

        
if __name__ == "__main__":
    leng=int(input())
    lis=input().split()
    insertionSort(lis,leng)

Submission status: Wrong Answer

Solution code:
def insertionSort(lis,leng):
    for i in range(leng):
        v = lis[i]
        j = i - 1
        while j >= 0 and lis[j] > v:
            lis[j+1] = lis[j]
            j = j-1
        lis[j+1]=v
        print(" ".join(lis))

        
if __name__ == "__main__":
    leng=int(input())
    lis=input().split()
    insertionSort(lis,leng)

Submission status: Wrong Answer

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

for i in xrange(len(a) - 1):
  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))
print " ".join(map(str,a))

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(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
    print(" ".join(A))

Submission status: Wrong Answer

Solution code:
N = int(input())

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

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
	B = [print(" ".join(map(str, A))) for k in range(N)]

Submission status: Wrong Answer

Solution code:
N = int(input())

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

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: Wrong Answer

Solution code:


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

for i in range(1, 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

Submission status: Wrong Answer

Solution code:


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

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)

Submission status: Wrong Answer

Solution code:

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

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

Submission status: Wrong Answer

Solution code:
def rren(): return list(map(int, input().split()))
N = int(input())
R = rren()

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]    
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: Wrong Answer

Solution code:
n = int(input())
sequence = input().split(' ')
sequence = [int(x) for x in sequence]

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

Submission status: Wrong Answer

Solution code:
n = int(input())
sequence = input().split(' ')
sequence = [int(x) for x in sequence]
print(sequence)

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

Submission status: Wrong Answer

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

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(i, end=' ') for i in A]
    print()

Submission status: Wrong Answer

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

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
    for index, v in enumerate(A):
        print(v, end='')
        if index != len(A) - 1:
            print(' ', end='')
    print()

Submission status: Wrong Answer

Solution code:
def sort(l):
    for i in range(len(l)) :
        key = l[i]
        j = i-1
        while i-1>=0 & l[j]>key:
            l[j+1] = l[j]
            j -= 1
        l[j+1] = key
        print(l)

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

sort(line)

Submission status: Wrong Answer

Solution code:
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
        print(" ".join([str(i) for i in a]))
        
n = input()
a = [int(s) for s in input().split(" ")]
insertionSort(a)

Submission status: Wrong Answer

Solution code:
def insertion_sort(array, element_number):
    for i in range(1, element_number):
        v = array[i]
        j = i - 1

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

        array[j+1] = v

        for k in range(0, element_number):
            if k < element_number:
                print(array[k] + ' ', end='')
            else:
                print(array[k], end='')

        if i < element_number-1:
            print('\n', end='')

def test():
    element_number = int(input())
    input_array = input().split()

    insertion_sort(input_array, element_number)

if __name__ == '__main__':
    test()

Submission status: Wrong Answer

Solution code:
def insertion_sort(array, element_number):
    for i in range(0, element_number):
        v = array[i]
        j = i - 1

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

        array[j+1] = v

        for k in range(0, element_number):
            if k < element_number-1:
                print(array[k] + ' ', end='')
            else:
                print(array[k], end='')

        print('\n', end='')

def test():
    element_number = int(input())
    input_array = input().split()

    insertion_sort(input_array, element_number)

if __name__ == '__main__':
    test()

Submission status: Wrong Answer

Solution code:
def insertion_sort(array, element_number):
    for i in range(1, element_number):
        v = array[i]
        j = i - 1

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

        array[j+1] = v

        for k in range(element_number):
            if k < element_number-1:
                print(str(array[k]) + ' ', end='')
            else:
                print(str(array[k]), end='')

        print('\n', end='')

def test():
    element_number = int(input())
    input_array = list(map(int, input().split()))

    insertion_sort(input_array, element_number)

if __name__ == '__main__':
    test()

Submission status: Wrong Answer

Solution code:
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 = [int(i) for i in input().split()]

insertionSort(a,n)

Submission status: Wrong Answer

Solution code:
import sys


def print_arr(arr):
    for v in arr:
        print(v, end=' ')
    print('')

def insertion_sort(arr):
    for i in range(1, len(arr)):
        print_arr(arr)
        v = arr[i]
        j = i-1
        while j >= 0 and arr[j] > v:
            arr[j+1] = arr[j]
            j -= 1
        arr[j+1] = v

input0 = sys.stdin.readline()
input_sample = sys.stdin.readline()
# input_sample = "5 2 4 6 1 3"
input = input_sample.split(" ")
input = [int(i) for i in input]
insertion_sort(input)

Submission status: Wrong Answer

Solution code:
tim = int(input())
A   = input().split()
for i in range(tim) :
    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(A))

Submission status: Wrong Answer

Solution code:
def get_input():
    length = int(raw_input())
    return map(int, raw_input().split())


input_array = get_input()
for i in range(1,len(input_array)-1):
    print " ".join([str(k) for k in input_array])
    key = input_array[i]
    j = i-1
    while j >= 0 and input_array[j] > key:
        input_array[j+1] = input_array[j]
        j -= 1
        input_array[j+1] = key

Submission status: Wrong Answer

Solution code:
def get_input():
    length = int(raw_input())
    return map(int, raw_input().split())


def insertionSort(input_array):
    for i in range(1,len(input_array)):
        print " ".join(str(each)  for each in input_array).rstrip(" ")
        key = input_array[i]
        j = i-1
        while j >= 0 and input_array[j] > key:
            input_array[j+1] = input_array[j]
            j -= 1
            input_array[j+1] = key


insertionSort(get_input())

Submission status: Wrong Answer

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